@xsai/shared-chat 0.3.5 → 0.4.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 +64 -53
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,74 +2,78 @@ import { 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 AssistantMessage extends Optional<CommonMessage<'assistant', AssistantMessagePart>, 'content'> {
|
|
40
|
-
refusal?: null | string;
|
|
41
|
-
tool_calls?: ToolCall[];
|
|
42
|
-
}
|
|
43
|
-
type AssistantMessagePart = RefusalPart | TextPart;
|
|
44
|
-
interface AssistantMessageResponse extends Omit<AssistantMessage, 'content'> {
|
|
45
|
-
content?: string;
|
|
46
|
-
}
|
|
47
|
-
interface CommonMessage<T extends string, P extends Part> {
|
|
48
|
-
content: Array<P> | string;
|
|
49
|
-
name?: string;
|
|
50
|
-
role: T;
|
|
51
|
-
}
|
|
52
|
-
type Message = AssistantMessage | SystemMessage | ToolMessage | UserMessage;
|
|
53
|
-
interface SystemMessage extends CommonMessage<'system', SystemMessagePart> {
|
|
54
|
-
}
|
|
55
|
-
type SystemMessagePart = TextPart;
|
|
56
38
|
interface ToolCall {
|
|
57
39
|
function: {
|
|
58
40
|
arguments: string;
|
|
59
41
|
name: string;
|
|
60
42
|
};
|
|
61
43
|
id: string;
|
|
62
|
-
index: number;
|
|
63
44
|
type: 'function';
|
|
64
45
|
}
|
|
65
|
-
|
|
46
|
+
|
|
47
|
+
interface AssistantMessage {
|
|
48
|
+
content?: (RefusalContentPart | TextContentPart)[] | string;
|
|
49
|
+
name?: string;
|
|
50
|
+
refusal?: string;
|
|
51
|
+
role: 'assistant';
|
|
52
|
+
tool_calls?: ToolCall[];
|
|
53
|
+
}
|
|
54
|
+
interface DeveloperMessage {
|
|
55
|
+
content: string | TextContentPart[];
|
|
56
|
+
name?: string;
|
|
57
|
+
/** @remarks Before using, confirm that your model supports this. */
|
|
58
|
+
role: 'developer';
|
|
59
|
+
}
|
|
60
|
+
type Message = AssistantMessage | DeveloperMessage | SystemMessage | ToolMessage | UserMessage;
|
|
61
|
+
interface SystemMessage {
|
|
62
|
+
content: string | TextContentPart[];
|
|
63
|
+
name?: string;
|
|
64
|
+
role: 'system';
|
|
65
|
+
}
|
|
66
|
+
interface ToolMessage {
|
|
67
|
+
/** @remarks considering the support of ecosystems (such as MCP), we have relaxed this type. */
|
|
68
|
+
content: CommonContentPart[] | string;
|
|
69
|
+
role: 'tool';
|
|
66
70
|
tool_call_id: string;
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
interface UserMessage {
|
|
73
|
+
content: CommonContentPart[] | string;
|
|
74
|
+
name?: string;
|
|
75
|
+
role: 'user';
|
|
70
76
|
}
|
|
71
|
-
type UserMessagePart = AudioPart | ImagePart | TextPart;
|
|
72
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>;
|
|
73
77
|
|
|
74
78
|
interface CompletionToolCall {
|
|
75
79
|
args: string;
|
|
@@ -79,7 +83,7 @@ interface CompletionToolCall {
|
|
|
79
83
|
}
|
|
80
84
|
interface CompletionToolResult {
|
|
81
85
|
args: Record<string, unknown>;
|
|
82
|
-
result:
|
|
86
|
+
result: ToolMessage['content'];
|
|
83
87
|
toolCallId: string;
|
|
84
88
|
toolName: string;
|
|
85
89
|
}
|
|
@@ -119,12 +123,19 @@ type CompletionStep<T extends boolean = false> = (T extends true ? {
|
|
|
119
123
|
};
|
|
120
124
|
type CompletionStepType = 'continue' | 'done' | 'initial' | 'tool-result';
|
|
121
125
|
|
|
122
|
-
type ToolChoice =
|
|
126
|
+
type ToolChoice = AllowedTools | ToolChoiceMode | ToolChoiceTool;
|
|
127
|
+
interface AllowedTools {
|
|
128
|
+
mode: 'auto' | 'required';
|
|
129
|
+
tools: ToolChoiceTool[];
|
|
130
|
+
type: 'allowed_tools';
|
|
131
|
+
}
|
|
132
|
+
type ToolChoiceMode = 'auto' | 'none' | 'required';
|
|
133
|
+
interface ToolChoiceTool {
|
|
123
134
|
function: {
|
|
124
135
|
name: string;
|
|
125
136
|
};
|
|
126
137
|
type: 'function';
|
|
127
|
-
}
|
|
138
|
+
}
|
|
128
139
|
|
|
129
140
|
/** @see {@link https://platform.openai.com/docs/api-reference/chat/create} */
|
|
130
141
|
interface ChatOptions extends CommonRequestOptions {
|
|
@@ -177,4 +188,4 @@ interface ExecuteToolResult {
|
|
|
177
188
|
}
|
|
178
189
|
declare const executeTool: ({ abortSignal, messages, toolCall, tools }: ExecuteToolOptions) => Promise<ExecuteToolResult>;
|
|
179
190
|
|
|
180
|
-
export { type AssistantMessage, type
|
|
191
|
+
export { type AssistantMessage, type AudioContentPart, type ChatOptions, type CommonContentPart, type CompletionStep, type CompletionStepType, type CompletionToolCall, type CompletionToolResult, type DetermineStepTypeOptions, type DeveloperMessage, type ExecuteToolOptions, type ExecuteToolResult, type FileContentPart, type FinishReason, type ImageContentPart, type Message, type RefusalContentPart, type SystemMessage, type TextContentPart, type Tool, type ToolCall, type ToolChoice, type ToolExecuteOptions, type ToolExecuteResult, type ToolMessage, type Usage, type UserMessage, chat, determineStepType, executeTool };
|
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.2",
|
|
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.2"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "pkgroll"
|