/** * WebSocket Client for Real-Time Communication * * Provides bidirectional streaming between agent and server. * - Receives messages instantly (no polling delay) * - Streams responses as they're generated * - Supports interruption and progress updates */ import type { WorkerStatus, LiaTodoItem } from './orchestrator.js'; import { AssetResponse } from './core/asset-api.js'; export type MessageHandler = (message: WebSocketMessage) => Promise; export type StreamHandler = (chunk: string) => void; export interface WebSocketMessage { type: 'message' | 'interrupt' | 'ping' | 'pong' | 'connected' | 'asset_request' | 'ready'; id?: string; content?: string; timestamp?: number; requestId?: string; assetId?: string; groupId?: string; viewId?: string; } export interface StreamingResponse { send: (chunk: string) => void; done: () => void; error: (message: string) => void; } export declare class AgentWebSocket { private ws; private serverUrl; private token; private messageHandler; private reconnectAttempts; private maxReconnectAttempts; private reconnectDelay; private pingInterval; private isConnected; private connecting; private connectPromise; private pendingResponses; private cloudflareBlocked; private pendingMessages; private readyPending; constructor(); /** * Connect to the WebSocket server */ connect(): Promise; /** * Set handler for incoming messages */ onMessage(handler: MessageHandler): void; sendReady(): void; /** * Send a streaming response for a message */ createStreamingResponse(messageId: string): StreamingResponse; /** * Send a complete response (non-streaming) */ sendResponse(messageId: string, content: string): void; /** * Send progress update */ sendProgress(messageId: string, status: string): void; /** * Send typing indicator */ sendTyping(isTyping: boolean): void; /** * Send workers status update for progress bars */ sendWorkersUpdate(workers: WorkerStatus[]): void; /** * Send todo list update for inline display in chat */ sendTodoUpdate(todos: LiaTodoItem[]): void; /** * Send gallery command (AI controls the gallery) */ sendGalleryCommand(command: 'open' | 'close' | 'focus_worker' | 'open_asset' | 'back', workerId?: string, assetIndex?: number): void; /** * Send gallery workers with their assets (legacy) */ sendGalleryWorkers(workers: Array<{ id: string; task: string; status: 'running' | 'completed' | 'failed'; assets: Array<{ path: string; name: string; type: 'new' | 'modified' | 'unchanged'; fileType: 'code' | 'image' | 'pdf' | 'text' | 'other'; preview?: string; diff?: Array<{ type: 'context' | 'add' | 'remove'; content: string; }>; }>; }>): void; /** * Send full gallery state (new fast-path system) */ sendGalleryState(): void; /** * Send asset response */ sendAssetResponse(response: AssetResponse): void; /** * Check if connected */ connected(): boolean; /** * Close the connection */ close(): void; private handleMessage; private sendToServer; /** * Handle asset requests (fast-path, no LLM) */ private handleAssetRequest; private startPingInterval; private stopPingInterval; private attemptReconnect; }