fix: 简化智能自动模式占位图逻辑
问题修复: 1. 移除复杂的延迟状态管理 2. 使用 isGeneratingImage 标记来区分阶段 3. 简化占位图显示条件 流程: 1. 提交/streaming -> 显示思考动画 2. 收到对话消息+GENERATING_IMAGE标记 -> 显示生图占位图 3. 收到图片 -> 隐藏占位图 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
98807b135a
commit
fbe797d436
@ -126,8 +126,6 @@ function PureMessages({
|
||||
|
||||
// 控制等待动画延迟消失(Gemini 图片模型延迟 4 秒,其他模型 6 秒)
|
||||
const [showThinkingWithDelay, setShowThinkingWithDelay] = useState(false);
|
||||
// 🆕 智能自动模式:收到对话消息后延迟显示生图占位图
|
||||
const [showImagePlaceholderDelayed, setShowImagePlaceholderDelayed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const lastMessage = messages.length > 0 ? messages[messages.length - 1] : null;
|
||||
@ -220,33 +218,23 @@ function PureMessages({
|
||||
// 根据模型类型设置延迟时间
|
||||
const delayTime = (isQianwenVideoModel || isVideoModel) ? 60000 : (isImageGenModel || isAutoModeWithImage) ? 4000 : 6000;
|
||||
|
||||
// 🆕 智能自动模式的占位图逻辑
|
||||
// 🆕 智能自动模式的占位图逻辑(简化版)
|
||||
if (isAutoModeWithImage) {
|
||||
if (hasImageContent) {
|
||||
// 图片已生成,延迟后隐藏占位图
|
||||
setShowImagePlaceholderDelayed(false);
|
||||
const timer = setTimeout(() => {
|
||||
setShowThinkingWithDelay(false);
|
||||
}, delayTime);
|
||||
return () => clearTimeout(timer);
|
||||
} else if (isGeneratingImage) {
|
||||
// 收到 GENERATING_IMAGE 标记,延迟6秒后显示生图占位图
|
||||
// 立即隐藏思考动画(因为对话文字已经显示了)
|
||||
setShowThinkingWithDelay(false);
|
||||
|
||||
// 延迟6秒后显示生图占位图
|
||||
const timer = setTimeout(() => {
|
||||
setShowImagePlaceholderDelayed(true);
|
||||
}, 6000);
|
||||
return () => clearTimeout(timer);
|
||||
} else if (status === "submitted" || (status === "streaming" && !hasTextContent)) {
|
||||
// 正在分析意图,显示普通思考动画
|
||||
// 收到 GENERATING_IMAGE 标记(对话消息已发送),继续显示占位图等待图片
|
||||
setShowThinkingWithDelay(true);
|
||||
} else if (status === "streaming" || status === "submitted") {
|
||||
// 正在处理中(分析意图或流式传输),显示占位图
|
||||
setShowThinkingWithDelay(true);
|
||||
setShowImagePlaceholderDelayed(false);
|
||||
} else {
|
||||
// 其他情况:隐藏所有占位图
|
||||
// ready 或其他状态:不显示占位图
|
||||
setShowThinkingWithDelay(false);
|
||||
setShowImagePlaceholderDelayed(false);
|
||||
}
|
||||
} else {
|
||||
// 非智能自动模式的原有逻辑
|
||||
@ -373,17 +361,6 @@ function PureMessages({
|
||||
messagesCount: messages.length,
|
||||
});
|
||||
|
||||
// 🆕 检查智能自动模式
|
||||
const isAutoMode = selectedModelId === "auto";
|
||||
const lastUserMsg = [...messages].reverse().find(m => m.role === "user");
|
||||
const userMessageHasImage = lastUserMsg?.parts?.some((p: any) => p.type === "file" || p.type === "image");
|
||||
|
||||
// 🆕 智能自动模式:使用延迟状态显示生图占位图
|
||||
if (isAutoMode && userMessageHasImage && showImagePlaceholderDelayed) {
|
||||
console.log("[Messages] ✅ 显示智能处理生图占位图 (延迟后)");
|
||||
return <ImageGenerationLoading imageCount={imageCount} maxImages={6} providerType="alibaba-image" modelName="智能处理" />;
|
||||
}
|
||||
|
||||
// 显示条件:正常等待动画 或 恢复的待处理状态
|
||||
const shouldShow = showThinkingWithDelay || hasRestoredPending;
|
||||
|
||||
@ -401,12 +378,33 @@ function PureMessages({
|
||||
const showAlibabaImage = modelType === "alibaba-image" || (!modelType && isAlibabaImageModel);
|
||||
const showVideo = modelType === "volcano-video" || modelType === "qianwen-video" || (!modelType && (isQianwenVideoModel || isVideoModel));
|
||||
|
||||
// 🆕 智能自动模式:检查用户是否发送了图片
|
||||
const isAutoMode = selectedModelId === "auto";
|
||||
const lastUserMsg = [...messages].reverse().find(m => m.role === "user");
|
||||
const userMessageHasImage = lastUserMsg?.parts?.some((p: any) => p.type === "file" || p.type === "image");
|
||||
|
||||
// 🆕 检查是否收到了 GENERATING_IMAGE 标记(表示对话已发送,开始生图)
|
||||
const hasGeneratingMarker = messages.some(msg =>
|
||||
msg.role === "assistant" && msg.parts?.some(
|
||||
(part: any) => part.type === "text" && part.text?.includes("<!-- GENERATING_IMAGE -->")
|
||||
)
|
||||
);
|
||||
|
||||
if (showVideo) return <QianwenVideoLoading />;
|
||||
if (showGemini) return <GeminiImageLoading imageCount={imageCount} />;
|
||||
if (showVolcano) return <VolcanoVisionLoading imageCount={imageCount} />;
|
||||
if (showAlibabaImage) return <ImageGenerationLoading imageCount={imageCount} maxImages={6} providerType="alibaba-image" modelName={currentModelDisplayName} />;
|
||||
// 🆕 智能自动模式:分析阶段显示思考动画
|
||||
if (isAutoMode && userMessageHasImage) return <ThinkingMessage />;
|
||||
|
||||
// 🆕 智能自动模式占位图
|
||||
if (isAutoMode && userMessageHasImage) {
|
||||
// 如果已经收到了 GENERATING_IMAGE 标记,显示生图占位图
|
||||
if (hasGeneratingMarker) {
|
||||
return <ImageGenerationLoading imageCount={imageCount} maxImages={6} providerType="alibaba-image" modelName="智能处理" />;
|
||||
}
|
||||
// 否则显示思考动画
|
||||
return <ThinkingMessage />;
|
||||
}
|
||||
|
||||
// 其他情况显示通用思考动画
|
||||
return <ThinkingMessage />;
|
||||
})()}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user