@camstack/addon-matter-broker 0.2.123 → 0.2.124

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 (3) hide show
  1. package/dist/addon.js +1771 -131
  2. package/dist/addon.mjs +1771 -131
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -5391,7 +5391,7 @@ var ZodIssueCode = {
5391
5391
  var ZodFirstPartyTypeKind;
5392
5392
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5393
5393
  //#endregion
5394
- //#region ../types/dist/sleep-Cr5YOk3m.mjs
5394
+ //#region ../types/dist/sleep-r3RWkGVx.mjs
5395
5395
  /**
5396
5396
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5397
5397
  * window to float samples (D455).
@@ -5508,7 +5508,7 @@ function isKeychainStoredField(field) {
5508
5508
  var SECRET_CLEAR = { $secretClear: true };
5509
5509
  /** The `'***'` token D634 redaction writes for non-admins. */
5510
5510
  var LEGACY_DEVICE_REDACTION = "***";
5511
- function isRecord$1$1(value) {
5511
+ function isRecord$2(value) {
5512
5512
  return typeof value === "object" && value !== null && !Array.isArray(value);
5513
5513
  }
5514
5514
  function makeSecretMarker(ref) {
@@ -5519,12 +5519,12 @@ function makeSecretMarker(ref) {
5519
5519
  }
5520
5520
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5521
5521
  function isSecretMarker(value) {
5522
- if (!isRecord$1$1(value)) return false;
5522
+ if (!isRecord$2(value)) return false;
5523
5523
  const ref = value["$secret"];
5524
5524
  return typeof ref === "string" && ref.length > 0;
5525
5525
  }
5526
5526
  function isSecretClear(value) {
5527
- return isRecord$1$1(value) && value["$secretClear"] === true;
5527
+ return isRecord$2(value) && value["$secretClear"] === true;
5528
5528
  }
5529
5529
  /**
5530
5530
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6040,6 +6040,13 @@ function globalSecretScope() {
6040
6040
  function encodeSegment(value) {
6041
6041
  return encodeURIComponent(value);
6042
6042
  }
6043
+ function decodeSegment(value) {
6044
+ try {
6045
+ return decodeURIComponent(value);
6046
+ } catch {
6047
+ return null;
6048
+ }
6049
+ }
6043
6050
  /**
6044
6051
  * The field path of a value inside an array item, addressed by the item's id:
6045
6052
  * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
@@ -6048,6 +6055,75 @@ function encodeSegment(value) {
6048
6055
  function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6049
6056
  return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6050
6057
  }
6058
+ function parseScope(segments) {
6059
+ switch (segments[0]) {
6060
+ case "global": return {
6061
+ scope: GLOBAL_SCOPE,
6062
+ used: 1
6063
+ };
6064
+ case "node": {
6065
+ const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6066
+ return nodeId === null || nodeId.length === 0 ? null : {
6067
+ scope: {
6068
+ kind: "node",
6069
+ nodeId
6070
+ },
6071
+ used: 2
6072
+ };
6073
+ }
6074
+ case "device": {
6075
+ const raw = segments[1];
6076
+ if (raw === void 0 || !/^\d+$/.test(raw)) return null;
6077
+ return {
6078
+ scope: {
6079
+ kind: "device",
6080
+ deviceId: Number(raw)
6081
+ },
6082
+ used: 2
6083
+ };
6084
+ }
6085
+ case "integration": {
6086
+ const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6087
+ return id === null || id.length === 0 ? null : {
6088
+ scope: {
6089
+ kind: "integration",
6090
+ integrationId: id
6091
+ },
6092
+ used: 2
6093
+ };
6094
+ }
6095
+ case "row": {
6096
+ const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6097
+ const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
6098
+ if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
6099
+ return {
6100
+ scope: {
6101
+ kind: "row",
6102
+ collection,
6103
+ rowId
6104
+ },
6105
+ used: 3
6106
+ };
6107
+ }
6108
+ default: return null;
6109
+ }
6110
+ }
6111
+ /** Take a ref apart; `null` when it is not a well-formed ref. */
6112
+ function parseSecretRef(ref) {
6113
+ if (!ref.startsWith("secret://")) return null;
6114
+ const segments = ref.slice(9).split("/");
6115
+ const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
6116
+ if (owner === null || owner.length === 0) return null;
6117
+ const parsed = parseScope(segments.slice(1));
6118
+ if (parsed === null) return null;
6119
+ const fieldPath = segments.slice(1 + parsed.used).join("/");
6120
+ if (fieldPath.length === 0) return null;
6121
+ return {
6122
+ owner,
6123
+ scope: parsed.scope,
6124
+ fieldPath
6125
+ };
6126
+ }
6051
6127
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6052
6128
  var KeychainWriteRefusedError = class extends Error {
6053
6129
  fieldPath;
@@ -6058,7 +6134,7 @@ var KeychainWriteRefusedError = class extends Error {
6058
6134
  }
6059
6135
  };
6060
6136
  var KEEP = { kind: "keep" };
6061
- function isRecord$2(value) {
6137
+ function isRecord$1$1(value) {
6062
6138
  return typeof value === "object" && value !== null && !Array.isArray(value);
6063
6139
  }
6064
6140
  function defaultMintId() {
@@ -6071,7 +6147,7 @@ function collectSecretMarkerRefs(value, out = []) {
6071
6147
  return out;
6072
6148
  }
6073
6149
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6074
- else if (isRecord$2(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6150
+ else if (isRecord$1$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6075
6151
  return out;
6076
6152
  }
6077
6153
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6126,7 +6202,7 @@ function rowId(row, idKey) {
6126
6202
  return null;
6127
6203
  }
6128
6204
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6129
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$2) : [];
6205
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1$1) : [];
6130
6206
  if (!Array.isArray(incoming)) {
6131
6207
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6132
6208
  return {
@@ -6142,7 +6218,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6142
6218
  const kept = /* @__PURE__ */ new Set();
6143
6219
  const rows = [];
6144
6220
  for (const row of incoming) {
6145
- if (!isRecord$2(row)) {
6221
+ if (!isRecord$1$1(row)) {
6146
6222
  rows.push(row);
6147
6223
  continue;
6148
6224
  }
@@ -6167,7 +6243,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6167
6243
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6168
6244
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6169
6245
  case "object": {
6170
- if (!isRecord$2(incoming)) {
6246
+ if (!isRecord$1$1(incoming)) {
6171
6247
  if (incoming === void 0) return KEEP;
6172
6248
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6173
6249
  return {
@@ -6175,7 +6251,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6175
6251
  value: incoming
6176
6252
  };
6177
6253
  }
6178
- const storedObj = isRecord$2(stored) ? stored : {};
6254
+ const storedObj = isRecord$1$1(stored) ? stored : {};
6179
6255
  return {
6180
6256
  kind: "value",
6181
6257
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6234,12 +6310,19 @@ async function transformSecretWrite(input) {
6234
6310
  }
6235
6311
  };
6236
6312
  }
6313
+ /** Is `ref` one of `owner`'s refs? */
6314
+ function isSecretRefOwnedBy(ref, owner) {
6315
+ return parseSecretRef(ref)?.owner === owner;
6316
+ }
6237
6317
  /**
6238
6318
  * Replace every marker in `value` with its keychain value. Returns the SAME
6239
6319
  * reference when there is no marker (no allocation, no keychain call).
6240
6320
  */
6241
- async function resolveSecretMarkers(value, secrets) {
6242
- const refs = collectSecretMarkerRefs(value);
6321
+ async function resolveSecretMarkers(value, secrets, options = {}) {
6322
+ const keepMarker = options.unresolved === "keep-marker";
6323
+ const owner = options.ownedBy;
6324
+ const inScope = (ref) => owner === void 0 || isSecretRefOwnedBy(ref, owner);
6325
+ const refs = collectSecretMarkerRefs(value).filter(inScope);
6243
6326
  if (refs.length === 0) return {
6244
6327
  value,
6245
6328
  unresolved: []
@@ -6263,10 +6346,18 @@ async function resolveSecretMarkers(value, secrets) {
6263
6346
  }
6264
6347
  const substitute = (v) => {
6265
6348
  if (isSecretMarker(v)) {
6349
+ if (!inScope(v.$secret)) return {
6350
+ keep: true,
6351
+ value: v
6352
+ };
6266
6353
  const answer = answers[v.$secret];
6267
- return answer?.kind === "value" ? {
6354
+ if (answer?.kind === "value") return {
6268
6355
  keep: true,
6269
6356
  value: answer.value
6357
+ };
6358
+ return keepMarker ? {
6359
+ keep: true,
6360
+ value: v
6270
6361
  } : {
6271
6362
  keep: false,
6272
6363
  value: void 0
@@ -6283,7 +6374,7 @@ async function resolveSecretMarkers(value, secrets) {
6283
6374
  value: items
6284
6375
  };
6285
6376
  }
6286
- if (isRecord$2(v)) {
6377
+ if (isRecord$1$1(v)) {
6287
6378
  const out = {};
6288
6379
  for (const [k, child] of Object.entries(v)) {
6289
6380
  const s = substitute(child);
@@ -6304,14 +6395,152 @@ async function resolveSecretMarkers(value, secrets) {
6304
6395
  unresolved
6305
6396
  };
6306
6397
  }
6307
- function touchesTree(tree, patch) {
6308
- if (tree.size === 0) return false;
6309
- for (const key of Object.keys(patch)) {
6310
- const at = key.indexOf("@");
6311
- if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6398
+ /** An addon tried to replace a stored secret it could not read. Nothing was written. */
6399
+ var SecretOverwriteRefusedError = class extends Error {
6400
+ ref;
6401
+ reason;
6402
+ constructor(ref, reason) {
6403
+ 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.`);
6404
+ this.ref = ref;
6405
+ this.reason = reason;
6406
+ this.name = "SecretOverwriteRefusedError";
6407
+ }
6408
+ };
6409
+ function isRecord$3(value) {
6410
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6411
+ }
6412
+ function resolvedValue(pass, marker) {
6413
+ const answer = pass.answers[marker.$secret];
6414
+ return answer?.kind === "value" ? answer.value : null;
6415
+ }
6416
+ async function atMarker(pass, incoming, stored) {
6417
+ if (incoming === null) return stored;
6418
+ if (typeof incoming !== "string") return incoming;
6419
+ if (incoming === resolvedValue(pass, stored)) return stored;
6420
+ const intent = classifySecretWrite(incoming);
6421
+ if (intent.kind !== "set") return stored;
6422
+ const ref = stored.$secret;
6423
+ if (!isSecretRefOwnedBy(ref, pass.secrets.owner)) return incoming;
6424
+ const answer = pass.answers[ref];
6425
+ 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);
6426
+ try {
6427
+ await pass.secrets.put(ref, intent.value);
6428
+ } catch (err) {
6429
+ throw new KeychainWriteRefusedError(ref, err);
6430
+ }
6431
+ pass.changedRefs.push(ref);
6432
+ return stored;
6433
+ }
6434
+ function inArray(pass, incoming, stored) {
6435
+ return incoming.map((item, index) => {
6436
+ const twin = stored[index];
6437
+ if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6438
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
6439
+ if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6440
+ return item;
6441
+ });
6442
+ }
6443
+ function inArrayRow(pass, incoming, stored) {
6444
+ const out = { ...incoming };
6445
+ for (const [key, value] of Object.entries(incoming)) {
6446
+ const twin = stored[key];
6447
+ if (isSecretMarker(twin)) {
6448
+ if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6449
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
6450
+ else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6451
+ }
6452
+ return out;
6453
+ }
6454
+ async function walk(pass, incoming, stored) {
6455
+ if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6456
+ if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6457
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
6458
+ const out = { ...incoming };
6459
+ for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
6460
+ return out;
6461
+ }
6462
+ /** Restore markers a write-back carries as values. See the file doc. */
6463
+ async function restoreUnchangedSecrets(input) {
6464
+ const refs = [];
6465
+ for (const key of Object.keys(input.patch)) collectSecretMarkerRefs(input.stored[key], refs);
6466
+ const owned = refs.filter((ref) => isSecretRefOwnedBy(ref, input.secrets.owner));
6467
+ if (owned.length === 0) return {
6468
+ patch: input.patch,
6469
+ changedRefs: []
6470
+ };
6471
+ const pass = {
6472
+ secrets: input.secrets,
6473
+ answers: await input.secrets.resolve([...new Set(owned)]),
6474
+ operatorWrite: input.operatorWrite,
6475
+ changedRefs: []
6476
+ };
6477
+ const out = {};
6478
+ for (const [key, value] of Object.entries(input.patch)) out[key] = await walk(pass, value, input.stored[key]);
6479
+ return {
6480
+ patch: out,
6481
+ changedRefs: pass.changedRefs
6482
+ };
6483
+ }
6484
+ /** Structural equality over JSON-shaped values (key order does not matter). */
6485
+ function isJsonEqual(a, b) {
6486
+ if (Object.is(a, b)) return true;
6487
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6488
+ if (isRecord$3(a) && isRecord$3(b)) {
6489
+ const keys = Object.keys(a);
6490
+ if (keys.length !== Object.keys(b).length) return false;
6491
+ return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
6312
6492
  }
6313
6493
  return false;
6314
6494
  }
6495
+ /** The patch without the keys whose value already equals the stored one. */
6496
+ function dropUnchangedKeys(patch, stored) {
6497
+ const out = {};
6498
+ for (const [key, value] of Object.entries(patch)) {
6499
+ if (Object.prototype.hasOwnProperty.call(stored, key) && isJsonEqual(value, stored[key])) continue;
6500
+ out[key] = value;
6501
+ }
6502
+ return out;
6503
+ }
6504
+ /** The top-level keys of a blob that hold at least one of `owner`'s markers. */
6505
+ function markerKeysOf(blob, owner) {
6506
+ const keys = /* @__PURE__ */ new Set();
6507
+ for (const [key, value] of Object.entries(blob)) if (collectSecretMarkerRefs(value).some((ref) => isSecretRefOwnedBy(ref, owner))) keys.add(key);
6508
+ return keys;
6509
+ }
6510
+ function nodeFromStored(value, owner) {
6511
+ if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6512
+ if (!isRecord$3(value)) return null;
6513
+ const children = /* @__PURE__ */ new Map();
6514
+ for (const [key, child] of Object.entries(value)) {
6515
+ const node = nodeFromStored(child, owner);
6516
+ if (node !== null) children.set(key, node);
6517
+ }
6518
+ return children.size > 0 ? {
6519
+ kind: "object",
6520
+ children
6521
+ } : null;
6522
+ }
6523
+ /**
6524
+ * The declared secret tree, widened by every place the STORED blob holds a
6525
+ * marker under one of `keys` — so a marker the schema no longer declares (or
6526
+ * never declared: Wyze before b4906cec6) still gets the save path's
6527
+ * KEEP / SET / CLEAR semantics instead of being overwritten by whatever the
6528
+ * addon writes. Markers inside arrays are not added: a row has no id field to
6529
+ * match by unless the schema declares one. Only `owner`'s markers count: a
6530
+ * builtin that keeps another addon's marker (device-manager) never takes it
6531
+ * over.
6532
+ */
6533
+ function widenTreeWithStoredMarkers(declared, stored, keys, owner) {
6534
+ const added = /* @__PURE__ */ new Map();
6535
+ for (const key of keys) {
6536
+ const at = key.indexOf("@");
6537
+ const base = at > 0 ? key.slice(0, at) : key;
6538
+ if (declared.has(base) || added.has(base)) continue;
6539
+ const node = nodeFromStored(stored[key], owner);
6540
+ if (node !== null) added.set(base, node);
6541
+ }
6542
+ return added.size === 0 ? declared : new Map([...declared, ...added]);
6543
+ }
6315
6544
  /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6316
6545
  async function readStoredAddonBlob(raw) {
6317
6546
  const threeWay = raw.readAddonStoreResult;
@@ -6320,7 +6549,41 @@ async function readStoredAddonBlob(raw) {
6320
6549
  if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6321
6550
  return result.kind === "missing" ? {} : result.value;
6322
6551
  }
6323
- function createSecretAwareSettings(raw, opts) {
6552
+ function touchesTree(tree, patch) {
6553
+ if (tree.size === 0) return false;
6554
+ for (const key of Object.keys(patch)) {
6555
+ const at = key.indexOf("@");
6556
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6557
+ }
6558
+ return false;
6559
+ }
6560
+ /**
6561
+ * Which top-level keys of each store held markers when last seen. `undefined`
6562
+ * for a store not seen yet: its first write reads it, to be safe.
6563
+ */
6564
+ var MarkerKeyIndex = class {
6565
+ owner;
6566
+ byStore = /* @__PURE__ */ new Map();
6567
+ constructor(owner) {
6568
+ this.owner = owner;
6569
+ }
6570
+ seen(store, blob) {
6571
+ this.byStore.set(store, markerKeysOf(blob, this.owner));
6572
+ }
6573
+ wrote(store, patch) {
6574
+ const keys = this.byStore.get(store);
6575
+ if (keys === void 0) return;
6576
+ const now = markerKeysOf(patch, this.owner);
6577
+ for (const key of Object.keys(patch)) if (now.has(key)) keys.add(key);
6578
+ else keys.delete(key);
6579
+ }
6580
+ mayHoldMarkers(store, patch) {
6581
+ const keys = this.byStore.get(store);
6582
+ if (keys === void 0) return true;
6583
+ return Object.keys(patch).some((key) => keys.has(key));
6584
+ }
6585
+ };
6586
+ function createHandle(raw, opts) {
6324
6587
  const chains = /* @__PURE__ */ new Map();
6325
6588
  const serialize = (key, fn) => {
6326
6589
  const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
@@ -6331,46 +6594,130 @@ function createSecretAwareSettings(raw, opts) {
6331
6594
  });
6332
6595
  return next;
6333
6596
  };
6334
- const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6335
- if (!touchesTree(tree, patch)) return rawWrite(patch);
6336
- return serialize(chainKey, async () => {
6597
+ const index = new MarkerKeyIndex(opts.secrets.owner);
6598
+ const resolveRead = async (store, blob) => {
6599
+ index.seen(store, blob);
6600
+ const { value, unresolved } = await resolveSecretMarkers(blob, opts.secrets, {
6601
+ unresolved: "keep-marker",
6602
+ ownedBy: opts.secrets.owner
6603
+ });
6604
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6605
+ return value;
6606
+ };
6607
+ const write = async (store, declared, scope, patch, readStored, rawWrite) => {
6608
+ if (!touchesTree(declared, patch) && !index.mayHoldMarkers(store, patch)) {
6609
+ await rawWrite(patch);
6610
+ index.wrote(store, patch);
6611
+ return { changed: true };
6612
+ }
6613
+ return serialize(store, async () => {
6337
6614
  const stored = await readStored();
6615
+ index.seen(store, stored);
6616
+ const operatorWrite = opts.isOperatorWrite?.() === true;
6617
+ const restored = await restoreUnchangedSecrets({
6618
+ patch,
6619
+ stored,
6620
+ secrets: opts.secrets,
6621
+ operatorWrite
6622
+ });
6338
6623
  const result = await transformSecretWrite({
6339
- tree,
6624
+ tree: widenTreeWithStoredMarkers(declared, stored, Object.keys(restored.patch), opts.secrets.owner),
6340
6625
  secrets: opts.secrets,
6341
- patch,
6626
+ patch: restored.patch,
6342
6627
  stored,
6343
6628
  ...scope !== void 0 ? { scope } : {},
6344
- operatorWrite: opts.isOperatorWrite?.() === true
6629
+ operatorWrite
6345
6630
  });
6346
- if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6631
+ const effective = dropUnchangedKeys(result.patch, stored);
6632
+ const wroteBlob = Object.keys(effective).length > 0;
6633
+ if (wroteBlob) {
6634
+ await rawWrite(effective);
6635
+ index.wrote(store, effective);
6636
+ }
6347
6637
  const { orphaned } = await result.afterWrite();
6348
6638
  if (orphaned.length > 0) opts.onOrphaned(orphaned);
6639
+ return { changed: wroteBlob || restored.changedRefs.length > 0 };
6349
6640
  });
6350
6641
  };
6351
- const wrapped = {
6352
- writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6353
- writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6354
- kind: "device",
6355
- deviceId
6356
- }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6642
+ const writeAddon = (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p));
6643
+ const readAddonStoreResult = raw.readAddonStoreResult;
6644
+ const readAddonStoreKeyResult = raw.readAddonStoreKeyResult;
6645
+ const readDeviceStoreBatch = raw.readDeviceStoreBatch;
6646
+ const overrides = {
6647
+ readAddonStore: async () => resolveRead("addon", await raw.readAddonStore()),
6648
+ ...readAddonStoreResult !== void 0 ? { readAddonStoreResult: async () => {
6649
+ const result = await readAddonStoreResult.call(raw);
6650
+ return result.kind === "value" ? {
6651
+ kind: "value",
6652
+ value: await resolveRead("addon", result.value)
6653
+ } : result;
6654
+ } } : {},
6655
+ ...readAddonStoreKeyResult !== void 0 ? { readAddonStoreKeyResult: async (key) => {
6656
+ const result = await readAddonStoreKeyResult.call(raw, key);
6657
+ if (result.kind !== "present") return result;
6658
+ const { value, unresolved } = await resolveSecretMarkers({ [key]: result.value }, opts.secrets, {
6659
+ unresolved: "keep-marker",
6660
+ ownedBy: opts.secrets.owner
6661
+ });
6662
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6663
+ return {
6664
+ kind: "present",
6665
+ value: value[key]
6666
+ };
6667
+ } } : {},
6668
+ readDeviceStore: async (deviceId) => resolveRead(`device:${deviceId}`, await raw.readDeviceStore(deviceId)),
6669
+ ...readDeviceStoreBatch !== void 0 ? { readDeviceStoreBatch: async (deviceIds) => {
6670
+ const rows = await readDeviceStoreBatch.call(raw, deviceIds);
6671
+ const out = /* @__PURE__ */ new Map();
6672
+ for (const [deviceId, blob] of rows) out.set(deviceId, await resolveRead(`device:${deviceId}`, blob));
6673
+ return out;
6674
+ } } : {},
6675
+ writeAddonStore: async (patch) => {
6676
+ await writeAddon(patch);
6677
+ },
6678
+ writeDeviceStore: async (deviceId, patch) => {
6679
+ await write(`device:${deviceId}`, opts.deviceTree(), {
6680
+ kind: "device",
6681
+ deviceId
6682
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p));
6683
+ }
6684
+ };
6685
+ return {
6686
+ settings: new Proxy(raw, { get(target, prop, receiver) {
6687
+ if (typeof prop === "string" && Object.prototype.hasOwnProperty.call(overrides, prop)) return Reflect.get(overrides, prop);
6688
+ const value = Reflect.get(target, prop, receiver);
6689
+ return typeof value === "function" ? value.bind(target) : value;
6690
+ } }),
6691
+ raw: {
6692
+ readAddonStore: async () => {
6693
+ const blob = await raw.readAddonStore();
6694
+ index.seen("addon", blob);
6695
+ return blob;
6696
+ },
6697
+ readDeviceStore: async (deviceId) => {
6698
+ const blob = await raw.readDeviceStore(deviceId);
6699
+ index.seen(`device:${deviceId}`, blob);
6700
+ return blob;
6701
+ }
6702
+ },
6703
+ writeAddonStore: writeAddon
6357
6704
  };
6358
- return new Proxy(raw, { get(target, prop, receiver) {
6359
- if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6360
- if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6361
- const value = Reflect.get(target, prop, receiver);
6362
- return typeof value === "function" ? value.bind(target) : value;
6363
- } });
6364
6705
  }
6365
- /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6366
- function withSecretAwareSettings(context, opts) {
6706
+ /** The context the addon sees, plus the private raw view and write outcome. */
6707
+ function createSecretAwareContext(context, opts) {
6367
6708
  const raw = context.settings;
6368
- if (raw === void 0) return context;
6369
- const settings = createSecretAwareSettings(raw, opts);
6370
- return new Proxy(context, { get(target, prop, receiver) {
6371
- if (prop === "settings") return settings;
6372
- return Reflect.get(target, prop, receiver);
6373
- } });
6709
+ if (raw === void 0) return {
6710
+ context,
6711
+ handle: null
6712
+ };
6713
+ const handle = createHandle(raw, opts);
6714
+ return {
6715
+ context: new Proxy(context, { get(target, prop, receiver) {
6716
+ if (prop === "settings") return handle.settings;
6717
+ return Reflect.get(target, prop, receiver);
6718
+ } }),
6719
+ handle
6720
+ };
6374
6721
  }
6375
6722
  var LEAF = { kind: "leaf" };
6376
6723
  var DEFAULT_ITEM_ID_KEY = "id";
@@ -6545,6 +6892,14 @@ var BaseAddon = class {
6545
6892
  _secretChangeUnsub = null;
6546
6893
  /** >0 while an OPERATOR's settings write is being applied. */
6547
6894
  _operatorWriteDepth = 0;
6895
+ /**
6896
+ * The keychain-aware settings handle (D798). Its `raw` view is the ONLY way
6897
+ * to the marker-bearing blobs and stays private to this class: the form
6898
+ * hydrate and config resolution need markers, addon code never does.
6899
+ */
6900
+ _secretSettings = null;
6901
+ /** Refs an addon-facing read could not resolve — each is logged once per process. */
6902
+ _loggedUnresolvedReads = /* @__PURE__ */ new Set();
6548
6903
  constructor(defaults) {
6549
6904
  this.defaults = defaults;
6550
6905
  this._config = { ...defaults };
@@ -6581,13 +6936,21 @@ var BaseAddon = class {
6581
6936
  }
6582
6937
  async initialize(context) {
6583
6938
  const secrets = context.secrets;
6584
- this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6585
- secrets,
6586
- addonTree: () => this.addonSecretTree(),
6587
- deviceTree: () => this.deviceSecretTree(),
6588
- onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6589
- isOperatorWrite: () => this._operatorWriteDepth > 0
6590
- }) : context;
6939
+ if (secrets !== void 0) {
6940
+ const { context: wrapped, handle } = createSecretAwareContext(context, {
6941
+ secrets,
6942
+ addonTree: () => this.addonSecretTree(),
6943
+ deviceTree: () => this.deviceSecretTree(),
6944
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6945
+ isOperatorWrite: () => this._operatorWriteDepth > 0,
6946
+ onUnresolved: (unresolved) => this.logUnresolvedRead(unresolved)
6947
+ });
6948
+ this._ctx = wrapped;
6949
+ this._secretSettings = handle;
6950
+ } else {
6951
+ this._ctx = context;
6952
+ this._secretSettings = null;
6953
+ }
6591
6954
  await this.resolveConfig();
6592
6955
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6593
6956
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -6704,11 +7067,8 @@ var BaseAddon = class {
6704
7067
  async getGlobalSettings(overlay, cap, nodeId) {
6705
7068
  const schema = this.globalSettingsSchema(cap);
6706
7069
  if (!schema) return { sections: [] };
6707
- const projected = await this.resolveGlobalStore(nodeId, cap);
6708
- return hydrateSchema(schema, overlay ? {
6709
- ...projected,
6710
- ...overlay
6711
- } : projected, { inlineSecretsAsViews: true });
7070
+ const projected = await this.readRawProjectedStore(nodeId, cap);
7071
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
6712
7072
  }
6713
7073
  /**
6714
7074
  * The integration-level view of this addon's settings: exactly the sections
@@ -6753,7 +7113,7 @@ var BaseAddon = class {
6753
7113
  });
6754
7114
  }
6755
7115
  if (sections.length === 0) return null;
6756
- const projected = await this.resolveGlobalStore(nodeId);
7116
+ const projected = await this.readRawProjectedStore(nodeId);
6757
7117
  return hydrateSchema({
6758
7118
  ...schema,
6759
7119
  sections
@@ -6770,12 +7130,50 @@ var BaseAddon = class {
6770
7130
  * the store for custom option logic (option narrowing, value snapping) to
6771
7131
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
6772
7132
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
7133
+ *
7134
+ * Keychain values come back RESOLVED (D798): a secret reads as its value,
7135
+ * never as a `{ $secret }` marker. One the keychain cannot serve right now
7136
+ * stays a marker — "stored, unavailable" (`isSecretMarker()` is true, and it
7137
+ * is listed in {@link unresolvedSecrets}) — never `''` and never absent, so
7138
+ * it cannot be mistaken for "nothing stored, mint a new one". Writing the
7139
+ * resolved blob back is a no-op for every unchanged secret.
6773
7140
  */
6774
7141
  async resolveGlobalStore(nodeId, cap) {
6775
7142
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
7143
+ return this.projectForNode(raw, nodeId, cap);
7144
+ }
7145
+ projectForNode(store, nodeId, cap) {
6776
7146
  const keys = this.perNodeKeys(cap);
6777
7147
  const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6778
- return keys.size > 0 ? projectStore(raw, keys, node) : raw;
7148
+ return keys.size > 0 ? projectStore(store, keys, node) : store;
7149
+ }
7150
+ /** The PROJECTED store with its markers — the form hydrate only (D798). */
7151
+ async readRawProjectedStore(nodeId, cap) {
7152
+ const raw = await this.rawSettings()?.readAddonStore() ?? {};
7153
+ return this.projectForNode(raw, nodeId, cap);
7154
+ }
7155
+ /**
7156
+ * `{ ...stored, ...overlay }`, except that an overlay member equal to the
7157
+ * RESOLVED stored one keeps the stored (marker-bearing) member — so a form
7158
+ * hydrated from a resolved overlay still shows a secret as "set", never as
7159
+ * its value.
7160
+ */
7161
+ async overlayKeepingMarkers(stored, overlay) {
7162
+ const secrets = this._ctx?.secrets;
7163
+ const merged = {
7164
+ ...stored,
7165
+ ...overlay
7166
+ };
7167
+ if (secrets === void 0 || collectSecretMarkerRefs(stored).length === 0) return merged;
7168
+ const { value: resolved } = await resolveSecretMarkers(stored, secrets, {
7169
+ unresolved: "keep-marker",
7170
+ ownedBy: secrets.owner
7171
+ });
7172
+ for (const key of Object.keys(overlay)) {
7173
+ if (collectSecretMarkerRefs(stored[key]).length === 0) continue;
7174
+ if (isJsonEqual(overlay[key], resolved[key])) merged[key] = stored[key];
7175
+ }
7176
+ return merged;
6779
7177
  }
6780
7178
  /**
6781
7179
  * Whether ONE global key of this addon's store was written, read three-way
@@ -6840,8 +7238,12 @@ var BaseAddon = class {
6840
7238
  async clearSecrets(keys, nodeId) {
6841
7239
  const tree = this.addonSecretTree();
6842
7240
  const keychain = this._ctx?.secrets !== void 0;
7241
+ const stored = keychain ? await this.readAddonStoreWithRetry() : {};
6843
7242
  const patch = {};
6844
- for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
7243
+ for (const key of keys) {
7244
+ const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
7245
+ patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
7246
+ }
6845
7247
  await this.applyGlobalPatch(patch, nodeId);
6846
7248
  }
6847
7249
  async applyGlobalPatch(barePatch, nodeId) {
@@ -6849,7 +7251,11 @@ var BaseAddon = class {
6849
7251
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6850
7252
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6851
7253
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6852
- await this._ctx?.settings?.writeAddonStore(scoped);
7254
+ const handle = this._secretSettings;
7255
+ if (handle !== null) {
7256
+ const { changed } = await handle.writeAddonStore(scoped);
7257
+ if (!changed) return;
7258
+ } else await this._ctx?.settings?.writeAddonStore(scoped);
6853
7259
  if (target !== localNode) return;
6854
7260
  await this.resolveConfig();
6855
7261
  await this.onConfigChanged();
@@ -6902,7 +7308,7 @@ var BaseAddon = class {
6902
7308
  async getDeviceSettings(deviceId) {
6903
7309
  const schema = this.deviceSettingsSchema();
6904
7310
  if (!schema) return { sections: [] };
6905
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7311
+ return hydrateSchema(schema, await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6906
7312
  }
6907
7313
  async updateDeviceSettings(deviceId, patch) {
6908
7314
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -7074,7 +7480,7 @@ var BaseAddon = class {
7074
7480
  key,
7075
7481
  schema,
7076
7482
  fallback,
7077
- read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
7483
+ read: async () => this.resolveStoredSecrets(await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, false),
7078
7484
  write: async (patch) => {
7079
7485
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
7080
7486
  },
@@ -7136,6 +7542,23 @@ var BaseAddon = class {
7136
7542
  }
7137
7543
  return value;
7138
7544
  }
7545
+ /**
7546
+ * The marker-bearing settings reads (D798) — private on purpose. Without a
7547
+ * keychain the context's own view is already raw.
7548
+ */
7549
+ rawSettings() {
7550
+ return this._secretSettings?.raw ?? this._ctx?.settings;
7551
+ }
7552
+ /** An addon-facing read met markers it could not resolve: say so once per ref. */
7553
+ logUnresolvedRead(unresolved) {
7554
+ const fresh = unresolved.filter((u) => !this._loggedUnresolvedReads.has(u.ref));
7555
+ if (fresh.length === 0) return;
7556
+ for (const u of fresh) this._loggedUnresolvedReads.add(u.ref);
7557
+ 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) => ({
7558
+ ref: u.ref,
7559
+ reason: u.reason
7560
+ })) } });
7561
+ }
7139
7562
  /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7140
7563
  scheduleSecretReresolve(delayMs) {
7141
7564
  const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
@@ -7162,7 +7585,7 @@ var BaseAddon = class {
7162
7585
  * `{}` (defaults) — the addon's first successful patch will rehydrate.
7163
7586
  */
7164
7587
  async readAddonStoreWithRetry() {
7165
- const settings = this._ctx?.settings;
7588
+ const settings = this.rawSettings();
7166
7589
  if (!settings) return {};
7167
7590
  const delaysMs = [
7168
7591
  150,
@@ -9465,6 +9888,278 @@ var CameraSwitchGroupSchema = object({
9465
9888
  fetchedAt: number()
9466
9889
  });
9467
9890
  /**
9891
+ * The trainer contract — what the hub hands the cloud trainer and what it
9892
+ * gets back (cloud training, D805+).
9893
+ *
9894
+ * The trainer (`hf/camstack-trainer`, published as the Hugging Face repo
9895
+ * `camstack/camstack-trainer`) is a separate AGPL program the hub never
9896
+ * imports: `job.json` goes in, files come out, and progress is `CAMSTACK_EVENT`
9897
+ * lines on stdout. These schemas are the hub's half of that boundary; the
9898
+ * trainer's pydantic models (and the JSON Schemas generated from them under
9899
+ * `hf/camstack-trainer/schemas/`) are the other half. A change here is a
9900
+ * change there, in the same piece of work.
9901
+ *
9902
+ * No `.default()` anywhere: defaults do not run on the addon cap path, so the
9903
+ * orchestrator fills every field of a job spec explicitly.
9904
+ */
9905
+ var TRAINING_JOB_SCHEMA = "camstack.training/v1";
9906
+ var TRAINING_RESULT_SCHEMA = "camstack.training-result/v1";
9907
+ /** What the trainer can export. Edge TPU is a later, separate image. */
9908
+ var TrainingExportSchema = _enum([
9909
+ "onnx",
9910
+ "openvino-fp16",
9911
+ "openvino-int8",
9912
+ "coreml-fp16"
9913
+ ]);
9914
+ var FloorsSchema = record(string$2(), number().min(0).max(1));
9915
+ object({
9916
+ schema: literal(TRAINING_JOB_SCHEMA),
9917
+ jobKey: string$2().uuid(),
9918
+ target: object({
9919
+ kind: literal("detector"),
9920
+ step: literal("object-detection")
9921
+ }),
9922
+ base: object({
9923
+ modelId: string$2().min(1),
9924
+ /** Ultralytics weights id, e.g. `yolov9m.pt`. */
9925
+ weights: string$2().min(1),
9926
+ imgsz: number().int().positive()
9927
+ }),
9928
+ baseline: object({
9929
+ modelId: string$2().min(1),
9930
+ /** The baseline ONNX the holdout comparison runs; public mirror URL. */
9931
+ onnxUrl: string$2().url(),
9932
+ imgsz: number().int().positive(),
9933
+ floors: FloorsSchema
9934
+ }),
9935
+ dataset: object({
9936
+ versionId: string$2().min(1),
9937
+ annotationHash: string$2(),
9938
+ /** sha256 of the uploaded archive; the trainer refuses a mismatch (exit 65). */
9939
+ sha256: string$2().regex(/^[0-9a-f]{64}$/)
9940
+ }),
9941
+ split: object({
9942
+ holdoutCameras: array(number().int()),
9943
+ /** When no camera is held out: the last N days of every camera. */
9944
+ holdoutLastDays: number().int().nonnegative(),
9945
+ valFraction: number().min(0).max(.5),
9946
+ seed: number().int()
9947
+ }),
9948
+ hyper: object({
9949
+ epochs: number().int().positive(),
9950
+ batch: number().int().positive(),
9951
+ lr0: number().positive(),
9952
+ /** Layers frozen from the start of the backbone; 0 = none. */
9953
+ freeze: number().int().nonnegative(),
9954
+ patience: number().int().nonnegative(),
9955
+ seed: number().int()
9956
+ }),
9957
+ replay: object({
9958
+ source: literal("coco2017"),
9959
+ count: number().int().nonnegative()
9960
+ }),
9961
+ exports: array(TrainingExportSchema).min(1),
9962
+ calibration: object({ maxFrames: number().int().positive() }),
9963
+ floors: object({
9964
+ minSupport: number().int().positive(),
9965
+ clamp: number().min(0).max(1)
9966
+ }),
9967
+ int8Gate: object({ maxMap50Drop: number().min(0).max(1) }),
9968
+ catalog: object({
9969
+ id: string$2().regex(/^[a-z0-9][a-z0-9-]{2,80}$/),
9970
+ name: string$2().min(1).max(160)
9971
+ })
9972
+ });
9973
+ /** One regular file of the bundle. An mlpackage contributes one row per member. */
9974
+ var TrainingResultFileSchema = object({
9975
+ path: string$2().min(1),
9976
+ bytes: number().int().nonnegative(),
9977
+ sha256: string$2().regex(/^[0-9a-f]{64}$/),
9978
+ format: _enum([
9979
+ "onnx",
9980
+ "openvino",
9981
+ "coreml",
9982
+ "pt"
9983
+ ]),
9984
+ variant: _enum(["base", "int8"])
9985
+ });
9986
+ var DraftFormatSchema = object({
9987
+ /** RELATIVE path inside the bundle; the hub rewrites it to `camstack-local://`. */
9988
+ url: string$2().min(1),
9989
+ sizeMB: number().nonnegative(),
9990
+ isDirectory: boolean().optional(),
9991
+ files: array(string$2()).optional(),
9992
+ runtimes: array(literal("python")).optional(),
9993
+ revision: string$2().min(1)
9994
+ });
9995
+ /** The trainer's half of a catalog entry; the hub completes it (labels, licence, group). */
9996
+ var TrainingCatalogDraftSchema = object({
9997
+ id: string$2().min(1),
9998
+ name: string$2().min(1),
9999
+ description: string$2(),
10000
+ labels: array(unknown()),
10001
+ inputSize: object({
10002
+ width: number().int().positive(),
10003
+ height: number().int().positive()
10004
+ }),
10005
+ preprocessMode: literal("letterbox"),
10006
+ defaultClassFloors: FloorsSchema,
10007
+ formats: object({
10008
+ onnx: DraftFormatSchema.optional(),
10009
+ openvino: DraftFormatSchema.optional(),
10010
+ coreml: DraftFormatSchema.optional()
10011
+ })
10012
+ });
10013
+ /** One class of one model's holdout report (the eval harness's summary). */
10014
+ var TrainingEvalClassSchema = object({
10015
+ positives: number().int(),
10016
+ floor: number().nullable(),
10017
+ tp: number().int(),
10018
+ fp: number().int(),
10019
+ fn: number().int(),
10020
+ precision: number().nullable(),
10021
+ recall: number().nullable(),
10022
+ ap50: number().nullable(),
10023
+ recallByCamera: record(string$2(), number().nullable()).optional(),
10024
+ recallByLight: record(string$2(), number().nullable()).optional(),
10025
+ fpByCamera: record(string$2(), number()).optional(),
10026
+ smallFound: number().int().optional(),
10027
+ smallTotal: number().int().optional()
10028
+ }).passthrough();
10029
+ var TrainingEvalReportSchema = object({
10030
+ frames: number().int(),
10031
+ classes: record(string$2(), TrainingEvalClassSchema)
10032
+ }).passthrough();
10033
+ /**
10034
+ * A succeeded result carries every block; a failed one carries the error and
10035
+ * whatever was known by then — the other blocks are ABSENT, not null. The
10036
+ * orchestrator checks the blocks it needs before it trusts a success.
10037
+ */
10038
+ var TrainingResultSchema = object({
10039
+ schema: literal(TRAINING_RESULT_SCHEMA),
10040
+ jobKey: string$2(),
10041
+ status: _enum(["succeeded", "failed"]),
10042
+ error: object({
10043
+ stage: string$2(),
10044
+ code: string$2(),
10045
+ message: string$2()
10046
+ }).nullable(),
10047
+ trainer: object({
10048
+ version: string$2(),
10049
+ revision: string$2()
10050
+ }),
10051
+ toolchain: record(string$2(), string$2().nullable()),
10052
+ dataset: object({
10053
+ versionId: string$2(),
10054
+ annotationHash: string$2(),
10055
+ sha256: string$2(),
10056
+ frames: object({
10057
+ train: number().int(),
10058
+ val: number().int(),
10059
+ holdout: number().int()
10060
+ }),
10061
+ holdoutCameras: array(number().int()),
10062
+ replayImages: number().int()
10063
+ }).optional(),
10064
+ training: object({
10065
+ epochsRun: number().int(),
10066
+ bestEpoch: number().int(),
10067
+ bestMap50: number(),
10068
+ bestMap50_95: number(),
10069
+ seconds: number()
10070
+ }).optional(),
10071
+ evaluation: object({
10072
+ holdoutFrames: number().int(),
10073
+ baseline: TrainingEvalReportSchema.nullable(),
10074
+ candidate: TrainingEvalReportSchema.nullable(),
10075
+ candidateInt8: TrainingEvalReportSchema.nullable(),
10076
+ recallDeltaByCamera: record(string$2(), record(string$2(), number())).nullable(),
10077
+ map50: record(string$2(), number().nullable())
10078
+ }).optional(),
10079
+ floors: object({
10080
+ baseline: FloorsSchema,
10081
+ candidate: FloorsSchema,
10082
+ candidateInt8: FloorsSchema.nullable(),
10083
+ notes: array(string$2())
10084
+ }).optional(),
10085
+ int8: object({
10086
+ kept: boolean(),
10087
+ map50Fp16: number().nullable(),
10088
+ map50Int8: number().nullable(),
10089
+ reason: string$2().nullable()
10090
+ }).optional(),
10091
+ exportsDropped: array(object({
10092
+ export: string$2(),
10093
+ reason: string$2()
10094
+ })).optional(),
10095
+ files: array(TrainingResultFileSchema).optional(),
10096
+ bundle: object({
10097
+ path: literal("bundle.tar"),
10098
+ bytes: number().int().nonnegative(),
10099
+ sha256: string$2().regex(/^[0-9a-f]{64}$/)
10100
+ }).nullable().optional(),
10101
+ catalogDraft: object({
10102
+ base: TrainingCatalogDraftSchema,
10103
+ int8: TrainingCatalogDraftSchema.nullable()
10104
+ }).nullable().optional(),
10105
+ licence: string$2()
10106
+ });
10107
+ var TrainingStageSchema = _enum([
10108
+ "prepare",
10109
+ "replay",
10110
+ "train",
10111
+ "eval",
10112
+ "export",
10113
+ "package"
10114
+ ]);
10115
+ var EventBase = {
10116
+ v: literal(1),
10117
+ ts: number()
10118
+ };
10119
+ discriminatedUnion("type", [
10120
+ object({
10121
+ ...EventBase,
10122
+ type: literal("stage"),
10123
+ stage: TrainingStageSchema
10124
+ }),
10125
+ object({
10126
+ ...EventBase,
10127
+ type: literal("epoch"),
10128
+ epoch: number().int(),
10129
+ epochs: number().int(),
10130
+ boxLoss: number().nullable().optional(),
10131
+ map50: number().nullable().optional(),
10132
+ map50_95: number().nullable().optional(),
10133
+ etaSec: number().nullable().optional()
10134
+ }),
10135
+ object({
10136
+ ...EventBase,
10137
+ type: literal("metric"),
10138
+ name: string$2(),
10139
+ value: number()
10140
+ }),
10141
+ object({
10142
+ ...EventBase,
10143
+ type: literal("artifact"),
10144
+ path: string$2(),
10145
+ bytes: number(),
10146
+ sha256: string$2()
10147
+ }),
10148
+ object({
10149
+ ...EventBase,
10150
+ type: literal("done"),
10151
+ status: _enum(["succeeded", "failed"]),
10152
+ resultSha256: string$2().nullable().optional()
10153
+ }),
10154
+ object({
10155
+ ...EventBase,
10156
+ type: literal("error"),
10157
+ stage: string$2(),
10158
+ code: string$2(),
10159
+ message: string$2()
10160
+ })
10161
+ ]);
10162
+ /**
9468
10163
  * What the gate decided about a birth, from the CALLER's point of view.
9469
10164
  *
9470
10165
  * Deliberately not `ConfirmationVerdict`: `undecided` is not a birth decision
@@ -11792,7 +12487,9 @@ var AddonHttpRouteSchema = object({
11792
12487
  "authenticated",
11793
12488
  "admin"
11794
12489
  ]).optional(),
11795
- description: string$2().optional()
12490
+ description: string$2().optional(),
12491
+ /** The hub limits this route per client address before the handler runs. */
12492
+ rateLimit: _enum(["auth"]).optional()
11796
12493
  });
11797
12494
  /**
11798
12495
  * Cross-process route invocation envelope. The hub captures the
@@ -12497,6 +13194,37 @@ var BackupDestinationInfoSchema = object({
12497
13194
  lastError: string$2().optional()
12498
13195
  });
12499
13196
  /**
13197
+ * How an archive is encrypted (operator decision 2026-10-09): to a backup
13198
+ * PUBLIC key the hub holds, so only the operator's secret key opens it.
13199
+ * Absent on a plain `.tar.gz` — every archive made before encryption, or
13200
+ * with it off — which restores without a key.
13201
+ */
13202
+ var BackupArchiveEncryptionSchema = object({
13203
+ /** `x25519-hkdf-aes256gcm-stream-v1`. */
13204
+ scheme: string$2(),
13205
+ /** 16 hex — the backup key whose secret restores this archive. */
13206
+ keyId: string$2()
13207
+ });
13208
+ /**
13209
+ * The backup encryption setting. The hub keeps PUBLIC keys only: the active
13210
+ * one new archives are encrypted to, and the retired ones older archives
13211
+ * still need. The secret key is shown once, at `setupEncryption`.
13212
+ */
13213
+ var BackupEncryptionStatusSchema = object({
13214
+ enabled: boolean(),
13215
+ active: object({
13216
+ keyId: string$2(),
13217
+ publicKey: string$2(),
13218
+ createdAt: number()
13219
+ }).nullable(),
13220
+ /** Every key ever set up, newest first. */
13221
+ keys: array(object({
13222
+ keyId: string$2(),
13223
+ createdAt: number(),
13224
+ retiredAt: number().nullable()
13225
+ })).readonly()
13226
+ });
13227
+ /**
12500
13228
  * Per-archive entry returned by `backup.listArchives({ destinationId })`.
12501
13229
  * Same shape the destination drill-in renders. Sourced from the per-
12502
13230
  * location `manifests.json` (no per-archive tarball read required).
@@ -12508,7 +13236,9 @@ var BackupArchiveEntrySchema = object({
12508
13236
  sizeBytes: number(),
12509
13237
  label: string$2().optional(),
12510
13238
  /** Top-level locations included in the archive (db, addons, tls, …). */
12511
- locations: array(string$2()).readonly()
13239
+ locations: array(string$2()).readonly(),
13240
+ /** Present when the archive is encrypted; restore then needs that key. */
13241
+ encryption: BackupArchiveEncryptionSchema.optional()
12512
13242
  });
12513
13243
  var BackupEntrySchema = object({
12514
13244
  id: string$2(),
@@ -12517,7 +13247,8 @@ var BackupEntrySchema = object({
12517
13247
  label: string$2().optional(),
12518
13248
  createdAt: number(),
12519
13249
  sizeBytes: number(),
12520
- locations: array(string$2()).optional()
13250
+ locations: array(string$2()).optional(),
13251
+ encryption: BackupArchiveEncryptionSchema.optional()
12521
13252
  });
12522
13253
  var ArchiveEntrySchema = object({
12523
13254
  path: string$2(),
@@ -12706,10 +13437,40 @@ method(_void(), array(BackupDestinationInfoSchema).readonly(), { auth: "admin" }
12706
13437
  * this list and skips entries whose path doesn't start with
12707
13438
  * any of them.
12708
13439
  */
12709
- locations: array(string$2()).optional()
13440
+ locations: array(string$2()).optional(),
13441
+ /**
13442
+ * The backup SECRET key, for an encrypted archive (ignored for a plain
13443
+ * one). The archive is decrypted into the hub's private staging
13444
+ * before the restart; the key is not stored. A wrong or missing key
13445
+ * is refused before the archive is downloaded.
13446
+ */
13447
+ backupSecretKey: string$2().optional()
12710
13448
  }), _void(), {
12711
13449
  kind: "mutation",
12712
13450
  auth: "admin"
13451
+ }), method(_void(), BackupEncryptionStatusSchema, { auth: "admin" }), method(object({}), object({
13452
+ keyId: string$2(),
13453
+ secretKey: string$2(),
13454
+ publicKey: string$2(),
13455
+ createdAt: number(),
13456
+ replacedKeyId: string$2().nullable()
13457
+ }), {
13458
+ kind: "mutation",
13459
+ auth: "admin"
13460
+ }), method(object({}), object({ disabledKeyId: string$2().nullable() }), {
13461
+ kind: "mutation",
13462
+ auth: "admin"
13463
+ }), method(object({ backupSecretKey: string$2() }), object({
13464
+ valid: boolean(),
13465
+ keyId: string$2().nullable(),
13466
+ /** The hub knows this key (active or retired). */
13467
+ known: boolean(),
13468
+ /** It is the key new archives are encrypted to. */
13469
+ active: boolean(),
13470
+ error: string$2().optional()
13471
+ }), {
13472
+ kind: "mutation",
13473
+ auth: "admin"
12713
13474
  }), method(object({
12714
13475
  destinationId: string$2(),
12715
13476
  backupId: string$2()
@@ -14484,7 +15245,60 @@ var CustomModelDescriptorSchema = object({
14484
15245
  stepId: string$2(),
14485
15246
  entry: ModelCatalogEntrySchema
14486
15247
  });
14487
- method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" });
15248
+ /** One regular file of an imported bundle, as the producer measured it. */
15249
+ var ModelBundleFileSchema = object({
15250
+ /** Relative path inside the bundle tar; an mlpackage member is `<x>.mlpackage/<member>`. */
15251
+ path: string$2().min(1),
15252
+ bytes: number().int().nonnegative(),
15253
+ sha256: string$2().regex(/^[0-9a-f]{64}$/)
15254
+ });
15255
+ var ImportModelBundleInputSchema = object({
15256
+ /** The registry provider that keeps the model (Model Studio). */
15257
+ addonId: string$2(),
15258
+ stepId: string$2().min(1),
15259
+ /**
15260
+ * The catalog rows to register, complete, every format URL already
15261
+ * `camstack-local://<modelId>/<file>` naming a file of the bundle. One
15262
+ * bundle may carry several rows (a base and its INT8 variant).
15263
+ */
15264
+ entries: array(ModelCatalogEntrySchema).min(1).max(4),
15265
+ /** The bundle tar, offered by the producer over `ctx.peerBytes` (same host). */
15266
+ bundle: object({
15267
+ ticket: PeerBytesTicketSchema,
15268
+ bytes: number().int().positive(),
15269
+ sha256: string$2().regex(/^[0-9a-f]{64}$/)
15270
+ }),
15271
+ /** Every file the tar must hold; anything missing, extra or different is refused. */
15272
+ files: array(ModelBundleFileSchema).min(1).max(64),
15273
+ /** Convert missing engine formats and push the model to every agent afterwards. */
15274
+ distribute: boolean()
15275
+ });
15276
+ var ImportModelBundleResultSchema = discriminatedUnion("kind", [object({
15277
+ kind: literal("imported"),
15278
+ modelIds: array(string$2()).readonly(),
15279
+ distributed: array(object({
15280
+ modelId: string$2(),
15281
+ nodeId: string$2(),
15282
+ format: _enum(MODEL_FORMATS),
15283
+ ok: boolean(),
15284
+ error: string$2().optional()
15285
+ })).readonly()
15286
+ }), object({
15287
+ kind: literal("refused"),
15288
+ reason: _enum([
15289
+ "transfer-failed",
15290
+ "checksum-mismatch",
15291
+ "bundle-mismatch",
15292
+ "invalid-entry",
15293
+ "id-taken"
15294
+ ]),
15295
+ detail: string$2()
15296
+ })]);
15297
+ method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }), method(ImportModelBundleInputSchema, ImportModelBundleResultSchema, {
15298
+ kind: "mutation",
15299
+ auth: "admin",
15300
+ timeoutMs: 30 * 6e4
15301
+ });
14488
15302
  /**
14489
15303
  * Query filter for settings-store collections.
14490
15304
  */
@@ -14963,6 +15777,35 @@ var KeychainKeySourceSchema = object({
14963
15777
  */
14964
15778
  sharesBackupWithDatabase: boolean()
14965
15779
  });
15780
+ /**
15781
+ * One keychain reset, as the Secrets page reports it until the operator
15782
+ * acknowledges it. Never a value: refs, counts and table names only.
15783
+ */
15784
+ var KeychainResetRecordSchema = object({
15785
+ id: string$2(),
15786
+ at: number(),
15787
+ /** `user:<id>` or {@link KEYCHAIN_RESET_TRIGGER_ACTOR}. */
15788
+ actor: string$2(),
15789
+ /** Why the keychain was locked when it was reset; `null` when it was not locked. */
15790
+ lockedReason: string$2().nullable(),
15791
+ /** Values moved into the archive table (ciphertext under the lost key). */
15792
+ archived: number().int(),
15793
+ /** `keychain:secrets-orphaned-<ts>`, or `null` when nothing was stored. */
15794
+ archivedCollection: string$2().nullable(),
15795
+ /**
15796
+ * `keychain:keys-orphaned-<ts>`: the wrapped data keys of the archive, kept
15797
+ * so the archive can still be opened if the lost master key turns up.
15798
+ */
15799
+ archivedKeysCollection: string$2().nullable(),
15800
+ /**
15801
+ * `system-settings` keys whose marker the reset cleared — the cluster
15802
+ * secret's: a marker left pointing at an archived value would refuse every
15803
+ * agent forever (D797).
15804
+ */
15805
+ clearedSettingsKeys: array(string$2()).readonly(),
15806
+ /** When an operator dismissed the notice on the Secrets page; `null` until then. */
15807
+ acknowledgedAt: number().nullable()
15808
+ });
14966
15809
  var KeychainStatusSchema = object({
14967
15810
  keychain: KeychainStateSchema,
14968
15811
  /** The source of the master key in use; `null` while locked. */
@@ -14980,7 +15823,9 @@ var KeychainStatusSchema = object({
14980
15823
  /** Wrapped copies of the data key under a previous master key, kept until purged. */
14981
15824
  retiredWraps: number().int(),
14982
15825
  recoveryKeyDownloadedAt: number().nullable(),
14983
- secretCount: number().int()
15826
+ secretCount: number().int(),
15827
+ /** The most recent reset, acknowledged or not; `null` when the keychain was never reset. */
15828
+ lastReset: KeychainResetRecordSchema.nullable()
14984
15829
  });
14985
15830
  /**
14986
15831
  * Whether a stored value is still pointed at by its owner's settings.
@@ -15002,17 +15847,26 @@ var KeychainAuditActionSchema = _enum([
15002
15847
  "download-recovery-key",
15003
15848
  "delete-orphans",
15004
15849
  "reset",
15850
+ "acknowledge-reset",
15005
15851
  "initialize"
15006
15852
  ]);
15007
15853
  var KeychainAuditEntrySchema = object({
15008
15854
  id: string$2(),
15009
15855
  at: number(),
15010
15856
  action: KeychainAuditActionSchema,
15011
- /** `addon:<id>` | `user:<id>` | `system`. */
15857
+ /** `addon:<id>` | `user:<id>` | `system` | `trigger-file`. */
15012
15858
  actor: string$2(),
15013
15859
  ref: string$2().nullable(),
15014
15860
  detail: string$2().nullable()
15015
15861
  });
15862
+ var KEYCHAIN_RESET_CONFIRMATION = "RESET KEYCHAIN";
15863
+ /**
15864
+ * Secrets the HUB itself holds (owner `system`) that no settings form shows:
15865
+ * `jwt-signing-key` — the session signing key (D797). It is always "in use",
15866
+ * never an orphan; it is generated on a fresh hub and replaced only through
15867
+ * {@link keychainAdminCapability.methods.setSystemSecret}.
15868
+ */
15869
+ var SystemHeldSecretNameSchema = _enum(["jwt-signing-key"]);
15016
15870
  method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}), array(KeychainAdminSecretSchema).readonly(), { auth: "admin" }), method(object({ limit: number().int().min(1).max(500).optional() }), array(KeychainAuditEntrySchema).readonly(), { auth: "admin" }), method(object({ ref: string$2().min(1) }), object({
15017
15871
  value: string$2(),
15018
15872
  version: number().int()
@@ -15020,6 +15874,16 @@ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}),
15020
15874
  kind: "mutation",
15021
15875
  auth: "admin",
15022
15876
  caller: "required"
15877
+ }), method(object({
15878
+ name: SystemHeldSecretNameSchema,
15879
+ value: string$2().min(16)
15880
+ }), object({
15881
+ ref: string$2(),
15882
+ version: number().int()
15883
+ }), {
15884
+ kind: "mutation",
15885
+ auth: "admin",
15886
+ caller: "required"
15023
15887
  }), method(object({ refs: array(string$2().min(1)).max(1e3) }), object({
15024
15888
  deleted: array(string$2()).readonly(),
15025
15889
  kept: array(object({
@@ -15049,13 +15913,20 @@ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}),
15049
15913
  kind: "mutation",
15050
15914
  auth: "admin",
15051
15915
  caller: "required"
15052
- }), method(object({ confirm: literal("RESET KEYCHAIN") }), object({
15916
+ }), method(object({ confirm: literal(KEYCHAIN_RESET_CONFIRMATION) }), object({
15053
15917
  archivedCollection: string$2().nullable(),
15054
15918
  archived: number().int()
15055
15919
  }), {
15056
15920
  kind: "mutation",
15057
15921
  auth: "admin",
15058
15922
  caller: "required"
15923
+ }), method(object({}), object({
15924
+ reset: KeychainResetRecordSchema.nullable(),
15925
+ pendingReentry: array(KeychainSecretMetaSchema).readonly()
15926
+ }), { auth: "admin" }), method(object({}), object({ acknowledged: boolean() }), {
15927
+ kind: "mutation",
15928
+ auth: "admin",
15929
+ caller: "required"
15059
15930
  });
15060
15931
  method(_void(), object({
15061
15932
  id: string$2(),
@@ -17906,7 +18777,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
17906
18777
  * `login-method` — collection cap through which auth addons contribute
17907
18778
  * their pre-auth login surfaces to the login page. This is the SINGLE,
17908
18779
  * generic mechanism that supersedes the dead `auth.listProviders` reader:
17909
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
18780
+ * every auth addon (OIDC, WebAuthn/passkey) registers a
17910
18781
  * `login-method` provider and the PUBLIC `auth.listLoginMethods`
17911
18782
  * procedure aggregates them for the unauthenticated login page.
17912
18783
  *
@@ -17914,8 +18785,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
17914
18785
  *
17915
18786
  * - `redirect` — a declarative button. The login page renders a generic
17916
18787
  * button that navigates to `startUrl` (an addon-owned HTTP route).
17917
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
17918
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
18788
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) with ZERO shell-side JS. A future SSO addon plugs in the same way — the
17919
18789
  * login page needs NO change.
17920
18790
  *
17921
18791
  * - `widget` — a Module-Federation widget the login page mounts (via
@@ -17934,8 +18804,8 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
17934
18804
  * decision.
17935
18805
  *
17936
18806
  * Every contribution carries a `stage`:
17937
- * - `primary` — shown on the first credentials screen (OIDC /
17938
- * magic-link buttons; a future usernameless passkey).
18807
+ * - `primary` — shown on the first credentials screen (OIDC
18808
+ * buttons; a usernameless passkey).
17939
18809
  * - `second-factor` — shown AFTER the password leg, gated on the
17940
18810
  * returned `factors` (passkey-as-2FA today).
17941
18811
  *
@@ -17962,7 +18832,7 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
17962
18832
  * The provider names an external identity a signed-in user can link to
17963
18833
  * their own account (D782): `auth.listLinkableProviders` /
17964
18834
  * `beginExternalLink` offer exactly the redirect methods that set this,
17965
- * whatever their id. Absent / false — a login button only (magic-link).
18835
+ * whatever their id. Absent / false — a login button only.
17966
18836
  */
17967
18837
  linkable: boolean().optional()
17968
18838
  }),
@@ -21817,8 +22687,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
21817
22687
  * `super_admin` — collapsed onto the single boolean because every
21818
22688
  * non-admin caller is governed by the same scope-check rules; the
21819
22689
  * distinction was only ever used to route role-specific procedures
21820
- * which we no longer have. Agents are admin sessions issued via
21821
- * `createServiceToken`; CLI / webhook integrations are `cst_*` tokens
22690
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
21822
22691
  * with `isAdmin: false` + an explicit scope list.
21823
22692
  */
21824
22693
  /** Per-method access flavour. Materialised on every cap method via codegen. */
@@ -23493,6 +24362,9 @@ var RetrainExportFilterSchema = object({
23493
24362
  frameIds: array(string$2()).max(2e4).optional(),
23494
24363
  /** Only frames in at least one of these named collections. */
23495
24364
  collectionIds: array(string$2()).max(200).optional(),
24365
+ /** Exactly the frames of this dataset version (and its completeOnly). An
24366
+ * unknown id selects nothing. */
24367
+ datasetVersionId: string$2().optional(),
23496
24368
  batchId: string$2().optional(),
23497
24369
  /** Only frames the operator marked complete (all subjects boxed). */
23498
24370
  completeOnly: boolean().optional()
@@ -23660,6 +24532,67 @@ var RetrainLlmAssistResultSchema = discriminatedUnion("kind", [object({
23660
24532
  ]),
23661
24533
  detail: string$2().optional()
23662
24534
  })]);
24535
+ /** What a dataset version is cut from. Every field narrows. */
24536
+ var RetrainDatasetSelectionSchema = object({
24537
+ deviceIds: array(number()).readonly().optional(),
24538
+ collectionIds: array(string$2()).max(200).readonly().optional(),
24539
+ frameIds: array(string$2()).max(2e4).readonly().optional()
24540
+ });
24541
+ /** The counts a dataset is judged by. */
24542
+ var RetrainDatasetStatsSchema = object({
24543
+ frames: number().int(),
24544
+ completeFrames: number().int(),
24545
+ /** `completeFrames / frames`, 0..1. */
24546
+ completeness: number(),
24547
+ /** Boxes to learn (model errors excluded). */
24548
+ subjects: number().int(),
24549
+ modelErrors: number().int(),
24550
+ /** Complete frames with no subject. */
24551
+ hardNegatives: number().int(),
24552
+ /** Subjects per class × camera × day/night. */
24553
+ cells: array(object({
24554
+ macroClass: string$2(),
24555
+ deviceId: number(),
24556
+ lighting: _enum([
24557
+ "day",
24558
+ "night",
24559
+ "unknown"
24560
+ ]),
24561
+ subjects: number().int(),
24562
+ frames: number().int()
24563
+ })).readonly(),
24564
+ cameras: array(object({
24565
+ deviceId: number(),
24566
+ frames: number().int(),
24567
+ completeFrames: number().int()
24568
+ })).readonly()
24569
+ });
24570
+ /** An immutable dataset version, without its frame list. */
24571
+ var RetrainDatasetVersionSchema = object({
24572
+ id: string$2(),
24573
+ name: string$2(),
24574
+ createdAt: number(),
24575
+ selection: RetrainDatasetSelectionSchema,
24576
+ layout: RetrainExportLayoutSchema,
24577
+ completeOnly: boolean(),
24578
+ frameCount: number().int(),
24579
+ /** sha256 of what the frames taught when the version was frozen. */
24580
+ annotationHash: string$2(),
24581
+ /** The export manifest schema the version was cut under. */
24582
+ manifestSchema: string$2(),
24583
+ stats: RetrainDatasetStatsSchema
24584
+ });
24585
+ var CreateRetrainDatasetVersionResultSchema = discriminatedUnion("kind", [object({
24586
+ kind: literal("created"),
24587
+ version: RetrainDatasetVersionSchema
24588
+ }), object({
24589
+ kind: literal("refused"),
24590
+ reason: _enum([
24591
+ "empty-name",
24592
+ "duplicate-name",
24593
+ "no-frames"
24594
+ ])
24595
+ })]);
23663
24596
  /** The outcome of a lifecycle move owned by the retrain page. */
23664
24597
  var RetrainTransitionResultSchema = object({
23665
24598
  trackId: string$2(),
@@ -24449,6 +25382,47 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
24449
25382
  kind: "mutation",
24450
25383
  auth: "admin",
24451
25384
  timeoutMs: 60 * 6e4
25385
+ }), method(object({
25386
+ filter: RetrainExportFilterSchema,
25387
+ layout: RetrainExportLayoutSchema
25388
+ }), object({
25389
+ ticket: PeerBytesTicketSchema,
25390
+ frames: number().int(),
25391
+ annotations: number().int()
25392
+ }), {
25393
+ kind: "mutation",
25394
+ auth: "admin",
25395
+ timeoutMs: 12e4
25396
+ }), method(object({
25397
+ selection: RetrainDatasetSelectionSchema,
25398
+ completeOnly: boolean().optional()
25399
+ }), RetrainDatasetStatsSchema, {
25400
+ kind: "query",
25401
+ auth: "admin"
25402
+ }), method(object({
25403
+ name: string$2().max(120),
25404
+ selection: RetrainDatasetSelectionSchema,
25405
+ layout: RetrainExportLayoutSchema,
25406
+ completeOnly: boolean()
25407
+ }), CreateRetrainDatasetVersionResultSchema, {
25408
+ kind: "mutation",
25409
+ auth: "admin",
25410
+ timeoutMs: 12e4
25411
+ }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), {
25412
+ kind: "query",
25413
+ auth: "admin"
25414
+ }), method(object({ id: string$2() }), object({ deleted: boolean() }), {
25415
+ kind: "mutation",
25416
+ auth: "admin"
25417
+ }), method(object({ id: string$2() }), object({
25418
+ found: boolean(),
25419
+ annotationHash: string$2(),
25420
+ matches: boolean(),
25421
+ missingFrames: number().int()
25422
+ }), {
25423
+ kind: "query",
25424
+ auth: "admin",
25425
+ timeoutMs: 12e4
24452
25426
  }), method(object({}), array(RetrainAssistProfileSchema).readonly(), {
24453
25427
  kind: "query",
24454
25428
  auth: "admin"
@@ -28027,8 +29001,8 @@ version: string$2().optional() }), ServerUpdateActionResultSchema, {
28027
29001
  * `smtp-provider` — pluggable email delivery surface.
28028
29002
  *
28029
29003
  * Collection cap: a deployment may install multiple SMTP relays (e.g.
28030
- * one for transactional / one for notifications). Consumers (magic-link,
28031
- * notifier addons, …) walk the collection and pick the first
29004
+ * one for transactional / one for notifications). Consumers (notifier
29005
+ * addons, …) walk the collection and pick the first
28032
29006
  * ready provider OR target a specific addonId.
28033
29007
  *
28034
29008
  * The shape stays small on purpose — `sendEmail` is enough for the
@@ -28207,7 +29181,7 @@ targets: array(object({
28207
29181
  })));
28208
29182
  /**
28209
29183
  * `sso-bridge` — internal hub-only cap that lets SSO-style auth
28210
- * providers (OIDC, SAML, magic-link, …) mint an HMAC-signed token
29184
+ * providers (OIDC, SAML, …) mint an HMAC-signed token
28211
29185
  * carrying the post-callback claims before redirecting back to
28212
29186
  * `/api/auth/sso/finish`.
28213
29187
  *
@@ -28270,7 +29244,14 @@ var SsoBridgeClaimsSchema = object({
28270
29244
  * Verified `iss` of the id_token behind an OIDC login bridge (D782). A
28271
29245
  * subject is unique only per issuer, so a link is bound to it.
28272
29246
  */
28273
- issuer: string$2().optional()
29247
+ issuer: string$2().optional(),
29248
+ /**
29249
+ * SHA-256 (hex) of the `camstack_sso_state` cookie the IdP `/start` set in
29250
+ * the browser that began this sign-in. `/api/auth/sso/finish` requires the
29251
+ * request to present the matching cookie — a login bridge is useless in
29252
+ * any other browser.
29253
+ */
29254
+ browserBinding: string$2().optional()
28274
29255
  });
28275
29256
  method(object({
28276
29257
  claims: SsoBridgeClaimsSchema,
@@ -40546,16 +41527,6 @@ var ApiKeySummarySchema = object({
40546
41527
  createdAt: number(),
40547
41528
  lastUsedAt: number().optional()
40548
41529
  });
40549
- var CreateApiKeyInputSchema = object({
40550
- label: string$2(),
40551
- isAdmin: boolean().default(false),
40552
- allowedProviders: union([array(string$2()), literal("*")]).optional(),
40553
- allowedDevices: record(string$2(), union([array(string$2()), literal("*")])).optional()
40554
- });
40555
- var CreateApiKeyResultSchema = object({
40556
- token: string$2(),
40557
- record: ApiKeySummarySchema
40558
- });
40559
41530
  var ScopedTokenSummarySchema = object({
40560
41531
  id: string$2(),
40561
41532
  userId: string$2(),
@@ -40654,17 +41625,10 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
40654
41625
  }), UserSummarySchema.extend({ passwordHash: string$2() }).nullable(), {
40655
41626
  kind: "mutation",
40656
41627
  access: "view"
40657
- }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(CreateApiKeyInputSchema, CreateApiKeyResultSchema, {
40658
- kind: "mutation",
40659
- auth: "admin",
40660
- access: "create"
40661
- }), method(object({ id: string$2() }), object({ success: literal(true) }), {
41628
+ }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(object({ id: string$2() }), object({ success: literal(true) }), {
40662
41629
  kind: "mutation",
40663
41630
  auth: "admin",
40664
41631
  access: "delete"
40665
- }), method(object({ token: string$2() }), ApiKeySummarySchema.nullable(), {
40666
- kind: "mutation",
40667
- access: "view"
40668
41632
  }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
40669
41633
  kind: "mutation",
40670
41634
  auth: "admin",
@@ -40738,15 +41702,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
40738
41702
  }).nullable(), { access: "view" }), method(object({ userId: string$2() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
40739
41703
  userId: string$2(),
40740
41704
  issuer: string$2()
40741
- }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({
40742
- userId: string$2(),
40743
- issuer: string$2().min(1),
40744
- label: string$2().optional()
40745
- }), object({ success: literal(true) }), {
40746
- kind: "mutation",
40747
- auth: "admin",
40748
- access: "create"
40749
- }), method(ExternalIdentityKeySchema.extend({ userId: string$2() }), object({ success: boolean() }), {
41705
+ }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({ userId: string$2() }), object({ success: boolean() }), {
40750
41706
  kind: "mutation",
40751
41707
  auth: "admin",
40752
41708
  access: "delete"
@@ -41451,6 +42407,451 @@ var zoneRulesCapability = {
41451
42407
  */
41452
42408
  durability: "restored"
41453
42409
  };
42410
+ /**
42411
+ * `training-provider` — ONE cloud that can run the CamStack trainer.
42412
+ *
42413
+ * A thin, mockable translation layer: it knows how to run a container with a
42414
+ * GPU, move a dataset in, read the job's stdout and hand artefacts back. It
42415
+ * knows nothing about datasets, splits, floors, cost policy or Model Studio —
42416
+ * those are the `training` orchestrator's (D805). Every rule written there
42417
+ * once is what makes a second provider (RunPod, a local NVIDIA node) a new
42418
+ * manifest entry and nothing else.
42419
+ *
42420
+ * Collection, routed by the `addonId` in every single-row input (the `llm` /
42421
+ * `notification-output` posture); `describe` concat-fans across providers.
42422
+ * Every method is `admin`: these spend money.
42423
+ *
42424
+ * Every cloud object a provider creates is tagged with the orchestrator's
42425
+ * `jobKey`, so a retried submit finds the job it already started instead of
42426
+ * starting a second GPU, and `listJobs` can find orphans.
42427
+ *
42428
+ * Bytes never ride a cap field: the dataset arrives as a `ctx.peerBytes`
42429
+ * ticket the producer (pipeline-analytics) minted, and artefacts leave as a
42430
+ * ticket the provider mints (D613).
42431
+ */
42432
+ var TrainingGpuOptionSchema = object({
42433
+ id: string$2(),
42434
+ label: string$2(),
42435
+ /** List price, USD per GPU-hour, before any region multiplier. */
42436
+ usdPerHour: number().nonnegative(),
42437
+ vramGb: number().nonnegative()
42438
+ });
42439
+ var TrainingRegionOptionSchema = object({
42440
+ /** `''` = any region (the provider's choice). */
42441
+ id: string$2(),
42442
+ label: string$2(),
42443
+ priceMultiplier: number().positive()
42444
+ });
42445
+ /**
42446
+ * The provider's per-account settings, as the orchestrator reads them. They
42447
+ * live in the PROVIDER addon's settings (operator decision 2026-10-08: they
42448
+ * depend on the user's account), never hard-coded in the orchestrator.
42449
+ */
42450
+ var TrainingProviderDefaultsSchema = object({
42451
+ gpuType: string$2(),
42452
+ region: string$2(),
42453
+ costCapUsd: number().nonnegative(),
42454
+ maxRuntimeSec: number().int().positive(),
42455
+ /** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
42456
+ failedDatasetGraceHours: number().nonnegative()
42457
+ });
42458
+ var TrainingProviderDescriptorSchema = object({
42459
+ addonId: string$2(),
42460
+ /** `modal`, `runpod`, `fake`, … */
42461
+ kind: string$2(),
42462
+ label: string$2(),
42463
+ gpuTypes: array(TrainingGpuOptionSchema).readonly(),
42464
+ regions: array(TrainingRegionOptionSchema).readonly(),
42465
+ maxDatasetBytes: number().int().positive(),
42466
+ maxRuntimeSec: number().int().positive(),
42467
+ freeTierNote: string$2().optional(),
42468
+ /** Where the data goes, in one sentence the confirm dialog repeats. */
42469
+ dataResidencyNote: string$2(),
42470
+ /** Credentials are present — never the values. */
42471
+ configured: boolean(),
42472
+ defaults: TrainingProviderDefaultsSchema
42473
+ });
42474
+ var TrainingCredentialCheckSchema = object({
42475
+ ok: boolean(),
42476
+ /** Workspace / account name, when the provider says. */
42477
+ account: string$2().optional(),
42478
+ reason: _enum([
42479
+ "missing",
42480
+ "invalid",
42481
+ "forbidden",
42482
+ "network",
42483
+ "quota"
42484
+ ]).optional(),
42485
+ detail: string$2().optional()
42486
+ });
42487
+ var ProviderJobStateSchema = _enum([
42488
+ "pending",
42489
+ "starting",
42490
+ "running",
42491
+ "succeeded",
42492
+ "failed",
42493
+ "cancelled",
42494
+ "lost"
42495
+ ]);
42496
+ var ProviderJobStatusSchema = object({
42497
+ jobKey: string$2(),
42498
+ providerJobId: string$2().optional(),
42499
+ state: ProviderJobStateSchema,
42500
+ startedAt: number().optional(),
42501
+ endedAt: number().optional(),
42502
+ exitCode: number().int().optional(),
42503
+ failureReason: string$2().optional(),
42504
+ gpuType: string$2(),
42505
+ region: string$2().optional(),
42506
+ billedSeconds: number().nonnegative(),
42507
+ costUsd: number().nonnegative(),
42508
+ /** True when `costUsd` is runtime × list price, not a billing answer. */
42509
+ costIsEstimate: boolean(),
42510
+ lastFetchedAt: number()
42511
+ });
42512
+ /**
42513
+ * The trainer the job runs, by SOURCE revision: the provider turns it into an
42514
+ * image its own way (Modal builds the published Dockerfile at that revision;
42515
+ * a registry-pull provider maps it to a tag). Recorded on the job and echoed
42516
+ * in `result.json`.
42517
+ */
42518
+ var TrainerSourceRefSchema = object({
42519
+ /** Hugging Face repo id, e.g. `camstack/camstack-trainer`. */
42520
+ repo: string$2().min(1),
42521
+ /** A commit sha (never a branch) — the job must be reproducible. */
42522
+ revision: string$2().regex(/^[0-9a-f]{7,64}$/)
42523
+ });
42524
+ var JobRef = {
42525
+ addonId: string$2(),
42526
+ jobKey: string$2().uuid()
42527
+ };
42528
+ var TrainingLogLineSchema = object({
42529
+ ts: number(),
42530
+ text: string$2()
42531
+ });
42532
+ method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({ addonId: string$2() }), TrainingCredentialCheckSchema, {
42533
+ kind: "mutation",
42534
+ auth: "admin",
42535
+ timeoutMs: 3e4
42536
+ }), method(object({
42537
+ addonId: string$2(),
42538
+ gpuType: string$2(),
42539
+ region: string$2(),
42540
+ datasetBytes: number().int().nonnegative(),
42541
+ gpuSecondsLow: number().nonnegative(),
42542
+ gpuSecondsHigh: number().nonnegative()
42543
+ }), object({
42544
+ usdLow: number().nonnegative(),
42545
+ usdHigh: number().nonnegative(),
42546
+ notes: array(string$2()).readonly()
42547
+ }), { auth: "admin" }), method(object({
42548
+ ...JobRef,
42549
+ ticket: PeerBytesTicketSchema
42550
+ }), object({
42551
+ bytes: number().int().nonnegative(),
42552
+ sha256: string$2()
42553
+ }), {
42554
+ kind: "mutation",
42555
+ auth: "admin",
42556
+ timeoutMs: 120 * 6e4
42557
+ }), method(object({
42558
+ ...JobRef,
42559
+ trainer: TrainerSourceRefSchema,
42560
+ jobSpecJson: string$2().min(2).max(64e3),
42561
+ gpuType: string$2(),
42562
+ region: string$2(),
42563
+ maxRuntimeSec: number().int().positive()
42564
+ }), ProviderJobStatusSchema, {
42565
+ kind: "mutation",
42566
+ auth: "admin",
42567
+ timeoutMs: 30 * 6e4
42568
+ }), method(object(JobRef), ProviderJobStatusSchema, {
42569
+ auth: "admin",
42570
+ timeoutMs: 6e4
42571
+ }), method(object({
42572
+ ...JobRef,
42573
+ cursor: string$2().optional(),
42574
+ max: number().int().min(1).max(500)
42575
+ }), object({
42576
+ lines: array(TrainingLogLineSchema).readonly(),
42577
+ cursor: string$2()
42578
+ }), {
42579
+ auth: "admin",
42580
+ timeoutMs: 6e4
42581
+ }), method(object(JobRef), object({ ok: literal(true) }), {
42582
+ kind: "mutation",
42583
+ auth: "admin",
42584
+ timeoutMs: 6e4
42585
+ }), method(object(JobRef), object({
42586
+ found: boolean(),
42587
+ text: string$2().optional()
42588
+ }), {
42589
+ kind: "mutation",
42590
+ auth: "admin",
42591
+ timeoutMs: 5 * 6e4
42592
+ }), method(object({
42593
+ ...JobRef,
42594
+ path: _enum(["bundle.tar"])
42595
+ }), object({ ticket: PeerBytesTicketSchema }), {
42596
+ kind: "mutation",
42597
+ auth: "admin",
42598
+ timeoutMs: 5 * 6e4
42599
+ }), method(object(JobRef), object({ deleted: array(string$2()).readonly() }), {
42600
+ kind: "mutation",
42601
+ auth: "admin",
42602
+ timeoutMs: 5 * 6e4
42603
+ }), method(object({ addonId: string$2() }), array(ProviderJobStatusSchema).readonly(), {
42604
+ auth: "admin",
42605
+ timeoutMs: 2 * 6e4
42606
+ });
42607
+ /**
42608
+ * `training` — the cloud-training orchestrator (D805). Hub-only singleton,
42609
+ * provided by `addon-training`.
42610
+ *
42611
+ * It owns what every provider must agree on, written once:
42612
+ *
42613
+ * - **Dataset versions.** Taken over from pipeline-analytics (D796): the rows
42614
+ * live here (D808); pipeline-analytics still CUTS a version (it owns the corpus and
42615
+ * the export plan) and reaches this store through the five row methods
42616
+ * below, so the Retrain page and the export did not change.
42617
+ * - **Jobs.** A persisted state machine, a reconcile loop against the
42618
+ * provider, a cost guard, a daily orphan sweep and the retention rules.
42619
+ * - **The return flow.** Verified artefacts → Model Studio
42620
+ * (`custom-model-registry.importModelBundle`) → canary on cameras →
42621
+ * rollback. Nothing is ever registered automatically.
42622
+ *
42623
+ * Every method is `admin`.
42624
+ */
42625
+ /** A version WITH its frame list — what the export and a job read. */
42626
+ var TrainingDatasetVersionRowSchema = RetrainDatasetVersionSchema.omit({ frameCount: true }).extend({ frameIds: array(string$2()).max(2e4).readonly() });
42627
+ /** A base model a detector job can fine-tune, and the baseline it is judged against. */
42628
+ var TrainingBaseModelSchema = object({
42629
+ modelId: string$2(),
42630
+ label: string$2(),
42631
+ weights: string$2(),
42632
+ imgsz: number().int(),
42633
+ baselineOnnxUrl: string$2(),
42634
+ baselineFloors: record(string$2(), number()),
42635
+ /** The base the fleet runs most — the UI's default. */
42636
+ recommended: boolean()
42637
+ });
42638
+ var TrainingPresetSchema = _enum([
42639
+ "quick",
42640
+ "standard",
42641
+ "thorough"
42642
+ ]);
42643
+ var TrainingJobRequestSchema = object({
42644
+ datasetVersionId: string$2().min(1),
42645
+ /** The `training-provider` addon that runs it. */
42646
+ addonId: string$2().min(1),
42647
+ gpuType: string$2().min(1),
42648
+ region: string$2(),
42649
+ baseModelId: string$2().min(1),
42650
+ preset: TrainingPresetSchema,
42651
+ /** Freeze the backbone's first N layers; `null` = the preset's choice. */
42652
+ freeze: number().int().nonnegative().nullable(),
42653
+ /** Cameras held out whole for evaluation; `null` = the orchestrator's default. */
42654
+ holdoutCameras: array(number().int()).nullable()
42655
+ });
42656
+ var TrainingSplitPlanSchema = object({
42657
+ holdoutCameras: array(number().int()).readonly(),
42658
+ /** Used when no camera is held out: the last N days of every camera. */
42659
+ holdoutLastDays: number().int().nonnegative(),
42660
+ /** Holdout subjects per class (camera holdout only; `null` = known only after the split). */
42661
+ holdoutSupport: record(string$2(), number().int()).nullable(),
42662
+ trainSubjects: number().int()
42663
+ });
42664
+ var TrainingRefusalReasonSchema = _enum([
42665
+ "unknown-dataset",
42666
+ "unknown-provider",
42667
+ "provider-not-configured",
42668
+ "unknown-base-model",
42669
+ "unknown-gpu",
42670
+ "dataset-too-large",
42671
+ "no-training-subjects",
42672
+ "job-already-running"
42673
+ ]);
42674
+ var TrainingJobPlanSchema = object({
42675
+ refusal: object({
42676
+ reason: TrainingRefusalReasonSchema,
42677
+ detail: string$2()
42678
+ }).nullable(),
42679
+ warnings: array(string$2()).readonly(),
42680
+ split: TrainingSplitPlanSchema.nullable(),
42681
+ estimate: object({
42682
+ datasetBytes: number().int(),
42683
+ uploadMinutesAt20Mbps: number(),
42684
+ gpuSecondsLow: number(),
42685
+ gpuSecondsHigh: number(),
42686
+ usdLow: number(),
42687
+ usdHigh: number(),
42688
+ notes: array(string$2()).readonly()
42689
+ }).nullable(),
42690
+ /** Pre-filled from the provider's settings; the operator may lower or raise them. */
42691
+ defaults: object({
42692
+ maxCostUsd: number(),
42693
+ maxRuntimeSec: number().int()
42694
+ }).nullable(),
42695
+ /** The sentence the confirm dialog repeats: where the frames go and when they are deleted. */
42696
+ dataNotice: string$2()
42697
+ });
42698
+ /**
42699
+ * Orchestrator-owned states, persisted. `uploading` covers exporting the
42700
+ * archive (it is streamed, never staged). Terminal: `failed`, `cancelled`,
42701
+ * `lost`, `expired`, `discarded`. `registered` and `canary` are where a
42702
+ * result lives after the operator acted on it.
42703
+ */
42704
+ var TrainingJobStateSchema = _enum([
42705
+ "uploading",
42706
+ "submitted",
42707
+ "starting",
42708
+ "running",
42709
+ "collecting",
42710
+ "ready",
42711
+ "registered",
42712
+ "canary",
42713
+ "failed",
42714
+ "cancelling",
42715
+ "cancelled",
42716
+ "lost",
42717
+ "expired",
42718
+ "discarded"
42719
+ ]);
42720
+ var TrainingFailureReasonSchema = _enum([
42721
+ "cost-cap",
42722
+ "runtime-cap",
42723
+ "upload-failed",
42724
+ "submit-failed",
42725
+ "trainer-failed",
42726
+ "result-invalid",
42727
+ "checksum-mismatch",
42728
+ "fetch-failed",
42729
+ "provider-error",
42730
+ "hub-restart-during-upload"
42731
+ ]);
42732
+ var TrainingProgressPointSchema = object({
42733
+ epoch: number().int(),
42734
+ map50: number().nullable(),
42735
+ map50_95: number().nullable()
42736
+ });
42737
+ var TrainingCanarySchema = object({
42738
+ deviceIds: array(number().int()).readonly(),
42739
+ since: number(),
42740
+ /** Every override the canary replaced, exactly, so rollback restores it. */
42741
+ previous: array(object({
42742
+ deviceId: number().int(),
42743
+ nodeId: string$2(),
42744
+ deviceKey: string$2(),
42745
+ patch: object({
42746
+ modelId: string$2().optional(),
42747
+ settings: record(string$2(), unknown()).readonly().optional()
42748
+ }).nullable()
42749
+ })).readonly()
42750
+ });
42751
+ var TrainingJobSchema = object({
42752
+ id: string$2(),
42753
+ idempotencyKey: string$2(),
42754
+ name: string$2(),
42755
+ createdAt: number(),
42756
+ updatedAt: number(),
42757
+ state: TrainingJobStateSchema,
42758
+ stage: TrainingStageSchema.nullable(),
42759
+ failure: object({
42760
+ reason: TrainingFailureReasonSchema,
42761
+ stage: string$2().nullable(),
42762
+ detail: string$2()
42763
+ }).nullable(),
42764
+ request: TrainingJobRequestSchema,
42765
+ maxCostUsd: number().nonnegative(),
42766
+ maxRuntimeSec: number().int().positive(),
42767
+ trainer: TrainerSourceRefSchema,
42768
+ datasetLayout: RetrainExportLayoutSchema,
42769
+ dataset: object({
42770
+ bytes: number().int(),
42771
+ sha256: string$2(),
42772
+ uploadedAt: number()
42773
+ }).nullable(),
42774
+ split: TrainingSplitPlanSchema,
42775
+ provider: object({
42776
+ state: ProviderJobStateSchema.nullable(),
42777
+ providerJobId: string$2().nullable(),
42778
+ startedAt: number().nullable(),
42779
+ endedAt: number().nullable(),
42780
+ billedSeconds: number(),
42781
+ costUsd: number(),
42782
+ costIsEstimate: boolean(),
42783
+ lastPolledAt: number().nullable()
42784
+ }),
42785
+ progress: object({
42786
+ epoch: number().int().nullable(),
42787
+ epochs: number().int().nullable(),
42788
+ etaSec: number().nullable(),
42789
+ series: array(TrainingProgressPointSchema).readonly()
42790
+ }),
42791
+ /** The last lines of the job's output (≤ 200), newest last. Never frame paths. */
42792
+ logTail: array(string$2()).readonly(),
42793
+ logCursor: string$2().nullable(),
42794
+ artifacts: object({
42795
+ bundleBytes: number().int(),
42796
+ bundleSha256: string$2(),
42797
+ fetchedAt: number(),
42798
+ /** When the staged artefacts are deleted from the hub. */
42799
+ expiresAt: number()
42800
+ }).nullable(),
42801
+ /** When the provider-side copy of the frames was deleted; null while it exists. */
42802
+ cloudDatasetDeletedAt: number().nullable(),
42803
+ /** A failed job's dataset is kept until then (the provider's grace), then deleted. */
42804
+ cloudCleanupDueAt: number().nullable(),
42805
+ /** Model ids registered from this job (base, and int8 when kept). */
42806
+ registeredModelIds: array(string$2()).readonly(),
42807
+ canary: TrainingCanarySchema.nullable()
42808
+ });
42809
+ var IdInput = object({ id: string$2().min(1) });
42810
+ method(TrainingDatasetVersionRowSchema, object({ stored: boolean() }), {
42811
+ kind: "mutation",
42812
+ auth: "admin"
42813
+ }), method(IdInput, TrainingDatasetVersionRowSchema.nullable(), { auth: "admin" }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), { auth: "admin" }), method(object({ name: string$2() }), object({ id: string$2().nullable() }), { auth: "admin" }), method(IdInput, object({ removed: boolean() }), {
42814
+ kind: "mutation",
42815
+ auth: "admin"
42816
+ }), method(object({}), array(TrainingBaseModelSchema).readonly(), { auth: "admin" }), method(TrainingJobRequestSchema, TrainingJobPlanSchema, {
42817
+ auth: "admin",
42818
+ timeoutMs: 6e4
42819
+ }), method(TrainingJobRequestSchema.extend({
42820
+ name: string$2().min(1).max(120),
42821
+ maxCostUsd: number().positive(),
42822
+ maxRuntimeSec: number().int().positive(),
42823
+ idempotencyKey: string$2().min(8).max(80)
42824
+ }), discriminatedUnion("kind", [object({
42825
+ kind: literal("started"),
42826
+ job: TrainingJobSchema
42827
+ }), object({
42828
+ kind: literal("refused"),
42829
+ reason: TrainingRefusalReasonSchema,
42830
+ detail: string$2()
42831
+ })]), {
42832
+ kind: "mutation",
42833
+ auth: "admin",
42834
+ timeoutMs: 12e4
42835
+ }), method(object({}), array(TrainingJobSchema).readonly(), { auth: "admin" }), method(IdInput, TrainingJobSchema.nullable(), { auth: "admin" }), method(IdInput, TrainingJobSchema, {
42836
+ kind: "mutation",
42837
+ auth: "admin",
42838
+ timeoutMs: 12e4
42839
+ }), method(IdInput, TrainingResultSchema.nullable(), { auth: "admin" }), method(IdInput.extend({ canaryDeviceIds: array(number().int()).readonly() }), TrainingJobSchema, {
42840
+ kind: "mutation",
42841
+ auth: "admin",
42842
+ timeoutMs: 30 * 6e4
42843
+ }), method(IdInput.extend({ deviceIds: array(number().int()).min(1).readonly() }), TrainingJobSchema, {
42844
+ kind: "mutation",
42845
+ auth: "admin",
42846
+ timeoutMs: 12e4
42847
+ }), method(IdInput, TrainingJobSchema, {
42848
+ kind: "mutation",
42849
+ auth: "admin",
42850
+ timeoutMs: 12e4
42851
+ }), method(IdInput, TrainingJobSchema, {
42852
+ kind: "mutation",
42853
+ auth: "admin"
42854
+ });
41454
42855
  SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
41455
42856
  Object.freeze({
41456
42857
  person: .5,
@@ -43599,6 +45000,12 @@ Object.freeze({
43599
45000
  addonId: null,
43600
45001
  access: "create"
43601
45002
  },
45003
+ "backup.checkBackupKey": {
45004
+ capName: "backup",
45005
+ capScope: "system",
45006
+ addonId: null,
45007
+ access: "create"
45008
+ },
43602
45009
  "backup.delete": {
43603
45010
  capName: "backup",
43604
45011
  capScope: "system",
@@ -43611,6 +45018,18 @@ Object.freeze({
43611
45018
  addonId: null,
43612
45019
  access: "delete"
43613
45020
  },
45021
+ "backup.disableEncryption": {
45022
+ capName: "backup",
45023
+ capScope: "system",
45024
+ addonId: null,
45025
+ access: "create"
45026
+ },
45027
+ "backup.getEncryption": {
45028
+ capName: "backup",
45029
+ capScope: "system",
45030
+ addonId: null,
45031
+ access: "view"
45032
+ },
43614
45033
  "backup.getEntries": {
43615
45034
  capName: "backup",
43616
45035
  capScope: "system",
@@ -43665,6 +45084,12 @@ Object.freeze({
43665
45084
  addonId: null,
43666
45085
  access: "create"
43667
45086
  },
45087
+ "backup.setupEncryption": {
45088
+ capName: "backup",
45089
+ capScope: "system",
45090
+ addonId: null,
45091
+ access: "create"
45092
+ },
43668
45093
  "backup.trigger": {
43669
45094
  capName: "backup",
43670
45095
  capScope: "system",
@@ -44217,6 +45642,12 @@ Object.freeze({
44217
45642
  addonId: null,
44218
45643
  access: "create"
44219
45644
  },
45645
+ "customModelRegistry.importModelBundle": {
45646
+ capName: "custom-model-registry",
45647
+ capScope: "system",
45648
+ addonId: null,
45649
+ access: "create"
45650
+ },
44220
45651
  "customModelRegistry.listModels": {
44221
45652
  capName: "custom-model-registry",
44222
45653
  capScope: "system",
@@ -45657,6 +47088,12 @@ Object.freeze({
45657
47088
  addonId: null,
45658
47089
  access: "view"
45659
47090
  },
47091
+ "keychainAdmin.acknowledgeReset": {
47092
+ capName: "keychain-admin",
47093
+ capScope: "system",
47094
+ addonId: null,
47095
+ access: "create"
47096
+ },
45660
47097
  "keychainAdmin.deleteOrphans": {
45661
47098
  capName: "keychain-admin",
45662
47099
  capScope: "system",
@@ -45693,6 +47130,12 @@ Object.freeze({
45693
47130
  addonId: null,
45694
47131
  access: "delete"
45695
47132
  },
47133
+ "keychainAdmin.resetReport": {
47134
+ capName: "keychain-admin",
47135
+ capScope: "system",
47136
+ addonId: null,
47137
+ access: "delete"
47138
+ },
45696
47139
  "keychainAdmin.reveal": {
45697
47140
  capName: "keychain-admin",
45698
47141
  capScope: "system",
@@ -45705,6 +47148,12 @@ Object.freeze({
45705
47148
  addonId: null,
45706
47149
  access: "create"
45707
47150
  },
47151
+ "keychainAdmin.setSystemSecret": {
47152
+ capName: "keychain-admin",
47153
+ capScope: "system",
47154
+ addonId: null,
47155
+ access: "create"
47156
+ },
45708
47157
  "keychainAdmin.status": {
45709
47158
  capName: "keychain-admin",
45710
47159
  capScope: "system",
@@ -47151,6 +48600,12 @@ Object.freeze({
47151
48600
  addonId: null,
47152
48601
  access: "create"
47153
48602
  },
48603
+ "pipelineAnalytics.createRetrainDatasetVersion": {
48604
+ capName: "pipeline-analytics",
48605
+ capScope: "device",
48606
+ addonId: null,
48607
+ access: "create"
48608
+ },
47154
48609
  "pipelineAnalytics.deleteDeviceEvents": {
47155
48610
  capName: "pipeline-analytics",
47156
48611
  capScope: "device",
@@ -47163,6 +48618,12 @@ Object.freeze({
47163
48618
  addonId: null,
47164
48619
  access: "delete"
47165
48620
  },
48621
+ "pipelineAnalytics.deleteRetrainDatasetVersion": {
48622
+ capName: "pipeline-analytics",
48623
+ capScope: "device",
48624
+ addonId: null,
48625
+ access: "delete"
48626
+ },
47166
48627
  "pipelineAnalytics.deleteTracks": {
47167
48628
  capName: "pipeline-analytics",
47168
48629
  capScope: "device",
@@ -47385,6 +48846,12 @@ Object.freeze({
47385
48846
  addonId: null,
47386
48847
  access: "view"
47387
48848
  },
48849
+ "pipelineAnalytics.listRetrainDatasetVersions": {
48850
+ capName: "pipeline-analytics",
48851
+ capScope: "device",
48852
+ addonId: null,
48853
+ access: "view"
48854
+ },
47388
48855
  "pipelineAnalytics.listRetrainFrames": {
47389
48856
  capName: "pipeline-analytics",
47390
48857
  capScope: "device",
@@ -47415,6 +48882,12 @@ Object.freeze({
47415
48882
  addonId: null,
47416
48883
  access: "view"
47417
48884
  },
48885
+ "pipelineAnalytics.offerRetrainArchive": {
48886
+ capName: "pipeline-analytics",
48887
+ capScope: "device",
48888
+ addonId: null,
48889
+ access: "create"
48890
+ },
47418
48891
  "pipelineAnalytics.ownersWithMedia": {
47419
48892
  capName: "pipeline-analytics",
47420
48893
  capScope: "device",
@@ -47427,6 +48900,12 @@ Object.freeze({
47427
48900
  addonId: null,
47428
48901
  access: "create"
47429
48902
  },
48903
+ "pipelineAnalytics.previewRetrainDataset": {
48904
+ capName: "pipeline-analytics",
48905
+ capScope: "device",
48906
+ addonId: null,
48907
+ access: "view"
48908
+ },
47430
48909
  "pipelineAnalytics.proposeRetrainAnnotations": {
47431
48910
  capName: "pipeline-analytics",
47432
48911
  capScope: "device",
@@ -47565,6 +49044,12 @@ Object.freeze({
47565
49044
  addonId: null,
47566
49045
  access: "create"
47567
49046
  },
49047
+ "pipelineAnalytics.verifyRetrainDatasetVersion": {
49048
+ capName: "pipeline-analytics",
49049
+ capScope: "device",
49050
+ addonId: null,
49051
+ access: "view"
49052
+ },
47568
49053
  "pipelineAnalytics.wipeAllAnalytics": {
47569
49054
  capName: "pipeline-analytics",
47570
49055
  capScope: "device",
@@ -49941,6 +51426,174 @@ Object.freeze({
49941
51426
  addonId: null,
49942
51427
  access: "view"
49943
51428
  },
51429
+ "training.canaryResult": {
51430
+ capName: "training",
51431
+ capScope: "system",
51432
+ addonId: null,
51433
+ access: "create"
51434
+ },
51435
+ "training.cancelJob": {
51436
+ capName: "training",
51437
+ capScope: "system",
51438
+ addonId: null,
51439
+ access: "create"
51440
+ },
51441
+ "training.discardResult": {
51442
+ capName: "training",
51443
+ capScope: "system",
51444
+ addonId: null,
51445
+ access: "create"
51446
+ },
51447
+ "training.findDatasetVersionIdByName": {
51448
+ capName: "training",
51449
+ capScope: "system",
51450
+ addonId: null,
51451
+ access: "view"
51452
+ },
51453
+ "training.getDatasetVersion": {
51454
+ capName: "training",
51455
+ capScope: "system",
51456
+ addonId: null,
51457
+ access: "view"
51458
+ },
51459
+ "training.getJob": {
51460
+ capName: "training",
51461
+ capScope: "system",
51462
+ addonId: null,
51463
+ access: "view"
51464
+ },
51465
+ "training.getJobResult": {
51466
+ capName: "training",
51467
+ capScope: "system",
51468
+ addonId: null,
51469
+ access: "view"
51470
+ },
51471
+ "training.listBaseModels": {
51472
+ capName: "training",
51473
+ capScope: "system",
51474
+ addonId: null,
51475
+ access: "view"
51476
+ },
51477
+ "training.listDatasetVersions": {
51478
+ capName: "training",
51479
+ capScope: "system",
51480
+ addonId: null,
51481
+ access: "view"
51482
+ },
51483
+ "training.listJobs": {
51484
+ capName: "training",
51485
+ capScope: "system",
51486
+ addonId: null,
51487
+ access: "view"
51488
+ },
51489
+ "training.planJob": {
51490
+ capName: "training",
51491
+ capScope: "system",
51492
+ addonId: null,
51493
+ access: "view"
51494
+ },
51495
+ "training.putDatasetVersion": {
51496
+ capName: "training",
51497
+ capScope: "system",
51498
+ addonId: null,
51499
+ access: "create"
51500
+ },
51501
+ "training.registerResult": {
51502
+ capName: "training",
51503
+ capScope: "system",
51504
+ addonId: null,
51505
+ access: "create"
51506
+ },
51507
+ "training.removeDatasetVersion": {
51508
+ capName: "training",
51509
+ capScope: "system",
51510
+ addonId: null,
51511
+ access: "delete"
51512
+ },
51513
+ "training.rollbackCanary": {
51514
+ capName: "training",
51515
+ capScope: "system",
51516
+ addonId: null,
51517
+ access: "create"
51518
+ },
51519
+ "training.startJob": {
51520
+ capName: "training",
51521
+ capScope: "system",
51522
+ addonId: null,
51523
+ access: "create"
51524
+ },
51525
+ "trainingProvider.cancelJob": {
51526
+ capName: "training-provider",
51527
+ capScope: "system",
51528
+ addonId: null,
51529
+ access: "create"
51530
+ },
51531
+ "trainingProvider.cleanupJob": {
51532
+ capName: "training-provider",
51533
+ capScope: "system",
51534
+ addonId: null,
51535
+ access: "create"
51536
+ },
51537
+ "trainingProvider.describe": {
51538
+ capName: "training-provider",
51539
+ capScope: "system",
51540
+ addonId: null,
51541
+ access: "view"
51542
+ },
51543
+ "trainingProvider.estimateJob": {
51544
+ capName: "training-provider",
51545
+ capScope: "system",
51546
+ addonId: null,
51547
+ access: "view"
51548
+ },
51549
+ "trainingProvider.getJob": {
51550
+ capName: "training-provider",
51551
+ capScope: "system",
51552
+ addonId: null,
51553
+ access: "view"
51554
+ },
51555
+ "trainingProvider.listJobEvents": {
51556
+ capName: "training-provider",
51557
+ capScope: "system",
51558
+ addonId: null,
51559
+ access: "view"
51560
+ },
51561
+ "trainingProvider.listJobs": {
51562
+ capName: "training-provider",
51563
+ capScope: "system",
51564
+ addonId: null,
51565
+ access: "view"
51566
+ },
51567
+ "trainingProvider.offerArtifact": {
51568
+ capName: "training-provider",
51569
+ capScope: "system",
51570
+ addonId: null,
51571
+ access: "create"
51572
+ },
51573
+ "trainingProvider.readResult": {
51574
+ capName: "training-provider",
51575
+ capScope: "system",
51576
+ addonId: null,
51577
+ access: "create"
51578
+ },
51579
+ "trainingProvider.submitJob": {
51580
+ capName: "training-provider",
51581
+ capScope: "system",
51582
+ addonId: null,
51583
+ access: "create"
51584
+ },
51585
+ "trainingProvider.uploadDataset": {
51586
+ capName: "training-provider",
51587
+ capScope: "system",
51588
+ addonId: null,
51589
+ access: "create"
51590
+ },
51591
+ "trainingProvider.validateCredentials": {
51592
+ capName: "training-provider",
51593
+ capScope: "system",
51594
+ addonId: null,
51595
+ access: "create"
51596
+ },
49944
51597
  "turnProvider.getTurnServers": {
49945
51598
  capName: "turn-provider",
49946
51599
  capScope: "system",
@@ -49965,12 +51618,6 @@ Object.freeze({
49965
51618
  addonId: null,
49966
51619
  access: "create"
49967
51620
  },
49968
- "userManagement.createApiKey": {
49969
- capName: "user-management",
49970
- capScope: "system",
49971
- addonId: null,
49972
- access: "create"
49973
- },
49974
51621
  "userManagement.createScopedToken": {
49975
51622
  capName: "user-management",
49976
51623
  capScope: "system",
@@ -50007,12 +51654,6 @@ Object.freeze({
50007
51654
  addonId: null,
50008
51655
  access: "view"
50009
51656
  },
50010
- "userManagement.linkExternalIdentity": {
50011
- capName: "user-management",
50012
- capScope: "system",
50013
- addonId: null,
50014
- access: "create"
50015
- },
50016
51657
  "userManagement.listApiKeys": {
50017
51658
  capName: "user-management",
50018
51659
  capScope: "system",
@@ -50115,12 +51756,6 @@ Object.freeze({
50115
51756
  addonId: null,
50116
51757
  access: "create"
50117
51758
  },
50118
- "userManagement.validateApiKey": {
50119
- capName: "user-management",
50120
- capScope: "system",
50121
- addonId: null,
50122
- access: "view"
50123
- },
50124
51759
  "userManagement.validateCredentials": {
50125
51760
  capName: "user-management",
50126
51761
  capScope: "system",
@@ -54234,6 +55869,11 @@ Object.freeze({
54234
55869
  form: "single",
54235
55870
  optional: false
54236
55871
  }],
55872
+ "training.canaryResult": [{
55873
+ name: "deviceIds",
55874
+ form: "array",
55875
+ optional: false
55876
+ }],
54237
55877
  "update.getStatus": [{
54238
55878
  name: "deviceId",
54239
55879
  form: "single",