@camstack/addon-export-hap 1.2.155 → 1.2.156

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.
@@ -5426,7 +5426,7 @@ var ZodIssueCode = {
5426
5426
  var ZodFirstPartyTypeKind;
5427
5427
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5428
5428
  //#endregion
5429
- //#region ../types/dist/sleep-Cr5YOk3m.mjs
5429
+ //#region ../types/dist/sleep-r3RWkGVx.mjs
5430
5430
  /**
5431
5431
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5432
5432
  * window to float samples (D455).
@@ -5543,7 +5543,7 @@ function isKeychainStoredField(field) {
5543
5543
  var SECRET_CLEAR = { $secretClear: true };
5544
5544
  /** The `'***'` token D634 redaction writes for non-admins. */
5545
5545
  var LEGACY_DEVICE_REDACTION = "***";
5546
- function isRecord$1$1(value) {
5546
+ function isRecord$2(value) {
5547
5547
  return typeof value === "object" && value !== null && !Array.isArray(value);
5548
5548
  }
5549
5549
  function makeSecretMarker(ref) {
@@ -5554,12 +5554,12 @@ function makeSecretMarker(ref) {
5554
5554
  }
5555
5555
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5556
5556
  function isSecretMarker(value) {
5557
- if (!isRecord$1$1(value)) return false;
5557
+ if (!isRecord$2(value)) return false;
5558
5558
  const ref = value["$secret"];
5559
5559
  return typeof ref === "string" && ref.length > 0;
5560
5560
  }
5561
5561
  function isSecretClear(value) {
5562
- return isRecord$1$1(value) && value["$secretClear"] === true;
5562
+ return isRecord$2(value) && value["$secretClear"] === true;
5563
5563
  }
5564
5564
  /**
5565
5565
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6075,6 +6075,13 @@ function globalSecretScope() {
6075
6075
  function encodeSegment(value) {
6076
6076
  return encodeURIComponent(value);
6077
6077
  }
6078
+ function decodeSegment(value) {
6079
+ try {
6080
+ return decodeURIComponent(value);
6081
+ } catch {
6082
+ return null;
6083
+ }
6084
+ }
6078
6085
  /**
6079
6086
  * The field path of a value inside an array item, addressed by the item's id:
6080
6087
  * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
@@ -6083,6 +6090,75 @@ function encodeSegment(value) {
6083
6090
  function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6084
6091
  return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6085
6092
  }
6093
+ function parseScope(segments) {
6094
+ switch (segments[0]) {
6095
+ case "global": return {
6096
+ scope: GLOBAL_SCOPE,
6097
+ used: 1
6098
+ };
6099
+ case "node": {
6100
+ const nodeId = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6101
+ return nodeId === null || nodeId.length === 0 ? null : {
6102
+ scope: {
6103
+ kind: "node",
6104
+ nodeId
6105
+ },
6106
+ used: 2
6107
+ };
6108
+ }
6109
+ case "device": {
6110
+ const raw = segments[1];
6111
+ if (raw === void 0 || !/^\d+$/.test(raw)) return null;
6112
+ return {
6113
+ scope: {
6114
+ kind: "device",
6115
+ deviceId: Number(raw)
6116
+ },
6117
+ used: 2
6118
+ };
6119
+ }
6120
+ case "integration": {
6121
+ const id = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6122
+ return id === null || id.length === 0 ? null : {
6123
+ scope: {
6124
+ kind: "integration",
6125
+ integrationId: id
6126
+ },
6127
+ used: 2
6128
+ };
6129
+ }
6130
+ case "row": {
6131
+ const collection = segments[1] !== void 0 ? decodeSegment(segments[1]) : null;
6132
+ const rowId = segments[2] !== void 0 ? decodeSegment(segments[2]) : null;
6133
+ if (collection === null || rowId === null || collection.length === 0 || rowId.length === 0) return null;
6134
+ return {
6135
+ scope: {
6136
+ kind: "row",
6137
+ collection,
6138
+ rowId
6139
+ },
6140
+ used: 3
6141
+ };
6142
+ }
6143
+ default: return null;
6144
+ }
6145
+ }
6146
+ /** Take a ref apart; `null` when it is not a well-formed ref. */
6147
+ function parseSecretRef(ref) {
6148
+ if (!ref.startsWith("secret://")) return null;
6149
+ const segments = ref.slice(9).split("/");
6150
+ const owner = segments[0] !== void 0 ? decodeSegment(segments[0]) : null;
6151
+ if (owner === null || owner.length === 0) return null;
6152
+ const parsed = parseScope(segments.slice(1));
6153
+ if (parsed === null) return null;
6154
+ const fieldPath = segments.slice(1 + parsed.used).join("/");
6155
+ if (fieldPath.length === 0) return null;
6156
+ return {
6157
+ owner,
6158
+ scope: parsed.scope,
6159
+ fieldPath
6160
+ };
6161
+ }
6086
6162
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6087
6163
  var KeychainWriteRefusedError = class extends Error {
6088
6164
  fieldPath;
@@ -6093,7 +6169,7 @@ var KeychainWriteRefusedError = class extends Error {
6093
6169
  }
6094
6170
  };
6095
6171
  var KEEP = { kind: "keep" };
6096
- function isRecord$2(value) {
6172
+ function isRecord$1$1(value) {
6097
6173
  return typeof value === "object" && value !== null && !Array.isArray(value);
6098
6174
  }
6099
6175
  function defaultMintId() {
@@ -6106,7 +6182,7 @@ function collectSecretMarkerRefs(value, out = []) {
6106
6182
  return out;
6107
6183
  }
6108
6184
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6109
- else if (isRecord$2(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6185
+ else if (isRecord$1$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6110
6186
  return out;
6111
6187
  }
6112
6188
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6161,7 +6237,7 @@ function rowId(row, idKey) {
6161
6237
  return null;
6162
6238
  }
6163
6239
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6164
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$2) : [];
6240
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1$1) : [];
6165
6241
  if (!Array.isArray(incoming)) {
6166
6242
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6167
6243
  return {
@@ -6177,7 +6253,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6177
6253
  const kept = /* @__PURE__ */ new Set();
6178
6254
  const rows = [];
6179
6255
  for (const row of incoming) {
6180
- if (!isRecord$2(row)) {
6256
+ if (!isRecord$1$1(row)) {
6181
6257
  rows.push(row);
6182
6258
  continue;
6183
6259
  }
@@ -6202,7 +6278,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6202
6278
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6203
6279
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6204
6280
  case "object": {
6205
- if (!isRecord$2(incoming)) {
6281
+ if (!isRecord$1$1(incoming)) {
6206
6282
  if (incoming === void 0) return KEEP;
6207
6283
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6208
6284
  return {
@@ -6210,7 +6286,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6210
6286
  value: incoming
6211
6287
  };
6212
6288
  }
6213
- const storedObj = isRecord$2(stored) ? stored : {};
6289
+ const storedObj = isRecord$1$1(stored) ? stored : {};
6214
6290
  return {
6215
6291
  kind: "value",
6216
6292
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6269,12 +6345,19 @@ async function transformSecretWrite(input) {
6269
6345
  }
6270
6346
  };
6271
6347
  }
6348
+ /** Is `ref` one of `owner`'s refs? */
6349
+ function isSecretRefOwnedBy(ref, owner) {
6350
+ return parseSecretRef(ref)?.owner === owner;
6351
+ }
6272
6352
  /**
6273
6353
  * Replace every marker in `value` with its keychain value. Returns the SAME
6274
6354
  * reference when there is no marker (no allocation, no keychain call).
6275
6355
  */
6276
- async function resolveSecretMarkers(value, secrets) {
6277
- const refs = collectSecretMarkerRefs(value);
6356
+ async function resolveSecretMarkers(value, secrets, options = {}) {
6357
+ const keepMarker = options.unresolved === "keep-marker";
6358
+ const owner = options.ownedBy;
6359
+ const inScope = (ref) => owner === void 0 || isSecretRefOwnedBy(ref, owner);
6360
+ const refs = collectSecretMarkerRefs(value).filter(inScope);
6278
6361
  if (refs.length === 0) return {
6279
6362
  value,
6280
6363
  unresolved: []
@@ -6298,10 +6381,18 @@ async function resolveSecretMarkers(value, secrets) {
6298
6381
  }
6299
6382
  const substitute = (v) => {
6300
6383
  if (isSecretMarker(v)) {
6384
+ if (!inScope(v.$secret)) return {
6385
+ keep: true,
6386
+ value: v
6387
+ };
6301
6388
  const answer = answers[v.$secret];
6302
- return answer?.kind === "value" ? {
6389
+ if (answer?.kind === "value") return {
6303
6390
  keep: true,
6304
6391
  value: answer.value
6392
+ };
6393
+ return keepMarker ? {
6394
+ keep: true,
6395
+ value: v
6305
6396
  } : {
6306
6397
  keep: false,
6307
6398
  value: void 0
@@ -6318,7 +6409,7 @@ async function resolveSecretMarkers(value, secrets) {
6318
6409
  value: items
6319
6410
  };
6320
6411
  }
6321
- if (isRecord$2(v)) {
6412
+ if (isRecord$1$1(v)) {
6322
6413
  const out = {};
6323
6414
  for (const [k, child] of Object.entries(v)) {
6324
6415
  const s = substitute(child);
@@ -6339,14 +6430,152 @@ async function resolveSecretMarkers(value, secrets) {
6339
6430
  unresolved
6340
6431
  };
6341
6432
  }
6342
- function touchesTree(tree, patch) {
6343
- if (tree.size === 0) return false;
6344
- for (const key of Object.keys(patch)) {
6345
- const at = key.indexOf("@");
6346
- if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6433
+ /** An addon tried to replace a stored secret it could not read. Nothing was written. */
6434
+ var SecretOverwriteRefusedError = class extends Error {
6435
+ ref;
6436
+ reason;
6437
+ constructor(ref, reason) {
6438
+ 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.`);
6439
+ this.ref = ref;
6440
+ this.reason = reason;
6441
+ this.name = "SecretOverwriteRefusedError";
6442
+ }
6443
+ };
6444
+ function isRecord$3(value) {
6445
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6446
+ }
6447
+ function resolvedValue(pass, marker) {
6448
+ const answer = pass.answers[marker.$secret];
6449
+ return answer?.kind === "value" ? answer.value : null;
6450
+ }
6451
+ async function atMarker(pass, incoming, stored) {
6452
+ if (incoming === null) return stored;
6453
+ if (typeof incoming !== "string") return incoming;
6454
+ if (incoming === resolvedValue(pass, stored)) return stored;
6455
+ const intent = classifySecretWrite(incoming);
6456
+ if (intent.kind !== "set") return stored;
6457
+ const ref = stored.$secret;
6458
+ if (!isSecretRefOwnedBy(ref, pass.secrets.owner)) return incoming;
6459
+ const answer = pass.answers[ref];
6460
+ 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);
6461
+ try {
6462
+ await pass.secrets.put(ref, intent.value);
6463
+ } catch (err) {
6464
+ throw new KeychainWriteRefusedError(ref, err);
6465
+ }
6466
+ pass.changedRefs.push(ref);
6467
+ return stored;
6468
+ }
6469
+ function inArray(pass, incoming, stored) {
6470
+ return incoming.map((item, index) => {
6471
+ const twin = stored[index];
6472
+ if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6473
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
6474
+ if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6475
+ return item;
6476
+ });
6477
+ }
6478
+ function inArrayRow(pass, incoming, stored) {
6479
+ const out = { ...incoming };
6480
+ for (const [key, value] of Object.entries(incoming)) {
6481
+ const twin = stored[key];
6482
+ if (isSecretMarker(twin)) {
6483
+ if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6484
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
6485
+ else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6486
+ }
6487
+ return out;
6488
+ }
6489
+ async function walk(pass, incoming, stored) {
6490
+ if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6491
+ if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6492
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
6493
+ const out = { ...incoming };
6494
+ for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
6495
+ return out;
6496
+ }
6497
+ /** Restore markers a write-back carries as values. See the file doc. */
6498
+ async function restoreUnchangedSecrets(input) {
6499
+ const refs = [];
6500
+ for (const key of Object.keys(input.patch)) collectSecretMarkerRefs(input.stored[key], refs);
6501
+ const owned = refs.filter((ref) => isSecretRefOwnedBy(ref, input.secrets.owner));
6502
+ if (owned.length === 0) return {
6503
+ patch: input.patch,
6504
+ changedRefs: []
6505
+ };
6506
+ const pass = {
6507
+ secrets: input.secrets,
6508
+ answers: await input.secrets.resolve([...new Set(owned)]),
6509
+ operatorWrite: input.operatorWrite,
6510
+ changedRefs: []
6511
+ };
6512
+ const out = {};
6513
+ for (const [key, value] of Object.entries(input.patch)) out[key] = await walk(pass, value, input.stored[key]);
6514
+ return {
6515
+ patch: out,
6516
+ changedRefs: pass.changedRefs
6517
+ };
6518
+ }
6519
+ /** Structural equality over JSON-shaped values (key order does not matter). */
6520
+ function isJsonEqual(a, b) {
6521
+ if (Object.is(a, b)) return true;
6522
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6523
+ if (isRecord$3(a) && isRecord$3(b)) {
6524
+ const keys = Object.keys(a);
6525
+ if (keys.length !== Object.keys(b).length) return false;
6526
+ return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
6347
6527
  }
6348
6528
  return false;
6349
6529
  }
6530
+ /** The patch without the keys whose value already equals the stored one. */
6531
+ function dropUnchangedKeys(patch, stored) {
6532
+ const out = {};
6533
+ for (const [key, value] of Object.entries(patch)) {
6534
+ if (Object.prototype.hasOwnProperty.call(stored, key) && isJsonEqual(value, stored[key])) continue;
6535
+ out[key] = value;
6536
+ }
6537
+ return out;
6538
+ }
6539
+ /** The top-level keys of a blob that hold at least one of `owner`'s markers. */
6540
+ function markerKeysOf(blob, owner) {
6541
+ const keys = /* @__PURE__ */ new Set();
6542
+ for (const [key, value] of Object.entries(blob)) if (collectSecretMarkerRefs(value).some((ref) => isSecretRefOwnedBy(ref, owner))) keys.add(key);
6543
+ return keys;
6544
+ }
6545
+ function nodeFromStored(value, owner) {
6546
+ if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6547
+ if (!isRecord$3(value)) return null;
6548
+ const children = /* @__PURE__ */ new Map();
6549
+ for (const [key, child] of Object.entries(value)) {
6550
+ const node = nodeFromStored(child, owner);
6551
+ if (node !== null) children.set(key, node);
6552
+ }
6553
+ return children.size > 0 ? {
6554
+ kind: "object",
6555
+ children
6556
+ } : null;
6557
+ }
6558
+ /**
6559
+ * The declared secret tree, widened by every place the STORED blob holds a
6560
+ * marker under one of `keys` — so a marker the schema no longer declares (or
6561
+ * never declared: Wyze before b4906cec6) still gets the save path's
6562
+ * KEEP / SET / CLEAR semantics instead of being overwritten by whatever the
6563
+ * addon writes. Markers inside arrays are not added: a row has no id field to
6564
+ * match by unless the schema declares one. Only `owner`'s markers count: a
6565
+ * builtin that keeps another addon's marker (device-manager) never takes it
6566
+ * over.
6567
+ */
6568
+ function widenTreeWithStoredMarkers(declared, stored, keys, owner) {
6569
+ const added = /* @__PURE__ */ new Map();
6570
+ for (const key of keys) {
6571
+ const at = key.indexOf("@");
6572
+ const base = at > 0 ? key.slice(0, at) : key;
6573
+ if (declared.has(base) || added.has(base)) continue;
6574
+ const node = nodeFromStored(stored[key], owner);
6575
+ if (node !== null) added.set(base, node);
6576
+ }
6577
+ return added.size === 0 ? declared : new Map([...declared, ...added]);
6578
+ }
6350
6579
  /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6351
6580
  async function readStoredAddonBlob(raw) {
6352
6581
  const threeWay = raw.readAddonStoreResult;
@@ -6355,7 +6584,41 @@ async function readStoredAddonBlob(raw) {
6355
6584
  if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6356
6585
  return result.kind === "missing" ? {} : result.value;
6357
6586
  }
6358
- function createSecretAwareSettings(raw, opts) {
6587
+ function touchesTree(tree, patch) {
6588
+ if (tree.size === 0) return false;
6589
+ for (const key of Object.keys(patch)) {
6590
+ const at = key.indexOf("@");
6591
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6592
+ }
6593
+ return false;
6594
+ }
6595
+ /**
6596
+ * Which top-level keys of each store held markers when last seen. `undefined`
6597
+ * for a store not seen yet: its first write reads it, to be safe.
6598
+ */
6599
+ var MarkerKeyIndex = class {
6600
+ owner;
6601
+ byStore = /* @__PURE__ */ new Map();
6602
+ constructor(owner) {
6603
+ this.owner = owner;
6604
+ }
6605
+ seen(store, blob) {
6606
+ this.byStore.set(store, markerKeysOf(blob, this.owner));
6607
+ }
6608
+ wrote(store, patch) {
6609
+ const keys = this.byStore.get(store);
6610
+ if (keys === void 0) return;
6611
+ const now = markerKeysOf(patch, this.owner);
6612
+ for (const key of Object.keys(patch)) if (now.has(key)) keys.add(key);
6613
+ else keys.delete(key);
6614
+ }
6615
+ mayHoldMarkers(store, patch) {
6616
+ const keys = this.byStore.get(store);
6617
+ if (keys === void 0) return true;
6618
+ return Object.keys(patch).some((key) => keys.has(key));
6619
+ }
6620
+ };
6621
+ function createHandle(raw, opts) {
6359
6622
  const chains = /* @__PURE__ */ new Map();
6360
6623
  const serialize = (key, fn) => {
6361
6624
  const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
@@ -6366,46 +6629,130 @@ function createSecretAwareSettings(raw, opts) {
6366
6629
  });
6367
6630
  return next;
6368
6631
  };
6369
- const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6370
- if (!touchesTree(tree, patch)) return rawWrite(patch);
6371
- return serialize(chainKey, async () => {
6632
+ const index = new MarkerKeyIndex(opts.secrets.owner);
6633
+ const resolveRead = async (store, blob) => {
6634
+ index.seen(store, blob);
6635
+ const { value, unresolved } = await resolveSecretMarkers(blob, opts.secrets, {
6636
+ unresolved: "keep-marker",
6637
+ ownedBy: opts.secrets.owner
6638
+ });
6639
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6640
+ return value;
6641
+ };
6642
+ const write = async (store, declared, scope, patch, readStored, rawWrite) => {
6643
+ if (!touchesTree(declared, patch) && !index.mayHoldMarkers(store, patch)) {
6644
+ await rawWrite(patch);
6645
+ index.wrote(store, patch);
6646
+ return { changed: true };
6647
+ }
6648
+ return serialize(store, async () => {
6372
6649
  const stored = await readStored();
6650
+ index.seen(store, stored);
6651
+ const operatorWrite = opts.isOperatorWrite?.() === true;
6652
+ const restored = await restoreUnchangedSecrets({
6653
+ patch,
6654
+ stored,
6655
+ secrets: opts.secrets,
6656
+ operatorWrite
6657
+ });
6373
6658
  const result = await transformSecretWrite({
6374
- tree,
6659
+ tree: widenTreeWithStoredMarkers(declared, stored, Object.keys(restored.patch), opts.secrets.owner),
6375
6660
  secrets: opts.secrets,
6376
- patch,
6661
+ patch: restored.patch,
6377
6662
  stored,
6378
6663
  ...scope !== void 0 ? { scope } : {},
6379
- operatorWrite: opts.isOperatorWrite?.() === true
6664
+ operatorWrite
6380
6665
  });
6381
- if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6666
+ const effective = dropUnchangedKeys(result.patch, stored);
6667
+ const wroteBlob = Object.keys(effective).length > 0;
6668
+ if (wroteBlob) {
6669
+ await rawWrite(effective);
6670
+ index.wrote(store, effective);
6671
+ }
6382
6672
  const { orphaned } = await result.afterWrite();
6383
6673
  if (orphaned.length > 0) opts.onOrphaned(orphaned);
6674
+ return { changed: wroteBlob || restored.changedRefs.length > 0 };
6384
6675
  });
6385
6676
  };
6386
- const wrapped = {
6387
- writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6388
- writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6389
- kind: "device",
6390
- deviceId
6391
- }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6392
- };
6393
- return new Proxy(raw, { get(target, prop, receiver) {
6394
- if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6395
- if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6396
- const value = Reflect.get(target, prop, receiver);
6397
- return typeof value === "function" ? value.bind(target) : value;
6398
- } });
6677
+ const writeAddon = (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p));
6678
+ const readAddonStoreResult = raw.readAddonStoreResult;
6679
+ const readAddonStoreKeyResult = raw.readAddonStoreKeyResult;
6680
+ const readDeviceStoreBatch = raw.readDeviceStoreBatch;
6681
+ const overrides = {
6682
+ readAddonStore: async () => resolveRead("addon", await raw.readAddonStore()),
6683
+ ...readAddonStoreResult !== void 0 ? { readAddonStoreResult: async () => {
6684
+ const result = await readAddonStoreResult.call(raw);
6685
+ return result.kind === "value" ? {
6686
+ kind: "value",
6687
+ value: await resolveRead("addon", result.value)
6688
+ } : result;
6689
+ } } : {},
6690
+ ...readAddonStoreKeyResult !== void 0 ? { readAddonStoreKeyResult: async (key) => {
6691
+ const result = await readAddonStoreKeyResult.call(raw, key);
6692
+ if (result.kind !== "present") return result;
6693
+ const { value, unresolved } = await resolveSecretMarkers({ [key]: result.value }, opts.secrets, {
6694
+ unresolved: "keep-marker",
6695
+ ownedBy: opts.secrets.owner
6696
+ });
6697
+ if (unresolved.length > 0) opts.onUnresolved?.(unresolved);
6698
+ return {
6699
+ kind: "present",
6700
+ value: value[key]
6701
+ };
6702
+ } } : {},
6703
+ readDeviceStore: async (deviceId) => resolveRead(`device:${deviceId}`, await raw.readDeviceStore(deviceId)),
6704
+ ...readDeviceStoreBatch !== void 0 ? { readDeviceStoreBatch: async (deviceIds) => {
6705
+ const rows = await readDeviceStoreBatch.call(raw, deviceIds);
6706
+ const out = /* @__PURE__ */ new Map();
6707
+ for (const [deviceId, blob] of rows) out.set(deviceId, await resolveRead(`device:${deviceId}`, blob));
6708
+ return out;
6709
+ } } : {},
6710
+ writeAddonStore: async (patch) => {
6711
+ await writeAddon(patch);
6712
+ },
6713
+ writeDeviceStore: async (deviceId, patch) => {
6714
+ await write(`device:${deviceId}`, opts.deviceTree(), {
6715
+ kind: "device",
6716
+ deviceId
6717
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p));
6718
+ }
6719
+ };
6720
+ return {
6721
+ settings: new Proxy(raw, { get(target, prop, receiver) {
6722
+ if (typeof prop === "string" && Object.prototype.hasOwnProperty.call(overrides, prop)) return Reflect.get(overrides, prop);
6723
+ const value = Reflect.get(target, prop, receiver);
6724
+ return typeof value === "function" ? value.bind(target) : value;
6725
+ } }),
6726
+ raw: {
6727
+ readAddonStore: async () => {
6728
+ const blob = await raw.readAddonStore();
6729
+ index.seen("addon", blob);
6730
+ return blob;
6731
+ },
6732
+ readDeviceStore: async (deviceId) => {
6733
+ const blob = await raw.readDeviceStore(deviceId);
6734
+ index.seen(`device:${deviceId}`, blob);
6735
+ return blob;
6736
+ }
6737
+ },
6738
+ writeAddonStore: writeAddon
6739
+ };
6399
6740
  }
6400
- /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6401
- function withSecretAwareSettings(context, opts) {
6741
+ /** The context the addon sees, plus the private raw view and write outcome. */
6742
+ function createSecretAwareContext(context, opts) {
6402
6743
  const raw = context.settings;
6403
- if (raw === void 0) return context;
6404
- const settings = createSecretAwareSettings(raw, opts);
6405
- return new Proxy(context, { get(target, prop, receiver) {
6406
- if (prop === "settings") return settings;
6407
- return Reflect.get(target, prop, receiver);
6408
- } });
6744
+ if (raw === void 0) return {
6745
+ context,
6746
+ handle: null
6747
+ };
6748
+ const handle = createHandle(raw, opts);
6749
+ return {
6750
+ context: new Proxy(context, { get(target, prop, receiver) {
6751
+ if (prop === "settings") return handle.settings;
6752
+ return Reflect.get(target, prop, receiver);
6753
+ } }),
6754
+ handle
6755
+ };
6409
6756
  }
6410
6757
  var LEAF = { kind: "leaf" };
6411
6758
  var DEFAULT_ITEM_ID_KEY = "id";
@@ -6580,6 +6927,14 @@ var BaseAddon = class {
6580
6927
  _secretChangeUnsub = null;
6581
6928
  /** >0 while an OPERATOR's settings write is being applied. */
6582
6929
  _operatorWriteDepth = 0;
6930
+ /**
6931
+ * The keychain-aware settings handle (D798). Its `raw` view is the ONLY way
6932
+ * to the marker-bearing blobs and stays private to this class: the form
6933
+ * hydrate and config resolution need markers, addon code never does.
6934
+ */
6935
+ _secretSettings = null;
6936
+ /** Refs an addon-facing read could not resolve — each is logged once per process. */
6937
+ _loggedUnresolvedReads = /* @__PURE__ */ new Set();
6583
6938
  constructor(defaults) {
6584
6939
  this.defaults = defaults;
6585
6940
  this._config = { ...defaults };
@@ -6616,13 +6971,21 @@ var BaseAddon = class {
6616
6971
  }
6617
6972
  async initialize(context) {
6618
6973
  const secrets = context.secrets;
6619
- this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6620
- secrets,
6621
- addonTree: () => this.addonSecretTree(),
6622
- deviceTree: () => this.deviceSecretTree(),
6623
- onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6624
- isOperatorWrite: () => this._operatorWriteDepth > 0
6625
- }) : context;
6974
+ if (secrets !== void 0) {
6975
+ const { context: wrapped, handle } = createSecretAwareContext(context, {
6976
+ secrets,
6977
+ addonTree: () => this.addonSecretTree(),
6978
+ deviceTree: () => this.deviceSecretTree(),
6979
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6980
+ isOperatorWrite: () => this._operatorWriteDepth > 0,
6981
+ onUnresolved: (unresolved) => this.logUnresolvedRead(unresolved)
6982
+ });
6983
+ this._ctx = wrapped;
6984
+ this._secretSettings = handle;
6985
+ } else {
6986
+ this._ctx = context;
6987
+ this._secretSettings = null;
6988
+ }
6626
6989
  await this.resolveConfig();
6627
6990
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6628
6991
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -6739,11 +7102,8 @@ var BaseAddon = class {
6739
7102
  async getGlobalSettings(overlay, cap, nodeId) {
6740
7103
  const schema = this.globalSettingsSchema(cap);
6741
7104
  if (!schema) return { sections: [] };
6742
- const projected = await this.resolveGlobalStore(nodeId, cap);
6743
- return hydrateSchema(schema, overlay ? {
6744
- ...projected,
6745
- ...overlay
6746
- } : projected, { inlineSecretsAsViews: true });
7105
+ const projected = await this.readRawProjectedStore(nodeId, cap);
7106
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
6747
7107
  }
6748
7108
  /**
6749
7109
  * The integration-level view of this addon's settings: exactly the sections
@@ -6788,7 +7148,7 @@ var BaseAddon = class {
6788
7148
  });
6789
7149
  }
6790
7150
  if (sections.length === 0) return null;
6791
- const projected = await this.resolveGlobalStore(nodeId);
7151
+ const projected = await this.readRawProjectedStore(nodeId);
6792
7152
  return hydrateSchema({
6793
7153
  ...schema,
6794
7154
  sections
@@ -6805,12 +7165,50 @@ var BaseAddon = class {
6805
7165
  * the store for custom option logic (option narrowing, value snapping) to
6806
7166
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
6807
7167
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
7168
+ *
7169
+ * Keychain values come back RESOLVED (D798): a secret reads as its value,
7170
+ * never as a `{ $secret }` marker. One the keychain cannot serve right now
7171
+ * stays a marker — "stored, unavailable" (`isSecretMarker()` is true, and it
7172
+ * is listed in {@link unresolvedSecrets}) — never `''` and never absent, so
7173
+ * it cannot be mistaken for "nothing stored, mint a new one". Writing the
7174
+ * resolved blob back is a no-op for every unchanged secret.
6808
7175
  */
6809
7176
  async resolveGlobalStore(nodeId, cap) {
6810
7177
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
7178
+ return this.projectForNode(raw, nodeId, cap);
7179
+ }
7180
+ projectForNode(store, nodeId, cap) {
6811
7181
  const keys = this.perNodeKeys(cap);
6812
7182
  const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6813
- return keys.size > 0 ? projectStore(raw, keys, node) : raw;
7183
+ return keys.size > 0 ? projectStore(store, keys, node) : store;
7184
+ }
7185
+ /** The PROJECTED store with its markers — the form hydrate only (D798). */
7186
+ async readRawProjectedStore(nodeId, cap) {
7187
+ const raw = await this.rawSettings()?.readAddonStore() ?? {};
7188
+ return this.projectForNode(raw, nodeId, cap);
7189
+ }
7190
+ /**
7191
+ * `{ ...stored, ...overlay }`, except that an overlay member equal to the
7192
+ * RESOLVED stored one keeps the stored (marker-bearing) member — so a form
7193
+ * hydrated from a resolved overlay still shows a secret as "set", never as
7194
+ * its value.
7195
+ */
7196
+ async overlayKeepingMarkers(stored, overlay) {
7197
+ const secrets = this._ctx?.secrets;
7198
+ const merged = {
7199
+ ...stored,
7200
+ ...overlay
7201
+ };
7202
+ if (secrets === void 0 || collectSecretMarkerRefs(stored).length === 0) return merged;
7203
+ const { value: resolved } = await resolveSecretMarkers(stored, secrets, {
7204
+ unresolved: "keep-marker",
7205
+ ownedBy: secrets.owner
7206
+ });
7207
+ for (const key of Object.keys(overlay)) {
7208
+ if (collectSecretMarkerRefs(stored[key]).length === 0) continue;
7209
+ if (isJsonEqual(overlay[key], resolved[key])) merged[key] = stored[key];
7210
+ }
7211
+ return merged;
6814
7212
  }
6815
7213
  /**
6816
7214
  * Whether ONE global key of this addon's store was written, read three-way
@@ -6875,8 +7273,12 @@ var BaseAddon = class {
6875
7273
  async clearSecrets(keys, nodeId) {
6876
7274
  const tree = this.addonSecretTree();
6877
7275
  const keychain = this._ctx?.secrets !== void 0;
7276
+ const stored = keychain ? await this.readAddonStoreWithRetry() : {};
6878
7277
  const patch = {};
6879
- for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
7278
+ for (const key of keys) {
7279
+ const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
7280
+ patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
7281
+ }
6880
7282
  await this.applyGlobalPatch(patch, nodeId);
6881
7283
  }
6882
7284
  async applyGlobalPatch(barePatch, nodeId) {
@@ -6884,7 +7286,11 @@ var BaseAddon = class {
6884
7286
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6885
7287
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6886
7288
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6887
- await this._ctx?.settings?.writeAddonStore(scoped);
7289
+ const handle = this._secretSettings;
7290
+ if (handle !== null) {
7291
+ const { changed } = await handle.writeAddonStore(scoped);
7292
+ if (!changed) return;
7293
+ } else await this._ctx?.settings?.writeAddonStore(scoped);
6888
7294
  if (target !== localNode) return;
6889
7295
  await this.resolveConfig();
6890
7296
  await this.onConfigChanged();
@@ -6937,7 +7343,7 @@ var BaseAddon = class {
6937
7343
  async getDeviceSettings(deviceId) {
6938
7344
  const schema = this.deviceSettingsSchema();
6939
7345
  if (!schema) return { sections: [] };
6940
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
7346
+ return hydrateSchema(schema, await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6941
7347
  }
6942
7348
  async updateDeviceSettings(deviceId, patch) {
6943
7349
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -7109,7 +7515,7 @@ var BaseAddon = class {
7109
7515
  key,
7110
7516
  schema,
7111
7517
  fallback,
7112
- read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
7518
+ read: async () => this.resolveStoredSecrets(await this.rawSettings()?.readDeviceStore(deviceId) ?? {}, false),
7113
7519
  write: async (patch) => {
7114
7520
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
7115
7521
  },
@@ -7171,6 +7577,23 @@ var BaseAddon = class {
7171
7577
  }
7172
7578
  return value;
7173
7579
  }
7580
+ /**
7581
+ * The marker-bearing settings reads (D798) — private on purpose. Without a
7582
+ * keychain the context's own view is already raw.
7583
+ */
7584
+ rawSettings() {
7585
+ return this._secretSettings?.raw ?? this._ctx?.settings;
7586
+ }
7587
+ /** An addon-facing read met markers it could not resolve: say so once per ref. */
7588
+ logUnresolvedRead(unresolved) {
7589
+ const fresh = unresolved.filter((u) => !this._loggedUnresolvedReads.has(u.ref));
7590
+ if (fresh.length === 0) return;
7591
+ for (const u of fresh) this._loggedUnresolvedReads.add(u.ref);
7592
+ 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) => ({
7593
+ ref: u.ref,
7594
+ reason: u.reason
7595
+ })) } });
7596
+ }
7174
7597
  /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7175
7598
  scheduleSecretReresolve(delayMs) {
7176
7599
  const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
@@ -7197,7 +7620,7 @@ var BaseAddon = class {
7197
7620
  * `{}` (defaults) — the addon's first successful patch will rehydrate.
7198
7621
  */
7199
7622
  async readAddonStoreWithRetry() {
7200
- const settings = this._ctx?.settings;
7623
+ const settings = this.rawSettings();
7201
7624
  if (!settings) return {};
7202
7625
  const delaysMs = [
7203
7626
  150,
@@ -10157,6 +10580,278 @@ var CameraSwitchGroupSchema = object({
10157
10580
  fetchedAt: number()
10158
10581
  });
10159
10582
  /**
10583
+ * The trainer contract — what the hub hands the cloud trainer and what it
10584
+ * gets back (cloud training, D805+).
10585
+ *
10586
+ * The trainer (`hf/camstack-trainer`, published as the Hugging Face repo
10587
+ * `camstack/camstack-trainer`) is a separate AGPL program the hub never
10588
+ * imports: `job.json` goes in, files come out, and progress is `CAMSTACK_EVENT`
10589
+ * lines on stdout. These schemas are the hub's half of that boundary; the
10590
+ * trainer's pydantic models (and the JSON Schemas generated from them under
10591
+ * `hf/camstack-trainer/schemas/`) are the other half. A change here is a
10592
+ * change there, in the same piece of work.
10593
+ *
10594
+ * No `.default()` anywhere: defaults do not run on the addon cap path, so the
10595
+ * orchestrator fills every field of a job spec explicitly.
10596
+ */
10597
+ var TRAINING_JOB_SCHEMA = "camstack.training/v1";
10598
+ var TRAINING_RESULT_SCHEMA = "camstack.training-result/v1";
10599
+ /** What the trainer can export. Edge TPU is a later, separate image. */
10600
+ var TrainingExportSchema = _enum([
10601
+ "onnx",
10602
+ "openvino-fp16",
10603
+ "openvino-int8",
10604
+ "coreml-fp16"
10605
+ ]);
10606
+ var FloorsSchema = record(string(), number().min(0).max(1));
10607
+ object({
10608
+ schema: literal(TRAINING_JOB_SCHEMA),
10609
+ jobKey: string().uuid(),
10610
+ target: object({
10611
+ kind: literal("detector"),
10612
+ step: literal("object-detection")
10613
+ }),
10614
+ base: object({
10615
+ modelId: string().min(1),
10616
+ /** Ultralytics weights id, e.g. `yolov9m.pt`. */
10617
+ weights: string().min(1),
10618
+ imgsz: number().int().positive()
10619
+ }),
10620
+ baseline: object({
10621
+ modelId: string().min(1),
10622
+ /** The baseline ONNX the holdout comparison runs; public mirror URL. */
10623
+ onnxUrl: string().url(),
10624
+ imgsz: number().int().positive(),
10625
+ floors: FloorsSchema
10626
+ }),
10627
+ dataset: object({
10628
+ versionId: string().min(1),
10629
+ annotationHash: string(),
10630
+ /** sha256 of the uploaded archive; the trainer refuses a mismatch (exit 65). */
10631
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10632
+ }),
10633
+ split: object({
10634
+ holdoutCameras: array(number().int()),
10635
+ /** When no camera is held out: the last N days of every camera. */
10636
+ holdoutLastDays: number().int().nonnegative(),
10637
+ valFraction: number().min(0).max(.5),
10638
+ seed: number().int()
10639
+ }),
10640
+ hyper: object({
10641
+ epochs: number().int().positive(),
10642
+ batch: number().int().positive(),
10643
+ lr0: number().positive(),
10644
+ /** Layers frozen from the start of the backbone; 0 = none. */
10645
+ freeze: number().int().nonnegative(),
10646
+ patience: number().int().nonnegative(),
10647
+ seed: number().int()
10648
+ }),
10649
+ replay: object({
10650
+ source: literal("coco2017"),
10651
+ count: number().int().nonnegative()
10652
+ }),
10653
+ exports: array(TrainingExportSchema).min(1),
10654
+ calibration: object({ maxFrames: number().int().positive() }),
10655
+ floors: object({
10656
+ minSupport: number().int().positive(),
10657
+ clamp: number().min(0).max(1)
10658
+ }),
10659
+ int8Gate: object({ maxMap50Drop: number().min(0).max(1) }),
10660
+ catalog: object({
10661
+ id: string().regex(/^[a-z0-9][a-z0-9-]{2,80}$/),
10662
+ name: string().min(1).max(160)
10663
+ })
10664
+ });
10665
+ /** One regular file of the bundle. An mlpackage contributes one row per member. */
10666
+ var TrainingResultFileSchema = object({
10667
+ path: string().min(1),
10668
+ bytes: number().int().nonnegative(),
10669
+ sha256: string().regex(/^[0-9a-f]{64}$/),
10670
+ format: _enum([
10671
+ "onnx",
10672
+ "openvino",
10673
+ "coreml",
10674
+ "pt"
10675
+ ]),
10676
+ variant: _enum(["base", "int8"])
10677
+ });
10678
+ var DraftFormatSchema = object({
10679
+ /** RELATIVE path inside the bundle; the hub rewrites it to `camstack-local://`. */
10680
+ url: string().min(1),
10681
+ sizeMB: number().nonnegative(),
10682
+ isDirectory: boolean().optional(),
10683
+ files: array(string()).optional(),
10684
+ runtimes: array(literal("python")).optional(),
10685
+ revision: string().min(1)
10686
+ });
10687
+ /** The trainer's half of a catalog entry; the hub completes it (labels, licence, group). */
10688
+ var TrainingCatalogDraftSchema = object({
10689
+ id: string().min(1),
10690
+ name: string().min(1),
10691
+ description: string(),
10692
+ labels: array(unknown()),
10693
+ inputSize: object({
10694
+ width: number().int().positive(),
10695
+ height: number().int().positive()
10696
+ }),
10697
+ preprocessMode: literal("letterbox"),
10698
+ defaultClassFloors: FloorsSchema,
10699
+ formats: object({
10700
+ onnx: DraftFormatSchema.optional(),
10701
+ openvino: DraftFormatSchema.optional(),
10702
+ coreml: DraftFormatSchema.optional()
10703
+ })
10704
+ });
10705
+ /** One class of one model's holdout report (the eval harness's summary). */
10706
+ var TrainingEvalClassSchema = object({
10707
+ positives: number().int(),
10708
+ floor: number().nullable(),
10709
+ tp: number().int(),
10710
+ fp: number().int(),
10711
+ fn: number().int(),
10712
+ precision: number().nullable(),
10713
+ recall: number().nullable(),
10714
+ ap50: number().nullable(),
10715
+ recallByCamera: record(string(), number().nullable()).optional(),
10716
+ recallByLight: record(string(), number().nullable()).optional(),
10717
+ fpByCamera: record(string(), number()).optional(),
10718
+ smallFound: number().int().optional(),
10719
+ smallTotal: number().int().optional()
10720
+ }).passthrough();
10721
+ var TrainingEvalReportSchema = object({
10722
+ frames: number().int(),
10723
+ classes: record(string(), TrainingEvalClassSchema)
10724
+ }).passthrough();
10725
+ /**
10726
+ * A succeeded result carries every block; a failed one carries the error and
10727
+ * whatever was known by then — the other blocks are ABSENT, not null. The
10728
+ * orchestrator checks the blocks it needs before it trusts a success.
10729
+ */
10730
+ var TrainingResultSchema = object({
10731
+ schema: literal(TRAINING_RESULT_SCHEMA),
10732
+ jobKey: string(),
10733
+ status: _enum(["succeeded", "failed"]),
10734
+ error: object({
10735
+ stage: string(),
10736
+ code: string(),
10737
+ message: string()
10738
+ }).nullable(),
10739
+ trainer: object({
10740
+ version: string(),
10741
+ revision: string()
10742
+ }),
10743
+ toolchain: record(string(), string().nullable()),
10744
+ dataset: object({
10745
+ versionId: string(),
10746
+ annotationHash: string(),
10747
+ sha256: string(),
10748
+ frames: object({
10749
+ train: number().int(),
10750
+ val: number().int(),
10751
+ holdout: number().int()
10752
+ }),
10753
+ holdoutCameras: array(number().int()),
10754
+ replayImages: number().int()
10755
+ }).optional(),
10756
+ training: object({
10757
+ epochsRun: number().int(),
10758
+ bestEpoch: number().int(),
10759
+ bestMap50: number(),
10760
+ bestMap50_95: number(),
10761
+ seconds: number()
10762
+ }).optional(),
10763
+ evaluation: object({
10764
+ holdoutFrames: number().int(),
10765
+ baseline: TrainingEvalReportSchema.nullable(),
10766
+ candidate: TrainingEvalReportSchema.nullable(),
10767
+ candidateInt8: TrainingEvalReportSchema.nullable(),
10768
+ recallDeltaByCamera: record(string(), record(string(), number())).nullable(),
10769
+ map50: record(string(), number().nullable())
10770
+ }).optional(),
10771
+ floors: object({
10772
+ baseline: FloorsSchema,
10773
+ candidate: FloorsSchema,
10774
+ candidateInt8: FloorsSchema.nullable(),
10775
+ notes: array(string())
10776
+ }).optional(),
10777
+ int8: object({
10778
+ kept: boolean(),
10779
+ map50Fp16: number().nullable(),
10780
+ map50Int8: number().nullable(),
10781
+ reason: string().nullable()
10782
+ }).optional(),
10783
+ exportsDropped: array(object({
10784
+ export: string(),
10785
+ reason: string()
10786
+ })).optional(),
10787
+ files: array(TrainingResultFileSchema).optional(),
10788
+ bundle: object({
10789
+ path: literal("bundle.tar"),
10790
+ bytes: number().int().nonnegative(),
10791
+ sha256: string().regex(/^[0-9a-f]{64}$/)
10792
+ }).nullable().optional(),
10793
+ catalogDraft: object({
10794
+ base: TrainingCatalogDraftSchema,
10795
+ int8: TrainingCatalogDraftSchema.nullable()
10796
+ }).nullable().optional(),
10797
+ licence: string()
10798
+ });
10799
+ var TrainingStageSchema = _enum([
10800
+ "prepare",
10801
+ "replay",
10802
+ "train",
10803
+ "eval",
10804
+ "export",
10805
+ "package"
10806
+ ]);
10807
+ var EventBase = {
10808
+ v: literal(1),
10809
+ ts: number()
10810
+ };
10811
+ discriminatedUnion("type", [
10812
+ object({
10813
+ ...EventBase,
10814
+ type: literal("stage"),
10815
+ stage: TrainingStageSchema
10816
+ }),
10817
+ object({
10818
+ ...EventBase,
10819
+ type: literal("epoch"),
10820
+ epoch: number().int(),
10821
+ epochs: number().int(),
10822
+ boxLoss: number().nullable().optional(),
10823
+ map50: number().nullable().optional(),
10824
+ map50_95: number().nullable().optional(),
10825
+ etaSec: number().nullable().optional()
10826
+ }),
10827
+ object({
10828
+ ...EventBase,
10829
+ type: literal("metric"),
10830
+ name: string(),
10831
+ value: number()
10832
+ }),
10833
+ object({
10834
+ ...EventBase,
10835
+ type: literal("artifact"),
10836
+ path: string(),
10837
+ bytes: number(),
10838
+ sha256: string()
10839
+ }),
10840
+ object({
10841
+ ...EventBase,
10842
+ type: literal("done"),
10843
+ status: _enum(["succeeded", "failed"]),
10844
+ resultSha256: string().nullable().optional()
10845
+ }),
10846
+ object({
10847
+ ...EventBase,
10848
+ type: literal("error"),
10849
+ stage: string(),
10850
+ code: string(),
10851
+ message: string()
10852
+ })
10853
+ ]);
10854
+ /**
10160
10855
  * What the gate decided about a birth, from the CALLER's point of view.
10161
10856
  *
10162
10857
  * Deliberately not `ConfirmationVerdict`: `undecided` is not a birth decision
@@ -12638,7 +13333,9 @@ var AddonHttpRouteSchema = object({
12638
13333
  "authenticated",
12639
13334
  "admin"
12640
13335
  ]).optional(),
12641
- description: string().optional()
13336
+ description: string().optional(),
13337
+ /** The hub limits this route per client address before the handler runs. */
13338
+ rateLimit: _enum(["auth"]).optional()
12642
13339
  });
12643
13340
  /**
12644
13341
  * Cross-process route invocation envelope. The hub captures the
@@ -13343,6 +14040,37 @@ var BackupDestinationInfoSchema = object({
13343
14040
  lastError: string().optional()
13344
14041
  });
13345
14042
  /**
14043
+ * How an archive is encrypted (operator decision 2026-10-09): to a backup
14044
+ * PUBLIC key the hub holds, so only the operator's secret key opens it.
14045
+ * Absent on a plain `.tar.gz` — every archive made before encryption, or
14046
+ * with it off — which restores without a key.
14047
+ */
14048
+ var BackupArchiveEncryptionSchema = object({
14049
+ /** `x25519-hkdf-aes256gcm-stream-v1`. */
14050
+ scheme: string(),
14051
+ /** 16 hex — the backup key whose secret restores this archive. */
14052
+ keyId: string()
14053
+ });
14054
+ /**
14055
+ * The backup encryption setting. The hub keeps PUBLIC keys only: the active
14056
+ * one new archives are encrypted to, and the retired ones older archives
14057
+ * still need. The secret key is shown once, at `setupEncryption`.
14058
+ */
14059
+ var BackupEncryptionStatusSchema = object({
14060
+ enabled: boolean(),
14061
+ active: object({
14062
+ keyId: string(),
14063
+ publicKey: string(),
14064
+ createdAt: number()
14065
+ }).nullable(),
14066
+ /** Every key ever set up, newest first. */
14067
+ keys: array(object({
14068
+ keyId: string(),
14069
+ createdAt: number(),
14070
+ retiredAt: number().nullable()
14071
+ })).readonly()
14072
+ });
14073
+ /**
13346
14074
  * Per-archive entry returned by `backup.listArchives({ destinationId })`.
13347
14075
  * Same shape the destination drill-in renders. Sourced from the per-
13348
14076
  * location `manifests.json` (no per-archive tarball read required).
@@ -13354,7 +14082,9 @@ var BackupArchiveEntrySchema = object({
13354
14082
  sizeBytes: number(),
13355
14083
  label: string().optional(),
13356
14084
  /** Top-level locations included in the archive (db, addons, tls, …). */
13357
- locations: array(string()).readonly()
14085
+ locations: array(string()).readonly(),
14086
+ /** Present when the archive is encrypted; restore then needs that key. */
14087
+ encryption: BackupArchiveEncryptionSchema.optional()
13358
14088
  });
13359
14089
  var BackupEntrySchema = object({
13360
14090
  id: string(),
@@ -13363,7 +14093,8 @@ var BackupEntrySchema = object({
13363
14093
  label: string().optional(),
13364
14094
  createdAt: number(),
13365
14095
  sizeBytes: number(),
13366
- locations: array(string()).optional()
14096
+ locations: array(string()).optional(),
14097
+ encryption: BackupArchiveEncryptionSchema.optional()
13367
14098
  });
13368
14099
  var ArchiveEntrySchema = object({
13369
14100
  path: string(),
@@ -13552,10 +14283,40 @@ method(_void(), array(BackupDestinationInfoSchema).readonly(), { auth: "admin" }
13552
14283
  * this list and skips entries whose path doesn't start with
13553
14284
  * any of them.
13554
14285
  */
13555
- locations: array(string()).optional()
14286
+ locations: array(string()).optional(),
14287
+ /**
14288
+ * The backup SECRET key, for an encrypted archive (ignored for a plain
14289
+ * one). The archive is decrypted into the hub's private staging
14290
+ * before the restart; the key is not stored. A wrong or missing key
14291
+ * is refused before the archive is downloaded.
14292
+ */
14293
+ backupSecretKey: string().optional()
13556
14294
  }), _void(), {
13557
14295
  kind: "mutation",
13558
14296
  auth: "admin"
14297
+ }), method(_void(), BackupEncryptionStatusSchema, { auth: "admin" }), method(object({}), object({
14298
+ keyId: string(),
14299
+ secretKey: string(),
14300
+ publicKey: string(),
14301
+ createdAt: number(),
14302
+ replacedKeyId: string().nullable()
14303
+ }), {
14304
+ kind: "mutation",
14305
+ auth: "admin"
14306
+ }), method(object({}), object({ disabledKeyId: string().nullable() }), {
14307
+ kind: "mutation",
14308
+ auth: "admin"
14309
+ }), method(object({ backupSecretKey: string() }), object({
14310
+ valid: boolean(),
14311
+ keyId: string().nullable(),
14312
+ /** The hub knows this key (active or retired). */
14313
+ known: boolean(),
14314
+ /** It is the key new archives are encrypted to. */
14315
+ active: boolean(),
14316
+ error: string().optional()
14317
+ }), {
14318
+ kind: "mutation",
14319
+ auth: "admin"
13559
14320
  }), method(object({
13560
14321
  destinationId: string(),
13561
14322
  backupId: string()
@@ -15179,7 +15940,60 @@ var CustomModelDescriptorSchema = object({
15179
15940
  stepId: string(),
15180
15941
  entry: ModelCatalogEntrySchema
15181
15942
  });
15182
- method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" });
15943
+ /** One regular file of an imported bundle, as the producer measured it. */
15944
+ var ModelBundleFileSchema = object({
15945
+ /** Relative path inside the bundle tar; an mlpackage member is `<x>.mlpackage/<member>`. */
15946
+ path: string().min(1),
15947
+ bytes: number().int().nonnegative(),
15948
+ sha256: string().regex(/^[0-9a-f]{64}$/)
15949
+ });
15950
+ var ImportModelBundleInputSchema = object({
15951
+ /** The registry provider that keeps the model (Model Studio). */
15952
+ addonId: string(),
15953
+ stepId: string().min(1),
15954
+ /**
15955
+ * The catalog rows to register, complete, every format URL already
15956
+ * `camstack-local://<modelId>/<file>` naming a file of the bundle. One
15957
+ * bundle may carry several rows (a base and its INT8 variant).
15958
+ */
15959
+ entries: array(ModelCatalogEntrySchema).min(1).max(4),
15960
+ /** The bundle tar, offered by the producer over `ctx.peerBytes` (same host). */
15961
+ bundle: object({
15962
+ ticket: PeerBytesTicketSchema,
15963
+ bytes: number().int().positive(),
15964
+ sha256: string().regex(/^[0-9a-f]{64}$/)
15965
+ }),
15966
+ /** Every file the tar must hold; anything missing, extra or different is refused. */
15967
+ files: array(ModelBundleFileSchema).min(1).max(64),
15968
+ /** Convert missing engine formats and push the model to every agent afterwards. */
15969
+ distribute: boolean()
15970
+ });
15971
+ var ImportModelBundleResultSchema = discriminatedUnion("kind", [object({
15972
+ kind: literal("imported"),
15973
+ modelIds: array(string()).readonly(),
15974
+ distributed: array(object({
15975
+ modelId: string(),
15976
+ nodeId: string(),
15977
+ format: _enum(MODEL_FORMATS),
15978
+ ok: boolean(),
15979
+ error: string().optional()
15980
+ })).readonly()
15981
+ }), object({
15982
+ kind: literal("refused"),
15983
+ reason: _enum([
15984
+ "transfer-failed",
15985
+ "checksum-mismatch",
15986
+ "bundle-mismatch",
15987
+ "invalid-entry",
15988
+ "id-taken"
15989
+ ]),
15990
+ detail: string()
15991
+ })]);
15992
+ method(_void(), array(CustomModelDescriptorSchema).readonly(), { auth: "admin" }), method(ImportModelBundleInputSchema, ImportModelBundleResultSchema, {
15993
+ kind: "mutation",
15994
+ auth: "admin",
15995
+ timeoutMs: 30 * 6e4
15996
+ });
15183
15997
  /**
15184
15998
  * Query filter for settings-store collections.
15185
15999
  */
@@ -15658,6 +16472,35 @@ var KeychainKeySourceSchema = object({
15658
16472
  */
15659
16473
  sharesBackupWithDatabase: boolean()
15660
16474
  });
16475
+ /**
16476
+ * One keychain reset, as the Secrets page reports it until the operator
16477
+ * acknowledges it. Never a value: refs, counts and table names only.
16478
+ */
16479
+ var KeychainResetRecordSchema = object({
16480
+ id: string(),
16481
+ at: number(),
16482
+ /** `user:<id>` or {@link KEYCHAIN_RESET_TRIGGER_ACTOR}. */
16483
+ actor: string(),
16484
+ /** Why the keychain was locked when it was reset; `null` when it was not locked. */
16485
+ lockedReason: string().nullable(),
16486
+ /** Values moved into the archive table (ciphertext under the lost key). */
16487
+ archived: number().int(),
16488
+ /** `keychain:secrets-orphaned-<ts>`, or `null` when nothing was stored. */
16489
+ archivedCollection: string().nullable(),
16490
+ /**
16491
+ * `keychain:keys-orphaned-<ts>`: the wrapped data keys of the archive, kept
16492
+ * so the archive can still be opened if the lost master key turns up.
16493
+ */
16494
+ archivedKeysCollection: string().nullable(),
16495
+ /**
16496
+ * `system-settings` keys whose marker the reset cleared — the cluster
16497
+ * secret's: a marker left pointing at an archived value would refuse every
16498
+ * agent forever (D797).
16499
+ */
16500
+ clearedSettingsKeys: array(string()).readonly(),
16501
+ /** When an operator dismissed the notice on the Secrets page; `null` until then. */
16502
+ acknowledgedAt: number().nullable()
16503
+ });
15661
16504
  var KeychainStatusSchema = object({
15662
16505
  keychain: KeychainStateSchema,
15663
16506
  /** The source of the master key in use; `null` while locked. */
@@ -15675,7 +16518,9 @@ var KeychainStatusSchema = object({
15675
16518
  /** Wrapped copies of the data key under a previous master key, kept until purged. */
15676
16519
  retiredWraps: number().int(),
15677
16520
  recoveryKeyDownloadedAt: number().nullable(),
15678
- secretCount: number().int()
16521
+ secretCount: number().int(),
16522
+ /** The most recent reset, acknowledged or not; `null` when the keychain was never reset. */
16523
+ lastReset: KeychainResetRecordSchema.nullable()
15679
16524
  });
15680
16525
  /**
15681
16526
  * Whether a stored value is still pointed at by its owner's settings.
@@ -15697,17 +16542,26 @@ var KeychainAuditActionSchema = _enum([
15697
16542
  "download-recovery-key",
15698
16543
  "delete-orphans",
15699
16544
  "reset",
16545
+ "acknowledge-reset",
15700
16546
  "initialize"
15701
16547
  ]);
15702
16548
  var KeychainAuditEntrySchema = object({
15703
16549
  id: string(),
15704
16550
  at: number(),
15705
16551
  action: KeychainAuditActionSchema,
15706
- /** `addon:<id>` | `user:<id>` | `system`. */
16552
+ /** `addon:<id>` | `user:<id>` | `system` | `trigger-file`. */
15707
16553
  actor: string(),
15708
16554
  ref: string().nullable(),
15709
16555
  detail: string().nullable()
15710
16556
  });
16557
+ var KEYCHAIN_RESET_CONFIRMATION = "RESET KEYCHAIN";
16558
+ /**
16559
+ * Secrets the HUB itself holds (owner `system`) that no settings form shows:
16560
+ * `jwt-signing-key` — the session signing key (D797). It is always "in use",
16561
+ * never an orphan; it is generated on a fresh hub and replaced only through
16562
+ * {@link keychainAdminCapability.methods.setSystemSecret}.
16563
+ */
16564
+ var SystemHeldSecretNameSchema = _enum(["jwt-signing-key"]);
15711
16565
  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().min(1) }), object({
15712
16566
  value: string(),
15713
16567
  version: number().int()
@@ -15715,6 +16569,16 @@ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}),
15715
16569
  kind: "mutation",
15716
16570
  auth: "admin",
15717
16571
  caller: "required"
16572
+ }), method(object({
16573
+ name: SystemHeldSecretNameSchema,
16574
+ value: string().min(16)
16575
+ }), object({
16576
+ ref: string(),
16577
+ version: number().int()
16578
+ }), {
16579
+ kind: "mutation",
16580
+ auth: "admin",
16581
+ caller: "required"
15718
16582
  }), method(object({ refs: array(string().min(1)).max(1e3) }), object({
15719
16583
  deleted: array(string()).readonly(),
15720
16584
  kept: array(object({
@@ -15744,13 +16608,20 @@ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}),
15744
16608
  kind: "mutation",
15745
16609
  auth: "admin",
15746
16610
  caller: "required"
15747
- }), method(object({ confirm: literal("RESET KEYCHAIN") }), object({
16611
+ }), method(object({ confirm: literal(KEYCHAIN_RESET_CONFIRMATION) }), object({
15748
16612
  archivedCollection: string().nullable(),
15749
16613
  archived: number().int()
15750
16614
  }), {
15751
16615
  kind: "mutation",
15752
16616
  auth: "admin",
15753
16617
  caller: "required"
16618
+ }), method(object({}), object({
16619
+ reset: KeychainResetRecordSchema.nullable(),
16620
+ pendingReentry: array(KeychainSecretMetaSchema).readonly()
16621
+ }), { auth: "admin" }), method(object({}), object({ acknowledged: boolean() }), {
16622
+ kind: "mutation",
16623
+ auth: "admin",
16624
+ caller: "required"
15754
16625
  });
15755
16626
  /**
15756
16627
  * Stable UI option list for the `hwaccel` setting. Decoder addons
@@ -18477,7 +19348,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18477
19348
  * `login-method` — collection cap through which auth addons contribute
18478
19349
  * their pre-auth login surfaces to the login page. This is the SINGLE,
18479
19350
  * generic mechanism that supersedes the dead `auth.listProviders` reader:
18480
- * every auth addon (OIDC, magic-link, WebAuthn/passkey) registers a
19351
+ * every auth addon (OIDC, WebAuthn/passkey) registers a
18481
19352
  * `login-method` provider and the PUBLIC `auth.listLoginMethods`
18482
19353
  * procedure aggregates them for the unauthenticated login page.
18483
19354
  *
@@ -18485,8 +19356,7 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18485
19356
  *
18486
19357
  * - `redirect` — a declarative button. The login page renders a generic
18487
19358
  * button that navigates to `startUrl` (an addon-owned HTTP route).
18488
- * Covers OIDC (`/addon/auth-oidc/<id>/start`) and magic-link with
18489
- * ZERO shell-side JS. A future SSO addon plugs in the same way — the
19359
+ * Covers OIDC (`/addon/auth-oidc/<id>/start`) with ZERO shell-side JS. A future SSO addon plugs in the same way — the
18490
19360
  * login page needs NO change.
18491
19361
  *
18492
19362
  * - `widget` — a Module-Federation widget the login page mounts (via
@@ -18505,8 +19375,8 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
18505
19375
  * decision.
18506
19376
  *
18507
19377
  * Every contribution carries a `stage`:
18508
- * - `primary` — shown on the first credentials screen (OIDC /
18509
- * magic-link buttons; a future usernameless passkey).
19378
+ * - `primary` — shown on the first credentials screen (OIDC
19379
+ * buttons; a usernameless passkey).
18510
19380
  * - `second-factor` — shown AFTER the password leg, gated on the
18511
19381
  * returned `factors` (passkey-as-2FA today).
18512
19382
  *
@@ -18533,7 +19403,7 @@ var LoginMethodContributionSchema = discriminatedUnion("kind", [
18533
19403
  * The provider names an external identity a signed-in user can link to
18534
19404
  * their own account (D782): `auth.listLinkableProviders` /
18535
19405
  * `beginExternalLink` offer exactly the redirect methods that set this,
18536
- * whatever their id. Absent / false — a login button only (magic-link).
19406
+ * whatever their id. Absent / false — a login button only.
18537
19407
  */
18538
19408
  linkable: boolean().optional()
18539
19409
  }),
@@ -22350,8 +23220,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
22350
23220
  * `super_admin` — collapsed onto the single boolean because every
22351
23221
  * non-admin caller is governed by the same scope-check rules; the
22352
23222
  * distinction was only ever used to route role-specific procedures
22353
- * which we no longer have. Agents are admin sessions issued via
22354
- * `createServiceToken`; CLI / webhook integrations are `cst_*` tokens
23223
+ * which we no longer have. CLI / webhook integrations are `cst_*` tokens
22355
23224
  * with `isAdmin: false` + an explicit scope list.
22356
23225
  */
22357
23226
  /** Per-method access flavour. Materialised on every cap method via codegen. */
@@ -24026,6 +24895,9 @@ var RetrainExportFilterSchema = object({
24026
24895
  frameIds: array(string()).max(2e4).optional(),
24027
24896
  /** Only frames in at least one of these named collections. */
24028
24897
  collectionIds: array(string()).max(200).optional(),
24898
+ /** Exactly the frames of this dataset version (and its completeOnly). An
24899
+ * unknown id selects nothing. */
24900
+ datasetVersionId: string().optional(),
24029
24901
  batchId: string().optional(),
24030
24902
  /** Only frames the operator marked complete (all subjects boxed). */
24031
24903
  completeOnly: boolean().optional()
@@ -24193,6 +25065,67 @@ var RetrainLlmAssistResultSchema = discriminatedUnion("kind", [object({
24193
25065
  ]),
24194
25066
  detail: string().optional()
24195
25067
  })]);
25068
+ /** What a dataset version is cut from. Every field narrows. */
25069
+ var RetrainDatasetSelectionSchema = object({
25070
+ deviceIds: array(number()).readonly().optional(),
25071
+ collectionIds: array(string()).max(200).readonly().optional(),
25072
+ frameIds: array(string()).max(2e4).readonly().optional()
25073
+ });
25074
+ /** The counts a dataset is judged by. */
25075
+ var RetrainDatasetStatsSchema = object({
25076
+ frames: number().int(),
25077
+ completeFrames: number().int(),
25078
+ /** `completeFrames / frames`, 0..1. */
25079
+ completeness: number(),
25080
+ /** Boxes to learn (model errors excluded). */
25081
+ subjects: number().int(),
25082
+ modelErrors: number().int(),
25083
+ /** Complete frames with no subject. */
25084
+ hardNegatives: number().int(),
25085
+ /** Subjects per class × camera × day/night. */
25086
+ cells: array(object({
25087
+ macroClass: string(),
25088
+ deviceId: number(),
25089
+ lighting: _enum([
25090
+ "day",
25091
+ "night",
25092
+ "unknown"
25093
+ ]),
25094
+ subjects: number().int(),
25095
+ frames: number().int()
25096
+ })).readonly(),
25097
+ cameras: array(object({
25098
+ deviceId: number(),
25099
+ frames: number().int(),
25100
+ completeFrames: number().int()
25101
+ })).readonly()
25102
+ });
25103
+ /** An immutable dataset version, without its frame list. */
25104
+ var RetrainDatasetVersionSchema = object({
25105
+ id: string(),
25106
+ name: string(),
25107
+ createdAt: number(),
25108
+ selection: RetrainDatasetSelectionSchema,
25109
+ layout: RetrainExportLayoutSchema,
25110
+ completeOnly: boolean(),
25111
+ frameCount: number().int(),
25112
+ /** sha256 of what the frames taught when the version was frozen. */
25113
+ annotationHash: string(),
25114
+ /** The export manifest schema the version was cut under. */
25115
+ manifestSchema: string(),
25116
+ stats: RetrainDatasetStatsSchema
25117
+ });
25118
+ var CreateRetrainDatasetVersionResultSchema = discriminatedUnion("kind", [object({
25119
+ kind: literal("created"),
25120
+ version: RetrainDatasetVersionSchema
25121
+ }), object({
25122
+ kind: literal("refused"),
25123
+ reason: _enum([
25124
+ "empty-name",
25125
+ "duplicate-name",
25126
+ "no-frames"
25127
+ ])
25128
+ })]);
24196
25129
  /** The outcome of a lifecycle move owned by the retrain page. */
24197
25130
  var RetrainTransitionResultSchema = object({
24198
25131
  trackId: string(),
@@ -24982,6 +25915,47 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
24982
25915
  kind: "mutation",
24983
25916
  auth: "admin",
24984
25917
  timeoutMs: 60 * 6e4
25918
+ }), method(object({
25919
+ filter: RetrainExportFilterSchema,
25920
+ layout: RetrainExportLayoutSchema
25921
+ }), object({
25922
+ ticket: PeerBytesTicketSchema,
25923
+ frames: number().int(),
25924
+ annotations: number().int()
25925
+ }), {
25926
+ kind: "mutation",
25927
+ auth: "admin",
25928
+ timeoutMs: 12e4
25929
+ }), method(object({
25930
+ selection: RetrainDatasetSelectionSchema,
25931
+ completeOnly: boolean().optional()
25932
+ }), RetrainDatasetStatsSchema, {
25933
+ kind: "query",
25934
+ auth: "admin"
25935
+ }), method(object({
25936
+ name: string().max(120),
25937
+ selection: RetrainDatasetSelectionSchema,
25938
+ layout: RetrainExportLayoutSchema,
25939
+ completeOnly: boolean()
25940
+ }), CreateRetrainDatasetVersionResultSchema, {
25941
+ kind: "mutation",
25942
+ auth: "admin",
25943
+ timeoutMs: 12e4
25944
+ }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), {
25945
+ kind: "query",
25946
+ auth: "admin"
25947
+ }), method(object({ id: string() }), object({ deleted: boolean() }), {
25948
+ kind: "mutation",
25949
+ auth: "admin"
25950
+ }), method(object({ id: string() }), object({
25951
+ found: boolean(),
25952
+ annotationHash: string(),
25953
+ matches: boolean(),
25954
+ missingFrames: number().int()
25955
+ }), {
25956
+ kind: "query",
25957
+ auth: "admin",
25958
+ timeoutMs: 12e4
24985
25959
  }), method(object({}), array(RetrainAssistProfileSchema).readonly(), {
24986
25960
  kind: "query",
24987
25961
  auth: "admin"
@@ -28520,8 +29494,8 @@ version: string().optional() }), ServerUpdateActionResultSchema, {
28520
29494
  * `smtp-provider` — pluggable email delivery surface.
28521
29495
  *
28522
29496
  * Collection cap: a deployment may install multiple SMTP relays (e.g.
28523
- * one for transactional / one for notifications). Consumers (magic-link,
28524
- * notifier addons, …) walk the collection and pick the first
29497
+ * one for transactional / one for notifications). Consumers (notifier
29498
+ * addons, …) walk the collection and pick the first
28525
29499
  * ready provider OR target a specific addonId.
28526
29500
  *
28527
29501
  * The shape stays small on purpose — `sendEmail` is enough for the
@@ -28700,7 +29674,7 @@ targets: array(object({
28700
29674
  })));
28701
29675
  /**
28702
29676
  * `sso-bridge` — internal hub-only cap that lets SSO-style auth
28703
- * providers (OIDC, SAML, magic-link, …) mint an HMAC-signed token
29677
+ * providers (OIDC, SAML, …) mint an HMAC-signed token
28704
29678
  * carrying the post-callback claims before redirecting back to
28705
29679
  * `/api/auth/sso/finish`.
28706
29680
  *
@@ -28763,7 +29737,14 @@ var SsoBridgeClaimsSchema = object({
28763
29737
  * Verified `iss` of the id_token behind an OIDC login bridge (D782). A
28764
29738
  * subject is unique only per issuer, so a link is bound to it.
28765
29739
  */
28766
- issuer: string().optional()
29740
+ issuer: string().optional(),
29741
+ /**
29742
+ * SHA-256 (hex) of the `camstack_sso_state` cookie the IdP `/start` set in
29743
+ * the browser that began this sign-in. `/api/auth/sso/finish` requires the
29744
+ * request to present the matching cookie — a login bridge is useless in
29745
+ * any other browser.
29746
+ */
29747
+ browserBinding: string().optional()
28767
29748
  });
28768
29749
  method(object({
28769
29750
  claims: SsoBridgeClaimsSchema,
@@ -38937,16 +39918,6 @@ var ApiKeySummarySchema = object({
38937
39918
  createdAt: number(),
38938
39919
  lastUsedAt: number().optional()
38939
39920
  });
38940
- var CreateApiKeyInputSchema = object({
38941
- label: string(),
38942
- isAdmin: boolean().default(false),
38943
- allowedProviders: union([array(string()), literal("*")]).optional(),
38944
- allowedDevices: record(string(), union([array(string()), literal("*")])).optional()
38945
- });
38946
- var CreateApiKeyResultSchema = object({
38947
- token: string(),
38948
- record: ApiKeySummarySchema
38949
- });
38950
39921
  var ScopedTokenSummarySchema = object({
38951
39922
  id: string(),
38952
39923
  userId: string(),
@@ -39045,17 +40016,10 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
39045
40016
  }), UserSummarySchema.extend({ passwordHash: string() }).nullable(), {
39046
40017
  kind: "mutation",
39047
40018
  access: "view"
39048
- }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(CreateApiKeyInputSchema, CreateApiKeyResultSchema, {
39049
- kind: "mutation",
39050
- auth: "admin",
39051
- access: "create"
39052
- }), method(object({ id: string() }), object({ success: literal(true) }), {
40019
+ }), method(_void(), array(ApiKeySummarySchema), { auth: "admin" }), method(object({ id: string() }), object({ success: literal(true) }), {
39053
40020
  kind: "mutation",
39054
40021
  auth: "admin",
39055
40022
  access: "delete"
39056
- }), method(object({ token: string() }), ApiKeySummarySchema.nullable(), {
39057
- kind: "mutation",
39058
- access: "view"
39059
40023
  }), method(CreateScopedTokenInputSchema, CreateScopedTokenResultSchema, {
39060
40024
  kind: "mutation",
39061
40025
  auth: "admin",
@@ -39129,15 +40093,7 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserI
39129
40093
  }).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
39130
40094
  userId: string(),
39131
40095
  issuer: string()
39132
- }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({
39133
- userId: string(),
39134
- issuer: string().min(1),
39135
- label: string().optional()
39136
- }), object({ success: literal(true) }), {
39137
- kind: "mutation",
39138
- auth: "admin",
39139
- access: "create"
39140
- }), method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
40096
+ }).nullable(), { auth: "admin" }), method(ExternalIdentityKeySchema.extend({ userId: string() }), object({ success: boolean() }), {
39141
40097
  kind: "mutation",
39142
40098
  auth: "admin",
39143
40099
  access: "delete"
@@ -39532,6 +40488,451 @@ DeviceType.Camera, method(object({
39532
40488
  detection: array(ZoneRuleSchema).readonly(),
39533
40489
  package: array(ZoneRuleSchema).readonly()
39534
40490
  });
40491
+ /**
40492
+ * `training-provider` — ONE cloud that can run the CamStack trainer.
40493
+ *
40494
+ * A thin, mockable translation layer: it knows how to run a container with a
40495
+ * GPU, move a dataset in, read the job's stdout and hand artefacts back. It
40496
+ * knows nothing about datasets, splits, floors, cost policy or Model Studio —
40497
+ * those are the `training` orchestrator's (D805). Every rule written there
40498
+ * once is what makes a second provider (RunPod, a local NVIDIA node) a new
40499
+ * manifest entry and nothing else.
40500
+ *
40501
+ * Collection, routed by the `addonId` in every single-row input (the `llm` /
40502
+ * `notification-output` posture); `describe` concat-fans across providers.
40503
+ * Every method is `admin`: these spend money.
40504
+ *
40505
+ * Every cloud object a provider creates is tagged with the orchestrator's
40506
+ * `jobKey`, so a retried submit finds the job it already started instead of
40507
+ * starting a second GPU, and `listJobs` can find orphans.
40508
+ *
40509
+ * Bytes never ride a cap field: the dataset arrives as a `ctx.peerBytes`
40510
+ * ticket the producer (pipeline-analytics) minted, and artefacts leave as a
40511
+ * ticket the provider mints (D613).
40512
+ */
40513
+ var TrainingGpuOptionSchema = object({
40514
+ id: string(),
40515
+ label: string(),
40516
+ /** List price, USD per GPU-hour, before any region multiplier. */
40517
+ usdPerHour: number().nonnegative(),
40518
+ vramGb: number().nonnegative()
40519
+ });
40520
+ var TrainingRegionOptionSchema = object({
40521
+ /** `''` = any region (the provider's choice). */
40522
+ id: string(),
40523
+ label: string(),
40524
+ priceMultiplier: number().positive()
40525
+ });
40526
+ /**
40527
+ * The provider's per-account settings, as the orchestrator reads them. They
40528
+ * live in the PROVIDER addon's settings (operator decision 2026-10-08: they
40529
+ * depend on the user's account), never hard-coded in the orchestrator.
40530
+ */
40531
+ var TrainingProviderDefaultsSchema = object({
40532
+ gpuType: string(),
40533
+ region: string(),
40534
+ costCapUsd: number().nonnegative(),
40535
+ maxRuntimeSec: number().int().positive(),
40536
+ /** Hours a FAILED job's cloud dataset is kept for debugging; 0 = delete at once. */
40537
+ failedDatasetGraceHours: number().nonnegative()
40538
+ });
40539
+ var TrainingProviderDescriptorSchema = object({
40540
+ addonId: string(),
40541
+ /** `modal`, `runpod`, `fake`, … */
40542
+ kind: string(),
40543
+ label: string(),
40544
+ gpuTypes: array(TrainingGpuOptionSchema).readonly(),
40545
+ regions: array(TrainingRegionOptionSchema).readonly(),
40546
+ maxDatasetBytes: number().int().positive(),
40547
+ maxRuntimeSec: number().int().positive(),
40548
+ freeTierNote: string().optional(),
40549
+ /** Where the data goes, in one sentence the confirm dialog repeats. */
40550
+ dataResidencyNote: string(),
40551
+ /** Credentials are present — never the values. */
40552
+ configured: boolean(),
40553
+ defaults: TrainingProviderDefaultsSchema
40554
+ });
40555
+ var TrainingCredentialCheckSchema = object({
40556
+ ok: boolean(),
40557
+ /** Workspace / account name, when the provider says. */
40558
+ account: string().optional(),
40559
+ reason: _enum([
40560
+ "missing",
40561
+ "invalid",
40562
+ "forbidden",
40563
+ "network",
40564
+ "quota"
40565
+ ]).optional(),
40566
+ detail: string().optional()
40567
+ });
40568
+ var ProviderJobStateSchema = _enum([
40569
+ "pending",
40570
+ "starting",
40571
+ "running",
40572
+ "succeeded",
40573
+ "failed",
40574
+ "cancelled",
40575
+ "lost"
40576
+ ]);
40577
+ var ProviderJobStatusSchema = object({
40578
+ jobKey: string(),
40579
+ providerJobId: string().optional(),
40580
+ state: ProviderJobStateSchema,
40581
+ startedAt: number().optional(),
40582
+ endedAt: number().optional(),
40583
+ exitCode: number().int().optional(),
40584
+ failureReason: string().optional(),
40585
+ gpuType: string(),
40586
+ region: string().optional(),
40587
+ billedSeconds: number().nonnegative(),
40588
+ costUsd: number().nonnegative(),
40589
+ /** True when `costUsd` is runtime × list price, not a billing answer. */
40590
+ costIsEstimate: boolean(),
40591
+ lastFetchedAt: number()
40592
+ });
40593
+ /**
40594
+ * The trainer the job runs, by SOURCE revision: the provider turns it into an
40595
+ * image its own way (Modal builds the published Dockerfile at that revision;
40596
+ * a registry-pull provider maps it to a tag). Recorded on the job and echoed
40597
+ * in `result.json`.
40598
+ */
40599
+ var TrainerSourceRefSchema = object({
40600
+ /** Hugging Face repo id, e.g. `camstack/camstack-trainer`. */
40601
+ repo: string().min(1),
40602
+ /** A commit sha (never a branch) — the job must be reproducible. */
40603
+ revision: string().regex(/^[0-9a-f]{7,64}$/)
40604
+ });
40605
+ var JobRef = {
40606
+ addonId: string(),
40607
+ jobKey: string().uuid()
40608
+ };
40609
+ var TrainingLogLineSchema = object({
40610
+ ts: number(),
40611
+ text: string()
40612
+ });
40613
+ method(object({}), array(TrainingProviderDescriptorSchema).readonly(), { auth: "admin" }), method(object({ addonId: string() }), TrainingCredentialCheckSchema, {
40614
+ kind: "mutation",
40615
+ auth: "admin",
40616
+ timeoutMs: 3e4
40617
+ }), method(object({
40618
+ addonId: string(),
40619
+ gpuType: string(),
40620
+ region: string(),
40621
+ datasetBytes: number().int().nonnegative(),
40622
+ gpuSecondsLow: number().nonnegative(),
40623
+ gpuSecondsHigh: number().nonnegative()
40624
+ }), object({
40625
+ usdLow: number().nonnegative(),
40626
+ usdHigh: number().nonnegative(),
40627
+ notes: array(string()).readonly()
40628
+ }), { auth: "admin" }), method(object({
40629
+ ...JobRef,
40630
+ ticket: PeerBytesTicketSchema
40631
+ }), object({
40632
+ bytes: number().int().nonnegative(),
40633
+ sha256: string()
40634
+ }), {
40635
+ kind: "mutation",
40636
+ auth: "admin",
40637
+ timeoutMs: 120 * 6e4
40638
+ }), method(object({
40639
+ ...JobRef,
40640
+ trainer: TrainerSourceRefSchema,
40641
+ jobSpecJson: string().min(2).max(64e3),
40642
+ gpuType: string(),
40643
+ region: string(),
40644
+ maxRuntimeSec: number().int().positive()
40645
+ }), ProviderJobStatusSchema, {
40646
+ kind: "mutation",
40647
+ auth: "admin",
40648
+ timeoutMs: 30 * 6e4
40649
+ }), method(object(JobRef), ProviderJobStatusSchema, {
40650
+ auth: "admin",
40651
+ timeoutMs: 6e4
40652
+ }), method(object({
40653
+ ...JobRef,
40654
+ cursor: string().optional(),
40655
+ max: number().int().min(1).max(500)
40656
+ }), object({
40657
+ lines: array(TrainingLogLineSchema).readonly(),
40658
+ cursor: string()
40659
+ }), {
40660
+ auth: "admin",
40661
+ timeoutMs: 6e4
40662
+ }), method(object(JobRef), object({ ok: literal(true) }), {
40663
+ kind: "mutation",
40664
+ auth: "admin",
40665
+ timeoutMs: 6e4
40666
+ }), method(object(JobRef), object({
40667
+ found: boolean(),
40668
+ text: string().optional()
40669
+ }), {
40670
+ kind: "mutation",
40671
+ auth: "admin",
40672
+ timeoutMs: 5 * 6e4
40673
+ }), method(object({
40674
+ ...JobRef,
40675
+ path: _enum(["bundle.tar"])
40676
+ }), object({ ticket: PeerBytesTicketSchema }), {
40677
+ kind: "mutation",
40678
+ auth: "admin",
40679
+ timeoutMs: 5 * 6e4
40680
+ }), method(object(JobRef), object({ deleted: array(string()).readonly() }), {
40681
+ kind: "mutation",
40682
+ auth: "admin",
40683
+ timeoutMs: 5 * 6e4
40684
+ }), method(object({ addonId: string() }), array(ProviderJobStatusSchema).readonly(), {
40685
+ auth: "admin",
40686
+ timeoutMs: 2 * 6e4
40687
+ });
40688
+ /**
40689
+ * `training` — the cloud-training orchestrator (D805). Hub-only singleton,
40690
+ * provided by `addon-training`.
40691
+ *
40692
+ * It owns what every provider must agree on, written once:
40693
+ *
40694
+ * - **Dataset versions.** Taken over from pipeline-analytics (D796): the rows
40695
+ * live here (D808); pipeline-analytics still CUTS a version (it owns the corpus and
40696
+ * the export plan) and reaches this store through the five row methods
40697
+ * below, so the Retrain page and the export did not change.
40698
+ * - **Jobs.** A persisted state machine, a reconcile loop against the
40699
+ * provider, a cost guard, a daily orphan sweep and the retention rules.
40700
+ * - **The return flow.** Verified artefacts → Model Studio
40701
+ * (`custom-model-registry.importModelBundle`) → canary on cameras →
40702
+ * rollback. Nothing is ever registered automatically.
40703
+ *
40704
+ * Every method is `admin`.
40705
+ */
40706
+ /** A version WITH its frame list — what the export and a job read. */
40707
+ var TrainingDatasetVersionRowSchema = RetrainDatasetVersionSchema.omit({ frameCount: true }).extend({ frameIds: array(string()).max(2e4).readonly() });
40708
+ /** A base model a detector job can fine-tune, and the baseline it is judged against. */
40709
+ var TrainingBaseModelSchema = object({
40710
+ modelId: string(),
40711
+ label: string(),
40712
+ weights: string(),
40713
+ imgsz: number().int(),
40714
+ baselineOnnxUrl: string(),
40715
+ baselineFloors: record(string(), number()),
40716
+ /** The base the fleet runs most — the UI's default. */
40717
+ recommended: boolean()
40718
+ });
40719
+ var TrainingPresetSchema = _enum([
40720
+ "quick",
40721
+ "standard",
40722
+ "thorough"
40723
+ ]);
40724
+ var TrainingJobRequestSchema = object({
40725
+ datasetVersionId: string().min(1),
40726
+ /** The `training-provider` addon that runs it. */
40727
+ addonId: string().min(1),
40728
+ gpuType: string().min(1),
40729
+ region: string(),
40730
+ baseModelId: string().min(1),
40731
+ preset: TrainingPresetSchema,
40732
+ /** Freeze the backbone's first N layers; `null` = the preset's choice. */
40733
+ freeze: number().int().nonnegative().nullable(),
40734
+ /** Cameras held out whole for evaluation; `null` = the orchestrator's default. */
40735
+ holdoutCameras: array(number().int()).nullable()
40736
+ });
40737
+ var TrainingSplitPlanSchema = object({
40738
+ holdoutCameras: array(number().int()).readonly(),
40739
+ /** Used when no camera is held out: the last N days of every camera. */
40740
+ holdoutLastDays: number().int().nonnegative(),
40741
+ /** Holdout subjects per class (camera holdout only; `null` = known only after the split). */
40742
+ holdoutSupport: record(string(), number().int()).nullable(),
40743
+ trainSubjects: number().int()
40744
+ });
40745
+ var TrainingRefusalReasonSchema = _enum([
40746
+ "unknown-dataset",
40747
+ "unknown-provider",
40748
+ "provider-not-configured",
40749
+ "unknown-base-model",
40750
+ "unknown-gpu",
40751
+ "dataset-too-large",
40752
+ "no-training-subjects",
40753
+ "job-already-running"
40754
+ ]);
40755
+ var TrainingJobPlanSchema = object({
40756
+ refusal: object({
40757
+ reason: TrainingRefusalReasonSchema,
40758
+ detail: string()
40759
+ }).nullable(),
40760
+ warnings: array(string()).readonly(),
40761
+ split: TrainingSplitPlanSchema.nullable(),
40762
+ estimate: object({
40763
+ datasetBytes: number().int(),
40764
+ uploadMinutesAt20Mbps: number(),
40765
+ gpuSecondsLow: number(),
40766
+ gpuSecondsHigh: number(),
40767
+ usdLow: number(),
40768
+ usdHigh: number(),
40769
+ notes: array(string()).readonly()
40770
+ }).nullable(),
40771
+ /** Pre-filled from the provider's settings; the operator may lower or raise them. */
40772
+ defaults: object({
40773
+ maxCostUsd: number(),
40774
+ maxRuntimeSec: number().int()
40775
+ }).nullable(),
40776
+ /** The sentence the confirm dialog repeats: where the frames go and when they are deleted. */
40777
+ dataNotice: string()
40778
+ });
40779
+ /**
40780
+ * Orchestrator-owned states, persisted. `uploading` covers exporting the
40781
+ * archive (it is streamed, never staged). Terminal: `failed`, `cancelled`,
40782
+ * `lost`, `expired`, `discarded`. `registered` and `canary` are where a
40783
+ * result lives after the operator acted on it.
40784
+ */
40785
+ var TrainingJobStateSchema = _enum([
40786
+ "uploading",
40787
+ "submitted",
40788
+ "starting",
40789
+ "running",
40790
+ "collecting",
40791
+ "ready",
40792
+ "registered",
40793
+ "canary",
40794
+ "failed",
40795
+ "cancelling",
40796
+ "cancelled",
40797
+ "lost",
40798
+ "expired",
40799
+ "discarded"
40800
+ ]);
40801
+ var TrainingFailureReasonSchema = _enum([
40802
+ "cost-cap",
40803
+ "runtime-cap",
40804
+ "upload-failed",
40805
+ "submit-failed",
40806
+ "trainer-failed",
40807
+ "result-invalid",
40808
+ "checksum-mismatch",
40809
+ "fetch-failed",
40810
+ "provider-error",
40811
+ "hub-restart-during-upload"
40812
+ ]);
40813
+ var TrainingProgressPointSchema = object({
40814
+ epoch: number().int(),
40815
+ map50: number().nullable(),
40816
+ map50_95: number().nullable()
40817
+ });
40818
+ var TrainingCanarySchema = object({
40819
+ deviceIds: array(number().int()).readonly(),
40820
+ since: number(),
40821
+ /** Every override the canary replaced, exactly, so rollback restores it. */
40822
+ previous: array(object({
40823
+ deviceId: number().int(),
40824
+ nodeId: string(),
40825
+ deviceKey: string(),
40826
+ patch: object({
40827
+ modelId: string().optional(),
40828
+ settings: record(string(), unknown()).readonly().optional()
40829
+ }).nullable()
40830
+ })).readonly()
40831
+ });
40832
+ var TrainingJobSchema = object({
40833
+ id: string(),
40834
+ idempotencyKey: string(),
40835
+ name: string(),
40836
+ createdAt: number(),
40837
+ updatedAt: number(),
40838
+ state: TrainingJobStateSchema,
40839
+ stage: TrainingStageSchema.nullable(),
40840
+ failure: object({
40841
+ reason: TrainingFailureReasonSchema,
40842
+ stage: string().nullable(),
40843
+ detail: string()
40844
+ }).nullable(),
40845
+ request: TrainingJobRequestSchema,
40846
+ maxCostUsd: number().nonnegative(),
40847
+ maxRuntimeSec: number().int().positive(),
40848
+ trainer: TrainerSourceRefSchema,
40849
+ datasetLayout: RetrainExportLayoutSchema,
40850
+ dataset: object({
40851
+ bytes: number().int(),
40852
+ sha256: string(),
40853
+ uploadedAt: number()
40854
+ }).nullable(),
40855
+ split: TrainingSplitPlanSchema,
40856
+ provider: object({
40857
+ state: ProviderJobStateSchema.nullable(),
40858
+ providerJobId: string().nullable(),
40859
+ startedAt: number().nullable(),
40860
+ endedAt: number().nullable(),
40861
+ billedSeconds: number(),
40862
+ costUsd: number(),
40863
+ costIsEstimate: boolean(),
40864
+ lastPolledAt: number().nullable()
40865
+ }),
40866
+ progress: object({
40867
+ epoch: number().int().nullable(),
40868
+ epochs: number().int().nullable(),
40869
+ etaSec: number().nullable(),
40870
+ series: array(TrainingProgressPointSchema).readonly()
40871
+ }),
40872
+ /** The last lines of the job's output (≤ 200), newest last. Never frame paths. */
40873
+ logTail: array(string()).readonly(),
40874
+ logCursor: string().nullable(),
40875
+ artifacts: object({
40876
+ bundleBytes: number().int(),
40877
+ bundleSha256: string(),
40878
+ fetchedAt: number(),
40879
+ /** When the staged artefacts are deleted from the hub. */
40880
+ expiresAt: number()
40881
+ }).nullable(),
40882
+ /** When the provider-side copy of the frames was deleted; null while it exists. */
40883
+ cloudDatasetDeletedAt: number().nullable(),
40884
+ /** A failed job's dataset is kept until then (the provider's grace), then deleted. */
40885
+ cloudCleanupDueAt: number().nullable(),
40886
+ /** Model ids registered from this job (base, and int8 when kept). */
40887
+ registeredModelIds: array(string()).readonly(),
40888
+ canary: TrainingCanarySchema.nullable()
40889
+ });
40890
+ var IdInput = object({ id: string().min(1) });
40891
+ method(TrainingDatasetVersionRowSchema, object({ stored: boolean() }), {
40892
+ kind: "mutation",
40893
+ auth: "admin"
40894
+ }), method(IdInput, TrainingDatasetVersionRowSchema.nullable(), { auth: "admin" }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), { auth: "admin" }), method(object({ name: string() }), object({ id: string().nullable() }), { auth: "admin" }), method(IdInput, object({ removed: boolean() }), {
40895
+ kind: "mutation",
40896
+ auth: "admin"
40897
+ }), method(object({}), array(TrainingBaseModelSchema).readonly(), { auth: "admin" }), method(TrainingJobRequestSchema, TrainingJobPlanSchema, {
40898
+ auth: "admin",
40899
+ timeoutMs: 6e4
40900
+ }), method(TrainingJobRequestSchema.extend({
40901
+ name: string().min(1).max(120),
40902
+ maxCostUsd: number().positive(),
40903
+ maxRuntimeSec: number().int().positive(),
40904
+ idempotencyKey: string().min(8).max(80)
40905
+ }), discriminatedUnion("kind", [object({
40906
+ kind: literal("started"),
40907
+ job: TrainingJobSchema
40908
+ }), object({
40909
+ kind: literal("refused"),
40910
+ reason: TrainingRefusalReasonSchema,
40911
+ detail: string()
40912
+ })]), {
40913
+ kind: "mutation",
40914
+ auth: "admin",
40915
+ timeoutMs: 12e4
40916
+ }), method(object({}), array(TrainingJobSchema).readonly(), { auth: "admin" }), method(IdInput, TrainingJobSchema.nullable(), { auth: "admin" }), method(IdInput, TrainingJobSchema, {
40917
+ kind: "mutation",
40918
+ auth: "admin",
40919
+ timeoutMs: 12e4
40920
+ }), method(IdInput, TrainingResultSchema.nullable(), { auth: "admin" }), method(IdInput.extend({ canaryDeviceIds: array(number().int()).readonly() }), TrainingJobSchema, {
40921
+ kind: "mutation",
40922
+ auth: "admin",
40923
+ timeoutMs: 30 * 6e4
40924
+ }), method(IdInput.extend({ deviceIds: array(number().int()).min(1).readonly() }), TrainingJobSchema, {
40925
+ kind: "mutation",
40926
+ auth: "admin",
40927
+ timeoutMs: 12e4
40928
+ }), method(IdInput, TrainingJobSchema, {
40929
+ kind: "mutation",
40930
+ auth: "admin",
40931
+ timeoutMs: 12e4
40932
+ }), method(IdInput, TrainingJobSchema, {
40933
+ kind: "mutation",
40934
+ auth: "admin"
40935
+ });
39535
40936
  SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
39536
40937
  Object.freeze({
39537
40938
  person: .5,
@@ -40155,6 +41556,12 @@ Object.freeze({
40155
41556
  addonId: null,
40156
41557
  access: "create"
40157
41558
  },
41559
+ "backup.checkBackupKey": {
41560
+ capName: "backup",
41561
+ capScope: "system",
41562
+ addonId: null,
41563
+ access: "create"
41564
+ },
40158
41565
  "backup.delete": {
40159
41566
  capName: "backup",
40160
41567
  capScope: "system",
@@ -40167,6 +41574,18 @@ Object.freeze({
40167
41574
  addonId: null,
40168
41575
  access: "delete"
40169
41576
  },
41577
+ "backup.disableEncryption": {
41578
+ capName: "backup",
41579
+ capScope: "system",
41580
+ addonId: null,
41581
+ access: "create"
41582
+ },
41583
+ "backup.getEncryption": {
41584
+ capName: "backup",
41585
+ capScope: "system",
41586
+ addonId: null,
41587
+ access: "view"
41588
+ },
40170
41589
  "backup.getEntries": {
40171
41590
  capName: "backup",
40172
41591
  capScope: "system",
@@ -40221,6 +41640,12 @@ Object.freeze({
40221
41640
  addonId: null,
40222
41641
  access: "create"
40223
41642
  },
41643
+ "backup.setupEncryption": {
41644
+ capName: "backup",
41645
+ capScope: "system",
41646
+ addonId: null,
41647
+ access: "create"
41648
+ },
40224
41649
  "backup.trigger": {
40225
41650
  capName: "backup",
40226
41651
  capScope: "system",
@@ -40773,6 +42198,12 @@ Object.freeze({
40773
42198
  addonId: null,
40774
42199
  access: "create"
40775
42200
  },
42201
+ "customModelRegistry.importModelBundle": {
42202
+ capName: "custom-model-registry",
42203
+ capScope: "system",
42204
+ addonId: null,
42205
+ access: "create"
42206
+ },
40776
42207
  "customModelRegistry.listModels": {
40777
42208
  capName: "custom-model-registry",
40778
42209
  capScope: "system",
@@ -42213,6 +43644,12 @@ Object.freeze({
42213
43644
  addonId: null,
42214
43645
  access: "view"
42215
43646
  },
43647
+ "keychainAdmin.acknowledgeReset": {
43648
+ capName: "keychain-admin",
43649
+ capScope: "system",
43650
+ addonId: null,
43651
+ access: "create"
43652
+ },
42216
43653
  "keychainAdmin.deleteOrphans": {
42217
43654
  capName: "keychain-admin",
42218
43655
  capScope: "system",
@@ -42249,6 +43686,12 @@ Object.freeze({
42249
43686
  addonId: null,
42250
43687
  access: "delete"
42251
43688
  },
43689
+ "keychainAdmin.resetReport": {
43690
+ capName: "keychain-admin",
43691
+ capScope: "system",
43692
+ addonId: null,
43693
+ access: "delete"
43694
+ },
42252
43695
  "keychainAdmin.reveal": {
42253
43696
  capName: "keychain-admin",
42254
43697
  capScope: "system",
@@ -42261,6 +43704,12 @@ Object.freeze({
42261
43704
  addonId: null,
42262
43705
  access: "create"
42263
43706
  },
43707
+ "keychainAdmin.setSystemSecret": {
43708
+ capName: "keychain-admin",
43709
+ capScope: "system",
43710
+ addonId: null,
43711
+ access: "create"
43712
+ },
42264
43713
  "keychainAdmin.status": {
42265
43714
  capName: "keychain-admin",
42266
43715
  capScope: "system",
@@ -43707,6 +45156,12 @@ Object.freeze({
43707
45156
  addonId: null,
43708
45157
  access: "create"
43709
45158
  },
45159
+ "pipelineAnalytics.createRetrainDatasetVersion": {
45160
+ capName: "pipeline-analytics",
45161
+ capScope: "device",
45162
+ addonId: null,
45163
+ access: "create"
45164
+ },
43710
45165
  "pipelineAnalytics.deleteDeviceEvents": {
43711
45166
  capName: "pipeline-analytics",
43712
45167
  capScope: "device",
@@ -43719,6 +45174,12 @@ Object.freeze({
43719
45174
  addonId: null,
43720
45175
  access: "delete"
43721
45176
  },
45177
+ "pipelineAnalytics.deleteRetrainDatasetVersion": {
45178
+ capName: "pipeline-analytics",
45179
+ capScope: "device",
45180
+ addonId: null,
45181
+ access: "delete"
45182
+ },
43722
45183
  "pipelineAnalytics.deleteTracks": {
43723
45184
  capName: "pipeline-analytics",
43724
45185
  capScope: "device",
@@ -43941,6 +45402,12 @@ Object.freeze({
43941
45402
  addonId: null,
43942
45403
  access: "view"
43943
45404
  },
45405
+ "pipelineAnalytics.listRetrainDatasetVersions": {
45406
+ capName: "pipeline-analytics",
45407
+ capScope: "device",
45408
+ addonId: null,
45409
+ access: "view"
45410
+ },
43944
45411
  "pipelineAnalytics.listRetrainFrames": {
43945
45412
  capName: "pipeline-analytics",
43946
45413
  capScope: "device",
@@ -43971,6 +45438,12 @@ Object.freeze({
43971
45438
  addonId: null,
43972
45439
  access: "view"
43973
45440
  },
45441
+ "pipelineAnalytics.offerRetrainArchive": {
45442
+ capName: "pipeline-analytics",
45443
+ capScope: "device",
45444
+ addonId: null,
45445
+ access: "create"
45446
+ },
43974
45447
  "pipelineAnalytics.ownersWithMedia": {
43975
45448
  capName: "pipeline-analytics",
43976
45449
  capScope: "device",
@@ -43983,6 +45456,12 @@ Object.freeze({
43983
45456
  addonId: null,
43984
45457
  access: "create"
43985
45458
  },
45459
+ "pipelineAnalytics.previewRetrainDataset": {
45460
+ capName: "pipeline-analytics",
45461
+ capScope: "device",
45462
+ addonId: null,
45463
+ access: "view"
45464
+ },
43986
45465
  "pipelineAnalytics.proposeRetrainAnnotations": {
43987
45466
  capName: "pipeline-analytics",
43988
45467
  capScope: "device",
@@ -44121,6 +45600,12 @@ Object.freeze({
44121
45600
  addonId: null,
44122
45601
  access: "create"
44123
45602
  },
45603
+ "pipelineAnalytics.verifyRetrainDatasetVersion": {
45604
+ capName: "pipeline-analytics",
45605
+ capScope: "device",
45606
+ addonId: null,
45607
+ access: "view"
45608
+ },
44124
45609
  "pipelineAnalytics.wipeAllAnalytics": {
44125
45610
  capName: "pipeline-analytics",
44126
45611
  capScope: "device",
@@ -46497,6 +47982,174 @@ Object.freeze({
46497
47982
  addonId: null,
46498
47983
  access: "view"
46499
47984
  },
47985
+ "training.canaryResult": {
47986
+ capName: "training",
47987
+ capScope: "system",
47988
+ addonId: null,
47989
+ access: "create"
47990
+ },
47991
+ "training.cancelJob": {
47992
+ capName: "training",
47993
+ capScope: "system",
47994
+ addonId: null,
47995
+ access: "create"
47996
+ },
47997
+ "training.discardResult": {
47998
+ capName: "training",
47999
+ capScope: "system",
48000
+ addonId: null,
48001
+ access: "create"
48002
+ },
48003
+ "training.findDatasetVersionIdByName": {
48004
+ capName: "training",
48005
+ capScope: "system",
48006
+ addonId: null,
48007
+ access: "view"
48008
+ },
48009
+ "training.getDatasetVersion": {
48010
+ capName: "training",
48011
+ capScope: "system",
48012
+ addonId: null,
48013
+ access: "view"
48014
+ },
48015
+ "training.getJob": {
48016
+ capName: "training",
48017
+ capScope: "system",
48018
+ addonId: null,
48019
+ access: "view"
48020
+ },
48021
+ "training.getJobResult": {
48022
+ capName: "training",
48023
+ capScope: "system",
48024
+ addonId: null,
48025
+ access: "view"
48026
+ },
48027
+ "training.listBaseModels": {
48028
+ capName: "training",
48029
+ capScope: "system",
48030
+ addonId: null,
48031
+ access: "view"
48032
+ },
48033
+ "training.listDatasetVersions": {
48034
+ capName: "training",
48035
+ capScope: "system",
48036
+ addonId: null,
48037
+ access: "view"
48038
+ },
48039
+ "training.listJobs": {
48040
+ capName: "training",
48041
+ capScope: "system",
48042
+ addonId: null,
48043
+ access: "view"
48044
+ },
48045
+ "training.planJob": {
48046
+ capName: "training",
48047
+ capScope: "system",
48048
+ addonId: null,
48049
+ access: "view"
48050
+ },
48051
+ "training.putDatasetVersion": {
48052
+ capName: "training",
48053
+ capScope: "system",
48054
+ addonId: null,
48055
+ access: "create"
48056
+ },
48057
+ "training.registerResult": {
48058
+ capName: "training",
48059
+ capScope: "system",
48060
+ addonId: null,
48061
+ access: "create"
48062
+ },
48063
+ "training.removeDatasetVersion": {
48064
+ capName: "training",
48065
+ capScope: "system",
48066
+ addonId: null,
48067
+ access: "delete"
48068
+ },
48069
+ "training.rollbackCanary": {
48070
+ capName: "training",
48071
+ capScope: "system",
48072
+ addonId: null,
48073
+ access: "create"
48074
+ },
48075
+ "training.startJob": {
48076
+ capName: "training",
48077
+ capScope: "system",
48078
+ addonId: null,
48079
+ access: "create"
48080
+ },
48081
+ "trainingProvider.cancelJob": {
48082
+ capName: "training-provider",
48083
+ capScope: "system",
48084
+ addonId: null,
48085
+ access: "create"
48086
+ },
48087
+ "trainingProvider.cleanupJob": {
48088
+ capName: "training-provider",
48089
+ capScope: "system",
48090
+ addonId: null,
48091
+ access: "create"
48092
+ },
48093
+ "trainingProvider.describe": {
48094
+ capName: "training-provider",
48095
+ capScope: "system",
48096
+ addonId: null,
48097
+ access: "view"
48098
+ },
48099
+ "trainingProvider.estimateJob": {
48100
+ capName: "training-provider",
48101
+ capScope: "system",
48102
+ addonId: null,
48103
+ access: "view"
48104
+ },
48105
+ "trainingProvider.getJob": {
48106
+ capName: "training-provider",
48107
+ capScope: "system",
48108
+ addonId: null,
48109
+ access: "view"
48110
+ },
48111
+ "trainingProvider.listJobEvents": {
48112
+ capName: "training-provider",
48113
+ capScope: "system",
48114
+ addonId: null,
48115
+ access: "view"
48116
+ },
48117
+ "trainingProvider.listJobs": {
48118
+ capName: "training-provider",
48119
+ capScope: "system",
48120
+ addonId: null,
48121
+ access: "view"
48122
+ },
48123
+ "trainingProvider.offerArtifact": {
48124
+ capName: "training-provider",
48125
+ capScope: "system",
48126
+ addonId: null,
48127
+ access: "create"
48128
+ },
48129
+ "trainingProvider.readResult": {
48130
+ capName: "training-provider",
48131
+ capScope: "system",
48132
+ addonId: null,
48133
+ access: "create"
48134
+ },
48135
+ "trainingProvider.submitJob": {
48136
+ capName: "training-provider",
48137
+ capScope: "system",
48138
+ addonId: null,
48139
+ access: "create"
48140
+ },
48141
+ "trainingProvider.uploadDataset": {
48142
+ capName: "training-provider",
48143
+ capScope: "system",
48144
+ addonId: null,
48145
+ access: "create"
48146
+ },
48147
+ "trainingProvider.validateCredentials": {
48148
+ capName: "training-provider",
48149
+ capScope: "system",
48150
+ addonId: null,
48151
+ access: "create"
48152
+ },
46500
48153
  "turnProvider.getTurnServers": {
46501
48154
  capName: "turn-provider",
46502
48155
  capScope: "system",
@@ -46521,12 +48174,6 @@ Object.freeze({
46521
48174
  addonId: null,
46522
48175
  access: "create"
46523
48176
  },
46524
- "userManagement.createApiKey": {
46525
- capName: "user-management",
46526
- capScope: "system",
46527
- addonId: null,
46528
- access: "create"
46529
- },
46530
48177
  "userManagement.createScopedToken": {
46531
48178
  capName: "user-management",
46532
48179
  capScope: "system",
@@ -46563,12 +48210,6 @@ Object.freeze({
46563
48210
  addonId: null,
46564
48211
  access: "view"
46565
48212
  },
46566
- "userManagement.linkExternalIdentity": {
46567
- capName: "user-management",
46568
- capScope: "system",
46569
- addonId: null,
46570
- access: "create"
46571
- },
46572
48213
  "userManagement.listApiKeys": {
46573
48214
  capName: "user-management",
46574
48215
  capScope: "system",
@@ -46671,12 +48312,6 @@ Object.freeze({
46671
48312
  addonId: null,
46672
48313
  access: "create"
46673
48314
  },
46674
- "userManagement.validateApiKey": {
46675
- capName: "user-management",
46676
- capScope: "system",
46677
- addonId: null,
46678
- access: "view"
46679
- },
46680
48315
  "userManagement.validateCredentials": {
46681
48316
  capName: "user-management",
46682
48317
  capScope: "system",
@@ -50790,6 +52425,11 @@ Object.freeze({
50790
52425
  form: "single",
50791
52426
  optional: false
50792
52427
  }],
52428
+ "training.canaryResult": [{
52429
+ name: "deviceIds",
52430
+ form: "array",
52431
+ optional: false
52432
+ }],
50793
52433
  "update.getStatus": [{
50794
52434
  name: "deviceId",
50795
52435
  form: "single",