fix: skip incompatible Pascal model providers

This commit is contained in:
134 2026-07-11 23:10:44 +08:00
parent 7bb1f06b11
commit 22069ada66
2 changed files with 15 additions and 27 deletions

View File

@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { getProviderDefaultBaseUrl } from "@/lib/ai/provider-defaults";
import { resolveModelRuntimeId } from "@/lib/ai/model-runtime";
import { getMultimodalAiModelWithProvider } from "@/lib/db/queries";
import { getMultimodalAiModelsWithProvider } from "@/lib/db/queries";
import { createLogger } from "@/lib/observability/logger";
import { isPascalInternalRequest } from "@/lib/pascal/internal-auth";
@ -31,12 +31,19 @@ function openAiError(message: string, status: number) {
);
}
async function getConfiguredMultimodalModel() {
const candidates = await getMultimodalAiModelsWithProvider();
return candidates.find(({ provider }) =>
OPENAI_COMPATIBLE_PROVIDER_TYPES.has(provider.type)
);
}
export async function GET(request: Request) {
if (!isPascalInternalRequest(request)) {
return NextResponse.json({ error: "not_found" }, { status: 404 });
}
const configured = await getMultimodalAiModelWithProvider();
const configured = await getConfiguredMultimodalModel();
if (!configured) {
return NextResponse.json({ configured: false, selection: "multimodal" });
}
@ -67,7 +74,7 @@ export async function POST(request: Request) {
return openAiError("Invalid JSON body.", 400);
}
const configured = await getMultimodalAiModelWithProvider();
const configured = await getConfiguredMultimodalModel();
if (!configured) {
return openAiError("No enabled multimodal model is configured.", 503);
}

View File

@ -4782,31 +4782,12 @@ export async function getAgentAiModelWithProvider() {
return candidates[0];
}
export async function getMultimodalAiModelWithProvider() {
export async function getMultimodalAiModelsWithProvider() {
const models = await getEnabledAiModelsWithProvider(false);
const healthPriority = (status?: string | null) => {
if (status === "healthy") return 0;
if (status === "degraded") return 1;
if (status === "auto_disabled") return 2;
return 3;
};
const candidates = models
.filter(
({ model }) =>
isAiModelMultimodal(model) && model.healthStatus !== "auto_disabled"
)
.sort((a, b) => {
const byHealth =
healthPriority(a.model.healthStatus) -
healthPriority(b.model.healthStatus);
if (byHealth !== 0) return byHealth;
if (a.model.isDefault !== b.model.isDefault) {
return Number(b.model.isDefault) - Number(a.model.isDefault);
}
return (a.model.sortOrder ?? 0) - (b.model.sortOrder ?? 0);
});
return candidates[0];
return models.filter(
({ model }) =>
isAiModelMultimodal(model) && model.healthStatus !== "auto_disabled"
);
}
/**