diff --git a/lib/ai/providers/huanke-gemini.ts b/lib/ai/providers/huanke-gemini.ts index f743fffbd..5696a6834 100644 --- a/lib/ai/providers/huanke-gemini.ts +++ b/lib/ai/providers/huanke-gemini.ts @@ -443,6 +443,35 @@ async function sendHuankeGeminiRequest( } }); console.log("[Huanke Gemini] Added image URL:", imageUrl.substring(0, 100)); + } else if (contentPart.type === "file" && (contentPart.data || contentPart.url)) { + // 🆕 处理 file 类型(从 Chat API 传过来的格式) + // 格式: { type: "file", mediaType: "image/jpeg", data: "https://..." } + let imageUrl = contentPart.data || contentPart.url; + const mimeType = contentPart.mediaType || contentPart.mimeType || "image/jpeg"; + + console.log("[Huanke Gemini] Processing file type:", { url: imageUrl?.substring(0, 80), mimeType }); + + if (imageUrl && imageUrl.startsWith("data:")) { + // Base64 图片 -> 上传到 S3 获取 URL + console.log("[Huanke Gemini] Converting Base64 file to URL (Base64 forbidden)..."); + try { + imageUrl = await convertBase64ToUrl(imageUrl); + } catch (error) { + console.error("[Huanke Gemini] Failed to convert Base64 to URL:", error); + continue; + } + } + + if (imageUrl && imageUrl.startsWith("http")) { + // 使用 fileData 格式传递图片 URL + parts.push({ + fileData: { + fileUri: imageUrl, + mimeType: mimeType.startsWith("image/") ? mimeType : "image/jpeg", + } + }); + console.log("[Huanke Gemini] Added file image URL:", imageUrl.substring(0, 100)); + } } } }