import type { ChatStopReason, StreamDelta } from './interface.js'; import type { AnthropicContentBlock } from './tool-formats.js'; import { fromAnthropicContent } from './tool-formats.js'; /** Anthropic SSE event shape (wire format from both direct API and compat endpoints). */ export interface AnthropicSSEEvent { type: string; index?: number | undefined; delta?: { type?: string | undefined; text?: string | undefined; thinking?: string | undefined; partial_json?: string | undefined; stop_reason?: string | null | undefined; }; content_block?: { type: string; id?: string | undefined; name?: string | undefined; }; message?: { usage?: { input_tokens: number; output_tokens: number; cache_read_input_tokens?: number | undefined; cache_creation_input_tokens?: number | undefined; }; }; usage?: { input_tokens?: number | undefined; output_tokens?: number | undefined; cache_read_input_tokens?: number | undefined; cache_creation_input_tokens?: number | undefined; }; } /** Mutable accumulator for a single Anthropic streaming response. */ export interface AnthropicSSEState { responseText: string; inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; rawStopReason: string | undefined; stopReason: ChatStopReason; toolBlocks: Map; } /** Create a fresh zero-valued SSE accumulator. */ export declare function createAnthropicSSEState(): AnthropicSSEState; /** * Dispatch one Anthropic SSE event into the accumulator. * Mutates state in place and calls onDelta for real-time delivery. */ export declare function processAnthropicSSEEvent(event: AnthropicSSEEvent, state: AnthropicSSEState, onDelta: ((delta: StreamDelta) => void) | undefined): void; /** * Read an Anthropic SSE stream to completion, dispatching each event through * processAnthropicSSEEvent. Uses SseLineBuffer for correct CRLF handling. * * @param reader ReadableStream reader from the fetch response body. * @param state Accumulator to mutate (created with createAnthropicSSEState). * @param onDelta Optional streaming delta callback. * @param providerLabel Used in warn logs, e.g. 'Anthropic' or 'AnthropicCompat(my-proxy)'. */ export declare function readAnthropicSSEStream(reader: ReadableStreamDefaultReader, state: AnthropicSSEState, onDelta: ((delta: StreamDelta) => void) | undefined, providerLabel: string): Promise; /** * Assemble the final content + toolCalls from accumulated streaming state. * Sorts tool blocks by stream index, parses JSON arguments, and calls * fromAnthropicContent to produce the canonical response shape. * * @param fallbackBlocks Used by the SDK provider: if no streaming content was * accumulated, fall back to finalMessage.content instead of returning empty. */ export declare function assembleAnthropicContentBlocks(toolBlocks: Map, responseText: string, providerName: string, fallbackBlocks?: AnthropicContentBlock[]): ReturnType; //# sourceMappingURL=anthropic-sse-assembler.d.ts.map