/** * Generic utilities for parsing Server-Sent Events (SSE) streams. * Shared between client, CLI, and any other consumer of provider SSE streams. */ import type { ProviderProtocol, AiChunk } from './protocol.js'; /** * Parses an SSE block (text between \n\n delimiters) into a data payload. * Handles multiple data: lines and the [DONE] sentinel. */ export declare function parseSseBlock(block: string): T | 'done' | null; /** * Reads an SSE stream and emits parsed chunks via callback. * Handles buffering, block splitting, and error recovery. * * @param reader - ReadableStream reader to consume * @param onChunk - Callback invoked for each parsed non-null chunk * @param signal - Optional abort signal for cancellation * @returns Object with whether any data was received */ export declare function consumeSseStream(reader: ReadableStreamDefaultReader, onChunk: (chunk: T) => void, signal?: AbortSignal): Promise<{ receivedAnyData: boolean; }>; /** * Pull-based twin of {@link consumeSseStream}: yields each parsed SSE block as it arrives so a * caller can `for await` the stream (and tear it down by breaking the loop). Same framing and * `[DONE]` handling; single-sources the SSE parsing. Cancels the reader on early exit; throws * on abort so callers' error paths fire. */ export declare function consumeSseStreamGen(reader: ReadableStreamDefaultReader, signal?: AbortSignal, onBytes?: () => void): AsyncGenerator; /** * Consume a provider SSE stream into a single text string. * Handles protocol detection, chunk parsing, and reasoning token filtering. * * @param response - Fetch Response with SSE body (from server or provider directly) * @param protocol - Provider protocol. If omitted, read from X-Provider-Protocol header. * @returns Accumulated text content (reasoning tokens discarded) */ export declare function consumeStreamText(response: Response, protocol?: ProviderProtocol): Promise; /** * Adapt a provider's SSE Response into a pull stream of public {@link AiChunk}s — the shared * SSE→AiChunk conversion behind `tb.ai.stream()`, used by both the CLI bridge and the web sandbox * bridge (each then wraps it in its own transport: NDJSON over HTTP / postMessage frames). Pure and * browser-safe: only a `Response` reader plus the already-shared parsing. Each internal * `{ text?, reasoning? }` piece becomes one or two discriminated chunks (reasoning before text). * A provider error event throws `ProviderStreamError` out of `parseStreamChunk`, which the caller's * transport turns into a terminal error so the client iterator rejects. */ export declare function streamAiChunks(response: Response, protocol?: ProviderProtocol): AsyncGenerator; //# sourceMappingURL=sseParser.d.ts.map