import type { ChatMessage, NativeToolCall, ReasoningArtifact, ReasoningBlock } from "../types.js"; /** All non-empty native tool-call ids already reserved by a transcript. */ export declare function toolCallIdsInHistory(messages: readonly ChatMessage[]): Set; /** * Ensure every tool call has a unique non-empty id before history append. * `reservedIds` closes the provider-reuse case: some gateways reuse ids across * separate assistant turns even though the wire protocol requires transcript- * wide uniqueness. */ export declare function ensureUniqueToolCallIds(calls: readonly NativeToolCall[], reservedIds?: ReadonlySet): NativeToolCall[]; /** * History copy of toolCalls: slim large write payloads so RAM and API * re-sends do not retain full file bodies (tools already ran from live args). */ export declare function slimNativeToolCallsForHistory(toolCalls: readonly NativeToolCall[]): NativeToolCall[]; /** Append assistant turn that requested tools (must precede tool results). */ export declare function appendAssistantWithTools(messages: ChatMessage[], text: string, toolCalls: NativeToolCall[], /** * Signed reasoning that must be replayed with this turn. Anthropic * rejects a tool_use turn whose thinking block is missing once extended * thinking is on; other dialects ignore the field. */ reasoningBlock?: ReasoningBlock | undefined, reasoningArtifacts?: readonly ReasoningArtifact[] | undefined): void; /** Append a single tool result linked by tool_call_id. */ export declare function appendToolResult(messages: ChatMessage[], toolCallId: string, content: string, name?: string, ok?: boolean): void; /** * Whether the message list would orphan a tool result (result without a * preceding assistant toolCalls entry that owns the id). */ export declare function hasOrphanToolMessages(messages: ChatMessage[]): boolean; /** Ids on the last assistant toolCalls message that lack a following tool result. */ export declare function missingToolResultIds(messages: ChatMessage[]): string[]; /** * Append synthetic failed tool results for any assistant toolCalls ids that * still lack a role:tool reply (deferred, cancelled, sliced, abort). */ export declare function fillMissingToolResults(messages: ChatMessage[], toolCalls: NativeToolCall[], reason?: string): number; /** * True when every id on every assistant toolCalls has a matching tool result * later in the list (no missing pairs). Used by tests and diagnostics. */ export declare function allToolCallsHaveResults(messages: ChatMessage[]): boolean; /** * When compacting, never leave role:tool without its assistant toolCalls. * Expand a keep-window start so tool pairs stay intact. */ export declare function expandKeepStartForToolPairs(messages: ChatMessage[], keepStart: number): number; /** * Validate native assistant/tool groups immediately before provider dispatch. * Every tool result must belong to the currently open assistant group, ids are * unique, and no non-tool message may begin until the whole group is closed. */ export declare function validateToolProtocol(messages: readonly ChatMessage[]): string[]; export declare function assertValidToolProtocol(messages: readonly ChatMessage[]): void; /** * Marker prefix for history-repair tool bodies. Detected by * {@link isProtocolPlaceholderOutput} so governors do not treat these as live work. * Keep stable; change wording below freely. */ export declare const PROTOCOL_PLACEHOLDER_MARKER = "[context-note]"; /** * Neutral pairing placeholder when a tool result is missing from history. * * Must stay boring: no "synthetic", "closure", "interrupted", "after resume", * "exit=130", "history-repair", or "tools are broken" — those phrases make * models invent "platform artifact" stories and re-run tools that already * succeeded in the live transcript. */ export declare function formatProtocolPlaceholder(name: string, id: string): string; /** * Heal broken assistant/tool pairing so a resume ("continue") never dies on * `invalid native tool protocol` after a mid-turn abort, partial stream, or * corrupted history reload. * * - Missing tool results for open assistant toolCalls → quiet ok placeholders * - Orphan tool results (no open call id) → dropped * - Non-tool message while results pending → close the group first * * Mutates `messages` in place when repairs are needed. Returns repair count. */ export declare function repairToolProtocol(messages: ChatMessage[]): number;