/** * API Stream Types * * Unified streaming response types that all providers yield. * This provides a consistent interface regardless of the underlying provider. */ import type { GeneratedMedia } from "@cline/shared"; /** * The main stream type - an async generator that yields chunks */ export type ApiStream = AsyncGenerator & { id?: string; }; /** * Union of all possible chunk types */ export type ApiStreamChunk = ApiStreamTextChunk | ApiStreamMediaChunk | ApiStreamReasoningChunk | ApiStreamUsageChunk | ApiStreamToolCallsChunk | ApiStreamDoneChunk; /** * Text content chunk */ export interface ApiStreamTextChunk { type: "text"; /** Text content generated by the model */ text: string; /** Response ID associated with this chunk */ id: string; /** Thought signature (used by Gemini) */ signature?: string; } /** * Model-generated media content chunk. */ export interface ApiStreamMediaChunk { type: "media"; media: GeneratedMedia; /** Response ID associated with this chunk */ id: string; } /** * Reasoning/thinking content chunk */ export interface ApiStreamReasoningChunk { type: "reasoning"; /** The reasoning text generated by the model */ reasoning: string; /** Additional reasoning details (provider-specific) */ details?: unknown; /** Signature for the thinking block (Anthropic, Gemini) */ signature?: string; /** Redacted reasoning data */ redacted_data?: string; /** Response ID associated with this chunk */ id: string; } /** * Usage/token count chunk */ export interface ApiStreamUsageChunk { type: "usage"; /** Total number of input tokens reported by the provider */ inputTokens: number; /** Number of output tokens */ outputTokens: number; /** Number of tokens written to cache */ cacheWriteTokens?: number; /** Number of tokens read from cache */ cacheReadTokens?: number; /** Number of thinking/reasoning tokens */ thoughtsTokenCount?: number; /** Total cost in USD (if calculable) */ totalCost?: number; /** Response ID */ id: string; } /** * Tool call chunk */ export interface ApiStreamToolCallsChunk { type: "tool_calls"; /** The tool call information */ tool_call: ApiStreamToolCall; /** Response ID */ id: string; /** Thought signature (Gemini) */ signature?: string; } /** * Tool call details */ export interface ApiStreamToolCall { /** Call ID for this tool invocation */ call_id?: string; /** Function/tool information */ function: { /** Tool call ID */ id?: string; /** Name of the tool */ name?: string; /** Arguments passed to the tool (can be string or parsed object) */ arguments?: string | Record; }; } /** * Stream completion chunk - indicates the stream has finished */ export interface ApiStreamDoneChunk { type: "done"; /** Whether the stream completed successfully */ success: boolean; /** Error message if the stream failed */ error?: string; /** Reason for incomplete response (e.g., "max_output_tokens") */ incompleteReason?: string; /** Response ID */ id: string; } //# sourceMappingURL=stream.d.ts.map