@camstack/addon-matter-broker 0.2.122 → 0.2.123

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/addon.js +1845 -56
  2. package/dist/addon.mjs +1845 -56
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -13,7 +13,7 @@ let node_stream_promises = require("node:stream/promises");
13
13
  let node_net = require("node:net");
14
14
  let node_dgram = require("node:dgram");
15
15
  node_dgram = require_esm.__toESM(node_dgram, 1);
16
- //#region ../types/dist/event-category-B_0XEcLF.mjs
16
+ //#region ../types/dist/event-category-DaIZi00R.mjs
17
17
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
18
18
  EventCategory["SystemBoot"] = "system.boot";
19
19
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -92,6 +92,13 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
92
92
  */
93
93
  EventCategory["AddonLoadFailed"] = "addon.load-failed";
94
94
  /**
95
+ * A keychain value was stored or removed (D787). Carries the ref, its
96
+ * owner and the new version — NEVER the value. A process holding the ref
97
+ * drops its cached copy and the owning `BaseAddon` re-resolves its config.
98
+ * Telemetry (D8): a process that misses it still revalidates by version.
99
+ */
100
+ EventCategory["KeychainChanged"] = "keychain.changed";
101
+ /**
95
102
  * Addon recovered from a previous failure. Emitted when an addon
96
103
  * transitions from `failed` back to `healthy` (typically via the
97
104
  * monitor's auto-retry loop, or after manual `addons.retryLoad`).
@@ -5384,7 +5391,7 @@ var ZodIssueCode = {
5384
5391
  var ZodFirstPartyTypeKind;
5385
5392
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5386
5393
  //#endregion
5387
- //#region ../types/dist/sleep-B0JG7-_F.mjs
5394
+ //#region ../types/dist/sleep-Cr5YOk3m.mjs
5388
5395
  /**
5389
5396
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5390
5397
  * window to float samples (D455).
@@ -5463,6 +5470,97 @@ function buildAlawTable() {
5463
5470
  }
5464
5471
  buildUlawTable();
5465
5472
  buildAlawTable();
5473
+ /** Is this field's stored value a credential? */
5474
+ function isSecretConfigField(field) {
5475
+ if (field.type === "password") return true;
5476
+ return "secret" in field && field.secret === true;
5477
+ }
5478
+ /**
5479
+ * Is this field's value stored in the KEYCHAIN (D787)? Every secret field is,
5480
+ * by its TYPE, unless it opts out with `storage: 'inline'` — never by its name.
5481
+ */
5482
+ function isKeychainStoredField(field) {
5483
+ if (!isSecretConfigField(field)) return false;
5484
+ if (field.type === "textarea" && field.isJson === true) return false;
5485
+ return !("storage" in field && field.storage === "inline");
5486
+ }
5487
+ /**
5488
+ * What a settings blob holds where a secret used to be.
5489
+ *
5490
+ * A keychain-stored field never holds its value. It holds a self-describing
5491
+ * MARKER, `{"$secret":"secret://…","v":1}` — an object, never a string, so no
5492
+ * code can mistake it for a credential and no form can send it to a camera as
5493
+ * a password. The empty state is `null` / absent, never `''`.
5494
+ *
5495
+ * The same shapes travel to and from the admin UI:
5496
+ *
5497
+ * - read: `hydrateSchema` hands a secret field a {@link SecretFieldView}
5498
+ * (`{ $secret, v, set: true }`) or `null` — the browser learns whether a
5499
+ * value is set, never the value.
5500
+ * - write: an untouched field submits the view back unchanged (KEEP); a typed
5501
+ * value is a plain non-empty string (CHANGE); the Clear button submits
5502
+ * {@link SECRET_CLEAR} (CLEAR). `''`, `null` and the legacy redaction tokens
5503
+ * are KEEP — an empty string is what a defaults-fallback pushes back, and
5504
+ * treating it as "clear" is how a save destroyed a stored credential before.
5505
+ *
5506
+ * Pure and browser-safe.
5507
+ */
5508
+ var SECRET_CLEAR = { $secretClear: true };
5509
+ /** The `'***'` token D634 redaction writes for non-admins. */
5510
+ var LEGACY_DEVICE_REDACTION = "***";
5511
+ function isRecord$1$1(value) {
5512
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5513
+ }
5514
+ function makeSecretMarker(ref) {
5515
+ return {
5516
+ $secret: ref,
5517
+ v: 1
5518
+ };
5519
+ }
5520
+ /** A stored marker: an object whose `$secret` is a non-empty string. */
5521
+ function isSecretMarker(value) {
5522
+ if (!isRecord$1$1(value)) return false;
5523
+ const ref = value["$secret"];
5524
+ return typeof ref === "string" && ref.length > 0;
5525
+ }
5526
+ function isSecretClear(value) {
5527
+ return isRecord$1$1(value) && value["$secretClear"] === true;
5528
+ }
5529
+ /**
5530
+ * The UI view of a stored secret field value: a marker becomes "set", inline
5531
+ * plaintext becomes "set (inline)", nothing becomes `null`. A value never
5532
+ * survives this function.
5533
+ */
5534
+ function toSecretFieldView(stored) {
5535
+ if (isSecretMarker(stored)) return {
5536
+ $secret: stored.$secret,
5537
+ v: 1,
5538
+ set: true
5539
+ };
5540
+ if (typeof stored === "string" && stored.length > 0) return {
5541
+ $secret: null,
5542
+ v: 1,
5543
+ set: true,
5544
+ inline: true
5545
+ };
5546
+ return null;
5547
+ }
5548
+ /**
5549
+ * Classify an incoming value for a secret path. Only a non-empty string that is
5550
+ * not a redaction token sets a value; only {@link SECRET_CLEAR} clears.
5551
+ * Everything else — a marker (ours or anyone's), a UI view, `''`, `null`,
5552
+ * `undefined`, a redaction token, a non-string — keeps what is stored.
5553
+ */
5554
+ function classifySecretWrite(incoming) {
5555
+ if (isSecretClear(incoming)) return { kind: "clear" };
5556
+ if (typeof incoming !== "string") return { kind: "keep" };
5557
+ if (incoming.length === 0) return { kind: "keep" };
5558
+ if (incoming === "__camstack_redacted__" || incoming === LEGACY_DEVICE_REDACTION) return { kind: "keep" };
5559
+ return {
5560
+ kind: "set",
5561
+ value: incoming
5562
+ };
5563
+ }
5466
5564
  Object.fromEntries([
5467
5565
  {
5468
5566
  id: "overview",
@@ -5634,33 +5732,19 @@ Object.fromEntries([
5634
5732
  function isValuelessField(field) {
5635
5733
  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";
5636
5734
  }
5637
- /**
5638
- * Merge a `ConfigUISchema` with a raw `values` record into a
5639
- * `ConfigUISchemaWithValues`. Used by every `get*Settings` backend endpoint
5640
- * before returning to the admin UI. Groups are walked recursively.
5641
- *
5642
- * For each leaf field:
5643
- * - structural fields (`separator`, `info`, `button`) pass through unchanged
5644
- * - other fields get `value = values[key] ?? field.default ?? null`
5645
- *
5646
- * Unknown keys in `values` (keys not declared in the schema) are silently
5647
- * ignored — they don't contribute to the output. Missing keys fall back to
5648
- * the schema default or `null`. This mirrors the old backend behaviour where
5649
- * `FormBuilder` rendered `values[key] ?? field.default`.
5650
- */
5651
- function hydrateSchema(schema, values) {
5735
+ function hydrateSchema(schema, values, options = {}) {
5652
5736
  return {
5653
5737
  ...schema.tabs ? { tabs: [...schema.tabs] } : {},
5654
5738
  sections: schema.sections.map((section) => ({
5655
5739
  ...section,
5656
- fields: section.fields.map((field) => hydrateField(field, values))
5740
+ fields: section.fields.map((field) => hydrateField(field, values, options))
5657
5741
  }))
5658
5742
  };
5659
5743
  }
5660
- function hydrateField(field, values) {
5744
+ function hydrateField(field, values, options) {
5661
5745
  if (isValuelessField(field)) return field;
5662
5746
  if (field.type === "group") {
5663
- const hydratedChildren = field.fields.map((child) => hydrateField(child, values));
5747
+ const hydratedChildren = field.fields.map((child) => hydrateField(child, values, options));
5664
5748
  return {
5665
5749
  ...field,
5666
5750
  fields: hydratedChildren
@@ -5669,7 +5753,7 @@ function hydrateField(field, values) {
5669
5753
  if (field.type === "sub-tabs") {
5670
5754
  const hydratedTabs = field.tabs.map((tab) => ({
5671
5755
  ...tab,
5672
- fields: tab.fields.map((child) => hydrateField(child, values))
5756
+ fields: tab.fields.map((child) => hydrateField(child, values, options))
5673
5757
  }));
5674
5758
  return {
5675
5759
  ...field,
@@ -5679,6 +5763,33 @@ function hydrateField(field, values) {
5679
5763
  const key = field.key;
5680
5764
  const storedValue = Object.prototype.hasOwnProperty.call(values, key) ? values[key] : void 0;
5681
5765
  const defaultValue = field.default;
5766
+ const asView = (v) => isSecretMarker(v) || options.inlineSecretsAsViews === true && v !== void 0;
5767
+ if (isKeychainStoredField(field) && asView(storedValue)) return {
5768
+ ...field,
5769
+ value: toSecretFieldView(storedValue)
5770
+ };
5771
+ if (isKeychainStoredField(field) && options.inlineSecretsAsViews === true) return {
5772
+ ...field,
5773
+ value: null
5774
+ };
5775
+ if (field.type === "editable-array" && Array.isArray(storedValue)) {
5776
+ const secretItemKeys = field.itemFields.filter((item) => "key" in item && isKeychainStoredField(item)).map((item) => "key" in item ? item.key : "");
5777
+ if (secretItemKeys.length > 0) {
5778
+ const rows = storedValue.map((row) => {
5779
+ if (row === null || typeof row !== "object" || Array.isArray(row)) return row;
5780
+ const out = { ...row };
5781
+ for (const k of secretItemKeys) {
5782
+ const v = Reflect.get(row, k);
5783
+ if (asView(v)) out[k] = toSecretFieldView(v);
5784
+ }
5785
+ return out;
5786
+ });
5787
+ return {
5788
+ ...field,
5789
+ value: rows
5790
+ };
5791
+ }
5792
+ }
5682
5793
  if (field.multiple) {
5683
5794
  const stored = Array.isArray(storedValue) ? storedValue : storedValue !== void 0 && storedValue !== null ? [storedValue] : [];
5684
5795
  const itemFallback = field.multiple.itemDefault !== void 0 ? field.multiple.itemDefault : defaultValue !== void 0 ? defaultValue : typeOf(field) === "string" ? "" : null;
@@ -5921,6 +6032,431 @@ function projectStore(store, perNodeKeys, nodeId) {
5921
6032
  }
5922
6033
  return out;
5923
6034
  }
6035
+ var GLOBAL_SCOPE = { kind: "global" };
6036
+ /** The scope every addon-wide (not per-node, not per-device) setting lives in. */
6037
+ function globalSecretScope() {
6038
+ return GLOBAL_SCOPE;
6039
+ }
6040
+ function encodeSegment(value) {
6041
+ return encodeURIComponent(value);
6042
+ }
6043
+ /**
6044
+ * The field path of a value inside an array item, addressed by the item's id:
6045
+ * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
6046
+ * `providers[authentik].clientSecret`.
6047
+ */
6048
+ function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6049
+ return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6050
+ }
6051
+ /** A write to a secret path could not be stored in the keychain, so it was refused. */
6052
+ var KeychainWriteRefusedError = class extends Error {
6053
+ fieldPath;
6054
+ constructor(fieldPath, cause) {
6055
+ super(`secret "${fieldPath}" was not saved: the keychain could not store it (${cause instanceof Error ? cause.message : String(cause)}). Nothing was written.`);
6056
+ this.fieldPath = fieldPath;
6057
+ this.name = "KeychainWriteRefusedError";
6058
+ }
6059
+ };
6060
+ var KEEP = { kind: "keep" };
6061
+ function isRecord$2(value) {
6062
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6063
+ }
6064
+ function defaultMintId() {
6065
+ return globalThis.crypto.randomUUID();
6066
+ }
6067
+ /** Every marker ref anywhere under `value`. */
6068
+ function collectSecretMarkerRefs(value, out = []) {
6069
+ if (isSecretMarker(value)) {
6070
+ out.push(value.$secret);
6071
+ return out;
6072
+ }
6073
+ if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6074
+ else if (isRecord$2(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6075
+ return out;
6076
+ }
6077
+ async function storedValueEquals(secrets, marker, candidate) {
6078
+ const resolved = (await secrets.resolve([marker.$secret]))[marker.$secret];
6079
+ return resolved?.kind === "value" && resolved.value === candidate;
6080
+ }
6081
+ async function writeLeaf(ctx, incoming, stored, fieldPath) {
6082
+ const intent = classifySecretWrite(incoming);
6083
+ const ref = ctx.secrets.ref(ctx.scope, fieldPath);
6084
+ const storedIsOurs = isSecretMarker(stored) && stored.$secret === ref;
6085
+ if (intent.kind === "keep") return KEEP;
6086
+ if (intent.kind === "set" && !ctx.operatorWrite && typeof stored === "string" && stored === intent.value) return KEEP;
6087
+ if (intent.kind === "clear") {
6088
+ if (storedIsOurs) ctx.deletes.push(ref);
6089
+ return {
6090
+ kind: "value",
6091
+ value: null
6092
+ };
6093
+ }
6094
+ if (storedIsOurs && await storedValueEquals(ctx.secrets, stored, intent.value)) return {
6095
+ kind: "value",
6096
+ value: stored
6097
+ };
6098
+ try {
6099
+ await ctx.secrets.put(ref, intent.value);
6100
+ } catch (err) {
6101
+ throw new KeychainWriteRefusedError(fieldPath, err);
6102
+ }
6103
+ return {
6104
+ kind: "value",
6105
+ value: makeSecretMarker(ref)
6106
+ };
6107
+ }
6108
+ /** Apply a member result onto `out`: KEEP restores the stored member, or removes it. */
6109
+ function applyMember(out, key, result, storedParent) {
6110
+ if (result.kind === "value") {
6111
+ out[key] = result.value;
6112
+ return;
6113
+ }
6114
+ if (Object.prototype.hasOwnProperty.call(storedParent, key)) out[key] = storedParent[key];
6115
+ else delete out[key];
6116
+ }
6117
+ async function writeMembers(ctx, children, incoming, stored, pathOf) {
6118
+ const out = { ...incoming };
6119
+ for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
6120
+ return out;
6121
+ }
6122
+ function rowId(row, idKey) {
6123
+ const raw = row[idKey];
6124
+ if (typeof raw === "string" && raw.length > 0) return raw;
6125
+ if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
6126
+ return null;
6127
+ }
6128
+ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6129
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$2) : [];
6130
+ if (!Array.isArray(incoming)) {
6131
+ ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6132
+ return {
6133
+ kind: "value",
6134
+ value: incoming
6135
+ };
6136
+ }
6137
+ const storedById = /* @__PURE__ */ new Map();
6138
+ for (const row of storedRows) {
6139
+ const id = rowId(row, node.idKey);
6140
+ if (id !== null) storedById.set(id, row);
6141
+ }
6142
+ const kept = /* @__PURE__ */ new Set();
6143
+ const rows = [];
6144
+ for (const row of incoming) {
6145
+ if (!isRecord$2(row)) {
6146
+ rows.push(row);
6147
+ continue;
6148
+ }
6149
+ const id = rowId(row, node.idKey) ?? ctx.mintId();
6150
+ kept.add(id);
6151
+ const withId = {
6152
+ ...row,
6153
+ [node.idKey]: row[node.idKey] ?? id
6154
+ };
6155
+ if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
6156
+ const storedRow = storedById.get(id) ?? {};
6157
+ rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
6158
+ }
6159
+ for (const [id, row] of storedById) if (!kept.has(id)) ctx.deletes.push(...collectSecretMarkerRefs(row));
6160
+ return {
6161
+ kind: "value",
6162
+ value: rows
6163
+ };
6164
+ }
6165
+ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6166
+ switch (node.kind) {
6167
+ case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6168
+ case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6169
+ case "object": {
6170
+ if (!isRecord$2(incoming)) {
6171
+ if (incoming === void 0) return KEEP;
6172
+ ctx.deletes.push(...collectSecretMarkerRefs(stored));
6173
+ return {
6174
+ kind: "value",
6175
+ value: incoming
6176
+ };
6177
+ }
6178
+ const storedObj = isRecord$2(stored) ? stored : {};
6179
+ return {
6180
+ kind: "value",
6181
+ value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
6182
+ };
6183
+ }
6184
+ }
6185
+ }
6186
+ /** Split a perNode-scoped key (`key@nodeId`). */
6187
+ function splitNodeKey(key) {
6188
+ const at = key.indexOf("@");
6189
+ return at <= 0 ? {
6190
+ base: key,
6191
+ nodeId: null
6192
+ } : {
6193
+ base: key.slice(0, at),
6194
+ nodeId: key.slice(at + 1)
6195
+ };
6196
+ }
6197
+ /** Rewrite a settings patch so no secret value reaches the blob. See the file doc. */
6198
+ async function transformSecretWrite(input) {
6199
+ const deletes = [];
6200
+ const base = {
6201
+ secrets: input.secrets,
6202
+ mintId: input.mintId ?? defaultMintId,
6203
+ deletes,
6204
+ operatorWrite: input.operatorWrite === true
6205
+ };
6206
+ const out = {};
6207
+ for (const [key, incoming] of Object.entries(input.patch)) {
6208
+ const { base: baseKey, nodeId } = splitNodeKey(key);
6209
+ const node = input.tree.get(baseKey);
6210
+ if (node === void 0) {
6211
+ out[key] = incoming;
6212
+ continue;
6213
+ }
6214
+ const scope = nodeId !== null && nodeId.length > 0 ? {
6215
+ kind: "node",
6216
+ nodeId
6217
+ } : input.scope ?? globalSecretScope();
6218
+ const result = await writeNode({
6219
+ ...base,
6220
+ scope
6221
+ }, node, incoming, input.stored[key], baseKey);
6222
+ if (result.kind === "value") out[key] = result.value;
6223
+ }
6224
+ return {
6225
+ patch: out,
6226
+ afterWrite: async () => {
6227
+ if (deletes.length === 0) return { orphaned: [] };
6228
+ try {
6229
+ await input.secrets.delete([...new Set(deletes)]);
6230
+ return { orphaned: [] };
6231
+ } catch {
6232
+ return { orphaned: [...new Set(deletes)] };
6233
+ }
6234
+ }
6235
+ };
6236
+ }
6237
+ /**
6238
+ * Replace every marker in `value` with its keychain value. Returns the SAME
6239
+ * reference when there is no marker (no allocation, no keychain call).
6240
+ */
6241
+ async function resolveSecretMarkers(value, secrets) {
6242
+ const refs = collectSecretMarkerRefs(value);
6243
+ if (refs.length === 0) return {
6244
+ value,
6245
+ unresolved: []
6246
+ };
6247
+ const answers = await secrets.resolve(refs);
6248
+ const unresolved = [];
6249
+ for (const ref of new Set(refs)) {
6250
+ const answer = answers[ref];
6251
+ if (answer === void 0) unresolved.push({
6252
+ ref,
6253
+ reason: "not-initialized"
6254
+ });
6255
+ else if (answer.kind === "unavailable") unresolved.push({
6256
+ ref,
6257
+ reason: answer.reason
6258
+ });
6259
+ else if (answer.kind === "missing" || answer.kind === "forbidden") unresolved.push({
6260
+ ref,
6261
+ reason: answer.kind
6262
+ });
6263
+ }
6264
+ const substitute = (v) => {
6265
+ if (isSecretMarker(v)) {
6266
+ const answer = answers[v.$secret];
6267
+ return answer?.kind === "value" ? {
6268
+ keep: true,
6269
+ value: answer.value
6270
+ } : {
6271
+ keep: false,
6272
+ value: void 0
6273
+ };
6274
+ }
6275
+ if (Array.isArray(v)) {
6276
+ const items = [];
6277
+ for (const item of v) {
6278
+ const s = substitute(item);
6279
+ if (s.keep) items.push(s.value);
6280
+ }
6281
+ return {
6282
+ keep: true,
6283
+ value: items
6284
+ };
6285
+ }
6286
+ if (isRecord$2(v)) {
6287
+ const out = {};
6288
+ for (const [k, child] of Object.entries(v)) {
6289
+ const s = substitute(child);
6290
+ if (s.keep) out[k] = s.value;
6291
+ }
6292
+ return {
6293
+ keep: true,
6294
+ value: out
6295
+ };
6296
+ }
6297
+ return {
6298
+ keep: true,
6299
+ value: v
6300
+ };
6301
+ };
6302
+ return {
6303
+ value: substitute(value).value,
6304
+ unresolved
6305
+ };
6306
+ }
6307
+ function touchesTree(tree, patch) {
6308
+ if (tree.size === 0) return false;
6309
+ for (const key of Object.keys(patch)) {
6310
+ const at = key.indexOf("@");
6311
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6312
+ }
6313
+ return false;
6314
+ }
6315
+ /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6316
+ async function readStoredAddonBlob(raw) {
6317
+ const threeWay = raw.readAddonStoreResult;
6318
+ if (threeWay === void 0) return raw.readAddonStore();
6319
+ const result = await threeWay.call(raw);
6320
+ if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6321
+ return result.kind === "missing" ? {} : result.value;
6322
+ }
6323
+ function createSecretAwareSettings(raw, opts) {
6324
+ const chains = /* @__PURE__ */ new Map();
6325
+ const serialize = (key, fn) => {
6326
+ const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
6327
+ const tail = next.catch(() => void 0);
6328
+ chains.set(key, tail);
6329
+ tail.then(() => {
6330
+ if (chains.get(key) === tail) chains.delete(key);
6331
+ });
6332
+ return next;
6333
+ };
6334
+ const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6335
+ if (!touchesTree(tree, patch)) return rawWrite(patch);
6336
+ return serialize(chainKey, async () => {
6337
+ const stored = await readStored();
6338
+ const result = await transformSecretWrite({
6339
+ tree,
6340
+ secrets: opts.secrets,
6341
+ patch,
6342
+ stored,
6343
+ ...scope !== void 0 ? { scope } : {},
6344
+ operatorWrite: opts.isOperatorWrite?.() === true
6345
+ });
6346
+ if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6347
+ const { orphaned } = await result.afterWrite();
6348
+ if (orphaned.length > 0) opts.onOrphaned(orphaned);
6349
+ });
6350
+ };
6351
+ const wrapped = {
6352
+ writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6353
+ writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6354
+ kind: "device",
6355
+ deviceId
6356
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6357
+ };
6358
+ return new Proxy(raw, { get(target, prop, receiver) {
6359
+ if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6360
+ if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6361
+ const value = Reflect.get(target, prop, receiver);
6362
+ return typeof value === "function" ? value.bind(target) : value;
6363
+ } });
6364
+ }
6365
+ /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6366
+ function withSecretAwareSettings(context, opts) {
6367
+ const raw = context.settings;
6368
+ if (raw === void 0) return context;
6369
+ const settings = createSecretAwareSettings(raw, opts);
6370
+ return new Proxy(context, { get(target, prop, receiver) {
6371
+ if (prop === "settings") return settings;
6372
+ return Reflect.get(target, prop, receiver);
6373
+ } });
6374
+ }
6375
+ var LEAF = { kind: "leaf" };
6376
+ var DEFAULT_ITEM_ID_KEY = "id";
6377
+ function collectFields(fields, out) {
6378
+ for (const field of fields) {
6379
+ if (field.type === "group") {
6380
+ collectFields(field.fields, out);
6381
+ continue;
6382
+ }
6383
+ if (field.type === "sub-tabs") {
6384
+ for (const tab of field.tabs) collectFields(tab.fields, out);
6385
+ continue;
6386
+ }
6387
+ if (field.type === "editable-array") {
6388
+ const item = /* @__PURE__ */ new Map();
6389
+ for (const itemField of field.itemFields) if ("key" in itemField && isKeychainStoredField(itemField)) item.set(itemField.key, LEAF);
6390
+ if (item.size > 0) out.set(field.key, {
6391
+ kind: "array",
6392
+ idKey: field.itemIdKey ?? DEFAULT_ITEM_ID_KEY,
6393
+ item
6394
+ });
6395
+ continue;
6396
+ }
6397
+ if (!("key" in field) || typeof field.key !== "string") continue;
6398
+ if (isKeychainStoredField(field)) out.set(field.key, LEAF);
6399
+ }
6400
+ }
6401
+ /** The secret tree a settings schema declares. */
6402
+ function secretTreeFromSchema(schema) {
6403
+ const out = /* @__PURE__ */ new Map();
6404
+ if (schema === null) return out;
6405
+ for (const section of schema.sections) collectFields(section.fields, out);
6406
+ return out;
6407
+ }
6408
+ /** Parse `a.b[id].c` into segments; throws on a malformed path (a declaration bug). */
6409
+ function parseSecretStatePath(path) {
6410
+ const segments = [];
6411
+ for (const raw of path.split(".")) {
6412
+ const m = /^([^[\]]+)(?:\[([^[\]]+)\])?$/.exec(raw);
6413
+ if (m === null || m[1] === void 0) throw new Error(`secretStatePaths: malformed path "${path}"`);
6414
+ segments.push(m[2] !== void 0 ? {
6415
+ key: m[1],
6416
+ idKey: m[2]
6417
+ } : { key: m[1] });
6418
+ }
6419
+ if (segments.length === 0) throw new Error(`secretStatePaths: empty path`);
6420
+ if (segments[segments.length - 1]?.idKey !== void 0) throw new Error(`secretStatePaths: "${path}" ends on an array — name the member that is secret`);
6421
+ return segments;
6422
+ }
6423
+ function insert(into, segments) {
6424
+ const [head, ...rest] = segments;
6425
+ if (head === void 0) return;
6426
+ if (rest.length === 0) {
6427
+ into.set(head.key, LEAF);
6428
+ return;
6429
+ }
6430
+ const existing = into.get(head.key);
6431
+ if (head.idKey !== void 0) {
6432
+ const item = new Map(existing?.kind === "array" ? existing.item : []);
6433
+ insert(item, rest);
6434
+ into.set(head.key, {
6435
+ kind: "array",
6436
+ idKey: head.idKey,
6437
+ item
6438
+ });
6439
+ return;
6440
+ }
6441
+ const children = new Map(existing?.kind === "object" ? existing.children : []);
6442
+ insert(children, rest);
6443
+ into.set(head.key, {
6444
+ kind: "object",
6445
+ children
6446
+ });
6447
+ }
6448
+ /** Add hidden-state paths (`secretStatePaths`) to a schema-derived tree. */
6449
+ function mergeSecretStatePaths(tree, paths) {
6450
+ if (paths.length === 0) return tree;
6451
+ const out = new Map(tree);
6452
+ for (const path of paths) insert(out, parseSecretStatePath(path));
6453
+ return out;
6454
+ }
6455
+ /** First retry of a secret the keychain could not serve; doubles to {@link SECRET_RETRY_MAX_MS}. */
6456
+ var SECRET_RETRY_FIRST_MS = 5e3;
6457
+ var SECRET_RETRY_MAX_MS = 5 * 6e4;
6458
+ /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
6459
+ var SECRET_CHANGE_DEBOUNCE_MS = 250;
5924
6460
  /**
5925
6461
  * Base class for CamStack addons. Eliminates settings boilerplate:
5926
6462
  *
@@ -5990,6 +6526,25 @@ var BaseAddon = class {
5990
6526
  settingsStoreReady = false;
5991
6527
  /** Default config values. Provided via constructor. */
5992
6528
  defaults;
6529
+ /**
6530
+ * Hidden-state paths that hold secrets (D787) — values the addon writes
6531
+ * itself (`updateGlobalSettings`, `state()`) that no form field declares.
6532
+ * Stored in the keychain exactly like a `password` field. Syntax:
6533
+ * `'snapshotSigningKey'`, `'identity.pincode'`, `'tokens[userId].accessToken'`
6534
+ * (`key[<id field>]` addresses array items by id, never by index).
6535
+ */
6536
+ secretStatePaths = [];
6537
+ _addonSecretTree = null;
6538
+ _deviceSecretTree = null;
6539
+ /** Refs the last resolved config pointed at — a change to one re-resolves. */
6540
+ _configSecretRefs = /* @__PURE__ */ new Set();
6541
+ _unresolvedSecrets = [];
6542
+ _secretRetryTimer = null;
6543
+ _secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
6544
+ _secretChangeTimer = null;
6545
+ _secretChangeUnsub = null;
6546
+ /** >0 while an OPERATOR's settings write is being applied. */
6547
+ _operatorWriteDepth = 0;
5993
6548
  constructor(defaults) {
5994
6549
  this.defaults = defaults;
5995
6550
  this._config = { ...defaults };
@@ -6025,8 +6580,18 @@ var BaseAddon = class {
6025
6580
  return this._config;
6026
6581
  }
6027
6582
  async initialize(context) {
6028
- this._ctx = context;
6583
+ const secrets = context.secrets;
6584
+ this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6585
+ secrets,
6586
+ addonTree: () => this.addonSecretTree(),
6587
+ deviceTree: () => this.deviceSecretTree(),
6588
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6589
+ isOperatorWrite: () => this._operatorWriteDepth > 0
6590
+ }) : context;
6029
6591
  await this.resolveConfig();
6592
+ if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6593
+ if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
6594
+ });
6030
6595
  const result = await this.onInitialize();
6031
6596
  this.emitLifecycle(EventCategory.AddonStarted);
6032
6597
  const normalized = normalizeAddonInitResult(result);
@@ -6059,6 +6624,12 @@ var BaseAddon = class {
6059
6624
  */
6060
6625
  async onHubReachable() {}
6061
6626
  async shutdown() {
6627
+ this._secretChangeUnsub?.();
6628
+ this._secretChangeUnsub = null;
6629
+ if (this._secretRetryTimer !== null) clearTimeout(this._secretRetryTimer);
6630
+ if (this._secretChangeTimer !== null) clearTimeout(this._secretChangeTimer);
6631
+ this._secretRetryTimer = null;
6632
+ this._secretChangeTimer = null;
6062
6633
  this.emitLifecycle(EventCategory.AddonStopped);
6063
6634
  if (this.autoEmitReadiness) this.emitReadinessForProviders("down");
6064
6635
  await this.onShutdown();
@@ -6137,7 +6708,7 @@ var BaseAddon = class {
6137
6708
  return hydrateSchema(schema, overlay ? {
6138
6709
  ...projected,
6139
6710
  ...overlay
6140
- } : projected);
6711
+ } : projected, { inlineSecretsAsViews: true });
6141
6712
  }
6142
6713
  /**
6143
6714
  * The integration-level view of this addon's settings: exactly the sections
@@ -6186,7 +6757,7 @@ var BaseAddon = class {
6186
6757
  return hydrateSchema({
6187
6758
  ...schema,
6188
6759
  sections
6189
- }, projected);
6760
+ }, projected, { inlineSecretsAsViews: true });
6190
6761
  }
6191
6762
  /**
6192
6763
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
@@ -6240,18 +6811,50 @@ var BaseAddon = class {
6240
6811
  value: result.value[key]
6241
6812
  };
6242
6813
  }
6814
+ /**
6815
+ * The OPERATOR's write — a settings form or an admin API call, dispatched by
6816
+ * the kernel. Identical to {@link updateGlobalSettings}, except that a secret
6817
+ * the operator sends is stored as sent even when it equals a pre-keychain
6818
+ * inline value: the operator re-entering a password is a change, an addon
6819
+ * writing back what it read is not (D787).
6820
+ */
6821
+ async updateGlobalSettingsAsOperator(patch, nodeId) {
6822
+ this._operatorWriteDepth++;
6823
+ try {
6824
+ await this.applyGlobalPatch(patch, nodeId);
6825
+ } finally {
6826
+ this._operatorWriteDepth--;
6827
+ }
6828
+ }
6243
6829
  async updateGlobalSettings(patch, nodeId) {
6830
+ await this.applyGlobalPatch(patch, nodeId);
6831
+ }
6832
+ /**
6833
+ * REMOVE stored secrets — their keychain values and their markers (D787).
6834
+ *
6835
+ * Writing `''` to a secret field KEEPS what is stored (an empty string is
6836
+ * what a defaults fallback writes back, and it must never destroy a
6837
+ * credential), so code that means "forget this token" says so here. Without
6838
+ * a keychain (an older kernel) it writes `''`, as such code always did.
6839
+ */
6840
+ async clearSecrets(keys, nodeId) {
6841
+ const tree = this.addonSecretTree();
6842
+ const keychain = this._ctx?.secrets !== void 0;
6843
+ const patch = {};
6844
+ for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
6845
+ await this.applyGlobalPatch(patch, nodeId);
6846
+ }
6847
+ async applyGlobalPatch(barePatch, nodeId) {
6244
6848
  const keys = this.perNodeKeys();
6245
6849
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6246
6850
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6247
- const barePatch = patch;
6248
6851
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6249
6852
  await this._ctx?.settings?.writeAddonStore(scoped);
6250
6853
  if (target !== localNode) return;
6251
6854
  await this.resolveConfig();
6252
6855
  await this.onConfigChanged();
6253
6856
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
6254
- this.maybeAutoRestart(patch, this.globalSettingsSchema());
6857
+ this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
6255
6858
  }
6256
6859
  /**
6257
6860
  * The set of field keys the global settings schema declares `perNode: true`
@@ -6276,7 +6879,7 @@ var BaseAddon = class {
6276
6879
  * time to return its response before the addon is torn down and
6277
6880
  * re-initialised by `AddonRegistryService.restartAddon`.
6278
6881
  */
6279
- maybeAutoRestart(patch, schema) {
6882
+ maybeAutoRestart(patchKeys, schema) {
6280
6883
  if (!schema) return;
6281
6884
  const restartKeys = /* @__PURE__ */ new Set();
6282
6885
  for (const section of schema.sections) for (const field of section.fields) {
@@ -6284,13 +6887,13 @@ var BaseAddon = class {
6284
6887
  if (field.requiresRestart) restartKeys.add(field.key);
6285
6888
  }
6286
6889
  if (restartKeys.size === 0) return;
6287
- if (!Object.keys(patch).some((k) => restartKeys.has(k))) return;
6890
+ if (!patchKeys.some((k) => restartKeys.has(k))) return;
6288
6891
  const ctx = this._ctx;
6289
6892
  if (!ctx) return;
6290
6893
  const addonId = ctx.id;
6291
6894
  setImmediate(() => {
6292
6895
  ctx.api.addons?.restartAddon?.mutate({ addonId }).then(() => {
6293
- ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: Object.keys(patch).filter((k) => restartKeys.has(k)) } });
6896
+ ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: patchKeys.filter((k) => restartKeys.has(k)) } });
6294
6897
  }).catch((err) => {
6295
6898
  ctx.logger.error("addon auto-restart failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
6296
6899
  });
@@ -6299,7 +6902,7 @@ var BaseAddon = class {
6299
6902
  async getDeviceSettings(deviceId) {
6300
6903
  const schema = this.deviceSettingsSchema();
6301
6904
  if (!schema) return { sections: [] };
6302
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {});
6905
+ return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6303
6906
  }
6304
6907
  async updateDeviceSettings(deviceId, patch) {
6305
6908
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -6429,7 +7032,7 @@ var BaseAddon = class {
6429
7032
  * selection at boot (absent scoped key ⇒ the constructor default wins).
6430
7033
  */
6431
7034
  async resolveConfig() {
6432
- const stored = await this.readAddonStoreWithRetry();
7035
+ const stored = await this.resolveStoredSecrets(await this.readAddonStoreWithRetry());
6433
7036
  const perNode = this.perNodeKeys();
6434
7037
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6435
7038
  const resolved = { ...this.defaults };
@@ -6454,7 +7057,7 @@ var BaseAddon = class {
6454
7057
  key,
6455
7058
  schema,
6456
7059
  fallback,
6457
- read: () => this.readAddonStoreWithRetry(),
7060
+ read: async () => this.resolveStoredSecrets(await this.readAddonStoreWithRetry()),
6458
7061
  write: async (patch) => {
6459
7062
  await this._ctx?.settings?.writeAddonStore(patch);
6460
7063
  },
@@ -6471,7 +7074,7 @@ var BaseAddon = class {
6471
7074
  key,
6472
7075
  schema,
6473
7076
  fallback,
6474
- read: async () => await this._ctx?.settings?.readDeviceStore(deviceId) ?? {},
7077
+ read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
6475
7078
  write: async (patch) => {
6476
7079
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
6477
7080
  },
@@ -6483,6 +7086,70 @@ var BaseAddon = class {
6483
7086
  } })
6484
7087
  });
6485
7088
  }
7089
+ /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
7090
+ addonSecretTree() {
7091
+ this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
7092
+ return this._addonSecretTree;
7093
+ }
7094
+ deviceSecretTree() {
7095
+ this._deviceSecretTree ??= secretTreeFromSchema(this.deviceSettingsSchema());
7096
+ return this._deviceSecretTree;
7097
+ }
7098
+ /**
7099
+ * Secrets of this addon's stored config that could not be resolved on the
7100
+ * last read, with why. Non-empty means the addon is running WITHOUT them —
7101
+ * an addon whose function needs one should report itself degraded rather
7102
+ * than start on an empty credential.
7103
+ */
7104
+ get unresolvedSecrets() {
7105
+ return this._unresolvedSecrets;
7106
+ }
7107
+ /**
7108
+ * Substitute every keychain marker in a stored blob with its value. With no
7109
+ * keychain (no `ctx.secrets`) or no marker, the blob comes back unchanged.
7110
+ * An unresolvable value is LEFT OUT (never `''`), logged by ref — never by
7111
+ * value — and, when the cause can pass, retried with backoff. Nothing is
7112
+ * ever written back from here.
7113
+ */
7114
+ async resolveStoredSecrets(blob, trackForConfig = true) {
7115
+ const secrets = this._ctx?.secrets;
7116
+ if (secrets === void 0) return blob;
7117
+ const refs = collectSecretMarkerRefs(blob);
7118
+ if (trackForConfig) this._configSecretRefs = new Set(refs);
7119
+ if (refs.length === 0) {
7120
+ if (trackForConfig) this._unresolvedSecrets = [];
7121
+ return blob;
7122
+ }
7123
+ const { value, unresolved } = await resolveSecretMarkers(blob, secrets);
7124
+ if (trackForConfig) {
7125
+ this._unresolvedSecrets = unresolved;
7126
+ if (unresolved.length > 0) {
7127
+ this._ctx?.logger?.error?.("secret unavailable — running without it, will retry", { meta: { secrets: unresolved.map((u) => ({
7128
+ ref: u.ref,
7129
+ reason: u.reason
7130
+ })) } });
7131
+ if (unresolved.some((u) => u.reason !== "missing" && u.reason !== "forbidden")) {
7132
+ this.scheduleSecretReresolve(this._secretRetryDelayMs);
7133
+ this._secretRetryDelayMs = Math.min(this._secretRetryDelayMs * 2, SECRET_RETRY_MAX_MS);
7134
+ }
7135
+ } else this._secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
7136
+ }
7137
+ return value;
7138
+ }
7139
+ /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7140
+ scheduleSecretReresolve(delayMs) {
7141
+ const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
7142
+ if (this[timerOf] !== null) return;
7143
+ const timer = setTimeout(() => {
7144
+ this[timerOf] = null;
7145
+ if (this._ctx === null) return;
7146
+ this.resolveConfig().then(() => this.onConfigChanged()).catch((err) => {
7147
+ this._ctx?.logger?.error?.("re-resolving secrets failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
7148
+ });
7149
+ }, delayMs);
7150
+ timer.unref?.();
7151
+ this[timerOf] = timer;
7152
+ }
6486
7153
  /**
6487
7154
  * Wrap `ctx.settings.readAddonStore()` with a short retry budget so a
6488
7155
  * transient settings-store outage (mid-restart of sqlite-settings, tsx-watch
@@ -7058,6 +7725,69 @@ method(object({ deviceId: number() }), array(StreamSourceEntrySchema)), method(o
7058
7725
  kind: "mutation",
7059
7726
  auth: "admin"
7060
7727
  }), method(object({ deviceId: number() }), unknown().nullable()), method(object({ deviceId: number() }), RawStateResultSchema.nullable(), { auth: "protected" });
7728
+ function defOf(schema) {
7729
+ return schema._zod?.def ?? {};
7730
+ }
7731
+ function declaredHere(schema) {
7732
+ return globalRegistry.get(schema)?.secret === true;
7733
+ }
7734
+ /** Wrapper kinds whose `innerType` is the field itself. */
7735
+ var WRAPPERS = new Set([
7736
+ "optional",
7737
+ "nullable",
7738
+ "default",
7739
+ "prefault",
7740
+ "catch",
7741
+ "readonly",
7742
+ "nonoptional"
7743
+ ]);
7744
+ /**
7745
+ * The schema layers that make up ONE field: the schema itself and every
7746
+ * wrapper below it (optional / default / nullable / readonly / catch), plus
7747
+ * both sides of a pipe (`z.preprocess` puts the real schema on `out`,
7748
+ * `.transform` on `in`).
7749
+ */
7750
+ function layersOf(schema) {
7751
+ const out = [];
7752
+ const queue = [schema];
7753
+ while (queue.length > 0) {
7754
+ const s = queue.shift();
7755
+ if (!s || out.includes(s)) continue;
7756
+ out.push(s);
7757
+ const def = defOf(s);
7758
+ if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
7759
+ if (def.type === "pipe") {
7760
+ if (def.in) queue.push(def.in);
7761
+ if (def.out) queue.push(def.out);
7762
+ }
7763
+ }
7764
+ return out;
7765
+ }
7766
+ /** True when any layer of this field declares `.meta({ secret: true })`. */
7767
+ function isZodSecret(schema) {
7768
+ return layersOf(schema).some(declaredHere);
7769
+ }
7770
+ /**
7771
+ * Every declared secret path in a config schema: dotted keys, `[]` for "each
7772
+ * element of this array" (`connection.password`, `rows[].token`). A declared
7773
+ * object or array is reported as one path and not descended into — everything
7774
+ * under it is secret.
7775
+ */
7776
+ function collectZodSecretPaths(schema, prefix = "") {
7777
+ if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
7778
+ const paths = [];
7779
+ for (const layer of layersOf(schema)) {
7780
+ const def = defOf(layer);
7781
+ if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
7782
+ else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
7783
+ else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
7784
+ else if (def.type === "intersection") {
7785
+ if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
7786
+ if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
7787
+ }
7788
+ }
7789
+ return [...new Set(paths)];
7790
+ }
7061
7791
  //#endregion
7062
7792
  //#region ../types/dist/err-msg-DX6i_MY4.mjs
7063
7793
  var DeviceType = /* @__PURE__ */ function(DeviceType) {
@@ -14137,6 +14867,196 @@ id: union([string$2(), number()]) }), {
14137
14867
  kind: "mutation",
14138
14868
  auth: "admin"
14139
14869
  });
14870
+ /**
14871
+ * `keychain` — the hub's encrypted store of secret values (D787).
14872
+ *
14873
+ * Settings blobs never hold a secret: they hold a marker
14874
+ * `{"$secret":"secret://<owner>/<scope>/<fieldPath>","v":1}` and the value
14875
+ * lives here, AES-256-GCM under a data key that a master key wraps. This cap
14876
+ * is the OWNER's door to its own values: every method is owner-checked
14877
+ * against the CALLER, never against anything the caller claims.
14878
+ *
14879
+ * Who the caller is: the transport stamps `callerAddonId` into the args of a
14880
+ * call that crossed a process (the parent `LocalChildRegistry` from the UDS
14881
+ * connection, the agent from its child's connection carried in
14882
+ * `$hub-cap-fwd`'s envelope). A stamp always overwrites; a wire call with no
14883
+ * stamp has its claim stripped. Only a hub in-process caller may state its own
14884
+ * identity — `ctx.secrets` does that with the addon id closed over. This is
14885
+ * identity against BUGS and misrouting, not against a malicious addon (every
14886
+ * runner is the same OS user): see the threat model in
14887
+ * `docs/design/2026-10-08-secrets-keychain.md`.
14888
+ *
14889
+ * `callerAddonId` is deliberately NOT in any input schema: the tRPC router
14890
+ * parses the input, so a session can never supply it, and the internal mount
14891
+ * floors every method to admin anyway (D240).
14892
+ *
14893
+ * Internal: addons reach it through `ctx.secrets`, never directly.
14894
+ */
14895
+ /** Why a value cannot be served right now. Never folded into "missing". */
14896
+ var KeychainUnavailableReasonSchema = _enum([
14897
+ "key-missing",
14898
+ "wrong-key",
14899
+ "key-file-unreadable",
14900
+ "store-unavailable",
14901
+ "not-initialized",
14902
+ "decrypt-failed"
14903
+ ]);
14904
+ var KeychainStateSchema = discriminatedUnion("state", [object({ state: literal("ready") }), object({
14905
+ state: literal("locked"),
14906
+ reason: KeychainUnavailableReasonSchema
14907
+ })]);
14908
+ var KeychainResolveEntrySchema = discriminatedUnion("kind", [
14909
+ object({
14910
+ kind: literal("value"),
14911
+ value: string$2(),
14912
+ version: number().int()
14913
+ }),
14914
+ object({ kind: literal("missing") }),
14915
+ object({
14916
+ kind: literal("unavailable"),
14917
+ reason: KeychainUnavailableReasonSchema
14918
+ }),
14919
+ object({ kind: literal("forbidden") })
14920
+ ]);
14921
+ var KeychainResolveResultSchema = record(string$2(), KeychainResolveEntrySchema);
14922
+ /** Metadata of one stored value — never the value. */
14923
+ var KeychainSecretMetaSchema = object({
14924
+ ref: string$2(),
14925
+ owner: string$2(),
14926
+ /** Formatted scope (`global`, `node/<id>`, `device/<id>`, …). */
14927
+ scope: string$2(),
14928
+ fieldPath: string$2(),
14929
+ version: number().int(),
14930
+ createdAt: number(),
14931
+ updatedAt: number(),
14932
+ /** `addon:<id>` | `user:<id>` | `system`. */
14933
+ updatedBy: string$2(),
14934
+ /** Coarse — written at most once an hour per ref. `null` = never read. */
14935
+ lastReadAt: number().nullable()
14936
+ });
14937
+ var RefListSchema = array(string$2().min(1)).max(512);
14938
+ method(object({
14939
+ ref: string$2().min(1),
14940
+ value: string$2().min(1)
14941
+ }), object({
14942
+ ref: string$2(),
14943
+ version: number().int()
14944
+ }), {
14945
+ kind: "mutation",
14946
+ auth: "admin"
14947
+ }), method(object({ refs: RefListSchema }), KeychainResolveResultSchema, { auth: "admin" }), method(object({ refs: RefListSchema }), object({ deleted: number().int() }), {
14948
+ kind: "mutation",
14949
+ auth: "admin"
14950
+ }), method(object({}), array(KeychainSecretMetaSchema).readonly(), { auth: "admin" }), method(object({}), KeychainStateSchema, { auth: "admin" });
14951
+ var KeychainKeySourceSchema = object({
14952
+ kind: _enum([
14953
+ "config-file",
14954
+ "previous-config-file",
14955
+ "platform",
14956
+ "default-file"
14957
+ ]),
14958
+ /** File sources only — a path is not a secret. */
14959
+ path: string$2().optional(),
14960
+ /**
14961
+ * True when a whole-volume backup of the data directory carries this key
14962
+ * next to the database it protects (the default file). The page warns.
14963
+ */
14964
+ sharesBackupWithDatabase: boolean()
14965
+ });
14966
+ var KeychainStatusSchema = object({
14967
+ keychain: KeychainStateSchema,
14968
+ /** The source of the master key in use; `null` while locked. */
14969
+ keySource: KeychainKeySourceSchema.nullable(),
14970
+ /** The source configured to be primary — differs from `keySource` while a rotation is pending. */
14971
+ configuredSource: KeychainKeySourceSchema,
14972
+ /** Short fingerprint of the master key in use (`HMAC(KEK, label)`, 16 hex). */
14973
+ fingerprint: string$2().nullable(),
14974
+ activeKeyId: string$2().nullable(),
14975
+ /**
14976
+ * The keychain unlocked with a NON-primary source: the configured primary
14977
+ * key is not the one that wraps the data key yet. `rotateMasterKey` moves it.
14978
+ */
14979
+ rotationPending: boolean(),
14980
+ /** Wrapped copies of the data key under a previous master key, kept until purged. */
14981
+ retiredWraps: number().int(),
14982
+ recoveryKeyDownloadedAt: number().nullable(),
14983
+ secretCount: number().int()
14984
+ });
14985
+ /**
14986
+ * Whether a stored value is still pointed at by its owner's settings.
14987
+ * `unknown` is a first-class answer: a scope whose blob could not be read is
14988
+ * never reported as an orphan (and never deleted as one).
14989
+ */
14990
+ var KeychainSecretUsageSchema = _enum([
14991
+ "in-use",
14992
+ "orphan",
14993
+ "unknown"
14994
+ ]);
14995
+ var KeychainAdminSecretSchema = KeychainSecretMetaSchema.extend({ usage: KeychainSecretUsageSchema });
14996
+ var KeychainAuditActionSchema = _enum([
14997
+ "put",
14998
+ "delete",
14999
+ "reveal",
15000
+ "rotate-master-key",
15001
+ "purge-retired-keys",
15002
+ "download-recovery-key",
15003
+ "delete-orphans",
15004
+ "reset",
15005
+ "initialize"
15006
+ ]);
15007
+ var KeychainAuditEntrySchema = object({
15008
+ id: string$2(),
15009
+ at: number(),
15010
+ action: KeychainAuditActionSchema,
15011
+ /** `addon:<id>` | `user:<id>` | `system`. */
15012
+ actor: string$2(),
15013
+ ref: string$2().nullable(),
15014
+ detail: string$2().nullable()
15015
+ });
15016
+ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}), array(KeychainAdminSecretSchema).readonly(), { auth: "admin" }), method(object({ limit: number().int().min(1).max(500).optional() }), array(KeychainAuditEntrySchema).readonly(), { auth: "admin" }), method(object({ ref: string$2().min(1) }), object({
15017
+ value: string$2(),
15018
+ version: number().int()
15019
+ }), {
15020
+ kind: "mutation",
15021
+ auth: "admin",
15022
+ caller: "required"
15023
+ }), method(object({ refs: array(string$2().min(1)).max(1e3) }), object({
15024
+ deleted: array(string$2()).readonly(),
15025
+ kept: array(object({
15026
+ ref: string$2(),
15027
+ usage: KeychainSecretUsageSchema
15028
+ })).readonly()
15029
+ }), {
15030
+ kind: "mutation",
15031
+ auth: "admin",
15032
+ caller: "required"
15033
+ }), method(object({}), object({
15034
+ fingerprint: string$2(),
15035
+ keySource: KeychainKeySourceSchema
15036
+ }), {
15037
+ kind: "mutation",
15038
+ auth: "admin",
15039
+ caller: "required"
15040
+ }), method(object({}), object({ purged: number().int() }), {
15041
+ kind: "mutation",
15042
+ auth: "admin",
15043
+ caller: "required"
15044
+ }), method(object({}), object({
15045
+ key: string$2(),
15046
+ fingerprint: string$2(),
15047
+ keySource: KeychainKeySourceSchema
15048
+ }), {
15049
+ kind: "mutation",
15050
+ auth: "admin",
15051
+ caller: "required"
15052
+ }), method(object({ confirm: literal("RESET KEYCHAIN") }), object({
15053
+ archivedCollection: string$2().nullable(),
15054
+ archived: number().int()
15055
+ }), {
15056
+ kind: "mutation",
15057
+ auth: "admin",
15058
+ caller: "required"
15059
+ });
14140
15060
  method(_void(), object({
14141
15061
  id: string$2(),
14142
15062
  name: string$2(),
@@ -15379,7 +16299,11 @@ var DeviceRegisterPayloadSchema = object({
15379
16299
  var DeviceRemovePayloadSchema = object({ deviceId: number() });
15380
16300
  var DevicePersistConfigPayloadSchema = object({
15381
16301
  deviceId: number(),
15382
- data: record(string$2(), unknown())
16302
+ data: record(string$2(), unknown()),
16303
+ /** The paths the device's schema declares secret (D783), when the caller
16304
+ * knows them — those values are kept in the keychain, not the blob (D787).
16305
+ * Absent: the paths the device last reported at `registerDevice` apply. */
16306
+ secretConfigPaths: array(string$2()).optional()
15383
16307
  });
15384
16308
  /** What a migration actually did, per switch. `unreachable` is a first-class
15385
16309
  * answer: a camera that could not be asked is not a camera that was silenced. */
@@ -22396,8 +23320,23 @@ var RetrainMacroClassSchema = _enum([
22396
23320
  ]);
22397
23321
  /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
22398
23322
  var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
22399
- /** Did a human draw this box, or did the assist propose it? */
22400
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
23323
+ /**
23324
+ * Where a box came from. A machine-sourced box is a DRAFT on the page until
23325
+ * the operator confirms it; once saved it keeps its source as provenance.
23326
+ *
23327
+ * - `operator` — drawn by hand.
23328
+ * - `assist` — proposed by a detector run on the copy (the camera's own
23329
+ * model, or a larger teacher model).
23330
+ * - `pipeline` — the box the live pipeline actually drew on that frame, read
23331
+ * back from the track store (never a re-run).
23332
+ * - `llm` — proposed by a vision-capable LLM profile.
23333
+ */
23334
+ var RetrainAnnotationSourceSchema = _enum([
23335
+ "operator",
23336
+ "assist",
23337
+ "pipeline",
23338
+ "llm"
23339
+ ]);
22401
23340
  /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
22402
23341
  var RetrainBboxSchema = object({
22403
23342
  x: number(),
@@ -22415,7 +23354,8 @@ var RetrainBboxSchema = object({
22415
23354
  */
22416
23355
  var RetrainAnnotationSchema = object({
22417
23356
  id: string$2(),
22418
- trackId: string$2(),
23357
+ /** The frame's track. Absent on a recording still, which has none. */
23358
+ trackId: string$2().optional(),
22419
23359
  deviceId: number(),
22420
23360
  /** The COPY in retrain storage — never the source track's media key. */
22421
23361
  mediaKey: string$2(),
@@ -22464,13 +23404,47 @@ var RetrainFrameCandidateSchema = object({
22464
23404
  * fail, whatever became of the original. */
22465
23405
  copied: boolean()
22466
23406
  });
23407
+ /**
23408
+ * One box the live pipeline drew on a copied frame — what a correction starts
23409
+ * from. Derived when the frame is listed, from the track store: the subject
23410
+ * box recorded on the source media row when there is one, else the track
23411
+ * position nearest the frame's capture time. Never stored as an annotation
23412
+ * until the operator confirms it.
23413
+ */
23414
+ var RetrainPipelineBoxSchema = object({
23415
+ /** Normalised `[0,1]` against the full frame. */
23416
+ bbox: RetrainBboxSchema,
23417
+ macroClass: RetrainMacroClassSchema,
23418
+ label: string$2().optional(),
23419
+ subLabel: string$2().optional(),
23420
+ /** The detection score of the position used, when it was recorded. */
23421
+ score: number().optional(),
23422
+ /** The root model that produced the track, when it was recorded. */
23423
+ modelId: string$2().optional(),
23424
+ trackId: string$2(),
23425
+ /** `subject-box`: recorded on this very frame. `position`: the track's
23426
+ * position nearest the capture time, `deltaMs` away. */
23427
+ basis: _enum(["subject-box", "position"]),
23428
+ deltaMs: number()
23429
+ });
23430
+ /**
23431
+ * Where a retrain frame came from: a TRACK's stored media (copy-on-select),
23432
+ * or the RECORDING at an instant — the frame a model saw nothing in has no
23433
+ * track at all.
23434
+ */
23435
+ var RetrainFrameOriginSchema = _enum(["track", "recording"]);
22467
23436
  /** A frame the dataset OWNS: bytes copied at selection time. */
22468
23437
  var RetrainFrameSchema = object({
22469
23438
  frameId: string$2(),
22470
23439
  deviceId: number(),
22471
- trackId: string$2(),
22472
- /** Provenance only. It may already point at nothing — that is expected. */
22473
- sourceMediaId: number().int(),
23440
+ origin: RetrainFrameOriginSchema,
23441
+ /** The track it was copied from. Absent on a recording still. */
23442
+ trackId: string$2().optional(),
23443
+ /** Provenance only. It may already point at nothing — that is expected.
23444
+ * Absent on a recording still. */
23445
+ sourceMediaId: number().int().optional(),
23446
+ /** A recording still: the playhead instant it was taken at. */
23447
+ epochMs: number().optional(),
22474
23448
  sourceKind: MediaFileKindEnum,
22475
23449
  sizeBytes: number().int(),
22476
23450
  width: number().int(),
@@ -22481,7 +23455,12 @@ var RetrainFrameSchema = object({
22481
23455
  /** The operator's "every subject in this frame is boxed". Detector
22482
23456
  * evaluation keeps only complete frames: an unboxed subject would count as
22483
23457
  * a false positive. */
22484
- complete: boolean()
23458
+ complete: boolean(),
23459
+ /** The boxes the pipeline drew on this frame. Present on list answers;
23460
+ * empty when nothing the track store holds can be placed on it. */
23461
+ pipelineBoxes: array(RetrainPipelineBoxSchema).readonly().optional(),
23462
+ /** The named collections this frame belongs to. Present on list answers. */
23463
+ collectionIds: array(string$2()).readonly().optional()
22485
23464
  });
22486
23465
  /** Why a copy-on-select could not be honoured — named, never a silent skip. */
22487
23466
  var RetrainCopyRefusalSchema = _enum([
@@ -22512,6 +23491,8 @@ var RetrainFrameListSchema = object({
22512
23491
  var RetrainExportFilterSchema = object({
22513
23492
  deviceIds: array(number()).optional(),
22514
23493
  frameIds: array(string$2()).max(2e4).optional(),
23494
+ /** Only frames in at least one of these named collections. */
23495
+ collectionIds: array(string$2()).max(200).optional(),
22515
23496
  batchId: string$2().optional(),
22516
23497
  /** Only frames the operator marked complete (all subjects boxed). */
22517
23498
  completeOnly: boolean().optional()
@@ -22576,6 +23557,109 @@ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
22576
23557
  reason: string$2(),
22577
23558
  detail: string$2().optional()
22578
23559
  })]);
23560
+ /** A named set over the retrain corpus — membership only, it owns no pixels. */
23561
+ var RetrainCollectionSchema = object({
23562
+ id: string$2(),
23563
+ name: string$2(),
23564
+ createdAt: number(),
23565
+ frameCount: number().int()
23566
+ });
23567
+ var RetrainCollectionCreateResultSchema = discriminatedUnion("kind", [object({
23568
+ kind: literal("created"),
23569
+ collection: RetrainCollectionSchema
23570
+ }), object({
23571
+ kind: literal("refused"),
23572
+ reason: _enum(["empty-name", "duplicate-name"])
23573
+ })]);
23574
+ var RetrainCollectionRenameResultSchema = discriminatedUnion("kind", [object({
23575
+ kind: literal("renamed"),
23576
+ collection: RetrainCollectionSchema
23577
+ }), object({
23578
+ kind: literal("refused"),
23579
+ reason: _enum([
23580
+ "empty-name",
23581
+ "duplicate-name",
23582
+ "unknown-collection"
23583
+ ])
23584
+ })]);
23585
+ /**
23586
+ * The outcome of adding the frame at a recording instant. Every refusal is
23587
+ * named: `still-unavailable` (not recording, a gap, or an undecodable frame —
23588
+ * `detail` says which), `still-busy` (the recorder is at its decode bound; try
23589
+ * again), `unreadable-image`, `write-failed`, `unknown-collection`.
23590
+ */
23591
+ var AddRetrainFrameFromRecordingResultSchema = discriminatedUnion("kind", [object({
23592
+ kind: literal("added"),
23593
+ collectionId: string$2(),
23594
+ frame: RetrainFrameSchema,
23595
+ /** The moment was already in the dataset; nothing was decoded. */
23596
+ reused: boolean()
23597
+ }), object({
23598
+ kind: literal("refused"),
23599
+ reason: _enum([
23600
+ "unknown-collection",
23601
+ "still-unavailable",
23602
+ "still-busy",
23603
+ "unreadable-image",
23604
+ "write-failed"
23605
+ ]),
23606
+ detail: string$2().optional()
23607
+ })]);
23608
+ /** A vision LLM profile the AI assist may use, and where it sends the frame. */
23609
+ var RetrainAssistProfileSchema = object({
23610
+ id: string$2(),
23611
+ name: string$2(),
23612
+ model: string$2(),
23613
+ kind: string$2(),
23614
+ /** `true` when the frame would leave the house (a cloud vendor, or an
23615
+ * endpoint that is not on the local network). The page confirms each such
23616
+ * run, and the provider refuses one without `allowCloud`. */
23617
+ leavesHouse: boolean()
23618
+ });
23619
+ /** A box the AI assist proposed: a draft, plus the model's own reason. */
23620
+ var RetrainLlmProposalSchema = RetrainAnnotationDraftSchema.extend({ reason: string$2() });
23621
+ /** What the AI assist said about a box that was already on the canvas. */
23622
+ var RetrainLlmReviewSchema = object({
23623
+ /** The `ref` the page sent the box under. */
23624
+ ref: string$2(),
23625
+ verdict: _enum([
23626
+ "confirmed",
23627
+ "wrong-class",
23628
+ "not-an-object",
23629
+ "uncertain"
23630
+ ]),
23631
+ suggestedClass: RetrainMacroClassSchema.optional(),
23632
+ reason: string$2()
23633
+ });
23634
+ /**
23635
+ * The AI assist's answer. `proposed` carries drafts (`source: 'llm'`, the
23636
+ * model and its confidence) and reviews; items the model got wrong (a box off
23637
+ * the frame, an unasked class, an unknown ref) are dropped and counted in
23638
+ * `rejected`. A whole answer that is not the schema is `malformed-answer`.
23639
+ */
23640
+ var RetrainLlmAssistResultSchema = discriminatedUnion("kind", [object({
23641
+ kind: literal("proposed"),
23642
+ profileId: string$2(),
23643
+ model: string$2(),
23644
+ /** The frame was sent outside the house for this answer. */
23645
+ leftHouse: boolean(),
23646
+ proposals: array(RetrainLlmProposalSchema).readonly(),
23647
+ reviews: array(RetrainLlmReviewSchema).readonly(),
23648
+ rejected: number().int()
23649
+ }), object({
23650
+ kind: literal("refused"),
23651
+ reason: _enum([
23652
+ "unknown-frame",
23653
+ "unreadable-frame",
23654
+ "unknown-profile",
23655
+ "profile-disabled",
23656
+ "no-vision",
23657
+ "cloud-not-confirmed",
23658
+ "llm-error",
23659
+ "malformed-answer"
23660
+ ]),
23661
+ detail: string$2().optional()
23662
+ })]);
22579
23663
  /** The outcome of a lifecycle move owned by the retrain page. */
22580
23664
  var RetrainTransitionResultSchema = object({
22581
23665
  trackId: string$2(),
@@ -23293,7 +24377,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23293
24377
  auth: "admin"
23294
24378
  }), method(object({
23295
24379
  deviceId: number(),
23296
- trackId: string$2(),
24380
+ trackId: string$2().optional(),
23297
24381
  frameId: string$2()
23298
24382
  }), object({
23299
24383
  removed: boolean(),
@@ -23310,7 +24394,8 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23310
24394
  auth: "admin"
23311
24395
  }), method(object({
23312
24396
  deviceId: number(),
23313
- trackId: string$2(),
24397
+ /** The frame's track, when it has one — checked against the frame. */
24398
+ trackId: string$2().optional(),
23314
24399
  frameId: string$2(),
23315
24400
  subject: RetrainAssistSubjectSchema,
23316
24401
  /** Which node runs it. Absent ⇒ wherever an unowned call lands. */
@@ -23318,12 +24403,16 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23318
24403
  }), RetrainAssistResultSchema, {
23319
24404
  kind: "mutation",
23320
24405
  auth: "admin"
23321
- }), method(object({ trackId: string$2() }), array(RetrainAnnotationSchema).readonly(), {
24406
+ }), method(object({
24407
+ trackId: string$2().optional(),
24408
+ frameIds: array(string$2()).max(2e3).optional()
24409
+ }), array(RetrainAnnotationSchema).readonly(), {
23322
24410
  kind: "query",
23323
24411
  auth: "admin"
23324
24412
  }), method(object({
23325
24413
  deviceId: number(),
23326
- trackId: string$2(),
24414
+ /** The frame's track, when it has one — checked against the frame. */
24415
+ trackId: string$2().optional(),
23327
24416
  frameId: string$2(),
23328
24417
  annotations: array(RetrainAnnotationDraftSchema)
23329
24418
  }), array(RetrainAnnotationSchema).readonly(), {
@@ -23346,7 +24435,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23346
24435
  auth: "admin"
23347
24436
  }), method(object({
23348
24437
  deviceId: number(),
23349
- trackId: string$2(),
24438
+ trackId: string$2().optional(),
23350
24439
  frameId: string$2(),
23351
24440
  complete: boolean()
23352
24441
  }), RetrainFrameSchema, {
@@ -23360,6 +24449,74 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23360
24449
  kind: "mutation",
23361
24450
  auth: "admin",
23362
24451
  timeoutMs: 60 * 6e4
24452
+ }), method(object({}), array(RetrainAssistProfileSchema).readonly(), {
24453
+ kind: "query",
24454
+ auth: "admin"
24455
+ }), method(object({
24456
+ deviceId: number(),
24457
+ trackId: string$2().optional(),
24458
+ frameId: string$2(),
24459
+ profileId: string$2(),
24460
+ classes: array(RetrainMacroClassSchema).min(1),
24461
+ boxes: array(object({
24462
+ ref: string$2(),
24463
+ bbox: RetrainBboxSchema,
24464
+ macroClass: RetrainMacroClassSchema,
24465
+ label: string$2().optional()
24466
+ })).max(50),
24467
+ allowCloud: boolean()
24468
+ }), RetrainLlmAssistResultSchema, {
24469
+ kind: "mutation",
24470
+ auth: "admin",
24471
+ timeoutMs: 18e4
24472
+ }), method(object({ name: string$2().max(120) }), RetrainCollectionCreateResultSchema, {
24473
+ kind: "mutation",
24474
+ auth: "admin"
24475
+ }), method(object({}), array(RetrainCollectionSchema).readonly(), {
24476
+ kind: "query",
24477
+ auth: "admin"
24478
+ }), method(object({
24479
+ id: string$2(),
24480
+ name: string$2().max(120)
24481
+ }), RetrainCollectionRenameResultSchema, {
24482
+ kind: "mutation",
24483
+ auth: "admin"
24484
+ }), method(object({ id: string$2() }), object({
24485
+ deleted: boolean(),
24486
+ removedFrames: number().int()
24487
+ }), {
24488
+ kind: "mutation",
24489
+ auth: "admin"
24490
+ }), method(object({
24491
+ collectionId: string$2(),
24492
+ deviceId: number(),
24493
+ epochMs: number()
24494
+ }), AddRetrainFrameFromRecordingResultSchema, {
24495
+ kind: "mutation",
24496
+ auth: "admin",
24497
+ timeoutMs: 6e4
24498
+ }), method(object({
24499
+ collectionId: string$2(),
24500
+ frameIds: array(string$2()).min(1).max(500)
24501
+ }), object({
24502
+ added: number().int(),
24503
+ alreadyMember: number().int(),
24504
+ unknownFrameIds: array(string$2()).readonly()
24505
+ }), {
24506
+ kind: "mutation",
24507
+ auth: "admin"
24508
+ }), method(object({
24509
+ collectionId: string$2(),
24510
+ frameId: string$2()
24511
+ }), object({
24512
+ removed: boolean(),
24513
+ deletedFrame: boolean()
24514
+ }), {
24515
+ kind: "mutation",
24516
+ auth: "admin"
24517
+ }), method(object({ collectionId: string$2() }), array(RetrainFrameSchema).readonly(), {
24518
+ kind: "query",
24519
+ auth: "admin"
23363
24520
  }), method(object({
23364
24521
  /** Which of the three event tables owns the row. */
23365
24522
  ownerType: EventOwnerTypeSchema,
@@ -23983,13 +25140,31 @@ var RecommendationReasonSchema = discriminatedUnion("kind", [
23983
25140
  object({
23984
25141
  kind: literal("no-family-build"),
23985
25142
  format: ModelFormatSchema$1
25143
+ }),
25144
+ object({
25145
+ kind: literal("kept-custom-pin"),
25146
+ modelId: string$2(),
25147
+ deviceKey: string$2()
23986
25148
  })
23987
25149
  ]);
25150
+ /** Why a device is left exactly as it is, whatever the plan would pick (D786). */
25151
+ var KeptReasonSchema = _enum(["custom-pin"]);
25152
+ /**
25153
+ * Where a choice's latency came from (D791): this node's own benchmark
25154
+ * result, or the hardware-class table. Measured on the node beats the table.
25155
+ */
25156
+ var LatencySourceSchema = discriminatedUnion("kind", [object({ kind: literal("table") }), object({
25157
+ kind: literal("node-benchmark"),
25158
+ resultId: string$2(),
25159
+ measuredAtMs: number()
25160
+ })]);
23988
25161
  var DeviceModelChoiceSchema = object({
23989
25162
  modelId: string$2(),
23990
25163
  p50Ms: number(),
23991
25164
  fps: number(),
23992
25165
  measured: boolean(),
25166
+ /** Absent on a plan from before D791 — read as the table. */
25167
+ source: LatencySourceSchema.optional(),
23993
25168
  /** Parallel sessions at the camera rate with the headroom kept free: ⌊fps × (1 − headroom) / camera fps⌋. */
23994
25169
  capacitySessions: number(),
23995
25170
  personRecall: number()
@@ -24000,6 +25175,8 @@ var DeviceRecommendationSchema = object({
24000
25175
  enabled: boolean(),
24001
25176
  available: boolean(),
24002
25177
  chosen: DeviceModelChoiceSchema.nullable(),
25178
+ /** Present when the device is kept as is: Apply writes nothing on it. */
25179
+ kept: KeptReasonSchema.optional(),
24003
25180
  reasons: array(RecommendationReasonSchema).readonly()
24004
25181
  });
24005
25182
  var NodeRecommendationSchema = object({
@@ -24053,6 +25230,17 @@ var AutoTuneWarningSchema = discriminatedUnion("kind", [
24053
25230
  kind: literal("coral-enabled"),
24054
25231
  nodeId: string$2(),
24055
25232
  deviceKey: string$2()
25233
+ }),
25234
+ object({
25235
+ kind: literal("custom-pin-kept"),
25236
+ nodeId: string$2(),
25237
+ deviceKey: string$2().nullable(),
25238
+ deviceId: number().nullable(),
25239
+ modelId: string$2()
25240
+ }),
25241
+ object({
25242
+ kind: literal("custom-registry-unreadable"),
25243
+ error: string$2()
24056
25244
  })
24057
25245
  ]);
24058
25246
  var AutoTuneOptionsSchema = object({
@@ -24231,13 +25419,14 @@ var SuggestSharesResultSchema = object({
24231
25419
  nodes: array(SuggestedNodeShareSchema).readonly()
24232
25420
  });
24233
25421
  /**
24234
- * Where the node and device shares come from (D750, D755).
24235
- * - `hardware` (default) — computed by the system from each node's static
24236
- * capacity (its accelerators at their Auto tune models, from the measured
24237
- * latency table), recomputed whenever a node or device joins, leaves, is
24238
- * switched on or off, or changes model. No load input.
24239
- * - `benchmark` — the same, from each node's measured capacity (node
24240
- * benchmark results); a node without results falls back to `hardware`.
25422
+ * Where the node and device shares come from (D750, D755, D791).
25423
+ * - `benchmark` (default since D791) — each node's capacity as its own node
25424
+ * benchmark measured it; a node without fresh results is sized from
25425
+ * `hardware` and says so. Measured on the node beats the table.
25426
+ * - `hardware` — computed from each node's static capacity only (its
25427
+ * accelerators at their Auto tune models, from the latency table).
25428
+ * Both are recomputed whenever a node or device joins, leaves, is switched
25429
+ * on or off, changes model, or a benchmark result is written. No load input.
24241
25430
  * - `manual` — the operator's stored sliders.
24242
25431
  * Either way a node or device that cannot take sessions gives its share to
24243
25432
  * the others in proportion; the stored values are never rewritten for that.
@@ -24286,6 +25475,362 @@ var EffectiveSharesSchema = object({
24286
25475
  nodeWeights: record(string$2(), number()),
24287
25476
  deviceWeights: record(string$2(), record(string$2(), number()))
24288
25477
  });
25478
+ /**
25479
+ * Wire shapes of the node benchmark (D791): the operator's plan, the
25480
+ * preflight the confirmation shows, the run the orchestrator owns, what the
25481
+ * measuring runner reports, and the result rows Auto tune and the automatic
25482
+ * shares read.
25483
+ *
25484
+ * ONE node at a time, owned by the pipeline orchestrator. While a run is
25485
+ * active the cluster is in BENCHMARK MODE for that node: it is not a
25486
+ * detection candidate, camera pins naming it are ignored so its sessions move
25487
+ * elsewhere, and both come back when the mode ends — after a crash or a hub
25488
+ * restart too (a persisted manifest, reconciled against the registry).
25489
+ *
25490
+ * Two measurements, both on the node, driven by its own runner (frames never
25491
+ * cross a process at frame rate, D9):
25492
+ * - `device` — one accelerator × one candidate detector, root only, open
25493
+ * loop: how many streams at the camera rate it carries inside the frame
25494
+ * interval;
25495
+ * - `pipeline` — the chosen detector plus the operator's detail steps
25496
+ * (faces, plates, classifiers, CLIP…), on varied frames from the bench
25497
+ * clip: how many parallel sessions the node carries before latency, drops,
25498
+ * CPU, RAM or the event loop give out.
25499
+ */
25500
+ /** Defaults and bounds, one place. */
25501
+ var NODE_BENCHMARK_DEFAULTS = {
25502
+ fpsPerStream: 10,
25503
+ budgetMinutes: 45,
25504
+ minBudgetMinutes: 10,
25505
+ maxBudgetMinutes: 120,
25506
+ /** A result older than this no longer beats the table. */
25507
+ staleAfterDays: 30,
25508
+ /** Warm-in per ramp step (not accounted). */
25509
+ settleSec: 5,
25510
+ /** Accounted window per ramp step. */
25511
+ measureSec: 20,
25512
+ /** Longest the drain may take before the run is refused. */
25513
+ drainTimeoutSec: 120,
25514
+ /** Candidate models per device in one run. */
25515
+ maxModelsPerDevice: 6
25516
+ };
25517
+ /** The two measurements a run can make. */
25518
+ var NodeBenchmarkPhaseSchema = _enum(["device", "pipeline"]);
25519
+ var NodeBenchmarkDevicePlanSchema = object({
25520
+ /** `<backend>:<device>` — `openvino:npu`, `coreml:all`, `cpu`. */
25521
+ deviceKey: string$2().min(1),
25522
+ /**
25523
+ * Root detector candidates for the `device` measurement, in the order
25524
+ * measured. The FIRST is the one the `pipeline` measurement runs.
25525
+ */
25526
+ modelIds: array(string$2().min(1)).min(1).max(NODE_BENCHMARK_DEFAULTS.maxModelsPerDevice)
25527
+ });
25528
+ /** What the operator confirmed. */
25529
+ var NodeBenchmarkPlanSchema = object({
25530
+ nodeId: string$2().min(1),
25531
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
25532
+ /** Which measurements run. At least one. */
25533
+ phases: array(NodeBenchmarkPhaseSchema).min(1).default(["device", "pipeline"]),
25534
+ /**
25535
+ * Detail steps (catalog step ids under the root: faces, plates,
25536
+ * classifiers, CLIP…) the `pipeline` measurement enables. The root
25537
+ * detector always runs.
25538
+ */
25539
+ steps: array(string$2().min(1)).default([]),
25540
+ /** Offered rate of one stream / session. */
25541
+ fpsPerStream: number().int().min(1).max(30).default(NODE_BENCHMARK_DEFAULTS.fpsPerStream),
25542
+ /** Hard deadline: the mode ends and the cluster is restored when it passes. */
25543
+ budgetMinutes: number().int().min(NODE_BENCHMARK_DEFAULTS.minBudgetMinutes).max(NODE_BENCHMARK_DEFAULTS.maxBudgetMinutes).default(NODE_BENCHMARK_DEFAULTS.budgetMinutes),
25544
+ /** Keep the models the run downloaded (default: delete what was not installed before). */
25545
+ keepDownloadedModels: boolean().default(false),
25546
+ /** Start although the other nodes' capacity does not cover the sessions running now. */
25547
+ acceptInsufficientHeadroom: boolean().default(false)
25548
+ });
25549
+ var NodeBenchmarkRefusalSchema = object({
25550
+ kind: _enum([
25551
+ "benchmark-active",
25552
+ "node-offline",
25553
+ "unknown-device",
25554
+ "no-phase",
25555
+ "insufficient-headroom"
25556
+ ]),
25557
+ detail: string$2(),
25558
+ overridable: boolean()
25559
+ });
25560
+ /** A camera whose detection leaves the node for the run. */
25561
+ var NodeBenchmarkMovingCameraSchema = object({
25562
+ deviceId: number(),
25563
+ /** Placed on the node now (a standing attach or a running session). */
25564
+ placedOnNode: boolean(),
25565
+ /** A node pin naming this node, ignored for the run. */
25566
+ pinnedToNode: boolean()
25567
+ });
25568
+ /** A camera that cannot leave: no other node can obtain its frames. */
25569
+ var NodeBenchmarkStayingCameraSchema = object({
25570
+ deviceId: number(),
25571
+ reason: literal("only-frame-source")
25572
+ });
25573
+ var NodeBenchmarkPreflightSchema = object({
25574
+ nodeId: string$2(),
25575
+ online: boolean(),
25576
+ moving: array(NodeBenchmarkMovingCameraSchema).readonly(),
25577
+ /** Keep running on the node during the run; the result is flagged contaminated. */
25578
+ staying: array(NodeBenchmarkStayingCameraSchema).readonly(),
25579
+ estimatedDurationMs: number(),
25580
+ /** The run ends and the cluster is restored at the latest after this long. */
25581
+ budgetMs: number(),
25582
+ phases: array(NodeBenchmarkPhaseSchema).readonly(),
25583
+ steps: array(string$2()).readonly(),
25584
+ devices: array(NodeBenchmarkDevicePlanSchema).readonly(),
25585
+ /** Parallel sessions the cluster runs now, and what the other nodes can carry. */
25586
+ headroom: object({
25587
+ sessionsNow: number(),
25588
+ otherNodesCapacitySessions: number().nullable()
25589
+ }),
25590
+ refusals: array(NodeBenchmarkRefusalSchema).readonly(),
25591
+ canStart: boolean()
25592
+ });
25593
+ /** Where the measuring runner is. */
25594
+ var NodeBenchProgressSchema = object({
25595
+ phase: _enum([
25596
+ "preparing",
25597
+ "device",
25598
+ "pipeline",
25599
+ "cleanup"
25600
+ ]),
25601
+ deviceKey: string$2().nullable(),
25602
+ modelId: string$2().nullable(),
25603
+ /** Streams (device) or sessions (pipeline) of the step running now. */
25604
+ load: number().nullable(),
25605
+ cellsDone: number(),
25606
+ cellsTotal: number(),
25607
+ message: string$2()
25608
+ });
25609
+ /** What limited a ramp. `none` = the ramp ran out of steps still passing. */
25610
+ var NodeBenchLimitSchema = _enum([
25611
+ "p95",
25612
+ "drops",
25613
+ "errors",
25614
+ "stall",
25615
+ "cpu",
25616
+ "ram",
25617
+ "none"
25618
+ ]);
25619
+ var NodeBenchRampStepSchema = object({
25620
+ load: number(),
25621
+ pass: boolean(),
25622
+ p95Ms: number(),
25623
+ dropRatio: number(),
25624
+ /** Completed frames per second over the accounted window. */
25625
+ fps: number(),
25626
+ cpuPct: number().nullable(),
25627
+ ramFreePct: number().nullable(),
25628
+ failReasons: array(string$2()).readonly()
25629
+ });
25630
+ var NodeBenchCellSchema = discriminatedUnion("phase", [object({
25631
+ phase: literal("device"),
25632
+ deviceKey: string$2(),
25633
+ modelId: string$2(),
25634
+ /** Single-stream latency (the K = 1 step). */
25635
+ p50Ms: number(),
25636
+ p95Ms: number(),
25637
+ p99Ms: number(),
25638
+ /** Frames per second sustained at the last passing step. */
25639
+ fps: number(),
25640
+ /** Streams at the camera rate the device carried inside the frame interval; 0 = not even one. */
25641
+ kMax: number(),
25642
+ limitedBy: NodeBenchLimitSchema,
25643
+ /** First call (model load + warm-up). */
25644
+ warmupMs: number(),
25645
+ ramp: array(NodeBenchRampStepSchema).readonly()
25646
+ }), object({
25647
+ phase: literal("pipeline"),
25648
+ deviceKey: string$2(),
25649
+ modelId: string$2(),
25650
+ steps: array(string$2()).readonly(),
25651
+ /** Parallel sessions at the camera rate the node carried; 0 = not even one. */
25652
+ maxSessions: number(),
25653
+ limitedBy: NodeBenchLimitSchema,
25654
+ /** Detail steps that produced at least one result on the clip — a step that never fired measured nothing. */
25655
+ stepsFired: array(string$2()).readonly(),
25656
+ warmupMs: number(),
25657
+ ramp: array(NodeBenchRampStepSchema).readonly()
25658
+ })]);
25659
+ /**
25660
+ * What a result was measured ON. A result whose fingerprint no longer matches
25661
+ * the node no longer beats the table.
25662
+ */
25663
+ var NodeBenchFingerprintSchema = object({
25664
+ pipelineVersion: string$2().nullable(),
25665
+ cpuModel: string$2().nullable(),
25666
+ ramGb: number().nullable(),
25667
+ os: string$2().nullable(),
25668
+ /** Per device: the pool the cells ran on (runtime + tuning). */
25669
+ pools: record(string$2(), object({
25670
+ runtime: string$2(),
25671
+ numWorkers: number(),
25672
+ concurrency: number(),
25673
+ batchMode: string$2()
25674
+ })).default({})
25675
+ });
25676
+ /** The frames the run used. */
25677
+ var NodeBenchClipSchema = object({
25678
+ /** `camstack-bench-v1` or `reference-images` (the fallback when the clip is not reachable). */
25679
+ id: string$2(),
25680
+ revision: string$2().nullable(),
25681
+ frames: number(),
25682
+ width: number(),
25683
+ height: number()
25684
+ });
25685
+ var NodeBenchRunnerInputSchema = object({
25686
+ runId: string$2().min(1),
25687
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
25688
+ phases: array(NodeBenchmarkPhaseSchema).min(1),
25689
+ /** The full detail step tree root for the `pipeline` measurement is built on the node from these ids. */
25690
+ steps: array(string$2()).default([]),
25691
+ fpsPerStream: number().int().min(1).max(30),
25692
+ /** The runner stops on its own past this instant, whatever the hub does. */
25693
+ deadlineAtMs: number(),
25694
+ settleSec: number().min(0).max(60).default(NODE_BENCHMARK_DEFAULTS.settleSec),
25695
+ measureSec: number().min(2).max(300).default(NODE_BENCHMARK_DEFAULTS.measureSec),
25696
+ keepDownloadedModels: boolean().default(false)
25697
+ });
25698
+ var NodeBenchRunnerStateSchema = _enum([
25699
+ "running",
25700
+ "done",
25701
+ "failed",
25702
+ "aborted"
25703
+ ]);
25704
+ var NodeBenchRunnerStatusSchema = object({
25705
+ runId: string$2(),
25706
+ nodeId: string$2(),
25707
+ state: NodeBenchRunnerStateSchema,
25708
+ progress: NodeBenchProgressSchema.nullable(),
25709
+ /** Every finished cell so far — a run stopped half way keeps what it measured. */
25710
+ cells: array(NodeBenchCellSchema).readonly(),
25711
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
25712
+ clip: NodeBenchClipSchema.nullable(),
25713
+ /** Cameras seen running on the node during the run (they share its pools). */
25714
+ activeCameraIds: array(number()).readonly(),
25715
+ /** Models the run downloaded and then deleted (not installed before). */
25716
+ deletedModels: array(string$2()).readonly(),
25717
+ error: string$2().nullable(),
25718
+ startedAtMs: number(),
25719
+ finishedAtMs: number().nullable()
25720
+ });
25721
+ var NodeBenchmarkStateSchema = _enum([
25722
+ "draining",
25723
+ "measuring",
25724
+ "restoring",
25725
+ "done",
25726
+ "failed",
25727
+ "aborted"
25728
+ ]);
25729
+ /** Why a run ended. */
25730
+ var NodeBenchmarkEndReasonSchema = _enum([
25731
+ "completed",
25732
+ "operator-abort",
25733
+ "deadline",
25734
+ "node-lost",
25735
+ "runner-lost",
25736
+ "hub-restart",
25737
+ "drain-timeout",
25738
+ "failed"
25739
+ ]);
25740
+ var NodeBenchmarkRunSchema = object({
25741
+ runId: string$2(),
25742
+ nodeId: string$2(),
25743
+ state: NodeBenchmarkStateSchema,
25744
+ plan: NodeBenchmarkPlanSchema,
25745
+ startedAtMs: number(),
25746
+ deadlineAtMs: number(),
25747
+ finishedAtMs: number().nullable(),
25748
+ endReason: NodeBenchmarkEndReasonSchema.nullable(),
25749
+ error: string$2().nullable(),
25750
+ /** Cameras moved off the node for the run. */
25751
+ moved: array(number()).readonly(),
25752
+ /** Cameras that stayed (their only frame source is the node). */
25753
+ staying: array(number()).readonly(),
25754
+ /** Something else ran on the node's pools during the run. */
25755
+ contaminated: boolean(),
25756
+ progress: NodeBenchProgressSchema.nullable(),
25757
+ resultIds: array(string$2()).readonly()
25758
+ });
25759
+ /** `getNodeBenchmarkStatus`: the active run (or the last one), and whether benchmark mode is on. */
25760
+ var NodeBenchmarkStatusSchema = object({
25761
+ /** The node the cluster is in benchmark mode for; null = none. */
25762
+ modeNodeId: string$2().nullable(),
25763
+ run: NodeBenchmarkRunSchema.nullable()
25764
+ });
25765
+ /**
25766
+ * One stored measurement — the only authority Auto tune and the automatic
25767
+ * shares read measured capacity from. Written by the orchestrator when a run
25768
+ * ends, never by anyone else.
25769
+ */
25770
+ var NodeBenchmarkResultSchema = object({
25771
+ id: string$2(),
25772
+ runId: string$2(),
25773
+ nodeId: string$2(),
25774
+ cell: NodeBenchCellSchema,
25775
+ fpsPerStream: number(),
25776
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
25777
+ clip: NodeBenchClipSchema.nullable(),
25778
+ /** Other work shared the node's pools (a camera that could not move, or the hub's own duties). */
25779
+ contaminated: boolean(),
25780
+ stayingCameras: array(number()).readonly(),
25781
+ /** The run ended early; the cell itself completed. */
25782
+ partialRun: boolean(),
25783
+ measuredAtMs: number()
25784
+ });
25785
+ var ListNodeBenchmarkResultsInputSchema = object({
25786
+ nodeId: string$2().optional(),
25787
+ deviceKey: string$2().optional()
25788
+ });
25789
+ /** A result with its standing today: does it still beat the table? */
25790
+ var NodeBenchmarkResultViewSchema = NodeBenchmarkResultSchema.extend({
25791
+ /** `fresh` beats the table; `stale` falls back to it; `superseded` = a newer row covers the same cell. */
25792
+ standing: _enum([
25793
+ "fresh",
25794
+ "stale",
25795
+ "superseded"
25796
+ ]),
25797
+ staleWhy: _enum([
25798
+ "age",
25799
+ "runtime",
25800
+ "pool-tuning"
25801
+ ]).nullable()
25802
+ });
25803
+ object({
25804
+ runId: string$2(),
25805
+ nodeId: string$2(),
25806
+ startedAtMs: number(),
25807
+ deadlineAtMs: number(),
25808
+ plan: NodeBenchmarkPlanSchema,
25809
+ moved: array(number()).readonly(),
25810
+ staying: array(number()).readonly()
25811
+ });
25812
+ /** Candidate detectors per device, for the plan editor. */
25813
+ var NodeBenchmarkCandidatesSchema = object({
25814
+ nodeId: string$2(),
25815
+ reachable: boolean(),
25816
+ devices: array(object({
25817
+ deviceKey: string$2(),
25818
+ enabled: boolean(),
25819
+ available: boolean(),
25820
+ /** Ordered: what Auto tune would pick first, then the rest of the family by accuracy. */
25821
+ suggested: array(string$2()).readonly(),
25822
+ /** Every root detector the device has a build for. */
25823
+ all: array(string$2()).readonly(),
25824
+ /** The model the device runs now, when pinned. */
25825
+ currentModelId: string$2().nullable()
25826
+ })).readonly(),
25827
+ /** Detail steps the node's catalog offers under the root (for the `pipeline` measurement). */
25828
+ steps: array(object({
25829
+ id: string$2(),
25830
+ name: string$2(),
25831
+ slot: string$2()
25832
+ })).readonly()
25833
+ });
24289
25834
  object({
24290
25835
  activeCameras: number(),
24291
25836
  throttledCameras: number(),
@@ -25414,7 +26959,16 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
25414
26959
  }), ParkedTrackFrameSchema.nullable()), method(object({
25415
26960
  deviceId: number(),
25416
26961
  trackId: string$2()
25417
- }), object({ released: number().int().nonnegative() }), { kind: "mutation" });
26962
+ }), object({ released: number().int().nonnegative() }), { kind: "mutation" }), method(NodeBenchRunnerInputSchema, object({
26963
+ accepted: literal(true),
26964
+ runId: string$2()
26965
+ }), {
26966
+ kind: "mutation",
26967
+ auth: "admin"
26968
+ }), method(object({ runId: string$2() }), NodeBenchRunnerStatusSchema.nullable(), { auth: "admin" }), method(object({ runId: string$2() }), object({ aborted: boolean() }), {
26969
+ kind: "mutation",
26970
+ auth: "admin"
26971
+ });
25418
26972
  var CameraPipelineConfigSchema = object({
25419
26973
  engine: PipelineEngineChoiceSchema.optional(),
25420
26974
  steps: array(PipelineStepInputSchema).readonly(),
@@ -26053,6 +27607,21 @@ method(object({
26053
27607
  }), method(PlacementStatsInputSchema, PlacementStatsSchema, { auth: "admin" }), method(SuggestSharesInputSchema, SuggestSharesResultSchema, { auth: "admin" }), method(_void(), EffectiveSharesSchema, { auth: "admin" }), method(SetShareSourceInputSchema, object({ success: literal(true) }), {
26054
27608
  kind: "mutation",
26055
27609
  auth: "admin"
27610
+ }), method(NodeBenchmarkPlanSchema, NodeBenchmarkPreflightSchema, { auth: "admin" }), method(NodeBenchmarkPlanSchema, discriminatedUnion("kind", [object({
27611
+ kind: literal("started"),
27612
+ runId: string$2()
27613
+ }), object({
27614
+ kind: literal("refused"),
27615
+ preflight: NodeBenchmarkPreflightSchema
27616
+ })]), {
27617
+ kind: "mutation",
27618
+ auth: "admin"
27619
+ }), method(_void(), NodeBenchmarkStatusSchema, { auth: "admin" }), method(object({ runId: string$2() }), object({ aborted: boolean() }), {
27620
+ kind: "mutation",
27621
+ auth: "admin"
27622
+ }), method(object({ nodeId: string$2() }), NodeBenchmarkCandidatesSchema, { auth: "admin" }), method(ListNodeBenchmarkResultsInputSchema, array(NodeBenchmarkResultViewSchema).readonly(), { auth: "admin" }), method(object({ id: string$2() }), object({ deleted: boolean() }), {
27623
+ kind: "mutation",
27624
+ auth: "admin"
26056
27625
  }), method(object({ deviceId: number() }), CameraPipelineSettingsSchema.nullable()), method(object({
26057
27626
  deviceId: number(),
26058
27627
  addonId: string$2(),
@@ -32177,6 +33746,9 @@ var CreateIntegrationInputSchema = object({
32177
33746
  enabled: boolean().optional(),
32178
33747
  info: record(string$2(), unknown()).optional(),
32179
33748
  settings: record(string$2(), unknown()).optional(),
33749
+ /** Keys of `settings` the form's schema declares secret (by type) — kept in
33750
+ * the keychain, not the table (D787). */
33751
+ secretKeys: array(string$2()).optional(),
32180
33752
  skipRestart: boolean().optional()
32181
33753
  });
32182
33754
  var UpdateIntegrationInputSchema = object({
@@ -32200,7 +33772,9 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string$2
32200
33772
  auth: "admin"
32201
33773
  }), method(object({ id: string$2() }), record(string$2(), unknown()), { auth: "admin" }), method(object({
32202
33774
  id: string$2(),
32203
- settings: record(string$2(), unknown())
33775
+ settings: record(string$2(), unknown()),
33776
+ /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
33777
+ secretKeys: array(string$2()).optional()
32204
33778
  }), object({ success: boolean() }), {
32205
33779
  kind: "mutation",
32206
33780
  auth: "admin"
@@ -40363,7 +41937,8 @@ var BaseDevice = class {
40363
41937
  this.role = options.role;
40364
41938
  this.parentDeviceId = ctx.parentDeviceId;
40365
41939
  const seedData = ctx.persistedConfig ?? {};
40366
- this.config = DeviceConfig.fromSchema(schema, (data) => ctx.persistConfig(data), seedData, ({ droppedKeys, issues }) => {
41940
+ const declaredSecretPaths = collectZodSecretPaths(schema);
41941
+ this.config = DeviceConfig.fromSchema(schema, (data) => ctx.persistConfig(data, { secretConfigPaths: declaredSecretPaths }), seedData, ({ droppedKeys, issues }) => {
40367
41942
  ctx.logger.warn("Device config recovery: dropping invalid persisted fields", {
40368
41943
  tags: {
40369
41944
  deviceId: ctx.id,
@@ -44052,6 +45627,90 @@ Object.freeze({
44052
45627
  addonId: null,
44053
45628
  access: "create"
44054
45629
  },
45630
+ "keychain.delete": {
45631
+ capName: "keychain",
45632
+ capScope: "system",
45633
+ addonId: null,
45634
+ access: "delete"
45635
+ },
45636
+ "keychain.getState": {
45637
+ capName: "keychain",
45638
+ capScope: "system",
45639
+ addonId: null,
45640
+ access: "view"
45641
+ },
45642
+ "keychain.listMeta": {
45643
+ capName: "keychain",
45644
+ capScope: "system",
45645
+ addonId: null,
45646
+ access: "view"
45647
+ },
45648
+ "keychain.put": {
45649
+ capName: "keychain",
45650
+ capScope: "system",
45651
+ addonId: null,
45652
+ access: "create"
45653
+ },
45654
+ "keychain.resolve": {
45655
+ capName: "keychain",
45656
+ capScope: "system",
45657
+ addonId: null,
45658
+ access: "view"
45659
+ },
45660
+ "keychainAdmin.deleteOrphans": {
45661
+ capName: "keychain-admin",
45662
+ capScope: "system",
45663
+ addonId: null,
45664
+ access: "delete"
45665
+ },
45666
+ "keychainAdmin.downloadRecoveryKey": {
45667
+ capName: "keychain-admin",
45668
+ capScope: "system",
45669
+ addonId: null,
45670
+ access: "create"
45671
+ },
45672
+ "keychainAdmin.listAudit": {
45673
+ capName: "keychain-admin",
45674
+ capScope: "system",
45675
+ addonId: null,
45676
+ access: "view"
45677
+ },
45678
+ "keychainAdmin.listSecrets": {
45679
+ capName: "keychain-admin",
45680
+ capScope: "system",
45681
+ addonId: null,
45682
+ access: "view"
45683
+ },
45684
+ "keychainAdmin.purgeRetiredKeys": {
45685
+ capName: "keychain-admin",
45686
+ capScope: "system",
45687
+ addonId: null,
45688
+ access: "delete"
45689
+ },
45690
+ "keychainAdmin.resetKeychain": {
45691
+ capName: "keychain-admin",
45692
+ capScope: "system",
45693
+ addonId: null,
45694
+ access: "delete"
45695
+ },
45696
+ "keychainAdmin.reveal": {
45697
+ capName: "keychain-admin",
45698
+ capScope: "system",
45699
+ addonId: null,
45700
+ access: "create"
45701
+ },
45702
+ "keychainAdmin.rotateMasterKey": {
45703
+ capName: "keychain-admin",
45704
+ capScope: "system",
45705
+ addonId: null,
45706
+ access: "create"
45707
+ },
45708
+ "keychainAdmin.status": {
45709
+ capName: "keychain-admin",
45710
+ capScope: "system",
45711
+ addonId: null,
45712
+ access: "view"
45713
+ },
44055
45714
  "lawnMowerControl.dock": {
44056
45715
  capName: "lawn-mower-control",
44057
45716
  capScope: "device",
@@ -45426,6 +47085,18 @@ Object.freeze({
45426
47085
  addonId: null,
45427
47086
  access: "create"
45428
47087
  },
47088
+ "pipelineAnalytics.addRetrainFrameFromRecording": {
47089
+ capName: "pipeline-analytics",
47090
+ capScope: "device",
47091
+ addonId: null,
47092
+ access: "create"
47093
+ },
47094
+ "pipelineAnalytics.addRetrainFramesToCollection": {
47095
+ capName: "pipeline-analytics",
47096
+ capScope: "device",
47097
+ addonId: null,
47098
+ access: "create"
47099
+ },
45429
47100
  "pipelineAnalytics.applyDeviceSettingsPatch": {
45430
47101
  capName: "pipeline-analytics",
45431
47102
  capScope: "device",
@@ -45474,12 +47145,24 @@ Object.freeze({
45474
47145
  addonId: null,
45475
47146
  access: "view"
45476
47147
  },
47148
+ "pipelineAnalytics.createRetrainCollection": {
47149
+ capName: "pipeline-analytics",
47150
+ capScope: "device",
47151
+ addonId: null,
47152
+ access: "create"
47153
+ },
45477
47154
  "pipelineAnalytics.deleteDeviceEvents": {
45478
47155
  capName: "pipeline-analytics",
45479
47156
  capScope: "device",
45480
47157
  addonId: null,
45481
47158
  access: "delete"
45482
47159
  },
47160
+ "pipelineAnalytics.deleteRetrainCollection": {
47161
+ capName: "pipeline-analytics",
47162
+ capScope: "device",
47163
+ addonId: null,
47164
+ access: "delete"
47165
+ },
45483
47166
  "pipelineAnalytics.deleteTracks": {
45484
47167
  capName: "pipeline-analytics",
45485
47168
  capScope: "device",
@@ -45684,6 +47367,24 @@ Object.freeze({
45684
47367
  addonId: null,
45685
47368
  access: "view"
45686
47369
  },
47370
+ "pipelineAnalytics.listRetrainAssistProfiles": {
47371
+ capName: "pipeline-analytics",
47372
+ capScope: "device",
47373
+ addonId: null,
47374
+ access: "view"
47375
+ },
47376
+ "pipelineAnalytics.listRetrainCollectionFrames": {
47377
+ capName: "pipeline-analytics",
47378
+ capScope: "device",
47379
+ addonId: null,
47380
+ access: "view"
47381
+ },
47382
+ "pipelineAnalytics.listRetrainCollections": {
47383
+ capName: "pipeline-analytics",
47384
+ capScope: "device",
47385
+ addonId: null,
47386
+ access: "view"
47387
+ },
45687
47388
  "pipelineAnalytics.listRetrainFrames": {
45688
47389
  capName: "pipeline-analytics",
45689
47390
  capScope: "device",
@@ -45732,6 +47433,12 @@ Object.freeze({
45732
47433
  addonId: null,
45733
47434
  access: "create"
45734
47435
  },
47436
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": {
47437
+ capName: "pipeline-analytics",
47438
+ capScope: "device",
47439
+ addonId: null,
47440
+ access: "create"
47441
+ },
45735
47442
  "pipelineAnalytics.pruneEvents": {
45736
47443
  capName: "pipeline-analytics",
45737
47444
  capScope: "device",
@@ -45786,6 +47493,18 @@ Object.freeze({
45786
47493
  addonId: null,
45787
47494
  access: "create"
45788
47495
  },
47496
+ "pipelineAnalytics.removeRetrainFrameFromCollection": {
47497
+ capName: "pipeline-analytics",
47498
+ capScope: "device",
47499
+ addonId: null,
47500
+ access: "delete"
47501
+ },
47502
+ "pipelineAnalytics.renameRetrainCollection": {
47503
+ capName: "pipeline-analytics",
47504
+ capScope: "device",
47505
+ addonId: null,
47506
+ access: "create"
47507
+ },
45789
47508
  "pipelineAnalytics.restageRetrainTrack": {
45790
47509
  capName: "pipeline-analytics",
45791
47510
  capScope: "device",
@@ -46074,6 +47793,12 @@ Object.freeze({
46074
47793
  addonId: null,
46075
47794
  access: "view"
46076
47795
  },
47796
+ "pipelineOrchestrator.abortNodeBenchmark": {
47797
+ capName: "pipeline-orchestrator",
47798
+ capScope: "system",
47799
+ addonId: null,
47800
+ access: "create"
47801
+ },
46077
47802
  "pipelineOrchestrator.applyAutoTune": {
46078
47803
  capName: "pipeline-orchestrator",
46079
47804
  capScope: "system",
@@ -46098,6 +47823,12 @@ Object.freeze({
46098
47823
  addonId: null,
46099
47824
  access: "create"
46100
47825
  },
47826
+ "pipelineOrchestrator.deleteNodeBenchmarkResult": {
47827
+ capName: "pipeline-orchestrator",
47828
+ capScope: "system",
47829
+ addonId: null,
47830
+ access: "delete"
47831
+ },
46101
47832
  "pipelineOrchestrator.getAgentLoad": {
46102
47833
  capName: "pipeline-orchestrator",
46103
47834
  capScope: "system",
@@ -46206,6 +47937,24 @@ Object.freeze({
46206
47937
  addonId: null,
46207
47938
  access: "view"
46208
47939
  },
47940
+ "pipelineOrchestrator.getNodeBenchmarkCandidates": {
47941
+ capName: "pipeline-orchestrator",
47942
+ capScope: "system",
47943
+ addonId: null,
47944
+ access: "view"
47945
+ },
47946
+ "pipelineOrchestrator.getNodeBenchmarkPreflight": {
47947
+ capName: "pipeline-orchestrator",
47948
+ capScope: "system",
47949
+ addonId: null,
47950
+ access: "view"
47951
+ },
47952
+ "pipelineOrchestrator.getNodeBenchmarkStatus": {
47953
+ capName: "pipeline-orchestrator",
47954
+ capScope: "system",
47955
+ addonId: null,
47956
+ access: "view"
47957
+ },
46209
47958
  "pipelineOrchestrator.getNodeInferenceDevices": {
46210
47959
  capName: "pipeline-orchestrator",
46211
47960
  capScope: "system",
@@ -46248,6 +47997,12 @@ Object.freeze({
46248
47997
  addonId: null,
46249
47998
  access: "view"
46250
47999
  },
48000
+ "pipelineOrchestrator.listNodeBenchmarkResults": {
48001
+ capName: "pipeline-orchestrator",
48002
+ capScope: "system",
48003
+ addonId: null,
48004
+ access: "view"
48005
+ },
46251
48006
  "pipelineOrchestrator.pauseForStorageMigration": {
46252
48007
  capName: "pipeline-orchestrator",
46253
48008
  capScope: "system",
@@ -46392,6 +48147,12 @@ Object.freeze({
46392
48147
  addonId: null,
46393
48148
  access: "create"
46394
48149
  },
48150
+ "pipelineOrchestrator.startNodeBenchmark": {
48151
+ capName: "pipeline-orchestrator",
48152
+ capScope: "system",
48153
+ addonId: null,
48154
+ access: "create"
48155
+ },
46395
48156
  "pipelineOrchestrator.suggestShares": {
46396
48157
  capName: "pipeline-orchestrator",
46397
48158
  capScope: "system",
@@ -46410,6 +48171,12 @@ Object.freeze({
46410
48171
  addonId: null,
46411
48172
  access: "create"
46412
48173
  },
48174
+ "pipelineRunner.abortNodeBench": {
48175
+ capName: "pipeline-runner",
48176
+ capScope: "system",
48177
+ addonId: null,
48178
+ access: "create"
48179
+ },
46413
48180
  "pipelineRunner.attachCamera": {
46414
48181
  capName: "pipeline-runner",
46415
48182
  capScope: "system",
@@ -46458,6 +48225,12 @@ Object.freeze({
46458
48225
  addonId: null,
46459
48226
  access: "view"
46460
48227
  },
48228
+ "pipelineRunner.getNodeBenchStatus": {
48229
+ capName: "pipeline-runner",
48230
+ capScope: "system",
48231
+ addonId: null,
48232
+ access: "view"
48233
+ },
46461
48234
  "pipelineRunner.getParkedTrackFrame": {
46462
48235
  capName: "pipeline-runner",
46463
48236
  capScope: "system",
@@ -46500,6 +48273,12 @@ Object.freeze({
46500
48273
  addonId: null,
46501
48274
  access: "create"
46502
48275
  },
48276
+ "pipelineRunner.startNodeBench": {
48277
+ capName: "pipeline-runner",
48278
+ capScope: "system",
48279
+ addonId: null,
48280
+ access: "create"
48281
+ },
46503
48282
  "plateGallery.assignPlate": {
46504
48283
  capName: "plate-gallery",
46505
48284
  capScope: "system",
@@ -51429,6 +53208,11 @@ Object.freeze({
51429
53208
  form: "single",
51430
53209
  optional: false
51431
53210
  }],
53211
+ "pipelineAnalytics.addRetrainFrameFromRecording": [{
53212
+ name: "deviceId",
53213
+ form: "single",
53214
+ optional: false
53215
+ }],
51432
53216
  "pipelineAnalytics.applyDeviceSettingsPatch": [{
51433
53217
  name: "deviceId",
51434
53218
  form: "single",
@@ -51619,6 +53403,11 @@ Object.freeze({
51619
53403
  form: "single",
51620
53404
  optional: false
51621
53405
  }],
53406
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": [{
53407
+ name: "deviceId",
53408
+ form: "single",
53409
+ optional: false
53410
+ }],
51622
53411
  "pipelineAnalytics.pruneEventsBefore": [{
51623
53412
  name: "deviceId",
51624
53413
  form: "single",