@camstack/addon-provider-hikvision 1.2.181 → 1.2.183

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.mjs CHANGED
@@ -5989,7 +5989,7 @@ var ZodIssueCode = {
5989
5989
  var ZodFirstPartyTypeKind;
5990
5990
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5991
5991
  //#endregion
5992
- //#region ../types/dist/sleep-Cv4Zmie9.mjs
5992
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
5993
5993
  /**
5994
5994
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5995
5995
  * window to float samples (D455).
@@ -6798,6 +6798,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6798
6798
  }
6799
6799
  return out;
6800
6800
  }
6801
+ /** Every scope, in the order the guard and the docs list them. */
6802
+ var SCOPED_SETTINGS_SCOPES = [
6803
+ "cluster",
6804
+ "device-defaults",
6805
+ "node"
6806
+ ];
6801
6807
  /**
6802
6808
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6803
6809
  *
@@ -7612,6 +7618,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7612
7618
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7613
7619
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7614
7620
  /**
7621
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7622
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7623
+ * through `api` (guard `check-migration-ports-surface`).
7624
+ */
7625
+ function migrationSet(catalogue, bindPorts) {
7626
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7627
+ }
7628
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7629
+ function refuseMixed(form, kept, dropped) {
7630
+ 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`);
7631
+ }
7632
+ function catalogueOf(list) {
7633
+ const kept = list.filter((entry) => !("execute" in entry));
7634
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7635
+ return kept;
7636
+ }
7637
+ function boundOf(list) {
7638
+ const kept = list.filter((entry) => "execute" in entry);
7639
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7640
+ return kept;
7641
+ }
7642
+ /**
7615
7643
  * Base class for CamStack addons. Eliminates settings boilerplate:
7616
7644
  *
7617
7645
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7689,6 +7717,13 @@ var BaseAddon = class {
7689
7717
  */
7690
7718
  secretStatePaths = [];
7691
7719
  _addonSecretTree = null;
7720
+ /**
7721
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7722
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7723
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7724
+ */
7725
+ _scopedByCap = /* @__PURE__ */ new Map();
7726
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7692
7727
  _deviceSecretTree = null;
7693
7728
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7694
7729
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7758,6 +7793,7 @@ var BaseAddon = class {
7758
7793
  this._ctx = context;
7759
7794
  this._secretSettings = null;
7760
7795
  }
7796
+ await this.loadScopedSchemas();
7761
7797
  await this.resolveConfig();
7762
7798
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7763
7799
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7767,25 +7803,24 @@ var BaseAddon = class {
7767
7803
  const normalized = normalizeAddonInitResult(result);
7768
7804
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7769
7805
  this._registeredCapNames = providers.map((p) => p.capability.name);
7806
+ await this.loadScopedSchemas();
7770
7807
  return normalized;
7771
7808
  }
7809
+ async runMigrations(first, second, third) {
7810
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7811
+ return this.runBound(boundOf(first), second);
7812
+ }
7772
7813
  /**
7773
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7774
- * engine. Call it at the point of the boot where the data must already have the new
7775
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7776
- * restored devices — with the catalogue bound to the addon's ports
7777
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7778
- *
7779
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7780
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7781
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7782
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7783
- *
7784
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7785
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7786
- * omitted applied ids "newer").
7814
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7815
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7816
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7787
7817
  */
7788
- async runMigrations(migrations, options) {
7818
+ async runMigrationSets(sets, options) {
7819
+ const api = this.ctx.migrationApi;
7820
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7821
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7822
+ }
7823
+ async runBound(migrations, options) {
7789
7824
  const api = this.ctx.api.migrations;
7790
7825
  const report = await runAddonMigrations({
7791
7826
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7855,6 +7890,16 @@ var BaseAddon = class {
7855
7890
  schema(schema) {
7856
7891
  return schema;
7857
7892
  }
7893
+ /**
7894
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7895
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7896
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7897
+ * must already know which keys are per node. Names the providers register at init are added
7898
+ * once known.
7899
+ */
7900
+ scopedSettingsCapabilities() {
7901
+ return [];
7902
+ }
7858
7903
  /** Override to provide global-level settings UI schema. */
7859
7904
  globalSettingsSchema(_cap) {
7860
7905
  return null;
@@ -7898,7 +7943,8 @@ var BaseAddon = class {
7898
7943
  return [];
7899
7944
  }
7900
7945
  async getGlobalSettings(overlay, cap, nodeId) {
7901
- const schema = this.globalSettingsSchema(cap);
7946
+ await this.loadScopedSchemas(cap);
7947
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7902
7948
  if (!schema) return { sections: [] };
7903
7949
  const projected = await this.readRawProjectedStore(nodeId, cap);
7904
7950
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -7933,10 +7979,9 @@ var BaseAddon = class {
7933
7979
  *
7934
7980
  * Override it only when an `instanceMode: multiple` addon's instances differ: an NVR integration
7935
7981
  * needs its connection fields, the default integration the addon's own sections. It is the
7936
- * SHAPE of the form only — the values live in `integrations.getSettings`, and the write path is
7937
- * unchanged (`integrations.setSettings` for an account integration).
7982
+ * SHAPE of the form only — the values live on the instance record.
7938
7983
  */
7939
- async integrationSettingsSchema(_instance) {
7984
+ async integrationFormSchema(_instance) {
7940
7985
  return null;
7941
7986
  }
7942
7987
  /**
@@ -7982,7 +8027,7 @@ var BaseAddon = class {
7982
8027
  * per-instance schema when it declares one, else its global schema (what they always showed).
7983
8028
  */
7984
8029
  async getIntegrationFormSchema(instance, nodeId) {
7985
- const scoped = await this.integrationSettingsSchema(instance);
8030
+ const scoped = await this.integrationFormSchema(instance);
7986
8031
  if (scoped === null) return this.getGlobalSettings(void 0, void 0, nodeId);
7987
8032
  return hydrateSchema(scoped, {}, { inlineSecretsAsViews: true });
7988
8033
  }
@@ -8030,6 +8075,7 @@ var BaseAddon = class {
8030
8075
  * resolved blob back is a no-op for every unchanged secret.
8031
8076
  */
8032
8077
  async resolveGlobalStore(nodeId, cap) {
8078
+ await this.loadScopedSchemas(cap);
8033
8079
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8034
8080
  return this.projectForNode(raw, nodeId, cap);
8035
8081
  }
@@ -8040,6 +8086,7 @@ var BaseAddon = class {
8040
8086
  }
8041
8087
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8042
8088
  async readRawProjectedStore(nodeId, cap) {
8089
+ await this.loadScopedSchemas(cap);
8043
8090
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8044
8091
  return this.projectForNode(raw, nodeId, cap);
8045
8092
  }
@@ -8142,6 +8189,7 @@ var BaseAddon = class {
8142
8189
  await this.applyGlobalPatch(patch, nodeId);
8143
8190
  }
8144
8191
  async applyGlobalPatch(barePatch, nodeId) {
8192
+ await this.loadScopedSchemas();
8145
8193
  const keys = this.perNodeKeys();
8146
8194
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8147
8195
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8155,7 +8203,8 @@ var BaseAddon = class {
8155
8203
  await this.resolveConfig();
8156
8204
  await this.onConfigChanged();
8157
8205
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8158
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8206
+ const legacy = this.globalSettingsSchema();
8207
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8159
8208
  }
8160
8209
  /**
8161
8210
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8163,14 +8212,67 @@ var BaseAddon = class {
8163
8212
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8164
8213
  * settings API behaves exactly like the legacy node-agnostic one.
8165
8214
  */
8166
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8215
+ /**
8216
+ * Load the scoped schemas of every capability this addon declares (the override and the
8217
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8218
+ * derived from the previous set. Idempotent.
8219
+ */
8220
+ async loadScopedSchemas(extraCap) {
8221
+ const caps = new Set([
8222
+ ...this.scopedSettingsCapabilities(),
8223
+ ...this._registeredCapNames,
8224
+ ...extraCap === void 0 ? [] : [extraCap]
8225
+ ]);
8226
+ let added = false;
8227
+ for (const cap of caps) {
8228
+ if (this._scopedByCap.has(cap)) continue;
8229
+ const loaded = [];
8230
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8231
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8232
+ if (schema !== null) loaded.push({
8233
+ scope,
8234
+ schema
8235
+ });
8236
+ }
8237
+ this._scopedByCap.set(cap, loaded);
8238
+ added = true;
8239
+ }
8240
+ if (!added) return;
8241
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8242
+ this._addonSecretTree = null;
8243
+ }
8244
+ /**
8245
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8246
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8247
+ */
8248
+ scopedFormSchema(cap) {
8249
+ const byId = /* @__PURE__ */ new Map();
8250
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8251
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8252
+ }
8253
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8254
+ loadedScopedSchemas(cap) {
8255
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8256
+ return [...this._scopedByCap.values()].flat();
8257
+ }
8258
+ /**
8259
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8260
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8261
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8262
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8263
+ * Call {@link loadScopedSchemas} first (the async seams do).
8264
+ */
8167
8265
  perNodeKeys(cap) {
8168
8266
  const cacheKey = cap ?? "";
8169
- const cached = this._perNodeKeysCache.get(cacheKey);
8267
+ const cached = this._nodeKeysByCap.get(cacheKey);
8170
8268
  if (cached) return cached;
8171
- const schema = this.globalSettingsSchema(cap);
8172
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8173
- this._perNodeKeysCache.set(cacheKey, keys);
8269
+ const legacy = this.globalSettingsSchema(cap);
8270
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8271
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8272
+ if (scope !== "node") continue;
8273
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8274
+ }
8275
+ this._nodeKeysByCap.set(cacheKey, keys);
8174
8276
  return keys;
8175
8277
  }
8176
8278
  /**
@@ -8180,10 +8282,9 @@ var BaseAddon = class {
8180
8282
  * time to return its response before the addon is torn down and
8181
8283
  * re-initialised by `AddonRegistryService.restartAddon`.
8182
8284
  */
8183
- maybeAutoRestart(patchKeys, schema) {
8184
- if (!schema) return;
8285
+ maybeAutoRestart(patchKeys, schemas) {
8185
8286
  const restartKeys = /* @__PURE__ */ new Set();
8186
- for (const section of schema.sections) for (const field of section.fields) {
8287
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8187
8288
  if (field.type === "separator" || field.type === "info") continue;
8188
8289
  if (field.requiresRestart) restartKeys.add(field.key);
8189
8290
  }
@@ -8379,12 +8480,14 @@ var BaseAddon = class {
8379
8480
  * here, in the addon's own process, so the hub keeps no copy of it.
8380
8481
  */
8381
8482
  async getDeclaredSettingsKeys() {
8483
+ await this.loadScopedSchemas();
8382
8484
  return { keys: [...this.declaredKeySet()].toSorted() };
8383
8485
  }
8384
8486
  declaredKeySet() {
8385
8487
  const keys = new Set(Object.keys(this.defaults));
8386
8488
  const schema = this.globalSettingsSchema();
8387
8489
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8490
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8388
8491
  for (const key of this._declaredStateKeys) keys.add(key);
8389
8492
  for (const path of this.secretStatePaths) {
8390
8493
  const root = path.split(/[.[]/, 1)[0];
@@ -8480,7 +8583,11 @@ var BaseAddon = class {
8480
8583
  }
8481
8584
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8482
8585
  addonSecretTree() {
8483
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8586
+ if (this._addonSecretTree === null) {
8587
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8588
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8589
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8590
+ }
8484
8591
  return this._addonSecretTree;
8485
8592
  }
8486
8593
  deviceSecretTree() {
@@ -8730,6 +8837,23 @@ function dropPerNodeFields(fields) {
8730
8837
  }
8731
8838
  return kept;
8732
8839
  }
8840
+ /** The keys of the value-holding fields, recursing into layout containers. */
8841
+ function collectValueFieldKeys(fields) {
8842
+ const collected = [];
8843
+ for (const field of fields) {
8844
+ if (field.type === "group") {
8845
+ collected.push(...collectValueFieldKeys(field.fields));
8846
+ continue;
8847
+ }
8848
+ if (field.type === "sub-tabs") {
8849
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8850
+ continue;
8851
+ }
8852
+ if (field.type === "separator" || field.type === "info") continue;
8853
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8854
+ }
8855
+ return collected;
8856
+ }
8733
8857
  function collectFieldKeys(fields) {
8734
8858
  const collected = [];
8735
8859
  for (const field of fields) {
@@ -9272,6 +9396,7 @@ function defineEntryKind(name, spec) {
9272
9396
  class: "config",
9273
9397
  writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
9274
9398
  retention: { none: "an entry goes only when the operator deletes it" },
9399
+ ...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
9275
9400
  ...spec.database === void 0 ? {} : { database: spec.database },
9276
9401
  ...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
9277
9402
  ...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
@@ -11967,7 +12092,7 @@ function userError(code, params, englishFallback) {
11967
12092
  return new CamstackError(code, params, englishFallback);
11968
12093
  }
11969
12094
  //#endregion
11970
- //#region ../types/dist/composition-CRNwcFYY.mjs
12095
+ //#region ../types/dist/composition-pOHbTzRB.mjs
11971
12096
  /**
11972
12097
  * The ffmpeg build every CamStack node downloads, per platform and arch.
11973
12098
  *
@@ -13448,7 +13573,7 @@ var RecordIntegrationInstances = class {
13448
13573
  return record === null ? null : this.viewOf(record);
13449
13574
  };
13450
13575
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13451
- createInstance = async ({ id, name, kind }) => {
13576
+ createInstance = async ({ id, name, kind, values }) => {
13452
13577
  const minted = id ?? this.hooks.mintId?.({
13453
13578
  name,
13454
13579
  ...kind !== void 0 ? { kind } : {}
@@ -13458,10 +13583,20 @@ var RecordIntegrationInstances = class {
13458
13583
  id: minted,
13459
13584
  data: this.hooks.initialBody(name, kind)
13460
13585
  }, { ifRev: 0 });
13586
+ const patch = this.patchOf(values ?? {});
13587
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13461
13588
  await this.hooks.onChanged?.(minted, "created");
13462
13589
  return { id: minted };
13463
13590
  };
13464
13591
  updateInstance = async ({ id, name, values }) => {
13592
+ const patch = this.patchOf(values);
13593
+ if (name !== void 0) patch[this.nameField] = name;
13594
+ await this.handle.patch(id, patch);
13595
+ await this.hooks.onChanged?.(id, "updated");
13596
+ return { ok: true };
13597
+ };
13598
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13599
+ patchOf(values) {
13465
13600
  const patch = {};
13466
13601
  for (const [key, value] of Object.entries(values)) {
13467
13602
  if (value === void 0) continue;
@@ -13472,11 +13607,8 @@ var RecordIntegrationInstances = class {
13472
13607
  else if (isSecretClear(value)) patch[key] = null;
13473
13608
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13474
13609
  }
13475
- if (name !== void 0) patch[this.nameField] = name;
13476
- await this.handle.patch(id, patch);
13477
- await this.hooks.onChanged?.(id, "updated");
13478
- return { ok: true };
13479
- };
13610
+ return patch;
13611
+ }
13480
13612
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13481
13613
  setInstanceEnabled = async ({ id, enabled }) => {
13482
13614
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14695,20 +14827,28 @@ async function moveIntegrationRowsToRecords(ports, spec) {
14695
14827
  };
14696
14828
  }
14697
14829
  /**
14698
- * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416): an addon runs the move
14699
- * from its own process, so the legacy rows are reached through the hub (`ctx.api.integrations`:
14700
- * `list`, `getSettings` - which answers the OWNER its secrets resolved - and `clearSettings`) and
14701
- * the new record through the addon's own records handle. The hub deletes the rows and their
14702
- * keychain values; the addon never touches the registry.
14830
+ * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416). An addon runs the move
14831
+ * from its own process, so the leftover rows are reached through the migration-only door
14832
+ * (`migrations.readLegacyIntegrationRows` / `clearLegacyIntegrationRows`) on the hub's connection.
14833
+ * The door returns markers. This process is the owner, so it resolves and releases them with
14834
+ * `resolveSecretMarkers` — the same call the old settings door used — and only then asks the
14835
+ * door to delete the rows. The addon's own record kind is its records handle.
14703
14836
  */
14837
+ async function resolvedRows(stored, secrets) {
14838
+ if (secrets === null) return stored;
14839
+ const { value, unresolved } = await resolveSecretMarkers(stored, secrets);
14840
+ if (unresolved.length > 0) throw new Error(`${unresolved.length} secret(s) cannot be read from the keychain`);
14841
+ return value;
14842
+ }
14704
14843
  function integrationRowsPortsOverApi(deps) {
14844
+ const secrets = deps.secrets ?? null;
14705
14845
  return {
14706
14846
  warn: (message) => deps.log.warn(message),
14707
14847
  listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
14708
14848
  id: i.id,
14709
14849
  name: i.name
14710
14850
  })),
14711
- readRows: (integrationId) => deps.api.getSettings({ id: integrationId }),
14851
+ readRows: async (integrationId) => resolvedRows(await deps.api.readLegacyIntegrationRows({ integrationId }), secrets),
14712
14852
  putRecord: async (id, body) => {
14713
14853
  if (await deps.records.get(id) !== null) return "exists";
14714
14854
  try {
@@ -14727,7 +14867,9 @@ function integrationRowsPortsOverApi(deps) {
14727
14867
  await deps.records.delete(id);
14728
14868
  },
14729
14869
  clearRows: async (integrationId) => {
14730
- await deps.api.clearSettings({ id: integrationId });
14870
+ const refs = collectSecretMarkerRefs(await deps.api.readLegacyIntegrationRows({ integrationId }));
14871
+ if (refs.length > 0 && secrets !== null) await secrets.delete(refs);
14872
+ await deps.api.clearLegacyIntegrationRows({ integrationId });
14731
14873
  }
14732
14874
  };
14733
14875
  }
@@ -14789,13 +14931,13 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14789
14931
  };
14790
14932
  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`);
14791
14933
  for (const device of orphans) if (resolve(device, new Set([device.id])) === null) unresolved.add(device.id);
14792
- 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);
14934
+ 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);
14793
14935
  for (const [deviceId, integrationId] of plan) await ports.setIntegrationId(deviceId, integrationId);
14794
14936
  const wrong = [];
14795
14937
  for (const [deviceId, integrationId] of plan) if (await ports.readIntegrationId(deviceId) !== integrationId) wrong.push(deviceId);
14796
14938
  if (wrong.length > 0) throw new Error(`device(s) ${wrong.join(", ")} did not read back their integration after the claim`);
14797
14939
  const claimed = plan.size;
14798
- 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`);
14940
+ 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`);
14799
14941
  return {
14800
14942
  outcome: claimed > 0 ? "done" : "already-done",
14801
14943
  summary: {
@@ -14817,14 +14959,14 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14817
14959
  * 2. `claim-devices` (tolerate): `claimDevicesToDefaultIntegration`; with no integration to claim
14818
14960
  * to it fails and is retried on the next boot.
14819
14961
  *
14820
- * Both run in the addon process through the hub API (`ctx.api`), BEFORE the addon registers its
14821
- * `integration-instances` provider: while a provider is registered the hub answers `getSettings`
14822
- * from the record, not from the rows.
14962
+ * Both run in the addon process through the hub API (`ctx.api`). The leftover rows are read
14963
+ * through the migration-only door, which answers empty once the store is gone.
14823
14964
  */
14824
14965
  function defaultIntegrationPortsOver(deps) {
14825
14966
  return {
14826
14967
  ...integrationRowsPortsOverApi({
14827
14968
  api: deps.api,
14969
+ ...deps.secrets !== void 0 ? { secrets: deps.secrets } : {},
14828
14970
  records: deps.records.kind({
14829
14971
  name: deps.kind.name,
14830
14972
  declaration: deps.kind.declaration,
@@ -14921,25 +15063,6 @@ function defaultIntegrationMigrations(spec) {
14921
15063
  ...spec.eligible !== void 0 ? { eligible: spec.eligible } : {}
14922
15064
  })];
14923
15065
  }
14924
- function defaultIntegrationApiOver(api) {
14925
- return {
14926
- list: () => api.integrations.list.query(),
14927
- getSettings: (input) => api.integrations.getSettings.query(input),
14928
- clearSettings: (input) => api.integrations.clearSettings.mutate(input),
14929
- listDevices: (addonId) => api.deviceManager.listAll.query({
14930
- addonId,
14931
- projection: "slim"
14932
- }),
14933
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14934
- await api.deviceManager.setIntegrationId.mutate({
14935
- deviceId,
14936
- integrationId
14937
- });
14938
- },
14939
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14940
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14941
- };
14942
- }
14943
15066
  /**
14944
15067
  * The trainer contract — what the hub hands the cloud trainer and what it
14945
15068
  * gets back (cloud training, D805+).
@@ -16046,6 +16169,39 @@ var UnstampedEventMediaCountSchema = object({
16046
16169
  /** Sum across both, or `null` when either lane could not be counted. */
16047
16170
  total: number().int().nonnegative().nullable()
16048
16171
  }).nullable();
16172
+ /**
16173
+ * Where the stored event media sits, per storage location: how many media rows
16174
+ * and how many bytes carry each location id, how many carry none (legacy,
16175
+ * resolved to the default `eventMedia` location), and how many name a location
16176
+ * that was not asked about (a deleted or never-listed one).
16177
+ *
16178
+ * One covering-index aggregate per asked location plus the NULL one, and one
16179
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
16180
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
16181
+ * it is a deleted location only when every location id was asked.
16182
+ * `null` is "could not be measured", never zero.
16183
+ */
16184
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
16185
+ var MediaLocationCensusSchema = object({
16186
+ locations: array(object({
16187
+ locationId: string(),
16188
+ rows: number().int().nonnegative(),
16189
+ bytes: number().nonnegative()
16190
+ })).readonly(),
16191
+ unstamped: object({
16192
+ rows: number().int().nonnegative(),
16193
+ bytes: number().nonnegative()
16194
+ }),
16195
+ /** Rows stamped with a location id that was not in the asked list. */
16196
+ unlisted: object({
16197
+ rows: number().int().nonnegative(),
16198
+ bytes: number().nonnegative()
16199
+ }),
16200
+ total: object({
16201
+ rows: number().int().nonnegative(),
16202
+ bytes: number().nonnegative()
16203
+ })
16204
+ });
16049
16205
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
16050
16206
  /** The independently selectable logical storage classes — every class
16051
16207
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -47363,52 +47519,7 @@ onBrightnessChanged: { data: object({
47363
47519
  minIntervalMs: 0
47364
47520
  } } }
47365
47521
  };
47366
- /**
47367
- * `broker` — unified pub/sub broker registry, system-scoped collection.
47368
- *
47369
- * The cap models any kind-tagged message broker the user wants to
47370
- * register and that other addons might consume. The first two kinds
47371
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
47372
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
47373
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
47374
- * the same surface.
47375
- *
47376
- * Why one cap, not one cap per kind:
47377
- * - The integrations page wants a single table of "every broker"
47378
- * across kinds; a unified cap drives it without join logic.
47379
- * - Generic admin operations (add / remove / test / status) are
47380
- * identical across kinds — duplicating them per cap was busywork.
47381
- * - The `network-access` cap precedent: same interface, many
47382
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47383
- *
47384
- * What stays kind-specific:
47385
- * - `getBrokerConfig` payload (kind decides whether it returns
47386
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47387
- * `Record<string, unknown>` at the wire; consumers narrow.
47388
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47389
- * key) — also typed as `Record<string, unknown>` so each kind can
47390
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47391
- * without rebreaking the cap signature.
47392
- * - `add` `settings` payload (different fields per kind, validated by
47393
- * the kind-specific provider).
47394
- *
47395
- * Bidirectionality:
47396
- * - `publish` is RPC — synchronous result (provider-defined).
47397
- * - `subscribe` returns a subscription handle; the actual message
47398
- * stream flows over the typed event-bus as `broker.message` events
47399
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47400
- * event handler. Subscriptions persist across reconnects — the
47401
- * provider re-subscribes upstream after a transport drop.
47402
- *
47403
- * Why event-bus push (not a subscription RPC stream):
47404
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47405
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47406
- * drop is recoverable via `getState({key})`).
47407
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47408
- * - Cross-process: events already route through `$event-bus`; no
47409
- * per-broker wire-shaping needed.
47410
- */
47411
- var BrokerStatusEnum = _enum([
47522
+ _enum([
47412
47523
  "connected",
47413
47524
  "disconnected",
47414
47525
  "connecting",
@@ -47416,141 +47527,12 @@ var BrokerStatusEnum = _enum([
47416
47527
  "unreachable",
47417
47528
  "error"
47418
47529
  ]);
47419
- var BrokerInfoSchema = object({
47420
- /** Stable broker id. Persisted; survives addon restarts. */
47421
- id: string(),
47422
- /** Addon id of the provider that OWNS this broker.
47423
- *
47424
- * The `broker` cap is a system-scoped collection: several addons
47425
- * register a `broker` provider, each owning a DISJOINT set of
47426
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47427
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47428
- * device belongs to one integration. The admin UI threads this id
47429
- * back as the `{ addonId }` system-collection selector on every
47430
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47431
- * `testConnection`), so the call routes to the OWNING provider
47432
- * instead of defaulting to the first-registered one. */
47433
- addonId: string(),
47434
- /** Human-readable name (operator-chosen at add-time). */
47435
- name: string(),
47436
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47437
- kind: string(),
47438
- status: BrokerStatusEnum,
47439
- /** Free-form provider-specific info (HA version, MQTT broker
47440
- * flavour, latency, mTLS active, …). */
47441
- info: record(string(), unknown()),
47442
- /** Ms epoch of the last connection probe / status update. */
47443
- lastCheckedAt: number().nullable(),
47444
- /** Last error message, when `status` indicates failure. */
47445
- error: string().nullable()
47446
- });
47447
47530
  var RegistryStatusSchema = object({
47448
47531
  brokerCount: number().int().nonnegative(),
47449
47532
  connectedCount: number().int().nonnegative()
47450
47533
  });
47451
- /**
47452
- * One entry per `broker` provider — which addon provides which broker
47453
- * kind(s). The unified create picker reads this to know, for each
47454
- * (addonId, kind) pair the operator can pick, where to route the
47455
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47456
- * `{ addonId }` selector). A provider only advertises a kind here when
47457
- * it implements `getSettingsSchema` for that kind (so the picker never
47458
- * offers a kind whose creation form can't be rendered).
47459
- */
47460
- var BrokerProviderInfoSchema = object({
47461
- /** Addon id of the `broker` provider this entry describes. */
47462
- addonId: string(),
47463
- /** Broker kinds this provider can create, with a display label. */
47464
- kinds: array(object({
47465
- kind: string(),
47466
- label: string(),
47467
- /**
47468
- * Relative hub path to start an interactive account link (OAuth popup).
47469
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47470
- */
47471
- interactiveConnectPath: string().min(1).optional(),
47472
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47473
- interactiveDisconnectPath: string().min(1).optional(),
47474
- /**
47475
- * The kind signs in through a server-held interactive session instead of
47476
- * (or before) typed credentials. `basePath` is a hub-relative route set
47477
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47478
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47479
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47480
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47481
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47482
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47483
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47484
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47485
- * offers it as the default path; the fields the session fills are
47486
- * marked `filledBySignIn` in the kind's settings schema.
47487
- *
47488
- * `methods` lists the ways the session can sign in, recommended first:
47489
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47490
- * settings) answering `{ sessionId, userCode, verificationUrl,
47491
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47492
- * any device, and the same `status` / `commit` / `cancel` routes follow
47493
- * (status then carries `method`, `userCode`, `verificationUrl`,
47494
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47495
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47496
- * `['proxy']`.
47497
- */
47498
- signIn: object({
47499
- basePath: string().min(1),
47500
- methods: array(_enum(["device-code", "proxy"])).optional()
47501
- }).optional()
47502
- }))
47503
- });
47504
- var ListInputSchema = object({
47505
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47506
- * only HA brokers. Omit to list every broker. */
47507
- kind: string().optional() });
47508
47534
  var GetInputSchema = object({ id: string() });
47509
- var AddInputSchema = object({
47510
- kind: string().min(1),
47511
- name: string().min(1),
47512
- /**
47513
- * ADOPT an existing id instead of minting a new one.
47514
- *
47515
- * Written the day this cost an outage. A broker's id is not a detail: HA
47516
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47517
- * lost from config and re-added as `ha_001` leaves every one of its devices
47518
- * bound to a broker that no longer exists. Re-entering the password under the
47519
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47520
- * password.
47521
- *
47522
- * A provider MUST refuse an id that is already in use — adopting a live
47523
- * broker's id would silently take it over.
47524
- */
47525
- id: string().min(1).optional(),
47526
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47527
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47528
- * branch on receipt — invalid shape rejects the add. */
47529
- settings: record(string(), unknown())
47530
- });
47531
- var AddResultSchema = object({ id: string() });
47532
- var RemoveInputSchema = object({ id: string() });
47533
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47534
- ok: literal(true),
47535
- latencyMs: number().nonnegative()
47536
- }), object({
47537
- ok: literal(false),
47538
- error: string()
47539
- })]);
47540
47535
  var SettingsRecordSchema$1 = record(string(), unknown());
47541
- var SettingsSchemaInputSchema = object({ kind: string() });
47542
- var TestSettingsInputSchema = object({
47543
- kind: string(),
47544
- settings: SettingsRecordSchema$1
47545
- });
47546
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47547
- ok: literal(true),
47548
- latencyMs: number().nonnegative().optional()
47549
- }).strict(), object({
47550
- ok: literal(false),
47551
- error: string()
47552
- })]);
47553
- var SettingsSchemaResultSchema = unknown().nullable();
47554
47536
  var PublishInputSchema = object({
47555
47537
  brokerId: string(),
47556
47538
  /** Kind-specific routing target.
@@ -47584,25 +47566,7 @@ var GetStateInputSchema = object({
47584
47566
  * HA: entity_id (returns the cached entity state). */
47585
47567
  key: string()
47586
47568
  });
47587
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47588
- kind: "mutation",
47589
- auth: "admin"
47590
- }), method(RemoveInputSchema, _void(), {
47591
- kind: "mutation",
47592
- auth: "admin"
47593
- }), method(GetInputSchema, TestConnectionResultSchema, {
47594
- kind: "mutation",
47595
- auth: "admin"
47596
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47597
- id: string(),
47598
- settings: SettingsRecordSchema$1
47599
- }), _void(), {
47600
- kind: "mutation",
47601
- auth: "admin"
47602
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47603
- kind: "mutation",
47604
- auth: "admin"
47605
- }), method(PublishInputSchema, unknown(), {
47569
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47606
47570
  kind: "mutation",
47607
47571
  auth: "admin"
47608
47572
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -50823,6 +50787,9 @@ var RunningProposalEvidenceSchema = object({
50823
50787
  runsFound: number().int().nonnegative(),
50824
50788
  pausesFound: number().int().nonnegative(),
50825
50789
  longestPauseMs: number().nonnegative(),
50790
+ /** Episodes shorter than ~90 s (an anti-crease pulse, a display waking): never a run, never a pause. */
50791
+ pulsesFound: number().int().nonnegative(),
50792
+ longestPulseMs: number().nonnegative(),
50826
50793
  idleFloorW: number(),
50827
50794
  noiseCeilingW: number(),
50828
50795
  plateauW: number(),
@@ -52420,7 +52387,14 @@ var DiscoveryCandidateSchema = object({
52420
52387
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52421
52388
  parentStableId: string().optional(),
52422
52389
  /** `false` = shown for context but not pickable. Default true. */
52423
- selectable: boolean().optional()
52390
+ selectable: boolean().optional(),
52391
+ /**
52392
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52393
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52394
+ * admin asks for exactly these, on the creation form prefilled with
52395
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52396
+ */
52397
+ needsParams: array(string()).optional()
52424
52398
  });
52425
52399
  /**
52426
52400
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52547,8 +52521,14 @@ var deviceProviderCapability = {
52547
52521
  * provider does not support manual creation. Lets the Add-Device dialog
52548
52522
  * pick the right type instead of assuming Camera.
52549
52523
  */
52550
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52551
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52524
+ getManualCreationType: method(object({
52525
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52526
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52527
+ adoptDiscoveredDevice: method(object({
52528
+ candidate: DiscoveryCandidateSchema,
52529
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52530
+ integrationId: string().optional()
52531
+ }), DeviceSummarySchema, {
52552
52532
  kind: "mutation",
52553
52533
  auth: "admin"
52554
52534
  }),
@@ -52559,10 +52539,16 @@ var deviceProviderCapability = {
52559
52539
  * devices of that type. The output is a `ConfigUISchema` — the
52560
52540
  * router type-asserts it at the boundary.
52561
52541
  */
52562
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52542
+ getChildCreationSchema: method(object({
52543
+ type: _enum(DeviceType),
52544
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52545
+ integrationId: string().optional()
52546
+ }), CreationSchemaOutputSchema),
52563
52547
  createDevice: method(object({
52564
52548
  type: _enum(DeviceType),
52565
- config: record(string(), unknown())
52549
+ config: record(string(), unknown()),
52550
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52551
+ integrationId: string().optional()
52566
52552
  }), DeviceSummarySchema, {
52567
52553
  kind: "mutation",
52568
52554
  auth: "admin"
@@ -53287,7 +53273,10 @@ method(object({
53287
53273
  auth: "admin"
53288
53274
  }), method(object({
53289
53275
  addonId: string(),
53290
- type: _enum(DeviceType)
53276
+ type: _enum(DeviceType),
53277
+ /** The integration the form is for; a provider whose integrations differ (a hub
53278
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
53279
+ integrationId: string().optional()
53291
53280
  }), unknown().nullable()), method(object({
53292
53281
  addonId: string(),
53293
53282
  type: _enum(DeviceType),
@@ -53371,7 +53360,11 @@ method(object({
53371
53360
  kind: "mutation",
53372
53361
  auth: "admin",
53373
53362
  timeoutMs: 12e4
53374
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53363
+ }), method(object({
53364
+ addonId: string(),
53365
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
53366
+ integrationId: string().optional()
53367
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53375
53368
  deviceId: number(),
53376
53369
  key: string(),
53377
53370
  value: unknown()
@@ -56670,7 +56663,7 @@ var TestConnectionStatusEnum = _enum([
56670
56663
  "inconclusive",
56671
56664
  "unsupported"
56672
56665
  ]);
56673
- var TestConnectionResultSchema$1 = object({
56666
+ var TestConnectionResultSchema = object({
56674
56667
  /** True ONLY for `validated`. Never true for a test that did not run. */
56675
56668
  success: boolean(),
56676
56669
  error: string().optional(),
@@ -56691,11 +56684,7 @@ var CreateIntegrationInputSchema = object({
56691
56684
  info: record(string(), unknown()).optional(),
56692
56685
  /** `stableId` of the discovery candidate the form was seeded from (D984). */
56693
56686
  originStableId: string().optional(),
56694
- settings: record(string(), unknown()).optional(),
56695
- /** Keys of `settings` the form's schema declares secret (by type) — kept in
56696
- * the keychain, not the table (D787). */
56697
- secretKeys: array(string()).optional(),
56698
- skipRestart: boolean().optional()
56687
+ settings: record(string(), unknown()).optional()
56699
56688
  });
56700
56689
  var UpdateIntegrationInputSchema = object({
56701
56690
  id: string(),
@@ -56716,26 +56705,10 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56716
56705
  }), method(object({ id: string() }), DeleteIntegrationResultSchema, {
56717
56706
  kind: "mutation",
56718
56707
  auth: "admin"
56719
- }), method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }), method(object({
56720
- id: string(),
56721
- settings: record(string(), unknown()),
56722
- /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
56723
- secretKeys: array(string()).optional(),
56724
- /** The integration's own addon applies the change in-process and asks the hub not to respawn it. */
56725
- skipRestart: boolean().optional()
56726
- }), object({ success: boolean() }), {
56727
- kind: "mutation",
56728
- auth: "admin"
56729
- }), method(object({ id: string() }), object({
56730
- rows: number().int().nonnegative(),
56731
- secrets: number().int().nonnegative()
56732
- }), {
56733
- kind: "mutation",
56734
- auth: "admin"
56735
56708
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56736
56709
  addonId: string(),
56737
56710
  settings: record(string(), unknown())
56738
- }), TestConnectionResultSchema$1, {
56711
+ }), TestConnectionResultSchema, {
56739
56712
  kind: "mutation",
56740
56713
  auth: "admin"
56741
56714
  });
@@ -56762,6 +56735,14 @@ var ConfigSchemaPassthrough$3 = custom();
56762
56735
  var IntegrationInstanceIdSchema = string().min(1);
56763
56736
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56764
56737
  /**
56738
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56739
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56740
+ * `services`: a connection configured from the addon's own function page, never listed on
56741
+ * Integrations.
56742
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56743
+ */
56744
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56745
+ /**
56765
56746
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56766
56747
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56767
56748
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56772,6 +56753,22 @@ var IntegrationInstanceKindSchema = object({
56772
56753
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56773
56754
  id: string().min(1),
56774
56755
  label: string().min(1),
56756
+ /**
56757
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56758
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56759
+ * provider with more than one section must name it on every kind.
56760
+ */
56761
+ functionCap: string().min(1),
56762
+ /**
56763
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56764
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56765
+ * finds the instances whose kind names it; absent takes the kind `id`.
56766
+ */
56767
+ brokerKind: string().min(1).optional(),
56768
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56769
+ role: IntegrationInstanceRoleSchema.optional(),
56770
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56771
+ canTest: boolean().optional(),
56775
56772
  /** The kind signs in through a server-held interactive session. */
56776
56773
  signIn: object({
56777
56774
  basePath: string().min(1),
@@ -56784,11 +56781,7 @@ var IntegrationInstanceKindSchema = object({
56784
56781
  });
56785
56782
  var IntegrationInstanceDescriptionSchema = object({
56786
56783
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56787
- role: _enum([
56788
- "devices",
56789
- "services",
56790
- "both"
56791
- ]),
56784
+ role: IntegrationInstanceRoleSchema,
56792
56785
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56793
56786
  discovery: object({
56794
56787
  mode: _enum([
@@ -56863,7 +56856,11 @@ var integrationInstancesCapability = {
56863
56856
  methods: {
56864
56857
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56865
56858
  /** The form; `id: null` is the create form. */
56866
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56859
+ instanceFormSchema: method(object({
56860
+ id: IntegrationInstanceIdSchema.nullable(),
56861
+ /** The kind of the create form (`id: null`) of a provider with several. */
56862
+ kind: string().min(1).optional()
56863
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56867
56864
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56868
56865
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56869
56866
  /**
@@ -56873,7 +56870,9 @@ var integrationInstancesCapability = {
56873
56870
  createInstance: method(object({
56874
56871
  id: IntegrationInstanceIdSchema.optional(),
56875
56872
  name: string().min(1),
56876
- kind: string().min(1).optional()
56873
+ kind: string().min(1).optional(),
56874
+ /** Form values written with the record (a link picked in the create dialog). */
56875
+ values: record(string(), unknown()).optional()
56877
56876
  }), object({ id: string() }), {
56878
56877
  kind: "mutation",
56879
56878
  auth: "admin"
@@ -56900,8 +56899,10 @@ var integrationInstancesCapability = {
56900
56899
  }),
56901
56900
  testInstance: optionalMethod(object({
56902
56901
  id: IntegrationInstanceIdSchema.nullable(),
56903
- values: record(string(), unknown())
56904
- }), TestConnectionResultSchema$1, {
56902
+ values: record(string(), unknown()),
56903
+ /** The kind to test when `id` is null and the provider has several. */
56904
+ kind: string().min(1).optional()
56905
+ }), TestConnectionResultSchema, {
56905
56906
  kind: "mutation",
56906
56907
  auth: "admin"
56907
56908
  })
@@ -59658,6 +59659,380 @@ var SystemMetricsSchema = object({
59658
59659
  gpuMemoryPercent: number().optional()
59659
59660
  });
59660
59661
  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);
59662
+ /**
59663
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59664
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59665
+ * (operator intent, D870) and device-history (numbers over time, D850).
59666
+ *
59667
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59668
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59669
+ * that with the addon id closed over). It is deliberately NOT in any input
59670
+ * schema, so a session can never supply it, and a call with no stamp is refused
59671
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59672
+ * addons go through the owner's capability.
59673
+ *
59674
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59675
+ * never `[]`. Secret fields are never on the wire: a read shows the
59676
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59677
+ * resolves itself, and a write may carry only a keychain marker bound to the
59678
+ * row's own ref.
59679
+ *
59680
+ * Internal: addons reach it through `ctx.records`, never directly.
59681
+ */
59682
+ var RecordIdSchema = string().min(1).max(256);
59683
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59684
+ var RecordBodySchema = record(string(), unknown());
59685
+ var RecordInputSchema = object({
59686
+ id: RecordIdSchema,
59687
+ /** The device this row belongs to (D865 removal, per-device reads). */
59688
+ deviceId: number().int().optional(),
59689
+ /** The domain clock, ms: observed / created / opened. */
59690
+ at: number().int().optional(),
59691
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59692
+ expiresAt: number().int().optional(),
59693
+ data: RecordBodySchema
59694
+ });
59695
+ var RecordViewSchema = object({
59696
+ id: string(),
59697
+ deviceId: number().int().nullable(),
59698
+ at: number().nullable(),
59699
+ expiresAt: number().nullable(),
59700
+ rev: number().int(),
59701
+ updatedAt: number(),
59702
+ data: RecordBodySchema
59703
+ });
59704
+ /** Declared index fields only. Anything else does not compile, by design. */
59705
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59706
+ string(),
59707
+ number(),
59708
+ boolean(),
59709
+ object({ in: array(union([
59710
+ string(),
59711
+ number(),
59712
+ boolean()
59713
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59714
+ object({
59715
+ gt: union([string(), number()]).optional(),
59716
+ gte: union([string(), number()]).optional(),
59717
+ lt: union([string(), number()]).optional(),
59718
+ lte: union([string(), number()]).optional()
59719
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59720
+ ]));
59721
+ var KindShape = { kind: RecordKindNameSchema };
59722
+ var TimeWindowShape = {
59723
+ deviceId: number().int().optional(),
59724
+ atFrom: number().optional(),
59725
+ atTo: number().optional()
59726
+ };
59727
+ var RecordQueryInputSchema = object({
59728
+ ...KindShape,
59729
+ ...TimeWindowShape,
59730
+ where: RecordWhereSchema.optional(),
59731
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59732
+ order: _enum(["at", "id"]).optional(),
59733
+ desc: boolean().optional(),
59734
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59735
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59736
+ cursor: string().min(1).optional()
59737
+ });
59738
+ var RecordQueryResultSchema = object({
59739
+ records: array(RecordViewSchema),
59740
+ nextCursor: string().nullable()
59741
+ });
59742
+ var RecordKindStateSchema = _enum([
59743
+ "created",
59744
+ "unchanged",
59745
+ "updated"
59746
+ ]);
59747
+ var DeclareKindResultSchema = object({
59748
+ kindId: number().int(),
59749
+ state: RecordKindStateSchema,
59750
+ createdIndexes: array(string())
59751
+ });
59752
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59753
+ var SecretRefsList = array(string());
59754
+ /**
59755
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59756
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59757
+ */
59758
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59759
+ object({
59760
+ op: literal("put"),
59761
+ kind: RecordKindNameSchema,
59762
+ record: RecordInputSchema,
59763
+ ifRev: number().int().min(0).optional()
59764
+ }),
59765
+ object({
59766
+ op: literal("patch"),
59767
+ kind: RecordKindNameSchema,
59768
+ id: RecordIdSchema,
59769
+ data: RecordBodySchema,
59770
+ at: number().int().nullable().optional(),
59771
+ expiresAt: number().int().nullable().optional(),
59772
+ ifRev: number().int().min(1).optional()
59773
+ }),
59774
+ object({
59775
+ op: literal("delete"),
59776
+ kind: RecordKindNameSchema,
59777
+ id: RecordIdSchema
59778
+ })
59779
+ ]);
59780
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59781
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59782
+ kind: "mutation",
59783
+ auth: "admin"
59784
+ }), method(object({
59785
+ ...KindShape,
59786
+ id: RecordIdSchema
59787
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59788
+ ...KindShape,
59789
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59790
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59791
+ ...KindShape,
59792
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59793
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59794
+ ...KindShape,
59795
+ record: RecordInputSchema,
59796
+ /** Compare-and-set. `0` means "the row must not exist". */
59797
+ ifRev: number().int().min(0).optional()
59798
+ }), object({
59799
+ rev: number().int(),
59800
+ releasedRefs: SecretRefsList
59801
+ }), {
59802
+ kind: "mutation",
59803
+ auth: "admin"
59804
+ }), method(object({
59805
+ ...KindShape,
59806
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59807
+ }), object({
59808
+ count: number().int(),
59809
+ releasedRefs: SecretRefsList
59810
+ }), {
59811
+ kind: "mutation",
59812
+ auth: "admin"
59813
+ }), method(object({
59814
+ ...KindShape,
59815
+ id: RecordIdSchema,
59816
+ data: RecordBodySchema,
59817
+ at: number().int().nullable().optional(),
59818
+ expiresAt: number().int().nullable().optional(),
59819
+ ifRev: number().int().min(1).optional()
59820
+ }), object({
59821
+ rev: number().int(),
59822
+ releasedRefs: SecretRefsList
59823
+ }), {
59824
+ kind: "mutation",
59825
+ auth: "admin"
59826
+ }), method(object({
59827
+ ...KindShape,
59828
+ id: RecordIdSchema
59829
+ }), object({
59830
+ deleted: boolean(),
59831
+ secretRefs: SecretRefsList
59832
+ }), {
59833
+ kind: "mutation",
59834
+ auth: "admin"
59835
+ }), method(object({
59836
+ ...KindShape,
59837
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59838
+ }), object({
59839
+ deleted: number().int(),
59840
+ secretRefs: SecretRefsList
59841
+ }), {
59842
+ kind: "mutation",
59843
+ auth: "admin"
59844
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59845
+ ...KindShape,
59846
+ ...TimeWindowShape,
59847
+ where: RecordWhereSchema.optional()
59848
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59849
+ ...KindShape,
59850
+ deviceId: number().int().optional(),
59851
+ from: number(),
59852
+ to: number(),
59853
+ bucketMs: number().int().positive()
59854
+ }), object({ buckets: array(object({
59855
+ bucketStart: number(),
59856
+ count: number().int()
59857
+ })) }), { auth: "admin" }), method(object({
59858
+ ...KindShape,
59859
+ op: _enum([
59860
+ "sum",
59861
+ "min",
59862
+ "max",
59863
+ "count"
59864
+ ]),
59865
+ field: RecordFieldPathSchema.optional(),
59866
+ groupBy: RecordFieldPathSchema.optional(),
59867
+ where: RecordWhereSchema.optional()
59868
+ }), object({ rows: array(object({
59869
+ group: union([
59870
+ string(),
59871
+ number(),
59872
+ _null()
59873
+ ]),
59874
+ value: number().nullable()
59875
+ })) }), { auth: "admin" }), method(object({
59876
+ ...KindShape,
59877
+ deviceId: number().int().optional(),
59878
+ atBefore: number().optional(),
59879
+ where: RecordWhereSchema.optional()
59880
+ }), object({
59881
+ deleted: number().int(),
59882
+ secretRefs: SecretRefsList
59883
+ }), {
59884
+ kind: "mutation",
59885
+ auth: "admin"
59886
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59887
+ results: array(object({
59888
+ rev: number().int().nullable(),
59889
+ deleted: boolean()
59890
+ })),
59891
+ releasedRefs: SecretRefsList,
59892
+ secretRefs: SecretRefsList
59893
+ }), {
59894
+ kind: "mutation",
59895
+ auth: "admin"
59896
+ }), method(object({
59897
+ deviceId: number().int(),
59898
+ kinds: array(RecordKindNameSchema).optional()
59899
+ }), object({
59900
+ deleted: record(string(), number().int()),
59901
+ secretRefs: SecretRefsList
59902
+ }), {
59903
+ kind: "mutation",
59904
+ auth: "admin"
59905
+ }), method(object(KindShape), object({ id: number().int() }), {
59906
+ kind: "mutation",
59907
+ auth: "admin"
59908
+ });
59909
+ /**
59910
+ * The wire shapes of the migration API, version 1 (planning#447).
59911
+ *
59912
+ * A migration is code that outlives the server it was written against: an addon at
59913
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59914
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59915
+ * is the contract of every method of it, one Zod pair per method.
59916
+ *
59917
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59918
+ * field is never removed or made required, an enum never narrows, an output field is
59919
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59920
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59921
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59922
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59923
+ */
59924
+ var Rows = record(string(), unknown());
59925
+ var IntegrationId = object({ integrationId: string().min(1) });
59926
+ var RecordId = object({ id: string().min(1) });
59927
+ var RecordRowSchema = object({
59928
+ id: string(),
59929
+ deviceId: number().int().nullable(),
59930
+ at: number().nullable(),
59931
+ expiresAt: number().nullable(),
59932
+ rev: number().int(),
59933
+ updatedAt: number(),
59934
+ data: Rows
59935
+ });
59936
+ var RecordPutShape = {
59937
+ id: string().min(1),
59938
+ deviceId: number().int().optional(),
59939
+ at: number().int().optional(),
59940
+ expiresAt: number().int().optional(),
59941
+ data: Rows
59942
+ };
59943
+ var MigrationIntegrationSchema = object({
59944
+ id: string(),
59945
+ addonId: string(),
59946
+ name: string(),
59947
+ info: Rows,
59948
+ originStableId: string().optional()
59949
+ });
59950
+ var MigrationDeviceSchema = object({
59951
+ id: number().int(),
59952
+ integrationId: string().nullable().optional(),
59953
+ /** The owning device; null or absent for a root. */
59954
+ parentDeviceId: number().int().nullable().optional(),
59955
+ type: string().optional(),
59956
+ name: string().optional(),
59957
+ stableId: string().optional()
59958
+ });
59959
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59960
+ var MigrationApiInfoSchema = object({
59961
+ version: number().int(),
59962
+ methods: array(string())
59963
+ });
59964
+ object({
59965
+ message: string(),
59966
+ meta: Rows.optional(),
59967
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59968
+ tags: object({ deviceId: number().int().optional() }).optional()
59969
+ });
59970
+ object({
59971
+ owner: string().min(1),
59972
+ metas: array(MigrationMetaSchema)
59973
+ }), object({
59974
+ bootId: string(),
59975
+ snapshot: _enum([
59976
+ "none",
59977
+ "written",
59978
+ "refused"
59979
+ ]),
59980
+ steps: array(MigrationOwnerStepSchema),
59981
+ /** The migration API the engine serves; absent from a server that predates it. */
59982
+ migrationApi: MigrationApiInfoSchema.optional()
59983
+ }), object({ id: string().min(1) }), object({
59984
+ proceed: boolean(),
59985
+ state: union([literal("pending"), MigrationStatusSchema]),
59986
+ reason: string().nullable()
59987
+ }), object({
59988
+ id: string().min(1),
59989
+ result: MigrationOwnerResultSchema
59990
+ }), object({
59991
+ status: MigrationStatusSchema,
59992
+ error: string().nullable(),
59993
+ rowsChanged: number().int().nonnegative()
59994
+ }), object({
59995
+ rows: number().int().nonnegative(),
59996
+ secrets: number().int().nonnegative()
59997
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59998
+ present: boolean(),
59999
+ removed: Rows
60000
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
60001
+ ...RecordPutShape,
60002
+ ifRev: number().int().optional()
60003
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
60004
+ partial: Rows,
60005
+ ifRev: number().int().optional()
60006
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
60007
+ deviceId: number().int().optional(),
60008
+ atFrom: number().optional(),
60009
+ atTo: number().optional(),
60010
+ where: RecordWhereSchema.optional(),
60011
+ limit: number().int().min(1).optional(),
60012
+ cursor: string().min(1).optional(),
60013
+ resolveSecrets: boolean().optional()
60014
+ }), object({
60015
+ records: array(RecordRowSchema),
60016
+ nextCursor: string().nullable()
60017
+ }), object({
60018
+ deviceId: number().int().optional(),
60019
+ atBefore: number().optional(),
60020
+ where: RecordWhereSchema.optional()
60021
+ }), 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({
60022
+ ref: string().min(1),
60023
+ value: string()
60024
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
60025
+ addonId: string().min(1),
60026
+ integrationId: string().min(1).optional()
60027
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
60028
+ id: number().int(),
60029
+ integrationId: string().nullable(),
60030
+ /** Whether the device carries any stored config; its content is not offered. */
60031
+ hasConfig: boolean()
60032
+ }).nullable(), object({
60033
+ deviceId: number().int(),
60034
+ integrationId: string().min(1)
60035
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59661
60036
  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({
59662
60037
  id: string().min(1),
59663
60038
  error: string().min(1)
@@ -59687,7 +60062,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59687
60062
  "written",
59688
60063
  "refused"
59689
60064
  ]),
59690
- steps: array(MigrationOwnerStepSchema)
60065
+ steps: array(MigrationOwnerStepSchema),
60066
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
60067
+ migrationApi: MigrationApiInfoSchema.optional()
59691
60068
  }), {
59692
60069
  kind: "mutation",
59693
60070
  auth: "admin"
@@ -59708,6 +60085,27 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59708
60085
  }), {
59709
60086
  kind: "mutation",
59710
60087
  auth: "admin"
60088
+ }), method(object({ integrationId: string().min(1) }), record(string(), unknown()), { auth: "admin" }), method(object({ integrationId: string().min(1) }), object({
60089
+ rows: number().int().nonnegative(),
60090
+ secrets: number().int().nonnegative()
60091
+ }), {
60092
+ kind: "mutation",
60093
+ auth: "admin"
60094
+ }), method(object({
60095
+ integrationId: string().min(1),
60096
+ patch: record(string(), unknown())
60097
+ }), object({ written: boolean() }), {
60098
+ kind: "mutation",
60099
+ auth: "admin"
60100
+ }), method(object({
60101
+ integrationId: string().min(1),
60102
+ keys: array(string().min(1))
60103
+ }), object({
60104
+ present: boolean(),
60105
+ removed: record(string(), unknown())
60106
+ }), {
60107
+ kind: "mutation",
60108
+ auth: "admin"
59711
60109
  });
59712
60110
  method(object({
59713
60111
  sourceUrl: string(),
@@ -62333,7 +62731,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
62333
62731
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
62334
62732
  kind: "mutation",
62335
62733
  auth: "admin"
62336
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62734
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62735
+ kind: "query",
62736
+ auth: "admin"
62737
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62337
62738
  kind: "query",
62338
62739
  auth: "admin"
62339
62740
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64988,7 +65389,7 @@ var BrokerStatusSchema$1 = _enum([
64988
65389
  "unreachable",
64989
65390
  "tls-error"
64990
65391
  ]);
64991
- var BrokerInfoSchema$1 = object({
65392
+ var BrokerInfoSchema = object({
64992
65393
  id: string(),
64993
65394
  name: string(),
64994
65395
  url: string(),
@@ -65051,7 +65452,7 @@ var StatusSchema = object({
65051
65452
  brokerCount: number(),
65052
65453
  embeddedRunning: boolean()
65053
65454
  });
65054
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65455
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65055
65456
  kind: "mutation",
65056
65457
  auth: "admin"
65057
65458
  }), method(IdInputSchema, _void(), {
@@ -72417,253 +72818,6 @@ var rebootCapability = {
72417
72818
  }) }
72418
72819
  };
72419
72820
  /**
72420
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
72421
- * config documents, mirrors. The third storage API next to `ctx.settings`
72422
- * (operator intent, D870) and device-history (numbers over time, D850).
72423
- *
72424
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
72425
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
72426
- * that with the addon id closed over). It is deliberately NOT in any input
72427
- * schema, so a session can never supply it, and a call with no stamp is refused
72428
- * `records/no-caller`. A kind is readable and writable only by its owner; other
72429
- * addons go through the owner's capability.
72430
- *
72431
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
72432
- * never `[]`. Secret fields are never on the wire: a read shows the
72433
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
72434
- * resolves itself, and a write may carry only a keychain marker bound to the
72435
- * row's own ref.
72436
- *
72437
- * Internal: addons reach it through `ctx.records`, never directly.
72438
- */
72439
- var RecordIdSchema = string().min(1).max(256);
72440
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
72441
- var RecordBodySchema = record(string(), unknown());
72442
- var RecordInputSchema = object({
72443
- id: RecordIdSchema,
72444
- /** The device this row belongs to (D865 removal, per-device reads). */
72445
- deviceId: number().int().optional(),
72446
- /** The domain clock, ms: observed / created / opened. */
72447
- at: number().int().optional(),
72448
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
72449
- expiresAt: number().int().optional(),
72450
- data: RecordBodySchema
72451
- });
72452
- var RecordViewSchema = object({
72453
- id: string(),
72454
- deviceId: number().int().nullable(),
72455
- at: number().nullable(),
72456
- expiresAt: number().nullable(),
72457
- rev: number().int(),
72458
- updatedAt: number(),
72459
- data: RecordBodySchema
72460
- });
72461
- /** Declared index fields only. Anything else does not compile, by design. */
72462
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
72463
- string(),
72464
- number(),
72465
- boolean(),
72466
- object({ in: array(union([
72467
- string(),
72468
- number(),
72469
- boolean()
72470
- ])).min(1).max(RECORD_BATCH_MAX) }),
72471
- object({
72472
- gt: union([string(), number()]).optional(),
72473
- gte: union([string(), number()]).optional(),
72474
- lt: union([string(), number()]).optional(),
72475
- lte: union([string(), number()]).optional()
72476
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
72477
- ]));
72478
- var KindShape = { kind: RecordKindNameSchema };
72479
- var TimeWindowShape = {
72480
- deviceId: number().int().optional(),
72481
- atFrom: number().optional(),
72482
- atTo: number().optional()
72483
- };
72484
- var RecordQueryInputSchema = object({
72485
- ...KindShape,
72486
- ...TimeWindowShape,
72487
- where: RecordWhereSchema.optional(),
72488
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
72489
- order: _enum(["at", "id"]).optional(),
72490
- desc: boolean().optional(),
72491
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
72492
- /** Opaque keyset cursor from a previous answer. There is no offset. */
72493
- cursor: string().min(1).optional()
72494
- });
72495
- var RecordQueryResultSchema = object({
72496
- records: array(RecordViewSchema),
72497
- nextCursor: string().nullable()
72498
- });
72499
- var RecordKindStateSchema = _enum([
72500
- "created",
72501
- "unchanged",
72502
- "updated"
72503
- ]);
72504
- var DeclareKindResultSchema = object({
72505
- kindId: number().int(),
72506
- state: RecordKindStateSchema,
72507
- createdIndexes: array(string())
72508
- });
72509
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
72510
- var SecretRefsList = array(string());
72511
- /**
72512
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
72513
- * All ops of one call share ONE database file and ONE `transactFamily`.
72514
- */
72515
- var RecordTransactOpSchema = discriminatedUnion("op", [
72516
- object({
72517
- op: literal("put"),
72518
- kind: RecordKindNameSchema,
72519
- record: RecordInputSchema,
72520
- ifRev: number().int().min(0).optional()
72521
- }),
72522
- object({
72523
- op: literal("patch"),
72524
- kind: RecordKindNameSchema,
72525
- id: RecordIdSchema,
72526
- data: RecordBodySchema,
72527
- at: number().int().nullable().optional(),
72528
- expiresAt: number().int().nullable().optional(),
72529
- ifRev: number().int().min(1).optional()
72530
- }),
72531
- object({
72532
- op: literal("delete"),
72533
- kind: RecordKindNameSchema,
72534
- id: RecordIdSchema
72535
- })
72536
- ]);
72537
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
72538
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
72539
- kind: "mutation",
72540
- auth: "admin"
72541
- }), method(object({
72542
- ...KindShape,
72543
- id: RecordIdSchema
72544
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
72545
- ...KindShape,
72546
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72547
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
72548
- ...KindShape,
72549
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72550
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
72551
- ...KindShape,
72552
- record: RecordInputSchema,
72553
- /** Compare-and-set. `0` means "the row must not exist". */
72554
- ifRev: number().int().min(0).optional()
72555
- }), object({
72556
- rev: number().int(),
72557
- releasedRefs: SecretRefsList
72558
- }), {
72559
- kind: "mutation",
72560
- auth: "admin"
72561
- }), method(object({
72562
- ...KindShape,
72563
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72564
- }), object({
72565
- count: number().int(),
72566
- releasedRefs: SecretRefsList
72567
- }), {
72568
- kind: "mutation",
72569
- auth: "admin"
72570
- }), method(object({
72571
- ...KindShape,
72572
- id: RecordIdSchema,
72573
- data: RecordBodySchema,
72574
- at: number().int().nullable().optional(),
72575
- expiresAt: number().int().nullable().optional(),
72576
- ifRev: number().int().min(1).optional()
72577
- }), object({
72578
- rev: number().int(),
72579
- releasedRefs: SecretRefsList
72580
- }), {
72581
- kind: "mutation",
72582
- auth: "admin"
72583
- }), method(object({
72584
- ...KindShape,
72585
- id: RecordIdSchema
72586
- }), object({
72587
- deleted: boolean(),
72588
- secretRefs: SecretRefsList
72589
- }), {
72590
- kind: "mutation",
72591
- auth: "admin"
72592
- }), method(object({
72593
- ...KindShape,
72594
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72595
- }), object({
72596
- deleted: number().int(),
72597
- secretRefs: SecretRefsList
72598
- }), {
72599
- kind: "mutation",
72600
- auth: "admin"
72601
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72602
- ...KindShape,
72603
- ...TimeWindowShape,
72604
- where: RecordWhereSchema.optional()
72605
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72606
- ...KindShape,
72607
- deviceId: number().int().optional(),
72608
- from: number(),
72609
- to: number(),
72610
- bucketMs: number().int().positive()
72611
- }), object({ buckets: array(object({
72612
- bucketStart: number(),
72613
- count: number().int()
72614
- })) }), { auth: "admin" }), method(object({
72615
- ...KindShape,
72616
- op: _enum([
72617
- "sum",
72618
- "min",
72619
- "max",
72620
- "count"
72621
- ]),
72622
- field: RecordFieldPathSchema.optional(),
72623
- groupBy: RecordFieldPathSchema.optional(),
72624
- where: RecordWhereSchema.optional()
72625
- }), object({ rows: array(object({
72626
- group: union([
72627
- string(),
72628
- number(),
72629
- _null()
72630
- ]),
72631
- value: number().nullable()
72632
- })) }), { auth: "admin" }), method(object({
72633
- ...KindShape,
72634
- deviceId: number().int().optional(),
72635
- atBefore: number().optional(),
72636
- where: RecordWhereSchema.optional()
72637
- }), object({
72638
- deleted: number().int(),
72639
- secretRefs: SecretRefsList
72640
- }), {
72641
- kind: "mutation",
72642
- auth: "admin"
72643
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72644
- results: array(object({
72645
- rev: number().int().nullable(),
72646
- deleted: boolean()
72647
- })),
72648
- releasedRefs: SecretRefsList,
72649
- secretRefs: SecretRefsList
72650
- }), {
72651
- kind: "mutation",
72652
- auth: "admin"
72653
- }), method(object({
72654
- deviceId: number().int(),
72655
- kinds: array(RecordKindNameSchema).optional()
72656
- }), object({
72657
- deleted: record(string(), number().int()),
72658
- secretRefs: SecretRefsList
72659
- }), {
72660
- kind: "mutation",
72661
- auth: "admin"
72662
- }), method(object(KindShape), object({ id: number().int() }), {
72663
- kind: "mutation",
72664
- auth: "admin"
72665
- });
72666
- /**
72667
72821
  * record-entries - the ONE admin surface for every list of user-created entries
72668
72822
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72669
72823
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -82210,11 +82364,15 @@ discriminatedUnion("kind", [object({
82210
82364
  * 1. idle floor F = time-weighted median; noise ceiling N = highest value seen
82211
82365
  * near F. A device that is not near one level most of the time has no floor.
82212
82366
  * 2. coarse activity = above max(2N, N + 5 W); consecutive stretches are episodes.
82213
- * 3. gaps between episodes split in two by the largest log-scale jump (>= 3x):
82214
- * the short ones are pauses INSIDE a run (a soak), the long ones separate runs.
82367
+ * 3. an episode shorter than `PULSE_MAX_MS` is a PULSE (an anti-crease tumble, a
82368
+ * display waking): it is neither a run nor a pause. Among the remaining
82369
+ * episodes, gaps over `PAUSE_MAX_MS` always separate runs; the rest split in
82370
+ * two by the largest log-scale jump (>= 3x): the short ones are pauses INSIDE
82371
+ * a run (a soak), the long ones separate runs. A stretch under `MIN_RUN_MS`
82372
+ * is no run.
82215
82373
  * 4. T = geometric mean of N and the plateau's 10th percentile, snapped to a
82216
- * grid a person would type; stop dwell covers the longest pause; start dwell
82217
- * covers the longest standby blip above T.
82374
+ * grid a person would type; stop dwell covers the longest pause and the
82375
+ * kind's floor; start dwell covers the longest pulse and standby blip above T.
82218
82376
  * 5. the numbers are proved by REPLAY through the real `dwell` evaluation: each
82219
82377
  * run must hold exactly one true interval and nothing may flap outside.
82220
82378
  */
@@ -82225,6 +82383,10 @@ var MINUTE_MS$1 = 60 * SECOND_MS;
82225
82383
  30 * SECOND_MS;
82226
82384
  60 * SECOND_MS;
82227
82385
  20 * MINUTE_MS$1;
82386
+ 90 * SECOND_MS;
82387
+ 30 * MINUTE_MS$1;
82388
+ 10 * MINUTE_MS$1;
82389
+ DeviceType.Dryer, 3 * MINUTE_MS$1, DeviceType.Dishwasher, 3 * MINUTE_MS$1, DeviceType.Washer, 10 * MINUTE_MS$1;
82228
82390
  10 * SECOND_MS;
82229
82391
  10 * SECOND_MS;
82230
82392
  /**
@@ -83523,7 +83685,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83523
83685
  * `deviceClasses` map (first registered type). `null` when manual creation is
83524
83686
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
83525
83687
  */
83526
- async getManualCreationType() {
83688
+ async getManualCreationType(_input) {
83527
83689
  if (!await this.supportsManualCreation()) return { deviceType: null };
83528
83690
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
83529
83691
  }
@@ -83534,7 +83696,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83534
83696
  return true;
83535
83697
  }
83536
83698
  async getChildCreationSchema(input) {
83537
- return this.onGetCreationSchema(input.type);
83699
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
83538
83700
  }
83539
83701
  /**
83540
83702
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -83546,7 +83708,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83546
83708
  * `deviceClasses` instead.
83547
83709
  */
83548
83710
  async createDevice(input) {
83549
- const spec = await this.onCreateDevice(input.type, input.config);
83711
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
83550
83712
  const Class = this.deviceClasses[spec.meta.type];
83551
83713
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
83552
83714
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -84959,20 +85121,6 @@ Object.freeze({
84959
85121
  access: "create",
84960
85122
  role: "viewer"
84961
85123
  },
84962
- "broker.add": {
84963
- capName: "broker",
84964
- capScope: "system",
84965
- addonId: null,
84966
- access: "create",
84967
- role: "admin"
84968
- },
84969
- "broker.get": {
84970
- capName: "broker",
84971
- capScope: "system",
84972
- addonId: null,
84973
- access: "view",
84974
- role: "admin"
84975
- },
84976
85124
  "broker.getBrokerConfig": {
84977
85125
  capName: "broker",
84978
85126
  capScope: "system",
@@ -84980,20 +85128,6 @@ Object.freeze({
84980
85128
  access: "view",
84981
85129
  role: "admin"
84982
85130
  },
84983
- "broker.getSettings": {
84984
- capName: "broker",
84985
- capScope: "system",
84986
- addonId: null,
84987
- access: "view",
84988
- role: "admin"
84989
- },
84990
- "broker.getSettingsSchema": {
84991
- capName: "broker",
84992
- capScope: "system",
84993
- addonId: null,
84994
- access: "view",
84995
- role: "admin"
84996
- },
84997
85131
  "broker.getState": {
84998
85132
  capName: "broker",
84999
85133
  capScope: "system",
@@ -85008,20 +85142,6 @@ Object.freeze({
85008
85142
  access: "view",
85009
85143
  role: "admin"
85010
85144
  },
85011
- "broker.list": {
85012
- capName: "broker",
85013
- capScope: "system",
85014
- addonId: null,
85015
- access: "view",
85016
- role: "admin"
85017
- },
85018
- "broker.listProviders": {
85019
- capName: "broker",
85020
- capScope: "system",
85021
- addonId: null,
85022
- access: "view",
85023
- role: "admin"
85024
- },
85025
85145
  "broker.publish": {
85026
85146
  capName: "broker",
85027
85147
  capScope: "system",
@@ -85029,20 +85149,6 @@ Object.freeze({
85029
85149
  access: "create",
85030
85150
  role: "admin"
85031
85151
  },
85032
- "broker.remove": {
85033
- capName: "broker",
85034
- capScope: "system",
85035
- addonId: null,
85036
- access: "delete",
85037
- role: "admin"
85038
- },
85039
- "broker.setSettings": {
85040
- capName: "broker",
85041
- capScope: "system",
85042
- addonId: null,
85043
- access: "create",
85044
- role: "admin"
85045
- },
85046
85152
  "broker.subscribe": {
85047
85153
  capName: "broker",
85048
85154
  capScope: "system",
@@ -85050,20 +85156,6 @@ Object.freeze({
85050
85156
  access: "create",
85051
85157
  role: "admin"
85052
85158
  },
85053
- "broker.testConnection": {
85054
- capName: "broker",
85055
- capScope: "system",
85056
- addonId: null,
85057
- access: "create",
85058
- role: "admin"
85059
- },
85060
- "broker.testSettings": {
85061
- capName: "broker",
85062
- capScope: "system",
85063
- addonId: null,
85064
- access: "create",
85065
- role: "admin"
85066
- },
85067
85159
  "broker.unsubscribe": {
85068
85160
  capName: "broker",
85069
85161
  capScope: "system",
@@ -87661,13 +87753,6 @@ Object.freeze({
87661
87753
  access: "create",
87662
87754
  role: "admin"
87663
87755
  },
87664
- "integrations.clearSettings": {
87665
- capName: "integrations",
87666
- capScope: "system",
87667
- addonId: null,
87668
- access: "delete",
87669
- role: "admin"
87670
- },
87671
87756
  "integrations.create": {
87672
87757
  capName: "integrations",
87673
87758
  capScope: "system",
@@ -87703,13 +87788,6 @@ Object.freeze({
87703
87788
  access: "view",
87704
87789
  role: "admin"
87705
87790
  },
87706
- "integrations.getSettings": {
87707
- capName: "integrations",
87708
- capScope: "system",
87709
- addonId: null,
87710
- access: "view",
87711
- role: "admin"
87712
- },
87713
87791
  "integrations.list": {
87714
87792
  capName: "integrations",
87715
87793
  capScope: "system",
@@ -87717,13 +87795,6 @@ Object.freeze({
87717
87795
  access: "view",
87718
87796
  role: "admin"
87719
87797
  },
87720
- "integrations.setSettings": {
87721
- capName: "integrations",
87722
- capScope: "system",
87723
- addonId: null,
87724
- access: "create",
87725
- role: "admin"
87726
- },
87727
87798
  "integrations.testConnection": {
87728
87799
  capName: "integrations",
87729
87800
  capScope: "system",
@@ -88718,6 +88789,13 @@ Object.freeze({
88718
88789
  access: "view",
88719
88790
  role: "admin"
88720
88791
  },
88792
+ "migrations.clearLegacyIntegrationRows": {
88793
+ capName: "migrations",
88794
+ capScope: "system",
88795
+ addonId: null,
88796
+ access: "delete",
88797
+ role: "admin"
88798
+ },
88721
88799
  "migrations.declareOwner": {
88722
88800
  capName: "migrations",
88723
88801
  capScope: "system",
@@ -88725,6 +88803,13 @@ Object.freeze({
88725
88803
  access: "create",
88726
88804
  role: "admin"
88727
88805
  },
88806
+ "migrations.deleteLegacyIntegrationRowKeys": {
88807
+ capName: "migrations",
88808
+ capScope: "system",
88809
+ addonId: null,
88810
+ access: "delete",
88811
+ role: "admin"
88812
+ },
88728
88813
  "migrations.dryRun": {
88729
88814
  capName: "migrations",
88730
88815
  capScope: "system",
@@ -88760,6 +88845,20 @@ Object.freeze({
88760
88845
  access: "create",
88761
88846
  role: "admin"
88762
88847
  },
88848
+ "migrations.patchLegacyIntegrationRows": {
88849
+ capName: "migrations",
88850
+ capScope: "system",
88851
+ addonId: null,
88852
+ access: "create",
88853
+ role: "admin"
88854
+ },
88855
+ "migrations.readLegacyIntegrationRows": {
88856
+ capName: "migrations",
88857
+ capScope: "system",
88858
+ addonId: null,
88859
+ access: "view",
88860
+ role: "admin"
88861
+ },
88763
88862
  "migrations.restorePreMigration": {
88764
88863
  capName: "migrations",
88765
88864
  capScope: "system",
@@ -90020,6 +90119,13 @@ Object.freeze({
90020
90119
  access: "view",
90021
90120
  role: "viewer"
90022
90121
  },
90122
+ "pipelineAnalytics.getMediaLocationCensus": {
90123
+ capName: "pipeline-analytics",
90124
+ capScope: "device",
90125
+ addonId: null,
90126
+ access: "view",
90127
+ role: "admin"
90128
+ },
90023
90129
  "pipelineAnalytics.getMediaReclaimStatus": {
90024
90130
  capName: "pipeline-analytics",
90025
90131
  capScope: "device",
@@ -99230,6 +99336,100 @@ object({
99230
99336
  delay: number().nonnegative().optional(),
99231
99337
  commands: record(string(), unknown())
99232
99338
  });
99339
+ entryBody({ brokerId: string() });
99340
+ function secretsOverMigrationApi(api) {
99341
+ return {
99342
+ resolve: async (refs) => {
99343
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
99344
+ const out = {};
99345
+ for (const ref of refs) {
99346
+ const value = values[ref];
99347
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
99348
+ kind: "value",
99349
+ value,
99350
+ version: 0
99351
+ };
99352
+ }
99353
+ return out;
99354
+ },
99355
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
99356
+ };
99357
+ }
99358
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
99359
+ function recordsOverMigrationApi(api) {
99360
+ return { kind: (definition) => {
99361
+ const handle = api.records.kind(definition);
99362
+ return {
99363
+ get: (id) => handle.get({ id }),
99364
+ getResolved: (id) => handle.getResolved({ id }),
99365
+ put: (input, opts) => handle.put({
99366
+ ...input,
99367
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
99368
+ }),
99369
+ delete: (id) => handle.delete({ id })
99370
+ };
99371
+ } };
99372
+ }
99373
+ function integrationRowsApiOver(api) {
99374
+ return {
99375
+ list: async () => (await api.integrations.list({})).integrations,
99376
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
99377
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
99378
+ };
99379
+ }
99380
+ /**
99381
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
99382
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
99383
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
99384
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
99385
+ */
99386
+ var lanes = /* @__PURE__ */ new WeakMap();
99387
+ function deliver(api, send) {
99388
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
99389
+ const reason = error instanceof Error ? error.message : String(error);
99390
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
99391
+ });
99392
+ lanes.set(api, next);
99393
+ return next;
99394
+ }
99395
+ function warnOver(api) {
99396
+ return (message) => deliver(api, () => api.log.warn({ message }));
99397
+ }
99398
+ /** What the rows-to-records move needs, over the migration API. */
99399
+ function rowsDepsOver(api) {
99400
+ return {
99401
+ api: integrationRowsApiOver(api),
99402
+ records: recordsOverMigrationApi(api),
99403
+ secrets: secretsOverMigrationApi(api),
99404
+ warn: warnOver(api)
99405
+ };
99406
+ }
99407
+ function defaultIntegrationApiOver$1(api) {
99408
+ return {
99409
+ ...integrationRowsApiOver(api),
99410
+ listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
99411
+ readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
99412
+ setDeviceIntegrationId: async (deviceId, integrationId) => {
99413
+ await api.devices.setIntegrationId({
99414
+ deviceId,
99415
+ integrationId
99416
+ });
99417
+ },
99418
+ readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
99419
+ };
99420
+ }
99421
+ /** What the rows-to-records move and the device claim need, over the migration API. */
99422
+ function defaultIntegrationDepsOver(api) {
99423
+ return {
99424
+ ...rowsDepsOver(api),
99425
+ api: defaultIntegrationApiOver$1(api),
99426
+ info: (message) => deliver(api, () => api.log.info({ message })),
99427
+ warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
99428
+ message,
99429
+ tags: { deviceId }
99430
+ }))
99431
+ };
99432
+ }
99233
99433
  /**
99234
99434
  * Per-device bounds for the STILLS, which are a different artifact entirely.
99235
99435
  *
@@ -112956,17 +113156,13 @@ var HikvisionProviderAddon = class extends BaseDeviceProvider {
112956
113156
  const records = this.ctx.records;
112957
113157
  if (records === void 0) throw new Error("provider-hikvision: ctx.records is required (hub-only addon)");
112958
113158
  await records.declare(hikvisionRecordKinds);
112959
- await this.runMigrations(defineAddonMigrations(defaultIntegrationMigrations({
113159
+ await this.runMigrations(defaultIntegrationMigrations({
112960
113160
  addonId: this.addonId,
112961
113161
  date: HIKVISION_MIGRATIONS_DATE
112962
- }), defaultIntegrationPortsOver({
112963
- api: defaultIntegrationApiOver(this.ctx.api),
112964
- records,
112965
- kind: hikvisionConnectionsEntryKind,
112966
- info: (message) => this.ctx.logger.info(message),
112967
- warn: (message) => this.ctx.logger.warn(message),
112968
- warnDevice: (message, deviceId) => this.ctx.logger.warn(message, { tags: { deviceId } })
112969
- })));
113162
+ }), (api) => defaultIntegrationPortsOver({
113163
+ ...defaultIntegrationDepsOver(api),
113164
+ kind: hikvisionConnectionsEntryKind
113165
+ }));
112970
113166
  regs.push({
112971
113167
  capability: failureContributionCapability,
112972
113168
  provider: { list: () => intercomFailureReport.list() }