diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index e59e631..13e4117 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -524,9 +524,30 @@ export async function POST(request: Request) { let smartAutoHistoryImages: string[] = []; // 从历史对话中提取的图片URL(支持多张) let smartAutoNeedsClarification = false; // 是否需要先追问用户 let smartAutoClarificationQuestion: string | undefined; + let shouldRunAgentConversation = finalModelId === "auto"; + let shouldKeepSelectedModel = false; + const requestedModelId = selectedChatModel; + + if (!shouldRunAgentConversation && requestedModelId !== "auto") { + const selectedModelIsUUID = + /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test( + requestedModelId + ); + + if (selectedModelIsUUID) { + const selectedModelConfig = await getAiModelById({ id: requestedModelId }); + if (selectedModelConfig?.supportsImageGen && !selectedModelConfig?.isSubModel) { + shouldRunAgentConversation = true; + shouldKeepSelectedModel = true; + console.log( + `[Smart Auto Mode] 🎯 Agent conversation enabled for fixed image model: ${selectedModelConfig.displayName}` + ); + } + } + } // ========== Smart Auto Mode Logic ========== - if (finalModelId === "auto") { + if (shouldRunAgentConversation) { console.log("[Smart Auto Mode] 🚀 Starting intelligent analysis..."); let autoTextForFallback = ""; let autoHasImageForFallback = false; @@ -698,9 +719,12 @@ export async function POST(request: Request) { }); } - if (autoGraphResult.route) { + if (autoGraphResult.route && !shouldKeepSelectedModel) { finalModelId = autoGraphResult.route.id; console.log(`[Smart Auto Mode] ✅ Routed to: ${autoGraphResult.route.displayName} (${autoGraphResult.route.reason})`); + } else if (autoGraphResult.route && shouldKeepSelectedModel) { + finalModelId = requestedModelId; + console.log("[Smart Auto Mode] 🔒 Keep user-selected model, skip routing override"); } } catch (autoError) { @@ -737,7 +761,10 @@ export async function POST(request: Request) { bestModel = allModels.find(m => !m.model.isSubModel) || allModels[0]; } - if (bestModel) { + if (shouldKeepSelectedModel) { + finalModelId = requestedModelId; + console.log("[Smart Auto Mode] 🔒 Keep user-selected model in fallback mode"); + } else if (bestModel) { finalModelId = bestModel.model.id; console.log(`[Smart Auto Mode] Fallback selected: ${bestModel.model.displayName}`); } else { @@ -858,7 +885,7 @@ export async function POST(request: Request) { const streamId = generateUUID(); await createStreamId({ streamId, chatId: id }); - if (selectedChatModel === "auto" && smartAutoNeedsClarification) { + if (shouldRunAgentConversation && smartAutoNeedsClarification) { const clarificationMessage = smartAutoClarificationQuestion || smartAutoFriendlyMessage || diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index d00d6e5..1ea191e 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -897,7 +897,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF const hiddenPrompt = hiddenSegments.join('\n\n').trim(); hiddenPromptRef.current = hiddenPrompt || null; - const autoContext = selectedModelId === "auto" ? buildAutoContext() : ""; + const autoContext = buildAutoContext(); autoContextRef.current = autoContext ? autoContext : null; if (textContent) {