/** * SSE Transport Adapter * * Server-Sent Events transport for real-time streaming. * Uses Web Streams API for compatibility with Next.js/Edge runtime. */ import type { StreamMessage, StreamTransportAdapterConfig } from '@plyaz/types/core'; import { BaseTransportAdapter } from '../BaseTransportAdapter'; /** * SSETransportAdapter - Server-Sent Events transport * * Features: * - Web Streams API for Edge runtime compatibility * - Automatic heartbeat to keep connections alive * - Proper SSE formatting with event, id, retry, data fields * - Connection cleanup on disconnect * * @example * ```ts * const sseAdapter = new SSETransportAdapter({ heartbeatInterval: 15000 }); * * // In API route * const response = await sseAdapter.createConnection(connectionId, request); * return response; // Returns SSE stream * * // Send message * await sseAdapter.send(connectionId, { * event: 'progress', * data: { percentage: 50 }, * }); * ``` */ export declare class SSETransportAdapter extends BaseTransportAdapter { private connections; constructor(config?: Partial); /** * Create a new SSE connection * * @param connectionId - Unique connection identifier * @returns Response with SSE stream */ createConnection(connectionId: string): Promise; /** * Send a message to a connection * * @param connectionId - Connection to send to * @param message - Message to send */ send(connectionId: string, message: StreamMessage): Promise; /** * Close a connection * * @param connectionId - Connection to close */ close(connectionId: string): Promise; /** * Check if a connection is alive * * @param connectionId - Connection to check */ isAlive(connectionId: string): boolean; /** * Get current connection count */ getConnectionCount(): number; /** * Get all connection IDs */ getConnectionIds(): string[]; /** * Send message immediately to controller */ private sendImmediate; /** * Format message as SSE * * SSE format: * ``` * id: messageId * retry: retryMs * data: {"event":"eventName","channel":"channelName","data":{...}} * * ``` * * Note: We intentionally DON'T use SSE named events (event: line) because: * 1. EventSource silently drops events without registered listeners * 2. Hardcoding all possible event names is not scalable * 3. Including event in JSON payload is more flexible * * The client extracts event/channel from the JSON payload in onmessage. */ private formatSSE; /** * Cleanup connection resources */ private cleanup; /** * Close all connections (for shutdown) */ closeAll(): Promise; } //# sourceMappingURL=SSETransportAdapter.d.ts.map