/** * Layer 2: SSE connection manager. * * Manages Server-Sent Event streams for real-time agent progress * updates to the dashboard. Each connection is tracked by a unique * ID and associated with a task ID. * * This module does not import from Layer 1. */ import type { Client } from '@libsql/client'; import type { ResolvedConfig } from '../../config.js'; import type { AgentEvent } from './types.js'; type RequestEvent = Parameters[0]['event']; /** * Create a new SSE stream for a task. * * Returns the HTTP Response and a unique connection ID. The stream * sends an initial `connected` event with the task ID. * * @param taskId - The task to stream events for. * @returns The Response object and the connection ID. */ export declare function createSSEStream(taskId: string): { response: Response; connectionId: string; }; /** * Remove an SSE connection by its ID. * * Closes the stream controller and removes the connection from the * registry. Safe to call with an ID that does not exist. */ export declare function removeSSEConnection(id: string): void; /** * Broadcast an agent event to all SSE connections for a given task. * * Accepts both persistent AgentMarker events (progress, blocked, complete, error) * and ephemeral ActivityEvent events. Iterates all connections matching the task * ID and writes the event as an SSE message. Connections that throw on write * (disconnected clients) are automatically removed. */ export declare function broadcastToSSEClients(taskId: string, event: AgentEvent): void; /** * Handle an SSE connection request for a task. * * If the request accepts `text/event-stream`, creates an SSE stream * and sends existing logs as catch-up events before streaming live. * Otherwise, returns the logs as a JSON array. * * @param event - The SvelteKit request event. * @param db - The database client. * @param _config - The resolved configuration (unused, reserved for future use). * @param params - Route parameters; expects `params.id` to be the task ID. */ export declare function handleSSEConnection(event: RequestEvent, db: Client, _config: ResolvedConfig, params: Record): Promise; /** * Get the number of active connections. Exposed for testing. * @internal */ export declare function _getConnectionCount(): number; /** * Check if the heartbeat is running. Exposed for testing. * @internal */ export declare function _isHeartbeatRunning(): boolean; /** * Clear all connections and stop heartbeat. Exposed for testing. * @internal */ export declare function _clearConnectionsForTesting(): void; export {}; //# sourceMappingURL=sse.d.ts.map