@xsai/tool 0.2.0 → 0.2.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 +5 -7
- package/dist/index.js +16 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { ToolExecuteOptions, ToolExecuteResult, Tool } from '@xsai/shared-chat';
|
|
2
|
-
import { Schema, InferIn
|
|
2
|
+
import { Schema, InferIn } from 'xsschema';
|
|
3
3
|
|
|
4
|
-
interface ToolOptions<
|
|
4
|
+
interface ToolOptions<T extends Schema> {
|
|
5
5
|
description?: string;
|
|
6
|
-
execute: (input: InferIn<
|
|
6
|
+
execute: (input: InferIn<T>, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult;
|
|
7
7
|
name: string;
|
|
8
|
-
parameters:
|
|
9
|
-
returns?: T2;
|
|
10
|
-
strict?: boolean;
|
|
8
|
+
parameters: T;
|
|
11
9
|
}
|
|
12
10
|
interface ToolResult extends Tool {
|
|
13
11
|
}
|
|
14
|
-
declare const tool: <
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 };
|