Merge PR #899: fix(model-sync) into release/v3.4.2

This commit is contained in:
diegosouzapw
2026-04-01 19:28:59 -03:00
2 changed files with 11 additions and 2 deletions
+1 -1
View File
@@ -258,7 +258,7 @@ export async function DELETE(request) {
// DELETE /api/provider-models?provider=<id>&all=true — clear all models
const all = searchParams.get("all");
if (all === "true") {
await replaceCustomModels(provider, []);
await replaceCustomModels(provider, [], { allowEmpty: true });
return Response.json({ cleared: true });
}
+10 -1
View File
@@ -383,8 +383,17 @@ export async function replaceCustomModels(
source?: string;
apiFormat?: string;
supportedEndpoints?: string[];
}>
}>,
{ allowEmpty = false }: { allowEmpty?: boolean } = {}
) {
// Guard: skip destructive clear when the caller hasn't explicitly opted in.
// This prevents auto-sync from wiping manually-imported models when the
// upstream /models endpoint fails, times out, or returns an empty list.
if (models.length === 0 && !allowEmpty) {
const existing = await getCustomModels(providerId);
return Array.isArray(existing) ? existing : [];
}
const db = getDbInstance();
const existing = await getCustomModels(providerId);
const existingMap = new Map<string, JsonRecord>();