brsh 3.3.1 → 3.5.0

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/wbt.es.js CHANGED
@@ -620,24 +620,24 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
620
620
  }), u.prototype.writeBigInt64BE = $(function(e, t = 0) {
621
621
  return G(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
622
622
  });
623
- function K(e, t, n, r, i, a) {
623
+ function ee(e, t, n, r, i, a) {
624
624
  if (n + r > e.length || n < 0) throw RangeError("Index out of range");
625
625
  }
626
- function q(e, t, r, i, a) {
627
- return t = +t, r >>>= 0, a || K(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
626
+ function K(e, t, r, i, a) {
627
+ return t = +t, r >>>= 0, a || ee(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
628
628
  }
629
629
  u.prototype.writeFloatLE = function(e, t, n) {
630
- return q(this, e, t, !0, n);
630
+ return K(this, e, t, !0, n);
631
631
  }, u.prototype.writeFloatBE = function(e, t, n) {
632
- return q(this, e, t, !1, n);
632
+ return K(this, e, t, !1, n);
633
633
  };
634
- function ee(e, t, r, i, a) {
635
- return t = +t, r >>>= 0, a || K(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
634
+ function q(e, t, r, i, a) {
635
+ return t = +t, r >>>= 0, a || ee(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
636
636
  }
637
637
  u.prototype.writeDoubleLE = function(e, t, n) {
638
- return ee(this, e, t, !0, n);
638
+ return q(this, e, t, !0, n);
639
639
  }, u.prototype.writeDoubleBE = function(e, t, n) {
640
- return ee(this, e, t, !1, n);
640
+ return q(this, e, t, !1, n);
641
641
  }, u.prototype.copy = function(e, t, n, r) {
642
642
  if (!u.isBuffer(e)) throw TypeError("argument should be a Buffer");
643
643
  if (n ||= 0, !r && r !== 0 && (r = this.length), t >= e.length && (t = e.length), t ||= 0, r > 0 && r < n && (r = n), r === n || e.length === 0 || this.length === 0) return 0;
@@ -1706,7 +1706,7 @@ function I(e, t) {
1706
1706
  this.fun = e, this.array = t;
1707
1707
  }
1708
1708
  function L() {}
1709
- var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
1709
+ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
1710
1710
  R = { exports: {} }, z = R.exports = {}, (function() {
1711
1711
  try {
1712
1712
  B = typeof setTimeout == "function" ? setTimeout : A;
@@ -1734,7 +1734,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
1734
1734
  throw Error("process.chdir is not supported");
1735
1735
  }, z.umask = function() {
1736
1736
  return 0;
1737
- }, K = R.exports, q = /* @__PURE__ */ k(K);
1737
+ }, ee = R.exports, K = /* @__PURE__ */ k(ee);
1738
1738
  })), J = /* @__PURE__ */ t(((e, t) => {
1739
1739
  var n = T();
1740
1740
  t.exports = class extends n {
@@ -1766,7 +1766,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
1766
1766
  }
1767
1767
  };
1768
1768
  })), Y = /* @__PURE__ */ t(((e, t) => {
1769
- b(), ee();
1769
+ b(), q();
1770
1770
  var { BinaryFile: n, SymlinkRef: r } = O(), i = new Uint8Array([
1771
1771
  66,
1772
1772
  82,
@@ -1903,8 +1903,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
1903
1903
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
1904
1904
  return new Uint8Array(r);
1905
1905
  }
1906
- if (q !== void 0 && typeof q.getBuiltinModule == "function") {
1907
- let t = q.getBuiltinModule("zlib");
1906
+ if (K !== void 0 && typeof K.getBuiltinModule == "function") {
1907
+ let t = K.getBuiltinModule("zlib");
1908
1908
  if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
1909
1909
  }
1910
1910
  throw Error("Gzip decompression is not supported in this environment");
@@ -1923,8 +1923,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
1923
1923
  return f(new Uint8Array(n), t);
1924
1924
  }
1925
1925
  if (typeof e == "string") {
1926
- if (!/^https?:\/\//i.test(e) && q !== void 0 && typeof q.getBuiltinModule == "function" && typeof window > "u") try {
1927
- let n = q.getBuiltinModule("fs");
1926
+ if (!/^https?:\/\//i.test(e) && K !== void 0 && typeof K.getBuiltinModule == "function" && typeof window > "u") try {
1927
+ let n = K.getBuiltinModule("fs");
1928
1928
  if (n && n.existsSync(e)) {
1929
1929
  let r = await n.promises.readFile(e);
1930
1930
  return f(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
@@ -2255,7 +2255,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
2255
2255
  })), ne = /* @__PURE__ */ t(((e, t) => {
2256
2256
  t.exports = null;
2257
2257
  })), re = /* @__PURE__ */ t(((e, t) => {
2258
- ee();
2258
+ q();
2259
2259
  function n(e) {
2260
2260
  if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
2261
2261
  }
@@ -2293,7 +2293,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
2293
2293
  resolve: function() {
2294
2294
  for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
2295
2295
  var o;
2296
- a >= 0 ? o = arguments[a] : (i === void 0 && (i = q.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
2296
+ a >= 0 ? o = arguments[a] : (i === void 0 && (i = K.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
2297
2297
  }
2298
2298
  return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
2299
2299
  },
@@ -3810,23 +3810,80 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3810
3810
  };
3811
3811
  })), oe = /* @__PURE__ */ t(((e, t) => {
3812
3812
  T();
3813
- var n = Z(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o = "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf", s = "https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm", c = "/var/cache/wllama", l = /* @__PURE__ */ new Map();
3814
- function u(e) {
3815
- if (!e) return `${c}/model.gguf`;
3813
+ var n = Z(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o = {
3814
+ smol: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3815
+ smollm: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3816
+ smollm2: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3817
+ "smol-135m": "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
3818
+ "smol-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
3819
+ "smollm-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
3820
+ "smollm2-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
3821
+ "smol-1.7b": "https://huggingface.co/bartowski/SmolLM2-1.7B-Instruct-GGUF/resolve/main/SmolLM2-1.7B-Instruct-Q4_K_M.gguf",
3822
+ qwen: "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
3823
+ "qwen2.5": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
3824
+ "qwen-0.5b": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
3825
+ "qwen2.5-0.5b": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
3826
+ "qwen-1.5b": "https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf",
3827
+ "qwen2.5-1.5b": "https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf",
3828
+ stories: "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf",
3829
+ stories15m: "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories15M.gguf"
3830
+ }, s = o.smol, c = "https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm", l = "/var/cache/wllama", u = /* @__PURE__ */ new Map();
3831
+ function d(e) {
3832
+ if (!e) return `${l}/model.gguf`;
3816
3833
  if (e.kind === "fs") return e.path;
3817
- if (e.kind === "hf-quant") return `${c}/${(e.repo || "model").split("/").pop().replace(/[^a-zA-Z0-9._-]/g, "_")}-${(e.quant || "Q4_K_M").replace(/[^a-zA-Z0-9._-]/g, "_")}.gguf`;
3818
- let t = (e.file || e.url || o).split("/").pop().split("?")[0] || "model.gguf";
3819
- return /\.gguf$/i.test(t) || (t += ".gguf"), `${c}/${t}`;
3834
+ if (e.kind === "hf-quant") return `${l}/${(e.repo || "model").split("/").pop().replace(/[^a-zA-Z0-9._-]/g, "_")}-${(e.quant || "Q4_K_M").replace(/[^a-zA-Z0-9._-]/g, "_")}.gguf`;
3835
+ let t = (e.file || e.url || s).split("/").pop().split("?")[0] || "model.gguf";
3836
+ return /\.gguf$/i.test(t) || (t += ".gguf"), `${l}/${t}`;
3820
3837
  }
3821
- function d(e, t, n, r = 20) {
3822
- let i = (e) => e >= 1024 * 1024 ? `${(e / (1024 * 1024)).toFixed(1)} MB` : e >= 1024 ? `${(e / (1024 * 1024)).toFixed(1)} KB` : `${e} B`, a = (e || "model.gguf").split("/").pop().split("?")[0] || e;
3838
+ function f(e) {
3839
+ return !e || e <= 0 ? "0 B" : e >= 1024 * 1024 * 1024 ? `${(e / (1024 * 1024 * 1024)).toFixed(1)} GB` : e >= 1024 * 1024 ? `${(e / (1024 * 1024)).toFixed(1)} MB` : e >= 1024 ? `${(e / 1024).toFixed(1)} KB` : `${e} B`;
3840
+ }
3841
+ function p(e, t, n, r = 20) {
3842
+ let i = (e || "model.gguf").split("/").pop().split("?")[0] || e;
3823
3843
  if (n > 0) {
3824
- let e = Math.max(0, Math.min(1, t / n)), o = Math.round(e * 100), s = Math.round(e * r);
3825
- return `\rPulling ${a}: [${"█".repeat(s) + "░".repeat(Math.max(0, r - s))}] ${String(o).padStart(3)}% (${i(t)} / ${i(n)})`;
3844
+ let e = Math.max(0, Math.min(1, t / n)), a = Math.round(e * 100), o = Math.round(e * r);
3845
+ return `\rPulling ${i}: [${"█".repeat(o) + "░".repeat(Math.max(0, r - o))}] ${String(a).padStart(3)}% (${f(t)} / ${f(n)})`;
3826
3846
  }
3827
- return `\rPulling ${a}: ${i(t)} downloaded...`;
3847
+ return `\rPulling ${i}: ${f(t)} downloaded...`;
3828
3848
  }
3829
- function f(e, t = null, n = null, r = null) {
3849
+ var m = class {
3850
+ constructor({ onRender: e = null, width: t = 20, intervalMs: n = 80, enabled: r = !0 } = {}) {
3851
+ this.onRender = e, this.width = t, this.intervalMs = n, this.enabled = r, this.label = "", this.total = 0, this.loaded = 0, this.hint = "", this.startTime = 0, this.step = 0, this.timer = null, this.active = !1, this.isDeterminate = !1;
3852
+ }
3853
+ start(e, { total: t = 0, loaded: n = 0, hint: r = "", determinate: i = null } = {}) {
3854
+ this.enabled && (this.stopTimer(), this.label = e || "Loading", this.total = t || 0, this.loaded = n || 0, this.hint = r || "", this.startTime = Date.now(), this.step = 0, this.active = !0, this.isDeterminate = i === null ? this.total > 0 && this.loaded > 0 : i, this.render(), this.timer = setInterval(() => {
3855
+ this.step++, this.render();
3856
+ }, this.intervalMs));
3857
+ }
3858
+ update({ loaded: e, total: t, hint: n } = {}) {
3859
+ !this.enabled || !this.active || (typeof t == "number" && t > 0 && (this.total = t, this.isDeterminate = !0), typeof e == "number" && e >= 0 && (this.loaded = e, this.total > 0 && (this.isDeterminate = !0)), typeof n == "string" && (this.hint = n), this.render());
3860
+ }
3861
+ formatLine() {
3862
+ let e = ((Date.now() - this.startTime) / 1e3).toFixed(1) + "s";
3863
+ if (this.isDeterminate && this.total > 0) {
3864
+ let t = Math.max(0, Math.min(1, this.loaded / this.total)), n = Math.round(t * 100), r = Math.round(t * this.width), i = "█".repeat(r) + "░".repeat(Math.max(0, this.width - r)), a = `${f(this.loaded)} / ${f(this.total)}`, o = this.hint ? ` (${this.hint})` : "";
3865
+ return `${this.label}: [${i}] ${String(n).padStart(3)}% (${a}, ${e})${o}`;
3866
+ }
3867
+ let t = Math.max(1, this.width - 5), n = t * 2, r = this.step % n, i = r < t ? r : n - r, a = `[${"░".repeat(i)}${"█".repeat(5)}${"░".repeat(Math.max(0, this.width - i - 5))}]`, o = this.hint ? ` (${this.hint})` : "";
3868
+ return `${this.label}: ${a} ${e}${o}`;
3869
+ }
3870
+ render() {
3871
+ !this.enabled || !this.active || typeof this.onRender != "function" || this.onRender(this.formatLine());
3872
+ }
3873
+ stopTimer() {
3874
+ this.timer !== null && (clearInterval(this.timer), this.timer = null);
3875
+ }
3876
+ finish(e = "Done") {
3877
+ if (!this.enabled || !this.active) return;
3878
+ this.stopTimer();
3879
+ let t = ((Date.now() - this.startTime) / 1e3).toFixed(1) + "s", n = "█".repeat(this.width), r = this.total > 0 ? `, ${f(this.total)}` : "", i = `${this.label}: [${n}] 100% (${t}${r}) — ${e}`;
3880
+ typeof this.onRender == "function" && this.onRender(i), this.active = !1;
3881
+ }
3882
+ clear() {
3883
+ this.stopTimer(), this.active = !1, this.enabled && typeof this.onRender == "function" && this.onRender("");
3884
+ }
3885
+ };
3886
+ function h(e, t = null, n = null, r = null) {
3830
3887
  if (t) {
3831
3888
  if (n) {
3832
3889
  let e = t.replace(/^hf:/i, "").replace(/^\/+|\/+$/g, ""), r = n.replace(/^\/+/, "");
@@ -3848,10 +3905,11 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3848
3905
  let i = (e || "").trim();
3849
3906
  if (!i) return {
3850
3907
  kind: "url",
3851
- key: o,
3852
- url: o
3908
+ key: s,
3909
+ url: s
3853
3910
  };
3854
- if (/^hf:\/\//i.test(i) || /^hf:/i.test(i)) {
3911
+ let a = i.toLowerCase();
3912
+ if (o[a] && (i = o[a]), /^hf:\/\//i.test(i) || /^hf:/i.test(i)) {
3855
3913
  let e = i.replace(/^hf:(\/\/)?/i, ""), t = e.match(/^([^/]+\/[^/:]+):([^/]+)$/);
3856
3914
  if (t) return {
3857
3915
  kind: "hf-quant",
@@ -3887,7 +3945,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3887
3945
  path: i
3888
3946
  };
3889
3947
  }
3890
- async function p(e, t) {
3948
+ async function g(e, t) {
3891
3949
  let n = await fetch(e);
3892
3950
  if (!n.ok) throw Error(`Failed to fetch model from ${e}: HTTP ${n.status}`);
3893
3951
  let r = Number(n.headers.get("content-length") || 0);
@@ -3912,8 +3970,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3912
3970
  let s = new Blob(a, { type: "application/octet-stream" });
3913
3971
  return s.name = e.split("/").pop().split("?")[0] || "model.gguf", s;
3914
3972
  }
3915
- async function m({ wllama: e, mod: t, modelSpec: n, downloadedBlob: r = null, targetPersistPath: a, fs: s, progressCallback: c }) {
3916
- if (!s || !a) return null;
3973
+ async function _({ wllama: e, mod: t, modelSpec: n, downloadedBlob: r = null, targetPersistPath: a, fs: o, progressCallback: c }) {
3974
+ if (!o || !a) return null;
3917
3975
  let l = null;
3918
3976
  if (r && typeof r.arrayBuffer == "function") l = new Uint8Array(await r.arrayBuffer());
3919
3977
  else if (e && typeof e.getLoadedBlob == "function") {
@@ -3927,7 +3985,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3927
3985
  }
3928
3986
  } catch {}
3929
3987
  if (!l) {
3930
- let e = n.url || (n.kind === "url" ? o : null);
3988
+ let e = n.url || (n.kind === "url" ? s : null);
3931
3989
  if (!e && n.kind === "hf-quant" && t && typeof t.getHFModelSource == "function") try {
3932
3990
  let r = await t.getHFModelSource({
3933
3991
  repo: n.repo,
@@ -3936,7 +3994,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3936
3994
  e = r.url || r;
3937
3995
  } catch {}
3938
3996
  if (e && typeof fetch == "function") try {
3939
- let t = await p(e, c);
3997
+ let t = await g(e, c);
3940
3998
  l = new Uint8Array(await t.arrayBuffer());
3941
3999
  } catch {}
3942
4000
  }
@@ -3949,33 +4007,33 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3949
4007
  0,
3950
4008
  0,
3951
4009
  0
3952
- ]), i(s, a, l, "application/octet-stream"), {
4010
+ ]), i(o, a, l, "application/octet-stream"), {
3953
4011
  path: a,
3954
4012
  size: l.byteLength
3955
4013
  };
3956
4014
  }
3957
- async function h(e = {}) {
3958
- let { modelSpec: t, mmprojSpec: n = null, loadParams: c = {}, fs: d, pkgMeta: f = {}, wbtConfig: h = {}, loadModel: g = !0, persist: _ = !1, persistPath: v = null, onStatus: y = null } = e;
3959
- typeof y == "function" && y("Initializing WASM runtime...");
3960
- let b = await a("@wllama/wllama", f.cdnUrl, h.moduleLoader), x = b.Wllama || b.default || b, S = b.LoggerWithoutDebug || void 0, C = f.wasmUrl || s;
3961
- if (f.wasmPath && d && typeof URL < "u" && typeof URL.createObjectURL == "function") {
3962
- let e = r(d, f.wasmPath);
3963
- e && e.byteLength > 0 && (C = URL.createObjectURL(new Blob([e], { type: "application/wasm" })));
3964
- }
3965
- let w = {
3966
- default: C,
3967
- "single-thread/wllama.wasm": C,
3968
- "multi-thread/wllama.wasm": C
3969
- }, T = () => {
4015
+ async function v(e = {}) {
4016
+ let { modelSpec: t, mmprojSpec: n = null, loadParams: o = {}, fs: l, pkgMeta: f = {}, wbtConfig: p = {}, loadModel: m = !0, persist: h = !1, persistPath: v = null, tracker: y = null, shortLabel: b = "model.gguf", isPullCommand: x = !1, onStatus: S = null } = e;
4017
+ typeof S == "function" && S("Initializing WASM runtime...");
4018
+ let C = await a("@wllama/wllama", f.cdnUrl, p.moduleLoader), w = C.Wllama || C.default || C, T = C.LoggerWithoutDebug || void 0, E = f.wasmUrl || c;
4019
+ if (f.wasmPath && l && typeof URL < "u" && typeof URL.createObjectURL == "function") {
4020
+ let e = r(l, f.wasmPath);
4021
+ e && e.byteLength > 0 && (E = URL.createObjectURL(new Blob([e], { type: "application/wasm" })));
4022
+ }
4023
+ let D = {
4024
+ default: E,
4025
+ "single-thread/wllama.wasm": E,
4026
+ "multi-thread/wllama.wasm": E
4027
+ }, O = () => {
3970
4028
  try {
3971
- return new x(w, {
4029
+ return new w(D, {
3972
4030
  suppressNativeLog: !0,
3973
- logger: S
4031
+ logger: T
3974
4032
  });
3975
4033
  } catch {
3976
- return new x(w, {
4034
+ return new w(D, {
3977
4035
  suppressNativeLog: !0,
3978
- logger: S,
4036
+ logger: T,
3979
4037
  cacheManager: {
3980
4038
  isSupported: () => !0,
3981
4039
  getNameFromURL: async (e) => e,
@@ -3986,135 +4044,181 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
3986
4044
  });
3987
4045
  }
3988
4046
  };
3989
- if (!g) return {
3990
- wllama: T(),
3991
- mod: b,
3992
- Wllama: x,
4047
+ if (!m) return {
4048
+ wllama: O(),
4049
+ mod: C,
4050
+ Wllama: w,
3993
4051
  modelKey: null,
3994
4052
  isCached: !1,
3995
4053
  persisted: null
3996
4054
  };
3997
- let E = v || (_ && t.kind !== "fs" ? u(t) : null), D = t.kind === "fs" ? null : u(t), O = t.kind === "fs" && d && typeof d.absolutePath == "function" ? `fs:${d.absolutePath(t.path)}:gpu=${c.n_gpu_layers ?? "auto"}:emb=${!!c.embeddings}` : `${t.key}:gpu=${c.n_gpu_layers ?? "auto"}:emb=${!!c.embeddings}`;
3998
- if (l.has(O)) {
3999
- let e = l.get(O);
4055
+ let k = v || (h && t.kind !== "fs" ? d(t) : null), A = t.kind === "fs" ? null : d(t), j = t.kind === "fs" && l && typeof l.absolutePath == "function" ? `fs:${l.absolutePath(t.path)}:gpu=${o.n_gpu_layers ?? "auto"}:emb=${!!o.embeddings}` : `${t.key}:gpu=${o.n_gpu_layers ?? "auto"}:emb=${!!o.embeddings}`;
4056
+ if (u.has(j)) {
4057
+ let e = u.get(j);
4000
4058
  if (typeof e.isModelLoaded != "function" || e.isModelLoaded()) {
4001
- typeof y == "function" && y("Loaded model from cache.");
4059
+ typeof S == "function" && S("Loaded model from cache."), y && y.finish("Loaded model from cache");
4002
4060
  let n = null;
4003
- if ((_ || v) && d && E) if (d.exists(E)) {
4004
- let e = r(d, E);
4061
+ if ((h || v) && l && k) if (l.exists(k)) {
4062
+ let e = r(l, k);
4005
4063
  n = {
4006
- path: E,
4064
+ path: k,
4007
4065
  size: e ? e.byteLength : 0
4008
4066
  };
4009
- } else n = await m({
4067
+ } else n = await _({
4010
4068
  wllama: e,
4011
- mod: b,
4069
+ mod: C,
4012
4070
  modelSpec: t,
4013
- targetPersistPath: E,
4014
- fs: d,
4015
- progressCallback: c.progressCallback
4071
+ targetPersistPath: k,
4072
+ fs: l,
4073
+ progressCallback: o.progressCallback
4016
4074
  });
4017
4075
  return {
4018
4076
  wllama: e,
4019
- mod: b,
4020
- Wllama: x,
4021
- modelKey: O,
4077
+ mod: C,
4078
+ Wllama: w,
4079
+ modelKey: j,
4022
4080
  isCached: !0,
4023
4081
  persisted: n
4024
4082
  };
4025
4083
  }
4026
4084
  }
4027
- let k = T(), A = null, j = null;
4028
- if (t.kind !== "fs" && d) {
4029
- let e = E && d.exists(E) ? E : D && d.exists(D) ? D : null;
4085
+ let M = O(), N = null, P = null, F = (e = "loading tensors") => ({
4086
+ ...o,
4087
+ progressCallback: ({ loaded: t, total: n }) => {
4088
+ y && y.update({
4089
+ loaded: t,
4090
+ total: n,
4091
+ hint: e
4092
+ }), typeof o.progressCallback == "function" && o.progressCallback({
4093
+ loaded: t,
4094
+ total: n
4095
+ });
4096
+ }
4097
+ });
4098
+ if (t.kind !== "fs" && l) {
4099
+ let e = k && l.exists(k) ? k : A && l.exists(A) ? A : null;
4030
4100
  if (e) {
4031
- let t = r(d, e);
4101
+ let t = r(l, e);
4032
4102
  if (t && t.byteLength > 0) {
4033
- typeof y == "function" && y(`Loading model from ${e}...`);
4103
+ typeof S == "function" && S(`Loading model from ${e}...`), y && y.start(`Loading model (${b}) weights`, {
4104
+ total: t.byteLength,
4105
+ hint: "parsing tensors & compiling WebGPU shaders"
4106
+ });
4034
4107
  let n = new Blob([t], { type: "application/octet-stream" });
4035
- n.name = e.split("/").pop() || "model.gguf", await k.loadModel([n], c), j = {
4108
+ n.name = e.split("/").pop() || "model.gguf", await M.loadModel([n], F()), P = {
4036
4109
  path: e,
4037
4110
  bytes: t
4038
- };
4111
+ }, y && y.finish("Model weights loaded");
4039
4112
  }
4040
4113
  }
4041
4114
  }
4042
- if (j) E && E !== j.path && i(d, E, j.bytes, "application/octet-stream");
4115
+ if (P) k && k !== P.path && i(l, k, P.bytes, "application/octet-stream");
4043
4116
  else if (t.kind === "fs") {
4044
- typeof y == "function" && y(`Loading model from ${t.path}...`);
4045
- let e = r(d, t.path);
4117
+ typeof S == "function" && S(`Loading model from ${t.path}...`), y && y.start(`Loading model (${b}) weights`, { hint: "reading file" });
4118
+ let e = r(l, t.path);
4046
4119
  if (!e) throw Error(`${t.path}: No such file or directory`);
4047
4120
  let a = new Blob([e], { type: "application/octet-stream" });
4048
4121
  a.name = t.path.split("/").pop() || "model.gguf";
4049
4122
  let o = [a];
4050
4123
  if (n) {
4051
- let e = r(d, n);
4124
+ let e = r(l, n);
4052
4125
  if (!e) throw Error(`${n}: No such file or directory`);
4053
4126
  let t = new Blob([e], { type: "application/octet-stream" });
4054
4127
  t.name = n.split("/").pop() || "mmproj.gguf", o.push(t);
4055
4128
  }
4056
- typeof y == "function" && y(`Loading model ${a.name} into memory...`), await k.loadModel(o, c), E && E !== t.path && i(d, E, e, "application/octet-stream");
4057
- } else if (t.kind === "hf-quant" && typeof k.loadModelFromHF == "function") {
4058
- typeof y == "function" && y(`Pulling model ${t.repo} (${t.quant})...`);
4129
+ typeof S == "function" && S(`Loading model ${a.name} into memory...`), y && y.start(`Loading model (${b}) weights`, {
4130
+ total: e.byteLength,
4131
+ loaded: e.byteLength,
4132
+ hint: "parsing tensors & compiling WebGPU shaders"
4133
+ }), await M.loadModel(o, F()), y && y.finish("Model weights loaded"), k && k !== t.path && i(l, k, e, "application/octet-stream");
4134
+ } else if (t.kind === "hf-quant" && typeof M.loadModelFromHF == "function") {
4135
+ typeof S == "function" && S(`Pulling model ${t.repo} (${t.quant})...`), y && y.start(`Pulling ${b}`, { hint: "connecting to Hugging Face" });
4059
4136
  try {
4060
- await k.loadModelFromHF({
4137
+ await M.loadModelFromHF({
4061
4138
  repo: t.repo,
4062
4139
  quant: t.quant
4063
- }, c);
4140
+ }, F("downloading")), y && y.finish("Model weights loaded");
4064
4141
  } catch (e) {
4065
- if (typeof b.getHFModelSource == "function") {
4066
- let e = await b.getHFModelSource({
4142
+ if (typeof C.getHFModelSource == "function") {
4143
+ let e = await C.getHFModelSource({
4067
4144
  repo: t.repo,
4068
4145
  quant: t.quant
4069
4146
  });
4070
- typeof y == "function" && y(`Pulling model ${t.repo} (${t.quant})...`), A = await p(e.url || e, c.progressCallback), typeof y == "function" && y("Loading model into memory..."), await k.loadModel([A], c);
4147
+ typeof S == "function" && S(`Pulling model ${t.repo} (${t.quant})...`), y && y.start(`Pulling ${b}`, { hint: "downloading" }), N = await g(e.url || e, (e) => {
4148
+ y && y.update({
4149
+ loaded: e.loaded,
4150
+ total: e.total,
4151
+ hint: "downloading"
4152
+ }), typeof o.progressCallback == "function" && o.progressCallback(e);
4153
+ }), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
4154
+ total: N.size,
4155
+ hint: "parsing tensors & compiling WebGPU shaders"
4156
+ }), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
4071
4157
  } else throw e;
4072
4158
  }
4073
- } else if (t.kind === "hf-file" && typeof k.loadModelFromHF == "function") {
4074
- typeof y == "function" && y(`Pulling model ${t.repo}/${t.file}...`);
4159
+ } else if (t.kind === "hf-file" && typeof M.loadModelFromHF == "function") {
4160
+ typeof S == "function" && S(`Pulling model ${t.repo}/${t.file}...`), y && y.start(`Pulling ${b}`, { hint: "connecting to Hugging Face" });
4075
4161
  try {
4076
- await k.loadModelFromHF({
4162
+ await M.loadModelFromHF({
4077
4163
  repo: t.repo,
4078
4164
  file: t.file
4079
- }, c);
4165
+ }, F("downloading")), y && y.finish("Model weights loaded");
4080
4166
  } catch {
4081
- A = await p(t.url, c.progressCallback), typeof y == "function" && y("Loading model into memory..."), await k.loadModel([A], c);
4167
+ y && y.start(`Pulling ${b}`, { hint: "downloading" }), N = await g(t.url, (e) => {
4168
+ y && y.update({
4169
+ loaded: e.loaded,
4170
+ total: e.total,
4171
+ hint: "downloading"
4172
+ }), typeof o.progressCallback == "function" && o.progressCallback(e);
4173
+ }), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
4174
+ total: N.size,
4175
+ hint: "parsing tensors & compiling WebGPU shaders"
4176
+ }), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
4082
4177
  }
4083
4178
  } else {
4084
- let e = t.url || o;
4085
- typeof y == "function" && y(`Pulling model from ${e.split("/").pop().split("?")[0] || e}...`);
4179
+ let e = t.url || s;
4180
+ typeof S == "function" && S(`Pulling model from ${e.split("/").pop().split("?")[0] || e}...`), y && y.start(`Pulling ${b}`, { hint: "downloading" });
4086
4181
  try {
4087
- n && /^https?:\/\//i.test(n) ? await k.loadModelFromUrl({
4182
+ n && /^https?:\/\//i.test(n) ? await M.loadModelFromUrl({
4088
4183
  url: e,
4089
4184
  mmprojUrl: n
4090
- }, c) : await k.loadModelFromUrl(e, c);
4185
+ }, F("downloading")) : await M.loadModelFromUrl(e, F("downloading")), y && y.finish("Model weights loaded");
4091
4186
  } catch {
4092
- A = await p(e, c.progressCallback), typeof y == "function" && y("Loading model into memory..."), await k.loadModel([A], c);
4093
- }
4094
- }
4095
- typeof y == "function" && y("Model loaded.");
4096
- let M = null;
4097
- return j ? M = {
4098
- path: E || j.path,
4099
- size: j.bytes.byteLength
4100
- } : (_ || v) && d && E && t.kind !== "fs" && (M = await m({
4101
- wllama: k,
4102
- mod: b,
4187
+ N = await g(e, (e) => {
4188
+ y && y.update({
4189
+ loaded: e.loaded,
4190
+ total: e.total,
4191
+ hint: "downloading"
4192
+ }), typeof o.progressCallback == "function" && o.progressCallback(e);
4193
+ }), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
4194
+ total: N.size,
4195
+ hint: "parsing tensors & compiling WebGPU shaders"
4196
+ }), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
4197
+ }
4198
+ }
4199
+ typeof S == "function" && S("Model loaded.");
4200
+ let I = null;
4201
+ return P ? I = {
4202
+ path: k || P.path,
4203
+ size: P.bytes.byteLength
4204
+ } : (h || v) && l && k && t.kind !== "fs" && (I = await _({
4205
+ wllama: M,
4206
+ mod: C,
4103
4207
  modelSpec: t,
4104
- downloadedBlob: A,
4105
- targetPersistPath: E,
4106
- fs: d,
4107
- progressCallback: c.progressCallback
4108
- })), l.set(O, k), {
4109
- wllama: k,
4110
- mod: b,
4111
- Wllama: x,
4112
- modelKey: O,
4208
+ downloadedBlob: N,
4209
+ targetPersistPath: k,
4210
+ fs: l,
4211
+ progressCallback: o.progressCallback
4212
+ })), u.set(j, M), {
4213
+ wllama: M,
4214
+ mod: C,
4215
+ Wllama: w,
4216
+ modelKey: j,
4113
4217
  isCached: !1,
4114
- persisted: M
4218
+ persisted: I
4115
4219
  };
4116
4220
  }
4117
- function g(e) {
4221
+ function y(e) {
4118
4222
  if (typeof e == "string") return e;
4119
4223
  if (!e || typeof e != "object") return "";
4120
4224
  if (Array.isArray(e.choices) && e.choices.length > 0) {
@@ -4125,7 +4229,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4125
4229
  }
4126
4230
  return typeof e.content == "string" ? e.content : typeof e.text == "string" ? e.text : "";
4127
4231
  }
4128
- function _(e = {}, t = {}, i = "wllama") {
4232
+ function b(e = {}, t = {}, i = "wllama") {
4129
4233
  class a extends n {
4130
4234
  static get name() {
4131
4235
  return i;
@@ -4140,22 +4244,22 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4140
4244
  });
4141
4245
  }
4142
4246
  _parseArgs(e) {
4143
- let t = null, n = null, r = null, i = null, a = null, o = null, s = null, c = null, l = 256, u = .7, d, p, m = 4096, h, g, _, v = !1, y = !1, b = !1, x = !0, S = !0, C = !1, w = null, T = !0, E = !1, D = !1, O = null, k = [], A = [];
4144
- for (let f = 0; f < e.length; f++) {
4145
- let j = e[f];
4146
- if (j === "--help" || j === "-h" && f + 1 >= e.length || j === "-?") E = !0;
4147
- else if (j === "--version" || j === "-V" || j === "-v") D = !0;
4148
- else if (j === "--serve" || j === "--daemon") O = "serve";
4149
- else if (j === "-q" || j === "--quiet" || j === "--no-progress") T = !1;
4150
- else if (j === "--progress") T = !0;
4151
- else if (j === "--persist" || j === "--save") {
4152
- C = !0;
4153
- let n = e[f + 1];
4154
- n && !n.startsWith("-") && !/^https?:\/\//i.test(n) && !/^hf:/i.test(n) && (n.startsWith("/") || n.startsWith("./") || n.startsWith("../") || /\.gguf$/i.test(n)) && (t !== null || r !== null || f + 2 < e.length || O === "pull") && (t !== null || r !== null) && (w = e[++f]);
4155
- } else j.startsWith("--persist=") ? (C = !0, w = j.slice(10) || null) : j.startsWith("--save=") ? (C = !0, w = j.slice(7) || null) : (j === "-o" || j === "--output") && f + 1 < e.length ? (C = !0, w = e[++f]) : j.startsWith("--output=") ? (C = !0, w = j.slice(9) || null) : (j === "-m" || j === "--model" || j === "--url") && f + 1 < e.length ? t = e[++f] : j.startsWith("--model=") ? t = j.slice(8) : j === "--mmproj" && f + 1 < e.length ? n = e[++f] : (j === "--hf" || j === "-hf" || j === "--hf-repo") && f + 1 < e.length ? r = e[++f] : j === "--hf-file" && f + 1 < e.length ? i = e[++f] : (j === "--quant" || j === "--hf-quant") && f + 1 < e.length ? a = e[++f] : (j === "-p" || j === "--prompt") && f + 1 < e.length ? o = e[++f] : j.startsWith("--prompt=") ? o = j.slice(9) : (j === "-f" || j === "--file") && f + 1 < e.length ? s = e[++f] : (j === "-s" || j === "--system" || j === "--system-prompt") && f + 1 < e.length ? c = e[++f] : (j === "-n" || j === "--n-predict" || j === "--max-tokens") && f + 1 < e.length ? l = Number(e[++f]) || 256 : (j === "--temp" || j === "--temperature") && f + 1 < e.length ? u = Number(e[++f]) : (j === "--top-k" || j === "--top_k") && f + 1 < e.length ? d = Number(e[++f]) : (j === "--top-p" || j === "--top_p") && f + 1 < e.length ? p = Number(e[++f]) : (j === "-c" || j === "--ctx-size" || j === "--n-ctx") && f + 1 < e.length ? m = Number(e[++f]) || 4096 : (j === "-b" || j === "--batch-size") && f + 1 < e.length ? h = Number(e[++f]) : (j === "-t" || j === "--threads") && f + 1 < e.length ? g = Number(e[++f]) : (j === "-ngl" || j === "--n-gpu-layers" || j === "--gpu-layers") && f + 1 < e.length ? _ = Number(e[++f]) : j === "--no-gpu" || j === "--cpu" ? _ = 0 : j === "--webgpu" || j === "--gpu" ? (_ === void 0 || _ === 0) && (_ = 99) : j === "--embeddings" || j === "--embedding" || j === "--embed" ? (v = !0, O ||= "embed") : j === "--raw" || j === "--completion" ? y = !0 : j === "--stream" ? x = !0 : j === "--no-stream" ? x = !1 : j === "--json" ? b = !0 : j === "--no-jinja" ? S = !1 : j.startsWith("-") ? k.push(j) : A.push(j);
4247
+ let t = null, n = null, r = null, i = null, a = null, s = null, c = null, l = null, u = 256, d = .7, f, p, m = 4096, g, _, v, y = !1, b = !1, x = !1, S = !0, C = !0, w = !1, T = null, E = !0, D = !1, O = !1, k = null, A = [], j = [];
4248
+ for (let o = 0; o < e.length; o++) {
4249
+ let h = e[o];
4250
+ if (h === "--help" || h === "-h" && o + 1 >= e.length || h === "-?") D = !0;
4251
+ else if (h === "--version" || h === "-V" || h === "-v") O = !0;
4252
+ else if (h === "--serve" || h === "--daemon") k = "serve";
4253
+ else if (h === "-q" || h === "--quiet" || h === "--no-progress") E = !1;
4254
+ else if (h === "--progress") E = !0;
4255
+ else if (h === "--persist" || h === "--save") {
4256
+ w = !0;
4257
+ let n = e[o + 1];
4258
+ n && !n.startsWith("-") && !/^https?:\/\//i.test(n) && !/^hf:/i.test(n) && (n.startsWith("/") || n.startsWith("./") || n.startsWith("../") || /\.gguf$/i.test(n)) && (t !== null || r !== null || o + 2 < e.length || k === "pull") && (t !== null || r !== null) && (T = e[++o]);
4259
+ } else h.startsWith("--persist=") ? (w = !0, T = h.slice(10) || null) : h.startsWith("--save=") ? (w = !0, T = h.slice(7) || null) : (h === "-o" || h === "--output") && o + 1 < e.length ? (w = !0, T = e[++o]) : h.startsWith("--output=") ? (w = !0, T = h.slice(9) || null) : (h === "-m" || h === "--model" || h === "--url") && o + 1 < e.length ? t = e[++o] : h.startsWith("--model=") ? t = h.slice(8) : h === "--mmproj" && o + 1 < e.length ? n = e[++o] : (h === "--hf" || h === "-hf" || h === "--hf-repo") && o + 1 < e.length ? r = e[++o] : h === "--hf-file" && o + 1 < e.length ? i = e[++o] : (h === "--quant" || h === "--hf-quant") && o + 1 < e.length ? a = e[++o] : (h === "-p" || h === "--prompt") && o + 1 < e.length ? s = e[++o] : h.startsWith("--prompt=") ? s = h.slice(9) : (h === "-f" || h === "--file") && o + 1 < e.length ? c = e[++o] : (h === "-s" || h === "--system" || h === "--system-prompt") && o + 1 < e.length ? l = e[++o] : (h === "-n" || h === "--n-predict" || h === "--max-tokens") && o + 1 < e.length ? u = Number(e[++o]) || 256 : (h === "--temp" || h === "--temperature") && o + 1 < e.length ? d = Number(e[++o]) : (h === "--top-k" || h === "--top_k") && o + 1 < e.length ? f = Number(e[++o]) : (h === "--top-p" || h === "--top_p") && o + 1 < e.length ? p = Number(e[++o]) : (h === "-c" || h === "--ctx-size" || h === "--n-ctx") && o + 1 < e.length ? m = Number(e[++o]) || 4096 : (h === "-b" || h === "--batch-size") && o + 1 < e.length ? g = Number(e[++o]) : (h === "-t" || h === "--threads") && o + 1 < e.length ? _ = Number(e[++o]) : (h === "-ngl" || h === "--n-gpu-layers" || h === "--gpu-layers") && o + 1 < e.length ? v = Number(e[++o]) : h === "--no-gpu" || h === "--cpu" ? v = 0 : h === "--webgpu" || h === "--gpu" ? (v === void 0 || v === 0) && (v = 99) : h === "--embeddings" || h === "--embedding" || h === "--embed" ? (y = !0, k ||= "embed") : h === "--raw" || h === "--completion" ? b = !0 : h === "--stream" ? S = !0 : h === "--no-stream" ? S = !1 : h === "--json" ? x = !0 : h === "--no-jinja" ? C = !1 : h.startsWith("-") ? A.push(h) : j.push(h);
4156
4260
  }
4157
- if (A.length > 0) {
4158
- let e = A[0].toLowerCase();
4261
+ if (j.length > 0) {
4262
+ let e = j[0].toLowerCase();
4159
4263
  if ([
4160
4264
  "info",
4161
4265
  "models",
@@ -4170,45 +4274,45 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4170
4274
  "pull",
4171
4275
  "download"
4172
4276
  ].includes(e)) {
4173
- let e = A.shift().toLowerCase();
4174
- e === "list" ? O = "models" : e === "embeddings" ? (O = "embed", v = !0) : e === "test-ops" ? O = "bench" : e === "completion" ? (O = "run", y = !0) : e === "download" || e === "pull" ? (O = "pull", C = !0) : O = e;
4277
+ let e = j.shift().toLowerCase();
4278
+ e === "list" ? k = "models" : e === "embeddings" ? (k = "embed", y = !0) : e === "test-ops" ? k = "bench" : e === "completion" ? (k = "run", b = !0) : e === "download" || e === "pull" ? (k = "pull", w = !0) : k = e;
4175
4279
  }
4176
4280
  }
4177
- if (A.length > 0 && (!t && !r && (O === "pull" || /\.gguf(\?.*)?$/i.test(A[0]) || /^hf:/i.test(A[0]) || /^https?:\/\//i.test(A[0])) && (t = A.shift()), O === "pull" && A.length > 0 && !w ? w = A.shift() : A.length > 0 && o === null && (o = A.join(" "))), !t && !r && this.context && typeof this.context.getVar == "function") {
4281
+ if (j.length > 0 && (!t && !r && (k === "pull" || o[j[0].toLowerCase()] || /\.gguf(\?.*)?$/i.test(j[0]) || /^hf:/i.test(j[0]) || /^https?:\/\//i.test(j[0])) && (t = j.shift()), k === "pull" && j.length > 0 && !T ? T = j.shift() : j.length > 0 && s === null && (s = j.join(" "))), !t && !r && this.context && typeof this.context.getVar == "function") {
4178
4282
  let e = this.context.getVar("WLLAMA_MODEL");
4179
4283
  e && (t = e);
4180
4284
  }
4181
- let j = f(t, r, i, a), M = {
4285
+ let M = h(t, r, i, a), N = {
4182
4286
  n_ctx: m,
4183
- jinja: S
4287
+ jinja: C
4184
4288
  };
4185
- return _ !== void 0 && (M.n_gpu_layers = _), h !== void 0 && (M.n_batch = h), g !== void 0 && (M.n_threads = g), v && (M.embeddings = !0), {
4289
+ return v !== void 0 && (N.n_gpu_layers = v), g !== void 0 && (N.n_batch = g), _ !== void 0 && (N.n_threads = _), y && (N.embeddings = !0), {
4186
4290
  model: t,
4187
4291
  mmproj: n,
4188
- modelSpec: j,
4189
- loadParams: M,
4190
- prompt: o,
4191
- file: s,
4192
- systemPrompt: c,
4193
- maxTokens: l,
4194
- temperature: u,
4195
- topK: d,
4292
+ modelSpec: M,
4293
+ loadParams: N,
4294
+ prompt: s,
4295
+ file: c,
4296
+ systemPrompt: l,
4297
+ maxTokens: u,
4298
+ temperature: d,
4299
+ topK: f,
4196
4300
  topP: p,
4197
4301
  nCtx: m,
4198
- nGpuLayers: _,
4199
- embeddings: v,
4200
- rawCompletion: y,
4201
- jsonOutput: b,
4202
- stream: x,
4203
- persist: C,
4204
- persistPath: w,
4205
- showProgress: T,
4206
- help: E,
4207
- version: D,
4208
- subcommand: O,
4302
+ nGpuLayers: v,
4303
+ embeddings: y,
4304
+ rawCompletion: b,
4305
+ jsonOutput: x,
4306
+ stream: S,
4307
+ persist: w,
4308
+ persistPath: T,
4309
+ showProgress: E,
4310
+ help: D,
4311
+ version: O,
4312
+ subcommand: k,
4209
4313
  host: "127.0.0.1",
4210
4314
  port: 8080,
4211
- extraArgs: k
4315
+ extraArgs: A
4212
4316
  };
4213
4317
  }
4214
4318
  shouldBeInteractive() {
@@ -4235,6 +4339,16 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4235
4339
  _clearStatus() {
4236
4340
  !this._parsed.showProgress || this._parsed.jsonOutput || this.stderr && typeof this.stderr.write == "function" && this.stderr.write("\r\x1B[K");
4237
4341
  }
4342
+ _createTracker(e = "Loading") {
4343
+ return new m({
4344
+ enabled: !!(this._parsed.showProgress && !this._parsed.jsonOutput),
4345
+ width: 20,
4346
+ intervalMs: 80,
4347
+ onRender: (e) => {
4348
+ this.interactive ? (this._replStatus = e, this._renderRepl()) : e ? this._renderStatus(e) : this._clearStatus();
4349
+ }
4350
+ });
4351
+ }
4238
4352
  _attachProgressCallback() {
4239
4353
  if (!this._parsed.showProgress || this._parsed.modelSpec.kind === "fs") return;
4240
4354
  let e = this._parsed.model || this._parsed.modelSpec.file || this._parsed.modelSpec.repo || this._parsed.modelSpec.url || "model.gguf", t = 0;
@@ -4242,28 +4356,36 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4242
4356
  let i = Date.now();
4243
4357
  if (t === 0 || r > 0 && n >= r || i - t >= 40) {
4244
4358
  t = i;
4245
- let a = d(e, n, r);
4359
+ let a = p(e, n, r);
4246
4360
  this.interactive ? (this._replStatus = a.replace(/^\r/, ""), this._renderRepl()) : this._parsed.subcommand === "pull" ? (this.stdOut = a, this.flush()) : this._renderStatus(a.replace(/^\r/, ""));
4247
4361
  }
4248
4362
  };
4249
4363
  }
4250
4364
  async _initWllama(n = !0) {
4251
4365
  n && this._attachProgressCallback();
4252
- let { wllama: r, Wllama: i, persisted: a } = await h({
4253
- modelSpec: this._parsed.modelSpec,
4254
- mmprojSpec: this._parsed.mmproj,
4255
- loadParams: this._parsed.loadParams,
4256
- fs: this.fs,
4257
- pkgMeta: e,
4258
- wbtConfig: t,
4259
- loadModel: n,
4260
- persist: this._parsed.persist,
4261
- persistPath: this._parsed.persistPath,
4262
- onStatus: (e) => {
4263
- this.interactive ? (this._replStatus = e, this._renderRepl()) : this._renderStatus(e);
4264
- }
4265
- });
4266
- this._wllama = r, this._WllamaClass = i, this._persisted = a, this.interactive || this._clearStatus();
4366
+ let r = this._parsed.model || this._parsed.modelSpec.file || this._parsed.modelSpec.repo || this._parsed.modelSpec.url || "model.gguf", i = r.split("/").pop().split("?")[0] || r, a = this._createTracker(), o = (e) => {
4367
+ this.interactive ? (this._replStatus = e, this._renderRepl()) : this._renderStatus(e);
4368
+ };
4369
+ try {
4370
+ let { wllama: r, Wllama: s, persisted: c } = await v({
4371
+ modelSpec: this._parsed.modelSpec,
4372
+ mmprojSpec: this._parsed.mmproj,
4373
+ loadParams: this._parsed.loadParams,
4374
+ fs: this.fs,
4375
+ pkgMeta: e,
4376
+ wbtConfig: t,
4377
+ loadModel: n,
4378
+ persist: this._parsed.persist,
4379
+ persistPath: this._parsed.persistPath,
4380
+ tracker: a,
4381
+ shortLabel: i,
4382
+ isPullCommand: this._parsed.subcommand === "pull",
4383
+ onStatus: o
4384
+ });
4385
+ this._wllama = r, this._WllamaClass = s, this._persisted = c;
4386
+ } finally {
4387
+ a && a.clear(), this.interactive || this._clearStatus();
4388
+ }
4267
4389
  }
4268
4390
  async initRepl() {
4269
4391
  await this._initWllama(!0);
@@ -4322,39 +4444,46 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4322
4444
  temperature: this._parsed.temperature,
4323
4445
  stream: n
4324
4446
  };
4325
- if (this._parsed.topK !== void 0 && (r.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (r.top_p = this._parsed.topP), this.interactive ? (this._replStatus = "Running inference...", this._renderRepl()) : this._renderStatus("Running inference..."), typeof this._wllama.createChatCompletion == "function") {
4326
- let e = await this._wllama.createChatCompletion(r);
4327
- if (e && typeof e[Symbol.asyncIterator] == "function") {
4328
- let n = "", r = !1;
4329
- for await (let i of e) {
4330
- let e = i?.choices?.[0]?.delta?.content ?? i?.choices?.[0]?.text ?? "";
4331
- e && (r || (r = !0, this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), n += e, typeof t == "function" && t(e));
4447
+ this._parsed.topK !== void 0 && (r.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (r.top_p = this._parsed.topP);
4448
+ let i = this._createTracker();
4449
+ i.start("Running inference", { hint: "evaluating prompt & preparing KV cache" });
4450
+ try {
4451
+ if (typeof this._wllama.createChatCompletion == "function") {
4452
+ let e = await this._wllama.createChatCompletion(r);
4453
+ if (e && typeof e[Symbol.asyncIterator] == "function") {
4454
+ let n = "", r = !1;
4455
+ for await (let a of e) {
4456
+ let e = a?.choices?.[0]?.delta?.content ?? a?.choices?.[0]?.text ?? "";
4457
+ e && (r || (r = !0, i.clear(), this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), n += e, typeof t == "function" && t(e));
4458
+ }
4459
+ return i.clear(), this.interactive || this._clearStatus(), n;
4332
4460
  }
4333
- return this.interactive || this._clearStatus(), n;
4461
+ if (i.clear(), this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(e);
4462
+ let n = y(e);
4463
+ return typeof t == "function" && n && t(n), n;
4334
4464
  }
4335
- if (this._parsed.jsonOutput) return this.interactive || this._clearStatus(), JSON.stringify(e);
4336
- let n = g(e);
4337
- return this.interactive || this._clearStatus(), typeof t == "function" && n && t(n), n;
4338
- }
4339
- let i = {
4340
- prompt: e[e.length - 1]?.content || "",
4341
- max_tokens: this._parsed.maxTokens,
4342
- temperature: this._parsed.temperature,
4343
- stream: n
4344
- };
4345
- this._parsed.topK !== void 0 && (i.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (i.top_p = this._parsed.topP);
4346
- let a = await this._wllama.createCompletion(i);
4347
- if (a && typeof a[Symbol.asyncIterator] == "function") {
4348
- let e = "", n = !1;
4349
- for await (let r of a) {
4350
- let i = r?.choices?.[0]?.text ?? r?.choices?.[0]?.delta?.content ?? "";
4351
- i && (n || (n = !0, this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), e += i, typeof t == "function" && t(i));
4465
+ let a = {
4466
+ prompt: e[e.length - 1]?.content || "",
4467
+ max_tokens: this._parsed.maxTokens,
4468
+ temperature: this._parsed.temperature,
4469
+ stream: n
4470
+ };
4471
+ this._parsed.topK !== void 0 && (a.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (a.top_p = this._parsed.topP);
4472
+ let o = await this._wllama.createCompletion(a);
4473
+ if (o && typeof o[Symbol.asyncIterator] == "function") {
4474
+ let e = "", n = !1;
4475
+ for await (let r of o) {
4476
+ let a = r?.choices?.[0]?.text ?? r?.choices?.[0]?.delta?.content ?? "";
4477
+ a && (n || (n = !0, i.clear(), this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), e += a, typeof t == "function" && t(a));
4478
+ }
4479
+ return i.clear(), this.interactive || this._clearStatus(), e;
4352
4480
  }
4353
- return this.interactive || this._clearStatus(), e;
4481
+ if (i.clear(), this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(o);
4482
+ let s = y(o);
4483
+ return typeof t == "function" && s && t(s), s;
4484
+ } finally {
4485
+ i.clear(), this.interactive || this._clearStatus();
4354
4486
  }
4355
- if (this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(a);
4356
- let o = g(a);
4357
- return typeof t == "function" && o && t(o), o;
4358
4487
  }
4359
4488
  _formatModelInfo() {
4360
4489
  let t = this._wllama && typeof this._wllama.isSupportWebGPU == "function" ? this._wllama.isSupportWebGPU() : !!(typeof navigator < "u" && navigator.gpu), n = this._wllama && typeof this._wllama.isMultithread == "function" ? this._wllama.isMultithread() : !1, r = this._wllama && typeof this._wllama.getNumThreads == "function" ? this._wllama.getNumThreads() : 1, i = this._WllamaClass && typeof this._WllamaClass.getLibllamaVersion == "function" ? this._WllamaClass.getLibllamaVersion() : "b6327", a = this._wllama && typeof this._wllama.getModelMetadata == "function" ? this._wllama.getModelMetadata() : null, o = [
@@ -4371,7 +4500,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4371
4500
  if (this._parsed.port, e === "pull") {
4372
4501
  try {
4373
4502
  await this._initWllama(!0);
4374
- let e = this._persisted && this._persisted.path || this._parsed.persistPath || u(this._parsed.modelSpec), t = this._persisted && this._persisted.size || 0, n = t >= 1024 * 1024 ? `${(t / (1024 * 1024)).toFixed(1)} MB` : `${t} B`;
4503
+ let e = this._persisted && this._persisted.path || this._parsed.persistPath || d(this._parsed.modelSpec), t = this._persisted && this._persisted.size || 0, n = t >= 1024 * 1024 ? `${(t / (1024 * 1024)).toFixed(1)} MB` : `${t} B`;
4375
4504
  this.stdOut = `Persisted model ${this._parsed.model || this._parsed.modelSpec.key} -> ${e} (${n})`;
4376
4505
  } catch (e) {
4377
4506
  this.stdErr = `wllama: could not pull model: ${e.message || e}`, this.exitCode = 1;
@@ -4388,22 +4517,22 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4388
4517
  let e = [];
4389
4518
  this._wllama && this._wllama.modelManager && typeof this._wllama.modelManager.getModels == "function" && (e = await this._wllama.modelManager.getModels());
4390
4519
  let t = [];
4391
- if (this.fs && typeof this.fs.exists == "function" && this.fs.exists(c)) {
4392
- let e = typeof this.fs.getFileByPath == "function" ? this.fs.getFileByPath(c) : null;
4520
+ if (this.fs && typeof this.fs.exists == "function" && this.fs.exists(l)) {
4521
+ let e = typeof this.fs.getFileByPath == "function" ? this.fs.getFileByPath(l) : null;
4393
4522
  if (e && typeof e == "object") for (let n of Object.keys(e)) {
4394
- let e = `${c}/${n}`, i = r(this.fs, e);
4523
+ let e = `${l}/${n}`, i = r(this.fs, e);
4395
4524
  t.push({
4396
4525
  path: e,
4397
4526
  size: i ? i.byteLength : 0
4398
4527
  });
4399
4528
  }
4400
4529
  }
4401
- if (e.length === 0 && l.size === 0 && t.length === 0) {
4530
+ if (e.length === 0 && u.size === 0 && t.length === 0) {
4402
4531
  this.stdOut = "No cached models found.";
4403
4532
  return;
4404
4533
  }
4405
4534
  this.stdOut = "MODEL SIZE STATUS";
4406
- for (let [e] of l.entries()) this.stdOut = `${e.split(":gpu=")[0].padEnd(54)} in-memory loaded`;
4535
+ for (let [e] of u.entries()) this.stdOut = `${e.split(":gpu=")[0].padEnd(54)} in-memory loaded`;
4407
4536
  for (let e of t) {
4408
4537
  let t = e.size >= 1024 * 1024 ? `${(e.size / (1024 * 1024)).toFixed(1)} MB` : `${e.size} B`;
4409
4538
  this.stdOut = `${e.path.padEnd(54)} ${t.padEnd(11)} persisted (fs)`;
@@ -4434,7 +4563,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4434
4563
  " wllama bench Run ggml WebGPU/CPU backend ops test",
4435
4564
  "",
4436
4565
  "Options:",
4437
- " -m, --model=MODEL Path in brsh filesystem, URL, or hf:owner/repo/file.gguf",
4566
+ " -m, --model=MODEL Path in brsh fs, URL, HF spec, or alias (default: smol [SmolLM2-135M]; also: qwen)",
4438
4567
  " --hf=REPO Hugging Face model repository (e.g. Qwen/Qwen2.5-0.5B-Instruct-GGUF)",
4439
4568
  " --quant=QUANT Hugging Face GGUF quantization (default: Q4_K_M)",
4440
4569
  " --persist[=PATH] Persist pulled remote model into brsh filesystem (default: /var/cache/wllama/)",
@@ -4486,10 +4615,17 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4486
4615
  e = String(t);
4487
4616
  } else this._parsed.prompt === null ? this.stdin !== void 0 && this.stdin !== null && String(this.stdin).trim().length > 0 && (e = String(this.stdin).trim()) : e = this._parsed.prompt;
4488
4617
  if (this._parsed.embeddings || this._parsed.subcommand === "embed") {
4489
- let t = await this._wllama.createEmbedding({ input: e });
4490
- if (this._parsed.jsonOutput) this.stdOut = JSON.stringify(t);
4618
+ let t = this._createTracker();
4619
+ t.start("Computing embeddings", { hint: "evaluating prompt" });
4620
+ let n;
4621
+ try {
4622
+ n = await this._wllama.createEmbedding({ input: e });
4623
+ } finally {
4624
+ t.clear(), this._clearStatus();
4625
+ }
4626
+ if (this._parsed.jsonOutput) this.stdOut = JSON.stringify(n);
4491
4627
  else {
4492
- let e = t?.data?.[0]?.embedding || t?.embedding || [];
4628
+ let e = n?.data?.[0]?.embedding || n?.embedding || [];
4493
4629
  this.stdOut = JSON.stringify(e);
4494
4630
  }
4495
4631
  return;
@@ -4501,20 +4637,26 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4501
4637
  temperature: this._parsed.temperature,
4502
4638
  stream: t
4503
4639
  };
4504
- this._parsed.topK !== void 0 && (n.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (n.top_p = this._parsed.topP), this._renderStatus("Running inference...");
4505
- let r = await this._wllama.createCompletion(n), i = "";
4506
- if (r && typeof r[Symbol.asyncIterator] == "function") {
4507
- let e = !1;
4508
- for await (let t of r) {
4509
- let n = t?.choices?.[0]?.text ?? t?.choices?.[0]?.delta?.content ?? "";
4510
- n && (e || (e = !0, this._streamedStdout = !0, this._clearStatus()), i += n, this.stdout && typeof this.stdout.write == "function" && this.stdout.write(n), this.emit("token", n));
4511
- }
4512
- this._clearStatus(), e && i.length > 0 && !i.endsWith("\n") && this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\r\n");
4513
- } else this._clearStatus(), i = this._parsed.jsonOutput ? JSON.stringify(r) : g(r);
4514
- i.split(/\r?\n/).forEach((e) => {
4515
- this.stdOut = e;
4516
- });
4517
- return;
4640
+ this._parsed.topK !== void 0 && (n.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (n.top_p = this._parsed.topP);
4641
+ let r = this._createTracker();
4642
+ r.start("Running inference", { hint: "evaluating prompt & preparing KV cache" });
4643
+ try {
4644
+ let e = await this._wllama.createCompletion(n), t = "";
4645
+ if (e && typeof e[Symbol.asyncIterator] == "function") {
4646
+ let n = !1;
4647
+ for await (let i of e) {
4648
+ let e = i?.choices?.[0]?.text ?? i?.choices?.[0]?.delta?.content ?? "";
4649
+ e && (n || (n = !0, this._streamedStdout = !0, r.clear(), this._clearStatus()), t += e, this.stdout && typeof this.stdout.write == "function" && this.stdout.write(e), this.emit("token", e));
4650
+ }
4651
+ r.clear(), this._clearStatus(), n && t.length > 0 && !t.endsWith("\n") && this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\r\n");
4652
+ } else r.clear(), this._clearStatus(), t = this._parsed.jsonOutput ? JSON.stringify(e) : y(e);
4653
+ t.split(/\r?\n/).forEach((e) => {
4654
+ this.stdOut = e;
4655
+ });
4656
+ return;
4657
+ } finally {
4658
+ r.clear(), this._clearStatus();
4659
+ }
4518
4660
  }
4519
4661
  let t = [];
4520
4662
  this._parsed.systemPrompt && t.push({
@@ -4541,26 +4683,26 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
4541
4683
  }
4542
4684
  return a;
4543
4685
  }
4544
- function v(e = {}, t = {}) {
4686
+ function x(e = {}, t = {}) {
4545
4687
  return [
4546
4688
  {
4547
4689
  bin: (e.bin || "wllama").toLowerCase(),
4548
- Cmd: _(e, t, "wllama")
4690
+ Cmd: b(e, t, "wllama")
4549
4691
  },
4550
4692
  {
4551
4693
  bin: "llama",
4552
- Cmd: _(e, t, "llama")
4694
+ Cmd: b(e, t, "llama")
4553
4695
  },
4554
4696
  {
4555
4697
  bin: "llama-cli",
4556
- Cmd: _(e, t, "llama-cli")
4698
+ Cmd: b(e, t, "llama-cli")
4557
4699
  }
4558
4700
  ];
4559
4701
  }
4560
- t.exports = _, t.exports.createWllamaCommand = _, t.exports.buildEntries = v, t.exports.WllamaCommand = _({
4702
+ t.exports = b, t.exports.createWllamaCommand = b, t.exports.buildEntries = x, t.exports.WllamaCommand = b({
4561
4703
  name: "wllama",
4562
4704
  version: "3.8.1"
4563
- }), t.exports.wllamaInstances = l, t.exports.getDefaultPersistPath = u, t.exports.DEFAULT_PERSIST_DIR = c, t.exports.resolveModelSpec = f, t.exports.formatDownloadProgress = d;
4705
+ }), t.exports.wllamaInstances = u, t.exports.getDefaultPersistPath = d, t.exports.DEFAULT_PERSIST_DIR = l, t.exports.resolveModelSpec = h, t.exports.formatDownloadProgress = p, t.exports.DEFAULT_MODEL_URL = s, t.exports.MODEL_ALIASES = o;
4564
4706
  })), se = /* @__PURE__ */ t(((e, t) => {
4565
4707
  b();
4566
4708
  var r = E(), i = X(), a = Z(), { DEFAULT_REGISTRY: o, resolvePackageName: s } = ie(), c = oe(), { writeBytesToFs: l, createGenericWasmCommand: u } = i, { createReplWasmCommand: d } = a, f = "/var/lib/wbt/installed.json", p = "/var/cache/wbt";