import { z, ZodRawShape } from "zod"; import { Message } from "@langchain/langgraph-sdk"; import { ToolRenderData } from "./ToolUI.js"; import { HumanInTheLoopDecision, InterruptResponse as HumanInTheLoopResponse } from "../humanInTheLoop.js"; export interface UnionTool { name: string; description: string; parameters: Args; /** 是否直接返回工具结果,而不是通过消息返回 */ returnDirect?: boolean; execute?: ToolCallback; /** 工具执行成功后触发的附加消息 */ callbackMessage?: (result: CallToolResult) => Message[]; handler?: (args: z.infer>, context?: any) => ResponseType | Promise; render?: (tool: ToolRenderData>, ResponseType>) => Child; onlyRender?: boolean; /** 只允许指定的 agent 使用该工具,如果未指定,则所有 agent 都可以使用 */ allowAgent?: string[]; /** 只允许指定的 Graph 使用该工具 */ allowGraph?: string[]; /** 是否是纯净的 json schema 参数,而不是 zod 参数 */ isPureParams?: boolean; } export type ToolCallback = (args: z.infer>, context?: any) => CallToolResult | Promise; export type CallToolResult = string | { type: "text"; text: string; }[] | HumanInTheLoopDecision | HumanInTheLoopResponse; /** 用于格式校验 */ export declare const createTool: (tool: UnionTool) => UnionTool; /** * create Type Safe Tool with zod and UI Render Feature */ export declare const createUITool: (tool: UnionTool) => UnionTool; export declare const createRenderUITool: (tool: UnionTool) => UnionTool; export declare const createInteractiveUITool: (tool: UnionTool) => UnionTool; export declare const createJSONDefineTool: (tool: UnionTool) => { name: string; description: string; parameters: Args | ({ anyOf: import("zod-to-json-schema").JsonSchema7DateType[]; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | ({ type: "object" | "array"; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | ({ type: ("string" | "number" | "boolean" | "null" | "integer") | ("string" | "number" | "boolean" | "null" | "integer")[]; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | ({ anyOf: import("zod-to-json-schema").JsonSchema7Type[]; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | (import("zod-to-json-schema").JsonSchema7UndefinedType & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | (import("zod-to-json-schema").JsonSchema7AnyType & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | ({ anyOf: [import("zod-to-json-schema").JsonSchema7Type, import("zod-to-json-schema").JsonSchema7NullType]; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | ({ type: [string, "null"]; } & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }) | (import("zod-to-json-schema").JsonSchema7AllOfType & { title?: string; default?: any; description?: string; markdownDescription?: string; } & { $schema?: string | undefined; definitions?: { [key: string]: import("zod-to-json-schema").JsonSchema7Type; } | undefined; }); };