MCPcopy Index your code
hub / github.com/anomalyco/opencode / unsupportedParts

Function unsupportedParts

packages/opencode/src/provider/transform.ts:374–410  ·  view source on GitHub ↗
(msgs: ModelMessage[], model: Provider.Model)

Source from the content-addressed store, hash-verified

372}
373
374function unsupportedParts(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {
375 return msgs.map((msg) => {
376 if (msg.role !== "user" || !Array.isArray(msg.content)) return msg
377
378 const filtered = msg.content.map((part) => {
379 if (part.type !== "file" && part.type !== "image") return part
380
381 // Check for empty base64 image data
382 if (part.type === "image") {
383 const imageStr = String(part.image)
384 if (imageStr.startsWith("data:")) {
385 const match = imageStr.match(/^data:([^;]+);base64,(.*)$/)
386 if (match && (!match[2] || match[2].length === 0)) {
387 return {
388 type: "text" as const,
389 text: "ERROR: Image file is empty or corrupted. Please provide a valid image.",
390 }
391 }
392 }
393 }
394
395 const mime = part.type === "image" ? String(part.image).split(";")[0].replace("data:", "") : part.mediaType
396 const filename = part.type === "file" ? part.filename : undefined
397 const modality = mimeToModality(mime)
398 if (!modality) return part
399 if (model.capabilities.input[modality]) return part
400
401 const name = filename ? `"${filename}"` : modality
402 return {
403 type: "text" as const,
404 text: `ERROR: Cannot read ${name} (this model does not support ${modality} input). Inform the user.`,
405 }
406 })
407
408 return { ...msg, content: filtered }
409 })
410}
411
412function mapProviderOptions(
413 msgs: ModelMessage[],

Callers 1

messageFunction · 0.85

Calls 1

mimeToModalityFunction · 0.85

Tested by

no test coverage detected