@camstack/addon-provider-amcrest 0.2.165 → 0.2.167

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.mjs CHANGED
@@ -5990,7 +5990,7 @@ var ZodIssueCode = {
5990
5990
  var ZodFirstPartyTypeKind;
5991
5991
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5992
5992
  //#endregion
5993
- //#region ../types/dist/sleep-Cv4Zmie9.mjs
5993
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
5994
5994
  /**
5995
5995
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5996
5996
  * window to float samples (D455).
@@ -6799,6 +6799,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6799
6799
  }
6800
6800
  return out;
6801
6801
  }
6802
+ /** Every scope, in the order the guard and the docs list them. */
6803
+ var SCOPED_SETTINGS_SCOPES = [
6804
+ "cluster",
6805
+ "device-defaults",
6806
+ "node"
6807
+ ];
6802
6808
  /**
6803
6809
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6804
6810
  *
@@ -7613,6 +7619,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7613
7619
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7614
7620
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7615
7621
  /**
7622
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7623
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7624
+ * through `api` (guard `check-migration-ports-surface`).
7625
+ */
7626
+ function migrationSet(catalogue, bindPorts) {
7627
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7628
+ }
7629
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7630
+ function refuseMixed(form, kept, dropped) {
7631
+ 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`);
7632
+ }
7633
+ function catalogueOf(list) {
7634
+ const kept = list.filter((entry) => !("execute" in entry));
7635
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7636
+ return kept;
7637
+ }
7638
+ function boundOf(list) {
7639
+ const kept = list.filter((entry) => "execute" in entry);
7640
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7641
+ return kept;
7642
+ }
7643
+ /**
7616
7644
  * Base class for CamStack addons. Eliminates settings boilerplate:
7617
7645
  *
7618
7646
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7690,6 +7718,13 @@ var BaseAddon = class {
7690
7718
  */
7691
7719
  secretStatePaths = [];
7692
7720
  _addonSecretTree = null;
7721
+ /**
7722
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7723
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7724
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7725
+ */
7726
+ _scopedByCap = /* @__PURE__ */ new Map();
7727
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7693
7728
  _deviceSecretTree = null;
7694
7729
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7695
7730
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7759,6 +7794,7 @@ var BaseAddon = class {
7759
7794
  this._ctx = context;
7760
7795
  this._secretSettings = null;
7761
7796
  }
7797
+ await this.loadScopedSchemas();
7762
7798
  await this.resolveConfig();
7763
7799
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7764
7800
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7768,25 +7804,24 @@ var BaseAddon = class {
7768
7804
  const normalized = normalizeAddonInitResult(result);
7769
7805
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7770
7806
  this._registeredCapNames = providers.map((p) => p.capability.name);
7807
+ await this.loadScopedSchemas();
7771
7808
  return normalized;
7772
7809
  }
7810
+ async runMigrations(first, second, third) {
7811
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7812
+ return this.runBound(boundOf(first), second);
7813
+ }
7773
7814
  /**
7774
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7775
- * engine. Call it at the point of the boot where the data must already have the new
7776
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7777
- * restored devices — with the catalogue bound to the addon's ports
7778
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7779
- *
7780
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7781
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7782
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7783
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7784
- *
7785
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7786
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7787
- * omitted applied ids "newer").
7815
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7816
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7817
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7788
7818
  */
7789
- async runMigrations(migrations, options) {
7819
+ async runMigrationSets(sets, options) {
7820
+ const api = this.ctx.migrationApi;
7821
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7822
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7823
+ }
7824
+ async runBound(migrations, options) {
7790
7825
  const api = this.ctx.api.migrations;
7791
7826
  const report = await runAddonMigrations({
7792
7827
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7856,6 +7891,16 @@ var BaseAddon = class {
7856
7891
  schema(schema) {
7857
7892
  return schema;
7858
7893
  }
7894
+ /**
7895
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7896
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7897
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7898
+ * must already know which keys are per node. Names the providers register at init are added
7899
+ * once known.
7900
+ */
7901
+ scopedSettingsCapabilities() {
7902
+ return [];
7903
+ }
7859
7904
  /** Override to provide global-level settings UI schema. */
7860
7905
  globalSettingsSchema(_cap) {
7861
7906
  return null;
@@ -7899,7 +7944,8 @@ var BaseAddon = class {
7899
7944
  return [];
7900
7945
  }
7901
7946
  async getGlobalSettings(overlay, cap, nodeId) {
7902
- const schema = this.globalSettingsSchema(cap);
7947
+ await this.loadScopedSchemas(cap);
7948
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7903
7949
  if (!schema) return { sections: [] };
7904
7950
  const projected = await this.readRawProjectedStore(nodeId, cap);
7905
7951
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -7934,10 +7980,9 @@ var BaseAddon = class {
7934
7980
  *
7935
7981
  * Override it only when an `instanceMode: multiple` addon's instances differ: an NVR integration
7936
7982
  * needs its connection fields, the default integration the addon's own sections. It is the
7937
- * SHAPE of the form only — the values live in `integrations.getSettings`, and the write path is
7938
- * unchanged (`integrations.setSettings` for an account integration).
7983
+ * SHAPE of the form only — the values live on the instance record.
7939
7984
  */
7940
- async integrationSettingsSchema(_instance) {
7985
+ async integrationFormSchema(_instance) {
7941
7986
  return null;
7942
7987
  }
7943
7988
  /**
@@ -7983,7 +8028,7 @@ var BaseAddon = class {
7983
8028
  * per-instance schema when it declares one, else its global schema (what they always showed).
7984
8029
  */
7985
8030
  async getIntegrationFormSchema(instance, nodeId) {
7986
- const scoped = await this.integrationSettingsSchema(instance);
8031
+ const scoped = await this.integrationFormSchema(instance);
7987
8032
  if (scoped === null) return this.getGlobalSettings(void 0, void 0, nodeId);
7988
8033
  return hydrateSchema(scoped, {}, { inlineSecretsAsViews: true });
7989
8034
  }
@@ -8031,6 +8076,7 @@ var BaseAddon = class {
8031
8076
  * resolved blob back is a no-op for every unchanged secret.
8032
8077
  */
8033
8078
  async resolveGlobalStore(nodeId, cap) {
8079
+ await this.loadScopedSchemas(cap);
8034
8080
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8035
8081
  return this.projectForNode(raw, nodeId, cap);
8036
8082
  }
@@ -8041,6 +8087,7 @@ var BaseAddon = class {
8041
8087
  }
8042
8088
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8043
8089
  async readRawProjectedStore(nodeId, cap) {
8090
+ await this.loadScopedSchemas(cap);
8044
8091
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8045
8092
  return this.projectForNode(raw, nodeId, cap);
8046
8093
  }
@@ -8143,6 +8190,7 @@ var BaseAddon = class {
8143
8190
  await this.applyGlobalPatch(patch, nodeId);
8144
8191
  }
8145
8192
  async applyGlobalPatch(barePatch, nodeId) {
8193
+ await this.loadScopedSchemas();
8146
8194
  const keys = this.perNodeKeys();
8147
8195
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8148
8196
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8156,7 +8204,8 @@ var BaseAddon = class {
8156
8204
  await this.resolveConfig();
8157
8205
  await this.onConfigChanged();
8158
8206
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8159
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8207
+ const legacy = this.globalSettingsSchema();
8208
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8160
8209
  }
8161
8210
  /**
8162
8211
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8164,14 +8213,67 @@ var BaseAddon = class {
8164
8213
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8165
8214
  * settings API behaves exactly like the legacy node-agnostic one.
8166
8215
  */
8167
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8216
+ /**
8217
+ * Load the scoped schemas of every capability this addon declares (the override and the
8218
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8219
+ * derived from the previous set. Idempotent.
8220
+ */
8221
+ async loadScopedSchemas(extraCap) {
8222
+ const caps = new Set([
8223
+ ...this.scopedSettingsCapabilities(),
8224
+ ...this._registeredCapNames,
8225
+ ...extraCap === void 0 ? [] : [extraCap]
8226
+ ]);
8227
+ let added = false;
8228
+ for (const cap of caps) {
8229
+ if (this._scopedByCap.has(cap)) continue;
8230
+ const loaded = [];
8231
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8232
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8233
+ if (schema !== null) loaded.push({
8234
+ scope,
8235
+ schema
8236
+ });
8237
+ }
8238
+ this._scopedByCap.set(cap, loaded);
8239
+ added = true;
8240
+ }
8241
+ if (!added) return;
8242
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8243
+ this._addonSecretTree = null;
8244
+ }
8245
+ /**
8246
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8247
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8248
+ */
8249
+ scopedFormSchema(cap) {
8250
+ const byId = /* @__PURE__ */ new Map();
8251
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8252
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8253
+ }
8254
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8255
+ loadedScopedSchemas(cap) {
8256
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8257
+ return [...this._scopedByCap.values()].flat();
8258
+ }
8259
+ /**
8260
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8261
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8262
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8263
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8264
+ * Call {@link loadScopedSchemas} first (the async seams do).
8265
+ */
8168
8266
  perNodeKeys(cap) {
8169
8267
  const cacheKey = cap ?? "";
8170
- const cached = this._perNodeKeysCache.get(cacheKey);
8268
+ const cached = this._nodeKeysByCap.get(cacheKey);
8171
8269
  if (cached) return cached;
8172
- const schema = this.globalSettingsSchema(cap);
8173
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8174
- this._perNodeKeysCache.set(cacheKey, keys);
8270
+ const legacy = this.globalSettingsSchema(cap);
8271
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8272
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8273
+ if (scope !== "node") continue;
8274
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8275
+ }
8276
+ this._nodeKeysByCap.set(cacheKey, keys);
8175
8277
  return keys;
8176
8278
  }
8177
8279
  /**
@@ -8181,10 +8283,9 @@ var BaseAddon = class {
8181
8283
  * time to return its response before the addon is torn down and
8182
8284
  * re-initialised by `AddonRegistryService.restartAddon`.
8183
8285
  */
8184
- maybeAutoRestart(patchKeys, schema) {
8185
- if (!schema) return;
8286
+ maybeAutoRestart(patchKeys, schemas) {
8186
8287
  const restartKeys = /* @__PURE__ */ new Set();
8187
- for (const section of schema.sections) for (const field of section.fields) {
8288
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8188
8289
  if (field.type === "separator" || field.type === "info") continue;
8189
8290
  if (field.requiresRestart) restartKeys.add(field.key);
8190
8291
  }
@@ -8380,12 +8481,14 @@ var BaseAddon = class {
8380
8481
  * here, in the addon's own process, so the hub keeps no copy of it.
8381
8482
  */
8382
8483
  async getDeclaredSettingsKeys() {
8484
+ await this.loadScopedSchemas();
8383
8485
  return { keys: [...this.declaredKeySet()].toSorted() };
8384
8486
  }
8385
8487
  declaredKeySet() {
8386
8488
  const keys = new Set(Object.keys(this.defaults));
8387
8489
  const schema = this.globalSettingsSchema();
8388
8490
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8491
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8389
8492
  for (const key of this._declaredStateKeys) keys.add(key);
8390
8493
  for (const path of this.secretStatePaths) {
8391
8494
  const root = path.split(/[.[]/, 1)[0];
@@ -8481,7 +8584,11 @@ var BaseAddon = class {
8481
8584
  }
8482
8585
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8483
8586
  addonSecretTree() {
8484
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8587
+ if (this._addonSecretTree === null) {
8588
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8589
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8590
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8591
+ }
8485
8592
  return this._addonSecretTree;
8486
8593
  }
8487
8594
  deviceSecretTree() {
@@ -8731,6 +8838,23 @@ function dropPerNodeFields(fields) {
8731
8838
  }
8732
8839
  return kept;
8733
8840
  }
8841
+ /** The keys of the value-holding fields, recursing into layout containers. */
8842
+ function collectValueFieldKeys(fields) {
8843
+ const collected = [];
8844
+ for (const field of fields) {
8845
+ if (field.type === "group") {
8846
+ collected.push(...collectValueFieldKeys(field.fields));
8847
+ continue;
8848
+ }
8849
+ if (field.type === "sub-tabs") {
8850
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8851
+ continue;
8852
+ }
8853
+ if (field.type === "separator" || field.type === "info") continue;
8854
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8855
+ }
8856
+ return collected;
8857
+ }
8734
8858
  function collectFieldKeys(fields) {
8735
8859
  const collected = [];
8736
8860
  for (const field of fields) {
@@ -9273,6 +9397,7 @@ function defineEntryKind(name, spec) {
9273
9397
  class: "config",
9274
9398
  writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
9275
9399
  retention: { none: "an entry goes only when the operator deletes it" },
9400
+ ...spec.maxDataBytes === void 0 ? {} : { maxDataBytes: spec.maxDataBytes },
9276
9401
  ...spec.database === void 0 ? {} : { database: spec.database },
9277
9402
  ...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
9278
9403
  ...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
@@ -11956,7 +12081,7 @@ function userError(code, params, englishFallback) {
11956
12081
  return new CamstackError(code, params, englishFallback);
11957
12082
  }
11958
12083
  //#endregion
11959
- //#region ../types/dist/composition-CRNwcFYY.mjs
12084
+ //#region ../types/dist/composition-pOHbTzRB.mjs
11960
12085
  /**
11961
12086
  * The ffmpeg build every CamStack node downloads, per platform and arch.
11962
12087
  *
@@ -13437,7 +13562,7 @@ var RecordIntegrationInstances = class {
13437
13562
  return record === null ? null : this.viewOf(record);
13438
13563
  };
13439
13564
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13440
- createInstance = async ({ id, name, kind }) => {
13565
+ createInstance = async ({ id, name, kind, values }) => {
13441
13566
  const minted = id ?? this.hooks.mintId?.({
13442
13567
  name,
13443
13568
  ...kind !== void 0 ? { kind } : {}
@@ -13447,10 +13572,20 @@ var RecordIntegrationInstances = class {
13447
13572
  id: minted,
13448
13573
  data: this.hooks.initialBody(name, kind)
13449
13574
  }, { ifRev: 0 });
13575
+ const patch = this.patchOf(values ?? {});
13576
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13450
13577
  await this.hooks.onChanged?.(minted, "created");
13451
13578
  return { id: minted };
13452
13579
  };
13453
13580
  updateInstance = async ({ id, name, values }) => {
13581
+ const patch = this.patchOf(values);
13582
+ if (name !== void 0) patch[this.nameField] = name;
13583
+ await this.handle.patch(id, patch);
13584
+ await this.hooks.onChanged?.(id, "updated");
13585
+ return { ok: true };
13586
+ };
13587
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13588
+ patchOf(values) {
13454
13589
  const patch = {};
13455
13590
  for (const [key, value] of Object.entries(values)) {
13456
13591
  if (value === void 0) continue;
@@ -13461,11 +13596,8 @@ var RecordIntegrationInstances = class {
13461
13596
  else if (isSecretClear(value)) patch[key] = null;
13462
13597
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13463
13598
  }
13464
- if (name !== void 0) patch[this.nameField] = name;
13465
- await this.handle.patch(id, patch);
13466
- await this.hooks.onChanged?.(id, "updated");
13467
- return { ok: true };
13468
- };
13599
+ return patch;
13600
+ }
13469
13601
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13470
13602
  setInstanceEnabled = async ({ id, enabled }) => {
13471
13603
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14684,20 +14816,28 @@ async function moveIntegrationRowsToRecords(ports, spec) {
14684
14816
  };
14685
14817
  }
14686
14818
  /**
14687
- * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416): an addon runs the move
14688
- * from its own process, so the legacy rows are reached through the hub (`ctx.api.integrations`:
14689
- * `list`, `getSettings` - which answers the OWNER its secrets resolved - and `clearSettings`) and
14690
- * the new record through the addon's own records handle. The hub deletes the rows and their
14691
- * keychain values; the addon never touches the registry.
14819
+ * The addon-side ports of `moveIntegrationRowsToRecords` (planning#416). An addon runs the move
14820
+ * from its own process, so the leftover rows are reached through the migration-only door
14821
+ * (`migrations.readLegacyIntegrationRows` / `clearLegacyIntegrationRows`) on the hub's connection.
14822
+ * The door returns markers. This process is the owner, so it resolves and releases them with
14823
+ * `resolveSecretMarkers` — the same call the old settings door used — and only then asks the
14824
+ * door to delete the rows. The addon's own record kind is its records handle.
14692
14825
  */
14826
+ async function resolvedRows(stored, secrets) {
14827
+ if (secrets === null) return stored;
14828
+ const { value, unresolved } = await resolveSecretMarkers(stored, secrets);
14829
+ if (unresolved.length > 0) throw new Error(`${unresolved.length} secret(s) cannot be read from the keychain`);
14830
+ return value;
14831
+ }
14693
14832
  function integrationRowsPortsOverApi(deps) {
14833
+ const secrets = deps.secrets ?? null;
14694
14834
  return {
14695
14835
  warn: (message) => deps.log.warn(message),
14696
14836
  listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
14697
14837
  id: i.id,
14698
14838
  name: i.name
14699
14839
  })),
14700
- readRows: (integrationId) => deps.api.getSettings({ id: integrationId }),
14840
+ readRows: async (integrationId) => resolvedRows(await deps.api.readLegacyIntegrationRows({ integrationId }), secrets),
14701
14841
  putRecord: async (id, body) => {
14702
14842
  if (await deps.records.get(id) !== null) return "exists";
14703
14843
  try {
@@ -14716,7 +14856,9 @@ function integrationRowsPortsOverApi(deps) {
14716
14856
  await deps.records.delete(id);
14717
14857
  },
14718
14858
  clearRows: async (integrationId) => {
14719
- await deps.api.clearSettings({ id: integrationId });
14859
+ const refs = collectSecretMarkerRefs(await deps.api.readLegacyIntegrationRows({ integrationId }));
14860
+ if (refs.length > 0 && secrets !== null) await secrets.delete(refs);
14861
+ await deps.api.clearLegacyIntegrationRows({ integrationId });
14720
14862
  }
14721
14863
  };
14722
14864
  }
@@ -14778,13 +14920,13 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14778
14920
  };
14779
14921
  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`);
14780
14922
  for (const device of orphans) if (resolve(device, new Set([device.id])) === null) unresolved.add(device.id);
14781
- 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);
14923
+ 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);
14782
14924
  for (const [deviceId, integrationId] of plan) await ports.setIntegrationId(deviceId, integrationId);
14783
14925
  const wrong = [];
14784
14926
  for (const [deviceId, integrationId] of plan) if (await ports.readIntegrationId(deviceId) !== integrationId) wrong.push(deviceId);
14785
14927
  if (wrong.length > 0) throw new Error(`device(s) ${wrong.join(", ")} did not read back their integration after the claim`);
14786
14928
  const claimed = plan.size;
14787
- 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`);
14929
+ 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`);
14788
14930
  return {
14789
14931
  outcome: claimed > 0 ? "done" : "already-done",
14790
14932
  summary: {
@@ -14806,14 +14948,14 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14806
14948
  * 2. `claim-devices` (tolerate): `claimDevicesToDefaultIntegration`; with no integration to claim
14807
14949
  * to it fails and is retried on the next boot.
14808
14950
  *
14809
- * Both run in the addon process through the hub API (`ctx.api`), BEFORE the addon registers its
14810
- * `integration-instances` provider: while a provider is registered the hub answers `getSettings`
14811
- * from the record, not from the rows.
14951
+ * Both run in the addon process through the hub API (`ctx.api`). The leftover rows are read
14952
+ * through the migration-only door, which answers empty once the store is gone.
14812
14953
  */
14813
14954
  function defaultIntegrationPortsOver(deps) {
14814
14955
  return {
14815
14956
  ...integrationRowsPortsOverApi({
14816
14957
  api: deps.api,
14958
+ ...deps.secrets !== void 0 ? { secrets: deps.secrets } : {},
14817
14959
  records: deps.records.kind({
14818
14960
  name: deps.kind.name,
14819
14961
  declaration: deps.kind.declaration,
@@ -14910,25 +15052,6 @@ function defaultIntegrationMigrations(spec) {
14910
15052
  ...spec.eligible !== void 0 ? { eligible: spec.eligible } : {}
14911
15053
  })];
14912
15054
  }
14913
- function defaultIntegrationApiOver(api) {
14914
- return {
14915
- list: () => api.integrations.list.query(),
14916
- getSettings: (input) => api.integrations.getSettings.query(input),
14917
- clearSettings: (input) => api.integrations.clearSettings.mutate(input),
14918
- listDevices: (addonId) => api.deviceManager.listAll.query({
14919
- addonId,
14920
- projection: "slim"
14921
- }),
14922
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14923
- await api.deviceManager.setIntegrationId.mutate({
14924
- deviceId,
14925
- integrationId
14926
- });
14927
- },
14928
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14929
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14930
- };
14931
- }
14932
15055
  /**
14933
15056
  * The trainer contract — what the hub hands the cloud trainer and what it
14934
15057
  * gets back (cloud training, D805+).
@@ -16035,6 +16158,39 @@ var UnstampedEventMediaCountSchema = object({
16035
16158
  /** Sum across both, or `null` when either lane could not be counted. */
16036
16159
  total: number().int().nonnegative().nullable()
16037
16160
  }).nullable();
16161
+ /**
16162
+ * Where the stored event media sits, per storage location: how many media rows
16163
+ * and how many bytes carry each location id, how many carry none (legacy,
16164
+ * resolved to the default `eventMedia` location), and how many name a location
16165
+ * that was not asked about (a deleted or never-listed one).
16166
+ *
16167
+ * One covering-index aggregate per asked location plus the NULL one, and one
16168
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
16169
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
16170
+ * it is a deleted location only when every location id was asked.
16171
+ * `null` is "could not be measured", never zero.
16172
+ */
16173
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
16174
+ var MediaLocationCensusSchema = object({
16175
+ locations: array(object({
16176
+ locationId: string(),
16177
+ rows: number().int().nonnegative(),
16178
+ bytes: number().nonnegative()
16179
+ })).readonly(),
16180
+ unstamped: object({
16181
+ rows: number().int().nonnegative(),
16182
+ bytes: number().nonnegative()
16183
+ }),
16184
+ /** Rows stamped with a location id that was not in the asked list. */
16185
+ unlisted: object({
16186
+ rows: number().int().nonnegative(),
16187
+ bytes: number().nonnegative()
16188
+ }),
16189
+ total: object({
16190
+ rows: number().int().nonnegative(),
16191
+ bytes: number().nonnegative()
16192
+ })
16193
+ });
16038
16194
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
16039
16195
  /** The independently selectable logical storage classes — every class
16040
16196
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -47071,52 +47227,7 @@ onBrightnessChanged: { data: object({
47071
47227
  minIntervalMs: 0
47072
47228
  } } }
47073
47229
  };
47074
- /**
47075
- * `broker` — unified pub/sub broker registry, system-scoped collection.
47076
- *
47077
- * The cap models any kind-tagged message broker the user wants to
47078
- * register and that other addons might consume. The first two kinds
47079
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
47080
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
47081
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
47082
- * the same surface.
47083
- *
47084
- * Why one cap, not one cap per kind:
47085
- * - The integrations page wants a single table of "every broker"
47086
- * across kinds; a unified cap drives it without join logic.
47087
- * - Generic admin operations (add / remove / test / status) are
47088
- * identical across kinds — duplicating them per cap was busywork.
47089
- * - The `network-access` cap precedent: same interface, many
47090
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47091
- *
47092
- * What stays kind-specific:
47093
- * - `getBrokerConfig` payload (kind decides whether it returns
47094
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47095
- * `Record<string, unknown>` at the wire; consumers narrow.
47096
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47097
- * key) — also typed as `Record<string, unknown>` so each kind can
47098
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47099
- * without rebreaking the cap signature.
47100
- * - `add` `settings` payload (different fields per kind, validated by
47101
- * the kind-specific provider).
47102
- *
47103
- * Bidirectionality:
47104
- * - `publish` is RPC — synchronous result (provider-defined).
47105
- * - `subscribe` returns a subscription handle; the actual message
47106
- * stream flows over the typed event-bus as `broker.message` events
47107
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47108
- * event handler. Subscriptions persist across reconnects — the
47109
- * provider re-subscribes upstream after a transport drop.
47110
- *
47111
- * Why event-bus push (not a subscription RPC stream):
47112
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47113
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47114
- * drop is recoverable via `getState({key})`).
47115
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47116
- * - Cross-process: events already route through `$event-bus`; no
47117
- * per-broker wire-shaping needed.
47118
- */
47119
- var BrokerStatusEnum = _enum([
47230
+ _enum([
47120
47231
  "connected",
47121
47232
  "disconnected",
47122
47233
  "connecting",
@@ -47124,141 +47235,12 @@ var BrokerStatusEnum = _enum([
47124
47235
  "unreachable",
47125
47236
  "error"
47126
47237
  ]);
47127
- var BrokerInfoSchema = object({
47128
- /** Stable broker id. Persisted; survives addon restarts. */
47129
- id: string(),
47130
- /** Addon id of the provider that OWNS this broker.
47131
- *
47132
- * The `broker` cap is a system-scoped collection: several addons
47133
- * register a `broker` provider, each owning a DISJOINT set of
47134
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47135
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47136
- * device belongs to one integration. The admin UI threads this id
47137
- * back as the `{ addonId }` system-collection selector on every
47138
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47139
- * `testConnection`), so the call routes to the OWNING provider
47140
- * instead of defaulting to the first-registered one. */
47141
- addonId: string(),
47142
- /** Human-readable name (operator-chosen at add-time). */
47143
- name: string(),
47144
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47145
- kind: string(),
47146
- status: BrokerStatusEnum,
47147
- /** Free-form provider-specific info (HA version, MQTT broker
47148
- * flavour, latency, mTLS active, …). */
47149
- info: record(string(), unknown()),
47150
- /** Ms epoch of the last connection probe / status update. */
47151
- lastCheckedAt: number().nullable(),
47152
- /** Last error message, when `status` indicates failure. */
47153
- error: string().nullable()
47154
- });
47155
47238
  var RegistryStatusSchema = object({
47156
47239
  brokerCount: number().int().nonnegative(),
47157
47240
  connectedCount: number().int().nonnegative()
47158
47241
  });
47159
- /**
47160
- * One entry per `broker` provider — which addon provides which broker
47161
- * kind(s). The unified create picker reads this to know, for each
47162
- * (addonId, kind) pair the operator can pick, where to route the
47163
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47164
- * `{ addonId }` selector). A provider only advertises a kind here when
47165
- * it implements `getSettingsSchema` for that kind (so the picker never
47166
- * offers a kind whose creation form can't be rendered).
47167
- */
47168
- var BrokerProviderInfoSchema = object({
47169
- /** Addon id of the `broker` provider this entry describes. */
47170
- addonId: string(),
47171
- /** Broker kinds this provider can create, with a display label. */
47172
- kinds: array(object({
47173
- kind: string(),
47174
- label: string(),
47175
- /**
47176
- * Relative hub path to start an interactive account link (OAuth popup).
47177
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47178
- */
47179
- interactiveConnectPath: string().min(1).optional(),
47180
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47181
- interactiveDisconnectPath: string().min(1).optional(),
47182
- /**
47183
- * The kind signs in through a server-held interactive session instead of
47184
- * (or before) typed credentials. `basePath` is a hub-relative route set
47185
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47186
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47187
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47188
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47189
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47190
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47191
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47192
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47193
- * offers it as the default path; the fields the session fills are
47194
- * marked `filledBySignIn` in the kind's settings schema.
47195
- *
47196
- * `methods` lists the ways the session can sign in, recommended first:
47197
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47198
- * settings) answering `{ sessionId, userCode, verificationUrl,
47199
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47200
- * any device, and the same `status` / `commit` / `cancel` routes follow
47201
- * (status then carries `method`, `userCode`, `verificationUrl`,
47202
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47203
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47204
- * `['proxy']`.
47205
- */
47206
- signIn: object({
47207
- basePath: string().min(1),
47208
- methods: array(_enum(["device-code", "proxy"])).optional()
47209
- }).optional()
47210
- }))
47211
- });
47212
- var ListInputSchema = object({
47213
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47214
- * only HA brokers. Omit to list every broker. */
47215
- kind: string().optional() });
47216
47242
  var GetInputSchema = object({ id: string() });
47217
- var AddInputSchema = object({
47218
- kind: string().min(1),
47219
- name: string().min(1),
47220
- /**
47221
- * ADOPT an existing id instead of minting a new one.
47222
- *
47223
- * Written the day this cost an outage. A broker's id is not a detail: HA
47224
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47225
- * lost from config and re-added as `ha_001` leaves every one of its devices
47226
- * bound to a broker that no longer exists. Re-entering the password under the
47227
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47228
- * password.
47229
- *
47230
- * A provider MUST refuse an id that is already in use — adopting a live
47231
- * broker's id would silently take it over.
47232
- */
47233
- id: string().min(1).optional(),
47234
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47235
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47236
- * branch on receipt — invalid shape rejects the add. */
47237
- settings: record(string(), unknown())
47238
- });
47239
- var AddResultSchema = object({ id: string() });
47240
- var RemoveInputSchema = object({ id: string() });
47241
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47242
- ok: literal(true),
47243
- latencyMs: number().nonnegative()
47244
- }), object({
47245
- ok: literal(false),
47246
- error: string()
47247
- })]);
47248
47243
  var SettingsRecordSchema$1 = record(string(), unknown());
47249
- var SettingsSchemaInputSchema = object({ kind: string() });
47250
- var TestSettingsInputSchema = object({
47251
- kind: string(),
47252
- settings: SettingsRecordSchema$1
47253
- });
47254
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47255
- ok: literal(true),
47256
- latencyMs: number().nonnegative().optional()
47257
- }).strict(), object({
47258
- ok: literal(false),
47259
- error: string()
47260
- })]);
47261
- var SettingsSchemaResultSchema = unknown().nullable();
47262
47244
  var PublishInputSchema = object({
47263
47245
  brokerId: string(),
47264
47246
  /** Kind-specific routing target.
@@ -47292,25 +47274,7 @@ var GetStateInputSchema = object({
47292
47274
  * HA: entity_id (returns the cached entity state). */
47293
47275
  key: string()
47294
47276
  });
47295
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47296
- kind: "mutation",
47297
- auth: "admin"
47298
- }), method(RemoveInputSchema, _void(), {
47299
- kind: "mutation",
47300
- auth: "admin"
47301
- }), method(GetInputSchema, TestConnectionResultSchema, {
47302
- kind: "mutation",
47303
- auth: "admin"
47304
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47305
- id: string(),
47306
- settings: SettingsRecordSchema$1
47307
- }), _void(), {
47308
- kind: "mutation",
47309
- auth: "admin"
47310
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47311
- kind: "mutation",
47312
- auth: "admin"
47313
- }), method(PublishInputSchema, unknown(), {
47277
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47314
47278
  kind: "mutation",
47315
47279
  auth: "admin"
47316
47280
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -50531,6 +50495,9 @@ var RunningProposalEvidenceSchema = object({
50531
50495
  runsFound: number().int().nonnegative(),
50532
50496
  pausesFound: number().int().nonnegative(),
50533
50497
  longestPauseMs: number().nonnegative(),
50498
+ /** Episodes shorter than ~90 s (an anti-crease pulse, a display waking): never a run, never a pause. */
50499
+ pulsesFound: number().int().nonnegative(),
50500
+ longestPulseMs: number().nonnegative(),
50534
50501
  idleFloorW: number(),
50535
50502
  noiseCeilingW: number(),
50536
50503
  plateauW: number(),
@@ -52128,7 +52095,14 @@ var DiscoveryCandidateSchema = object({
52128
52095
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52129
52096
  parentStableId: string().optional(),
52130
52097
  /** `false` = shown for context but not pickable. Default true. */
52131
- selectable: boolean().optional()
52098
+ selectable: boolean().optional(),
52099
+ /**
52100
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52101
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52102
+ * admin asks for exactly these, on the creation form prefilled with
52103
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52104
+ */
52105
+ needsParams: array(string()).optional()
52132
52106
  });
52133
52107
  /**
52134
52108
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52255,8 +52229,14 @@ var deviceProviderCapability = {
52255
52229
  * provider does not support manual creation. Lets the Add-Device dialog
52256
52230
  * pick the right type instead of assuming Camera.
52257
52231
  */
52258
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52259
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52232
+ getManualCreationType: method(object({
52233
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52234
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52235
+ adoptDiscoveredDevice: method(object({
52236
+ candidate: DiscoveryCandidateSchema,
52237
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52238
+ integrationId: string().optional()
52239
+ }), DeviceSummarySchema, {
52260
52240
  kind: "mutation",
52261
52241
  auth: "admin"
52262
52242
  }),
@@ -52267,10 +52247,16 @@ var deviceProviderCapability = {
52267
52247
  * devices of that type. The output is a `ConfigUISchema` — the
52268
52248
  * router type-asserts it at the boundary.
52269
52249
  */
52270
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52250
+ getChildCreationSchema: method(object({
52251
+ type: _enum(DeviceType),
52252
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52253
+ integrationId: string().optional()
52254
+ }), CreationSchemaOutputSchema),
52271
52255
  createDevice: method(object({
52272
52256
  type: _enum(DeviceType),
52273
- config: record(string(), unknown())
52257
+ config: record(string(), unknown()),
52258
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52259
+ integrationId: string().optional()
52274
52260
  }), DeviceSummarySchema, {
52275
52261
  kind: "mutation",
52276
52262
  auth: "admin"
@@ -52995,7 +52981,10 @@ method(object({
52995
52981
  auth: "admin"
52996
52982
  }), method(object({
52997
52983
  addonId: string(),
52998
- type: _enum(DeviceType)
52984
+ type: _enum(DeviceType),
52985
+ /** The integration the form is for; a provider whose integrations differ (a hub
52986
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
52987
+ integrationId: string().optional()
52999
52988
  }), unknown().nullable()), method(object({
53000
52989
  addonId: string(),
53001
52990
  type: _enum(DeviceType),
@@ -53079,7 +53068,11 @@ method(object({
53079
53068
  kind: "mutation",
53080
53069
  auth: "admin",
53081
53070
  timeoutMs: 12e4
53082
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53071
+ }), method(object({
53072
+ addonId: string(),
53073
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
53074
+ integrationId: string().optional()
53075
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53083
53076
  deviceId: number(),
53084
53077
  key: string(),
53085
53078
  value: unknown()
@@ -56359,7 +56352,7 @@ var TestConnectionStatusEnum = _enum([
56359
56352
  "inconclusive",
56360
56353
  "unsupported"
56361
56354
  ]);
56362
- var TestConnectionResultSchema$1 = object({
56355
+ var TestConnectionResultSchema = object({
56363
56356
  /** True ONLY for `validated`. Never true for a test that did not run. */
56364
56357
  success: boolean(),
56365
56358
  error: string().optional(),
@@ -56380,11 +56373,7 @@ var CreateIntegrationInputSchema = object({
56380
56373
  info: record(string(), unknown()).optional(),
56381
56374
  /** `stableId` of the discovery candidate the form was seeded from (D984). */
56382
56375
  originStableId: string().optional(),
56383
- settings: record(string(), unknown()).optional(),
56384
- /** Keys of `settings` the form's schema declares secret (by type) — kept in
56385
- * the keychain, not the table (D787). */
56386
- secretKeys: array(string()).optional(),
56387
- skipRestart: boolean().optional()
56376
+ settings: record(string(), unknown()).optional()
56388
56377
  });
56389
56378
  var UpdateIntegrationInputSchema = object({
56390
56379
  id: string(),
@@ -56405,26 +56394,10 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56405
56394
  }), method(object({ id: string() }), DeleteIntegrationResultSchema, {
56406
56395
  kind: "mutation",
56407
56396
  auth: "admin"
56408
- }), method(object({ id: string() }), record(string(), unknown()), { auth: "admin" }), method(object({
56409
- id: string(),
56410
- settings: record(string(), unknown()),
56411
- /** Keys the form's schema declares secret (by type) — keychain-stored (D787). */
56412
- secretKeys: array(string()).optional(),
56413
- /** The integration's own addon applies the change in-process and asks the hub not to respawn it. */
56414
- skipRestart: boolean().optional()
56415
- }), object({ success: boolean() }), {
56416
- kind: "mutation",
56417
- auth: "admin"
56418
- }), method(object({ id: string() }), object({
56419
- rows: number().int().nonnegative(),
56420
- secrets: number().int().nonnegative()
56421
- }), {
56422
- kind: "mutation",
56423
- auth: "admin"
56424
56397
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56425
56398
  addonId: string(),
56426
56399
  settings: record(string(), unknown())
56427
- }), TestConnectionResultSchema$1, {
56400
+ }), TestConnectionResultSchema, {
56428
56401
  kind: "mutation",
56429
56402
  auth: "admin"
56430
56403
  });
@@ -56451,6 +56424,14 @@ var ConfigSchemaPassthrough$3 = custom();
56451
56424
  var IntegrationInstanceIdSchema = string().min(1);
56452
56425
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56453
56426
  /**
56427
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56428
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56429
+ * `services`: a connection configured from the addon's own function page, never listed on
56430
+ * Integrations.
56431
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56432
+ */
56433
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56434
+ /**
56454
56435
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56455
56436
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56456
56437
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56461,6 +56442,22 @@ var IntegrationInstanceKindSchema = object({
56461
56442
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56462
56443
  id: string().min(1),
56463
56444
  label: string().min(1),
56445
+ /**
56446
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56447
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56448
+ * provider with more than one section must name it on every kind.
56449
+ */
56450
+ functionCap: string().min(1),
56451
+ /**
56452
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56453
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56454
+ * finds the instances whose kind names it; absent takes the kind `id`.
56455
+ */
56456
+ brokerKind: string().min(1).optional(),
56457
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56458
+ role: IntegrationInstanceRoleSchema.optional(),
56459
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56460
+ canTest: boolean().optional(),
56464
56461
  /** The kind signs in through a server-held interactive session. */
56465
56462
  signIn: object({
56466
56463
  basePath: string().min(1),
@@ -56473,11 +56470,7 @@ var IntegrationInstanceKindSchema = object({
56473
56470
  });
56474
56471
  var IntegrationInstanceDescriptionSchema = object({
56475
56472
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56476
- role: _enum([
56477
- "devices",
56478
- "services",
56479
- "both"
56480
- ]),
56473
+ role: IntegrationInstanceRoleSchema,
56481
56474
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56482
56475
  discovery: object({
56483
56476
  mode: _enum([
@@ -56552,7 +56545,11 @@ var integrationInstancesCapability = {
56552
56545
  methods: {
56553
56546
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56554
56547
  /** The form; `id: null` is the create form. */
56555
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56548
+ instanceFormSchema: method(object({
56549
+ id: IntegrationInstanceIdSchema.nullable(),
56550
+ /** The kind of the create form (`id: null`) of a provider with several. */
56551
+ kind: string().min(1).optional()
56552
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56556
56553
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56557
56554
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56558
56555
  /**
@@ -56562,7 +56559,9 @@ var integrationInstancesCapability = {
56562
56559
  createInstance: method(object({
56563
56560
  id: IntegrationInstanceIdSchema.optional(),
56564
56561
  name: string().min(1),
56565
- kind: string().min(1).optional()
56562
+ kind: string().min(1).optional(),
56563
+ /** Form values written with the record (a link picked in the create dialog). */
56564
+ values: record(string(), unknown()).optional()
56566
56565
  }), object({ id: string() }), {
56567
56566
  kind: "mutation",
56568
56567
  auth: "admin"
@@ -56589,8 +56588,10 @@ var integrationInstancesCapability = {
56589
56588
  }),
56590
56589
  testInstance: optionalMethod(object({
56591
56590
  id: IntegrationInstanceIdSchema.nullable(),
56592
- values: record(string(), unknown())
56593
- }), TestConnectionResultSchema$1, {
56591
+ values: record(string(), unknown()),
56592
+ /** The kind to test when `id` is null and the provider has several. */
56593
+ kind: string().min(1).optional()
56594
+ }), TestConnectionResultSchema, {
56594
56595
  kind: "mutation",
56595
56596
  auth: "admin"
56596
56597
  })
@@ -59347,6 +59348,380 @@ var SystemMetricsSchema = object({
59347
59348
  gpuMemoryPercent: number().optional()
59348
59349
  });
59349
59350
  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);
59351
+ /**
59352
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59353
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59354
+ * (operator intent, D870) and device-history (numbers over time, D850).
59355
+ *
59356
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59357
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59358
+ * that with the addon id closed over). It is deliberately NOT in any input
59359
+ * schema, so a session can never supply it, and a call with no stamp is refused
59360
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59361
+ * addons go through the owner's capability.
59362
+ *
59363
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59364
+ * never `[]`. Secret fields are never on the wire: a read shows the
59365
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59366
+ * resolves itself, and a write may carry only a keychain marker bound to the
59367
+ * row's own ref.
59368
+ *
59369
+ * Internal: addons reach it through `ctx.records`, never directly.
59370
+ */
59371
+ var RecordIdSchema = string().min(1).max(256);
59372
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59373
+ var RecordBodySchema = record(string(), unknown());
59374
+ var RecordInputSchema = object({
59375
+ id: RecordIdSchema,
59376
+ /** The device this row belongs to (D865 removal, per-device reads). */
59377
+ deviceId: number().int().optional(),
59378
+ /** The domain clock, ms: observed / created / opened. */
59379
+ at: number().int().optional(),
59380
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59381
+ expiresAt: number().int().optional(),
59382
+ data: RecordBodySchema
59383
+ });
59384
+ var RecordViewSchema = object({
59385
+ id: string(),
59386
+ deviceId: number().int().nullable(),
59387
+ at: number().nullable(),
59388
+ expiresAt: number().nullable(),
59389
+ rev: number().int(),
59390
+ updatedAt: number(),
59391
+ data: RecordBodySchema
59392
+ });
59393
+ /** Declared index fields only. Anything else does not compile, by design. */
59394
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59395
+ string(),
59396
+ number(),
59397
+ boolean(),
59398
+ object({ in: array(union([
59399
+ string(),
59400
+ number(),
59401
+ boolean()
59402
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59403
+ object({
59404
+ gt: union([string(), number()]).optional(),
59405
+ gte: union([string(), number()]).optional(),
59406
+ lt: union([string(), number()]).optional(),
59407
+ lte: union([string(), number()]).optional()
59408
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59409
+ ]));
59410
+ var KindShape = { kind: RecordKindNameSchema };
59411
+ var TimeWindowShape = {
59412
+ deviceId: number().int().optional(),
59413
+ atFrom: number().optional(),
59414
+ atTo: number().optional()
59415
+ };
59416
+ var RecordQueryInputSchema = object({
59417
+ ...KindShape,
59418
+ ...TimeWindowShape,
59419
+ where: RecordWhereSchema.optional(),
59420
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59421
+ order: _enum(["at", "id"]).optional(),
59422
+ desc: boolean().optional(),
59423
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59424
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59425
+ cursor: string().min(1).optional()
59426
+ });
59427
+ var RecordQueryResultSchema = object({
59428
+ records: array(RecordViewSchema),
59429
+ nextCursor: string().nullable()
59430
+ });
59431
+ var RecordKindStateSchema = _enum([
59432
+ "created",
59433
+ "unchanged",
59434
+ "updated"
59435
+ ]);
59436
+ var DeclareKindResultSchema = object({
59437
+ kindId: number().int(),
59438
+ state: RecordKindStateSchema,
59439
+ createdIndexes: array(string())
59440
+ });
59441
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59442
+ var SecretRefsList = array(string());
59443
+ /**
59444
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59445
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59446
+ */
59447
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59448
+ object({
59449
+ op: literal("put"),
59450
+ kind: RecordKindNameSchema,
59451
+ record: RecordInputSchema,
59452
+ ifRev: number().int().min(0).optional()
59453
+ }),
59454
+ object({
59455
+ op: literal("patch"),
59456
+ kind: RecordKindNameSchema,
59457
+ id: RecordIdSchema,
59458
+ data: RecordBodySchema,
59459
+ at: number().int().nullable().optional(),
59460
+ expiresAt: number().int().nullable().optional(),
59461
+ ifRev: number().int().min(1).optional()
59462
+ }),
59463
+ object({
59464
+ op: literal("delete"),
59465
+ kind: RecordKindNameSchema,
59466
+ id: RecordIdSchema
59467
+ })
59468
+ ]);
59469
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59470
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59471
+ kind: "mutation",
59472
+ auth: "admin"
59473
+ }), method(object({
59474
+ ...KindShape,
59475
+ id: RecordIdSchema
59476
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59477
+ ...KindShape,
59478
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59479
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59480
+ ...KindShape,
59481
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59482
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59483
+ ...KindShape,
59484
+ record: RecordInputSchema,
59485
+ /** Compare-and-set. `0` means "the row must not exist". */
59486
+ ifRev: number().int().min(0).optional()
59487
+ }), object({
59488
+ rev: number().int(),
59489
+ releasedRefs: SecretRefsList
59490
+ }), {
59491
+ kind: "mutation",
59492
+ auth: "admin"
59493
+ }), method(object({
59494
+ ...KindShape,
59495
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59496
+ }), object({
59497
+ count: number().int(),
59498
+ releasedRefs: SecretRefsList
59499
+ }), {
59500
+ kind: "mutation",
59501
+ auth: "admin"
59502
+ }), method(object({
59503
+ ...KindShape,
59504
+ id: RecordIdSchema,
59505
+ data: RecordBodySchema,
59506
+ at: number().int().nullable().optional(),
59507
+ expiresAt: number().int().nullable().optional(),
59508
+ ifRev: number().int().min(1).optional()
59509
+ }), object({
59510
+ rev: number().int(),
59511
+ releasedRefs: SecretRefsList
59512
+ }), {
59513
+ kind: "mutation",
59514
+ auth: "admin"
59515
+ }), method(object({
59516
+ ...KindShape,
59517
+ id: RecordIdSchema
59518
+ }), object({
59519
+ deleted: boolean(),
59520
+ secretRefs: SecretRefsList
59521
+ }), {
59522
+ kind: "mutation",
59523
+ auth: "admin"
59524
+ }), method(object({
59525
+ ...KindShape,
59526
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59527
+ }), object({
59528
+ deleted: number().int(),
59529
+ secretRefs: SecretRefsList
59530
+ }), {
59531
+ kind: "mutation",
59532
+ auth: "admin"
59533
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59534
+ ...KindShape,
59535
+ ...TimeWindowShape,
59536
+ where: RecordWhereSchema.optional()
59537
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59538
+ ...KindShape,
59539
+ deviceId: number().int().optional(),
59540
+ from: number(),
59541
+ to: number(),
59542
+ bucketMs: number().int().positive()
59543
+ }), object({ buckets: array(object({
59544
+ bucketStart: number(),
59545
+ count: number().int()
59546
+ })) }), { auth: "admin" }), method(object({
59547
+ ...KindShape,
59548
+ op: _enum([
59549
+ "sum",
59550
+ "min",
59551
+ "max",
59552
+ "count"
59553
+ ]),
59554
+ field: RecordFieldPathSchema.optional(),
59555
+ groupBy: RecordFieldPathSchema.optional(),
59556
+ where: RecordWhereSchema.optional()
59557
+ }), object({ rows: array(object({
59558
+ group: union([
59559
+ string(),
59560
+ number(),
59561
+ _null()
59562
+ ]),
59563
+ value: number().nullable()
59564
+ })) }), { auth: "admin" }), method(object({
59565
+ ...KindShape,
59566
+ deviceId: number().int().optional(),
59567
+ atBefore: number().optional(),
59568
+ where: RecordWhereSchema.optional()
59569
+ }), object({
59570
+ deleted: number().int(),
59571
+ secretRefs: SecretRefsList
59572
+ }), {
59573
+ kind: "mutation",
59574
+ auth: "admin"
59575
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59576
+ results: array(object({
59577
+ rev: number().int().nullable(),
59578
+ deleted: boolean()
59579
+ })),
59580
+ releasedRefs: SecretRefsList,
59581
+ secretRefs: SecretRefsList
59582
+ }), {
59583
+ kind: "mutation",
59584
+ auth: "admin"
59585
+ }), method(object({
59586
+ deviceId: number().int(),
59587
+ kinds: array(RecordKindNameSchema).optional()
59588
+ }), object({
59589
+ deleted: record(string(), number().int()),
59590
+ secretRefs: SecretRefsList
59591
+ }), {
59592
+ kind: "mutation",
59593
+ auth: "admin"
59594
+ }), method(object(KindShape), object({ id: number().int() }), {
59595
+ kind: "mutation",
59596
+ auth: "admin"
59597
+ });
59598
+ /**
59599
+ * The wire shapes of the migration API, version 1 (planning#447).
59600
+ *
59601
+ * A migration is code that outlives the server it was written against: an addon at
59602
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59603
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59604
+ * is the contract of every method of it, one Zod pair per method.
59605
+ *
59606
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59607
+ * field is never removed or made required, an enum never narrows, an output field is
59608
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59609
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59610
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59611
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59612
+ */
59613
+ var Rows = record(string(), unknown());
59614
+ var IntegrationId = object({ integrationId: string().min(1) });
59615
+ var RecordId = object({ id: string().min(1) });
59616
+ var RecordRowSchema = object({
59617
+ id: string(),
59618
+ deviceId: number().int().nullable(),
59619
+ at: number().nullable(),
59620
+ expiresAt: number().nullable(),
59621
+ rev: number().int(),
59622
+ updatedAt: number(),
59623
+ data: Rows
59624
+ });
59625
+ var RecordPutShape = {
59626
+ id: string().min(1),
59627
+ deviceId: number().int().optional(),
59628
+ at: number().int().optional(),
59629
+ expiresAt: number().int().optional(),
59630
+ data: Rows
59631
+ };
59632
+ var MigrationIntegrationSchema = object({
59633
+ id: string(),
59634
+ addonId: string(),
59635
+ name: string(),
59636
+ info: Rows,
59637
+ originStableId: string().optional()
59638
+ });
59639
+ var MigrationDeviceSchema = object({
59640
+ id: number().int(),
59641
+ integrationId: string().nullable().optional(),
59642
+ /** The owning device; null or absent for a root. */
59643
+ parentDeviceId: number().int().nullable().optional(),
59644
+ type: string().optional(),
59645
+ name: string().optional(),
59646
+ stableId: string().optional()
59647
+ });
59648
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59649
+ var MigrationApiInfoSchema = object({
59650
+ version: number().int(),
59651
+ methods: array(string())
59652
+ });
59653
+ object({
59654
+ message: string(),
59655
+ meta: Rows.optional(),
59656
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59657
+ tags: object({ deviceId: number().int().optional() }).optional()
59658
+ });
59659
+ object({
59660
+ owner: string().min(1),
59661
+ metas: array(MigrationMetaSchema)
59662
+ }), object({
59663
+ bootId: string(),
59664
+ snapshot: _enum([
59665
+ "none",
59666
+ "written",
59667
+ "refused"
59668
+ ]),
59669
+ steps: array(MigrationOwnerStepSchema),
59670
+ /** The migration API the engine serves; absent from a server that predates it. */
59671
+ migrationApi: MigrationApiInfoSchema.optional()
59672
+ }), object({ id: string().min(1) }), object({
59673
+ proceed: boolean(),
59674
+ state: union([literal("pending"), MigrationStatusSchema]),
59675
+ reason: string().nullable()
59676
+ }), object({
59677
+ id: string().min(1),
59678
+ result: MigrationOwnerResultSchema
59679
+ }), object({
59680
+ status: MigrationStatusSchema,
59681
+ error: string().nullable(),
59682
+ rowsChanged: number().int().nonnegative()
59683
+ }), object({
59684
+ rows: number().int().nonnegative(),
59685
+ secrets: number().int().nonnegative()
59686
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59687
+ present: boolean(),
59688
+ removed: Rows
59689
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
59690
+ ...RecordPutShape,
59691
+ ifRev: number().int().optional()
59692
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
59693
+ partial: Rows,
59694
+ ifRev: number().int().optional()
59695
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
59696
+ deviceId: number().int().optional(),
59697
+ atFrom: number().optional(),
59698
+ atTo: number().optional(),
59699
+ where: RecordWhereSchema.optional(),
59700
+ limit: number().int().min(1).optional(),
59701
+ cursor: string().min(1).optional(),
59702
+ resolveSecrets: boolean().optional()
59703
+ }), object({
59704
+ records: array(RecordRowSchema),
59705
+ nextCursor: string().nullable()
59706
+ }), object({
59707
+ deviceId: number().int().optional(),
59708
+ atBefore: number().optional(),
59709
+ where: RecordWhereSchema.optional()
59710
+ }), 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({
59711
+ ref: string().min(1),
59712
+ value: string()
59713
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
59714
+ addonId: string().min(1),
59715
+ integrationId: string().min(1).optional()
59716
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
59717
+ id: number().int(),
59718
+ integrationId: string().nullable(),
59719
+ /** Whether the device carries any stored config; its content is not offered. */
59720
+ hasConfig: boolean()
59721
+ }).nullable(), object({
59722
+ deviceId: number().int(),
59723
+ integrationId: string().min(1)
59724
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59350
59725
  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({
59351
59726
  id: string().min(1),
59352
59727
  error: string().min(1)
@@ -59376,7 +59751,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59376
59751
  "written",
59377
59752
  "refused"
59378
59753
  ]),
59379
- steps: array(MigrationOwnerStepSchema)
59754
+ steps: array(MigrationOwnerStepSchema),
59755
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
59756
+ migrationApi: MigrationApiInfoSchema.optional()
59380
59757
  }), {
59381
59758
  kind: "mutation",
59382
59759
  auth: "admin"
@@ -59397,6 +59774,27 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59397
59774
  }), {
59398
59775
  kind: "mutation",
59399
59776
  auth: "admin"
59777
+ }), method(object({ integrationId: string().min(1) }), record(string(), unknown()), { auth: "admin" }), method(object({ integrationId: string().min(1) }), object({
59778
+ rows: number().int().nonnegative(),
59779
+ secrets: number().int().nonnegative()
59780
+ }), {
59781
+ kind: "mutation",
59782
+ auth: "admin"
59783
+ }), method(object({
59784
+ integrationId: string().min(1),
59785
+ patch: record(string(), unknown())
59786
+ }), object({ written: boolean() }), {
59787
+ kind: "mutation",
59788
+ auth: "admin"
59789
+ }), method(object({
59790
+ integrationId: string().min(1),
59791
+ keys: array(string().min(1))
59792
+ }), object({
59793
+ present: boolean(),
59794
+ removed: record(string(), unknown())
59795
+ }), {
59796
+ kind: "mutation",
59797
+ auth: "admin"
59400
59798
  });
59401
59799
  method(object({
59402
59800
  sourceUrl: string(),
@@ -62022,7 +62420,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
62022
62420
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
62023
62421
  kind: "mutation",
62024
62422
  auth: "admin"
62025
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62423
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62424
+ kind: "query",
62425
+ auth: "admin"
62426
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62026
62427
  kind: "query",
62027
62428
  auth: "admin"
62028
62429
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64677,7 +65078,7 @@ var BrokerStatusSchema$1 = _enum([
64677
65078
  "unreachable",
64678
65079
  "tls-error"
64679
65080
  ]);
64680
- var BrokerInfoSchema$1 = object({
65081
+ var BrokerInfoSchema = object({
64681
65082
  id: string(),
64682
65083
  name: string(),
64683
65084
  url: string(),
@@ -64740,7 +65141,7 @@ var StatusSchema = object({
64740
65141
  brokerCount: number(),
64741
65142
  embeddedRunning: boolean()
64742
65143
  });
64743
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65144
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64744
65145
  kind: "mutation",
64745
65146
  auth: "admin"
64746
65147
  }), method(IdInputSchema, _void(), {
@@ -72080,253 +72481,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, DeviceType.Gateway, met
72080
72481
  auth: "admin"
72081
72482
  });
72082
72483
  /**
72083
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
72084
- * config documents, mirrors. The third storage API next to `ctx.settings`
72085
- * (operator intent, D870) and device-history (numbers over time, D850).
72086
- *
72087
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
72088
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
72089
- * that with the addon id closed over). It is deliberately NOT in any input
72090
- * schema, so a session can never supply it, and a call with no stamp is refused
72091
- * `records/no-caller`. A kind is readable and writable only by its owner; other
72092
- * addons go through the owner's capability.
72093
- *
72094
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
72095
- * never `[]`. Secret fields are never on the wire: a read shows the
72096
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
72097
- * resolves itself, and a write may carry only a keychain marker bound to the
72098
- * row's own ref.
72099
- *
72100
- * Internal: addons reach it through `ctx.records`, never directly.
72101
- */
72102
- var RecordIdSchema = string().min(1).max(256);
72103
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
72104
- var RecordBodySchema = record(string(), unknown());
72105
- var RecordInputSchema = object({
72106
- id: RecordIdSchema,
72107
- /** The device this row belongs to (D865 removal, per-device reads). */
72108
- deviceId: number().int().optional(),
72109
- /** The domain clock, ms: observed / created / opened. */
72110
- at: number().int().optional(),
72111
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
72112
- expiresAt: number().int().optional(),
72113
- data: RecordBodySchema
72114
- });
72115
- var RecordViewSchema = object({
72116
- id: string(),
72117
- deviceId: number().int().nullable(),
72118
- at: number().nullable(),
72119
- expiresAt: number().nullable(),
72120
- rev: number().int(),
72121
- updatedAt: number(),
72122
- data: RecordBodySchema
72123
- });
72124
- /** Declared index fields only. Anything else does not compile, by design. */
72125
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
72126
- string(),
72127
- number(),
72128
- boolean(),
72129
- object({ in: array(union([
72130
- string(),
72131
- number(),
72132
- boolean()
72133
- ])).min(1).max(RECORD_BATCH_MAX) }),
72134
- object({
72135
- gt: union([string(), number()]).optional(),
72136
- gte: union([string(), number()]).optional(),
72137
- lt: union([string(), number()]).optional(),
72138
- lte: union([string(), number()]).optional()
72139
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
72140
- ]));
72141
- var KindShape = { kind: RecordKindNameSchema };
72142
- var TimeWindowShape = {
72143
- deviceId: number().int().optional(),
72144
- atFrom: number().optional(),
72145
- atTo: number().optional()
72146
- };
72147
- var RecordQueryInputSchema = object({
72148
- ...KindShape,
72149
- ...TimeWindowShape,
72150
- where: RecordWhereSchema.optional(),
72151
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
72152
- order: _enum(["at", "id"]).optional(),
72153
- desc: boolean().optional(),
72154
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
72155
- /** Opaque keyset cursor from a previous answer. There is no offset. */
72156
- cursor: string().min(1).optional()
72157
- });
72158
- var RecordQueryResultSchema = object({
72159
- records: array(RecordViewSchema),
72160
- nextCursor: string().nullable()
72161
- });
72162
- var RecordKindStateSchema = _enum([
72163
- "created",
72164
- "unchanged",
72165
- "updated"
72166
- ]);
72167
- var DeclareKindResultSchema = object({
72168
- kindId: number().int(),
72169
- state: RecordKindStateSchema,
72170
- createdIndexes: array(string())
72171
- });
72172
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
72173
- var SecretRefsList = array(string());
72174
- /**
72175
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
72176
- * All ops of one call share ONE database file and ONE `transactFamily`.
72177
- */
72178
- var RecordTransactOpSchema = discriminatedUnion("op", [
72179
- object({
72180
- op: literal("put"),
72181
- kind: RecordKindNameSchema,
72182
- record: RecordInputSchema,
72183
- ifRev: number().int().min(0).optional()
72184
- }),
72185
- object({
72186
- op: literal("patch"),
72187
- kind: RecordKindNameSchema,
72188
- id: RecordIdSchema,
72189
- data: RecordBodySchema,
72190
- at: number().int().nullable().optional(),
72191
- expiresAt: number().int().nullable().optional(),
72192
- ifRev: number().int().min(1).optional()
72193
- }),
72194
- object({
72195
- op: literal("delete"),
72196
- kind: RecordKindNameSchema,
72197
- id: RecordIdSchema
72198
- })
72199
- ]);
72200
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
72201
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
72202
- kind: "mutation",
72203
- auth: "admin"
72204
- }), method(object({
72205
- ...KindShape,
72206
- id: RecordIdSchema
72207
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
72208
- ...KindShape,
72209
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72210
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
72211
- ...KindShape,
72212
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72213
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
72214
- ...KindShape,
72215
- record: RecordInputSchema,
72216
- /** Compare-and-set. `0` means "the row must not exist". */
72217
- ifRev: number().int().min(0).optional()
72218
- }), object({
72219
- rev: number().int(),
72220
- releasedRefs: SecretRefsList
72221
- }), {
72222
- kind: "mutation",
72223
- auth: "admin"
72224
- }), method(object({
72225
- ...KindShape,
72226
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72227
- }), object({
72228
- count: number().int(),
72229
- releasedRefs: SecretRefsList
72230
- }), {
72231
- kind: "mutation",
72232
- auth: "admin"
72233
- }), method(object({
72234
- ...KindShape,
72235
- id: RecordIdSchema,
72236
- data: RecordBodySchema,
72237
- at: number().int().nullable().optional(),
72238
- expiresAt: number().int().nullable().optional(),
72239
- ifRev: number().int().min(1).optional()
72240
- }), object({
72241
- rev: number().int(),
72242
- releasedRefs: SecretRefsList
72243
- }), {
72244
- kind: "mutation",
72245
- auth: "admin"
72246
- }), method(object({
72247
- ...KindShape,
72248
- id: RecordIdSchema
72249
- }), object({
72250
- deleted: boolean(),
72251
- secretRefs: SecretRefsList
72252
- }), {
72253
- kind: "mutation",
72254
- auth: "admin"
72255
- }), method(object({
72256
- ...KindShape,
72257
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72258
- }), object({
72259
- deleted: number().int(),
72260
- secretRefs: SecretRefsList
72261
- }), {
72262
- kind: "mutation",
72263
- auth: "admin"
72264
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72265
- ...KindShape,
72266
- ...TimeWindowShape,
72267
- where: RecordWhereSchema.optional()
72268
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72269
- ...KindShape,
72270
- deviceId: number().int().optional(),
72271
- from: number(),
72272
- to: number(),
72273
- bucketMs: number().int().positive()
72274
- }), object({ buckets: array(object({
72275
- bucketStart: number(),
72276
- count: number().int()
72277
- })) }), { auth: "admin" }), method(object({
72278
- ...KindShape,
72279
- op: _enum([
72280
- "sum",
72281
- "min",
72282
- "max",
72283
- "count"
72284
- ]),
72285
- field: RecordFieldPathSchema.optional(),
72286
- groupBy: RecordFieldPathSchema.optional(),
72287
- where: RecordWhereSchema.optional()
72288
- }), object({ rows: array(object({
72289
- group: union([
72290
- string(),
72291
- number(),
72292
- _null()
72293
- ]),
72294
- value: number().nullable()
72295
- })) }), { auth: "admin" }), method(object({
72296
- ...KindShape,
72297
- deviceId: number().int().optional(),
72298
- atBefore: number().optional(),
72299
- where: RecordWhereSchema.optional()
72300
- }), object({
72301
- deleted: number().int(),
72302
- secretRefs: SecretRefsList
72303
- }), {
72304
- kind: "mutation",
72305
- auth: "admin"
72306
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72307
- results: array(object({
72308
- rev: number().int().nullable(),
72309
- deleted: boolean()
72310
- })),
72311
- releasedRefs: SecretRefsList,
72312
- secretRefs: SecretRefsList
72313
- }), {
72314
- kind: "mutation",
72315
- auth: "admin"
72316
- }), method(object({
72317
- deviceId: number().int(),
72318
- kinds: array(RecordKindNameSchema).optional()
72319
- }), object({
72320
- deleted: record(string(), number().int()),
72321
- secretRefs: SecretRefsList
72322
- }), {
72323
- kind: "mutation",
72324
- auth: "admin"
72325
- }), method(object(KindShape), object({ id: number().int() }), {
72326
- kind: "mutation",
72327
- auth: "admin"
72328
- });
72329
- /**
72330
72484
  * record-entries - the ONE admin surface for every list of user-created entries
72331
72485
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72332
72486
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -81790,11 +81944,15 @@ discriminatedUnion("kind", [object({
81790
81944
  * 1. idle floor F = time-weighted median; noise ceiling N = highest value seen
81791
81945
  * near F. A device that is not near one level most of the time has no floor.
81792
81946
  * 2. coarse activity = above max(2N, N + 5 W); consecutive stretches are episodes.
81793
- * 3. gaps between episodes split in two by the largest log-scale jump (>= 3x):
81794
- * the short ones are pauses INSIDE a run (a soak), the long ones separate runs.
81947
+ * 3. an episode shorter than `PULSE_MAX_MS` is a PULSE (an anti-crease tumble, a
81948
+ * display waking): it is neither a run nor a pause. Among the remaining
81949
+ * episodes, gaps over `PAUSE_MAX_MS` always separate runs; the rest split in
81950
+ * two by the largest log-scale jump (>= 3x): the short ones are pauses INSIDE
81951
+ * a run (a soak), the long ones separate runs. A stretch under `MIN_RUN_MS`
81952
+ * is no run.
81795
81953
  * 4. T = geometric mean of N and the plateau's 10th percentile, snapped to a
81796
- * grid a person would type; stop dwell covers the longest pause; start dwell
81797
- * covers the longest standby blip above T.
81954
+ * grid a person would type; stop dwell covers the longest pause and the
81955
+ * kind's floor; start dwell covers the longest pulse and standby blip above T.
81798
81956
  * 5. the numbers are proved by REPLAY through the real `dwell` evaluation: each
81799
81957
  * run must hold exactly one true interval and nothing may flap outside.
81800
81958
  */
@@ -81805,6 +81963,10 @@ var MINUTE_MS$1 = 60 * SECOND_MS;
81805
81963
  30 * SECOND_MS;
81806
81964
  60 * SECOND_MS;
81807
81965
  20 * MINUTE_MS$1;
81966
+ 90 * SECOND_MS;
81967
+ 30 * MINUTE_MS$1;
81968
+ 10 * MINUTE_MS$1;
81969
+ DeviceType.Dryer, 3 * MINUTE_MS$1, DeviceType.Dishwasher, 3 * MINUTE_MS$1, DeviceType.Washer, 10 * MINUTE_MS$1;
81808
81970
  10 * SECOND_MS;
81809
81971
  10 * SECOND_MS;
81810
81972
  /**
@@ -83088,7 +83250,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83088
83250
  * `deviceClasses` map (first registered type). `null` when manual creation is
83089
83251
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
83090
83252
  */
83091
- async getManualCreationType() {
83253
+ async getManualCreationType(_input) {
83092
83254
  if (!await this.supportsManualCreation()) return { deviceType: null };
83093
83255
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
83094
83256
  }
@@ -83099,7 +83261,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83099
83261
  return true;
83100
83262
  }
83101
83263
  async getChildCreationSchema(input) {
83102
- return this.onGetCreationSchema(input.type);
83264
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
83103
83265
  }
83104
83266
  /**
83105
83267
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -83111,7 +83273,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83111
83273
  * `deviceClasses` instead.
83112
83274
  */
83113
83275
  async createDevice(input) {
83114
- const spec = await this.onCreateDevice(input.type, input.config);
83276
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
83115
83277
  const Class = this.deviceClasses[spec.meta.type];
83116
83278
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
83117
83279
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -84524,20 +84686,6 @@ Object.freeze({
84524
84686
  access: "create",
84525
84687
  role: "viewer"
84526
84688
  },
84527
- "broker.add": {
84528
- capName: "broker",
84529
- capScope: "system",
84530
- addonId: null,
84531
- access: "create",
84532
- role: "admin"
84533
- },
84534
- "broker.get": {
84535
- capName: "broker",
84536
- capScope: "system",
84537
- addonId: null,
84538
- access: "view",
84539
- role: "admin"
84540
- },
84541
84689
  "broker.getBrokerConfig": {
84542
84690
  capName: "broker",
84543
84691
  capScope: "system",
@@ -84545,20 +84693,6 @@ Object.freeze({
84545
84693
  access: "view",
84546
84694
  role: "admin"
84547
84695
  },
84548
- "broker.getSettings": {
84549
- capName: "broker",
84550
- capScope: "system",
84551
- addonId: null,
84552
- access: "view",
84553
- role: "admin"
84554
- },
84555
- "broker.getSettingsSchema": {
84556
- capName: "broker",
84557
- capScope: "system",
84558
- addonId: null,
84559
- access: "view",
84560
- role: "admin"
84561
- },
84562
84696
  "broker.getState": {
84563
84697
  capName: "broker",
84564
84698
  capScope: "system",
@@ -84573,20 +84707,6 @@ Object.freeze({
84573
84707
  access: "view",
84574
84708
  role: "admin"
84575
84709
  },
84576
- "broker.list": {
84577
- capName: "broker",
84578
- capScope: "system",
84579
- addonId: null,
84580
- access: "view",
84581
- role: "admin"
84582
- },
84583
- "broker.listProviders": {
84584
- capName: "broker",
84585
- capScope: "system",
84586
- addonId: null,
84587
- access: "view",
84588
- role: "admin"
84589
- },
84590
84710
  "broker.publish": {
84591
84711
  capName: "broker",
84592
84712
  capScope: "system",
@@ -84594,20 +84714,6 @@ Object.freeze({
84594
84714
  access: "create",
84595
84715
  role: "admin"
84596
84716
  },
84597
- "broker.remove": {
84598
- capName: "broker",
84599
- capScope: "system",
84600
- addonId: null,
84601
- access: "delete",
84602
- role: "admin"
84603
- },
84604
- "broker.setSettings": {
84605
- capName: "broker",
84606
- capScope: "system",
84607
- addonId: null,
84608
- access: "create",
84609
- role: "admin"
84610
- },
84611
84717
  "broker.subscribe": {
84612
84718
  capName: "broker",
84613
84719
  capScope: "system",
@@ -84615,20 +84721,6 @@ Object.freeze({
84615
84721
  access: "create",
84616
84722
  role: "admin"
84617
84723
  },
84618
- "broker.testConnection": {
84619
- capName: "broker",
84620
- capScope: "system",
84621
- addonId: null,
84622
- access: "create",
84623
- role: "admin"
84624
- },
84625
- "broker.testSettings": {
84626
- capName: "broker",
84627
- capScope: "system",
84628
- addonId: null,
84629
- access: "create",
84630
- role: "admin"
84631
- },
84632
84724
  "broker.unsubscribe": {
84633
84725
  capName: "broker",
84634
84726
  capScope: "system",
@@ -87226,13 +87318,6 @@ Object.freeze({
87226
87318
  access: "create",
87227
87319
  role: "admin"
87228
87320
  },
87229
- "integrations.clearSettings": {
87230
- capName: "integrations",
87231
- capScope: "system",
87232
- addonId: null,
87233
- access: "delete",
87234
- role: "admin"
87235
- },
87236
87321
  "integrations.create": {
87237
87322
  capName: "integrations",
87238
87323
  capScope: "system",
@@ -87268,13 +87353,6 @@ Object.freeze({
87268
87353
  access: "view",
87269
87354
  role: "admin"
87270
87355
  },
87271
- "integrations.getSettings": {
87272
- capName: "integrations",
87273
- capScope: "system",
87274
- addonId: null,
87275
- access: "view",
87276
- role: "admin"
87277
- },
87278
87356
  "integrations.list": {
87279
87357
  capName: "integrations",
87280
87358
  capScope: "system",
@@ -87282,13 +87360,6 @@ Object.freeze({
87282
87360
  access: "view",
87283
87361
  role: "admin"
87284
87362
  },
87285
- "integrations.setSettings": {
87286
- capName: "integrations",
87287
- capScope: "system",
87288
- addonId: null,
87289
- access: "create",
87290
- role: "admin"
87291
- },
87292
87363
  "integrations.testConnection": {
87293
87364
  capName: "integrations",
87294
87365
  capScope: "system",
@@ -88283,6 +88354,13 @@ Object.freeze({
88283
88354
  access: "view",
88284
88355
  role: "admin"
88285
88356
  },
88357
+ "migrations.clearLegacyIntegrationRows": {
88358
+ capName: "migrations",
88359
+ capScope: "system",
88360
+ addonId: null,
88361
+ access: "delete",
88362
+ role: "admin"
88363
+ },
88286
88364
  "migrations.declareOwner": {
88287
88365
  capName: "migrations",
88288
88366
  capScope: "system",
@@ -88290,6 +88368,13 @@ Object.freeze({
88290
88368
  access: "create",
88291
88369
  role: "admin"
88292
88370
  },
88371
+ "migrations.deleteLegacyIntegrationRowKeys": {
88372
+ capName: "migrations",
88373
+ capScope: "system",
88374
+ addonId: null,
88375
+ access: "delete",
88376
+ role: "admin"
88377
+ },
88293
88378
  "migrations.dryRun": {
88294
88379
  capName: "migrations",
88295
88380
  capScope: "system",
@@ -88325,6 +88410,20 @@ Object.freeze({
88325
88410
  access: "create",
88326
88411
  role: "admin"
88327
88412
  },
88413
+ "migrations.patchLegacyIntegrationRows": {
88414
+ capName: "migrations",
88415
+ capScope: "system",
88416
+ addonId: null,
88417
+ access: "create",
88418
+ role: "admin"
88419
+ },
88420
+ "migrations.readLegacyIntegrationRows": {
88421
+ capName: "migrations",
88422
+ capScope: "system",
88423
+ addonId: null,
88424
+ access: "view",
88425
+ role: "admin"
88426
+ },
88328
88427
  "migrations.restorePreMigration": {
88329
88428
  capName: "migrations",
88330
88429
  capScope: "system",
@@ -89585,6 +89684,13 @@ Object.freeze({
89585
89684
  access: "view",
89586
89685
  role: "viewer"
89587
89686
  },
89687
+ "pipelineAnalytics.getMediaLocationCensus": {
89688
+ capName: "pipeline-analytics",
89689
+ capScope: "device",
89690
+ addonId: null,
89691
+ access: "view",
89692
+ role: "admin"
89693
+ },
89588
89694
  "pipelineAnalytics.getMediaReclaimStatus": {
89589
89695
  capName: "pipeline-analytics",
89590
89696
  capScope: "device",
@@ -98783,6 +98889,100 @@ object({
98783
98889
  delay: number().nonnegative().optional(),
98784
98890
  commands: record(string(), unknown())
98785
98891
  });
98892
+ entryBody({ brokerId: string() });
98893
+ function secretsOverMigrationApi(api) {
98894
+ return {
98895
+ resolve: async (refs) => {
98896
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
98897
+ const out = {};
98898
+ for (const ref of refs) {
98899
+ const value = values[ref];
98900
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
98901
+ kind: "value",
98902
+ value,
98903
+ version: 0
98904
+ };
98905
+ }
98906
+ return out;
98907
+ },
98908
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
98909
+ };
98910
+ }
98911
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
98912
+ function recordsOverMigrationApi(api) {
98913
+ return { kind: (definition) => {
98914
+ const handle = api.records.kind(definition);
98915
+ return {
98916
+ get: (id) => handle.get({ id }),
98917
+ getResolved: (id) => handle.getResolved({ id }),
98918
+ put: (input, opts) => handle.put({
98919
+ ...input,
98920
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
98921
+ }),
98922
+ delete: (id) => handle.delete({ id })
98923
+ };
98924
+ } };
98925
+ }
98926
+ function integrationRowsApiOver(api) {
98927
+ return {
98928
+ list: async () => (await api.integrations.list({})).integrations,
98929
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
98930
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
98931
+ };
98932
+ }
98933
+ /**
98934
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
98935
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
98936
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
98937
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
98938
+ */
98939
+ var lanes = /* @__PURE__ */ new WeakMap();
98940
+ function deliver(api, send) {
98941
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
98942
+ const reason = error instanceof Error ? error.message : String(error);
98943
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
98944
+ });
98945
+ lanes.set(api, next);
98946
+ return next;
98947
+ }
98948
+ function warnOver(api) {
98949
+ return (message) => deliver(api, () => api.log.warn({ message }));
98950
+ }
98951
+ /** What the rows-to-records move needs, over the migration API. */
98952
+ function rowsDepsOver(api) {
98953
+ return {
98954
+ api: integrationRowsApiOver(api),
98955
+ records: recordsOverMigrationApi(api),
98956
+ secrets: secretsOverMigrationApi(api),
98957
+ warn: warnOver(api)
98958
+ };
98959
+ }
98960
+ function defaultIntegrationApiOver$1(api) {
98961
+ return {
98962
+ ...integrationRowsApiOver(api),
98963
+ listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
98964
+ readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
98965
+ setDeviceIntegrationId: async (deviceId, integrationId) => {
98966
+ await api.devices.setIntegrationId({
98967
+ deviceId,
98968
+ integrationId
98969
+ });
98970
+ },
98971
+ readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
98972
+ };
98973
+ }
98974
+ /** What the rows-to-records move and the device claim need, over the migration API. */
98975
+ function defaultIntegrationDepsOver(api) {
98976
+ return {
98977
+ ...rowsDepsOver(api),
98978
+ api: defaultIntegrationApiOver$1(api),
98979
+ info: (message) => deliver(api, () => api.log.info({ message })),
98980
+ warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
98981
+ message,
98982
+ tags: { deviceId }
98983
+ }))
98984
+ };
98985
+ }
98786
98986
  //#endregion
98787
98987
  //#region src/amcrest-instances.ts
98788
98988
  /**
@@ -106856,18 +107056,13 @@ var AmcrestProviderAddon = class extends BaseDeviceProvider {
106856
107056
  const records = this.ctx.records;
106857
107057
  if (records === void 0) throw new Error("provider-amcrest: ctx.records is required (hub-only addon)");
106858
107058
  await records.declare(amcrestRecordKinds);
106859
- const defaultIntegration = defineAddonMigrations(defaultIntegrationMigrations({
107059
+ await this.runMigrations(defaultIntegrationMigrations({
106860
107060
  addonId: this.addonId,
106861
107061
  date: "2026-11-04"
106862
- }), defaultIntegrationPortsOver({
106863
- api: defaultIntegrationApiOver(this.ctx.api),
106864
- records,
106865
- kind: amcrestConnectionsEntryKind,
106866
- info: (message) => this.ctx.logger.info(message),
106867
- warn: (message) => this.ctx.logger.warn(message),
106868
- warnDevice: (message, deviceId) => this.ctx.logger.warn(message, { tags: { deviceId } })
107062
+ }), (api) => defaultIntegrationPortsOver({
107063
+ ...defaultIntegrationDepsOver(api),
107064
+ kind: amcrestConnectionsEntryKind
106869
107065
  }));
106870
- await this.runMigrations(defaultIntegration);
106871
107066
  this.clipService = createClipService({
106872
107067
  dataDir: this.ctx.dataDir,
106873
107068
  logger: this.ctx.logger,