( stdout: string, toolUseID: string, )
| 69 | * Returns null if parse fails so callers can fall through to text handling. |
| 70 | */ |
| 71 | export function buildImageToolResult( |
| 72 | stdout: string, |
| 73 | toolUseID: string, |
| 74 | ): ToolResultBlockParam | null { |
| 75 | const parsed = parseDataUri(stdout) |
| 76 | if (!parsed) return null |
| 77 | return { |
| 78 | tool_use_id: toolUseID, |
| 79 | type: 'tool_result', |
| 80 | content: [ |
| 81 | { |
| 82 | type: 'image', |
| 83 | source: { |
| 84 | type: 'base64', |
| 85 | media_type: parsed.mediaType as Base64ImageSource['media_type'], |
| 86 | data: parsed.data, |
| 87 | }, |
| 88 | }, |
| 89 | ], |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Cap file reads to 20 MB — any image data URI larger than this is |
| 94 | // well beyond what the API accepts (5 MB base64) and would OOM if read |
no test coverage detected