扩展Agent对话到全站生图模型并固定手动选模

This commit is contained in:
Your Name 2026-02-08 22:14:03 +08:00
parent d4baf61e1f
commit 3f61b27057
2 changed files with 32 additions and 5 deletions

View File

@ -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 ||

View File

@ -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) {