( content: string | null | undefined, files: UserFile[] | undefined, providerId: ProviderId | string )
| 419 | type AnthropicImageMediaType = Anthropic.Messages.Base64ImageSource['media_type'] |
| 420 | |
| 421 | export function buildOpenAIMessageContent( |
| 422 | content: string | null | undefined, |
| 423 | files: UserFile[] | undefined, |
| 424 | providerId: ProviderId | string |
| 425 | ): string | OpenAIResponsesInputContent[] { |
| 426 | const attachments = prepareProviderAttachments(files, providerId) |
| 427 | if (attachments.length === 0) return content ?? '' |
| 428 | |
| 429 | const parts: OpenAIResponsesInputContent[] = [] |
| 430 | if (content) { |
| 431 | parts.push({ type: 'input_text', text: content } satisfies OpenAI.Responses.ResponseInputText) |
| 432 | } |
| 433 | |
| 434 | for (const attachment of attachments) { |
| 435 | if (attachment.contentType === 'image') { |
| 436 | parts.push( |
| 437 | attachment.providerFileId |
| 438 | ? ({ |
| 439 | type: 'input_image', |
| 440 | file_id: attachment.providerFileId, |
| 441 | detail: 'auto', |
| 442 | } satisfies OpenAI.Responses.ResponseInputImage) |
| 443 | : ({ |
| 444 | type: 'input_image', |
| 445 | image_url: attachment.dataUrl, |
| 446 | detail: 'auto', |
| 447 | } satisfies OpenAI.Responses.ResponseInputImage) |
| 448 | ) |
| 449 | } else { |
| 450 | parts.push( |
| 451 | attachment.providerFileId |
| 452 | ? ({ |
| 453 | type: 'input_file', |
| 454 | file_id: attachment.providerFileId, |
| 455 | } satisfies OpenAI.Responses.ResponseInputFile) |
| 456 | : ({ |
| 457 | type: 'input_file', |
| 458 | filename: attachment.filename, |
| 459 | file_data: attachment.dataUrl, |
| 460 | } satisfies OpenAI.Responses.ResponseInputFile) |
| 461 | ) |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return parts |
| 466 | } |
| 467 | |
| 468 | export function buildAnthropicMessageContent( |
| 469 | content: string | null | undefined, |
no test coverage detected