UNPKG

mcp-chrome-bridge

Version:

Chrome Native-Messaging host (Node)

43 lines (42 loc) 1.45 kB
import type { ServerResponse } from 'node:http'; import type { RealtimeEvent } from './types'; type WebSocketLike = { readyState?: number; send(data: string): void; close?: () => void; }; /** * AgentStreamManager manages SSE/WebSocket connections keyed by sessionId. * * 中文说明:此实现参考 other/cweb 中的 StreamManager,但适配 Fastify/Node HTTP, * 使用 ServerResponse 直接写入 SSE 数据,避免在 Node 环境中额外引入 Web Streams 依赖。 */ export declare class AgentStreamManager { private readonly sseClients; private readonly webSocketClients; private heartbeatTimer; addSseStream(sessionId: string, res: ServerResponse): void; removeSseStream(sessionId: string, res: ServerResponse): void; addWebSocket(sessionId: string, socket: WebSocketLike): void; removeWebSocket(sessionId: string, socket: WebSocketLike): void; publish(event: RealtimeEvent): void; /** * Extract sessionId from event based on event type. */ private extractSessionId; /** * Send event to a specific session's clients only. */ private sendToSession; /** * Broadcast event to all connected clients (used for heartbeat). */ private broadcastToAll; private isResponseDead; private isSocketDead; closeAll(): void; private ensureHeartbeatTimer; private stopHeartbeatTimerIfIdle; private stopHeartbeatTimer; } export {};