| 339 | } |
| 340 | |
| 341 | private cleanMessageContent(content: any): any { |
| 342 | if (!content) { |
| 343 | return content |
| 344 | } |
| 345 | |
| 346 | if (typeof content === "string") { |
| 347 | return content |
| 348 | } |
| 349 | |
| 350 | if (Array.isArray(content)) { |
| 351 | return content.map((item) => this.cleanMessageContent(item)) |
| 352 | } |
| 353 | |
| 354 | if (typeof content === "object") { |
| 355 | const cleaned: any = {} |
| 356 | for (const [key, value] of Object.entries(content)) { |
| 357 | cleaned[key] = this.cleanMessageContent(value) |
| 358 | } |
| 359 | return cleaned |
| 360 | } |
| 361 | |
| 362 | return content |
| 363 | } |
| 364 | |
| 365 | override async *createMessage( |
| 366 | systemPrompt: string, |