import { ThreadMetadata } from './memory.js'; import { CONNECTOR_PROTOCOL_TYPE } from './connector.js'; type StreamEvent = { event: "text_chunk"; data: { delta: string; }; } | { event: "task_output"; data: { taskId: string; title: string; delta: string; agent?: string; }; } | { event: "task_result"; data: { taskId: string; title: string; status: "completed" | "failed" | "skipped"; agent?: string; error?: string; }; } | { event: "tool_start"; data: { toolCallId: string; protocol: CONNECTOR_PROTOCOL_TYPE; toolName: string; toolArgs: unknown; }; } | { event: "tool_output"; data: { toolCallId: string; protocol: CONNECTOR_PROTOCOL_TYPE; toolName: string; result: unknown; }; } | { event: "error"; data: { message: string; }; } | { event: "thread_id"; data: ThreadMetadata; } | { event: "document_id"; data: { documentId: string; slotId: string; }; } | { event: "intent_process"; data: { subquery: string; actionPlan: string; }; } | { event: "collection_name"; data: { name: string; }; } | { event: "thinking_process"; data: { title: string; description: string; metadata?: Record; }; }; /** * Tool call delta for streaming tool invocations */ interface ToolCallDelta { index: number; id?: string; type?: "function"; function?: { name?: string; arguments?: string; }; } /** * A fully-assembled tool call reconstructed from a streamed assistant turn. * * The `id` is provider-issued and is the join key between the assistant's * tool call and the corresponding tool result message that follows. */ interface AssembledToolCall { id: string; type: "function"; function: { name: string; arguments: string; }; } /** * Normalized stream chunk interface for all LLM providers. * * This interface provides a consistent structure for stream responses * across different AI model providers (OpenAI, Gemini, Claude, etc.) */ interface StreamChunk { /** Text content delta from the model */ delta?: { role?: string; content?: string; tool_calls?: ToolCallDelta[]; }; /** Indicates if the stream has finished and why */ finish_reason?: "stop" | "length" | "tool_calls" | "content_filter" | null; /** Provider-specific metadata */ metadata?: Record; } /** * Async iterable stream interface for LLM responses */ interface LLMStream extends AsyncIterable { /** Cancels the stream */ cancel?: () => void; /** Stream metadata */ metadata?: Record; } export type { AssembledToolCall, LLMStream, StreamChunk, StreamEvent, ToolCallDelta };