( content: string | null | undefined, files: UserFile[] | undefined, providerId: ProviderId | string )
| 584 | } |
| 585 | |
| 586 | export function buildOpenRouterMessageContent( |
| 587 | content: string | null | undefined, |
| 588 | files: UserFile[] | undefined, |
| 589 | providerId: ProviderId | string |
| 590 | ): string | OpenAIChatContentPart[] { |
| 591 | const attachments = prepareProviderAttachments(files, providerId) |
| 592 | if (attachments.length === 0) return content ?? '' |
| 593 | |
| 594 | const parts: OpenAIChatContentPart[] = [] |
| 595 | if (content) { |
| 596 | parts.push({ |
| 597 | type: 'text', |
| 598 | text: content, |
| 599 | } satisfies OpenAI.Chat.Completions.ChatCompletionContentPartText) |
| 600 | } |
| 601 | |
| 602 | for (const attachment of attachments) { |
| 603 | if (attachment.contentType === 'image') { |
| 604 | parts.push({ |
| 605 | type: 'image_url', |
| 606 | image_url: { url: attachment.remoteUrl ?? attachment.dataUrl ?? '' }, |
| 607 | } satisfies OpenAI.Chat.Completions.ChatCompletionContentPartImage) |
| 608 | } else { |
| 609 | parts.push({ |
| 610 | type: 'file', |
| 611 | file: { |
| 612 | filename: attachment.filename, |
| 613 | file_data: attachment.remoteUrl ?? attachment.dataUrl ?? '', |
| 614 | }, |
| 615 | } satisfies OpenAI.Chat.Completions.ChatCompletionContentPart.File) |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | return parts |
| 620 | } |
| 621 | |
| 622 | function sanitizeBedrockName(filename: string): string { |
| 623 | const baseName = filename.replace(/\.[^/.]+$/, '').replace(/[^a-zA-Z0-9\s()[\]-]/g, ' ') |
no test coverage detected