import type { ActionChatUIConfig } from "../action-ui.js"; import { type ArtifactReceipt } from "../artifacts/detect.js"; import type { AgentMcpAppPayload } from "../mcp-client/app-result.js"; import type { EngineMessage, EngineToolCallPart, EngineToolResultPart } from "./engine/types.js"; import type { AgentChatEvent, AgentFileMutationProof, AgentToolInput, UnknownWriteCause } from "./types.js"; export interface ToolCallJournalEntry { key: string; tool: string; id?: string; executionStepId?: string; input?: AgentToolInput; inputFingerprint?: string; inputStoredFingerprint?: string; order: number; result?: string; /** The call failed after its side effect completed. */ isError?: true; errorCode?: string; /** The call recorded a completed side effect, its own or a nested call's. */ committed?: true; /** Exact identity of the arguments the call ran with, defaults applied. */ argumentsHash?: string; /** The call settled with an outcome it could not confirm. */ outcomeUnknown?: true; /** Why such a call's outcome is unknown, when its event recorded it. */ unknownCause?: UnknownWriteCause; artifacts?: ArtifactReceipt[]; fileMutation?: AgentFileMutationProof; mcpApp?: AgentMcpAppPayload; chatUI?: Omit; chatUIResult?: unknown; } export interface ToolCallJournal { completed: ToolCallJournalEntry[]; interrupted: ToolCallJournalEntry[]; } export declare function toolCallIdentityKey(id?: string, executionStepId?: string): string | undefined; export declare function matchToolCallResultsInHistory(history: readonly EngineMessage[]): Array<{ call: EngineToolCallPart; result: EngineToolResultPart; }>; export declare function unmatchedAmbiguousLegacyToolCallResultsInHistory(history: readonly EngineMessage[]): Array<{ result: EngineToolResultPart; candidateCalls: EngineToolCallPart[]; }>; export declare function journalEntriesRepresentedInHistory(journal: ToolCallJournal, history: readonly EngineMessage[]): Set; export declare function journalEntriesAmbiguousInHistory(journal: ToolCallJournal, history: readonly EngineMessage[]): Set; export declare function toolCallInputFingerprint(input: unknown): string; export declare function isUnavailableToolCallInput(input: unknown): boolean; export declare function isConsistentToolCallInputFingerprint(input: unknown, fingerprint: string | undefined, storedFingerprint?: string): boolean; export declare function classifyToolCallJournal(events: readonly AgentChatEvent[]): ToolCallJournal; export declare function isJournalEmpty(journal: ToolCallJournal): boolean; export type JournalCallEffect = "none" | "committed" | "unknown"; /** * A conservative legacy effect group for IDs reused across calls. This key is * only for invalidating cached reads and holding unknown writes; it does not * identify a call for replay or argument matching. */ export declare function ambiguousLegacyCallEffectKey(id: string, toolName: string): string; /** * What each call recorded having done, keyed by execution step where present * and otherwise by an unambiguous legacy provider ID. Ambiguous legacy IDs * retain a conservative effect group, separate from call identity. */ export declare function journalCallEffects(journal: ToolCallJournal, events: readonly AgentChatEvent[], history?: readonly EngineMessage[]): Map; /** * The prepared identity for each call, keyed by its execution step where * present and otherwise by an unambiguous legacy provider ID. */ export declare function journalCallIdentities(events: readonly AgentChatEvent[], history: readonly EngineMessage[]): Map; /** * The completed call a continued turn replays instead of running a call * prepared to `argumentsHash`: one that recorded a committed effect for that * exact identity, whatever raw input either call was sent with. A call that * recorded no committed effect runs fresh. A call recorded before calls had * identities is matched as it was then, by its raw input, and only for a * call prepared as a write, given in `rawWrite`: running that fresh could * repeat its effect. A legacy result already represented in history cannot * identify a new step merely because its tool and arguments match. The result * and the identity it ran with come from one `tool_done`, never joined by call * id, so a repeated id cannot attach one call's result to another's arguments. */ export declare function findReplayableJournalEntry(journal: ToolCallJournal, toolName: string, argumentsHash: string, consumedKeys?: Set, rawWrite?: { input: unknown; }, representedKeys?: ReadonlySet, executionStepId?: string, ambiguousKeys?: ReadonlySet): ToolCallJournalEntry | undefined; export declare function findAmbiguousLegacyJournalEntryForCall(journal: ToolCallJournal, ambiguousKeys: ReadonlySet, representedKeys: ReadonlySet, toolName: string, argumentsHash: string, input: unknown, consumedKeys?: ReadonlySet, includeRepresentedDuplicates?: boolean): ToolCallJournalEntry | undefined; export declare function findInterruptedJournalEntryForCall(journal: ToolCallJournal, toolName: string, argumentsHash: string | undefined, input: unknown, consumedKeys?: Set): ToolCallJournalEntry | undefined; /** * The entry with a durable step that this call's identity claims: the * earliest-started unclaimed match among the interrupted entries and the * finished ones the model never saw. A finished entry carries its own result, * so identical calls pair with identical entries in the order they started; * an interrupted one binds only when no other interrupted entry matches. */ export declare function findUnresolvedJournalStepForCall(journal: ToolCallJournal, unseenFinished: readonly ToolCallJournalEntry[], toolName: string, argumentsHash: string | undefined, input: unknown, consumedKeys?: Set): ToolCallJournalEntry | undefined; /** Whether any interrupted or unseen finished entry could name this call's step. */ export declare function hasJournalStepForCall(journal: ToolCallJournal, unseenFinished: readonly ToolCallJournalEntry[], toolName: string, argumentsHash: string | undefined, input: unknown): boolean; export declare function findInterruptedLegacyJournalEntryForCall(journal: ToolCallJournal, toolName: string, argumentsHash: string | undefined, input: unknown, history: readonly EngineMessage[], consumedKeys?: Set): { status: "none"; } | { status: "ambiguous"; } | { status: "matched"; entry: ToolCallJournalEntry; stepId: string; }; export declare function buildResumeJournalNote(journal: ToolCallJournal): string | null;