/** * Streaming support for recursive-llm-ts. * * Provides `AsyncIterable`-based streaming for both text completions * and structured output, with AbortController support. */ export type StreamChunkType = 'text' | 'partial_object' | 'usage' | 'error' | 'done'; export interface StreamChunkBase { type: StreamChunkType; timestamp: number; } export interface TextStreamChunk extends StreamChunkBase { type: 'text'; text: string; } export interface PartialObjectStreamChunk extends StreamChunkBase { type: 'partial_object'; object: Partial; /** JSON path of the field being populated */ path?: string; } export interface UsageStreamChunk extends StreamChunkBase { type: 'usage'; usage: { promptTokens: number; completionTokens: number; totalTokens: number; }; } export interface ErrorStreamChunk extends StreamChunkBase { type: 'error'; error: Error; } export interface DoneStreamChunk extends StreamChunkBase { type: 'done'; stats: { llm_calls: number; iterations: number; depth: number; }; } export type StreamChunk = TextStreamChunk | PartialObjectStreamChunk | UsageStreamChunk | ErrorStreamChunk | DoneStreamChunk; export interface StreamOptions { /** AbortController signal to cancel the stream */ signal?: AbortSignal; /** Called on each chunk (alternative to async iteration) */ onChunk?: (chunk: StreamChunk) => void; } /** * An async iterable stream of completion chunks. * * Can be consumed with `for await...of` or by attaching an `onChunk` callback. * * @example * ```typescript * const stream = rlm.streamCompletion(query, context); * let fullText = ''; * for await (const chunk of stream) { * if (chunk.type === 'text') fullText += chunk.text; * } * ``` */ export declare class RLMStream implements AsyncIterable> { private chunks; private resolvers; private done; private error; private signal?; private abortHandler?; constructor(signal?: AbortSignal); /** Push a chunk into the stream (called by the producer) */ push(chunk: StreamChunk): void; /** Signal an error on the stream */ pushError(err: Error): void; /** Mark the stream as complete */ complete(stats: { llm_calls: number; iterations: number; depth: number; }): void; private cleanup; /** Collect all text chunks into a single string */ toText(): Promise; /** Collect the final structured object (for structured streaming) */ toObject(): Promise; [Symbol.asyncIterator](): AsyncIterator>; } /** * Creates a simulated stream from a non-streaming completion result. * Useful as a compatibility bridge until full streaming is implemented in the Go binary. */ export declare function createSimulatedStream(text: string, stats: { llm_calls: number; iterations: number; depth: number; }, signal?: AbortSignal, chunkSize?: number): RLMStream;