(
message: string,
images?: Array<{ base64: string; mediaType: string }>,
)
| 256 | type ContentBlock = TextBlock | ImageBlock |
| 257 | |
| 258 | function buildPrompt( |
| 259 | message: string, |
| 260 | images?: Array<{ base64: string; mediaType: string }>, |
| 261 | ): string | AsyncIterable<SDKUserMessage> { |
| 262 | if (!images || images.length === 0) { |
| 263 | return message |
| 264 | } |
| 265 | |
| 266 | const content: ContentBlock[] = [] |
| 267 | |
| 268 | for (const img of images) { |
| 269 | content.push({ |
| 270 | type: "image", |
| 271 | source: { |
| 272 | type: "base64", |
| 273 | media_type: img.mediaType, |
| 274 | data: img.base64, |
| 275 | }, |
| 276 | }) |
| 277 | } |
| 278 | |
| 279 | content.push({ type: "text", text: message }) |
| 280 | |
| 281 | async function* messageGenerator(): AsyncGenerator<SDKUserMessage> { |
| 282 | yield { |
| 283 | type: "user", |
| 284 | message: { |
| 285 | role: "user", |
| 286 | content, |
| 287 | }, |
| 288 | parent_tool_use_id: null, |
| 289 | session_id: "", |
| 290 | } as SDKUserMessage |
| 291 | } |
| 292 | |
| 293 | return messageGenerator() |
| 294 | } |
| 295 | |
| 296 | // --- SDK options --- |
| 297 |
no test coverage detected