diff --git a/packages/tool/src/index.ts b/packages/tool/src/index.ts index 4078979..177a741 100644 --- a/packages/tool/src/index.ts +++ b/packages/tool/src/index.ts @@ -1,5 +1,5 @@ import type { Tool, ToolExecuteOptions, ToolExecuteResult } from '@xsai/shared-chat' -import type { Infer, InferIn, Schema } from 'xsschema' +import type { Infer, InferIn, JsonSchema, Schema } from 'xsschema' import { toJsonSchema } from 'xsschema' @@ -13,19 +13,25 @@ export interface ToolOptions(options: ToolOptions): Promise => ({ - execute: options.execute, - function: { - description: options.description, - name: options.name, - parameters: await toJsonSchema(options.parameters) as Record, - returns: options.returns ? (await toJsonSchema(options.returns)) as Record : undefined, - strict: options.strict, - }, - type: 'function', -}) +export const tool = async (options: ToolOptions): Promise => { + const schema = await toJsonSchema(options.parameters) + + return { + execute: options.execute, + function: { + description: options.description, + name: options.name, + parameters: { + ...schema, + additionalProperties: false, + } satisfies JsonSchema, + returns: options.returns ? (await toJsonSchema(options.returns)) as Record : undefined, + strict: true, + }, + type: 'function', + } +}