@camstack/addon-auth 1.2.131 → 1.2.133

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.
@@ -1,4 +1,4 @@
1
- //#region ../types/dist/event-category-B_0XEcLF.mjs
1
+ //#region ../types/dist/event-category-DaIZi00R.mjs
2
2
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
3
3
  EventCategory["SystemBoot"] = "system.boot";
4
4
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -77,6 +77,13 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
77
77
  */
78
78
  EventCategory["AddonLoadFailed"] = "addon.load-failed";
79
79
  /**
80
+ * A keychain value was stored or removed (D787). Carries the ref, its
81
+ * owner and the new version — NEVER the value. A process holding the ref
82
+ * drops its cached copy and the owning `BaseAddon` re-resolves its config.
83
+ * Telemetry (D8): a process that misses it still revalidates by version.
84
+ */
85
+ EventCategory["KeychainChanged"] = "keychain.changed";
86
+ /**
80
87
  * Addon recovered from a previous failure. Emitted when an addon
81
88
  * transitions from `failed` back to `healthy` (typically via the
82
89
  * monitor's auto-retry loop, or after manual `addons.retryLoad`).
@@ -5369,7 +5376,7 @@ var ZodIssueCode = {
5369
5376
  var ZodFirstPartyTypeKind;
5370
5377
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5371
5378
  //#endregion
5372
- //#region ../types/dist/sleep-B0JG7-_F.mjs
5379
+ //#region ../types/dist/sleep-DujUvOcb.mjs
5373
5380
  /**
5374
5381
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5375
5382
  * window to float samples (D455).
@@ -5448,6 +5455,97 @@ function buildAlawTable() {
5448
5455
  }
5449
5456
  buildUlawTable();
5450
5457
  buildAlawTable();
5458
+ /** Is this field's stored value a credential? */
5459
+ function isSecretConfigField(field) {
5460
+ if (field.type === "password") return true;
5461
+ return "secret" in field && field.secret === true;
5462
+ }
5463
+ /**
5464
+ * Is this field's value stored in the KEYCHAIN (D787)? Every secret field is,
5465
+ * by its TYPE, unless it opts out with `storage: 'inline'` — never by its name.
5466
+ */
5467
+ function isKeychainStoredField(field) {
5468
+ if (!isSecretConfigField(field)) return false;
5469
+ if (field.type === "textarea" && field.isJson === true) return false;
5470
+ return !("storage" in field && field.storage === "inline");
5471
+ }
5472
+ /**
5473
+ * What a settings blob holds where a secret used to be.
5474
+ *
5475
+ * A keychain-stored field never holds its value. It holds a self-describing
5476
+ * MARKER, `{"$secret":"secret://…","v":1}` — an object, never a string, so no
5477
+ * code can mistake it for a credential and no form can send it to a camera as
5478
+ * a password. The empty state is `null` / absent, never `''`.
5479
+ *
5480
+ * The same shapes travel to and from the admin UI:
5481
+ *
5482
+ * - read: `hydrateSchema` hands a secret field a {@link SecretFieldView}
5483
+ * (`{ $secret, v, set: true }`) or `null` — the browser learns whether a
5484
+ * value is set, never the value.
5485
+ * - write: an untouched field submits the view back unchanged (KEEP); a typed
5486
+ * value is a plain non-empty string (CHANGE); the Clear button submits
5487
+ * {@link SECRET_CLEAR} (CLEAR). `''`, `null` and the legacy redaction tokens
5488
+ * are KEEP — an empty string is what a defaults-fallback pushes back, and
5489
+ * treating it as "clear" is how a save destroyed a stored credential before.
5490
+ *
5491
+ * Pure and browser-safe.
5492
+ */
5493
+ var SECRET_CLEAR = { $secretClear: true };
5494
+ /** The `'***'` token D634 redaction writes for non-admins. */
5495
+ var LEGACY_DEVICE_REDACTION = "***";
5496
+ function isRecord$1(value) {
5497
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5498
+ }
5499
+ function makeSecretMarker(ref) {
5500
+ return {
5501
+ $secret: ref,
5502
+ v: 1
5503
+ };
5504
+ }
5505
+ /** A stored marker: an object whose `$secret` is a non-empty string. */
5506
+ function isSecretMarker(value) {
5507
+ if (!isRecord$1(value)) return false;
5508
+ const ref = value["$secret"];
5509
+ return typeof ref === "string" && ref.length > 0;
5510
+ }
5511
+ function isSecretClear(value) {
5512
+ return isRecord$1(value) && value["$secretClear"] === true;
5513
+ }
5514
+ /**
5515
+ * The UI view of a stored secret field value: a marker becomes "set", inline
5516
+ * plaintext becomes "set (inline)", nothing becomes `null`. A value never
5517
+ * survives this function.
5518
+ */
5519
+ function toSecretFieldView(stored) {
5520
+ if (isSecretMarker(stored)) return {
5521
+ $secret: stored.$secret,
5522
+ v: 1,
5523
+ set: true
5524
+ };
5525
+ if (typeof stored === "string" && stored.length > 0) return {
5526
+ $secret: null,
5527
+ v: 1,
5528
+ set: true,
5529
+ inline: true
5530
+ };
5531
+ return null;
5532
+ }
5533
+ /**
5534
+ * Classify an incoming value for a secret path. Only a non-empty string that is
5535
+ * not a redaction token sets a value; only {@link SECRET_CLEAR} clears.
5536
+ * Everything else — a marker (ours or anyone's), a UI view, `''`, `null`,
5537
+ * `undefined`, a redaction token, a non-string — keeps what is stored.
5538
+ */
5539
+ function classifySecretWrite(incoming) {
5540
+ if (isSecretClear(incoming)) return { kind: "clear" };
5541
+ if (typeof incoming !== "string") return { kind: "keep" };
5542
+ if (incoming.length === 0) return { kind: "keep" };
5543
+ if (incoming === "__camstack_redacted__" || incoming === LEGACY_DEVICE_REDACTION) return { kind: "keep" };
5544
+ return {
5545
+ kind: "set",
5546
+ value: incoming
5547
+ };
5548
+ }
5451
5549
  Object.fromEntries([
5452
5550
  {
5453
5551
  id: "overview",
@@ -5619,33 +5717,19 @@ Object.fromEntries([
5619
5717
  function isValuelessField(field) {
5620
5718
  return field.type === "separator" || field.type === "info" || field.type === "qr-code" || field.type === "button" || field.type === "object-array" || field.type === "widget" || field.type === "addon-action-button" || field.type === "device-action-button";
5621
5719
  }
5622
- /**
5623
- * Merge a `ConfigUISchema` with a raw `values` record into a
5624
- * `ConfigUISchemaWithValues`. Used by every `get*Settings` backend endpoint
5625
- * before returning to the admin UI. Groups are walked recursively.
5626
- *
5627
- * For each leaf field:
5628
- * - structural fields (`separator`, `info`, `button`) pass through unchanged
5629
- * - other fields get `value = values[key] ?? field.default ?? null`
5630
- *
5631
- * Unknown keys in `values` (keys not declared in the schema) are silently
5632
- * ignored — they don't contribute to the output. Missing keys fall back to
5633
- * the schema default or `null`. This mirrors the old backend behaviour where
5634
- * `FormBuilder` rendered `values[key] ?? field.default`.
5635
- */
5636
- function hydrateSchema(schema, values) {
5720
+ function hydrateSchema(schema, values, options = {}) {
5637
5721
  return {
5638
5722
  ...schema.tabs ? { tabs: [...schema.tabs] } : {},
5639
5723
  sections: schema.sections.map((section) => ({
5640
5724
  ...section,
5641
- fields: section.fields.map((field) => hydrateField(field, values))
5725
+ fields: section.fields.map((field) => hydrateField(field, values, options))
5642
5726
  }))
5643
5727
  };
5644
5728
  }
5645
- function hydrateField(field, values) {
5729
+ function hydrateField(field, values, options) {
5646
5730
  if (isValuelessField(field)) return field;
5647
5731
  if (field.type === "group") {
5648
- const hydratedChildren = field.fields.map((child) => hydrateField(child, values));
5732
+ const hydratedChildren = field.fields.map((child) => hydrateField(child, values, options));
5649
5733
  return {
5650
5734
  ...field,
5651
5735
  fields: hydratedChildren
@@ -5654,7 +5738,7 @@ function hydrateField(field, values) {
5654
5738
  if (field.type === "sub-tabs") {
5655
5739
  const hydratedTabs = field.tabs.map((tab) => ({
5656
5740
  ...tab,
5657
- fields: tab.fields.map((child) => hydrateField(child, values))
5741
+ fields: tab.fields.map((child) => hydrateField(child, values, options))
5658
5742
  }));
5659
5743
  return {
5660
5744
  ...field,
@@ -5664,6 +5748,33 @@ function hydrateField(field, values) {
5664
5748
  const key = field.key;
5665
5749
  const storedValue = Object.prototype.hasOwnProperty.call(values, key) ? values[key] : void 0;
5666
5750
  const defaultValue = field.default;
5751
+ const asView = (v) => isSecretMarker(v) || options.inlineSecretsAsViews === true && v !== void 0;
5752
+ if (isKeychainStoredField(field) && asView(storedValue)) return {
5753
+ ...field,
5754
+ value: toSecretFieldView(storedValue)
5755
+ };
5756
+ if (isKeychainStoredField(field) && options.inlineSecretsAsViews === true) return {
5757
+ ...field,
5758
+ value: null
5759
+ };
5760
+ if (field.type === "editable-array" && Array.isArray(storedValue)) {
5761
+ const secretItemKeys = field.itemFields.filter((item) => "key" in item && isKeychainStoredField(item)).map((item) => "key" in item ? item.key : "");
5762
+ if (secretItemKeys.length > 0) {
5763
+ const rows = storedValue.map((row) => {
5764
+ if (row === null || typeof row !== "object" || Array.isArray(row)) return row;
5765
+ const out = { ...row };
5766
+ for (const k of secretItemKeys) {
5767
+ const v = Reflect.get(row, k);
5768
+ if (asView(v)) out[k] = toSecretFieldView(v);
5769
+ }
5770
+ return out;
5771
+ });
5772
+ return {
5773
+ ...field,
5774
+ value: rows
5775
+ };
5776
+ }
5777
+ }
5667
5778
  if (field.multiple) {
5668
5779
  const stored = Array.isArray(storedValue) ? storedValue : storedValue !== void 0 && storedValue !== null ? [storedValue] : [];
5669
5780
  const itemFallback = field.multiple.itemDefault !== void 0 ? field.multiple.itemDefault : defaultValue !== void 0 ? defaultValue : typeOf(field) === "string" ? "" : null;
@@ -5906,6 +6017,431 @@ function projectStore(store, perNodeKeys, nodeId) {
5906
6017
  }
5907
6018
  return out;
5908
6019
  }
6020
+ var GLOBAL_SCOPE = { kind: "global" };
6021
+ /** The scope every addon-wide (not per-node, not per-device) setting lives in. */
6022
+ function globalSecretScope() {
6023
+ return GLOBAL_SCOPE;
6024
+ }
6025
+ function encodeSegment(value) {
6026
+ return encodeURIComponent(value);
6027
+ }
6028
+ /**
6029
+ * The field path of a value inside an array item, addressed by the item's id:
6030
+ * `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
6031
+ * `providers[authentik].clientSecret`.
6032
+ */
6033
+ function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
6034
+ return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
6035
+ }
6036
+ /** A write to a secret path could not be stored in the keychain, so it was refused. */
6037
+ var KeychainWriteRefusedError = class extends Error {
6038
+ fieldPath;
6039
+ constructor(fieldPath, cause) {
6040
+ super(`secret "${fieldPath}" was not saved: the keychain could not store it (${cause instanceof Error ? cause.message : String(cause)}). Nothing was written.`);
6041
+ this.fieldPath = fieldPath;
6042
+ this.name = "KeychainWriteRefusedError";
6043
+ }
6044
+ };
6045
+ var KEEP = { kind: "keep" };
6046
+ function isRecord(value) {
6047
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6048
+ }
6049
+ function defaultMintId() {
6050
+ return globalThis.crypto.randomUUID();
6051
+ }
6052
+ /** Every marker ref anywhere under `value`. */
6053
+ function collectSecretMarkerRefs(value, out = []) {
6054
+ if (isSecretMarker(value)) {
6055
+ out.push(value.$secret);
6056
+ return out;
6057
+ }
6058
+ if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6059
+ else if (isRecord(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6060
+ return out;
6061
+ }
6062
+ async function storedValueEquals(secrets, marker, candidate) {
6063
+ const resolved = (await secrets.resolve([marker.$secret]))[marker.$secret];
6064
+ return resolved?.kind === "value" && resolved.value === candidate;
6065
+ }
6066
+ async function writeLeaf(ctx, incoming, stored, fieldPath) {
6067
+ const intent = classifySecretWrite(incoming);
6068
+ const ref = ctx.secrets.ref(ctx.scope, fieldPath);
6069
+ const storedIsOurs = isSecretMarker(stored) && stored.$secret === ref;
6070
+ if (intent.kind === "keep") return KEEP;
6071
+ if (intent.kind === "set" && !ctx.operatorWrite && typeof stored === "string" && stored === intent.value) return KEEP;
6072
+ if (intent.kind === "clear") {
6073
+ if (storedIsOurs) ctx.deletes.push(ref);
6074
+ return {
6075
+ kind: "value",
6076
+ value: null
6077
+ };
6078
+ }
6079
+ if (storedIsOurs && await storedValueEquals(ctx.secrets, stored, intent.value)) return {
6080
+ kind: "value",
6081
+ value: stored
6082
+ };
6083
+ try {
6084
+ await ctx.secrets.put(ref, intent.value);
6085
+ } catch (err) {
6086
+ throw new KeychainWriteRefusedError(fieldPath, err);
6087
+ }
6088
+ return {
6089
+ kind: "value",
6090
+ value: makeSecretMarker(ref)
6091
+ };
6092
+ }
6093
+ /** Apply a member result onto `out`: KEEP restores the stored member, or removes it. */
6094
+ function applyMember(out, key, result, storedParent) {
6095
+ if (result.kind === "value") {
6096
+ out[key] = result.value;
6097
+ return;
6098
+ }
6099
+ if (Object.prototype.hasOwnProperty.call(storedParent, key)) out[key] = storedParent[key];
6100
+ else delete out[key];
6101
+ }
6102
+ async function writeMembers(ctx, children, incoming, stored, pathOf) {
6103
+ const out = { ...incoming };
6104
+ for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
6105
+ return out;
6106
+ }
6107
+ function rowId(row, idKey) {
6108
+ const raw = row[idKey];
6109
+ if (typeof raw === "string" && raw.length > 0) return raw;
6110
+ if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
6111
+ return null;
6112
+ }
6113
+ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6114
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord) : [];
6115
+ if (!Array.isArray(incoming)) {
6116
+ ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6117
+ return {
6118
+ kind: "value",
6119
+ value: incoming
6120
+ };
6121
+ }
6122
+ const storedById = /* @__PURE__ */ new Map();
6123
+ for (const row of storedRows) {
6124
+ const id = rowId(row, node.idKey);
6125
+ if (id !== null) storedById.set(id, row);
6126
+ }
6127
+ const kept = /* @__PURE__ */ new Set();
6128
+ const rows = [];
6129
+ for (const row of incoming) {
6130
+ if (!isRecord(row)) {
6131
+ rows.push(row);
6132
+ continue;
6133
+ }
6134
+ const id = rowId(row, node.idKey) ?? ctx.mintId();
6135
+ kept.add(id);
6136
+ const withId = {
6137
+ ...row,
6138
+ [node.idKey]: row[node.idKey] ?? id
6139
+ };
6140
+ if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
6141
+ const storedRow = storedById.get(id) ?? {};
6142
+ rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
6143
+ }
6144
+ for (const [id, row] of storedById) if (!kept.has(id)) ctx.deletes.push(...collectSecretMarkerRefs(row));
6145
+ return {
6146
+ kind: "value",
6147
+ value: rows
6148
+ };
6149
+ }
6150
+ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6151
+ switch (node.kind) {
6152
+ case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6153
+ case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6154
+ case "object": {
6155
+ if (!isRecord(incoming)) {
6156
+ if (incoming === void 0) return KEEP;
6157
+ ctx.deletes.push(...collectSecretMarkerRefs(stored));
6158
+ return {
6159
+ kind: "value",
6160
+ value: incoming
6161
+ };
6162
+ }
6163
+ const storedObj = isRecord(stored) ? stored : {};
6164
+ return {
6165
+ kind: "value",
6166
+ value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
6167
+ };
6168
+ }
6169
+ }
6170
+ }
6171
+ /** Split a perNode-scoped key (`key@nodeId`). */
6172
+ function splitNodeKey(key) {
6173
+ const at = key.indexOf("@");
6174
+ return at <= 0 ? {
6175
+ base: key,
6176
+ nodeId: null
6177
+ } : {
6178
+ base: key.slice(0, at),
6179
+ nodeId: key.slice(at + 1)
6180
+ };
6181
+ }
6182
+ /** Rewrite a settings patch so no secret value reaches the blob. See the file doc. */
6183
+ async function transformSecretWrite(input) {
6184
+ const deletes = [];
6185
+ const base = {
6186
+ secrets: input.secrets,
6187
+ mintId: input.mintId ?? defaultMintId,
6188
+ deletes,
6189
+ operatorWrite: input.operatorWrite === true
6190
+ };
6191
+ const out = {};
6192
+ for (const [key, incoming] of Object.entries(input.patch)) {
6193
+ const { base: baseKey, nodeId } = splitNodeKey(key);
6194
+ const node = input.tree.get(baseKey);
6195
+ if (node === void 0) {
6196
+ out[key] = incoming;
6197
+ continue;
6198
+ }
6199
+ const scope = nodeId !== null && nodeId.length > 0 ? {
6200
+ kind: "node",
6201
+ nodeId
6202
+ } : input.scope ?? globalSecretScope();
6203
+ const result = await writeNode({
6204
+ ...base,
6205
+ scope
6206
+ }, node, incoming, input.stored[key], baseKey);
6207
+ if (result.kind === "value") out[key] = result.value;
6208
+ }
6209
+ return {
6210
+ patch: out,
6211
+ afterWrite: async () => {
6212
+ if (deletes.length === 0) return { orphaned: [] };
6213
+ try {
6214
+ await input.secrets.delete([...new Set(deletes)]);
6215
+ return { orphaned: [] };
6216
+ } catch {
6217
+ return { orphaned: [...new Set(deletes)] };
6218
+ }
6219
+ }
6220
+ };
6221
+ }
6222
+ /**
6223
+ * Replace every marker in `value` with its keychain value. Returns the SAME
6224
+ * reference when there is no marker (no allocation, no keychain call).
6225
+ */
6226
+ async function resolveSecretMarkers(value, secrets) {
6227
+ const refs = collectSecretMarkerRefs(value);
6228
+ if (refs.length === 0) return {
6229
+ value,
6230
+ unresolved: []
6231
+ };
6232
+ const answers = await secrets.resolve(refs);
6233
+ const unresolved = [];
6234
+ for (const ref of new Set(refs)) {
6235
+ const answer = answers[ref];
6236
+ if (answer === void 0) unresolved.push({
6237
+ ref,
6238
+ reason: "not-initialized"
6239
+ });
6240
+ else if (answer.kind === "unavailable") unresolved.push({
6241
+ ref,
6242
+ reason: answer.reason
6243
+ });
6244
+ else if (answer.kind === "missing" || answer.kind === "forbidden") unresolved.push({
6245
+ ref,
6246
+ reason: answer.kind
6247
+ });
6248
+ }
6249
+ const substitute = (v) => {
6250
+ if (isSecretMarker(v)) {
6251
+ const answer = answers[v.$secret];
6252
+ return answer?.kind === "value" ? {
6253
+ keep: true,
6254
+ value: answer.value
6255
+ } : {
6256
+ keep: false,
6257
+ value: void 0
6258
+ };
6259
+ }
6260
+ if (Array.isArray(v)) {
6261
+ const items = [];
6262
+ for (const item of v) {
6263
+ const s = substitute(item);
6264
+ if (s.keep) items.push(s.value);
6265
+ }
6266
+ return {
6267
+ keep: true,
6268
+ value: items
6269
+ };
6270
+ }
6271
+ if (isRecord(v)) {
6272
+ const out = {};
6273
+ for (const [k, child] of Object.entries(v)) {
6274
+ const s = substitute(child);
6275
+ if (s.keep) out[k] = s.value;
6276
+ }
6277
+ return {
6278
+ keep: true,
6279
+ value: out
6280
+ };
6281
+ }
6282
+ return {
6283
+ keep: true,
6284
+ value: v
6285
+ };
6286
+ };
6287
+ return {
6288
+ value: substitute(value).value,
6289
+ unresolved
6290
+ };
6291
+ }
6292
+ function touchesTree(tree, patch) {
6293
+ if (tree.size === 0) return false;
6294
+ for (const key of Object.keys(patch)) {
6295
+ const at = key.indexOf("@");
6296
+ if (tree.has(at > 0 ? key.slice(0, at) : key)) return true;
6297
+ }
6298
+ return false;
6299
+ }
6300
+ /** The blob as stored now; a failed read REFUSES the write instead of guessing. */
6301
+ async function readStoredAddonBlob(raw) {
6302
+ const threeWay = raw.readAddonStoreResult;
6303
+ if (threeWay === void 0) return raw.readAddonStore();
6304
+ const result = await threeWay.call(raw);
6305
+ if (result.kind === "failed") throw new Error(`settings write refused: the stored blob could not be read (${result.error})`);
6306
+ return result.kind === "missing" ? {} : result.value;
6307
+ }
6308
+ function createSecretAwareSettings(raw, opts) {
6309
+ const chains = /* @__PURE__ */ new Map();
6310
+ const serialize = (key, fn) => {
6311
+ const next = (chains.get(key) ?? Promise.resolve()).then(fn, fn);
6312
+ const tail = next.catch(() => void 0);
6313
+ chains.set(key, tail);
6314
+ tail.then(() => {
6315
+ if (chains.get(key) === tail) chains.delete(key);
6316
+ });
6317
+ return next;
6318
+ };
6319
+ const write = async (chainKey, tree, scope, patch, readStored, rawWrite) => {
6320
+ if (!touchesTree(tree, patch)) return rawWrite(patch);
6321
+ return serialize(chainKey, async () => {
6322
+ const stored = await readStored();
6323
+ const result = await transformSecretWrite({
6324
+ tree,
6325
+ secrets: opts.secrets,
6326
+ patch,
6327
+ stored,
6328
+ ...scope !== void 0 ? { scope } : {},
6329
+ operatorWrite: opts.isOperatorWrite?.() === true
6330
+ });
6331
+ if (Object.keys(result.patch).length > 0) await rawWrite(result.patch);
6332
+ const { orphaned } = await result.afterWrite();
6333
+ if (orphaned.length > 0) opts.onOrphaned(orphaned);
6334
+ });
6335
+ };
6336
+ const wrapped = {
6337
+ writeAddonStore: (patch) => write("addon", opts.addonTree(), void 0, patch, () => readStoredAddonBlob(raw), (p) => raw.writeAddonStore(p)),
6338
+ writeDeviceStore: (deviceId, patch) => write(`device:${deviceId}`, opts.deviceTree(), {
6339
+ kind: "device",
6340
+ deviceId
6341
+ }, patch, () => raw.readDeviceStore(deviceId), (p) => raw.writeDeviceStore(deviceId, p))
6342
+ };
6343
+ return new Proxy(raw, { get(target, prop, receiver) {
6344
+ if (prop === "writeAddonStore") return wrapped.writeAddonStore;
6345
+ if (prop === "writeDeviceStore") return wrapped.writeDeviceStore;
6346
+ const value = Reflect.get(target, prop, receiver);
6347
+ return typeof value === "function" ? value.bind(target) : value;
6348
+ } });
6349
+ }
6350
+ /** The context the addon sees: identical, except that its settings writes are secret-aware. */
6351
+ function withSecretAwareSettings(context, opts) {
6352
+ const raw = context.settings;
6353
+ if (raw === void 0) return context;
6354
+ const settings = createSecretAwareSettings(raw, opts);
6355
+ return new Proxy(context, { get(target, prop, receiver) {
6356
+ if (prop === "settings") return settings;
6357
+ return Reflect.get(target, prop, receiver);
6358
+ } });
6359
+ }
6360
+ var LEAF = { kind: "leaf" };
6361
+ var DEFAULT_ITEM_ID_KEY = "id";
6362
+ function collectFields(fields, out) {
6363
+ for (const field of fields) {
6364
+ if (field.type === "group") {
6365
+ collectFields(field.fields, out);
6366
+ continue;
6367
+ }
6368
+ if (field.type === "sub-tabs") {
6369
+ for (const tab of field.tabs) collectFields(tab.fields, out);
6370
+ continue;
6371
+ }
6372
+ if (field.type === "editable-array") {
6373
+ const item = /* @__PURE__ */ new Map();
6374
+ for (const itemField of field.itemFields) if ("key" in itemField && isKeychainStoredField(itemField)) item.set(itemField.key, LEAF);
6375
+ if (item.size > 0) out.set(field.key, {
6376
+ kind: "array",
6377
+ idKey: field.itemIdKey ?? DEFAULT_ITEM_ID_KEY,
6378
+ item
6379
+ });
6380
+ continue;
6381
+ }
6382
+ if (!("key" in field) || typeof field.key !== "string") continue;
6383
+ if (isKeychainStoredField(field)) out.set(field.key, LEAF);
6384
+ }
6385
+ }
6386
+ /** The secret tree a settings schema declares. */
6387
+ function secretTreeFromSchema(schema) {
6388
+ const out = /* @__PURE__ */ new Map();
6389
+ if (schema === null) return out;
6390
+ for (const section of schema.sections) collectFields(section.fields, out);
6391
+ return out;
6392
+ }
6393
+ /** Parse `a.b[id].c` into segments; throws on a malformed path (a declaration bug). */
6394
+ function parseSecretStatePath(path) {
6395
+ const segments = [];
6396
+ for (const raw of path.split(".")) {
6397
+ const m = /^([^[\]]+)(?:\[([^[\]]+)\])?$/.exec(raw);
6398
+ if (m === null || m[1] === void 0) throw new Error(`secretStatePaths: malformed path "${path}"`);
6399
+ segments.push(m[2] !== void 0 ? {
6400
+ key: m[1],
6401
+ idKey: m[2]
6402
+ } : { key: m[1] });
6403
+ }
6404
+ if (segments.length === 0) throw new Error(`secretStatePaths: empty path`);
6405
+ if (segments[segments.length - 1]?.idKey !== void 0) throw new Error(`secretStatePaths: "${path}" ends on an array — name the member that is secret`);
6406
+ return segments;
6407
+ }
6408
+ function insert(into, segments) {
6409
+ const [head, ...rest] = segments;
6410
+ if (head === void 0) return;
6411
+ if (rest.length === 0) {
6412
+ into.set(head.key, LEAF);
6413
+ return;
6414
+ }
6415
+ const existing = into.get(head.key);
6416
+ if (head.idKey !== void 0) {
6417
+ const item = new Map(existing?.kind === "array" ? existing.item : []);
6418
+ insert(item, rest);
6419
+ into.set(head.key, {
6420
+ kind: "array",
6421
+ idKey: head.idKey,
6422
+ item
6423
+ });
6424
+ return;
6425
+ }
6426
+ const children = new Map(existing?.kind === "object" ? existing.children : []);
6427
+ insert(children, rest);
6428
+ into.set(head.key, {
6429
+ kind: "object",
6430
+ children
6431
+ });
6432
+ }
6433
+ /** Add hidden-state paths (`secretStatePaths`) to a schema-derived tree. */
6434
+ function mergeSecretStatePaths(tree, paths) {
6435
+ if (paths.length === 0) return tree;
6436
+ const out = new Map(tree);
6437
+ for (const path of paths) insert(out, parseSecretStatePath(path));
6438
+ return out;
6439
+ }
6440
+ /** First retry of a secret the keychain could not serve; doubles to {@link SECRET_RETRY_MAX_MS}. */
6441
+ var SECRET_RETRY_FIRST_MS = 5e3;
6442
+ var SECRET_RETRY_MAX_MS = 5 * 6e4;
6443
+ /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
6444
+ var SECRET_CHANGE_DEBOUNCE_MS = 250;
5909
6445
  /**
5910
6446
  * Base class for CamStack addons. Eliminates settings boilerplate:
5911
6447
  *
@@ -5975,6 +6511,25 @@ var BaseAddon = class {
5975
6511
  settingsStoreReady = false;
5976
6512
  /** Default config values. Provided via constructor. */
5977
6513
  defaults;
6514
+ /**
6515
+ * Hidden-state paths that hold secrets (D787) — values the addon writes
6516
+ * itself (`updateGlobalSettings`, `state()`) that no form field declares.
6517
+ * Stored in the keychain exactly like a `password` field. Syntax:
6518
+ * `'snapshotSigningKey'`, `'identity.pincode'`, `'tokens[userId].accessToken'`
6519
+ * (`key[<id field>]` addresses array items by id, never by index).
6520
+ */
6521
+ secretStatePaths = [];
6522
+ _addonSecretTree = null;
6523
+ _deviceSecretTree = null;
6524
+ /** Refs the last resolved config pointed at — a change to one re-resolves. */
6525
+ _configSecretRefs = /* @__PURE__ */ new Set();
6526
+ _unresolvedSecrets = [];
6527
+ _secretRetryTimer = null;
6528
+ _secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
6529
+ _secretChangeTimer = null;
6530
+ _secretChangeUnsub = null;
6531
+ /** >0 while an OPERATOR's settings write is being applied. */
6532
+ _operatorWriteDepth = 0;
5978
6533
  constructor(defaults) {
5979
6534
  this.defaults = defaults;
5980
6535
  this._config = { ...defaults };
@@ -6010,8 +6565,18 @@ var BaseAddon = class {
6010
6565
  return this._config;
6011
6566
  }
6012
6567
  async initialize(context) {
6013
- this._ctx = context;
6568
+ const secrets = context.secrets;
6569
+ this._ctx = secrets !== void 0 ? withSecretAwareSettings(context, {
6570
+ secrets,
6571
+ addonTree: () => this.addonSecretTree(),
6572
+ deviceTree: () => this.deviceSecretTree(),
6573
+ onOrphaned: (refs) => context.logger.warn("keychain refs dropped by a settings write could not be deleted", { meta: { refs: [...refs] } }),
6574
+ isOperatorWrite: () => this._operatorWriteDepth > 0
6575
+ }) : context;
6014
6576
  await this.resolveConfig();
6577
+ if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
6578
+ if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
6579
+ });
6015
6580
  const result = await this.onInitialize();
6016
6581
  this.emitLifecycle(EventCategory.AddonStarted);
6017
6582
  const normalized = normalizeAddonInitResult(result);
@@ -6044,6 +6609,12 @@ var BaseAddon = class {
6044
6609
  */
6045
6610
  async onHubReachable() {}
6046
6611
  async shutdown() {
6612
+ this._secretChangeUnsub?.();
6613
+ this._secretChangeUnsub = null;
6614
+ if (this._secretRetryTimer !== null) clearTimeout(this._secretRetryTimer);
6615
+ if (this._secretChangeTimer !== null) clearTimeout(this._secretChangeTimer);
6616
+ this._secretRetryTimer = null;
6617
+ this._secretChangeTimer = null;
6047
6618
  this.emitLifecycle(EventCategory.AddonStopped);
6048
6619
  if (this.autoEmitReadiness) this.emitReadinessForProviders("down");
6049
6620
  await this.onShutdown();
@@ -6122,7 +6693,7 @@ var BaseAddon = class {
6122
6693
  return hydrateSchema(schema, overlay ? {
6123
6694
  ...projected,
6124
6695
  ...overlay
6125
- } : projected);
6696
+ } : projected, { inlineSecretsAsViews: true });
6126
6697
  }
6127
6698
  /**
6128
6699
  * The integration-level view of this addon's settings: exactly the sections
@@ -6171,7 +6742,7 @@ var BaseAddon = class {
6171
6742
  return hydrateSchema({
6172
6743
  ...schema,
6173
6744
  sections
6174
- }, projected);
6745
+ }, projected, { inlineSecretsAsViews: true });
6175
6746
  }
6176
6747
  /**
6177
6748
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
@@ -6225,18 +6796,50 @@ var BaseAddon = class {
6225
6796
  value: result.value[key]
6226
6797
  };
6227
6798
  }
6799
+ /**
6800
+ * The OPERATOR's write — a settings form or an admin API call, dispatched by
6801
+ * the kernel. Identical to {@link updateGlobalSettings}, except that a secret
6802
+ * the operator sends is stored as sent even when it equals a pre-keychain
6803
+ * inline value: the operator re-entering a password is a change, an addon
6804
+ * writing back what it read is not (D787).
6805
+ */
6806
+ async updateGlobalSettingsAsOperator(patch, nodeId) {
6807
+ this._operatorWriteDepth++;
6808
+ try {
6809
+ await this.applyGlobalPatch(patch, nodeId);
6810
+ } finally {
6811
+ this._operatorWriteDepth--;
6812
+ }
6813
+ }
6228
6814
  async updateGlobalSettings(patch, nodeId) {
6815
+ await this.applyGlobalPatch(patch, nodeId);
6816
+ }
6817
+ /**
6818
+ * REMOVE stored secrets — their keychain values and their markers (D787).
6819
+ *
6820
+ * Writing `''` to a secret field KEEPS what is stored (an empty string is
6821
+ * what a defaults fallback writes back, and it must never destroy a
6822
+ * credential), so code that means "forget this token" says so here. Without
6823
+ * a keychain (an older kernel) it writes `''`, as such code always did.
6824
+ */
6825
+ async clearSecrets(keys, nodeId) {
6826
+ const tree = this.addonSecretTree();
6827
+ const keychain = this._ctx?.secrets !== void 0;
6828
+ const patch = {};
6829
+ for (const key of keys) patch[key] = keychain && tree.has(key) ? SECRET_CLEAR : "";
6830
+ await this.applyGlobalPatch(patch, nodeId);
6831
+ }
6832
+ async applyGlobalPatch(barePatch, nodeId) {
6229
6833
  const keys = this.perNodeKeys();
6230
6834
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6231
6835
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
6232
- const barePatch = patch;
6233
6836
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
6234
6837
  await this._ctx?.settings?.writeAddonStore(scoped);
6235
6838
  if (target !== localNode) return;
6236
6839
  await this.resolveConfig();
6237
6840
  await this.onConfigChanged();
6238
6841
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
6239
- this.maybeAutoRestart(patch, this.globalSettingsSchema());
6842
+ this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
6240
6843
  }
6241
6844
  /**
6242
6845
  * The set of field keys the global settings schema declares `perNode: true`
@@ -6261,7 +6864,7 @@ var BaseAddon = class {
6261
6864
  * time to return its response before the addon is torn down and
6262
6865
  * re-initialised by `AddonRegistryService.restartAddon`.
6263
6866
  */
6264
- maybeAutoRestart(patch, schema) {
6867
+ maybeAutoRestart(patchKeys, schema) {
6265
6868
  if (!schema) return;
6266
6869
  const restartKeys = /* @__PURE__ */ new Set();
6267
6870
  for (const section of schema.sections) for (const field of section.fields) {
@@ -6269,13 +6872,13 @@ var BaseAddon = class {
6269
6872
  if (field.requiresRestart) restartKeys.add(field.key);
6270
6873
  }
6271
6874
  if (restartKeys.size === 0) return;
6272
- if (!Object.keys(patch).some((k) => restartKeys.has(k))) return;
6875
+ if (!patchKeys.some((k) => restartKeys.has(k))) return;
6273
6876
  const ctx = this._ctx;
6274
6877
  if (!ctx) return;
6275
6878
  const addonId = ctx.id;
6276
6879
  setImmediate(() => {
6277
6880
  ctx.api.addons?.restartAddon?.mutate({ addonId }).then(() => {
6278
- ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: Object.keys(patch).filter((k) => restartKeys.has(k)) } });
6881
+ ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: patchKeys.filter((k) => restartKeys.has(k)) } });
6279
6882
  }).catch((err) => {
6280
6883
  ctx.logger.error("addon auto-restart failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
6281
6884
  });
@@ -6284,7 +6887,7 @@ var BaseAddon = class {
6284
6887
  async getDeviceSettings(deviceId) {
6285
6888
  const schema = this.deviceSettingsSchema();
6286
6889
  if (!schema) return { sections: [] };
6287
- return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {});
6890
+ return hydrateSchema(schema, await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, { inlineSecretsAsViews: true });
6288
6891
  }
6289
6892
  async updateDeviceSettings(deviceId, patch) {
6290
6893
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
@@ -6414,7 +7017,7 @@ var BaseAddon = class {
6414
7017
  * selection at boot (absent scoped key ⇒ the constructor default wins).
6415
7018
  */
6416
7019
  async resolveConfig() {
6417
- const stored = await this.readAddonStoreWithRetry();
7020
+ const stored = await this.resolveStoredSecrets(await this.readAddonStoreWithRetry());
6418
7021
  const perNode = this.perNodeKeys();
6419
7022
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
6420
7023
  const resolved = { ...this.defaults };
@@ -6439,7 +7042,7 @@ var BaseAddon = class {
6439
7042
  key,
6440
7043
  schema,
6441
7044
  fallback,
6442
- read: () => this.readAddonStoreWithRetry(),
7045
+ read: async () => this.resolveStoredSecrets(await this.readAddonStoreWithRetry()),
6443
7046
  write: async (patch) => {
6444
7047
  await this._ctx?.settings?.writeAddonStore(patch);
6445
7048
  },
@@ -6456,7 +7059,7 @@ var BaseAddon = class {
6456
7059
  key,
6457
7060
  schema,
6458
7061
  fallback,
6459
- read: async () => await this._ctx?.settings?.readDeviceStore(deviceId) ?? {},
7062
+ read: async () => this.resolveStoredSecrets(await this._ctx?.settings?.readDeviceStore(deviceId) ?? {}, false),
6460
7063
  write: async (patch) => {
6461
7064
  await this._ctx?.settings?.writeDeviceStore(deviceId, patch);
6462
7065
  },
@@ -6468,6 +7071,70 @@ var BaseAddon = class {
6468
7071
  } })
6469
7072
  });
6470
7073
  }
7074
+ /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
7075
+ addonSecretTree() {
7076
+ this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
7077
+ return this._addonSecretTree;
7078
+ }
7079
+ deviceSecretTree() {
7080
+ this._deviceSecretTree ??= secretTreeFromSchema(this.deviceSettingsSchema());
7081
+ return this._deviceSecretTree;
7082
+ }
7083
+ /**
7084
+ * Secrets of this addon's stored config that could not be resolved on the
7085
+ * last read, with why. Non-empty means the addon is running WITHOUT them —
7086
+ * an addon whose function needs one should report itself degraded rather
7087
+ * than start on an empty credential.
7088
+ */
7089
+ get unresolvedSecrets() {
7090
+ return this._unresolvedSecrets;
7091
+ }
7092
+ /**
7093
+ * Substitute every keychain marker in a stored blob with its value. With no
7094
+ * keychain (no `ctx.secrets`) or no marker, the blob comes back unchanged.
7095
+ * An unresolvable value is LEFT OUT (never `''`), logged by ref — never by
7096
+ * value — and, when the cause can pass, retried with backoff. Nothing is
7097
+ * ever written back from here.
7098
+ */
7099
+ async resolveStoredSecrets(blob, trackForConfig = true) {
7100
+ const secrets = this._ctx?.secrets;
7101
+ if (secrets === void 0) return blob;
7102
+ const refs = collectSecretMarkerRefs(blob);
7103
+ if (trackForConfig) this._configSecretRefs = new Set(refs);
7104
+ if (refs.length === 0) {
7105
+ if (trackForConfig) this._unresolvedSecrets = [];
7106
+ return blob;
7107
+ }
7108
+ const { value, unresolved } = await resolveSecretMarkers(blob, secrets);
7109
+ if (trackForConfig) {
7110
+ this._unresolvedSecrets = unresolved;
7111
+ if (unresolved.length > 0) {
7112
+ this._ctx?.logger?.error?.("secret unavailable — running without it, will retry", { meta: { secrets: unresolved.map((u) => ({
7113
+ ref: u.ref,
7114
+ reason: u.reason
7115
+ })) } });
7116
+ if (unresolved.some((u) => u.reason !== "missing" && u.reason !== "forbidden")) {
7117
+ this.scheduleSecretReresolve(this._secretRetryDelayMs);
7118
+ this._secretRetryDelayMs = Math.min(this._secretRetryDelayMs * 2, SECRET_RETRY_MAX_MS);
7119
+ }
7120
+ } else this._secretRetryDelayMs = SECRET_RETRY_FIRST_MS;
7121
+ }
7122
+ return value;
7123
+ }
7124
+ /** Re-resolve the config (a keychain-only change, or a retry) and apply it. */
7125
+ scheduleSecretReresolve(delayMs) {
7126
+ const timerOf = delayMs === SECRET_CHANGE_DEBOUNCE_MS ? "_secretChangeTimer" : "_secretRetryTimer";
7127
+ if (this[timerOf] !== null) return;
7128
+ const timer = setTimeout(() => {
7129
+ this[timerOf] = null;
7130
+ if (this._ctx === null) return;
7131
+ this.resolveConfig().then(() => this.onConfigChanged()).catch((err) => {
7132
+ this._ctx?.logger?.error?.("re-resolving secrets failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
7133
+ });
7134
+ }, delayMs);
7135
+ timer.unref?.();
7136
+ this[timerOf] = timer;
7137
+ }
6471
7138
  /**
6472
7139
  * Wrap `ctx.settings.readAddonStore()` with a short retry budget so a
6473
7140
  * transient settings-store outage (mid-restart of sqlite-settings, tsx-watch
@@ -14135,6 +14802,214 @@ id: union([string(), number()]) }), {
14135
14802
  kind: "mutation",
14136
14803
  auth: "admin"
14137
14804
  });
14805
+ /**
14806
+ * `keychain` — the hub's encrypted store of secret values (D787).
14807
+ *
14808
+ * Settings blobs never hold a secret: they hold a marker
14809
+ * `{"$secret":"secret://<owner>/<scope>/<fieldPath>","v":1}` and the value
14810
+ * lives here, AES-256-GCM under a data key that a master key wraps. This cap
14811
+ * is the OWNER's door to its own values: every method is owner-checked
14812
+ * against the CALLER, never against anything the caller claims.
14813
+ *
14814
+ * Who the caller is: the transport stamps `callerAddonId` into the args of a
14815
+ * call that crossed a process (the parent `LocalChildRegistry` from the UDS
14816
+ * connection, the agent from its child's connection carried in
14817
+ * `$hub-cap-fwd`'s envelope). A stamp always overwrites; a wire call with no
14818
+ * stamp has its claim stripped. Only a hub in-process caller may state its own
14819
+ * identity — `ctx.secrets` does that with the addon id closed over. This is
14820
+ * identity against BUGS and misrouting, not against a malicious addon (every
14821
+ * runner is the same OS user): see the threat model in
14822
+ * `docs/design/2026-10-08-secrets-keychain.md`.
14823
+ *
14824
+ * `callerAddonId` is deliberately NOT in any input schema: the tRPC router
14825
+ * parses the input, so a session can never supply it, and the internal mount
14826
+ * floors every method to admin anyway (D240).
14827
+ *
14828
+ * Internal: addons reach it through `ctx.secrets`, never directly.
14829
+ */
14830
+ /** Why a value cannot be served right now. Never folded into "missing". */
14831
+ var KeychainUnavailableReasonSchema = _enum([
14832
+ "key-missing",
14833
+ "wrong-key",
14834
+ "key-file-unreadable",
14835
+ "store-unavailable",
14836
+ "not-initialized",
14837
+ "decrypt-failed"
14838
+ ]);
14839
+ var KeychainStateSchema = discriminatedUnion("state", [object({ state: literal("ready") }), object({
14840
+ state: literal("locked"),
14841
+ reason: KeychainUnavailableReasonSchema
14842
+ })]);
14843
+ var KeychainResolveEntrySchema = discriminatedUnion("kind", [
14844
+ object({
14845
+ kind: literal("value"),
14846
+ value: string(),
14847
+ version: number().int()
14848
+ }),
14849
+ object({ kind: literal("missing") }),
14850
+ object({
14851
+ kind: literal("unavailable"),
14852
+ reason: KeychainUnavailableReasonSchema
14853
+ }),
14854
+ object({ kind: literal("forbidden") })
14855
+ ]);
14856
+ var KeychainResolveResultSchema = record(string(), KeychainResolveEntrySchema);
14857
+ /** Metadata of one stored value — never the value. */
14858
+ var KeychainSecretMetaSchema = object({
14859
+ ref: string(),
14860
+ owner: string(),
14861
+ /** Formatted scope (`global`, `node/<id>`, `device/<id>`, …). */
14862
+ scope: string(),
14863
+ fieldPath: string(),
14864
+ version: number().int(),
14865
+ createdAt: number(),
14866
+ updatedAt: number(),
14867
+ /** `addon:<id>` | `user:<id>` | `system`. */
14868
+ updatedBy: string(),
14869
+ /** Coarse — written at most once an hour per ref. `null` = never read. */
14870
+ lastReadAt: number().nullable()
14871
+ });
14872
+ var RefListSchema = array(string().min(1)).max(512);
14873
+ method(object({
14874
+ ref: string().min(1),
14875
+ value: string().min(1)
14876
+ }), object({
14877
+ ref: string(),
14878
+ version: number().int()
14879
+ }), {
14880
+ kind: "mutation",
14881
+ auth: "admin"
14882
+ }), method(object({ refs: RefListSchema }), KeychainResolveResultSchema, { auth: "admin" }), method(object({ refs: RefListSchema }), object({ deleted: number().int() }), {
14883
+ kind: "mutation",
14884
+ auth: "admin"
14885
+ }), method(object({}), array(KeychainSecretMetaSchema).readonly(), { auth: "admin" }), method(object({}), KeychainStateSchema, { auth: "admin" });
14886
+ var KeychainKeySourceSchema = object({
14887
+ kind: _enum([
14888
+ "config-file",
14889
+ "previous-config-file",
14890
+ "platform",
14891
+ "default-file"
14892
+ ]),
14893
+ /** File sources only — a path is not a secret. */
14894
+ path: string().optional(),
14895
+ /**
14896
+ * True when a whole-volume backup of the data directory carries this key
14897
+ * next to the database it protects (the default file). The page warns.
14898
+ */
14899
+ sharesBackupWithDatabase: boolean()
14900
+ });
14901
+ var KeychainStatusSchema = object({
14902
+ keychain: KeychainStateSchema,
14903
+ /** The source of the master key in use; `null` while locked. */
14904
+ keySource: KeychainKeySourceSchema.nullable(),
14905
+ /** The source configured to be primary — differs from `keySource` while a rotation is pending. */
14906
+ configuredSource: KeychainKeySourceSchema,
14907
+ /** Short fingerprint of the master key in use (`HMAC(KEK, label)`, 16 hex). */
14908
+ fingerprint: string().nullable(),
14909
+ activeKeyId: string().nullable(),
14910
+ /**
14911
+ * The keychain unlocked with a NON-primary source: the configured primary
14912
+ * key is not the one that wraps the data key yet. `rotateMasterKey` moves it.
14913
+ */
14914
+ rotationPending: boolean(),
14915
+ /** Wrapped copies of the data key under a previous master key, kept until purged. */
14916
+ retiredWraps: number().int(),
14917
+ recoveryKeyDownloadedAt: number().nullable(),
14918
+ secretCount: number().int()
14919
+ });
14920
+ /**
14921
+ * Whether a stored value is still pointed at by its owner's settings.
14922
+ * `unknown` is a first-class answer: a scope whose blob could not be read is
14923
+ * never reported as an orphan (and never deleted as one).
14924
+ */
14925
+ var KeychainSecretUsageSchema = _enum([
14926
+ "in-use",
14927
+ "orphan",
14928
+ "unknown"
14929
+ ]);
14930
+ var KeychainAdminSecretSchema = KeychainSecretMetaSchema.extend({ usage: KeychainSecretUsageSchema });
14931
+ var KeychainAuditActionSchema = _enum([
14932
+ "put",
14933
+ "delete",
14934
+ "reveal",
14935
+ "rotate-master-key",
14936
+ "purge-retired-keys",
14937
+ "download-recovery-key",
14938
+ "delete-orphans",
14939
+ "reset",
14940
+ "initialize"
14941
+ ]);
14942
+ var KeychainAuditEntrySchema = object({
14943
+ id: string(),
14944
+ at: number(),
14945
+ action: KeychainAuditActionSchema,
14946
+ /** `addon:<id>` | `user:<id>` | `system`. */
14947
+ actor: string(),
14948
+ ref: string().nullable(),
14949
+ detail: string().nullable()
14950
+ });
14951
+ var KEYCHAIN_RESET_CONFIRMATION = "RESET KEYCHAIN";
14952
+ /**
14953
+ * Secrets the HUB itself holds (owner `system`) that no settings form shows:
14954
+ * `jwt-signing-key` — the session signing key (D797). It is always "in use",
14955
+ * never an orphan; it is generated on a fresh hub and replaced only through
14956
+ * {@link keychainAdminCapability.methods.setSystemSecret}.
14957
+ */
14958
+ var SystemHeldSecretNameSchema = _enum(["jwt-signing-key"]);
14959
+ method(object({}), KeychainStatusSchema, { auth: "admin" }), method(object({}), array(KeychainAdminSecretSchema).readonly(), { auth: "admin" }), method(object({ limit: number().int().min(1).max(500).optional() }), array(KeychainAuditEntrySchema).readonly(), { auth: "admin" }), method(object({ ref: string().min(1) }), object({
14960
+ value: string(),
14961
+ version: number().int()
14962
+ }), {
14963
+ kind: "mutation",
14964
+ auth: "admin",
14965
+ caller: "required"
14966
+ }), method(object({
14967
+ name: SystemHeldSecretNameSchema,
14968
+ value: string().min(16)
14969
+ }), object({
14970
+ ref: string(),
14971
+ version: number().int()
14972
+ }), {
14973
+ kind: "mutation",
14974
+ auth: "admin",
14975
+ caller: "required"
14976
+ }), method(object({ refs: array(string().min(1)).max(1e3) }), object({
14977
+ deleted: array(string()).readonly(),
14978
+ kept: array(object({
14979
+ ref: string(),
14980
+ usage: KeychainSecretUsageSchema
14981
+ })).readonly()
14982
+ }), {
14983
+ kind: "mutation",
14984
+ auth: "admin",
14985
+ caller: "required"
14986
+ }), method(object({}), object({
14987
+ fingerprint: string(),
14988
+ keySource: KeychainKeySourceSchema
14989
+ }), {
14990
+ kind: "mutation",
14991
+ auth: "admin",
14992
+ caller: "required"
14993
+ }), method(object({}), object({ purged: number().int() }), {
14994
+ kind: "mutation",
14995
+ auth: "admin",
14996
+ caller: "required"
14997
+ }), method(object({}), object({
14998
+ key: string(),
14999
+ fingerprint: string(),
15000
+ keySource: KeychainKeySourceSchema
15001
+ }), {
15002
+ kind: "mutation",
15003
+ auth: "admin",
15004
+ caller: "required"
15005
+ }), method(object({ confirm: literal(KEYCHAIN_RESET_CONFIRMATION) }), object({
15006
+ archivedCollection: string().nullable(),
15007
+ archived: number().int()
15008
+ }), {
15009
+ kind: "mutation",
15010
+ auth: "admin",
15011
+ caller: "required"
15012
+ });
14138
15013
  method(_void(), object({
14139
15014
  id: string(),
14140
15015
  name: string(),
@@ -15172,7 +16047,11 @@ var DeviceRegisterPayloadSchema = object({
15172
16047
  var DeviceRemovePayloadSchema = object({ deviceId: number() });
15173
16048
  var DevicePersistConfigPayloadSchema = object({
15174
16049
  deviceId: number(),
15175
- data: record(string(), unknown())
16050
+ data: record(string(), unknown()),
16051
+ /** The paths the device's schema declares secret (D783), when the caller
16052
+ * knows them — those values are kept in the keychain, not the blob (D787).
16053
+ * Absent: the paths the device last reported at `registerDevice` apply. */
16054
+ secretConfigPaths: array(string()).optional()
15176
16055
  });
15177
16056
  /** What a migration actually did, per switch. `unreachable` is a first-class
15178
16057
  * answer: a camera that could not be asked is not a camera that was silenced. */
@@ -22159,8 +23038,23 @@ var RetrainMacroClassSchema = _enum([
22159
23038
  ]);
22160
23039
  /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
22161
23040
  var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
22162
- /** Did a human draw this box, or did the assist propose it? */
22163
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
23041
+ /**
23042
+ * Where a box came from. A machine-sourced box is a DRAFT on the page until
23043
+ * the operator confirms it; once saved it keeps its source as provenance.
23044
+ *
23045
+ * - `operator` — drawn by hand.
23046
+ * - `assist` — proposed by a detector run on the copy (the camera's own
23047
+ * model, or a larger teacher model).
23048
+ * - `pipeline` — the box the live pipeline actually drew on that frame, read
23049
+ * back from the track store (never a re-run).
23050
+ * - `llm` — proposed by a vision-capable LLM profile.
23051
+ */
23052
+ var RetrainAnnotationSourceSchema = _enum([
23053
+ "operator",
23054
+ "assist",
23055
+ "pipeline",
23056
+ "llm"
23057
+ ]);
22164
23058
  /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
22165
23059
  var RetrainBboxSchema = object({
22166
23060
  x: number(),
@@ -22178,7 +23072,8 @@ var RetrainBboxSchema = object({
22178
23072
  */
22179
23073
  var RetrainAnnotationSchema = object({
22180
23074
  id: string(),
22181
- trackId: string(),
23075
+ /** The frame's track. Absent on a recording still, which has none. */
23076
+ trackId: string().optional(),
22182
23077
  deviceId: number(),
22183
23078
  /** The COPY in retrain storage — never the source track's media key. */
22184
23079
  mediaKey: string(),
@@ -22227,13 +23122,47 @@ var RetrainFrameCandidateSchema = object({
22227
23122
  * fail, whatever became of the original. */
22228
23123
  copied: boolean()
22229
23124
  });
23125
+ /**
23126
+ * One box the live pipeline drew on a copied frame — what a correction starts
23127
+ * from. Derived when the frame is listed, from the track store: the subject
23128
+ * box recorded on the source media row when there is one, else the track
23129
+ * position nearest the frame's capture time. Never stored as an annotation
23130
+ * until the operator confirms it.
23131
+ */
23132
+ var RetrainPipelineBoxSchema = object({
23133
+ /** Normalised `[0,1]` against the full frame. */
23134
+ bbox: RetrainBboxSchema,
23135
+ macroClass: RetrainMacroClassSchema,
23136
+ label: string().optional(),
23137
+ subLabel: string().optional(),
23138
+ /** The detection score of the position used, when it was recorded. */
23139
+ score: number().optional(),
23140
+ /** The root model that produced the track, when it was recorded. */
23141
+ modelId: string().optional(),
23142
+ trackId: string(),
23143
+ /** `subject-box`: recorded on this very frame. `position`: the track's
23144
+ * position nearest the capture time, `deltaMs` away. */
23145
+ basis: _enum(["subject-box", "position"]),
23146
+ deltaMs: number()
23147
+ });
23148
+ /**
23149
+ * Where a retrain frame came from: a TRACK's stored media (copy-on-select),
23150
+ * or the RECORDING at an instant — the frame a model saw nothing in has no
23151
+ * track at all.
23152
+ */
23153
+ var RetrainFrameOriginSchema = _enum(["track", "recording"]);
22230
23154
  /** A frame the dataset OWNS: bytes copied at selection time. */
22231
23155
  var RetrainFrameSchema = object({
22232
23156
  frameId: string(),
22233
23157
  deviceId: number(),
22234
- trackId: string(),
22235
- /** Provenance only. It may already point at nothing — that is expected. */
22236
- sourceMediaId: number().int(),
23158
+ origin: RetrainFrameOriginSchema,
23159
+ /** The track it was copied from. Absent on a recording still. */
23160
+ trackId: string().optional(),
23161
+ /** Provenance only. It may already point at nothing — that is expected.
23162
+ * Absent on a recording still. */
23163
+ sourceMediaId: number().int().optional(),
23164
+ /** A recording still: the playhead instant it was taken at. */
23165
+ epochMs: number().optional(),
22237
23166
  sourceKind: MediaFileKindEnum,
22238
23167
  sizeBytes: number().int(),
22239
23168
  width: number().int(),
@@ -22244,7 +23173,12 @@ var RetrainFrameSchema = object({
22244
23173
  /** The operator's "every subject in this frame is boxed". Detector
22245
23174
  * evaluation keeps only complete frames: an unboxed subject would count as
22246
23175
  * a false positive. */
22247
- complete: boolean()
23176
+ complete: boolean(),
23177
+ /** The boxes the pipeline drew on this frame. Present on list answers;
23178
+ * empty when nothing the track store holds can be placed on it. */
23179
+ pipelineBoxes: array(RetrainPipelineBoxSchema).readonly().optional(),
23180
+ /** The named collections this frame belongs to. Present on list answers. */
23181
+ collectionIds: array(string()).readonly().optional()
22248
23182
  });
22249
23183
  /** Why a copy-on-select could not be honoured — named, never a silent skip. */
22250
23184
  var RetrainCopyRefusalSchema = _enum([
@@ -22275,6 +23209,11 @@ var RetrainFrameListSchema = object({
22275
23209
  var RetrainExportFilterSchema = object({
22276
23210
  deviceIds: array(number()).optional(),
22277
23211
  frameIds: array(string()).max(2e4).optional(),
23212
+ /** Only frames in at least one of these named collections. */
23213
+ collectionIds: array(string()).max(200).optional(),
23214
+ /** Exactly the frames of this dataset version (and its completeOnly). An
23215
+ * unknown id selects nothing. */
23216
+ datasetVersionId: string().optional(),
22278
23217
  batchId: string().optional(),
22279
23218
  /** Only frames the operator marked complete (all subjects boxed). */
22280
23219
  completeOnly: boolean().optional()
@@ -22339,6 +23278,170 @@ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
22339
23278
  reason: string(),
22340
23279
  detail: string().optional()
22341
23280
  })]);
23281
+ /** A named set over the retrain corpus — membership only, it owns no pixels. */
23282
+ var RetrainCollectionSchema = object({
23283
+ id: string(),
23284
+ name: string(),
23285
+ createdAt: number(),
23286
+ frameCount: number().int()
23287
+ });
23288
+ var RetrainCollectionCreateResultSchema = discriminatedUnion("kind", [object({
23289
+ kind: literal("created"),
23290
+ collection: RetrainCollectionSchema
23291
+ }), object({
23292
+ kind: literal("refused"),
23293
+ reason: _enum(["empty-name", "duplicate-name"])
23294
+ })]);
23295
+ var RetrainCollectionRenameResultSchema = discriminatedUnion("kind", [object({
23296
+ kind: literal("renamed"),
23297
+ collection: RetrainCollectionSchema
23298
+ }), object({
23299
+ kind: literal("refused"),
23300
+ reason: _enum([
23301
+ "empty-name",
23302
+ "duplicate-name",
23303
+ "unknown-collection"
23304
+ ])
23305
+ })]);
23306
+ /**
23307
+ * The outcome of adding the frame at a recording instant. Every refusal is
23308
+ * named: `still-unavailable` (not recording, a gap, or an undecodable frame —
23309
+ * `detail` says which), `still-busy` (the recorder is at its decode bound; try
23310
+ * again), `unreadable-image`, `write-failed`, `unknown-collection`.
23311
+ */
23312
+ var AddRetrainFrameFromRecordingResultSchema = discriminatedUnion("kind", [object({
23313
+ kind: literal("added"),
23314
+ collectionId: string(),
23315
+ frame: RetrainFrameSchema,
23316
+ /** The moment was already in the dataset; nothing was decoded. */
23317
+ reused: boolean()
23318
+ }), object({
23319
+ kind: literal("refused"),
23320
+ reason: _enum([
23321
+ "unknown-collection",
23322
+ "still-unavailable",
23323
+ "still-busy",
23324
+ "unreadable-image",
23325
+ "write-failed"
23326
+ ]),
23327
+ detail: string().optional()
23328
+ })]);
23329
+ /** A vision LLM profile the AI assist may use, and where it sends the frame. */
23330
+ var RetrainAssistProfileSchema = object({
23331
+ id: string(),
23332
+ name: string(),
23333
+ model: string(),
23334
+ kind: string(),
23335
+ /** `true` when the frame would leave the house (a cloud vendor, or an
23336
+ * endpoint that is not on the local network). The page confirms each such
23337
+ * run, and the provider refuses one without `allowCloud`. */
23338
+ leavesHouse: boolean()
23339
+ });
23340
+ /** A box the AI assist proposed: a draft, plus the model's own reason. */
23341
+ var RetrainLlmProposalSchema = RetrainAnnotationDraftSchema.extend({ reason: string() });
23342
+ /** What the AI assist said about a box that was already on the canvas. */
23343
+ var RetrainLlmReviewSchema = object({
23344
+ /** The `ref` the page sent the box under. */
23345
+ ref: string(),
23346
+ verdict: _enum([
23347
+ "confirmed",
23348
+ "wrong-class",
23349
+ "not-an-object",
23350
+ "uncertain"
23351
+ ]),
23352
+ suggestedClass: RetrainMacroClassSchema.optional(),
23353
+ reason: string()
23354
+ });
23355
+ /**
23356
+ * The AI assist's answer. `proposed` carries drafts (`source: 'llm'`, the
23357
+ * model and its confidence) and reviews; items the model got wrong (a box off
23358
+ * the frame, an unasked class, an unknown ref) are dropped and counted in
23359
+ * `rejected`. A whole answer that is not the schema is `malformed-answer`.
23360
+ */
23361
+ var RetrainLlmAssistResultSchema = discriminatedUnion("kind", [object({
23362
+ kind: literal("proposed"),
23363
+ profileId: string(),
23364
+ model: string(),
23365
+ /** The frame was sent outside the house for this answer. */
23366
+ leftHouse: boolean(),
23367
+ proposals: array(RetrainLlmProposalSchema).readonly(),
23368
+ reviews: array(RetrainLlmReviewSchema).readonly(),
23369
+ rejected: number().int()
23370
+ }), object({
23371
+ kind: literal("refused"),
23372
+ reason: _enum([
23373
+ "unknown-frame",
23374
+ "unreadable-frame",
23375
+ "unknown-profile",
23376
+ "profile-disabled",
23377
+ "no-vision",
23378
+ "cloud-not-confirmed",
23379
+ "llm-error",
23380
+ "malformed-answer"
23381
+ ]),
23382
+ detail: string().optional()
23383
+ })]);
23384
+ /** What a dataset version is cut from. Every field narrows. */
23385
+ var RetrainDatasetSelectionSchema = object({
23386
+ deviceIds: array(number()).readonly().optional(),
23387
+ collectionIds: array(string()).max(200).readonly().optional(),
23388
+ frameIds: array(string()).max(2e4).readonly().optional()
23389
+ });
23390
+ /** The counts a dataset is judged by. */
23391
+ var RetrainDatasetStatsSchema = object({
23392
+ frames: number().int(),
23393
+ completeFrames: number().int(),
23394
+ /** `completeFrames / frames`, 0..1. */
23395
+ completeness: number(),
23396
+ /** Boxes to learn (model errors excluded). */
23397
+ subjects: number().int(),
23398
+ modelErrors: number().int(),
23399
+ /** Complete frames with no subject. */
23400
+ hardNegatives: number().int(),
23401
+ /** Subjects per class × camera × day/night. */
23402
+ cells: array(object({
23403
+ macroClass: string(),
23404
+ deviceId: number(),
23405
+ lighting: _enum([
23406
+ "day",
23407
+ "night",
23408
+ "unknown"
23409
+ ]),
23410
+ subjects: number().int(),
23411
+ frames: number().int()
23412
+ })).readonly(),
23413
+ cameras: array(object({
23414
+ deviceId: number(),
23415
+ frames: number().int(),
23416
+ completeFrames: number().int()
23417
+ })).readonly()
23418
+ });
23419
+ /** An immutable dataset version, without its frame list. */
23420
+ var RetrainDatasetVersionSchema = object({
23421
+ id: string(),
23422
+ name: string(),
23423
+ createdAt: number(),
23424
+ selection: RetrainDatasetSelectionSchema,
23425
+ layout: RetrainExportLayoutSchema,
23426
+ completeOnly: boolean(),
23427
+ frameCount: number().int(),
23428
+ /** sha256 of what the frames taught when the version was frozen. */
23429
+ annotationHash: string(),
23430
+ /** The export manifest schema the version was cut under. */
23431
+ manifestSchema: string(),
23432
+ stats: RetrainDatasetStatsSchema
23433
+ });
23434
+ var CreateRetrainDatasetVersionResultSchema = discriminatedUnion("kind", [object({
23435
+ kind: literal("created"),
23436
+ version: RetrainDatasetVersionSchema
23437
+ }), object({
23438
+ kind: literal("refused"),
23439
+ reason: _enum([
23440
+ "empty-name",
23441
+ "duplicate-name",
23442
+ "no-frames"
23443
+ ])
23444
+ })]);
22342
23445
  /** The outcome of a lifecycle move owned by the retrain page. */
22343
23446
  var RetrainTransitionResultSchema = object({
22344
23447
  trackId: string(),
@@ -23056,7 +24159,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23056
24159
  auth: "admin"
23057
24160
  }), method(object({
23058
24161
  deviceId: number(),
23059
- trackId: string(),
24162
+ trackId: string().optional(),
23060
24163
  frameId: string()
23061
24164
  }), object({
23062
24165
  removed: boolean(),
@@ -23073,7 +24176,8 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23073
24176
  auth: "admin"
23074
24177
  }), method(object({
23075
24178
  deviceId: number(),
23076
- trackId: string(),
24179
+ /** The frame's track, when it has one — checked against the frame. */
24180
+ trackId: string().optional(),
23077
24181
  frameId: string(),
23078
24182
  subject: RetrainAssistSubjectSchema,
23079
24183
  /** Which node runs it. Absent ⇒ wherever an unowned call lands. */
@@ -23081,12 +24185,16 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23081
24185
  }), RetrainAssistResultSchema, {
23082
24186
  kind: "mutation",
23083
24187
  auth: "admin"
23084
- }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
24188
+ }), method(object({
24189
+ trackId: string().optional(),
24190
+ frameIds: array(string()).max(2e3).optional()
24191
+ }), array(RetrainAnnotationSchema).readonly(), {
23085
24192
  kind: "query",
23086
24193
  auth: "admin"
23087
24194
  }), method(object({
23088
24195
  deviceId: number(),
23089
- trackId: string(),
24196
+ /** The frame's track, when it has one — checked against the frame. */
24197
+ trackId: string().optional(),
23090
24198
  frameId: string(),
23091
24199
  annotations: array(RetrainAnnotationDraftSchema)
23092
24200
  }), array(RetrainAnnotationSchema).readonly(), {
@@ -23109,7 +24217,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23109
24217
  auth: "admin"
23110
24218
  }), method(object({
23111
24219
  deviceId: number(),
23112
- trackId: string(),
24220
+ trackId: string().optional(),
23113
24221
  frameId: string(),
23114
24222
  complete: boolean()
23115
24223
  }), RetrainFrameSchema, {
@@ -23123,6 +24231,104 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
23123
24231
  kind: "mutation",
23124
24232
  auth: "admin",
23125
24233
  timeoutMs: 60 * 6e4
24234
+ }), method(object({
24235
+ selection: RetrainDatasetSelectionSchema,
24236
+ completeOnly: boolean().optional()
24237
+ }), RetrainDatasetStatsSchema, {
24238
+ kind: "query",
24239
+ auth: "admin"
24240
+ }), method(object({
24241
+ name: string().max(120),
24242
+ selection: RetrainDatasetSelectionSchema,
24243
+ layout: RetrainExportLayoutSchema,
24244
+ completeOnly: boolean()
24245
+ }), CreateRetrainDatasetVersionResultSchema, {
24246
+ kind: "mutation",
24247
+ auth: "admin",
24248
+ timeoutMs: 12e4
24249
+ }), method(object({}), array(RetrainDatasetVersionSchema).readonly(), {
24250
+ kind: "query",
24251
+ auth: "admin"
24252
+ }), method(object({ id: string() }), object({ deleted: boolean() }), {
24253
+ kind: "mutation",
24254
+ auth: "admin"
24255
+ }), method(object({ id: string() }), object({
24256
+ found: boolean(),
24257
+ annotationHash: string(),
24258
+ matches: boolean(),
24259
+ missingFrames: number().int()
24260
+ }), {
24261
+ kind: "query",
24262
+ auth: "admin",
24263
+ timeoutMs: 12e4
24264
+ }), method(object({}), array(RetrainAssistProfileSchema).readonly(), {
24265
+ kind: "query",
24266
+ auth: "admin"
24267
+ }), method(object({
24268
+ deviceId: number(),
24269
+ trackId: string().optional(),
24270
+ frameId: string(),
24271
+ profileId: string(),
24272
+ classes: array(RetrainMacroClassSchema).min(1),
24273
+ boxes: array(object({
24274
+ ref: string(),
24275
+ bbox: RetrainBboxSchema,
24276
+ macroClass: RetrainMacroClassSchema,
24277
+ label: string().optional()
24278
+ })).max(50),
24279
+ allowCloud: boolean()
24280
+ }), RetrainLlmAssistResultSchema, {
24281
+ kind: "mutation",
24282
+ auth: "admin",
24283
+ timeoutMs: 18e4
24284
+ }), method(object({ name: string().max(120) }), RetrainCollectionCreateResultSchema, {
24285
+ kind: "mutation",
24286
+ auth: "admin"
24287
+ }), method(object({}), array(RetrainCollectionSchema).readonly(), {
24288
+ kind: "query",
24289
+ auth: "admin"
24290
+ }), method(object({
24291
+ id: string(),
24292
+ name: string().max(120)
24293
+ }), RetrainCollectionRenameResultSchema, {
24294
+ kind: "mutation",
24295
+ auth: "admin"
24296
+ }), method(object({ id: string() }), object({
24297
+ deleted: boolean(),
24298
+ removedFrames: number().int()
24299
+ }), {
24300
+ kind: "mutation",
24301
+ auth: "admin"
24302
+ }), method(object({
24303
+ collectionId: string(),
24304
+ deviceId: number(),
24305
+ epochMs: number()
24306
+ }), AddRetrainFrameFromRecordingResultSchema, {
24307
+ kind: "mutation",
24308
+ auth: "admin",
24309
+ timeoutMs: 6e4
24310
+ }), method(object({
24311
+ collectionId: string(),
24312
+ frameIds: array(string()).min(1).max(500)
24313
+ }), object({
24314
+ added: number().int(),
24315
+ alreadyMember: number().int(),
24316
+ unknownFrameIds: array(string()).readonly()
24317
+ }), {
24318
+ kind: "mutation",
24319
+ auth: "admin"
24320
+ }), method(object({
24321
+ collectionId: string(),
24322
+ frameId: string()
24323
+ }), object({
24324
+ removed: boolean(),
24325
+ deletedFrame: boolean()
24326
+ }), {
24327
+ kind: "mutation",
24328
+ auth: "admin"
24329
+ }), method(object({ collectionId: string() }), array(RetrainFrameSchema).readonly(), {
24330
+ kind: "query",
24331
+ auth: "admin"
23126
24332
  }), method(object({
23127
24333
  /** Which of the three event tables owns the row. */
23128
24334
  ownerType: EventOwnerTypeSchema,
@@ -23746,13 +24952,31 @@ var RecommendationReasonSchema = discriminatedUnion("kind", [
23746
24952
  object({
23747
24953
  kind: literal("no-family-build"),
23748
24954
  format: ModelFormatSchema$1
24955
+ }),
24956
+ object({
24957
+ kind: literal("kept-custom-pin"),
24958
+ modelId: string(),
24959
+ deviceKey: string()
23749
24960
  })
23750
24961
  ]);
24962
+ /** Why a device is left exactly as it is, whatever the plan would pick (D786). */
24963
+ var KeptReasonSchema = _enum(["custom-pin"]);
24964
+ /**
24965
+ * Where a choice's latency came from (D791): this node's own benchmark
24966
+ * result, or the hardware-class table. Measured on the node beats the table.
24967
+ */
24968
+ var LatencySourceSchema = discriminatedUnion("kind", [object({ kind: literal("table") }), object({
24969
+ kind: literal("node-benchmark"),
24970
+ resultId: string(),
24971
+ measuredAtMs: number()
24972
+ })]);
23751
24973
  var DeviceModelChoiceSchema = object({
23752
24974
  modelId: string(),
23753
24975
  p50Ms: number(),
23754
24976
  fps: number(),
23755
24977
  measured: boolean(),
24978
+ /** Absent on a plan from before D791 — read as the table. */
24979
+ source: LatencySourceSchema.optional(),
23756
24980
  /** Parallel sessions at the camera rate with the headroom kept free: ⌊fps × (1 − headroom) / camera fps⌋. */
23757
24981
  capacitySessions: number(),
23758
24982
  personRecall: number()
@@ -23763,6 +24987,8 @@ var DeviceRecommendationSchema = object({
23763
24987
  enabled: boolean(),
23764
24988
  available: boolean(),
23765
24989
  chosen: DeviceModelChoiceSchema.nullable(),
24990
+ /** Present when the device is kept as is: Apply writes nothing on it. */
24991
+ kept: KeptReasonSchema.optional(),
23766
24992
  reasons: array(RecommendationReasonSchema).readonly()
23767
24993
  });
23768
24994
  var NodeRecommendationSchema = object({
@@ -23816,6 +25042,17 @@ var AutoTuneWarningSchema = discriminatedUnion("kind", [
23816
25042
  kind: literal("coral-enabled"),
23817
25043
  nodeId: string(),
23818
25044
  deviceKey: string()
25045
+ }),
25046
+ object({
25047
+ kind: literal("custom-pin-kept"),
25048
+ nodeId: string(),
25049
+ deviceKey: string().nullable(),
25050
+ deviceId: number().nullable(),
25051
+ modelId: string()
25052
+ }),
25053
+ object({
25054
+ kind: literal("custom-registry-unreadable"),
25055
+ error: string()
23819
25056
  })
23820
25057
  ]);
23821
25058
  var AutoTuneOptionsSchema = object({
@@ -23994,13 +25231,14 @@ var SuggestSharesResultSchema = object({
23994
25231
  nodes: array(SuggestedNodeShareSchema).readonly()
23995
25232
  });
23996
25233
  /**
23997
- * Where the node and device shares come from (D750, D755).
23998
- * - `hardware` (default) — computed by the system from each node's static
23999
- * capacity (its accelerators at their Auto tune models, from the measured
24000
- * latency table), recomputed whenever a node or device joins, leaves, is
24001
- * switched on or off, or changes model. No load input.
24002
- * - `benchmark` — the same, from each node's measured capacity (node
24003
- * benchmark results); a node without results falls back to `hardware`.
25234
+ * Where the node and device shares come from (D750, D755, D791).
25235
+ * - `benchmark` (default since D791) — each node's capacity as its own node
25236
+ * benchmark measured it; a node without fresh results is sized from
25237
+ * `hardware` and says so. Measured on the node beats the table.
25238
+ * - `hardware` — computed from each node's static capacity only (its
25239
+ * accelerators at their Auto tune models, from the latency table).
25240
+ * Both are recomputed whenever a node or device joins, leaves, is switched
25241
+ * on or off, changes model, or a benchmark result is written. No load input.
24004
25242
  * - `manual` — the operator's stored sliders.
24005
25243
  * Either way a node or device that cannot take sessions gives its share to
24006
25244
  * the others in proportion; the stored values are never rewritten for that.
@@ -24049,6 +25287,362 @@ var EffectiveSharesSchema = object({
24049
25287
  nodeWeights: record(string(), number()),
24050
25288
  deviceWeights: record(string(), record(string(), number()))
24051
25289
  });
25290
+ /**
25291
+ * Wire shapes of the node benchmark (D791): the operator's plan, the
25292
+ * preflight the confirmation shows, the run the orchestrator owns, what the
25293
+ * measuring runner reports, and the result rows Auto tune and the automatic
25294
+ * shares read.
25295
+ *
25296
+ * ONE node at a time, owned by the pipeline orchestrator. While a run is
25297
+ * active the cluster is in BENCHMARK MODE for that node: it is not a
25298
+ * detection candidate, camera pins naming it are ignored so its sessions move
25299
+ * elsewhere, and both come back when the mode ends — after a crash or a hub
25300
+ * restart too (a persisted manifest, reconciled against the registry).
25301
+ *
25302
+ * Two measurements, both on the node, driven by its own runner (frames never
25303
+ * cross a process at frame rate, D9):
25304
+ * - `device` — one accelerator × one candidate detector, root only, open
25305
+ * loop: how many streams at the camera rate it carries inside the frame
25306
+ * interval;
25307
+ * - `pipeline` — the chosen detector plus the operator's detail steps
25308
+ * (faces, plates, classifiers, CLIP…), on varied frames from the bench
25309
+ * clip: how many parallel sessions the node carries before latency, drops,
25310
+ * CPU, RAM or the event loop give out.
25311
+ */
25312
+ /** Defaults and bounds, one place. */
25313
+ var NODE_BENCHMARK_DEFAULTS = {
25314
+ fpsPerStream: 10,
25315
+ budgetMinutes: 45,
25316
+ minBudgetMinutes: 10,
25317
+ maxBudgetMinutes: 120,
25318
+ /** A result older than this no longer beats the table. */
25319
+ staleAfterDays: 30,
25320
+ /** Warm-in per ramp step (not accounted). */
25321
+ settleSec: 5,
25322
+ /** Accounted window per ramp step. */
25323
+ measureSec: 20,
25324
+ /** Longest the drain may take before the run is refused. */
25325
+ drainTimeoutSec: 120,
25326
+ /** Candidate models per device in one run. */
25327
+ maxModelsPerDevice: 6
25328
+ };
25329
+ /** The two measurements a run can make. */
25330
+ var NodeBenchmarkPhaseSchema = _enum(["device", "pipeline"]);
25331
+ var NodeBenchmarkDevicePlanSchema = object({
25332
+ /** `<backend>:<device>` — `openvino:npu`, `coreml:all`, `cpu`. */
25333
+ deviceKey: string().min(1),
25334
+ /**
25335
+ * Root detector candidates for the `device` measurement, in the order
25336
+ * measured. The FIRST is the one the `pipeline` measurement runs.
25337
+ */
25338
+ modelIds: array(string().min(1)).min(1).max(NODE_BENCHMARK_DEFAULTS.maxModelsPerDevice)
25339
+ });
25340
+ /** What the operator confirmed. */
25341
+ var NodeBenchmarkPlanSchema = object({
25342
+ nodeId: string().min(1),
25343
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
25344
+ /** Which measurements run. At least one. */
25345
+ phases: array(NodeBenchmarkPhaseSchema).min(1).default(["device", "pipeline"]),
25346
+ /**
25347
+ * Detail steps (catalog step ids under the root: faces, plates,
25348
+ * classifiers, CLIP…) the `pipeline` measurement enables. The root
25349
+ * detector always runs.
25350
+ */
25351
+ steps: array(string().min(1)).default([]),
25352
+ /** Offered rate of one stream / session. */
25353
+ fpsPerStream: number().int().min(1).max(30).default(NODE_BENCHMARK_DEFAULTS.fpsPerStream),
25354
+ /** Hard deadline: the mode ends and the cluster is restored when it passes. */
25355
+ budgetMinutes: number().int().min(NODE_BENCHMARK_DEFAULTS.minBudgetMinutes).max(NODE_BENCHMARK_DEFAULTS.maxBudgetMinutes).default(NODE_BENCHMARK_DEFAULTS.budgetMinutes),
25356
+ /** Keep the models the run downloaded (default: delete what was not installed before). */
25357
+ keepDownloadedModels: boolean().default(false),
25358
+ /** Start although the other nodes' capacity does not cover the sessions running now. */
25359
+ acceptInsufficientHeadroom: boolean().default(false)
25360
+ });
25361
+ var NodeBenchmarkRefusalSchema = object({
25362
+ kind: _enum([
25363
+ "benchmark-active",
25364
+ "node-offline",
25365
+ "unknown-device",
25366
+ "no-phase",
25367
+ "insufficient-headroom"
25368
+ ]),
25369
+ detail: string(),
25370
+ overridable: boolean()
25371
+ });
25372
+ /** A camera whose detection leaves the node for the run. */
25373
+ var NodeBenchmarkMovingCameraSchema = object({
25374
+ deviceId: number(),
25375
+ /** Placed on the node now (a standing attach or a running session). */
25376
+ placedOnNode: boolean(),
25377
+ /** A node pin naming this node, ignored for the run. */
25378
+ pinnedToNode: boolean()
25379
+ });
25380
+ /** A camera that cannot leave: no other node can obtain its frames. */
25381
+ var NodeBenchmarkStayingCameraSchema = object({
25382
+ deviceId: number(),
25383
+ reason: literal("only-frame-source")
25384
+ });
25385
+ var NodeBenchmarkPreflightSchema = object({
25386
+ nodeId: string(),
25387
+ online: boolean(),
25388
+ moving: array(NodeBenchmarkMovingCameraSchema).readonly(),
25389
+ /** Keep running on the node during the run; the result is flagged contaminated. */
25390
+ staying: array(NodeBenchmarkStayingCameraSchema).readonly(),
25391
+ estimatedDurationMs: number(),
25392
+ /** The run ends and the cluster is restored at the latest after this long. */
25393
+ budgetMs: number(),
25394
+ phases: array(NodeBenchmarkPhaseSchema).readonly(),
25395
+ steps: array(string()).readonly(),
25396
+ devices: array(NodeBenchmarkDevicePlanSchema).readonly(),
25397
+ /** Parallel sessions the cluster runs now, and what the other nodes can carry. */
25398
+ headroom: object({
25399
+ sessionsNow: number(),
25400
+ otherNodesCapacitySessions: number().nullable()
25401
+ }),
25402
+ refusals: array(NodeBenchmarkRefusalSchema).readonly(),
25403
+ canStart: boolean()
25404
+ });
25405
+ /** Where the measuring runner is. */
25406
+ var NodeBenchProgressSchema = object({
25407
+ phase: _enum([
25408
+ "preparing",
25409
+ "device",
25410
+ "pipeline",
25411
+ "cleanup"
25412
+ ]),
25413
+ deviceKey: string().nullable(),
25414
+ modelId: string().nullable(),
25415
+ /** Streams (device) or sessions (pipeline) of the step running now. */
25416
+ load: number().nullable(),
25417
+ cellsDone: number(),
25418
+ cellsTotal: number(),
25419
+ message: string()
25420
+ });
25421
+ /** What limited a ramp. `none` = the ramp ran out of steps still passing. */
25422
+ var NodeBenchLimitSchema = _enum([
25423
+ "p95",
25424
+ "drops",
25425
+ "errors",
25426
+ "stall",
25427
+ "cpu",
25428
+ "ram",
25429
+ "none"
25430
+ ]);
25431
+ var NodeBenchRampStepSchema = object({
25432
+ load: number(),
25433
+ pass: boolean(),
25434
+ p95Ms: number(),
25435
+ dropRatio: number(),
25436
+ /** Completed frames per second over the accounted window. */
25437
+ fps: number(),
25438
+ cpuPct: number().nullable(),
25439
+ ramFreePct: number().nullable(),
25440
+ failReasons: array(string()).readonly()
25441
+ });
25442
+ var NodeBenchCellSchema = discriminatedUnion("phase", [object({
25443
+ phase: literal("device"),
25444
+ deviceKey: string(),
25445
+ modelId: string(),
25446
+ /** Single-stream latency (the K = 1 step). */
25447
+ p50Ms: number(),
25448
+ p95Ms: number(),
25449
+ p99Ms: number(),
25450
+ /** Frames per second sustained at the last passing step. */
25451
+ fps: number(),
25452
+ /** Streams at the camera rate the device carried inside the frame interval; 0 = not even one. */
25453
+ kMax: number(),
25454
+ limitedBy: NodeBenchLimitSchema,
25455
+ /** First call (model load + warm-up). */
25456
+ warmupMs: number(),
25457
+ ramp: array(NodeBenchRampStepSchema).readonly()
25458
+ }), object({
25459
+ phase: literal("pipeline"),
25460
+ deviceKey: string(),
25461
+ modelId: string(),
25462
+ steps: array(string()).readonly(),
25463
+ /** Parallel sessions at the camera rate the node carried; 0 = not even one. */
25464
+ maxSessions: number(),
25465
+ limitedBy: NodeBenchLimitSchema,
25466
+ /** Detail steps that produced at least one result on the clip — a step that never fired measured nothing. */
25467
+ stepsFired: array(string()).readonly(),
25468
+ warmupMs: number(),
25469
+ ramp: array(NodeBenchRampStepSchema).readonly()
25470
+ })]);
25471
+ /**
25472
+ * What a result was measured ON. A result whose fingerprint no longer matches
25473
+ * the node no longer beats the table.
25474
+ */
25475
+ var NodeBenchFingerprintSchema = object({
25476
+ pipelineVersion: string().nullable(),
25477
+ cpuModel: string().nullable(),
25478
+ ramGb: number().nullable(),
25479
+ os: string().nullable(),
25480
+ /** Per device: the pool the cells ran on (runtime + tuning). */
25481
+ pools: record(string(), object({
25482
+ runtime: string(),
25483
+ numWorkers: number(),
25484
+ concurrency: number(),
25485
+ batchMode: string()
25486
+ })).default({})
25487
+ });
25488
+ /** The frames the run used. */
25489
+ var NodeBenchClipSchema = object({
25490
+ /** `camstack-bench-v1` or `reference-images` (the fallback when the clip is not reachable). */
25491
+ id: string(),
25492
+ revision: string().nullable(),
25493
+ frames: number(),
25494
+ width: number(),
25495
+ height: number()
25496
+ });
25497
+ var NodeBenchRunnerInputSchema = object({
25498
+ runId: string().min(1),
25499
+ devices: array(NodeBenchmarkDevicePlanSchema).min(1),
25500
+ phases: array(NodeBenchmarkPhaseSchema).min(1),
25501
+ /** The full detail step tree root for the `pipeline` measurement is built on the node from these ids. */
25502
+ steps: array(string()).default([]),
25503
+ fpsPerStream: number().int().min(1).max(30),
25504
+ /** The runner stops on its own past this instant, whatever the hub does. */
25505
+ deadlineAtMs: number(),
25506
+ settleSec: number().min(0).max(60).default(NODE_BENCHMARK_DEFAULTS.settleSec),
25507
+ measureSec: number().min(2).max(300).default(NODE_BENCHMARK_DEFAULTS.measureSec),
25508
+ keepDownloadedModels: boolean().default(false)
25509
+ });
25510
+ var NodeBenchRunnerStateSchema = _enum([
25511
+ "running",
25512
+ "done",
25513
+ "failed",
25514
+ "aborted"
25515
+ ]);
25516
+ var NodeBenchRunnerStatusSchema = object({
25517
+ runId: string(),
25518
+ nodeId: string(),
25519
+ state: NodeBenchRunnerStateSchema,
25520
+ progress: NodeBenchProgressSchema.nullable(),
25521
+ /** Every finished cell so far — a run stopped half way keeps what it measured. */
25522
+ cells: array(NodeBenchCellSchema).readonly(),
25523
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
25524
+ clip: NodeBenchClipSchema.nullable(),
25525
+ /** Cameras seen running on the node during the run (they share its pools). */
25526
+ activeCameraIds: array(number()).readonly(),
25527
+ /** Models the run downloaded and then deleted (not installed before). */
25528
+ deletedModels: array(string()).readonly(),
25529
+ error: string().nullable(),
25530
+ startedAtMs: number(),
25531
+ finishedAtMs: number().nullable()
25532
+ });
25533
+ var NodeBenchmarkStateSchema = _enum([
25534
+ "draining",
25535
+ "measuring",
25536
+ "restoring",
25537
+ "done",
25538
+ "failed",
25539
+ "aborted"
25540
+ ]);
25541
+ /** Why a run ended. */
25542
+ var NodeBenchmarkEndReasonSchema = _enum([
25543
+ "completed",
25544
+ "operator-abort",
25545
+ "deadline",
25546
+ "node-lost",
25547
+ "runner-lost",
25548
+ "hub-restart",
25549
+ "drain-timeout",
25550
+ "failed"
25551
+ ]);
25552
+ var NodeBenchmarkRunSchema = object({
25553
+ runId: string(),
25554
+ nodeId: string(),
25555
+ state: NodeBenchmarkStateSchema,
25556
+ plan: NodeBenchmarkPlanSchema,
25557
+ startedAtMs: number(),
25558
+ deadlineAtMs: number(),
25559
+ finishedAtMs: number().nullable(),
25560
+ endReason: NodeBenchmarkEndReasonSchema.nullable(),
25561
+ error: string().nullable(),
25562
+ /** Cameras moved off the node for the run. */
25563
+ moved: array(number()).readonly(),
25564
+ /** Cameras that stayed (their only frame source is the node). */
25565
+ staying: array(number()).readonly(),
25566
+ /** Something else ran on the node's pools during the run. */
25567
+ contaminated: boolean(),
25568
+ progress: NodeBenchProgressSchema.nullable(),
25569
+ resultIds: array(string()).readonly()
25570
+ });
25571
+ /** `getNodeBenchmarkStatus`: the active run (or the last one), and whether benchmark mode is on. */
25572
+ var NodeBenchmarkStatusSchema = object({
25573
+ /** The node the cluster is in benchmark mode for; null = none. */
25574
+ modeNodeId: string().nullable(),
25575
+ run: NodeBenchmarkRunSchema.nullable()
25576
+ });
25577
+ /**
25578
+ * One stored measurement — the only authority Auto tune and the automatic
25579
+ * shares read measured capacity from. Written by the orchestrator when a run
25580
+ * ends, never by anyone else.
25581
+ */
25582
+ var NodeBenchmarkResultSchema = object({
25583
+ id: string(),
25584
+ runId: string(),
25585
+ nodeId: string(),
25586
+ cell: NodeBenchCellSchema,
25587
+ fpsPerStream: number(),
25588
+ fingerprint: NodeBenchFingerprintSchema.nullable(),
25589
+ clip: NodeBenchClipSchema.nullable(),
25590
+ /** Other work shared the node's pools (a camera that could not move, or the hub's own duties). */
25591
+ contaminated: boolean(),
25592
+ stayingCameras: array(number()).readonly(),
25593
+ /** The run ended early; the cell itself completed. */
25594
+ partialRun: boolean(),
25595
+ measuredAtMs: number()
25596
+ });
25597
+ var ListNodeBenchmarkResultsInputSchema = object({
25598
+ nodeId: string().optional(),
25599
+ deviceKey: string().optional()
25600
+ });
25601
+ /** A result with its standing today: does it still beat the table? */
25602
+ var NodeBenchmarkResultViewSchema = NodeBenchmarkResultSchema.extend({
25603
+ /** `fresh` beats the table; `stale` falls back to it; `superseded` = a newer row covers the same cell. */
25604
+ standing: _enum([
25605
+ "fresh",
25606
+ "stale",
25607
+ "superseded"
25608
+ ]),
25609
+ staleWhy: _enum([
25610
+ "age",
25611
+ "runtime",
25612
+ "pool-tuning"
25613
+ ]).nullable()
25614
+ });
25615
+ object({
25616
+ runId: string(),
25617
+ nodeId: string(),
25618
+ startedAtMs: number(),
25619
+ deadlineAtMs: number(),
25620
+ plan: NodeBenchmarkPlanSchema,
25621
+ moved: array(number()).readonly(),
25622
+ staying: array(number()).readonly()
25623
+ });
25624
+ /** Candidate detectors per device, for the plan editor. */
25625
+ var NodeBenchmarkCandidatesSchema = object({
25626
+ nodeId: string(),
25627
+ reachable: boolean(),
25628
+ devices: array(object({
25629
+ deviceKey: string(),
25630
+ enabled: boolean(),
25631
+ available: boolean(),
25632
+ /** Ordered: what Auto tune would pick first, then the rest of the family by accuracy. */
25633
+ suggested: array(string()).readonly(),
25634
+ /** Every root detector the device has a build for. */
25635
+ all: array(string()).readonly(),
25636
+ /** The model the device runs now, when pinned. */
25637
+ currentModelId: string().nullable()
25638
+ })).readonly(),
25639
+ /** Detail steps the node's catalog offers under the root (for the `pipeline` measurement). */
25640
+ steps: array(object({
25641
+ id: string(),
25642
+ name: string(),
25643
+ slot: string()
25644
+ })).readonly()
25645
+ });
24052
25646
  object({
24053
25647
  activeCameras: number(),
24054
25648
  throttledCameras: number(),
@@ -25137,7 +26731,16 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
25137
26731
  }), ParkedTrackFrameSchema.nullable()), method(object({
25138
26732
  deviceId: number(),
25139
26733
  trackId: string()
25140
- }), object({ released: number().int().nonnegative() }), { kind: "mutation" });
26734
+ }), object({ released: number().int().nonnegative() }), { kind: "mutation" }), method(NodeBenchRunnerInputSchema, object({
26735
+ accepted: literal(true),
26736
+ runId: string()
26737
+ }), {
26738
+ kind: "mutation",
26739
+ auth: "admin"
26740
+ }), method(object({ runId: string() }), NodeBenchRunnerStatusSchema.nullable(), { auth: "admin" }), method(object({ runId: string() }), object({ aborted: boolean() }), {
26741
+ kind: "mutation",
26742
+ auth: "admin"
26743
+ });
25141
26744
  var CameraPipelineConfigSchema = object({
25142
26745
  engine: PipelineEngineChoiceSchema.optional(),
25143
26746
  steps: array(PipelineStepInputSchema).readonly(),
@@ -25776,6 +27379,21 @@ method(object({
25776
27379
  }), method(PlacementStatsInputSchema, PlacementStatsSchema, { auth: "admin" }), method(SuggestSharesInputSchema, SuggestSharesResultSchema, { auth: "admin" }), method(_void(), EffectiveSharesSchema, { auth: "admin" }), method(SetShareSourceInputSchema, object({ success: literal(true) }), {
25777
27380
  kind: "mutation",
25778
27381
  auth: "admin"
27382
+ }), method(NodeBenchmarkPlanSchema, NodeBenchmarkPreflightSchema, { auth: "admin" }), method(NodeBenchmarkPlanSchema, discriminatedUnion("kind", [object({
27383
+ kind: literal("started"),
27384
+ runId: string()
27385
+ }), object({
27386
+ kind: literal("refused"),
27387
+ preflight: NodeBenchmarkPreflightSchema
27388
+ })]), {
27389
+ kind: "mutation",
27390
+ auth: "admin"
27391
+ }), method(_void(), NodeBenchmarkStatusSchema, { auth: "admin" }), method(object({ runId: string() }), object({ aborted: boolean() }), {
27392
+ kind: "mutation",
27393
+ auth: "admin"
27394
+ }), method(object({ nodeId: string() }), NodeBenchmarkCandidatesSchema, { auth: "admin" }), method(ListNodeBenchmarkResultsInputSchema, array(NodeBenchmarkResultViewSchema).readonly(), { auth: "admin" }), method(object({ id: string() }), object({ deleted: boolean() }), {
27395
+ kind: "mutation",
27396
+ auth: "admin"
25779
27397
  }), method(object({ deviceId: number() }), CameraPipelineSettingsSchema.nullable()), method(object({
25780
27398
  deviceId: number(),
25781
27399
  addonId: string(),
@@ -30892,6 +32510,9 @@ var CreateIntegrationInputSchema = object({
30892
32510
  enabled: boolean().optional(),
30893
32511
  info: record(string(), unknown()).optional(),
30894
32512
  settings: record(string(), unknown()).optional(),
32513
+ /** Keys of `settings` the form's schema declares secret (by type) — kept in
32514
+ * the keychain, not the table (D787). */
32515
+ secretKeys: array(string()).optional(),
30895
32516
  skipRestart: boolean().optional()
30896
32517
  });
30897
32518
  var UpdateIntegrationInputSchema = object({
@@ -30915,7 +32536,9 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
30915
32536
  auth: "admin"
30916
32537
  }), method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }), method(object({
30917
32538
  id: string(),
30918
- settings: record(string(), unknown())
32539
+ settings: record(string(), unknown()),
32540
+ /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
32541
+ secretKeys: array(string()).optional()
30919
32542
  }), object({ success: boolean() }), {
30920
32543
  kind: "mutation",
30921
32544
  auth: "admin"
@@ -39620,6 +41243,96 @@ Object.freeze({
39620
41243
  addonId: null,
39621
41244
  access: "create"
39622
41245
  },
41246
+ "keychain.delete": {
41247
+ capName: "keychain",
41248
+ capScope: "system",
41249
+ addonId: null,
41250
+ access: "delete"
41251
+ },
41252
+ "keychain.getState": {
41253
+ capName: "keychain",
41254
+ capScope: "system",
41255
+ addonId: null,
41256
+ access: "view"
41257
+ },
41258
+ "keychain.listMeta": {
41259
+ capName: "keychain",
41260
+ capScope: "system",
41261
+ addonId: null,
41262
+ access: "view"
41263
+ },
41264
+ "keychain.put": {
41265
+ capName: "keychain",
41266
+ capScope: "system",
41267
+ addonId: null,
41268
+ access: "create"
41269
+ },
41270
+ "keychain.resolve": {
41271
+ capName: "keychain",
41272
+ capScope: "system",
41273
+ addonId: null,
41274
+ access: "view"
41275
+ },
41276
+ "keychainAdmin.deleteOrphans": {
41277
+ capName: "keychain-admin",
41278
+ capScope: "system",
41279
+ addonId: null,
41280
+ access: "delete"
41281
+ },
41282
+ "keychainAdmin.downloadRecoveryKey": {
41283
+ capName: "keychain-admin",
41284
+ capScope: "system",
41285
+ addonId: null,
41286
+ access: "create"
41287
+ },
41288
+ "keychainAdmin.listAudit": {
41289
+ capName: "keychain-admin",
41290
+ capScope: "system",
41291
+ addonId: null,
41292
+ access: "view"
41293
+ },
41294
+ "keychainAdmin.listSecrets": {
41295
+ capName: "keychain-admin",
41296
+ capScope: "system",
41297
+ addonId: null,
41298
+ access: "view"
41299
+ },
41300
+ "keychainAdmin.purgeRetiredKeys": {
41301
+ capName: "keychain-admin",
41302
+ capScope: "system",
41303
+ addonId: null,
41304
+ access: "delete"
41305
+ },
41306
+ "keychainAdmin.resetKeychain": {
41307
+ capName: "keychain-admin",
41308
+ capScope: "system",
41309
+ addonId: null,
41310
+ access: "delete"
41311
+ },
41312
+ "keychainAdmin.reveal": {
41313
+ capName: "keychain-admin",
41314
+ capScope: "system",
41315
+ addonId: null,
41316
+ access: "create"
41317
+ },
41318
+ "keychainAdmin.rotateMasterKey": {
41319
+ capName: "keychain-admin",
41320
+ capScope: "system",
41321
+ addonId: null,
41322
+ access: "create"
41323
+ },
41324
+ "keychainAdmin.setSystemSecret": {
41325
+ capName: "keychain-admin",
41326
+ capScope: "system",
41327
+ addonId: null,
41328
+ access: "create"
41329
+ },
41330
+ "keychainAdmin.status": {
41331
+ capName: "keychain-admin",
41332
+ capScope: "system",
41333
+ addonId: null,
41334
+ access: "view"
41335
+ },
39623
41336
  "lawnMowerControl.dock": {
39624
41337
  capName: "lawn-mower-control",
39625
41338
  capScope: "device",
@@ -40994,6 +42707,18 @@ Object.freeze({
40994
42707
  addonId: null,
40995
42708
  access: "create"
40996
42709
  },
42710
+ "pipelineAnalytics.addRetrainFrameFromRecording": {
42711
+ capName: "pipeline-analytics",
42712
+ capScope: "device",
42713
+ addonId: null,
42714
+ access: "create"
42715
+ },
42716
+ "pipelineAnalytics.addRetrainFramesToCollection": {
42717
+ capName: "pipeline-analytics",
42718
+ capScope: "device",
42719
+ addonId: null,
42720
+ access: "create"
42721
+ },
40997
42722
  "pipelineAnalytics.applyDeviceSettingsPatch": {
40998
42723
  capName: "pipeline-analytics",
40999
42724
  capScope: "device",
@@ -41042,12 +42767,36 @@ Object.freeze({
41042
42767
  addonId: null,
41043
42768
  access: "view"
41044
42769
  },
42770
+ "pipelineAnalytics.createRetrainCollection": {
42771
+ capName: "pipeline-analytics",
42772
+ capScope: "device",
42773
+ addonId: null,
42774
+ access: "create"
42775
+ },
42776
+ "pipelineAnalytics.createRetrainDatasetVersion": {
42777
+ capName: "pipeline-analytics",
42778
+ capScope: "device",
42779
+ addonId: null,
42780
+ access: "create"
42781
+ },
41045
42782
  "pipelineAnalytics.deleteDeviceEvents": {
41046
42783
  capName: "pipeline-analytics",
41047
42784
  capScope: "device",
41048
42785
  addonId: null,
41049
42786
  access: "delete"
41050
42787
  },
42788
+ "pipelineAnalytics.deleteRetrainCollection": {
42789
+ capName: "pipeline-analytics",
42790
+ capScope: "device",
42791
+ addonId: null,
42792
+ access: "delete"
42793
+ },
42794
+ "pipelineAnalytics.deleteRetrainDatasetVersion": {
42795
+ capName: "pipeline-analytics",
42796
+ capScope: "device",
42797
+ addonId: null,
42798
+ access: "delete"
42799
+ },
41051
42800
  "pipelineAnalytics.deleteTracks": {
41052
42801
  capName: "pipeline-analytics",
41053
42802
  capScope: "device",
@@ -41252,6 +43001,30 @@ Object.freeze({
41252
43001
  addonId: null,
41253
43002
  access: "view"
41254
43003
  },
43004
+ "pipelineAnalytics.listRetrainAssistProfiles": {
43005
+ capName: "pipeline-analytics",
43006
+ capScope: "device",
43007
+ addonId: null,
43008
+ access: "view"
43009
+ },
43010
+ "pipelineAnalytics.listRetrainCollectionFrames": {
43011
+ capName: "pipeline-analytics",
43012
+ capScope: "device",
43013
+ addonId: null,
43014
+ access: "view"
43015
+ },
43016
+ "pipelineAnalytics.listRetrainCollections": {
43017
+ capName: "pipeline-analytics",
43018
+ capScope: "device",
43019
+ addonId: null,
43020
+ access: "view"
43021
+ },
43022
+ "pipelineAnalytics.listRetrainDatasetVersions": {
43023
+ capName: "pipeline-analytics",
43024
+ capScope: "device",
43025
+ addonId: null,
43026
+ access: "view"
43027
+ },
41255
43028
  "pipelineAnalytics.listRetrainFrames": {
41256
43029
  capName: "pipeline-analytics",
41257
43030
  capScope: "device",
@@ -41294,12 +43067,24 @@ Object.freeze({
41294
43067
  addonId: null,
41295
43068
  access: "create"
41296
43069
  },
43070
+ "pipelineAnalytics.previewRetrainDataset": {
43071
+ capName: "pipeline-analytics",
43072
+ capScope: "device",
43073
+ addonId: null,
43074
+ access: "view"
43075
+ },
41297
43076
  "pipelineAnalytics.proposeRetrainAnnotations": {
41298
43077
  capName: "pipeline-analytics",
41299
43078
  capScope: "device",
41300
43079
  addonId: null,
41301
43080
  access: "create"
41302
43081
  },
43082
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": {
43083
+ capName: "pipeline-analytics",
43084
+ capScope: "device",
43085
+ addonId: null,
43086
+ access: "create"
43087
+ },
41303
43088
  "pipelineAnalytics.pruneEvents": {
41304
43089
  capName: "pipeline-analytics",
41305
43090
  capScope: "device",
@@ -41354,6 +43139,18 @@ Object.freeze({
41354
43139
  addonId: null,
41355
43140
  access: "create"
41356
43141
  },
43142
+ "pipelineAnalytics.removeRetrainFrameFromCollection": {
43143
+ capName: "pipeline-analytics",
43144
+ capScope: "device",
43145
+ addonId: null,
43146
+ access: "delete"
43147
+ },
43148
+ "pipelineAnalytics.renameRetrainCollection": {
43149
+ capName: "pipeline-analytics",
43150
+ capScope: "device",
43151
+ addonId: null,
43152
+ access: "create"
43153
+ },
41357
43154
  "pipelineAnalytics.restageRetrainTrack": {
41358
43155
  capName: "pipeline-analytics",
41359
43156
  capScope: "device",
@@ -41414,6 +43211,12 @@ Object.freeze({
41414
43211
  addonId: null,
41415
43212
  access: "create"
41416
43213
  },
43214
+ "pipelineAnalytics.verifyRetrainDatasetVersion": {
43215
+ capName: "pipeline-analytics",
43216
+ capScope: "device",
43217
+ addonId: null,
43218
+ access: "view"
43219
+ },
41417
43220
  "pipelineAnalytics.wipeAllAnalytics": {
41418
43221
  capName: "pipeline-analytics",
41419
43222
  capScope: "device",
@@ -41642,6 +43445,12 @@ Object.freeze({
41642
43445
  addonId: null,
41643
43446
  access: "view"
41644
43447
  },
43448
+ "pipelineOrchestrator.abortNodeBenchmark": {
43449
+ capName: "pipeline-orchestrator",
43450
+ capScope: "system",
43451
+ addonId: null,
43452
+ access: "create"
43453
+ },
41645
43454
  "pipelineOrchestrator.applyAutoTune": {
41646
43455
  capName: "pipeline-orchestrator",
41647
43456
  capScope: "system",
@@ -41666,6 +43475,12 @@ Object.freeze({
41666
43475
  addonId: null,
41667
43476
  access: "create"
41668
43477
  },
43478
+ "pipelineOrchestrator.deleteNodeBenchmarkResult": {
43479
+ capName: "pipeline-orchestrator",
43480
+ capScope: "system",
43481
+ addonId: null,
43482
+ access: "delete"
43483
+ },
41669
43484
  "pipelineOrchestrator.getAgentLoad": {
41670
43485
  capName: "pipeline-orchestrator",
41671
43486
  capScope: "system",
@@ -41774,6 +43589,24 @@ Object.freeze({
41774
43589
  addonId: null,
41775
43590
  access: "view"
41776
43591
  },
43592
+ "pipelineOrchestrator.getNodeBenchmarkCandidates": {
43593
+ capName: "pipeline-orchestrator",
43594
+ capScope: "system",
43595
+ addonId: null,
43596
+ access: "view"
43597
+ },
43598
+ "pipelineOrchestrator.getNodeBenchmarkPreflight": {
43599
+ capName: "pipeline-orchestrator",
43600
+ capScope: "system",
43601
+ addonId: null,
43602
+ access: "view"
43603
+ },
43604
+ "pipelineOrchestrator.getNodeBenchmarkStatus": {
43605
+ capName: "pipeline-orchestrator",
43606
+ capScope: "system",
43607
+ addonId: null,
43608
+ access: "view"
43609
+ },
41777
43610
  "pipelineOrchestrator.getNodeInferenceDevices": {
41778
43611
  capName: "pipeline-orchestrator",
41779
43612
  capScope: "system",
@@ -41816,6 +43649,12 @@ Object.freeze({
41816
43649
  addonId: null,
41817
43650
  access: "view"
41818
43651
  },
43652
+ "pipelineOrchestrator.listNodeBenchmarkResults": {
43653
+ capName: "pipeline-orchestrator",
43654
+ capScope: "system",
43655
+ addonId: null,
43656
+ access: "view"
43657
+ },
41819
43658
  "pipelineOrchestrator.pauseForStorageMigration": {
41820
43659
  capName: "pipeline-orchestrator",
41821
43660
  capScope: "system",
@@ -41960,6 +43799,12 @@ Object.freeze({
41960
43799
  addonId: null,
41961
43800
  access: "create"
41962
43801
  },
43802
+ "pipelineOrchestrator.startNodeBenchmark": {
43803
+ capName: "pipeline-orchestrator",
43804
+ capScope: "system",
43805
+ addonId: null,
43806
+ access: "create"
43807
+ },
41963
43808
  "pipelineOrchestrator.suggestShares": {
41964
43809
  capName: "pipeline-orchestrator",
41965
43810
  capScope: "system",
@@ -41978,6 +43823,12 @@ Object.freeze({
41978
43823
  addonId: null,
41979
43824
  access: "create"
41980
43825
  },
43826
+ "pipelineRunner.abortNodeBench": {
43827
+ capName: "pipeline-runner",
43828
+ capScope: "system",
43829
+ addonId: null,
43830
+ access: "create"
43831
+ },
41981
43832
  "pipelineRunner.attachCamera": {
41982
43833
  capName: "pipeline-runner",
41983
43834
  capScope: "system",
@@ -42026,6 +43877,12 @@ Object.freeze({
42026
43877
  addonId: null,
42027
43878
  access: "view"
42028
43879
  },
43880
+ "pipelineRunner.getNodeBenchStatus": {
43881
+ capName: "pipeline-runner",
43882
+ capScope: "system",
43883
+ addonId: null,
43884
+ access: "view"
43885
+ },
42029
43886
  "pipelineRunner.getParkedTrackFrame": {
42030
43887
  capName: "pipeline-runner",
42031
43888
  capScope: "system",
@@ -42068,6 +43925,12 @@ Object.freeze({
42068
43925
  addonId: null,
42069
43926
  access: "create"
42070
43927
  },
43928
+ "pipelineRunner.startNodeBench": {
43929
+ capName: "pipeline-runner",
43930
+ capScope: "system",
43931
+ addonId: null,
43932
+ access: "create"
43933
+ },
42071
43934
  "plateGallery.assignPlate": {
42072
43935
  capName: "plate-gallery",
42073
43936
  capScope: "system",
@@ -47001,6 +48864,11 @@ Object.freeze({
47001
48864
  form: "single",
47002
48865
  optional: false
47003
48866
  }],
48867
+ "pipelineAnalytics.addRetrainFrameFromRecording": [{
48868
+ name: "deviceId",
48869
+ form: "single",
48870
+ optional: false
48871
+ }],
47004
48872
  "pipelineAnalytics.applyDeviceSettingsPatch": [{
47005
48873
  name: "deviceId",
47006
48874
  form: "single",
@@ -47191,6 +49059,11 @@ Object.freeze({
47191
49059
  form: "single",
47192
49060
  optional: false
47193
49061
  }],
49062
+ "pipelineAnalytics.proposeRetrainAnnotationsWithLlm": [{
49063
+ name: "deviceId",
49064
+ form: "single",
49065
+ optional: false
49066
+ }],
47194
49067
  "pipelineAnalytics.pruneEventsBefore": [{
47195
49068
  name: "deviceId",
47196
49069
  form: "single",
@@ -49297,14 +51170,4 @@ DEFAULT_NATIVE_LEASE_SETTINGS.admission;
49297
51170
  var MB = 1024 * 1024;
49298
51171
  1024 * MB, 3072 * MB;
49299
51172
  //#endregion
49300
- //#region src/hub-browser-origin.ts
49301
- async function hubBrowserOrigin(localNetwork, logger) {
49302
- try {
49303
- return (await localNetwork.getAddresses.query()).roles.publicEndpoint.resolved;
49304
- } catch (err) {
49305
- logger.warn("hub address unavailable from local-network — using the localhost default", { meta: { error: err instanceof Error ? err.message : String(err) } });
49306
- return null;
49307
- }
49308
- }
49309
- //#endregion
49310
- export { buildAddonRouteProvider as a, userPasskeysCapability as c, array as d, boolean as f, string as h, authProviderCapability as i, errMsg as l, object as m, addonRoutesCapability as n, isDisplayIconKey as o, number as p, addonWidgetsSourceCapability as r, loginMethodCapability as s, hubBrowserOrigin as t, BaseAddon as u };
51173
+ export { isDisplayIconKey as a, errMsg as c, boolean as d, number as f, buildAddonRouteProvider as i, BaseAddon as l, string as m, addonWidgetsSourceCapability as n, loginMethodCapability as o, object as p, authProviderCapability as r, userPasskeysCapability as s, addonRoutesCapability as t, array as u };