fix: align agent avatar with auto image model setting
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-20 17:51:10 +08:00
parent 40a1b429ea
commit 9cb6a779c3

View File

@ -3,6 +3,7 @@ import {
getAgentAiModelWithProvider,
getDefaultAiModel,
getEnabledAiModelsWithProvider,
getSiteSettings,
} from "@/lib/db/queries";
import { ChatSDKError } from "@/lib/errors";
import { isAiModelAgentAuto } from "@/lib/db/ai-model-flags";
@ -33,6 +34,7 @@ export async function GET() {
const modelsWithProvider = await getEnabledAiModelsWithProvider(false);
const agentModelWithProvider = await getAgentAiModelWithProvider();
const defaultModel = await getDefaultAiModel();
const siteSettings = await getSiteSettings();
const visibleModelsWithProvider = sortModelsForDisplay(
modelsWithProvider
.filter(({ model }) => !isAiModelAgentAuto(model))
@ -66,6 +68,32 @@ export async function GET() {
sortOrder: model.sortOrder ?? 0,
}));
// Agent 模式在前端展示头像/参数时,优先使用“Agent模式 - 默认生图模型”的配置
// 避免展示成分析模型(如视觉模型)的头像,导致与管理员设置不一致
const imageGenModelsWithProvider = visibleModelsWithProviderSorted.filter(
({ model }) => model.supportsImageGen
);
const configuredAutoImageModelId =
typeof siteSettings?.canvasAutoModeDefaultModelId === "string"
? siteSettings.canvasAutoModeDefaultModelId.trim()
: "";
const configuredAutoImageModel = configuredAutoImageModelId
? imageGenModelsWithProvider.find(
({ model }) => model.id === configuredAutoImageModelId
)
: undefined;
const defaultImageGenModel =
(defaultModel &&
!isAiModelAgentAuto(defaultModel) &&
defaultModel.supportsImageGen
? imageGenModelsWithProvider.find(({ model }) => model.id === defaultModel.id)
: undefined) || imageGenModelsWithProvider[0];
const agentDisplayModelWithProvider =
configuredAutoImageModel ||
defaultImageGenModel ||
agentModelWithProvider ||
null;
const resolvedDefaultModelId =
(defaultModel &&
!isAiModelAgentAuto(defaultModel) &&
@ -78,13 +106,13 @@ export async function GET() {
return Response.json({
models,
defaultModelId: resolvedDefaultModelId,
agentModel: agentModelWithProvider
agentModel: agentDisplayModelWithProvider
? {
id: agentModelWithProvider.model.id,
displayName: agentModelWithProvider.model.displayName,
avatarUrl: agentModelWithProvider.model.avatarUrl,
providerType: agentModelWithProvider.provider.type,
imageGenConfig: agentModelWithProvider.model.imageGenConfig,
id: agentDisplayModelWithProvider.model.id,
displayName: agentDisplayModelWithProvider.model.displayName,
avatarUrl: agentDisplayModelWithProvider.model.avatarUrl,
providerType: agentDisplayModelWithProvider.provider.type,
imageGenConfig: agentDisplayModelWithProvider.model.imageGenConfig,
}
: null,
});