import type { AIProviderToolChoice, AIToolMap, AIUsage } from "../../types/ai"; import { type GenerateAIOptions, type GenerateAIToolCall } from "./generateAI"; export type StreamAIWithToolsOptions = Omit & { /** Tools the model may call — each with a `handler` the loop runs on its behalf. */ tools: AIToolMap; /** Max model⇄tool round-trips before forcing a final answer. Default 8. */ maxTurns?: number; toolChoice?: AIProviderToolChoice; }; export type StreamAIWithToolsSummary = { /** All assistant text across every turn, concatenated in stream order. */ text: string; /** Every tool call the model made (executed or not), in order. */ toolCalls: GenerateAIToolCall[]; /** Model turns consumed (1 = no tool round-trips). */ turns: number; /** Summed usage across all turns. */ usage?: AIUsage; }; export type StreamAIWithToolsEvent = { type: "thinking"; content: string; } | { type: "text"; content: string; } | { type: "audio"; data: string; format: string; transcript?: string; audioId?: string; } /** A model turn finished streaming — carries that turn's own usage, so * metering can bill per-turn instead of waiting for the summed total. */ | { type: "turn"; usage?: AIUsage; } | { type: "tool_start"; id: string; name: string; input: unknown; } | { type: "tool_result"; id: string; name: string; input: unknown; ms: number; /** False when the handler threw or the tool name was unknown. */ ok: boolean; result: string; } | ({ type: "done"; } & StreamAIWithToolsSummary); /** * Agentic STREAMING generation: text/thinking deltas are yielded live while the * model may call the provided handler tools mid-answer — the loop runs them, * feeds the results back, and continues streaming until the model finishes (or * `maxTurns`). Transport-agnostic (an async generator, unlike the WebSocket * `streamAI`), so HTTP/SSE handlers can re-encode events however they like. * * Event order per turn: thinking/text deltas → turn → tool_start/tool_result * pairs → next turn's deltas… → done (with the summed usage + full text). */ export declare const streamAIWithTools: (options: StreamAIWithToolsOptions) => AsyncGenerator;