fix(tool)!: set additional properties to false (#146)
This commit is contained in:
1 parent
2138ee19c6
commit
5b86eece82
1 file changed
+19
-13
+19
-13
@@ -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<T1 extends Schema, T2 extends Schema | undefined =
|
||||
name: string
|
||||
parameters: T1
|
||||
returns?: T2
|
||||
strict?: boolean
|
||||
}
|
||||
|
||||
export interface ToolResult extends Tool {}
|
||||
|
||||
export const tool = async <T1 extends Schema, T2 extends Schema | undefined = undefined>(options: ToolOptions<T1, T2>): Promise<ToolResult> => ({
|
||||
execute: options.execute,
|
||||
function: {
|
||||
description: options.description,
|
||||
name: options.name,
|
||||
parameters: await toJsonSchema(options.parameters) as Record<string, unknown>,
|
||||
returns: options.returns ? (await toJsonSchema(options.returns)) as Record<string, unknown> : undefined,
|
||||
strict: options.strict,
|
||||
},
|
||||
type: 'function',
|
||||
})
|
||||
export const tool = async <T1 extends Schema, T2 extends Schema | undefined = undefined>(options: ToolOptions<T1, T2>): Promise<ToolResult> => {
|
||||
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<string, unknown> : undefined,
|
||||
strict: true,
|
||||
},
|
||||
type: 'function',
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user