@hasna/models 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -2806,6 +2806,15 @@ import { pipeline } from "stream/promises";
2806
2806
  import { Readable } from "stream";
2807
2807
  import { randomUUID } from "crypto";
2808
2808
  var HF_ENDPOINT = process.env["HF_ENDPOINT"] || "https://huggingface.co";
2809
+
2810
+ class HuggingFaceApiError extends Error {
2811
+ status;
2812
+ constructor(response, body) {
2813
+ super(`Hugging Face request failed ${response.status} ${response.statusText}: ${body.slice(0, 300)}`);
2814
+ this.name = "HuggingFaceApiError";
2815
+ this.status = response.status;
2816
+ }
2817
+ }
2809
2818
  function apiBase() {
2810
2819
  return HF_ENDPOINT.replace(/\/+$/, "");
2811
2820
  }
@@ -2823,7 +2832,7 @@ async function hfJson(path, init) {
2823
2832
  });
2824
2833
  if (!response.ok) {
2825
2834
  const text = await response.text().catch(() => "");
2826
- throw new Error(`Hugging Face request failed ${response.status} ${response.statusText}: ${text.slice(0, 300)}`);
2835
+ throw new HuggingFaceApiError(response, text);
2827
2836
  }
2828
2837
  return response.json();
2829
2838
  }
@@ -2997,12 +3006,15 @@ async function getHuggingFaceInfo(refOrInput, defaultKind = "model") {
2997
3006
  }
2998
3007
  async function listHuggingFaceFiles(refOrInput, defaultKind = "model") {
2999
3008
  const ref = typeof refOrInput === "string" ? parseProviderRef(refOrInput, defaultKind) : refOrInput;
3000
- const treePath = `/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/tree/${encodeURIComponent(ref.revision)}?recursive=1&expand=1`;
3009
+ const revision = ref.revision || "main";
3010
+ const treePath = `/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/tree/${encodeURIComponent(revision)}?recursive=1&expand=1`;
3001
3011
  try {
3002
3012
  const raw = await hfJson(treePath);
3003
3013
  return raw.map((entry) => normalizeTreeFile(entry, ref)).filter((entry) => Boolean(entry));
3004
- } catch {
3005
- const info = await hfJson(`/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}`);
3014
+ } catch (error) {
3015
+ if (!(error instanceof HuggingFaceApiError) || error.status !== 404)
3016
+ throw error;
3017
+ const info = await hfJson(`/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/revision/${encodeURIComponent(revision)}`);
3006
3018
  const siblings = Array.isArray(info.siblings) ? info.siblings : [];
3007
3019
  return siblings.map((entry) => normalizeSibling(entry, ref)).filter((entry) => Boolean(entry));
3008
3020
  }
package/dist/index.js CHANGED
@@ -430,6 +430,15 @@ import { pipeline } from "stream/promises";
430
430
  import { Readable } from "stream";
431
431
  import { randomUUID } from "crypto";
432
432
  var HF_ENDPOINT = process.env["HF_ENDPOINT"] || "https://huggingface.co";
433
+
434
+ class HuggingFaceApiError extends Error {
435
+ status;
436
+ constructor(response, body) {
437
+ super(`Hugging Face request failed ${response.status} ${response.statusText}: ${body.slice(0, 300)}`);
438
+ this.name = "HuggingFaceApiError";
439
+ this.status = response.status;
440
+ }
441
+ }
433
442
  function apiBase() {
434
443
  return HF_ENDPOINT.replace(/\/+$/, "");
435
444
  }
@@ -447,7 +456,7 @@ async function hfJson(path, init) {
447
456
  });
448
457
  if (!response.ok) {
449
458
  const text = await response.text().catch(() => "");
450
- throw new Error(`Hugging Face request failed ${response.status} ${response.statusText}: ${text.slice(0, 300)}`);
459
+ throw new HuggingFaceApiError(response, text);
451
460
  }
452
461
  return response.json();
453
462
  }
@@ -621,12 +630,15 @@ async function getHuggingFaceInfo(refOrInput, defaultKind = "model") {
621
630
  }
622
631
  async function listHuggingFaceFiles(refOrInput, defaultKind = "model") {
623
632
  const ref = typeof refOrInput === "string" ? parseProviderRef(refOrInput, defaultKind) : refOrInput;
624
- const treePath = `/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/tree/${encodeURIComponent(ref.revision)}?recursive=1&expand=1`;
633
+ const revision = ref.revision || "main";
634
+ const treePath = `/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/tree/${encodeURIComponent(revision)}?recursive=1&expand=1`;
625
635
  try {
626
636
  const raw = await hfJson(treePath);
627
637
  return raw.map((entry) => normalizeTreeFile(entry, ref)).filter((entry) => Boolean(entry));
628
- } catch {
629
- const info = await hfJson(`/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}`);
638
+ } catch (error) {
639
+ if (!(error instanceof HuggingFaceApiError) || error.status !== 404)
640
+ throw error;
641
+ const info = await hfJson(`/api/${apiKind(ref.entityKind)}/${encodeRepoId(ref.repoId)}/revision/${encodeURIComponent(revision)}`);
630
642
  const siblings = Array.isArray(info.siblings) ? info.siblings : [];
631
643
  return siblings.map((entry) => normalizeSibling(entry, ref)).filter((entry) => Boolean(entry));
632
644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/models",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "CLI-first local model and dataset lifecycle tool for open-source/open-weight catalogs",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",