import type { AgentPromptOptions, Tool, ToolCall, ToolCallContext } from './types.js'; /** * Detect an async generator (the value returned by `async function*` or any * object implementing the AsyncGenerator protocol). We use a structural check * because the executor may not be authored as a literal `async function*` * (e.g. wrapped or returned from a factory). */ export declare function isAsyncGenerator(value: unknown): value is AsyncGenerator; /** * Uniformly iterate a tool's `execute`, whether it returns a value, a * promise, or an async generator. * * The helper is itself an async generator: each `yield` is a preliminary * tool-update payload (only generator-style executes produce these), and the * generator's `return` value is the final tool result. * * Streaming callers iterate and emit `tool-update` chunks live as updates * arrive. Non-streaming callers iterate and discard yields, capturing only * the final return value — same tool definition works in both modes. */ export declare function executeMaybeStreaming(tool: Tool, args: Record, ctx: ToolCallContext): AsyncGenerator; /** * Structured error returned to the model when a tool call's arguments fail * the tool's `inputSchema`. Surfaced both as the `result` on `AgentStep` * and as the JSON-encoded `tool` message the next provider step receives, * so the model can correct itself on the next turn. */ export interface InvalidToolArgumentsError { error: 'invalid_arguments'; message: string; issues: Array<{ path: string; message: string; }>; } /** * Validate a tool call's arguments against the tool's `inputSchema`. On * success, the parsed value is returned — zod transforms (`.transform`, * `.default`, type coercion) are applied, so `execute` receives the * canonical shape the schema describes. On failure, a structured error * suitable for feeding back to the model is returned. */ export declare function validateToolArgs(tool: Tool, args: Record): { ok: true; value: Record; } | { ok: false; error: InvalidToolArgumentsError; }; /** * Default stringification used for the `tool` role message content when a * tool has no `toModelOutput` transform: pass through strings, JSON-encode * everything else. */ export declare function defaultStringify(value: unknown): string; /** * Convert a tool's structured `result` into the string the **model** will * see on its next step. Honors `tool.toModelOutput` when present, falling * back to {@link defaultStringify}. * * Per R6 in the ai-loop-parity plan: a throwing `toModelOutput` MUST NOT * crash the loop. We swallow the error, route it through `onError` * middleware so it stays observable, and use the default stringification * as a safety net. */ export declare function applyToModelOutput(tool: Tool, result: unknown, onError?: (err: unknown) => void | Promise): Promise; /** * Resolve `needsApproval` for a tool call, taking into account the * client-supplied `approvedToolCallIds` / `rejectedToolCallIds` lists. * * Returns: * - `'allow'` — execute the tool normally (default; also when approved) * - `'pending'` — needsApproval is truthy and the call has not been approved * - `'rejected'` — the call appears in `rejectedToolCallIds` */ export declare function evaluateApproval(tool: Tool, tc: ToolCall, options: AgentPromptOptions | undefined): Promise<'allow' | 'pending' | 'rejected'>; //# sourceMappingURL=tool-helpers.d.ts.map