UNPKG

@gensx/vercel-ai

Version:
1 lines 1.61 kB
{"version":3,"file":"tools.cjs","sources":["@gensx/vercel-ai/../../../../src/tools.ts"],"sourcesContent":["import type { InferToolParams, ToolBox } from \"@gensx/core\";\n\nimport { executeExternalTool } from \"@gensx/core\";\nimport { jsonSchema, type Tool } from \"ai\";\n\nimport { toJsonSchema } from \"./zod.js\";\n\n// Utility function to convert ToolBox to Vercel AI SDK ToolSet format\nexport function asToolSet(toolBox: ToolBox): Record<string, Tool> {\n return Object.entries(toolBox).reduce<Record<string, Tool>>(\n (acc, [name, toolDef]) => {\n acc[name] = {\n description: toolDef.description,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n inputSchema: jsonSchema(toJsonSchema(toolDef.params) as any),\n execute: async (args: InferToolParams<typeof toolBox, typeof name>) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return await executeExternalTool(toolBox, name, args);\n },\n };\n return acc;\n },\n {},\n );\n}\n"],"names":["jsonSchema","toJsonSchema","executeExternalTool"],"mappings":";;;;;;;;;;;;AAOA;AACM,SAAU,SAAS,CAAC,OAAgB,EAAA;AACxC,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CACnC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,KAAI;QACvB,GAAG,CAAC,IAAI,CAAC,GAAG;YACV,WAAW,EAAE,OAAO,CAAC,WAAW;;YAEhC,WAAW,EAAEA,aAAU,CAACC,gBAAY,CAAC,OAAO,CAAC,MAAM,CAAQ,CAAC;AAC5D,YAAA,OAAO,EAAE,OAAO,IAAkD,KAAI;;gBAEpE,OAAO,MAAMC,wBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;aACtD;SACF;AACD,QAAA,OAAO,GAAG;KACX,EACD,EAAE,CACH;AACH;;;;"}