UNPKG

@butlerbot/sdk

Version:

The official ButlerBot SDK

137 lines (136 loc) 6.07 kB
import { EventSource } from "eventsource"; import { CONFIG } from "../config"; import { RequestResponseV4 } from "../types/type_registry"; import { ConversationStateResponse } from "../types/state/convo_state_response"; import { TurnProgressEntry } from "../types/response/v4/turn_registry_v4"; export type DialogueRequestParams = { /** Unique identifier for the chat session */ chatId?: string; /** The message to be sent to the AI */ message: string; /** AI model to use for generating responses */ model?: string; /** Additional instructions for location-specific context */ instructions?: string; /** Platform where the chat is occurring */ platform?: string; /** Custom personality configuration for the AI */ personality?: string; }; export type DialogueRequestOptions = Omit<Omit<DialogueRequestParams, "message">, "chatId">; type APIPath = keyof typeof CONFIG.paths.conversation; export type ConversationOptions = { /** The conversation ID to load the conversation from, server will error if this convo id doesn't exist */ convoId?: string; /** The API key to use */ apiKey: string; /** The server URL to use */ serverUrl?: string; /** * The path to append to the server URL specifying the API endpoint to use (specifically for conversations) * @deprecated use convoPath instead */ path?: string; /** The path to append to the server URL specifying the conversation API endpoint to use */ convoPath?: string; /** The path to append to the server URL specifying the history API endpoint to use */ historyPath?: string; /** The path to append to the server URL specifying the progress API endpoint to use */ progressPath?: string; /** The path to append to the server URL specifying the progress stream API endpoint to use */ progressStreamPath?: string; /** Whether to enable debug logs */ debug?: boolean; /** The API version to use */ chatApiV?: APIPath; }; export type RequestResponse = RequestResponseV4; export declare class Conversation { convoId?: string; apiKey: string; private debug; private options?; private events; private endpoints; constructor(config: ConversationOptions); /** * Sets the endpoint where the request is sent to, appended to server URL * @deprecated Use setConversationEndpoint() instead */ setEndpoint(endpoint: string): this; /** Sets the conversation endpoint where the request is sent to, appended to server URL */ setConversationEndpoint(conversationEndpoint: string): this; /** Sets the history endpoint where the quest is sent to, appended to server URL */ setHistoryEndpoint(historyEndpoint: string): this; /** Sets the progress stream endpoint where the request is sent to, appended to server URL */ setProgressStreamEndpoint(progressStreamEndpoint: string): this; /** Sets the progress endpoint where the request is sent to, appended to server URL */ setProgressEndpoint(progressEndpoint: string): this; /** Sets the conversation ID, has to be an existing conversation ID, undefined otherwise */ setConvoId(convoId: string | undefined): this; /** Sets the AI model used for the next interaction, e.g Claude-Sonnet, GPT-4 */ setModel(model: string): this; /** Sets additional instructions for location-specific context */ setInstructions(instructions: string): this; /** Sets the platform where the chat is occurring, used internally for logging - ignore in most contexts */ setPlatform(platform: string): this; /** Sets a custom personality configuration for the AI */ setPersonality(personality: string): this; /** Gets the current conversation ID */ getConvoId(): string | undefined; /** * Gets the current endpoint * @deprecated Use getConversationEndpoint() instead */ getEndpoint(): string; /** Gets the current conversation endpoint */ getConversationEndpoint(): string; /** Gets the current history endpoint */ getHistoryEndpoint(): string; /** Gets the current progress stream endpoint */ getProgressStreamEndpoint(): string; /** Gets the current progress endpoint */ getProgressEndpoint(): string; /** Gets the current options object */ getModel(): string | undefined; /** Gets the current location-specific instructions */ getInstructions(): string | undefined; /** Gets the current platform */ getPlatform(): string | undefined; /** Gets the current personality configuration */ getPersonality(): string | undefined; private hasEmitter; private addEmitter; private removeEmitter; private addListener; private removeListener; private emit; /** * Fires when the conversation ID is set * if convoId is already set when this is called, fires immediately * */ onConvoId(cb: (convoId: string) => any): string; /** Removes a convoId listener */ offConvoId(listenerId: string): void; /** * Fires once when the conversation ID is set, then removes the listener. * If convoId is already set, fires immediately */ onceConvoId(cb: (convoId: string) => any): `${string}-${string}-${string}-${string}-${string}` | undefined; private handleSSE; /** Fetches the conversation state from the server, including message history and metadata */ fetchState(): Promise<ConversationStateResponse>; /** Fetches the conversation progress stream from the server */ fetchProgressStream(cb: (chunk: RequestResponse) => any): EventSource; /** * Fetches the conversation progress from the server * Returns undefined if no active turn progress */ fetchProgress(options?: { lastEventId?: string; includeCompleted?: boolean; }): Promise<TurnProgressEntry[] | undefined>; /** Sends a message into the conversation */ send(message: string, cb: (chunk: RequestResponse) => any, options?: DialogueRequestOptions): EventSource; } export {};