@camstack/addon-provider-amcrest 0.2.165 → 0.2.167

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.
package/dist/addon.js CHANGED
@@ -6015,7 +6015,7 @@ var ZodIssueCode = {
6015
6015
  var ZodFirstPartyTypeKind;
6016
6016
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6017
6017
  //#endregion
6018
- //#region ../types/dist/sleep-Cv4Zmie9.mjs
6018
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
6019
6019
  /**
6020
6020
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6021
6021
  * window to float samples (D455).
@@ -6824,6 +6824,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6824
6824
  }
6825
6825
  return out;
6826
6826
  }
6827
+ /** Every scope, in the order the guard and the docs list them. */
6828
+ var SCOPED_SETTINGS_SCOPES = [
6829
+ "cluster",
6830
+ "device-defaults",
6831
+ "node"
6832
+ ];
6827
6833
  /**
6828
6834
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6829
6835
  *
@@ -7638,6 +7644,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7638
7644
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7639
7645
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7640
7646
  /**
7647
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7648
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7649
+ * through `api` (guard `check-migration-ports-surface`).
7650
+ */
7651
+ function migrationSet(catalogue, bindPorts) {
7652
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7653
+ }
7654
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7655
+ function refuseMixed(form, kept, dropped) {
7656
+ if (dropped > 0) throw new Error(`runMigrations(${form}): ${dropped} of ${kept + dropped} entries are of the other kind and would be dropped; pass one kind per call`);
7657
+ }
7658
+ function catalogueOf(list) {
7659
+ const kept = list.filter((entry) => !("execute" in entry));
7660
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7661
+ return kept;
7662
+ }
7663
+ function boundOf(list) {
7664
+ const kept = list.filter((entry) => "execute" in entry);
7665
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7666
+ return kept;
7667
+ }
7668
+ /**
7641
7669
  * Base class for CamStack addons. Eliminates settings boilerplate:
7642
7670
  *
7643
7671
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7715,6 +7743,13 @@ var BaseAddon = class {
7715
7743
  */
7716
7744
  secretStatePaths = [];
7717
7745
  _addonSecretTree = null;
7746
+ /**
7747
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7748
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7749
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7750
+ */
7751
+ _scopedByCap = /* @__PURE__ */ new Map();
7752
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7718
7753
  _deviceSecretTree = null;
7719
7754
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7720
7755
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7784,6 +7819,7 @@ var BaseAddon = class {
7784
7819
  this._ctx = context;
7785
7820
  this._secretSettings = null;
7786
7821
  }
7822
+ await this.loadScopedSchemas();
7787
7823
  await this.resolveConfig();
7788
7824
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7789
7825
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7793,25 +7829,24 @@ var BaseAddon = class {
7793
7829
  const normalized = normalizeAddonInitResult(result);
7794
7830
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7795
7831
  this._registeredCapNames = providers.map((p) => p.capability.name);
7832
+ await this.loadScopedSchemas();
7796
7833
  return normalized;
7797
7834
  }
7835
+ async runMigrations(first, second, third) {
7836
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7837
+ return this.runBound(boundOf(first), second);
7838
+ }
7798
7839
  /**
7799
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7800
- * engine. Call it at the point of the boot where the data must already have the new
7801
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7802
- * restored devices — with the catalogue bound to the addon's ports
7803
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7804
- *
7805
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7806
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7807
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7808
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7809
- *
7810
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7811
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7812
- * omitted applied ids "newer").
7840
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7841
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7842
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7813
7843
  */
7814
- async runMigrations(migrations, options) {
7844
+ async runMigrationSets(sets, options) {
7845
+ const api = this.ctx.migrationApi;
7846
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7847
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7848
+ }
7849
+ async runBound(migrations, options) {
7815
7850
  const api = this.ctx.api.migrations;
7816
7851
  const report = await runAddonMigrations({
7817
7852
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7881,6 +7916,16 @@ var BaseAddon = class {
7881
7916
  schema(schema) {
7882
7917
  return schema;
7883
7918
  }
7919
+ /**
7920
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7921
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7922
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7923
+ * must already know which keys are per node. Names the providers register at init are added
7924
+ * once known.
7925
+ */
7926
+ scopedSettingsCapabilities() {
7927
+ return [];
7928
+ }
7884
7929
  /** Override to provide global-level settings UI schema. */
7885
7930
  globalSettingsSchema(_cap) {
7886
7931
  return null;
@@ -7924,7 +7969,8 @@ var BaseAddon = class {
7924
7969
  return [];
7925
7970
  }
7926
7971
  async getGlobalSettings(overlay, cap, nodeId) {
7927
- const schema = this.globalSettingsSchema(cap);
7972
+ await this.loadScopedSchemas(cap);
7973
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7928
7974
  if (!schema) return { sections: [] };
7929
7975
  const projected = await this.readRawProjectedStore(nodeId, cap);
7930
7976
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -7959,10 +8005,9 @@ var BaseAddon = class {
7959
8005
  *
7960
8006
  * Override it only when an `instanceMode: multiple` addon's instances differ: an NVR integration
7961
8007
  * needs its connection fields, the default integration the addon's own sections. It is the
7962
- * SHAPE of the form only — the values live in `integrations.getSettings`, and the write path is
7963
- * unchanged (`integrations.setSettings` for an account integration).
8008
+ * SHAPE of the form only — the values live on the instance record.
7964
8009
  */
7965
- async integrationSettingsSchema(_instance) {
8010
+ async integrationFormSchema(_instance) {
7966
8011
  return null;
7967
8012
  }
7968
8013
  /**
@@ -8008,7 +8053,7 @@ var BaseAddon = class {
8008
8053
  * per-instance schema when it declares one, else its global schema (what they always showed).
8009
8054
  */
8010
8055
  async getIntegrationFormSchema(instance, nodeId) {
8011
- const scoped = await this.integrationSettingsSchema(instance);
8056
+ const scoped = await this.integrationFormSchema(instance);
8012
8057
  if (scoped === null) return this.getGlobalSettings(void 0, void 0, nodeId);
8013
8058
  return hydrateSchema(scoped, {}, { inlineSecretsAsViews: true });
8014
8059
  }
@@ -8056,6 +8101,7 @@ var BaseAddon = class {
8056
8101
  * resolved blob back is a no-op for every unchanged secret.
8057
8102
  */
8058
8103
  async resolveGlobalStore(nodeId, cap) {
8104
+ await this.loadScopedSchemas(cap);
8059
8105
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8060
8106
  return this.projectForNode(raw, nodeId, cap);
8061
8107
  }
@@ -8066,6 +8112,7 @@ var BaseAddon = class {
8066
8112
  }
8067
8113
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8068
8114
  async readRawProjectedStore(nodeId, cap) {
8115
+ await this.loadScopedSchemas(cap);
8069
8116
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8070
8117
  return this.projectForNode(raw, nodeId, cap);
8071
8118
  }
@@ -8168,6 +8215,7 @@ var BaseAddon = class {
8168
8215
  await this.applyGlobalPatch(patch, nodeId);
8169
8216
  }
8170
8217
  async applyGlobalPatch(barePatch, nodeId) {
8218
+ await this.loadScopedSchemas();
8171
8219
  const keys = this.perNodeKeys();
8172
8220
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8173
8221
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8181,7 +8229,8 @@ var BaseAddon = class {
8181
8229
  await this.resolveConfig();
8182
8230
  await this.onConfigChanged();
8183
8231
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8184
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8232
+ const legacy = this.globalSettingsSchema();
8233
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8185
8234
  }
8186
8235
  /**
8187
8236
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8189,14 +8238,67 @@ var BaseAddon = class {
8189
8238
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8190
8239
  * settings API behaves exactly like the legacy node-agnostic one.
8191
8240
  */
8192
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8241
+ /**
8242
+ * Load the scoped schemas of every capability this addon declares (the override and the
8243
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8244
+ * derived from the previous set. Idempotent.
8245
+ */
8246
+ async loadScopedSchemas(extraCap) {
8247
+ const caps = new Set([
8248
+ ...this.scopedSettingsCapabilities(),
8249
+ ...this._registeredCapNames,
8250
+ ...extraCap === void 0 ? [] : [extraCap]
8251
+ ]);
8252
+ let added = false;
8253
+ for (const cap of caps) {
8254
+ if (this._scopedByCap.has(cap)) continue;
8255
+ const loaded = [];
8256
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8257
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8258
+ if (schema !== null) loaded.push({
8259
+ scope,
8260
+ schema
8261
+ });
8262
+ }
8263
+ this._scopedByCap.set(cap, loaded);
8264
+ added = true;
8265
+ }
8266
+ if (!added) return;
8267
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8268
+ this._addonSecretTree = null;
8269
+ }
8270
+ /**
8271
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8272
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8273
+ */
8274
+ scopedFormSchema(cap) {
8275
+ const byId = /* @__PURE__ */ new Map();
8276
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8277
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8278
+ }
8279
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8280
+ loadedScopedSchemas(cap) {
8281
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8282
+ return [...this._scopedByCap.values()].flat();
8283
+ }
8284
+ /**
8285
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8286
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8287
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8288
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8289
+ * Call {@link loadScopedSchemas} first (the async seams do).
8290
+ */
8193
8291
  perNodeKeys(cap) {
8194
8292
  const cacheKey = cap ?? "";
8195
- const cached = this._perNodeKeysCache.get(cacheKey);
8293
+ const cached = this._nodeKeysByCap.get(cacheKey);
8196
8294
  if (cached) return cached;
8197
- const schema = this.globalSettingsSchema(cap);
8198
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8199
- this._perNodeKeysCache.set(cacheKey, keys);
8295
+ const legacy = this.globalSettingsSchema(cap);
8296
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8297
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8298
+ if (scope !== "node") continue;
8299
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8300
+ }
8301
+ this._nodeKeysByCap.set(cacheKey, keys);
8200
8302
  return keys;
8201
8303
  }
8202
8304
  /**
@@ -8206,10 +8308,9 @@ var BaseAddon = class {
8206
8308
  * time to return its response before the addon is torn down and
8207
8309
  * re-initialised by `AddonRegistryService.restartAddon`.
8208
8310
  */
8209
- maybeAutoRestart(patchKeys, schema) {
8210
- if (!schema) return;
8311
+ maybeAutoRestart(patchKeys, schemas) {
8211
8312
  const restartKeys = /* @__PURE__ */ new Set();
8212
- for (const section of schema.sections) for (const field of section.fields) {
8313
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8213
8314
  if (field.type === "separator" || field.type === "info") continue;
8214
8315
  if (field.requiresRestart) restartKeys.add(field.key);
8215
8316
  }
@@ -8405,12 +8506,14 @@ var BaseAddon = class {
8405
8506
  * here, in the addon's own process, so the hub keeps no copy of it.
8406
8507
  */
8407
8508
  async getDeclaredSettingsKeys() {
8509
+ await this.loadScopedSchemas();
8408
8510
  return { keys: [...this.declaredKeySet()].toSorted() };
8409
8511
  }
8410
8512
  declaredKeySet() {
8411
8513
  const keys = new Set(Object.keys(this.defaults));
8412
8514
  const schema = this.globalSettingsSchema();
8413
8515
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8516
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8414
8517
  for (const key of this._declaredStateKeys) keys.add(key);
8415
8518
  for (const path of this.secretStatePaths) {
8416
8519
  const root = path.split(/[.[]/, 1)[0];
@@ -8506,7 +8609,11 @@ var BaseAddon = class {
8506
8609
  }
8507
8610
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8508
8611
  addonSecretTree() {
8509
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8612
+ if (this._addonSecretTree === null) {
8613
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8614
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8615
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8616
+ }
8510
8617
  return this._addonSecretTree;
8511
8618
  }
8512
8619
  deviceSecretTree() {
@@ -8756,6 +8863,23 @@ function dropPerNodeFields(fields) {
8756
8863
  }
8757
8864
  return kept;
8758
8865
  }
8866
+ /** The keys of the value-holding fields, recursing into layout containers. */
8867
+ function collectValueFieldKeys(fields) {
8868
+ const collected = [];
8869
+ for (const field of fields) {
8870
+ if (field.type === "group") {
8871
+ collected.push(...collectValueFieldKeys(field.fields));
8872
+ continue;
8873
+ }
8874
+ if (field.type === "sub-tabs") {
8875
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8876
+ continue;
8877
+ }
8878
+ if (field.type === "separator" || field.type === "info") continue;
8879
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8880
+ }
8881
+ return collected;
8882
+ }
8759
8883
  function collectFieldKeys(fields) {
8760
8884
  const collected = [];
8761
8885
  for (const field of fields) {
@@ -9298,6 +9422,7 @@ function defineEntryKind(name, spec) {
9298
9422
  class: "config",
9299
9423
  writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
9300
9424
  retention: { none: "an entry goes only when the operator deletes it" },
9425
+ ...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
9301
9426
  ...spec.database === void 0 ? {} : { database: spec.database },
9302
9427
  ...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
9303
9428
  ...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
@@ -11981,7 +12106,7 @@ function userError(code, params, englishFallback) {
11981
12106
  return new CamstackError(code, params, englishFallback);
11982
12107
  }
11983
12108
  //#endregion
11984
- //#region ../types/dist/composition-CRNwcFYY.mjs
12109
+ //#region ../types/dist/composition-pOHbTzRB.mjs
11985
12110
  /**
11986
12111
  * The ffmpeg build every CamStack node downloads, per platform and arch.
11987
12112
  *
@@ -13462,7 +13587,7 @@ var RecordIntegrationInstances = class {
13462
13587
  return record === null ? null : this.viewOf(record);
13463
13588
  };
13464
13589
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13465
- createInstance = async ({ id, name, kind }) => {
13590
+ createInstance = async ({ id, name, kind, values }) => {
13466
13591
  const minted = id ?? this.hooks.mintId?.({
13467
13592
  name,
13468
13593
  ...kind !== void 0 ? { kind } : {}
@@ -13472,10 +13597,20 @@ var RecordIntegrationInstances = class {
13472
13597
  id: minted,
13473
13598
  data: this.hooks.initialBody(name, kind)
13474
13599
  }, { ifRev: 0 });
13600
+ const patch = this.patchOf(values ?? {});
13601
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13475
13602
  await this.hooks.onChanged?.(minted, "created");
13476
13603
  return { id: minted };
13477
13604
  };
13478
13605
  updateInstance = async ({ id, name, values }) => {
13606
+ const patch = this.patchOf(values);
13607
+ if (name !== void 0) patch[this.nameField] = name;
13608
+ await this.handle.patch(id, patch);
13609
+ await this.hooks.onChanged?.(id, "updated");
13610
+ return { ok: true };
13611
+ };
13612
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13613
+ patchOf(values) {
13479
13614
  const patch = {};
13480
13615
  for (const [key, value] of Object.entries(values)) {
13481
13616
  if (value === void 0) continue;
@@ -13486,11 +13621,8 @@ var RecordIntegrationInstances = class {
13486
13621
  else if (isSecretClear(value)) patch[key] = null;
13487
13622
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13488
13623
  }
13489
- if (name !== void 0) patch[this.nameField] = name;
13490
- await this.handle.patch(id, patch);
13491
- await this.hooks.onChanged?.(id, "updated");
13492
- return { ok: true };
13493
- };
13624
+ return patch;
13625
+ }
13494
13626
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13495
13627
  setInstanceEnabled = async ({ id, enabled }) => {
13496
13628
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14709,20 +14841,28 @@ async function moveIntegrationRowsToRecords(ports, spec) {
14709
14841
  };
14710
14842
  }
14711
14843
  /**
14712
- * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416): an addon runs the move
14713
- * from its own process, so the legacy rows are reached through the hub (`ctx.api.integrations`:
14714
- * `list`, `getSettings` - which answers the OWNER its secrets resolved - and `clearSettings`) and
14715
- * the new record through the addon's own records handle. The hub deletes the rows and their
14716
- * keychain values; the addon never touches the registry.
14844
+ * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416). An addon runs the move
14845
+ * from its own process, so the leftover rows are reached through the migration-only door
14846
+ * (`migrations.readLegacyIntegrationRows` / `clearLegacyIntegrationRows`) on the hub's connection.
14847
+ * The door returns markers. This process is the owner, so it resolves and releases them with
14848
+ * `resolveSecretMarkers` — the same call the old settings door used — and only then asks the
14849
+ * door to delete the rows. The addon's own record kind is its records handle.
14717
14850
  */
14851
+ async function resolvedRows(stored, secrets) {
14852
+ if (secrets === null) return stored;
14853
+ const { value, unresolved } = await resolveSecretMarkers(stored, secrets);
14854
+ if (unresolved.length > 0) throw new Error(`${unresolved.length} secret(s) cannot be read from the keychain`);
14855
+ return value;
14856
+ }
14718
14857
  function integrationRowsPortsOverApi(deps) {
14858
+ const secrets = deps.secrets ?? null;
14719
14859
  return {
14720
14860
  warn: (message) => deps.log.warn(message),
14721
14861
  listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
14722
14862
  id: i.id,
14723
14863
  name: i.name
14724
14864
  })),
14725
- readRows: (integrationId) => deps.api.getSettings({ id: integrationId }),
14865
+ readRows: async (integrationId) => resolvedRows(await deps.api.readLegacyIntegrationRows({ integrationId }), secrets),
14726
14866
  putRecord: async (id, body) => {
14727
14867
  if (await deps.records.get(id) !== null) return "exists";
14728
14868
  try {
@@ -14741,7 +14881,9 @@ function integrationRowsPortsOverApi(deps) {
14741
14881
  await deps.records.delete(id);
14742
14882
  },
14743
14883
  clearRows: async (integrationId) => {
14744
- await deps.api.clearSettings({ id: integrationId });
14884
+ const refs = collectSecretMarkerRefs(await deps.api.readLegacyIntegrationRows({ integrationId }));
14885
+ if (refs.length > 0 && secrets !== null) await secrets.delete(refs);
14886
+ await deps.api.clearLegacyIntegrationRows({ integrationId });
14745
14887
  }
14746
14888
  };
14747
14889
  }
@@ -14803,13 +14945,13 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14803
14945
  };
14804
14946
  if (orphans.some((d) => (d.parentDeviceId ?? null) === null) && fallback === null) throw new Error(`${orphans.length} device(s) of '${spec.addonId}' carry no integration and the addon has no integration to claim them to`);
14805
14947
  for (const device of orphans) if (resolve(device, new Set([device.id])) === null) unresolved.add(device.id);
14806
- for (const id of unresolved) ports.warnDevice(`device ${id} of '${spec.addonId}' carries no integration and its owner chain does not resolve to one: left unstamped`, id);
14948
+ for (const id of unresolved) await ports.warnDevice(`device ${id} of '${spec.addonId}' carries no integration and its owner chain does not resolve to one: left unstamped`, id);
14807
14949
  for (const [deviceId, integrationId] of plan) await ports.setIntegrationId(deviceId, integrationId);
14808
14950
  const wrong = [];
14809
14951
  for (const [deviceId, integrationId] of plan) if (await ports.readIntegrationId(deviceId) !== integrationId) wrong.push(deviceId);
14810
14952
  if (wrong.length > 0) throw new Error(`device(s) ${wrong.join(", ")} did not read back their integration after the claim`);
14811
14953
  const claimed = plan.size;
14812
- ports.info(`${claimed} device(s) of '${spec.addonId}' claimed to their owner's integration or the default; ${unresolved.size} unresolved, ${reservations.size} reservation(s) skipped`);
14954
+ await ports.info(`${claimed} device(s) of '${spec.addonId}' claimed to their owner's integration or the default; ${unresolved.size} unresolved, ${reservations.size} reservation(s) skipped`);
14813
14955
  return {
14814
14956
  outcome: claimed > 0 ? "done" : "already-done",
14815
14957
  summary: {
@@ -14831,14 +14973,14 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14831
14973
  * 2. `claim-devices` (tolerate): `claimDevicesToDefaultIntegration`; with no integration to claim
14832
14974
  * to it fails and is retried on the next boot.
14833
14975
  *
14834
- * Both run in the addon process through the hub API (`ctx.api`), BEFORE the addon registers its
14835
- * `integration-instances` provider: while a provider is registered the hub answers `getSettings`
14836
- * from the record, not from the rows.
14976
+ * Both run in the addon process through the hub API (`ctx.api`). The leftover rows are read
14977
+ * through the migration-only door, which answers empty once the store is gone.
14837
14978
  */
14838
14979
  function defaultIntegrationPortsOver(deps) {
14839
14980
  return {
14840
14981
  ...integrationRowsPortsOverApi({
14841
14982
  api: deps.api,
14983
+ ...deps.secrets !== void 0 ? { secrets: deps.secrets } : {},
14842
14984
  records: deps.records.kind({
14843
14985
  name: deps.kind.name,
14844
14986
  declaration: deps.kind.declaration,
@@ -14935,25 +15077,6 @@ function defaultIntegrationMigrations(spec) {
14935
15077
  ...spec.eligible !== void 0 ? { eligible: spec.eligible } : {}
14936
15078
  })];
14937
15079
  }
14938
- function defaultIntegrationApiOver(api) {
14939
- return {
14940
- list: () => api.integrations.list.query(),
14941
- getSettings: (input) => api.integrations.getSettings.query(input),
14942
- clearSettings: (input) => api.integrations.clearSettings.mutate(input),
14943
- listDevices: (addonId) => api.deviceManager.listAll.query({
14944
- addonId,
14945
- projection: "slim"
14946
- }),
14947
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14948
- await api.deviceManager.setIntegrationId.mutate({
14949
- deviceId,
14950
- integrationId
14951
- });
14952
- },
14953
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14954
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14955
- };
14956
- }
14957
15080
  /**
14958
15081
  * The trainer contract — what the hub hands the cloud trainer and what it
14959
15082
  * gets back (cloud training, D805+).
@@ -16060,6 +16183,39 @@ var UnstampedEventMediaCountSchema = object({
16060
16183
  /** Sum across both, or `null` when either lane could not be counted. */
16061
16184
  total: number().int().nonnegative().nullable()
16062
16185
  }).nullable();
16186
+ /**
16187
+ * Where the stored event media sits, per storage location: how many media rows
16188
+ * and how many bytes carry each location id, how many carry none (legacy,
16189
+ * resolved to the default `eventMedia` location), and how many name a location
16190
+ * that was not asked about (a deleted or never-listed one).
16191
+ *
16192
+ * One covering-index aggregate per asked location plus the NULL one, and one
16193
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
16194
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
16195
+ * it is a deleted location only when every location id was asked.
16196
+ * `null` is "could not be measured", never zero.
16197
+ */
16198
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
16199
+ var MediaLocationCensusSchema = object({
16200
+ locations: array(object({
16201
+ locationId: string(),
16202
+ rows: number().int().nonnegative(),
16203
+ bytes: number().nonnegative()
16204
+ })).readonly(),
16205
+ unstamped: object({
16206
+ rows: number().int().nonnegative(),
16207
+ bytes: number().nonnegative()
16208
+ }),
16209
+ /** Rows stamped with a location id that was not in the asked list. */
16210
+ unlisted: object({
16211
+ rows: number().int().nonnegative(),
16212
+ bytes: number().nonnegative()
16213
+ }),
16214
+ total: object({
16215
+ rows: number().int().nonnegative(),
16216
+ bytes: number().nonnegative()
16217
+ })
16218
+ });
16063
16219
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
16064
16220
  /** The independently selectable logical storage classes — every class
16065
16221
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -47096,52 +47252,7 @@ onBrightnessChanged: { data: object({
47096
47252
  minIntervalMs: 0
47097
47253
  } } }
47098
47254
  };
47099
- /**
47100
- * `broker` — unified pub/sub broker registry, system-scoped collection.
47101
- *
47102
- * The cap models any kind-tagged message broker the user wants to
47103
- * register and that other addons might consume. The first two kinds
47104
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
47105
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
47106
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
47107
- * the same surface.
47108
- *
47109
- * Why one cap, not one cap per kind:
47110
- * - The integrations page wants a single table of "every broker"
47111
- * across kinds; a unified cap drives it without join logic.
47112
- * - Generic admin operations (add / remove / test / status) are
47113
- * identical across kinds — duplicating them per cap was busywork.
47114
- * - The `network-access` cap precedent: same interface, many
47115
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47116
- *
47117
- * What stays kind-specific:
47118
- * - `getBrokerConfig` payload (kind decides whether it returns
47119
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47120
- * `Record<string, unknown>` at the wire; consumers narrow.
47121
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47122
- * key) — also typed as `Record<string, unknown>` so each kind can
47123
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47124
- * without rebreaking the cap signature.
47125
- * - `add` `settings` payload (different fields per kind, validated by
47126
- * the kind-specific provider).
47127
- *
47128
- * Bidirectionality:
47129
- * - `publish` is RPC — synchronous result (provider-defined).
47130
- * - `subscribe` returns a subscription handle; the actual message
47131
- * stream flows over the typed event-bus as `broker.message` events
47132
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47133
- * event handler. Subscriptions persist across reconnects — the
47134
- * provider re-subscribes upstream after a transport drop.
47135
- *
47136
- * Why event-bus push (not a subscription RPC stream):
47137
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47138
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47139
- * drop is recoverable via `getState({key})`).
47140
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47141
- * - Cross-process: events already route through `$event-bus`; no
47142
- * per-broker wire-shaping needed.
47143
- */
47144
- var BrokerStatusEnum = _enum([
47255
+ _enum([
47145
47256
  "connected",
47146
47257
  "disconnected",
47147
47258
  "connecting",
@@ -47149,141 +47260,12 @@ var BrokerStatusEnum = _enum([
47149
47260
  "unreachable",
47150
47261
  "error"
47151
47262
  ]);
47152
- var BrokerInfoSchema = object({
47153
- /** Stable broker id. Persisted; survives addon restarts. */
47154
- id: string(),
47155
- /** Addon id of the provider that OWNS this broker.
47156
- *
47157
- * The `broker` cap is a system-scoped collection: several addons
47158
- * register a `broker` provider, each owning a DISJOINT set of
47159
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47160
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47161
- * device belongs to one integration. The admin UI threads this id
47162
- * back as the `{ addonId }` system-collection selector on every
47163
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47164
- * `testConnection`), so the call routes to the OWNING provider
47165
- * instead of defaulting to the first-registered one. */
47166
- addonId: string(),
47167
- /** Human-readable name (operator-chosen at add-time). */
47168
- name: string(),
47169
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47170
- kind: string(),
47171
- status: BrokerStatusEnum,
47172
- /** Free-form provider-specific info (HA version, MQTT broker
47173
- * flavour, latency, mTLS active, …). */
47174
- info: record(string(), unknown()),
47175
- /** Ms epoch of the last connection probe / status update. */
47176
- lastCheckedAt: number().nullable(),
47177
- /** Last error message, when `status` indicates failure. */
47178
- error: string().nullable()
47179
- });
47180
47263
  var RegistryStatusSchema = object({
47181
47264
  brokerCount: number().int().nonnegative(),
47182
47265
  connectedCount: number().int().nonnegative()
47183
47266
  });
47184
- /**
47185
- * One entry per `broker` provider — which addon provides which broker
47186
- * kind(s). The unified create picker reads this to know, for each
47187
- * (addonId, kind) pair the operator can pick, where to route the
47188
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47189
- * `{ addonId }` selector). A provider only advertises a kind here when
47190
- * it implements `getSettingsSchema` for that kind (so the picker never
47191
- * offers a kind whose creation form can't be rendered).
47192
- */
47193
- var BrokerProviderInfoSchema = object({
47194
- /** Addon id of the `broker` provider this entry describes. */
47195
- addonId: string(),
47196
- /** Broker kinds this provider can create, with a display label. */
47197
- kinds: array(object({
47198
- kind: string(),
47199
- label: string(),
47200
- /**
47201
- * Relative hub path to start an interactive account link (OAuth popup).
47202
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47203
- */
47204
- interactiveConnectPath: string().min(1).optional(),
47205
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47206
- interactiveDisconnectPath: string().min(1).optional(),
47207
- /**
47208
- * The kind signs in through a server-held interactive session instead of
47209
- * (or before) typed credentials. `basePath` is a hub-relative route set
47210
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47211
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47212
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47213
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47214
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47215
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47216
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47217
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47218
- * offers it as the default path; the fields the session fills are
47219
- * marked `filledBySignIn` in the kind's settings schema.
47220
- *
47221
- * `methods` lists the ways the session can sign in, recommended first:
47222
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47223
- * settings) answering `{ sessionId, userCode, verificationUrl,
47224
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47225
- * any device, and the same `status` / `commit` / `cancel` routes follow
47226
- * (status then carries `method`, `userCode`, `verificationUrl`,
47227
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47228
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47229
- * `['proxy']`.
47230
- */
47231
- signIn: object({
47232
- basePath: string().min(1),
47233
- methods: array(_enum(["device-code", "proxy"])).optional()
47234
- }).optional()
47235
- }))
47236
- });
47237
- var ListInputSchema = object({
47238
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47239
- * only HA brokers. Omit to list every broker. */
47240
- kind: string().optional() });
47241
47267
  var GetInputSchema = object({ id: string() });
47242
- var AddInputSchema = object({
47243
- kind: string().min(1),
47244
- name: string().min(1),
47245
- /**
47246
- * ADOPT an existing id instead of minting a new one.
47247
- *
47248
- * Written the day this cost an outage. A broker's id is not a detail: HA
47249
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47250
- * lost from config and re-added as `ha_001` leaves every one of its devices
47251
- * bound to a broker that no longer exists. Re-entering the password under the
47252
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47253
- * password.
47254
- *
47255
- * A provider MUST refuse an id that is already in use — adopting a live
47256
- * broker's id would silently take it over.
47257
- */
47258
- id: string().min(1).optional(),
47259
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47260
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47261
- * branch on receipt — invalid shape rejects the add. */
47262
- settings: record(string(), unknown())
47263
- });
47264
- var AddResultSchema = object({ id: string() });
47265
- var RemoveInputSchema = object({ id: string() });
47266
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47267
- ok: literal(true),
47268
- latencyMs: number().nonnegative()
47269
- }), object({
47270
- ok: literal(false),
47271
- error: string()
47272
- })]);
47273
47268
  var SettingsRecordSchema$1 = record(string(), unknown());
47274
- var SettingsSchemaInputSchema = object({ kind: string() });
47275
- var TestSettingsInputSchema = object({
47276
- kind: string(),
47277
- settings: SettingsRecordSchema$1
47278
- });
47279
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47280
- ok: literal(true),
47281
- latencyMs: number().nonnegative().optional()
47282
- }).strict(), object({
47283
- ok: literal(false),
47284
- error: string()
47285
- })]);
47286
- var SettingsSchemaResultSchema = unknown().nullable();
47287
47269
  var PublishInputSchema = object({
47288
47270
  brokerId: string(),
47289
47271
  /** Kind-specific routing target.
@@ -47317,25 +47299,7 @@ var GetStateInputSchema = object({
47317
47299
  * HA: entity_id (returns the cached entity state). */
47318
47300
  key: string()
47319
47301
  });
47320
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47321
- kind: "mutation",
47322
- auth: "admin"
47323
- }), method(RemoveInputSchema, _void(), {
47324
- kind: "mutation",
47325
- auth: "admin"
47326
- }), method(GetInputSchema, TestConnectionResultSchema, {
47327
- kind: "mutation",
47328
- auth: "admin"
47329
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47330
- id: string(),
47331
- settings: SettingsRecordSchema$1
47332
- }), _void(), {
47333
- kind: "mutation",
47334
- auth: "admin"
47335
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47336
- kind: "mutation",
47337
- auth: "admin"
47338
- }), method(PublishInputSchema, unknown(), {
47302
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47339
47303
  kind: "mutation",
47340
47304
  auth: "admin"
47341
47305
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -50556,6 +50520,9 @@ var RunningProposalEvidenceSchema = object({
50556
50520
  runsFound: number().int().nonnegative(),
50557
50521
  pausesFound: number().int().nonnegative(),
50558
50522
  longestPauseMs: number().nonnegative(),
50523
+ /** Episodes shorter than ~90 s (an anti-crease pulse, a display waking): never a run, never a pause. */
50524
+ pulsesFound: number().int().nonnegative(),
50525
+ longestPulseMs: number().nonnegative(),
50559
50526
  idleFloorW: number(),
50560
50527
  noiseCeilingW: number(),
50561
50528
  plateauW: number(),
@@ -52153,7 +52120,14 @@ var DiscoveryCandidateSchema = object({
52153
52120
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52154
52121
  parentStableId: string().optional(),
52155
52122
  /** `false` = shown for context but not pickable. Default true. */
52156
- selectable: boolean().optional()
52123
+ selectable: boolean().optional(),
52124
+ /**
52125
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52126
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52127
+ * admin asks for exactly these, on the creation form prefilled with
52128
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52129
+ */
52130
+ needsParams: array(string()).optional()
52157
52131
  });
52158
52132
  /**
52159
52133
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52280,8 +52254,14 @@ var deviceProviderCapability = {
52280
52254
  * provider does not support manual creation. Lets the Add-Device dialog
52281
52255
  * pick the right type instead of assuming Camera.
52282
52256
  */
52283
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52284
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52257
+ getManualCreationType: method(object({
52258
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52259
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52260
+ adoptDiscoveredDevice: method(object({
52261
+ candidate: DiscoveryCandidateSchema,
52262
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52263
+ integrationId: string().optional()
52264
+ }), DeviceSummarySchema, {
52285
52265
  kind: "mutation",
52286
52266
  auth: "admin"
52287
52267
  }),
@@ -52292,10 +52272,16 @@ var deviceProviderCapability = {
52292
52272
  * devices of that type. The output is a `ConfigUISchema` — the
52293
52273
  * router type-asserts it at the boundary.
52294
52274
  */
52295
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52275
+ getChildCreationSchema: method(object({
52276
+ type: _enum(DeviceType),
52277
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52278
+ integrationId: string().optional()
52279
+ }), CreationSchemaOutputSchema),
52296
52280
  createDevice: method(object({
52297
52281
  type: _enum(DeviceType),
52298
- config: record(string(), unknown())
52282
+ config: record(string(), unknown()),
52283
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52284
+ integrationId: string().optional()
52299
52285
  }), DeviceSummarySchema, {
52300
52286
  kind: "mutation",
52301
52287
  auth: "admin"
@@ -53020,7 +53006,10 @@ method(object({
53020
53006
  auth: "admin"
53021
53007
  }), method(object({
53022
53008
  addonId: string(),
53023
- type: _enum(DeviceType)
53009
+ type: _enum(DeviceType),
53010
+ /** The integration the form is for; a provider whose integrations differ (a hub
53011
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
53012
+ integrationId: string().optional()
53024
53013
  }), unknown().nullable()), method(object({
53025
53014
  addonId: string(),
53026
53015
  type: _enum(DeviceType),
@@ -53104,7 +53093,11 @@ method(object({
53104
53093
  kind: "mutation",
53105
53094
  auth: "admin",
53106
53095
  timeoutMs: 12e4
53107
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53096
+ }), method(object({
53097
+ addonId: string(),
53098
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
53099
+ integrationId: string().optional()
53100
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53108
53101
  deviceId: number(),
53109
53102
  key: string(),
53110
53103
  value: unknown()
@@ -56384,7 +56377,7 @@ var TestConnectionStatusEnum = _enum([
56384
56377
  "inconclusive",
56385
56378
  "unsupported"
56386
56379
  ]);
56387
- var TestConnectionResultSchema$1 = object({
56380
+ var TestConnectionResultSchema = object({
56388
56381
  /** True ONLY for `validated`. Never true for a test that did not run. */
56389
56382
  success: boolean(),
56390
56383
  error: string().optional(),
@@ -56405,11 +56398,7 @@ var CreateIntegrationInputSchema = object({
56405
56398
  info: record(string(), unknown()).optional(),
56406
56399
  /** `stableId` of the discovery candidate the form was seeded from (D984). */
56407
56400
  originStableId: string().optional(),
56408
- settings: record(string(), unknown()).optional(),
56409
- /** Keys of `settings` the form's schema declares secret (by type) — kept in
56410
- * the keychain, not the table (D787). */
56411
- secretKeys: array(string()).optional(),
56412
- skipRestart: boolean().optional()
56401
+ settings: record(string(), unknown()).optional()
56413
56402
  });
56414
56403
  var UpdateIntegrationInputSchema = object({
56415
56404
  id: string(),
@@ -56430,26 +56419,10 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56430
56419
  }), method(object({ id: string() }), DeleteIntegrationResultSchema, {
56431
56420
  kind: "mutation",
56432
56421
  auth: "admin"
56433
- }), method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }), method(object({
56434
- id: string(),
56435
- settings: record(string(), unknown()),
56436
- /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
56437
- secretKeys: array(string()).optional(),
56438
- /** The integration's own addon applies the change in-process and asks the hub not to respawn it. */
56439
- skipRestart: boolean().optional()
56440
- }), object({ success: boolean() }), {
56441
- kind: "mutation",
56442
- auth: "admin"
56443
- }), method(object({ id: string() }), object({
56444
- rows: number().int().nonnegative(),
56445
- secrets: number().int().nonnegative()
56446
- }), {
56447
- kind: "mutation",
56448
- auth: "admin"
56449
56422
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56450
56423
  addonId: string(),
56451
56424
  settings: record(string(), unknown())
56452
- }), TestConnectionResultSchema$1, {
56425
+ }), TestConnectionResultSchema, {
56453
56426
  kind: "mutation",
56454
56427
  auth: "admin"
56455
56428
  });
@@ -56476,6 +56449,14 @@ var ConfigSchemaPassthrough$3 = custom();
56476
56449
  var IntegrationInstanceIdSchema = string().min(1);
56477
56450
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56478
56451
  /**
56452
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56453
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56454
+ * `services`: a connection configured from the addon's own function page, never listed on
56455
+ * Integrations.
56456
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56457
+ */
56458
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56459
+ /**
56479
56460
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56480
56461
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56481
56462
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56486,6 +56467,22 @@ var IntegrationInstanceKindSchema = object({
56486
56467
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56487
56468
  id: string().min(1),
56488
56469
  label: string().min(1),
56470
+ /**
56471
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56472
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56473
+ * provider with more than one section must name it on every kind.
56474
+ */
56475
+ functionCap: string().min(1),
56476
+ /**
56477
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56478
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56479
+ * finds the instances whose kind names it; absent takes the kind `id`.
56480
+ */
56481
+ brokerKind: string().min(1).optional(),
56482
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56483
+ role: IntegrationInstanceRoleSchema.optional(),
56484
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56485
+ canTest: boolean().optional(),
56489
56486
  /** The kind signs in through a server-held interactive session. */
56490
56487
  signIn: object({
56491
56488
  basePath: string().min(1),
@@ -56498,11 +56495,7 @@ var IntegrationInstanceKindSchema = object({
56498
56495
  });
56499
56496
  var IntegrationInstanceDescriptionSchema = object({
56500
56497
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56501
- role: _enum([
56502
- "devices",
56503
- "services",
56504
- "both"
56505
- ]),
56498
+ role: IntegrationInstanceRoleSchema,
56506
56499
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56507
56500
  discovery: object({
56508
56501
  mode: _enum([
@@ -56577,7 +56570,11 @@ var integrationInstancesCapability = {
56577
56570
  methods: {
56578
56571
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56579
56572
  /** The form; `id: null` is the create form. */
56580
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56573
+ instanceFormSchema: method(object({
56574
+ id: IntegrationInstanceIdSchema.nullable(),
56575
+ /** The kind of the create form (`id: null`) of a provider with several. */
56576
+ kind: string().min(1).optional()
56577
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56581
56578
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56582
56579
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56583
56580
  /**
@@ -56587,7 +56584,9 @@ var integrationInstancesCapability = {
56587
56584
  createInstance: method(object({
56588
56585
  id: IntegrationInstanceIdSchema.optional(),
56589
56586
  name: string().min(1),
56590
- kind: string().min(1).optional()
56587
+ kind: string().min(1).optional(),
56588
+ /** Form values written with the record (a link picked in the create dialog). */
56589
+ values: record(string(), unknown()).optional()
56591
56590
  }), object({ id: string() }), {
56592
56591
  kind: "mutation",
56593
56592
  auth: "admin"
@@ -56614,8 +56613,10 @@ var integrationInstancesCapability = {
56614
56613
  }),
56615
56614
  testInstance: optionalMethod(object({
56616
56615
  id: IntegrationInstanceIdSchema.nullable(),
56617
- values: record(string(), unknown())
56618
- }), TestConnectionResultSchema$1, {
56616
+ values: record(string(), unknown()),
56617
+ /** The kind to test when `id` is null and the provider has several. */
56618
+ kind: string().min(1).optional()
56619
+ }), TestConnectionResultSchema, {
56619
56620
  kind: "mutation",
56620
56621
  auth: "admin"
56621
56622
  })
@@ -59372,6 +59373,380 @@ var SystemMetricsSchema = object({
59372
59373
  gpuMemoryPercent: number().optional()
59373
59374
  });
59374
59375
  method(_void(), SystemResourceSnapshotSchema), method(_void(), SystemResourceSnapshotSchema.nullable()), method(_void(), SystemMetricsSchema), method(object({ dirPath: string() }), DiskSpaceInfoSchema), method(_void(), MetricsGpuInfoSchema.nullable()), method(_void(), number().nullable()), method(object({ pids: array(number()) }), array(PidResourceStatsSchema)), method(_void(), array(AddonInstanceSchema).readonly()), method(object({ addonId: string() }), PidResourceStatsSchema.nullable()), method(_void(), array(NodeProcessSchema).readonly()), method(GetLoadSeriesInputSchema, NodeLoadSeriesSchema);
59376
+ /**
59377
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59378
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59379
+ * (operator intent, D870) and device-history (numbers over time, D850).
59380
+ *
59381
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59382
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59383
+ * that with the addon id closed over). It is deliberately NOT in any input
59384
+ * schema, so a session can never supply it, and a call with no stamp is refused
59385
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59386
+ * addons go through the owner's capability.
59387
+ *
59388
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59389
+ * never `[]`. Secret fields are never on the wire: a read shows the
59390
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59391
+ * resolves itself, and a write may carry only a keychain marker bound to the
59392
+ * row's own ref.
59393
+ *
59394
+ * Internal: addons reach it through `ctx.records`, never directly.
59395
+ */
59396
+ var RecordIdSchema = string().min(1).max(256);
59397
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59398
+ var RecordBodySchema = record(string(), unknown());
59399
+ var RecordInputSchema = object({
59400
+ id: RecordIdSchema,
59401
+ /** The device this row belongs to (D865 removal, per-device reads). */
59402
+ deviceId: number().int().optional(),
59403
+ /** The domain clock, ms: observed / created / opened. */
59404
+ at: number().int().optional(),
59405
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59406
+ expiresAt: number().int().optional(),
59407
+ data: RecordBodySchema
59408
+ });
59409
+ var RecordViewSchema = object({
59410
+ id: string(),
59411
+ deviceId: number().int().nullable(),
59412
+ at: number().nullable(),
59413
+ expiresAt: number().nullable(),
59414
+ rev: number().int(),
59415
+ updatedAt: number(),
59416
+ data: RecordBodySchema
59417
+ });
59418
+ /** Declared index fields only. Anything else does not compile, by design. */
59419
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59420
+ string(),
59421
+ number(),
59422
+ boolean(),
59423
+ object({ in: array(union([
59424
+ string(),
59425
+ number(),
59426
+ boolean()
59427
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59428
+ object({
59429
+ gt: union([string(), number()]).optional(),
59430
+ gte: union([string(), number()]).optional(),
59431
+ lt: union([string(), number()]).optional(),
59432
+ lte: union([string(), number()]).optional()
59433
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59434
+ ]));
59435
+ var KindShape = { kind: RecordKindNameSchema };
59436
+ var TimeWindowShape = {
59437
+ deviceId: number().int().optional(),
59438
+ atFrom: number().optional(),
59439
+ atTo: number().optional()
59440
+ };
59441
+ var RecordQueryInputSchema = object({
59442
+ ...KindShape,
59443
+ ...TimeWindowShape,
59444
+ where: RecordWhereSchema.optional(),
59445
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59446
+ order: _enum(["at", "id"]).optional(),
59447
+ desc: boolean().optional(),
59448
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59449
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59450
+ cursor: string().min(1).optional()
59451
+ });
59452
+ var RecordQueryResultSchema = object({
59453
+ records: array(RecordViewSchema),
59454
+ nextCursor: string().nullable()
59455
+ });
59456
+ var RecordKindStateSchema = _enum([
59457
+ "created",
59458
+ "unchanged",
59459
+ "updated"
59460
+ ]);
59461
+ var DeclareKindResultSchema = object({
59462
+ kindId: number().int(),
59463
+ state: RecordKindStateSchema,
59464
+ createdIndexes: array(string())
59465
+ });
59466
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59467
+ var SecretRefsList = array(string());
59468
+ /**
59469
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59470
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59471
+ */
59472
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59473
+ object({
59474
+ op: literal("put"),
59475
+ kind: RecordKindNameSchema,
59476
+ record: RecordInputSchema,
59477
+ ifRev: number().int().min(0).optional()
59478
+ }),
59479
+ object({
59480
+ op: literal("patch"),
59481
+ kind: RecordKindNameSchema,
59482
+ id: RecordIdSchema,
59483
+ data: RecordBodySchema,
59484
+ at: number().int().nullable().optional(),
59485
+ expiresAt: number().int().nullable().optional(),
59486
+ ifRev: number().int().min(1).optional()
59487
+ }),
59488
+ object({
59489
+ op: literal("delete"),
59490
+ kind: RecordKindNameSchema,
59491
+ id: RecordIdSchema
59492
+ })
59493
+ ]);
59494
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59495
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59496
+ kind: "mutation",
59497
+ auth: "admin"
59498
+ }), method(object({
59499
+ ...KindShape,
59500
+ id: RecordIdSchema
59501
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59502
+ ...KindShape,
59503
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59504
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59505
+ ...KindShape,
59506
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59507
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59508
+ ...KindShape,
59509
+ record: RecordInputSchema,
59510
+ /** Compare-and-set. `0` means "the row must not exist". */
59511
+ ifRev: number().int().min(0).optional()
59512
+ }), object({
59513
+ rev: number().int(),
59514
+ releasedRefs: SecretRefsList
59515
+ }), {
59516
+ kind: "mutation",
59517
+ auth: "admin"
59518
+ }), method(object({
59519
+ ...KindShape,
59520
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59521
+ }), object({
59522
+ count: number().int(),
59523
+ releasedRefs: SecretRefsList
59524
+ }), {
59525
+ kind: "mutation",
59526
+ auth: "admin"
59527
+ }), method(object({
59528
+ ...KindShape,
59529
+ id: RecordIdSchema,
59530
+ data: RecordBodySchema,
59531
+ at: number().int().nullable().optional(),
59532
+ expiresAt: number().int().nullable().optional(),
59533
+ ifRev: number().int().min(1).optional()
59534
+ }), object({
59535
+ rev: number().int(),
59536
+ releasedRefs: SecretRefsList
59537
+ }), {
59538
+ kind: "mutation",
59539
+ auth: "admin"
59540
+ }), method(object({
59541
+ ...KindShape,
59542
+ id: RecordIdSchema
59543
+ }), object({
59544
+ deleted: boolean(),
59545
+ secretRefs: SecretRefsList
59546
+ }), {
59547
+ kind: "mutation",
59548
+ auth: "admin"
59549
+ }), method(object({
59550
+ ...KindShape,
59551
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59552
+ }), object({
59553
+ deleted: number().int(),
59554
+ secretRefs: SecretRefsList
59555
+ }), {
59556
+ kind: "mutation",
59557
+ auth: "admin"
59558
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59559
+ ...KindShape,
59560
+ ...TimeWindowShape,
59561
+ where: RecordWhereSchema.optional()
59562
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59563
+ ...KindShape,
59564
+ deviceId: number().int().optional(),
59565
+ from: number(),
59566
+ to: number(),
59567
+ bucketMs: number().int().positive()
59568
+ }), object({ buckets: array(object({
59569
+ bucketStart: number(),
59570
+ count: number().int()
59571
+ })) }), { auth: "admin" }), method(object({
59572
+ ...KindShape,
59573
+ op: _enum([
59574
+ "sum",
59575
+ "min",
59576
+ "max",
59577
+ "count"
59578
+ ]),
59579
+ field: RecordFieldPathSchema.optional(),
59580
+ groupBy: RecordFieldPathSchema.optional(),
59581
+ where: RecordWhereSchema.optional()
59582
+ }), object({ rows: array(object({
59583
+ group: union([
59584
+ string(),
59585
+ number(),
59586
+ _null()
59587
+ ]),
59588
+ value: number().nullable()
59589
+ })) }), { auth: "admin" }), method(object({
59590
+ ...KindShape,
59591
+ deviceId: number().int().optional(),
59592
+ atBefore: number().optional(),
59593
+ where: RecordWhereSchema.optional()
59594
+ }), object({
59595
+ deleted: number().int(),
59596
+ secretRefs: SecretRefsList
59597
+ }), {
59598
+ kind: "mutation",
59599
+ auth: "admin"
59600
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59601
+ results: array(object({
59602
+ rev: number().int().nullable(),
59603
+ deleted: boolean()
59604
+ })),
59605
+ releasedRefs: SecretRefsList,
59606
+ secretRefs: SecretRefsList
59607
+ }), {
59608
+ kind: "mutation",
59609
+ auth: "admin"
59610
+ }), method(object({
59611
+ deviceId: number().int(),
59612
+ kinds: array(RecordKindNameSchema).optional()
59613
+ }), object({
59614
+ deleted: record(string(), number().int()),
59615
+ secretRefs: SecretRefsList
59616
+ }), {
59617
+ kind: "mutation",
59618
+ auth: "admin"
59619
+ }), method(object(KindShape), object({ id: number().int() }), {
59620
+ kind: "mutation",
59621
+ auth: "admin"
59622
+ });
59623
+ /**
59624
+ * The wire shapes of the migration API, version 1 (planning#447).
59625
+ *
59626
+ * A migration is code that outlives the server it was written against: an addon at
59627
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59628
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59629
+ * is the contract of every method of it, one Zod pair per method.
59630
+ *
59631
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59632
+ * field is never removed or made required, an enum never narrows, an output field is
59633
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59634
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59635
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59636
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59637
+ */
59638
+ var Rows = record(string(), unknown());
59639
+ var IntegrationId = object({ integrationId: string().min(1) });
59640
+ var RecordId = object({ id: string().min(1) });
59641
+ var RecordRowSchema = object({
59642
+ id: string(),
59643
+ deviceId: number().int().nullable(),
59644
+ at: number().nullable(),
59645
+ expiresAt: number().nullable(),
59646
+ rev: number().int(),
59647
+ updatedAt: number(),
59648
+ data: Rows
59649
+ });
59650
+ var RecordPutShape = {
59651
+ id: string().min(1),
59652
+ deviceId: number().int().optional(),
59653
+ at: number().int().optional(),
59654
+ expiresAt: number().int().optional(),
59655
+ data: Rows
59656
+ };
59657
+ var MigrationIntegrationSchema = object({
59658
+ id: string(),
59659
+ addonId: string(),
59660
+ name: string(),
59661
+ info: Rows,
59662
+ originStableId: string().optional()
59663
+ });
59664
+ var MigrationDeviceSchema = object({
59665
+ id: number().int(),
59666
+ integrationId: string().nullable().optional(),
59667
+ /** The owning device; null or absent for a root. */
59668
+ parentDeviceId: number().int().nullable().optional(),
59669
+ type: string().optional(),
59670
+ name: string().optional(),
59671
+ stableId: string().optional()
59672
+ });
59673
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59674
+ var MigrationApiInfoSchema = object({
59675
+ version: number().int(),
59676
+ methods: array(string())
59677
+ });
59678
+ object({
59679
+ message: string(),
59680
+ meta: Rows.optional(),
59681
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59682
+ tags: object({ deviceId: number().int().optional() }).optional()
59683
+ });
59684
+ object({
59685
+ owner: string().min(1),
59686
+ metas: array(MigrationMetaSchema)
59687
+ }), object({
59688
+ bootId: string(),
59689
+ snapshot: _enum([
59690
+ "none",
59691
+ "written",
59692
+ "refused"
59693
+ ]),
59694
+ steps: array(MigrationOwnerStepSchema),
59695
+ /** The migration API the engine serves; absent from a server that predates it. */
59696
+ migrationApi: MigrationApiInfoSchema.optional()
59697
+ }), object({ id: string().min(1) }), object({
59698
+ proceed: boolean(),
59699
+ state: union([literal("pending"), MigrationStatusSchema]),
59700
+ reason: string().nullable()
59701
+ }), object({
59702
+ id: string().min(1),
59703
+ result: MigrationOwnerResultSchema
59704
+ }), object({
59705
+ status: MigrationStatusSchema,
59706
+ error: string().nullable(),
59707
+ rowsChanged: number().int().nonnegative()
59708
+ }), object({
59709
+ rows: number().int().nonnegative(),
59710
+ secrets: number().int().nonnegative()
59711
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59712
+ present: boolean(),
59713
+ removed: Rows
59714
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
59715
+ ...RecordPutShape,
59716
+ ifRev: number().int().optional()
59717
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
59718
+ partial: Rows,
59719
+ ifRev: number().int().optional()
59720
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
59721
+ deviceId: number().int().optional(),
59722
+ atFrom: number().optional(),
59723
+ atTo: number().optional(),
59724
+ where: RecordWhereSchema.optional(),
59725
+ limit: number().int().min(1).optional(),
59726
+ cursor: string().min(1).optional(),
59727
+ resolveSecrets: boolean().optional()
59728
+ }), object({
59729
+ records: array(RecordRowSchema),
59730
+ nextCursor: string().nullable()
59731
+ }), object({
59732
+ deviceId: number().int().optional(),
59733
+ atBefore: number().optional(),
59734
+ where: RecordWhereSchema.optional()
59735
+ }), object({ count: number().int().nonnegative() }), object({}), object({ store: Rows }), object({ patch: Rows }), object({}), object({ keys: array(string().min(1)) }), object({ removed: array(string()) }), object({ refs: array(string()) }), object({ values: record(string(), string().nullable()) }), object({
59736
+ ref: string().min(1),
59737
+ value: string()
59738
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
59739
+ addonId: string().min(1),
59740
+ integrationId: string().min(1).optional()
59741
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
59742
+ id: number().int(),
59743
+ integrationId: string().nullable(),
59744
+ /** Whether the device carries any stored config; its content is not offered. */
59745
+ hasConfig: boolean()
59746
+ }).nullable(), object({
59747
+ deviceId: number().int(),
59748
+ integrationId: string().min(1)
59749
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59375
59750
  method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { auth: "admin" }), method(object({ owner: string().optional() }), object({ pending: array(MigrationPendingEntrySchema) }), { auth: "admin" }), method(object({ id: string().min(1) }), MigrationDryRunResultSchema, { auth: "admin" }), method(object({
59376
59751
  id: string().min(1),
59377
59752
  error: string().min(1)
@@ -59401,7 +59776,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59401
59776
  "written",
59402
59777
  "refused"
59403
59778
  ]),
59404
- steps: array(MigrationOwnerStepSchema)
59779
+ steps: array(MigrationOwnerStepSchema),
59780
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
59781
+ migrationApi: MigrationApiInfoSchema.optional()
59405
59782
  }), {
59406
59783
  kind: "mutation",
59407
59784
  auth: "admin"
@@ -59422,6 +59799,27 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59422
59799
  }), {
59423
59800
  kind: "mutation",
59424
59801
  auth: "admin"
59802
+ }), method(object({ integrationId: string().min(1) }), record(string(), unknown()), { auth: "admin" }), method(object({ integrationId: string().min(1) }), object({
59803
+ rows: number().int().nonnegative(),
59804
+ secrets: number().int().nonnegative()
59805
+ }), {
59806
+ kind: "mutation",
59807
+ auth: "admin"
59808
+ }), method(object({
59809
+ integrationId: string().min(1),
59810
+ patch: record(string(), unknown())
59811
+ }), object({ written: boolean() }), {
59812
+ kind: "mutation",
59813
+ auth: "admin"
59814
+ }), method(object({
59815
+ integrationId: string().min(1),
59816
+ keys: array(string().min(1))
59817
+ }), object({
59818
+ present: boolean(),
59819
+ removed: record(string(), unknown())
59820
+ }), {
59821
+ kind: "mutation",
59822
+ auth: "admin"
59425
59823
  });
59426
59824
  method(object({
59427
59825
  sourceUrl: string(),
@@ -62047,7 +62445,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
62047
62445
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
62048
62446
  kind: "mutation",
62049
62447
  auth: "admin"
62050
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62448
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62449
+ kind: "query",
62450
+ auth: "admin"
62451
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62051
62452
  kind: "query",
62052
62453
  auth: "admin"
62053
62454
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64702,7 +65103,7 @@ var BrokerStatusSchema$1 = _enum([
64702
65103
  "unreachable",
64703
65104
  "tls-error"
64704
65105
  ]);
64705
- var BrokerInfoSchema$1 = object({
65106
+ var BrokerInfoSchema = object({
64706
65107
  id: string(),
64707
65108
  name: string(),
64708
65109
  url: string(),
@@ -64765,7 +65166,7 @@ var StatusSchema = object({
64765
65166
  brokerCount: number(),
64766
65167
  embeddedRunning: boolean()
64767
65168
  });
64768
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65169
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64769
65170
  kind: "mutation",
64770
65171
  auth: "admin"
64771
65172
  }), method(IdInputSchema, _void(), {
@@ -72105,253 +72506,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, DeviceType.Gateway, met
72105
72506
  auth: "admin"
72106
72507
  });
72107
72508
  /**
72108
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
72109
- * config documents, mirrors. The third storage API next to `ctx.settings`
72110
- * (operator intent, D870) and device-history (numbers over time, D850).
72111
- *
72112
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
72113
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
72114
- * that with the addon id closed over). It is deliberately NOT in any input
72115
- * schema, so a session can never supply it, and a call with no stamp is refused
72116
- * `records/no-caller`. A kind is readable and writable only by its owner; other
72117
- * addons go through the owner's capability.
72118
- *
72119
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
72120
- * never `[]`. Secret fields are never on the wire: a read shows the
72121
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
72122
- * resolves itself, and a write may carry only a keychain marker bound to the
72123
- * row's own ref.
72124
- *
72125
- * Internal: addons reach it through `ctx.records`, never directly.
72126
- */
72127
- var RecordIdSchema = string().min(1).max(256);
72128
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
72129
- var RecordBodySchema = record(string(), unknown());
72130
- var RecordInputSchema = object({
72131
- id: RecordIdSchema,
72132
- /** The device this row belongs to (D865 removal, per-device reads). */
72133
- deviceId: number().int().optional(),
72134
- /** The domain clock, ms: observed / created / opened. */
72135
- at: number().int().optional(),
72136
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
72137
- expiresAt: number().int().optional(),
72138
- data: RecordBodySchema
72139
- });
72140
- var RecordViewSchema = object({
72141
- id: string(),
72142
- deviceId: number().int().nullable(),
72143
- at: number().nullable(),
72144
- expiresAt: number().nullable(),
72145
- rev: number().int(),
72146
- updatedAt: number(),
72147
- data: RecordBodySchema
72148
- });
72149
- /** Declared index fields only. Anything else does not compile, by design. */
72150
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
72151
- string(),
72152
- number(),
72153
- boolean(),
72154
- object({ in: array(union([
72155
- string(),
72156
- number(),
72157
- boolean()
72158
- ])).min(1).max(RECORD_BATCH_MAX) }),
72159
- object({
72160
- gt: union([string(), number()]).optional(),
72161
- gte: union([string(), number()]).optional(),
72162
- lt: union([string(), number()]).optional(),
72163
- lte: union([string(), number()]).optional()
72164
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
72165
- ]));
72166
- var KindShape = { kind: RecordKindNameSchema };
72167
- var TimeWindowShape = {
72168
- deviceId: number().int().optional(),
72169
- atFrom: number().optional(),
72170
- atTo: number().optional()
72171
- };
72172
- var RecordQueryInputSchema = object({
72173
- ...KindShape,
72174
- ...TimeWindowShape,
72175
- where: RecordWhereSchema.optional(),
72176
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
72177
- order: _enum(["at", "id"]).optional(),
72178
- desc: boolean().optional(),
72179
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
72180
- /** Opaque keyset cursor from a previous answer. There is no offset. */
72181
- cursor: string().min(1).optional()
72182
- });
72183
- var RecordQueryResultSchema = object({
72184
- records: array(RecordViewSchema),
72185
- nextCursor: string().nullable()
72186
- });
72187
- var RecordKindStateSchema = _enum([
72188
- "created",
72189
- "unchanged",
72190
- "updated"
72191
- ]);
72192
- var DeclareKindResultSchema = object({
72193
- kindId: number().int(),
72194
- state: RecordKindStateSchema,
72195
- createdIndexes: array(string())
72196
- });
72197
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
72198
- var SecretRefsList = array(string());
72199
- /**
72200
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
72201
- * All ops of one call share ONE database file and ONE `transactFamily`.
72202
- */
72203
- var RecordTransactOpSchema = discriminatedUnion("op", [
72204
- object({
72205
- op: literal("put"),
72206
- kind: RecordKindNameSchema,
72207
- record: RecordInputSchema,
72208
- ifRev: number().int().min(0).optional()
72209
- }),
72210
- object({
72211
- op: literal("patch"),
72212
- kind: RecordKindNameSchema,
72213
- id: RecordIdSchema,
72214
- data: RecordBodySchema,
72215
- at: number().int().nullable().optional(),
72216
- expiresAt: number().int().nullable().optional(),
72217
- ifRev: number().int().min(1).optional()
72218
- }),
72219
- object({
72220
- op: literal("delete"),
72221
- kind: RecordKindNameSchema,
72222
- id: RecordIdSchema
72223
- })
72224
- ]);
72225
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
72226
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
72227
- kind: "mutation",
72228
- auth: "admin"
72229
- }), method(object({
72230
- ...KindShape,
72231
- id: RecordIdSchema
72232
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
72233
- ...KindShape,
72234
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72235
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
72236
- ...KindShape,
72237
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72238
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
72239
- ...KindShape,
72240
- record: RecordInputSchema,
72241
- /** Compare-and-set. `0` means "the row must not exist". */
72242
- ifRev: number().int().min(0).optional()
72243
- }), object({
72244
- rev: number().int(),
72245
- releasedRefs: SecretRefsList
72246
- }), {
72247
- kind: "mutation",
72248
- auth: "admin"
72249
- }), method(object({
72250
- ...KindShape,
72251
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72252
- }), object({
72253
- count: number().int(),
72254
- releasedRefs: SecretRefsList
72255
- }), {
72256
- kind: "mutation",
72257
- auth: "admin"
72258
- }), method(object({
72259
- ...KindShape,
72260
- id: RecordIdSchema,
72261
- data: RecordBodySchema,
72262
- at: number().int().nullable().optional(),
72263
- expiresAt: number().int().nullable().optional(),
72264
- ifRev: number().int().min(1).optional()
72265
- }), object({
72266
- rev: number().int(),
72267
- releasedRefs: SecretRefsList
72268
- }), {
72269
- kind: "mutation",
72270
- auth: "admin"
72271
- }), method(object({
72272
- ...KindShape,
72273
- id: RecordIdSchema
72274
- }), object({
72275
- deleted: boolean(),
72276
- secretRefs: SecretRefsList
72277
- }), {
72278
- kind: "mutation",
72279
- auth: "admin"
72280
- }), method(object({
72281
- ...KindShape,
72282
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72283
- }), object({
72284
- deleted: number().int(),
72285
- secretRefs: SecretRefsList
72286
- }), {
72287
- kind: "mutation",
72288
- auth: "admin"
72289
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72290
- ...KindShape,
72291
- ...TimeWindowShape,
72292
- where: RecordWhereSchema.optional()
72293
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72294
- ...KindShape,
72295
- deviceId: number().int().optional(),
72296
- from: number(),
72297
- to: number(),
72298
- bucketMs: number().int().positive()
72299
- }), object({ buckets: array(object({
72300
- bucketStart: number(),
72301
- count: number().int()
72302
- })) }), { auth: "admin" }), method(object({
72303
- ...KindShape,
72304
- op: _enum([
72305
- "sum",
72306
- "min",
72307
- "max",
72308
- "count"
72309
- ]),
72310
- field: RecordFieldPathSchema.optional(),
72311
- groupBy: RecordFieldPathSchema.optional(),
72312
- where: RecordWhereSchema.optional()
72313
- }), object({ rows: array(object({
72314
- group: union([
72315
- string(),
72316
- number(),
72317
- _null()
72318
- ]),
72319
- value: number().nullable()
72320
- })) }), { auth: "admin" }), method(object({
72321
- ...KindShape,
72322
- deviceId: number().int().optional(),
72323
- atBefore: number().optional(),
72324
- where: RecordWhereSchema.optional()
72325
- }), object({
72326
- deleted: number().int(),
72327
- secretRefs: SecretRefsList
72328
- }), {
72329
- kind: "mutation",
72330
- auth: "admin"
72331
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72332
- results: array(object({
72333
- rev: number().int().nullable(),
72334
- deleted: boolean()
72335
- })),
72336
- releasedRefs: SecretRefsList,
72337
- secretRefs: SecretRefsList
72338
- }), {
72339
- kind: "mutation",
72340
- auth: "admin"
72341
- }), method(object({
72342
- deviceId: number().int(),
72343
- kinds: array(RecordKindNameSchema).optional()
72344
- }), object({
72345
- deleted: record(string(), number().int()),
72346
- secretRefs: SecretRefsList
72347
- }), {
72348
- kind: "mutation",
72349
- auth: "admin"
72350
- }), method(object(KindShape), object({ id: number().int() }), {
72351
- kind: "mutation",
72352
- auth: "admin"
72353
- });
72354
- /**
72355
72509
  * record-entries - the ONE admin surface for every list of user-created entries
72356
72510
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72357
72511
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -81815,11 +81969,15 @@ discriminatedUnion("kind", [object({
81815
81969
  * 1. idle floor F = time-weighted median; noise ceiling N = highest value seen
81816
81970
  * near F. A device that is not near one level most of the time has no floor.
81817
81971
  * 2. coarse activity = above max(2N, N + 5 W); consecutive stretches are episodes.
81818
- * 3. gaps between episodes split in two by the largest log-scale jump (>= 3x):
81819
- * the short ones are pauses INSIDE a run (a soak), the long ones separate runs.
81972
+ * 3. an episode shorter than `PULSE_MAX_MS` is a PULSE (an anti-crease tumble, a
81973
+ * display waking): it is neither a run nor a pause. Among the remaining
81974
+ * episodes, gaps over `PAUSE_MAX_MS` always separate runs; the rest split in
81975
+ * two by the largest log-scale jump (>= 3x): the short ones are pauses INSIDE
81976
+ * a run (a soak), the long ones separate runs. A stretch under `MIN_RUN_MS`
81977
+ * is no run.
81820
81978
  * 4. T = geometric mean of N and the plateau's 10th percentile, snapped to a
81821
- * grid a person would type; stop dwell covers the longest pause; start dwell
81822
- * covers the longest standby blip above T.
81979
+ * grid a person would type; stop dwell covers the longest pause and the
81980
+ * kind's floor; start dwell covers the longest pulse and standby blip above T.
81823
81981
  * 5. the numbers are proved by REPLAY through the real `dwell` evaluation: each
81824
81982
  * run must hold exactly one true interval and nothing may flap outside.
81825
81983
  */
@@ -81830,6 +81988,10 @@ var MINUTE_MS$1 = 60 * SECOND_MS;
81830
81988
  30 * SECOND_MS;
81831
81989
  60 * SECOND_MS;
81832
81990
  20 * MINUTE_MS$1;
81991
+ 90 * SECOND_MS;
81992
+ 30 * MINUTE_MS$1;
81993
+ 10 * MINUTE_MS$1;
81994
+ DeviceType.Dryer, 3 * MINUTE_MS$1, DeviceType.Dishwasher, 3 * MINUTE_MS$1, DeviceType.Washer, 10 * MINUTE_MS$1;
81833
81995
  10 * SECOND_MS;
81834
81996
  10 * SECOND_MS;
81835
81997
  /**
@@ -83113,7 +83275,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83113
83275
  * `deviceClasses` map (first registered type). `null` when manual creation is
83114
83276
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
83115
83277
  */
83116
- async getManualCreationType() {
83278
+ async getManualCreationType(_input) {
83117
83279
  if (!await this.supportsManualCreation()) return { deviceType: null };
83118
83280
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
83119
83281
  }
@@ -83124,7 +83286,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83124
83286
  return true;
83125
83287
  }
83126
83288
  async getChildCreationSchema(input) {
83127
- return this.onGetCreationSchema(input.type);
83289
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
83128
83290
  }
83129
83291
  /**
83130
83292
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -83136,7 +83298,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83136
83298
  * `deviceClasses` instead.
83137
83299
  */
83138
83300
  async createDevice(input) {
83139
- const spec = await this.onCreateDevice(input.type, input.config);
83301
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
83140
83302
  const Class = this.deviceClasses[spec.meta.type];
83141
83303
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
83142
83304
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -84549,20 +84711,6 @@ Object.freeze({
84549
84711
  access: "create",
84550
84712
  role: "viewer"
84551
84713
  },
84552
- "broker.add": {
84553
- capName: "broker",
84554
- capScope: "system",
84555
- addonId: null,
84556
- access: "create",
84557
- role: "admin"
84558
- },
84559
- "broker.get": {
84560
- capName: "broker",
84561
- capScope: "system",
84562
- addonId: null,
84563
- access: "view",
84564
- role: "admin"
84565
- },
84566
84714
  "broker.getBrokerConfig": {
84567
84715
  capName: "broker",
84568
84716
  capScope: "system",
@@ -84570,20 +84718,6 @@ Object.freeze({
84570
84718
  access: "view",
84571
84719
  role: "admin"
84572
84720
  },
84573
- "broker.getSettings": {
84574
- capName: "broker",
84575
- capScope: "system",
84576
- addonId: null,
84577
- access: "view",
84578
- role: "admin"
84579
- },
84580
- "broker.getSettingsSchema": {
84581
- capName: "broker",
84582
- capScope: "system",
84583
- addonId: null,
84584
- access: "view",
84585
- role: "admin"
84586
- },
84587
84721
  "broker.getState": {
84588
84722
  capName: "broker",
84589
84723
  capScope: "system",
@@ -84598,20 +84732,6 @@ Object.freeze({
84598
84732
  access: "view",
84599
84733
  role: "admin"
84600
84734
  },
84601
- "broker.list": {
84602
- capName: "broker",
84603
- capScope: "system",
84604
- addonId: null,
84605
- access: "view",
84606
- role: "admin"
84607
- },
84608
- "broker.listProviders": {
84609
- capName: "broker",
84610
- capScope: "system",
84611
- addonId: null,
84612
- access: "view",
84613
- role: "admin"
84614
- },
84615
84735
  "broker.publish": {
84616
84736
  capName: "broker",
84617
84737
  capScope: "system",
@@ -84619,20 +84739,6 @@ Object.freeze({
84619
84739
  access: "create",
84620
84740
  role: "admin"
84621
84741
  },
84622
- "broker.remove": {
84623
- capName: "broker",
84624
- capScope: "system",
84625
- addonId: null,
84626
- access: "delete",
84627
- role: "admin"
84628
- },
84629
- "broker.setSettings": {
84630
- capName: "broker",
84631
- capScope: "system",
84632
- addonId: null,
84633
- access: "create",
84634
- role: "admin"
84635
- },
84636
84742
  "broker.subscribe": {
84637
84743
  capName: "broker",
84638
84744
  capScope: "system",
@@ -84640,20 +84746,6 @@ Object.freeze({
84640
84746
  access: "create",
84641
84747
  role: "admin"
84642
84748
  },
84643
- "broker.testConnection": {
84644
- capName: "broker",
84645
- capScope: "system",
84646
- addonId: null,
84647
- access: "create",
84648
- role: "admin"
84649
- },
84650
- "broker.testSettings": {
84651
- capName: "broker",
84652
- capScope: "system",
84653
- addonId: null,
84654
- access: "create",
84655
- role: "admin"
84656
- },
84657
84749
  "broker.unsubscribe": {
84658
84750
  capName: "broker",
84659
84751
  capScope: "system",
@@ -87251,13 +87343,6 @@ Object.freeze({
87251
87343
  access: "create",
87252
87344
  role: "admin"
87253
87345
  },
87254
- "integrations.clearSettings": {
87255
- capName: "integrations",
87256
- capScope: "system",
87257
- addonId: null,
87258
- access: "delete",
87259
- role: "admin"
87260
- },
87261
87346
  "integrations.create": {
87262
87347
  capName: "integrations",
87263
87348
  capScope: "system",
@@ -87293,13 +87378,6 @@ Object.freeze({
87293
87378
  access: "view",
87294
87379
  role: "admin"
87295
87380
  },
87296
- "integrations.getSettings": {
87297
- capName: "integrations",
87298
- capScope: "system",
87299
- addonId: null,
87300
- access: "view",
87301
- role: "admin"
87302
- },
87303
87381
  "integrations.list": {
87304
87382
  capName: "integrations",
87305
87383
  capScope: "system",
@@ -87307,13 +87385,6 @@ Object.freeze({
87307
87385
  access: "view",
87308
87386
  role: "admin"
87309
87387
  },
87310
- "integrations.setSettings": {
87311
- capName: "integrations",
87312
- capScope: "system",
87313
- addonId: null,
87314
- access: "create",
87315
- role: "admin"
87316
- },
87317
87388
  "integrations.testConnection": {
87318
87389
  capName: "integrations",
87319
87390
  capScope: "system",
@@ -88308,6 +88379,13 @@ Object.freeze({
88308
88379
  access: "view",
88309
88380
  role: "admin"
88310
88381
  },
88382
+ "migrations.clearLegacyIntegrationRows": {
88383
+ capName: "migrations",
88384
+ capScope: "system",
88385
+ addonId: null,
88386
+ access: "delete",
88387
+ role: "admin"
88388
+ },
88311
88389
  "migrations.declareOwner": {
88312
88390
  capName: "migrations",
88313
88391
  capScope: "system",
@@ -88315,6 +88393,13 @@ Object.freeze({
88315
88393
  access: "create",
88316
88394
  role: "admin"
88317
88395
  },
88396
+ "migrations.deleteLegacyIntegrationRowKeys": {
88397
+ capName: "migrations",
88398
+ capScope: "system",
88399
+ addonId: null,
88400
+ access: "delete",
88401
+ role: "admin"
88402
+ },
88318
88403
  "migrations.dryRun": {
88319
88404
  capName: "migrations",
88320
88405
  capScope: "system",
@@ -88350,6 +88435,20 @@ Object.freeze({
88350
88435
  access: "create",
88351
88436
  role: "admin"
88352
88437
  },
88438
+ "migrations.patchLegacyIntegrationRows": {
88439
+ capName: "migrations",
88440
+ capScope: "system",
88441
+ addonId: null,
88442
+ access: "create",
88443
+ role: "admin"
88444
+ },
88445
+ "migrations.readLegacyIntegrationRows": {
88446
+ capName: "migrations",
88447
+ capScope: "system",
88448
+ addonId: null,
88449
+ access: "view",
88450
+ role: "admin"
88451
+ },
88353
88452
  "migrations.restorePreMigration": {
88354
88453
  capName: "migrations",
88355
88454
  capScope: "system",
@@ -89610,6 +89709,13 @@ Object.freeze({
89610
89709
  access: "view",
89611
89710
  role: "viewer"
89612
89711
  },
89712
+ "pipelineAnalytics.getMediaLocationCensus": {
89713
+ capName: "pipeline-analytics",
89714
+ capScope: "device",
89715
+ addonId: null,
89716
+ access: "view",
89717
+ role: "admin"
89718
+ },
89613
89719
  "pipelineAnalytics.getMediaReclaimStatus": {
89614
89720
  capName: "pipeline-analytics",
89615
89721
  capScope: "device",
@@ -98808,6 +98914,100 @@ object({
98808
98914
  delay: number().nonnegative().optional(),
98809
98915
  commands: record(string(), unknown())
98810
98916
  });
98917
+ entryBody({ brokerId: string() });
98918
+ function secretsOverMigrationApi(api) {
98919
+ return {
98920
+ resolve: async (refs) => {
98921
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
98922
+ const out = {};
98923
+ for (const ref of refs) {
98924
+ const value = values[ref];
98925
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
98926
+ kind: "value",
98927
+ value,
98928
+ version: 0
98929
+ };
98930
+ }
98931
+ return out;
98932
+ },
98933
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
98934
+ };
98935
+ }
98936
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
98937
+ function recordsOverMigrationApi(api) {
98938
+ return { kind: (definition) => {
98939
+ const handle = api.records.kind(definition);
98940
+ return {
98941
+ get: (id) => handle.get({ id }),
98942
+ getResolved: (id) => handle.getResolved({ id }),
98943
+ put: (input, opts) => handle.put({
98944
+ ...input,
98945
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
98946
+ }),
98947
+ delete: (id) => handle.delete({ id })
98948
+ };
98949
+ } };
98950
+ }
98951
+ function integrationRowsApiOver(api) {
98952
+ return {
98953
+ list: async () => (await api.integrations.list({})).integrations,
98954
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
98955
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
98956
+ };
98957
+ }
98958
+ /**
98959
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
98960
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
98961
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
98962
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
98963
+ */
98964
+ var lanes = /* @__PURE__ */ new WeakMap();
98965
+ function deliver(api, send) {
98966
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
98967
+ const reason = error instanceof Error ? error.message : String(error);
98968
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
98969
+ });
98970
+ lanes.set(api, next);
98971
+ return next;
98972
+ }
98973
+ function warnOver(api) {
98974
+ return (message) => deliver(api, () => api.log.warn({ message }));
98975
+ }
98976
+ /** What the rows-to-records move needs, over the migration API. */
98977
+ function rowsDepsOver(api) {
98978
+ return {
98979
+ api: integrationRowsApiOver(api),
98980
+ records: recordsOverMigrationApi(api),
98981
+ secrets: secretsOverMigrationApi(api),
98982
+ warn: warnOver(api)
98983
+ };
98984
+ }
98985
+ function defaultIntegrationApiOver$1(api) {
98986
+ return {
98987
+ ...integrationRowsApiOver(api),
98988
+ listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
98989
+ readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
98990
+ setDeviceIntegrationId: async (deviceId, integrationId) => {
98991
+ await api.devices.setIntegrationId({
98992
+ deviceId,
98993
+ integrationId
98994
+ });
98995
+ },
98996
+ readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
98997
+ };
98998
+ }
98999
+ /** What the rows-to-records move and the device claim need, over the migration API. */
99000
+ function defaultIntegrationDepsOver(api) {
99001
+ return {
99002
+ ...rowsDepsOver(api),
99003
+ api: defaultIntegrationApiOver$1(api),
99004
+ info: (message) => deliver(api, () => api.log.info({ message })),
99005
+ warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
99006
+ message,
99007
+ tags: { deviceId }
99008
+ }))
99009
+ };
99010
+ }
98811
99011
  //#endregion
98812
99012
  //#region src/amcrest-instances.ts
98813
99013
  /**
@@ -106881,18 +107081,13 @@ var AmcrestProviderAddon = class extends BaseDeviceProvider {
106881
107081
  const records = this.ctx.records;
106882
107082
  if (records === void 0) throw new Error("provider-amcrest: ctx.records is required (hub-only addon)");
106883
107083
  await records.declare(amcrestRecordKinds);
106884
- const defaultIntegration = defineAddonMigrations(defaultIntegrationMigrations({
107084
+ await this.runMigrations(defaultIntegrationMigrations({
106885
107085
  addonId: this.addonId,
106886
107086
  date: "2026-11-04"
106887
- }), defaultIntegrationPortsOver({
106888
- api: defaultIntegrationApiOver(this.ctx.api),
106889
- records,
106890
- kind: amcrestConnectionsEntryKind,
106891
- info: (message) => this.ctx.logger.info(message),
106892
- warn: (message) => this.ctx.logger.warn(message),
106893
- warnDevice: (message, deviceId) => this.ctx.logger.warn(message, { tags: { deviceId } })
107087
+ }), (api) => defaultIntegrationPortsOver({
107088
+ ...defaultIntegrationDepsOver(api),
107089
+ kind: amcrestConnectionsEntryKind
106894
107090
  }));
106895
- await this.runMigrations(defaultIntegration);
106896
107091
  this.clipService = createClipService({
106897
107092
  dataDir: this.ctx.dataDir,
106898
107093
  logger: this.ctx.logger,