import type { $ZodObject, $ZodShape, $ZodType, infer as zodInfer } from 'zod/v4/core'; import { type Tool, type ToolExecuteContext, type ToolWithExecute, type ToolWithGenerator, type ManualTool, type NextTurnParamsFunctions, type ToolApprovalCheck } from "./tool-types.js"; /** * Configuration for a regular tool with outputSchema */ type RegularToolConfigWithOutput, TOutput extends $ZodType, TContext extends Record = Record, TName extends string = string> = { name: TName; description?: string; inputSchema: TInput; outputSchema: TOutput; eventSchema?: undefined; /** Zod schema declaring the context data this tool needs */ contextSchema?: $ZodObject<$ZodShape>; nextTurnParams?: NextTurnParamsFunctions>; requireApproval?: boolean | ToolApprovalCheck>; execute: (params: zodInfer, context?: ToolExecuteContext) => Promise> | zodInfer; }; /** * Configuration for a regular tool without outputSchema (infers return type from execute) */ type RegularToolConfigWithoutOutput, TReturn, TContext extends Record = Record, TName extends string = string> = { name: TName; description?: string; inputSchema: TInput; outputSchema?: undefined; eventSchema?: undefined; /** Zod schema declaring the context data this tool needs */ contextSchema?: $ZodObject<$ZodShape>; nextTurnParams?: NextTurnParamsFunctions>; requireApproval?: boolean | ToolApprovalCheck>; execute: (params: zodInfer, context?: ToolExecuteContext) => Promise | TReturn; }; /** * Configuration for a generator tool (with eventSchema) */ type GeneratorToolConfig, TEvent extends $ZodType, TOutput extends $ZodType, TContext extends Record = Record, TName extends string = string> = { name: TName; description?: string; inputSchema: TInput; eventSchema: TEvent; outputSchema: TOutput; /** Zod schema declaring the context data this tool needs */ contextSchema?: $ZodObject<$ZodShape>; nextTurnParams?: NextTurnParamsFunctions>; requireApproval?: boolean | ToolApprovalCheck>; execute: (params: zodInfer, context?: ToolExecuteContext) => AsyncGenerator | zodInfer>; }; /** * Configuration for a manual tool (execute: false, no eventSchema or outputSchema) */ type ManualToolConfig> = { name: string; description?: string; inputSchema: TInput; /** Zod schema declaring the context data this tool needs */ contextSchema?: $ZodObject<$ZodShape>; nextTurnParams?: NextTurnParamsFunctions>; requireApproval?: boolean | ToolApprovalCheck>; execute: false; }; /** * Loose config type for the `tool()` overload. * Accepts any valid tool config while typing `ctx.shared` from TShared. */ type ToolConfigWithSharedContext> = { name: string; description?: string; inputSchema: $ZodObject<$ZodShape>; outputSchema?: $ZodType; eventSchema?: $ZodType; contextSchema?: $ZodObject<$ZodShape>; nextTurnParams?: NextTurnParamsFunctions>; requireApproval?: boolean | ToolApprovalCheck>; execute: ((params: Record, context?: ToolExecuteContext, TShared>) => unknown) | ((params: Record, context?: ToolExecuteContext, TShared>) => AsyncGenerator) | false; }; /** * Creates a tool with full type inference from Zod schemas. * * The tool type is automatically determined based on the configuration: * - **Generator tool**: When `eventSchema` is provided * - **Regular tool**: When `execute` is a function (no `eventSchema`) * - **Manual tool**: When `execute: false` is set * * Shared context typing: Pass a type parameter to type `ctx.shared` * in the execute callback. Runtime validation happens at callModel * via `sharedContextSchema`. * * @example Regular tool with typed shared context: * ```typescript * type SharedCtx = z.infer; * * const execTool = tool({ * name: "sandbox_exec", * inputSchema: z.object({ command: z.string() }), * execute: async (params, ctx) => { * ctx?.shared._sessionId; // string | undefined * return { output: '...' }; * }, * }); * ``` */ export declare function tool, TEvent extends $ZodType, TOutput extends $ZodType, TContext extends Record = Record, TName extends string = string>(config: GeneratorToolConfig): ToolWithGenerator; export declare function tool>(config: ManualToolConfig): ManualTool; export declare function tool, TOutput extends $ZodType, TContext extends Record = Record, TName extends string = string>(config: RegularToolConfigWithOutput): ToolWithExecute; export declare function tool, TReturn, TContext extends Record = Record, TName extends string = string>(config: RegularToolConfigWithoutOutput): ToolWithExecute, TContext>; export declare function tool>(config: ToolConfigWithSharedContext): Tool; export {}; //# sourceMappingURL=tool.d.ts.map