import { DATASET } from '$lib/types'; const REF = 'main'; export type FetchOpts = { fetch?: typeof fetch; signal?: AbortSignal }; /** Build a `huggingface.co/datasets//resolve/main/` URL. */ export function resolveUrl(repoPath: string): string { return `https://huggingface.co/datasets/${DATASET}/resolve/${REF}/${repoPath}`; } export type TreeEntry = { type: 'file' | 'directory'; path: string; size?: number }; /** List entries under `/` via the HF tree API. */ export async function listTree(dirPath: string, opts: FetchOpts = {}): Promise { const fetchFn = opts.fetch ?? fetch; const url = `https://huggingface.co/api/datasets/${DATASET}/tree/${REF}/${dirPath}`; const r = await fetchFn(url, { signal: opts.signal }); if (!r.ok) throw new Error(`tree ${dirPath}: ${r.status}`); return (await r.json()) as TreeEntry[]; }