/** * Helper for defining tools with type safety */ import type { Tool, ToolExecutionResult, ToolInputSchema } from './types.js'; /** * Options for defining a tool */ export interface DefineToolOptions { /** * Unique name for the tool */ name: string; /** * Description of what the tool does (shown to LLM) */ description: string; /** * JSON Schema for the tool's input parameters */ inputSchema: ToolInputSchema; /** * Function that executes the tool */ execute: (input: T) => Promise; /** * If true, multiple calls to this tool can execute in parallel. * When the LLM requests multiple parallel-safe tools in one response, * they will be executed concurrently using Promise.all. * Default: false (sequential execution) */ parallel?: boolean; /** * If true, this tool runs silently without spinner updates or result output. * Used for internal housekeeping tools like todo_read, suggest, etc. * Default: false (normal visibility) */ silent?: boolean; /** * If true, this tool performs no side effects (only reads data). * Read-only tools are automatically batched for parallel execution * even in a mixed batch with write tools. * Default: false */ readonly?: boolean; /** * If true, this tool is exempt from tool-loop detection (repeated identical * calls are always legitimate). Default: false. */ repeatable?: boolean; } /** * Define a tool with type-safe input handling * * @example * ```typescript * const readFile = defineTool({ * name: 'read_file', * description: 'Read the contents of a file', * inputSchema: { * type: 'object', * properties: { * path: { type: 'string', description: 'File path to read' }, * }, * required: ['path'], * }, * execute: async ({ path }) => { * const content = await fs.readFile(path, 'utf-8'); * return { success: true, result: content }; * }, * }); * ``` */ export declare function defineTool(options: DefineToolOptions): Tool; /** * Create a simple tool that returns success with a result */ export declare function createSuccessResult(result: unknown): ToolExecutionResult; /** * Create an error result for a tool */ export declare function createErrorResult(error: string | Error): ToolExecutionResult; /** * Wrap an async function to catch errors and return ToolExecutionResult */ export declare function wrapToolExecute(fn: (input: T) => Promise): (input: T) => Promise;