( item: ToolItem, descriptor: AgentActivityDescriptor, )
| 12 | }; |
| 13 | |
| 14 | export function buildImageContent( |
| 15 | item: ToolItem, |
| 16 | descriptor: AgentActivityDescriptor, |
| 17 | ): ImageToolContent | null { |
| 18 | if (descriptor.renderClass !== "image") { |
| 19 | return null; |
| 20 | } |
| 21 | |
| 22 | const source = getToolString(item.args, ["source"]); |
| 23 | if (!source) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | const trimmed = source.trim(); |
| 28 | if ( |
| 29 | !trimmed.startsWith("data:image/") && |
| 30 | !trimmed.startsWith("http://") && |
| 31 | !trimmed.startsWith("https://") |
| 32 | ) { |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | return { |
| 37 | src: trimmed, |
| 38 | title: descriptor.preview ?? descriptor.object ?? null, |
| 39 | }; |
| 40 | } |
no test coverage detected