( content: string | null | undefined, files: UserFile[] | undefined, providerId: ProviderId | string )
| 636 | } |
| 637 | |
| 638 | export function buildBedrockMessageContent( |
| 639 | content: string | null | undefined, |
| 640 | files: UserFile[] | undefined, |
| 641 | providerId: ProviderId | string |
| 642 | ): ContentBlock[] { |
| 643 | const parts: ContentBlock[] = [] |
| 644 | if (content) { |
| 645 | parts.push({ text: content } as ContentBlock.TextMember) |
| 646 | } |
| 647 | |
| 648 | for (const attachment of prepareProviderAttachments(files, providerId)) { |
| 649 | const bytes = Buffer.from(attachment.base64 ?? '', 'base64') |
| 650 | if (attachment.contentType === 'image') { |
| 651 | parts.push({ |
| 652 | image: { |
| 653 | format: getBedrockImageFormat(attachment) as ContentBlock.ImageMember['image']['format'], |
| 654 | source: { bytes }, |
| 655 | }, |
| 656 | } as ContentBlock.ImageMember) |
| 657 | } else if (attachment.contentType === 'video') { |
| 658 | parts.push({ |
| 659 | video: { |
| 660 | format: attachment.extension as ContentBlock.VideoMember['video']['format'], |
| 661 | source: { bytes }, |
| 662 | }, |
| 663 | } as ContentBlock.VideoMember) |
| 664 | } else { |
| 665 | parts.push({ |
| 666 | document: { |
| 667 | format: getBedrockDocumentFormat( |
| 668 | attachment |
| 669 | ) as ContentBlock.DocumentMember['document']['format'], |
| 670 | name: sanitizeBedrockName(attachment.filename), |
| 671 | source: { bytes }, |
| 672 | }, |
| 673 | } as ContentBlock.DocumentMember) |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | return parts |
| 678 | } |
| 679 | |
| 680 | const SDK_NATIVE_ATTACHMENT_PROVIDERS = new Set<AttachmentProvider>([ |
| 681 | 'openai', |
no test coverage detected