fix(core): omit historical images for text models

This commit is contained in:
Patrick Wozniak
2026-08-25 17:46:41 +02:00
parent b6550918ba
commit 45281d693e
4 changed files with 87 additions and 27 deletions
+54 -11
View File
@@ -161,7 +161,7 @@ describe("projectSlugFromPath()", () => {
})
describe("text-only image handling", () => {
it("rejects image content for models without image support", () => {
it("rejects direct image input for models without image support", () => {
assert.throws(
() =>
assertTextOnlyMessages([
@@ -172,16 +172,17 @@ describe("text-only image handling", () => {
]),
/does not support image content/i,
)
assert.throws(
() =>
assertTextOnlyMessages([
{
role: "toolResult",
toolCallId: "c1",
content: [{ type: "image", data: "base64-data", mimeType: "image/png" }],
},
]),
/does not support image content/i,
})
it("allows historical tool-result images to be omitted for text-only models", () => {
assert.doesNotThrow(() =>
assertTextOnlyMessages([
{
role: "toolResult",
toolCallId: "c1",
content: [{ type: "image", data: "base64-data", mimeType: "image/png" }],
},
]),
)
})
})
@@ -597,6 +598,48 @@ describe("messagesToCC()", () => {
)
})
it("omits tool-result images for text-only models while preserving their text", () => {
const result = messagesToCC([
{ role: "user", content: "read image" },
{
role: "assistant",
content: [{ type: "toolCall", id: "c1", name: "read", arguments: {} }],
},
{
role: "toolResult",
toolCallId: "c1",
toolName: "read",
content: [
{ type: "text", text: "image attached" },
{ type: "image", data: "aGVsbG8=", mimeType: "image/jpeg" },
],
},
])
assert.equal(objectAt(result, ["2", "content", "0", "output", "value"]), "image attached")
assert.equal(objectAt(result, ["3"]), undefined)
})
it("describes an omitted image-only tool result for text-only models", () => {
const result = messagesToCC([
{
role: "assistant",
content: [{ type: "toolCall", id: "c1", name: "read", arguments: {} }],
},
{
role: "toolResult",
toolCallId: "c1",
toolName: "read",
content: [{ type: "image", data: "aGVsbG8=", mimeType: "image/jpeg" }],
},
])
assert.equal(
objectAt(result, ["1", "content", "0", "output", "value"]),
"[Image omitted: model does not support images]",
)
})
it("preserves tool-result images as a following user image message", () => {
const result = messagesToCC(
[