import type { InvokableTool, ToolContext, ToolStreamGenerator } from './tool.js'; import { Tool } from './tool.js'; import type { ToolSpec } from './types.js'; import type { JSONValue } from '../types/json.js'; import { z } from 'zod'; /** * Helper type to infer input type from Zod schema or default to never. */ type ZodInferred = TInput extends z.ZodType ? z.infer : never; /** * Configuration for creating a Zod-based tool. * * @typeParam TInput - Zod schema type for input validation * @typeParam TReturn - Return type of the callback function */ export interface ZodToolConfig { /** The name of the tool */ name: string; /** A description of what the tool does (optional) */ description?: string; /** * Zod schema for input validation and JSON schema generation. * If omitted or z.void(), the tool takes no input parameters. */ inputSchema?: TInput; /** * Callback function that implements the tool's functionality. * * @param input - Validated input matching the Zod schema * @param context - Optional execution context * @returns The result (can be a value, Promise, or AsyncGenerator) */ callback: (input: ZodInferred, context?: ToolContext) => AsyncGenerator | Promise | TReturn; } /** * Zod-based tool implementation. * Extends Tool abstract class and implements InvokableTool interface. */ export declare class ZodTool extends Tool implements InvokableTool, TReturn> { /** * Internal FunctionTool for delegating stream operations. */ private readonly _functionTool; /** * Zod schema for input validation. * Note: undefined is normalized to z.void() in constructor, so this is always defined. */ private readonly _inputSchema; /** * User callback function. */ private readonly _callback; constructor(config: ZodToolConfig); /** * The unique name of the tool. */ get name(): string; /** * Human-readable description of what the tool does. */ get description(): string; /** * OpenAPI JSON specification for the tool. */ get toolSpec(): ToolSpec; /** * Executes the tool with streaming support. * Delegates to internal FunctionTool implementation. * * @param toolContext - Context information including the tool use request and invocation state * @returns Async generator that yields ToolStreamEvents and returns a ToolResultBlock */ stream(toolContext: ToolContext): ToolStreamGenerator; /** * Invokes the tool directly with type-safe input and returns the unwrapped result. * * Unlike stream(), this method: * - Returns the raw result (not wrapped in ToolResult) * - Consumes async generators and returns only the final value * - Lets errors throw naturally (not wrapped in error ToolResult) * * @param input - The input parameters for the tool * @param context - Optional tool execution context * @returns The unwrapped result */ invoke(input: ZodInferred, context?: ToolContext): Promise; } export {}; //# sourceMappingURL=zod-tool.d.ts.map