import type { StreamCallbacks, TransportState, WebSocketOptions } from './types.js'; /** * Options for a single WebSocket chat request */ interface WsChatOptions { sessionId?: string; context?: { currentPage?: string; pageTitle?: string; }; wordLimit?: number; } /** * WebSocket transport for streaming chat. * * Maps the chat-handler Lambda WebSocket protocol to the client's StreamCallbacks: * Server typing → ignored (UI has its own indicator) * Server chunk → onToken(content) * Server done → onSources(sources) + onComplete(response) * Server error → onError(error) * * Connection is lazy — established on the first chatStream() call. * Reuses the same connection across multiple messages. * Reconnects with exponential backoff on close/error. */ export declare class WebSocketTransport { private ws; private wsUrl; private apiKey; private state; private reconnectAttempts; private maxReconnectAttempts; private reconnectDelay; private connectionTimeout; private connectionPromise; private activeCallbacks; private activeFullText; private activeSessionId; private beforeUnloadHandler; constructor(wsUrl: string, apiKey: string, options?: WebSocketOptions); /** * Current transport state */ getState(): TransportState; /** * Whether the WebSocket is currently connected */ isConnected(): boolean; /** * Connect to the WebSocket endpoint. * Appends the API key as a query parameter for authentication. * Returns a promise that resolves when the connection is open. */ connect(): Promise; /** * Stream a chat message over WebSocket. * * Sends: { type: "sendMessage", message, sessionId?, wordLimit?, context? } * Receives: typing → chunk × N → done (with sources and metadata) */ chatStream(message: string, options: WsChatOptions & StreamCallbacks): Promise; private _resolveStream; private _rejectStream; /** * Disconnect and clean up the WebSocket connection */ disconnect(): void; /** * Attempt reconnection with exponential backoff. * Used internally after connection loss. */ reconnect(): Promise; /** * Handle incoming WebSocket messages from the chat-handler Lambda. * * Protocol: * { type: 'typing', status: boolean } → ignored * { type: 'chunk', content: string } → onToken(content) * { type: 'done', sessionId, sources, metadata, messageId } → onSources + onComplete * { type: 'error', error: string } → onError */ private handleMessage; /** * Map sources from the chat-handler WebSocket format to the client Source interface. * * Chat-handler sends: { heading, content, score, documentId, documentName } * Client expects: { title, snippet, relevance, documentId, documentName } */ private mapSources; /** * Clear active request state after completion or error */ private clearActiveRequest; /** * Register a beforeunload handler to close the WebSocket on page unload */ private registerCleanup; /** * Remove the beforeunload handler */ private unregisterCleanup; } export {}; //# sourceMappingURL=WebSocketTransport.d.ts.map