/** * SSE parsing. * * Deliberately NOT `EventSource`, for three reasons that each cost real * behaviour: * * 1. EventSource cannot set request headers, so it cannot send * `st-protocol` — negotiation would be query-param-only forever. * 2. EventSource reconnects automatically and silently. On a stream that * ends in `error` that means retrying a request the server already * answered definitively, repeatedly, from inside a customer's page. * 3. EventSource cannot read response headers, so the client could never * see which protocol version it actually got. * * fetch + a manual parser gives all three back. The cost is ~80 lines, which * is a good trade for not having a background reconnect loop we do not * control. */ export interface SseMessage { /** `event:` name. Unnamed messages arrive as "message", per the spec. */ event: string; /** `data:` payload, lines joined with "\n". */ data: string; } /** * Incremental SSE frame parser. Feed it decoded text; it yields complete * messages. Holds partial frames across chunk boundaries — a `data:` line * split mid-UTF-8-sequence or mid-JSON is the normal case on a real network, * not an edge case. */ export declare class SseParser { private buffer; /** Index into `buffer` where unscanned text begins. Everything before it * was already searched for a separator and found none. */ private scanFrom; /** Blank line between frames: \n\n, \r\n\r\n, or a mix from a proxy that * rewrites only some line endings. Stateful (`g`), so one instance each. */ private readonly separator; /** Feed a chunk of decoded text; returns every message it completed. */ push(chunk: string): SseMessage[]; /** Flush a trailing frame that never got its blank line (server closed). */ flush(): SseMessage[]; } export interface ReadSseOptions { signal?: AbortSignal; /** Called for every complete message, in order. */ onMessage: (message: SseMessage) => void; } /** * Drain a fetch Response body as SSE. * * Returns when the server closes the stream. Aborting via `signal` resolves * rather than throwing: a component unmounting mid-stream is the normal way * these end, not an error worth surfacing in a customer's console. */ export declare function readSseStream(response: Response, options: ReadSseOptions): Promise; //# sourceMappingURL=sse.d.ts.map