Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
refactor(model-sync): move empty-list guard to early return
tombiic214c6c12018
diff --git a/src/lib/db/models.ts b/src/lib/db/models.tsindex 9c1538e102..74234a7f12 100644--- a/src/lib/db/models.ts+++ b/src/lib/db/models.ts@@ -386,6 +386,14 @@ export async function replaceCustomModels(}>,{ 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>();@@ -421,12 +429,6 @@ export async function replaceCustomModels(});if (merged.length === 0) {- // 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 (!allowEmpty) {- return Array.isArray(existing) ? existing : [];- }db.prepare("DELETE FROM key_value WHERE namespace = 'customModels' AND key = ?").run(providerId);