import { type ToolResultMessage } from "@earendil-works/pi-ai"; import type { AgentToolCall, AgentToolResult } from "../../types.ts"; import { type Context } from "../context.ts"; import type { JsonValue } from "../session/types.ts"; import type { AgentHarnessTool, AgentHarnessToolInvocation, AgentHarnessToolUpdateCallback } from "../types.ts"; import type { Gate } from "./effect-gate.ts"; /** A tool call whose tool exists and whose prepared arguments passed validation. */ export interface PreparedToolCall { toolCall: AgentToolCall; tool: AgentHarnessTool; args: Record; } /** Synthetic result produced without crossing the external tool-effect boundary. */ export interface ImmediateToolOutcome { kind: "immediate"; toolCall: AgentToolCall; result: AgentToolResult; isError: true; terminate: boolean; } /** Aggregated decision from the before-tool hook pipeline. */ export interface BeforeToolDecision { args?: Record; block?: { reason: string; terminate?: boolean; }; } /** A prepared call cleared for durable intent publication and execution. */ export interface ClearedToolCall { toolCall: AgentToolCall; tool: AgentHarnessTool; args: Record; } /** Raw phase-two tool output before after-tool patching. */ export interface ExecutedToolCall { result: AgentToolResult; isError: boolean; } /** Aggregated patch from the after-tool hook pipeline. */ export interface AfterToolPatch { content?: AgentToolResult["content"]; details?: JsonValue; isError?: boolean; usage?: AgentToolResult["usage"]; terminate?: boolean; } /** Final tool output ready to become a durable tool-result message. */ export interface FinalizedToolCall { toolCall: AgentToolCall; result: AgentToolResult; isError: boolean; terminate: boolean; } /** Resolve a tool, apply its deterministic argument preparation, and validate the result. */ export declare function prepareToolCall(call: AgentToolCall, tools: AgentHarnessTool[]): PreparedToolCall | ImmediateToolOutcome; /** Apply an explicit hook decision and revalidate replacement arguments. */ export declare function applyBeforeToolDecision(prepared: PreparedToolCall, decision: BeforeToolDecision | undefined): ClearedToolCall | ImmediateToolOutcome; /** Execute one cleared external tool effect, converting expected tool throws to error output. */ export declare function executeToolCall(call: ClearedToolCall, gate: Gate, onUpdate: AgentHarnessToolUpdateCallback, toolContext: TContext, invocation: AgentHarnessToolInvocation, context: Context): Promise; /** Apply an after-tool patch field by field. */ export declare function finalizeToolCall(call: ClearedToolCall, executed: ExecutedToolCall, patch: AfterToolPatch | undefined): FinalizedToolCall; /** Reconstruct the canonical tool result represented by a staged transcript message. */ export declare function toolResultFromMessage(message: ToolResultMessage, terminate: boolean): AgentToolResult; /** Convert finalized tool output to the provider-facing transcript message. */ export declare function createToolResultMessage(call: FinalizedToolCall): ToolResultMessage; //# sourceMappingURL=tools.d.ts.map