@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 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
- interface ToolResult extends Tool {
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 ToolOptions, type ToolResult, tool };
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 tool = async (options) => {
4
- const schema = await toJsonSchema(options.parameters);
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: options.execute,
20
+ execute,
7
21
  function: {
8
- description: options.description,
9
- name: options.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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/tool",
3
3
  "type": "module",
4
- "version": "0.3.0-beta.2",
4
+ "version": "0.3.0-beta.3",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",