Skip to content

Commit d9db2de

Browse files
committed
fix(session): use image part type for images injected from tool results
When providers that don't support media in tool results receive an image from a tool like Read, the image is extracted from the tool result and re-injected as a separate user message. This injection used type: "file" for all media, which is not understood by OpenAI-compatible providers that expect type: "image" (mapping to image_url in the API). This caused vision-capable OpenAI-compatible models (e.g., qwen3.5-plus via @ai-sdk/openai-compatible) to receive file parts they couldn't handle, even when the user correctly configured image modalities in opencode.json. Fix: use type: "image" with the data URL for image/* MIME types in the injected user message. Non-image media (e.g., PDF) continues to use type: "file" as before. Fixes anomalyco#15728
1 parent 98c75be commit d9db2de

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎packages/opencode/src/session/message-v2.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,18 @@ export namespace MessageV2 {
705705
type: "text" as const,
706706
text: "Attached image(s) from tool result:",
707707
},
708-
...media.map((attachment) => ({
709-
type: "file" as const,
710-
url: attachment.url,
711-
mediaType: attachment.mime,
712-
})),
708+
...media.map((attachment) =>
709+
attachment.mime.startsWith("image/")
710+
? ({
711+
type: "image" as const,
712+
image: attachment.url,
713+
} as const)
714+
: ({
715+
type: "file" as const,
716+
url: attachment.url,
717+
mediaType: attachment.mime,
718+
} as const),
719+
),
713720
],
714721
})
715722
}

0 commit comments

Comments
 (0)