/** * High-level SynapseSDK API * Provides a simple interface for managing chat sessions */ import { SYNAPSE_REALTIME_EVENTS } from "./messages/types"; import { type SessionResponse } from "./resources/session/types"; import { type AudioMetaData } from "./media/audio/types"; import type { AgentConfigResponse, ExistingSessionOptions, SendMessageOptions, SynapseSDKConfig, USER_FEEDBACK } from "./types"; import { VoiceAgent } from "./voice/VoiceAgent"; export declare class SynapseSDK { private connection; private messageManager; private resourceManager; private sessionConfig; private config; private connectionType; private isRefreshingSession; private connectionAttempts; private sdkEventEmitter; private _voice; constructor(config: SynapseSDKConfig); /** * Start the session * if existing session is provided, it will be validated and refreshed * if no existing session is provided, a new session will be created * then the connection will be initialized and event handlers will be setup * return the session response */ startSession(existingSession?: ExistingSessionOptions): Promise; /** * Send a message conetnt will be text always */ sendMessage({ message, files, audio, tool_declined, tool_id, initial_prompts, tool_result }: SendMessageOptions): Promise; /** * Send feedback on a message */ sendFeedback(messageId: string, feedback: USER_FEEDBACK, reason?: string): Promise; /** * Register a listener for a specific event */ on(event: SYNAPSE_REALTIME_EVENTS, listener: (...args: unknown[]) => void): void; /** * Remove a listener for a specific event */ off(event: SYNAPSE_REALTIME_EVENTS, listener: (...args: unknown[]) => void): void; /** * Get the session ID */ getSessionConfig(): SessionResponse; /** * Call tool */ callTool(tool_id: string, message_id: string, params?: Record): Promise; /** * Send audio * */ startRecording({ onChunks, onError, }: { onChunks: (chunks: AudioMetaData) => void; onError?: (error: Error) => void; }): Promise; /** * Stop recording audio */ endRecording(): void; getAgentConfig(): Promise; isConnected(): boolean; get voice(): VoiceAgent; /** * End the session */ endSession(): void; private buildVoiceConfig; private toClientError; private emitError; private toSessionError; /** * Initialize the connection * eg: socket connection or polling connection */ private initializeConnection; /** * Resolve the session * function to decide whether to create a new session or refresh the existing session */ private manageSession; /** * Refresh the session */ private refreshSession; /** * Create a new session */ private createNewSession; /** * Set up event handlers for connection and messages */ private setupEventHandlers; /** * Handle socket error */ private onSocketConnectionError; /** * Handle socket connection open */ private onSocketConnectionOpen; /** * Handle incoming socket messages */ private onIncomingSocketMessage; /** * Handle session expired */ private handleSessionExpiry; private toConnectionError; private closeConnection; private cleanup; }