import type { Model } from "@utils/models.ts"; const ORIGIN = "https://huggingface.co"; export const isModelCached = async (model: Model): Promise => { try { const cache = await caches.open("transformers-cache"); const keys = await cache.keys(); const cachedUrls = keys.map((req) => req.url); const filesUrls = Object.keys(model.files).map( (file) => `${ORIGIN}/${model.modelId}/resolve/main/${file}` ); return filesUrls.every((url) => cachedUrls.includes(url)); } catch (error) { console.error("Error checking model cache:", error); return false; } };