/** * SSE (Server-Sent Events) connection pool for the sidecar server. * * Manages a set of SSE client connections with a configurable maximum * concurrent connection limit and an optional heartbeat interval. * Dead connections are automatically cleaned up during broadcast. * * @module sidecar/server/sse/pool */ import type { SidecarEvent } from "../../types.js"; /** Configuration options for the SSE connection pool. */ export interface SseConnectionPoolOptions { /** Heartbeat interval in milliseconds (default 30000). */ heartbeatIntervalMs?: number; /** Maximum concurrent SSE connections (default 50). */ maxClients?: number; } /** A single SSE connection handle. */ export interface SseConnection { id: string; controller: ReadableStreamDefaultController; } /** * Manages a pool of SSE client connections with broadcast, * heartbeat, and dead-connection cleanup. */ export declare class SseConnectionPool { #private; constructor(opts?: SseConnectionPoolOptions); /** * Register a new SSE client connection. * * @param controller - The stream controller for the SSE response. * @returns A unique connection ID. * @throws `[Hivemind]` error when the maximum connection count is reached. */ addClient(controller: ReadableStreamDefaultController): string; /** * Deregister an SSE client connection. * * @param id - The connection ID returned by {@link addClient}. */ removeClient(id: string): void; /** Returns the number of active SSE connections. */ get clientCount(): number; /** Returns the maximum allowed SSE connections. */ get maxClients(): number; /** * Broadcast a sidecar event to all connected SSE clients. * * The event is formatted as an SSE message (`event:` + `data:` lines). * If a client's stream controller throws during enqueue, the client * is considered dead and is automatically removed. * * @param event - The sidecar event to broadcast. */ broadcast(event: SidecarEvent): void; /** * Start the heartbeat interval. * * Sends an `event: heartbeat` message to all connected clients at * the configured interval. Clears any previously running heartbeat * before starting a new one. */ startHeartbeat(): void; /** * Stop the heartbeat interval and remove all connections. * * Each connection's controller is closed before removal. */ stop(): void; } //# sourceMappingURL=pool.d.ts.map