Skip to content

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

Add LKGP cache exports and storage functions

oyi7722656c86992d
diff --git a/src/lib/db/settings.ts b/src/lib/db/settings.ts
index f723748fbd..05e2fc0a2d 100644
--- a/src/lib/db/settings.ts
+++ b/src/lib/db/settings.ts
@@ -744,3 +744,30 @@ export async function resetCacheMetrics() {
);
return getCacheMetrics();
}
+
+// ──────────────── Last Known Good Provider (LKGP) ────────────────
+
+export async function getLKGP(comboName: string, modelId: string): Promise<string | null> {
+ const db = getDbInstance();
+ const key = `lkgp:${comboName}:${modelId}`;
+ const row = db
+ .prepare("SELECT value FROM key_value WHERE namespace = 'lkgp' AND key = ?")
+ .get(key);
+ if (!row) return null;
+ const record = toRecord(row);
+ return typeof record.value === "string" ? record.value : null;
+}
+
+export async function setLKGP(
+ comboName: string,
+ modelId: string,
+ providerId: string
+): Promise<void> {
+ const db = getDbInstance();
+ const key = `lkgp:${comboName}:${modelId}`;
+ db.prepare("INSERT OR REPLACE INTO key_value (namespace, key, value) VALUES ('lkgp', ?, ?)").run(
+ key,
+ providerId
+ );
+ backupDbFile("pre-write");
+}
diff --git a/src/lib/localDb.ts b/src/lib/localDb.ts
index 521416daa5..4a3aa106bd 100644
--- a/src/lib/localDb.ts
+++ b/src/lib/localDb.ts
@@ -158,6 +158,8 @@ export {
getCachedSettings,
getCachedPricing,
getCachedProviderConnections,
+ getCachedLKGP,
+ setCachedLKGP,
invalidateDbCache,
} from "./db/readCache";