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

Function normalizeImageBlocks

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 2

isMalformedBase64ImageFunction · 0.85

Tested by

no test coverage detected