@xsai/tool 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  import { ToolExecuteOptions, ToolExecuteResult, Tool } from '@xsai/shared-chat';
2
- import { Schema, InferIn, Infer } from 'xsschema';
2
+ import { Schema, InferIn } from 'xsschema';
3
3
 
4
- interface ToolOptions<T1 extends Schema, T2 extends Schema | undefined = undefined> {
4
+ interface ToolOptions<T extends Schema> {
5
5
  description?: string;
6
- execute: (input: InferIn<T1>, options: ToolExecuteOptions) => T2 extends Schema ? Infer<T2> extends object ? Infer<T2> | Promise<Infer<T2>> : Promise<ToolExecuteResult> | ToolExecuteResult : Promise<ToolExecuteResult> | ToolExecuteResult;
6
+ execute: (input: InferIn<T>, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult;
7
7
  name: string;
8
- parameters: T1;
9
- returns?: T2;
10
- strict?: boolean;
8
+ parameters: T;
11
9
  }
12
10
  interface ToolResult extends Tool {
13
11
  }
14
- declare const tool: <T1 extends Schema, T2 extends Schema | undefined = undefined>(options: ToolOptions<T1, T2>) => Promise<ToolResult>;
12
+ declare const tool: <T extends Schema>(options: ToolOptions<T>) => Promise<ToolResult>;
15
13
 
16
14
  export { type ToolOptions, type ToolResult, tool };
package/dist/index.js CHANGED
@@ -1,15 +1,20 @@
1
1
  import { toJsonSchema } from 'xsschema';
2
2
 
3
- const tool = async (options) => ({
4
- execute: options.execute,
5
- function: {
6
- description: options.description,
7
- name: options.name,
8
- parameters: await toJsonSchema(options.parameters),
9
- returns: options.returns ? await toJsonSchema(options.returns) : void 0,
10
- strict: options.strict
11
- },
12
- type: "function"
13
- });
3
+ const tool = async (options) => {
4
+ const schema = await toJsonSchema(options.parameters);
5
+ return {
6
+ execute: options.execute,
7
+ function: {
8
+ description: options.description,
9
+ name: options.name,
10
+ parameters: {
11
+ ...schema,
12
+ additionalProperties: false
13
+ },
14
+ strict: true
15
+ },
16
+ type: "function"
17
+ };
18
+ };
14
19
 
15
20
  export { tool };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/tool",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",