import type { Catalog, SearchResponse } from "./types"; export const REPO = "https://github.com/openai/math"; export const blob = (path: string) => `${REPO}/blob/main/${path}`; export const tree = (path: string) => `${REPO}/tree/main/${path}`; export async function fetchCatalog(): Promise { const res = await fetch("/api/catalog"); if (!res.ok) throw new Error(`catalog: ${res.status}`); return res.json(); } const cache = new Map(); export async function search(q: string, signal?: AbortSignal): Promise { const key = q.trim().toLowerCase(); const hit = cache.get(key); if (hit) return hit; const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`, { signal }); if (!res.ok) throw new Error(`search: ${res.status}`); const data: SearchResponse = await res.json(); cache.set(key, data); return data; }