fix: filter registry models from auto-sync to prevent duplicates

The model sync scheduler and sync-models endpoint were blindly
replacing custom models with all fetched models, including ones
already in the built-in registry. Now filters out registry models
before saving to custom models.
This commit is contained in:
Chris Staley
2026-03-29 14:23:25 -06:00
parent 0b133fe55e
commit 8e17756bf8
2 changed files with 11 additions and 10 deletions

View File

@@ -1460,14 +1460,6 @@ export default function ProviderDetailPage() {
return;
}
setImportProgress((prev) => ({
...prev,
phase: "importing",
total: fetchedModels.length,
status: t("importingModelsProgress", { current: 0, total: fetchedModels.length }),
logs: [t("foundModelsStartingImport", { count: fetchedModels.length })],
}));
const existingIds = new Set([
...(modelMeta.customModels || []).map((m: any) => m.id),
...models.map((m: any) => m.id),
@@ -1483,6 +1475,8 @@ export default function ProviderDetailPage() {
status: t("allModelsAlreadyImported") || "All models already imported",
logs: [t("noNewModelsToImport") || "No new models to import"],
importedCount: 0,
total: 0,
current: 0,
}));
return;
}
@@ -1490,7 +1484,8 @@ export default function ProviderDetailPage() {
setImportProgress((prev) => ({
...prev,
phase: "importing",
total: fetchedModels.length,
total: newModels.length,
current: 0,
status: t("importingModelsProgress", { current: 0, total: newModels.length }),
logs: [
t("foundModelsStartingImport", { count: newModels.length }),

View File

@@ -7,6 +7,7 @@ import {
buildModelSyncInternalHeaders,
isModelSyncInternalRequest,
} from "@/shared/services/modelSyncScheduler";
import { getModelsByProviderId } from "@/shared/constants/models";
/**
* POST /api/providers/[id]/sync-models
@@ -75,6 +76,11 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:
const fetchedModels = modelsData.models || [];
// Filter out models already in the built-in registry
const registryIds = new Set(
getModelsByProviderId(connection.provider).map((m: any) => m.id)
);
// Replace the full model list
const models = fetchedModels
.map((m: any) => ({
@@ -82,7 +88,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:
name: m.name || m.displayName || m.id || m.model,
source: "auto-sync",
}))
.filter((m: any) => m.id);
.filter((m: any) => m.id && !registryIds.has(m.id));
const replaced = await replaceCustomModels(connection.provider, models);