From 5b86eece82a944bc3004b96c1ea25dfa3af24bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Wed, 7 May 2025 14:55:26 +0800 Subject: [PATCH] fix(tool)!: set additional properties to false (#146) --- packages/tool/src/index.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) 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', + } +}