import { createStore, get, set, del } from "idb-keyval" const fileCacheStore = createStore("supermemory-file-cache", "blobs") interface CachedFile { blob: Blob mimeType: string } export async function cacheFileBlob( documentId: string, blob: Blob, mimeType: string, ): Promise { try { await set( documentId, { blob, mimeType } satisfies CachedFile, fileCacheStore, ) } catch { // Storage full or unavailable — non-critical, skip silently } } export async function getCachedFileBlob( documentId: string, ): Promise { try { const cached = await get(documentId, fileCacheStore) return cached?.blob ?? null } catch { return null } } export async function getCachedFileUrl( documentId: string, ): Promise { const blob = await getCachedFileBlob(documentId) if (!blob) return null return URL.createObjectURL(blob) } export async function removeCachedFile(documentId: string): Promise { try { await del(documentId, fileCacheStore) } catch { // non-critical } }