@camstack/addon-osd-manager 0.1.193 → 0.1.194

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 (19) hide show
  1. package/dist/{MotionZonesSettings-DA6kMhDo.mjs → MotionZonesSettings-DUltQQw1.mjs} +2 -2
  2. package/dist/{PrivacyMaskSettings-yu64qorr.mjs → PrivacyMaskSettings-xC6YrNM-.mjs} +4 -4
  3. package/dist/{SceneMonitorEditor-BDPE-kLF.mjs → SceneMonitorEditor-DKN2cL7k.mjs} +3 -3
  4. package/dist/_stub.js +13 -13
  5. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_osd_manager_page-CoX8JVLh.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_osd_manager_page-CQQfH2Z7.mjs} +4 -4
  6. package/dist/{_virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_sdk__loadShare__.js-B_4MkXHU.mjs → _virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_sdk__loadShare__.js-BdjiJb9r.mjs} +1 -1
  7. package/dist/_virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-CGoq0DWk.mjs +26 -0
  8. package/dist/{hostInit-DhwSWrE7.mjs → hostInit-B-V1SPAc.mjs} +3 -3
  9. package/dist/index.js +1759 -147
  10. package/dist/index.mjs +1759 -147
  11. package/dist/{player-overlays-yo3byY33.mjs → player-overlays-TxRsHixk.mjs} +1 -1
  12. package/dist/remoteEntry.js +1 -1
  13. package/dist/{responsive-DManlL_B.mjs → responsive-t3UayeQT.mjs} +1 -1
  14. package/dist/{scene-monitor-copy-D3DDVyfO.mjs → scene-monitor-copy-gMmaT-FC.mjs} +1 -1
  15. package/dist/{square-Cez2ojTo.mjs → square-B_CvlH_T.mjs} +1 -1
  16. package/dist/{trash-2-Dfdmc9go.mjs → trash-2-BfeGf6tH.mjs} +1 -1
  17. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_osd_manager_page__remoteEntry_js-CEE9ag27.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_osd_manager_page__remoteEntry_js-DledZN7I.mjs} +1 -1
  18. package/package.json +1 -1
  19. package/dist/_virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-Bn-J0B4D.mjs +0 -26
package/dist/index.mjs CHANGED
@@ -5376,7 +5376,7 @@ var ZodIssueCode = {
5376
5376
  var ZodFirstPartyTypeKind;
5377
5377
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5378
5378
  //#endregion
5379
- //#region ../types/dist/sleep-DujUvOcb.mjs
5379
+ //#region ../types/dist/sleep-r3RWkGVx.mjs
5380
5380
  /**
5381
5381
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5382
5382
  * window to float samples (D455).
@@ -5493,7 +5493,7 @@ function isKeychainStoredField(field) {
5493
5493
  var SECRET_CLEAR = { $secretClear: true };
5494
5494
  /** The `'***'` token D634 redaction writes for non-admins. */
5495
5495
  var LEGACY_DEVICE_REDACTION = "***";
5496
- function isRecord$1(value) {
5496
+ function isRecord$2(value) {
5497
5497
  return typeof value === "object" && value !== null && !Array.isArray(value);
5498
5498
  }
5499
5499
  function makeSecretMarker(ref) {
@@ -5504,12 +5504,12 @@ function makeSecretMarker(ref) {
5504
5504
  }
5505
5505
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5506
5506
  function isSecretMarker(value) {
5507
- if (!isRecord$1(value)) return false;
5507
+ if (!isRecord$2(value)) return false;
5508
5508
  const ref = value["$secret"];
5509
5509
  return typeof ref === "string" && ref.length > 0;
5510
5510
  }
5511
5511
  function isSecretClear(value) {
5512
- return isRecord$1(value) && value["$secretClear"] === true;
5512
+ return isRecord$2(value) && value["$secretClear"] === true;
5513
5513
  }
5514
5514
  /**
5515
5515
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6025,6 +6025,13 @@ function globalSecretScope() {
6025
6025
  function encodeSegment(value) {
6026
6026
  return encodeURIComponent(value);
6027
6027
  }
6028
+ function decodeSegment(value) {
6029
+ try {
6030
+ return decodeURIComponent(value);
6031
+ } catch {
6032
+ return null;
6033
+ }
6034
+ }
6028
6035
  /**
6029
6036
  * The field path of a value inside an array item, addressed by the item's id:
6030
6037
  * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
@@ -6033,6 +6040,75 @@ function encodeSegment(value) {
6033
6040
  function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6034
6041
  return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6035
6042
  }
6043
+ function parseScope(segments) {
6044
+ switch (segments[0]) {
6045
+ case "global": return {
6046
+ scope: GLOBAL_SCOPE,
6047
+ used: 1
6048
+ };
6049
+ case "node": {
6050
+ const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6051
+ return nodeId === null || nodeId.length === 0 ? null : {
6052
+ scope: {
6053
+ kind: "node",
6054
+ nodeId
6055
+ },
6056
+ used: 2
6057
+ };
6058
+ }
6059
+ case "device": {
6060
+ const raw = segments[1];
6061
+ if (raw === void 0 || !/^\d+$/.test(raw)) return null;
6062
+ return {
6063
+ scope: {
6064
+ kind: "device",
6065
+ deviceId: Number(raw)
6066
+ },
6067
+ used: 2
6068
+ };
6069
+ }
6070
+ case "integration": {
6071
+ const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6072
+ return id === null || id.length === 0 ? null : {
6073
+ scope: {
6074
+ kind: "integration",
6075
+ integrationId: id
6076
+ },
6077
+ used: 2
6078
+ };
6079
+ }
6080
+ case "row": {
6081
+ const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6082
+ const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
6083
+ if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
6084
+ return {
6085
+ scope: {
6086
+ kind: "row",
6087
+ collection,
6088
+ rowId
6089
+ },
6090
+ used: 3
6091
+ };
6092
+ }
6093
+ default: return null;
6094
+ }
6095
+ }
6096
+ /** Take a ref apart; `null` when it is not a well-formed ref. */
6097
+ function parseSecretRef(ref) {
6098
+ if (!ref.startsWith("secret://")) return null;
6099
+ const segments = ref.slice(9).split("/");
6100
+ const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
6101
+ if (owner === null || owner.length === 0) return null;
6102
+ const parsed = parseScope(segments.slice(1));
6103
+ if (parsed === null) return null;
6104
+ const fieldPath = segments.slice(1 + parsed.used).join("/");
6105
+ if (fieldPath.length === 0) return null;
6106
+ return {
6107
+ owner,
6108
+ scope: parsed.scope,
6109
+ fieldPath
6110
+ };
6111
+ }
6036
6112
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6037
6113
  var KeychainWriteRefusedError = class extends Error {
6038
6114
  fieldPath;
@@ -6043,7 +6119,7 @@ var KeychainWriteRefusedError = class extends Error {
6043
6119
  }
6044
6120
  };
6045
6121
  var KEEP = { kind: "keep" };
6046
- function isRecord(value) {
6122
+ function isRecord$1(value) {
6047
6123
  return typeof value === "object" && value !== null && !Array.isArray(value);
6048
6124
  }
6049
6125
  function defaultMintId() {
@@ -6056,7 +6132,7 @@ function collectSecretMarkerRefs(value, out = []) {
6056
6132
  return out;
6057
6133
  }
6058
6134
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6059
- else if (isRecord(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6135
+ else if (isRecord$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6060
6136
  return out;
6061
6137
  }
6062
6138
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6111,7 +6187,7 @@ function rowId(row, idKey) {
6111
6187
  return null;
6112
6188
  }
6113
6189
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6114
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord) : [];
6190
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1) : [];
6115
6191
  if (!Array.isArray(incoming)) {
6116
6192
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6117
6193
  return {
@@ -6127,7 +6203,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6127
6203
  const kept = /* @__PURE__ */ new Set();
6128
6204
  const rows = [];
6129
6205
  for (const row of incoming) {
6130
- if (!isRecord(row)) {
6206
+ if (!isRecord$1(row)) {
6131
6207
  rows.push(row);
6132
6208
  continue;
6133
6209
  }
@@ -6152,7 +6228,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6152
6228
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6153
6229
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6154
6230
  case "object": {
6155
- if (!isRecord(incoming)) {
6231
+ if (!isRecord$1(incoming)) {
6156
6232
  if (incoming === void 0) return KEEP;
6157
6233
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6158
6234
  return {
@@ -6160,7 +6236,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6160
6236
  value: incoming
6161
6237
  };
6162
6238
  }
6163
- const storedObj = isRecord(stored) ? stored : {};
6239
+ const storedObj = isRecord$1(stored) ? stored : {};
6164
6240
  return {
6165
6241
  kind: "value",
6166
6242
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6219,12 +6295,19 @@ async function transformSecretWrite(input) {
6219
6295
  }
6220
6296
  };
6221
6297
  }
6298
+ /** Is `ref` one of `owner`'s refs? */
6299
+ function isSecretRefOwnedBy(ref, owner) {
6300
+ return parseSecretRef(ref)?.owner === owner;
6301
+ }
6222
6302
  /**
6223
6303
  * Replace every marker in `value` with its keychain value. Returns the SAME
6224
6304
  * reference when there is no marker (no allocation, no keychain call).
6225
6305
  */
6226
- async function resolveSecretMarkers(value, secrets) {
6227
- const refs = collectSecretMarkerRefs(value);
6306
+ async function resolveSecretMarkers(value, secrets, options = {}) {
6307
+ const keepMarker = options.unresolved === "keep-marker";
6308
+ const owner = options.ownedBy;
6309
+ const inScope = (ref) => owner === void 0 || isSecretRefOwnedBy(ref, owner);
6310
+ const refs = collectSecretMarkerRefs(value).filter(inScope);
6228
6311
  if (refs.length === 0) return {
6229
6312
  value,
6230
6313
  unresolved: []
@@ -6248,10 +6331,18 @@ async function resolveSecretMarkers(value, secrets) {
6248
6331
  }
6249
6332
  const substitute = (v) => {
6250
6333
  if (isSecretMarker(v)) {
6334
+ if (!inScope(v.$secret)) return {
6335
+ keep: true,
6336
+ value: v
6337
+ };
6251
6338
  const answer = answers[v.$secret];
6252
- return answer?.kind === "value" ? {
6339
+ if (answer?.kind === "value") return {
6253
6340
  keep: true,
6254
6341
  value: answer.value
6342
+ };
6343
+ return keepMarker ? {
6344
+ keep: true,
6345
+ value: v
6255
6346
  } : {
6256
6347
  keep: false,
6257
6348
  value: void 0
@@ -6268,7 +6359,7 @@ async function resolveSecretMarkers(value, secrets) {
6268
6359
  value: items
6269
6360
  };
6270
6361
  }
6271
- if (isRecord(v)) {
6362
+ if (isRecord$1(v)) {
6272
6363
  const out = {};
6273
6364
  for (const [k, child] of Object.entries(v)) {
6274
6365
  const s = substitute(child);
@@ -6289,14 +6380,152 @@ async function resolveSecretMarkers(value, secrets) {
6289
6380
  unresolved
6290
6381
  };
6291
6382
  }
6292
- function touchesTree(tree, patch) {
6293
- if (tree.size === 0) return false;
6294
- for (const key of Object.keys(patch)) {
6295
- const at = key.indexOf("@");
6296
- if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6383
+ /** An addon tried to replace a stored secret it could not read. Nothing was written. */
6384
+ var SecretOverwriteRefusedError = class extends Error {
6385
+ ref;
6386
+ reason;
6387
+ constructor(ref, reason) {
6388
+ 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.`);
6389
+ this.ref = ref;
6390
+ this.reason = reason;
6391
+ this.name = "SecretOverwriteRefusedError";
6392
+ }
6393
+ };
6394
+ function isRecord(value) {
6395
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6396
+ }
6397
+ function resolvedValue(pass, marker) {
6398
+ const answer = pass.answers[marker.$secret];
6399
+ return answer?.kind === "value" ? answer.value : null;
6400
+ }
6401
+ async function atMarker(pass, incoming, stored) {
6402
+ if (incoming === null) return stored;
6403
+ if (typeof incoming !== "string") return incoming;
6404
+ if (incoming === resolvedValue(pass, stored)) return stored;
6405
+ const intent = classifySecretWrite(incoming);
6406
+ if (intent.kind !== "set") return stored;
6407
+ const ref = stored.$secret;
6408
+ if (!isSecretRefOwnedBy(ref, pass.secrets.owner)) return incoming;
6409
+ const answer = pass.answers[ref];
6410
+ 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);
6411
+ try {
6412
+ await pass.secrets.put(ref, intent.value);
6413
+ } catch (err) {
6414
+ throw new KeychainWriteRefusedError(ref, err);
6415
+ }
6416
+ pass.changedRefs.push(ref);
6417
+ return stored;
6418
+ }
6419
+ function inArray(pass, incoming, stored) {
6420
+ return incoming.map((item, index) => {
6421
+ const twin = stored[index];
6422
+ if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6423
+ if (isRecord(item) && isRecord(twin)) return inArrayRow(pass, item, twin);
6424
+ if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6425
+ return item;
6426
+ });
6427
+ }
6428
+ function inArrayRow(pass, incoming, stored) {
6429
+ const out = { ...incoming };
6430
+ for (const [key, value] of Object.entries(incoming)) {
6431
+ const twin = stored[key];
6432
+ if (isSecretMarker(twin)) {
6433
+ if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6434
+ } else if (isRecord(value) && isRecord(twin)) out[key] = inArrayRow(pass, value, twin);
6435
+ else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6436
+ }
6437
+ return out;
6438
+ }
6439
+ async function walk$1(pass, incoming, stored) {
6440
+ if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6441
+ if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6442
+ if (!isRecord(incoming) || !isRecord(stored)) return incoming;
6443
+ const out = { ...incoming };
6444
+ for (const [key, value] of Object.entries(incoming)) out[key] = await walk$1(pass, value, stored[key]);
6445
+ return out;
6446
+ }
6447
+ /** Restore markers a write-back carries as values. See the file doc. */
6448
+ async function restoreUnchangedSecrets(input) {
6449
+ const refs = [];
6450
+ for (const key of Object.keys(input.patch)) collectSecretMarkerRefs(input.stored[key], refs);
6451
+ const owned = refs.filter((ref) => isSecretRefOwnedBy(ref, input.secrets.owner));
6452
+ if (owned.length === 0) return {
6453
+ patch: input.patch,
6454
+ changedRefs: []
6455
+ };
6456
+ const pass = {
6457
+ secrets: input.secrets,
6458
+ answers: await input.secrets.resolve([...new Set(owned)]),
6459
+ operatorWrite: input.operatorWrite,
6460
+ changedRefs: []
6461
+ };
6462
+ const out = {};
6463
+ for (const [key, value] of Object.entries(input.patch)) out[key] = await walk$1(pass, value, input.stored[key]);
6464
+ return {
6465
+ patch: out,
6466
+ changedRefs: pass.changedRefs
6467
+ };
6468
+ }
6469
+ /** Structural equality over JSON-shaped values (key order does not matter). */
6470
+ function isJsonEqual(a, b) {
6471
+ if (Object.is(a, b)) return true;
6472
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6473
+ if (isRecord(a) && isRecord(b)) {
6474
+ const keys = Object.keys(a);
6475
+ if (keys.length !== Object.keys(b).length) return false;
6476
+ return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
6297
6477
  }
6298
6478
  return false;
6299
6479
  }
6480
+ /** The patch without the keys whose value already equals the stored one. */
6481
+ function dropUnchangedKeys(patch, stored) {
6482
+ const out = {};
6483
+ for (const [key, value] of Object.entries(patch)) {
6484
+ if (Object.prototype.hasOwnProperty.call(stored, key) && isJsonEqual(value, stored[key])) continue;
6485
+ out[key] = value;
6486
+ }
6487
+ return out;
6488
+ }
6489
+ /** The top-level keys of a blob that hold at least one of `owner`'s markers. */
6490
+ function markerKeysOf(blob, owner) {
6491
+ const keys = /* @__PURE__ */ new Set();
6492
+ for (const [key, value] of Object.entries(blob)) if (collectSecretMarkerRefs(value).some((ref) => isSecretRefOwnedBy(ref, owner))) keys.add(key);
6493
+ return keys;
6494
+ }
6495
+ function nodeFromStored(value, owner) {
6496
+ if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6497
+ if (!isRecord(value)) return null;
6498
+ const children = /* @__PURE__ */ new Map();
6499
+ for (const [key, child] of Object.entries(value)) {
6500
+ const node = nodeFromStored(child, owner);
6501
+ if (node !== null) children.set(key, node);
6502
+ }
6503
+ return children.size > 0 ? {
6504
+ kind: "object",
6505
+ children
6506
+ } : null;
6507
+ }
6508
+ /**
6509
+ * The declared secret tree, widened by every place the STORED blob holds a
6510
+ * marker under one of `keys` — so a marker the schema no longer declares (or
6511
+ * never declared: Wyze before b4906cec6) still gets the save path's
6512
+ * KEEP / SET / CLEAR semantics instead of being overwritten by whatever the
6513
+ * addon writes. Markers inside arrays are not added: a row has no id field to
6514
+ * match by unless the schema declares one. Only `owner`'s markers count: a
6515
+ * builtin that keeps another addon's marker (device-manager) never takes it
6516
+ * over.
6517
+ */
6518
+ function widenTreeWithStoredMarkers(declared, stored, keys, owner) {
6519
+ const added = /* @__PURE__ */ new Map();
6520
+ for (const key of keys) {
6521
+ const at = key.indexOf("@");
6522
+ const base = at > 0 ? key.slice(0, at) : key;
6523
+ if (declared.has(base) || added.has(base)) continue;
6524
+ const node = nodeFromStored(stored[key], owner);
6525
+ if (node !== null) added.set(base, node);
6526
+ }
6527
+ return added.size === 0 ? declared : new Map([...declared, ...added]);
6528
+ }
6300
6529
  /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6301
6530
  async function readStoredAddonBlob(raw) {
6302
6531
  const threeWay = raw.readAddonStoreResult;
@@ -6305,7 +6534,41 @@ async function readStoredAddonBlob(raw) {
6305
6534
  if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6306
6535
  return result.kind === "missing" ? {} : result.value;
6307
6536
  }
6308
- function createSecretAwareSettings(raw, opts) {
6537
+ function touchesTree(tree, patch) {
6538
+ if (tree.size === 0) return false;
6539
+ for (const key of Object.keys(patch)) {
6540
+ const at = key.indexOf("@");
6541
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6542
+ }
6543
+ return false;
6544
+ }
6545
+ /**
6546
+ * Which top-level keys of each store held markers when last seen. `undefined`
6547
+ * for a store not seen yet: its first write reads it, to be safe.
6548
+ */
6549
+ var MarkerKeyIndex = class {
6550
+ owner;
6551
+ byStore = /* @__PURE__ */ new Map();
6552
+ constructor(owner) {
6553
+ this.owner = owner;
6554
+ }
6555
+ seen(store, blob) {
6556
+ this.byStore.set(store, markerKeysOf(blob, this.owner));
6557
+ }
6558
+ wrote(store, patch) {
6559
+ const keys = this.byStore.get(store);
6560
+ if (keys === void 0) return;
6561
+ const now = markerKeysOf(patch, this.owner);
6562
+ for (const key of Object.keys(patch)) if (now.has(key)) keys.add(key);
6563
+ else keys.delete(key);
6564
+ }
6565
+ mayHoldMarkers(store, patch) {
6566
+ const keys = this.byStore.get(store);
6567
+ if (keys === void 0) return true;
6568
+ return Object.keys(patch).some((key) => keys.has(key));
6569
+ }
6570
+ };
6571
+ function createHandle(raw, opts) {
6309
6572
  const chains = /* @__PURE__ */ new Map();
6310
6573
  const serialize = (key, fn) => {
6311
6574
  const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
@@ -6316,46 +6579,130 @@ function createSecretAwareSettings(raw, opts) {
6316
6579
  });
6317
6580
  return next;
6318
6581
  };
6319
- const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6320
- if (!touchesTree(tree, patch)) return rawWrite(patch);
6321
- return serialize(chainKey, async () => {
6582
+ const index = new MarkerKeyIndex(opts.secrets.owner);
6583
+ const resolveRead = async (store, blob) => {
6584
+ index.seen(store, blob);
6585
+ const { value, unresolved } = await resolveSecretMarkers(blob, opts.secrets, {
6586
+ unresolved: "keep-marker",
6587
+ ownedBy: opts.secrets.owner
6588
+ });
6589
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6590
+ return value;
6591
+ };
6592
+ const write = async (store, declared, scope, patch, readStored, rawWrite) => {
6593
+ if (!touchesTree(declared, patch) && !index.mayHoldMarkers(store, patch)) {
6594
+ await rawWrite(patch);
6595
+ index.wrote(store, patch);
6596
+ return { changed: true };
6597
+ }
6598
+ return serialize(store, async () => {
6322
6599
  const stored = await readStored();
6600
+ index.seen(store, stored);
6601
+ const operatorWrite = opts.isOperatorWrite?.() === true;
6602
+ const restored = await restoreUnchangedSecrets({
6603
+ patch,
6604
+ stored,
6605
+ secrets: opts.secrets,
6606
+ operatorWrite
6607
+ });
6323
6608
  const result = await transformSecretWrite({
6324
- tree,
6609
+ tree: widenTreeWithStoredMarkers(declared, stored, Object.keys(restored.patch), opts.secrets.owner),
6325
6610
  secrets: opts.secrets,
6326
- patch,
6611
+ patch: restored.patch,
6327
6612
  stored,
6328
6613
  ...scope !== void 0 ? { scope } : {},
6329
- operatorWrite: opts.isOperatorWrite?.() === true
6614
+ operatorWrite
6330
6615
  });
6331
- if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6616
+ const effective = dropUnchangedKeys(result.patch, stored);
6617
+ const wroteBlob = Object.keys(effective).length > 0;
6618
+ if (wroteBlob) {
6619
+ await rawWrite(effective);
6620
+ index.wrote(store, effective);
6621
+ }
6332
6622
  const { orphaned } = await result.afterWrite();
6333
6623
  if (orphaned.length > 0) opts.onOrphaned(orphaned);
6624
+ return { changed: wroteBlob || restored.changedRefs.length > 0 };
6334
6625
  });
6335
6626
  };
6336
- const wrapped = {
6337
- writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6338
- writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6339
- kind: "device",
6340
- deviceId
6341
- }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6627
+ const writeAddon = (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p));
6628
+ const readAddonStoreResult = raw.readAddonStoreResult;
6629
+ const readAddonStoreKeyResult = raw.readAddonStoreKeyResult;
6630
+ const readDeviceStoreBatch = raw.readDeviceStoreBatch;
6631
+ const overrides = {
6632
+ readAddonStore: async () => resolveRead("addon", await raw.readAddonStore()),
6633
+ ...readAddonStoreResult !== void 0 ? { readAddonStoreResult: async () => {
6634
+ const result = await readAddonStoreResult.call(raw);
6635
+ return result.kind === "value" ? {
6636
+ kind: "value",
6637
+ value: await resolveRead("addon", result.value)
6638
+ } : result;
6639
+ } } : {},
6640
+ ...readAddonStoreKeyResult !== void 0 ? { readAddonStoreKeyResult: async (key) => {
6641
+ const result = await readAddonStoreKeyResult.call(raw, key);
6642
+ if (result.kind !== "present") return result;
6643
+ const { value, unresolved } = await resolveSecretMarkers({ [key]: result.value }, opts.secrets, {
6644
+ unresolved: "keep-marker",
6645
+ ownedBy: opts.secrets.owner
6646
+ });
6647
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6648
+ return {
6649
+ kind: "present",
6650
+ value: value[key]
6651
+ };
6652
+ } } : {},
6653
+ readDeviceStore: async (deviceId) => resolveRead(`device:${deviceId}`, await raw.readDeviceStore(deviceId)),
6654
+ ...readDeviceStoreBatch !== void 0 ? { readDeviceStoreBatch: async (deviceIds) => {
6655
+ const rows = await readDeviceStoreBatch.call(raw, deviceIds);
6656
+ const out = /* @__PURE__ */ new Map();
6657
+ for (const [deviceId, blob] of rows) out.set(deviceId, await resolveRead(`device:${deviceId}`, blob));
6658
+ return out;
6659
+ } } : {},
6660
+ writeAddonStore: async (patch) => {
6661
+ await writeAddon(patch);
6662
+ },
6663
+ writeDeviceStore: async (deviceId, patch) => {
6664
+ await write(`device:${deviceId}`, opts.deviceTree(), {
6665
+ kind: "device",
6666
+ deviceId
6667
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p));
6668
+ }
6669
+ };
6670
+ return {
6671
+ settings: new Proxy(raw, { get(target, prop, receiver) {
6672
+ if (typeof prop === "string" && Object.prototype.hasOwnProperty.call(overrides, prop)) return Reflect.get(overrides, prop);
6673
+ const value = Reflect.get(target, prop, receiver);
6674
+ return typeof value === "function" ? value.bind(target) : value;
6675
+ } }),
6676
+ raw: {
6677
+ readAddonStore: async () => {
6678
+ const blob = await raw.readAddonStore();
6679
+ index.seen("addon", blob);
6680
+ return blob;
6681
+ },
6682
+ readDeviceStore: async (deviceId) => {
6683
+ const blob = await raw.readDeviceStore(deviceId);
6684
+ index.seen(`device:${deviceId}`, blob);
6685
+ return blob;
6686
+ }
6687
+ },
6688
+ writeAddonStore: writeAddon
6342
6689
  };
6343
- return new Proxy(raw, { get(target, prop, receiver) {
6344
- if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6345
- if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6346
- const value = Reflect.get(target, prop, receiver);
6347
- return typeof value === "function" ? value.bind(target) : value;
6348
- } });
6349
6690
  }
6350
- /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6351
- function withSecretAwareSettings(context, opts) {
6691
+ /** The context the addon sees, plus the private raw view and write outcome. */
6692
+ function createSecretAwareContext(context, opts) {
6352
6693
  const raw = context.settings;
6353
- if (raw === void 0) return context;
6354
- const settings = createSecretAwareSettings(raw, opts);
6355
- return new Proxy(context, { get(target, prop, receiver) {
6356
- if (prop === "settings") return settings;
6357
- return Reflect.get(target, prop, receiver);
6358
- } });
6694
+ if (raw === void 0) return {
6695
+ context,
6696
+ handle: null
6697
+ };
6698
+ const handle = createHandle(raw, opts);
6699
+ return {
6700
+ context: new Proxy(context, { get(target, prop, receiver) {
6701
+ if (prop === "settings") return handle.settings;
6702
+ return Reflect.get(target, prop, receiver);
6703
+ } }),
6704
+ handle
6705
+ };
6359
6706
  }
6360
6707
  var LEAF = { kind: "leaf" };
6361
6708
  var DEFAULT_ITEM_ID_KEY = "id";
@@ -6530,6 +6877,14 @@ var BaseAddon = class {
6530
6877
  _secretChangeUnsub = null;
6531
6878
  /** >0 while an OPERATOR's settings write is being applied. */
6532
6879
  _operatorWriteDepth = 0;
6880
+ /**
6881
+ * The keychain-aware settings handle (D798). Its `raw` view is the ONLY way
6882
+ * to the marker-bearing blobs and stays private to this class: the form
6883
+ * hydrate and config resolution need markers, addon code never does.
6884
+ */
6885
+ _secretSettings = null;
6886
+ /** Refs an addon-facing read could not resolve — each is logged once per process. */
6887
+ _loggedUnresolvedReads = /* @__PURE__ */ new Set();
6533
6888
  constructor(defaults) {
6534
6889
  this.defaults = defaults;
6535
6890
  this._config = { ...defaults };
@@ -6566,13 +6921,21 @@ var BaseAddon = class {
6566
6921
  }
6567
6922
  async initialize(context) {
6568
6923
  const secrets = context.secrets;
6569
- this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6570
- secrets,
6571
- addonTree: () => this.addonSecretTree(),
6572
- deviceTree: () => this.deviceSecretTree(),
6573
- onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6574
- isOperatorWrite: () => this._operatorWriteDepth > 0
6575
- }) : context;
6924
+ if (secrets !== void 0) {
6925
+ const { context: wrapped, handle } = createSecretAwareContext(context, {
6926
+ secrets,
6927
+ addonTree: () => this.addonSecretTree(),
6928
+ deviceTree: () => this.deviceSecretTree(),
6929
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6930
+ isOperatorWrite: () => this._operatorWriteDepth > 0,
6931
+ onUnresolved: (unresolved) => this.logUnresolvedRead(unresolved)
6932
+ });
6933
+ this._ctx = wrapped;
6934
+ this._secretSettings = handle;
6935
+ } else {
6936
+ this._ctx = context;
6937
+ this._secretSettings = null;
6938
+ }
6576
6939
  await this.resolveConfig();
6577
6940
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6578
6941
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -6689,11 +7052,8 @@ var BaseAddon = class {
6689
7052
  async getGlobalSettings(overlay, cap, nodeId) {
6690
7053
  const schema = this.globalSettingsSchema(cap);
6691
7054
  if (!schema) return { sections: [] };
6692
- const projected = await this.resolveGlobalStore(nodeId, cap);
6693
- return hydrateSchema(schema, overlay ? {
6694
- ...projected,
6695
- ...overlay
6696
- } : projected, { inlineSecretsAsViews: true });
7055
+ const projected = await this.readRawProjectedStore(nodeId, cap);
7056
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
6697
7057
  }
6698
7058
  /**
6699
7059
  * The integration-level view of this addon's settings: exactly the sections
@@ -6738,7 +7098,7 @@ var BaseAddon = class {
6738
7098
  });
6739
7099
  }
6740
7100
  if (sections.length === 0) return null;
6741
- const projected = await this.resolveGlobalStore(nodeId);
7101
+ const projected = await this.readRawProjectedStore(nodeId);
6742
7102
  return hydrateSchema({
6743
7103
  ...schema,
6744
7104
  sections
@@ -6755,12 +7115,50 @@ var BaseAddon = class {
6755
7115
  * the store for custom option logic (option narrowing, value snapping) to
6756
7116
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
6757
7117
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
7118
+ *
7119
+ * Keychain values come back RESOLVED (D798): a secret reads as its value,
7120
+ * never as a `{ $secret }` marker. One the keychain cannot serve right now
7121
+ * stays a marker — "stored, unavailable" (`isSecretMarker()` is true, and it
7122
+ * is listed in {@link unresolvedSecrets}) — never `''` and never absent, so
7123
+ * it cannot be mistaken for "nothing stored, mint a new one". Writing the
7124
+ * resolved blob back is a no-op for every unchanged secret.
6758
7125
  */
6759
7126
  async resolveGlobalStore(nodeId, cap) {
6760
7127
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
7128
+ return this.projectForNode(raw, nodeId, cap);
7129
+ }
7130
+ projectForNode(store, nodeId, cap) {
6761
7131
  const keys = this.perNodeKeys(cap);
6762
7132
  const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6763
- return keys.size > 0 ? projectStore(raw, keys, node) : raw;
7133
+ return keys.size > 0 ? projectStore(store, keys, node) : store;
7134
+ }
7135
+ /** The PROJECTED store with its markers — the form hydrate only (D798). */
7136
+ async readRawProjectedStore(nodeId, cap) {
7137
+ const raw = await this.rawSettings()?.readAddonStore() ?? {};
7138
+ return this.projectForNode(raw, nodeId, cap);
7139
+ }
7140
+ /**
7141
+ * `{ ...stored, ...overlay }`, except that an overlay member equal to the
7142
+ * RESOLVED stored one keeps the stored (marker-bearing) member — so a form
7143
+ * hydrated from a resolved overlay still shows a secret as "set", never as
7144
+ * its value.
7145
+ */
7146
+ async overlayKeepingMarkers(stored, overlay) {
7147
+ const secrets = this._ctx?.secrets;
7148
+ const merged = {
7149
+ ...stored,
7150
+ ...overlay
7151
+ };
7152
+ if (secrets === void 0 || collectSecretMarkerRefs(stored).length === 0) return merged;
7153
+ const { value: resolved } = await resolveSecretMarkers(stored, secrets, {
7154
+ unresolved: "keep-marker",
7155
+ ownedBy: secrets.owner
7156
+ });
7157
+ for (const key of Object.keys(overlay)) {
7158
+ if (collectSecretMarkerRefs(stored[key]).length === 0) continue;
7159
+ if (isJsonEqual(overlay[key], resolved[key])) merged[key] = stored[key];
7160
+ }
7161
+ return merged;
6764
7162
  }
6765
7163
  /**
6766
7164
  * Whether ONE global key of this addon's store was written, read three-way
@@ -6825,8 +7223,12 @@ var BaseAddon = class {
6825
7223
  async clearSecrets(keys, nodeId) {
6826
7224
  const tree = this.addonSecretTree();
6827
7225
  const keychain = this._ctx?.secrets !== void 0;
7226
+ const stored = keychain ? await this.readAddonStoreWithRetry() : {};
6828
7227
  const patch = {};
6829
- for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
7228
+ for (const key of keys) {
7229
+ const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
7230
+ patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
7231
+ }
6830
7232
  await this.applyGlobalPatch(patch, nodeId);
6831
7233
  }
6832
7234
  async applyGlobalPatch(barePatch, nodeId) {
@@ -6834,7 +7236,11 @@ var BaseAddon = class {
6834
7236
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6835
7237
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6836
7238
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6837
- await this._ctx?.settings?.writeAddonStore(scoped);
7239
+ const handle = this._secretSettings;
7240
+ if (handle !== null) {
7241
+ const { changed } = await handle.writeAddonStore(scoped);
7242
+ if (!changed) return;
7243
+ } else await this._ctx?.settings?.writeAddonStore(scoped);
6838
7244
  if (target !== localNode) return;
6839
7245
  await this.resolveConfig();
6840
7246
  await this.onConfigChanged();
@@ -6887,7 +7293,7 @@ var BaseAddon = class {
6887
7293
  async getDeviceSettings(deviceId) {
6888
7294
  const schema = this.deviceSettingsSchema();
6889
7295
  if (!schema) return { sections: [] };
6890
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7296
+ return hydrateSchema(schema, await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6891
7297
  }
6892
7298
  async updateDeviceSettings(deviceId, patch) {
6893
7299
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -7059,7 +7465,7 @@ var BaseAddon = class {
7059
7465
  key,
7060
7466
  schema,
7061
7467
  fallback,
7062
- read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
7468
+ read: async () => this.resolveStoredSecrets(await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, false),
7063
7469
  write: async (patch) => {
7064
7470
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
7065
7471
  },
@@ -7121,6 +7527,23 @@ var BaseAddon = class {
7121
7527
  }
7122
7528
  return value;
7123
7529
  }
7530
+ /**
7531
+ * The marker-bearing settings reads (D798) — private on purpose. Without a
7532
+ * keychain the context's own view is already raw.
7533
+ */
7534
+ rawSettings() {
7535
+ return this._secretSettings?.raw ?? this._ctx?.settings;
7536
+ }
7537
+ /** An addon-facing read met markers it could not resolve: say so once per ref. */
7538
+ logUnresolvedRead(unresolved) {
7539
+ const fresh = unresolved.filter((u) => !this._loggedUnresolvedReads.has(u.ref));
7540
+ if (fresh.length === 0) return;
7541
+ for (const u of fresh) this._loggedUnresolvedReads.add(u.ref);
7542
+ 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) => ({
7543
+ ref: u.ref,
7544
+ reason: u.reason
7545
+ })) } });
7546
+ }
7124
7547
  /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7125
7548
  scheduleSecretReresolve(delayMs) {
7126
7549
  const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
@@ -7147,7 +7570,7 @@ var BaseAddon = class {
7147
7570
  * `{}` (defaults) — the addon's first successful patch will rehydrate.
7148
7571
  */
7149
7572
  async readAddonStoreWithRetry() {
7150
- const settings = this._ctx?.settings;
7573
+ const settings = this.rawSettings();
7151
7574
  if (!settings) return {};
7152
7575
  const delaysMs = [
7153
7576
  150,
@@ -9485,6 +9908,278 @@ var CameraSwitchGroupSchema = object({
9485
9908
  fetchedAt: number()
9486
9909
  });
9487
9910
  /**
9911
+ * The trainer contract — what the hub hands the cloud trainer and what it
9912
+ * gets back (cloud training, D805+).
9913
+ *
9914
+ * The trainer (`hf/camstack-trainer`, published as the Hugging Face repo
9915
+ * `camstack/camstack-trainer`) is a separate AGPL program the hub never
9916
+ * imports: `job.json` goes in, files come out, and progress is `CAMSTACK_EVENT`
9917
+ * lines on stdout. These schemas are the hub's half of that boundary; the
9918
+ * trainer's pydantic models (and the JSON Schemas generated from them under
9919
+ * `hf/camstack-trainer/schemas/`) are the other half. A change here is a
9920
+ * change there, in the same piece of work.
9921
+ *
9922
+ * No `.default()` anywhere: defaults do not run on the addon cap path, so the
9923
+ * orchestrator fills every field of a job spec explicitly.
9924
+ */
9925
+ var TRAINING_JOB_SCHEMA = "camstack.training/v1";
9926
+ var TRAINING_RESULT_SCHEMA = "camstack.training-result/v1";
9927
+ /** What the trainer can export. Edge TPU is a later, separate image. */
9928
+ var TrainingExportSchema = _enum([
9929
+ "onnx",
9930
+ "openvino-fp16",
9931
+ "openvino-int8",
9932
+ "coreml-fp16"
9933
+ ]);
9934
+ var FloorsSchema = record(string(), number().min(0).max(1));
9935
+ object({
9936
+ schema: literal(TRAINING_JOB_SCHEMA),
9937
+ jobKey: string().uuid(),
9938
+ target: object({
9939
+ kind: literal("detector"),
9940
+ step: literal("object-detection")
9941
+ }),
9942
+ base: object({
9943
+ modelId: string().min(1),
9944
+ /** Ultralytics weights id, e.g. `yolov9m.pt`. */
9945
+ weights: string().min(1),
9946
+ imgsz: number().int().positive()
9947
+ }),
9948
+ baseline: object({
9949
+ modelId: string().min(1),
9950
+ /** The baseline ONNX the holdout comparison runs; public mirror URL. */
9951
+ onnxUrl: string().url(),
9952
+ imgsz: number().int().positive(),
9953
+ floors: FloorsSchema
9954
+ }),
9955
+ dataset: object({
9956
+ versionId: string().min(1),
9957
+ annotationHash: string(),
9958
+ /** sha256 of the uploaded archive; the trainer refuses a mismatch (exit 65). */
9959
+ sha256: string().regex(/^[0-9a-f]{64}$/)
9960
+ }),
9961
+ split: object({
9962
+ holdoutCameras: array(number().int()),
9963
+ /** When no camera is held out: the last N days of every camera. */
9964
+ holdoutLastDays: number().int().nonnegative(),
9965
+ valFraction: number().min(0).max(.5),
9966
+ seed: number().int()
9967
+ }),
9968
+ hyper: object({
9969
+ epochs: number().int().positive(),
9970
+ batch: number().int().positive(),
9971
+ lr0: number().positive(),
9972
+ /** Layers frozen from the start of the backbone; 0 = none. */
9973
+ freeze: number().int().nonnegative(),
9974
+ patience: number().int().nonnegative(),
9975
+ seed: number().int()
9976
+ }),
9977
+ replay: object({
9978
+ source: literal("coco2017"),
9979
+ count: number().int().nonnegative()
9980
+ }),
9981
+ exports: array(TrainingExportSchema).min(1),
9982
+ calibration: object({ maxFrames: number().int().positive() }),
9983
+ floors: object({
9984
+ minSupport: number().int().positive(),
9985
+ clamp: number().min(0).max(1)
9986
+ }),
9987
+ int8Gate: object({ maxMap50Drop: number().min(0).max(1) }),
9988
+ catalog: object({
9989
+ id: string().regex(/^[a-z0-9][a-z0-9-]{2,80}$/),
9990
+ name: string().min(1).max(160)
9991
+ })
9992
+ });
9993
+ /** One regular file of the bundle. An mlpackage contributes one row per member. */
9994
+ var TrainingResultFileSchema = object({
9995
+ path: string().min(1),
9996
+ bytes: number().int().nonnegative(),
9997
+ sha256: string().regex(/^[0-9a-f]{64}$/),
9998
+ format: _enum([
9999
+ "onnx",
10000
+ "openvino",
10001
+ "coreml",
10002
+ "pt"
10003
+ ]),
10004
+ variant: _enum(["base", "int8"])
10005
+ });
10006
+ var DraftFormatSchema = object({
10007
+ /** RELATIVE path inside the bundle; the hub rewrites it to `camstack-local://`. */
10008
+ url: string().min(1),
10009
+ sizeMB: number().nonnegative(),
10010
+ isDirectory: boolean().optional(),
10011
+ files: array(string()).optional(),
10012
+ runtimes: array(literal("python")).optional(),
10013
+ revision: string().min(1)
10014
+ });
10015
+ /** The trainer's half of a catalog entry; the hub completes it (labels, licence, group). */
10016
+ var TrainingCatalogDraftSchema = object({
10017
+ id: string().min(1),
10018
+ name: string().min(1),
10019
+ description: string(),
10020
+ labels: array(unknown()),
10021
+ inputSize: object({
10022
+ width: number().int().positive(),
10023
+ height: number().int().positive()
10024
+ }),
10025
+ preprocessMode: literal("letterbox"),
10026
+ defaultClassFloors: FloorsSchema,
10027
+ formats: object({
10028
+ onnx: DraftFormatSchema.optional(),
10029
+ openvino: DraftFormatSchema.optional(),
10030
+ coreml: DraftFormatSchema.optional()
10031
+ })
10032
+ });
10033
+ /** One class of one model's holdout report (the eval harness's summary). */
10034
+ var TrainingEvalClassSchema = object({
10035
+ positives: number().int(),
10036
+ floor: number().nullable(),
10037
+ tp: number().int(),
10038
+ fp: number().int(),
10039
+ fn: number().int(),
10040
+ precision: number().nullable(),
10041
+ recall: number().nullable(),
10042
+ ap50: number().nullable(),
10043
+ recallByCamera: record(string(), number().nullable()).optional(),
10044
+ recallByLight: record(string(), number().nullable()).optional(),
10045
+ fpByCamera: record(string(), number()).optional(),
10046
+ smallFound: number().int().optional(),
10047
+ smallTotal: number().int().optional()
10048
+ }).passthrough();
10049
+ var TrainingEvalReportSchema = object({
10050
+ frames: number().int(),
10051
+ classes: record(string(), TrainingEvalClassSchema)
10052
+ }).passthrough();
10053
+ /**
10054
+ * A succeeded result carries every block; a failed one carries the error and
10055
+ * whatever was known by then — the other blocks are ABSENT, not null. The
10056
+ * orchestrator checks the blocks it needs before it trusts a success.
10057
+ */
10058
+ var TrainingResultSchema = object({
10059
+ schema: literal(TRAINING_RESULT_SCHEMA),
10060
+ jobKey: string(),
10061
+ status: _enum(["succeeded", "failed"]),
10062
+ error: object({
10063
+ stage: string(),
10064
+ code: string(),
10065
+ message: string()
10066
+ }).nullable(),
10067
+ trainer: object({
10068
+ version: string(),
10069
+ revision: string()
10070
+ }),
10071
+ toolchain: record(string(), string().nullable()),
10072
+ dataset: object({
10073
+ versionId: string(),
10074
+ annotationHash: string(),
10075
+ sha256: string(),
10076
+ frames: object({
10077
+ train: number().int(),
10078
+ val: number().int(),
10079
+ holdout: number().int()
10080
+ }),
10081
+ holdoutCameras: array(number().int()),
10082
+ replayImages: number().int()
10083
+ }).optional(),
10084
+ training: object({
10085
+ epochsRun: number().int(),
10086
+ bestEpoch: number().int(),
10087
+ bestMap50: number(),
10088
+ bestMap50_95: number(),
10089
+ seconds: number()
10090
+ }).optional(),
10091
+ evaluation: object({
10092
+ holdoutFrames: number().int(),
10093
+ baseline: TrainingEvalReportSchema.nullable(),
10094
+ candidate: TrainingEvalReportSchema.nullable(),
10095
+ candidateInt8: TrainingEvalReportSchema.nullable(),
10096
+ recallDeltaByCamera: record(string(), record(string(), number())).nullable(),
10097
+ map50: record(string(), number().nullable())
10098
+ }).optional(),
10099
+ floors: object({
10100
+ baseline: FloorsSchema,
10101
+ candidate: FloorsSchema,
10102
+ candidateInt8: FloorsSchema.nullable(),
10103
+ notes: array(string())
10104
+ }).optional(),
10105
+ int8: object({
10106
+ kept: boolean(),
10107
+ map50Fp16: number().nullable(),
10108
+ map50Int8: number().nullable(),
10109
+ reason: string().nullable()
10110
+ }).optional(),
10111
+ exportsDropped: array(object({
10112
+ export: string(),
10113
+ reason: string()
10114
+ })).optional(),
10115
+ files: array(TrainingResultFileSchema).optional(),
10116
+ bundle: object({
10117
+ path: literal("bundle.tar"),
10118
+ bytes: number().int().nonnegative(),
10119
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10120
+ }).nullable().optional(),
10121
+ catalogDraft: object({
10122
+ base: TrainingCatalogDraftSchema,
10123
+ int8: TrainingCatalogDraftSchema.nullable()
10124
+ }).nullable().optional(),
10125
+ licence: string()
10126
+ });
10127
+ var TrainingStageSchema = _enum([
10128
+ "prepare",
10129
+ "replay",
10130
+ "train",
10131
+ "eval",
10132
+ "export",
10133
+ "package"
10134
+ ]);
10135
+ var EventBase = {
10136
+ v: literal(1),
10137
+ ts: number()
10138
+ };
10139
+ discriminatedUnion("type", [
10140
+ object({
10141
+ ...EventBase,
10142
+ type: literal("stage"),
10143
+ stage: TrainingStageSchema
10144
+ }),
10145
+ object({
10146
+ ...EventBase,
10147
+ type: literal("epoch"),
10148
+ epoch: number().int(),
10149
+ epochs: number().int(),
10150
+ boxLoss: number().nullable().optional(),
10151
+ map50: number().nullable().optional(),
10152
+ map50_95: number().nullable().optional(),
10153
+ etaSec: number().nullable().optional()
10154
+ }),
10155
+ object({
10156
+ ...EventBase,
10157
+ type: literal("metric"),
10158
+ name: string(),
10159
+ value: number()
10160
+ }),
10161
+ object({
10162
+ ...EventBase,
10163
+ type: literal("artifact"),
10164
+ path: string(),
10165
+ bytes: number(),
10166
+ sha256: string()
10167
+ }),
10168
+ object({
10169
+ ...EventBase,
10170
+ type: literal("done"),
10171
+ status: _enum(["succeeded", "failed"]),
10172
+ resultSha256: string().nullable().optional()
10173
+ }),
10174
+ object({
10175
+ ...EventBase,
10176
+ type: literal("error"),
10177
+ stage: string(),
10178
+ code: string(),
10179
+ message: string()
10180
+ })
10181
+ ]);
10182
+ /**
9488
10183
  * What the gate decided about a birth, from the CALLER's point of view.
9489
10184
  *
9490
10185
  * Deliberately not `ConfirmationVerdict`: `undecided` is not a birth decision
@@ -11834,7 +12529,9 @@ var AddonHttpRouteSchema = object({
11834
12529
  "authenticated",
11835
12530
  "admin"
11836
12531
  ]).optional(),
11837
- description: string().optional()
12532
+ description: string().optional(),
12533
+ /** The hub limits this route per client address before the handler runs. */
12534
+ rateLimit: _enum(["auth"]).optional()
11838
12535
  });
11839
12536
  /**
11840
12537
  * Cross-process route invocation envelope. The hub captures the
@@ -12784,6 +13481,37 @@ var BackupDestinationInfoSchema = object({
12784
13481
  lastError: string().optional()
12785
13482
  });
12786
13483
  /**
13484
+ * How an archive is encrypted (operator decision 2026-10-09): to a backup
13485
+ * PUBLIC key the hub holds, so only the operator's secret key opens it.
13486
+ * Absent on a plain `.tar.gz` — every archive made before encryption, or
13487
+ * with it off — which restores without a key.
13488
+ */
13489
+ var BackupArchiveEncryptionSchema = object({
13490
+ /** `x25519-hkdf-aes256gcm-stream-v1`. */
13491
+ scheme: string(),
13492
+ /** 16 hex — the backup key whose secret restores this archive. */
13493
+ keyId: string()
13494
+ });
13495
+ /**
13496
+ * The backup encryption setting. The hub keeps PUBLIC keys only: the active
13497
+ * one new archives are encrypted to, and the retired ones older archives
13498
+ * still need. The secret key is shown once, at `setupEncryption`.
13499
+ */
13500
+ var BackupEncryptionStatusSchema = object({
13501
+ enabled: boolean(),
13502
+ active: object({
13503
+ keyId: string(),
13504
+ publicKey: string(),
13505
+ createdAt: number()
13506
+ }).nullable(),
13507
+ /** Every key ever set up, newest first. */
13508
+ keys: array(object({
13509
+ keyId: string(),
13510
+ createdAt: number(),
13511
+ retiredAt: number().nullable()
13512
+ })).readonly()
13513
+ });
13514
+ /**
12787
13515
  * Per-archive entry returned by `backup.listArchives({ destinationId })`.
12788
13516
  * Same shape the destination drill-in renders. Sourced from the per-
12789
13517
  * location `manifests.json` (no per-archive tarball read required).
@@ -12795,7 +13523,9 @@ var BackupArchiveEntrySchema = object({
12795
13523
  sizeBytes: number(),
12796
13524
  label: string().optional(),
12797
13525
  /** Top-level locations included in the archive (db, addons, tls, …). */
12798
- locations: array(string()).readonly()
13526
+ locations: array(string()).readonly(),
13527
+ /** Present when the archive is encrypted; restore then needs that key. */
13528
+ encryption: BackupArchiveEncryptionSchema.optional()
12799
13529
  });
12800
13530
  var BackupEntrySchema = object({
12801
13531
  id: string(),
@@ -12804,7 +13534,8 @@ var BackupEntrySchema = object({
12804
13534
  label: string().optional(),
12805
13535
  createdAt: number(),
12806
13536
  sizeBytes: number(),
12807
- locations: array(string()).optional()
13537
+ locations: array(string()).optional(),
13538
+ encryption: BackupArchiveEncryptionSchema.optional()
12808
13539
  });
12809
13540
  var ArchiveEntrySchema = object({
12810
13541
  path: string(),
@@ -13059,11 +13790,58 @@ var backupCapability = {
13059
13790
  * this list and skips entries whose path doesn't start with
13060
13791
  * any of them.
13061
13792
  */
13062
- locations: array(string()).optional()
13793
+ locations: array(string()).optional(),
13794
+ /**
13795
+ * The backup SECRET key, for an encrypted archive (ignored for a plain
13796
+ * one). The archive is decrypted into the hub's private staging
13797
+ * before the restart; the key is not stored. A wrong or missing key
13798
+ * is refused before the archive is downloaded.
13799
+ */
13800
+ backupSecretKey: string().optional()
13063
13801
  }), _void(), {
13064
13802
  kind: "mutation",
13065
13803
  auth: "admin"
13066
13804
  }),
13805
+ /** The encryption setting — public keys only. */
13806
+ getEncryption: method(_void(), BackupEncryptionStatusSchema, { auth: "admin" }),
13807
+ /**
13808
+ * Turn encryption on, or replace the key: generates a new key pair, keeps
13809
+ * the PUBLIC key, and returns the SECRET key — once. It is never stored
13810
+ * on the hub and cannot be shown again; archives made from now on need
13811
+ * it to be restored. A previous key is retired: archives made with it
13812
+ * still need IT.
13813
+ */
13814
+ setupEncryption: method(object({}), object({
13815
+ keyId: string(),
13816
+ secretKey: string(),
13817
+ publicKey: string(),
13818
+ createdAt: number(),
13819
+ replacedKeyId: string().nullable()
13820
+ }), {
13821
+ kind: "mutation",
13822
+ auth: "admin"
13823
+ }),
13824
+ /** New archives are plain again. Existing encrypted archives keep needing their key. */
13825
+ disableEncryption: method(object({}), object({ disabledKeyId: string().nullable() }), {
13826
+ kind: "mutation",
13827
+ auth: "admin"
13828
+ }),
13829
+ /**
13830
+ * Does this secret key parse, and which backup key is it? A mutation so
13831
+ * the key never travels in a URL. Nothing is stored.
13832
+ */
13833
+ checkBackupKey: method(object({ backupSecretKey: string() }), object({
13834
+ valid: boolean(),
13835
+ keyId: string().nullable(),
13836
+ /** The hub knows this key (active or retired). */
13837
+ known: boolean(),
13838
+ /** It is the key new archives are encrypted to. */
13839
+ active: boolean(),
13840
+ error: string().optional()
13841
+ }), {
13842
+ kind: "mutation",
13843
+ auth: "admin"
13844
+ }),
13067
13845
  delete: method(object({
13068
13846
  destinationId: string(),
13069
13847
  backupId: string()
@@ -15248,22 +16026,87 @@ var CustomModelDescriptorSchema = object({
15248
16026
  stepId: string(),
15249
16027
  entry: ModelCatalogEntrySchema
15250
16028
  });
16029
+ /** One regular file of an imported bundle, as the producer measured it. */
16030
+ var ModelBundleFileSchema = object({
16031
+ /** Relative path inside the bundle tar; an mlpackage member is `<x>.mlpackage/<member>`. */
16032
+ path: string().min(1),
16033
+ bytes: number().int().nonnegative(),
16034
+ sha256: string().regex(/^[0-9a-f]{64}$/)
16035
+ });
16036
+ var ImportModelBundleInputSchema = object({
16037
+ /** The registry provider that keeps the model (Model Studio). */
16038
+ addonId: string(),
16039
+ stepId: string().min(1),
16040
+ /**
16041
+ * The catalog rows to register, complete, every format URL already
16042
+ * `camstack-local://<modelId>/<file>` naming a file of the bundle. One
16043
+ * bundle may carry several rows (a base and its INT8 variant).
16044
+ */
16045
+ entries: array(ModelCatalogEntrySchema).min(1).max(4),
16046
+ /** The bundle tar, offered by the producer over `ctx.peerBytes` (same host). */
16047
+ bundle: object({
16048
+ ticket: PeerBytesTicketSchema,
16049
+ bytes: number().int().positive(),
16050
+ sha256: string().regex(/^[0-9a-f]{64}$/)
16051
+ }),
16052
+ /** Every file the tar must hold; anything missing, extra or different is refused. */
16053
+ files: array(ModelBundleFileSchema).min(1).max(64),
16054
+ /** Convert missing engine formats and push the model to every agent afterwards. */
16055
+ distribute: boolean()
16056
+ });
16057
+ var ImportModelBundleResultSchema = discriminatedUnion("kind", [object({
16058
+ kind: literal("imported"),
16059
+ modelIds: array(string()).readonly(),
16060
+ distributed: array(object({
16061
+ modelId: string(),
16062
+ nodeId: string(),
16063
+ format: _enum(MODEL_FORMATS),
16064
+ ok: boolean(),
16065
+ error: string().optional()
16066
+ })).readonly()
16067
+ }), object({
16068
+ kind: literal("refused"),
16069
+ reason: _enum([
16070
+ "transfer-failed",
16071
+ "checksum-mismatch",
16072
+ "bundle-mismatch",
16073
+ "invalid-entry",
16074
+ "id-taken"
16075
+ ]),
16076
+ detail: string()
16077
+ })]);
15251
16078
  var customModelRegistryCapability = {
15252
16079
  name: "custom-model-registry",
15253
16080
  scope: "system",
15254
16081
  mode: "collection",
15255
16082
  internal: true,
15256
- methods: {
15257
- /**
15258
- * `internal: true` did not gate the mount (see the 2026-08-26 note on
15259
- * `data-store-provider`) — this was reachable on the AppRouter by ANY
15260
- * authenticated session at the default `auth: 'protected'`. The only
15261
- * consumer, the detection-pipeline's model resolution
15262
- * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
15263
- * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
15264
- * never tRPC — so `auth: 'admin'` costs it nothing.
15265
- */
15266
- listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }) }
16083
+ methods: {
16084
+ /**
16085
+ * `internal: true` did not gate the mount (see the 2026-08-26 note on
16086
+ * `data-store-provider`) — this was reachable on the AppRouter by ANY
16087
+ * authenticated session at the default `auth: 'protected'`. The only
16088
+ * consumer, the detection-pipeline's model resolution
16089
+ * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
16090
+ * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
16091
+ * never tRPC — so `auth: 'admin'` costs it nothing.
16092
+ */
16093
+ listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }),
16094
+ /**
16095
+ * Register a model whose files arrive as ONE bundle tar (D806): the tar
16096
+ * is taken over `ctx.peerBytes`, checked against `bundle.sha256` and
16097
+ * every row of `files`, unpacked into the hub's flat modelsDir (directory
16098
+ * formats included), each format's `.revision` record written, the rows
16099
+ * upserted under the operator's name, the hub marked available and —
16100
+ * when asked — engine formats converted and the model distributed. A
16101
+ * model id already registered by another source is refused, never
16102
+ * overwritten.
16103
+ */
16104
+ importModelBundle: method(ImportModelBundleInputSchema, ImportModelBundleResultSchema, {
16105
+ kind: "mutation",
16106
+ auth: "admin",
16107
+ timeoutMs: 30 * 6e4
16108
+ })
16109
+ }
15267
16110
  };
15268
16111
  /**
15269
16112
  * Query filter for settings-store collections.
@@ -16054,6 +16897,35 @@ var KeychainKeySourceSchema = object({
16054
16897
  */
16055
16898
  sharesBackupWithDatabase: boolean()
16056
16899
  });
16900
+ /**
16901
+ * One keychain reset, as the Secrets page reports it until the operator
16902
+ * acknowledges it. Never a value: refs, counts and table names only.
16903
+ */
16904
+ var KeychainResetRecordSchema = object({
16905
+ id: string(),
16906
+ at: number(),
16907
+ /** `user:<id>` or {@link KEYCHAIN_RESET_TRIGGER_ACTOR}. */
16908
+ actor: string(),
16909
+ /** Why the keychain was locked when it was reset; `null` when it was not locked. */
16910
+ lockedReason: string().nullable(),
16911
+ /** Values moved into the archive table (ciphertext under the lost key). */
16912
+ archived: number().int(),
16913
+ /** `keychain:secrets-orphaned-<ts>`, or `null` when nothing was stored. */
16914
+ archivedCollection: string().nullable(),
16915
+ /**
16916
+ * `keychain:keys-orphaned-<ts>`: the wrapped data keys of the archive, kept
16917
+ * so the archive can still be opened if the lost master key turns up.
16918
+ */
16919
+ archivedKeysCollection: string().nullable(),
16920
+ /**
16921
+ * `system-settings` keys whose marker the reset cleared — the cluster
16922
+ * secret's: a marker left pointing at an archived value would refuse every
16923
+ * agent forever (D797).
16924
+ */
16925
+ clearedSettingsKeys: array(string()).readonly(),
16926
+ /** When an operator dismissed the notice on the Secrets page; `null` until then. */
16927
+ acknowledgedAt: number().nullable()
16928
+ });
16057
16929
  var KeychainStatusSchema = object({
16058
16930
  keychain: KeychainStateSchema,
16059
16931
  /** The source of the master key in use; `null` while locked. */
@@ -16071,7 +16943,9 @@ var KeychainStatusSchema = object({
16071
16943
  /** Wrapped copies of the data key under a previous master key, kept until purged. */
16072
16944
  retiredWraps: number().int(),
16073
16945
  recoveryKeyDownloadedAt: number().nullable(),
16074
- secretCount: number().int()
16946
+ secretCount: number().int(),
16947
+ /** The most recent reset, acknowledged or not; `null` when the keychain was never reset. */
16948
+ lastReset: KeychainResetRecordSchema.nullable()
16075
16949
  });
16076
16950
  /**
16077
16951
  * Whether a stored value is still pointed at by its owner's settings.
@@ -16093,13 +16967,14 @@ var KeychainAuditActionSchema = _enum([
16093
16967
  "download-recovery-key",
16094
16968
  "delete-orphans",
16095
16969
  "reset",
16970
+ "acknowledge-reset",
16096
16971
  "initialize"
16097
16972
  ]);
16098
16973
  var KeychainAuditEntrySchema = object({
16099
16974
  id: string(),
16100
16975
  at: number(),
16101
16976
  action: KeychainAuditActionSchema,
16102
- /** `addon:<id>` | `user:<id>` | `system`. */
16977
+ /** `addon:<id>` | `user:<id>` | `system` | `trigger-file`. */
16103
16978
  actor: string(),
16104
16979
  ref: string().nullable(),
16105
16980
  detail: string().nullable()
@@ -16209,6 +17084,21 @@ var keychainAdminCapability = {
16209
17084
  kind: "mutation",
16210
17085
  auth: "admin",
16211
17086
  caller: "required"
17087
+ }),
17088
+ /**
17089
+ * What the last reset left to re-enter: the archived refs (owner, scope,
17090
+ * field — never a value) that hold no value again yet. Process-held refs
17091
+ * the hub regenerates itself (the session signing key) are not listed.
17092
+ */
17093
+ resetReport: method(object({}), object({
17094
+ reset: KeychainResetRecordSchema.nullable(),
17095
+ pendingReentry: array(KeychainSecretMetaSchema).readonly()
17096
+ }), { auth: "admin" }),
17097
+ /** Dismiss the "keychain was reset" notice. Audited. */
17098
+ acknowledgeReset: method(object({}), object({ acknowledged: boolean() }), {
17099
+ kind: "mutation",
17100
+ auth: "admin",
17101
+ caller: "required"
16212
17102
  })
16213
17103
  }
16214
17104
  };
@@ -20124,7 +21014,7 @@ var logDestinationCapability = {
20124
21014
  * `login-method` — collection cap through which auth addons contribute
20125
21015
  * their pre-auth login surfaces to the login page. This is the SINGLE,
20126
21016
  * generic mechanism that supersedes the dead `auth.listProviders` reader:
20127
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
21017
+ * every auth addon (OIDC, WebAuthn/passkey) registers a
20128
21018
  * `login-method` provider and the PUBLIC `auth.listLoginMethods`
20129
21019
  * procedure aggregates them for the unauthenticated login page.
20130
21020
  *
@@ -20132,8 +21022,7 @@ var logDestinationCapability = {
20132
21022
  *
20133
21023
  * - `redirect` — a declarative button. The login page renders a generic
20134
21024
  * button that navigates to `startUrl` (an addon-owned HTTP route).
20135
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
20136
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
21025
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) with ZERO shell-side JS. A future SSO addon plugs in the same way — the
20137
21026
  * login page needs NO change.
20138
21027
  *
20139
21028
  * - `widget` — a Module-Federation widget the login page mounts (via
@@ -20152,8 +21041,8 @@ var logDestinationCapability = {
20152
21041
  * decision.
20153
21042
  *
20154
21043
  * Every contribution carries a `stage`:
20155
- * - `primary` — shown on the first credentials screen (OIDC /
20156
- * magic-link buttons; a future usernameless passkey).
21044
+ * - `primary` — shown on the first credentials screen (OIDC
21045
+ * buttons; a usernameless passkey).
20157
21046
  * - `second-factor` — shown AFTER the password leg, gated on the
20158
21047
  * returned `factors` (passkey-as-2FA today).
20159
21048
  *
@@ -20180,7 +21069,7 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
20180
21069
  * The provider names an external identity a signed-in user can link to
20181
21070
  * their own account (D782): `auth.listLinkableProviders` /
20182
21071
  * `beginExternalLink` offer exactly the redirect methods that set this,
20183
- * whatever their id. Absent / false — a login button only (magic-link).
21072
+ * whatever their id. Absent / false — a login button only.
20184
21073
  */
20185
21074
  linkable: boolean().optional()
20186
21075
  }),
@@ -24941,8 +25830,7 @@ var notificationRulesCapability = {
24941
25830
  * `super_admin` — collapsed onto the single boolean because every
24942
25831
  * non-admin caller is governed by the same scope-check rules; the
24943
25832
  * distinction was only ever used to route role-specific procedures
24944
- * which we no longer have. Agents are admin sessions issued via
24945
- * `createServiceToken`; CLI / webhook integrations are `cst_*` tokens
25833
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
24946
25834
  * with `isAdmin: false` + an explicit scope list.
24947
25835
  */
24948
25836
  /** Per-method access flavour. Materialised on every cap method via codegen. */
@@ -28214,6 +29102,26 @@ var pipelineAnalyticsCapability = {
28214
29102
  auth: "admin",
28215
29103
  timeoutMs: 60 * 6e4
28216
29104
  }),
29105
+ /**
29106
+ * OFFER the annotated archive instead of pushing it (D805): the same tar
29107
+ * `writeRetrainArchive` streams, behind a one-shot `ctx.peerBytes` ticket
29108
+ * the caller dials at once (same host). For a consumer that cannot expose
29109
+ * an upload URL — a training provider streaming straight into its cloud.
29110
+ * The answer is the plan; the bytes and their sha256 are the consumer's
29111
+ * to measure as they arrive.
29112
+ */
29113
+ offerRetrainArchive: method(object({
29114
+ filter: RetrainExportFilterSchema,
29115
+ layout: RetrainExportLayoutSchema
29116
+ }), object({
29117
+ ticket: PeerBytesTicketSchema,
29118
+ frames: number().int(),
29119
+ annotations: number().int()
29120
+ }), {
29121
+ kind: "mutation",
29122
+ auth: "admin",
29123
+ timeoutMs: 12e4
29124
+ }),
28217
29125
  /** The counts a selection would freeze — class × camera × day/night,
28218
29126
  * completeness — without freezing anything. Index reads only. */
28219
29127
  previewRetrainDataset: method(object({
@@ -32855,8 +33763,8 @@ version: string().optional() }), ServerUpdateActionResultSchema, {
32855
33763
  * `smtp-provider` — pluggable email delivery surface.
32856
33764
  *
32857
33765
  * Collection cap: a deployment may install multiple SMTP relays (e.g.
32858
- * one for transactional / one for notifications). Consumers (magic-link,
32859
- * notifier addons, …) walk the collection and pick the first
33766
+ * one for transactional / one for notifications). Consumers (notifier
33767
+ * addons, …) walk the collection and pick the first
32860
33768
  * ready provider OR target a specific addonId.
32861
33769
  *
32862
33770
  * The shape stays small on purpose — `sendEmail` is enough for the
@@ -33152,7 +34060,7 @@ targets: array(object({
33152
34060
  };
33153
34061
  /**
33154
34062
  * `sso-bridge` — internal hub-only cap that lets SSO-style auth
33155
- * providers (OIDC, SAML, magic-link, …) mint an HMAC-signed token
34063
+ * providers (OIDC, SAML, …) mint an HMAC-signed token
33156
34064
  * carrying the post-callback claims before redirecting back to
33157
34065
  * `/api/auth/sso/finish`.
33158
34066
  *
@@ -33215,7 +34123,14 @@ var SsoBridgeClaimsSchema = object({
33215
34123
  * Verified `iss` of the id_token behind an OIDC login bridge (D782). A
33216
34124
  * subject is unique only per issuer, so a link is bound to it.
33217
34125
  */
33218
- issuer: string().optional()
34126
+ issuer: string().optional(),
34127
+ /**
34128
+ * SHA-256 (hex) of the `camstack_sso_state` cookie the IdP `/start` set in
34129
+ * the browser that began this sign-in. `/api/auth/sso/finish` requires the
34130
+ * request to present the matching cookie — a login bridge is useless in
34131
+ * any other browser.
34132
+ */
34133
+ browserBinding: string().optional()
33219
34134
  });
33220
34135
  var ssoBridgeCapability = {
33221
34136
  name: "sso-bridge",
@@ -33233,7 +34148,7 @@ var ssoBridgeCapability = {
33233
34148
  * `/api/auth/sso/finish` to become admin — a full privilege escalation
33234
34149
  * through the exact surface this cap exists to close (see the module
33235
34150
  * docblock). Every real caller (`oauth-grants.ts`, `main.ts`
33236
- * registration, the OIDC/magic-link addons) reaches this through
34151
+ * registration, the OIDC addon) reaches this through
33237
34152
  * `ctx.api` / the in-process registry — never through tRPC — so
33238
34153
  * `auth: 'admin'` costs those callers nothing.
33239
34154
  */
@@ -47510,16 +48425,6 @@ var ApiKeySummarySchema = object({
47510
48425
  createdAt: number(),
47511
48426
  lastUsedAt: number().optional()
47512
48427
  });
47513
- var CreateApiKeyInputSchema = object({
47514
- label: string(),
47515
- isAdmin: boolean().default(false),
47516
- allowedProviders: union([array(string()), literal("*")]).optional(),
47517
- allowedDevices: record(string(), union([array(string()), literal("*")])).optional()
47518
- });
47519
- var CreateApiKeyResultSchema = object({
47520
- token: string(),
47521
- record: ApiKeySummarySchema
47522
- });
47523
48428
  var ScopedTokenSummarySchema = object({
47524
48429
  id: string(),
47525
48430
  userId: string(),
@@ -47631,20 +48536,11 @@ var userManagementCapability = {
47631
48536
  access: "view"
47632
48537
  }),
47633
48538
  listApiKeys: method(_void(), array(ApiKeySummarySchema), { auth: "admin" }),
47634
- createApiKey: method(CreateApiKeyInputSchema, CreateApiKeyResultSchema, {
47635
- kind: "mutation",
47636
- auth: "admin",
47637
- access: "create"
47638
- }),
47639
48539
  revokeApiKey: method(object({ id: string() }), object({ success: literal(true) }), {
47640
48540
  kind: "mutation",
47641
48541
  auth: "admin",
47642
48542
  access: "delete"
47643
48543
  }),
47644
- validateApiKey: method(object({ token: string() }), ApiKeySummarySchema.nullable(), {
47645
- kind: "mutation",
47646
- access: "view"
47647
- }),
47648
48544
  createScopedToken: method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
47649
48545
  kind: "mutation",
47650
48546
  auth: "admin",
@@ -47734,20 +48630,6 @@ var userManagementCapability = {
47734
48630
  userId: string(),
47735
48631
  issuer: string()
47736
48632
  }).nullable(), { auth: "admin" }),
47737
- /**
47738
- * Link `(provider, subject)` to `userId`. Idempotent for the same user;
47739
- * REFUSES (throws) an identity already linked to another user, and a
47740
- * user that does not exist.
47741
- */
47742
- linkExternalIdentity: method(ExternalIdentityKeySchema.extend({
47743
- userId: string(),
47744
- issuer: string().min(1),
47745
- label: string().optional()
47746
- }), object({ success: literal(true) }), {
47747
- kind: "mutation",
47748
- auth: "admin",
47749
- access: "create"
47750
- }),
47751
48633
  /** Remove one link of `userId`. `success: false` when it was not linked to that user. */
47752
48634
  unlinkExternalIdentity: method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
47753
48635
  kind: "mutation",
@@ -48459,6 +49341,531 @@ var zoneRulesCapability = {
48459
49341
  durability: "restored"
48460
49342
  };
48461
49343
  /**
49344
+ * `training-provider` — ONE cloud that can run the CamStack trainer.
49345
+ *
49346
+ * A thin, mockable translation layer: it knows how to run a container with a
49347
+ * GPU, move a dataset in, read the job's stdout and hand artefacts back. It
49348
+ * knows nothing about datasets, splits, floors, cost policy or Model Studio —
49349
+ * those are the `training` orchestrator's (D805). Every rule written there
49350
+ * once is what makes a second provider (RunPod, a local NVIDIA node) a new
49351
+ * manifest entry and nothing else.
49352
+ *
49353
+ * Collection, routed by the `addonId` in every single-row input (the `llm` /
49354
+ * `notification-output` posture); `describe` concat-fans across providers.
49355
+ * Every method is `admin`: these spend money.
49356
+ *
49357
+ * Every cloud object a provider creates is tagged with the orchestrator's
49358
+ * `jobKey`, so a retried submit finds the job it already started instead of
49359
+ * starting a second GPU, and `listJobs` can find orphans.
49360
+ *
49361
+ * Bytes never ride a cap field: the dataset arrives as a `ctx.peerBytes`
49362
+ * ticket the producer (pipeline-analytics) minted, and artefacts leave as a
49363
+ * ticket the provider mints (D613).
49364
+ */
49365
+ var TrainingGpuOptionSchema = object({
49366
+ id: string(),
49367
+ label: string(),
49368
+ /** List price, USD per GPU-hour, before any region multiplier. */
49369
+ usdPerHour: number().nonnegative(),
49370
+ vramGb: number().nonnegative()
49371
+ });
49372
+ var TrainingRegionOptionSchema = object({
49373
+ /** `''` = any region (the provider's choice). */
49374
+ id: string(),
49375
+ label: string(),
49376
+ priceMultiplier: number().positive()
49377
+ });
49378
+ /**
49379
+ * The provider's per-account settings, as the orchestrator reads them. They
49380
+ * live in the PROVIDER addon's settings (operator decision 2026-10-08: they
49381
+ * depend on the user's account), never hard-coded in the orchestrator.
49382
+ */
49383
+ var TrainingProviderDefaultsSchema = object({
49384
+ gpuType: string(),
49385
+ region: string(),
49386
+ costCapUsd: number().nonnegative(),
49387
+ maxRuntimeSec: number().int().positive(),
49388
+ /** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
49389
+ failedDatasetGraceHours: number().nonnegative()
49390
+ });
49391
+ var TrainingProviderDescriptorSchema = object({
49392
+ addonId: string(),
49393
+ /** `modal`, `runpod`, `fake`, … */
49394
+ kind: string(),
49395
+ label: string(),
49396
+ gpuTypes: array(TrainingGpuOptionSchema).readonly(),
49397
+ regions: array(TrainingRegionOptionSchema).readonly(),
49398
+ maxDatasetBytes: number().int().positive(),
49399
+ maxRuntimeSec: number().int().positive(),
49400
+ freeTierNote: string().optional(),
49401
+ /** Where the data goes, in one sentence the confirm dialog repeats. */
49402
+ dataResidencyNote: string(),
49403
+ /** Credentials are present — never the values. */
49404
+ configured: boolean(),
49405
+ defaults: TrainingProviderDefaultsSchema
49406
+ });
49407
+ var TrainingCredentialCheckSchema = object({
49408
+ ok: boolean(),
49409
+ /** Workspace / account name, when the provider says. */
49410
+ account: string().optional(),
49411
+ reason: _enum([
49412
+ "missing",
49413
+ "invalid",
49414
+ "forbidden",
49415
+ "network",
49416
+ "quota"
49417
+ ]).optional(),
49418
+ detail: string().optional()
49419
+ });
49420
+ var ProviderJobStateSchema = _enum([
49421
+ "pending",
49422
+ "starting",
49423
+ "running",
49424
+ "succeeded",
49425
+ "failed",
49426
+ "cancelled",
49427
+ "lost"
49428
+ ]);
49429
+ var ProviderJobStatusSchema = object({
49430
+ jobKey: string(),
49431
+ providerJobId: string().optional(),
49432
+ state: ProviderJobStateSchema,
49433
+ startedAt: number().optional(),
49434
+ endedAt: number().optional(),
49435
+ exitCode: number().int().optional(),
49436
+ failureReason: string().optional(),
49437
+ gpuType: string(),
49438
+ region: string().optional(),
49439
+ billedSeconds: number().nonnegative(),
49440
+ costUsd: number().nonnegative(),
49441
+ /** True when `costUsd` is runtime × list price, not a billing answer. */
49442
+ costIsEstimate: boolean(),
49443
+ lastFetchedAt: number()
49444
+ });
49445
+ /**
49446
+ * The trainer the job runs, by SOURCE revision: the provider turns it into an
49447
+ * image its own way (Modal builds the published Dockerfile at that revision;
49448
+ * a registry-pull provider maps it to a tag). Recorded on the job and echoed
49449
+ * in `result.json`.
49450
+ */
49451
+ var TrainerSourceRefSchema = object({
49452
+ /** Hugging Face repo id, e.g. `camstack/camstack-trainer`. */
49453
+ repo: string().min(1),
49454
+ /** A commit sha (never a branch) — the job must be reproducible. */
49455
+ revision: string().regex(/^[0-9a-f]{7,64}$/)
49456
+ });
49457
+ var JobRef = {
49458
+ addonId: string(),
49459
+ jobKey: string().uuid()
49460
+ };
49461
+ var TrainingLogLineSchema = object({
49462
+ ts: number(),
49463
+ text: string()
49464
+ });
49465
+ var trainingProviderCapability = {
49466
+ name: "training-provider",
49467
+ scope: "system",
49468
+ mode: "collection",
49469
+ internal: true,
49470
+ methods: {
49471
+ /** Every provider's offer and settings. Concat-fans across providers. */
49472
+ describe: method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }),
49473
+ /** Call the provider with the stored credentials. Never returns them. */
49474
+ validateCredentials: method(object({ addonId: string() }), TrainingCredentialCheckSchema, {
49475
+ kind: "mutation",
49476
+ auth: "admin",
49477
+ timeoutMs: 3e4
49478
+ }),
49479
+ /** USD range for a run of `gpuSeconds` on `gpuType` in `region`. */
49480
+ estimateJob: method(object({
49481
+ addonId: string(),
49482
+ gpuType: string(),
49483
+ region: string(),
49484
+ datasetBytes: number().int().nonnegative(),
49485
+ gpuSecondsLow: number().nonnegative(),
49486
+ gpuSecondsHigh: number().nonnegative()
49487
+ }), object({
49488
+ usdLow: number().nonnegative(),
49489
+ usdHigh: number().nonnegative(),
49490
+ notes: array(string()).readonly()
49491
+ }), { auth: "admin" }),
49492
+ /**
49493
+ * Take the dataset archive behind `ticket` (minted by pipeline-analytics,
49494
+ * same host) and land it as the job's dataset in the cloud, streamed —
49495
+ * nothing is staged on the hub's disk. Idempotent per `jobKey`: a second
49496
+ * call replaces a partial upload. Answers what actually landed.
49497
+ */
49498
+ uploadDataset: method(object({
49499
+ ...JobRef,
49500
+ ticket: PeerBytesTicketSchema
49501
+ }), object({
49502
+ bytes: number().int().nonnegative(),
49503
+ sha256: string()
49504
+ }), {
49505
+ kind: "mutation",
49506
+ auth: "admin",
49507
+ timeoutMs: 120 * 6e4
49508
+ }),
49509
+ /**
49510
+ * Start the trainer on a GPU. Looks the job up by `jobKey` first, so a
49511
+ * retried submit never starts a second GPU. `jobSpecJson` is written next
49512
+ * to the dataset as `job.json`; `maxRuntimeSec` is enforced by the
49513
+ * provider (a hard timeout), not by the hub.
49514
+ */
49515
+ submitJob: method(object({
49516
+ ...JobRef,
49517
+ trainer: TrainerSourceRefSchema,
49518
+ jobSpecJson: string().min(2).max(64e3),
49519
+ gpuType: string(),
49520
+ region: string(),
49521
+ maxRuntimeSec: number().int().positive()
49522
+ }), ProviderJobStatusSchema, {
49523
+ kind: "mutation",
49524
+ auth: "admin",
49525
+ timeoutMs: 30 * 6e4
49526
+ }),
49527
+ getJob: method(object(JobRef), ProviderJobStatusSchema, {
49528
+ auth: "admin",
49529
+ timeoutMs: 6e4
49530
+ }),
49531
+ /** Stdout/stderr since `cursor` (opaque), oldest first, at most `max` lines. */
49532
+ listJobEvents: method(object({
49533
+ ...JobRef,
49534
+ cursor: string().optional(),
49535
+ max: number().int().min(1).max(500)
49536
+ }), object({
49537
+ lines: array(TrainingLogLineSchema).readonly(),
49538
+ cursor: string()
49539
+ }), {
49540
+ auth: "admin",
49541
+ timeoutMs: 6e4
49542
+ }),
49543
+ /** Stop the job. Idempotent: an unknown or finished job is a no-op. */
49544
+ cancelJob: method(object(JobRef), object({ ok: literal(true) }), {
49545
+ kind: "mutation",
49546
+ auth: "admin",
49547
+ timeoutMs: 6e4
49548
+ }),
49549
+ /** The job's `result.json`, as text (small, JSON). `found: false` before it exists. */
49550
+ readResult: method(object(JobRef), object({
49551
+ found: boolean(),
49552
+ text: string().optional()
49553
+ }), {
49554
+ kind: "mutation",
49555
+ auth: "admin",
49556
+ timeoutMs: 5 * 6e4
49557
+ }),
49558
+ /**
49559
+ * Offer one output file of the job (`bundle.tar`) to the caller as a
49560
+ * one-shot `ctx.peerBytes` ticket, streamed from the cloud — the provider
49561
+ * stages nothing on disk. The caller dials it at once.
49562
+ */
49563
+ offerArtifact: method(object({
49564
+ ...JobRef,
49565
+ path: _enum(["bundle.tar"])
49566
+ }), object({ ticket: PeerBytesTicketSchema }), {
49567
+ kind: "mutation",
49568
+ auth: "admin",
49569
+ timeoutMs: 5 * 6e4
49570
+ }),
49571
+ /** Delete every cloud object tagged with `jobKey` (the dataset first). Idempotent. */
49572
+ cleanupJob: method(object(JobRef), object({ deleted: array(string()).readonly() }), {
49573
+ kind: "mutation",
49574
+ auth: "admin",
49575
+ timeoutMs: 5 * 6e4
49576
+ }),
49577
+ /** Every job the provider can still see — the orphan sweep diffs it against our records. */
49578
+ listJobs: method(object({ addonId: string() }), array(ProviderJobStatusSchema).readonly(), {
49579
+ auth: "admin",
49580
+ timeoutMs: 2 * 6e4
49581
+ })
49582
+ }
49583
+ };
49584
+ /**
49585
+ * `training` — the cloud-training orchestrator (D805). Hub-only singleton,
49586
+ * provided by `addon-training`.
49587
+ *
49588
+ * It owns what every provider must agree on, written once:
49589
+ *
49590
+ * - **Dataset versions.** Taken over from pipeline-analytics (D796): the rows
49591
+ * live here (D808); pipeline-analytics still CUTS a version (it owns the corpus and
49592
+ * the export plan) and reaches this store through the five row methods
49593
+ * below, so the Retrain page and the export did not change.
49594
+ * - **Jobs.** A persisted state machine, a reconcile loop against the
49595
+ * provider, a cost guard, a daily orphan sweep and the retention rules.
49596
+ * - **The return flow.** Verified artefacts → Model Studio
49597
+ * (`custom-model-registry.importModelBundle`) → canary on cameras →
49598
+ * rollback. Nothing is ever registered automatically.
49599
+ *
49600
+ * Every method is `admin`.
49601
+ */
49602
+ /** A version WITH its frame list — what the export and a job read. */
49603
+ var TrainingDatasetVersionRowSchema = RetrainDatasetVersionSchema.omit({ frameCount: true }).extend({ frameIds: array(string()).max(2e4).readonly() });
49604
+ /** A base model a detector job can fine-tune, and the baseline it is judged against. */
49605
+ var TrainingBaseModelSchema = object({
49606
+ modelId: string(),
49607
+ label: string(),
49608
+ weights: string(),
49609
+ imgsz: number().int(),
49610
+ baselineOnnxUrl: string(),
49611
+ baselineFloors: record(string(), number()),
49612
+ /** The base the fleet runs most — the UI's default. */
49613
+ recommended: boolean()
49614
+ });
49615
+ var TrainingPresetSchema = _enum([
49616
+ "quick",
49617
+ "standard",
49618
+ "thorough"
49619
+ ]);
49620
+ var TrainingJobRequestSchema = object({
49621
+ datasetVersionId: string().min(1),
49622
+ /** The `training-provider` addon that runs it. */
49623
+ addonId: string().min(1),
49624
+ gpuType: string().min(1),
49625
+ region: string(),
49626
+ baseModelId: string().min(1),
49627
+ preset: TrainingPresetSchema,
49628
+ /** Freeze the backbone's first N layers; `null` = the preset's choice. */
49629
+ freeze: number().int().nonnegative().nullable(),
49630
+ /** Cameras held out whole for evaluation; `null` = the orchestrator's default. */
49631
+ holdoutCameras: array(number().int()).nullable()
49632
+ });
49633
+ var TrainingSplitPlanSchema = object({
49634
+ holdoutCameras: array(number().int()).readonly(),
49635
+ /** Used when no camera is held out: the last N days of every camera. */
49636
+ holdoutLastDays: number().int().nonnegative(),
49637
+ /** Holdout subjects per class (camera holdout only; `null` = known only after the split). */
49638
+ holdoutSupport: record(string(), number().int()).nullable(),
49639
+ trainSubjects: number().int()
49640
+ });
49641
+ var TrainingRefusalReasonSchema = _enum([
49642
+ "unknown-dataset",
49643
+ "unknown-provider",
49644
+ "provider-not-configured",
49645
+ "unknown-base-model",
49646
+ "unknown-gpu",
49647
+ "dataset-too-large",
49648
+ "no-training-subjects",
49649
+ "job-already-running"
49650
+ ]);
49651
+ var TrainingJobPlanSchema = object({
49652
+ refusal: object({
49653
+ reason: TrainingRefusalReasonSchema,
49654
+ detail: string()
49655
+ }).nullable(),
49656
+ warnings: array(string()).readonly(),
49657
+ split: TrainingSplitPlanSchema.nullable(),
49658
+ estimate: object({
49659
+ datasetBytes: number().int(),
49660
+ uploadMinutesAt20Mbps: number(),
49661
+ gpuSecondsLow: number(),
49662
+ gpuSecondsHigh: number(),
49663
+ usdLow: number(),
49664
+ usdHigh: number(),
49665
+ notes: array(string()).readonly()
49666
+ }).nullable(),
49667
+ /** Pre-filled from the provider's settings; the operator may lower or raise them. */
49668
+ defaults: object({
49669
+ maxCostUsd: number(),
49670
+ maxRuntimeSec: number().int()
49671
+ }).nullable(),
49672
+ /** The sentence the confirm dialog repeats: where the frames go and when they are deleted. */
49673
+ dataNotice: string()
49674
+ });
49675
+ /**
49676
+ * Orchestrator-owned states, persisted. `uploading` covers exporting the
49677
+ * archive (it is streamed, never staged). Terminal: `failed`, `cancelled`,
49678
+ * `lost`, `expired`, `discarded`. `registered` and `canary` are where a
49679
+ * result lives after the operator acted on it.
49680
+ */
49681
+ var TrainingJobStateSchema = _enum([
49682
+ "uploading",
49683
+ "submitted",
49684
+ "starting",
49685
+ "running",
49686
+ "collecting",
49687
+ "ready",
49688
+ "registered",
49689
+ "canary",
49690
+ "failed",
49691
+ "cancelling",
49692
+ "cancelled",
49693
+ "lost",
49694
+ "expired",
49695
+ "discarded"
49696
+ ]);
49697
+ var TrainingFailureReasonSchema = _enum([
49698
+ "cost-cap",
49699
+ "runtime-cap",
49700
+ "upload-failed",
49701
+ "submit-failed",
49702
+ "trainer-failed",
49703
+ "result-invalid",
49704
+ "checksum-mismatch",
49705
+ "fetch-failed",
49706
+ "provider-error",
49707
+ "hub-restart-during-upload"
49708
+ ]);
49709
+ var TrainingProgressPointSchema = object({
49710
+ epoch: number().int(),
49711
+ map50: number().nullable(),
49712
+ map50_95: number().nullable()
49713
+ });
49714
+ var TrainingCanarySchema = object({
49715
+ deviceIds: array(number().int()).readonly(),
49716
+ since: number(),
49717
+ /** Every override the canary replaced, exactly, so rollback restores it. */
49718
+ previous: array(object({
49719
+ deviceId: number().int(),
49720
+ nodeId: string(),
49721
+ deviceKey: string(),
49722
+ patch: object({
49723
+ modelId: string().optional(),
49724
+ settings: record(string(), unknown()).readonly().optional()
49725
+ }).nullable()
49726
+ })).readonly()
49727
+ });
49728
+ var TrainingJobSchema = object({
49729
+ id: string(),
49730
+ idempotencyKey: string(),
49731
+ name: string(),
49732
+ createdAt: number(),
49733
+ updatedAt: number(),
49734
+ state: TrainingJobStateSchema,
49735
+ stage: TrainingStageSchema.nullable(),
49736
+ failure: object({
49737
+ reason: TrainingFailureReasonSchema,
49738
+ stage: string().nullable(),
49739
+ detail: string()
49740
+ }).nullable(),
49741
+ request: TrainingJobRequestSchema,
49742
+ maxCostUsd: number().nonnegative(),
49743
+ maxRuntimeSec: number().int().positive(),
49744
+ trainer: TrainerSourceRefSchema,
49745
+ datasetLayout: RetrainExportLayoutSchema,
49746
+ dataset: object({
49747
+ bytes: number().int(),
49748
+ sha256: string(),
49749
+ uploadedAt: number()
49750
+ }).nullable(),
49751
+ split: TrainingSplitPlanSchema,
49752
+ provider: object({
49753
+ state: ProviderJobStateSchema.nullable(),
49754
+ providerJobId: string().nullable(),
49755
+ startedAt: number().nullable(),
49756
+ endedAt: number().nullable(),
49757
+ billedSeconds: number(),
49758
+ costUsd: number(),
49759
+ costIsEstimate: boolean(),
49760
+ lastPolledAt: number().nullable()
49761
+ }),
49762
+ progress: object({
49763
+ epoch: number().int().nullable(),
49764
+ epochs: number().int().nullable(),
49765
+ etaSec: number().nullable(),
49766
+ series: array(TrainingProgressPointSchema).readonly()
49767
+ }),
49768
+ /** The last lines of the job's output (≤ 200), newest last. Never frame paths. */
49769
+ logTail: array(string()).readonly(),
49770
+ logCursor: string().nullable(),
49771
+ artifacts: object({
49772
+ bundleBytes: number().int(),
49773
+ bundleSha256: string(),
49774
+ fetchedAt: number(),
49775
+ /** When the staged artefacts are deleted from the hub. */
49776
+ expiresAt: number()
49777
+ }).nullable(),
49778
+ /** When the provider-side copy of the frames was deleted; null while it exists. */
49779
+ cloudDatasetDeletedAt: number().nullable(),
49780
+ /** A failed job's dataset is kept until then (the provider's grace), then deleted. */
49781
+ cloudCleanupDueAt: number().nullable(),
49782
+ /** Model ids registered from this job (base, and int8 when kept). */
49783
+ registeredModelIds: array(string()).readonly(),
49784
+ canary: TrainingCanarySchema.nullable()
49785
+ });
49786
+ var IdInput = object({ id: string().min(1) });
49787
+ var trainingCapability = {
49788
+ name: "training",
49789
+ scope: "system",
49790
+ mode: "singleton",
49791
+ mount: { kind: "hub-only" },
49792
+ methods: {
49793
+ /** Store a version once. `stored: false` = that id already exists (immutable). */
49794
+ putDatasetVersion: method(TrainingDatasetVersionRowSchema, object({ stored: boolean() }), {
49795
+ kind: "mutation",
49796
+ auth: "admin"
49797
+ }),
49798
+ getDatasetVersion: method(IdInput, TrainingDatasetVersionRowSchema.nullable(), { auth: "admin" }),
49799
+ /** Every version without its frame list, newest first. */
49800
+ listDatasetVersions: method(object({}), array(RetrainDatasetVersionSchema).readonly(), { auth: "admin" }),
49801
+ findDatasetVersionIdByName: method(object({ name: string() }), object({ id: string().nullable() }), { auth: "admin" }),
49802
+ removeDatasetVersion: method(IdInput, object({ removed: boolean() }), {
49803
+ kind: "mutation",
49804
+ auth: "admin"
49805
+ }),
49806
+ listBaseModels: method(object({}), array(TrainingBaseModelSchema).readonly(), { auth: "admin" }),
49807
+ /** Split, estimate, defaults and any named refusal — nothing is started. */
49808
+ planJob: method(TrainingJobRequestSchema, TrainingJobPlanSchema, {
49809
+ auth: "admin",
49810
+ timeoutMs: 6e4
49811
+ }),
49812
+ /**
49813
+ * Start a job. The same `idempotencyKey` returns the job it already
49814
+ * started. Answers at once (`uploading`); the upload and the submit run in
49815
+ * the background and the job record says how far they got.
49816
+ */
49817
+ startJob: method(TrainingJobRequestSchema.extend({
49818
+ name: string().min(1).max(120),
49819
+ maxCostUsd: number().positive(),
49820
+ maxRuntimeSec: number().int().positive(),
49821
+ idempotencyKey: string().min(8).max(80)
49822
+ }), discriminatedUnion("kind", [object({
49823
+ kind: literal("started"),
49824
+ job: TrainingJobSchema
49825
+ }), object({
49826
+ kind: literal("refused"),
49827
+ reason: TrainingRefusalReasonSchema,
49828
+ detail: string()
49829
+ })]), {
49830
+ kind: "mutation",
49831
+ auth: "admin",
49832
+ timeoutMs: 12e4
49833
+ }),
49834
+ listJobs: method(object({}), array(TrainingJobSchema).readonly(), { auth: "admin" }),
49835
+ getJob: method(IdInput, TrainingJobSchema.nullable(), { auth: "admin" }),
49836
+ cancelJob: method(IdInput, TrainingJobSchema, {
49837
+ kind: "mutation",
49838
+ auth: "admin",
49839
+ timeoutMs: 12e4
49840
+ }),
49841
+ /** The verified `result.json` of a job in `ready` or later; null before. */
49842
+ getJobResult: method(IdInput, TrainingResultSchema.nullable(), { auth: "admin" }),
49843
+ /** Hand the verified bundle to Model Studio; optionally canary right after. */
49844
+ registerResult: method(IdInput.extend({ canaryDeviceIds: array(number().int()).readonly() }), TrainingJobSchema, {
49845
+ kind: "mutation",
49846
+ auth: "admin",
49847
+ timeoutMs: 30 * 6e4
49848
+ }),
49849
+ /** Pin the registered model on these cameras, remembering what it replaced. */
49850
+ canaryResult: method(IdInput.extend({ deviceIds: array(number().int()).min(1).readonly() }), TrainingJobSchema, {
49851
+ kind: "mutation",
49852
+ auth: "admin",
49853
+ timeoutMs: 12e4
49854
+ }),
49855
+ /** Put every canary camera back exactly as it was. */
49856
+ rollbackCanary: method(IdInput, TrainingJobSchema, {
49857
+ kind: "mutation",
49858
+ auth: "admin",
49859
+ timeoutMs: 12e4
49860
+ }),
49861
+ /** Delete the staged artefacts of an unregistered result. */
49862
+ discardResult: method(IdInput, TrainingJobSchema, {
49863
+ kind: "mutation",
49864
+ auth: "admin"
49865
+ })
49866
+ }
49867
+ };
49868
+ /**
48462
49869
  * Frozen unit → spec table. `•` in the doc marks each dimension's canonical
48463
49870
  * unit (`factor: 1, offset: 0`). °F derives from `°C = (°F − 32) × 5/9` ⇒
48464
49871
  * `factor = 5/9`, `offset = -160/9` (kept as exact expressions, not rounded
@@ -49397,6 +50804,12 @@ Object.freeze({
49397
50804
  addonId: null,
49398
50805
  access: "create"
49399
50806
  },
50807
+ "backup.checkBackupKey": {
50808
+ capName: "backup",
50809
+ capScope: "system",
50810
+ addonId: null,
50811
+ access: "create"
50812
+ },
49400
50813
  "backup.delete": {
49401
50814
  capName: "backup",
49402
50815
  capScope: "system",
@@ -49409,6 +50822,18 @@ Object.freeze({
49409
50822
  addonId: null,
49410
50823
  access: "delete"
49411
50824
  },
50825
+ "backup.disableEncryption": {
50826
+ capName: "backup",
50827
+ capScope: "system",
50828
+ addonId: null,
50829
+ access: "create"
50830
+ },
50831
+ "backup.getEncryption": {
50832
+ capName: "backup",
50833
+ capScope: "system",
50834
+ addonId: null,
50835
+ access: "view"
50836
+ },
49412
50837
  "backup.getEntries": {
49413
50838
  capName: "backup",
49414
50839
  capScope: "system",
@@ -49463,6 +50888,12 @@ Object.freeze({
49463
50888
  addonId: null,
49464
50889
  access: "create"
49465
50890
  },
50891
+ "backup.setupEncryption": {
50892
+ capName: "backup",
50893
+ capScope: "system",
50894
+ addonId: null,
50895
+ access: "create"
50896
+ },
49466
50897
  "backup.trigger": {
49467
50898
  capName: "backup",
49468
50899
  capScope: "system",
@@ -50015,6 +51446,12 @@ Object.freeze({
50015
51446
  addonId: null,
50016
51447
  access: "create"
50017
51448
  },
51449
+ "customModelRegistry.importModelBundle": {
51450
+ capName: "custom-model-registry",
51451
+ capScope: "system",
51452
+ addonId: null,
51453
+ access: "create"
51454
+ },
50018
51455
  "customModelRegistry.listModels": {
50019
51456
  capName: "custom-model-registry",
50020
51457
  capScope: "system",
@@ -51455,6 +52892,12 @@ Object.freeze({
51455
52892
  addonId: null,
51456
52893
  access: "view"
51457
52894
  },
52895
+ "keychainAdmin.acknowledgeReset": {
52896
+ capName: "keychain-admin",
52897
+ capScope: "system",
52898
+ addonId: null,
52899
+ access: "create"
52900
+ },
51458
52901
  "keychainAdmin.deleteOrphans": {
51459
52902
  capName: "keychain-admin",
51460
52903
  capScope: "system",
@@ -51491,6 +52934,12 @@ Object.freeze({
51491
52934
  addonId: null,
51492
52935
  access: "delete"
51493
52936
  },
52937
+ "keychainAdmin.resetReport": {
52938
+ capName: "keychain-admin",
52939
+ capScope: "system",
52940
+ addonId: null,
52941
+ access: "delete"
52942
+ },
51494
52943
  "keychainAdmin.reveal": {
51495
52944
  capName: "keychain-admin",
51496
52945
  capScope: "system",
@@ -53237,6 +54686,12 @@ Object.freeze({
53237
54686
  addonId: null,
53238
54687
  access: "view"
53239
54688
  },
54689
+ "pipelineAnalytics.offerRetrainArchive": {
54690
+ capName: "pipeline-analytics",
54691
+ capScope: "device",
54692
+ addonId: null,
54693
+ access: "create"
54694
+ },
53240
54695
  "pipelineAnalytics.ownersWithMedia": {
53241
54696
  capName: "pipeline-analytics",
53242
54697
  capScope: "device",
@@ -55775,6 +57230,174 @@ Object.freeze({
55775
57230
  addonId: null,
55776
57231
  access: "view"
55777
57232
  },
57233
+ "training.canaryResult": {
57234
+ capName: "training",
57235
+ capScope: "system",
57236
+ addonId: null,
57237
+ access: "create"
57238
+ },
57239
+ "training.cancelJob": {
57240
+ capName: "training",
57241
+ capScope: "system",
57242
+ addonId: null,
57243
+ access: "create"
57244
+ },
57245
+ "training.discardResult": {
57246
+ capName: "training",
57247
+ capScope: "system",
57248
+ addonId: null,
57249
+ access: "create"
57250
+ },
57251
+ "training.findDatasetVersionIdByName": {
57252
+ capName: "training",
57253
+ capScope: "system",
57254
+ addonId: null,
57255
+ access: "view"
57256
+ },
57257
+ "training.getDatasetVersion": {
57258
+ capName: "training",
57259
+ capScope: "system",
57260
+ addonId: null,
57261
+ access: "view"
57262
+ },
57263
+ "training.getJob": {
57264
+ capName: "training",
57265
+ capScope: "system",
57266
+ addonId: null,
57267
+ access: "view"
57268
+ },
57269
+ "training.getJobResult": {
57270
+ capName: "training",
57271
+ capScope: "system",
57272
+ addonId: null,
57273
+ access: "view"
57274
+ },
57275
+ "training.listBaseModels": {
57276
+ capName: "training",
57277
+ capScope: "system",
57278
+ addonId: null,
57279
+ access: "view"
57280
+ },
57281
+ "training.listDatasetVersions": {
57282
+ capName: "training",
57283
+ capScope: "system",
57284
+ addonId: null,
57285
+ access: "view"
57286
+ },
57287
+ "training.listJobs": {
57288
+ capName: "training",
57289
+ capScope: "system",
57290
+ addonId: null,
57291
+ access: "view"
57292
+ },
57293
+ "training.planJob": {
57294
+ capName: "training",
57295
+ capScope: "system",
57296
+ addonId: null,
57297
+ access: "view"
57298
+ },
57299
+ "training.putDatasetVersion": {
57300
+ capName: "training",
57301
+ capScope: "system",
57302
+ addonId: null,
57303
+ access: "create"
57304
+ },
57305
+ "training.registerResult": {
57306
+ capName: "training",
57307
+ capScope: "system",
57308
+ addonId: null,
57309
+ access: "create"
57310
+ },
57311
+ "training.removeDatasetVersion": {
57312
+ capName: "training",
57313
+ capScope: "system",
57314
+ addonId: null,
57315
+ access: "delete"
57316
+ },
57317
+ "training.rollbackCanary": {
57318
+ capName: "training",
57319
+ capScope: "system",
57320
+ addonId: null,
57321
+ access: "create"
57322
+ },
57323
+ "training.startJob": {
57324
+ capName: "training",
57325
+ capScope: "system",
57326
+ addonId: null,
57327
+ access: "create"
57328
+ },
57329
+ "trainingProvider.cancelJob": {
57330
+ capName: "training-provider",
57331
+ capScope: "system",
57332
+ addonId: null,
57333
+ access: "create"
57334
+ },
57335
+ "trainingProvider.cleanupJob": {
57336
+ capName: "training-provider",
57337
+ capScope: "system",
57338
+ addonId: null,
57339
+ access: "create"
57340
+ },
57341
+ "trainingProvider.describe": {
57342
+ capName: "training-provider",
57343
+ capScope: "system",
57344
+ addonId: null,
57345
+ access: "view"
57346
+ },
57347
+ "trainingProvider.estimateJob": {
57348
+ capName: "training-provider",
57349
+ capScope: "system",
57350
+ addonId: null,
57351
+ access: "view"
57352
+ },
57353
+ "trainingProvider.getJob": {
57354
+ capName: "training-provider",
57355
+ capScope: "system",
57356
+ addonId: null,
57357
+ access: "view"
57358
+ },
57359
+ "trainingProvider.listJobEvents": {
57360
+ capName: "training-provider",
57361
+ capScope: "system",
57362
+ addonId: null,
57363
+ access: "view"
57364
+ },
57365
+ "trainingProvider.listJobs": {
57366
+ capName: "training-provider",
57367
+ capScope: "system",
57368
+ addonId: null,
57369
+ access: "view"
57370
+ },
57371
+ "trainingProvider.offerArtifact": {
57372
+ capName: "training-provider",
57373
+ capScope: "system",
57374
+ addonId: null,
57375
+ access: "create"
57376
+ },
57377
+ "trainingProvider.readResult": {
57378
+ capName: "training-provider",
57379
+ capScope: "system",
57380
+ addonId: null,
57381
+ access: "create"
57382
+ },
57383
+ "trainingProvider.submitJob": {
57384
+ capName: "training-provider",
57385
+ capScope: "system",
57386
+ addonId: null,
57387
+ access: "create"
57388
+ },
57389
+ "trainingProvider.uploadDataset": {
57390
+ capName: "training-provider",
57391
+ capScope: "system",
57392
+ addonId: null,
57393
+ access: "create"
57394
+ },
57395
+ "trainingProvider.validateCredentials": {
57396
+ capName: "training-provider",
57397
+ capScope: "system",
57398
+ addonId: null,
57399
+ access: "create"
57400
+ },
55778
57401
  "turnProvider.getTurnServers": {
55779
57402
  capName: "turn-provider",
55780
57403
  capScope: "system",
@@ -55799,12 +57422,6 @@ Object.freeze({
55799
57422
  addonId: null,
55800
57423
  access: "create"
55801
57424
  },
55802
- "userManagement.createApiKey": {
55803
- capName: "user-management",
55804
- capScope: "system",
55805
- addonId: null,
55806
- access: "create"
55807
- },
55808
57425
  "userManagement.createScopedToken": {
55809
57426
  capName: "user-management",
55810
57427
  capScope: "system",
@@ -55841,12 +57458,6 @@ Object.freeze({
55841
57458
  addonId: null,
55842
57459
  access: "view"
55843
57460
  },
55844
- "userManagement.linkExternalIdentity": {
55845
- capName: "user-management",
55846
- capScope: "system",
55847
- addonId: null,
55848
- access: "create"
55849
- },
55850
57461
  "userManagement.listApiKeys": {
55851
57462
  capName: "user-management",
55852
57463
  capScope: "system",
@@ -55949,12 +57560,6 @@ Object.freeze({
55949
57560
  addonId: null,
55950
57561
  access: "create"
55951
57562
  },
55952
- "userManagement.validateApiKey": {
55953
- capName: "user-management",
55954
- capScope: "system",
55955
- addonId: null,
55956
- access: "view"
55957
- },
55958
57563
  "userManagement.validateCredentials": {
55959
57564
  capName: "user-management",
55960
57565
  capScope: "system",
@@ -57868,6 +59473,8 @@ var ALL_CAPABILITY_DEFINITIONS = [
57868
59473
  temperatureSensorCapability,
57869
59474
  terminalSessionCapability,
57870
59475
  toastCapability,
59476
+ trainingCapability,
59477
+ trainingProviderCapability,
57871
59478
  turnProviderCapability,
57872
59479
  updateCapability,
57873
59480
  userManagementCapability,
@@ -60246,6 +61853,11 @@ Object.freeze({
60246
61853
  form: "single",
60247
61854
  optional: false
60248
61855
  }],
61856
+ "training.canaryResult": [{
61857
+ name: "deviceIds",
61858
+ form: "array",
61859
+ optional: false
61860
+ }],
60249
61861
  "update.getStatus": [{
60250
61862
  name: "deviceId",
60251
61863
  form: "single",