UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

71 lines (70 loc) 2.88 kB
/** * 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<string>; /** * 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> | unknown; totalUsage?: Promise<unknown> | 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>): StreamResult; /** * Create stream analytics - consolidates analytics from 4/10 providers */ createStreamAnalytics(result: UnknownRecord, startTime: number, options: StreamOptions): Promise<UnknownRecord | undefined>; /** * Validate streaming-only options (called before executeStream) * Simpler validation for options object structure */ validateStreamOptionsOnly(options: StreamOptions): void; }