From 4008e958a34d648bd7fd84e1b7fcd2f075b500d9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 Jan 2026 14:00:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E7=94=9F=E5=9B=BE=E6=A8=A1=E5=9E=8B=E5=9B=BE=E7=89=87=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AI SDK convertToModelMessages 将 url 转换为 data 字段 - 同时支持 url 和 data 字段以兼容不同格式 --- lib/ai/providers/alibaba-image.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/ai/providers/alibaba-image.ts b/lib/ai/providers/alibaba-image.ts index 4b2c6e9..24ecf2d 100644 --- a/lib/ai/providers/alibaba-image.ts +++ b/lib/ai/providers/alibaba-image.ts @@ -333,14 +333,17 @@ export function createAlibabaImage({ apiKey, baseURL }: AlibabaImageConfig) { } else { imageUrls.push(imageUrl); } - } else if (part.type === "file" && (part as any).url) { - // 格式3: { type: "file", url: string } - 来自 ChatMessage 的原始格式 - const fileUrl = (part as any).url; - if (fileUrl.startsWith("data:")) { - const url = await uploadBase64ToS3(fileUrl); - imageUrls.push(url); - } else { - imageUrls.push(fileUrl); + } else if (part.type === "file") { + // 格式3: { type: "file", url/data: string } - 来自 ChatMessage 的原始格式 + // AI SDK convertToModelMessages 会将 url 转换为 data 字段 + const fileUrl = (part as any).url || (part as any).data; + if (fileUrl) { + if (fileUrl.startsWith("data:")) { + const url = await uploadBase64ToS3(fileUrl); + imageUrls.push(url); + } else { + imageUrls.push(fileUrl); + } } } }