import { Message } from "./Message.js"; import { ConversationConfig } from "./ConversationConfig.js"; import { ConversationHistoryModel } from "../schemas/conversationHistory.schema.js"; import { AddMessageListener, RemoveMessageListener } from "../utils/types/index.js"; import { ConversationPluginService } from "./ConversationPluginService.js"; /** * The request options for a conversation. * * @internal * This class is used internally by the library and is not meant to be **instantiated** by consumers of the library. */ export declare class ConversationHistory { private readonly pluginService; private readonly config; private messages; private addMessageEvents; private removeMessageEvents; constructor(pluginService: ConversationPluginService, config: ConversationConfig, options?: ConversationHistoryModel); /** * Serializes the `ConversationHistory` to JSON. * * @returns A JSON representation of the `ConversationHistory` instance. * * @internal * This method is used internally by the library and is not meant to be used by consumers of the library. */ toJSON(): ConversationHistoryModel; /** * Adds a message to the conversation. * * @remarks * This method is mostly meant to be internal, but exposed for convenience. * You should use the `addAssistantMessage`, `addUserMessage`, `addFunctionCallMessage`, or `addFunctionMessage` methods when possible. * * @param message The message instance to add to the conversation. * @returns The added message. */ addMessage(message: Message): Message; /** * Adds a message with the role of `"assistant"` to the conversation. * * @param message The content of the message. * @returns The [Message](./utils/types.ts) object that was added to the conversation */ addAssistantMessage(message: string): Message; /** * Adds a message with the role of "user" to the conversation. * * @param message The content of the message. * @returns The [Message](./utils/types.ts) object that was added to the conversation */ addUserMessage(message: string): Message; /** * Adds a message with the role of "assistant" to the conversation with the function call generated by the assistant. * * @param functionCall The name and arguments of the function to call, generated by the assistant. * @returns The [Message](./utils/types.ts) object that was added to the conversation */ addFunctionCallMessage(functionCall: { name: string; arguments: Record; }): Message; /** * Adds a message with the role of "function" to the conversation with the content being the return value of the function call, called by your own code. * * @param message The return value of the function call, stringified if needed. * @param name The name of the function that was called. * @returns The [Message](./utils/types.ts) object that was added to the conversation */ addFunctionMessage(message: string, name: string): Message; /** * Sets the first message sent to the OpenAI API with the role of "system". This gives context the Chat Completion and can be used to customize its behavior. * * @param context The content of the system message. */ setContext(context: string): void; /** * Returns the context message content, if it is set. */ getContext(): string | null; /** * Get the messages in the conversation. * * @param includeContext Whether to include the context message in the returned array. * @returns A **shallow copy** of the messages array. */ getMessages(includeContext?: boolean): Message[]; /** * Clears all messages in the conversation except the context message, if it is set. */ clearMessages(): void; /** * Removes a message from the conversation's history. * * @param message Either the ID of the message to remove, or the message object itself (where the ID will be extracted from). */ removeMessage(message: string | Message): void; /** * Returns the messages in a format OpenAI's Chat Completion API can understand. */ getCreateChatCompletionMessages(): (import("../utils/types/message.types.js").CreateChatCompletionMessage | import("../utils/types/message.types.js").CreateChatCompletionFunctionCallMessage | import("../utils/types/message.types.js").CreateChatCompletionFunctionMessage)[]; private addSystemMessage; /** * Adds a listener function that is called whenever a message is added to the conversation. * * @param listener The function to call when a message is added to the conversation. * @returns A function that removes the listener from the list of listeners. */ onMessageAdded(listener: AddMessageListener): () => void; /** * Adds a listener function that is called only once whenever a message is added to the conversation. * * @param listener The function to call when a message is added to the conversation. * @returns A function that removes the listener from the list of listeners. */ onceMessageAdded(listener: AddMessageListener): () => void; /** * Removes a listener function from the list of listeners that was previously added with `onMessageAdded`. * * @param listener The function to remove from the list of listeners. */ offMessageAdded(listener: AddMessageListener): void; /** * Adds a listener function that is called whenever a message is removed to the conversation. * * @param listener The function to call when a message is removed to the conversation. * @returns A function that removes the listener from the list of listeners. */ onMessageRemoved(listener: RemoveMessageListener): () => void; /** * Adds a listener function that is called only once whenever a message is removed to the conversation. * * @param listener The function to call when a message is removed to the conversation. * @returns A function that removes the listener from the list of listeners. */ onceMessageRemoved(listener: RemoveMessageListener): () => void; /** * Removes a listener function from the list of listeners that was previously added with `onMessageRemoved`. * * @param listener The function to remove from the list of listeners. */ offMessageRemoved(listener: RemoveMessageListener): void; }