MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / maybeRemoveImageBlocks

Function maybeRemoveImageBlocks

src/api/transform/image-cleaning.ts:6–32  ·  view source on GitHub ↗
(messages: ApiMessage[], apiHandler: ApiHandler)

Source from the content-addressed store, hash-verified

4
5/* Removes image blocks from messages if they are not supported by the Api Handler */
6export function maybeRemoveImageBlocks(messages: ApiMessage[], apiHandler: ApiHandler): ApiMessage[] {
7 // Check model capability ONCE instead of for every message
8 const supportsImages = apiHandler.getModel().info.supportsImages
9
10 return messages.map((message) => {
11 // Handle array content (could contain image blocks).
12 let { content } = message
13 if (Array.isArray(content)) {
14 if (!supportsImages) {
15 // Convert image blocks to text descriptions.
16 content = content.map((block) => {
17 if (block.type === "image") {
18 // Convert image blocks to text descriptions.
19 // Note: We can't access the actual image content/url due to API limitations,
20 // but we can indicate that an image was present in the conversation.
21 return {
22 type: "text",
23 text: "[Referenced image in conversation]",
24 }
25 }
26 return block
27 })
28 }
29 }
30 return { ...message, content }
31 })
32}

Callers 3

attemptApiRequestMethod · 0.90
summarizeConversationFunction · 0.90

Calls 1

getModelMethod · 0.65

Tested by

no test coverage detected