fix(usage): harden models.dev analytics integration

This commit is contained in:
Tam Nhu Tran committed 2026-04-28 15:25:58 -04:00
1 parent a38c1a75ba
commit a538627933
9 files changed
+161 -46

No files matched your search

@@ -9,6 +9,8 @@ const CACHE_FILE_NAME = 'models-dev-registry-cache.json';
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
const LIVE_FETCH_TIMEOUT_MS = 3000;
let pendingBackgroundRefresh: Promise<ModelsDevRegistry | null> | null = null;
export interface RegistryCacheReadOptions {
allowStale?: boolean;
now?: number;
@@ -131,3 +133,17 @@ export async function refreshModelsDevRegistry(
clearTimeout(timeoutId);
}
}
export function startModelsDevRegistryRefresh(
options: RegistryRefreshOptions = {}
): Promise<ModelsDevRegistry | null> {
if (!pendingBackgroundRefresh) {
pendingBackgroundRefresh = refreshModelsDevRegistry(options)
.catch(() => null)
.finally(() => {
pendingBackgroundRefresh = null;
});
}
return pendingBackgroundRefresh;
}