From 231d726b37f87ef7a9f080462061dbc8a09c0720 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 1 Feb 2026 02:18:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=A8=A1=E5=BC=8F=E5=AF=B9=E8=AF=9D=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复内容: 1. 前端:检查用户最后一条消息是否有图片(而不是整个对话最后一条) 2. 前端:useEffect 依赖项添加 selectedModelId 3. 后端:错误回退时也生成友好消息 4. 后端:保存消息时添加完整的数据库字段 5. 分析器:增加颜色调整关键词匹配(改成X色、换成X色) 现在大模型(Qwen3 VL)会生成自然对话回复 Co-authored-by: Cursor --- app/(chat)/api/chat/route.ts | 12 ++++++++++++ components/messages.tsx | 8 ++++---- lib/ai/smart-analyzer.ts | 9 ++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 4bde3500f..604588ec1 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -486,6 +486,8 @@ export async function POST(request: Request) { let bestModel = null; if (hasImage) { bestModel = allModels.find(m => m.model.supportsImageGen && !m.model.isSubModel); + // 🆕 回退时也生成一个友好消息 + smartAutoFriendlyMessage = "好的,我来帮你处理这张图片~"; } if (!bestModel) { bestModel = allModels.find(m => m.model.isDefault && !m.model.isSubModel); @@ -1016,6 +1018,11 @@ export async function POST(request: Request) { parts: [{ type: "text", text: smartAutoFriendlyMessage }], attachments: [], createdAt: new Date(), + videoStorageStatus: null, + temporaryVideoUrl: null, + permanentVideoUrl: null, + archivedAt: null, + videoMetadata: null, }, ], }); @@ -1235,6 +1242,11 @@ export async function POST(request: Request) { parts: [{ type: "text", text: smartAutoFriendlyMessage }], attachments: [], createdAt: new Date(), + videoStorageStatus: null, + temporaryVideoUrl: null, + permanentVideoUrl: null, + archivedAt: null, + videoMetadata: null, }, ], }); diff --git a/components/messages.tsx b/components/messages.tsx index dc3208742..7da88f4df 100644 --- a/components/messages.tsx +++ b/components/messages.tsx @@ -236,7 +236,7 @@ function PureMessages({ else { setShowThinkingWithDelay(false); } - }, [status, messages, isGeminiModel, isQianwenVideoModel, isVolcanoVisionModel, isVideoModel, isAlibabaImageModel]); + }, [status, messages, isGeminiModel, isQianwenVideoModel, isVolcanoVisionModel, isVideoModel, isAlibabaImageModel, selectedModelId]); // 🆕 监听新消息添加,当用户发送带图片的消息或添加加载消息时,强制滚动到底部 const prevMessagesLengthRef = useRef(messages.length); @@ -365,9 +365,9 @@ function PureMessages({ // 🆕 检查智能自动模式是否有图片(需要显示生图占位图) const isAutoMode = selectedModelId === "auto"; - const userMessageHasImage = messages.length > 0 && - messages[messages.length - 1]?.role === "user" && - messages[messages.length - 1]?.parts?.some((p: any) => p.type === "file" || p.type === "image"); + // 🆕 找用户的最后一条消息(而不是整个对话的最后一条) + const lastUserMsg = [...messages].reverse().find(m => m.role === "user"); + const userMessageHasImage = lastUserMsg?.parts?.some((p: any) => p.type === "file" || p.type === "image"); const showAutoModeImage = isAutoMode && userMessageHasImage; if (showVideo) return ; diff --git a/lib/ai/smart-analyzer.ts b/lib/ai/smart-analyzer.ts index c14a9bbe3..a51365b6b 100644 --- a/lib/ai/smart-analyzer.ts +++ b/lib/ai/smart-analyzer.ts @@ -312,13 +312,16 @@ export function fallbackKeywordAnalysis( }; } - // 调色 - if (/调色|调整颜色|亮度|对比度|饱和度|色调|曝光|滤镜/.test(lowerText)) { + // 调色/改颜色 + if (/调色|调整颜色|亮度|对比度|饱和度|色调|曝光|滤镜|改成.*色|换成.*色|变成.*色|颜色改成|颜色换成|颜色变成/.test(lowerText)) { + // 提取目标颜色 + const colorMatch = text.match(/(?:改成|换成|变成)(.+?)(?:色|$)/); + const color = colorMatch ? colorMatch[1].trim() + "色" : ""; return { intent: "image_edit", subIntent: "color_adjust", confidence: 0.9, - conversationalReply: "收到,我来帮你调整图片色彩~", + conversationalReply: color ? `好的,我来帮你把颜色改成${color}~` : "收到,我来帮你调整图片色彩~", }; }