fix: use agent default for agent replies
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-03-14 13:00:42 +08:00
parent 161c04e23e
commit d1bcb7ce16

View File

@ -66,6 +66,7 @@ import {
saveMessages,
updateMessageById,
updateChatLastContextById,
getAgentAiModelWithProvider,
getAiModelById,
getEnabledAiModelsWithProvider,
getSubModelsByParentModelId,
@ -3034,6 +3035,7 @@ export async function POST(request: Request) {
let confirmedPromptForConversationState: string | undefined;
let smartAutoHistoryMessagesFromDb: DBMessage[] = [];
let preferredAgentModelId: string | undefined;
let configuredAgentConversationModelId: string | undefined;
let pendingGridConfirmation:
| PendingGridConfirmation
| null = null;
@ -3107,6 +3109,8 @@ export async function POST(request: Request) {
if (isAiModelAgentAuto(selectedModelConfig)) {
shouldRunAgentConversation = true;
shouldKeepSelectedModel = false;
preferredAgentModelId = selectedModelConfig.id;
configuredAgentConversationModelId = selectedModelConfig.id;
console.log(
`[Smart Auto Mode] 🧠 Agent-only model detected, force auto routing: ${selectedModelConfig.displayName}`
);
@ -3130,6 +3134,21 @@ export async function POST(request: Request) {
}
}
if (shouldRunAgentConversation && !preferredAgentModelId) {
const configuredAgentModel = await getAgentAiModelWithProvider().catch((agentModelError) => {
console.warn("[Chat API] Failed to load configured agent model:", agentModelError);
return null;
});
if (configuredAgentModel?.model?.id) {
preferredAgentModelId = configuredAgentModel.model.id;
configuredAgentConversationModelId = configuredAgentModel.model.id;
console.log(
`[Smart Auto Mode] 🧠 Loaded configured agent conversation model: ${configuredAgentModel.model.displayName}`,
);
}
}
const allowAgentVideoGeneration =
Boolean(requestBody.videoParams) || isVideoProviderType(requestedModelProviderType);
let smartAutoWorkflowDecision:
@ -4306,6 +4325,20 @@ export async function POST(request: Request) {
smartAutoFriendlyMessage = normalizeAgentReportForDisplay(smartAutoFriendlyMessage);
}
if (
shouldRunAgentConversation &&
!shouldKeepSelectedModel &&
smartAutoExecution?.shouldStayConversational &&
preferredAgentModelId
) {
if (finalModelId !== preferredAgentModelId) {
finalModelId = preferredAgentModelId;
console.log(
`[Smart Auto Mode] 🧠 Conversational reply follows agent default model: ${configuredAgentConversationModelId || preferredAgentModelId}`,
);
}
}
const session = await auth();
if (!session?.user) {