@xsai/shared-chat 0.3.5 → 0.4.0-beta.10
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 +78 -58
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,88 @@
|
|
|
1
|
-
import { CommonRequestOptions } from '@xsai/shared';
|
|
1
|
+
import { WithUnknown, CommonRequestOptions } from '@xsai/shared';
|
|
2
2
|
|
|
3
3
|
type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | (string & {});
|
|
4
4
|
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
interface AudioPart extends CommonPart<'input_audio'> {
|
|
13
|
-
input_audio: AudioBase64;
|
|
14
|
-
}
|
|
15
|
-
interface CommonPart<T extends string> {
|
|
16
|
-
type: T;
|
|
5
|
+
interface AudioContentPart {
|
|
6
|
+
input_audio: {
|
|
7
|
+
data: string;
|
|
8
|
+
format: 'mp3' | 'wav';
|
|
9
|
+
};
|
|
10
|
+
type: 'input_audio';
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
/** @internal */
|
|
13
|
+
type CommonContentPart = AudioContentPart | FileContentPart | ImageContentPart | TextContentPart;
|
|
14
|
+
interface FileContentPart {
|
|
15
|
+
file: {
|
|
16
|
+
file_data?: string;
|
|
17
|
+
file_id?: string;
|
|
18
|
+
filename?: string;
|
|
19
|
+
};
|
|
20
|
+
type: 'file';
|
|
20
21
|
}
|
|
21
|
-
interface
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Either a URL of the image or the base64 encoded image data.
|
|
28
|
-
*/
|
|
29
|
-
url: string;
|
|
22
|
+
interface ImageContentPart {
|
|
23
|
+
image_url: {
|
|
24
|
+
detail?: 'auto' | 'high' | 'low';
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
type: 'image_url';
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
interface RefusalPart extends CommonPart<'refusal'> {
|
|
29
|
+
interface RefusalContentPart {
|
|
33
30
|
refusal: string;
|
|
31
|
+
type: 'refusal';
|
|
34
32
|
}
|
|
35
|
-
interface
|
|
33
|
+
interface TextContentPart {
|
|
36
34
|
text: string;
|
|
35
|
+
type: 'text';
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
interface
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
interface ToolCall {
|
|
39
|
+
function: ToolCallFunction | ToolCallFunctionWithoutArguments | ToolCallFunctionWithoutName;
|
|
40
|
+
id: string;
|
|
41
|
+
type: 'function';
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
interface ToolCallFunction {
|
|
44
|
+
arguments: string;
|
|
45
|
+
name: string;
|
|
46
46
|
}
|
|
47
|
-
interface
|
|
48
|
-
|
|
47
|
+
interface ToolCallFunctionWithoutArguments {
|
|
48
|
+
arguments?: never;
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
interface ToolCallFunctionWithoutName {
|
|
52
|
+
arguments: string;
|
|
53
|
+
name?: never;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AssistantMessage {
|
|
57
|
+
content?: (RefusalContentPart | TextContentPart)[] | string;
|
|
49
58
|
name?: string;
|
|
50
|
-
|
|
59
|
+
refusal?: string;
|
|
60
|
+
role: 'assistant';
|
|
61
|
+
tool_calls?: ToolCall[];
|
|
51
62
|
}
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
interface DeveloperMessage {
|
|
64
|
+
content: string | TextContentPart[];
|
|
65
|
+
name?: string;
|
|
66
|
+
/** @remarks Before using, confirm that your model supports this. */
|
|
67
|
+
role: 'developer';
|
|
54
68
|
}
|
|
55
|
-
type
|
|
56
|
-
interface
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
id: string;
|
|
62
|
-
index: number;
|
|
63
|
-
type: 'function';
|
|
69
|
+
type Message = AssistantMessage | DeveloperMessage | SystemMessage | ToolMessage | UserMessage;
|
|
70
|
+
interface SystemMessage {
|
|
71
|
+
content: string | TextContentPart[];
|
|
72
|
+
name?: string;
|
|
73
|
+
role: 'system';
|
|
64
74
|
}
|
|
65
|
-
interface ToolMessage
|
|
75
|
+
interface ToolMessage {
|
|
76
|
+
/** @remarks considering the support of ecosystems (such as MCP), we have relaxed this type. */
|
|
77
|
+
content: CommonContentPart[] | string;
|
|
78
|
+
role: 'tool';
|
|
66
79
|
tool_call_id: string;
|
|
67
80
|
}
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
interface UserMessage {
|
|
82
|
+
content: CommonContentPart[] | string;
|
|
83
|
+
name?: string;
|
|
84
|
+
role: 'user';
|
|
70
85
|
}
|
|
71
|
-
type UserMessagePart = AudioPart | ImagePart | TextPart;
|
|
72
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>;
|
|
73
86
|
|
|
74
87
|
interface CompletionToolCall {
|
|
75
88
|
args: string;
|
|
@@ -79,7 +92,7 @@ interface CompletionToolCall {
|
|
|
79
92
|
}
|
|
80
93
|
interface CompletionToolResult {
|
|
81
94
|
args: Record<string, unknown>;
|
|
82
|
-
result:
|
|
95
|
+
result: ToolMessage['content'];
|
|
83
96
|
toolCallId: string;
|
|
84
97
|
toolName: string;
|
|
85
98
|
}
|
|
@@ -119,16 +132,22 @@ type CompletionStep<T extends boolean = false> = (T extends true ? {
|
|
|
119
132
|
};
|
|
120
133
|
type CompletionStepType = 'continue' | 'done' | 'initial' | 'tool-result';
|
|
121
134
|
|
|
122
|
-
type ToolChoice =
|
|
135
|
+
type ToolChoice = AllowedTools | ToolChoiceMode | ToolChoiceTool;
|
|
136
|
+
interface AllowedTools {
|
|
137
|
+
mode: 'auto' | 'required';
|
|
138
|
+
tools: ToolChoiceTool[];
|
|
139
|
+
type: 'allowed_tools';
|
|
140
|
+
}
|
|
141
|
+
type ToolChoiceMode = 'auto' | 'none' | 'required';
|
|
142
|
+
interface ToolChoiceTool {
|
|
123
143
|
function: {
|
|
124
144
|
name: string;
|
|
125
145
|
};
|
|
126
146
|
type: 'function';
|
|
127
|
-
}
|
|
147
|
+
}
|
|
128
148
|
|
|
129
149
|
/** @see {@link https://platform.openai.com/docs/api-reference/chat/create} */
|
|
130
150
|
interface ChatOptions extends CommonRequestOptions {
|
|
131
|
-
[key: string]: unknown;
|
|
132
151
|
/**
|
|
133
152
|
* number between -2.0 and 2.0.
|
|
134
153
|
* @default 0
|
|
@@ -153,7 +172,7 @@ interface ChatOptions extends CommonRequestOptions {
|
|
|
153
172
|
/** @default 1 */
|
|
154
173
|
topP?: number;
|
|
155
174
|
}
|
|
156
|
-
declare const chat: <T extends ChatOptions
|
|
175
|
+
declare const chat: <T extends WithUnknown<ChatOptions>>(options: T) => Promise<Response>;
|
|
157
176
|
|
|
158
177
|
interface DetermineStepTypeOptions {
|
|
159
178
|
finishReason: FinishReason;
|
|
@@ -177,4 +196,5 @@ interface ExecuteToolResult {
|
|
|
177
196
|
}
|
|
178
197
|
declare const executeTool: ({ abortSignal, messages, toolCall, tools }: ExecuteToolOptions) => Promise<ExecuteToolResult>;
|
|
179
198
|
|
|
180
|
-
export {
|
|
199
|
+
export { chat, determineStepType, executeTool };
|
|
200
|
+
export type { AssistantMessage, AudioContentPart, ChatOptions, CommonContentPart, CompletionStep, CompletionStepType, CompletionToolCall, CompletionToolResult, DetermineStepTypeOptions, DeveloperMessage, ExecuteToolOptions, ExecuteToolResult, FileContentPart, FinishReason, ImageContentPart, Message, RefusalContentPart, SystemMessage, TextContentPart, Tool, ToolCall, ToolChoice, ToolExecuteOptions, ToolExecuteResult, ToolMessage, Usage, UserMessage };
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const wrapToolResult = (result) => {
|
|
|
35
35
|
if (typeof result === "string")
|
|
36
36
|
return result;
|
|
37
37
|
if (Array.isArray(result)) {
|
|
38
|
-
if (result.every((item) => !!(typeof item === "object" && "type" in item && ["
|
|
38
|
+
if (result.every((item) => !!(typeof item === "object" && "type" in item && ["file", "image_url", "input_audio", "text"].includes(item.type)))) {
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
41
41
|
}
|
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.4.0-beta.10",
|
|
5
5
|
"description": "extra-small AI SDK.",
|
|
6
6
|
"author": "Moeru AI",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xsai/shared": "~0.
|
|
32
|
+
"@xsai/shared": "~0.4.0-beta.10"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "pkgroll"
|