/** * Killable registry of in-flight tool executions for one agent run. * * The agent loop hands every `tool.execute()` a run-level abort signal, which * makes whole-turn cancellation the only kill path. This registry adds a * per-call controller chained from the run signal so a single hung/long-running * tool call can be aborted on its own (`stopToolCall`) while its siblings keep * running and the agent loop continues the turn. * * Lifecycle: * - `register()` is called by the tool executor right before execution and * returns a handle carrying the per-call abort signal. * - `settle()` is called by the executor when the call finishes (success or * error) — it removes the entry and resolves the handle's `settled` promise, * which is what `stop()` awaits. * - `stop()` marks a user-initiated stop (so the caught abort error is * replaced by the synthesized user-stop tool result), aborts only the * targeted call's controller, and resolves once the call settles. * * Chaining: when the run-level signal aborts (turn cancel), every per-call * controller aborts too, so existing whole-turn cancel behavior is preserved. */ /** Default reason recorded on the handle when the caller passes none. */ export declare const DEFAULT_USER_STOP_REASON = "stopped by user"; /** * Exactly-matching synthesized toolResult content per the `stop_tool_call` * wire contract. The wire tool_result frame carries `stoppedByUser: true`. */ export declare const USER_STOP_TOOL_RESULT_TEXT = "Tool call stopped by user (was running too long)"; /** Handle for one in-flight tool call execution. */ export interface InFlightToolCallHandle { readonly toolCallId: string; readonly toolName: string; /** Per-call abort signal source. `controller.signal` is what tools receive. */ readonly controller: AbortController; /** Resolves when the executor settles this call (success or error). */ readonly settled: Promise; /** Set true when a user-initiated stop targets this call. */ userStopRequested: boolean; /** Reason supplied by the caller of `stop()` (defaults to "stopped by user"). */ userStopReason?: string; /** Resolve the `settled` promise. Called by the executor, not by callers. */ settle(): void; } /** * Per-run killable registry of in-flight tool executions. * Keyed by toolCallId; one Agent owns one registry per run. */ export declare class ToolCallRegistry { private readonly calls; /** * Register an in-flight call and return its handle. The returned * controller's signal aborts when this call is stopped individually OR * when the run-level signal aborts (turn cancel propagates). */ register(toolCallId: string, toolName: string, runSignal?: AbortSignal): InFlightToolCallHandle; /** Look up an in-flight call by id. Undefined for unknown/finished ids. */ get(toolCallId: string): InFlightToolCallHandle | undefined; /** * Mark a user-initiated stop and abort only this call's controller. * Returns false for unknown/finished ids (no-op). Idempotent: a second * stop for the same id keeps the first marker and reason. */ markUserStop(toolCallId: string, reason?: string): boolean; /** * Abort only the targeted call and resolve once it settles. * Returns false for unknown/finished ids (no-op). */ stop(toolCallId: string, reason?: string): Promise; /** Settle an in-flight call. Called by the executor when execution ends. */ settle(toolCallId: string): void; /** Settle and drop every tracked call. Called when a run starts/ends. */ clear(): void; } //# sourceMappingURL=tool-call-registry.d.ts.map