@hackbuild/ai-views 0.1.6 → 0.1.8
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/README.md +4 -4
- package/dist/loaders.js +6 -2
- package/dist/single/index.iife.js +77 -12
- package/dist/single/index.js +77 -12
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Put a model picker, a chat, a transcriber, a mask studio or a camera frame on your page, drawn with the hackbuild-ui stylesheet, as custom elements or Vue components.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@hackbuild/ai-views) [](../../LICENSE) ](https://www.npmjs.com/package/@hackbuild/ai-views) [](../../LICENSE)  
|
|
6
6
|
|
|
7
7
|
Browser status: no model run of this package has been verified in a real browser yet.
|
|
8
8
|
|
|
@@ -254,9 +254,9 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
254
254
|
|
|
255
255
|
| file | gzip (measured) | ceiling |
|
|
256
256
|
|---|---|---|
|
|
257
|
-
| `dist/index.js` (main entry, imports external) | 21,
|
|
258
|
-
| `dist/single/elements.iife.js` (single file build) | 100,
|
|
257
|
+
| `dist/index.js` (main entry, imports external) | 21,595 bytes | 22,674 bytes |
|
|
258
|
+
| `dist/single/elements.iife.js` (single file build) | 100,083 bytes | 105,087 bytes |
|
|
259
259
|
|
|
260
|
-
Measured 2026-11-
|
|
260
|
+
Measured 2026-11-26 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
261
261
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
262
262
|
5 percent from its row.
|
package/dist/loaders.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* and webgpu work takes one gpu lock.
|
|
12
12
|
*/
|
|
13
13
|
import { importEsm, probe } from "@hackbuild/ai-env";
|
|
14
|
-
import { createHub, createRegistry } from "@hackbuild/models";
|
|
14
|
+
import { createHub, createRegistry, pinnedUrl } from "@hackbuild/models";
|
|
15
15
|
import { hfResolve } from "@hackbuild/weights";
|
|
16
16
|
import { ALL_RECORDS } from "./jobs.js";
|
|
17
17
|
/** Pinned CDN modules jobLoader imports at load time. */
|
|
@@ -46,6 +46,10 @@ function licenceFor(url) {
|
|
|
46
46
|
}
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
|
+
/** The pinned revision of the record a Hugging Face repo belongs to, so resolve/main requests share one stored file. */
|
|
50
|
+
function revisionFor(repo) {
|
|
51
|
+
return ALL_RECORDS.find((r) => (r.source.modelId ?? r.source.repo) === repo)?.source.revision;
|
|
52
|
+
}
|
|
49
53
|
async function makeRuntime(o) {
|
|
50
54
|
const [{ loadOrt, loadTransformers, ortProvider, runtimeLoader, tjsProvider }, { openWeightStore, transformersCache }] = await Promise.all([import("@hackbuild/devices"), import("@hackbuild/weights")]);
|
|
51
55
|
const [env, store] = await Promise.all([o.env ?? probe(), o.store ?? openWeightStore()]);
|
|
@@ -53,7 +57,7 @@ async function makeRuntime(o) {
|
|
|
53
57
|
const m = o.modules ?? {};
|
|
54
58
|
const rt = { hub, store, modules: m, tokenizers: new Map() };
|
|
55
59
|
const tjsModule = m.transformers ?? loadTransformers();
|
|
56
|
-
const tjs = tjsProvider({ runtime: tjsModule, cache: transformersCache(store, { licenceFor }) });
|
|
60
|
+
const tjs = tjsProvider({ runtime: tjsModule, cache: transformersCache(store, { licenceFor, keyFor: (u) => pinnedUrl(u, revisionFor) }) });
|
|
57
61
|
const [vision, chatTjs, embed] = await Promise.all([import("@hackbuild/vision"), import("@hackbuild/chat/transformers"), import("@hackbuild/embed")]);
|
|
58
62
|
tjs.loader("depth", vision.depthLoader);
|
|
59
63
|
tjs.loader("vision.caption", vision.vlmLoader);
|
|
@@ -3049,10 +3049,31 @@ var HackbuildAiViews = (function(exports) {
|
|
|
3049
3049
|
function pinnedBase(repo, fallback = "main") {
|
|
3050
3050
|
return `https://huggingface.co/${repo}/resolve/${pinOf(repo)?.revision ?? fallback}/`;
|
|
3051
3051
|
}
|
|
3052
|
-
|
|
3052
|
+
/**
|
|
3053
|
+
* A Hugging Face resolve URL at the pinned commit when it names a pinned
|
|
3054
|
+
* repo at `main` (transformers.js lists files at main before it loads at
|
|
3055
|
+
* the revision it was given); any other URL comes back unchanged.
|
|
3056
|
+
* `revisionFor` names revisions for repos outside the pins.
|
|
3057
|
+
*/
|
|
3058
|
+
function pinnedUrl(url, revisionFor) {
|
|
3059
|
+
const m = HF.exec(url);
|
|
3060
|
+
if (!m || m[2] !== "main") return url;
|
|
3061
|
+
const rev = revisionFor?.(m[1]) ?? pinOf(m[1])?.revision;
|
|
3062
|
+
return rev ? `https://huggingface.co/${m[1]}/resolve/${rev}/${m[3]}` : url;
|
|
3063
|
+
}
|
|
3064
|
+
/** True the first time a model is named in this page session; shared by every hackbuild package through a global symbol. */
|
|
3065
|
+
function firstInSession$1(model) {
|
|
3066
|
+
const g = globalThis;
|
|
3067
|
+
const seen = g[SEEN$1] ??= /* @__PURE__ */ new Set();
|
|
3068
|
+
if (seen.has(model)) return false;
|
|
3069
|
+
seen.add(model);
|
|
3070
|
+
return true;
|
|
3071
|
+
}
|
|
3072
|
+
var HF, SEEN$1;
|
|
3053
3073
|
var init_pinning = __esmMin((() => {
|
|
3054
3074
|
init_pins();
|
|
3055
3075
|
HF = /^https:\/\/huggingface\.co\/([^/]+\/[^/]+)\/resolve\/([^/]+)\/(.+)$/;
|
|
3076
|
+
SEEN$1 = Symbol.for("hackbuild.licence.seen");
|
|
3056
3077
|
}));
|
|
3057
3078
|
// packages/models/src/registry.ts
|
|
3058
3079
|
/** Size class by download size: tiny under 400 MB, small under 1.5 GB, medium under 3.5 GB (inferred cut points). */
|
|
@@ -4750,7 +4771,10 @@ var HackbuildAiViews = (function(exports) {
|
|
|
4750
4771
|
if (!told.has(record.id)) {
|
|
4751
4772
|
told.add(record.id);
|
|
4752
4773
|
const rev = record.source.revision ? ` at ${record.source.revision.slice(0, 7)}` : "";
|
|
4753
|
-
|
|
4774
|
+
const line = `model ${record.id}${rev}: weight licence ${record.licence}. the weights are not part of this library.`;
|
|
4775
|
+
const first = firstInSession$1(record.source.repo ?? record.source.modelId ?? record.source.url ?? record.id);
|
|
4776
|
+
if (opts.onLicence) opts.onLicence(line, record);
|
|
4777
|
+
else if (first) console.info(line);
|
|
4754
4778
|
}
|
|
4755
4779
|
const factory = factories.get(record.provider);
|
|
4756
4780
|
if (!factory) throw new HubError("no-provider", `no factory for provider ${record.provider}; call hub.provide("${record.provider}", ...)`);
|
|
@@ -4939,6 +4963,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
4939
4963
|
var init_hub$1 = __esmMin((() => {
|
|
4940
4964
|
init_record();
|
|
4941
4965
|
init_registry();
|
|
4966
|
+
init_pinning();
|
|
4942
4967
|
HubError = class extends Error {
|
|
4943
4968
|
code;
|
|
4944
4969
|
constructor(code, message) {
|
|
@@ -6040,7 +6065,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6040
6065
|
async function openWeightStore(opts = {}) {
|
|
6041
6066
|
const partBytes = opts.partBytes ?? 134217728;
|
|
6042
6067
|
const doFetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
6043
|
-
const notice = opts.onNotice
|
|
6068
|
+
const notice = opts.onNotice;
|
|
6044
6069
|
const now = opts.now ?? (() => Date.now());
|
|
6045
6070
|
let backend = null;
|
|
6046
6071
|
for (const b of pickBackends(opts)) try {
|
|
@@ -6074,9 +6099,13 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6074
6099
|
};
|
|
6075
6100
|
const onceMap = /* @__PURE__ */ new Map();
|
|
6076
6101
|
const tellLicence = (key, licence) => {
|
|
6077
|
-
|
|
6078
|
-
noticed.
|
|
6079
|
-
|
|
6102
|
+
const model = modelOf(key);
|
|
6103
|
+
if (noticed.has(model)) return;
|
|
6104
|
+
noticed.add(model);
|
|
6105
|
+
const first = firstInSession(model);
|
|
6106
|
+
const line = `weights ${model}: licence ${licence}. the weights are not part of this library.`;
|
|
6107
|
+
if (notice) notice(line);
|
|
6108
|
+
else if (first) console.info(line);
|
|
6080
6109
|
};
|
|
6081
6110
|
const estimate = async () => {
|
|
6082
6111
|
const fn = opts.estimate ?? (() => globalThis.navigator?.storage?.estimate?.() ?? Promise.resolve({}));
|
|
@@ -6409,7 +6438,23 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6409
6438
|
};
|
|
6410
6439
|
return store;
|
|
6411
6440
|
}
|
|
6412
|
-
|
|
6441
|
+
/** The model a weight key belongs to: its Hugging Face repo, the folder of any other URL, or a non URL key as is. */
|
|
6442
|
+
function modelOf(key) {
|
|
6443
|
+
const m = HF_REPO.exec(key);
|
|
6444
|
+
if (m) return m[1];
|
|
6445
|
+
if (!/^https?:\/\//.test(key)) return key;
|
|
6446
|
+
const cut = key.split("?")[0].lastIndexOf("/");
|
|
6447
|
+
return cut > 0 ? key.slice(0, cut) : key;
|
|
6448
|
+
}
|
|
6449
|
+
/** True the first time a model is named in this page session; shared by every hackbuild package through a global symbol. */
|
|
6450
|
+
function firstInSession(model) {
|
|
6451
|
+
const g = globalThis;
|
|
6452
|
+
const seen = g[SEEN] ??= /* @__PURE__ */ new Set();
|
|
6453
|
+
if (seen.has(model)) return false;
|
|
6454
|
+
seen.add(model);
|
|
6455
|
+
return true;
|
|
6456
|
+
}
|
|
6457
|
+
var WeightError, bareTag, HF_REPO, SEEN;
|
|
6413
6458
|
var init_store = __esmMin((() => {
|
|
6414
6459
|
init_backends();
|
|
6415
6460
|
init_sha256();
|
|
@@ -6422,6 +6467,8 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6422
6467
|
}
|
|
6423
6468
|
};
|
|
6424
6469
|
bareTag = (t) => t ? t.replace(/^W\//, "").replace(/^"|"$/g, "") : null;
|
|
6470
|
+
HF_REPO = /^https:\/\/huggingface\.co\/([^/]+\/[^/]+)\/resolve\//;
|
|
6471
|
+
SEEN = Symbol.for("hackbuild.licence.seen");
|
|
6425
6472
|
}));
|
|
6426
6473
|
// packages/weights/src/repo.ts
|
|
6427
6474
|
/** Hugging Face resolve URL base for a repo and revision. Pin a commit hash for reproducible loads. */
|
|
@@ -6492,13 +6539,18 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6492
6539
|
* env.customCache = transformersCache(store, ...)`). URLs that
|
|
6493
6540
|
* `licenceFor` names are downloaded through the store on `match`, so they
|
|
6494
6541
|
* get parts, resume and the licence line; other URLs pass through to
|
|
6495
|
-
* transformers.js's own fetch and are stored on `put`.
|
|
6542
|
+
* transformers.js's own fetch and are stored on `put`. Keys that are not
|
|
6543
|
+
* http(s) URLs (the local model path) miss without a fetch.
|
|
6496
6544
|
*/
|
|
6497
6545
|
function transformersCache(store, opts) {
|
|
6498
|
-
const urlOf = (r) =>
|
|
6546
|
+
const urlOf = (r) => {
|
|
6547
|
+
const u = typeof r === "string" ? r : r.url;
|
|
6548
|
+
return REMOTE.test(u) && opts.keyFor ? opts.keyFor(u) : u;
|
|
6549
|
+
};
|
|
6499
6550
|
return {
|
|
6500
6551
|
async match(req) {
|
|
6501
6552
|
const url = urlOf(req);
|
|
6553
|
+
if (!REMOTE.test(url)) return void 0;
|
|
6502
6554
|
const licence = opts.licenceFor(url);
|
|
6503
6555
|
if (licence !== null) {
|
|
6504
6556
|
const o = opts.onProgress ? { onProgress: opts.onProgress } : {};
|
|
@@ -6523,6 +6575,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6523
6575
|
},
|
|
6524
6576
|
async put(req, res) {
|
|
6525
6577
|
const url = urlOf(req);
|
|
6578
|
+
if (!REMOTE.test(url)) return;
|
|
6526
6579
|
if (await store.has(url)) return;
|
|
6527
6580
|
await store.put({
|
|
6528
6581
|
key: url,
|
|
@@ -6532,7 +6585,10 @@ var HackbuildAiViews = (function(exports) {
|
|
|
6532
6585
|
}
|
|
6533
6586
|
};
|
|
6534
6587
|
}
|
|
6535
|
-
var
|
|
6588
|
+
var REMOTE;
|
|
6589
|
+
var init_repo = __esmMin((() => {
|
|
6590
|
+
REMOTE = /^https?:\/\//;
|
|
6591
|
+
}));
|
|
6536
6592
|
// packages/weights/src/index.ts
|
|
6537
6593
|
var src_exports$8 = /* @__PURE__ */ __exportAll({
|
|
6538
6594
|
Sha256: () => Sha256,
|
|
@@ -13798,7 +13854,9 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13798
13854
|
const rec = o.record ?? VISION_RECORDS.find((r) => r.provides.includes("depth") && r.source.modelId === (o.modelId ?? "onnx-community/depth-anything-v2-small"));
|
|
13799
13855
|
if (!rec?.source.modelId) throw new Error(`depth worker: ${o.modelId} is not a registered depth record; pass record with its licence named`);
|
|
13800
13856
|
const pinned = withPin(rec);
|
|
13801
|
-
|
|
13857
|
+
const line = `model ${pinned.id}: weight licence ${pinned.licence}. the weights are not part of this library.`;
|
|
13858
|
+
if (o.onLicence) o.onLicence(line);
|
|
13859
|
+
else if (firstInSession$1(pinned.source.modelId ?? pinned.id)) console.info(line);
|
|
13802
13860
|
await call({
|
|
13803
13861
|
op: "load",
|
|
13804
13862
|
urls: [...o.urls],
|
|
@@ -18398,6 +18456,10 @@ self.onmessage = async (ev) => {
|
|
|
18398
18456
|
}
|
|
18399
18457
|
return null;
|
|
18400
18458
|
}
|
|
18459
|
+
/** The pinned revision of the record a Hugging Face repo belongs to, so resolve/main requests share one stored file. */
|
|
18460
|
+
function revisionFor(repo) {
|
|
18461
|
+
return ALL_RECORDS.find((r) => (r.source.modelId ?? r.source.repo) === repo)?.source.revision;
|
|
18462
|
+
}
|
|
18401
18463
|
async function makeRuntime(o) {
|
|
18402
18464
|
const [{ loadOrt, loadTransformers, ortProvider, runtimeLoader, tjsProvider }, { openWeightStore, transformersCache }] = await Promise.all([Promise.resolve().then(() => (init_src$9(), src_exports$7)), Promise.resolve().then(() => (init_src$11(), src_exports$8))]);
|
|
18403
18465
|
const [env, store] = await Promise.all([o.env ?? probe(), o.store ?? openWeightStore()]);
|
|
@@ -18414,7 +18476,10 @@ self.onmessage = async (ev) => {
|
|
|
18414
18476
|
};
|
|
18415
18477
|
const tjs = tjsProvider({
|
|
18416
18478
|
runtime: m.transformers ?? loadTransformers(),
|
|
18417
|
-
cache: transformersCache(store, {
|
|
18479
|
+
cache: transformersCache(store, {
|
|
18480
|
+
licenceFor,
|
|
18481
|
+
keyFor: (u) => pinnedUrl(u, revisionFor)
|
|
18482
|
+
})
|
|
18418
18483
|
});
|
|
18419
18484
|
const [vision, chatTjs, embed] = await Promise.all([
|
|
18420
18485
|
Promise.resolve().then(() => (init_src$2(), src_exports$1)),
|
package/dist/single/index.js
CHANGED
|
@@ -3047,10 +3047,31 @@ function pinnedSha(url) {
|
|
|
3047
3047
|
function pinnedBase(repo, fallback = "main") {
|
|
3048
3048
|
return `https://huggingface.co/${repo}/resolve/${pinOf(repo)?.revision ?? fallback}/`;
|
|
3049
3049
|
}
|
|
3050
|
-
|
|
3050
|
+
/**
|
|
3051
|
+
* A Hugging Face resolve URL at the pinned commit when it names a pinned
|
|
3052
|
+
* repo at `main` (transformers.js lists files at main before it loads at
|
|
3053
|
+
* the revision it was given); any other URL comes back unchanged.
|
|
3054
|
+
* `revisionFor` names revisions for repos outside the pins.
|
|
3055
|
+
*/
|
|
3056
|
+
function pinnedUrl(url, revisionFor) {
|
|
3057
|
+
const m = HF.exec(url);
|
|
3058
|
+
if (!m || m[2] !== "main") return url;
|
|
3059
|
+
const rev = revisionFor?.(m[1]) ?? pinOf(m[1])?.revision;
|
|
3060
|
+
return rev ? `https://huggingface.co/${m[1]}/resolve/${rev}/${m[3]}` : url;
|
|
3061
|
+
}
|
|
3062
|
+
/** True the first time a model is named in this page session; shared by every hackbuild package through a global symbol. */
|
|
3063
|
+
function firstInSession$1(model) {
|
|
3064
|
+
const g = globalThis;
|
|
3065
|
+
const seen = g[SEEN$1] ??= /* @__PURE__ */ new Set();
|
|
3066
|
+
if (seen.has(model)) return false;
|
|
3067
|
+
seen.add(model);
|
|
3068
|
+
return true;
|
|
3069
|
+
}
|
|
3070
|
+
var HF, SEEN$1;
|
|
3051
3071
|
var init_pinning = __esmMin((() => {
|
|
3052
3072
|
init_pins();
|
|
3053
3073
|
HF = /^https:\/\/huggingface\.co\/([^/]+\/[^/]+)\/resolve\/([^/]+)\/(.+)$/;
|
|
3074
|
+
SEEN$1 = Symbol.for("hackbuild.licence.seen");
|
|
3054
3075
|
}));
|
|
3055
3076
|
// packages/models/src/registry.ts
|
|
3056
3077
|
/** Size class by download size: tiny under 400 MB, small under 1.5 GB, medium under 3.5 GB (inferred cut points). */
|
|
@@ -4748,7 +4769,10 @@ function createHub(opts = {}) {
|
|
|
4748
4769
|
if (!told.has(record.id)) {
|
|
4749
4770
|
told.add(record.id);
|
|
4750
4771
|
const rev = record.source.revision ? ` at ${record.source.revision.slice(0, 7)}` : "";
|
|
4751
|
-
|
|
4772
|
+
const line = `model ${record.id}${rev}: weight licence ${record.licence}. the weights are not part of this library.`;
|
|
4773
|
+
const first = firstInSession$1(record.source.repo ?? record.source.modelId ?? record.source.url ?? record.id);
|
|
4774
|
+
if (opts.onLicence) opts.onLicence(line, record);
|
|
4775
|
+
else if (first) console.info(line);
|
|
4752
4776
|
}
|
|
4753
4777
|
const factory = factories.get(record.provider);
|
|
4754
4778
|
if (!factory) throw new HubError("no-provider", `no factory for provider ${record.provider}; call hub.provide("${record.provider}", ...)`);
|
|
@@ -4937,6 +4961,7 @@ var HubError;
|
|
|
4937
4961
|
var init_hub$1 = __esmMin((() => {
|
|
4938
4962
|
init_record();
|
|
4939
4963
|
init_registry();
|
|
4964
|
+
init_pinning();
|
|
4940
4965
|
HubError = class extends Error {
|
|
4941
4966
|
code;
|
|
4942
4967
|
constructor(code, message) {
|
|
@@ -6038,7 +6063,7 @@ async function assemble(b, meta) {
|
|
|
6038
6063
|
async function openWeightStore(opts = {}) {
|
|
6039
6064
|
const partBytes = opts.partBytes ?? 134217728;
|
|
6040
6065
|
const doFetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
6041
|
-
const notice = opts.onNotice
|
|
6066
|
+
const notice = opts.onNotice;
|
|
6042
6067
|
const now = opts.now ?? (() => Date.now());
|
|
6043
6068
|
let backend = null;
|
|
6044
6069
|
for (const b of pickBackends(opts)) try {
|
|
@@ -6072,9 +6097,13 @@ async function openWeightStore(opts = {}) {
|
|
|
6072
6097
|
};
|
|
6073
6098
|
const onceMap = /* @__PURE__ */ new Map();
|
|
6074
6099
|
const tellLicence = (key, licence) => {
|
|
6075
|
-
|
|
6076
|
-
noticed.
|
|
6077
|
-
|
|
6100
|
+
const model = modelOf(key);
|
|
6101
|
+
if (noticed.has(model)) return;
|
|
6102
|
+
noticed.add(model);
|
|
6103
|
+
const first = firstInSession(model);
|
|
6104
|
+
const line = `weights ${model}: licence ${licence}. the weights are not part of this library.`;
|
|
6105
|
+
if (notice) notice(line);
|
|
6106
|
+
else if (first) console.info(line);
|
|
6078
6107
|
};
|
|
6079
6108
|
const estimate = async () => {
|
|
6080
6109
|
const fn = opts.estimate ?? (() => globalThis.navigator?.storage?.estimate?.() ?? Promise.resolve({}));
|
|
@@ -6407,7 +6436,23 @@ async function openWeightStore(opts = {}) {
|
|
|
6407
6436
|
};
|
|
6408
6437
|
return store;
|
|
6409
6438
|
}
|
|
6410
|
-
|
|
6439
|
+
/** The model a weight key belongs to: its Hugging Face repo, the folder of any other URL, or a non URL key as is. */
|
|
6440
|
+
function modelOf(key) {
|
|
6441
|
+
const m = HF_REPO.exec(key);
|
|
6442
|
+
if (m) return m[1];
|
|
6443
|
+
if (!/^https?:\/\//.test(key)) return key;
|
|
6444
|
+
const cut = key.split("?")[0].lastIndexOf("/");
|
|
6445
|
+
return cut > 0 ? key.slice(0, cut) : key;
|
|
6446
|
+
}
|
|
6447
|
+
/** True the first time a model is named in this page session; shared by every hackbuild package through a global symbol. */
|
|
6448
|
+
function firstInSession(model) {
|
|
6449
|
+
const g = globalThis;
|
|
6450
|
+
const seen = g[SEEN] ??= /* @__PURE__ */ new Set();
|
|
6451
|
+
if (seen.has(model)) return false;
|
|
6452
|
+
seen.add(model);
|
|
6453
|
+
return true;
|
|
6454
|
+
}
|
|
6455
|
+
var WeightError, bareTag, HF_REPO, SEEN;
|
|
6411
6456
|
var init_store = __esmMin((() => {
|
|
6412
6457
|
init_backends();
|
|
6413
6458
|
init_sha256();
|
|
@@ -6420,6 +6465,8 @@ var init_store = __esmMin((() => {
|
|
|
6420
6465
|
}
|
|
6421
6466
|
};
|
|
6422
6467
|
bareTag = (t) => t ? t.replace(/^W\//, "").replace(/^"|"$/g, "") : null;
|
|
6468
|
+
HF_REPO = /^https:\/\/huggingface\.co\/([^/]+\/[^/]+)\/resolve\//;
|
|
6469
|
+
SEEN = Symbol.for("hackbuild.licence.seen");
|
|
6423
6470
|
}));
|
|
6424
6471
|
// packages/weights/src/repo.ts
|
|
6425
6472
|
/** Hugging Face resolve URL base for a repo and revision. Pin a commit hash for reproducible loads. */
|
|
@@ -6490,13 +6537,18 @@ async function ortExternalData(files, graphPath) {
|
|
|
6490
6537
|
* env.customCache = transformersCache(store, ...)`). URLs that
|
|
6491
6538
|
* `licenceFor` names are downloaded through the store on `match`, so they
|
|
6492
6539
|
* get parts, resume and the licence line; other URLs pass through to
|
|
6493
|
-
* transformers.js's own fetch and are stored on `put`.
|
|
6540
|
+
* transformers.js's own fetch and are stored on `put`. Keys that are not
|
|
6541
|
+
* http(s) URLs (the local model path) miss without a fetch.
|
|
6494
6542
|
*/
|
|
6495
6543
|
function transformersCache(store, opts) {
|
|
6496
|
-
const urlOf = (r) =>
|
|
6544
|
+
const urlOf = (r) => {
|
|
6545
|
+
const u = typeof r === "string" ? r : r.url;
|
|
6546
|
+
return REMOTE.test(u) && opts.keyFor ? opts.keyFor(u) : u;
|
|
6547
|
+
};
|
|
6497
6548
|
return {
|
|
6498
6549
|
async match(req) {
|
|
6499
6550
|
const url = urlOf(req);
|
|
6551
|
+
if (!REMOTE.test(url)) return void 0;
|
|
6500
6552
|
const licence = opts.licenceFor(url);
|
|
6501
6553
|
if (licence !== null) {
|
|
6502
6554
|
const o = opts.onProgress ? { onProgress: opts.onProgress } : {};
|
|
@@ -6521,6 +6573,7 @@ function transformersCache(store, opts) {
|
|
|
6521
6573
|
},
|
|
6522
6574
|
async put(req, res) {
|
|
6523
6575
|
const url = urlOf(req);
|
|
6576
|
+
if (!REMOTE.test(url)) return;
|
|
6524
6577
|
if (await store.has(url)) return;
|
|
6525
6578
|
await store.put({
|
|
6526
6579
|
key: url,
|
|
@@ -6530,7 +6583,10 @@ function transformersCache(store, opts) {
|
|
|
6530
6583
|
}
|
|
6531
6584
|
};
|
|
6532
6585
|
}
|
|
6533
|
-
var
|
|
6586
|
+
var REMOTE;
|
|
6587
|
+
var init_repo = __esmMin((() => {
|
|
6588
|
+
REMOTE = /^https?:\/\//;
|
|
6589
|
+
}));
|
|
6534
6590
|
// packages/weights/src/index.ts
|
|
6535
6591
|
var src_exports$8 = /* @__PURE__ */ __exportAll({
|
|
6536
6592
|
Sha256: () => Sha256,
|
|
@@ -13796,7 +13852,9 @@ async function depthWorker(o) {
|
|
|
13796
13852
|
const rec = o.record ?? VISION_RECORDS.find((r) => r.provides.includes("depth") && r.source.modelId === (o.modelId ?? "onnx-community/depth-anything-v2-small"));
|
|
13797
13853
|
if (!rec?.source.modelId) throw new Error(`depth worker: ${o.modelId} is not a registered depth record; pass record with its licence named`);
|
|
13798
13854
|
const pinned = withPin(rec);
|
|
13799
|
-
|
|
13855
|
+
const line = `model ${pinned.id}: weight licence ${pinned.licence}. the weights are not part of this library.`;
|
|
13856
|
+
if (o.onLicence) o.onLicence(line);
|
|
13857
|
+
else if (firstInSession$1(pinned.source.modelId ?? pinned.id)) console.info(line);
|
|
13800
13858
|
await call({
|
|
13801
13859
|
op: "load",
|
|
13802
13860
|
urls: [...o.urls],
|
|
@@ -18396,6 +18454,10 @@ function licenceFor(url) {
|
|
|
18396
18454
|
}
|
|
18397
18455
|
return null;
|
|
18398
18456
|
}
|
|
18457
|
+
/** The pinned revision of the record a Hugging Face repo belongs to, so resolve/main requests share one stored file. */
|
|
18458
|
+
function revisionFor(repo) {
|
|
18459
|
+
return ALL_RECORDS.find((r) => (r.source.modelId ?? r.source.repo) === repo)?.source.revision;
|
|
18460
|
+
}
|
|
18399
18461
|
async function makeRuntime(o) {
|
|
18400
18462
|
const [{ loadOrt, loadTransformers, ortProvider, runtimeLoader, tjsProvider }, { openWeightStore, transformersCache }] = await Promise.all([Promise.resolve().then(() => (init_src$9(), src_exports$7)), Promise.resolve().then(() => (init_src$11(), src_exports$8))]);
|
|
18401
18463
|
const [env, store] = await Promise.all([o.env ?? probe(), o.store ?? openWeightStore()]);
|
|
@@ -18412,7 +18474,10 @@ async function makeRuntime(o) {
|
|
|
18412
18474
|
};
|
|
18413
18475
|
const tjs = tjsProvider({
|
|
18414
18476
|
runtime: m.transformers ?? loadTransformers(),
|
|
18415
|
-
cache: transformersCache(store, {
|
|
18477
|
+
cache: transformersCache(store, {
|
|
18478
|
+
licenceFor,
|
|
18479
|
+
keyFor: (u) => pinnedUrl(u, revisionFor)
|
|
18480
|
+
})
|
|
18416
18481
|
});
|
|
18417
18482
|
const [vision, chatTjs, embed] = await Promise.all([
|
|
18418
18483
|
Promise.resolve().then(() => (init_src$2(), src_exports$1)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/ai-views",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Views that bind the browser AI packages to hackbuild-ui: a model picker per job, a chat pane and composer, a drop first transcriber, a mask studio, a frame view and a camera feed. Each ships as a Vue component and a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"@hackbuild/ai-env": "0.1.2",
|
|
45
45
|
"@hackbuild/audio-dsp": "0.1.2",
|
|
46
46
|
"@hackbuild/chat": "0.1.3",
|
|
47
|
-
"@hackbuild/devices": "0.1.
|
|
48
|
-
"@hackbuild/embed": "0.1.
|
|
49
|
-
"@hackbuild/imagegen": "0.2.
|
|
47
|
+
"@hackbuild/devices": "0.1.4",
|
|
48
|
+
"@hackbuild/embed": "0.1.5",
|
|
49
|
+
"@hackbuild/imagegen": "0.2.1",
|
|
50
50
|
"@hackbuild/memory": "0.1.4",
|
|
51
|
-
"@hackbuild/models": "0.2.
|
|
52
|
-
"@hackbuild/speak": "0.1.
|
|
53
|
-
"@hackbuild/transcribe": "0.1.
|
|
54
|
-
"@hackbuild/vision": "0.2.
|
|
55
|
-
"@hackbuild/weights": "0.1.
|
|
51
|
+
"@hackbuild/models": "0.2.3",
|
|
52
|
+
"@hackbuild/speak": "0.1.4",
|
|
53
|
+
"@hackbuild/transcribe": "0.1.4",
|
|
54
|
+
"@hackbuild/vision": "0.2.2",
|
|
55
|
+
"@hackbuild/weights": "0.1.3"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@virgilvox/hackbuild-ui": ">=0.10.0 <0.11.0",
|