@camstack/addon-post-analysis 1.2.347 → 1.2.349

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 (15) hide show
  1. package/dist/{clip-model-registry-BftmbgcV.mjs → clip-model-registry-CC-BJYiK.mjs} +1786 -148
  2. package/dist/{clip-model-registry--UsI8Ud4.js → clip-model-registry-DI12tTgY.js} +1786 -148
  3. package/dist/embedding-encoder/index.js +1 -1
  4. package/dist/embedding-encoder/index.mjs +1 -1
  5. package/dist/pipeline-analytics/_stub.js +2 -2
  6. package/dist/pipeline-analytics/{_virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-DuQPp3dT.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_analytics_widgets-BYsMflvm.mjs} +3 -3
  7. package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-Du_tzgi2.mjs +26 -0
  8. package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-CQOJKiwa.mjs +26 -0
  9. package/dist/pipeline-analytics/{hostInit-BDQ6oQ7b.mjs → hostInit-Cpi67Icm.mjs} +3 -3
  10. package/dist/pipeline-analytics/index.js +575 -259
  11. package/dist/pipeline-analytics/index.mjs +575 -259
  12. package/dist/pipeline-analytics/remoteEntry.js +1 -1
  13. package/package.json +1 -1
  14. package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-4Fu7jNn9.mjs +0 -26
  15. package/dist/pipeline-analytics/_virtual_mf___mfe_internal__addon_pipeline_analytics_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-D5IzYeGQ.mjs +0 -26
@@ -5449,7 +5449,7 @@ var ZodIssueCode = {
5449
5449
  var ZodFirstPartyTypeKind;
5450
5450
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5451
5451
  //#endregion
5452
- //#region ../types/dist/sleep-DujUvOcb.mjs
5452
+ //#region ../types/dist/sleep-r3RWkGVx.mjs
5453
5453
  /**
5454
5454
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5455
5455
  * window to float samples (D455).
@@ -5566,7 +5566,7 @@ function isKeychainStoredField(field) {
5566
5566
  var SECRET_CLEAR = { $secretClear: true };
5567
5567
  /** The `'***'` token D634 redaction writes for non-admins. */
5568
5568
  var LEGACY_DEVICE_REDACTION = "***";
5569
- function isRecord$1(value) {
5569
+ function isRecord$2(value) {
5570
5570
  return typeof value === "object" && value !== null && !Array.isArray(value);
5571
5571
  }
5572
5572
  function makeSecretMarker(ref) {
@@ -5577,12 +5577,12 @@ function makeSecretMarker(ref) {
5577
5577
  }
5578
5578
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5579
5579
  function isSecretMarker(value) {
5580
- if (!isRecord$1(value)) return false;
5580
+ if (!isRecord$2(value)) return false;
5581
5581
  const ref = value["$secret"];
5582
5582
  return typeof ref === "string" && ref.length > 0;
5583
5583
  }
5584
5584
  function isSecretClear(value) {
5585
- return isRecord$1(value) && value["$secretClear"] === true;
5585
+ return isRecord$2(value) && value["$secretClear"] === true;
5586
5586
  }
5587
5587
  /**
5588
5588
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6098,6 +6098,13 @@ function globalSecretScope() {
6098
6098
  function encodeSegment(value) {
6099
6099
  return encodeURIComponent(value);
6100
6100
  }
6101
+ function decodeSegment(value) {
6102
+ try {
6103
+ return decodeURIComponent(value);
6104
+ } catch {
6105
+ return null;
6106
+ }
6107
+ }
6101
6108
  /**
6102
6109
  * The field path of a value inside an array item, addressed by the item's id:
6103
6110
  * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
@@ -6106,6 +6113,75 @@ function encodeSegment(value) {
6106
6113
  function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6107
6114
  return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6108
6115
  }
6116
+ function parseScope(segments) {
6117
+ switch (segments[0]) {
6118
+ case "global": return {
6119
+ scope: GLOBAL_SCOPE,
6120
+ used: 1
6121
+ };
6122
+ case "node": {
6123
+ const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6124
+ return nodeId === null || nodeId.length === 0 ? null : {
6125
+ scope: {
6126
+ kind: "node",
6127
+ nodeId
6128
+ },
6129
+ used: 2
6130
+ };
6131
+ }
6132
+ case "device": {
6133
+ const raw = segments[1];
6134
+ if (raw === void 0 || !/^\d+$/.test(raw)) return null;
6135
+ return {
6136
+ scope: {
6137
+ kind: "device",
6138
+ deviceId: Number(raw)
6139
+ },
6140
+ used: 2
6141
+ };
6142
+ }
6143
+ case "integration": {
6144
+ const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6145
+ return id === null || id.length === 0 ? null : {
6146
+ scope: {
6147
+ kind: "integration",
6148
+ integrationId: id
6149
+ },
6150
+ used: 2
6151
+ };
6152
+ }
6153
+ case "row": {
6154
+ const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6155
+ const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
6156
+ if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
6157
+ return {
6158
+ scope: {
6159
+ kind: "row",
6160
+ collection,
6161
+ rowId
6162
+ },
6163
+ used: 3
6164
+ };
6165
+ }
6166
+ default: return null;
6167
+ }
6168
+ }
6169
+ /** Take a ref apart; `null` when it is not a well-formed ref. */
6170
+ function parseSecretRef(ref) {
6171
+ if (!ref.startsWith("secret://")) return null;
6172
+ const segments = ref.slice(9).split("/");
6173
+ const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
6174
+ if (owner === null || owner.length === 0) return null;
6175
+ const parsed = parseScope(segments.slice(1));
6176
+ if (parsed === null) return null;
6177
+ const fieldPath = segments.slice(1 + parsed.used).join("/");
6178
+ if (fieldPath.length === 0) return null;
6179
+ return {
6180
+ owner,
6181
+ scope: parsed.scope,
6182
+ fieldPath
6183
+ };
6184
+ }
6109
6185
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6110
6186
  var KeychainWriteRefusedError = class extends Error {
6111
6187
  fieldPath;
@@ -6116,7 +6192,7 @@ var KeychainWriteRefusedError = class extends Error {
6116
6192
  }
6117
6193
  };
6118
6194
  var KEEP = { kind: "keep" };
6119
- function isRecord(value) {
6195
+ function isRecord$1(value) {
6120
6196
  return typeof value === "object" && value !== null && !Array.isArray(value);
6121
6197
  }
6122
6198
  function defaultMintId() {
@@ -6129,7 +6205,7 @@ function collectSecretMarkerRefs(value, out = []) {
6129
6205
  return out;
6130
6206
  }
6131
6207
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6132
- else if (isRecord(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6208
+ else if (isRecord$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6133
6209
  return out;
6134
6210
  }
6135
6211
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6184,7 +6260,7 @@ function rowId(row, idKey) {
6184
6260
  return null;
6185
6261
  }
6186
6262
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6187
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord) : [];
6263
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1) : [];
6188
6264
  if (!Array.isArray(incoming)) {
6189
6265
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6190
6266
  return {
@@ -6200,7 +6276,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6200
6276
  const kept = /* @__PURE__ */ new Set();
6201
6277
  const rows = [];
6202
6278
  for (const row of incoming) {
6203
- if (!isRecord(row)) {
6279
+ if (!isRecord$1(row)) {
6204
6280
  rows.push(row);
6205
6281
  continue;
6206
6282
  }
@@ -6225,7 +6301,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6225
6301
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6226
6302
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6227
6303
  case "object": {
6228
- if (!isRecord(incoming)) {
6304
+ if (!isRecord$1(incoming)) {
6229
6305
  if (incoming === void 0) return KEEP;
6230
6306
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6231
6307
  return {
@@ -6233,7 +6309,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6233
6309
  value: incoming
6234
6310
  };
6235
6311
  }
6236
- const storedObj = isRecord(stored) ? stored : {};
6312
+ const storedObj = isRecord$1(stored) ? stored : {};
6237
6313
  return {
6238
6314
  kind: "value",
6239
6315
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6292,12 +6368,19 @@ async function transformSecretWrite(input) {
6292
6368
  }
6293
6369
  };
6294
6370
  }
6371
+ /** Is `ref` one of `owner`'s refs? */
6372
+ function isSecretRefOwnedBy(ref, owner) {
6373
+ return parseSecretRef(ref)?.owner === owner;
6374
+ }
6295
6375
  /**
6296
6376
  * Replace every marker in `value` with its keychain value. Returns the SAME
6297
6377
  * reference when there is no marker (no allocation, no keychain call).
6298
6378
  */
6299
- async function resolveSecretMarkers(value, secrets) {
6300
- const refs = collectSecretMarkerRefs(value);
6379
+ async function resolveSecretMarkers(value, secrets, options = {}) {
6380
+ const keepMarker = options.unresolved === "keep-marker";
6381
+ const owner = options.ownedBy;
6382
+ const inScope = (ref) => owner === void 0 || isSecretRefOwnedBy(ref, owner);
6383
+ const refs = collectSecretMarkerRefs(value).filter(inScope);
6301
6384
  if (refs.length === 0) return {
6302
6385
  value,
6303
6386
  unresolved: []
@@ -6321,10 +6404,18 @@ async function resolveSecretMarkers(value, secrets) {
6321
6404
  }
6322
6405
  const substitute = (v) => {
6323
6406
  if (isSecretMarker(v)) {
6407
+ if (!inScope(v.$secret)) return {
6408
+ keep: true,
6409
+ value: v
6410
+ };
6324
6411
  const answer = answers[v.$secret];
6325
- return answer?.kind === "value" ? {
6412
+ if (answer?.kind === "value") return {
6326
6413
  keep: true,
6327
6414
  value: answer.value
6415
+ };
6416
+ return keepMarker ? {
6417
+ keep: true,
6418
+ value: v
6328
6419
  } : {
6329
6420
  keep: false,
6330
6421
  value: void 0
@@ -6341,7 +6432,7 @@ async function resolveSecretMarkers(value, secrets) {
6341
6432
  value: items
6342
6433
  };
6343
6434
  }
6344
- if (isRecord(v)) {
6435
+ if (isRecord$1(v)) {
6345
6436
  const out = {};
6346
6437
  for (const [k, child] of Object.entries(v)) {
6347
6438
  const s = substitute(child);
@@ -6362,14 +6453,152 @@ async function resolveSecretMarkers(value, secrets) {
6362
6453
  unresolved
6363
6454
  };
6364
6455
  }
6365
- function touchesTree(tree, patch) {
6366
- if (tree.size === 0) return false;
6367
- for (const key of Object.keys(patch)) {
6368
- const at = key.indexOf("@");
6369
- if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6456
+ /** An addon tried to replace a stored secret it could not read. Nothing was written. */
6457
+ var SecretOverwriteRefusedError = class extends Error {
6458
+ ref;
6459
+ reason;
6460
+ constructor(ref, reason) {
6461
+ 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.`);
6462
+ this.ref = ref;
6463
+ this.reason = reason;
6464
+ this.name = "SecretOverwriteRefusedError";
6465
+ }
6466
+ };
6467
+ function isRecord(value) {
6468
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6469
+ }
6470
+ function resolvedValue(pass, marker) {
6471
+ const answer = pass.answers[marker.$secret];
6472
+ return answer?.kind === "value" ? answer.value : null;
6473
+ }
6474
+ async function atMarker(pass, incoming, stored) {
6475
+ if (incoming === null) return stored;
6476
+ if (typeof incoming !== "string") return incoming;
6477
+ if (incoming === resolvedValue(pass, stored)) return stored;
6478
+ const intent = classifySecretWrite(incoming);
6479
+ if (intent.kind !== "set") return stored;
6480
+ const ref = stored.$secret;
6481
+ if (!isSecretRefOwnedBy(ref, pass.secrets.owner)) return incoming;
6482
+ const answer = pass.answers[ref];
6483
+ 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);
6484
+ try {
6485
+ await pass.secrets.put(ref, intent.value);
6486
+ } catch (err) {
6487
+ throw new KeychainWriteRefusedError(ref, err);
6488
+ }
6489
+ pass.changedRefs.push(ref);
6490
+ return stored;
6491
+ }
6492
+ function inArray(pass, incoming, stored) {
6493
+ return incoming.map((item, index) => {
6494
+ const twin = stored[index];
6495
+ if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6496
+ if (isRecord(item) && isRecord(twin)) return inArrayRow(pass, item, twin);
6497
+ if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6498
+ return item;
6499
+ });
6500
+ }
6501
+ function inArrayRow(pass, incoming, stored) {
6502
+ const out = { ...incoming };
6503
+ for (const [key, value] of Object.entries(incoming)) {
6504
+ const twin = stored[key];
6505
+ if (isSecretMarker(twin)) {
6506
+ if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6507
+ } else if (isRecord(value) && isRecord(twin)) out[key] = inArrayRow(pass, value, twin);
6508
+ else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6509
+ }
6510
+ return out;
6511
+ }
6512
+ async function walk(pass, incoming, stored) {
6513
+ if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6514
+ if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6515
+ if (!isRecord(incoming) || !isRecord(stored)) return incoming;
6516
+ const out = { ...incoming };
6517
+ for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
6518
+ return out;
6519
+ }
6520
+ /** Restore markers a write-back carries as values. See the file doc. */
6521
+ async function restoreUnchangedSecrets(input) {
6522
+ const refs = [];
6523
+ for (const key of Object.keys(input.patch)) collectSecretMarkerRefs(input.stored[key], refs);
6524
+ const owned = refs.filter((ref) => isSecretRefOwnedBy(ref, input.secrets.owner));
6525
+ if (owned.length === 0) return {
6526
+ patch: input.patch,
6527
+ changedRefs: []
6528
+ };
6529
+ const pass = {
6530
+ secrets: input.secrets,
6531
+ answers: await input.secrets.resolve([...new Set(owned)]),
6532
+ operatorWrite: input.operatorWrite,
6533
+ changedRefs: []
6534
+ };
6535
+ const out = {};
6536
+ for (const [key, value] of Object.entries(input.patch)) out[key] = await walk(pass, value, input.stored[key]);
6537
+ return {
6538
+ patch: out,
6539
+ changedRefs: pass.changedRefs
6540
+ };
6541
+ }
6542
+ /** Structural equality over JSON-shaped values (key order does not matter). */
6543
+ function isJsonEqual(a, b) {
6544
+ if (Object.is(a, b)) return true;
6545
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6546
+ if (isRecord(a) && isRecord(b)) {
6547
+ const keys = Object.keys(a);
6548
+ if (keys.length !== Object.keys(b).length) return false;
6549
+ return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
6370
6550
  }
6371
6551
  return false;
6372
6552
  }
6553
+ /** The patch without the keys whose value already equals the stored one. */
6554
+ function dropUnchangedKeys(patch, stored) {
6555
+ const out = {};
6556
+ for (const [key, value] of Object.entries(patch)) {
6557
+ if (Object.prototype.hasOwnProperty.call(stored, key) && isJsonEqual(value, stored[key])) continue;
6558
+ out[key] = value;
6559
+ }
6560
+ return out;
6561
+ }
6562
+ /** The top-level keys of a blob that hold at least one of `owner`'s markers. */
6563
+ function markerKeysOf(blob, owner) {
6564
+ const keys = /* @__PURE__ */ new Set();
6565
+ for (const [key, value] of Object.entries(blob)) if (collectSecretMarkerRefs(value).some((ref) => isSecretRefOwnedBy(ref, owner))) keys.add(key);
6566
+ return keys;
6567
+ }
6568
+ function nodeFromStored(value, owner) {
6569
+ if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6570
+ if (!isRecord(value)) return null;
6571
+ const children = /* @__PURE__ */ new Map();
6572
+ for (const [key, child] of Object.entries(value)) {
6573
+ const node = nodeFromStored(child, owner);
6574
+ if (node !== null) children.set(key, node);
6575
+ }
6576
+ return children.size > 0 ? {
6577
+ kind: "object",
6578
+ children
6579
+ } : null;
6580
+ }
6581
+ /**
6582
+ * The declared secret tree, widened by every place the STORED blob holds a
6583
+ * marker under one of `keys` — so a marker the schema no longer declares (or
6584
+ * never declared: Wyze before b4906cec6) still gets the save path's
6585
+ * KEEP / SET / CLEAR semantics instead of being overwritten by whatever the
6586
+ * addon writes. Markers inside arrays are not added: a row has no id field to
6587
+ * match by unless the schema declares one. Only `owner`'s markers count: a
6588
+ * builtin that keeps another addon's marker (device-manager) never takes it
6589
+ * over.
6590
+ */
6591
+ function widenTreeWithStoredMarkers(declared, stored, keys, owner) {
6592
+ const added = /* @__PURE__ */ new Map();
6593
+ for (const key of keys) {
6594
+ const at = key.indexOf("@");
6595
+ const base = at > 0 ? key.slice(0, at) : key;
6596
+ if (declared.has(base) || added.has(base)) continue;
6597
+ const node = nodeFromStored(stored[key], owner);
6598
+ if (node !== null) added.set(base, node);
6599
+ }
6600
+ return added.size === 0 ? declared : new Map([...declared, ...added]);
6601
+ }
6373
6602
  /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6374
6603
  async function readStoredAddonBlob(raw) {
6375
6604
  const threeWay = raw.readAddonStoreResult;
@@ -6378,7 +6607,41 @@ async function readStoredAddonBlob(raw) {
6378
6607
  if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6379
6608
  return result.kind === "missing" ? {} : result.value;
6380
6609
  }
6381
- function createSecretAwareSettings(raw, opts) {
6610
+ function touchesTree(tree, patch) {
6611
+ if (tree.size === 0) return false;
6612
+ for (const key of Object.keys(patch)) {
6613
+ const at = key.indexOf("@");
6614
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6615
+ }
6616
+ return false;
6617
+ }
6618
+ /**
6619
+ * Which top-level keys of each store held markers when last seen. `undefined`
6620
+ * for a store not seen yet: its first write reads it, to be safe.
6621
+ */
6622
+ var MarkerKeyIndex = class {
6623
+ owner;
6624
+ byStore = /* @__PURE__ */ new Map();
6625
+ constructor(owner) {
6626
+ this.owner = owner;
6627
+ }
6628
+ seen(store, blob) {
6629
+ this.byStore.set(store, markerKeysOf(blob, this.owner));
6630
+ }
6631
+ wrote(store, patch) {
6632
+ const keys = this.byStore.get(store);
6633
+ if (keys === void 0) return;
6634
+ const now = markerKeysOf(patch, this.owner);
6635
+ for (const key of Object.keys(patch)) if (now.has(key)) keys.add(key);
6636
+ else keys.delete(key);
6637
+ }
6638
+ mayHoldMarkers(store, patch) {
6639
+ const keys = this.byStore.get(store);
6640
+ if (keys === void 0) return true;
6641
+ return Object.keys(patch).some((key) => keys.has(key));
6642
+ }
6643
+ };
6644
+ function createHandle(raw, opts) {
6382
6645
  const chains = /* @__PURE__ */ new Map();
6383
6646
  const serialize = (key, fn) => {
6384
6647
  const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
@@ -6389,46 +6652,130 @@ function createSecretAwareSettings(raw, opts) {
6389
6652
  });
6390
6653
  return next;
6391
6654
  };
6392
- const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6393
- if (!touchesTree(tree, patch)) return rawWrite(patch);
6394
- return serialize(chainKey, async () => {
6655
+ const index = new MarkerKeyIndex(opts.secrets.owner);
6656
+ const resolveRead = async (store, blob) => {
6657
+ index.seen(store, blob);
6658
+ const { value, unresolved } = await resolveSecretMarkers(blob, opts.secrets, {
6659
+ unresolved: "keep-marker",
6660
+ ownedBy: opts.secrets.owner
6661
+ });
6662
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6663
+ return value;
6664
+ };
6665
+ const write = async (store, declared, scope, patch, readStored, rawWrite) => {
6666
+ if (!touchesTree(declared, patch) && !index.mayHoldMarkers(store, patch)) {
6667
+ await rawWrite(patch);
6668
+ index.wrote(store, patch);
6669
+ return { changed: true };
6670
+ }
6671
+ return serialize(store, async () => {
6395
6672
  const stored = await readStored();
6673
+ index.seen(store, stored);
6674
+ const operatorWrite = opts.isOperatorWrite?.() === true;
6675
+ const restored = await restoreUnchangedSecrets({
6676
+ patch,
6677
+ stored,
6678
+ secrets: opts.secrets,
6679
+ operatorWrite
6680
+ });
6396
6681
  const result = await transformSecretWrite({
6397
- tree,
6682
+ tree: widenTreeWithStoredMarkers(declared, stored, Object.keys(restored.patch), opts.secrets.owner),
6398
6683
  secrets: opts.secrets,
6399
- patch,
6684
+ patch: restored.patch,
6400
6685
  stored,
6401
6686
  ...scope !== void 0 ? { scope } : {},
6402
- operatorWrite: opts.isOperatorWrite?.() === true
6687
+ operatorWrite
6403
6688
  });
6404
- if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6689
+ const effective = dropUnchangedKeys(result.patch, stored);
6690
+ const wroteBlob = Object.keys(effective).length > 0;
6691
+ if (wroteBlob) {
6692
+ await rawWrite(effective);
6693
+ index.wrote(store, effective);
6694
+ }
6405
6695
  const { orphaned } = await result.afterWrite();
6406
6696
  if (orphaned.length > 0) opts.onOrphaned(orphaned);
6697
+ return { changed: wroteBlob || restored.changedRefs.length > 0 };
6407
6698
  });
6408
6699
  };
6409
- const wrapped = {
6410
- writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6411
- writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6412
- kind: "device",
6413
- deviceId
6414
- }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6700
+ const writeAddon = (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p));
6701
+ const readAddonStoreResult = raw.readAddonStoreResult;
6702
+ const readAddonStoreKeyResult = raw.readAddonStoreKeyResult;
6703
+ const readDeviceStoreBatch = raw.readDeviceStoreBatch;
6704
+ const overrides = {
6705
+ readAddonStore: async () => resolveRead("addon", await raw.readAddonStore()),
6706
+ ...readAddonStoreResult !== void 0 ? { readAddonStoreResult: async () => {
6707
+ const result = await readAddonStoreResult.call(raw);
6708
+ return result.kind === "value" ? {
6709
+ kind: "value",
6710
+ value: await resolveRead("addon", result.value)
6711
+ } : result;
6712
+ } } : {},
6713
+ ...readAddonStoreKeyResult !== void 0 ? { readAddonStoreKeyResult: async (key) => {
6714
+ const result = await readAddonStoreKeyResult.call(raw, key);
6715
+ if (result.kind !== "present") return result;
6716
+ const { value, unresolved } = await resolveSecretMarkers({ [key]: result.value }, opts.secrets, {
6717
+ unresolved: "keep-marker",
6718
+ ownedBy: opts.secrets.owner
6719
+ });
6720
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6721
+ return {
6722
+ kind: "present",
6723
+ value: value[key]
6724
+ };
6725
+ } } : {},
6726
+ readDeviceStore: async (deviceId) => resolveRead(`device:${deviceId}`, await raw.readDeviceStore(deviceId)),
6727
+ ...readDeviceStoreBatch !== void 0 ? { readDeviceStoreBatch: async (deviceIds) => {
6728
+ const rows = await readDeviceStoreBatch.call(raw, deviceIds);
6729
+ const out = /* @__PURE__ */ new Map();
6730
+ for (const [deviceId, blob] of rows) out.set(deviceId, await resolveRead(`device:${deviceId}`, blob));
6731
+ return out;
6732
+ } } : {},
6733
+ writeAddonStore: async (patch) => {
6734
+ await writeAddon(patch);
6735
+ },
6736
+ writeDeviceStore: async (deviceId, patch) => {
6737
+ await write(`device:${deviceId}`, opts.deviceTree(), {
6738
+ kind: "device",
6739
+ deviceId
6740
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p));
6741
+ }
6742
+ };
6743
+ return {
6744
+ settings: new Proxy(raw, { get(target, prop, receiver) {
6745
+ if (typeof prop === "string" && Object.prototype.hasOwnProperty.call(overrides, prop)) return Reflect.get(overrides, prop);
6746
+ const value = Reflect.get(target, prop, receiver);
6747
+ return typeof value === "function" ? value.bind(target) : value;
6748
+ } }),
6749
+ raw: {
6750
+ readAddonStore: async () => {
6751
+ const blob = await raw.readAddonStore();
6752
+ index.seen("addon", blob);
6753
+ return blob;
6754
+ },
6755
+ readDeviceStore: async (deviceId) => {
6756
+ const blob = await raw.readDeviceStore(deviceId);
6757
+ index.seen(`device:${deviceId}`, blob);
6758
+ return blob;
6759
+ }
6760
+ },
6761
+ writeAddonStore: writeAddon
6415
6762
  };
6416
- return new Proxy(raw, { get(target, prop, receiver) {
6417
- if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6418
- if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6419
- const value = Reflect.get(target, prop, receiver);
6420
- return typeof value === "function" ? value.bind(target) : value;
6421
- } });
6422
6763
  }
6423
- /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6424
- function withSecretAwareSettings(context, opts) {
6764
+ /** The context the addon sees, plus the private raw view and write outcome. */
6765
+ function createSecretAwareContext(context, opts) {
6425
6766
  const raw = context.settings;
6426
- if (raw === void 0) return context;
6427
- const settings = createSecretAwareSettings(raw, opts);
6428
- return new Proxy(context, { get(target, prop, receiver) {
6429
- if (prop === "settings") return settings;
6430
- return Reflect.get(target, prop, receiver);
6431
- } });
6767
+ if (raw === void 0) return {
6768
+ context,
6769
+ handle: null
6770
+ };
6771
+ const handle = createHandle(raw, opts);
6772
+ return {
6773
+ context: new Proxy(context, { get(target, prop, receiver) {
6774
+ if (prop === "settings") return handle.settings;
6775
+ return Reflect.get(target, prop, receiver);
6776
+ } }),
6777
+ handle
6778
+ };
6432
6779
  }
6433
6780
  var LEAF = { kind: "leaf" };
6434
6781
  var DEFAULT_ITEM_ID_KEY = "id";
@@ -6603,6 +6950,14 @@ var BaseAddon = class {
6603
6950
  _secretChangeUnsub = null;
6604
6951
  /** >0 while an OPERATOR's settings write is being applied. */
6605
6952
  _operatorWriteDepth = 0;
6953
+ /**
6954
+ * The keychain-aware settings handle (D798). Its `raw` view is the ONLY way
6955
+ * to the marker-bearing blobs and stays private to this class: the form
6956
+ * hydrate and config resolution need markers, addon code never does.
6957
+ */
6958
+ _secretSettings = null;
6959
+ /** Refs an addon-facing read could not resolve — each is logged once per process. */
6960
+ _loggedUnresolvedReads = /* @__PURE__ */ new Set();
6606
6961
  constructor(defaults) {
6607
6962
  this.defaults = defaults;
6608
6963
  this._config = { ...defaults };
@@ -6639,13 +6994,21 @@ var BaseAddon = class {
6639
6994
  }
6640
6995
  async initialize(context) {
6641
6996
  const secrets = context.secrets;
6642
- this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6643
- secrets,
6644
- addonTree: () => this.addonSecretTree(),
6645
- deviceTree: () => this.deviceSecretTree(),
6646
- onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6647
- isOperatorWrite: () => this._operatorWriteDepth > 0
6648
- }) : context;
6997
+ if (secrets !== void 0) {
6998
+ const { context: wrapped, handle } = createSecretAwareContext(context, {
6999
+ secrets,
7000
+ addonTree: () => this.addonSecretTree(),
7001
+ deviceTree: () => this.deviceSecretTree(),
7002
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
7003
+ isOperatorWrite: () => this._operatorWriteDepth > 0,
7004
+ onUnresolved: (unresolved) => this.logUnresolvedRead(unresolved)
7005
+ });
7006
+ this._ctx = wrapped;
7007
+ this._secretSettings = handle;
7008
+ } else {
7009
+ this._ctx = context;
7010
+ this._secretSettings = null;
7011
+ }
6649
7012
  await this.resolveConfig();
6650
7013
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6651
7014
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -6762,11 +7125,8 @@ var BaseAddon = class {
6762
7125
  async getGlobalSettings(overlay, cap, nodeId) {
6763
7126
  const schema = this.globalSettingsSchema(cap);
6764
7127
  if (!schema) return { sections: [] };
6765
- const projected = await this.resolveGlobalStore(nodeId, cap);
6766
- return hydrateSchema(schema, overlay ? {
6767
- ...projected,
6768
- ...overlay
6769
- } : projected, { inlineSecretsAsViews: true });
7128
+ const projected = await this.readRawProjectedStore(nodeId, cap);
7129
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
6770
7130
  }
6771
7131
  /**
6772
7132
  * The integration-level view of this addon's settings: exactly the sections
@@ -6811,7 +7171,7 @@ var BaseAddon = class {
6811
7171
  });
6812
7172
  }
6813
7173
  if (sections.length === 0) return null;
6814
- const projected = await this.resolveGlobalStore(nodeId);
7174
+ const projected = await this.readRawProjectedStore(nodeId);
6815
7175
  return hydrateSchema({
6816
7176
  ...schema,
6817
7177
  sections
@@ -6828,12 +7188,50 @@ var BaseAddon = class {
6828
7188
  * the store for custom option logic (option narrowing, value snapping) to
6829
7189
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
6830
7190
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
7191
+ *
7192
+ * Keychain values come back RESOLVED (D798): a secret reads as its value,
7193
+ * never as a `{ $secret }` marker. One the keychain cannot serve right now
7194
+ * stays a marker — "stored, unavailable" (`isSecretMarker()` is true, and it
7195
+ * is listed in {@link unresolvedSecrets}) — never `''` and never absent, so
7196
+ * it cannot be mistaken for "nothing stored, mint a new one". Writing the
7197
+ * resolved blob back is a no-op for every unchanged secret.
6831
7198
  */
6832
7199
  async resolveGlobalStore(nodeId, cap) {
6833
7200
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
7201
+ return this.projectForNode(raw, nodeId, cap);
7202
+ }
7203
+ projectForNode(store, nodeId, cap) {
6834
7204
  const keys = this.perNodeKeys(cap);
6835
7205
  const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6836
- return keys.size > 0 ? projectStore(raw, keys, node) : raw;
7206
+ return keys.size > 0 ? projectStore(store, keys, node) : store;
7207
+ }
7208
+ /** The PROJECTED store with its markers — the form hydrate only (D798). */
7209
+ async readRawProjectedStore(nodeId, cap) {
7210
+ const raw = await this.rawSettings()?.readAddonStore() ?? {};
7211
+ return this.projectForNode(raw, nodeId, cap);
7212
+ }
7213
+ /**
7214
+ * `{ ...stored, ...overlay }`, except that an overlay member equal to the
7215
+ * RESOLVED stored one keeps the stored (marker-bearing) member — so a form
7216
+ * hydrated from a resolved overlay still shows a secret as "set", never as
7217
+ * its value.
7218
+ */
7219
+ async overlayKeepingMarkers(stored, overlay) {
7220
+ const secrets = this._ctx?.secrets;
7221
+ const merged = {
7222
+ ...stored,
7223
+ ...overlay
7224
+ };
7225
+ if (secrets === void 0 || collectSecretMarkerRefs(stored).length === 0) return merged;
7226
+ const { value: resolved } = await resolveSecretMarkers(stored, secrets, {
7227
+ unresolved: "keep-marker",
7228
+ ownedBy: secrets.owner
7229
+ });
7230
+ for (const key of Object.keys(overlay)) {
7231
+ if (collectSecretMarkerRefs(stored[key]).length === 0) continue;
7232
+ if (isJsonEqual(overlay[key], resolved[key])) merged[key] = stored[key];
7233
+ }
7234
+ return merged;
6837
7235
  }
6838
7236
  /**
6839
7237
  * Whether ONE global key of this addon's store was written, read three-way
@@ -6898,8 +7296,12 @@ var BaseAddon = class {
6898
7296
  async clearSecrets(keys, nodeId) {
6899
7297
  const tree = this.addonSecretTree();
6900
7298
  const keychain = this._ctx?.secrets !== void 0;
7299
+ const stored = keychain ? await this.readAddonStoreWithRetry() : {};
6901
7300
  const patch = {};
6902
- for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
7301
+ for (const key of keys) {
7302
+ const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
7303
+ patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
7304
+ }
6903
7305
  await this.applyGlobalPatch(patch, nodeId);
6904
7306
  }
6905
7307
  async applyGlobalPatch(barePatch, nodeId) {
@@ -6907,7 +7309,11 @@ var BaseAddon = class {
6907
7309
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6908
7310
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6909
7311
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6910
- await this._ctx?.settings?.writeAddonStore(scoped);
7312
+ const handle = this._secretSettings;
7313
+ if (handle !== null) {
7314
+ const { changed } = await handle.writeAddonStore(scoped);
7315
+ if (!changed) return;
7316
+ } else await this._ctx?.settings?.writeAddonStore(scoped);
6911
7317
  if (target !== localNode) return;
6912
7318
  await this.resolveConfig();
6913
7319
  await this.onConfigChanged();
@@ -6960,7 +7366,7 @@ var BaseAddon = class {
6960
7366
  async getDeviceSettings(deviceId) {
6961
7367
  const schema = this.deviceSettingsSchema();
6962
7368
  if (!schema) return { sections: [] };
6963
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7369
+ return hydrateSchema(schema, await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6964
7370
  }
6965
7371
  async updateDeviceSettings(deviceId, patch) {
6966
7372
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -7132,7 +7538,7 @@ var BaseAddon = class {
7132
7538
  key,
7133
7539
  schema,
7134
7540
  fallback,
7135
- read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
7541
+ read: async () => this.resolveStoredSecrets(await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, false),
7136
7542
  write: async (patch) => {
7137
7543
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
7138
7544
  },
@@ -7194,6 +7600,23 @@ var BaseAddon = class {
7194
7600
  }
7195
7601
  return value;
7196
7602
  }
7603
+ /**
7604
+ * The marker-bearing settings reads (D798) — private on purpose. Without a
7605
+ * keychain the context's own view is already raw.
7606
+ */
7607
+ rawSettings() {
7608
+ return this._secretSettings?.raw ?? this._ctx?.settings;
7609
+ }
7610
+ /** An addon-facing read met markers it could not resolve: say so once per ref. */
7611
+ logUnresolvedRead(unresolved) {
7612
+ const fresh = unresolved.filter((u) => !this._loggedUnresolvedReads.has(u.ref));
7613
+ if (fresh.length === 0) return;
7614
+ for (const u of fresh) this._loggedUnresolvedReads.add(u.ref);
7615
+ 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) => ({
7616
+ ref: u.ref,
7617
+ reason: u.reason
7618
+ })) } });
7619
+ }
7197
7620
  /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7198
7621
  scheduleSecretReresolve(delayMs) {
7199
7622
  const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
@@ -7220,7 +7643,7 @@ var BaseAddon = class {
7220
7643
  * `{}` (defaults) — the addon's first successful patch will rehydrate.
7221
7644
  */
7222
7645
  async readAddonStoreWithRetry() {
7223
- const settings = this._ctx?.settings;
7646
+ const settings = this.rawSettings();
7224
7647
  if (!settings) return {};
7225
7648
  const delaysMs = [
7226
7649
  150,
@@ -10134,6 +10557,278 @@ var CameraSwitchGroupSchema = object({
10134
10557
  */
10135
10558
  var DETECTION_PIPELINE_CAP_NAME = "detection-pipeline";
10136
10559
  /**
10560
+ * The trainer contract — what the hub hands the cloud trainer and what it
10561
+ * gets back (cloud training, D805+).
10562
+ *
10563
+ * The trainer (`hf/camstack-trainer`, published as the Hugging Face repo
10564
+ * `camstack/camstack-trainer`) is a separate AGPL program the hub never
10565
+ * imports: `job.json` goes in, files come out, and progress is `CAMSTACK_EVENT`
10566
+ * lines on stdout. These schemas are the hub's half of that boundary; the
10567
+ * trainer's pydantic models (and the JSON Schemas generated from them under
10568
+ * `hf/camstack-trainer/schemas/`) are the other half. A change here is a
10569
+ * change there, in the same piece of work.
10570
+ *
10571
+ * No `.default()` anywhere: defaults do not run on the addon cap path, so the
10572
+ * orchestrator fills every field of a job spec explicitly.
10573
+ */
10574
+ var TRAINING_JOB_SCHEMA = "camstack.training/v1";
10575
+ var TRAINING_RESULT_SCHEMA = "camstack.training-result/v1";
10576
+ /** What the trainer can export. Edge TPU is a later, separate image. */
10577
+ var TrainingExportSchema = _enum([
10578
+ "onnx",
10579
+ "openvino-fp16",
10580
+ "openvino-int8",
10581
+ "coreml-fp16"
10582
+ ]);
10583
+ var FloorsSchema = record(string(), number().min(0).max(1));
10584
+ object({
10585
+ schema: literal(TRAINING_JOB_SCHEMA),
10586
+ jobKey: string().uuid(),
10587
+ target: object({
10588
+ kind: literal("detector"),
10589
+ step: literal("object-detection")
10590
+ }),
10591
+ base: object({
10592
+ modelId: string().min(1),
10593
+ /** Ultralytics weights id, e.g. `yolov9m.pt`. */
10594
+ weights: string().min(1),
10595
+ imgsz: number().int().positive()
10596
+ }),
10597
+ baseline: object({
10598
+ modelId: string().min(1),
10599
+ /** The baseline ONNX the holdout comparison runs; public mirror URL. */
10600
+ onnxUrl: string().url(),
10601
+ imgsz: number().int().positive(),
10602
+ floors: FloorsSchema
10603
+ }),
10604
+ dataset: object({
10605
+ versionId: string().min(1),
10606
+ annotationHash: string(),
10607
+ /** sha256 of the uploaded archive; the trainer refuses a mismatch (exit 65). */
10608
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10609
+ }),
10610
+ split: object({
10611
+ holdoutCameras: array(number().int()),
10612
+ /** When no camera is held out: the last N days of every camera. */
10613
+ holdoutLastDays: number().int().nonnegative(),
10614
+ valFraction: number().min(0).max(.5),
10615
+ seed: number().int()
10616
+ }),
10617
+ hyper: object({
10618
+ epochs: number().int().positive(),
10619
+ batch: number().int().positive(),
10620
+ lr0: number().positive(),
10621
+ /** Layers frozen from the start of the backbone; 0 = none. */
10622
+ freeze: number().int().nonnegative(),
10623
+ patience: number().int().nonnegative(),
10624
+ seed: number().int()
10625
+ }),
10626
+ replay: object({
10627
+ source: literal("coco2017"),
10628
+ count: number().int().nonnegative()
10629
+ }),
10630
+ exports: array(TrainingExportSchema).min(1),
10631
+ calibration: object({ maxFrames: number().int().positive() }),
10632
+ floors: object({
10633
+ minSupport: number().int().positive(),
10634
+ clamp: number().min(0).max(1)
10635
+ }),
10636
+ int8Gate: object({ maxMap50Drop: number().min(0).max(1) }),
10637
+ catalog: object({
10638
+ id: string().regex(/^[a-z0-9][a-z0-9-]{2,80}$/),
10639
+ name: string().min(1).max(160)
10640
+ })
10641
+ });
10642
+ /** One regular file of the bundle. An mlpackage contributes one row per member. */
10643
+ var TrainingResultFileSchema = object({
10644
+ path: string().min(1),
10645
+ bytes: number().int().nonnegative(),
10646
+ sha256: string().regex(/^[0-9a-f]{64}$/),
10647
+ format: _enum([
10648
+ "onnx",
10649
+ "openvino",
10650
+ "coreml",
10651
+ "pt"
10652
+ ]),
10653
+ variant: _enum(["base", "int8"])
10654
+ });
10655
+ var DraftFormatSchema = object({
10656
+ /** RELATIVE path inside the bundle; the hub rewrites it to `camstack-local://`. */
10657
+ url: string().min(1),
10658
+ sizeMB: number().nonnegative(),
10659
+ isDirectory: boolean().optional(),
10660
+ files: array(string()).optional(),
10661
+ runtimes: array(literal("python")).optional(),
10662
+ revision: string().min(1)
10663
+ });
10664
+ /** The trainer's half of a catalog entry; the hub completes it (labels, licence, group). */
10665
+ var TrainingCatalogDraftSchema = object({
10666
+ id: string().min(1),
10667
+ name: string().min(1),
10668
+ description: string(),
10669
+ labels: array(unknown()),
10670
+ inputSize: object({
10671
+ width: number().int().positive(),
10672
+ height: number().int().positive()
10673
+ }),
10674
+ preprocessMode: literal("letterbox"),
10675
+ defaultClassFloors: FloorsSchema,
10676
+ formats: object({
10677
+ onnx: DraftFormatSchema.optional(),
10678
+ openvino: DraftFormatSchema.optional(),
10679
+ coreml: DraftFormatSchema.optional()
10680
+ })
10681
+ });
10682
+ /** One class of one model's holdout report (the eval harness's summary). */
10683
+ var TrainingEvalClassSchema = object({
10684
+ positives: number().int(),
10685
+ floor: number().nullable(),
10686
+ tp: number().int(),
10687
+ fp: number().int(),
10688
+ fn: number().int(),
10689
+ precision: number().nullable(),
10690
+ recall: number().nullable(),
10691
+ ap50: number().nullable(),
10692
+ recallByCamera: record(string(), number().nullable()).optional(),
10693
+ recallByLight: record(string(), number().nullable()).optional(),
10694
+ fpByCamera: record(string(), number()).optional(),
10695
+ smallFound: number().int().optional(),
10696
+ smallTotal: number().int().optional()
10697
+ }).passthrough();
10698
+ var TrainingEvalReportSchema = object({
10699
+ frames: number().int(),
10700
+ classes: record(string(), TrainingEvalClassSchema)
10701
+ }).passthrough();
10702
+ /**
10703
+ * A succeeded result carries every block; a failed one carries the error and
10704
+ * whatever was known by then — the other blocks are ABSENT, not null. The
10705
+ * orchestrator checks the blocks it needs before it trusts a success.
10706
+ */
10707
+ var TrainingResultSchema = object({
10708
+ schema: literal(TRAINING_RESULT_SCHEMA),
10709
+ jobKey: string(),
10710
+ status: _enum(["succeeded", "failed"]),
10711
+ error: object({
10712
+ stage: string(),
10713
+ code: string(),
10714
+ message: string()
10715
+ }).nullable(),
10716
+ trainer: object({
10717
+ version: string(),
10718
+ revision: string()
10719
+ }),
10720
+ toolchain: record(string(), string().nullable()),
10721
+ dataset: object({
10722
+ versionId: string(),
10723
+ annotationHash: string(),
10724
+ sha256: string(),
10725
+ frames: object({
10726
+ train: number().int(),
10727
+ val: number().int(),
10728
+ holdout: number().int()
10729
+ }),
10730
+ holdoutCameras: array(number().int()),
10731
+ replayImages: number().int()
10732
+ }).optional(),
10733
+ training: object({
10734
+ epochsRun: number().int(),
10735
+ bestEpoch: number().int(),
10736
+ bestMap50: number(),
10737
+ bestMap50_95: number(),
10738
+ seconds: number()
10739
+ }).optional(),
10740
+ evaluation: object({
10741
+ holdoutFrames: number().int(),
10742
+ baseline: TrainingEvalReportSchema.nullable(),
10743
+ candidate: TrainingEvalReportSchema.nullable(),
10744
+ candidateInt8: TrainingEvalReportSchema.nullable(),
10745
+ recallDeltaByCamera: record(string(), record(string(), number())).nullable(),
10746
+ map50: record(string(), number().nullable())
10747
+ }).optional(),
10748
+ floors: object({
10749
+ baseline: FloorsSchema,
10750
+ candidate: FloorsSchema,
10751
+ candidateInt8: FloorsSchema.nullable(),
10752
+ notes: array(string())
10753
+ }).optional(),
10754
+ int8: object({
10755
+ kept: boolean(),
10756
+ map50Fp16: number().nullable(),
10757
+ map50Int8: number().nullable(),
10758
+ reason: string().nullable()
10759
+ }).optional(),
10760
+ exportsDropped: array(object({
10761
+ export: string(),
10762
+ reason: string()
10763
+ })).optional(),
10764
+ files: array(TrainingResultFileSchema).optional(),
10765
+ bundle: object({
10766
+ path: literal("bundle.tar"),
10767
+ bytes: number().int().nonnegative(),
10768
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10769
+ }).nullable().optional(),
10770
+ catalogDraft: object({
10771
+ base: TrainingCatalogDraftSchema,
10772
+ int8: TrainingCatalogDraftSchema.nullable()
10773
+ }).nullable().optional(),
10774
+ licence: string()
10775
+ });
10776
+ var TrainingStageSchema = _enum([
10777
+ "prepare",
10778
+ "replay",
10779
+ "train",
10780
+ "eval",
10781
+ "export",
10782
+ "package"
10783
+ ]);
10784
+ var EventBase = {
10785
+ v: literal(1),
10786
+ ts: number()
10787
+ };
10788
+ discriminatedUnion("type", [
10789
+ object({
10790
+ ...EventBase,
10791
+ type: literal("stage"),
10792
+ stage: TrainingStageSchema
10793
+ }),
10794
+ object({
10795
+ ...EventBase,
10796
+ type: literal("epoch"),
10797
+ epoch: number().int(),
10798
+ epochs: number().int(),
10799
+ boxLoss: number().nullable().optional(),
10800
+ map50: number().nullable().optional(),
10801
+ map50_95: number().nullable().optional(),
10802
+ etaSec: number().nullable().optional()
10803
+ }),
10804
+ object({
10805
+ ...EventBase,
10806
+ type: literal("metric"),
10807
+ name: string(),
10808
+ value: number()
10809
+ }),
10810
+ object({
10811
+ ...EventBase,
10812
+ type: literal("artifact"),
10813
+ path: string(),
10814
+ bytes: number(),
10815
+ sha256: string()
10816
+ }),
10817
+ object({
10818
+ ...EventBase,
10819
+ type: literal("done"),
10820
+ status: _enum(["succeeded", "failed"]),
10821
+ resultSha256: string().nullable().optional()
10822
+ }),
10823
+ object({
10824
+ ...EventBase,
10825
+ type: literal("error"),
10826
+ stage: string(),
10827
+ code: string(),
10828
+ message: string()
10829
+ })
10830
+ ]);
10831
+ /**
10137
10832
  * Birth-decision ledger — one durable row per track-birth VERDICT (D409).
10138
10833
  *
10139
10834
  * ── Why this exists ────────────────────────────────────────────────────────
@@ -12901,7 +13596,9 @@ var AddonHttpRouteSchema = object({
12901
13596
  "authenticated",
12902
13597
  "admin"
12903
13598
  ]).optional(),
12904
- description: string().optional()
13599
+ description: string().optional(),
13600
+ /** The hub limits this route per client address before the handler runs. */
13601
+ rateLimit: _enum(["auth"]).optional()
12905
13602
  });
12906
13603
  /**
12907
13604
  * Cross-process route invocation envelope. The hub captures the
@@ -13851,6 +14548,37 @@ var BackupDestinationInfoSchema = object({
13851
14548
  lastError: string().optional()
13852
14549
  });
13853
14550
  /**
14551
+ * How an archive is encrypted (operator decision 2026-10-09): to a backup
14552
+ * PUBLIC key the hub holds, so only the operator's secret key opens it.
14553
+ * Absent on a plain `.tar.gz` — every archive made before encryption, or
14554
+ * with it off — which restores without a key.
14555
+ */
14556
+ var BackupArchiveEncryptionSchema = object({
14557
+ /** `x25519-hkdf-aes256gcm-stream-v1`. */
14558
+ scheme: string(),
14559
+ /** 16 hex — the backup key whose secret restores this archive. */
14560
+ keyId: string()
14561
+ });
14562
+ /**
14563
+ * The backup encryption setting. The hub keeps PUBLIC keys only: the active
14564
+ * one new archives are encrypted to, and the retired ones older archives
14565
+ * still need. The secret key is shown once, at `setupEncryption`.
14566
+ */
14567
+ var BackupEncryptionStatusSchema = object({
14568
+ enabled: boolean(),
14569
+ active: object({
14570
+ keyId: string(),
14571
+ publicKey: string(),
14572
+ createdAt: number()
14573
+ }).nullable(),
14574
+ /** Every key ever set up, newest first. */
14575
+ keys: array(object({
14576
+ keyId: string(),
14577
+ createdAt: number(),
14578
+ retiredAt: number().nullable()
14579
+ })).readonly()
14580
+ });
14581
+ /**
13854
14582
  * Per-archive entry returned by `backup.listArchives({ destinationId })`.
13855
14583
  * Same shape the destination drill-in renders. Sourced from the per-
13856
14584
  * location `manifests.json` (no per-archive tarball read required).
@@ -13862,7 +14590,9 @@ var BackupArchiveEntrySchema = object({
13862
14590
  sizeBytes: number(),
13863
14591
  label: string().optional(),
13864
14592
  /** Top-level locations included in the archive (db, addons, tls, …). */
13865
- locations: array(string()).readonly()
14593
+ locations: array(string()).readonly(),
14594
+ /** Present when the archive is encrypted; restore then needs that key. */
14595
+ encryption: BackupArchiveEncryptionSchema.optional()
13866
14596
  });
13867
14597
  var BackupEntrySchema = object({
13868
14598
  id: string(),
@@ -13871,7 +14601,8 @@ var BackupEntrySchema = object({
13871
14601
  label: string().optional(),
13872
14602
  createdAt: number(),
13873
14603
  sizeBytes: number(),
13874
- locations: array(string()).optional()
14604
+ locations: array(string()).optional(),
14605
+ encryption: BackupArchiveEncryptionSchema.optional()
13875
14606
  });
13876
14607
  var ArchiveEntrySchema = object({
13877
14608
  path: string(),
@@ -14126,11 +14857,58 @@ var backupCapability = {
14126
14857
  * this list and skips entries whose path doesn't start with
14127
14858
  * any of them.
14128
14859
  */
14129
- locations: array(string()).optional()
14860
+ locations: array(string()).optional(),
14861
+ /**
14862
+ * The backup SECRET key, for an encrypted archive (ignored for a plain
14863
+ * one). The archive is decrypted into the hub's private staging
14864
+ * before the restart; the key is not stored. A wrong or missing key
14865
+ * is refused before the archive is downloaded.
14866
+ */
14867
+ backupSecretKey: string().optional()
14130
14868
  }), _void(), {
14131
14869
  kind: "mutation",
14132
14870
  auth: "admin"
14133
14871
  }),
14872
+ /** The encryption setting — public keys only. */
14873
+ getEncryption: method(_void(), BackupEncryptionStatusSchema, { auth: "admin" }),
14874
+ /**
14875
+ * Turn encryption on, or replace the key: generates a new key pair, keeps
14876
+ * the PUBLIC key, and returns the SECRET key — once. It is never stored
14877
+ * on the hub and cannot be shown again; archives made from now on need
14878
+ * it to be restored. A previous key is retired: archives made with it
14879
+ * still need IT.
14880
+ */
14881
+ setupEncryption: method(object({}), object({
14882
+ keyId: string(),
14883
+ secretKey: string(),
14884
+ publicKey: string(),
14885
+ createdAt: number(),
14886
+ replacedKeyId: string().nullable()
14887
+ }), {
14888
+ kind: "mutation",
14889
+ auth: "admin"
14890
+ }),
14891
+ /** New archives are plain again. Existing encrypted archives keep needing their key. */
14892
+ disableEncryption: method(object({}), object({ disabledKeyId: string().nullable() }), {
14893
+ kind: "mutation",
14894
+ auth: "admin"
14895
+ }),
14896
+ /**
14897
+ * Does this secret key parse, and which backup key is it? A mutation so
14898
+ * the key never travels in a URL. Nothing is stored.
14899
+ */
14900
+ checkBackupKey: method(object({ backupSecretKey: string() }), object({
14901
+ valid: boolean(),
14902
+ keyId: string().nullable(),
14903
+ /** The hub knows this key (active or retired). */
14904
+ known: boolean(),
14905
+ /** It is the key new archives are encrypted to. */
14906
+ active: boolean(),
14907
+ error: string().optional()
14908
+ }), {
14909
+ kind: "mutation",
14910
+ auth: "admin"
14911
+ }),
14134
14912
  delete: method(object({
14135
14913
  destinationId: string(),
14136
14914
  backupId: string()
@@ -16326,22 +17104,87 @@ var CustomModelDescriptorSchema = object({
16326
17104
  stepId: string(),
16327
17105
  entry: ModelCatalogEntrySchema
16328
17106
  });
17107
+ /** One regular file of an imported bundle, as the producer measured it. */
17108
+ var ModelBundleFileSchema = object({
17109
+ /** Relative path inside the bundle tar; an mlpackage member is `<x>.mlpackage/<member>`. */
17110
+ path: string().min(1),
17111
+ bytes: number().int().nonnegative(),
17112
+ sha256: string().regex(/^[0-9a-f]{64}$/)
17113
+ });
17114
+ var ImportModelBundleInputSchema = object({
17115
+ /** The registry provider that keeps the model (Model Studio). */
17116
+ addonId: string(),
17117
+ stepId: string().min(1),
17118
+ /**
17119
+ * The catalog rows to register, complete, every format URL already
17120
+ * `camstack-local://<modelId>/<file>` naming a file of the bundle. One
17121
+ * bundle may carry several rows (a base and its INT8 variant).
17122
+ */
17123
+ entries: array(ModelCatalogEntrySchema).min(1).max(4),
17124
+ /** The bundle tar, offered by the producer over `ctx.peerBytes` (same host). */
17125
+ bundle: object({
17126
+ ticket: PeerBytesTicketSchema,
17127
+ bytes: number().int().positive(),
17128
+ sha256: string().regex(/^[0-9a-f]{64}$/)
17129
+ }),
17130
+ /** Every file the tar must hold; anything missing, extra or different is refused. */
17131
+ files: array(ModelBundleFileSchema).min(1).max(64),
17132
+ /** Convert missing engine formats and push the model to every agent afterwards. */
17133
+ distribute: boolean()
17134
+ });
17135
+ var ImportModelBundleResultSchema = discriminatedUnion("kind", [object({
17136
+ kind: literal("imported"),
17137
+ modelIds: array(string()).readonly(),
17138
+ distributed: array(object({
17139
+ modelId: string(),
17140
+ nodeId: string(),
17141
+ format: _enum(MODEL_FORMATS),
17142
+ ok: boolean(),
17143
+ error: string().optional()
17144
+ })).readonly()
17145
+ }), object({
17146
+ kind: literal("refused"),
17147
+ reason: _enum([
17148
+ "transfer-failed",
17149
+ "checksum-mismatch",
17150
+ "bundle-mismatch",
17151
+ "invalid-entry",
17152
+ "id-taken"
17153
+ ]),
17154
+ detail: string()
17155
+ })]);
16329
17156
  var customModelRegistryCapability = {
16330
17157
  name: "custom-model-registry",
16331
17158
  scope: "system",
16332
17159
  mode: "collection",
16333
17160
  internal: true,
16334
- methods: {
16335
- /**
16336
- * `internal: true` did not gate the mount (see the 2026-08-26 note on
16337
- * `data-store-provider`) — this was reachable on the AppRouter by ANY
16338
- * authenticated session at the default `auth: 'protected'`. The only
16339
- * consumer, the detection-pipeline's model resolution
16340
- * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
16341
- * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
16342
- * never tRPC — so `auth: 'admin'` costs it nothing.
16343
- */
16344
- listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }) }
17161
+ methods: {
17162
+ /**
17163
+ * `internal: true` did not gate the mount (see the 2026-08-26 note on
17164
+ * `data-store-provider`) — this was reachable on the AppRouter by ANY
17165
+ * authenticated session at the default `auth: 'protected'`. The only
17166
+ * consumer, the detection-pipeline's model resolution
17167
+ * (`addon-pipeline/src/detection-pipeline/provider.ts`), calls
17168
+ * `ctx.api.customModelRegistry.listModels.query()` — UDS/Moleculer,
17169
+ * never tRPC — so `auth: 'admin'` costs it nothing.
17170
+ */
17171
+ listModels: method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }),
17172
+ /**
17173
+ * Register a model whose files arrive as ONE bundle tar (D806): the tar
17174
+ * is taken over `ctx.peerBytes`, checked against `bundle.sha256` and
17175
+ * every row of `files`, unpacked into the hub's flat modelsDir (directory
17176
+ * formats included), each format's `.revision` record written, the rows
17177
+ * upserted under the operator's name, the hub marked available and —
17178
+ * when asked — engine formats converted and the model distributed. A
17179
+ * model id already registered by another source is refused, never
17180
+ * overwritten.
17181
+ */
17182
+ importModelBundle: method(ImportModelBundleInputSchema, ImportModelBundleResultSchema, {
17183
+ kind: "mutation",
17184
+ auth: "admin",
17185
+ timeoutMs: 30 * 6e4
17186
+ })
17187
+ }
16345
17188
  };
16346
17189
  /**
16347
17190
  * Query filter for settings-store collections.
@@ -17132,6 +17975,35 @@ var KeychainKeySourceSchema = object({
17132
17975
  */
17133
17976
  sharesBackupWithDatabase: boolean()
17134
17977
  });
17978
+ /**
17979
+ * One keychain reset, as the Secrets page reports it until the operator
17980
+ * acknowledges it. Never a value: refs, counts and table names only.
17981
+ */
17982
+ var KeychainResetRecordSchema = object({
17983
+ id: string(),
17984
+ at: number(),
17985
+ /** `user:<id>` or {@link KEYCHAIN_RESET_TRIGGER_ACTOR}. */
17986
+ actor: string(),
17987
+ /** Why the keychain was locked when it was reset; `null` when it was not locked. */
17988
+ lockedReason: string().nullable(),
17989
+ /** Values moved into the archive table (ciphertext under the lost key). */
17990
+ archived: number().int(),
17991
+ /** `keychain:secrets-orphaned-<ts>`, or `null` when nothing was stored. */
17992
+ archivedCollection: string().nullable(),
17993
+ /**
17994
+ * `keychain:keys-orphaned-<ts>`: the wrapped data keys of the archive, kept
17995
+ * so the archive can still be opened if the lost master key turns up.
17996
+ */
17997
+ archivedKeysCollection: string().nullable(),
17998
+ /**
17999
+ * `system-settings` keys whose marker the reset cleared — the cluster
18000
+ * secret's: a marker left pointing at an archived value would refuse every
18001
+ * agent forever (D797).
18002
+ */
18003
+ clearedSettingsKeys: array(string()).readonly(),
18004
+ /** When an operator dismissed the notice on the Secrets page; `null` until then. */
18005
+ acknowledgedAt: number().nullable()
18006
+ });
17135
18007
  var KeychainStatusSchema = object({
17136
18008
  keychain: KeychainStateSchema,
17137
18009
  /** The source of the master key in use; `null` while locked. */
@@ -17149,7 +18021,9 @@ var KeychainStatusSchema = object({
17149
18021
  /** Wrapped copies of the data key under a previous master key, kept until purged. */
17150
18022
  retiredWraps: number().int(),
17151
18023
  recoveryKeyDownloadedAt: number().nullable(),
17152
- secretCount: number().int()
18024
+ secretCount: number().int(),
18025
+ /** The most recent reset, acknowledged or not; `null` when the keychain was never reset. */
18026
+ lastReset: KeychainResetRecordSchema.nullable()
17153
18027
  });
17154
18028
  /**
17155
18029
  * Whether a stored value is still pointed at by its owner's settings.
@@ -17171,13 +18045,14 @@ var KeychainAuditActionSchema = _enum([
17171
18045
  "download-recovery-key",
17172
18046
  "delete-orphans",
17173
18047
  "reset",
18048
+ "acknowledge-reset",
17174
18049
  "initialize"
17175
18050
  ]);
17176
18051
  var KeychainAuditEntrySchema = object({
17177
18052
  id: string(),
17178
18053
  at: number(),
17179
18054
  action: KeychainAuditActionSchema,
17180
- /** `addon:<id>` | `user:<id>` | `system`. */
18055
+ /** `addon:<id>` | `user:<id>` | `system` | `trigger-file`. */
17181
18056
  actor: string(),
17182
18057
  ref: string().nullable(),
17183
18058
  detail: string().nullable()
@@ -17287,6 +18162,21 @@ var keychainAdminCapability = {
17287
18162
  kind: "mutation",
17288
18163
  auth: "admin",
17289
18164
  caller: "required"
18165
+ }),
18166
+ /**
18167
+ * What the last reset left to re-enter: the archived refs (owner, scope,
18168
+ * field — never a value) that hold no value again yet. Process-held refs
18169
+ * the hub regenerates itself (the session signing key) are not listed.
18170
+ */
18171
+ resetReport: method(object({}), object({
18172
+ reset: KeychainResetRecordSchema.nullable(),
18173
+ pendingReentry: array(KeychainSecretMetaSchema).readonly()
18174
+ }), { auth: "admin" }),
18175
+ /** Dismiss the "keychain was reset" notice. Audited. */
18176
+ acknowledgeReset: method(object({}), object({ acknowledged: boolean() }), {
18177
+ kind: "mutation",
18178
+ auth: "admin",
18179
+ caller: "required"
17290
18180
  })
17291
18181
  }
17292
18182
  };
@@ -21337,7 +22227,7 @@ var logDestinationCapability = {
21337
22227
  * `login-method` — collection cap through which auth addons contribute
21338
22228
  * their pre-auth login surfaces to the login page. This is the SINGLE,
21339
22229
  * generic mechanism that supersedes the dead `auth.listProviders` reader:
21340
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
22230
+ * every auth addon (OIDC, WebAuthn/passkey) registers a
21341
22231
  * `login-method` provider and the PUBLIC `auth.listLoginMethods`
21342
22232
  * procedure aggregates them for the unauthenticated login page.
21343
22233
  *
@@ -21345,8 +22235,7 @@ var logDestinationCapability = {
21345
22235
  *
21346
22236
  * - `redirect` — a declarative button. The login page renders a generic
21347
22237
  * button that navigates to `startUrl` (an addon-owned HTTP route).
21348
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
21349
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
22238
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) with ZERO shell-side JS. A future SSO addon plugs in the same way — the
21350
22239
  * login page needs NO change.
21351
22240
  *
21352
22241
  * - `widget` — a Module-Federation widget the login page mounts (via
@@ -21365,8 +22254,8 @@ var logDestinationCapability = {
21365
22254
  * decision.
21366
22255
  *
21367
22256
  * Every contribution carries a `stage`:
21368
- * - `primary` — shown on the first credentials screen (OIDC /
21369
- * magic-link buttons; a future usernameless passkey).
22257
+ * - `primary` — shown on the first credentials screen (OIDC
22258
+ * buttons; a usernameless passkey).
21370
22259
  * - `second-factor` — shown AFTER the password leg, gated on the
21371
22260
  * returned `factors` (passkey-as-2FA today).
21372
22261
  *
@@ -21393,7 +22282,7 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
21393
22282
  * The provider names an external identity a signed-in user can link to
21394
22283
  * their own account (D782): `auth.listLinkableProviders` /
21395
22284
  * `beginExternalLink` offer exactly the redirect methods that set this,
21396
- * whatever their id. Absent / false — a login button only (magic-link).
22285
+ * whatever their id. Absent / false — a login button only.
21397
22286
  */
21398
22287
  linkable: boolean().optional()
21399
22288
  }),
@@ -26296,8 +27185,7 @@ var notificationRulesCapability = {
26296
27185
  * `super_admin` — collapsed onto the single boolean because every
26297
27186
  * non-admin caller is governed by the same scope-check rules; the
26298
27187
  * distinction was only ever used to route role-specific procedures
26299
- * which we no longer have. Agents are admin sessions issued via
26300
- * `createServiceToken`; CLI / webhook integrations are `cst_*` tokens
27188
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
26301
27189
  * with `isAdmin: false` + an explicit scope list.
26302
27190
  */
26303
27191
  /** Per-method access flavour. Materialised on every cap method via codegen. */
@@ -29685,6 +30573,26 @@ var pipelineAnalyticsCapability = {
29685
30573
  auth: "admin",
29686
30574
  timeoutMs: 60 * 6e4
29687
30575
  }),
30576
+ /**
30577
+ * OFFER the annotated archive instead of pushing it (D805): the same tar
30578
+ * `writeRetrainArchive` streams, behind a one-shot `ctx.peerBytes` ticket
30579
+ * the caller dials at once (same host). For a consumer that cannot expose
30580
+ * an upload URL — a training provider streaming straight into its cloud.
30581
+ * The answer is the plan; the bytes and their sha256 are the consumer's
30582
+ * to measure as they arrive.
30583
+ */
30584
+ offerRetrainArchive: method(object({
30585
+ filter: RetrainExportFilterSchema,
30586
+ layout: RetrainExportLayoutSchema
30587
+ }), object({
30588
+ ticket: PeerBytesTicketSchema,
30589
+ frames: number().int(),
30590
+ annotations: number().int()
30591
+ }), {
30592
+ kind: "mutation",
30593
+ auth: "admin",
30594
+ timeoutMs: 12e4
30595
+ }),
29688
30596
  /** The counts a selection would freeze — class × camera × day/night,
29689
30597
  * completeness — without freezing anything. Index reads only. */
29690
30598
  previewRetrainDataset: method(object({
@@ -34354,8 +35262,8 @@ version: string().optional() }), ServerUpdateActionResultSchema, {
34354
35262
  * `smtp-provider` — pluggable email delivery surface.
34355
35263
  *
34356
35264
  * Collection cap: a deployment may install multiple SMTP relays (e.g.
34357
- * one for transactional / one for notifications). Consumers (magic-link,
34358
- * notifier addons, …) walk the collection and pick the first
35265
+ * one for transactional / one for notifications). Consumers (notifier
35266
+ * addons, …) walk the collection and pick the first
34359
35267
  * ready provider OR target a specific addonId.
34360
35268
  *
34361
35269
  * The shape stays small on purpose — `sendEmail` is enough for the
@@ -34651,7 +35559,7 @@ targets: array(object({
34651
35559
  };
34652
35560
  /**
34653
35561
  * `sso-bridge` — internal hub-only cap that lets SSO-style auth
34654
- * providers (OIDC, SAML, magic-link, …) mint an HMAC-signed token
35562
+ * providers (OIDC, SAML, …) mint an HMAC-signed token
34655
35563
  * carrying the post-callback claims before redirecting back to
34656
35564
  * `/api/auth/sso/finish`.
34657
35565
  *
@@ -34714,7 +35622,14 @@ var SsoBridgeClaimsSchema = object({
34714
35622
  * Verified `iss` of the id_token behind an OIDC login bridge (D782). A
34715
35623
  * subject is unique only per issuer, so a link is bound to it.
34716
35624
  */
34717
- issuer: string().optional()
35625
+ issuer: string().optional(),
35626
+ /**
35627
+ * SHA-256 (hex) of the `camstack_sso_state` cookie the IdP `/start` set in
35628
+ * the browser that began this sign-in. `/api/auth/sso/finish` requires the
35629
+ * request to present the matching cookie — a login bridge is useless in
35630
+ * any other browser.
35631
+ */
35632
+ browserBinding: string().optional()
34718
35633
  });
34719
35634
  var ssoBridgeCapability = {
34720
35635
  name: "sso-bridge",
@@ -34732,7 +35647,7 @@ var ssoBridgeCapability = {
34732
35647
  * `/api/auth/sso/finish` to become admin — a full privilege escalation
34733
35648
  * through the exact surface this cap exists to close (see the module
34734
35649
  * docblock). Every real caller (`oauth-grants.ts`, `main.ts`
34735
- * registration, the OIDC/magic-link addons) reaches this through
35650
+ * registration, the OIDC addon) reaches this through
34736
35651
  * `ctx.api` / the in-process registry — never through tRPC — so
34737
35652
  * `auth: 'admin'` costs those callers nothing.
34738
35653
  */
@@ -43535,7 +44450,13 @@ var TopologyNodeSchema = object({
43535
44450
  })).readonly(),
43536
44451
  processes: array(TopologyProcessSchema).readonly(),
43537
44452
  categories: array(TopologyCategorySchema).readonly(),
43538
- rootPackage: TopologyRootPackageSchema.nullable()
44453
+ rootPackage: TopologyRootPackageSchema.nullable(),
44454
+ /**
44455
+ * How an online AGENT reaches the hub (mesh mTLS Release A): `tls` once it has
44456
+ * completed a mutual-TLS handshake, `clear` otherwise. Absent for the hub,
44457
+ * for offline rows and when the hub cannot tell.
44458
+ */
44459
+ meshTransport: _enum(["tls", "clear"]).optional()
43539
44460
  });
43540
44461
  var CapUsageEdgeSchema = object({
43541
44462
  callerAddonId: string(),
@@ -49141,16 +50062,6 @@ var ApiKeySummarySchema = object({
49141
50062
  createdAt: number(),
49142
50063
  lastUsedAt: number().optional()
49143
50064
  });
49144
- var CreateApiKeyInputSchema = object({
49145
- label: string(),
49146
- isAdmin: boolean().default(false),
49147
- allowedProviders: union([array(string()), literal("*")]).optional(),
49148
- allowedDevices: record(string(), union([array(string()), literal("*")])).optional()
49149
- });
49150
- var CreateApiKeyResultSchema = object({
49151
- token: string(),
49152
- record: ApiKeySummarySchema
49153
- });
49154
50065
  var ScopedTokenSummarySchema = object({
49155
50066
  id: string(),
49156
50067
  userId: string(),
@@ -49262,20 +50173,11 @@ var userManagementCapability = {
49262
50173
  access: "view"
49263
50174
  }),
49264
50175
  listApiKeys: method(_void(), array(ApiKeySummarySchema), { auth: "admin" }),
49265
- createApiKey: method(CreateApiKeyInputSchema, CreateApiKeyResultSchema, {
49266
- kind: "mutation",
49267
- auth: "admin",
49268
- access: "create"
49269
- }),
49270
50176
  revokeApiKey: method(object({ id: string() }), object({ success: literal(true) }), {
49271
50177
  kind: "mutation",
49272
50178
  auth: "admin",
49273
50179
  access: "delete"
49274
50180
  }),
49275
- validateApiKey: method(object({ token: string() }), ApiKeySummarySchema.nullable(), {
49276
- kind: "mutation",
49277
- access: "view"
49278
- }),
49279
50181
  createScopedToken: method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
49280
50182
  kind: "mutation",
49281
50183
  auth: "admin",
@@ -49365,20 +50267,6 @@ var userManagementCapability = {
49365
50267
  userId: string(),
49366
50268
  issuer: string()
49367
50269
  }).nullable(), { auth: "admin" }),
49368
- /**
49369
- * Link `(provider, subject)` to `userId`. Idempotent for the same user;
49370
- * REFUSES (throws) an identity already linked to another user, and a
49371
- * user that does not exist.
49372
- */
49373
- linkExternalIdentity: method(ExternalIdentityKeySchema.extend({
49374
- userId: string(),
49375
- issuer: string().min(1),
49376
- label: string().optional()
49377
- }), object({ success: literal(true) }), {
49378
- kind: "mutation",
49379
- auth: "admin",
49380
- access: "create"
49381
- }),
49382
50270
  /** Remove one link of `userId`. `success: false` when it was not linked to that user. */
49383
50271
  unlinkExternalIdentity: method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
49384
50272
  kind: "mutation",
@@ -50089,6 +50977,531 @@ var zoneRulesCapability = {
50089
50977
  */
50090
50978
  durability: "restored"
50091
50979
  };
50980
+ /**
50981
+ * `training-provider` — ONE cloud that can run the CamStack trainer.
50982
+ *
50983
+ * A thin, mockable translation layer: it knows how to run a container with a
50984
+ * GPU, move a dataset in, read the job's stdout and hand artefacts back. It
50985
+ * knows nothing about datasets, splits, floors, cost policy or Model Studio —
50986
+ * those are the `training` orchestrator's (D805). Every rule written there
50987
+ * once is what makes a second provider (RunPod, a local NVIDIA node) a new
50988
+ * manifest entry and nothing else.
50989
+ *
50990
+ * Collection, routed by the `addonId` in every single-row input (the `llm` /
50991
+ * `notification-output` posture); `describe` concat-fans across providers.
50992
+ * Every method is `admin`: these spend money.
50993
+ *
50994
+ * Every cloud object a provider creates is tagged with the orchestrator's
50995
+ * `jobKey`, so a retried submit finds the job it already started instead of
50996
+ * starting a second GPU, and `listJobs` can find orphans.
50997
+ *
50998
+ * Bytes never ride a cap field: the dataset arrives as a `ctx.peerBytes`
50999
+ * ticket the producer (pipeline-analytics) minted, and artefacts leave as a
51000
+ * ticket the provider mints (D613).
51001
+ */
51002
+ var TrainingGpuOptionSchema = object({
51003
+ id: string(),
51004
+ label: string(),
51005
+ /** List price, USD per GPU-hour, before any region multiplier. */
51006
+ usdPerHour: number().nonnegative(),
51007
+ vramGb: number().nonnegative()
51008
+ });
51009
+ var TrainingRegionOptionSchema = object({
51010
+ /** `''` = any region (the provider's choice). */
51011
+ id: string(),
51012
+ label: string(),
51013
+ priceMultiplier: number().positive()
51014
+ });
51015
+ /**
51016
+ * The provider's per-account settings, as the orchestrator reads them. They
51017
+ * live in the PROVIDER addon's settings (operator decision 2026-10-08: they
51018
+ * depend on the user's account), never hard-coded in the orchestrator.
51019
+ */
51020
+ var TrainingProviderDefaultsSchema = object({
51021
+ gpuType: string(),
51022
+ region: string(),
51023
+ costCapUsd: number().nonnegative(),
51024
+ maxRuntimeSec: number().int().positive(),
51025
+ /** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
51026
+ failedDatasetGraceHours: number().nonnegative()
51027
+ });
51028
+ var TrainingProviderDescriptorSchema = object({
51029
+ addonId: string(),
51030
+ /** `modal`, `runpod`, `fake`, … */
51031
+ kind: string(),
51032
+ label: string(),
51033
+ gpuTypes: array(TrainingGpuOptionSchema).readonly(),
51034
+ regions: array(TrainingRegionOptionSchema).readonly(),
51035
+ maxDatasetBytes: number().int().positive(),
51036
+ maxRuntimeSec: number().int().positive(),
51037
+ freeTierNote: string().optional(),
51038
+ /** Where the data goes, in one sentence the confirm dialog repeats. */
51039
+ dataResidencyNote: string(),
51040
+ /** Credentials are present — never the values. */
51041
+ configured: boolean(),
51042
+ defaults: TrainingProviderDefaultsSchema
51043
+ });
51044
+ var TrainingCredentialCheckSchema = object({
51045
+ ok: boolean(),
51046
+ /** Workspace / account name, when the provider says. */
51047
+ account: string().optional(),
51048
+ reason: _enum([
51049
+ "missing",
51050
+ "invalid",
51051
+ "forbidden",
51052
+ "network",
51053
+ "quota"
51054
+ ]).optional(),
51055
+ detail: string().optional()
51056
+ });
51057
+ var ProviderJobStateSchema = _enum([
51058
+ "pending",
51059
+ "starting",
51060
+ "running",
51061
+ "succeeded",
51062
+ "failed",
51063
+ "cancelled",
51064
+ "lost"
51065
+ ]);
51066
+ var ProviderJobStatusSchema = object({
51067
+ jobKey: string(),
51068
+ providerJobId: string().optional(),
51069
+ state: ProviderJobStateSchema,
51070
+ startedAt: number().optional(),
51071
+ endedAt: number().optional(),
51072
+ exitCode: number().int().optional(),
51073
+ failureReason: string().optional(),
51074
+ gpuType: string(),
51075
+ region: string().optional(),
51076
+ billedSeconds: number().nonnegative(),
51077
+ costUsd: number().nonnegative(),
51078
+ /** True when `costUsd` is runtime × list price, not a billing answer. */
51079
+ costIsEstimate: boolean(),
51080
+ lastFetchedAt: number()
51081
+ });
51082
+ /**
51083
+ * The trainer the job runs, by SOURCE revision: the provider turns it into an
51084
+ * image its own way (Modal builds the published Dockerfile at that revision;
51085
+ * a registry-pull provider maps it to a tag). Recorded on the job and echoed
51086
+ * in `result.json`.
51087
+ */
51088
+ var TrainerSourceRefSchema = object({
51089
+ /** Hugging Face repo id, e.g. `camstack/camstack-trainer`. */
51090
+ repo: string().min(1),
51091
+ /** A commit sha (never a branch) — the job must be reproducible. */
51092
+ revision: string().regex(/^[0-9a-f]{7,64}$/)
51093
+ });
51094
+ var JobRef = {
51095
+ addonId: string(),
51096
+ jobKey: string().uuid()
51097
+ };
51098
+ var TrainingLogLineSchema = object({
51099
+ ts: number(),
51100
+ text: string()
51101
+ });
51102
+ var trainingProviderCapability = {
51103
+ name: "training-provider",
51104
+ scope: "system",
51105
+ mode: "collection",
51106
+ internal: true,
51107
+ methods: {
51108
+ /** Every provider's offer and settings. Concat-fans across providers. */
51109
+ describe: method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }),
51110
+ /** Call the provider with the stored credentials. Never returns them. */
51111
+ validateCredentials: method(object({ addonId: string() }), TrainingCredentialCheckSchema, {
51112
+ kind: "mutation",
51113
+ auth: "admin",
51114
+ timeoutMs: 3e4
51115
+ }),
51116
+ /** USD range for a run of `gpuSeconds` on `gpuType` in `region`. */
51117
+ estimateJob: method(object({
51118
+ addonId: string(),
51119
+ gpuType: string(),
51120
+ region: string(),
51121
+ datasetBytes: number().int().nonnegative(),
51122
+ gpuSecondsLow: number().nonnegative(),
51123
+ gpuSecondsHigh: number().nonnegative()
51124
+ }), object({
51125
+ usdLow: number().nonnegative(),
51126
+ usdHigh: number().nonnegative(),
51127
+ notes: array(string()).readonly()
51128
+ }), { auth: "admin" }),
51129
+ /**
51130
+ * Take the dataset archive behind `ticket` (minted by pipeline-analytics,
51131
+ * same host) and land it as the job's dataset in the cloud, streamed —
51132
+ * nothing is staged on the hub's disk. Idempotent per `jobKey`: a second
51133
+ * call replaces a partial upload. Answers what actually landed.
51134
+ */
51135
+ uploadDataset: method(object({
51136
+ ...JobRef,
51137
+ ticket: PeerBytesTicketSchema
51138
+ }), object({
51139
+ bytes: number().int().nonnegative(),
51140
+ sha256: string()
51141
+ }), {
51142
+ kind: "mutation",
51143
+ auth: "admin",
51144
+ timeoutMs: 120 * 6e4
51145
+ }),
51146
+ /**
51147
+ * Start the trainer on a GPU. Looks the job up by `jobKey` first, so a
51148
+ * retried submit never starts a second GPU. `jobSpecJson` is written next
51149
+ * to the dataset as `job.json`; `maxRuntimeSec` is enforced by the
51150
+ * provider (a hard timeout), not by the hub.
51151
+ */
51152
+ submitJob: method(object({
51153
+ ...JobRef,
51154
+ trainer: TrainerSourceRefSchema,
51155
+ jobSpecJson: string().min(2).max(64e3),
51156
+ gpuType: string(),
51157
+ region: string(),
51158
+ maxRuntimeSec: number().int().positive()
51159
+ }), ProviderJobStatusSchema, {
51160
+ kind: "mutation",
51161
+ auth: "admin",
51162
+ timeoutMs: 30 * 6e4
51163
+ }),
51164
+ getJob: method(object(JobRef), ProviderJobStatusSchema, {
51165
+ auth: "admin",
51166
+ timeoutMs: 6e4
51167
+ }),
51168
+ /** Stdout/stderr since `cursor` (opaque), oldest first, at most `max` lines. */
51169
+ listJobEvents: method(object({
51170
+ ...JobRef,
51171
+ cursor: string().optional(),
51172
+ max: number().int().min(1).max(500)
51173
+ }), object({
51174
+ lines: array(TrainingLogLineSchema).readonly(),
51175
+ cursor: string()
51176
+ }), {
51177
+ auth: "admin",
51178
+ timeoutMs: 6e4
51179
+ }),
51180
+ /** Stop the job. Idempotent: an unknown or finished job is a no-op. */
51181
+ cancelJob: method(object(JobRef), object({ ok: literal(true) }), {
51182
+ kind: "mutation",
51183
+ auth: "admin",
51184
+ timeoutMs: 6e4
51185
+ }),
51186
+ /** The job's `result.json`, as text (small, JSON). `found: false` before it exists. */
51187
+ readResult: method(object(JobRef), object({
51188
+ found: boolean(),
51189
+ text: string().optional()
51190
+ }), {
51191
+ kind: "mutation",
51192
+ auth: "admin",
51193
+ timeoutMs: 5 * 6e4
51194
+ }),
51195
+ /**
51196
+ * Offer one output file of the job (`bundle.tar`) to the caller as a
51197
+ * one-shot `ctx.peerBytes` ticket, streamed from the cloud — the provider
51198
+ * stages nothing on disk. The caller dials it at once.
51199
+ */
51200
+ offerArtifact: method(object({
51201
+ ...JobRef,
51202
+ path: _enum(["bundle.tar"])
51203
+ }), object({ ticket: PeerBytesTicketSchema }), {
51204
+ kind: "mutation",
51205
+ auth: "admin",
51206
+ timeoutMs: 5 * 6e4
51207
+ }),
51208
+ /** Delete every cloud object tagged with `jobKey` (the dataset first). Idempotent. */
51209
+ cleanupJob: method(object(JobRef), object({ deleted: array(string()).readonly() }), {
51210
+ kind: "mutation",
51211
+ auth: "admin",
51212
+ timeoutMs: 5 * 6e4
51213
+ }),
51214
+ /** Every job the provider can still see — the orphan sweep diffs it against our records. */
51215
+ listJobs: method(object({ addonId: string() }), array(ProviderJobStatusSchema).readonly(), {
51216
+ auth: "admin",
51217
+ timeoutMs: 2 * 6e4
51218
+ })
51219
+ }
51220
+ };
51221
+ /**
51222
+ * `training` — the cloud-training orchestrator (D805). Hub-only singleton,
51223
+ * provided by `addon-training`.
51224
+ *
51225
+ * It owns what every provider must agree on, written once:
51226
+ *
51227
+ * - **Dataset versions.** Taken over from pipeline-analytics (D796): the rows
51228
+ * live here (D808); pipeline-analytics still CUTS a version (it owns the corpus and
51229
+ * the export plan) and reaches this store through the five row methods
51230
+ * below, so the Retrain page and the export did not change.
51231
+ * - **Jobs.** A persisted state machine, a reconcile loop against the
51232
+ * provider, a cost guard, a daily orphan sweep and the retention rules.
51233
+ * - **The return flow.** Verified artefacts → Model Studio
51234
+ * (`custom-model-registry.importModelBundle`) → canary on cameras →
51235
+ * rollback. Nothing is ever registered automatically.
51236
+ *
51237
+ * Every method is `admin`.
51238
+ */
51239
+ /** A version WITH its frame list — what the export and a job read. */
51240
+ var TrainingDatasetVersionRowSchema = RetrainDatasetVersionSchema.omit({ frameCount: true }).extend({ frameIds: array(string()).max(2e4).readonly() });
51241
+ /** A base model a detector job can fine-tune, and the baseline it is judged against. */
51242
+ var TrainingBaseModelSchema = object({
51243
+ modelId: string(),
51244
+ label: string(),
51245
+ weights: string(),
51246
+ imgsz: number().int(),
51247
+ baselineOnnxUrl: string(),
51248
+ baselineFloors: record(string(), number()),
51249
+ /** The base the fleet runs most — the UI's default. */
51250
+ recommended: boolean()
51251
+ });
51252
+ var TrainingPresetSchema = _enum([
51253
+ "quick",
51254
+ "standard",
51255
+ "thorough"
51256
+ ]);
51257
+ var TrainingJobRequestSchema = object({
51258
+ datasetVersionId: string().min(1),
51259
+ /** The `training-provider` addon that runs it. */
51260
+ addonId: string().min(1),
51261
+ gpuType: string().min(1),
51262
+ region: string(),
51263
+ baseModelId: string().min(1),
51264
+ preset: TrainingPresetSchema,
51265
+ /** Freeze the backbone's first N layers; `null` = the preset's choice. */
51266
+ freeze: number().int().nonnegative().nullable(),
51267
+ /** Cameras held out whole for evaluation; `null` = the orchestrator's default. */
51268
+ holdoutCameras: array(number().int()).nullable()
51269
+ });
51270
+ var TrainingSplitPlanSchema = object({
51271
+ holdoutCameras: array(number().int()).readonly(),
51272
+ /** Used when no camera is held out: the last N days of every camera. */
51273
+ holdoutLastDays: number().int().nonnegative(),
51274
+ /** Holdout subjects per class (camera holdout only; `null` = known only after the split). */
51275
+ holdoutSupport: record(string(), number().int()).nullable(),
51276
+ trainSubjects: number().int()
51277
+ });
51278
+ var TrainingRefusalReasonSchema = _enum([
51279
+ "unknown-dataset",
51280
+ "unknown-provider",
51281
+ "provider-not-configured",
51282
+ "unknown-base-model",
51283
+ "unknown-gpu",
51284
+ "dataset-too-large",
51285
+ "no-training-subjects",
51286
+ "job-already-running"
51287
+ ]);
51288
+ var TrainingJobPlanSchema = object({
51289
+ refusal: object({
51290
+ reason: TrainingRefusalReasonSchema,
51291
+ detail: string()
51292
+ }).nullable(),
51293
+ warnings: array(string()).readonly(),
51294
+ split: TrainingSplitPlanSchema.nullable(),
51295
+ estimate: object({
51296
+ datasetBytes: number().int(),
51297
+ uploadMinutesAt20Mbps: number(),
51298
+ gpuSecondsLow: number(),
51299
+ gpuSecondsHigh: number(),
51300
+ usdLow: number(),
51301
+ usdHigh: number(),
51302
+ notes: array(string()).readonly()
51303
+ }).nullable(),
51304
+ /** Pre-filled from the provider's settings; the operator may lower or raise them. */
51305
+ defaults: object({
51306
+ maxCostUsd: number(),
51307
+ maxRuntimeSec: number().int()
51308
+ }).nullable(),
51309
+ /** The sentence the confirm dialog repeats: where the frames go and when they are deleted. */
51310
+ dataNotice: string()
51311
+ });
51312
+ /**
51313
+ * Orchestrator-owned states, persisted. `uploading` covers exporting the
51314
+ * archive (it is streamed, never staged). Terminal: `failed`, `cancelled`,
51315
+ * `lost`, `expired`, `discarded`. `registered` and `canary` are where a
51316
+ * result lives after the operator acted on it.
51317
+ */
51318
+ var TrainingJobStateSchema = _enum([
51319
+ "uploading",
51320
+ "submitted",
51321
+ "starting",
51322
+ "running",
51323
+ "collecting",
51324
+ "ready",
51325
+ "registered",
51326
+ "canary",
51327
+ "failed",
51328
+ "cancelling",
51329
+ "cancelled",
51330
+ "lost",
51331
+ "expired",
51332
+ "discarded"
51333
+ ]);
51334
+ var TrainingFailureReasonSchema = _enum([
51335
+ "cost-cap",
51336
+ "runtime-cap",
51337
+ "upload-failed",
51338
+ "submit-failed",
51339
+ "trainer-failed",
51340
+ "result-invalid",
51341
+ "checksum-mismatch",
51342
+ "fetch-failed",
51343
+ "provider-error",
51344
+ "hub-restart-during-upload"
51345
+ ]);
51346
+ var TrainingProgressPointSchema = object({
51347
+ epoch: number().int(),
51348
+ map50: number().nullable(),
51349
+ map50_95: number().nullable()
51350
+ });
51351
+ var TrainingCanarySchema = object({
51352
+ deviceIds: array(number().int()).readonly(),
51353
+ since: number(),
51354
+ /** Every override the canary replaced, exactly, so rollback restores it. */
51355
+ previous: array(object({
51356
+ deviceId: number().int(),
51357
+ nodeId: string(),
51358
+ deviceKey: string(),
51359
+ patch: object({
51360
+ modelId: string().optional(),
51361
+ settings: record(string(), unknown()).readonly().optional()
51362
+ }).nullable()
51363
+ })).readonly()
51364
+ });
51365
+ var TrainingJobSchema = object({
51366
+ id: string(),
51367
+ idempotencyKey: string(),
51368
+ name: string(),
51369
+ createdAt: number(),
51370
+ updatedAt: number(),
51371
+ state: TrainingJobStateSchema,
51372
+ stage: TrainingStageSchema.nullable(),
51373
+ failure: object({
51374
+ reason: TrainingFailureReasonSchema,
51375
+ stage: string().nullable(),
51376
+ detail: string()
51377
+ }).nullable(),
51378
+ request: TrainingJobRequestSchema,
51379
+ maxCostUsd: number().nonnegative(),
51380
+ maxRuntimeSec: number().int().positive(),
51381
+ trainer: TrainerSourceRefSchema,
51382
+ datasetLayout: RetrainExportLayoutSchema,
51383
+ dataset: object({
51384
+ bytes: number().int(),
51385
+ sha256: string(),
51386
+ uploadedAt: number()
51387
+ }).nullable(),
51388
+ split: TrainingSplitPlanSchema,
51389
+ provider: object({
51390
+ state: ProviderJobStateSchema.nullable(),
51391
+ providerJobId: string().nullable(),
51392
+ startedAt: number().nullable(),
51393
+ endedAt: number().nullable(),
51394
+ billedSeconds: number(),
51395
+ costUsd: number(),
51396
+ costIsEstimate: boolean(),
51397
+ lastPolledAt: number().nullable()
51398
+ }),
51399
+ progress: object({
51400
+ epoch: number().int().nullable(),
51401
+ epochs: number().int().nullable(),
51402
+ etaSec: number().nullable(),
51403
+ series: array(TrainingProgressPointSchema).readonly()
51404
+ }),
51405
+ /** The last lines of the job's output (≤ 200), newest last. Never frame paths. */
51406
+ logTail: array(string()).readonly(),
51407
+ logCursor: string().nullable(),
51408
+ artifacts: object({
51409
+ bundleBytes: number().int(),
51410
+ bundleSha256: string(),
51411
+ fetchedAt: number(),
51412
+ /** When the staged artefacts are deleted from the hub. */
51413
+ expiresAt: number()
51414
+ }).nullable(),
51415
+ /** When the provider-side copy of the frames was deleted; null while it exists. */
51416
+ cloudDatasetDeletedAt: number().nullable(),
51417
+ /** A failed job's dataset is kept until then (the provider's grace), then deleted. */
51418
+ cloudCleanupDueAt: number().nullable(),
51419
+ /** Model ids registered from this job (base, and int8 when kept). */
51420
+ registeredModelIds: array(string()).readonly(),
51421
+ canary: TrainingCanarySchema.nullable()
51422
+ });
51423
+ var IdInput = object({ id: string().min(1) });
51424
+ var trainingCapability = {
51425
+ name: "training",
51426
+ scope: "system",
51427
+ mode: "singleton",
51428
+ mount: { kind: "hub-only" },
51429
+ methods: {
51430
+ /** Store a version once. `stored: false` = that id already exists (immutable). */
51431
+ putDatasetVersion: method(TrainingDatasetVersionRowSchema, object({ stored: boolean() }), {
51432
+ kind: "mutation",
51433
+ auth: "admin"
51434
+ }),
51435
+ getDatasetVersion: method(IdInput, TrainingDatasetVersionRowSchema.nullable(), { auth: "admin" }),
51436
+ /** Every version without its frame list, newest first. */
51437
+ listDatasetVersions: method(object({}), array(RetrainDatasetVersionSchema).readonly(), { auth: "admin" }),
51438
+ findDatasetVersionIdByName: method(object({ name: string() }), object({ id: string().nullable() }), { auth: "admin" }),
51439
+ removeDatasetVersion: method(IdInput, object({ removed: boolean() }), {
51440
+ kind: "mutation",
51441
+ auth: "admin"
51442
+ }),
51443
+ listBaseModels: method(object({}), array(TrainingBaseModelSchema).readonly(), { auth: "admin" }),
51444
+ /** Split, estimate, defaults and any named refusal — nothing is started. */
51445
+ planJob: method(TrainingJobRequestSchema, TrainingJobPlanSchema, {
51446
+ auth: "admin",
51447
+ timeoutMs: 6e4
51448
+ }),
51449
+ /**
51450
+ * Start a job. The same `idempotencyKey` returns the job it already
51451
+ * started. Answers at once (`uploading`); the upload and the submit run in
51452
+ * the background and the job record says how far they got.
51453
+ */
51454
+ startJob: method(TrainingJobRequestSchema.extend({
51455
+ name: string().min(1).max(120),
51456
+ maxCostUsd: number().positive(),
51457
+ maxRuntimeSec: number().int().positive(),
51458
+ idempotencyKey: string().min(8).max(80)
51459
+ }), discriminatedUnion("kind", [object({
51460
+ kind: literal("started"),
51461
+ job: TrainingJobSchema
51462
+ }), object({
51463
+ kind: literal("refused"),
51464
+ reason: TrainingRefusalReasonSchema,
51465
+ detail: string()
51466
+ })]), {
51467
+ kind: "mutation",
51468
+ auth: "admin",
51469
+ timeoutMs: 12e4
51470
+ }),
51471
+ listJobs: method(object({}), array(TrainingJobSchema).readonly(), { auth: "admin" }),
51472
+ getJob: method(IdInput, TrainingJobSchema.nullable(), { auth: "admin" }),
51473
+ cancelJob: method(IdInput, TrainingJobSchema, {
51474
+ kind: "mutation",
51475
+ auth: "admin",
51476
+ timeoutMs: 12e4
51477
+ }),
51478
+ /** The verified `result.json` of a job in `ready` or later; null before. */
51479
+ getJobResult: method(IdInput, TrainingResultSchema.nullable(), { auth: "admin" }),
51480
+ /** Hand the verified bundle to Model Studio; optionally canary right after. */
51481
+ registerResult: method(IdInput.extend({ canaryDeviceIds: array(number().int()).readonly() }), TrainingJobSchema, {
51482
+ kind: "mutation",
51483
+ auth: "admin",
51484
+ timeoutMs: 30 * 6e4
51485
+ }),
51486
+ /** Pin the registered model on these cameras, remembering what it replaced. */
51487
+ canaryResult: method(IdInput.extend({ deviceIds: array(number().int()).min(1).readonly() }), TrainingJobSchema, {
51488
+ kind: "mutation",
51489
+ auth: "admin",
51490
+ timeoutMs: 12e4
51491
+ }),
51492
+ /** Put every canary camera back exactly as it was. */
51493
+ rollbackCanary: method(IdInput, TrainingJobSchema, {
51494
+ kind: "mutation",
51495
+ auth: "admin",
51496
+ timeoutMs: 12e4
51497
+ }),
51498
+ /** Delete the staged artefacts of an unregistered result. */
51499
+ discardResult: method(IdInput, TrainingJobSchema, {
51500
+ kind: "mutation",
51501
+ auth: "admin"
51502
+ })
51503
+ }
51504
+ };
50092
51505
  SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
50093
51506
  Object.freeze({
50094
51507
  person: .5,
@@ -51813,6 +53226,12 @@ Object.freeze({
51813
53226
  addonId: null,
51814
53227
  access: "create"
51815
53228
  },
53229
+ "backup.checkBackupKey": {
53230
+ capName: "backup",
53231
+ capScope: "system",
53232
+ addonId: null,
53233
+ access: "create"
53234
+ },
51816
53235
  "backup.delete": {
51817
53236
  capName: "backup",
51818
53237
  capScope: "system",
@@ -51825,6 +53244,18 @@ Object.freeze({
51825
53244
  addonId: null,
51826
53245
  access: "delete"
51827
53246
  },
53247
+ "backup.disableEncryption": {
53248
+ capName: "backup",
53249
+ capScope: "system",
53250
+ addonId: null,
53251
+ access: "create"
53252
+ },
53253
+ "backup.getEncryption": {
53254
+ capName: "backup",
53255
+ capScope: "system",
53256
+ addonId: null,
53257
+ access: "view"
53258
+ },
51828
53259
  "backup.getEntries": {
51829
53260
  capName: "backup",
51830
53261
  capScope: "system",
@@ -51879,6 +53310,12 @@ Object.freeze({
51879
53310
  addonId: null,
51880
53311
  access: "create"
51881
53312
  },
53313
+ "backup.setupEncryption": {
53314
+ capName: "backup",
53315
+ capScope: "system",
53316
+ addonId: null,
53317
+ access: "create"
53318
+ },
51882
53319
  "backup.trigger": {
51883
53320
  capName: "backup",
51884
53321
  capScope: "system",
@@ -52431,6 +53868,12 @@ Object.freeze({
52431
53868
  addonId: null,
52432
53869
  access: "create"
52433
53870
  },
53871
+ "customModelRegistry.importModelBundle": {
53872
+ capName: "custom-model-registry",
53873
+ capScope: "system",
53874
+ addonId: null,
53875
+ access: "create"
53876
+ },
52434
53877
  "customModelRegistry.listModels": {
52435
53878
  capName: "custom-model-registry",
52436
53879
  capScope: "system",
@@ -53871,6 +55314,12 @@ Object.freeze({
53871
55314
  addonId: null,
53872
55315
  access: "view"
53873
55316
  },
55317
+ "keychainAdmin.acknowledgeReset": {
55318
+ capName: "keychain-admin",
55319
+ capScope: "system",
55320
+ addonId: null,
55321
+ access: "create"
55322
+ },
53874
55323
  "keychainAdmin.deleteOrphans": {
53875
55324
  capName: "keychain-admin",
53876
55325
  capScope: "system",
@@ -53907,6 +55356,12 @@ Object.freeze({
53907
55356
  addonId: null,
53908
55357
  access: "delete"
53909
55358
  },
55359
+ "keychainAdmin.resetReport": {
55360
+ capName: "keychain-admin",
55361
+ capScope: "system",
55362
+ addonId: null,
55363
+ access: "delete"
55364
+ },
53910
55365
  "keychainAdmin.reveal": {
53911
55366
  capName: "keychain-admin",
53912
55367
  capScope: "system",
@@ -55653,6 +57108,12 @@ Object.freeze({
55653
57108
  addonId: null,
55654
57109
  access: "view"
55655
57110
  },
57111
+ "pipelineAnalytics.offerRetrainArchive": {
57112
+ capName: "pipeline-analytics",
57113
+ capScope: "device",
57114
+ addonId: null,
57115
+ access: "create"
57116
+ },
55656
57117
  "pipelineAnalytics.ownersWithMedia": {
55657
57118
  capName: "pipeline-analytics",
55658
57119
  capScope: "device",
@@ -58191,6 +59652,174 @@ Object.freeze({
58191
59652
  addonId: null,
58192
59653
  access: "view"
58193
59654
  },
59655
+ "training.canaryResult": {
59656
+ capName: "training",
59657
+ capScope: "system",
59658
+ addonId: null,
59659
+ access: "create"
59660
+ },
59661
+ "training.cancelJob": {
59662
+ capName: "training",
59663
+ capScope: "system",
59664
+ addonId: null,
59665
+ access: "create"
59666
+ },
59667
+ "training.discardResult": {
59668
+ capName: "training",
59669
+ capScope: "system",
59670
+ addonId: null,
59671
+ access: "create"
59672
+ },
59673
+ "training.findDatasetVersionIdByName": {
59674
+ capName: "training",
59675
+ capScope: "system",
59676
+ addonId: null,
59677
+ access: "view"
59678
+ },
59679
+ "training.getDatasetVersion": {
59680
+ capName: "training",
59681
+ capScope: "system",
59682
+ addonId: null,
59683
+ access: "view"
59684
+ },
59685
+ "training.getJob": {
59686
+ capName: "training",
59687
+ capScope: "system",
59688
+ addonId: null,
59689
+ access: "view"
59690
+ },
59691
+ "training.getJobResult": {
59692
+ capName: "training",
59693
+ capScope: "system",
59694
+ addonId: null,
59695
+ access: "view"
59696
+ },
59697
+ "training.listBaseModels": {
59698
+ capName: "training",
59699
+ capScope: "system",
59700
+ addonId: null,
59701
+ access: "view"
59702
+ },
59703
+ "training.listDatasetVersions": {
59704
+ capName: "training",
59705
+ capScope: "system",
59706
+ addonId: null,
59707
+ access: "view"
59708
+ },
59709
+ "training.listJobs": {
59710
+ capName: "training",
59711
+ capScope: "system",
59712
+ addonId: null,
59713
+ access: "view"
59714
+ },
59715
+ "training.planJob": {
59716
+ capName: "training",
59717
+ capScope: "system",
59718
+ addonId: null,
59719
+ access: "view"
59720
+ },
59721
+ "training.putDatasetVersion": {
59722
+ capName: "training",
59723
+ capScope: "system",
59724
+ addonId: null,
59725
+ access: "create"
59726
+ },
59727
+ "training.registerResult": {
59728
+ capName: "training",
59729
+ capScope: "system",
59730
+ addonId: null,
59731
+ access: "create"
59732
+ },
59733
+ "training.removeDatasetVersion": {
59734
+ capName: "training",
59735
+ capScope: "system",
59736
+ addonId: null,
59737
+ access: "delete"
59738
+ },
59739
+ "training.rollbackCanary": {
59740
+ capName: "training",
59741
+ capScope: "system",
59742
+ addonId: null,
59743
+ access: "create"
59744
+ },
59745
+ "training.startJob": {
59746
+ capName: "training",
59747
+ capScope: "system",
59748
+ addonId: null,
59749
+ access: "create"
59750
+ },
59751
+ "trainingProvider.cancelJob": {
59752
+ capName: "training-provider",
59753
+ capScope: "system",
59754
+ addonId: null,
59755
+ access: "create"
59756
+ },
59757
+ "trainingProvider.cleanupJob": {
59758
+ capName: "training-provider",
59759
+ capScope: "system",
59760
+ addonId: null,
59761
+ access: "create"
59762
+ },
59763
+ "trainingProvider.describe": {
59764
+ capName: "training-provider",
59765
+ capScope: "system",
59766
+ addonId: null,
59767
+ access: "view"
59768
+ },
59769
+ "trainingProvider.estimateJob": {
59770
+ capName: "training-provider",
59771
+ capScope: "system",
59772
+ addonId: null,
59773
+ access: "view"
59774
+ },
59775
+ "trainingProvider.getJob": {
59776
+ capName: "training-provider",
59777
+ capScope: "system",
59778
+ addonId: null,
59779
+ access: "view"
59780
+ },
59781
+ "trainingProvider.listJobEvents": {
59782
+ capName: "training-provider",
59783
+ capScope: "system",
59784
+ addonId: null,
59785
+ access: "view"
59786
+ },
59787
+ "trainingProvider.listJobs": {
59788
+ capName: "training-provider",
59789
+ capScope: "system",
59790
+ addonId: null,
59791
+ access: "view"
59792
+ },
59793
+ "trainingProvider.offerArtifact": {
59794
+ capName: "training-provider",
59795
+ capScope: "system",
59796
+ addonId: null,
59797
+ access: "create"
59798
+ },
59799
+ "trainingProvider.readResult": {
59800
+ capName: "training-provider",
59801
+ capScope: "system",
59802
+ addonId: null,
59803
+ access: "create"
59804
+ },
59805
+ "trainingProvider.submitJob": {
59806
+ capName: "training-provider",
59807
+ capScope: "system",
59808
+ addonId: null,
59809
+ access: "create"
59810
+ },
59811
+ "trainingProvider.uploadDataset": {
59812
+ capName: "training-provider",
59813
+ capScope: "system",
59814
+ addonId: null,
59815
+ access: "create"
59816
+ },
59817
+ "trainingProvider.validateCredentials": {
59818
+ capName: "training-provider",
59819
+ capScope: "system",
59820
+ addonId: null,
59821
+ access: "create"
59822
+ },
58194
59823
  "turnProvider.getTurnServers": {
58195
59824
  capName: "turn-provider",
58196
59825
  capScope: "system",
@@ -58215,12 +59844,6 @@ Object.freeze({
58215
59844
  addonId: null,
58216
59845
  access: "create"
58217
59846
  },
58218
- "userManagement.createApiKey": {
58219
- capName: "user-management",
58220
- capScope: "system",
58221
- addonId: null,
58222
- access: "create"
58223
- },
58224
59847
  "userManagement.createScopedToken": {
58225
59848
  capName: "user-management",
58226
59849
  capScope: "system",
@@ -58257,12 +59880,6 @@ Object.freeze({
58257
59880
  addonId: null,
58258
59881
  access: "view"
58259
59882
  },
58260
- "userManagement.linkExternalIdentity": {
58261
- capName: "user-management",
58262
- capScope: "system",
58263
- addonId: null,
58264
- access: "create"
58265
- },
58266
59883
  "userManagement.listApiKeys": {
58267
59884
  capName: "user-management",
58268
59885
  capScope: "system",
@@ -58365,12 +59982,6 @@ Object.freeze({
58365
59982
  addonId: null,
58366
59983
  access: "create"
58367
59984
  },
58368
- "userManagement.validateApiKey": {
58369
- capName: "user-management",
58370
- capScope: "system",
58371
- addonId: null,
58372
- access: "view"
58373
- },
58374
59985
  "userManagement.validateCredentials": {
58375
59986
  capName: "user-management",
58376
59987
  capScope: "system",
@@ -60284,6 +61895,8 @@ var ALL_CAPABILITY_DEFINITIONS = [
60284
61895
  temperatureSensorCapability,
60285
61896
  terminalSessionCapability,
60286
61897
  toastCapability,
61898
+ trainingCapability,
61899
+ trainingProviderCapability,
60287
61900
  turnProviderCapability,
60288
61901
  updateCapability,
60289
61902
  userManagementCapability,
@@ -62662,6 +64275,11 @@ Object.freeze({
62662
64275
  form: "single",
62663
64276
  optional: false
62664
64277
  }],
64278
+ "training.canaryResult": [{
64279
+ name: "deviceIds",
64280
+ form: "array",
64281
+ optional: false
64282
+ }],
62665
64283
  "update.getStatus": [{
62666
64284
  name: "deviceId",
62667
64285
  form: "single",
@@ -64595,6 +66213,26 @@ var NC_TEMPLATE_VARS = [
64595
66213
  "server-updated"
64596
66214
  ]
64597
66215
  },
66216
+ {
66217
+ name: "nodeName",
66218
+ label: "Node name",
66219
+ example: "little-unraid",
66220
+ group: "system",
66221
+ families: ["rule"],
66222
+ fields: [...RULE_TEXT],
66223
+ kinds: ["system"],
66224
+ systemEventKinds: ["node-online", "node-offline"]
66225
+ },
66226
+ {
66227
+ name: "offlineFor",
66228
+ label: "Offline for",
66229
+ example: "44 min",
66230
+ group: "system",
66231
+ families: ["rule"],
66232
+ fields: [...RULE_TEXT],
66233
+ kinds: ["system"],
66234
+ systemEventKinds: ["node-online"]
66235
+ },
64598
66236
  {
64599
66237
  name: "devices",
64600
66238
  label: "Devices",