import { Logger } from "./logger.cjs"; import { RecordProviderKey, ToolCall } from "./types.cjs"; //#region src/stream-collapse.d.ts interface CollapseResult { content?: string; reasoning?: string; /** * The real cryptographic `signature` value captured from an Anthropic * `signature_delta`. Carried so a recorded real-provider thinking turn can * replay its ACTUAL signature instead of aimock's placeholder. Absent when the * stream carried no signature. Single-signature assumption: a turn with * MULTIPLE thinking blocks collapses to one merged `reasoning` string carrying * only the FINAL block's signature (last-signature-wins) — per-block fidelity * is not preserved. The recorder persists this only alongside a non-empty * `reasoning` (a bare signature has nothing to attach to on replay); see * `TextResponse.reasoningSignature` in types.ts. */ reasoningSignature?: string; /** * The opaque `data` payload(s) of any Anthropic `redacted_thinking` blocks, in * stream order. Captured so a recorded redacted-thinking turn round-trips its * encrypted reasoning faithfully. Absent when none present. */ redactedThinking?: string[]; webSearches?: string[]; toolCalls?: ToolCall[]; droppedChunks?: number; firstDroppedSample?: string; truncated?: boolean; audioB64?: string; audioMimeType?: string; /** * Set when harmony channel tokens were present in the accumulated content but * could NOT be parsed into a complete, valid harmony structure. The content * is preserved VERBATIM, so this is NOT transport loss — it is distinct from * `droppedChunks` / `truncated`, which are reserved for genuine transport loss * (malformed SSE/NDJSON frames, CRC mismatch). The caller surfaces this as a * dedicated warning rather than a dropped/truncated-chunk warning. */ harmonyUnparsed?: true; /** Short human-readable note accompanying {@link harmonyUnparsed}. */ harmonyNote?: string; } /** * The opaque `data` of a non-empty Anthropic `redacted_thinking` block, or * `undefined` if `block` is not a redacted_thinking block or carries empty/no * data. NON-EMPTY is required: the replay-side validator rejects a leading * empty-data redacted_thinking block, so recording `data: ""` would yield a * fixture that 400s under strict replay. Shared by every capture site (SSE, * Anthropic-native binary, non-streaming recorder) so the rule stays in one * place. */ /** * Collapse OpenAI Chat Completions SSE stream into a single response. * * Format: * data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"Hello"}}]}\n\n * data: [DONE]\n\n */ declare function collapseOpenAISSE(body: string): CollapseResult; /** * Collapse Anthropic Claude Messages SSE stream into a single response. * * Format: * event: message_start\ndata: {...}\n\n * event: content_block_delta\ndata: {"delta":{"type":"text_delta","text":"Hello"}}\n\n */ declare function collapseAnthropicSSE(body: string): CollapseResult; /** * Collapse Gemini SSE stream into a single response. * * Format (data-only, no event prefix, no [DONE]): * data: {"candidates":[{"content":{"parts":[{"text":"Hello"}]}}]}\n\n */ declare function collapseGeminiSSE(body: string): CollapseResult; /** * Collapse Ollama NDJSON stream into a single response. * * /api/chat format: * {"model":"llama3","message":{"role":"assistant","content":"Hello"},"done":false}\n * * /api/generate format: * {"model":"llama3","response":"Hello","done":false}\n * * Open-weight gpt-oss served via Ollama streams harmony channel tokens inside * `message.content` (just like the OpenAI SSE path), so after accumulation the * content is run through the same fail-safe {@link parseHarmonyContent} gate to * capture structured tool calls / reasoning instead of leaking raw tokens. */ declare function collapseOllamaNDJSON(body: string): CollapseResult; /** * Collapse Cohere SSE stream into a single response. * * Format: * event: content-delta\ndata: {"type":"content-delta","delta":{"message":{"content":{"text":"Hello"}}}}\n\n */ declare function collapseCohereSSE(body: string): CollapseResult; /** * Collapse Bedrock binary Event Stream into a single response. * * Each frame contains a JSON payload with event types like: * contentBlockDelta, contentBlockStart, etc. */ declare function collapseBedrockEventStream(body: Buffer): CollapseResult; /** * Collapse Gemini Interactions SSE stream into a single response. * * Handles the SDK 2.x event protocol (the "Interactions breaking changes, * May 2026" shapes): * data: {"event_type":"step.start","index":1,"step":{"type":"function_call","id":"call_1","name":"fn","arguments":{}}} * data: {"event_type":"step.delta","index":0,"delta":{"type":"text","text":"Hello"}} * data: {"event_type":"step.delta","index":1,"delta":{"type":"arguments_delta","arguments":"{\"x\":1}"}} * data: {"event_type":"interaction.completed","interaction":{"id":"...","usage":{...}}} * * The legacy SDK 1.x shapes (`content.delta` with an inline `function_call` * delta) are still accepted for backward compatibility with previously * recorded fixtures. */ declare function collapseGeminiInteractionsSSE(body: string): CollapseResult; /** * Collapse a streaming response body into a non-streaming fixture response. * Returns null if the content type is not a known streaming format. * Falls back to OpenAI SSE parsing for unrecognized provider keys with text/event-stream. */ declare function collapseStreamingResponse(contentType: string, providerKey: RecordProviderKey, body: string | Buffer, logger?: Logger): CollapseResult | null; //# sourceMappingURL=stream-collapse.d.ts.map //#endregion export { CollapseResult, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiInteractionsSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse }; //# sourceMappingURL=stream-collapse.d.cts.map