ITADN

Anthropic MessageMapper::mapImageBlock doesn't support SourceType::ID (file_id)

#535Closedthomasdv 创建于 2026-04-08
T
thomasdvcommented
`AnthropicMessageMapper::mapImageBlock()` only handles `SourceType::URL` and `SourceType::BASE64`. `SourceType::ID` falls through to `default => null` and the image block is silently dropped. This prevents referencing previously uploaded images by `file_id`. **Current behavior** (src/Providers/Anthropic/MessageMapper.php, lines 79–99): ```php protected function mapImageBlock(ImageContent $block): ?array { return match ($block->sourceType) { SourceType::URL => [ 'type' => 'image', 'source' => [ 'type' => 'url', 'url' => $block->content ] ], SourceType::BASE64 => [ 'type' => 'image', 'source' => [ 'type' => 'base64', 'media_type' => $block->mediaType, 'data' => $block->content ] ], default => null }; } ``` Passing new ImageContent($fileId, SourceType::ID, 'image/jpeg') results in the block being filtered out of the outgoing payload — no error, just missing image. **Proposed fix**: ```php protected function mapImageBlock(ImageContent $block): ?array { return match ($block->sourceType) { SourceType::URL => [ 'type' => 'image', 'source' => ['type' => 'url', 'url' => $block->content], ], SourceType::BASE64 => [ 'type' => 'image', 'source' => [ 'type' => 'base64', 'media_type' => $block->mediaType, 'data' => $block->content, ], ], SourceType::ID => [ 'type' => 'image', 'source' => [ 'type' => 'file', 'file_id' => $block->content, ], ], }; } ```
关闭于 2026-04-09 1 条评论