@camstack/addon-osd-manager 0.1.189 → 0.1.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. package/dist/{MotionZonesSettings-8xm5pG3y.mjs → MotionZonesSettings-Bu5cG8Nn.mjs} +2 -2
  2. package/dist/{PrivacyMaskSettings-CtawWTNs.mjs → PrivacyMaskSettings-D6dKZaUy.mjs} +4 -4
  3. package/dist/{SceneMonitorEditor-DQ-eU1J-.mjs → SceneMonitorEditor-CQOKJvlI.mjs} +3 -3
  4. package/dist/_stub.js +4755 -4755
  5. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_osd_manager_page-Ee0XGOd5.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_osd_manager_page-COS742kp.mjs} +3 -3
  6. package/dist/_virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DX4fnanS.mjs +26 -0
  7. package/dist/addon-osd-manager.css +1 -1
  8. package/dist/{hostInit-DRmpuSdp.mjs → hostInit-DKr2qNjM.mjs} +2 -2
  9. package/dist/index.js +1927 -56
  10. package/dist/index.mjs +1927 -56
  11. package/dist/{player-overlays-00L4bzaL.mjs → player-overlays-DeovLOpb.mjs} +1 -1
  12. package/dist/remoteEntry.js +1 -1
  13. package/dist/{responsive-BazUqbVY.mjs → responsive-SPEdfsGi.mjs} +1 -1
  14. package/dist/{scene-monitor-copy-BMxLX_wC.mjs → scene-monitor-copy-DiAzNFxa.mjs} +1 -1
  15. package/dist/{square-C-PPPKSF.mjs → square-C-hgouUR.mjs} +1 -1
  16. package/dist/{trash-2-DD0_NJPI.mjs → trash-2-DnRyzFp8.mjs} +1 -1
  17. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_osd_manager_page__remoteEntry_js-BD4P2kRn.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_osd_manager_page__remoteEntry_js-BHhohvcl.mjs} +1 -1
  18. package/package.json +1 -1
  19. package/dist/_virtual_mf___mfe_internal__addon_osd_manager_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-ClWLIzft.mjs +0 -26
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../types/dist/event-category-B_0XEcLF.mjs
1
+ //#region ../types/dist/event-category-DaIZi00R.mjs
2
2
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
3
3
  EventCategory["SystemBoot"] = "system.boot";
4
4
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -77,6 +77,13 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
77
77
  */
78
78
  EventCategory["AddonLoadFailed"] = "addon.load-failed";
79
79
  /**
80
+ * A keychain value was stored or removed (D787). Carries the ref, its
81
+ * owner and the new version — NEVER the value. A process holding the ref
82
+ * drops its cached copy and the owning `BaseAddon` re-resolves its config.
83
+ * Telemetry (D8): a process that misses it still revalidates by version.
84
+ */
85
+ EventCategory["KeychainChanged"] = "keychain.changed";
86
+ /**
80
87
  * Addon recovered from a previous failure. Emitted when an addon
81
88
  * transitions from `failed` back to `healthy` (typically via the
82
89
  * monitor's auto-retry loop, or after manual `addons.retryLoad`).
@@ -5369,7 +5376,7 @@ var ZodIssueCode = {
5369
5376
  var ZodFirstPartyTypeKind;
5370
5377
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5371
5378
  //#endregion
5372
- //#region ../types/dist/sleep-B0JG7-_F.mjs
5379
+ //#region ../types/dist/sleep-Cr5YOk3m.mjs
5373
5380
  /**
5374
5381
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5375
5382
  * window to float samples (D455).
@@ -5448,6 +5455,97 @@ function buildAlawTable() {
5448
5455
  }
5449
5456
  buildUlawTable();
5450
5457
  buildAlawTable();
5458
+ /** Is this field's stored value a credential? */
5459
+ function isSecretConfigField(field) {
5460
+ if (field.type === "password") return true;
5461
+ return "secret" in field && field.secret === true;
5462
+ }
5463
+ /**
5464
+ * Is this field's value stored in the KEYCHAIN (D787)? Every secret field is,
5465
+ * by its TYPE, unless it opts out with `storage: 'inline'` — never by its name.
5466
+ */
5467
+ function isKeychainStoredField(field) {
5468
+ if (!isSecretConfigField(field)) return false;
5469
+ if (field.type === "textarea" && field.isJson === true) return false;
5470
+ return !("storage" in field && field.storage === "inline");
5471
+ }
5472
+ /**
5473
+ * What a settings blob holds where a secret used to be.
5474
+ *
5475
+ * A keychain-stored field never holds its value. It holds a self-describing
5476
+ * MARKER, `{"$secret":"secret://…","v":1}` — an object, never a string, so no
5477
+ * code can mistake it for a credential and no form can send it to a camera as
5478
+ * a password. The empty state is `null` / absent, never `''`.
5479
+ *
5480
+ * The same shapes travel to and from the admin UI:
5481
+ *
5482
+ * - read: `hydrateSchema` hands a secret field a {@link SecretFieldView}
5483
+ * (`{ $secret, v, set: true }`) or `null` — the browser learns whether a
5484
+ * value is set, never the value.
5485
+ * - write: an untouched field submits the view back unchanged (KEEP); a typed
5486
+ * value is a plain non-empty string (CHANGE); the Clear button submits
5487
+ * {@link SECRET_CLEAR} (CLEAR). `''`, `null` and the legacy redaction tokens
5488
+ * are KEEP — an empty string is what a defaults-fallback pushes back, and
5489
+ * treating it as "clear" is how a save destroyed a stored credential before.
5490
+ *
5491
+ * Pure and browser-safe.
5492
+ */
5493
+ var SECRET_CLEAR = { $secretClear: true };
5494
+ /** The `'***'` token D634 redaction writes for non-admins. */
5495
+ var LEGACY_DEVICE_REDACTION = "***";
5496
+ function isRecord$1(value) {
5497
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5498
+ }
5499
+ function makeSecretMarker(ref) {
5500
+ return {
5501
+ $secret: ref,
5502
+ v: 1
5503
+ };
5504
+ }
5505
+ /** A stored marker: an object whose `$secret` is a non-empty string. */
5506
+ function isSecretMarker(value) {
5507
+ if (!isRecord$1(value)) return false;
5508
+ const ref = value["$secret"];
5509
+ return typeof ref === "string" && ref.length > 0;
5510
+ }
5511
+ function isSecretClear(value) {
5512
+ return isRecord$1(value) && value["$secretClear"] === true;
5513
+ }
5514
+ /**
5515
+ * The UI view of a stored secret field value: a marker becomes "set", inline
5516
+ * plaintext becomes "set (inline)", nothing becomes `null`. A value never
5517
+ * survives this function.
5518
+ */
5519
+ function toSecretFieldView(stored) {
5520
+ if (isSecretMarker(stored)) return {
5521
+ $secret: stored.$secret,
5522
+ v: 1,
5523
+ set: true
5524
+ };
5525
+ if (typeof stored === "string" && stored.length > 0) return {
5526
+ $secret: null,
5527
+ v: 1,
5528
+ set: true,
5529
+ inline: true
5530
+ };
5531
+ return null;
5532
+ }
5533
+ /**
5534
+ * Classify an incoming value for a secret path. Only a non-empty string that is
5535
+ * not a redaction token sets a value; only {@link SECRET_CLEAR} clears.
5536
+ * Everything else — a marker (ours or anyone's), a UI view, `''`, `null`,
5537
+ * `undefined`, a redaction token, a non-string — keeps what is stored.
5538
+ */
5539
+ function classifySecretWrite(incoming) {
5540
+ if (isSecretClear(incoming)) return { kind: "clear" };
5541
+ if (typeof incoming !== "string") return { kind: "keep" };
5542
+ if (incoming.length === 0) return { kind: "keep" };
5543
+ if (incoming === "__camstack_redacted__" || incoming === LEGACY_DEVICE_REDACTION) return { kind: "keep" };
5544
+ return {
5545
+ kind: "set",
5546
+ value: incoming
5547
+ };
5548
+ }
5451
5549
  Object.fromEntries([
5452
5550
  {
5453
5551
  id: "overview",
@@ -5619,33 +5717,19 @@ Object.fromEntries([
5619
5717
  function isValuelessField(field) {
5620
5718
  return field.type === "separator" || field.type === "info" || field.type === "qr-code" || field.type === "button" || field.type === "object-array" || field.type === "widget" || field.type === "addon-action-button" || field.type === "device-action-button";
5621
5719
  }
5622
- /**
5623
- * Merge a `ConfigUISchema` with a raw `values` record into a
5624
- * `ConfigUISchemaWithValues`. Used by every `get*Settings` backend endpoint
5625
- * before returning to the admin UI. Groups are walked recursively.
5626
- *
5627
- * For each leaf field:
5628
- * - structural fields (`separator`, `info`, `button`) pass through unchanged
5629
- * - other fields get `value = values[key] ?? field.default ?? null`
5630
- *
5631
- * Unknown keys in `values` (keys not declared in the schema) are silently
5632
- * ignored — they don't contribute to the output. Missing keys fall back to
5633
- * the schema default or `null`. This mirrors the old backend behaviour where
5634
- * `FormBuilder` rendered `values[key] ?? field.default`.
5635
- */
5636
- function hydrateSchema(schema, values) {
5720
+ function hydrateSchema(schema, values, options = {}) {
5637
5721
  return {
5638
5722
  ...schema.tabs ? { tabs: [...schema.tabs] } : {},
5639
5723
  sections: schema.sections.map((section) => ({
5640
5724
  ...section,
5641
- fields: section.fields.map((field) => hydrateField(field, values))
5725
+ fields: section.fields.map((field) => hydrateField(field, values, options))
5642
5726
  }))
5643
5727
  };
5644
5728
  }
5645
- function hydrateField(field, values) {
5729
+ function hydrateField(field, values, options) {
5646
5730
  if (isValuelessField(field)) return field;
5647
5731
  if (field.type === "group") {
5648
- const hydratedChildren = field.fields.map((child) => hydrateField(child, values));
5732
+ const hydratedChildren = field.fields.map((child) => hydrateField(child, values, options));
5649
5733
  return {
5650
5734
  ...field,
5651
5735
  fields: hydratedChildren
@@ -5654,7 +5738,7 @@ function hydrateField(field, values) {
5654
5738
  if (field.type === "sub-tabs") {
5655
5739
  const hydratedTabs = field.tabs.map((tab) => ({
5656
5740
  ...tab,
5657
- fields: tab.fields.map((child) => hydrateField(child, values))
5741
+ fields: tab.fields.map((child) => hydrateField(child, values, options))
5658
5742
  }));
5659
5743
  return {
5660
5744
  ...field,
@@ -5664,6 +5748,33 @@ function hydrateField(field, values) {
5664
5748
  const key = field.key;
5665
5749
  const storedValue = Object.prototype.hasOwnProperty.call(values, key) ? values[key] : void 0;
5666
5750
  const defaultValue = field.default;
5751
+ const asView = (v) => isSecretMarker(v) || options.inlineSecretsAsViews === true && v !== void 0;
5752
+ if (isKeychainStoredField(field) && asView(storedValue)) return {
5753
+ ...field,
5754
+ value: toSecretFieldView(storedValue)
5755
+ };
5756
+ if (isKeychainStoredField(field) && options.inlineSecretsAsViews === true) return {
5757
+ ...field,
5758
+ value: null
5759
+ };
5760
+ if (field.type === "editable-array" && Array.isArray(storedValue)) {
5761
+ const secretItemKeys = field.itemFields.filter((item) => "key" in item && isKeychainStoredField(item)).map((item) => "key" in item ? item.key : "");
5762
+ if (secretItemKeys.length > 0) {
5763
+ const rows = storedValue.map((row) => {
5764
+ if (row === null || typeof row !== "object" || Array.isArray(row)) return row;
5765
+ const out = { ...row };
5766
+ for (const k of secretItemKeys) {
5767
+ const v = Reflect.get(row, k);
5768
+ if (asView(v)) out[k] = toSecretFieldView(v);
5769
+ }
5770
+ return out;
5771
+ });
5772
+ return {
5773
+ ...field,
5774
+ value: rows
5775
+ };
5776
+ }
5777
+ }
5667
5778
  if (field.multiple) {
5668
5779
  const stored = Array.isArray(storedValue) ? storedValue : storedValue !== void 0 && storedValue !== null ? [storedValue] : [];
5669
5780
  const itemFallback = field.multiple.itemDefault !== void 0 ? field.multiple.itemDefault : defaultValue !== void 0 ? defaultValue : typeOf(field) === "string" ? "" : null;
@@ -5906,6 +6017,431 @@ function projectStore(store, perNodeKeys, nodeId) {
5906
6017
  }
5907
6018
  return out;
5908
6019
  }
6020
+ var GLOBAL_SCOPE = { kind: "global" };
6021
+ /** The scope every addon-wide (not per-node, not per-device) setting lives in. */
6022
+ function globalSecretScope() {
6023
+ return GLOBAL_SCOPE;
6024
+ }
6025
+ function encodeSegment(value) {
6026
+ return encodeURIComponent(value);
6027
+ }
6028
+ /**
6029
+ * The field path of a value inside an array item, addressed by the item's id:
6030
+ * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
6031
+ * `providers[authentik].clientSecret`.
6032
+ */
6033
+ function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6034
+ return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6035
+ }
6036
+ /** A write to a secret path could not be stored in the keychain, so it was refused. */
6037
+ var KeychainWriteRefusedError = class extends Error {
6038
+ fieldPath;
6039
+ constructor(fieldPath, cause) {
6040
+ super(`secret "${fieldPath}" was not saved: the keychain could not store it (${cause instanceof Error ? cause.message : String(cause)}). Nothing was written.`);
6041
+ this.fieldPath = fieldPath;
6042
+ this.name = "KeychainWriteRefusedError";
6043
+ }
6044
+ };
6045
+ var KEEP = { kind: "keep" };
6046
+ function isRecord(value) {
6047
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6048
+ }
6049
+ function defaultMintId() {
6050
+ return globalThis.crypto.randomUUID();
6051
+ }
6052
+ /** Every marker ref anywhere under `value`. */
6053
+ function collectSecretMarkerRefs(value, out = []) {
6054
+ if (isSecretMarker(value)) {
6055
+ out.push(value.$secret);
6056
+ return out;
6057
+ }
6058
+ if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6059
+ else if (isRecord(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6060
+ return out;
6061
+ }
6062
+ async function storedValueEquals(secrets, marker, candidate) {
6063
+ const resolved = (await secrets.resolve([marker.$secret]))[marker.$secret];
6064
+ return resolved?.kind === "value" && resolved.value === candidate;
6065
+ }
6066
+ async function writeLeaf(ctx, incoming, stored, fieldPath) {
6067
+ const intent = classifySecretWrite(incoming);
6068
+ const ref = ctx.secrets.ref(ctx.scope, fieldPath);
6069
+ const storedIsOurs = isSecretMarker(stored) && stored.$secret === ref;
6070
+ if (intent.kind === "keep") return KEEP;
6071
+ if (intent.kind === "set" && !ctx.operatorWrite && typeof stored === "string" && stored === intent.value) return KEEP;
6072
+ if (intent.kind === "clear") {
6073
+ if (storedIsOurs) ctx.deletes.push(ref);
6074
+ return {
6075
+ kind: "value",
6076
+ value: null
6077
+ };
6078
+ }
6079
+ if (storedIsOurs && await storedValueEquals(ctx.secrets, stored, intent.value)) return {
6080
+ kind: "value",
6081
+ value: stored
6082
+ };
6083
+ try {
6084
+ await ctx.secrets.put(ref, intent.value);
6085
+ } catch (err) {
6086
+ throw new KeychainWriteRefusedError(fieldPath, err);
6087
+ }
6088
+ return {
6089
+ kind: "value",
6090
+ value: makeSecretMarker(ref)
6091
+ };
6092
+ }
6093
+ /** Apply a member result onto `out`: KEEP restores the stored member, or removes it. */
6094
+ function applyMember(out, key, result, storedParent) {
6095
+ if (result.kind === "value") {
6096
+ out[key] = result.value;
6097
+ return;
6098
+ }
6099
+ if (Object.prototype.hasOwnProperty.call(storedParent, key)) out[key] = storedParent[key];
6100
+ else delete out[key];
6101
+ }
6102
+ async function writeMembers(ctx, children, incoming, stored, pathOf) {
6103
+ const out = { ...incoming };
6104
+ for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
6105
+ return out;
6106
+ }
6107
+ function rowId(row, idKey) {
6108
+ const raw = row[idKey];
6109
+ if (typeof raw === "string" && raw.length > 0) return raw;
6110
+ if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
6111
+ return null;
6112
+ }
6113
+ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6114
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord) : [];
6115
+ if (!Array.isArray(incoming)) {
6116
+ ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6117
+ return {
6118
+ kind: "value",
6119
+ value: incoming
6120
+ };
6121
+ }
6122
+ const storedById = /* @__PURE__ */ new Map();
6123
+ for (const row of storedRows) {
6124
+ const id = rowId(row, node.idKey);
6125
+ if (id !== null) storedById.set(id, row);
6126
+ }
6127
+ const kept = /* @__PURE__ */ new Set();
6128
+ const rows = [];
6129
+ for (const row of incoming) {
6130
+ if (!isRecord(row)) {
6131
+ rows.push(row);
6132
+ continue;
6133
+ }
6134
+ const id = rowId(row, node.idKey) ?? ctx.mintId();
6135
+ kept.add(id);
6136
+ const withId = {
6137
+ ...row,
6138
+ [node.idKey]: row[node.idKey] ?? id
6139
+ };
6140
+ if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
6141
+ const storedRow = storedById.get(id) ?? {};
6142
+ rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
6143
+ }
6144
+ for (const [id, row] of storedById) if (!kept.has(id)) ctx.deletes.push(...collectSecretMarkerRefs(row));
6145
+ return {
6146
+ kind: "value",
6147
+ value: rows
6148
+ };
6149
+ }
6150
+ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6151
+ switch (node.kind) {
6152
+ case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6153
+ case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6154
+ case "object": {
6155
+ if (!isRecord(incoming)) {
6156
+ if (incoming === void 0) return KEEP;
6157
+ ctx.deletes.push(...collectSecretMarkerRefs(stored));
6158
+ return {
6159
+ kind: "value",
6160
+ value: incoming
6161
+ };
6162
+ }
6163
+ const storedObj = isRecord(stored) ? stored : {};
6164
+ return {
6165
+ kind: "value",
6166
+ value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
6167
+ };
6168
+ }
6169
+ }
6170
+ }
6171
+ /** Split a perNode-scoped key (`key@nodeId`). */
6172
+ function splitNodeKey(key) {
6173
+ const at = key.indexOf("@");
6174
+ return at <= 0 ? {
6175
+ base: key,
6176
+ nodeId: null
6177
+ } : {
6178
+ base: key.slice(0, at),
6179
+ nodeId: key.slice(at + 1)
6180
+ };
6181
+ }
6182
+ /** Rewrite a settings patch so no secret value reaches the blob. See the file doc. */
6183
+ async function transformSecretWrite(input) {
6184
+ const deletes = [];
6185
+ const base = {
6186
+ secrets: input.secrets,
6187
+ mintId: input.mintId ?? defaultMintId,
6188
+ deletes,
6189
+ operatorWrite: input.operatorWrite === true
6190
+ };
6191
+ const out = {};
6192
+ for (const [key, incoming] of Object.entries(input.patch)) {
6193
+ const { base: baseKey, nodeId } = splitNodeKey(key);
6194
+ const node = input.tree.get(baseKey);
6195
+ if (node === void 0) {
6196
+ out[key] = incoming;
6197
+ continue;
6198
+ }
6199
+ const scope = nodeId !== null && nodeId.length > 0 ? {
6200
+ kind: "node",
6201
+ nodeId
6202
+ } : input.scope ?? globalSecretScope();
6203
+ const result = await writeNode({
6204
+ ...base,
6205
+ scope
6206
+ }, node, incoming, input.stored[key], baseKey);
6207
+ if (result.kind === "value") out[key] = result.value;
6208
+ }
6209
+ return {
6210
+ patch: out,
6211
+ afterWrite: async () => {
6212
+ if (deletes.length === 0) return { orphaned: [] };
6213
+ try {
6214
+ await input.secrets.delete([...new Set(deletes)]);
6215
+ return { orphaned: [] };
6216
+ } catch {
6217
+ return { orphaned: [...new Set(deletes)] };
6218
+ }
6219
+ }
6220
+ };
6221
+ }
6222
+ /**
6223
+ * Replace every marker in `value` with its keychain value. Returns the SAME
6224
+ * reference when there is no marker (no allocation, no keychain call).
6225
+ */
6226
+ async function resolveSecretMarkers(value, secrets) {
6227
+ const refs = collectSecretMarkerRefs(value);
6228
+ if (refs.length === 0) return {
6229
+ value,
6230
+ unresolved: []
6231
+ };
6232
+ const answers = await secrets.resolve(refs);
6233
+ const unresolved = [];
6234
+ for (const ref of new Set(refs)) {
6235
+ const answer = answers[ref];
6236
+ if (answer === void 0) unresolved.push({
6237
+ ref,
6238
+ reason: "not-initialized"
6239
+ });
6240
+ else if (answer.kind === "unavailable") unresolved.push({
6241
+ ref,
6242
+ reason: answer.reason
6243
+ });
6244
+ else if (answer.kind === "missing" || answer.kind === "forbidden") unresolved.push({
6245
+ ref,
6246
+ reason: answer.kind
6247
+ });
6248
+ }
6249
+ const substitute = (v) => {
6250
+ if (isSecretMarker(v)) {
6251
+ const answer = answers[v.$secret];
6252
+ return answer?.kind === "value" ? {
6253
+ keep: true,
6254
+ value: answer.value
6255
+ } : {
6256
+ keep: false,
6257
+ value: void 0
6258
+ };
6259
+ }
6260
+ if (Array.isArray(v)) {
6261
+ const items = [];
6262
+ for (const item of v) {
6263
+ const s = substitute(item);
6264
+ if (s.keep) items.push(s.value);
6265
+ }
6266
+ return {
6267
+ keep: true,
6268
+ value: items
6269
+ };
6270
+ }
6271
+ if (isRecord(v)) {
6272
+ const out = {};
6273
+ for (const [k, child] of Object.entries(v)) {
6274
+ const s = substitute(child);
6275
+ if (s.keep) out[k] = s.value;
6276
+ }
6277
+ return {
6278
+ keep: true,
6279
+ value: out
6280
+ };
6281
+ }
6282
+ return {
6283
+ keep: true,
6284
+ value: v
6285
+ };
6286
+ };
6287
+ return {
6288
+ value: substitute(value).value,
6289
+ unresolved
6290
+ };
6291
+ }
6292
+ function touchesTree(tree, patch) {
6293
+ if (tree.size === 0) return false;
6294
+ for (const key of Object.keys(patch)) {
6295
+ const at = key.indexOf("@");
6296
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6297
+ }
6298
+ return false;
6299
+ }
6300
+ /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6301
+ async function readStoredAddonBlob(raw) {
6302
+ const threeWay = raw.readAddonStoreResult;
6303
+ if (threeWay === void 0) return raw.readAddonStore();
6304
+ const result = await threeWay.call(raw);
6305
+ if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6306
+ return result.kind === "missing" ? {} : result.value;
6307
+ }
6308
+ function createSecretAwareSettings(raw, opts) {
6309
+ const chains = /* @__PURE__ */ new Map();
6310
+ const serialize = (key, fn) => {
6311
+ const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
6312
+ const tail = next.catch(() => void 0);
6313
+ chains.set(key, tail);
6314
+ tail.then(() => {
6315
+ if (chains.get(key) === tail) chains.delete(key);
6316
+ });
6317
+ return next;
6318
+ };
6319
+ const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6320
+ if (!touchesTree(tree, patch)) return rawWrite(patch);
6321
+ return serialize(chainKey, async () => {
6322
+ const stored = await readStored();
6323
+ const result = await transformSecretWrite({
6324
+ tree,
6325
+ secrets: opts.secrets,
6326
+ patch,
6327
+ stored,
6328
+ ...scope !== void 0 ? { scope } : {},
6329
+ operatorWrite: opts.isOperatorWrite?.() === true
6330
+ });
6331
+ if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6332
+ const { orphaned } = await result.afterWrite();
6333
+ if (orphaned.length > 0) opts.onOrphaned(orphaned);
6334
+ });
6335
+ };
6336
+ const wrapped = {
6337
+ writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6338
+ writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6339
+ kind: "device",
6340
+ deviceId
6341
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6342
+ };
6343
+ return new Proxy(raw, { get(target, prop, receiver) {
6344
+ if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6345
+ if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6346
+ const value = Reflect.get(target, prop, receiver);
6347
+ return typeof value === "function" ? value.bind(target) : value;
6348
+ } });
6349
+ }
6350
+ /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6351
+ function withSecretAwareSettings(context, opts) {
6352
+ const raw = context.settings;
6353
+ if (raw === void 0) return context;
6354
+ const settings = createSecretAwareSettings(raw, opts);
6355
+ return new Proxy(context, { get(target, prop, receiver) {
6356
+ if (prop === "settings") return settings;
6357
+ return Reflect.get(target, prop, receiver);
6358
+ } });
6359
+ }
6360
+ var LEAF = { kind: "leaf" };
6361
+ var DEFAULT_ITEM_ID_KEY = "id";
6362
+ function collectFields(fields, out) {
6363
+ for (const field of fields) {
6364
+ if (field.type === "group") {
6365
+ collectFields(field.fields, out);
6366
+ continue;
6367
+ }
6368
+ if (field.type === "sub-tabs") {
6369
+ for (const tab of field.tabs) collectFields(tab.fields, out);
6370
+ continue;
6371
+ }
6372
+ if (field.type === "editable-array") {
6373
+ const item = /* @__PURE__ */ new Map();
6374
+ for (const itemField of field.itemFields) if ("key" in itemField && isKeychainStoredField(itemField)) item.set(itemField.key, LEAF);
6375
+ if (item.size > 0) out.set(field.key, {
6376
+ kind: "array",
6377
+ idKey: field.itemIdKey ?? DEFAULT_ITEM_ID_KEY,
6378
+ item
6379
+ });
6380
+ continue;
6381
+ }
6382
+ if (!("key" in field) || typeof field.key !== "string") continue;
6383
+ if (isKeychainStoredField(field)) out.set(field.key, LEAF);
6384
+ }
6385
+ }
6386
+ /** The secret tree a settings schema declares. */
6387
+ function secretTreeFromSchema(schema) {
6388
+ const out = /* @__PURE__ */ new Map();
6389
+ if (schema === null) return out;
6390
+ for (const section of schema.sections) collectFields(section.fields, out);
6391
+ return out;
6392
+ }
6393
+ /** Parse `a.b[id].c` into segments; throws on a malformed path (a declaration bug). */
6394
+ function parseSecretStatePath(path) {
6395
+ const segments = [];
6396
+ for (const raw of path.split(".")) {
6397
+ const m = /^([^[\]]+)(?:\[([^[\]]+)\])?$/.exec(raw);
6398
+ if (m === null || m[1] === void 0) throw new Error(`secretStatePaths: malformed path "${path}"`);
6399
+ segments.push(m[2] !== void 0 ? {
6400
+ key: m[1],
6401
+ idKey: m[2]
6402
+ } : { key: m[1] });
6403
+ }
6404
+ if (segments.length === 0) throw new Error(`secretStatePaths: empty path`);
6405
+ if (segments[segments.length - 1]?.idKey !== void 0) throw new Error(`secretStatePaths: "${path}" ends on an array — name the member that is secret`);
6406
+ return segments;
6407
+ }
6408
+ function insert(into, segments) {
6409
+ const [head, ...rest] = segments;
6410
+ if (head === void 0) return;
6411
+ if (rest.length === 0) {
6412
+ into.set(head.key, LEAF);
6413
+ return;
6414
+ }
6415
+ const existing = into.get(head.key);
6416
+ if (head.idKey !== void 0) {
6417
+ const item = new Map(existing?.kind === "array" ? existing.item : []);
6418
+ insert(item, rest);
6419
+ into.set(head.key, {
6420
+ kind: "array",
6421
+ idKey: head.idKey,
6422
+ item
6423
+ });
6424
+ return;
6425
+ }
6426
+ const children = new Map(existing?.kind === "object" ? existing.children : []);
6427
+ insert(children, rest);
6428
+ into.set(head.key, {
6429
+ kind: "object",
6430
+ children
6431
+ });
6432
+ }
6433
+ /** Add hidden-state paths (`secretStatePaths`) to a schema-derived tree. */
6434
+ function mergeSecretStatePaths(tree, paths) {
6435
+ if (paths.length === 0) return tree;
6436
+ const out = new Map(tree);
6437
+ for (const path of paths) insert(out, parseSecretStatePath(path));
6438
+ return out;
6439
+ }
6440
+ /** First retry of a secret the keychain could not serve; doubles to {@link SECRET_RETRY_MAX_MS}. */
6441
+ var SECRET_RETRY_FIRST_MS = 5e3;
6442
+ var SECRET_RETRY_MAX_MS = 5 * 6e4;
6443
+ /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
6444
+ var SECRET_CHANGE_DEBOUNCE_MS = 250;
5909
6445
  /**
5910
6446
  * Base class for CamStack addons. Eliminates settings boilerplate:
5911
6447
  *
@@ -5975,6 +6511,25 @@ var BaseAddon = class {
5975
6511
  settingsStoreReady = false;
5976
6512
  /** Default config values. Provided via constructor. */
5977
6513
  defaults;
6514
+ /**
6515
+ * Hidden-state paths that hold secrets (D787) — values the addon writes
6516
+ * itself (`updateGlobalSettings`, `state()`) that no form field declares.
6517
+ * Stored in the keychain exactly like a `password` field. Syntax:
6518
+ * `'snapshotSigningKey'`, `'identity.pincode'`, `'tokens[userId].accessToken'`
6519
+ * (`key[<id field>]` addresses array items by id, never by index).
6520
+ */
6521
+ secretStatePaths = [];
6522
+ _addonSecretTree = null;
6523
+ _deviceSecretTree = null;
6524
+ /** Refs the last resolved config pointed at — a change to one re-resolves. */
6525
+ _configSecretRefs = /* @__PURE__ */ new Set();
6526
+ _unresolvedSecrets = [];
6527
+ _secretRetryTimer = null;
6528
+ _secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
6529
+ _secretChangeTimer = null;
6530
+ _secretChangeUnsub = null;
6531
+ /** >0 while an OPERATOR's settings write is being applied. */
6532
+ _operatorWriteDepth = 0;
5978
6533
  constructor(defaults) {
5979
6534
  this.defaults = defaults;
5980
6535
  this._config = { ...defaults };
@@ -6010,8 +6565,18 @@ var BaseAddon = class {
6010
6565
  return this._config;
6011
6566
  }
6012
6567
  async initialize(context) {
6013
- this._ctx = context;
6568
+ const secrets = context.secrets;
6569
+ this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6570
+ secrets,
6571
+ addonTree: () => this.addonSecretTree(),
6572
+ deviceTree: () => this.deviceSecretTree(),
6573
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6574
+ isOperatorWrite: () => this._operatorWriteDepth > 0
6575
+ }) : context;
6014
6576
  await this.resolveConfig();
6577
+ if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6578
+ if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
6579
+ });
6015
6580
  const result = await this.onInitialize();
6016
6581
  this.emitLifecycle(EventCategory.AddonStarted);
6017
6582
  const normalized = normalizeAddonInitResult(result);
@@ -6044,6 +6609,12 @@ var BaseAddon = class {
6044
6609
  */
6045
6610
  async onHubReachable() {}
6046
6611
  async shutdown() {
6612
+ this._secretChangeUnsub?.();
6613
+ this._secretChangeUnsub = null;
6614
+ if (this._secretRetryTimer !== null) clearTimeout(this._secretRetryTimer);
6615
+ if (this._secretChangeTimer !== null) clearTimeout(this._secretChangeTimer);
6616
+ this._secretRetryTimer = null;
6617
+ this._secretChangeTimer = null;
6047
6618
  this.emitLifecycle(EventCategory.AddonStopped);
6048
6619
  if (this.autoEmitReadiness) this.emitReadinessForProviders("down");
6049
6620
  await this.onShutdown();
@@ -6122,7 +6693,7 @@ var BaseAddon = class {
6122
6693
  return hydrateSchema(schema, overlay ? {
6123
6694
  ...projected,
6124
6695
  ...overlay
6125
- } : projected);
6696
+ } : projected, { inlineSecretsAsViews: true });
6126
6697
  }
6127
6698
  /**
6128
6699
  * The integration-level view of this addon's settings: exactly the sections
@@ -6171,7 +6742,7 @@ var BaseAddon = class {
6171
6742
  return hydrateSchema({
6172
6743
  ...schema,
6173
6744
  sections
6174
- }, projected);
6745
+ }, projected, { inlineSecretsAsViews: true });
6175
6746
  }
6176
6747
  /**
6177
6748
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
@@ -6225,18 +6796,50 @@ var BaseAddon = class {
6225
6796
  value: result.value[key]
6226
6797
  };
6227
6798
  }
6799
+ /**
6800
+ * The OPERATOR's write — a settings form or an admin API call, dispatched by
6801
+ * the kernel. Identical to {@link updateGlobalSettings}, except that a secret
6802
+ * the operator sends is stored as sent even when it equals a pre-keychain
6803
+ * inline value: the operator re-entering a password is a change, an addon
6804
+ * writing back what it read is not (D787).
6805
+ */
6806
+ async updateGlobalSettingsAsOperator(patch, nodeId) {
6807
+ this._operatorWriteDepth++;
6808
+ try {
6809
+ await this.applyGlobalPatch(patch, nodeId);
6810
+ } finally {
6811
+ this._operatorWriteDepth--;
6812
+ }
6813
+ }
6228
6814
  async updateGlobalSettings(patch, nodeId) {
6815
+ await this.applyGlobalPatch(patch, nodeId);
6816
+ }
6817
+ /**
6818
+ * REMOVE stored secrets — their keychain values and their markers (D787).
6819
+ *
6820
+ * Writing `''` to a secret field KEEPS what is stored (an empty string is
6821
+ * what a defaults fallback writes back, and it must never destroy a
6822
+ * credential), so code that means "forget this token" says so here. Without
6823
+ * a keychain (an older kernel) it writes `''`, as such code always did.
6824
+ */
6825
+ async clearSecrets(keys, nodeId) {
6826
+ const tree = this.addonSecretTree();
6827
+ const keychain = this._ctx?.secrets !== void 0;
6828
+ const patch = {};
6829
+ for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
6830
+ await this.applyGlobalPatch(patch, nodeId);
6831
+ }
6832
+ async applyGlobalPatch(barePatch, nodeId) {
6229
6833
  const keys = this.perNodeKeys();
6230
6834
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6231
6835
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6232
- const barePatch = patch;
6233
6836
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6234
6837
  await this._ctx?.settings?.writeAddonStore(scoped);
6235
6838
  if (target !== localNode) return;
6236
6839
  await this.resolveConfig();
6237
6840
  await this.onConfigChanged();
6238
6841
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
6239
- this.maybeAutoRestart(patch, this.globalSettingsSchema());
6842
+ this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
6240
6843
  }
6241
6844
  /**
6242
6845
  * The set of field keys the global settings schema declares `perNode: true`
@@ -6261,7 +6864,7 @@ var BaseAddon = class {
6261
6864
  * time to return its response before the addon is torn down and
6262
6865
  * re-initialised by `AddonRegistryService.restartAddon`.
6263
6866
  */
6264
- maybeAutoRestart(patch, schema) {
6867
+ maybeAutoRestart(patchKeys, schema) {
6265
6868
  if (!schema) return;
6266
6869
  const restartKeys = /* @__PURE__ */ new Set();
6267
6870
  for (const section of schema.sections) for (const field of section.fields) {
@@ -6269,13 +6872,13 @@ var BaseAddon = class {
6269
6872
  if (field.requiresRestart) restartKeys.add(field.key);
6270
6873
  }
6271
6874
  if (restartKeys.size === 0) return;
6272
- if (!Object.keys(patch).some((k) => restartKeys.has(k))) return;
6875
+ if (!patchKeys.some((k) => restartKeys.has(k))) return;
6273
6876
  const ctx = this._ctx;
6274
6877
  if (!ctx) return;
6275
6878
  const addonId = ctx.id;
6276
6879
  setImmediate(() => {
6277
6880
  ctx.api.addons?.restartAddon?.mutate({ addonId }).then(() => {
6278
- ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: Object.keys(patch).filter((k) => restartKeys.has(k)) } });
6881
+ ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: patchKeys.filter((k) => restartKeys.has(k)) } });
6279
6882
  }).catch((err) => {
6280
6883
  ctx.logger.error("addon auto-restart failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
6281
6884
  });
@@ -6284,7 +6887,7 @@ var BaseAddon = class {
6284
6887
  async getDeviceSettings(deviceId) {
6285
6888
  const schema = this.deviceSettingsSchema();
6286
6889
  if (!schema) return { sections: [] };
6287
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {});
6890
+ return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6288
6891
  }
6289
6892
  async updateDeviceSettings(deviceId, patch) {
6290
6893
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -6414,7 +7017,7 @@ var BaseAddon = class {
6414
7017
  * selection at boot (absent scoped key ⇒ the constructor default wins).
6415
7018
  */
6416
7019
  async resolveConfig() {
6417
- const stored = await this.readAddonStoreWithRetry();
7020
+ const stored = await this.resolveStoredSecrets(await this.readAddonStoreWithRetry());
6418
7021
  const perNode = this.perNodeKeys();
6419
7022
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6420
7023
  const resolved = { ...this.defaults };
@@ -6439,7 +7042,7 @@ var BaseAddon = class {
6439
7042
  key,
6440
7043
  schema,
6441
7044
  fallback,
6442
- read: () => this.readAddonStoreWithRetry(),
7045
+ read: async () => this.resolveStoredSecrets(await this.readAddonStoreWithRetry()),
6443
7046
  write: async (patch) => {
6444
7047
  await this._ctx?.settings?.writeAddonStore(patch);
6445
7048
  },
@@ -6456,7 +7059,7 @@ var BaseAddon = class {
6456
7059
  key,
6457
7060
  schema,
6458
7061
  fallback,
6459
- read: async () => await this._ctx?.settings?.readDeviceStore(deviceId) ?? {},
7062
+ read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
6460
7063
  write: async (patch) => {
6461
7064
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
6462
7065
  },
@@ -6468,6 +7071,70 @@ var BaseAddon = class {
6468
7071
  } })
6469
7072
  });
6470
7073
  }
7074
+ /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
7075
+ addonSecretTree() {
7076
+ this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
7077
+ return this._addonSecretTree;
7078
+ }
7079
+ deviceSecretTree() {
7080
+ this._deviceSecretTree ??= secretTreeFromSchema(this.deviceSettingsSchema());
7081
+ return this._deviceSecretTree;
7082
+ }
7083
+ /**
7084
+ * Secrets of this addon's stored config that could not be resolved on the
7085
+ * last read, with why. Non-empty means the addon is running WITHOUT them —
7086
+ * an addon whose function needs one should report itself degraded rather
7087
+ * than start on an empty credential.
7088
+ */
7089
+ get unresolvedSecrets() {
7090
+ return this._unresolvedSecrets;
7091
+ }
7092
+ /**
7093
+ * Substitute every keychain marker in a stored blob with its value. With no
7094
+ * keychain (no `ctx.secrets`) or no marker, the blob comes back unchanged.
7095
+ * An unresolvable value is LEFT OUT (never `''`), logged by ref — never by
7096
+ * value — and, when the cause can pass, retried with backoff. Nothing is
7097
+ * ever written back from here.
7098
+ */
7099
+ async resolveStoredSecrets(blob, trackForConfig = true) {
7100
+ const secrets = this._ctx?.secrets;
7101
+ if (secrets === void 0) return blob;
7102
+ const refs = collectSecretMarkerRefs(blob);
7103
+ if (trackForConfig) this._configSecretRefs = new Set(refs);
7104
+ if (refs.length === 0) {
7105
+ if (trackForConfig) this._unresolvedSecrets = [];
7106
+ return blob;
7107
+ }
7108
+ const { value, unresolved } = await resolveSecretMarkers(blob, secrets);
7109
+ if (trackForConfig) {
7110
+ this._unresolvedSecrets = unresolved;
7111
+ if (unresolved.length > 0) {
7112
+ this._ctx?.logger?.error?.("secret unavailable — running without it, will retry", { meta: { secrets: unresolved.map((u) => ({
7113
+ ref: u.ref,
7114
+ reason: u.reason
7115
+ })) } });
7116
+ if (unresolved.some((u) => u.reason !== "missing" && u.reason !== "forbidden")) {
7117
+ this.scheduleSecretReresolve(this._secretRetryDelayMs);
7118
+ this._secretRetryDelayMs = Math.min(this._secretRetryDelayMs * 2, SECRET_RETRY_MAX_MS);
7119
+ }
7120
+ } else this._secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
7121
+ }
7122
+ return value;
7123
+ }
7124
+ /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7125
+ scheduleSecretReresolve(delayMs) {
7126
+ const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
7127
+ if (this[timerOf] !== null) return;
7128
+ const timer = setTimeout(() => {
7129
+ this[timerOf] = null;
7130
+ if (this._ctx === null) return;
7131
+ this.resolveConfig().then(() => this.onConfigChanged()).catch((err) => {
7132
+ this._ctx?.logger?.error?.("re-resolving secrets failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
7133
+ });
7134
+ }, delayMs);
7135
+ timer.unref?.();
7136
+ this[timerOf] = timer;
7137
+ }
6471
7138
  /**
6472
7139
  * Wrap `ctx.settings.readAddonStore()` with a short retry budget so a
6473
7140
  * transient settings-store outage (mid-restart of sqlite-settings, tsx-watch
@@ -15271,6 +15938,254 @@ id: union([string(), number()]) }), {
15271
15938
  })
15272
15939
  }
15273
15940
  };
15941
+ /**
15942
+ * `keychain` — the hub's encrypted store of secret values (D787).
15943
+ *
15944
+ * Settings blobs never hold a secret: they hold a marker
15945
+ * `{"$secret":"secret://<owner>/<scope>/<fieldPath>","v":1}` and the value
15946
+ * lives here, AES-256-GCM under a data key that a master key wraps. This cap
15947
+ * is the OWNER's door to its own values: every method is owner-checked
15948
+ * against the CALLER, never against anything the caller claims.
15949
+ *
15950
+ * Who the caller is: the transport stamps `callerAddonId` into the args of a
15951
+ * call that crossed a process (the parent `LocalChildRegistry` from the UDS
15952
+ * connection, the agent from its child's connection carried in
15953
+ * `$hub-cap-fwd`'s envelope). A stamp always overwrites; a wire call with no
15954
+ * stamp has its claim stripped. Only a hub in-process caller may state its own
15955
+ * identity — `ctx.secrets` does that with the addon id closed over. This is
15956
+ * identity against BUGS and misrouting, not against a malicious addon (every
15957
+ * runner is the same OS user): see the threat model in
15958
+ * `docs/design/2026-10-08-secrets-keychain.md`.
15959
+ *
15960
+ * `callerAddonId` is deliberately NOT in any input schema: the tRPC router
15961
+ * parses the input, so a session can never supply it, and the internal mount
15962
+ * floors every method to admin anyway (D240).
15963
+ *
15964
+ * Internal: addons reach it through `ctx.secrets`, never directly.
15965
+ */
15966
+ /** Why a value cannot be served right now. Never folded into "missing". */
15967
+ var KeychainUnavailableReasonSchema = _enum([
15968
+ "key-missing",
15969
+ "wrong-key",
15970
+ "key-file-unreadable",
15971
+ "store-unavailable",
15972
+ "not-initialized",
15973
+ "decrypt-failed"
15974
+ ]);
15975
+ var KeychainStateSchema = discriminatedUnion("state", [object({ state: literal("ready") }), object({
15976
+ state: literal("locked"),
15977
+ reason: KeychainUnavailableReasonSchema
15978
+ })]);
15979
+ var KeychainResolveEntrySchema = discriminatedUnion("kind", [
15980
+ object({
15981
+ kind: literal("value"),
15982
+ value: string(),
15983
+ version: number().int()
15984
+ }),
15985
+ object({ kind: literal("missing") }),
15986
+ object({
15987
+ kind: literal("unavailable"),
15988
+ reason: KeychainUnavailableReasonSchema
15989
+ }),
15990
+ object({ kind: literal("forbidden") })
15991
+ ]);
15992
+ var KeychainResolveResultSchema = record(string(), KeychainResolveEntrySchema);
15993
+ /** Metadata of one stored value — never the value. */
15994
+ var KeychainSecretMetaSchema = object({
15995
+ ref: string(),
15996
+ owner: string(),
15997
+ /** Formatted scope (`global`, `node/<id>`, `device/<id>`, …). */
15998
+ scope: string(),
15999
+ fieldPath: string(),
16000
+ version: number().int(),
16001
+ createdAt: number(),
16002
+ updatedAt: number(),
16003
+ /** `addon:<id>` | `user:<id>` | `system`. */
16004
+ updatedBy: string(),
16005
+ /** Coarse — written at most once an hour per ref. `null` = never read. */
16006
+ lastReadAt: number().nullable()
16007
+ });
16008
+ var RefListSchema = array(string().min(1)).max(512);
16009
+ var keychainCapability = {
16010
+ name: "keychain",
16011
+ scope: "system",
16012
+ mode: "singleton",
16013
+ internal: true,
16014
+ methods: {
16015
+ /** Store (or replace) the caller's value at `ref`. Refused while locked. */
16016
+ put: method(object({
16017
+ ref: string().min(1),
16018
+ value: string().min(1)
16019
+ }), object({
16020
+ ref: string(),
16021
+ version: number().int()
16022
+ }), {
16023
+ kind: "mutation",
16024
+ auth: "admin"
16025
+ }),
16026
+ /**
16027
+ * Resolve the caller's refs in one round-trip. A locked keychain answers
16028
+ * `unavailable` per ref — never `missing`, never an empty value.
16029
+ */
16030
+ resolve: method(object({ refs: RefListSchema }), KeychainResolveResultSchema, { auth: "admin" }),
16031
+ /** Remove the caller's refs. Unknown refs are ignored. */
16032
+ delete: method(object({ refs: RefListSchema }), object({ deleted: number().int() }), {
16033
+ kind: "mutation",
16034
+ auth: "admin"
16035
+ }),
16036
+ /** The caller's own refs, metadata only. */
16037
+ listMeta: method(object({}), array(KeychainSecretMetaSchema).readonly(), { auth: "admin" }),
16038
+ /** Whether values can be served — the save path refuses a write while locked. */
16039
+ getState: method(object({}), KeychainStateSchema, { auth: "admin" })
16040
+ }
16041
+ };
16042
+ var KeychainKeySourceSchema = object({
16043
+ kind: _enum([
16044
+ "config-file",
16045
+ "previous-config-file",
16046
+ "platform",
16047
+ "default-file"
16048
+ ]),
16049
+ /** File sources only — a path is not a secret. */
16050
+ path: string().optional(),
16051
+ /**
16052
+ * True when a whole-volume backup of the data directory carries this key
16053
+ * next to the database it protects (the default file). The page warns.
16054
+ */
16055
+ sharesBackupWithDatabase: boolean()
16056
+ });
16057
+ var KeychainStatusSchema = object({
16058
+ keychain: KeychainStateSchema,
16059
+ /** The source of the master key in use; `null` while locked. */
16060
+ keySource: KeychainKeySourceSchema.nullable(),
16061
+ /** The source configured to be primary — differs from `keySource` while a rotation is pending. */
16062
+ configuredSource: KeychainKeySourceSchema,
16063
+ /** Short fingerprint of the master key in use (`HMAC(KEK, label)`, 16 hex). */
16064
+ fingerprint: string().nullable(),
16065
+ activeKeyId: string().nullable(),
16066
+ /**
16067
+ * The keychain unlocked with a NON-primary source: the configured primary
16068
+ * key is not the one that wraps the data key yet. `rotateMasterKey` moves it.
16069
+ */
16070
+ rotationPending: boolean(),
16071
+ /** Wrapped copies of the data key under a previous master key, kept until purged. */
16072
+ retiredWraps: number().int(),
16073
+ recoveryKeyDownloadedAt: number().nullable(),
16074
+ secretCount: number().int()
16075
+ });
16076
+ /**
16077
+ * Whether a stored value is still pointed at by its owner's settings.
16078
+ * `unknown` is a first-class answer: a scope whose blob could not be read is
16079
+ * never reported as an orphan (and never deleted as one).
16080
+ */
16081
+ var KeychainSecretUsageSchema = _enum([
16082
+ "in-use",
16083
+ "orphan",
16084
+ "unknown"
16085
+ ]);
16086
+ var KeychainAdminSecretSchema = KeychainSecretMetaSchema.extend({ usage: KeychainSecretUsageSchema });
16087
+ var KeychainAuditActionSchema = _enum([
16088
+ "put",
16089
+ "delete",
16090
+ "reveal",
16091
+ "rotate-master-key",
16092
+ "purge-retired-keys",
16093
+ "download-recovery-key",
16094
+ "delete-orphans",
16095
+ "reset",
16096
+ "initialize"
16097
+ ]);
16098
+ var KeychainAuditEntrySchema = object({
16099
+ id: string(),
16100
+ at: number(),
16101
+ action: KeychainAuditActionSchema,
16102
+ /** `addon:<id>` | `user:<id>` | `system`. */
16103
+ actor: string(),
16104
+ ref: string().nullable(),
16105
+ detail: string().nullable()
16106
+ });
16107
+ var keychainAdminCapability = {
16108
+ name: "keychain-admin",
16109
+ scope: "system",
16110
+ mode: "singleton",
16111
+ methods: {
16112
+ status: method(object({}), KeychainStatusSchema, { auth: "admin" }),
16113
+ listSecrets: method(object({}), array(KeychainAdminSecretSchema).readonly(), { auth: "admin" }),
16114
+ listAudit: method(object({ limit: number().int().min(1).max(500).optional() }), array(KeychainAuditEntrySchema).readonly(), { auth: "admin" }),
16115
+ /**
16116
+ * Show one value to the operator. Audited. The UI hides it again after a
16117
+ * few seconds; nothing caches it.
16118
+ */
16119
+ reveal: method(object({ ref: string().min(1) }), object({
16120
+ value: string(),
16121
+ version: number().int()
16122
+ }), {
16123
+ kind: "mutation",
16124
+ auth: "admin",
16125
+ caller: "required"
16126
+ }),
16127
+ /** Delete refs no owner points at any more. Re-checked here; `unknown` is kept. */
16128
+ deleteOrphans: method(object({ refs: array(string().min(1)).max(1e3) }), object({
16129
+ deleted: array(string()).readonly(),
16130
+ kept: array(object({
16131
+ ref: string(),
16132
+ usage: KeychainSecretUsageSchema
16133
+ })).readonly()
16134
+ }), {
16135
+ kind: "mutation",
16136
+ auth: "admin",
16137
+ caller: "required"
16138
+ }),
16139
+ /**
16140
+ * Wrap the data key under the configured primary master key.
16141
+ *
16142
+ * Pending rotation (the keychain unlocked with a previous source): re-wrap
16143
+ * under the primary. Otherwise, with the default file as primary: generate
16144
+ * a new master key, write it there, re-wrap. A file or OS-keychain primary
16145
+ * that is already in use cannot be replaced from here — put the new key at
16146
+ * the source, keep the old one as `keychain.previousKeyFile`, restart, and
16147
+ * rotate. No value is re-encrypted either way; the previous wrap is kept
16148
+ * (retired) until purged.
16149
+ */
16150
+ rotateMasterKey: method(object({}), object({
16151
+ fingerprint: string(),
16152
+ keySource: KeychainKeySourceSchema
16153
+ }), {
16154
+ kind: "mutation",
16155
+ auth: "admin",
16156
+ caller: "required"
16157
+ }),
16158
+ purgeRetiredKeys: method(object({}), object({ purged: number().int() }), {
16159
+ kind: "mutation",
16160
+ auth: "admin",
16161
+ caller: "required"
16162
+ }),
16163
+ /** The master key, base64. Audited; marks the recovery copy as taken. */
16164
+ downloadRecoveryKey: method(object({}), object({
16165
+ key: string(),
16166
+ fingerprint: string(),
16167
+ keySource: KeychainKeySourceSchema
16168
+ }), {
16169
+ kind: "mutation",
16170
+ auth: "admin",
16171
+ caller: "required"
16172
+ }),
16173
+ /**
16174
+ * Lost-key recovery: archive every stored value into a
16175
+ * `keychain:secrets-orphaned-<ts>` table and start over with a new data
16176
+ * key. Every secret field then reads "not set". Requires the typed
16177
+ * confirmation {@link KEYCHAIN_RESET_CONFIRMATION}.
16178
+ */
16179
+ resetKeychain: method(object({ confirm: literal("RESET KEYCHAIN") }), object({
16180
+ archivedCollection: string().nullable(),
16181
+ archived: number().int()
16182
+ }), {
16183
+ kind: "mutation",
16184
+ auth: "admin",
16185
+ caller: "required"
16186
+ })
16187
+ }
16188
+ };
15274
16189
  var decoderCapability = {
15275
16190
  name: "decoder",
15276
16191
  scope: "system",
@@ -16611,7 +17526,11 @@ var DeviceRegisterPayloadSchema = object({
16611
17526
  var DeviceRemovePayloadSchema = object({ deviceId: number() });
16612
17527
  var DevicePersistConfigPayloadSchema = object({
16613
17528
  deviceId: number(),
16614
- data: record(string(), unknown())
17529
+ data: record(string(), unknown()),
17530
+ /** The paths the device's schema declares secret (D783), when the caller
17531
+ * knows them — those values are kept in the keychain, not the blob (D787).
17532
+ * Absent: the paths the device last reported at `registerDevice` apply. */
17533
+ secretConfigPaths: array(string()).optional()
16615
17534
  });
16616
17535
  /** What a migration actually did, per switch. `unreachable` is a first-class
16617
17536
  * answer: a camera that could not be asked is not a camera that was silenced. */
@@ -25515,8 +26434,23 @@ var RetrainMacroClassSchema = _enum([
25515
26434
  ]);
25516
26435
  /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
25517
26436
  var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
25518
- /** Did a human draw this box, or did the assist propose it? */
25519
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
26437
+ /**
26438
+ * Where a box came from. A machine-sourced box is a DRAFT on the page until
26439
+ * the operator confirms it; once saved it keeps its source as provenance.
26440
+ *
26441
+ * - `operator` — drawn by hand.
26442
+ * - `assist` — proposed by a detector run on the copy (the camera's own
26443
+ * model, or a larger teacher model).
26444
+ * - `pipeline` — the box the live pipeline actually drew on that frame, read
26445
+ * back from the track store (never a re-run).
26446
+ * - `llm` — proposed by a vision-capable LLM profile.
26447
+ */
26448
+ var RetrainAnnotationSourceSchema = _enum([
26449
+ "operator",
26450
+ "assist",
26451
+ "pipeline",
26452
+ "llm"
26453
+ ]);
25520
26454
  /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
25521
26455
  var RetrainBboxSchema = object({
25522
26456
  x: number(),
@@ -25534,7 +26468,8 @@ var RetrainBboxSchema = object({
25534
26468
  */
25535
26469
  var RetrainAnnotationSchema = object({
25536
26470
  id: string(),
25537
- trackId: string(),
26471
+ /** The frame's track. Absent on a recording still, which has none. */
26472
+ trackId: string().optional(),
25538
26473
  deviceId: number(),
25539
26474
  /** The COPY in retrain storage — never the source track's media key. */
25540
26475
  mediaKey: string(),
@@ -25583,13 +26518,47 @@ var RetrainFrameCandidateSchema = object({
25583
26518
  * fail, whatever became of the original. */
25584
26519
  copied: boolean()
25585
26520
  });
26521
+ /**
26522
+ * One box the live pipeline drew on a copied frame — what a correction starts
26523
+ * from. Derived when the frame is listed, from the track store: the subject
26524
+ * box recorded on the source media row when there is one, else the track
26525
+ * position nearest the frame's capture time. Never stored as an annotation
26526
+ * until the operator confirms it.
26527
+ */
26528
+ var RetrainPipelineBoxSchema = object({
26529
+ /** Normalised `[0,1]` against the full frame. */
26530
+ bbox: RetrainBboxSchema,
26531
+ macroClass: RetrainMacroClassSchema,
26532
+ label: string().optional(),
26533
+ subLabel: string().optional(),
26534
+ /** The detection score of the position used, when it was recorded. */
26535
+ score: number().optional(),
26536
+ /** The root model that produced the track, when it was recorded. */
26537
+ modelId: string().optional(),
26538
+ trackId: string(),
26539
+ /** `subject-box`: recorded on this very frame. `position`: the track's
26540
+ * position nearest the capture time, `deltaMs` away. */
26541
+ basis: _enum(["subject-box", "position"]),
26542
+ deltaMs: number()
26543
+ });
26544
+ /**
26545
+ * Where a retrain frame came from: a TRACK's stored media (copy-on-select),
26546
+ * or the RECORDING at an instant — the frame a model saw nothing in has no
26547
+ * track at all.
26548
+ */
26549
+ var RetrainFrameOriginSchema = _enum(["track", "recording"]);
25586
26550
  /** A frame the dataset OWNS: bytes copied at selection time. */
25587
26551
  var RetrainFrameSchema = object({
25588
26552
  frameId: string(),
25589
26553
  deviceId: number(),
25590
- trackId: string(),
25591
- /** Provenance only. It may already point at nothing — that is expected. */
25592
- sourceMediaId: number().int(),
26554
+ origin: RetrainFrameOriginSchema,
26555
+ /** The track it was copied from. Absent on a recording still. */
26556
+ trackId: string().optional(),
26557
+ /** Provenance only. It may already point at nothing — that is expected.
26558
+ * Absent on a recording still. */
26559
+ sourceMediaId: number().int().optional(),
26560
+ /** A recording still: the playhead instant it was taken at. */
26561
+ epochMs: number().optional(),
25593
26562
  sourceKind: MediaFileKindEnum,
25594
26563
  sizeBytes: number().int(),
25595
26564
  width: number().int(),
@@ -25600,7 +26569,12 @@ var RetrainFrameSchema = object({
25600
26569
  /** The operator's "every subject in this frame is boxed". Detector
25601
26570
  * evaluation keeps only complete frames: an unboxed subject would count as
25602
26571
  * a false positive. */
25603
- complete: boolean()
26572
+ complete: boolean(),
26573
+ /** The boxes the pipeline drew on this frame. Present on list answers;
26574
+ * empty when nothing the track store holds can be placed on it. */
26575
+ pipelineBoxes: array(RetrainPipelineBoxSchema).readonly().optional(),
26576
+ /** The named collections this frame belongs to. Present on list answers. */
26577
+ collectionIds: array(string()).readonly().optional()
25604
26578
  });
25605
26579
  /** Why a copy-on-select could not be honoured — named, never a silent skip. */
25606
26580
  var RetrainCopyRefusalSchema = _enum([
@@ -25631,6 +26605,8 @@ var RetrainFrameListSchema = object({
25631
26605
  var RetrainExportFilterSchema = object({
25632
26606
  deviceIds: array(number()).optional(),
25633
26607
  frameIds: array(string()).max(2e4).optional(),
26608
+ /** Only frames in at least one of these named collections. */
26609
+ collectionIds: array(string()).max(200).optional(),
25634
26610
  batchId: string().optional(),
25635
26611
  /** Only frames the operator marked complete (all subjects boxed). */
25636
26612
  completeOnly: boolean().optional()
@@ -25695,6 +26671,109 @@ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
25695
26671
  reason: string(),
25696
26672
  detail: string().optional()
25697
26673
  })]);
26674
+ /** A named set over the retrain corpus — membership only, it owns no pixels. */
26675
+ var RetrainCollectionSchema = object({
26676
+ id: string(),
26677
+ name: string(),
26678
+ createdAt: number(),
26679
+ frameCount: number().int()
26680
+ });
26681
+ var RetrainCollectionCreateResultSchema = discriminatedUnion("kind", [object({
26682
+ kind: literal("created"),
26683
+ collection: RetrainCollectionSchema
26684
+ }), object({
26685
+ kind: literal("refused"),
26686
+ reason: _enum(["empty-name", "duplicate-name"])
26687
+ })]);
26688
+ var RetrainCollectionRenameResultSchema = discriminatedUnion("kind", [object({
26689
+ kind: literal("renamed"),
26690
+ collection: RetrainCollectionSchema
26691
+ }), object({
26692
+ kind: literal("refused"),
26693
+ reason: _enum([
26694
+ "empty-name",
26695
+ "duplicate-name",
26696
+ "unknown-collection"
26697
+ ])
26698
+ })]);
26699
+ /**
26700
+ * The outcome of adding the frame at a recording instant. Every refusal is
26701
+ * named: `still-unavailable` (not recording, a gap, or an undecodable frame —
26702
+ * `detail` says which), `still-busy` (the recorder is at its decode bound; try
26703
+ * again), `unreadable-image`, `write-failed`, `unknown-collection`.
26704
+ */
26705
+ var AddRetrainFrameFromRecordingResultSchema = discriminatedUnion("kind", [object({
26706
+ kind: literal("added"),
26707
+ collectionId: string(),
26708
+ frame: RetrainFrameSchema,
26709
+ /** The moment was already in the dataset; nothing was decoded. */
26710
+ reused: boolean()
26711
+ }), object({
26712
+ kind: literal("refused"),
26713
+ reason: _enum([
26714
+ "unknown-collection",
26715
+ "still-unavailable",
26716
+ "still-busy",
26717
+ "unreadable-image",
26718
+ "write-failed"
26719
+ ]),
26720
+ detail: string().optional()
26721
+ })]);
26722
+ /** A vision LLM profile the AI assist may use, and where it sends the frame. */
26723
+ var RetrainAssistProfileSchema = object({
26724
+ id: string(),
26725
+ name: string(),
26726
+ model: string(),
26727
+ kind: string(),
26728
+ /** `true` when the frame would leave the house (a cloud vendor, or an
26729
+ * endpoint that is not on the local network). The page confirms each such
26730
+ * run, and the provider refuses one without `allowCloud`. */
26731
+ leavesHouse: boolean()
26732
+ });
26733
+ /** A box the AI assist proposed: a draft, plus the model's own reason. */
26734
+ var RetrainLlmProposalSchema = RetrainAnnotationDraftSchema.extend({ reason: string() });
26735
+ /** What the AI assist said about a box that was already on the canvas. */
26736
+ var RetrainLlmReviewSchema = object({
26737
+ /** The `ref` the page sent the box under. */
26738
+ ref: string(),
26739
+ verdict: _enum([
26740
+ "confirmed",
26741
+ "wrong-class",
26742
+ "not-an-object",
26743
+ "uncertain"
26744
+ ]),
26745
+ suggestedClass: RetrainMacroClassSchema.optional(),
26746
+ reason: string()
26747
+ });
26748
+ /**
26749
+ * The AI assist's answer. `proposed` carries drafts (`source: 'llm'`, the
26750
+ * model and its confidence) and reviews; items the model got wrong (a box off
26751
+ * the frame, an unasked class, an unknown ref) are dropped and counted in
26752
+ * `rejected`. A whole answer that is not the schema is `malformed-answer`.
26753
+ */
26754
+ var RetrainLlmAssistResultSchema = discriminatedUnion("kind", [object({
26755
+ kind: literal("proposed"),
26756
+ profileId: string(),
26757
+ model: string(),
26758
+ /** The frame was sent outside the house for this answer. */
26759
+ leftHouse: boolean(),
26760
+ proposals: array(RetrainLlmProposalSchema).readonly(),
26761
+ reviews: array(RetrainLlmReviewSchema).readonly(),
26762
+ rejected: number().int()
26763
+ }), object({
26764
+ kind: literal("refused"),
26765
+ reason: _enum([
26766
+ "unknown-frame",
26767
+ "unreadable-frame",
26768
+ "unknown-profile",
26769
+ "profile-disabled",
26770
+ "no-vision",
26771
+ "cloud-not-confirmed",
26772
+ "llm-error",
26773
+ "malformed-answer"
26774
+ ]),
26775
+ detail: string().optional()
26776
+ })]);
25698
26777
  /** The outcome of a lifecycle move owned by the retrain page. */
25699
26778
  var RetrainTransitionResultSchema = object({
25700
26779
  trackId: string(),
@@ -26881,7 +27960,7 @@ var pipelineAnalyticsCapability = {
26881
27960
  * a frame leaves the dataset before export. */
26882
27961
  deselectRetrainFrame: method(object({
26883
27962
  deviceId: number(),
26884
- trackId: string(),
27963
+ trackId: string().optional(),
26885
27964
  frameId: string()
26886
27965
  }), object({
26887
27966
  removed: boolean(),
@@ -26924,7 +28003,8 @@ var pipelineAnalyticsCapability = {
26924
28003
  */
26925
28004
  proposeRetrainAnnotations: method(object({
26926
28005
  deviceId: number(),
26927
- trackId: string(),
28006
+ /** The frame's track, when it has one — checked against the frame. */
28007
+ trackId: string().optional(),
26928
28008
  frameId: string(),
26929
28009
  subject: RetrainAssistSubjectSchema,
26930
28010
  /** Which node runs it. Absent ⇒ wherever an unowned call lands. */
@@ -26933,8 +28013,12 @@ var pipelineAnalyticsCapability = {
26933
28013
  kind: "mutation",
26934
28014
  auth: "admin"
26935
28015
  }),
26936
- /** Every annotation on a track, oldest first. */
26937
- listRetrainAnnotations: method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
28016
+ /** Every annotation on a track, or on named frames (a recording still has
28017
+ * no track), oldest first. One of the two is required. */
28018
+ listRetrainAnnotations: method(object({
28019
+ trackId: string().optional(),
28020
+ frameIds: array(string()).max(2e3).optional()
28021
+ }), array(RetrainAnnotationSchema).readonly(), {
26938
28022
  kind: "query",
26939
28023
  auth: "admin"
26940
28024
  }),
@@ -26953,7 +28037,8 @@ var pipelineAnalyticsCapability = {
26953
28037
  */
26954
28038
  saveRetrainAnnotations: method(object({
26955
28039
  deviceId: number(),
26956
- trackId: string(),
28040
+ /** The frame's track, when it has one — checked against the frame. */
28041
+ trackId: string().optional(),
26957
28042
  frameId: string(),
26958
28043
  annotations: array(RetrainAnnotationDraftSchema)
26959
28044
  }), array(RetrainAnnotationSchema).readonly(), {
@@ -27016,7 +28101,7 @@ var pipelineAnalyticsCapability = {
27016
28101
  */
27017
28102
  setRetrainFrameComplete: method(object({
27018
28103
  deviceId: number(),
27019
- trackId: string(),
28104
+ trackId: string().optional(),
27020
28105
  frameId: string(),
27021
28106
  complete: boolean()
27022
28107
  }), RetrainFrameSchema, {
@@ -27039,6 +28124,115 @@ var pipelineAnalyticsCapability = {
27039
28124
  auth: "admin",
27040
28125
  timeoutMs: 60 * 6e4
27041
28126
  }),
28127
+ /** The enabled, vision-capable LLM profiles, each saying whether a frame
28128
+ * sent to it leaves the house. */
28129
+ listRetrainAssistProfiles: method(object({}), array(RetrainAssistProfileSchema).readonly(), {
28130
+ kind: "query",
28131
+ auth: "admin"
28132
+ }),
28133
+ /**
28134
+ * Ask a vision LLM (the `llm` capability) about ONE copied frame: list the
28135
+ * objects of `classes` with boxes, and review the boxes already on the
28136
+ * canvas (sent by `ref`). Answers drafts (`source: 'llm'`) and reviews —
28137
+ * nothing is stored, nothing is accepted. A profile that sends the frame
28138
+ * outside the house is refused unless `allowCloud` says the operator
28139
+ * confirmed this run.
28140
+ */
28141
+ proposeRetrainAnnotationsWithLlm: method(object({
28142
+ deviceId: number(),
28143
+ trackId: string().optional(),
28144
+ frameId: string(),
28145
+ profileId: string(),
28146
+ classes: array(RetrainMacroClassSchema).min(1),
28147
+ boxes: array(object({
28148
+ ref: string(),
28149
+ bbox: RetrainBboxSchema,
28150
+ macroClass: RetrainMacroClassSchema,
28151
+ label: string().optional()
28152
+ })).max(50),
28153
+ allowCloud: boolean()
28154
+ }), RetrainLlmAssistResultSchema, {
28155
+ kind: "mutation",
28156
+ auth: "admin",
28157
+ timeoutMs: 18e4
28158
+ }),
28159
+ /**
28160
+ * Create a named collection — a set over the retrain corpus ("packages
28161
+ * porch night"). Names are unique case-insensitively and never empty;
28162
+ * both refusals are named.
28163
+ */
28164
+ createRetrainCollection: method(object({ name: string().max(120) }), RetrainCollectionCreateResultSchema, {
28165
+ kind: "mutation",
28166
+ auth: "admin"
28167
+ }),
28168
+ /** Every collection, newest first, with its frame count. */
28169
+ listRetrainCollections: method(object({}), array(RetrainCollectionSchema).readonly(), {
28170
+ kind: "query",
28171
+ auth: "admin"
28172
+ }),
28173
+ renameRetrainCollection: method(object({
28174
+ id: string(),
28175
+ name: string().max(120)
28176
+ }), RetrainCollectionRenameResultSchema, {
28177
+ kind: "mutation",
28178
+ auth: "admin"
28179
+ }),
28180
+ /**
28181
+ * Delete a collection. Its recording stills that no other collection
28182
+ * holds are deleted with their annotations (nothing else reaches them);
28183
+ * frames copied from tracks always stay in the dataset.
28184
+ */
28185
+ deleteRetrainCollection: method(object({ id: string() }), object({
28186
+ deleted: boolean(),
28187
+ removedFrames: number().int()
28188
+ }), {
28189
+ kind: "mutation",
28190
+ auth: "admin"
28191
+ }),
28192
+ /**
28193
+ * Add the frame at a recording instant to a collection — the frame the
28194
+ * model may have seen NOTHING in. The recorder re-decodes the native
28195
+ * frame at `epochMs`; the dataset copies it (trackless, durable). The same
28196
+ * moment twice is one copy. Every refusal is named.
28197
+ */
28198
+ addRetrainFrameFromRecording: method(object({
28199
+ collectionId: string(),
28200
+ deviceId: number(),
28201
+ epochMs: number()
28202
+ }), AddRetrainFrameFromRecordingResultSchema, {
28203
+ kind: "mutation",
28204
+ auth: "admin",
28205
+ timeoutMs: 6e4
28206
+ }),
28207
+ /** Add frames already in the dataset to a collection. */
28208
+ addRetrainFramesToCollection: method(object({
28209
+ collectionId: string(),
28210
+ frameIds: array(string()).min(1).max(500)
28211
+ }), object({
28212
+ added: number().int(),
28213
+ alreadyMember: number().int(),
28214
+ unknownFrameIds: array(string()).readonly()
28215
+ }), {
28216
+ kind: "mutation",
28217
+ auth: "admin"
28218
+ }),
28219
+ /** Remove a frame from a collection. A recording still left in no
28220
+ * collection is deleted with its annotations (`deletedFrame`). */
28221
+ removeRetrainFrameFromCollection: method(object({
28222
+ collectionId: string(),
28223
+ frameId: string()
28224
+ }), object({
28225
+ removed: boolean(),
28226
+ deletedFrame: boolean()
28227
+ }), {
28228
+ kind: "mutation",
28229
+ auth: "admin"
28230
+ }),
28231
+ /** The frames of a collection, with their pipeline boxes. */
28232
+ listRetrainCollectionFrames: method(object({ collectionId: string() }), array(RetrainFrameSchema).readonly(), {
28233
+ kind: "query",
28234
+ auth: "admin"
28235
+ }),
27042
28236
  /**
27043
28237
  * The media an EVENT owns.
27044
28238
  *
@@ -27978,13 +29172,31 @@ var RecommendationReasonSchema = discriminatedUnion("kind", [
27978
29172
  object({
27979
29173
  kind: literal("no-family-build"),
27980
29174
  format: ModelFormatSchema$1
29175
+ }),
29176
+ object({
29177
+ kind: literal("kept-custom-pin"),
29178
+ modelId: string(),
29179
+ deviceKey: string()
27981
29180
  })
27982
29181
  ]);
29182
+ /** Why a device is left exactly as it is, whatever the plan would pick (D786). */
29183
+ var KeptReasonSchema = _enum(["custom-pin"]);
29184
+ /**
29185
+ * Where a choice's latency came from (D791): this node's own benchmark
29186
+ * result, or the hardware-class table. Measured on the node beats the table.
29187
+ */
29188
+ var LatencySourceSchema = discriminatedUnion("kind", [object({ kind: literal("table") }), object({
29189
+ kind: literal("node-benchmark"),
29190
+ resultId: string(),
29191
+ measuredAtMs: number()
29192
+ })]);
27983
29193
  var DeviceModelChoiceSchema = object({
27984
29194
  modelId: string(),
27985
29195
  p50Ms: number(),
27986
29196
  fps: number(),
27987
29197
  measured: boolean(),
29198
+ /** Absent on a plan from before D791 — read as the table. */
29199
+ source: LatencySourceSchema.optional(),
27988
29200
  /** Parallel sessions at the camera rate with the headroom kept free: ⌊fps × (1 − headroom) / camera fps⌋. */
27989
29201
  capacitySessions: number(),
27990
29202
  personRecall: number()
@@ -27995,6 +29207,8 @@ var DeviceRecommendationSchema = object({
27995
29207
  enabled: boolean(),
27996
29208
  available: boolean(),
27997
29209
  chosen: DeviceModelChoiceSchema.nullable(),
29210
+ /** Present when the device is kept as is: Apply writes nothing on it. */
29211
+ kept: KeptReasonSchema.optional(),
27998
29212
  reasons: array(RecommendationReasonSchema).readonly()
27999
29213
  });
28000
29214
  var NodeRecommendationSchema = object({
@@ -28048,6 +29262,17 @@ var AutoTuneWarningSchema = discriminatedUnion("kind", [
28048
29262
  kind: literal("coral-enabled"),
28049
29263
  nodeId: string(),
28050
29264
  deviceKey: string()
29265
+ }),
29266
+ object({
29267
+ kind: literal("custom-pin-kept"),
29268
+ nodeId: string(),
29269
+ deviceKey: string().nullable(),
29270
+ deviceId: number().nullable(),
29271
+ modelId: string()
29272
+ }),
29273
+ object({
29274
+ kind: literal("custom-registry-unreadable"),
29275
+ error: string()
28051
29276
  })
28052
29277
  ]);
28053
29278
  var AutoTuneOptionsSchema = object({
@@ -28226,13 +29451,14 @@ var SuggestSharesResultSchema = object({
28226
29451
  nodes: array(SuggestedNodeShareSchema).readonly()
28227
29452
  });
28228
29453
  /**
28229
- * Where the node and device shares come from (D750, D755).
28230
- * - `hardware` (default) — computed by the system from each node's static
28231
- * capacity (its accelerators at their Auto tune models, from the measured
28232
- * latency table), recomputed whenever a node or device joins, leaves, is
28233
- * switched on or off, or changes model. No load input.
28234
- * - `benchmark` — the same, from each node's measured capacity (node
28235
- * benchmark results); a node without results falls back to `hardware`.
29454
+ * Where the node and device shares come from (D750, D755, D791).
29455
+ * - `benchmark` (default since D791) — each node's capacity as its own node
29456
+ * benchmark measured it; a node without fresh results is sized from
29457
+ * `hardware` and says so. Measured on the node beats the table.
29458
+ * - `hardware` — computed from each node's static capacity only (its
29459
+ * accelerators at their Auto tune models, from the latency table).
29460
+ * Both are recomputed whenever a node or device joins, leaves, is switched
29461
+ * on or off, changes model, or a benchmark result is written. No load input.
28236
29462
  * - `manual` — the operator's stored sliders.
28237
29463
  * Either way a node or device that cannot take sessions gives its share to
28238
29464
  * the others in proportion; the stored values are never rewritten for that.
@@ -28281,6 +29507,362 @@ var EffectiveSharesSchema = object({
28281
29507
  nodeWeights: record(string(), number()),
28282
29508
  deviceWeights: record(string(), record(string(), number()))
28283
29509
  });
29510
+ /**
29511
+ * Wire shapes of the node benchmark (D791): the operator's plan, the
29512
+ * preflight the confirmation shows, the run the orchestrator owns, what the
29513
+ * measuring runner reports, and the result rows Auto tune and the automatic
29514
+ * shares read.
29515
+ *
29516
+ * ONE node at a time, owned by the pipeline orchestrator. While a run is
29517
+ * active the cluster is in BENCHMARK MODE for that node: it is not a
29518
+ * detection candidate, camera pins naming it are ignored so its sessions move
29519
+ * elsewhere, and both come back when the mode ends — after a crash or a hub
29520
+ * restart too (a persisted manifest, reconciled against the registry).
29521
+ *
29522
+ * Two measurements, both on the node, driven by its own runner (frames never
29523
+ * cross a process at frame rate, D9):
29524
+ * - `device` — one accelerator × one candidate detector, root only, open
29525
+ * loop: how many streams at the camera rate it carries inside the frame
29526
+ * interval;
29527
+ * - `pipeline` — the chosen detector plus the operator's detail steps
29528
+ * (faces, plates, classifiers, CLIP…), on varied frames from the bench
29529
+ * clip: how many parallel sessions the node carries before latency, drops,
29530
+ * CPU, RAM or the event loop give out.
29531
+ */
29532
+ /** Defaults and bounds, one place. */
29533
+ var NODE_BENCHMARK_DEFAULTS = {
29534
+ fpsPerStream: 10,
29535
+ budgetMinutes: 45,
29536
+ minBudgetMinutes: 10,
29537
+ maxBudgetMinutes: 120,
29538
+ /** A result older than this no longer beats the table. */
29539
+ staleAfterDays: 30,
29540
+ /** Warm-in per ramp step (not accounted). */
29541
+ settleSec: 5,
29542
+ /** Accounted window per ramp step. */
29543
+ measureSec: 20,
29544
+ /** Longest the drain may take before the run is refused. */
29545
+ drainTimeoutSec: 120,
29546
+ /** Candidate models per device in one run. */
29547
+ maxModelsPerDevice: 6
29548
+ };
29549
+ /** The two measurements a run can make. */
29550
+ var NodeBenchmarkPhaseSchema = _enum(["device", "pipeline"]);
29551
+ var NodeBenchmarkDevicePlanSchema = object({
29552
+ /** `<backend>:<device>` — `openvino:npu`, `coreml:all`, `cpu`. */
29553
+ deviceKey: string().min(1),
29554
+ /**
29555
+ * Root detector candidates for the `device` measurement, in the order
29556
+ * measured. The FIRST is the one the `pipeline` measurement runs.
29557
+ */
29558
+ modelIds: array(string().min(1)).min(1).max(NODE_BENCHMARK_DEFAULTS.maxModelsPerDevice)
29559
+ });
29560
+ /** What the operator confirmed. */
29561
+ var NodeBenchmarkPlanSchema = object({
29562
+ nodeId: string().min(1),
29563
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
29564
+ /** Which measurements run. At least one. */
29565
+ phases: array(NodeBenchmarkPhaseSchema).min(1).default(["device", "pipeline"]),
29566
+ /**
29567
+ * Detail steps (catalog step ids under the root: faces, plates,
29568
+ * classifiers, CLIP…) the `pipeline` measurement enables. The root
29569
+ * detector always runs.
29570
+ */
29571
+ steps: array(string().min(1)).default([]),
29572
+ /** Offered rate of one stream / session. */
29573
+ fpsPerStream: number().int().min(1).max(30).default(NODE_BENCHMARK_DEFAULTS.fpsPerStream),
29574
+ /** Hard deadline: the mode ends and the cluster is restored when it passes. */
29575
+ budgetMinutes: number().int().min(NODE_BENCHMARK_DEFAULTS.minBudgetMinutes).max(NODE_BENCHMARK_DEFAULTS.maxBudgetMinutes).default(NODE_BENCHMARK_DEFAULTS.budgetMinutes),
29576
+ /** Keep the models the run downloaded (default: delete what was not installed before). */
29577
+ keepDownloadedModels: boolean().default(false),
29578
+ /** Start although the other nodes' capacity does not cover the sessions running now. */
29579
+ acceptInsufficientHeadroom: boolean().default(false)
29580
+ });
29581
+ var NodeBenchmarkRefusalSchema = object({
29582
+ kind: _enum([
29583
+ "benchmark-active",
29584
+ "node-offline",
29585
+ "unknown-device",
29586
+ "no-phase",
29587
+ "insufficient-headroom"
29588
+ ]),
29589
+ detail: string(),
29590
+ overridable: boolean()
29591
+ });
29592
+ /** A camera whose detection leaves the node for the run. */
29593
+ var NodeBenchmarkMovingCameraSchema = object({
29594
+ deviceId: number(),
29595
+ /** Placed on the node now (a standing attach or a running session). */
29596
+ placedOnNode: boolean(),
29597
+ /** A node pin naming this node, ignored for the run. */
29598
+ pinnedToNode: boolean()
29599
+ });
29600
+ /** A camera that cannot leave: no other node can obtain its frames. */
29601
+ var NodeBenchmarkStayingCameraSchema = object({
29602
+ deviceId: number(),
29603
+ reason: literal("only-frame-source")
29604
+ });
29605
+ var NodeBenchmarkPreflightSchema = object({
29606
+ nodeId: string(),
29607
+ online: boolean(),
29608
+ moving: array(NodeBenchmarkMovingCameraSchema).readonly(),
29609
+ /** Keep running on the node during the run; the result is flagged contaminated. */
29610
+ staying: array(NodeBenchmarkStayingCameraSchema).readonly(),
29611
+ estimatedDurationMs: number(),
29612
+ /** The run ends and the cluster is restored at the latest after this long. */
29613
+ budgetMs: number(),
29614
+ phases: array(NodeBenchmarkPhaseSchema).readonly(),
29615
+ steps: array(string()).readonly(),
29616
+ devices: array(NodeBenchmarkDevicePlanSchema).readonly(),
29617
+ /** Parallel sessions the cluster runs now, and what the other nodes can carry. */
29618
+ headroom: object({
29619
+ sessionsNow: number(),
29620
+ otherNodesCapacitySessions: number().nullable()
29621
+ }),
29622
+ refusals: array(NodeBenchmarkRefusalSchema).readonly(),
29623
+ canStart: boolean()
29624
+ });
29625
+ /** Where the measuring runner is. */
29626
+ var NodeBenchProgressSchema = object({
29627
+ phase: _enum([
29628
+ "preparing",
29629
+ "device",
29630
+ "pipeline",
29631
+ "cleanup"
29632
+ ]),
29633
+ deviceKey: string().nullable(),
29634
+ modelId: string().nullable(),
29635
+ /** Streams (device) or sessions (pipeline) of the step running now. */
29636
+ load: number().nullable(),
29637
+ cellsDone: number(),
29638
+ cellsTotal: number(),
29639
+ message: string()
29640
+ });
29641
+ /** What limited a ramp. `none` = the ramp ran out of steps still passing. */
29642
+ var NodeBenchLimitSchema = _enum([
29643
+ "p95",
29644
+ "drops",
29645
+ "errors",
29646
+ "stall",
29647
+ "cpu",
29648
+ "ram",
29649
+ "none"
29650
+ ]);
29651
+ var NodeBenchRampStepSchema = object({
29652
+ load: number(),
29653
+ pass: boolean(),
29654
+ p95Ms: number(),
29655
+ dropRatio: number(),
29656
+ /** Completed frames per second over the accounted window. */
29657
+ fps: number(),
29658
+ cpuPct: number().nullable(),
29659
+ ramFreePct: number().nullable(),
29660
+ failReasons: array(string()).readonly()
29661
+ });
29662
+ var NodeBenchCellSchema = discriminatedUnion("phase", [object({
29663
+ phase: literal("device"),
29664
+ deviceKey: string(),
29665
+ modelId: string(),
29666
+ /** Single-stream latency (the K = 1 step). */
29667
+ p50Ms: number(),
29668
+ p95Ms: number(),
29669
+ p99Ms: number(),
29670
+ /** Frames per second sustained at the last passing step. */
29671
+ fps: number(),
29672
+ /** Streams at the camera rate the device carried inside the frame interval; 0 = not even one. */
29673
+ kMax: number(),
29674
+ limitedBy: NodeBenchLimitSchema,
29675
+ /** First call (model load + warm-up). */
29676
+ warmupMs: number(),
29677
+ ramp: array(NodeBenchRampStepSchema).readonly()
29678
+ }), object({
29679
+ phase: literal("pipeline"),
29680
+ deviceKey: string(),
29681
+ modelId: string(),
29682
+ steps: array(string()).readonly(),
29683
+ /** Parallel sessions at the camera rate the node carried; 0 = not even one. */
29684
+ maxSessions: number(),
29685
+ limitedBy: NodeBenchLimitSchema,
29686
+ /** Detail steps that produced at least one result on the clip — a step that never fired measured nothing. */
29687
+ stepsFired: array(string()).readonly(),
29688
+ warmupMs: number(),
29689
+ ramp: array(NodeBenchRampStepSchema).readonly()
29690
+ })]);
29691
+ /**
29692
+ * What a result was measured ON. A result whose fingerprint no longer matches
29693
+ * the node no longer beats the table.
29694
+ */
29695
+ var NodeBenchFingerprintSchema = object({
29696
+ pipelineVersion: string().nullable(),
29697
+ cpuModel: string().nullable(),
29698
+ ramGb: number().nullable(),
29699
+ os: string().nullable(),
29700
+ /** Per device: the pool the cells ran on (runtime + tuning). */
29701
+ pools: record(string(), object({
29702
+ runtime: string(),
29703
+ numWorkers: number(),
29704
+ concurrency: number(),
29705
+ batchMode: string()
29706
+ })).default({})
29707
+ });
29708
+ /** The frames the run used. */
29709
+ var NodeBenchClipSchema = object({
29710
+ /** `camstack-bench-v1` or `reference-images` (the fallback when the clip is not reachable). */
29711
+ id: string(),
29712
+ revision: string().nullable(),
29713
+ frames: number(),
29714
+ width: number(),
29715
+ height: number()
29716
+ });
29717
+ var NodeBenchRunnerInputSchema = object({
29718
+ runId: string().min(1),
29719
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
29720
+ phases: array(NodeBenchmarkPhaseSchema).min(1),
29721
+ /** The full detail step tree root for the `pipeline` measurement is built on the node from these ids. */
29722
+ steps: array(string()).default([]),
29723
+ fpsPerStream: number().int().min(1).max(30),
29724
+ /** The runner stops on its own past this instant, whatever the hub does. */
29725
+ deadlineAtMs: number(),
29726
+ settleSec: number().min(0).max(60).default(NODE_BENCHMARK_DEFAULTS.settleSec),
29727
+ measureSec: number().min(2).max(300).default(NODE_BENCHMARK_DEFAULTS.measureSec),
29728
+ keepDownloadedModels: boolean().default(false)
29729
+ });
29730
+ var NodeBenchRunnerStateSchema = _enum([
29731
+ "running",
29732
+ "done",
29733
+ "failed",
29734
+ "aborted"
29735
+ ]);
29736
+ var NodeBenchRunnerStatusSchema = object({
29737
+ runId: string(),
29738
+ nodeId: string(),
29739
+ state: NodeBenchRunnerStateSchema,
29740
+ progress: NodeBenchProgressSchema.nullable(),
29741
+ /** Every finished cell so far — a run stopped half way keeps what it measured. */
29742
+ cells: array(NodeBenchCellSchema).readonly(),
29743
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
29744
+ clip: NodeBenchClipSchema.nullable(),
29745
+ /** Cameras seen running on the node during the run (they share its pools). */
29746
+ activeCameraIds: array(number()).readonly(),
29747
+ /** Models the run downloaded and then deleted (not installed before). */
29748
+ deletedModels: array(string()).readonly(),
29749
+ error: string().nullable(),
29750
+ startedAtMs: number(),
29751
+ finishedAtMs: number().nullable()
29752
+ });
29753
+ var NodeBenchmarkStateSchema = _enum([
29754
+ "draining",
29755
+ "measuring",
29756
+ "restoring",
29757
+ "done",
29758
+ "failed",
29759
+ "aborted"
29760
+ ]);
29761
+ /** Why a run ended. */
29762
+ var NodeBenchmarkEndReasonSchema = _enum([
29763
+ "completed",
29764
+ "operator-abort",
29765
+ "deadline",
29766
+ "node-lost",
29767
+ "runner-lost",
29768
+ "hub-restart",
29769
+ "drain-timeout",
29770
+ "failed"
29771
+ ]);
29772
+ var NodeBenchmarkRunSchema = object({
29773
+ runId: string(),
29774
+ nodeId: string(),
29775
+ state: NodeBenchmarkStateSchema,
29776
+ plan: NodeBenchmarkPlanSchema,
29777
+ startedAtMs: number(),
29778
+ deadlineAtMs: number(),
29779
+ finishedAtMs: number().nullable(),
29780
+ endReason: NodeBenchmarkEndReasonSchema.nullable(),
29781
+ error: string().nullable(),
29782
+ /** Cameras moved off the node for the run. */
29783
+ moved: array(number()).readonly(),
29784
+ /** Cameras that stayed (their only frame source is the node). */
29785
+ staying: array(number()).readonly(),
29786
+ /** Something else ran on the node's pools during the run. */
29787
+ contaminated: boolean(),
29788
+ progress: NodeBenchProgressSchema.nullable(),
29789
+ resultIds: array(string()).readonly()
29790
+ });
29791
+ /** `getNodeBenchmarkStatus`: the active run (or the last one), and whether benchmark mode is on. */
29792
+ var NodeBenchmarkStatusSchema = object({
29793
+ /** The node the cluster is in benchmark mode for; null = none. */
29794
+ modeNodeId: string().nullable(),
29795
+ run: NodeBenchmarkRunSchema.nullable()
29796
+ });
29797
+ /**
29798
+ * One stored measurement — the only authority Auto tune and the automatic
29799
+ * shares read measured capacity from. Written by the orchestrator when a run
29800
+ * ends, never by anyone else.
29801
+ */
29802
+ var NodeBenchmarkResultSchema = object({
29803
+ id: string(),
29804
+ runId: string(),
29805
+ nodeId: string(),
29806
+ cell: NodeBenchCellSchema,
29807
+ fpsPerStream: number(),
29808
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
29809
+ clip: NodeBenchClipSchema.nullable(),
29810
+ /** Other work shared the node's pools (a camera that could not move, or the hub's own duties). */
29811
+ contaminated: boolean(),
29812
+ stayingCameras: array(number()).readonly(),
29813
+ /** The run ended early; the cell itself completed. */
29814
+ partialRun: boolean(),
29815
+ measuredAtMs: number()
29816
+ });
29817
+ var ListNodeBenchmarkResultsInputSchema = object({
29818
+ nodeId: string().optional(),
29819
+ deviceKey: string().optional()
29820
+ });
29821
+ /** A result with its standing today: does it still beat the table? */
29822
+ var NodeBenchmarkResultViewSchema = NodeBenchmarkResultSchema.extend({
29823
+ /** `fresh` beats the table; `stale` falls back to it; `superseded` = a newer row covers the same cell. */
29824
+ standing: _enum([
29825
+ "fresh",
29826
+ "stale",
29827
+ "superseded"
29828
+ ]),
29829
+ staleWhy: _enum([
29830
+ "age",
29831
+ "runtime",
29832
+ "pool-tuning"
29833
+ ]).nullable()
29834
+ });
29835
+ object({
29836
+ runId: string(),
29837
+ nodeId: string(),
29838
+ startedAtMs: number(),
29839
+ deadlineAtMs: number(),
29840
+ plan: NodeBenchmarkPlanSchema,
29841
+ moved: array(number()).readonly(),
29842
+ staying: array(number()).readonly()
29843
+ });
29844
+ /** Candidate detectors per device, for the plan editor. */
29845
+ var NodeBenchmarkCandidatesSchema = object({
29846
+ nodeId: string(),
29847
+ reachable: boolean(),
29848
+ devices: array(object({
29849
+ deviceKey: string(),
29850
+ enabled: boolean(),
29851
+ available: boolean(),
29852
+ /** Ordered: what Auto tune would pick first, then the rest of the family by accuracy. */
29853
+ suggested: array(string()).readonly(),
29854
+ /** Every root detector the device has a build for. */
29855
+ all: array(string()).readonly(),
29856
+ /** The model the device runs now, when pinned. */
29857
+ currentModelId: string().nullable()
29858
+ })).readonly(),
29859
+ /** Detail steps the node's catalog offers under the root (for the `pipeline` measurement). */
29860
+ steps: array(object({
29861
+ id: string(),
29862
+ name: string(),
29863
+ slot: string()
29864
+ })).readonly()
29865
+ });
28284
29866
  object({
28285
29867
  activeCameras: number(),
28286
29868
  throttledCameras: number(),
@@ -29599,7 +31181,30 @@ var pipelineRunnerCapability = {
29599
31181
  releaseParkedTrackFrames: method(object({
29600
31182
  deviceId: number(),
29601
31183
  trackId: string()
29602
- }), object({ released: number().int().nonnegative() }), { kind: "mutation" })
31184
+ }), object({ released: number().int().nonnegative() }), { kind: "mutation" }),
31185
+ /**
31186
+ * Start measuring THIS node for the orchestrator's node benchmark: the
31187
+ * bench clip decoded once into RAM, each device × candidate detector on an
31188
+ * open-loop ramp (`device`), then the chosen pipeline with the requested
31189
+ * detail steps (`pipeline`). Everything runs in-process with the executor
31190
+ * — no frame crosses a node (D9) — and writes nothing: no track, event,
31191
+ * media or notification. Reached by `nodePin(nodeId)`. Answers at once;
31192
+ * one run per node; the run stops itself at `deadlineAtMs`.
31193
+ */
31194
+ startNodeBench: method(NodeBenchRunnerInputSchema, object({
31195
+ accepted: literal(true),
31196
+ runId: string()
31197
+ }), {
31198
+ kind: "mutation",
31199
+ auth: "admin"
31200
+ }),
31201
+ /** The run's progress and every finished cell; null when this runner does not know `runId`. */
31202
+ getNodeBenchStatus: method(object({ runId: string() }), NodeBenchRunnerStatusSchema.nullable(), { auth: "admin" }),
31203
+ /** Stop the run; what it finished is kept. */
31204
+ abortNodeBench: method(object({ runId: string() }), object({ aborted: boolean() }), {
31205
+ kind: "mutation",
31206
+ auth: "admin"
31207
+ })
29603
31208
  }
29604
31209
  };
29605
31210
  var CameraPipelineConfigSchema = object({
@@ -30527,6 +32132,51 @@ var pipelineOrchestratorCapability = {
30527
32132
  kind: "mutation",
30528
32133
  auth: "admin"
30529
32134
  }),
32135
+ /**
32136
+ * Node benchmark — what a run of this plan would do, without doing it:
32137
+ * the cameras that leave the node, those that cannot (the node is their
32138
+ * only frame source; they stay and flag the run), the estimated duration
32139
+ * and every reason it may not start. The confirmation shows this.
32140
+ */
32141
+ getNodeBenchmarkPreflight: method(NodeBenchmarkPlanSchema, NodeBenchmarkPreflightSchema, { auth: "admin" }),
32142
+ /**
32143
+ * Node benchmark — start ONE run (cluster-wide lock). The orchestrator
32144
+ * persists a restore manifest, enters benchmark mode for the node (out of
32145
+ * placement, its camera pins ignored, nothing rewritten), drains it, drives
32146
+ * the node's own runner, then restores — always, including after an
32147
+ * abort, a lost node or a hub restart. Answers at once; poll
32148
+ * `getNodeBenchmarkStatus`. Refused runs carry the preflight.
32149
+ */
32150
+ startNodeBenchmark: method(NodeBenchmarkPlanSchema, discriminatedUnion("kind", [object({
32151
+ kind: literal("started"),
32152
+ runId: string()
32153
+ }), object({
32154
+ kind: literal("refused"),
32155
+ preflight: NodeBenchmarkPreflightSchema
32156
+ })]), {
32157
+ kind: "mutation",
32158
+ auth: "admin"
32159
+ }),
32160
+ /** Node benchmark — the active run (or the last one) and the node in benchmark mode. */
32161
+ getNodeBenchmarkStatus: method(_void(), NodeBenchmarkStatusSchema, { auth: "admin" }),
32162
+ /** Node benchmark — stop the active run; the cluster is restored as it was. */
32163
+ abortNodeBenchmark: method(object({ runId: string() }), object({ aborted: boolean() }), {
32164
+ kind: "mutation",
32165
+ auth: "admin"
32166
+ }),
32167
+ /**
32168
+ * Node benchmark — root detector candidates per device (what Auto tune
32169
+ * would pick first, then the family) and the detail steps the node's
32170
+ * catalog offers, for the plan editor.
32171
+ */
32172
+ getNodeBenchmarkCandidates: method(object({ nodeId: string() }), NodeBenchmarkCandidatesSchema, { auth: "admin" }),
32173
+ /** Node benchmark — stored results, newest first, each with its standing today. */
32174
+ listNodeBenchmarkResults: method(ListNodeBenchmarkResultsInputSchema, array(NodeBenchmarkResultViewSchema).readonly(), { auth: "admin" }),
32175
+ /** Node benchmark — delete one result; Auto tune and the shares stop reading it. */
32176
+ deleteNodeBenchmarkResult: method(object({ id: string() }), object({ deleted: boolean() }), {
32177
+ kind: "mutation",
32178
+ auth: "admin"
32179
+ }),
30530
32180
  /** Read one camera's settings. Null when never touched (inherits agent defaults fully). */
30531
32181
  getCameraSettings: method(object({ deviceId: number() }), CameraPipelineSettingsSchema.nullable()),
30532
32182
  /** Set or clear the 3-state toggle for one (camera, addonId). Pass `enabled: null` to clear and revert to agent default. */
@@ -37943,6 +39593,9 @@ var CreateIntegrationInputSchema = object({
37943
39593
  enabled: boolean().optional(),
37944
39594
  info: record(string(), unknown()).optional(),
37945
39595
  settings: record(string(), unknown()).optional(),
39596
+ /** Keys of `settings` the form's schema declares secret (by type) — kept in
39597
+ * the keychain, not the table (D787). */
39598
+ secretKeys: array(string()).optional(),
37946
39599
  skipRestart: boolean().optional()
37947
39600
  });
37948
39601
  var UpdateIntegrationInputSchema = object({
@@ -37978,7 +39631,9 @@ var integrationsCapability = {
37978
39631
  getSettings: method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }),
37979
39632
  setSettings: method(object({
37980
39633
  id: string(),
37981
- settings: record(string(), unknown())
39634
+ settings: record(string(), unknown()),
39635
+ /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
39636
+ secretKeys: array(string()).optional()
37982
39637
  }), object({ success: boolean() }), {
37983
39638
  kind: "mutation",
37984
39639
  auth: "admin"
@@ -49633,6 +51288,90 @@ Object.freeze({
49633
51288
  addonId: null,
49634
51289
  access: "create"
49635
51290
  },
51291
+ "keychain.delete": {
51292
+ capName: "keychain",
51293
+ capScope: "system",
51294
+ addonId: null,
51295
+ access: "delete"
51296
+ },
51297
+ "keychain.getState": {
51298
+ capName: "keychain",
51299
+ capScope: "system",
51300
+ addonId: null,
51301
+ access: "view"
51302
+ },
51303
+ "keychain.listMeta": {
51304
+ capName: "keychain",
51305
+ capScope: "system",
51306
+ addonId: null,
51307
+ access: "view"
51308
+ },
51309
+ "keychain.put": {
51310
+ capName: "keychain",
51311
+ capScope: "system",
51312
+ addonId: null,
51313
+ access: "create"
51314
+ },
51315
+ "keychain.resolve": {
51316
+ capName: "keychain",
51317
+ capScope: "system",
51318
+ addonId: null,
51319
+ access: "view"
51320
+ },
51321
+ "keychainAdmin.deleteOrphans": {
51322
+ capName: "keychain-admin",
51323
+ capScope: "system",
51324
+ addonId: null,
51325
+ access: "delete"
51326
+ },
51327
+ "keychainAdmin.downloadRecoveryKey": {
51328
+ capName: "keychain-admin",
51329
+ capScope: "system",
51330
+ addonId: null,
51331
+ access: "create"
51332
+ },
51333
+ "keychainAdmin.listAudit": {
51334
+ capName: "keychain-admin",
51335
+ capScope: "system",
51336
+ addonId: null,
51337
+ access: "view"
51338
+ },
51339
+ "keychainAdmin.listSecrets": {
51340
+ capName: "keychain-admin",
51341
+ capScope: "system",
51342
+ addonId: null,
51343
+ access: "view"
51344
+ },
51345
+ "keychainAdmin.purgeRetiredKeys": {
51346
+ capName: "keychain-admin",
51347
+ capScope: "system",
51348
+ addonId: null,
51349
+ access: "delete"
51350
+ },
51351
+ "keychainAdmin.resetKeychain": {
51352
+ capName: "keychain-admin",
51353
+ capScope: "system",
51354
+ addonId: null,
51355
+ access: "delete"
51356
+ },
51357
+ "keychainAdmin.reveal": {
51358
+ capName: "keychain-admin",
51359
+ capScope: "system",
51360
+ addonId: null,
51361
+ access: "create"
51362
+ },
51363
+ "keychainAdmin.rotateMasterKey": {
51364
+ capName: "keychain-admin",
51365
+ capScope: "system",
51366
+ addonId: null,
51367
+ access: "create"
51368
+ },
51369
+ "keychainAdmin.status": {
51370
+ capName: "keychain-admin",
51371
+ capScope: "system",
51372
+ addonId: null,
51373
+ access: "view"
51374
+ },
49636
51375
  "lawnMowerControl.dock": {
49637
51376
  capName: "lawn-mower-control",
49638
51377
  capScope: "device",
@@ -51007,6 +52746,18 @@ Object.freeze({
51007
52746
  addonId: null,
51008
52747
  access: "create"
51009
52748
  },
52749
+ "pipelineAnalytics.addRetrainFrameFromRecording": {
52750
+ capName: "pipeline-analytics",
52751
+ capScope: "device",
52752
+ addonId: null,
52753
+ access: "create"
52754
+ },
52755
+ "pipelineAnalytics.addRetrainFramesToCollection": {
52756
+ capName: "pipeline-analytics",
52757
+ capScope: "device",
52758
+ addonId: null,
52759
+ access: "create"
52760
+ },
51010
52761
  "pipelineAnalytics.applyDeviceSettingsPatch": {
51011
52762
  capName: "pipeline-analytics",
51012
52763
  capScope: "device",
@@ -51055,12 +52806,24 @@ Object.freeze({
51055
52806
  addonId: null,
51056
52807
  access: "view"
51057
52808
  },
52809
+ "pipelineAnalytics.createRetrainCollection": {
52810
+ capName: "pipeline-analytics",
52811
+ capScope: "device",
52812
+ addonId: null,
52813
+ access: "create"
52814
+ },
51058
52815
  "pipelineAnalytics.deleteDeviceEvents": {
51059
52816
  capName: "pipeline-analytics",
51060
52817
  capScope: "device",
51061
52818
  addonId: null,
51062
52819
  access: "delete"
51063
52820
  },
52821
+ "pipelineAnalytics.deleteRetrainCollection": {
52822
+ capName: "pipeline-analytics",
52823
+ capScope: "device",
52824
+ addonId: null,
52825
+ access: "delete"
52826
+ },
51064
52827
  "pipelineAnalytics.deleteTracks": {
51065
52828
  capName: "pipeline-analytics",
51066
52829
  capScope: "device",
@@ -51265,6 +53028,24 @@ Object.freeze({
51265
53028
  addonId: null,
51266
53029
  access: "view"
51267
53030
  },
53031
+ "pipelineAnalytics.listRetrainAssistProfiles": {
53032
+ capName: "pipeline-analytics",
53033
+ capScope: "device",
53034
+ addonId: null,
53035
+ access: "view"
53036
+ },
53037
+ "pipelineAnalytics.listRetrainCollectionFrames": {
53038
+ capName: "pipeline-analytics",
53039
+ capScope: "device",
53040
+ addonId: null,
53041
+ access: "view"
53042
+ },
53043
+ "pipelineAnalytics.listRetrainCollections": {
53044
+ capName: "pipeline-analytics",
53045
+ capScope: "device",
53046
+ addonId: null,
53047
+ access: "view"
53048
+ },
51268
53049
  "pipelineAnalytics.listRetrainFrames": {
51269
53050
  capName: "pipeline-analytics",
51270
53051
  capScope: "device",
@@ -51313,6 +53094,12 @@ Object.freeze({
51313
53094
  addonId: null,
51314
53095
  access: "create"
51315
53096
  },
53097
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": {
53098
+ capName: "pipeline-analytics",
53099
+ capScope: "device",
53100
+ addonId: null,
53101
+ access: "create"
53102
+ },
51316
53103
  "pipelineAnalytics.pruneEvents": {
51317
53104
  capName: "pipeline-analytics",
51318
53105
  capScope: "device",
@@ -51367,6 +53154,18 @@ Object.freeze({
51367
53154
  addonId: null,
51368
53155
  access: "create"
51369
53156
  },
53157
+ "pipelineAnalytics.removeRetrainFrameFromCollection": {
53158
+ capName: "pipeline-analytics",
53159
+ capScope: "device",
53160
+ addonId: null,
53161
+ access: "delete"
53162
+ },
53163
+ "pipelineAnalytics.renameRetrainCollection": {
53164
+ capName: "pipeline-analytics",
53165
+ capScope: "device",
53166
+ addonId: null,
53167
+ access: "create"
53168
+ },
51370
53169
  "pipelineAnalytics.restageRetrainTrack": {
51371
53170
  capName: "pipeline-analytics",
51372
53171
  capScope: "device",
@@ -51655,6 +53454,12 @@ Object.freeze({
51655
53454
  addonId: null,
51656
53455
  access: "view"
51657
53456
  },
53457
+ "pipelineOrchestrator.abortNodeBenchmark": {
53458
+ capName: "pipeline-orchestrator",
53459
+ capScope: "system",
53460
+ addonId: null,
53461
+ access: "create"
53462
+ },
51658
53463
  "pipelineOrchestrator.applyAutoTune": {
51659
53464
  capName: "pipeline-orchestrator",
51660
53465
  capScope: "system",
@@ -51679,6 +53484,12 @@ Object.freeze({
51679
53484
  addonId: null,
51680
53485
  access: "create"
51681
53486
  },
53487
+ "pipelineOrchestrator.deleteNodeBenchmarkResult": {
53488
+ capName: "pipeline-orchestrator",
53489
+ capScope: "system",
53490
+ addonId: null,
53491
+ access: "delete"
53492
+ },
51682
53493
  "pipelineOrchestrator.getAgentLoad": {
51683
53494
  capName: "pipeline-orchestrator",
51684
53495
  capScope: "system",
@@ -51787,6 +53598,24 @@ Object.freeze({
51787
53598
  addonId: null,
51788
53599
  access: "view"
51789
53600
  },
53601
+ "pipelineOrchestrator.getNodeBenchmarkCandidates": {
53602
+ capName: "pipeline-orchestrator",
53603
+ capScope: "system",
53604
+ addonId: null,
53605
+ access: "view"
53606
+ },
53607
+ "pipelineOrchestrator.getNodeBenchmarkPreflight": {
53608
+ capName: "pipeline-orchestrator",
53609
+ capScope: "system",
53610
+ addonId: null,
53611
+ access: "view"
53612
+ },
53613
+ "pipelineOrchestrator.getNodeBenchmarkStatus": {
53614
+ capName: "pipeline-orchestrator",
53615
+ capScope: "system",
53616
+ addonId: null,
53617
+ access: "view"
53618
+ },
51790
53619
  "pipelineOrchestrator.getNodeInferenceDevices": {
51791
53620
  capName: "pipeline-orchestrator",
51792
53621
  capScope: "system",
@@ -51829,6 +53658,12 @@ Object.freeze({
51829
53658
  addonId: null,
51830
53659
  access: "view"
51831
53660
  },
53661
+ "pipelineOrchestrator.listNodeBenchmarkResults": {
53662
+ capName: "pipeline-orchestrator",
53663
+ capScope: "system",
53664
+ addonId: null,
53665
+ access: "view"
53666
+ },
51832
53667
  "pipelineOrchestrator.pauseForStorageMigration": {
51833
53668
  capName: "pipeline-orchestrator",
51834
53669
  capScope: "system",
@@ -51973,6 +53808,12 @@ Object.freeze({
51973
53808
  addonId: null,
51974
53809
  access: "create"
51975
53810
  },
53811
+ "pipelineOrchestrator.startNodeBenchmark": {
53812
+ capName: "pipeline-orchestrator",
53813
+ capScope: "system",
53814
+ addonId: null,
53815
+ access: "create"
53816
+ },
51976
53817
  "pipelineOrchestrator.suggestShares": {
51977
53818
  capName: "pipeline-orchestrator",
51978
53819
  capScope: "system",
@@ -51991,6 +53832,12 @@ Object.freeze({
51991
53832
  addonId: null,
51992
53833
  access: "create"
51993
53834
  },
53835
+ "pipelineRunner.abortNodeBench": {
53836
+ capName: "pipeline-runner",
53837
+ capScope: "system",
53838
+ addonId: null,
53839
+ access: "create"
53840
+ },
51994
53841
  "pipelineRunner.attachCamera": {
51995
53842
  capName: "pipeline-runner",
51996
53843
  capScope: "system",
@@ -52039,6 +53886,12 @@ Object.freeze({
52039
53886
  addonId: null,
52040
53887
  access: "view"
52041
53888
  },
53889
+ "pipelineRunner.getNodeBenchStatus": {
53890
+ capName: "pipeline-runner",
53891
+ capScope: "system",
53892
+ addonId: null,
53893
+ access: "view"
53894
+ },
52042
53895
  "pipelineRunner.getParkedTrackFrame": {
52043
53896
  capName: "pipeline-runner",
52044
53897
  capScope: "system",
@@ -52081,6 +53934,12 @@ Object.freeze({
52081
53934
  addonId: null,
52082
53935
  access: "create"
52083
53936
  },
53937
+ "pipelineRunner.startNodeBench": {
53938
+ capName: "pipeline-runner",
53939
+ capScope: "system",
53940
+ addonId: null,
53941
+ access: "create"
53942
+ },
52084
53943
  "plateGallery.assignPlate": {
52085
53944
  capName: "plate-gallery",
52086
53945
  capScope: "system",
@@ -55760,6 +57619,8 @@ var ALL_CAPABILITY_DEFINITIONS = [
55760
57619
  imageSettingsCapability,
55761
57620
  integrationsCapability,
55762
57621
  intercomCapability,
57622
+ keychainCapability,
57623
+ keychainAdminCapability,
55763
57624
  lawnMowerControlCapability,
55764
57625
  llmCapability,
55765
57626
  llmRuntimeCapability,
@@ -57186,6 +59047,11 @@ Object.freeze({
57186
59047
  form: "single",
57187
59048
  optional: false
57188
59049
  }],
59050
+ "pipelineAnalytics.addRetrainFrameFromRecording": [{
59051
+ name: "deviceId",
59052
+ form: "single",
59053
+ optional: false
59054
+ }],
57189
59055
  "pipelineAnalytics.applyDeviceSettingsPatch": [{
57190
59056
  name: "deviceId",
57191
59057
  form: "single",
@@ -57376,6 +59242,11 @@ Object.freeze({
57376
59242
  form: "single",
57377
59243
  optional: false
57378
59244
  }],
59245
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": [{
59246
+ name: "deviceId",
59247
+ form: "single",
59248
+ optional: false
59249
+ }],
57379
59250
  "pipelineAnalytics.pruneEventsBefore": [{
57380
59251
  name: "deviceId",
57381
59252
  form: "single",