Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ function unsupportedParts(msgs: ModelMessage[], model: Provider.Model): ModelMes
const filename = part.type === "file" ? part.filename : undefined
const modality = mimeToModality(mime)
if (!modality) return part
if (model.capabilities.input[modality]) return part
if (
Array.isArray(model.capabilities.input)
? model.capabilities.input.includes(modality)
: model.capabilities.input[modality]
)
return part

const name = filename ? `"${filename}"` : modality
return {
Expand Down
15 changes: 15 additions & 0 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,21 @@ describe("ProviderTransform.message - empty image handling", () => {
expect(result[0].content[1]).toEqual({ type: "image", image: `data:image/png;base64,${validBase64}` })
})

test("should keep images when custom-provider input capabilities use modalities", () => {
const image = { type: "image" as const, image: "data:image/png;base64,abcd" }
const model = {
...mockModel,
capabilities: {
...mockModel.capabilities,
input: ["text", "image"],
},
} as unknown as Parameters<typeof ProviderTransform.message>[1]

const result = ProviderTransform.message([{ role: "user", content: [image] }], model, {})

expect(result[0].content[0]).toEqual(image)
})

test("should handle mixed valid and empty images", () => {
const validBase64 =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
Expand Down
Loading