fix(catalog): skip static PROVIDER_MODELS when synced models exist (#2625)

Integrated into release/v3.8.3
This commit is contained in:
Hernan Javier Ardila Sanchez
2026-05-23 22:06:27 +02:00
committed by GitHub
parent ceab23803d
commit fcc21aaa61

View File

@@ -18,7 +18,7 @@ import { getAllMusicModels } from "@omniroute/open-sse/config/musicRegistry";
import { REGISTRY } from "@omniroute/open-sse/config/providerRegistry";
import { CODEX_NATIVE_UNPREFIXED_MODELS } from "@omniroute/open-sse/services/model";
import { resolveNestedComboTargets } from "@omniroute/open-sse/services/combo";
import { getAllSyncedAvailableModels } from "@/lib/db/models";
import { getAllSyncedAvailableModels, type SyncedAvailableModel } from "@/lib/db/models";
import { getCompatibleFallbackModels } from "@/lib/providers/managedAvailableModels";
import { hasEligibleConnectionForModel } from "@/domain/connectionModelRules";
import {
@@ -596,6 +596,22 @@ export async function getUnifiedModelsResponse(
});
}
// Resolve synced available models (from auto-sync) — used to skip static
// PROVIDER_MODELS entries for providers that have a live, API-fresh list.
let syncedModelsByProvider: Record<string, SyncedAvailableModel[]> = {};
try {
syncedModelsByProvider = await getAllSyncedAvailableModels();
} catch (e) {
// DB unavailable — log and fall through; static models remain as defaults.
console.log("[catalog] Could not fetch synced available models:", e);
}
const providersWithSyncedModels = new Set(
Object.keys(syncedModelsByProvider).filter((pid) => {
const models = syncedModelsByProvider[pid];
return Array.isArray(models) && models.length > 0;
})
);
// Add provider models (chat)
for (const [alias, providerModels] of Object.entries(PROVIDER_MODELS)) {
const providerId = aliasToProviderId[alias] || alias;
@@ -609,6 +625,10 @@ export async function getUnifiedModelsResponse(
continue;
}
// Skip static models for providers that have synced available models
// (auto-sync provides the authoritative, up-to-date list from the API).
if (providersWithSyncedModels.has(canonicalProviderId)) continue;
for (const model of providerModels) {
if (!providerSupportsModel(canonicalProviderId, model.id)) continue;
const aliasId = `${alias}/${model.id}`;
@@ -676,7 +696,8 @@ export async function getUnifiedModelsResponse(
}
try {
const syncedModelsByProvider = await getAllSyncedAvailableModels();
// Data already loaded above into syncedModelsByProvider; the try block
// here protects the for-loop / model processing from unexpected errors.
for (const [providerId, syncedModels] of Object.entries(syncedModelsByProvider)) {
if (!Array.isArray(syncedModels) || syncedModels.length === 0) continue;
if (blockedProviders.has(providerId)) continue;