@xsai/tool 0.3.0-beta.2 → 0.3.0-beta.3
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 +11 -5
- package/dist/index.js +20 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ToolExecuteOptions, ToolExecuteResult, Tool } from '@xsai/shared-chat';
|
|
2
|
-
import { Schema, InferIn } from 'xsschema';
|
|
2
|
+
import { JsonSchema, Schema, InferIn } from 'xsschema';
|
|
3
|
+
|
|
4
|
+
interface RawToolOptions<T = unknown> {
|
|
5
|
+
description?: string;
|
|
6
|
+
execute: (input: T, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult;
|
|
7
|
+
name: string;
|
|
8
|
+
parameters: JsonSchema;
|
|
9
|
+
}
|
|
10
|
+
declare const rawTool: <T = unknown>({ description, execute, name, parameters }: RawToolOptions<T>) => Tool;
|
|
3
11
|
|
|
4
12
|
interface ToolOptions<T extends Schema> {
|
|
5
13
|
description?: string;
|
|
@@ -7,8 +15,6 @@ interface ToolOptions<T extends Schema> {
|
|
|
7
15
|
name: string;
|
|
8
16
|
parameters: T;
|
|
9
17
|
}
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
declare const tool: <T extends Schema>(options: ToolOptions<T>) => Promise<ToolResult>;
|
|
18
|
+
declare const tool: <T extends Schema>({ description, execute, name, parameters }: ToolOptions<T>) => Promise<Tool>;
|
|
13
19
|
|
|
14
|
-
export { type
|
|
20
|
+
export { type RawToolOptions, type ToolOptions, rawTool, tool };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { toJsonSchema } from 'xsschema';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const rawTool = ({ description, execute, name, parameters }) => ({
|
|
4
|
+
execute,
|
|
5
|
+
function: {
|
|
6
|
+
description,
|
|
7
|
+
name,
|
|
8
|
+
parameters: {
|
|
9
|
+
...parameters,
|
|
10
|
+
additionalProperties: false
|
|
11
|
+
},
|
|
12
|
+
strict: true
|
|
13
|
+
},
|
|
14
|
+
type: "function"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const tool = async ({ description, execute, name, parameters }) => {
|
|
18
|
+
const schema = await toJsonSchema(parameters);
|
|
5
19
|
return {
|
|
6
|
-
execute
|
|
20
|
+
execute,
|
|
7
21
|
function: {
|
|
8
|
-
description
|
|
9
|
-
name
|
|
22
|
+
description,
|
|
23
|
+
name,
|
|
10
24
|
parameters: {
|
|
11
25
|
...schema,
|
|
12
26
|
additionalProperties: false
|
|
@@ -17,4 +31,4 @@ const tool = async (options) => {
|
|
|
17
31
|
};
|
|
18
32
|
};
|
|
19
33
|
|
|
20
|
-
export { tool };
|
|
34
|
+
export { rawTool, tool };
|