@xsai/shared-chat 0.1.1 → 0.1.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 +6 -4
- package/dist/index.js +14 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ interface ToolCall {
|
|
|
64
64
|
interface ToolMessage extends Omit<CommonMessage<'tool', ToolMessagePart>, 'name'> {
|
|
65
65
|
tool_call_id: string;
|
|
66
66
|
}
|
|
67
|
-
type ToolMessagePart = TextPart;
|
|
67
|
+
type ToolMessagePart = AudioPart | ImagePart | TextPart;
|
|
68
68
|
interface UserMessage extends CommonMessage<'user', UserMessagePart> {
|
|
69
69
|
}
|
|
70
70
|
type UserMessagePart = AudioPart | ImagePart | TextPart;
|
|
@@ -78,12 +78,12 @@ interface CompletionToolCall {
|
|
|
78
78
|
}
|
|
79
79
|
interface CompletionToolResult {
|
|
80
80
|
args: Record<string, unknown>;
|
|
81
|
-
result: string;
|
|
81
|
+
result: string | ToolMessagePart[];
|
|
82
82
|
toolCallId: string;
|
|
83
83
|
toolName: string;
|
|
84
84
|
}
|
|
85
85
|
interface Tool {
|
|
86
|
-
execute: (input: unknown, options: ToolExecuteOptions) => Promise<string
|
|
86
|
+
execute: (input: unknown, options: ToolExecuteOptions) => (object | string | unknown[]) | Promise<object | string | unknown[]>;
|
|
87
87
|
function: {
|
|
88
88
|
description?: string;
|
|
89
89
|
name: string;
|
|
@@ -139,4 +139,6 @@ interface ChatOptions extends CommonRequestOptions {
|
|
|
139
139
|
}
|
|
140
140
|
declare const chat: <T extends ChatOptions>(options: T) => Promise<Response>;
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
declare const wrapToolResult: (result: object | string | unknown[]) => string | ToolMessagePart[];
|
|
143
|
+
|
|
144
|
+
export { type AssistantMessage, type AssistantMessagePart, type AssistantMessageResponse, type AudioBase64, type AudioPart, type ChatOptions, type CommonMessage, type CommonPart, type CompletionToolCall, type CompletionToolResult, type FinishReason, type ImagePart, type ImageURLorBase64, type Message, type Part, type RefusalPart, 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, wrapToolResult };
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,19 @@ var chat = async (options) => (options.fetch ?? globalThis.fetch)(requestURL("ch
|
|
|
15
15
|
method: "POST",
|
|
16
16
|
signal: options.abortSignal
|
|
17
17
|
}).then(responseCatch);
|
|
18
|
+
|
|
19
|
+
// src/utils/wrap-tool-result.ts
|
|
20
|
+
var wrapToolResult = (result) => {
|
|
21
|
+
if (typeof result === "string")
|
|
22
|
+
return result;
|
|
23
|
+
if (Array.isArray(result)) {
|
|
24
|
+
if (result.every((item) => !!(typeof item === "object" && "type" in item && ["audio", "image", "text"].includes(item.type)))) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return JSON.stringify(result);
|
|
29
|
+
};
|
|
18
30
|
export {
|
|
19
|
-
chat
|
|
31
|
+
chat,
|
|
32
|
+
wrapToolResult
|
|
20
33
|
};
|