import { EventEmitter } from "events"; import { ElevenLabsClient } from "../../../../Client"; import { AudioInterface } from "./AudioInterface"; import { ClientTools } from "./ClientTools"; import { ConversationInitiationData } from "./ConversationConfig"; import { WebSocketFactory } from "./interfaces/WebSocketInterface"; import { ConversationClient } from "./interfaces/ConversationClient"; /** * Why a conversation session ended, passed as the last argument of `session_ended`. * * `user` is an explicit `endSession()`. `agent` is the server closing the socket normally (code * 1000, 1001 or none), which is how a session ends when the agent ends the call. `error` is a * socket error, an abnormal close, or a failure to send audio; `closeCode` and `closeReason` are * set when the socket closed, and a connection lost without a close frame has code 1006. */ export type DisconnectionDetails = { reason: "user"; } | { reason: "agent"; closeCode: number; closeReason: string; } | { reason: "error"; message: string; closeCode?: number; closeReason?: string; }; /** * Conversational AI session for Node.js. * * Emits `session_ended` once per session with `(conversationId, closeCode, closeReason, details)`. * `closeCode` and `closeReason` are set when the server closed the socket, and `details` is the * session's {@link DisconnectionDetails}. * * BETA: This API is subject to change without regard to backwards compatibility. */ export declare class Conversation extends EventEmitter { private client; private agentId; private requiresAuth; private audioInterface; private clientTools; private config; private webSocketFactory; private conversationClient; private callbackAgentResponse?; private callbackAgentResponseCorrection?; private callbackUserTranscript?; private callbackLatencyMeasurement?; private callbackMessageReceived?; private ws?; private shouldStop; private socketError?; private conversationId?; private lastInterruptId; private inputCallback?; constructor(options: { client?: ElevenLabsClient; conversationClient?: ConversationClient; webSocketFactory?: WebSocketFactory; agentId: string; requiresAuth: boolean; audioInterface: AudioInterface; config?: ConversationInitiationData; clientTools?: ClientTools; callbackAgentResponse?: (response: string) => void; callbackAgentResponseCorrection?: (original: string, corrected: string) => void; callbackUserTranscript?: (transcript: string) => void; callbackLatencyMeasurement?: (latencyMs: number) => void; callbackMessageReceived?: (message: any) => void; }); /** * Starts the conversation session. * * Will run until `endSession` is called. */ startSession(): Promise; /** * Ends the conversation session and cleans up resources. * * `session_ended` is emitted once per session, however many times this is called. */ endSession(): void; private _endSession; /** * Send a text message from the user to the agent. * * @param text The text message to send to the agent */ sendUserMessage(text: string): void; /** * Register user activity to prevent session timeout. * * This sends a ping to the orchestrator to reset the timeout timer. */ registerUserActivity(): void; /** * Send a multimodal message combining text and file references to the agent. * * At least one of `text`, `fileId`, or `fileIds` must be provided. * * @param options.text Optional text message to include * @param options.fileId @deprecated Use `fileIds`. * @param options.fileIds Optional ElevenLabs file IDs to include */ sendMultimodalMessage(options: { text?: string; /** @deprecated Use `fileIds`. */ fileId?: string; fileIds?: string[]; }): void; /** * Send a contextual update to the conversation. * * Contextual updates are non-interrupting content that is sent to the server * to update the conversation state without directly prompting the agent. * * @param text The contextual information to send to the conversation */ sendContextualUpdate(text: string): void; /** * Get the conversation ID if available. * * @returns The conversation ID or undefined if not yet available */ getConversationId(): string | undefined; /** * Check if the session is currently active. * * @returns True if the session is active */ isSessionActive(): boolean; private _onWebSocketOpen; private _onWebSocketMessage; private _onWebSocketClose; private _handleMessage; private _getWssUrl; private _getSignedUrl; }