UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

108 lines (107 loc) 3.25 kB
/** * WebSocketHandler - Unified WebSocket Support * * Provides cross-framework WebSocket handling for real-time AI interactions. * Supports connection management, message routing, and graceful shutdown. */ import type { WebSocketConfig, WebSocketHandler as IWebSocketHandler, WebSocketConnection, WebSocketMessage, AuthenticatedUser } from "../../types/index.js"; /** * WebSocket connection manager */ export declare class WebSocketConnectionManager { private connections; private config; private pingIntervals; private handlers; constructor(config?: WebSocketConfig); /** * Register a handler for a path */ registerHandler(path: string, handler: IWebSocketHandler): void; /** * Get handler for a path */ getHandler(path: string): IWebSocketHandler | undefined; /** * Handle new connection */ handleConnection(socket: unknown, path: string, user?: AuthenticatedUser): Promise<WebSocketConnection>; /** * Handle incoming message */ handleMessage(connectionId: string, data: string | ArrayBuffer, isBinary: boolean): Promise<void>; /** * Handle connection close */ handleClose(connectionId: string, code: number, reason: string): Promise<void>; /** * Handle connection error */ handleError(connectionId: string, error: Error): Promise<void>; /** * Get connection by ID */ getConnection(connectionId: string): WebSocketConnection | undefined; /** * Get all connections */ getAllConnections(): WebSocketConnection[]; /** * Get connections for a user */ getConnectionsByUser(userId: string): WebSocketConnection[]; /** * Get connections for a path */ getConnectionsByPath(path: string): WebSocketConnection[]; /** * Send message to a connection */ send(connectionId: string, data: string | ArrayBuffer): void; /** * Broadcast message to all connections */ broadcast(data: string | ArrayBuffer, filter?: (conn: WebSocketConnection) => boolean): void; /** * Close a connection */ close(connectionId: string, code?: number, reason?: string): Promise<void>; /** * Close all connections */ closeAll(code?: number, reason?: string): Promise<void>; /** * Get connection count */ getConnectionCount(): number; /** * Start ping interval for a connection */ private startPingInterval; /** * Stop ping interval for a connection */ private stopPingInterval; } /** * WebSocket message router for handling different message types */ export declare class WebSocketMessageRouter { private routes; /** * Register a message route */ route(type: string, handler: (connection: WebSocketConnection, payload: unknown) => Promise<unknown>): void; /** * Handle incoming message */ handle(connection: WebSocketConnection, message: WebSocketMessage): Promise<unknown>; /** * Get registered routes */ getRoutes(): string[]; } /** * Create a WebSocket handler for AI agent interactions */ export declare function createAgentWebSocketHandler(_neurolink: unknown): IWebSocketHandler;