@hackbuild/vision 0.1.1 → 0.1.3

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.
@@ -1,7 +1,7 @@
1
1
  var HackbuildVision = (function(exports) {
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  // packages/models/src/record.ts
4
- /** The onnxruntime-web ladder the earlier transcription tool walks after one fetch: webgpu at basic, all, disabled, then wasm. */
4
+ /** The onnxruntime-web ladder to walk after one fetch: webgpu at basic, all, disabled, then wasm. */
5
5
  function ortLadder() {
6
6
  return [
7
7
  {
@@ -35,6 +35,7 @@ var HackbuildVision = (function(exports) {
35
35
  ];
36
36
  }
37
37
  // packages/models/src/pins.ts
38
+ /** Pinned commits and file hashes per Hugging Face repo, written by tools/pin-weights.mjs. */
38
39
  const PINS = {
39
40
  "HuggingFaceTB/SmolLM2-135M-Instruct": {
40
41
  "revision": "12fd25f77366fa6b3b4b768ec3050bf629380bac",
@@ -2883,6 +2884,7 @@ var HackbuildVision = (function(exports) {
2883
2884
  * added to a registry, so every loader resolves `resolve/<commit>/` URLs,
2884
2885
  * and pinnedSha gives the SHA-256 for such a URL.
2885
2886
  */
2887
+ /** The pin of a repo, or undefined when the repo is not pinned. */
2886
2888
  function pinOf(repo) {
2887
2889
  return repo && Object.hasOwn(PINS, repo) ? PINS[repo] : void 0;
2888
2890
  }
@@ -2921,25 +2923,25 @@ var HackbuildVision = (function(exports) {
2921
2923
  }
2922
2924
  return spec.wasmFirst ? [...cpu, ...gpu] : [...gpu, ...cpu];
2923
2925
  }
2924
- /** onnxruntime-web rungs: the earlier transcription tool walk, or wasm only when the graph is known to fail on webgpu. */
2926
+ /** onnxruntime-web rungs: webgpu then wasm, or wasm only when the graph is known to fail on webgpu. */
2925
2927
  function ortRungs(opts = {}) {
2926
2928
  const all = ortLadder();
2927
2929
  return opts.webgpu === false ? all.filter((r) => r.device === "wasm") : all;
2928
2930
  }
2929
- /** Ladders by name, from the builds. Each model record may copy one or write its own. */
2931
+ /** Ladders by name, one per model family. Each model record may copy one or write its own. */
2930
2932
  const LADDERS = {
2931
- /** an earlier relief bench runDepth. */
2933
+ /** Depth: fp16 then fp32 on webgpu, q8 then fp32 on wasm. */
2932
2934
  depth: () => tjsLadder({
2933
2935
  webgpu: ["fp16", "fp32"],
2934
2936
  wasm: ["q8", "fp32"]
2935
2937
  }),
2936
- /** earlier builds: perception models on cpu by default. */
2938
+ /** Perception models on cpu by default. */
2937
2939
  perceptionCpu: () => tjsLadder({
2938
2940
  webgpu: ["fp32"],
2939
2941
  wasm: ["q8", "fp32"],
2940
2942
  wasmFirst: true
2941
2943
  }),
2942
- /** whisper-large-v3-turbo (weights MIT), as the earlier transcription tool ran it. */
2944
+ /** whisper-large-v3-turbo (weights MIT). */
2943
2945
  whisperTurbo: () => tjsLadder({
2944
2946
  webgpu: [{
2945
2947
  encoder_model: "fp16",
@@ -2964,7 +2966,7 @@ var HackbuildVision = (function(exports) {
2964
2966
  decoder_model_merged: "q8"
2965
2967
  }]
2966
2968
  }),
2967
- /** SmolVLM (weights Apache-2.0): fp16 embed and vision, q4 decoder on webgpu; q8 vision on wasm, as earlier builds ran it. */
2969
+ /** SmolVLM (weights Apache-2.0): fp16 embed and vision, q4 decoder on webgpu; q8 vision on wasm. */
2968
2970
  smolvlm: () => tjsLadder({
2969
2971
  webgpu: [{
2970
2972
  embed_tokens: "fp32",
@@ -2982,11 +2984,12 @@ var HackbuildVision = (function(exports) {
2982
2984
  }],
2983
2985
  freshHeapRetry: true
2984
2986
  }),
2985
- /** earlier builds: q4f16 on webgpu only. */
2987
+ /** q4f16 on webgpu only. */
2986
2988
  vlmGpuOnly: () => tjsLadder({ webgpu: ["q4f16", "q4"] }),
2987
2989
  ort: ortRungs
2988
2990
  };
2989
2991
  // packages/ai-env/src/source.ts
2992
+ /** Applies string or RegExp rewrites to source text and reports each one that matched nothing. */
2990
2993
  function rewriteSource(src, rewrites) {
2991
2994
  let text = src;
2992
2995
  const missed = [];
@@ -3016,7 +3019,7 @@ var HackbuildVision = (function(exports) {
3016
3019
  const MODULE_WORKER = /new\s+Worker\(\s*([^,()]+(?:\([^()]*\))?[^,()]*)\s*,\s*\{([^{}]*)\}\s*\)/g;
3017
3020
  /**
3018
3021
  * Turn module workers into classic workers: Chrome refuses module workers
3019
- * from a file:// page (as earlier builds did). Other option keys
3022
+ * from a file:// page. Other option keys
3020
3023
  * are kept. Returns the text and how many constructors changed.
3021
3024
  */
3022
3025
  function toClassicWorker(src) {
@@ -3061,6 +3064,7 @@ var HackbuildVision = (function(exports) {
3061
3064
  }
3062
3065
  return parts.join("");
3063
3066
  }
3067
+ /** Encodes text as a base64 data: URL, JavaScript by default. */
3064
3068
  function textToDataUrl(text, mime = "text/javascript") {
3065
3069
  return `data:${mime};base64,${bytesToBase64(new TextEncoder().encode(text))}`;
3066
3070
  }
@@ -3070,7 +3074,7 @@ var HackbuildVision = (function(exports) {
3070
3074
  *
3071
3075
  * importEsm: plain import() first when nothing needs patching and the page
3072
3076
  * is served over http(s); else fetch the text, patch it, import it from a
3073
- * Blob URL, then from a base64 data: URL (as earlier builds did). Each URL in
3077
+ * Blob URL, then from a base64 data: URL. Each URL in
3074
3078
  * `urls` is tried in order, so a CDN fallback list is one call.
3075
3079
  *
3076
3080
  * spawnWorker: the worker ladder, written once. Rungs are module-blob,
@@ -3089,6 +3093,10 @@ var HackbuildVision = (function(exports) {
3089
3093
  const d = new Uint8Array(await subtle.digest("SHA-256", new TextEncoder().encode(text)));
3090
3094
  return Array.from(d, (b) => b.toString(16).padStart(2, "0")).join("");
3091
3095
  }
3096
+ /**
3097
+ * The error importEsm and spawnWorker throw when every URL or rung failed, with one entry per
3098
+ * attempt in `attempts`.
3099
+ */
3092
3100
  var LoadError = class extends Error {
3093
3101
  attempts;
3094
3102
  constructor(message, attempts) {
@@ -3104,6 +3112,10 @@ var HackbuildVision = (function(exports) {
3104
3112
  function errText(e) {
3105
3113
  return e instanceof Error ? `${e.name}: ${e.message}` : String(e);
3106
3114
  }
3115
+ /**
3116
+ * Imports an ES module from the first URL that loads, through plain import, then a patched Blob
3117
+ * URL, then a base64 data: URL, checking a SHA-256 when you give one.
3118
+ */
3107
3119
  async function importEsm(urls, opts = {}) {
3108
3120
  const list = typeof urls === "string" ? [urls] : urls;
3109
3121
  const importer = opts.importer ?? nativeImport;
@@ -3392,17 +3404,23 @@ var HackbuildVision = (function(exports) {
3392
3404
  // packages/vision/src/records.ts
3393
3405
  /**
3394
3406
  * Vision records for the models hub. Licences are the model cards' as of
3395
- * 2026-11-22; sizes are inferred from the builds and parameter counts.
3407
+ * 2026-11-22; sizes are inferred from the builds and parameter counts, except where
3408
+ * a row says vendor: those sum the hub listing's files (no download), in MiB.
3396
3409
  * YOLO weights are AGPL-3.0 (Ultralytics): they are never registered by
3397
- * default, and `yoloRecord` builds a record only for a URL the app
3398
- * supplies.
3410
+ * default. YOLOv8n has no public hub repo, so `yoloRecord` builds a record
3411
+ * only for a URL the app supplies; YOLOv10 n, s and m, FastSAM and the face
3412
+ * swap set sit in PICKER_RECORDS.
3399
3413
  */
3414
+ /** The MediaPipe model storage base URL the MediaPipe records load from. */
3400
3415
  const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
3401
3416
  /** MediaPipe ladder: GPU delegate (webgl), then the CPU delegate (wasm). */
3402
3417
  const mediapipeLadder = () => [{ device: "webgl" }, { device: "wasm" }];
3403
- const mp = (id, provides, path, sizeMB, label) => ({
3418
+ const mp = (id, provides, path, sizeMB, label, verdict = "light, on the gpu", group = "start here") => ({
3404
3419
  id,
3405
3420
  label,
3421
+ group,
3422
+ speed: "instant",
3423
+ verdict,
3406
3424
  provides: [provides],
3407
3425
  provider: "mediapipe",
3408
3426
  source: { url: MP_MODELS + path },
@@ -3414,10 +3432,14 @@ var HackbuildVision = (function(exports) {
3414
3432
  place: "main",
3415
3433
  runtime: "@mediapipe/tasks-vision@1.2.3"
3416
3434
  });
3435
+ /** The vision records registered by `attachVision`: Depth Anything V2 small, MediaPipe detection, segmentation and landmarks, SlimSAM, SmolVLM 256M and LFM2-VL 450M. */
3417
3436
  const VISION_RECORDS = [
3418
3437
  {
3419
3438
  id: "depth-anything-v2-small",
3420
3439
  label: "depth anything v2 small",
3440
+ speed: "fast",
3441
+ verdict: "good edges",
3442
+ group: "start here",
3421
3443
  provides: ["depth"],
3422
3444
  provider: "tjs",
3423
3445
  source: { modelId: "onnx-community/depth-anything-v2-small" },
@@ -3428,9 +3450,9 @@ var HackbuildVision = (function(exports) {
3428
3450
  commercial: true,
3429
3451
  place: "cpu-worker",
3430
3452
  runtime: "@huggingface/transformers@4.3.2",
3431
- notes: ["earlier builds: fp16 on webgpu, fp32 on the same device after a failure"]
3453
+ notes: ["fp16 on webgpu, fp32 on the same device after a failure"]
3432
3454
  },
3433
- mp("efficientdet-lite0", "detect", "object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite", 7, "mediapipe efficientdet lite0 (coco, 80 classes)"),
3455
+ mp("efficientdet-lite0", "detect", "object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite", 7, "mediapipe efficientdet lite0 (coco, 80 classes)", "light, 80 things"),
3434
3456
  mp("selfie-segmenter", "segment.person", "image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite", 1, "mediapipe selfie segmenter"),
3435
3457
  mp("face-landmarker", "landmarks.face", "face_landmarker/face_landmarker/float16/1/face_landmarker.task", 4, "mediapipe face landmarker with blendshapes"),
3436
3458
  mp("hand-landmarker", "landmarks.hand", "hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task", 8, "mediapipe hand landmarker"),
@@ -3444,11 +3466,14 @@ var HackbuildVision = (function(exports) {
3444
3466
  {
3445
3467
  id: "slimsam-77-uniform",
3446
3468
  label: "slimsam 77 uniform (point prompts)",
3469
+ speed: "fast",
3470
+ verdict: "click to cut",
3471
+ group: "start here",
3447
3472
  provides: ["segment"],
3448
3473
  provider: "tjs",
3449
3474
  source: { modelId: "Xenova/slimsam-77-uniform" },
3450
- sizeMB: 40,
3451
- sizeSource: "inferred",
3475
+ sizeMB: 38,
3476
+ sizeSource: "vendor",
3452
3477
  ladder: tjsLadder({
3453
3478
  webgpu: ["fp16", "fp32"],
3454
3479
  wasm: ["fp32"]
@@ -3457,11 +3482,14 @@ var HackbuildVision = (function(exports) {
3457
3482
  commercial: true,
3458
3483
  place: "cpu-worker",
3459
3484
  runtime: "@huggingface/transformers@4.3.2",
3460
- notes: ["earlier builds: one image embedding, then any number of point prompts"]
3485
+ notes: ["one image embedding, then any number of point prompts"]
3461
3486
  },
3462
3487
  {
3463
3488
  id: "smolvlm-256m-instruct",
3464
3489
  label: "smolvlm 256m",
3490
+ speed: "fast",
3491
+ verdict: "fastest, short answers",
3492
+ group: "start here",
3465
3493
  provides: ["vision.caption", "vision.ask"],
3466
3494
  provider: "tjs",
3467
3495
  source: { modelId: "HuggingFaceTB/SmolVLM-256M-Instruct" },
@@ -3480,6 +3508,9 @@ var HackbuildVision = (function(exports) {
3480
3508
  {
3481
3509
  id: "lfm2-vl-450m",
3482
3510
  label: "lfm2-vl 450m",
3511
+ speed: "fast",
3512
+ verdict: "faster, sharper",
3513
+ group: "tiny",
3483
3514
  provides: ["vision.caption", "vision.ask"],
3484
3515
  provider: "tjs",
3485
3516
  source: { modelId: "onnx-community/LFM2-VL-450M-ONNX" },
@@ -3494,7 +3525,250 @@ var HackbuildVision = (function(exports) {
3494
3525
  commercial: "unknown",
3495
3526
  place: "gpu",
3496
3527
  runtime: "@huggingface/transformers@4.3.2",
3497
- notes: ["earlier builds: q4f16 on webgpu only; the licence limits commercial use by revenue, read it before shipping"]
3528
+ notes: ["q4f16 on webgpu only; the licence limits commercial use by revenue, read it before shipping"]
3529
+ }
3530
+ ];
3531
+ /**
3532
+ * Records listed for pickers and never registered by default, so a hub's
3533
+ * routing by capability keeps its small defaults: larger alternates (smolvlm 500m and 2 video, gemma 4 e2b, two more
3534
+ * depth models), and records under licences that limit use (YOLOv10 and
3535
+ * FastSAM are AGPL-3.0 upstream, Ultralytics; the face swap set is
3536
+ * InsightFace, non-commercial). A hub that runs one adds it itself. Sizes
3537
+ * are the hub listings' files (vendor, 2026-11-25), in MiB.
3538
+ */
3539
+ const yolo10 = (size, mb, speed, verdict) => ({
3540
+ id: `yolov10${size}`,
3541
+ label: `yolov10 ${{
3542
+ n: "nano",
3543
+ s: "small",
3544
+ m: "medium"
3545
+ }[size]}`,
3546
+ group: size === "n" ? "tiny" : "good",
3547
+ speed,
3548
+ verdict,
3549
+ provides: ["detect"],
3550
+ provider: "ort",
3551
+ source: {
3552
+ repo: `onnx-community/yolov10${size}`,
3553
+ file: "onnx/model.onnx"
3554
+ },
3555
+ sizeMB: mb,
3556
+ sizeSource: "vendor",
3557
+ ladder: [{
3558
+ device: "webgpu",
3559
+ ort: { executionProviders: ["webgpu", "wasm"] }
3560
+ }, {
3561
+ device: "wasm",
3562
+ ort: { executionProviders: ["wasm"] }
3563
+ }],
3564
+ licence: "AGPL-3.0 (Ultralytics weights, the model card's licence field)",
3565
+ commercial: false,
3566
+ place: "gpu",
3567
+ notes: ["output [1, 300, 6] after the model's own selection, so no nms pass (vendor, the yolov10 paper)", "comes in nano, small and medium"]
3568
+ });
3569
+ /** Records listed for pickers and never registered by default: larger alternates, and records under licences that limit use (YOLOv10, FastSAM, the face swap set). */
3570
+ const PICKER_RECORDS = [
3571
+ {
3572
+ id: "smolvlm-500m-instruct",
3573
+ label: "smolvlm 500m",
3574
+ speed: "steady",
3575
+ verdict: "better captions, slower",
3576
+ group: "good",
3577
+ provides: ["vision.caption", "vision.ask"],
3578
+ provider: "tjs",
3579
+ source: { modelId: "HuggingFaceTB/SmolVLM-500M-Instruct" },
3580
+ sizeMB: 463,
3581
+ sizeSource: "vendor",
3582
+ ladder: LADDERS.smolvlm(),
3583
+ quirks: {
3584
+ repetitionPenalty: 1.3,
3585
+ maxTokensAction: 64
3586
+ },
3587
+ licence: "Apache-2.0",
3588
+ commercial: true,
3589
+ place: "cpu-worker",
3590
+ runtime: "@huggingface/transformers@4.3.2"
3591
+ },
3592
+ {
3593
+ id: "smolvlm2-256m-video-instruct",
3594
+ label: "smolvlm2 256m video",
3595
+ speed: "fast",
3596
+ verdict: "watches short clips",
3597
+ group: "tiny",
3598
+ provides: ["vision.caption", "vision.ask"],
3599
+ provider: "tjs",
3600
+ source: { modelId: "HuggingFaceTB/SmolVLM2-256M-Video-Instruct" },
3601
+ sizeMB: 252,
3602
+ sizeSource: "vendor",
3603
+ ladder: LADDERS.smolvlm(),
3604
+ quirks: {
3605
+ repetitionPenalty: 1.3,
3606
+ maxTokensAction: 64
3607
+ },
3608
+ licence: "Apache-2.0",
3609
+ commercial: true,
3610
+ place: "cpu-worker",
3611
+ runtime: "@huggingface/transformers@4.3.2",
3612
+ notes: ["an option beside smolvlm 256m and 500m"]
3613
+ },
3614
+ {
3615
+ id: "depth-anything-v2-base",
3616
+ label: "depth anything v2 base",
3617
+ speed: "steady",
3618
+ verdict: "finer depth, non commercial",
3619
+ group: "good",
3620
+ provides: ["depth"],
3621
+ provider: "tjs",
3622
+ source: { modelId: "onnx-community/depth-anything-v2-base" },
3623
+ sizeMB: 186,
3624
+ sizeSource: "vendor",
3625
+ ladder: LADDERS.depth(),
3626
+ licence: "CC-BY-NC-4.0 (the model card's licence field)",
3627
+ commercial: false,
3628
+ place: "cpu-worker",
3629
+ runtime: "@huggingface/transformers@4.3.2"
3630
+ },
3631
+ {
3632
+ id: "depth-anything-small-v1",
3633
+ label: "depth anything v1 small",
3634
+ speed: "fast",
3635
+ verdict: "the first version",
3636
+ group: "tiny",
3637
+ provides: ["depth"],
3638
+ provider: "tjs",
3639
+ source: { modelId: "Xenova/depth-anything-small-hf" },
3640
+ sizeMB: 48,
3641
+ sizeSource: "vendor",
3642
+ ladder: LADDERS.depth(),
3643
+ licence: "Apache-2.0 (the upstream card; this export's card has no licence field)",
3644
+ commercial: "unknown",
3645
+ place: "cpu-worker",
3646
+ runtime: "@huggingface/transformers@4.3.2"
3647
+ },
3648
+ {
3649
+ id: "gemma-4-e2b-vision",
3650
+ label: "gemma 4 e2b",
3651
+ speed: "slow",
3652
+ verdict: "sees most, heavy",
3653
+ group: "good",
3654
+ provides: ["vision.caption", "vision.ask"],
3655
+ provider: "tjs",
3656
+ source: { modelId: "onnx-community/gemma-4-E2B-it-ONNX" },
3657
+ sizeMB: 3566,
3658
+ sizeSource: "vendor",
3659
+ ladder: LADDERS.vlmGpuOnly(),
3660
+ quirks: {
3661
+ systemRole: false,
3662
+ strictAlternation: true,
3663
+ maxTokensAction: 96
3664
+ },
3665
+ licence: "Apache-2.0 (the model card's licence field)",
3666
+ commercial: true,
3667
+ place: "gpu",
3668
+ runtime: "@huggingface/transformers@4.3.2",
3669
+ notes: ["about 3.3 GB (vendor)"]
3670
+ },
3671
+ yolo10("n", 9, "instant", "nano, quick"),
3672
+ yolo10("s", 28, "fast", "small, sharper"),
3673
+ yolo10("m", 59, "steady", "medium, best boxes"),
3674
+ {
3675
+ id: "fastsam-s",
3676
+ label: "fastsam s",
3677
+ speed: "fast",
3678
+ verdict: "finds everything, cpu ok",
3679
+ group: "good",
3680
+ provides: ["segment.everything"],
3681
+ provider: "ort",
3682
+ source: {
3683
+ repo: "anakhiu/fastsam-onnx",
3684
+ file: "fastsam_s.onnx"
3685
+ },
3686
+ sizeMB: 45,
3687
+ sizeSource: "vendor",
3688
+ ladder: [{
3689
+ device: "webgpu",
3690
+ ort: { executionProviders: ["webgpu", "wasm"] }
3691
+ }, {
3692
+ device: "wasm",
3693
+ ort: { executionProviders: ["wasm"] }
3694
+ }],
3695
+ licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
3696
+ commercial: false,
3697
+ place: "cpu-worker",
3698
+ notes: ["finds every mask in one pass on onnxruntime-web (93 MB, vendor)", "segment everything: prototype masks, nms, then a pick by click"]
3699
+ },
3700
+ {
3701
+ id: "scrfd-10g",
3702
+ label: "face finder (scrfd 10g)",
3703
+ speed: "fast",
3704
+ verdict: "finds faces",
3705
+ group: "start here",
3706
+ provides: ["face.detect"],
3707
+ provider: "ort",
3708
+ source: {
3709
+ repo: "immich-app/buffalo_l",
3710
+ file: "detection/model.onnx"
3711
+ },
3712
+ sizeMB: 16,
3713
+ sizeSource: "vendor",
3714
+ ladder: [{
3715
+ device: "wasm",
3716
+ ort: { executionProviders: ["wasm"] }
3717
+ }],
3718
+ licence: "InsightFace model pack: non-commercial research only (the buffalo_l pack terms)",
3719
+ commercial: false,
3720
+ place: "cpu-worker"
3721
+ },
3722
+ {
3723
+ id: "arcface-w600k-r50",
3724
+ label: "face id (arcface r50)",
3725
+ speed: "steady",
3726
+ verdict: "who is who",
3727
+ group: "start here",
3728
+ provides: ["face.embed"],
3729
+ provider: "ort",
3730
+ source: {
3731
+ repo: "immich-app/buffalo_l",
3732
+ file: "recognition/model.onnx"
3733
+ },
3734
+ sizeMB: 166,
3735
+ sizeSource: "vendor",
3736
+ ladder: [{
3737
+ device: "webgpu",
3738
+ ort: { executionProviders: ["webgpu", "wasm"] }
3739
+ }, {
3740
+ device: "wasm",
3741
+ ort: { executionProviders: ["wasm"] }
3742
+ }],
3743
+ licence: "InsightFace model pack: non-commercial research only (the buffalo_l pack terms)",
3744
+ commercial: false,
3745
+ place: "cpu-worker"
3746
+ },
3747
+ {
3748
+ id: "inswapper-128",
3749
+ label: "face swap (inswapper 128)",
3750
+ speed: "slow",
3751
+ verdict: "the swap itself",
3752
+ group: "start here",
3753
+ provides: ["face.swap"],
3754
+ provider: "ort",
3755
+ source: {
3756
+ repo: "hacksider/inswapper_128",
3757
+ file: "inswapper_128.onnx"
3758
+ },
3759
+ sizeMB: 529,
3760
+ sizeSource: "vendor",
3761
+ ladder: [{
3762
+ device: "webgpu",
3763
+ ort: { executionProviders: ["webgpu", "wasm"] }
3764
+ }, {
3765
+ device: "wasm",
3766
+ ort: { executionProviders: ["wasm"] }
3767
+ }],
3768
+ licence: "InsightFace: non-commercial research only; the mirror's card says gpl-3.0",
3769
+ commercial: false,
3770
+ place: "gpu",
3771
+ notes: ["128 px faces; paste the result back with a feathered mask"]
3498
3772
  }
3499
3773
  ];
3500
3774
  /** A face landmark fallback record over face-api.js tiny nets (code MIT; weights MIT from @vladmandic/face-api). */
@@ -3502,6 +3776,9 @@ var HackbuildVision = (function(exports) {
3502
3776
  return {
3503
3777
  id: "face-api-tiny",
3504
3778
  label: "face-api tiny landmarks (68 points)",
3779
+ speed: "instant",
3780
+ verdict: "68 points, cpu",
3781
+ group: "cpu",
3505
3782
  provides: ["landmarks.face"],
3506
3783
  provider: "faceapi",
3507
3784
  source: { url: baseUrl },
@@ -3518,6 +3795,9 @@ var HackbuildVision = (function(exports) {
3518
3795
  return {
3519
3796
  id: o.id ?? "yolov8n",
3520
3797
  label: "yolov8n (external)",
3798
+ group: "tiny",
3799
+ speed: "instant",
3800
+ verdict: "nano, your file",
3521
3801
  provides: ["detect"],
3522
3802
  provider: "ort",
3523
3803
  source: {
@@ -3536,7 +3816,7 @@ var HackbuildVision = (function(exports) {
3536
3816
  licence: o.licence ?? "AGPL-3.0 (Ultralytics YOLOv8 weights), supplied by the app",
3537
3817
  commercial: false,
3538
3818
  place: "gpu",
3539
- notes: ["earlier builds: 640 letterbox, per class nms at iou 0.45, at most 13 boxes"]
3819
+ notes: ["640 letterbox, per class nms at iou 0.45, at most 13 boxes"]
3540
3820
  };
3541
3821
  }
3542
3822
  // packages/vision/src/segment.ts
@@ -3621,7 +3901,7 @@ var HackbuildVision = (function(exports) {
3621
3901
  const R = tjs.RawImage;
3622
3902
  return R?.read ? R.read(img) : img;
3623
3903
  }
3624
- /** Normalize a depth pipeline result. predicted_depth keeps the raw range (as earlier builds did); depth is the 8 bit image (as earlier builds did). */
3904
+ /** Normalize a depth pipeline result. predicted_depth keeps the raw range; depth is the 8 bit image. */
3625
3905
  function depthFromOutput(out) {
3626
3906
  const pd = out.predicted_depth;
3627
3907
  if (pd && pd.data && pd.dims?.length >= 2) {
@@ -3656,6 +3936,7 @@ var HackbuildVision = (function(exports) {
3656
3936
  range: [0, 255]
3657
3937
  };
3658
3938
  }
3939
+ /** The transformers.js loader for depth records: a depth-estimation pipeline wrapped as a {@link DepthModel}. */
3659
3940
  async function depthLoader(ctx) {
3660
3941
  const pipe = await ctx.tjs.pipeline("depth-estimation", ctx.record.source.modelId, ctx.options);
3661
3942
  return {
@@ -3663,6 +3944,7 @@ var HackbuildVision = (function(exports) {
3663
3944
  dispose: () => pipe.dispose?.()
3664
3945
  };
3665
3946
  }
3947
+ /** The transformers.js loader for caption and question records: the VLM's processor and model wrapped as a {@link Vlm}. */
3666
3948
  async function vlmLoader(ctx) {
3667
3949
  const id = ctx.record.source.modelId;
3668
3950
  const processor = await cls(ctx.tjs, "AutoProcessor").from_pretrained(id);
@@ -3750,7 +4032,9 @@ var HackbuildVision = (function(exports) {
3750
4032
  });
3751
4033
  }
3752
4034
  // packages/vision/src/yolo.ts
4035
+ /** The 80 COCO class names, in YOLO class index order. */
3753
4036
  const COCO_LABELS = "person,bicycle,car,motorcycle,airplane,bus,train,truck,boat,traffic light,fire hydrant,stop sign,parking meter,bench,bird,cat,dog,horse,sheep,cow,elephant,bear,zebra,giraffe,backpack,umbrella,handbag,tie,suitcase,frisbee,skis,snowboard,sports ball,kite,baseball bat,baseball glove,skateboard,surfboard,tennis racket,bottle,wine glass,cup,fork,knife,spoon,bowl,banana,apple,sandwich,orange,broccoli,carrot,hot dog,pizza,donut,cake,chair,couch,potted plant,bed,dining table,toilet,tv,laptop,mouse,remote,keyboard,cell phone,microwave,oven,toaster,sink,refrigerator,book,clock,vase,scissors,teddy bear,hair drier,toothbrush".split(",");
4037
+ /** The scale and padding that fit a `w` by `h` image into a `size` square (640 by default), centred. */
3754
4038
  function letterboxParams(w, h, size = 640) {
3755
4039
  const scale = Math.min(size / w, size / h);
3756
4040
  return {
@@ -3783,6 +4067,7 @@ var HackbuildVision = (function(exports) {
3783
4067
  lb
3784
4068
  };
3785
4069
  }
4070
+ /** Intersection over union of two boxes, 0 to 1. */
3786
4071
  function iou(a, b) {
3787
4072
  const x1 = Math.max(a.x, b.x);
3788
4073
  const y1 = Math.max(a.y, b.y);
@@ -3866,7 +4151,7 @@ var HackbuildVision = (function(exports) {
3866
4151
  dispose: () => m.dispose()
3867
4152
  };
3868
4153
  }
3869
- /** Detection cadence as earlier builds ran it: wait max(0.45 s, 4 times the last latency) between runs. */
4154
+ /** Detection cadence: wait max(0.45 s, 4 times the last latency) between runs. */
3870
4155
  function detectCadenceMs(lastLatencyMs) {
3871
4156
  return Math.max(450, 4 * lastLatencyMs);
3872
4157
  }
@@ -3896,6 +4181,7 @@ var HackbuildVision = (function(exports) {
3896
4181
  }
3897
4182
  }
3898
4183
  const target = (cap, o) => o.model ? { id: o.model } : cap;
4184
+ /** A depth map of an image from the routed depth model (Depth Anything V2 small by default), loaded and released through the hub. */
3899
4185
  function depth(hub, image, o = {}) {
3900
4186
  return withModel(hub, target("depth", o), (m) => m.estimate(image), o);
3901
4187
  }
@@ -3903,6 +4189,7 @@ var HackbuildVision = (function(exports) {
3903
4189
  if (v && typeof v === "object" && "sessions" in v) return yoloDetector(v, toPixels ? { toPixels } : {});
3904
4190
  return v;
3905
4191
  }
4192
+ /** Objects in an image from the routed detector (MediaPipe EfficientDet by default, or a YOLO ort model), loaded and released through the hub. */
3906
4193
  function detect(hub, image, o = {}) {
3907
4194
  const opts = {};
3908
4195
  if (o.scoreThreshold !== void 0) opts.scoreThreshold = o.scoreThreshold;
@@ -3960,6 +4247,7 @@ var HackbuildVision = (function(exports) {
3960
4247
  function caption(hub, image, o = {}) {
3961
4248
  return hub.chain("vlm")(() => withModel(hub, target("vision.caption", o), (m) => m.ask(image, void 0, o.maxTokens ? { maxTokens: o.maxTokens } : {}), o));
3962
4249
  }
4250
+ /** Answer a question about an image with the routed vision language model. VLM calls are serialized on one chain. */
3963
4251
  function ask(hub, image, question, o = {}) {
3964
4252
  return hub.chain("vlm")(() => withModel(hub, target("vision.ask", o), (m) => m.ask(image, question, o.maxTokens ? { maxTokens: o.maxTokens } : {}), o));
3965
4253
  }
@@ -3968,17 +4256,21 @@ var HackbuildVision = (function(exports) {
3968
4256
  * A MediaPipe tasks-vision provider for the models hub. One wasm fileset
3969
4257
  * per page; one task per record, created with the GPU delegate on a
3970
4258
  * "webgl" rung and the CPU delegate on a "wasm" rung, so a failed GPU
3971
- * delegate falls to the CPU one (FaceSwap and an earlier scene app had no fallback).
4259
+ * delegate falls to the CPU one.
3972
4260
  * Results are turned into the package's Detector, Segmenter and
3973
4261
  * Landmarker shapes.
3974
4262
  */
4263
+ /** The pinned @mediapipe/tasks-vision version, 1.2.3. */
3975
4264
  const TASKS_VISION = "1.2.3";
4265
+ /** The URL @mediapipe/tasks-vision is imported from, on jsDelivr. */
3976
4266
  function tasksVisionUrls(version = TASKS_VISION) {
3977
4267
  return [`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/vision_bundle.mjs`];
3978
4268
  }
4269
+ /** The directory of the tasks-vision wasm fileset, on jsDelivr. */
3979
4270
  function tasksVisionWasm(version = TASKS_VISION) {
3980
4271
  return `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/wasm`;
3981
4272
  }
4273
+ /** A loader that imports the pinned @mediapipe/tasks-vision at run time; pass it as `runtime` to {@link mediapipeProvider}. */
3982
4274
  const loadTasksVision = (version = TASKS_VISION) => () => importEsm(tasksVisionUrls(version));
3983
4275
  const CLASS = {
3984
4276
  detect: "ObjectDetector",
@@ -4067,6 +4359,7 @@ var HackbuildVision = (function(exports) {
4067
4359
  dispose: () => call(t, "close")
4068
4360
  };
4069
4361
  }
4362
+ /** The MediaPipe tasks-vision provider for the models hub: one task per record, the GPU delegate on a webgl rung and the CPU delegate on a wasm rung. */
4070
4363
  function mediapipeProvider(opts) {
4071
4364
  let fileset = null;
4072
4365
  return async ({ record, rung, signal }) => {
@@ -4104,6 +4397,7 @@ var HackbuildVision = (function(exports) {
4104
4397
  };
4105
4398
  }
4106
4399
  // packages/vision/src/faceapi.ts
4400
+ /** The face-api.js provider for the models hub: the tiny face detector and 68 point tiny landmark net, as a face {@link Landmarker}. */
4107
4401
  function faceApiProvider(opts) {
4108
4402
  return async ({ record }) => {
4109
4403
  const fa = await opts.runtime();
@@ -4123,6 +4417,7 @@ var HackbuildVision = (function(exports) {
4123
4417
  };
4124
4418
  }
4125
4419
  // packages/vision/src/loop.ts
4420
+ /** Run a perception step beside a render loop, one at a time, each started no sooner than `interval(lastLatency)` after the previous one began. */
4126
4421
  function perceptionLoop(o) {
4127
4422
  const now = o.now ?? (() => globalThis.performance ? performance.now() : Date.now());
4128
4423
  const g = globalThis;
@@ -4216,7 +4511,7 @@ var HackbuildVision = (function(exports) {
4216
4511
  }
4217
4512
  };
4218
4513
  }
4219
- /** A small LRU of results by key (an earlier relief bench keeps the depth map with the design so it never reruns). */
4514
+ /** A small LRU of results by key, so a depth map is computed once per image. */
4220
4515
  var ResultCache = class {
4221
4516
  max;
4222
4517
  m = /* @__PURE__ */ new Map();
@@ -4247,7 +4542,7 @@ var HackbuildVision = (function(exports) {
4247
4542
  return this.m.size;
4248
4543
  }
4249
4544
  };
4250
- /** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (an earlier relief bench stores depth as a PNG data URL). */
4545
+ /** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (store it as a PNG data URL to keep it with a design). */
4251
4546
  function depthToRgba(d) {
4252
4547
  const out = new Uint8ClampedArray(d.width * d.height * 4);
4253
4548
  for (let i = 0; i < d.width * d.height; i++) {
@@ -4257,7 +4552,7 @@ var HackbuildVision = (function(exports) {
4257
4552
  }
4258
4553
  return out;
4259
4554
  }
4260
- /** Scale so the longest side is at most maxPx (as earlier builds did). */
4555
+ /** Scale so the longest side is at most maxPx. */
4261
4556
  function fitSize(w, h, maxPx = 1024) {
4262
4557
  const s = Math.min(1, maxPx / Math.max(w, h));
4263
4558
  return {
@@ -4399,6 +4694,7 @@ self.onmessage = async (ev) => {
4399
4694
  height: o?.height ?? 48
4400
4695
  };
4401
4696
  };
4697
+ /** A stub depth model with no weights: a left to right ramp at the image's size. */
4402
4698
  function rampDepth() {
4403
4699
  return { async estimate(img) {
4404
4700
  const { width, height } = dims(img);
@@ -4412,6 +4708,7 @@ self.onmessage = async (ev) => {
4412
4708
  };
4413
4709
  } };
4414
4710
  }
4711
+ /** A stub detector with no weights: one centred box with the given label. */
4415
4712
  function centreDetector(label = "person") {
4416
4713
  return { async detect(img) {
4417
4714
  const { width, height } = dims(img);
@@ -4477,6 +4774,7 @@ self.onmessage = async (ev) => {
4477
4774
  h: 2 * r
4478
4775
  };
4479
4776
  };
4777
+ /** A stub landmarker with no weights: one list of `count` fixed points. */
4480
4778
  function fixedLandmarker(count, source = "stub") {
4481
4779
  return { async detect() {
4482
4780
  return {
@@ -4489,6 +4787,7 @@ self.onmessage = async (ev) => {
4489
4787
  };
4490
4788
  } };
4491
4789
  }
4790
+ /** A stub vision language model with no weights: a fixed caption, or a fixed answer that repeats the question. */
4492
4791
  function fixedVlm(text = "a stub caption.") {
4493
4792
  return { ask: async (_img, q) => q ? `stub answer to: ${q}` : text };
4494
4793
  }
@@ -4534,19 +4833,22 @@ self.onmessage = async (ev) => {
4534
4833
  function maskThreshold(m, t = ON) {
4535
4834
  return make(m, m.data.map((v) => v >= t ? 255 : 0));
4536
4835
  }
4836
+ /** Pixels inside either mask, the larger value of each. Throws when the sizes differ. */
4537
4837
  function maskUnion(a, b) {
4538
4838
  same("maskUnion", a, b);
4539
4839
  return make(a, a.data.map((v, i) => Math.max(v, b.data[i])));
4540
4840
  }
4841
+ /** Pixels inside both masks, the smaller value of each. Throws when the sizes differ. */
4541
4842
  function maskIntersect(a, b) {
4542
4843
  same("maskIntersect", a, b);
4543
4844
  return make(a, a.data.map((v, i) => Math.min(v, b.data[i])));
4544
4845
  }
4545
- /** `a` with `b` taken out (shift with a selection tool in the earlier mask studio). */
4846
+ /** `a` with `b` taken out (shift with a selection tool in a mask editor). */
4546
4847
  function maskSubtract(a, b) {
4547
4848
  same("maskSubtract", a, b);
4548
4849
  return make(a, a.data.map((v, i) => Math.min(v, 255 - b.data[i])));
4549
4850
  }
4851
+ /** The mask with inside and outside swapped, 255 minus each value. */
4550
4852
  function maskInvert(m) {
4551
4853
  return make(m, m.data.map((v) => 255 - v));
4552
4854
  }
@@ -4600,7 +4902,7 @@ self.onmessage = async (ev) => {
4600
4902
  const d = distance2((i) => m.data[i] < ON, m.width, m.height);
4601
4903
  return make(m, Uint8Array.from(d, (v) => v > r * r ? 255 : 0));
4602
4904
  }
4603
- /** Soft edges: a gaussian of radius `r` with sigma r / 2 (the earlier mask studio's smooth, before its rethreshold), edges clamped. */
4905
+ /** Soft edges: a gaussian of radius `r` with sigma r / 2 (a smooth without a rethreshold), edges clamped. */
4604
4906
  function maskFeather(m, r) {
4605
4907
  if (r <= 0) return make(m, m.data.slice());
4606
4908
  const { width: w, height: h } = m;
@@ -4841,6 +5143,7 @@ self.onmessage = async (ev) => {
4841
5143
  const d = maskOutline(m).map((l) => `M${l.map((p) => `${p[0]} ${p[1]}`).join("L")}Z`).join("");
4842
5144
  return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${m.width} ${m.height}" width="${m.width}" height="${m.height}"><path d="${d}" fill="${o.fill ?? "#000"}" fill-rule="evenodd"/></svg>`;
4843
5145
  }
5146
+ /** The mask as COCO style uncompressed run length, column major, 128 and up inside. */
4844
5147
  function maskToRle(m) {
4845
5148
  const { width: w, height: h } = m;
4846
5149
  const counts = [];
@@ -4861,6 +5164,7 @@ self.onmessage = async (ev) => {
4861
5164
  counts
4862
5165
  };
4863
5166
  }
5167
+ /** A mask from COCO style run length, inside 255. Throws when the counts do not cover the image. */
4864
5168
  function maskFromRle(r) {
4865
5169
  const [h, w] = r.size;
4866
5170
  const data = new Uint8Array(w * h);
@@ -4912,6 +5216,7 @@ self.onmessage = async (ev) => {
4912
5216
  frown: 0,
4913
5217
  gesture: null
4914
5218
  });
5219
+ /** Turns raw face and hand frames into steady signals and discrete events, smoothed or held so one noisy frame never fires a reaction. */
4915
5220
  var SignalTracker = class {
4916
5221
  p = absent();
4917
5222
  lastSeen = -Infinity;
@@ -5172,6 +5477,7 @@ self.onmessage = async (ev) => {
5172
5477
  };
5173
5478
  /** Questions that call for an on demand look rather than the steady signals. Replace it to suit a persona. */
5174
5479
  const LOOK_PATTERN = /\b(what (am i|is this|'?s this|do you see|can you see)|can you see|do you see|look at (this|me|my)|what('?s| is) in my hand|holding|wearing|show(ing)? you)\b/i;
5480
+ /** True when a message asks the character to look, by {@link LOOK_PATTERN} or the pattern you pass. */
5175
5481
  const wantsLook = (text, pattern = LOOK_PATTERN) => pattern.test(text);
5176
5482
  /** Default reactions (vendor): greet on arrival, smile back after 600 ms at 0.7 chance, answer waves and a few gestures. */
5177
5483
  const DEFAULT_REACTIONS = [
@@ -5242,6 +5548,7 @@ self.onmessage = async (ev) => {
5242
5548
  exports.EmbeddingCache = EmbeddingCache;
5243
5549
  exports.LOOK_PATTERN = LOOK_PATTERN;
5244
5550
  exports.MP_MODELS = MP_MODELS;
5551
+ exports.PICKER_RECORDS = PICKER_RECORDS;
5245
5552
  exports.ResultCache = ResultCache;
5246
5553
  exports.SeenNotes = SeenNotes;
5247
5554
  exports.SignalTracker = SignalTracker;