fix: ensure images are properly returned as tool results

This commit is contained in:
Aiden Cline
2026-01-21 23:54:39 -06:00
parent fc0210c2fd
commit c2844697f3
3 changed files with 64 additions and 47 deletions

View File

@@ -262,7 +262,7 @@ describe("session.message-v2.toModelMessage", () => {
])
})
test("converts assistant tool completion into tool-call + tool-result messages and emits attachment message", () => {
test("converts assistant tool completion into tool-call + tool-result messages with attachments", () => {
const userID = "m-user"
const assistantID = "m-assistant"
@@ -304,7 +304,7 @@ describe("session.message-v2.toModelMessage", () => {
type: "file",
mime: "image/png",
filename: "attachment.png",
url: "https://example.com/attachment.png",
url: "data:image/png;base64,Zm9v",
},
],
},
@@ -319,18 +319,6 @@ describe("session.message-v2.toModelMessage", () => {
role: "user",
content: [{ type: "text", text: "run tool" }],
},
{
role: "user",
content: [
{ type: "text", text: "The tool bash returned the following attachments:" },
{
type: "file",
mediaType: "image/png",
filename: "attachment.png",
data: "https://example.com/attachment.png",
},
],
},
{
role: "assistant",
content: [
@@ -352,7 +340,13 @@ describe("session.message-v2.toModelMessage", () => {
type: "tool-result",
toolCallId: "call-1",
toolName: "bash",
output: { type: "text", value: "ok" },
output: {
type: "content",
value: [
{ type: "text", text: "ok" },
{ type: "media", mediaType: "image/png", data: "Zm9v" },
],
},
providerOptions: { openai: { tool: "meta" } },
},
],