Skip to content

Commit 87aaa14

Browse files
committed
fix(openai-chat): skip tool-result images without a usable URL
The tool-output parser accepts any string for image_url, including the empty file_id shape, and a {"url":""} carrier part would fail the whole request where the "[image]" marker degrades safely.
1 parent 9c8a0c5 commit 87aaa14

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/adapters/openai-chat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ function toolResultImageChatParts(content: string | OcxContentPart[]): unknown[]
8787
if (typeof content === "string") return [];
8888
const parts: unknown[] = [];
8989
for (const p of content) {
90-
if (p.type !== "image") continue;
90+
// Skip parts without a usable URL (the tool-output parser accepts the empty file_id shape):
91+
// a {"url":""} part would fail the whole request where the "[image]" marker degrades safely.
92+
if (p.type !== "image" || !p.imageUrl) continue;
9193
parts.push({ type: "image_url", image_url: { url: p.imageUrl, ...(p.detail ? { detail: p.detail } : {}) } });
9294
}
9395
return parts;

tests/openai-chat-tool-result-images.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ test("tool-result images ride a follow-up user message; text, detail, and https
8585
{ type: "text", text: "1 match found" },
8686
{ type: "image", imageUrl: IMAGE_URL, detail: "high" },
8787
{ type: "image", imageUrl: "https://example.test/shot.png" },
88+
{ type: "image", imageUrl: "" }, // empty file_id shape: keeps its marker, never reaches the carrier
8889
]),
8990
]);
9091
assertRoundsUnbroken(messages);
9192
const tool = messages.find(m => m.role === "tool")!;
92-
expect(tool.content).toBe("1 match found[image][image]");
93+
expect(tool.content).toBe("1 match found[image][image][image]");
9394
const carrier = messages.find(isImageCarrier)!;
9495
expect(carrier).toBeDefined();
9596
expect(messages.indexOf(carrier)).toBe(messages.indexOf(tool) + 1);

0 commit comments

Comments
 (0)