fix: 完善智能自动模式对话流程
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

修复内容:
1. 前端:检查用户最后一条消息是否有图片(而不是整个对话最后一条)
2. 前端:useEffect 依赖项添加 selectedModelId
3. 后端:错误回退时也生成友好消息
4. 后端:保存消息时添加完整的数据库字段
5. 分析器:增加颜色调整关键词匹配(改成X色、换成X色)

现在大模型(Qwen3 VL)会生成自然对话回复

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Your Name 2026-02-01 02:18:30 +08:00
parent ddada59db1
commit 231d726b37
3 changed files with 22 additions and 7 deletions

View File

@ -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,
},
],
});

View File

@ -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 <QianwenVideoLoading />;

View File

@ -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}~` : "收到,我来帮你调整图片色彩~",
};
}