@xsai/shared-chat 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 +5 -2
- package/dist/index.js +12 -15
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -85,11 +85,13 @@ interface CompletionToolResult {
|
|
|
85
85
|
toolName: string;
|
|
86
86
|
}
|
|
87
87
|
interface Tool {
|
|
88
|
-
execute: (input: unknown, options: ToolExecuteOptions) =>
|
|
88
|
+
execute: (input: unknown, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult;
|
|
89
89
|
function: {
|
|
90
90
|
description?: string;
|
|
91
91
|
name: string;
|
|
92
92
|
parameters: Record<string, unknown>;
|
|
93
|
+
/** @experimental */
|
|
94
|
+
returns?: Record<string, unknown>;
|
|
93
95
|
strict?: boolean;
|
|
94
96
|
};
|
|
95
97
|
type: 'function';
|
|
@@ -99,6 +101,7 @@ interface ToolExecuteOptions {
|
|
|
99
101
|
messages: Message[];
|
|
100
102
|
toolCallId: string;
|
|
101
103
|
}
|
|
104
|
+
type ToolExecuteResult = object | string | unknown[];
|
|
102
105
|
|
|
103
106
|
type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
104
107
|
function: {
|
|
@@ -163,4 +166,4 @@ interface ExecuteToolResult {
|
|
|
163
166
|
}
|
|
164
167
|
declare const executeTool: ({ abortSignal, messages, toolCall, tools }: ExecuteToolOptions) => Promise<ExecuteToolResult>;
|
|
165
168
|
|
|
166
|
-
export { type AssistantMessage, type AssistantMessagePart, type AssistantMessageResponse, type AudioBase64, type AudioPart, type ChatOptions, type CommonMessage, type CommonPart, type CompletionToolCall, type CompletionToolResult, type DetermineStepTypeOptions, type ExecuteToolOptions, type ExecuteToolResult, type FinishReason, type ImagePart, type ImageURLorBase64, type Message, type Part, type RefusalPart, type StepType, type SystemMessage, type SystemMessagePart, type TextPart, type Tool, type ToolCall, type ToolChoice, type ToolExecuteOptions, type ToolMessage, type ToolMessagePart, type Usage, type UserMessage, type UserMessagePart, chat, determineStepType, executeTool };
|
|
169
|
+
export { type AssistantMessage, type AssistantMessagePart, type AssistantMessageResponse, type AudioBase64, type AudioPart, type ChatOptions, type CommonMessage, type CommonPart, type CompletionToolCall, type CompletionToolResult, type DetermineStepTypeOptions, type ExecuteToolOptions, type ExecuteToolResult, type FinishReason, type ImagePart, type ImageURLorBase64, type Message, type Part, type RefusalPart, type StepType, type SystemMessage, type SystemMessagePart, type TextPart, type Tool, type ToolCall, type ToolChoice, type ToolExecuteOptions, type ToolExecuteResult, type ToolMessage, type ToolMessagePart, type Usage, type UserMessage, type UserMessagePart, chat, determineStepType, executeTool };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { requestURL, requestHeaders, requestBody, clean, responseCatch } from '@xsai/shared';
|
|
2
|
+
|
|
3
|
+
const chat = async (options) => (options.fetch ?? globalThis.fetch)(requestURL("chat/completions", options.baseURL), {
|
|
4
4
|
body: requestBody({
|
|
5
5
|
...options,
|
|
6
6
|
tools: options.tools?.map((tool) => ({
|
|
7
|
-
function:
|
|
7
|
+
function: clean({
|
|
8
|
+
...tool.function,
|
|
9
|
+
returns: void 0
|
|
10
|
+
}),
|
|
8
11
|
type: "function"
|
|
9
12
|
}))
|
|
10
13
|
}),
|
|
@@ -16,8 +19,7 @@ var chat = async (options) => (options.fetch ?? globalThis.fetch)(requestURL("ch
|
|
|
16
19
|
signal: options.abortSignal
|
|
17
20
|
}).then(responseCatch);
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
var determineStepType = ({ finishReason, maxSteps, stepsLength, toolCallsLength }) => {
|
|
22
|
+
const determineStepType = ({ finishReason, maxSteps, stepsLength, toolCallsLength }) => {
|
|
21
23
|
if (stepsLength === 0) {
|
|
22
24
|
return "initial";
|
|
23
25
|
} else if (stepsLength < maxSteps) {
|
|
@@ -29,8 +31,7 @@ var determineStepType = ({ finishReason, maxSteps, stepsLength, toolCallsLength
|
|
|
29
31
|
return "done";
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
var wrapToolResult = (result) => {
|
|
34
|
+
const wrapToolResult = (result) => {
|
|
34
35
|
if (typeof result === "string")
|
|
35
36
|
return result;
|
|
36
37
|
if (Array.isArray(result)) {
|
|
@@ -41,8 +42,7 @@ var wrapToolResult = (result) => {
|
|
|
41
42
|
return JSON.stringify(result);
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
var executeTool = async ({ abortSignal, messages, toolCall, tools }) => {
|
|
45
|
+
const executeTool = async ({ abortSignal, messages, toolCall, tools }) => {
|
|
46
46
|
const tool = tools?.find((tool2) => tool2.function.name === toolCall.function.name);
|
|
47
47
|
if (!tool) {
|
|
48
48
|
const availableTools = tools?.map((tool2) => tool2.function.name);
|
|
@@ -57,8 +57,5 @@ var executeTool = async ({ abortSignal, messages, toolCall, tools }) => {
|
|
|
57
57
|
}));
|
|
58
58
|
return { parsedArgs, result, toolName: toolCall.function.name };
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
determineStepType,
|
|
63
|
-
executeTool
|
|
64
|
-
};
|
|
60
|
+
|
|
61
|
+
export { chat, determineStepType, executeTool };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsai/shared-chat",
|
|
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",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@xsai/shared": ""
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "
|
|
35
|
+
"build": "pkgroll"
|
|
36
36
|
},
|
|
37
37
|
"main": "./dist/index.js",
|
|
38
38
|
"types": "./dist/index.d.ts"
|