smoltalk 0.0.63 → 0.0.64
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.
|
@@ -7,15 +7,18 @@ import { Message } from "ollama";
|
|
|
7
7
|
import type { ResponseInputItem } from "openai/resources/responses/responses.js";
|
|
8
8
|
export declare const ToolMessageJSONSchema: z.ZodObject<{
|
|
9
9
|
role: z.ZodLiteral<"tool">;
|
|
10
|
-
content: z.
|
|
11
|
-
type: z.ZodLiteral<"text">;
|
|
12
|
-
text: z.ZodString;
|
|
13
|
-
}, z.core.$strip>>]>;
|
|
10
|
+
content: z.ZodAny;
|
|
14
11
|
name: z.ZodString;
|
|
15
12
|
tool_call_id: z.ZodDefault<z.ZodString>;
|
|
16
13
|
rawData: z.ZodOptional<z.ZodAny>;
|
|
17
14
|
}, z.core.$strip>;
|
|
18
|
-
export type ToolMessageJSON =
|
|
15
|
+
export type ToolMessageJSON = {
|
|
16
|
+
role: "tool";
|
|
17
|
+
content: any;
|
|
18
|
+
name: string;
|
|
19
|
+
tool_call_id: string;
|
|
20
|
+
rawData?: any;
|
|
21
|
+
};
|
|
19
22
|
export declare class ToolMessage extends BaseMessage implements MessageClass {
|
|
20
23
|
_role: "tool";
|
|
21
24
|
_content: string | Array<TextPart>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseMessage } from "./BaseMessage.js";
|
|
3
3
|
import { TextPartSchema } from "../../types.js";
|
|
4
|
+
import { getLogger } from "../../util/logger.js";
|
|
4
5
|
export const ToolMessageJSONSchema = z.object({
|
|
5
6
|
role: z.literal("tool"),
|
|
6
|
-
content: z.union([z.string(), z.array(TextPartSchema)]),
|
|
7
|
+
//content: z.union([z.string(), z.array(TextPartSchema)]),
|
|
8
|
+
content: z.any(),
|
|
7
9
|
name: z.string(),
|
|
8
10
|
tool_call_id: z.string().default(""),
|
|
9
11
|
rawData: z.any().optional(),
|
|
@@ -55,6 +57,18 @@ export class ToolMessage extends BaseMessage {
|
|
|
55
57
|
console.error(z.prettifyError(result.error));
|
|
56
58
|
throw new Error("Failed to parse ToolMessage");
|
|
57
59
|
}
|
|
60
|
+
const TextPartArraySchema = z.array(TextPartSchema);
|
|
61
|
+
const textPartArrayResult = TextPartArraySchema.safeParse(result.data.content);
|
|
62
|
+
if (textPartArrayResult.success) {
|
|
63
|
+
result.data.content = textPartArrayResult.data;
|
|
64
|
+
}
|
|
65
|
+
else if (typeof result.data.content === "string") {
|
|
66
|
+
// do nothing, it's already a string
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
getLogger().warn("ToolMessage content is neither a string nor an array of TextParts. Converting to string using JSON.stringify.");
|
|
70
|
+
result.data.content = JSON.stringify(result.data.content);
|
|
71
|
+
}
|
|
58
72
|
return new ToolMessage(result.data.content, {
|
|
59
73
|
tool_call_id: result.data.tool_call_id,
|
|
60
74
|
name: result.data.name,
|
|
@@ -101,7 +115,13 @@ export class ToolMessage extends BaseMessage {
|
|
|
101
115
|
toAnthropicMessage() {
|
|
102
116
|
return {
|
|
103
117
|
role: "user",
|
|
104
|
-
content: [
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: "tool_result",
|
|
121
|
+
tool_use_id: this.tool_call_id,
|
|
122
|
+
content: this.content,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
105
125
|
};
|
|
106
126
|
}
|
|
107
127
|
}
|