Add LKGP cache exports and storage functions

This commit is contained in:
oyi77 2026-04-03 04:49:41 +07:00
parent 08f1f05d58
commit 22656c8699
2 changed files with 29 additions and 0 deletions

View file

@ -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");
}

View file

@ -158,6 +158,8 @@ export {
getCachedSettings,
getCachedPricing,
getCachedProviderConnections,
getCachedLKGP,
setCachedLKGP,
invalidateDbCache,
} from "./db/readCache";