fix: 修复阿里生图模型图片解析问题

- AI SDK convertToModelMessages 将 url 转换为 data 字段
- 同时支持 url 和 data 字段以兼容不同格式
This commit is contained in:
Your Name 2026-01-12 14:00:58 +08:00
parent da207f654e
commit 4008e958a3

View File

@ -333,14 +333,17 @@ export function createAlibabaImage({ apiKey, baseURL }: AlibabaImageConfig) {
} else { } else {
imageUrls.push(imageUrl); imageUrls.push(imageUrl);
} }
} else if (part.type === "file" && (part as any).url) { } else if (part.type === "file") {
// 格式3: { type: "file", url: string } - 来自 ChatMessage 的原始格式 // 格式3: { type: "file", url/data: string } - 来自 ChatMessage 的原始格式
const fileUrl = (part as any).url; // AI SDK convertToModelMessages 会将 url 转换为 data 字段
if (fileUrl.startsWith("data:")) { const fileUrl = (part as any).url || (part as any).data;
const url = await uploadBase64ToS3(fileUrl); if (fileUrl) {
imageUrls.push(url); if (fileUrl.startsWith("data:")) {
} else { const url = await uploadBase64ToS3(fileUrl);
imageUrls.push(fileUrl); imageUrls.push(url);
} else {
imageUrls.push(fileUrl);
}
} }
} }
} }