feat(chat): enhance image extraction and file path handling in messages (#116)

This commit is contained in:
Haze
2026-02-20 10:48:46 +08:00
committed by GitHub
Unverified
parent 1c418ab22a
commit c969e899c8
2 changed files with 163 additions and 26 deletions

View File

@@ -127,10 +127,17 @@ export function extractImages(message: RawMessage | unknown): Array<{ mimeType:
const images: Array<{ mimeType: string; data: string }> = [];
for (const block of content as ContentBlock[]) {
if (block.type === 'image' && block.source) {
const src = block.source;
if (src.type === 'base64' && src.media_type && src.data) {
images.push({ mimeType: src.media_type, data: src.data });
if (block.type === 'image') {
// Path 1: Anthropic source-wrapped format
if (block.source) {
const src = block.source;
if (src.type === 'base64' && src.media_type && src.data) {
images.push({ mimeType: src.media_type, data: src.data });
}
}
// Path 2: Flat format from Gateway tool results {data, mimeType}
else if (block.data) {
images.push({ mimeType: block.mimeType || 'image/jpeg', data: block.data });
}
}
}