@camstack/addon-model-studio 1.1.223 → 1.1.225

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.
Files changed (22) hide show
  1. package/dist/{MotionZonesSettings-1CDVW7ke.mjs → MotionZonesSettings-AwjU_jds.mjs} +2 -2
  2. package/dist/{PrivacyMaskSettings-D86lwQor.mjs → PrivacyMaskSettings-BxJyOTIX.mjs} +4 -4
  3. package/dist/{SceneMonitorEditor-DaIyTg2F.mjs → SceneMonitorEditor-CvsWahwh.mjs} +3 -3
  4. package/dist/_stub.js +3613 -3487
  5. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_model_studio_page-BTzjbw2l.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_model_studio_page-Bz8hcMYe.mjs} +4 -4
  6. package/dist/{_virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_sdk__loadShare__.js-CISC_XrP.mjs → _virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_sdk__loadShare__.js-IW_NC3TX.mjs} +1 -1
  7. package/dist/_virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DTZ_Cxlt.mjs +26 -0
  8. package/dist/addon-model-studio.css +1 -1
  9. package/dist/{hostInit-BdkWsNLF.mjs → hostInit-BCIUeCcs.mjs} +3 -3
  10. package/dist/model-studio.addon.js +2008 -142
  11. package/dist/model-studio.addon.mjs +2009 -143
  12. package/dist/{player-overlays-9n207Syf.mjs → player-overlays-DUpfuxPB.mjs} +1 -1
  13. package/dist/remoteEntry.js +1 -1
  14. package/dist/{responsive-BrYRx--E.mjs → responsive-BHoVd25G.mjs} +1 -1
  15. package/dist/{scene-monitor-copy-Ccsj8OvK.mjs → scene-monitor-copy-DGpr-uDO.mjs} +1 -1
  16. package/dist/{square-DceOOyOz.mjs → square-CeBzl9Ag.mjs} +1 -1
  17. package/dist/{trash-2-B_ZsSine.mjs → trash-2-Bl3EnWCS.mjs} +1 -1
  18. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_model_studio_page__remoteEntry_js-DuDl-a7I.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_model_studio_page__remoteEntry_js-BE9Offwp.mjs} +1 -1
  19. package/package.json +1 -1
  20. package/python/__tests__/test_int8_recipe.py +77 -0
  21. package/python/convert_lib.py +68 -1
  22. package/dist/_virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-Drvqb9B5.mjs +0 -26
@@ -2,11 +2,12 @@ import { createRequire } from "node:module";
2
2
  import { spawn } from "node:child_process";
3
3
  import crypto$1, { createHash, randomUUID } from "node:crypto";
4
4
  import * as fs$1 from "node:fs";
5
- import fs from "node:fs";
5
+ import fs, { createReadStream } from "node:fs";
6
6
  import os from "node:os";
7
7
  import * as path$1 from "node:path";
8
8
  import path from "node:path";
9
9
  import { deleteModelFromDisk, downloadFile } from "@camstack/system/addon-utils";
10
+ import { cp, mkdir, open, rename, rm, writeFile } from "node:fs/promises";
10
11
  //#region \0rolldown/runtime.js
11
12
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
12
13
  //#endregion
@@ -5745,7 +5746,7 @@ var ZodIssueCode = {
5745
5746
  var ZodFirstPartyTypeKind;
5746
5747
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5747
5748
  //#endregion
5748
- //#region ../types/dist/sleep-DujUvOcb.mjs
5749
+ //#region ../types/dist/sleep-r3RWkGVx.mjs
5749
5750
  /**
5750
5751
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5751
5752
  * window to float samples (D455).
@@ -5862,7 +5863,7 @@ function isKeychainStoredField(field) {
5862
5863
  var SECRET_CLEAR = { $secretClear: true };
5863
5864
  /** The `'***'` token D634 redaction writes for non-admins. */
5864
5865
  var LEGACY_DEVICE_REDACTION = "***";
5865
- function isRecord$1(value) {
5866
+ function isRecord$2(value) {
5866
5867
  return typeof value === "object" && value !== null && !Array.isArray(value);
5867
5868
  }
5868
5869
  function makeSecretMarker(ref) {
@@ -5873,12 +5874,12 @@ function makeSecretMarker(ref) {
5873
5874
  }
5874
5875
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5875
5876
  function isSecretMarker(value) {
5876
- if (!isRecord$1(value)) return false;
5877
+ if (!isRecord$2(value)) return false;
5877
5878
  const ref = value["$secret"];
5878
5879
  return typeof ref === "string" && ref.length > 0;
5879
5880
  }
5880
5881
  function isSecretClear(value) {
5881
- return isRecord$1(value) && value["$secretClear"] === true;
5882
+ return isRecord$2(value) && value["$secretClear"] === true;
5882
5883
  }
5883
5884
  /**
5884
5885
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6394,6 +6395,13 @@ function globalSecretScope() {
6394
6395
  function encodeSegment(value) {
6395
6396
  return encodeURIComponent(value);
6396
6397
  }
6398
+ function decodeSegment(value) {
6399
+ try {
6400
+ return decodeURIComponent(value);
6401
+ } catch {
6402
+ return null;
6403
+ }
6404
+ }
6397
6405
  /**
6398
6406
  * The field path of a value inside an array item, addressed by the item's id:
6399
6407
  * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
@@ -6402,6 +6410,75 @@ function encodeSegment(value) {
6402
6410
  function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6403
6411
  return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6404
6412
  }
6413
+ function parseScope(segments) {
6414
+ switch (segments[0]) {
6415
+ case "global": return {
6416
+ scope: GLOBAL_SCOPE,
6417
+ used: 1
6418
+ };
6419
+ case "node": {
6420
+ const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6421
+ return nodeId === null || nodeId.length === 0 ? null : {
6422
+ scope: {
6423
+ kind: "node",
6424
+ nodeId
6425
+ },
6426
+ used: 2
6427
+ };
6428
+ }
6429
+ case "device": {
6430
+ const raw = segments[1];
6431
+ if (raw === void 0 || !/^\d+$/.test(raw)) return null;
6432
+ return {
6433
+ scope: {
6434
+ kind: "device",
6435
+ deviceId: Number(raw)
6436
+ },
6437
+ used: 2
6438
+ };
6439
+ }
6440
+ case "integration": {
6441
+ const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6442
+ return id === null || id.length === 0 ? null : {
6443
+ scope: {
6444
+ kind: "integration",
6445
+ integrationId: id
6446
+ },
6447
+ used: 2
6448
+ };
6449
+ }
6450
+ case "row": {
6451
+ const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6452
+ const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
6453
+ if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
6454
+ return {
6455
+ scope: {
6456
+ kind: "row",
6457
+ collection,
6458
+ rowId
6459
+ },
6460
+ used: 3
6461
+ };
6462
+ }
6463
+ default: return null;
6464
+ }
6465
+ }
6466
+ /** Take a ref apart; `null` when it is not a well-formed ref. */
6467
+ function parseSecretRef(ref) {
6468
+ if (!ref.startsWith("secret://")) return null;
6469
+ const segments = ref.slice(9).split("/");
6470
+ const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
6471
+ if (owner === null || owner.length === 0) return null;
6472
+ const parsed = parseScope(segments.slice(1));
6473
+ if (parsed === null) return null;
6474
+ const fieldPath = segments.slice(1 + parsed.used).join("/");
6475
+ if (fieldPath.length === 0) return null;
6476
+ return {
6477
+ owner,
6478
+ scope: parsed.scope,
6479
+ fieldPath
6480
+ };
6481
+ }
6405
6482
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6406
6483
  var KeychainWriteRefusedError = class extends Error {
6407
6484
  fieldPath;
@@ -6412,7 +6489,7 @@ var KeychainWriteRefusedError = class extends Error {
6412
6489
  }
6413
6490
  };
6414
6491
  var KEEP = { kind: "keep" };
6415
- function isRecord$2(value) {
6492
+ function isRecord$1(value) {
6416
6493
  return typeof value === "object" && value !== null && !Array.isArray(value);
6417
6494
  }
6418
6495
  function defaultMintId() {
@@ -6425,7 +6502,7 @@ function collectSecretMarkerRefs(value, out = []) {
6425
6502
  return out;
6426
6503
  }
6427
6504
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6428
- else if (isRecord$2(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6505
+ else if (isRecord$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6429
6506
  return out;
6430
6507
  }
6431
6508
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6480,7 +6557,7 @@ function rowId(row, idKey) {
6480
6557
  return null;
6481
6558
  }
6482
6559
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6483
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$2) : [];
6560
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1) : [];
6484
6561
  if (!Array.isArray(incoming)) {
6485
6562
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6486
6563
  return {
@@ -6496,7 +6573,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6496
6573
  const kept = /* @__PURE__ */ new Set();
6497
6574
  const rows = [];
6498
6575
  for (const row of incoming) {
6499
- if (!isRecord$2(row)) {
6576
+ if (!isRecord$1(row)) {
6500
6577
  rows.push(row);
6501
6578
  continue;
6502
6579
  }
@@ -6521,7 +6598,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6521
6598
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6522
6599
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6523
6600
  case "object": {
6524
- if (!isRecord$2(incoming)) {
6601
+ if (!isRecord$1(incoming)) {
6525
6602
  if (incoming === void 0) return KEEP;
6526
6603
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6527
6604
  return {
@@ -6529,7 +6606,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6529
6606
  value: incoming
6530
6607
  };
6531
6608
  }
6532
- const storedObj = isRecord$2(stored) ? stored : {};
6609
+ const storedObj = isRecord$1(stored) ? stored : {};
6533
6610
  return {
6534
6611
  kind: "value",
6535
6612
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6588,12 +6665,19 @@ async function transformSecretWrite(input) {
6588
6665
  }
6589
6666
  };
6590
6667
  }
6668
+ /** Is `ref` one of `owner`'s refs? */
6669
+ function isSecretRefOwnedBy(ref, owner) {
6670
+ return parseSecretRef(ref)?.owner === owner;
6671
+ }
6591
6672
  /**
6592
6673
  * Replace every marker in `value` with its keychain value. Returns the SAME
6593
6674
  * reference when there is no marker (no allocation, no keychain call).
6594
6675
  */
6595
- async function resolveSecretMarkers(value, secrets) {
6596
- const refs = collectSecretMarkerRefs(value);
6676
+ async function resolveSecretMarkers(value, secrets, options = {}) {
6677
+ const keepMarker = options.unresolved === "keep-marker";
6678
+ const owner = options.ownedBy;
6679
+ const inScope = (ref) => owner === void 0 || isSecretRefOwnedBy(ref, owner);
6680
+ const refs = collectSecretMarkerRefs(value).filter(inScope);
6597
6681
  if (refs.length === 0) return {
6598
6682
  value,
6599
6683
  unresolved: []
@@ -6617,10 +6701,18 @@ async function resolveSecretMarkers(value, secrets) {
6617
6701
  }
6618
6702
  const substitute = (v) => {
6619
6703
  if (isSecretMarker(v)) {
6704
+ if (!inScope(v.$secret)) return {
6705
+ keep: true,
6706
+ value: v
6707
+ };
6620
6708
  const answer = answers[v.$secret];
6621
- return answer?.kind === "value" ? {
6709
+ if (answer?.kind === "value") return {
6622
6710
  keep: true,
6623
6711
  value: answer.value
6712
+ };
6713
+ return keepMarker ? {
6714
+ keep: true,
6715
+ value: v
6624
6716
  } : {
6625
6717
  keep: false,
6626
6718
  value: void 0
@@ -6637,7 +6729,7 @@ async function resolveSecretMarkers(value, secrets) {
6637
6729
  value: items
6638
6730
  };
6639
6731
  }
6640
- if (isRecord$2(v)) {
6732
+ if (isRecord$1(v)) {
6641
6733
  const out = {};
6642
6734
  for (const [k, child] of Object.entries(v)) {
6643
6735
  const s = substitute(child);
@@ -6658,14 +6750,152 @@ async function resolveSecretMarkers(value, secrets) {
6658
6750
  unresolved
6659
6751
  };
6660
6752
  }
6661
- function touchesTree(tree, patch) {
6662
- if (tree.size === 0) return false;
6663
- for (const key of Object.keys(patch)) {
6664
- const at = key.indexOf("@");
6665
- if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6753
+ /** An addon tried to replace a stored secret it could not read. Nothing was written. */
6754
+ var SecretOverwriteRefusedError = class extends Error {
6755
+ ref;
6756
+ reason;
6757
+ constructor(ref, reason) {
6758
+ super(`secret ${ref} was not replaced: its stored value cannot be read right now (${reason}), and an addon may not overwrite a secret it cannot see. Nothing was written.`);
6759
+ this.ref = ref;
6760
+ this.reason = reason;
6761
+ this.name = "SecretOverwriteRefusedError";
6762
+ }
6763
+ };
6764
+ function isRecord$3(value) {
6765
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6766
+ }
6767
+ function resolvedValue(pass, marker) {
6768
+ const answer = pass.answers[marker.$secret];
6769
+ return answer?.kind === "value" ? answer.value : null;
6770
+ }
6771
+ async function atMarker(pass, incoming, stored) {
6772
+ if (incoming === null) return stored;
6773
+ if (typeof incoming !== "string") return incoming;
6774
+ if (incoming === resolvedValue(pass, stored)) return stored;
6775
+ const intent = classifySecretWrite(incoming);
6776
+ if (intent.kind !== "set") return stored;
6777
+ const ref = stored.$secret;
6778
+ if (!isSecretRefOwnedBy(ref, pass.secrets.owner)) return incoming;
6779
+ const answer = pass.answers[ref];
6780
+ if ((answer === void 0 || answer.kind === "unavailable" || answer.kind === "forbidden") && !pass.operatorWrite) throw new SecretOverwriteRefusedError(ref, answer === void 0 ? "not-initialized" : answer.kind === "unavailable" ? answer.reason : answer.kind);
6781
+ try {
6782
+ await pass.secrets.put(ref, intent.value);
6783
+ } catch (err) {
6784
+ throw new KeychainWriteRefusedError(ref, err);
6785
+ }
6786
+ pass.changedRefs.push(ref);
6787
+ return stored;
6788
+ }
6789
+ function inArray(pass, incoming, stored) {
6790
+ return incoming.map((item, index) => {
6791
+ const twin = stored[index];
6792
+ if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6793
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
6794
+ if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6795
+ return item;
6796
+ });
6797
+ }
6798
+ function inArrayRow(pass, incoming, stored) {
6799
+ const out = { ...incoming };
6800
+ for (const [key, value] of Object.entries(incoming)) {
6801
+ const twin = stored[key];
6802
+ if (isSecretMarker(twin)) {
6803
+ if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6804
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
6805
+ else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6806
+ }
6807
+ return out;
6808
+ }
6809
+ async function walk(pass, incoming, stored) {
6810
+ if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6811
+ if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6812
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
6813
+ const out = { ...incoming };
6814
+ for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
6815
+ return out;
6816
+ }
6817
+ /** Restore markers a write-back carries as values. See the file doc. */
6818
+ async function restoreUnchangedSecrets(input) {
6819
+ const refs = [];
6820
+ for (const key of Object.keys(input.patch)) collectSecretMarkerRefs(input.stored[key], refs);
6821
+ const owned = refs.filter((ref) => isSecretRefOwnedBy(ref, input.secrets.owner));
6822
+ if (owned.length === 0) return {
6823
+ patch: input.patch,
6824
+ changedRefs: []
6825
+ };
6826
+ const pass = {
6827
+ secrets: input.secrets,
6828
+ answers: await input.secrets.resolve([...new Set(owned)]),
6829
+ operatorWrite: input.operatorWrite,
6830
+ changedRefs: []
6831
+ };
6832
+ const out = {};
6833
+ for (const [key, value] of Object.entries(input.patch)) out[key] = await walk(pass, value, input.stored[key]);
6834
+ return {
6835
+ patch: out,
6836
+ changedRefs: pass.changedRefs
6837
+ };
6838
+ }
6839
+ /** Structural equality over JSON-shaped values (key order does not matter). */
6840
+ function isJsonEqual(a, b) {
6841
+ if (Object.is(a, b)) return true;
6842
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6843
+ if (isRecord$3(a) && isRecord$3(b)) {
6844
+ const keys = Object.keys(a);
6845
+ if (keys.length !== Object.keys(b).length) return false;
6846
+ return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
6666
6847
  }
6667
6848
  return false;
6668
6849
  }
6850
+ /** The patch without the keys whose value already equals the stored one. */
6851
+ function dropUnchangedKeys(patch, stored) {
6852
+ const out = {};
6853
+ for (const [key, value] of Object.entries(patch)) {
6854
+ if (Object.prototype.hasOwnProperty.call(stored, key) && isJsonEqual(value, stored[key])) continue;
6855
+ out[key] = value;
6856
+ }
6857
+ return out;
6858
+ }
6859
+ /** The top-level keys of a blob that hold at least one of `owner`'s markers. */
6860
+ function markerKeysOf(blob, owner) {
6861
+ const keys = /* @__PURE__ */ new Set();
6862
+ for (const [key, value] of Object.entries(blob)) if (collectSecretMarkerRefs(value).some((ref) => isSecretRefOwnedBy(ref, owner))) keys.add(key);
6863
+ return keys;
6864
+ }
6865
+ function nodeFromStored(value, owner) {
6866
+ if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6867
+ if (!isRecord$3(value)) return null;
6868
+ const children = /* @__PURE__ */ new Map();
6869
+ for (const [key, child] of Object.entries(value)) {
6870
+ const node = nodeFromStored(child, owner);
6871
+ if (node !== null) children.set(key, node);
6872
+ }
6873
+ return children.size > 0 ? {
6874
+ kind: "object",
6875
+ children
6876
+ } : null;
6877
+ }
6878
+ /**
6879
+ * The declared secret tree, widened by every place the STORED blob holds a
6880
+ * marker under one of `keys` — so a marker the schema no longer declares (or
6881
+ * never declared: Wyze before b4906cec6) still gets the save path's
6882
+ * KEEP / SET / CLEAR semantics instead of being overwritten by whatever the
6883
+ * addon writes. Markers inside arrays are not added: a row has no id field to
6884
+ * match by unless the schema declares one. Only `owner`'s markers count: a
6885
+ * builtin that keeps another addon's marker (device-manager) never takes it
6886
+ * over.
6887
+ */
6888
+ function widenTreeWithStoredMarkers(declared, stored, keys, owner) {
6889
+ const added = /* @__PURE__ */ new Map();
6890
+ for (const key of keys) {
6891
+ const at = key.indexOf("@");
6892
+ const base = at > 0 ? key.slice(0, at) : key;
6893
+ if (declared.has(base) || added.has(base)) continue;
6894
+ const node = nodeFromStored(stored[key], owner);
6895
+ if (node !== null) added.set(base, node);
6896
+ }
6897
+ return added.size === 0 ? declared : new Map([...declared, ...added]);
6898
+ }
6669
6899
  /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6670
6900
  async function readStoredAddonBlob(raw) {
6671
6901
  const threeWay = raw.readAddonStoreResult;
@@ -6674,7 +6904,41 @@ async function readStoredAddonBlob(raw) {
6674
6904
  if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6675
6905
  return result.kind === "missing" ? {} : result.value;
6676
6906
  }
6677
- function createSecretAwareSettings(raw, opts) {
6907
+ function touchesTree(tree, patch) {
6908
+ if (tree.size === 0) return false;
6909
+ for (const key of Object.keys(patch)) {
6910
+ const at = key.indexOf("@");
6911
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6912
+ }
6913
+ return false;
6914
+ }
6915
+ /**
6916
+ * Which top-level keys of each store held markers when last seen. `undefined`
6917
+ * for a store not seen yet: its first write reads it, to be safe.
6918
+ */
6919
+ var MarkerKeyIndex = class {
6920
+ owner;
6921
+ byStore = /* @__PURE__ */ new Map();
6922
+ constructor(owner) {
6923
+ this.owner = owner;
6924
+ }
6925
+ seen(store, blob) {
6926
+ this.byStore.set(store, markerKeysOf(blob, this.owner));
6927
+ }
6928
+ wrote(store, patch) {
6929
+ const keys = this.byStore.get(store);
6930
+ if (keys === void 0) return;
6931
+ const now = markerKeysOf(patch, this.owner);
6932
+ for (const key of Object.keys(patch)) if (now.has(key)) keys.add(key);
6933
+ else keys.delete(key);
6934
+ }
6935
+ mayHoldMarkers(store, patch) {
6936
+ const keys = this.byStore.get(store);
6937
+ if (keys === void 0) return true;
6938
+ return Object.keys(patch).some((key) => keys.has(key));
6939
+ }
6940
+ };
6941
+ function createHandle(raw, opts) {
6678
6942
  const chains = /* @__PURE__ */ new Map();
6679
6943
  const serialize = (key, fn) => {
6680
6944
  const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
@@ -6685,46 +6949,130 @@ function createSecretAwareSettings(raw, opts) {
6685
6949
  });
6686
6950
  return next;
6687
6951
  };
6688
- const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6689
- if (!touchesTree(tree, patch)) return rawWrite(patch);
6690
- return serialize(chainKey, async () => {
6952
+ const index = new MarkerKeyIndex(opts.secrets.owner);
6953
+ const resolveRead = async (store, blob) => {
6954
+ index.seen(store, blob);
6955
+ const { value, unresolved } = await resolveSecretMarkers(blob, opts.secrets, {
6956
+ unresolved: "keep-marker",
6957
+ ownedBy: opts.secrets.owner
6958
+ });
6959
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6960
+ return value;
6961
+ };
6962
+ const write = async (store, declared, scope, patch, readStored, rawWrite) => {
6963
+ if (!touchesTree(declared, patch) && !index.mayHoldMarkers(store, patch)) {
6964
+ await rawWrite(patch);
6965
+ index.wrote(store, patch);
6966
+ return { changed: true };
6967
+ }
6968
+ return serialize(store, async () => {
6691
6969
  const stored = await readStored();
6970
+ index.seen(store, stored);
6971
+ const operatorWrite = opts.isOperatorWrite?.() === true;
6972
+ const restored = await restoreUnchangedSecrets({
6973
+ patch,
6974
+ stored,
6975
+ secrets: opts.secrets,
6976
+ operatorWrite
6977
+ });
6692
6978
  const result = await transformSecretWrite({
6693
- tree,
6979
+ tree: widenTreeWithStoredMarkers(declared, stored, Object.keys(restored.patch), opts.secrets.owner),
6694
6980
  secrets: opts.secrets,
6695
- patch,
6981
+ patch: restored.patch,
6696
6982
  stored,
6697
6983
  ...scope !== void 0 ? { scope } : {},
6698
- operatorWrite: opts.isOperatorWrite?.() === true
6984
+ operatorWrite
6699
6985
  });
6700
- if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6986
+ const effective = dropUnchangedKeys(result.patch, stored);
6987
+ const wroteBlob = Object.keys(effective).length > 0;
6988
+ if (wroteBlob) {
6989
+ await rawWrite(effective);
6990
+ index.wrote(store, effective);
6991
+ }
6701
6992
  const { orphaned } = await result.afterWrite();
6702
6993
  if (orphaned.length > 0) opts.onOrphaned(orphaned);
6994
+ return { changed: wroteBlob || restored.changedRefs.length > 0 };
6703
6995
  });
6704
6996
  };
6705
- const wrapped = {
6706
- writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6707
- writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6708
- kind: "device",
6709
- deviceId
6710
- }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6997
+ const writeAddon = (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p));
6998
+ const readAddonStoreResult = raw.readAddonStoreResult;
6999
+ const readAddonStoreKeyResult = raw.readAddonStoreKeyResult;
7000
+ const readDeviceStoreBatch = raw.readDeviceStoreBatch;
7001
+ const overrides = {
7002
+ readAddonStore: async () => resolveRead("addon", await raw.readAddonStore()),
7003
+ ...readAddonStoreResult !== void 0 ? { readAddonStoreResult: async () => {
7004
+ const result = await readAddonStoreResult.call(raw);
7005
+ return result.kind === "value" ? {
7006
+ kind: "value",
7007
+ value: await resolveRead("addon", result.value)
7008
+ } : result;
7009
+ } } : {},
7010
+ ...readAddonStoreKeyResult !== void 0 ? { readAddonStoreKeyResult: async (key) => {
7011
+ const result = await readAddonStoreKeyResult.call(raw, key);
7012
+ if (result.kind !== "present") return result;
7013
+ const { value, unresolved } = await resolveSecretMarkers({ [key]: result.value }, opts.secrets, {
7014
+ unresolved: "keep-marker",
7015
+ ownedBy: opts.secrets.owner
7016
+ });
7017
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
7018
+ return {
7019
+ kind: "present",
7020
+ value: value[key]
7021
+ };
7022
+ } } : {},
7023
+ readDeviceStore: async (deviceId) => resolveRead(`device:${deviceId}`, await raw.readDeviceStore(deviceId)),
7024
+ ...readDeviceStoreBatch !== void 0 ? { readDeviceStoreBatch: async (deviceIds) => {
7025
+ const rows = await readDeviceStoreBatch.call(raw, deviceIds);
7026
+ const out = /* @__PURE__ */ new Map();
7027
+ for (const [deviceId, blob] of rows) out.set(deviceId, await resolveRead(`device:${deviceId}`, blob));
7028
+ return out;
7029
+ } } : {},
7030
+ writeAddonStore: async (patch) => {
7031
+ await writeAddon(patch);
7032
+ },
7033
+ writeDeviceStore: async (deviceId, patch) => {
7034
+ await write(`device:${deviceId}`, opts.deviceTree(), {
7035
+ kind: "device",
7036
+ deviceId
7037
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p));
7038
+ }
7039
+ };
7040
+ return {
7041
+ settings: new Proxy(raw, { get(target, prop, receiver) {
7042
+ if (typeof prop === "string" && Object.prototype.hasOwnProperty.call(overrides, prop)) return Reflect.get(overrides, prop);
7043
+ const value = Reflect.get(target, prop, receiver);
7044
+ return typeof value === "function" ? value.bind(target) : value;
7045
+ } }),
7046
+ raw: {
7047
+ readAddonStore: async () => {
7048
+ const blob = await raw.readAddonStore();
7049
+ index.seen("addon", blob);
7050
+ return blob;
7051
+ },
7052
+ readDeviceStore: async (deviceId) => {
7053
+ const blob = await raw.readDeviceStore(deviceId);
7054
+ index.seen(`device:${deviceId}`, blob);
7055
+ return blob;
7056
+ }
7057
+ },
7058
+ writeAddonStore: writeAddon
6711
7059
  };
6712
- return new Proxy(raw, { get(target, prop, receiver) {
6713
- if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6714
- if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6715
- const value = Reflect.get(target, prop, receiver);
6716
- return typeof value === "function" ? value.bind(target) : value;
6717
- } });
6718
7060
  }
6719
- /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6720
- function withSecretAwareSettings(context, opts) {
7061
+ /** The context the addon sees, plus the private raw view and write outcome. */
7062
+ function createSecretAwareContext(context, opts) {
6721
7063
  const raw = context.settings;
6722
- if (raw === void 0) return context;
6723
- const settings = createSecretAwareSettings(raw, opts);
6724
- return new Proxy(context, { get(target, prop, receiver) {
6725
- if (prop === "settings") return settings;
6726
- return Reflect.get(target, prop, receiver);
6727
- } });
7064
+ if (raw === void 0) return {
7065
+ context,
7066
+ handle: null
7067
+ };
7068
+ const handle = createHandle(raw, opts);
7069
+ return {
7070
+ context: new Proxy(context, { get(target, prop, receiver) {
7071
+ if (prop === "settings") return handle.settings;
7072
+ return Reflect.get(target, prop, receiver);
7073
+ } }),
7074
+ handle
7075
+ };
6728
7076
  }
6729
7077
  var LEAF = { kind: "leaf" };
6730
7078
  var DEFAULT_ITEM_ID_KEY = "id";
@@ -6899,6 +7247,14 @@ var BaseAddon = class {
6899
7247
  _secretChangeUnsub = null;
6900
7248
  /** >0 while an OPERATOR's settings write is being applied. */
6901
7249
  _operatorWriteDepth = 0;
7250
+ /**
7251
+ * The keychain-aware settings handle (D798). Its `raw` view is the ONLY way
7252
+ * to the marker-bearing blobs and stays private to this class: the form
7253
+ * hydrate and config resolution need markers, addon code never does.
7254
+ */
7255
+ _secretSettings = null;
7256
+ /** Refs an addon-facing read could not resolve — each is logged once per process. */
7257
+ _loggedUnresolvedReads = /* @__PURE__ */ new Set();
6902
7258
  constructor(defaults) {
6903
7259
  this.defaults = defaults;
6904
7260
  this._config = { ...defaults };
@@ -6935,13 +7291,21 @@ var BaseAddon = class {
6935
7291
  }
6936
7292
  async initialize(context) {
6937
7293
  const secrets = context.secrets;
6938
- this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6939
- secrets,
6940
- addonTree: () => this.addonSecretTree(),
6941
- deviceTree: () => this.deviceSecretTree(),
6942
- onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6943
- isOperatorWrite: () => this._operatorWriteDepth > 0
6944
- }) : context;
7294
+ if (secrets !== void 0) {
7295
+ const { context: wrapped, handle } = createSecretAwareContext(context, {
7296
+ secrets,
7297
+ addonTree: () => this.addonSecretTree(),
7298
+ deviceTree: () => this.deviceSecretTree(),
7299
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
7300
+ isOperatorWrite: () => this._operatorWriteDepth > 0,
7301
+ onUnresolved: (unresolved) => this.logUnresolvedRead(unresolved)
7302
+ });
7303
+ this._ctx = wrapped;
7304
+ this._secretSettings = handle;
7305
+ } else {
7306
+ this._ctx = context;
7307
+ this._secretSettings = null;
7308
+ }
6945
7309
  await this.resolveConfig();
6946
7310
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6947
7311
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7058,11 +7422,8 @@ var BaseAddon = class {
7058
7422
  async getGlobalSettings(overlay, cap, nodeId) {
7059
7423
  const schema = this.globalSettingsSchema(cap);
7060
7424
  if (!schema) return { sections: [] };
7061
- const projected = await this.resolveGlobalStore(nodeId, cap);
7062
- return hydrateSchema(schema, overlay ? {
7063
- ...projected,
7064
- ...overlay
7065
- } : projected, { inlineSecretsAsViews: true });
7425
+ const projected = await this.readRawProjectedStore(nodeId, cap);
7426
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
7066
7427
  }
7067
7428
  /**
7068
7429
  * The integration-level view of this addon's settings: exactly the sections
@@ -7107,7 +7468,7 @@ var BaseAddon = class {
7107
7468
  });
7108
7469
  }
7109
7470
  if (sections.length === 0) return null;
7110
- const projected = await this.resolveGlobalStore(nodeId);
7471
+ const projected = await this.readRawProjectedStore(nodeId);
7111
7472
  return hydrateSchema({
7112
7473
  ...schema,
7113
7474
  sections
@@ -7124,12 +7485,50 @@ var BaseAddon = class {
7124
7485
  * the store for custom option logic (option narrowing, value snapping) to
7125
7486
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
7126
7487
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
7488
+ *
7489
+ * Keychain values come back RESOLVED (D798): a secret reads as its value,
7490
+ * never as a `{ $secret }` marker. One the keychain cannot serve right now
7491
+ * stays a marker — "stored, unavailable" (`isSecretMarker()` is true, and it
7492
+ * is listed in {@link unresolvedSecrets}) — never `''` and never absent, so
7493
+ * it cannot be mistaken for "nothing stored, mint a new one". Writing the
7494
+ * resolved blob back is a no-op for every unchanged secret.
7127
7495
  */
7128
7496
  async resolveGlobalStore(nodeId, cap) {
7129
7497
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
7498
+ return this.projectForNode(raw, nodeId, cap);
7499
+ }
7500
+ projectForNode(store, nodeId, cap) {
7130
7501
  const keys = this.perNodeKeys(cap);
7131
7502
  const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
7132
- return keys.size > 0 ? projectStore(raw, keys, node) : raw;
7503
+ return keys.size > 0 ? projectStore(store, keys, node) : store;
7504
+ }
7505
+ /** The PROJECTED store with its markers — the form hydrate only (D798). */
7506
+ async readRawProjectedStore(nodeId, cap) {
7507
+ const raw = await this.rawSettings()?.readAddonStore() ?? {};
7508
+ return this.projectForNode(raw, nodeId, cap);
7509
+ }
7510
+ /**
7511
+ * `{ ...stored, ...overlay }`, except that an overlay member equal to the
7512
+ * RESOLVED stored one keeps the stored (marker-bearing) member — so a form
7513
+ * hydrated from a resolved overlay still shows a secret as "set", never as
7514
+ * its value.
7515
+ */
7516
+ async overlayKeepingMarkers(stored, overlay) {
7517
+ const secrets = this._ctx?.secrets;
7518
+ const merged = {
7519
+ ...stored,
7520
+ ...overlay
7521
+ };
7522
+ if (secrets === void 0 || collectSecretMarkerRefs(stored).length === 0) return merged;
7523
+ const { value: resolved } = await resolveSecretMarkers(stored, secrets, {
7524
+ unresolved: "keep-marker",
7525
+ ownedBy: secrets.owner
7526
+ });
7527
+ for (const key of Object.keys(overlay)) {
7528
+ if (collectSecretMarkerRefs(stored[key]).length === 0) continue;
7529
+ if (isJsonEqual(overlay[key], resolved[key])) merged[key] = stored[key];
7530
+ }
7531
+ return merged;
7133
7532
  }
7134
7533
  /**
7135
7534
  * Whether ONE global key of this addon's store was written, read three-way
@@ -7194,8 +7593,12 @@ var BaseAddon = class {
7194
7593
  async clearSecrets(keys, nodeId) {
7195
7594
  const tree = this.addonSecretTree();
7196
7595
  const keychain = this._ctx?.secrets !== void 0;
7596
+ const stored = keychain ? await this.readAddonStoreWithRetry() : {};
7197
7597
  const patch = {};
7198
- for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
7598
+ for (const key of keys) {
7599
+ const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
7600
+ patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
7601
+ }
7199
7602
  await this.applyGlobalPatch(patch, nodeId);
7200
7603
  }
7201
7604
  async applyGlobalPatch(barePatch, nodeId) {
@@ -7203,7 +7606,11 @@ var BaseAddon = class {
7203
7606
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
7204
7607
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
7205
7608
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
7206
- await this._ctx?.settings?.writeAddonStore(scoped);
7609
+ const handle = this._secretSettings;
7610
+ if (handle !== null) {
7611
+ const { changed } = await handle.writeAddonStore(scoped);
7612
+ if (!changed) return;
7613
+ } else await this._ctx?.settings?.writeAddonStore(scoped);
7207
7614
  if (target !== localNode) return;
7208
7615
  await this.resolveConfig();
7209
7616
  await this.onConfigChanged();
@@ -7256,7 +7663,7 @@ var BaseAddon = class {
7256
7663
  async getDeviceSettings(deviceId) {
7257
7664
  const schema = this.deviceSettingsSchema();
7258
7665
  if (!schema) return { sections: [] };
7259
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7666
+ return hydrateSchema(schema, await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7260
7667
  }
7261
7668
  async updateDeviceSettings(deviceId, patch) {
7262
7669
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -7428,7 +7835,7 @@ var BaseAddon = class {
7428
7835
  key,
7429
7836
  schema,
7430
7837
  fallback,
7431
- read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
7838
+ read: async () => this.resolveStoredSecrets(await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, false),
7432
7839
  write: async (patch) => {
7433
7840
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
7434
7841
  },
@@ -7490,6 +7897,23 @@ var BaseAddon = class {
7490
7897
  }
7491
7898
  return value;
7492
7899
  }
7900
+ /**
7901
+ * The marker-bearing settings reads (D798) — private on purpose. Without a
7902
+ * keychain the context's own view is already raw.
7903
+ */
7904
+ rawSettings() {
7905
+ return this._secretSettings?.raw ?? this._ctx?.settings;
7906
+ }
7907
+ /** An addon-facing read met markers it could not resolve: say so once per ref. */
7908
+ logUnresolvedRead(unresolved) {
7909
+ const fresh = unresolved.filter((u) => !this._loggedUnresolvedReads.has(u.ref));
7910
+ if (fresh.length === 0) return;
7911
+ for (const u of fresh) this._loggedUnresolvedReads.add(u.ref);
7912
+ this._ctx?.logger?.warn?.("settings read: a stored secret is unavailable — it reads as its marker, not as a value", { meta: { secrets: fresh.map((u) => ({
7913
+ ref: u.ref,
7914
+ reason: u.reason
7915
+ })) } });
7916
+ }
7493
7917
  /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7494
7918
  scheduleSecretReresolve(delayMs) {
7495
7919
  const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
@@ -7516,7 +7940,7 @@ var BaseAddon = class {
7516
7940
  * `{}` (defaults) — the addon's first successful patch will rehydrate.
7517
7941
  */
7518
7942
  async readAddonStoreWithRetry() {
7519
- const settings = this._ctx?.settings;
7943
+ const settings = this.rawSettings();
7520
7944
  if (!settings) return {};
7521
7945
  const delaysMs = [
7522
7946
  150,
@@ -9823,6 +10247,278 @@ var CameraSwitchGroupSchema = object({
9823
10247
  fetchedAt: number()
9824
10248
  });
9825
10249
  /**
10250
+ * The trainer contract — what the hub hands the cloud trainer and what it
10251
+ * gets back (cloud training, D805+).
10252
+ *
10253
+ * The trainer (`hf/camstack-trainer`, published as the Hugging Face repo
10254
+ * `camstack/camstack-trainer`) is a separate AGPL program the hub never
10255
+ * imports: `job.json` goes in, files come out, and progress is `CAMSTACK_EVENT`
10256
+ * lines on stdout. These schemas are the hub's half of that boundary; the
10257
+ * trainer's pydantic models (and the JSON Schemas generated from them under
10258
+ * `hf/camstack-trainer/schemas/`) are the other half. A change here is a
10259
+ * change there, in the same piece of work.
10260
+ *
10261
+ * No `.default()` anywhere: defaults do not run on the addon cap path, so the
10262
+ * orchestrator fills every field of a job spec explicitly.
10263
+ */
10264
+ var TRAINING_JOB_SCHEMA = "camstack.training/v1";
10265
+ var TRAINING_RESULT_SCHEMA = "camstack.training-result/v1";
10266
+ /** What the trainer can export. Edge TPU is a later, separate image. */
10267
+ var TrainingExportSchema = _enum([
10268
+ "onnx",
10269
+ "openvino-fp16",
10270
+ "openvino-int8",
10271
+ "coreml-fp16"
10272
+ ]);
10273
+ var FloorsSchema = record(string(), number().min(0).max(1));
10274
+ object({
10275
+ schema: literal(TRAINING_JOB_SCHEMA),
10276
+ jobKey: string().uuid(),
10277
+ target: object({
10278
+ kind: literal("detector"),
10279
+ step: literal("object-detection")
10280
+ }),
10281
+ base: object({
10282
+ modelId: string().min(1),
10283
+ /** Ultralytics weights id, e.g. `yolov9m.pt`. */
10284
+ weights: string().min(1),
10285
+ imgsz: number().int().positive()
10286
+ }),
10287
+ baseline: object({
10288
+ modelId: string().min(1),
10289
+ /** The baseline ONNX the holdout comparison runs; public mirror URL. */
10290
+ onnxUrl: string().url(),
10291
+ imgsz: number().int().positive(),
10292
+ floors: FloorsSchema
10293
+ }),
10294
+ dataset: object({
10295
+ versionId: string().min(1),
10296
+ annotationHash: string(),
10297
+ /** sha256 of the uploaded archive; the trainer refuses a mismatch (exit 65). */
10298
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10299
+ }),
10300
+ split: object({
10301
+ holdoutCameras: array(number().int()),
10302
+ /** When no camera is held out: the last N days of every camera. */
10303
+ holdoutLastDays: number().int().nonnegative(),
10304
+ valFraction: number().min(0).max(.5),
10305
+ seed: number().int()
10306
+ }),
10307
+ hyper: object({
10308
+ epochs: number().int().positive(),
10309
+ batch: number().int().positive(),
10310
+ lr0: number().positive(),
10311
+ /** Layers frozen from the start of the backbone; 0 = none. */
10312
+ freeze: number().int().nonnegative(),
10313
+ patience: number().int().nonnegative(),
10314
+ seed: number().int()
10315
+ }),
10316
+ replay: object({
10317
+ source: literal("coco2017"),
10318
+ count: number().int().nonnegative()
10319
+ }),
10320
+ exports: array(TrainingExportSchema).min(1),
10321
+ calibration: object({ maxFrames: number().int().positive() }),
10322
+ floors: object({
10323
+ minSupport: number().int().positive(),
10324
+ clamp: number().min(0).max(1)
10325
+ }),
10326
+ int8Gate: object({ maxMap50Drop: number().min(0).max(1) }),
10327
+ catalog: object({
10328
+ id: string().regex(/^[a-z0-9][a-z0-9-]{2,80}$/),
10329
+ name: string().min(1).max(160)
10330
+ })
10331
+ });
10332
+ /** One regular file of the bundle. An mlpackage contributes one row per member. */
10333
+ var TrainingResultFileSchema = object({
10334
+ path: string().min(1),
10335
+ bytes: number().int().nonnegative(),
10336
+ sha256: string().regex(/^[0-9a-f]{64}$/),
10337
+ format: _enum([
10338
+ "onnx",
10339
+ "openvino",
10340
+ "coreml",
10341
+ "pt"
10342
+ ]),
10343
+ variant: _enum(["base", "int8"])
10344
+ });
10345
+ var DraftFormatSchema = object({
10346
+ /** RELATIVE path inside the bundle; the hub rewrites it to `camstack-local://`. */
10347
+ url: string().min(1),
10348
+ sizeMB: number().nonnegative(),
10349
+ isDirectory: boolean().optional(),
10350
+ files: array(string()).optional(),
10351
+ runtimes: array(literal("python")).optional(),
10352
+ revision: string().min(1)
10353
+ });
10354
+ /** The trainer's half of a catalog entry; the hub completes it (labels, licence, group). */
10355
+ var TrainingCatalogDraftSchema = object({
10356
+ id: string().min(1),
10357
+ name: string().min(1),
10358
+ description: string(),
10359
+ labels: array(unknown()),
10360
+ inputSize: object({
10361
+ width: number().int().positive(),
10362
+ height: number().int().positive()
10363
+ }),
10364
+ preprocessMode: literal("letterbox"),
10365
+ defaultClassFloors: FloorsSchema,
10366
+ formats: object({
10367
+ onnx: DraftFormatSchema.optional(),
10368
+ openvino: DraftFormatSchema.optional(),
10369
+ coreml: DraftFormatSchema.optional()
10370
+ })
10371
+ });
10372
+ /** One class of one model's holdout report (the eval harness's summary). */
10373
+ var TrainingEvalClassSchema = object({
10374
+ positives: number().int(),
10375
+ floor: number().nullable(),
10376
+ tp: number().int(),
10377
+ fp: number().int(),
10378
+ fn: number().int(),
10379
+ precision: number().nullable(),
10380
+ recall: number().nullable(),
10381
+ ap50: number().nullable(),
10382
+ recallByCamera: record(string(), number().nullable()).optional(),
10383
+ recallByLight: record(string(), number().nullable()).optional(),
10384
+ fpByCamera: record(string(), number()).optional(),
10385
+ smallFound: number().int().optional(),
10386
+ smallTotal: number().int().optional()
10387
+ }).passthrough();
10388
+ var TrainingEvalReportSchema = object({
10389
+ frames: number().int(),
10390
+ classes: record(string(), TrainingEvalClassSchema)
10391
+ }).passthrough();
10392
+ /**
10393
+ * A succeeded result carries every block; a failed one carries the error and
10394
+ * whatever was known by then — the other blocks are ABSENT, not null. The
10395
+ * orchestrator checks the blocks it needs before it trusts a success.
10396
+ */
10397
+ var TrainingResultSchema = object({
10398
+ schema: literal(TRAINING_RESULT_SCHEMA),
10399
+ jobKey: string(),
10400
+ status: _enum(["succeeded", "failed"]),
10401
+ error: object({
10402
+ stage: string(),
10403
+ code: string(),
10404
+ message: string()
10405
+ }).nullable(),
10406
+ trainer: object({
10407
+ version: string(),
10408
+ revision: string()
10409
+ }),
10410
+ toolchain: record(string(), string().nullable()),
10411
+ dataset: object({
10412
+ versionId: string(),
10413
+ annotationHash: string(),
10414
+ sha256: string(),
10415
+ frames: object({
10416
+ train: number().int(),
10417
+ val: number().int(),
10418
+ holdout: number().int()
10419
+ }),
10420
+ holdoutCameras: array(number().int()),
10421
+ replayImages: number().int()
10422
+ }).optional(),
10423
+ training: object({
10424
+ epochsRun: number().int(),
10425
+ bestEpoch: number().int(),
10426
+ bestMap50: number(),
10427
+ bestMap50_95: number(),
10428
+ seconds: number()
10429
+ }).optional(),
10430
+ evaluation: object({
10431
+ holdoutFrames: number().int(),
10432
+ baseline: TrainingEvalReportSchema.nullable(),
10433
+ candidate: TrainingEvalReportSchema.nullable(),
10434
+ candidateInt8: TrainingEvalReportSchema.nullable(),
10435
+ recallDeltaByCamera: record(string(), record(string(), number())).nullable(),
10436
+ map50: record(string(), number().nullable())
10437
+ }).optional(),
10438
+ floors: object({
10439
+ baseline: FloorsSchema,
10440
+ candidate: FloorsSchema,
10441
+ candidateInt8: FloorsSchema.nullable(),
10442
+ notes: array(string())
10443
+ }).optional(),
10444
+ int8: object({
10445
+ kept: boolean(),
10446
+ map50Fp16: number().nullable(),
10447
+ map50Int8: number().nullable(),
10448
+ reason: string().nullable()
10449
+ }).optional(),
10450
+ exportsDropped: array(object({
10451
+ export: string(),
10452
+ reason: string()
10453
+ })).optional(),
10454
+ files: array(TrainingResultFileSchema).optional(),
10455
+ bundle: object({
10456
+ path: literal("bundle.tar"),
10457
+ bytes: number().int().nonnegative(),
10458
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10459
+ }).nullable().optional(),
10460
+ catalogDraft: object({
10461
+ base: TrainingCatalogDraftSchema,
10462
+ int8: TrainingCatalogDraftSchema.nullable()
10463
+ }).nullable().optional(),
10464
+ licence: string()
10465
+ });
10466
+ var TrainingStageSchema = _enum([
10467
+ "prepare",
10468
+ "replay",
10469
+ "train",
10470
+ "eval",
10471
+ "export",
10472
+ "package"
10473
+ ]);
10474
+ var EventBase = {
10475
+ v: literal(1),
10476
+ ts: number()
10477
+ };
10478
+ discriminatedUnion("type", [
10479
+ object({
10480
+ ...EventBase,
10481
+ type: literal("stage"),
10482
+ stage: TrainingStageSchema
10483
+ }),
10484
+ object({
10485
+ ...EventBase,
10486
+ type: literal("epoch"),
10487
+ epoch: number().int(),
10488
+ epochs: number().int(),
10489
+ boxLoss: number().nullable().optional(),
10490
+ map50: number().nullable().optional(),
10491
+ map50_95: number().nullable().optional(),
10492
+ etaSec: number().nullable().optional()
10493
+ }),
10494
+ object({
10495
+ ...EventBase,
10496
+ type: literal("metric"),
10497
+ name: string(),
10498
+ value: number()
10499
+ }),
10500
+ object({
10501
+ ...EventBase,
10502
+ type: literal("artifact"),
10503
+ path: string(),
10504
+ bytes: number(),
10505
+ sha256: string()
10506
+ }),
10507
+ object({
10508
+ ...EventBase,
10509
+ type: literal("done"),
10510
+ status: _enum(["succeeded", "failed"]),
10511
+ resultSha256: string().nullable().optional()
10512
+ }),
10513
+ object({
10514
+ ...EventBase,
10515
+ type: literal("error"),
10516
+ stage: string(),
10517
+ code: string(),
10518
+ message: string()
10519
+ })
10520
+ ]);
10521
+ /**
9826
10522
  * What the gate decided about a birth, from the CALLER's point of view.
9827
10523
  *
9828
10524
  * Deliberately not `ConfirmationVerdict`: `undecided` is not a birth decision
@@ -12306,7 +13002,9 @@ var AddonHttpRouteSchema = object({
12306
13002
  "authenticated",
12307
13003
  "admin"
12308
13004
  ]).optional(),
12309
- description: string().optional()
13005
+ description: string().optional(),
13006
+ /** The hub limits this route per client address before the handler runs. */
13007
+ rateLimit: _enum(["auth"]).optional()
12310
13008
  });
12311
13009
  /**
12312
13010
  * Cross-process route invocation envelope. The hub captures the
@@ -13011,6 +13709,37 @@ var BackupDestinationInfoSchema = object({
13011
13709
  lastError: string().optional()
13012
13710
  });
13013
13711
  /**
13712
+ * How an archive is encrypted (operator decision 2026-10-09): to a backup
13713
+ * PUBLIC key the hub holds, so only the operator's secret key opens it.
13714
+ * Absent on a plain `.tar.gz` — every archive made before encryption, or
13715
+ * with it off — which restores without a key.
13716
+ */
13717
+ var BackupArchiveEncryptionSchema = object({
13718
+ /** `x25519-hkdf-aes256gcm-stream-v1`. */
13719
+ scheme: string(),
13720
+ /** 16 hex — the backup key whose secret restores this archive. */
13721
+ keyId: string()
13722
+ });
13723
+ /**
13724
+ * The backup encryption setting. The hub keeps PUBLIC keys only: the active
13725
+ * one new archives are encrypted to, and the retired ones older archives
13726
+ * still need. The secret key is shown once, at `setupEncryption`.
13727
+ */
13728
+ var BackupEncryptionStatusSchema = object({
13729
+ enabled: boolean(),
13730
+ active: object({
13731
+ keyId: string(),
13732
+ publicKey: string(),
13733
+ createdAt: number()
13734
+ }).nullable(),
13735
+ /** Every key ever set up, newest first. */
13736
+ keys: array(object({
13737
+ keyId: string(),
13738
+ createdAt: number(),
13739
+ retiredAt: number().nullable()
13740
+ })).readonly()
13741
+ });
13742
+ /**
13014
13743
  * Per-archive entry returned by `backup.listArchives({ destinationId })`.
13015
13744
  * Same shape the destination drill-in renders. Sourced from the per-
13016
13745
  * location `manifests.json` (no per-archive tarball read required).
@@ -13022,7 +13751,9 @@ var BackupArchiveEntrySchema = object({
13022
13751
  sizeBytes: number(),
13023
13752
  label: string().optional(),
13024
13753
  /** Top-level locations included in the archive (db, addons, tls, …). */
13025
- locations: array(string()).readonly()
13754
+ locations: array(string()).readonly(),
13755
+ /** Present when the archive is encrypted; restore then needs that key. */
13756
+ encryption: BackupArchiveEncryptionSchema.optional()
13026
13757
  });
13027
13758
  var BackupEntrySchema = object({
13028
13759
  id: string(),
@@ -13031,7 +13762,8 @@ var BackupEntrySchema = object({
13031
13762
  label: string().optional(),
13032
13763
  createdAt: number(),
13033
13764
  sizeBytes: number(),
13034
- locations: array(string()).optional()
13765
+ locations: array(string()).optional(),
13766
+ encryption: BackupArchiveEncryptionSchema.optional()
13035
13767
  });
13036
13768
  var ArchiveEntrySchema = object({
13037
13769
  path: string(),
@@ -13220,10 +13952,40 @@ method(_void(), array(BackupDestinationInfoSchema).readonly(), { auth: "admin" }
13220
13952
  * this list and skips entries whose path doesn't start with
13221
13953
  * any of them.
13222
13954
  */
13223
- locations: array(string()).optional()
13955
+ locations: array(string()).optional(),
13956
+ /**
13957
+ * The backup SECRET key, for an encrypted archive (ignored for a plain
13958
+ * one). The archive is decrypted into the hub's private staging
13959
+ * before the restart; the key is not stored. A wrong or missing key
13960
+ * is refused before the archive is downloaded.
13961
+ */
13962
+ backupSecretKey: string().optional()
13224
13963
  }), _void(), {
13225
13964
  kind: "mutation",
13226
13965
  auth: "admin"
13966
+ }), method(_void(), BackupEncryptionStatusSchema, { auth: "admin" }), method(object({}), object({
13967
+ keyId: string(),
13968
+ secretKey: string(),
13969
+ publicKey: string(),
13970
+ createdAt: number(),
13971
+ replacedKeyId: string().nullable()
13972
+ }), {
13973
+ kind: "mutation",
13974
+ auth: "admin"
13975
+ }), method(object({}), object({ disabledKeyId: string().nullable() }), {
13976
+ kind: "mutation",
13977
+ auth: "admin"
13978
+ }), method(object({ backupSecretKey: string() }), object({
13979
+ valid: boolean(),
13980
+ keyId: string().nullable(),
13981
+ /** The hub knows this key (active or retired). */
13982
+ known: boolean(),
13983
+ /** It is the key new archives are encrypted to. */
13984
+ active: boolean(),
13985
+ error: string().optional()
13986
+ }), {
13987
+ kind: "mutation",
13988
+ auth: "admin"
13227
13989
  }), method(object({
13228
13990
  destinationId: string(),
13229
13991
  backupId: string()
@@ -14847,22 +15609,87 @@ var CustomModelDescriptorSchema = object({
14847
15609
  stepId: string(),
14848
15610
  entry: ModelCatalogEntrySchema
14849
15611
  });
15612
+ /** One regular file of an imported bundle, as the producer measured it. */
15613
+ var ModelBundleFileSchema = object({
15614
+ /** Relative path inside the bundle tar; an mlpackage member is `<x>.mlpackage/<member>`. */
15615
+ path: string().min(1),
15616
+ bytes: number().int().nonnegative(),
15617
+ sha256: string().regex(/^[0-9a-f]{64}$/)
15618
+ });
15619
+ var ImportModelBundleInputSchema = object({
15620
+ /** The registry provider that keeps the model (Model Studio). */
15621
+ addonId: string(),
15622
+ stepId: string().min(1),
15623
+ /**
15624
+ * The catalog rows to register, complete, every format URL already
15625
+ * `camstack-local://<modelId>/<file>` naming a file of the bundle. One
15626
+ * bundle may carry several rows (a base and its INT8 variant).
15627
+ */
15628
+ entries: array(ModelCatalogEntrySchema).min(1).max(4),
15629
+ /** The bundle tar, offered by the producer over `ctx.peerBytes` (same host). */
15630
+ bundle: object({
15631
+ ticket: PeerBytesTicketSchema,
15632
+ bytes: number().int().positive(),
15633
+ sha256: string().regex(/^[0-9a-f]{64}$/)
15634
+ }),
15635
+ /** Every file the tar must hold; anything missing, extra or different is refused. */
15636
+ files: array(ModelBundleFileSchema).min(1).max(64),
15637
+ /** Convert missing engine formats and push the model to every agent afterwards. */
15638
+ distribute: boolean()
15639
+ });
15640
+ var ImportModelBundleResultSchema = discriminatedUnion("kind", [object({
15641
+ kind: literal("imported"),
15642
+ modelIds: array(string()).readonly(),
15643
+ distributed: array(object({
15644
+ modelId: string(),
15645
+ nodeId: string(),
15646
+ format: _enum(MODEL_FORMATS),
15647
+ ok: boolean(),
15648
+ error: string().optional()
15649
+ })).readonly()
15650
+ }), object({
15651
+ kind: literal("refused"),
15652
+ reason: _enum([
15653
+ "transfer-failed",
15654
+ "checksum-mismatch",
15655
+ "bundle-mismatch",
15656
+ "invalid-entry",
15657
+ "id-taken"
15658
+ ]),
15659
+ detail: string()
15660
+ })]);
14850
15661
  var customModelRegistryCapability = {
14851
15662
  name: "custom-model-registry",
14852
15663
  scope: "system",
14853
15664
  mode: "collection",
14854
15665
  internal: true,
14855
- methods: {
14856
- /**
14857
- * `internal: true` did not gate the mount (see the 2026-08-26 note on
14858
- * `data-store-provider`) — this was reachable on the AppRouter by ANY
14859
- * authenticated session at the default `auth: 'protected'`. The only
14860
- * consumer, the detection-pipeline's model resolution
14861
- * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
14862
- * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
14863
- * never tRPC — so `auth: 'admin'` costs it nothing.
14864
- */
14865
- listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }) }
15666
+ methods: {
15667
+ /**
15668
+ * `internal: true` did not gate the mount (see the 2026-08-26 note on
15669
+ * `data-store-provider`) — this was reachable on the AppRouter by ANY
15670
+ * authenticated session at the default `auth: 'protected'`. The only
15671
+ * consumer, the detection-pipeline's model resolution
15672
+ * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
15673
+ * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
15674
+ * never tRPC — so `auth: 'admin'` costs it nothing.
15675
+ */
15676
+ listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }),
15677
+ /**
15678
+ * Register a model whose files arrive as ONE bundle tar (D806): the tar
15679
+ * is taken over `ctx.peerBytes`, checked against `bundle.sha256` and
15680
+ * every row of `files`, unpacked into the hub's flat modelsDir (directory
15681
+ * formats included), each format's `.revision` record written, the rows
15682
+ * upserted under the operator's name, the hub marked available and —
15683
+ * when asked — engine formats converted and the model distributed. A
15684
+ * model id already registered by another source is refused, never
15685
+ * overwritten.
15686
+ */
15687
+ importModelBundle: method(ImportModelBundleInputSchema, ImportModelBundleResultSchema, {
15688
+ kind: "mutation",
15689
+ auth: "admin",
15690
+ timeoutMs: 30 * 6e4
15691
+ })
15692
+ }
14866
15693
  };
14867
15694
  /**
14868
15695
  * Query filter for settings-store collections.
@@ -15342,6 +16169,35 @@ var KeychainKeySourceSchema = object({
15342
16169
  */
15343
16170
  sharesBackupWithDatabase: boolean()
15344
16171
  });
16172
+ /**
16173
+ * One keychain reset, as the Secrets page reports it until the operator
16174
+ * acknowledges it. Never a value: refs, counts and table names only.
16175
+ */
16176
+ var KeychainResetRecordSchema = object({
16177
+ id: string(),
16178
+ at: number(),
16179
+ /** `user:<id>` or {@link KEYCHAIN_RESET_TRIGGER_ACTOR}. */
16180
+ actor: string(),
16181
+ /** Why the keychain was locked when it was reset; `null` when it was not locked. */
16182
+ lockedReason: string().nullable(),
16183
+ /** Values moved into the archive table (ciphertext under the lost key). */
16184
+ archived: number().int(),
16185
+ /** `keychain:secrets-orphaned-<ts>`, or `null` when nothing was stored. */
16186
+ archivedCollection: string().nullable(),
16187
+ /**
16188
+ * `keychain:keys-orphaned-<ts>`: the wrapped data keys of the archive, kept
16189
+ * so the archive can still be opened if the lost master key turns up.
16190
+ */
16191
+ archivedKeysCollection: string().nullable(),
16192
+ /**
16193
+ * `system-settings` keys whose marker the reset cleared — the cluster
16194
+ * secret's: a marker left pointing at an archived value would refuse every
16195
+ * agent forever (D797).
16196
+ */
16197
+ clearedSettingsKeys: array(string()).readonly(),
16198
+ /** When an operator dismissed the notice on the Secrets page; `null` until then. */
16199
+ acknowledgedAt: number().nullable()
16200
+ });
15345
16201
  var KeychainStatusSchema = object({
15346
16202
  keychain: KeychainStateSchema,
15347
16203
  /** The source of the master key in use; `null` while locked. */
@@ -15359,7 +16215,9 @@ var KeychainStatusSchema = object({
15359
16215
  /** Wrapped copies of the data key under a previous master key, kept until purged. */
15360
16216
  retiredWraps: number().int(),
15361
16217
  recoveryKeyDownloadedAt: number().nullable(),
15362
- secretCount: number().int()
16218
+ secretCount: number().int(),
16219
+ /** The most recent reset, acknowledged or not; `null` when the keychain was never reset. */
16220
+ lastReset: KeychainResetRecordSchema.nullable()
15363
16221
  });
15364
16222
  /**
15365
16223
  * Whether a stored value is still pointed at by its owner's settings.
@@ -15381,13 +16239,14 @@ var KeychainAuditActionSchema = _enum([
15381
16239
  "download-recovery-key",
15382
16240
  "delete-orphans",
15383
16241
  "reset",
16242
+ "acknowledge-reset",
15384
16243
  "initialize"
15385
16244
  ]);
15386
16245
  var KeychainAuditEntrySchema = object({
15387
16246
  id: string(),
15388
16247
  at: number(),
15389
16248
  action: KeychainAuditActionSchema,
15390
- /** `addon:<id>` | `user:<id>` | `system`. */
16249
+ /** `addon:<id>` | `user:<id>` | `system` | `trigger-file`. */
15391
16250
  actor: string(),
15392
16251
  ref: string().nullable(),
15393
16252
  detail: string().nullable()
@@ -15453,6 +16312,13 @@ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}),
15453
16312
  kind: "mutation",
15454
16313
  auth: "admin",
15455
16314
  caller: "required"
16315
+ }), method(object({}), object({
16316
+ reset: KeychainResetRecordSchema.nullable(),
16317
+ pendingReentry: array(KeychainSecretMetaSchema).readonly()
16318
+ }), { auth: "admin" }), method(object({}), object({ acknowledged: boolean() }), {
16319
+ kind: "mutation",
16320
+ auth: "admin",
16321
+ caller: "required"
15456
16322
  });
15457
16323
  method(_void(), object({
15458
16324
  id: string(),
@@ -18098,7 +18964,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18098
18964
  * `login-method` — collection cap through which auth addons contribute
18099
18965
  * their pre-auth login surfaces to the login page. This is the SINGLE,
18100
18966
  * generic mechanism that supersedes the dead `auth.listProviders` reader:
18101
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
18967
+ * every auth addon (OIDC, WebAuthn/passkey) registers a
18102
18968
  * `login-method` provider and the PUBLIC `auth.listLoginMethods`
18103
18969
  * procedure aggregates them for the unauthenticated login page.
18104
18970
  *
@@ -18106,8 +18972,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18106
18972
  *
18107
18973
  * - `redirect` — a declarative button. The login page renders a generic
18108
18974
  * button that navigates to `startUrl` (an addon-owned HTTP route).
18109
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
18110
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
18975
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) with ZERO shell-side JS. A future SSO addon plugs in the same way — the
18111
18976
  * login page needs NO change.
18112
18977
  *
18113
18978
  * - `widget` — a Module-Federation widget the login page mounts (via
@@ -18126,8 +18991,8 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18126
18991
  * decision.
18127
18992
  *
18128
18993
  * Every contribution carries a `stage`:
18129
- * - `primary` — shown on the first credentials screen (OIDC /
18130
- * magic-link buttons; a future usernameless passkey).
18994
+ * - `primary` — shown on the first credentials screen (OIDC
18995
+ * buttons; a usernameless passkey).
18131
18996
  * - `second-factor` — shown AFTER the password leg, gated on the
18132
18997
  * returned `factors` (passkey-as-2FA today).
18133
18998
  *
@@ -18154,7 +19019,7 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
18154
19019
  * The provider names an external identity a signed-in user can link to
18155
19020
  * their own account (D782): `auth.listLinkableProviders` /
18156
19021
  * `beginExternalLink` offer exactly the redirect methods that set this,
18157
- * whatever their id. Absent / false — a login button only (magic-link).
19022
+ * whatever their id. Absent / false — a login button only.
18158
19023
  */
18159
19024
  linkable: boolean().optional()
18160
19025
  }),
@@ -21977,8 +22842,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
21977
22842
  * `super_admin` — collapsed onto the single boolean because every
21978
22843
  * non-admin caller is governed by the same scope-check rules; the
21979
22844
  * distinction was only ever used to route role-specific procedures
21980
- * which we no longer have. Agents are admin sessions issued via
21981
- * `createServiceToken`; CLI / webhook integrations are `cst_*` tokens
22845
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
21982
22846
  * with `isAdmin: false` + an explicit scope list.
21983
22847
  */
21984
22848
  /** Per-method access flavour. Materialised on every cap method via codegen. */
@@ -24673,6 +25537,17 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
24673
25537
  kind: "mutation",
24674
25538
  auth: "admin",
24675
25539
  timeoutMs: 60 * 6e4
25540
+ }), method(object({
25541
+ filter: RetrainExportFilterSchema,
25542
+ layout: RetrainExportLayoutSchema
25543
+ }), object({
25544
+ ticket: PeerBytesTicketSchema,
25545
+ frames: number().int(),
25546
+ annotations: number().int()
25547
+ }), {
25548
+ kind: "mutation",
25549
+ auth: "admin",
25550
+ timeoutMs: 12e4
24676
25551
  }), method(object({
24677
25552
  selection: RetrainDatasetSelectionSchema,
24678
25553
  completeOnly: boolean().optional()
@@ -28241,8 +29116,8 @@ version: string().optional() }), ServerUpdateActionResultSchema, {
28241
29116
  * `smtp-provider` — pluggable email delivery surface.
28242
29117
  *
28243
29118
  * Collection cap: a deployment may install multiple SMTP relays (e.g.
28244
- * one for transactional / one for notifications). Consumers (magic-link,
28245
- * notifier addons, …) walk the collection and pick the first
29119
+ * one for transactional / one for notifications). Consumers (notifier
29120
+ * addons, …) walk the collection and pick the first
28246
29121
  * ready provider OR target a specific addonId.
28247
29122
  *
28248
29123
  * The shape stays small on purpose — `sendEmail` is enough for the
@@ -28421,7 +29296,7 @@ targets: array(object({
28421
29296
  })));
28422
29297
  /**
28423
29298
  * `sso-bridge` — internal hub-only cap that lets SSO-style auth
28424
- * providers (OIDC, SAML, magic-link, …) mint an HMAC-signed token
29299
+ * providers (OIDC, SAML, …) mint an HMAC-signed token
28425
29300
  * carrying the post-callback claims before redirecting back to
28426
29301
  * `/api/auth/sso/finish`.
28427
29302
  *
@@ -28484,7 +29359,14 @@ var SsoBridgeClaimsSchema = object({
28484
29359
  * Verified `iss` of the id_token behind an OIDC login bridge (D782). A
28485
29360
  * subject is unique only per issuer, so a link is bound to it.
28486
29361
  */
28487
- issuer: string().optional()
29362
+ issuer: string().optional(),
29363
+ /**
29364
+ * SHA-256 (hex) of the `camstack_sso_state` cookie the IdP `/start` set in
29365
+ * the browser that began this sign-in. `/api/auth/sso/finish` requires the
29366
+ * request to present the matching cookie — a login bridge is useless in
29367
+ * any other browser.
29368
+ */
29369
+ browserBinding: string().optional()
28488
29370
  });
28489
29371
  method(object({
28490
29372
  claims: SsoBridgeClaimsSchema,
@@ -34376,7 +35258,13 @@ var TopologyNodeSchema = object({
34376
35258
  })).readonly(),
34377
35259
  processes: array(TopologyProcessSchema).readonly(),
34378
35260
  categories: array(TopologyCategorySchema).readonly(),
34379
- rootPackage: TopologyRootPackageSchema.nullable()
35261
+ rootPackage: TopologyRootPackageSchema.nullable(),
35262
+ /**
35263
+ * How an online AGENT reaches the hub (mesh mTLS Release A): `tls` once it has
35264
+ * completed a mutual-TLS handshake, `clear` otherwise. Absent for the hub,
35265
+ * for offline rows and when the hub cannot tell.
35266
+ */
35267
+ meshTransport: _enum(["tls", "clear"]).optional()
34380
35268
  });
34381
35269
  var CapUsageEdgeSchema = object({
34382
35270
  callerAddonId: string(),
@@ -38404,16 +39292,6 @@ var ApiKeySummarySchema = object({
38404
39292
  createdAt: number(),
38405
39293
  lastUsedAt: number().optional()
38406
39294
  });
38407
- var CreateApiKeyInputSchema = object({
38408
- label: string(),
38409
- isAdmin: boolean().default(false),
38410
- allowedProviders: union([array(string()), literal("*")]).optional(),
38411
- allowedDevices: record(string(), union([array(string()), literal("*")])).optional()
38412
- });
38413
- var CreateApiKeyResultSchema = object({
38414
- token: string(),
38415
- record: ApiKeySummarySchema
38416
- });
38417
39295
  var ScopedTokenSummarySchema = object({
38418
39296
  id: string(),
38419
39297
  userId: string(),
@@ -38512,17 +39390,10 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
38512
39390
  }), UserSummarySchema.extend({ passwordHash: string() }).nullable(), {
38513
39391
  kind: "mutation",
38514
39392
  access: "view"
38515
- }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(CreateApiKeyInputSchema, CreateApiKeyResultSchema, {
38516
- kind: "mutation",
38517
- auth: "admin",
38518
- access: "create"
38519
- }), method(object({ id: string() }), object({ success: literal(true) }), {
39393
+ }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(object({ id: string() }), object({ success: literal(true) }), {
38520
39394
  kind: "mutation",
38521
39395
  auth: "admin",
38522
39396
  access: "delete"
38523
- }), method(object({ token: string() }), ApiKeySummarySchema.nullable(), {
38524
- kind: "mutation",
38525
- access: "view"
38526
39397
  }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
38527
39398
  kind: "mutation",
38528
39399
  auth: "admin",
@@ -38596,15 +39467,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
38596
39467
  }).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
38597
39468
  userId: string(),
38598
39469
  issuer: string()
38599
- }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({
38600
- userId: string(),
38601
- issuer: string().min(1),
38602
- label: string().optional()
38603
- }), object({ success: literal(true) }), {
38604
- kind: "mutation",
38605
- auth: "admin",
38606
- access: "create"
38607
- }), method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
39470
+ }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
38608
39471
  kind: "mutation",
38609
39472
  auth: "admin",
38610
39473
  access: "delete"
@@ -38999,6 +39862,451 @@ DeviceType.Camera, method(object({
38999
39862
  detection: array(ZoneRuleSchema).readonly(),
39000
39863
  package: array(ZoneRuleSchema).readonly()
39001
39864
  });
39865
+ /**
39866
+ * `training-provider` — ONE cloud that can run the CamStack trainer.
39867
+ *
39868
+ * A thin, mockable translation layer: it knows how to run a container with a
39869
+ * GPU, move a dataset in, read the job's stdout and hand artefacts back. It
39870
+ * knows nothing about datasets, splits, floors, cost policy or Model Studio —
39871
+ * those are the `training` orchestrator's (D805). Every rule written there
39872
+ * once is what makes a second provider (RunPod, a local NVIDIA node) a new
39873
+ * manifest entry and nothing else.
39874
+ *
39875
+ * Collection, routed by the `addonId` in every single-row input (the `llm` /
39876
+ * `notification-output` posture); `describe` concat-fans across providers.
39877
+ * Every method is `admin`: these spend money.
39878
+ *
39879
+ * Every cloud object a provider creates is tagged with the orchestrator's
39880
+ * `jobKey`, so a retried submit finds the job it already started instead of
39881
+ * starting a second GPU, and `listJobs` can find orphans.
39882
+ *
39883
+ * Bytes never ride a cap field: the dataset arrives as a `ctx.peerBytes`
39884
+ * ticket the producer (pipeline-analytics) minted, and artefacts leave as a
39885
+ * ticket the provider mints (D613).
39886
+ */
39887
+ var TrainingGpuOptionSchema = object({
39888
+ id: string(),
39889
+ label: string(),
39890
+ /** List price, USD per GPU-hour, before any region multiplier. */
39891
+ usdPerHour: number().nonnegative(),
39892
+ vramGb: number().nonnegative()
39893
+ });
39894
+ var TrainingRegionOptionSchema = object({
39895
+ /** `''` = any region (the provider's choice). */
39896
+ id: string(),
39897
+ label: string(),
39898
+ priceMultiplier: number().positive()
39899
+ });
39900
+ /**
39901
+ * The provider's per-account settings, as the orchestrator reads them. They
39902
+ * live in the PROVIDER addon's settings (operator decision 2026-10-08: they
39903
+ * depend on the user's account), never hard-coded in the orchestrator.
39904
+ */
39905
+ var TrainingProviderDefaultsSchema = object({
39906
+ gpuType: string(),
39907
+ region: string(),
39908
+ costCapUsd: number().nonnegative(),
39909
+ maxRuntimeSec: number().int().positive(),
39910
+ /** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
39911
+ failedDatasetGraceHours: number().nonnegative()
39912
+ });
39913
+ var TrainingProviderDescriptorSchema = object({
39914
+ addonId: string(),
39915
+ /** `modal`, `runpod`, `fake`, … */
39916
+ kind: string(),
39917
+ label: string(),
39918
+ gpuTypes: array(TrainingGpuOptionSchema).readonly(),
39919
+ regions: array(TrainingRegionOptionSchema).readonly(),
39920
+ maxDatasetBytes: number().int().positive(),
39921
+ maxRuntimeSec: number().int().positive(),
39922
+ freeTierNote: string().optional(),
39923
+ /** Where the data goes, in one sentence the confirm dialog repeats. */
39924
+ dataResidencyNote: string(),
39925
+ /** Credentials are present — never the values. */
39926
+ configured: boolean(),
39927
+ defaults: TrainingProviderDefaultsSchema
39928
+ });
39929
+ var TrainingCredentialCheckSchema = object({
39930
+ ok: boolean(),
39931
+ /** Workspace / account name, when the provider says. */
39932
+ account: string().optional(),
39933
+ reason: _enum([
39934
+ "missing",
39935
+ "invalid",
39936
+ "forbidden",
39937
+ "network",
39938
+ "quota"
39939
+ ]).optional(),
39940
+ detail: string().optional()
39941
+ });
39942
+ var ProviderJobStateSchema = _enum([
39943
+ "pending",
39944
+ "starting",
39945
+ "running",
39946
+ "succeeded",
39947
+ "failed",
39948
+ "cancelled",
39949
+ "lost"
39950
+ ]);
39951
+ var ProviderJobStatusSchema = object({
39952
+ jobKey: string(),
39953
+ providerJobId: string().optional(),
39954
+ state: ProviderJobStateSchema,
39955
+ startedAt: number().optional(),
39956
+ endedAt: number().optional(),
39957
+ exitCode: number().int().optional(),
39958
+ failureReason: string().optional(),
39959
+ gpuType: string(),
39960
+ region: string().optional(),
39961
+ billedSeconds: number().nonnegative(),
39962
+ costUsd: number().nonnegative(),
39963
+ /** True when `costUsd` is runtime × list price, not a billing answer. */
39964
+ costIsEstimate: boolean(),
39965
+ lastFetchedAt: number()
39966
+ });
39967
+ /**
39968
+ * The trainer the job runs, by SOURCE revision: the provider turns it into an
39969
+ * image its own way (Modal builds the published Dockerfile at that revision;
39970
+ * a registry-pull provider maps it to a tag). Recorded on the job and echoed
39971
+ * in `result.json`.
39972
+ */
39973
+ var TrainerSourceRefSchema = object({
39974
+ /** Hugging Face repo id, e.g. `camstack/camstack-trainer`. */
39975
+ repo: string().min(1),
39976
+ /** A commit sha (never a branch) — the job must be reproducible. */
39977
+ revision: string().regex(/^[0-9a-f]{7,64}$/)
39978
+ });
39979
+ var JobRef = {
39980
+ addonId: string(),
39981
+ jobKey: string().uuid()
39982
+ };
39983
+ var TrainingLogLineSchema = object({
39984
+ ts: number(),
39985
+ text: string()
39986
+ });
39987
+ method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({ addonId: string() }), TrainingCredentialCheckSchema, {
39988
+ kind: "mutation",
39989
+ auth: "admin",
39990
+ timeoutMs: 3e4
39991
+ }), method(object({
39992
+ addonId: string(),
39993
+ gpuType: string(),
39994
+ region: string(),
39995
+ datasetBytes: number().int().nonnegative(),
39996
+ gpuSecondsLow: number().nonnegative(),
39997
+ gpuSecondsHigh: number().nonnegative()
39998
+ }), object({
39999
+ usdLow: number().nonnegative(),
40000
+ usdHigh: number().nonnegative(),
40001
+ notes: array(string()).readonly()
40002
+ }), { auth: "admin" }), method(object({
40003
+ ...JobRef,
40004
+ ticket: PeerBytesTicketSchema
40005
+ }), object({
40006
+ bytes: number().int().nonnegative(),
40007
+ sha256: string()
40008
+ }), {
40009
+ kind: "mutation",
40010
+ auth: "admin",
40011
+ timeoutMs: 120 * 6e4
40012
+ }), method(object({
40013
+ ...JobRef,
40014
+ trainer: TrainerSourceRefSchema,
40015
+ jobSpecJson: string().min(2).max(64e3),
40016
+ gpuType: string(),
40017
+ region: string(),
40018
+ maxRuntimeSec: number().int().positive()
40019
+ }), ProviderJobStatusSchema, {
40020
+ kind: "mutation",
40021
+ auth: "admin",
40022
+ timeoutMs: 30 * 6e4
40023
+ }), method(object(JobRef), ProviderJobStatusSchema, {
40024
+ auth: "admin",
40025
+ timeoutMs: 6e4
40026
+ }), method(object({
40027
+ ...JobRef,
40028
+ cursor: string().optional(),
40029
+ max: number().int().min(1).max(500)
40030
+ }), object({
40031
+ lines: array(TrainingLogLineSchema).readonly(),
40032
+ cursor: string()
40033
+ }), {
40034
+ auth: "admin",
40035
+ timeoutMs: 6e4
40036
+ }), method(object(JobRef), object({ ok: literal(true) }), {
40037
+ kind: "mutation",
40038
+ auth: "admin",
40039
+ timeoutMs: 6e4
40040
+ }), method(object(JobRef), object({
40041
+ found: boolean(),
40042
+ text: string().optional()
40043
+ }), {
40044
+ kind: "mutation",
40045
+ auth: "admin",
40046
+ timeoutMs: 5 * 6e4
40047
+ }), method(object({
40048
+ ...JobRef,
40049
+ path: _enum(["bundle.tar"])
40050
+ }), object({ ticket: PeerBytesTicketSchema }), {
40051
+ kind: "mutation",
40052
+ auth: "admin",
40053
+ timeoutMs: 5 * 6e4
40054
+ }), method(object(JobRef), object({ deleted: array(string()).readonly() }), {
40055
+ kind: "mutation",
40056
+ auth: "admin",
40057
+ timeoutMs: 5 * 6e4
40058
+ }), method(object({ addonId: string() }), array(ProviderJobStatusSchema).readonly(), {
40059
+ auth: "admin",
40060
+ timeoutMs: 2 * 6e4
40061
+ });
40062
+ /**
40063
+ * `training` — the cloud-training orchestrator (D805). Hub-only singleton,
40064
+ * provided by `addon-training`.
40065
+ *
40066
+ * It owns what every provider must agree on, written once:
40067
+ *
40068
+ * - **Dataset versions.** Taken over from pipeline-analytics (D796): the rows
40069
+ * live here (D808); pipeline-analytics still CUTS a version (it owns the corpus and
40070
+ * the export plan) and reaches this store through the five row methods
40071
+ * below, so the Retrain page and the export did not change.
40072
+ * - **Jobs.** A persisted state machine, a reconcile loop against the
40073
+ * provider, a cost guard, a daily orphan sweep and the retention rules.
40074
+ * - **The return flow.** Verified artefacts → Model Studio
40075
+ * (`custom-model-registry.importModelBundle`) → canary on cameras →
40076
+ * rollback. Nothing is ever registered automatically.
40077
+ *
40078
+ * Every method is `admin`.
40079
+ */
40080
+ /** A version WITH its frame list — what the export and a job read. */
40081
+ var TrainingDatasetVersionRowSchema = RetrainDatasetVersionSchema.omit({ frameCount: true }).extend({ frameIds: array(string()).max(2e4).readonly() });
40082
+ /** A base model a detector job can fine-tune, and the baseline it is judged against. */
40083
+ var TrainingBaseModelSchema = object({
40084
+ modelId: string(),
40085
+ label: string(),
40086
+ weights: string(),
40087
+ imgsz: number().int(),
40088
+ baselineOnnxUrl: string(),
40089
+ baselineFloors: record(string(), number()),
40090
+ /** The base the fleet runs most — the UI's default. */
40091
+ recommended: boolean()
40092
+ });
40093
+ var TrainingPresetSchema = _enum([
40094
+ "quick",
40095
+ "standard",
40096
+ "thorough"
40097
+ ]);
40098
+ var TrainingJobRequestSchema = object({
40099
+ datasetVersionId: string().min(1),
40100
+ /** The `training-provider` addon that runs it. */
40101
+ addonId: string().min(1),
40102
+ gpuType: string().min(1),
40103
+ region: string(),
40104
+ baseModelId: string().min(1),
40105
+ preset: TrainingPresetSchema,
40106
+ /** Freeze the backbone's first N layers; `null` = the preset's choice. */
40107
+ freeze: number().int().nonnegative().nullable(),
40108
+ /** Cameras held out whole for evaluation; `null` = the orchestrator's default. */
40109
+ holdoutCameras: array(number().int()).nullable()
40110
+ });
40111
+ var TrainingSplitPlanSchema = object({
40112
+ holdoutCameras: array(number().int()).readonly(),
40113
+ /** Used when no camera is held out: the last N days of every camera. */
40114
+ holdoutLastDays: number().int().nonnegative(),
40115
+ /** Holdout subjects per class (camera holdout only; `null` = known only after the split). */
40116
+ holdoutSupport: record(string(), number().int()).nullable(),
40117
+ trainSubjects: number().int()
40118
+ });
40119
+ var TrainingRefusalReasonSchema = _enum([
40120
+ "unknown-dataset",
40121
+ "unknown-provider",
40122
+ "provider-not-configured",
40123
+ "unknown-base-model",
40124
+ "unknown-gpu",
40125
+ "dataset-too-large",
40126
+ "no-training-subjects",
40127
+ "job-already-running"
40128
+ ]);
40129
+ var TrainingJobPlanSchema = object({
40130
+ refusal: object({
40131
+ reason: TrainingRefusalReasonSchema,
40132
+ detail: string()
40133
+ }).nullable(),
40134
+ warnings: array(string()).readonly(),
40135
+ split: TrainingSplitPlanSchema.nullable(),
40136
+ estimate: object({
40137
+ datasetBytes: number().int(),
40138
+ uploadMinutesAt20Mbps: number(),
40139
+ gpuSecondsLow: number(),
40140
+ gpuSecondsHigh: number(),
40141
+ usdLow: number(),
40142
+ usdHigh: number(),
40143
+ notes: array(string()).readonly()
40144
+ }).nullable(),
40145
+ /** Pre-filled from the provider's settings; the operator may lower or raise them. */
40146
+ defaults: object({
40147
+ maxCostUsd: number(),
40148
+ maxRuntimeSec: number().int()
40149
+ }).nullable(),
40150
+ /** The sentence the confirm dialog repeats: where the frames go and when they are deleted. */
40151
+ dataNotice: string()
40152
+ });
40153
+ /**
40154
+ * Orchestrator-owned states, persisted. `uploading` covers exporting the
40155
+ * archive (it is streamed, never staged). Terminal: `failed`, `cancelled`,
40156
+ * `lost`, `expired`, `discarded`. `registered` and `canary` are where a
40157
+ * result lives after the operator acted on it.
40158
+ */
40159
+ var TrainingJobStateSchema = _enum([
40160
+ "uploading",
40161
+ "submitted",
40162
+ "starting",
40163
+ "running",
40164
+ "collecting",
40165
+ "ready",
40166
+ "registered",
40167
+ "canary",
40168
+ "failed",
40169
+ "cancelling",
40170
+ "cancelled",
40171
+ "lost",
40172
+ "expired",
40173
+ "discarded"
40174
+ ]);
40175
+ var TrainingFailureReasonSchema = _enum([
40176
+ "cost-cap",
40177
+ "runtime-cap",
40178
+ "upload-failed",
40179
+ "submit-failed",
40180
+ "trainer-failed",
40181
+ "result-invalid",
40182
+ "checksum-mismatch",
40183
+ "fetch-failed",
40184
+ "provider-error",
40185
+ "hub-restart-during-upload"
40186
+ ]);
40187
+ var TrainingProgressPointSchema = object({
40188
+ epoch: number().int(),
40189
+ map50: number().nullable(),
40190
+ map50_95: number().nullable()
40191
+ });
40192
+ var TrainingCanarySchema = object({
40193
+ deviceIds: array(number().int()).readonly(),
40194
+ since: number(),
40195
+ /** Every override the canary replaced, exactly, so rollback restores it. */
40196
+ previous: array(object({
40197
+ deviceId: number().int(),
40198
+ nodeId: string(),
40199
+ deviceKey: string(),
40200
+ patch: object({
40201
+ modelId: string().optional(),
40202
+ settings: record(string(), unknown()).readonly().optional()
40203
+ }).nullable()
40204
+ })).readonly()
40205
+ });
40206
+ var TrainingJobSchema = object({
40207
+ id: string(),
40208
+ idempotencyKey: string(),
40209
+ name: string(),
40210
+ createdAt: number(),
40211
+ updatedAt: number(),
40212
+ state: TrainingJobStateSchema,
40213
+ stage: TrainingStageSchema.nullable(),
40214
+ failure: object({
40215
+ reason: TrainingFailureReasonSchema,
40216
+ stage: string().nullable(),
40217
+ detail: string()
40218
+ }).nullable(),
40219
+ request: TrainingJobRequestSchema,
40220
+ maxCostUsd: number().nonnegative(),
40221
+ maxRuntimeSec: number().int().positive(),
40222
+ trainer: TrainerSourceRefSchema,
40223
+ datasetLayout: RetrainExportLayoutSchema,
40224
+ dataset: object({
40225
+ bytes: number().int(),
40226
+ sha256: string(),
40227
+ uploadedAt: number()
40228
+ }).nullable(),
40229
+ split: TrainingSplitPlanSchema,
40230
+ provider: object({
40231
+ state: ProviderJobStateSchema.nullable(),
40232
+ providerJobId: string().nullable(),
40233
+ startedAt: number().nullable(),
40234
+ endedAt: number().nullable(),
40235
+ billedSeconds: number(),
40236
+ costUsd: number(),
40237
+ costIsEstimate: boolean(),
40238
+ lastPolledAt: number().nullable()
40239
+ }),
40240
+ progress: object({
40241
+ epoch: number().int().nullable(),
40242
+ epochs: number().int().nullable(),
40243
+ etaSec: number().nullable(),
40244
+ series: array(TrainingProgressPointSchema).readonly()
40245
+ }),
40246
+ /** The last lines of the job's output (≤ 200), newest last. Never frame paths. */
40247
+ logTail: array(string()).readonly(),
40248
+ logCursor: string().nullable(),
40249
+ artifacts: object({
40250
+ bundleBytes: number().int(),
40251
+ bundleSha256: string(),
40252
+ fetchedAt: number(),
40253
+ /** When the staged artefacts are deleted from the hub. */
40254
+ expiresAt: number()
40255
+ }).nullable(),
40256
+ /** When the provider-side copy of the frames was deleted; null while it exists. */
40257
+ cloudDatasetDeletedAt: number().nullable(),
40258
+ /** A failed job's dataset is kept until then (the provider's grace), then deleted. */
40259
+ cloudCleanupDueAt: number().nullable(),
40260
+ /** Model ids registered from this job (base, and int8 when kept). */
40261
+ registeredModelIds: array(string()).readonly(),
40262
+ canary: TrainingCanarySchema.nullable()
40263
+ });
40264
+ var IdInput = object({ id: string().min(1) });
40265
+ method(TrainingDatasetVersionRowSchema, object({ stored: boolean() }), {
40266
+ kind: "mutation",
40267
+ auth: "admin"
40268
+ }), method(IdInput, TrainingDatasetVersionRowSchema.nullable(), { auth: "admin" }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), { auth: "admin" }), method(object({ name: string() }), object({ id: string().nullable() }), { auth: "admin" }), method(IdInput, object({ removed: boolean() }), {
40269
+ kind: "mutation",
40270
+ auth: "admin"
40271
+ }), method(object({}), array(TrainingBaseModelSchema).readonly(), { auth: "admin" }), method(TrainingJobRequestSchema, TrainingJobPlanSchema, {
40272
+ auth: "admin",
40273
+ timeoutMs: 6e4
40274
+ }), method(TrainingJobRequestSchema.extend({
40275
+ name: string().min(1).max(120),
40276
+ maxCostUsd: number().positive(),
40277
+ maxRuntimeSec: number().int().positive(),
40278
+ idempotencyKey: string().min(8).max(80)
40279
+ }), discriminatedUnion("kind", [object({
40280
+ kind: literal("started"),
40281
+ job: TrainingJobSchema
40282
+ }), object({
40283
+ kind: literal("refused"),
40284
+ reason: TrainingRefusalReasonSchema,
40285
+ detail: string()
40286
+ })]), {
40287
+ kind: "mutation",
40288
+ auth: "admin",
40289
+ timeoutMs: 12e4
40290
+ }), method(object({}), array(TrainingJobSchema).readonly(), { auth: "admin" }), method(IdInput, TrainingJobSchema.nullable(), { auth: "admin" }), method(IdInput, TrainingJobSchema, {
40291
+ kind: "mutation",
40292
+ auth: "admin",
40293
+ timeoutMs: 12e4
40294
+ }), method(IdInput, TrainingResultSchema.nullable(), { auth: "admin" }), method(IdInput.extend({ canaryDeviceIds: array(number().int()).readonly() }), TrainingJobSchema, {
40295
+ kind: "mutation",
40296
+ auth: "admin",
40297
+ timeoutMs: 30 * 6e4
40298
+ }), method(IdInput.extend({ deviceIds: array(number().int()).min(1).readonly() }), TrainingJobSchema, {
40299
+ kind: "mutation",
40300
+ auth: "admin",
40301
+ timeoutMs: 12e4
40302
+ }), method(IdInput, TrainingJobSchema, {
40303
+ kind: "mutation",
40304
+ auth: "admin",
40305
+ timeoutMs: 12e4
40306
+ }), method(IdInput, TrainingJobSchema, {
40307
+ kind: "mutation",
40308
+ auth: "admin"
40309
+ });
39002
40310
  SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
39003
40311
  function isClassMapMacroTarget(value) {
39004
40312
  return CLASS_MAP_MACRO_TARGETS.some((target) => target === value);
@@ -39720,6 +41028,12 @@ Object.freeze({
39720
41028
  addonId: null,
39721
41029
  access: "create"
39722
41030
  },
41031
+ "backup.checkBackupKey": {
41032
+ capName: "backup",
41033
+ capScope: "system",
41034
+ addonId: null,
41035
+ access: "create"
41036
+ },
39723
41037
  "backup.delete": {
39724
41038
  capName: "backup",
39725
41039
  capScope: "system",
@@ -39732,6 +41046,18 @@ Object.freeze({
39732
41046
  addonId: null,
39733
41047
  access: "delete"
39734
41048
  },
41049
+ "backup.disableEncryption": {
41050
+ capName: "backup",
41051
+ capScope: "system",
41052
+ addonId: null,
41053
+ access: "create"
41054
+ },
41055
+ "backup.getEncryption": {
41056
+ capName: "backup",
41057
+ capScope: "system",
41058
+ addonId: null,
41059
+ access: "view"
41060
+ },
39735
41061
  "backup.getEntries": {
39736
41062
  capName: "backup",
39737
41063
  capScope: "system",
@@ -39786,6 +41112,12 @@ Object.freeze({
39786
41112
  addonId: null,
39787
41113
  access: "create"
39788
41114
  },
41115
+ "backup.setupEncryption": {
41116
+ capName: "backup",
41117
+ capScope: "system",
41118
+ addonId: null,
41119
+ access: "create"
41120
+ },
39789
41121
  "backup.trigger": {
39790
41122
  capName: "backup",
39791
41123
  capScope: "system",
@@ -40338,6 +41670,12 @@ Object.freeze({
40338
41670
  addonId: null,
40339
41671
  access: "create"
40340
41672
  },
41673
+ "customModelRegistry.importModelBundle": {
41674
+ capName: "custom-model-registry",
41675
+ capScope: "system",
41676
+ addonId: null,
41677
+ access: "create"
41678
+ },
40341
41679
  "customModelRegistry.listModels": {
40342
41680
  capName: "custom-model-registry",
40343
41681
  capScope: "system",
@@ -41778,6 +43116,12 @@ Object.freeze({
41778
43116
  addonId: null,
41779
43117
  access: "view"
41780
43118
  },
43119
+ "keychainAdmin.acknowledgeReset": {
43120
+ capName: "keychain-admin",
43121
+ capScope: "system",
43122
+ addonId: null,
43123
+ access: "create"
43124
+ },
41781
43125
  "keychainAdmin.deleteOrphans": {
41782
43126
  capName: "keychain-admin",
41783
43127
  capScope: "system",
@@ -41814,6 +43158,12 @@ Object.freeze({
41814
43158
  addonId: null,
41815
43159
  access: "delete"
41816
43160
  },
43161
+ "keychainAdmin.resetReport": {
43162
+ capName: "keychain-admin",
43163
+ capScope: "system",
43164
+ addonId: null,
43165
+ access: "delete"
43166
+ },
41817
43167
  "keychainAdmin.reveal": {
41818
43168
  capName: "keychain-admin",
41819
43169
  capScope: "system",
@@ -43560,6 +44910,12 @@ Object.freeze({
43560
44910
  addonId: null,
43561
44911
  access: "view"
43562
44912
  },
44913
+ "pipelineAnalytics.offerRetrainArchive": {
44914
+ capName: "pipeline-analytics",
44915
+ capScope: "device",
44916
+ addonId: null,
44917
+ access: "create"
44918
+ },
43563
44919
  "pipelineAnalytics.ownersWithMedia": {
43564
44920
  capName: "pipeline-analytics",
43565
44921
  capScope: "device",
@@ -46098,6 +47454,174 @@ Object.freeze({
46098
47454
  addonId: null,
46099
47455
  access: "view"
46100
47456
  },
47457
+ "training.canaryResult": {
47458
+ capName: "training",
47459
+ capScope: "system",
47460
+ addonId: null,
47461
+ access: "create"
47462
+ },
47463
+ "training.cancelJob": {
47464
+ capName: "training",
47465
+ capScope: "system",
47466
+ addonId: null,
47467
+ access: "create"
47468
+ },
47469
+ "training.discardResult": {
47470
+ capName: "training",
47471
+ capScope: "system",
47472
+ addonId: null,
47473
+ access: "create"
47474
+ },
47475
+ "training.findDatasetVersionIdByName": {
47476
+ capName: "training",
47477
+ capScope: "system",
47478
+ addonId: null,
47479
+ access: "view"
47480
+ },
47481
+ "training.getDatasetVersion": {
47482
+ capName: "training",
47483
+ capScope: "system",
47484
+ addonId: null,
47485
+ access: "view"
47486
+ },
47487
+ "training.getJob": {
47488
+ capName: "training",
47489
+ capScope: "system",
47490
+ addonId: null,
47491
+ access: "view"
47492
+ },
47493
+ "training.getJobResult": {
47494
+ capName: "training",
47495
+ capScope: "system",
47496
+ addonId: null,
47497
+ access: "view"
47498
+ },
47499
+ "training.listBaseModels": {
47500
+ capName: "training",
47501
+ capScope: "system",
47502
+ addonId: null,
47503
+ access: "view"
47504
+ },
47505
+ "training.listDatasetVersions": {
47506
+ capName: "training",
47507
+ capScope: "system",
47508
+ addonId: null,
47509
+ access: "view"
47510
+ },
47511
+ "training.listJobs": {
47512
+ capName: "training",
47513
+ capScope: "system",
47514
+ addonId: null,
47515
+ access: "view"
47516
+ },
47517
+ "training.planJob": {
47518
+ capName: "training",
47519
+ capScope: "system",
47520
+ addonId: null,
47521
+ access: "view"
47522
+ },
47523
+ "training.putDatasetVersion": {
47524
+ capName: "training",
47525
+ capScope: "system",
47526
+ addonId: null,
47527
+ access: "create"
47528
+ },
47529
+ "training.registerResult": {
47530
+ capName: "training",
47531
+ capScope: "system",
47532
+ addonId: null,
47533
+ access: "create"
47534
+ },
47535
+ "training.removeDatasetVersion": {
47536
+ capName: "training",
47537
+ capScope: "system",
47538
+ addonId: null,
47539
+ access: "delete"
47540
+ },
47541
+ "training.rollbackCanary": {
47542
+ capName: "training",
47543
+ capScope: "system",
47544
+ addonId: null,
47545
+ access: "create"
47546
+ },
47547
+ "training.startJob": {
47548
+ capName: "training",
47549
+ capScope: "system",
47550
+ addonId: null,
47551
+ access: "create"
47552
+ },
47553
+ "trainingProvider.cancelJob": {
47554
+ capName: "training-provider",
47555
+ capScope: "system",
47556
+ addonId: null,
47557
+ access: "create"
47558
+ },
47559
+ "trainingProvider.cleanupJob": {
47560
+ capName: "training-provider",
47561
+ capScope: "system",
47562
+ addonId: null,
47563
+ access: "create"
47564
+ },
47565
+ "trainingProvider.describe": {
47566
+ capName: "training-provider",
47567
+ capScope: "system",
47568
+ addonId: null,
47569
+ access: "view"
47570
+ },
47571
+ "trainingProvider.estimateJob": {
47572
+ capName: "training-provider",
47573
+ capScope: "system",
47574
+ addonId: null,
47575
+ access: "view"
47576
+ },
47577
+ "trainingProvider.getJob": {
47578
+ capName: "training-provider",
47579
+ capScope: "system",
47580
+ addonId: null,
47581
+ access: "view"
47582
+ },
47583
+ "trainingProvider.listJobEvents": {
47584
+ capName: "training-provider",
47585
+ capScope: "system",
47586
+ addonId: null,
47587
+ access: "view"
47588
+ },
47589
+ "trainingProvider.listJobs": {
47590
+ capName: "training-provider",
47591
+ capScope: "system",
47592
+ addonId: null,
47593
+ access: "view"
47594
+ },
47595
+ "trainingProvider.offerArtifact": {
47596
+ capName: "training-provider",
47597
+ capScope: "system",
47598
+ addonId: null,
47599
+ access: "create"
47600
+ },
47601
+ "trainingProvider.readResult": {
47602
+ capName: "training-provider",
47603
+ capScope: "system",
47604
+ addonId: null,
47605
+ access: "create"
47606
+ },
47607
+ "trainingProvider.submitJob": {
47608
+ capName: "training-provider",
47609
+ capScope: "system",
47610
+ addonId: null,
47611
+ access: "create"
47612
+ },
47613
+ "trainingProvider.uploadDataset": {
47614
+ capName: "training-provider",
47615
+ capScope: "system",
47616
+ addonId: null,
47617
+ access: "create"
47618
+ },
47619
+ "trainingProvider.validateCredentials": {
47620
+ capName: "training-provider",
47621
+ capScope: "system",
47622
+ addonId: null,
47623
+ access: "create"
47624
+ },
46101
47625
  "turnProvider.getTurnServers": {
46102
47626
  capName: "turn-provider",
46103
47627
  capScope: "system",
@@ -46122,12 +47646,6 @@ Object.freeze({
46122
47646
  addonId: null,
46123
47647
  access: "create"
46124
47648
  },
46125
- "userManagement.createApiKey": {
46126
- capName: "user-management",
46127
- capScope: "system",
46128
- addonId: null,
46129
- access: "create"
46130
- },
46131
47649
  "userManagement.createScopedToken": {
46132
47650
  capName: "user-management",
46133
47651
  capScope: "system",
@@ -46164,12 +47682,6 @@ Object.freeze({
46164
47682
  addonId: null,
46165
47683
  access: "view"
46166
47684
  },
46167
- "userManagement.linkExternalIdentity": {
46168
- capName: "user-management",
46169
- capScope: "system",
46170
- addonId: null,
46171
- access: "create"
46172
- },
46173
47685
  "userManagement.listApiKeys": {
46174
47686
  capName: "user-management",
46175
47687
  capScope: "system",
@@ -46272,12 +47784,6 @@ Object.freeze({
46272
47784
  addonId: null,
46273
47785
  access: "create"
46274
47786
  },
46275
- "userManagement.validateApiKey": {
46276
- capName: "user-management",
46277
- capScope: "system",
46278
- addonId: null,
46279
- access: "view"
46280
- },
46281
47787
  "userManagement.validateCredentials": {
46282
47788
  capName: "user-management",
46283
47789
  capScope: "system",
@@ -50391,6 +51897,11 @@ Object.freeze({
50391
51897
  form: "single",
50392
51898
  optional: false
50393
51899
  }],
51900
+ "training.canaryResult": [{
51901
+ name: "deviceIds",
51902
+ form: "array",
51903
+ optional: false
51904
+ }],
50394
51905
  "update.getStatus": [{
50395
51906
  name: "deviceId",
50396
51907
  form: "single",
@@ -52327,6 +53838,310 @@ async function ensureFormatsThenDistribute(modelId, deps) {
52327
53838
  };
52328
53839
  }
52329
53840
  //#endregion
53841
+ //#region src/bundle/bundle-tar.ts
53842
+ /**
53843
+ * A minimal, allowlist-only tar reader for model bundles (D806).
53844
+ *
53845
+ * The bundle comes from a trainer we did not run on this machine, so the
53846
+ * reader trusts nothing in it: every regular file must be NAMED in the
53847
+ * caller's allowlist (exact match after normalisation), anything else — an
53848
+ * unlisted file, a link, a device, an absolute or `..` path — fails the whole
53849
+ * bundle. Files are streamed to disk in chunks and hashed on the way; nothing
53850
+ * is held whole in memory.
53851
+ *
53852
+ * Formats read: POSIX ustar (with its 155-byte prefix), PAX `path` records
53853
+ * (`x`), GNU long names (`L`) — what Python's `tarfile` writes. Directory
53854
+ * entries are accepted and ignored (directories are created from file paths).
53855
+ */
53856
+ var BLOCK = 512;
53857
+ var COPY_CHUNK = 1024 * 1024;
53858
+ function readString(buf, start, length) {
53859
+ const slice = buf.subarray(start, start + length);
53860
+ const nul = slice.indexOf(0);
53861
+ return slice.subarray(0, nul < 0 ? slice.length : nul).toString("utf8");
53862
+ }
53863
+ function readOctal(buf, start, length) {
53864
+ const text = readString(buf, start, length).trim();
53865
+ return text === "" ? 0 : Number.parseInt(text, 8);
53866
+ }
53867
+ function isZeroBlock(buf) {
53868
+ for (const byte of buf) if (byte !== 0) return false;
53869
+ return true;
53870
+ }
53871
+ /** `a/b/c` only: no absolute path, no `.`/`..`/empty segment, no backslash. */
53872
+ function isSafeBundlePath(name) {
53873
+ if (name === "" || name.startsWith("/") || name.includes("\\") || name.includes("\0")) return false;
53874
+ return name.split("/").every((seg) => seg !== "" && seg !== "." && seg !== "..");
53875
+ }
53876
+ function paxPath(body) {
53877
+ let offset = 0;
53878
+ while (offset < body.length) {
53879
+ const space = body.indexOf(32, offset);
53880
+ if (space < 0) break;
53881
+ const length = Number.parseInt(body.subarray(offset, space).toString("utf8"), 10);
53882
+ if (!Number.isFinite(length) || length <= 0) break;
53883
+ const record = body.subarray(space + 1, offset + length - 1).toString("utf8");
53884
+ const eq = record.indexOf("=");
53885
+ if (eq > 0 && record.slice(0, eq) === "path") return record.slice(eq + 1);
53886
+ offset += length;
53887
+ }
53888
+ return null;
53889
+ }
53890
+ /**
53891
+ * Extract every allowlisted regular file of `tarPath` under `destDir`,
53892
+ * keeping its relative path. Refuses on the first entry outside the
53893
+ * allowlist, a duplicate, a non-file entry or a truncated archive.
53894
+ */
53895
+ async function extractBundleTar(tarPath, destDir, allow) {
53896
+ const handle = await open(tarPath, "r");
53897
+ try {
53898
+ const header = Buffer.alloc(BLOCK);
53899
+ const seen = /* @__PURE__ */ new Map();
53900
+ let position = 0;
53901
+ let pendingName = null;
53902
+ for (;;) {
53903
+ const { bytesRead } = await handle.read(header, 0, BLOCK, position);
53904
+ if (bytesRead === 0) break;
53905
+ if (bytesRead < BLOCK) return {
53906
+ kind: "refused",
53907
+ detail: "truncated tar header"
53908
+ };
53909
+ position += BLOCK;
53910
+ if (isZeroBlock(header)) break;
53911
+ const size = readOctal(header, 124, 12);
53912
+ const type = String.fromCharCode(header[156] ?? 48);
53913
+ const padded = Math.ceil(size / BLOCK) * BLOCK;
53914
+ if (type === "x" || type === "L") {
53915
+ const body = Buffer.alloc(size);
53916
+ await handle.read(body, 0, size, position);
53917
+ pendingName = type === "x" ? paxPath(body) : readString(body, 0, size);
53918
+ position += padded;
53919
+ continue;
53920
+ }
53921
+ if (type === "g") {
53922
+ position += padded;
53923
+ continue;
53924
+ }
53925
+ const prefix = readString(header, 345, 155);
53926
+ const shortName = readString(header, 0, 100);
53927
+ const name = (pendingName ?? (prefix !== "" ? `${prefix}/${shortName}` : shortName)).replace(/^\.\//, "");
53928
+ pendingName = null;
53929
+ if (type === "5") {
53930
+ position += padded;
53931
+ continue;
53932
+ }
53933
+ if (type !== "0" && type !== "\0" && type !== "7") return {
53934
+ kind: "refused",
53935
+ detail: `entry "${name}" is not a regular file (type ${type})`
53936
+ };
53937
+ if (!isSafeBundlePath(name) || !allow.has(name)) return {
53938
+ kind: "refused",
53939
+ detail: `entry "${name}" is not part of the declared bundle`
53940
+ };
53941
+ if (seen.has(name)) return {
53942
+ kind: "refused",
53943
+ detail: `entry "${name}" appears twice`
53944
+ };
53945
+ const written = await copyEntry(handle, position, size, path.join(destDir, name));
53946
+ if (written === null) return {
53947
+ kind: "refused",
53948
+ detail: `entry "${name}" is truncated`
53949
+ };
53950
+ seen.set(name, {
53951
+ path: name,
53952
+ bytes: size,
53953
+ sha256: written
53954
+ });
53955
+ position += padded;
53956
+ }
53957
+ return {
53958
+ kind: "extracted",
53959
+ files: [...seen.values()]
53960
+ };
53961
+ } finally {
53962
+ await handle.close();
53963
+ }
53964
+ }
53965
+ async function copyEntry(source, start, size, target) {
53966
+ await mkdir(path.dirname(target), { recursive: true });
53967
+ const out = await open(target, "w");
53968
+ const hash = createHash("sha256");
53969
+ const chunk = Buffer.alloc(Math.min(COPY_CHUNK, Math.max(size, 1)));
53970
+ try {
53971
+ let done = 0;
53972
+ while (done < size) {
53973
+ const want = Math.min(chunk.length, size - done);
53974
+ const { bytesRead } = await source.read(chunk, 0, want, start + done);
53975
+ if (bytesRead === 0) return null;
53976
+ const piece = chunk.subarray(0, bytesRead);
53977
+ hash.update(piece);
53978
+ await out.write(piece);
53979
+ done += bytesRead;
53980
+ }
53981
+ return hash.digest("hex");
53982
+ } finally {
53983
+ await out.close();
53984
+ }
53985
+ }
53986
+ //#endregion
53987
+ //#region src/bundle/bundle-import.ts
53988
+ /**
53989
+ * `custom-model-registry.importModelBundle` — a model whose files arrive as
53990
+ * ONE tar from another addon (D806; the training orchestrator is the first
53991
+ * caller).
53992
+ *
53993
+ * Model Studio's upload path takes one `.onnx`/`.tflite` at a time; a trained
53994
+ * detector is an ONNX, two OpenVINO IR pairs and a Core ML package, which is
53995
+ * a directory. So the bundle is taken whole over `ctx.peerBytes` (D613),
53996
+ * checked against its declared sha256 AND against every declared file, and
53997
+ * only then moved into the hub's FLAT modelsDir — the layout every model
53998
+ * download path already resolves (`<modelsDir>/<basename of the url>`).
53999
+ *
54000
+ * Nothing is half-imported: the files land in a staging directory first, the
54001
+ * registry row is written only after every file is in place, and a refusal
54002
+ * names its reason (`checksum-mismatch`, `bundle-mismatch`, `invalid-entry`,
54003
+ * `id-taken`, `transfer-failed`).
54004
+ */
54005
+ var LOCAL_SCHEME = "camstack-local://";
54006
+ var refuse = (reason, detail) => ({
54007
+ kind: "refused",
54008
+ reason,
54009
+ detail
54010
+ });
54011
+ /** The bundle paths one format occupies: main file + siblings, or the package members. */
54012
+ function formatBundlePaths(entry, format) {
54013
+ const fmt = entry.formats[format];
54014
+ if (fmt === void 0) return [];
54015
+ const prefix = `${LOCAL_SCHEME}${entry.id}/`;
54016
+ if (!fmt.url.startsWith(prefix)) return null;
54017
+ const main = fmt.url.slice(prefix.length);
54018
+ if (main === "" || main.includes("/")) return null;
54019
+ if (fmt.isDirectory === true) return (fmt.files ?? []).map((member) => `${main}/${member}`);
54020
+ return [main, ...fmt.files ?? []];
54021
+ }
54022
+ function presentFormats(entry) {
54023
+ return MODEL_FORMATS.filter((format) => entry.formats[format] !== void 0);
54024
+ }
54025
+ function entryPaths(entry) {
54026
+ const out = [];
54027
+ for (const format of presentFormats(entry)) {
54028
+ const paths = formatBundlePaths(entry, format);
54029
+ if (paths === null) return null;
54030
+ out.push(...paths);
54031
+ }
54032
+ return out;
54033
+ }
54034
+ function sameRevisions(a, b) {
54035
+ for (const format of MODEL_FORMATS) {
54036
+ const ra = a.formats[format];
54037
+ const rb = b.formats[format];
54038
+ if (ra === void 0 && rb === void 0) continue;
54039
+ if (ra?.revision === void 0 || ra.revision !== rb?.revision) return false;
54040
+ }
54041
+ return true;
54042
+ }
54043
+ async function sha256File(file) {
54044
+ const hash = createHash("sha256");
54045
+ for await (const chunk of createReadStream(file)) hash.update(chunk);
54046
+ return hash.digest("hex");
54047
+ }
54048
+ async function importModelBundle(input, deps) {
54049
+ const declared = new Map(input.files.map((f) => [f.path, f]));
54050
+ const covered = /* @__PURE__ */ new Set();
54051
+ for (const entry of input.entries) {
54052
+ const paths = entryPaths(entry);
54053
+ if (paths === null) return refuse("invalid-entry", `"${entry.id}": every format URL must be ${LOCAL_SCHEME}${entry.id}/<file>`);
54054
+ for (const p of paths) {
54055
+ if (!declared.has(p)) return refuse("bundle-mismatch", `"${entry.id}" names "${p}", which the bundle does not declare`);
54056
+ covered.add(p);
54057
+ }
54058
+ }
54059
+ const existing = new Map((await deps.listModels()).map((m) => [m.entry.id, m.entry]));
54060
+ const fresh = [];
54061
+ for (const entry of input.entries) {
54062
+ const prior = existing.get(entry.id);
54063
+ if (prior === void 0) fresh.push(entry);
54064
+ else if (!sameRevisions(prior, entry)) return refuse("id-taken", `"${entry.id}" is already registered with other files`);
54065
+ }
54066
+ if (fresh.length === 0) return {
54067
+ kind: "imported",
54068
+ modelIds: input.entries.map((e) => e.id),
54069
+ distributed: []
54070
+ };
54071
+ const work = path.join(deps.stagingDir, `bundle-${deps.newId()}`);
54072
+ await mkdir(work, { recursive: true });
54073
+ try {
54074
+ const opened = await deps.openTicket(input.bundle.ticket);
54075
+ if (opened.kind === "refused") return refuse("transfer-failed", `${opened.code}: ${opened.detail}`);
54076
+ const tarPath = path.join(work, "bundle.tar");
54077
+ const written = await opened.body.writeToFile(tarPath, { maxBytes: input.bundle.bytes });
54078
+ if (written.kind === "refused") return refuse("transfer-failed", `${written.code}: ${written.detail}`);
54079
+ if (written.bytes !== input.bundle.bytes || await sha256File(tarPath) !== input.bundle.sha256) return refuse("checksum-mismatch", "the bundle does not match its declared size and sha256");
54080
+ const unpacked = path.join(work, "files");
54081
+ const extracted = await extractBundleTar(tarPath, unpacked, new Set(declared.keys()));
54082
+ if (extracted.kind === "refused") return refuse("bundle-mismatch", extracted.detail);
54083
+ for (const file of input.files) {
54084
+ const got = extracted.files.find((f) => f.path === file.path);
54085
+ if (got === void 0) return refuse("bundle-mismatch", `"${file.path}" is missing from the bundle`);
54086
+ if (got.sha256 !== file.sha256 || got.bytes !== file.bytes) return refuse("checksum-mismatch", `"${file.path}" does not match its declared sha256`);
54087
+ }
54088
+ await mkdir(deps.modelsDir, { recursive: true });
54089
+ for (const entry of fresh) await placeEntry(entry, unpacked, deps);
54090
+ for (const entry of fresh) {
54091
+ await deps.upsert({
54092
+ stepId: input.stepId,
54093
+ entry
54094
+ });
54095
+ for (const format of presentFormats(entry)) {
54096
+ const bytes = (formatBundlePaths(entry, format) ?? []).reduce((sum, p) => sum + (declared.get(p)?.bytes ?? 0), 0);
54097
+ await deps.markHubAvailable(entry.id, format, bytes);
54098
+ }
54099
+ }
54100
+ const distributed = [];
54101
+ if (input.distribute) for (const entry of fresh) distributed.push(...await deps.distribute(entry.id));
54102
+ return {
54103
+ kind: "imported",
54104
+ modelIds: input.entries.map((e) => e.id),
54105
+ distributed
54106
+ };
54107
+ } finally {
54108
+ await rm(work, {
54109
+ recursive: true,
54110
+ force: true
54111
+ });
54112
+ }
54113
+ }
54114
+ async function placeEntry(entry, unpacked, deps) {
54115
+ for (const format of presentFormats(entry)) {
54116
+ const fmt = entry.formats[format];
54117
+ if (fmt === void 0) continue;
54118
+ const main = fmt.url.slice(`${LOCAL_SCHEME}${entry.id}/`.length);
54119
+ const names = fmt.isDirectory === true ? [main] : [main, ...fmt.files ?? []];
54120
+ for (const name of names) {
54121
+ const target = path.join(deps.modelsDir, name);
54122
+ await rm(target, {
54123
+ recursive: true,
54124
+ force: true
54125
+ });
54126
+ await moveInto(path.join(unpacked, name), target);
54127
+ }
54128
+ if (fmt.revision !== void 0) await writeFile(path.join(deps.modelsDir, `${main}.revision`), `${fmt.revision}\n`, "utf8");
54129
+ }
54130
+ }
54131
+ /** Rename, or copy-then-remove when staging and modelsDir sit on different filesystems. */
54132
+ async function moveInto(source, target) {
54133
+ try {
54134
+ await rename(source, target);
54135
+ } catch (err) {
54136
+ if (!(err instanceof Error && "code" in err && err.code === "EXDEV")) throw err;
54137
+ await cp(source, target, { recursive: true });
54138
+ await rm(source, {
54139
+ recursive: true,
54140
+ force: true
54141
+ });
54142
+ }
54143
+ }
54144
+ //#endregion
52330
54145
  //#region src/frigate/frigate-plus.ts
52331
54146
  /**
52332
54147
  * Frigate+ API client — the REAL api.frigate.video contract, verified against
@@ -53124,7 +54939,10 @@ var ModelStudioAddon = class ModelStudioAddon extends BaseAddon {
53124
54939
  }];
53125
54940
  if (isHub) providers.push({
53126
54941
  capability: customModelRegistryCapability,
53127
- provider: { listModels: async () => state.get() }
54942
+ provider: {
54943
+ listModels: async () => state.get(),
54944
+ importModelBundle: async (input) => this.importModelBundle_(input)
54945
+ }
53128
54946
  });
53129
54947
  return {
53130
54948
  providers,
@@ -53672,6 +55490,54 @@ var ModelStudioAddon = class ModelStudioAddon extends BaseAddon {
53672
55490
  } });
53673
55491
  return { conversions: ensured.conversions };
53674
55492
  }
55493
+ /** `custom-model-registry.importModelBundle` (D806); the body is `bundle/bundle-import.ts`. */
55494
+ async importModelBundle_(input) {
55495
+ const peerBytes = this.ctx.peerBytes;
55496
+ if (peerBytes === void 0) return {
55497
+ kind: "refused",
55498
+ reason: "transfer-failed",
55499
+ detail: "no peer-bytes facility in this process"
55500
+ };
55501
+ const modelsDir = await this.resolveModelsDir();
55502
+ const nodeId = this.ctx.kernel?.localNodeId ?? "hub";
55503
+ const result = await importModelBundle(input, {
55504
+ modelsDir,
55505
+ stagingDir: path.join(this.ctx.dataDir ?? os.tmpdir(), "model-bundles"),
55506
+ openTicket: (ticket) => peerBytes.open(ticket),
55507
+ listModels: async () => this.state_.get(),
55508
+ upsert: async (descriptor) => {
55509
+ await this.state_.update((prev) => upsertCustomModel(prev, descriptor, "operator"));
55510
+ },
55511
+ markHubAvailable: async (modelId, format, bytes) => {
55512
+ await this.availability_.update((prev) => upsertAvailability(prev, modelId, nodeId.split("/")[0] ?? "hub", {
55513
+ format,
55514
+ sha256: "",
55515
+ bytes,
55516
+ at: Date.now()
55517
+ }));
55518
+ },
55519
+ distribute: async (modelId) => {
55520
+ return (await this.ensureFormatsThenDistribute_(modelId)).distributed.map((d) => ({
55521
+ modelId,
55522
+ nodeId: d.nodeId,
55523
+ format: d.format,
55524
+ ok: d.ok,
55525
+ ...d.error !== void 0 ? { error: d.error } : {}
55526
+ }));
55527
+ },
55528
+ newId: () => crypto$1.randomUUID()
55529
+ });
55530
+ if (result.kind === "refused") this.ctx.logger.warn("Model bundle import refused", { meta: {
55531
+ reason: result.reason,
55532
+ detail: result.detail,
55533
+ modelIds: input.entries.map((e) => e.id)
55534
+ } });
55535
+ else this.ctx.logger.info("Model bundle imported", { meta: {
55536
+ modelIds: [...result.modelIds],
55537
+ distributed: result.distributed.length
55538
+ } });
55539
+ return result;
55540
+ }
53675
55541
  async ensureFormatsThenDistribute_(modelId) {
53676
55542
  const api = this.ctx.api;
53677
55543
  if (!api) throw new Error("ensureFormatsThenDistribute: ctx.api unavailable");