import type { JSONValue } from 'ai'; import type { TurnControl } from '../../types/channel.js'; import type { RunContext } from '../../types/run-context.js'; import type { AnyTool } from '../../types/effectTool.js'; export interface ModelToolCall { toolName: string; input: unknown; toolCallId: string; } export interface ModelToolCallOutcome { result: unknown; control?: TurnControl; failed: boolean; /** * Set when the call unwound with a control-flow signal rather than a failure. Held as a * value so a parallel batch can still finalize its siblings; the dispatcher rethrows it * once the batch has settled. Never surfaced to the model. */ signal?: unknown; } export declare function executeModelToolCall(ctx: RunContext, call: ModelToolCall, localTools?: Record, durableOpts?: { callsite?: string; index?: number; }): Promise; /** * Ceiling on parallel-safe tools running at once within one model-emitted batch. * * The model's batch size must never be the concurrency policy: an unbounded * `Promise.all` lets a twelve-call response open twelve sockets, twelve * subprocesses, or twelve rate-limited vendor calls at once. * * Eight is not an arbitrary round number. Above eight-way in-process tool * concurrency the session store's optimistic-concurrency check starts rejecting * concurrent writes and surfacing `Stale write for session …` as client-visible * error parts; at eight and below it does not. Measured in * `packages/core/examples/latency-bench` — twelve unbounded calls emit four such * errors, the same twelve at a limit of eight emit none. */ export declare const DEFAULT_MAX_TOOL_CONCURRENCY = 8; export declare function dispatchModelToolCalls(ctx: RunContext, toolCalls: ModelToolCall[], localTools: Record, onEach: (args: { call: ModelToolCall; outcome: ModelToolCallOutcome; }) => void): Promise; /** * Builds the transcript-facing tool-result message. This is the transcript boundary: the * result is bounded to `maxTokens` here so the model never re-reads an unbounded payload on * every subsequent call. `ctx.tool()` and the durable journal are unaffected — they receive * the full value before this function is ever called. */ export declare function toolResultMessage(call: ModelToolCall, result: unknown, maxTokens?: number): { role: 'tool'; content: [ { type: 'tool-result'; toolCallId: string; toolName: string; output: { type: 'json'; value: JSONValue; }; } ]; };