MCPcopy
hub / github.com/claude-code-best/claude-code / normalizeImageBlocks

Function normalizeImageBlocks

src/bridge/inboundMessages.ts:54–75  ·  view source on GitHub ↗
(
  blocks: Array<ContentBlockParam>,
)

Source from the content-addressed store, hash-verified

52 * normalization is needed (zero allocation on the happy path).
53 */
54export function normalizeImageBlocks(
55 blocks: Array<ContentBlockParam>,
56): Array<ContentBlockParam> {
57 if (!blocks.some(isMalformedBase64Image)) return blocks
58
59 return blocks.map(block => {
60 if (!isMalformedBase64Image(block)) return block
61 const src = block.source as unknown as Record<string, unknown>
62 const mediaType =
63 typeof src.mediaType === 'string' && src.mediaType
64 ? src.mediaType
65 : detectImageFormatFromBase64(block.source.data)
66 return {
67 ...block,
68 source: {
69 type: 'base64' as const,
70 media_type: mediaType as Base64ImageSource['media_type'],
71 data: block.source.data,
72 },
73 }
74 })
75}
76
77function isMalformedBase64Image(
78 block: ContentBlockParam,

Callers 1

Calls 2

isMalformedBase64ImageFunction · 0.85

Tested by

no test coverage detected