(attachment: ToolAttachment)
| 350 | } |
| 351 | |
| 352 | function dataUrlImage(attachment: ToolAttachment) { |
| 353 | const match = stringValue(attachment.url)?.match(/^data:([^;,]+)(?:;[^,]*)*;base64,(.*)$/) |
| 354 | const mime = match?.[1] ?? stringValue(attachment.mime) |
| 355 | if (!mime?.startsWith("image/")) return undefined |
| 356 | |
| 357 | const data = match?.[2] |
| 358 | if (data === undefined) return undefined |
| 359 | return { mimeType: mime, data } |
| 360 | } |
| 361 | |
| 362 | function stringValue(value: unknown) { |
| 363 | return typeof value === "string" ? value : undefined |
no test coverage detected