interface ModelsDevCache { data: any; etag: string | null; lastFetched: number; } let modelsDevCache: ModelsDevCache = { data: null, etag: null, lastFetched: 0, }; const MODELS_DEV_URL = 'https://models.dev/api.json'; const CACHE_TTL = 60 * 1000; // 60 seconds export async function getModelsDevData(): Promise { const now = Date.now(); if (modelsDevCache.data && (now - modelsDevCache.lastFetched < CACHE_TTL)) { return modelsDevCache.data; } try { const headers: HeadersInit = {}; if (modelsDevCache.etag) { headers['If-None-Match'] = modelsDevCache.etag; } const response = await fetch(MODELS_DEV_URL, { headers }); if (response.status === 304) { modelsDevCache.lastFetched = now; return modelsDevCache.data; } const newData = await response.json(); const newEtag = response.headers.get('ETag') || null; modelsDevCache = { data: newData, etag: newEtag, lastFetched: now, }; return newData; } catch (error) { console.error('Error fetching models.dev:', error); return modelsDevCache.data || {}; } }