/** The Hugging Face Hub as three requests: the snapshot (commit sha and * file list), the signed CDN URL for one file, and one byte range of it. * Every request leaves through `request`, which refuses a URL that is * not https and sends the token to the hub host only. */ export declare const DEFAULT_HUB_URL = "https://huggingface.co"; export declare const GATED_MESSAGE = "This repo is gated. Set HF_TOKEN to a Hugging Face token that has accepted its terms."; export type HubFile = { path: string; size: number; sha256?: string; }; export type HubSnapshot = { repo: string; revision: string; files: HubFile[]; }; export type HubOptions = { hubUrl?: string; token?: string; fetch?: typeof fetch; /** Tests run a fake hub over http. Nothing else sets this. */ allowHttp?: boolean; /** A range request that delivers no bytes for this long is abandoned * and retried. Default one minute. */ stallTimeoutMs?: number; /** Cancels every request. A download stops without retrying. */ signal?: AbortSignal; }; export type Chunk = { path: string; index: number; start: number; end: number; }; /** Thrown when the CDN refuses a signed URL, which is what an expired * signature looks like. The caller resolves the file again. */ export declare class Expired extends Error { } export declare class HubClient { private readonly options; private readonly hubUrl; private readonly hubHost; constructor(options?: HubOptions); /** The commit and the file list, with a size for every file and a * sha256 for every LFS file. `revision` defaults to `main`; a given * one may be a short sha. Gated repos need `token`. */ fetchSnapshot(repo: string, revision: string | undefined): Promise; /** Follows `resolve/` to the URL a file's bytes come from. Each hop is * resolved against the URL it came from, since the Hub sends relative * locations. The walk stops at the first URL off the hub host, which * is the signed CDN URL, or at a 200 from the hub itself, which is how * it serves a small non-LFS file. */ resolveFileUrl(snapshot: HubSnapshot, filePath: string): Promise; /** Streams one byte range of a file to `sink`, a piece at a time, and * checks the server's idea of the file size and the range against the * tree. Throws `Expired` on a 403. */ fetchRange(url: string, chunk: Chunk, size: number, sink: (piece: Uint8Array) => void): Promise; private hasToken; /** Every request goes through here. Refuses http, attaches the token * when the URL is on the hub host, and turns a 401 or 403 into a * message that says whether a token was sent. Redirects are never * followed by `fetch` itself, so no hop can skip the https check; * `resolveFileUrl` walks its own. */ private request; private json; /** Follows the `Link: <…>; rel="next"` header the tree API sends for a * repo with more entries than one page holds. */ private fetchTree; private requireHttps; } /** The downloader writes its record as `.agency-model.json` and moves a * file that fails its hash to `.invalidSha`. A repo file with * either name would collide with those, so such a repo is refused. * Case is ignored, for case-insensitive filesystems. */ export declare function isReservedPath(filePath: string): boolean; /** One small file of a snapshot, read into memory as text, without writing * anything to disk. For a file the downloader needs to read before it * decides what else to fetch. */ export declare function fetchHubFileText(snapshot: HubSnapshot, filePath: string, options?: HubOptions): Promise; /** The snapshot for a repo, for callers that need nothing else from the hub. */ export declare function fetchHubSnapshot(repo: string, revision: string | undefined, options?: HubOptions): Promise;