import type { ContentPart, Message, ToolContext, ToolDefinition, ToolOutput } from '../types/messages.js'; import type { ToolExecutionResult } from '../types/agent.js'; /** How a tool built with `tool()` runs: once, with `execute`, or reporting progress, with `stream`. */ export type ToolBody = { /** Runs the tool. In an agent, `context` says who the run is for and carries its signal and store. */ execute: (args: TArgs, context: ToolContext) => Promise | unknown; stream?: never; } | { /** * Runs the tool, yielding progress while it works and returning the result. See * `ToolDefinition.stream`. */ stream: (args: TArgs, context: ToolContext) => AsyncGenerator; execute?: never; }; /** * Defines a tool the model can call, typing its arguments. A tool given `stream` gets an `execute` * too, which runs the stream and reports each yield to `context.progress`, so it works wherever a * tool is executed. */ export declare function tool = Record>(definition: { name: string; description: string; parameters: Record; /** What the tool does to the world, for a permission policy; see `ToolDefinition.capabilities`. */ capabilities?: readonly string[] | ((args: TArgs) => readonly string[]); /** Loads the tool only once the model finds it; see `ToolDefinition.deferred`. */ deferred?: boolean; } & ToolBody): ToolDefinition; /** * Builds a tool's result as content: text, images, and asset references, in order. A string becomes * a text part. Returned from `execute`, it is sent as the tool message itself, so an image a tool * produced reaches the model as an image or as a reference rather than as base64 JSON. */ export declare function toolOutput(...content: Array): ToolOutput; /** True for a result built with `toolOutput()`. */ export declare function isToolOutput(value: unknown): value is ToolOutput; /** * What the model reads for a tool's result: the parts of a `toolOutput()`, or anything else as JSON. * An error is always JSON, as `{ error }`. */ export declare function toolMessageContent(result: ToolExecutionResult): Message['content']; /** Runs tool calls by name, reporting failures as results rather than throwing. */ export declare class ToolExecutor { private tools; constructor(tools?: ToolDefinition[]); /** Adds a tool, replacing one with the same name. Returns the executor, for chaining. */ register(toolDefinition: ToolDefinition): this; /** Whether a tool is registered. */ has(name: string): boolean; /** A registered tool, or `undefined`. */ get(name: string): ToolDefinition | undefined; /** Every registered tool. */ list(): ToolDefinition[]; /** Runs a tool. An unknown name or a thrown error comes back as a failed result. */ execute(name: string, args: Record, context?: ToolContext): Promise; }