export declare function readLines(stream: ReadableStream, signal?: AbortSignal): AsyncGenerator; export type JsonlLineObserver = (raw: string) => void; export declare function readJsonl(stream: ReadableStream, signal?: AbortSignal, onLine?: JsonlLineObserver): AsyncGenerator; /** * Stream parsed JSON objects from SSE `data:` lines. * * Thin wrapper over {@link readSseEvents}: yields one parsed JSON value per * dispatched SSE event, skipping events with empty `data` and stopping at the * OpenAI-style `[DONE]` sentinel. If your consumer doesn't care about `event:` * names or doesn't need a custom parse step, use this; otherwise call * `readSseEvents` directly. * * @example * ```ts * for await (const obj of readSseJson(response.body!)) { * console.log(obj); * } * ``` */ export type SseEventObserver = (event: ServerSentEvent) => void; export interface SseReadOptions { maxEventBytes?: number; maxTotalBytes?: number; } export declare function readSseJson(stream: ReadableStream, signal?: AbortSignal, onEvent?: SseEventObserver, options?: SseReadOptions): AsyncGenerator; /** * A single Server-Sent Event dispatched on a blank-line boundary. * * - `event` is the value of the most recent `event:` field, or `null` if none. * - `data` is the concatenation (joined by `\n`) of every `data:` field in the * event, exactly as required by the SSE spec. * - `raw` is the list of decoded non-empty lines that made up the event, * preserved for diagnostic context (error reporting, debugging). The * dispatching blank line is not included. */ export interface ServerSentEvent { event: string | null; data: string; raw: string[]; } /** * Stream raw Server-Sent Events from an HTTP response body. * * Yields one `ServerSentEvent` per blank-line dispatch. The consumer is * responsible for parsing `data` (e.g. JSON, plain text, error envelope). * Use `readSseJson` instead when every event is a single `data:` JSON object * and you don't need access to the `event:` field. * * Internally backed by a Buffer-based line reader (`ConcatSink`) so chunk * concatenation is O(n) and never triggers per-line string slicing of the * accumulated buffer. * * @example * ```ts * for await (const sse of readSseEvents(response.body!)) { * if (sse.event === "ping") continue; * const obj = JSON.parse(sse.data); * } * ``` */ export declare function readSseEvents(stream: ReadableStream, signal?: AbortSignal, options?: SseReadOptions): AsyncGenerator; /** * Parse a complete JSONL string, skipping malformed lines instead of throwing. * * Uses `Bun.JSONL.parseChunk` internally. On parse errors, the malformed * region is skipped up to the next newline and parsing continues. * * @example * ```ts * const entries = parseJsonlLenient(fileContents); * ``` */ export declare function parseJsonlLenient(buffer: string): T[];