@xsai/tool 0.1.3 → 0.2.0-beta.2
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 +7 -6
- package/dist/index.js +7 -7
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ToolExecuteOptions, Tool } from '@xsai/shared-chat';
|
|
2
|
-
import { Schema, InferIn } from 'xsschema';
|
|
1
|
+
import { ToolExecuteOptions, ToolExecuteResult, Tool } from '@xsai/shared-chat';
|
|
2
|
+
import { Schema, InferIn, Infer } from 'xsschema';
|
|
3
3
|
|
|
4
|
-
interface ToolOptions<
|
|
4
|
+
interface ToolOptions<T1 extends Schema, T2 extends Schema | undefined = undefined> {
|
|
5
5
|
description?: string;
|
|
6
|
-
execute: (input: InferIn<
|
|
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;
|
|
7
7
|
name: string;
|
|
8
|
-
parameters:
|
|
8
|
+
parameters: T1;
|
|
9
|
+
returns?: T2;
|
|
9
10
|
strict?: boolean;
|
|
10
11
|
}
|
|
11
12
|
interface ToolResult extends Tool {
|
|
12
13
|
}
|
|
13
|
-
declare const tool: <
|
|
14
|
+
declare const tool: <T1 extends Schema, T2 extends Schema | undefined = undefined>(options: ToolOptions<T1, T2>) => Promise<ToolResult>;
|
|
14
15
|
|
|
15
16
|
export { type ToolOptions, type ToolResult, tool };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { toJsonSchema } from 'xsschema';
|
|
2
|
+
|
|
3
|
+
const tool = async (options) => ({
|
|
4
4
|
execute: options.execute,
|
|
5
5
|
function: {
|
|
6
6
|
description: options.description,
|
|
7
7
|
name: options.name,
|
|
8
|
-
parameters: await
|
|
8
|
+
parameters: await toJsonSchema(options.parameters),
|
|
9
|
+
returns: options.returns ? await toJsonSchema(options.returns) : void 0,
|
|
9
10
|
strict: options.strict
|
|
10
11
|
},
|
|
11
12
|
type: "function"
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
14
|
+
|
|
15
|
+
export { tool };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/tool",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0-beta.2",
|
|
5
5
|
"description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"xsschema": ""
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"valibot": "^1.0.0
|
|
37
|
+
"valibot": "^1.0.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
40
|
+
"build": "pkgroll",
|
|
41
41
|
"test": "vitest run",
|
|
42
42
|
"test:watch": "vitest"
|
|
43
43
|
},
|