/** * Stream Handler Module * * Handles streaming-related validation, result creation, and analytics. * Extracted from BaseProvider to follow Single Responsibility Principle. * * Responsibilities: * - Stream options validation * - Text stream creation * - Stream result formatting * - Stream analytics creation * * @module core/modules/StreamHandler */ import type { StreamOptions, StreamResult, UnknownRecord, AIProviderName, StreamNoOutputSentinel } from "../../types/index.js"; /** * StreamHandler class - Handles streaming operations for AI providers */ export declare class StreamHandler { private readonly providerName; private readonly modelName; constructor(providerName: AIProviderName, modelName: string); /** * Validate stream options - consolidates validation from 7/10 providers */ validateStreamOptions(options: StreamOptions): void; /** * Create text stream transformation - consolidates identical logic from 7/10 providers * Tracks TTFC (Time To First Chunk), chunk count, and total bytes streamed. */ createTextStream(result: { textStream: AsyncIterable; /** * Optional metadata getters from the AI SDK's StreamTextResult. These * reject with NoOutputGeneratedError when no output is produced, which * is exactly the path Curator's P3-6 fix needs to enrich. We attempt * to await them in the catch block; whichever resolve get included in * the sentinel chunk metadata. */ finishReason?: Promise | unknown; totalUsage?: Promise | unknown; }, /** * Reviewer follow-up: optional getter for the provider's captured * upstream error (typically wired from `streamText`'s `onError` * callback). When set, the sentinel's `providerError` / * `modelResponseRaw` reflect the real upstream cause instead of the * AI SDK's generic "No output generated" message. Callers that don't * capture upstream errors can omit this — the sentinel still * populates with the AI SDK error. */ getUnderlyingError?: () => unknown): AsyncGenerator<{ content: string; } | StreamNoOutputSentinel>; /** * Create standardized stream result - consolidates result structure */ createStreamResult(stream: AsyncGenerator<{ content: string; }>, additionalProps?: Partial): StreamResult; /** * Create stream analytics - consolidates analytics from 4/10 providers */ createStreamAnalytics(result: UnknownRecord, startTime: number, options: StreamOptions): Promise; /** * Validate streaming-only options (called before executeStream) * Simpler validation for options object structure */ validateStreamOptionsOnly(options: StreamOptions): void; }