MCPcopy Create free account
hub / github.com/anomalyco/opencode / dataUrlImage

Function dataUrlImage

packages/opencode/src/acp/tool.ts:352–360  ·  view source on GitHub ↗
(attachment: ToolAttachment)

Source from the content-addressed store, hash-verified

350}
351
352function dataUrlImage(attachment: ToolAttachment) {
353 const match = stringValue(attachment.url)?.match(/^data:([^;,]+)(?:;[^,]*)*;base64,(.*)$/)
354 const mime = match?.[1] ?? stringValue(attachment.mime)
355 if (!mime?.startsWith("image/")) return undefined
356
357 const data = match?.[2]
358 if (data === undefined) return undefined
359 return { mimeType: mime, data }
360}
361
362function stringValue(value: unknown) {
363 return typeof value === "string" ? value : undefined

Callers 1

extractImageAttachmentsFunction · 0.85

Calls 1

stringValueFunction · 0.70

Tested by

no test coverage detected