mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
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:
@@ -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 }),
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user