fix(agent): never fallback to video model in auto image flow
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-02-19 02:50:36 +08:00
parent 485571b8eb
commit 794ab44fe8

View File

@ -1922,7 +1922,12 @@ export async function POST(request: Request) {
// 简单回退:有图选图片模型,无图选默认模型
let bestModel = null;
if (hasImage) {
bestModel = allModels.find(m => m.model.supportsImageGen && !m.model.isSubModel);
bestModel = allModels.find(
(m) =>
m.model.supportsImageGen &&
!m.model.isSubModel &&
!isVideoProviderType(m.provider?.type),
);
if (isAutoTimeout) {
smartAutoFriendlyMessage = buildAutoModeFallbackMessage({
text: autoTextForFallback,
@ -1948,10 +1953,14 @@ export async function POST(request: Request) {
});
}
if (!bestModel) {
bestModel = allModels.find(m => m.model.isDefault && !m.model.isSubModel);
bestModel = allModels.find(
(m) => m.model.isDefault && !m.model.isSubModel && !isVideoProviderType(m.provider?.type),
);
}
if (!bestModel && allModels.length > 0) {
bestModel = allModels.find(m => !m.model.isSubModel) || allModels[0];
bestModel = allModels.find(
(m) => !m.model.isSubModel && !isVideoProviderType(m.provider?.type),
) || allModels.find((m) => !m.model.isSubModel) || allModels[0];
}
if (shouldKeepSelectedModel) {
@ -1967,6 +1976,50 @@ export async function POST(request: Request) {
}
// ========== End Smart Auto Mode Logic ==========
if (shouldRunAgentConversation && !allowAgentVideoGeneration) {
const finalModelIsUuid =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(finalModelId);
let finalProviderType: string | undefined;
if (finalModelIsUuid) {
const finalModelConfig = await getAiModelById({ id: finalModelId }).catch(() => null);
if (finalModelConfig) {
finalProviderType = (
await getAiProviderById({ id: finalModelConfig.providerId }).catch(() => null)
)?.type as string | undefined;
}
}
if (isVideoProviderType(finalProviderType)) {
const allModels = await getEnabledAiModelsWithProvider(false);
const fallbackModel =
allModels.find(
(m) =>
!m.model.isSubModel &&
m.model.supportsImageGen &&
!isVideoProviderType(m.provider?.type),
) ||
allModels.find(
(m) =>
!m.model.isSubModel &&
!isVideoProviderType(m.provider?.type),
);
if (fallbackModel) {
const hasImageInput = message.parts.some((part: any) =>
part?.type === "file" || part?.type === "image" || part?.type === "image_url"
);
smartAutoDetectedIntent = hasImageInput ? "image_edit" : "image_gen";
finalModelId = fallbackModel.model.id;
smartAutoVideoPlan = undefined;
smartAutoRecommendedVideoParams = undefined;
console.log(
`[Smart Auto Mode] 🚫 Safety override: replace video model (${finalProviderType}) with ${fallbackModel.model.displayName}`,
);
}
}
}
if (
shouldRunAgentConversation &&
!smartAutoNeedsClarification &&