import type { GenericContentBlock } from '../../../shared/types.js'; /** * The outcome of finalizing a streamed tool_use block. * `ok: false` means the model produced malformed JSON input — the tool_use block * is still recorded (so the assistant message stays structurally valid), but the * caller should return an error tool_result rather than dispatch the tool. */ export type FinishedToolUse = { ok: true; id: string; name: string; input: Record; /** Raw concatenated input JSON — used for repeated-call detection. */ inputJson: string; } | { ok: false; id: string; name: string; }; /** * Turns a provider's stream of delta events (`text_*` / `tool_use_*`) into the * completed content blocks of a single assistant turn. * * This is the pure, side-effect-free state machine extracted from `runAgentLoop`: * it owns the in-progress text/tool_use buffers and the resulting block array, * while the caller keeps the I/O concerns (streaming deltas to the client, * dispatching tools, retry/repeat detection). */ export declare class StreamAccumulator { private readonly _blocks; private currentText; private inText; private toolUse; /** * Live array of completed content blocks for the current turn. The caller may * append to it directly (e.g. reasoning blocks) and reset it (`.length = 0`) * when committing messages early — the accumulator keeps appending afterwards. */ get blocks(): GenericContentBlock[]; startText(): void; /** * Accumulate a raw text delta and return its transformed form for the caller * to stream to the client. Returns `null` when no text block is open (the * delta is ignored, matching the original `if (inTextBlock)` guard). */ pushTextDelta(raw: string): string | null; /** Finalize the open text block, recording it only if it has content. */ endText(): void; startToolUse(id: string, name: string): void; pushToolUseDelta(partialJson: string): void; /** * Finalize the open tool_use block: parse its accumulated JSON input, always * record the tool_use block (so the assistant message stays valid even on * malformed input), and return the parse outcome. Returns `null` if no tool_use * was open. */ finishToolUse(): FinishedToolUse | null; }