( base64: string, mimeType: string )
| 155 | * Create message content from base64-encoded file data. |
| 156 | */ |
| 157 | export function createFileContentFromBase64( |
| 158 | base64: string, |
| 159 | mimeType: string |
| 160 | ): MessageContent | null { |
| 161 | // SVG is XML text — Claude only supports raster image formats (JPEG, PNG, GIF, WebP), |
| 162 | // so send SVGs as an XML document instead |
| 163 | if (mimeType.toLowerCase() === 'image/svg+xml') { |
| 164 | return { |
| 165 | type: 'document', |
| 166 | source: { |
| 167 | type: 'base64', |
| 168 | media_type: 'text/xml', |
| 169 | data: base64, |
| 170 | }, |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | const contentType = getContentType(mimeType) |
| 175 | if (!contentType) { |
| 176 | return null |
| 177 | } |
| 178 | |
| 179 | if (contentType === 'image' && !MODEL_SUPPORTED_IMAGE_MIME_TYPES.has(mimeType.toLowerCase())) { |
| 180 | return null |
| 181 | } |
| 182 | |
| 183 | return { |
| 184 | type: contentType, |
| 185 | source: { |
| 186 | type: 'base64', |
| 187 | media_type: mimeType, |
| 188 | data: base64, |
| 189 | }, |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | export const MODEL_SUPPORTED_IMAGE_MIME_TYPES = new Set([ |
| 194 | 'image/jpeg', |
no test coverage detected