From 8ff91edb1140f1da1761404f5a10f254ccd578ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Feb 2026 00:43:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Gemini=20=E5=9B=BE=E7=89=87=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=B5=81=E7=A8=8B=E6=B7=BB=E5=8A=A0=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Gemini/Huanke-Gemini 图片生成流程中添加 conversationalReply 发送逻辑 - 与 Alibaba 图片生成流程保持一致 - 确保无限画布中的智能自动模式能显示 AI 对话回复 --- app/(chat)/api/chat/route.ts | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 48b8c7d43..69007f0f8 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -752,6 +752,46 @@ export async function POST(request: Request) { const geminiStream = createUIMessageStream({ execute: async ({ writer }) => { + // 🆕 如果是智能模式且有对话回复,先发送对话消息让用户看到 + // 在消息末尾加上特殊标记,告诉前端"图片正在生成中" + const messageWithMarker = smartAutoFriendlyMessage + ? `${smartAutoFriendlyMessage}\n\n` + : null; + + if (messageWithMarker) { + const chatMessageId = generateUUID(); + console.log("[Chat API] 💬 Gemini: Sending conversational reply first:", smartAutoFriendlyMessage); + + // 发送带标记的对话消息 + writer.write({ + type: "data-appendMessage", + data: JSON.stringify({ + id: chatMessageId, + role: "assistant", + parts: [{ type: "text", text: messageWithMarker }], + }), + }); + + // 保存对话消息到数据库(不带标记,纯对话) + await saveMessages({ + messages: [ + { + id: chatMessageId, + chatId: id, + role: "assistant", + parts: [{ type: "text", text: smartAutoFriendlyMessage }], + attachments: [], + createdAt: new Date(), + videoStorageStatus: null, + temporaryVideoUrl: null, + permanentVideoUrl: null, + archivedAt: null, + videoMetadata: null, + }, + ], + }); + } + // 🆕 尝试生成图片的函数(支持备用模型切换) const tryGenerateImage = async (modelIdToUse: string, isRetry = false): Promise => { console.log(`[Chat API] ${isRetry ? "🔄 Retry with fallback" : "🚀 Trying"} model: ${modelIdToUse}`);