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