@camstack/addon-provider-enpal 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.js CHANGED
@@ -5981,7 +5981,7 @@ var ZodIssueCode = {
5981
5981
  var ZodFirstPartyTypeKind;
5982
5982
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5983
5983
  //#endregion
5984
- //#region ../types/dist/sleep-9TIHFj1w.mjs
5984
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
5985
5985
  /**
5986
5986
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5987
5987
  * window to float samples (D455).
@@ -6790,6 +6790,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6790
6790
  }
6791
6791
  return out;
6792
6792
  }
6793
+ /** Every scope, in the order the guard and the docs list them. */
6794
+ var SCOPED_SETTINGS_SCOPES = [
6795
+ "cluster",
6796
+ "device-defaults",
6797
+ "node"
6798
+ ];
6793
6799
  /**
6794
6800
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6795
6801
  *
@@ -7604,6 +7610,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7604
7610
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7605
7611
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7606
7612
  /**
7613
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7614
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7615
+ * through `api` (guard `check-migration-ports-surface`).
7616
+ */
7617
+ function migrationSet(catalogue, bindPorts) {
7618
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7619
+ }
7620
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7621
+ function refuseMixed(form, kept, dropped) {
7622
+ 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`);
7623
+ }
7624
+ function catalogueOf(list) {
7625
+ const kept = list.filter((entry) => !("execute" in entry));
7626
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7627
+ return kept;
7628
+ }
7629
+ function boundOf(list) {
7630
+ const kept = list.filter((entry) => "execute" in entry);
7631
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7632
+ return kept;
7633
+ }
7634
+ /**
7607
7635
  * Base class for CamStack addons. Eliminates settings boilerplate:
7608
7636
  *
7609
7637
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7681,6 +7709,13 @@ var BaseAddon = class {
7681
7709
  */
7682
7710
  secretStatePaths = [];
7683
7711
  _addonSecretTree = null;
7712
+ /**
7713
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7714
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7715
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7716
+ */
7717
+ _scopedByCap = /* @__PURE__ */ new Map();
7718
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7684
7719
  _deviceSecretTree = null;
7685
7720
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7686
7721
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7750,6 +7785,7 @@ var BaseAddon = class {
7750
7785
  this._ctx = context;
7751
7786
  this._secretSettings = null;
7752
7787
  }
7788
+ await this.loadScopedSchemas();
7753
7789
  await this.resolveConfig();
7754
7790
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7755
7791
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7759,25 +7795,24 @@ var BaseAddon = class {
7759
7795
  const normalized = normalizeAddonInitResult(result);
7760
7796
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7761
7797
  this._registeredCapNames = providers.map((p) => p.capability.name);
7798
+ await this.loadScopedSchemas();
7762
7799
  return normalized;
7763
7800
  }
7801
+ async runMigrations(first, second, third) {
7802
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7803
+ return this.runBound(boundOf(first), second);
7804
+ }
7764
7805
  /**
7765
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7766
- * engine. Call it at the point of the boot where the data must already have the new
7767
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7768
- * restored devices — with the catalogue bound to the addon's ports
7769
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7770
- *
7771
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7772
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7773
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7774
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7775
- *
7776
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7777
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7778
- * omitted applied ids "newer").
7806
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7807
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7808
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7779
7809
  */
7780
- async runMigrations(migrations, options) {
7810
+ async runMigrationSets(sets, options) {
7811
+ const api = this.ctx.migrationApi;
7812
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7813
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7814
+ }
7815
+ async runBound(migrations, options) {
7781
7816
  const api = this.ctx.api.migrations;
7782
7817
  const report = await runAddonMigrations({
7783
7818
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7847,6 +7882,16 @@ var BaseAddon = class {
7847
7882
  schema(schema) {
7848
7883
  return schema;
7849
7884
  }
7885
+ /**
7886
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7887
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7888
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7889
+ * must already know which keys are per node. Names the providers register at init are added
7890
+ * once known.
7891
+ */
7892
+ scopedSettingsCapabilities() {
7893
+ return [];
7894
+ }
7850
7895
  /** Override to provide global-level settings UI schema. */
7851
7896
  globalSettingsSchema(_cap) {
7852
7897
  return null;
@@ -7890,7 +7935,8 @@ var BaseAddon = class {
7890
7935
  return [];
7891
7936
  }
7892
7937
  async getGlobalSettings(overlay, cap, nodeId) {
7893
- const schema = this.globalSettingsSchema(cap);
7938
+ await this.loadScopedSchemas(cap);
7939
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7894
7940
  if (!schema) return { sections: [] };
7895
7941
  const projected = await this.readRawProjectedStore(nodeId, cap);
7896
7942
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -8021,6 +8067,7 @@ var BaseAddon = class {
8021
8067
  * resolved blob back is a no-op for every unchanged secret.
8022
8068
  */
8023
8069
  async resolveGlobalStore(nodeId, cap) {
8070
+ await this.loadScopedSchemas(cap);
8024
8071
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8025
8072
  return this.projectForNode(raw, nodeId, cap);
8026
8073
  }
@@ -8031,6 +8078,7 @@ var BaseAddon = class {
8031
8078
  }
8032
8079
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8033
8080
  async readRawProjectedStore(nodeId, cap) {
8081
+ await this.loadScopedSchemas(cap);
8034
8082
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8035
8083
  return this.projectForNode(raw, nodeId, cap);
8036
8084
  }
@@ -8133,6 +8181,7 @@ var BaseAddon = class {
8133
8181
  await this.applyGlobalPatch(patch, nodeId);
8134
8182
  }
8135
8183
  async applyGlobalPatch(barePatch, nodeId) {
8184
+ await this.loadScopedSchemas();
8136
8185
  const keys = this.perNodeKeys();
8137
8186
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8138
8187
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8146,7 +8195,8 @@ var BaseAddon = class {
8146
8195
  await this.resolveConfig();
8147
8196
  await this.onConfigChanged();
8148
8197
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8149
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8198
+ const legacy = this.globalSettingsSchema();
8199
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8150
8200
  }
8151
8201
  /**
8152
8202
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8154,14 +8204,67 @@ var BaseAddon = class {
8154
8204
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8155
8205
  * settings API behaves exactly like the legacy node-agnostic one.
8156
8206
  */
8157
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8207
+ /**
8208
+ * Load the scoped schemas of every capability this addon declares (the override and the
8209
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8210
+ * derived from the previous set. Idempotent.
8211
+ */
8212
+ async loadScopedSchemas(extraCap) {
8213
+ const caps = new Set([
8214
+ ...this.scopedSettingsCapabilities(),
8215
+ ...this._registeredCapNames,
8216
+ ...extraCap === void 0 ? [] : [extraCap]
8217
+ ]);
8218
+ let added = false;
8219
+ for (const cap of caps) {
8220
+ if (this._scopedByCap.has(cap)) continue;
8221
+ const loaded = [];
8222
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8223
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8224
+ if (schema !== null) loaded.push({
8225
+ scope,
8226
+ schema
8227
+ });
8228
+ }
8229
+ this._scopedByCap.set(cap, loaded);
8230
+ added = true;
8231
+ }
8232
+ if (!added) return;
8233
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8234
+ this._addonSecretTree = null;
8235
+ }
8236
+ /**
8237
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8238
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8239
+ */
8240
+ scopedFormSchema(cap) {
8241
+ const byId = /* @__PURE__ */ new Map();
8242
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8243
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8244
+ }
8245
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8246
+ loadedScopedSchemas(cap) {
8247
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8248
+ return [...this._scopedByCap.values()].flat();
8249
+ }
8250
+ /**
8251
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8252
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8253
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8254
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8255
+ * Call {@link loadScopedSchemas} first (the async seams do).
8256
+ */
8158
8257
  perNodeKeys(cap) {
8159
8258
  const cacheKey = cap ?? "";
8160
- const cached = this._perNodeKeysCache.get(cacheKey);
8259
+ const cached = this._nodeKeysByCap.get(cacheKey);
8161
8260
  if (cached) return cached;
8162
- const schema = this.globalSettingsSchema(cap);
8163
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8164
- this._perNodeKeysCache.set(cacheKey, keys);
8261
+ const legacy = this.globalSettingsSchema(cap);
8262
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8263
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8264
+ if (scope !== "node") continue;
8265
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8266
+ }
8267
+ this._nodeKeysByCap.set(cacheKey, keys);
8165
8268
  return keys;
8166
8269
  }
8167
8270
  /**
@@ -8171,10 +8274,9 @@ var BaseAddon = class {
8171
8274
  * time to return its response before the addon is torn down and
8172
8275
  * re-initialised by `AddonRegistryService.restartAddon`.
8173
8276
  */
8174
- maybeAutoRestart(patchKeys, schema) {
8175
- if (!schema) return;
8277
+ maybeAutoRestart(patchKeys, schemas) {
8176
8278
  const restartKeys = /* @__PURE__ */ new Set();
8177
- for (const section of schema.sections) for (const field of section.fields) {
8279
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8178
8280
  if (field.type === "separator" || field.type === "info") continue;
8179
8281
  if (field.requiresRestart) restartKeys.add(field.key);
8180
8282
  }
@@ -8370,12 +8472,14 @@ var BaseAddon = class {
8370
8472
  * here, in the addon's own process, so the hub keeps no copy of it.
8371
8473
  */
8372
8474
  async getDeclaredSettingsKeys() {
8475
+ await this.loadScopedSchemas();
8373
8476
  return { keys: [...this.declaredKeySet()].toSorted() };
8374
8477
  }
8375
8478
  declaredKeySet() {
8376
8479
  const keys = new Set(Object.keys(this.defaults));
8377
8480
  const schema = this.globalSettingsSchema();
8378
8481
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8482
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8379
8483
  for (const key of this._declaredStateKeys) keys.add(key);
8380
8484
  for (const path of this.secretStatePaths) {
8381
8485
  const root = path.split(/[.[]/, 1)[0];
@@ -8471,7 +8575,11 @@ var BaseAddon = class {
8471
8575
  }
8472
8576
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8473
8577
  addonSecretTree() {
8474
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8578
+ if (this._addonSecretTree === null) {
8579
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8580
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8581
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8582
+ }
8475
8583
  return this._addonSecretTree;
8476
8584
  }
8477
8585
  deviceSecretTree() {
@@ -8721,6 +8829,23 @@ function dropPerNodeFields(fields) {
8721
8829
  }
8722
8830
  return kept;
8723
8831
  }
8832
+ /** The keys of the value-holding fields, recursing into layout containers. */
8833
+ function collectValueFieldKeys(fields) {
8834
+ const collected = [];
8835
+ for (const field of fields) {
8836
+ if (field.type === "group") {
8837
+ collected.push(...collectValueFieldKeys(field.fields));
8838
+ continue;
8839
+ }
8840
+ if (field.type === "sub-tabs") {
8841
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8842
+ continue;
8843
+ }
8844
+ if (field.type === "separator" || field.type === "info") continue;
8845
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8846
+ }
8847
+ return collected;
8848
+ }
8724
8849
  function collectFieldKeys(fields) {
8725
8850
  const collected = [];
8726
8851
  for (const field of fields) {
@@ -13414,7 +13539,7 @@ var RecordIntegrationInstances = class {
13414
13539
  return record === null ? null : this.viewOf(record);
13415
13540
  };
13416
13541
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13417
- createInstance = async ({ id, name, kind }) => {
13542
+ createInstance = async ({ id, name, kind, values }) => {
13418
13543
  const minted = id ?? this.hooks.mintId?.({
13419
13544
  name,
13420
13545
  ...kind !== void 0 ? { kind } : {}
@@ -13424,10 +13549,20 @@ var RecordIntegrationInstances = class {
13424
13549
  id: minted,
13425
13550
  data: this.hooks.initialBody(name, kind)
13426
13551
  }, { ifRev: 0 });
13552
+ const patch = this.patchOf(values ?? {});
13553
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13427
13554
  await this.hooks.onChanged?.(minted, "created");
13428
13555
  return { id: minted };
13429
13556
  };
13430
13557
  updateInstance = async ({ id, name, values }) => {
13558
+ const patch = this.patchOf(values);
13559
+ if (name !== void 0) patch[this.nameField] = name;
13560
+ await this.handle.patch(id, patch);
13561
+ await this.hooks.onChanged?.(id, "updated");
13562
+ return { ok: true };
13563
+ };
13564
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13565
+ patchOf(values) {
13431
13566
  const patch = {};
13432
13567
  for (const [key, value] of Object.entries(values)) {
13433
13568
  if (value === void 0) continue;
@@ -13438,11 +13573,8 @@ var RecordIntegrationInstances = class {
13438
13573
  else if (isSecretClear(value)) patch[key] = null;
13439
13574
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13440
13575
  }
13441
- if (name !== void 0) patch[this.nameField] = name;
13442
- await this.handle.patch(id, patch);
13443
- await this.hooks.onChanged?.(id, "updated");
13444
- return { ok: true };
13445
- };
13576
+ return patch;
13577
+ }
13446
13578
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13447
13579
  setInstanceEnabled = async ({ id, enabled }) => {
13448
13580
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14760,25 +14892,6 @@ function integrationRowsPortsOver(deps) {
14760
14892
  log: { warn: deps.warn }
14761
14893
  });
14762
14894
  }
14763
- function defaultIntegrationApiOver(api) {
14764
- return {
14765
- list: () => api.integrations.list.query(),
14766
- readLegacyIntegrationRows: (input) => api.migrations.readLegacyIntegrationRows.query(input),
14767
- clearLegacyIntegrationRows: (input) => api.migrations.clearLegacyIntegrationRows.mutate(input),
14768
- listDevices: (addonId) => api.deviceManager.listAll.query({
14769
- addonId,
14770
- projection: "slim"
14771
- }),
14772
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14773
- await api.deviceManager.setIntegrationId.mutate({
14774
- deviceId,
14775
- integrationId
14776
- });
14777
- },
14778
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14779
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14780
- };
14781
- }
14782
14895
  /**
14783
14896
  * The trainer contract — what the hub hands the cloud trainer and what it
14784
14897
  * gets back (cloud training, D805+).
@@ -15867,6 +15980,39 @@ var UnstampedEventMediaCountSchema = object({
15867
15980
  /** Sum across both, or `null` when either lane could not be counted. */
15868
15981
  total: number().int().nonnegative().nullable()
15869
15982
  }).nullable();
15983
+ /**
15984
+ * Where the stored event media sits, per storage location: how many media rows
15985
+ * and how many bytes carry each location id, how many carry none (legacy,
15986
+ * resolved to the default `eventMedia` location), and how many name a location
15987
+ * that was not asked about (a deleted or never-listed one).
15988
+ *
15989
+ * One covering-index aggregate per asked location plus the NULL one, and one
15990
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
15991
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
15992
+ * it is a deleted location only when every location id was asked.
15993
+ * `null` is "could not be measured", never zero.
15994
+ */
15995
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
15996
+ var MediaLocationCensusSchema = object({
15997
+ locations: array(object({
15998
+ locationId: string(),
15999
+ rows: number().int().nonnegative(),
16000
+ bytes: number().nonnegative()
16001
+ })).readonly(),
16002
+ unstamped: object({
16003
+ rows: number().int().nonnegative(),
16004
+ bytes: number().nonnegative()
16005
+ }),
16006
+ /** Rows stamped with a location id that was not in the asked list. */
16007
+ unlisted: object({
16008
+ rows: number().int().nonnegative(),
16009
+ bytes: number().nonnegative()
16010
+ }),
16011
+ total: object({
16012
+ rows: number().int().nonnegative(),
16013
+ bytes: number().nonnegative()
16014
+ })
16015
+ });
15870
16016
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
15871
16017
  /** The independently selectable logical storage classes — every class
15872
16018
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -46982,52 +47128,7 @@ onBrightnessChanged: { data: object({
46982
47128
  minIntervalMs: 0
46983
47129
  } } }
46984
47130
  };
46985
- /**
46986
- * `broker` — unified pub/sub broker registry, system-scoped collection.
46987
- *
46988
- * The cap models any kind-tagged message broker the user wants to
46989
- * register and that other addons might consume. The first two kinds
46990
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
46991
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
46992
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
46993
- * the same surface.
46994
- *
46995
- * Why one cap, not one cap per kind:
46996
- * - The integrations page wants a single table of "every broker"
46997
- * across kinds; a unified cap drives it without join logic.
46998
- * - Generic admin operations (add / remove / test / status) are
46999
- * identical across kinds — duplicating them per cap was busywork.
47000
- * - The `network-access` cap precedent: same interface, many
47001
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47002
- *
47003
- * What stays kind-specific:
47004
- * - `getBrokerConfig` payload (kind decides whether it returns
47005
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47006
- * `Record<string, unknown>` at the wire; consumers narrow.
47007
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47008
- * key) — also typed as `Record<string, unknown>` so each kind can
47009
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47010
- * without rebreaking the cap signature.
47011
- * - `add` `settings` payload (different fields per kind, validated by
47012
- * the kind-specific provider).
47013
- *
47014
- * Bidirectionality:
47015
- * - `publish` is RPC — synchronous result (provider-defined).
47016
- * - `subscribe` returns a subscription handle; the actual message
47017
- * stream flows over the typed event-bus as `broker.message` events
47018
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47019
- * event handler. Subscriptions persist across reconnects — the
47020
- * provider re-subscribes upstream after a transport drop.
47021
- *
47022
- * Why event-bus push (not a subscription RPC stream):
47023
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47024
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47025
- * drop is recoverable via `getState({key})`).
47026
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47027
- * - Cross-process: events already route through `$event-bus`; no
47028
- * per-broker wire-shaping needed.
47029
- */
47030
- var BrokerStatusEnum = _enum([
47131
+ _enum([
47031
47132
  "connected",
47032
47133
  "disconnected",
47033
47134
  "connecting",
@@ -47035,141 +47136,12 @@ var BrokerStatusEnum = _enum([
47035
47136
  "unreachable",
47036
47137
  "error"
47037
47138
  ]);
47038
- var BrokerInfoSchema = object({
47039
- /** Stable broker id. Persisted; survives addon restarts. */
47040
- id: string(),
47041
- /** Addon id of the provider that OWNS this broker.
47042
- *
47043
- * The `broker` cap is a system-scoped collection: several addons
47044
- * register a `broker` provider, each owning a DISJOINT set of
47045
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47046
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47047
- * device belongs to one integration. The admin UI threads this id
47048
- * back as the `{ addonId }` system-collection selector on every
47049
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47050
- * `testConnection`), so the call routes to the OWNING provider
47051
- * instead of defaulting to the first-registered one. */
47052
- addonId: string(),
47053
- /** Human-readable name (operator-chosen at add-time). */
47054
- name: string(),
47055
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47056
- kind: string(),
47057
- status: BrokerStatusEnum,
47058
- /** Free-form provider-specific info (HA version, MQTT broker
47059
- * flavour, latency, mTLS active, …). */
47060
- info: record(string(), unknown()),
47061
- /** Ms epoch of the last connection probe / status update. */
47062
- lastCheckedAt: number().nullable(),
47063
- /** Last error message, when `status` indicates failure. */
47064
- error: string().nullable()
47065
- });
47066
47139
  var RegistryStatusSchema = object({
47067
47140
  brokerCount: number().int().nonnegative(),
47068
47141
  connectedCount: number().int().nonnegative()
47069
47142
  });
47070
- /**
47071
- * One entry per `broker` provider — which addon provides which broker
47072
- * kind(s). The unified create picker reads this to know, for each
47073
- * (addonId, kind) pair the operator can pick, where to route the
47074
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47075
- * `{ addonId }` selector). A provider only advertises a kind here when
47076
- * it implements `getSettingsSchema` for that kind (so the picker never
47077
- * offers a kind whose creation form can't be rendered).
47078
- */
47079
- var BrokerProviderInfoSchema = object({
47080
- /** Addon id of the `broker` provider this entry describes. */
47081
- addonId: string(),
47082
- /** Broker kinds this provider can create, with a display label. */
47083
- kinds: array(object({
47084
- kind: string(),
47085
- label: string(),
47086
- /**
47087
- * Relative hub path to start an interactive account link (OAuth popup).
47088
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47089
- */
47090
- interactiveConnectPath: string().min(1).optional(),
47091
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47092
- interactiveDisconnectPath: string().min(1).optional(),
47093
- /**
47094
- * The kind signs in through a server-held interactive session instead of
47095
- * (or before) typed credentials. `basePath` is a hub-relative route set
47096
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47097
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47098
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47099
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47100
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47101
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47102
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47103
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47104
- * offers it as the default path; the fields the session fills are
47105
- * marked `filledBySignIn` in the kind's settings schema.
47106
- *
47107
- * `methods` lists the ways the session can sign in, recommended first:
47108
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47109
- * settings) answering `{ sessionId, userCode, verificationUrl,
47110
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47111
- * any device, and the same `status` / `commit` / `cancel` routes follow
47112
- * (status then carries `method`, `userCode`, `verificationUrl`,
47113
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47114
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47115
- * `['proxy']`.
47116
- */
47117
- signIn: object({
47118
- basePath: string().min(1),
47119
- methods: array(_enum(["device-code", "proxy"])).optional()
47120
- }).optional()
47121
- }))
47122
- });
47123
- var ListInputSchema = object({
47124
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47125
- * only HA brokers. Omit to list every broker. */
47126
- kind: string().optional() });
47127
47143
  var GetInputSchema = object({ id: string() });
47128
- var AddInputSchema = object({
47129
- kind: string().min(1),
47130
- name: string().min(1),
47131
- /**
47132
- * ADOPT an existing id instead of minting a new one.
47133
- *
47134
- * Written the day this cost an outage. A broker's id is not a detail: HA
47135
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47136
- * lost from config and re-added as `ha_001` leaves every one of its devices
47137
- * bound to a broker that no longer exists. Re-entering the password under the
47138
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47139
- * password.
47140
- *
47141
- * A provider MUST refuse an id that is already in use — adopting a live
47142
- * broker's id would silently take it over.
47143
- */
47144
- id: string().min(1).optional(),
47145
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47146
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47147
- * branch on receipt — invalid shape rejects the add. */
47148
- settings: record(string(), unknown())
47149
- });
47150
- var AddResultSchema = object({ id: string() });
47151
- var RemoveInputSchema = object({ id: string() });
47152
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47153
- ok: literal(true),
47154
- latencyMs: number().nonnegative()
47155
- }), object({
47156
- ok: literal(false),
47157
- error: string()
47158
- })]);
47159
47144
  var SettingsRecordSchema$1 = record(string(), unknown());
47160
- var SettingsSchemaInputSchema = object({ kind: string() });
47161
- var TestSettingsInputSchema = object({
47162
- kind: string(),
47163
- settings: SettingsRecordSchema$1
47164
- });
47165
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47166
- ok: literal(true),
47167
- latencyMs: number().nonnegative().optional()
47168
- }).strict(), object({
47169
- ok: literal(false),
47170
- error: string()
47171
- })]);
47172
- var SettingsSchemaResultSchema = unknown().nullable();
47173
47145
  var PublishInputSchema = object({
47174
47146
  brokerId: string(),
47175
47147
  /** Kind-specific routing target.
@@ -47203,25 +47175,7 @@ var GetStateInputSchema = object({
47203
47175
  * HA: entity_id (returns the cached entity state). */
47204
47176
  key: string()
47205
47177
  });
47206
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47207
- kind: "mutation",
47208
- auth: "admin"
47209
- }), method(RemoveInputSchema, _void(), {
47210
- kind: "mutation",
47211
- auth: "admin"
47212
- }), method(GetInputSchema, TestConnectionResultSchema, {
47213
- kind: "mutation",
47214
- auth: "admin"
47215
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47216
- id: string(),
47217
- settings: SettingsRecordSchema$1
47218
- }), _void(), {
47219
- kind: "mutation",
47220
- auth: "admin"
47221
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47222
- kind: "mutation",
47223
- auth: "admin"
47224
- }), method(PublishInputSchema, unknown(), {
47178
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47225
47179
  kind: "mutation",
47226
47180
  auth: "admin"
47227
47181
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -52059,7 +52013,14 @@ var DiscoveryCandidateSchema = object({
52059
52013
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52060
52014
  parentStableId: string().optional(),
52061
52015
  /** `false` = shown for context but not pickable. Default true. */
52062
- selectable: boolean().optional()
52016
+ selectable: boolean().optional(),
52017
+ /**
52018
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52019
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52020
+ * admin asks for exactly these, on the creation form prefilled with
52021
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52022
+ */
52023
+ needsParams: array(string()).optional()
52063
52024
  });
52064
52025
  /**
52065
52026
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52186,8 +52147,14 @@ var deviceProviderCapability = {
52186
52147
  * provider does not support manual creation. Lets the Add-Device dialog
52187
52148
  * pick the right type instead of assuming Camera.
52188
52149
  */
52189
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52190
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52150
+ getManualCreationType: method(object({
52151
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52152
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52153
+ adoptDiscoveredDevice: method(object({
52154
+ candidate: DiscoveryCandidateSchema,
52155
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52156
+ integrationId: string().optional()
52157
+ }), DeviceSummarySchema, {
52191
52158
  kind: "mutation",
52192
52159
  auth: "admin"
52193
52160
  }),
@@ -52198,10 +52165,16 @@ var deviceProviderCapability = {
52198
52165
  * devices of that type. The output is a `ConfigUISchema` — the
52199
52166
  * router type-asserts it at the boundary.
52200
52167
  */
52201
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52168
+ getChildCreationSchema: method(object({
52169
+ type: _enum(DeviceType),
52170
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52171
+ integrationId: string().optional()
52172
+ }), CreationSchemaOutputSchema),
52202
52173
  createDevice: method(object({
52203
52174
  type: _enum(DeviceType),
52204
- config: record(string(), unknown())
52175
+ config: record(string(), unknown()),
52176
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52177
+ integrationId: string().optional()
52205
52178
  }), DeviceSummarySchema, {
52206
52179
  kind: "mutation",
52207
52180
  auth: "admin"
@@ -52926,7 +52899,10 @@ method(object({
52926
52899
  auth: "admin"
52927
52900
  }), method(object({
52928
52901
  addonId: string(),
52929
- type: _enum(DeviceType)
52902
+ type: _enum(DeviceType),
52903
+ /** The integration the form is for; a provider whose integrations differ (a hub
52904
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
52905
+ integrationId: string().optional()
52930
52906
  }), unknown().nullable()), method(object({
52931
52907
  addonId: string(),
52932
52908
  type: _enum(DeviceType),
@@ -53010,7 +52986,11 @@ method(object({
53010
52986
  kind: "mutation",
53011
52987
  auth: "admin",
53012
52988
  timeoutMs: 12e4
53013
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
52989
+ }), method(object({
52990
+ addonId: string(),
52991
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
52992
+ integrationId: string().optional()
52993
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53014
52994
  deviceId: number(),
53015
52995
  key: string(),
53016
52996
  value: unknown()
@@ -56290,7 +56270,7 @@ var TestConnectionStatusEnum = _enum([
56290
56270
  "inconclusive",
56291
56271
  "unsupported"
56292
56272
  ]);
56293
- var TestConnectionResultSchema$1 = object({
56273
+ var TestConnectionResultSchema = object({
56294
56274
  /** True ONLY for `validated`. Never true for a test that did not run. */
56295
56275
  success: boolean(),
56296
56276
  error: string().optional(),
@@ -56335,7 +56315,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56335
56315
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56336
56316
  addonId: string(),
56337
56317
  settings: record(string(), unknown())
56338
- }), TestConnectionResultSchema$1, {
56318
+ }), TestConnectionResultSchema, {
56339
56319
  kind: "mutation",
56340
56320
  auth: "admin"
56341
56321
  });
@@ -56362,6 +56342,14 @@ var ConfigSchemaPassthrough$3 = custom();
56362
56342
  var IntegrationInstanceIdSchema = string().min(1);
56363
56343
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56364
56344
  /**
56345
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56346
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56347
+ * `services`: a connection configured from the addon's own function page, never listed on
56348
+ * Integrations.
56349
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56350
+ */
56351
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56352
+ /**
56365
56353
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56366
56354
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56367
56355
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56372,6 +56360,22 @@ var IntegrationInstanceKindSchema = object({
56372
56360
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56373
56361
  id: string().min(1),
56374
56362
  label: string().min(1),
56363
+ /**
56364
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56365
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56366
+ * provider with more than one section must name it on every kind.
56367
+ */
56368
+ functionCap: string().min(1),
56369
+ /**
56370
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56371
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56372
+ * finds the instances whose kind names it; absent takes the kind `id`.
56373
+ */
56374
+ brokerKind: string().min(1).optional(),
56375
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56376
+ role: IntegrationInstanceRoleSchema.optional(),
56377
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56378
+ canTest: boolean().optional(),
56375
56379
  /** The kind signs in through a server-held interactive session. */
56376
56380
  signIn: object({
56377
56381
  basePath: string().min(1),
@@ -56384,11 +56388,7 @@ var IntegrationInstanceKindSchema = object({
56384
56388
  });
56385
56389
  var IntegrationInstanceDescriptionSchema = object({
56386
56390
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56387
- role: _enum([
56388
- "devices",
56389
- "services",
56390
- "both"
56391
- ]),
56391
+ role: IntegrationInstanceRoleSchema,
56392
56392
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56393
56393
  discovery: object({
56394
56394
  mode: _enum([
@@ -56463,7 +56463,11 @@ var integrationInstancesCapability = {
56463
56463
  methods: {
56464
56464
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56465
56465
  /** The form; `id: null` is the create form. */
56466
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56466
+ instanceFormSchema: method(object({
56467
+ id: IntegrationInstanceIdSchema.nullable(),
56468
+ /** The kind of the create form (`id: null`) of a provider with several. */
56469
+ kind: string().min(1).optional()
56470
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56467
56471
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56468
56472
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56469
56473
  /**
@@ -56473,7 +56477,9 @@ var integrationInstancesCapability = {
56473
56477
  createInstance: method(object({
56474
56478
  id: IntegrationInstanceIdSchema.optional(),
56475
56479
  name: string().min(1),
56476
- kind: string().min(1).optional()
56480
+ kind: string().min(1).optional(),
56481
+ /** Form values written with the record (a link picked in the create dialog). */
56482
+ values: record(string(), unknown()).optional()
56477
56483
  }), object({ id: string() }), {
56478
56484
  kind: "mutation",
56479
56485
  auth: "admin"
@@ -56500,8 +56506,10 @@ var integrationInstancesCapability = {
56500
56506
  }),
56501
56507
  testInstance: optionalMethod(object({
56502
56508
  id: IntegrationInstanceIdSchema.nullable(),
56503
- values: record(string(), unknown())
56504
- }), TestConnectionResultSchema$1, {
56509
+ values: record(string(), unknown()),
56510
+ /** The kind to test when `id` is null and the provider has several. */
56511
+ kind: string().min(1).optional()
56512
+ }), TestConnectionResultSchema, {
56505
56513
  kind: "mutation",
56506
56514
  auth: "admin"
56507
56515
  })
@@ -59258,6 +59266,380 @@ var SystemMetricsSchema = object({
59258
59266
  gpuMemoryPercent: number().optional()
59259
59267
  });
59260
59268
  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);
59269
+ /**
59270
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59271
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59272
+ * (operator intent, D870) and device-history (numbers over time, D850).
59273
+ *
59274
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59275
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59276
+ * that with the addon id closed over). It is deliberately NOT in any input
59277
+ * schema, so a session can never supply it, and a call with no stamp is refused
59278
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59279
+ * addons go through the owner's capability.
59280
+ *
59281
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59282
+ * never `[]`. Secret fields are never on the wire: a read shows the
59283
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59284
+ * resolves itself, and a write may carry only a keychain marker bound to the
59285
+ * row's own ref.
59286
+ *
59287
+ * Internal: addons reach it through `ctx.records`, never directly.
59288
+ */
59289
+ var RecordIdSchema = string().min(1).max(256);
59290
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59291
+ var RecordBodySchema = record(string(), unknown());
59292
+ var RecordInputSchema = object({
59293
+ id: RecordIdSchema,
59294
+ /** The device this row belongs to (D865 removal, per-device reads). */
59295
+ deviceId: number().int().optional(),
59296
+ /** The domain clock, ms: observed / created / opened. */
59297
+ at: number().int().optional(),
59298
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59299
+ expiresAt: number().int().optional(),
59300
+ data: RecordBodySchema
59301
+ });
59302
+ var RecordViewSchema = object({
59303
+ id: string(),
59304
+ deviceId: number().int().nullable(),
59305
+ at: number().nullable(),
59306
+ expiresAt: number().nullable(),
59307
+ rev: number().int(),
59308
+ updatedAt: number(),
59309
+ data: RecordBodySchema
59310
+ });
59311
+ /** Declared index fields only. Anything else does not compile, by design. */
59312
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59313
+ string(),
59314
+ number(),
59315
+ boolean(),
59316
+ object({ in: array(union([
59317
+ string(),
59318
+ number(),
59319
+ boolean()
59320
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59321
+ object({
59322
+ gt: union([string(), number()]).optional(),
59323
+ gte: union([string(), number()]).optional(),
59324
+ lt: union([string(), number()]).optional(),
59325
+ lte: union([string(), number()]).optional()
59326
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59327
+ ]));
59328
+ var KindShape = { kind: RecordKindNameSchema };
59329
+ var TimeWindowShape = {
59330
+ deviceId: number().int().optional(),
59331
+ atFrom: number().optional(),
59332
+ atTo: number().optional()
59333
+ };
59334
+ var RecordQueryInputSchema = object({
59335
+ ...KindShape,
59336
+ ...TimeWindowShape,
59337
+ where: RecordWhereSchema.optional(),
59338
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59339
+ order: _enum(["at", "id"]).optional(),
59340
+ desc: boolean().optional(),
59341
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59342
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59343
+ cursor: string().min(1).optional()
59344
+ });
59345
+ var RecordQueryResultSchema = object({
59346
+ records: array(RecordViewSchema),
59347
+ nextCursor: string().nullable()
59348
+ });
59349
+ var RecordKindStateSchema = _enum([
59350
+ "created",
59351
+ "unchanged",
59352
+ "updated"
59353
+ ]);
59354
+ var DeclareKindResultSchema = object({
59355
+ kindId: number().int(),
59356
+ state: RecordKindStateSchema,
59357
+ createdIndexes: array(string())
59358
+ });
59359
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59360
+ var SecretRefsList = array(string());
59361
+ /**
59362
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59363
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59364
+ */
59365
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59366
+ object({
59367
+ op: literal("put"),
59368
+ kind: RecordKindNameSchema,
59369
+ record: RecordInputSchema,
59370
+ ifRev: number().int().min(0).optional()
59371
+ }),
59372
+ object({
59373
+ op: literal("patch"),
59374
+ kind: RecordKindNameSchema,
59375
+ id: RecordIdSchema,
59376
+ data: RecordBodySchema,
59377
+ at: number().int().nullable().optional(),
59378
+ expiresAt: number().int().nullable().optional(),
59379
+ ifRev: number().int().min(1).optional()
59380
+ }),
59381
+ object({
59382
+ op: literal("delete"),
59383
+ kind: RecordKindNameSchema,
59384
+ id: RecordIdSchema
59385
+ })
59386
+ ]);
59387
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59388
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59389
+ kind: "mutation",
59390
+ auth: "admin"
59391
+ }), method(object({
59392
+ ...KindShape,
59393
+ id: RecordIdSchema
59394
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59395
+ ...KindShape,
59396
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59397
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59398
+ ...KindShape,
59399
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59400
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59401
+ ...KindShape,
59402
+ record: RecordInputSchema,
59403
+ /** Compare-and-set. `0` means "the row must not exist". */
59404
+ ifRev: number().int().min(0).optional()
59405
+ }), object({
59406
+ rev: number().int(),
59407
+ releasedRefs: SecretRefsList
59408
+ }), {
59409
+ kind: "mutation",
59410
+ auth: "admin"
59411
+ }), method(object({
59412
+ ...KindShape,
59413
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59414
+ }), object({
59415
+ count: number().int(),
59416
+ releasedRefs: SecretRefsList
59417
+ }), {
59418
+ kind: "mutation",
59419
+ auth: "admin"
59420
+ }), method(object({
59421
+ ...KindShape,
59422
+ id: RecordIdSchema,
59423
+ data: RecordBodySchema,
59424
+ at: number().int().nullable().optional(),
59425
+ expiresAt: number().int().nullable().optional(),
59426
+ ifRev: number().int().min(1).optional()
59427
+ }), object({
59428
+ rev: number().int(),
59429
+ releasedRefs: SecretRefsList
59430
+ }), {
59431
+ kind: "mutation",
59432
+ auth: "admin"
59433
+ }), method(object({
59434
+ ...KindShape,
59435
+ id: RecordIdSchema
59436
+ }), object({
59437
+ deleted: boolean(),
59438
+ secretRefs: SecretRefsList
59439
+ }), {
59440
+ kind: "mutation",
59441
+ auth: "admin"
59442
+ }), method(object({
59443
+ ...KindShape,
59444
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59445
+ }), object({
59446
+ deleted: number().int(),
59447
+ secretRefs: SecretRefsList
59448
+ }), {
59449
+ kind: "mutation",
59450
+ auth: "admin"
59451
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59452
+ ...KindShape,
59453
+ ...TimeWindowShape,
59454
+ where: RecordWhereSchema.optional()
59455
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59456
+ ...KindShape,
59457
+ deviceId: number().int().optional(),
59458
+ from: number(),
59459
+ to: number(),
59460
+ bucketMs: number().int().positive()
59461
+ }), object({ buckets: array(object({
59462
+ bucketStart: number(),
59463
+ count: number().int()
59464
+ })) }), { auth: "admin" }), method(object({
59465
+ ...KindShape,
59466
+ op: _enum([
59467
+ "sum",
59468
+ "min",
59469
+ "max",
59470
+ "count"
59471
+ ]),
59472
+ field: RecordFieldPathSchema.optional(),
59473
+ groupBy: RecordFieldPathSchema.optional(),
59474
+ where: RecordWhereSchema.optional()
59475
+ }), object({ rows: array(object({
59476
+ group: union([
59477
+ string(),
59478
+ number(),
59479
+ _null()
59480
+ ]),
59481
+ value: number().nullable()
59482
+ })) }), { auth: "admin" }), method(object({
59483
+ ...KindShape,
59484
+ deviceId: number().int().optional(),
59485
+ atBefore: number().optional(),
59486
+ where: RecordWhereSchema.optional()
59487
+ }), object({
59488
+ deleted: number().int(),
59489
+ secretRefs: SecretRefsList
59490
+ }), {
59491
+ kind: "mutation",
59492
+ auth: "admin"
59493
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59494
+ results: array(object({
59495
+ rev: number().int().nullable(),
59496
+ deleted: boolean()
59497
+ })),
59498
+ releasedRefs: SecretRefsList,
59499
+ secretRefs: SecretRefsList
59500
+ }), {
59501
+ kind: "mutation",
59502
+ auth: "admin"
59503
+ }), method(object({
59504
+ deviceId: number().int(),
59505
+ kinds: array(RecordKindNameSchema).optional()
59506
+ }), object({
59507
+ deleted: record(string(), number().int()),
59508
+ secretRefs: SecretRefsList
59509
+ }), {
59510
+ kind: "mutation",
59511
+ auth: "admin"
59512
+ }), method(object(KindShape), object({ id: number().int() }), {
59513
+ kind: "mutation",
59514
+ auth: "admin"
59515
+ });
59516
+ /**
59517
+ * The wire shapes of the migration API, version 1 (planning#447).
59518
+ *
59519
+ * A migration is code that outlives the server it was written against: an addon at
59520
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59521
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59522
+ * is the contract of every method of it, one Zod pair per method.
59523
+ *
59524
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59525
+ * field is never removed or made required, an enum never narrows, an output field is
59526
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59527
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59528
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59529
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59530
+ */
59531
+ var Rows = record(string(), unknown());
59532
+ var IntegrationId = object({ integrationId: string().min(1) });
59533
+ var RecordId = object({ id: string().min(1) });
59534
+ var RecordRowSchema = object({
59535
+ id: string(),
59536
+ deviceId: number().int().nullable(),
59537
+ at: number().nullable(),
59538
+ expiresAt: number().nullable(),
59539
+ rev: number().int(),
59540
+ updatedAt: number(),
59541
+ data: Rows
59542
+ });
59543
+ var RecordPutShape = {
59544
+ id: string().min(1),
59545
+ deviceId: number().int().optional(),
59546
+ at: number().int().optional(),
59547
+ expiresAt: number().int().optional(),
59548
+ data: Rows
59549
+ };
59550
+ var MigrationIntegrationSchema = object({
59551
+ id: string(),
59552
+ addonId: string(),
59553
+ name: string(),
59554
+ info: Rows,
59555
+ originStableId: string().optional()
59556
+ });
59557
+ var MigrationDeviceSchema = object({
59558
+ id: number().int(),
59559
+ integrationId: string().nullable().optional(),
59560
+ /** The owning device; null or absent for a root. */
59561
+ parentDeviceId: number().int().nullable().optional(),
59562
+ type: string().optional(),
59563
+ name: string().optional(),
59564
+ stableId: string().optional()
59565
+ });
59566
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59567
+ var MigrationApiInfoSchema = object({
59568
+ version: number().int(),
59569
+ methods: array(string())
59570
+ });
59571
+ object({
59572
+ message: string(),
59573
+ meta: Rows.optional(),
59574
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59575
+ tags: object({ deviceId: number().int().optional() }).optional()
59576
+ });
59577
+ object({
59578
+ owner: string().min(1),
59579
+ metas: array(MigrationMetaSchema)
59580
+ }), object({
59581
+ bootId: string(),
59582
+ snapshot: _enum([
59583
+ "none",
59584
+ "written",
59585
+ "refused"
59586
+ ]),
59587
+ steps: array(MigrationOwnerStepSchema),
59588
+ /** The migration API the engine serves; absent from a server that predates it. */
59589
+ migrationApi: MigrationApiInfoSchema.optional()
59590
+ }), object({ id: string().min(1) }), object({
59591
+ proceed: boolean(),
59592
+ state: union([literal("pending"), MigrationStatusSchema]),
59593
+ reason: string().nullable()
59594
+ }), object({
59595
+ id: string().min(1),
59596
+ result: MigrationOwnerResultSchema
59597
+ }), object({
59598
+ status: MigrationStatusSchema,
59599
+ error: string().nullable(),
59600
+ rowsChanged: number().int().nonnegative()
59601
+ }), object({
59602
+ rows: number().int().nonnegative(),
59603
+ secrets: number().int().nonnegative()
59604
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59605
+ present: boolean(),
59606
+ removed: Rows
59607
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
59608
+ ...RecordPutShape,
59609
+ ifRev: number().int().optional()
59610
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
59611
+ partial: Rows,
59612
+ ifRev: number().int().optional()
59613
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
59614
+ deviceId: number().int().optional(),
59615
+ atFrom: number().optional(),
59616
+ atTo: number().optional(),
59617
+ where: RecordWhereSchema.optional(),
59618
+ limit: number().int().min(1).optional(),
59619
+ cursor: string().min(1).optional(),
59620
+ resolveSecrets: boolean().optional()
59621
+ }), object({
59622
+ records: array(RecordRowSchema),
59623
+ nextCursor: string().nullable()
59624
+ }), object({
59625
+ deviceId: number().int().optional(),
59626
+ atBefore: number().optional(),
59627
+ where: RecordWhereSchema.optional()
59628
+ }), 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({
59629
+ ref: string().min(1),
59630
+ value: string()
59631
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
59632
+ addonId: string().min(1),
59633
+ integrationId: string().min(1).optional()
59634
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
59635
+ id: number().int(),
59636
+ integrationId: string().nullable(),
59637
+ /** Whether the device carries any stored config; its content is not offered. */
59638
+ hasConfig: boolean()
59639
+ }).nullable(), object({
59640
+ deviceId: number().int(),
59641
+ integrationId: string().min(1)
59642
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59261
59643
  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({
59262
59644
  id: string().min(1),
59263
59645
  error: string().min(1)
@@ -59287,7 +59669,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59287
59669
  "written",
59288
59670
  "refused"
59289
59671
  ]),
59290
- steps: array(MigrationOwnerStepSchema)
59672
+ steps: array(MigrationOwnerStepSchema),
59673
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
59674
+ migrationApi: MigrationApiInfoSchema.optional()
59291
59675
  }), {
59292
59676
  kind: "mutation",
59293
59677
  auth: "admin"
@@ -61954,7 +62338,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
61954
62338
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
61955
62339
  kind: "mutation",
61956
62340
  auth: "admin"
61957
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62341
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62342
+ kind: "query",
62343
+ auth: "admin"
62344
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
61958
62345
  kind: "query",
61959
62346
  auth: "admin"
61960
62347
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64609,7 +64996,7 @@ var BrokerStatusSchema$1 = _enum([
64609
64996
  "unreachable",
64610
64997
  "tls-error"
64611
64998
  ]);
64612
- var BrokerInfoSchema$1 = object({
64999
+ var BrokerInfoSchema = object({
64613
65000
  id: string(),
64614
65001
  name: string(),
64615
65002
  url: string(),
@@ -64672,7 +65059,7 @@ var StatusSchema = object({
64672
65059
  brokerCount: number(),
64673
65060
  embeddedRunning: boolean()
64674
65061
  });
64675
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65062
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64676
65063
  kind: "mutation",
64677
65064
  auth: "admin"
64678
65065
  }), method(IdInputSchema, _void(), {
@@ -71854,253 +72241,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, DeviceType.Gateway, met
71854
72241
  auth: "admin"
71855
72242
  });
71856
72243
  /**
71857
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
71858
- * config documents, mirrors. The third storage API next to `ctx.settings`
71859
- * (operator intent, D870) and device-history (numbers over time, D850).
71860
- *
71861
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
71862
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
71863
- * that with the addon id closed over). It is deliberately NOT in any input
71864
- * schema, so a session can never supply it, and a call with no stamp is refused
71865
- * `records/no-caller`. A kind is readable and writable only by its owner; other
71866
- * addons go through the owner's capability.
71867
- *
71868
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
71869
- * never `[]`. Secret fields are never on the wire: a read shows the
71870
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
71871
- * resolves itself, and a write may carry only a keychain marker bound to the
71872
- * row's own ref.
71873
- *
71874
- * Internal: addons reach it through `ctx.records`, never directly.
71875
- */
71876
- var RecordIdSchema = string().min(1).max(256);
71877
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
71878
- var RecordBodySchema = record(string(), unknown());
71879
- var RecordInputSchema = object({
71880
- id: RecordIdSchema,
71881
- /** The device this row belongs to (D865 removal, per-device reads). */
71882
- deviceId: number().int().optional(),
71883
- /** The domain clock, ms: observed / created / opened. */
71884
- at: number().int().optional(),
71885
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
71886
- expiresAt: number().int().optional(),
71887
- data: RecordBodySchema
71888
- });
71889
- var RecordViewSchema = object({
71890
- id: string(),
71891
- deviceId: number().int().nullable(),
71892
- at: number().nullable(),
71893
- expiresAt: number().nullable(),
71894
- rev: number().int(),
71895
- updatedAt: number(),
71896
- data: RecordBodySchema
71897
- });
71898
- /** Declared index fields only. Anything else does not compile, by design. */
71899
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
71900
- string(),
71901
- number(),
71902
- boolean(),
71903
- object({ in: array(union([
71904
- string(),
71905
- number(),
71906
- boolean()
71907
- ])).min(1).max(RECORD_BATCH_MAX) }),
71908
- object({
71909
- gt: union([string(), number()]).optional(),
71910
- gte: union([string(), number()]).optional(),
71911
- lt: union([string(), number()]).optional(),
71912
- lte: union([string(), number()]).optional()
71913
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
71914
- ]));
71915
- var KindShape = { kind: RecordKindNameSchema };
71916
- var TimeWindowShape = {
71917
- deviceId: number().int().optional(),
71918
- atFrom: number().optional(),
71919
- atTo: number().optional()
71920
- };
71921
- var RecordQueryInputSchema = object({
71922
- ...KindShape,
71923
- ...TimeWindowShape,
71924
- where: RecordWhereSchema.optional(),
71925
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
71926
- order: _enum(["at", "id"]).optional(),
71927
- desc: boolean().optional(),
71928
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
71929
- /** Opaque keyset cursor from a previous answer. There is no offset. */
71930
- cursor: string().min(1).optional()
71931
- });
71932
- var RecordQueryResultSchema = object({
71933
- records: array(RecordViewSchema),
71934
- nextCursor: string().nullable()
71935
- });
71936
- var RecordKindStateSchema = _enum([
71937
- "created",
71938
- "unchanged",
71939
- "updated"
71940
- ]);
71941
- var DeclareKindResultSchema = object({
71942
- kindId: number().int(),
71943
- state: RecordKindStateSchema,
71944
- createdIndexes: array(string())
71945
- });
71946
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
71947
- var SecretRefsList = array(string());
71948
- /**
71949
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
71950
- * All ops of one call share ONE database file and ONE `transactFamily`.
71951
- */
71952
- var RecordTransactOpSchema = discriminatedUnion("op", [
71953
- object({
71954
- op: literal("put"),
71955
- kind: RecordKindNameSchema,
71956
- record: RecordInputSchema,
71957
- ifRev: number().int().min(0).optional()
71958
- }),
71959
- object({
71960
- op: literal("patch"),
71961
- kind: RecordKindNameSchema,
71962
- id: RecordIdSchema,
71963
- data: RecordBodySchema,
71964
- at: number().int().nullable().optional(),
71965
- expiresAt: number().int().nullable().optional(),
71966
- ifRev: number().int().min(1).optional()
71967
- }),
71968
- object({
71969
- op: literal("delete"),
71970
- kind: RecordKindNameSchema,
71971
- id: RecordIdSchema
71972
- })
71973
- ]);
71974
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
71975
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
71976
- kind: "mutation",
71977
- auth: "admin"
71978
- }), method(object({
71979
- ...KindShape,
71980
- id: RecordIdSchema
71981
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
71982
- ...KindShape,
71983
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
71984
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
71985
- ...KindShape,
71986
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
71987
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
71988
- ...KindShape,
71989
- record: RecordInputSchema,
71990
- /** Compare-and-set. `0` means "the row must not exist". */
71991
- ifRev: number().int().min(0).optional()
71992
- }), object({
71993
- rev: number().int(),
71994
- releasedRefs: SecretRefsList
71995
- }), {
71996
- kind: "mutation",
71997
- auth: "admin"
71998
- }), method(object({
71999
- ...KindShape,
72000
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72001
- }), object({
72002
- count: number().int(),
72003
- releasedRefs: SecretRefsList
72004
- }), {
72005
- kind: "mutation",
72006
- auth: "admin"
72007
- }), method(object({
72008
- ...KindShape,
72009
- id: RecordIdSchema,
72010
- data: RecordBodySchema,
72011
- at: number().int().nullable().optional(),
72012
- expiresAt: number().int().nullable().optional(),
72013
- ifRev: number().int().min(1).optional()
72014
- }), object({
72015
- rev: number().int(),
72016
- releasedRefs: SecretRefsList
72017
- }), {
72018
- kind: "mutation",
72019
- auth: "admin"
72020
- }), method(object({
72021
- ...KindShape,
72022
- id: RecordIdSchema
72023
- }), object({
72024
- deleted: boolean(),
72025
- secretRefs: SecretRefsList
72026
- }), {
72027
- kind: "mutation",
72028
- auth: "admin"
72029
- }), method(object({
72030
- ...KindShape,
72031
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72032
- }), object({
72033
- deleted: number().int(),
72034
- secretRefs: SecretRefsList
72035
- }), {
72036
- kind: "mutation",
72037
- auth: "admin"
72038
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72039
- ...KindShape,
72040
- ...TimeWindowShape,
72041
- where: RecordWhereSchema.optional()
72042
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72043
- ...KindShape,
72044
- deviceId: number().int().optional(),
72045
- from: number(),
72046
- to: number(),
72047
- bucketMs: number().int().positive()
72048
- }), object({ buckets: array(object({
72049
- bucketStart: number(),
72050
- count: number().int()
72051
- })) }), { auth: "admin" }), method(object({
72052
- ...KindShape,
72053
- op: _enum([
72054
- "sum",
72055
- "min",
72056
- "max",
72057
- "count"
72058
- ]),
72059
- field: RecordFieldPathSchema.optional(),
72060
- groupBy: RecordFieldPathSchema.optional(),
72061
- where: RecordWhereSchema.optional()
72062
- }), object({ rows: array(object({
72063
- group: union([
72064
- string(),
72065
- number(),
72066
- _null()
72067
- ]),
72068
- value: number().nullable()
72069
- })) }), { auth: "admin" }), method(object({
72070
- ...KindShape,
72071
- deviceId: number().int().optional(),
72072
- atBefore: number().optional(),
72073
- where: RecordWhereSchema.optional()
72074
- }), object({
72075
- deleted: number().int(),
72076
- secretRefs: SecretRefsList
72077
- }), {
72078
- kind: "mutation",
72079
- auth: "admin"
72080
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72081
- results: array(object({
72082
- rev: number().int().nullable(),
72083
- deleted: boolean()
72084
- })),
72085
- releasedRefs: SecretRefsList,
72086
- secretRefs: SecretRefsList
72087
- }), {
72088
- kind: "mutation",
72089
- auth: "admin"
72090
- }), method(object({
72091
- deviceId: number().int(),
72092
- kinds: array(RecordKindNameSchema).optional()
72093
- }), object({
72094
- deleted: record(string(), number().int()),
72095
- secretRefs: SecretRefsList
72096
- }), {
72097
- kind: "mutation",
72098
- auth: "admin"
72099
- }), method(object(KindShape), object({ id: number().int() }), {
72100
- kind: "mutation",
72101
- auth: "admin"
72102
- });
72103
- /**
72104
72244
  * record-entries - the ONE admin surface for every list of user-created entries
72105
72245
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72106
72246
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -81920,7 +82060,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81920
82060
  * `deviceClasses` map (first registered type). `null` when manual creation is
81921
82061
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
81922
82062
  */
81923
- async getManualCreationType() {
82063
+ async getManualCreationType(_input) {
81924
82064
  if (!await this.supportsManualCreation()) return { deviceType: null };
81925
82065
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
81926
82066
  }
@@ -81931,7 +82071,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81931
82071
  return true;
81932
82072
  }
81933
82073
  async getChildCreationSchema(input) {
81934
- return this.onGetCreationSchema(input.type);
82074
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
81935
82075
  }
81936
82076
  /**
81937
82077
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -81943,7 +82083,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81943
82083
  * `deviceClasses` instead.
81944
82084
  */
81945
82085
  async createDevice(input) {
81946
- const spec = await this.onCreateDevice(input.type, input.config);
82086
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
81947
82087
  const Class = this.deviceClasses[spec.meta.type];
81948
82088
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
81949
82089
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -83352,20 +83492,6 @@ Object.freeze({
83352
83492
  access: "create",
83353
83493
  role: "viewer"
83354
83494
  },
83355
- "broker.add": {
83356
- capName: "broker",
83357
- capScope: "system",
83358
- addonId: null,
83359
- access: "create",
83360
- role: "admin"
83361
- },
83362
- "broker.get": {
83363
- capName: "broker",
83364
- capScope: "system",
83365
- addonId: null,
83366
- access: "view",
83367
- role: "admin"
83368
- },
83369
83495
  "broker.getBrokerConfig": {
83370
83496
  capName: "broker",
83371
83497
  capScope: "system",
@@ -83373,20 +83499,6 @@ Object.freeze({
83373
83499
  access: "view",
83374
83500
  role: "admin"
83375
83501
  },
83376
- "broker.getSettings": {
83377
- capName: "broker",
83378
- capScope: "system",
83379
- addonId: null,
83380
- access: "view",
83381
- role: "admin"
83382
- },
83383
- "broker.getSettingsSchema": {
83384
- capName: "broker",
83385
- capScope: "system",
83386
- addonId: null,
83387
- access: "view",
83388
- role: "admin"
83389
- },
83390
83502
  "broker.getState": {
83391
83503
  capName: "broker",
83392
83504
  capScope: "system",
@@ -83401,20 +83513,6 @@ Object.freeze({
83401
83513
  access: "view",
83402
83514
  role: "admin"
83403
83515
  },
83404
- "broker.list": {
83405
- capName: "broker",
83406
- capScope: "system",
83407
- addonId: null,
83408
- access: "view",
83409
- role: "admin"
83410
- },
83411
- "broker.listProviders": {
83412
- capName: "broker",
83413
- capScope: "system",
83414
- addonId: null,
83415
- access: "view",
83416
- role: "admin"
83417
- },
83418
83516
  "broker.publish": {
83419
83517
  capName: "broker",
83420
83518
  capScope: "system",
@@ -83422,20 +83520,6 @@ Object.freeze({
83422
83520
  access: "create",
83423
83521
  role: "admin"
83424
83522
  },
83425
- "broker.remove": {
83426
- capName: "broker",
83427
- capScope: "system",
83428
- addonId: null,
83429
- access: "delete",
83430
- role: "admin"
83431
- },
83432
- "broker.setSettings": {
83433
- capName: "broker",
83434
- capScope: "system",
83435
- addonId: null,
83436
- access: "create",
83437
- role: "admin"
83438
- },
83439
83523
  "broker.subscribe": {
83440
83524
  capName: "broker",
83441
83525
  capScope: "system",
@@ -83443,20 +83527,6 @@ Object.freeze({
83443
83527
  access: "create",
83444
83528
  role: "admin"
83445
83529
  },
83446
- "broker.testConnection": {
83447
- capName: "broker",
83448
- capScope: "system",
83449
- addonId: null,
83450
- access: "create",
83451
- role: "admin"
83452
- },
83453
- "broker.testSettings": {
83454
- capName: "broker",
83455
- capScope: "system",
83456
- addonId: null,
83457
- access: "create",
83458
- role: "admin"
83459
- },
83460
83530
  "broker.unsubscribe": {
83461
83531
  capName: "broker",
83462
83532
  capScope: "system",
@@ -88420,6 +88490,13 @@ Object.freeze({
88420
88490
  access: "view",
88421
88491
  role: "viewer"
88422
88492
  },
88493
+ "pipelineAnalytics.getMediaLocationCensus": {
88494
+ capName: "pipeline-analytics",
88495
+ capScope: "device",
88496
+ addonId: null,
88497
+ access: "view",
88498
+ role: "admin"
88499
+ },
88423
88500
  "pipelineAnalytics.getMediaReclaimStatus": {
88424
88501
  capName: "pipeline-analytics",
88425
88502
  capScope: "device",
@@ -97486,6 +97563,74 @@ object({
97486
97563
  delay: number().nonnegative().optional(),
97487
97564
  commands: record(string(), unknown())
97488
97565
  });
97566
+ entryBody({ brokerId: string() });
97567
+ function secretsOverMigrationApi(api) {
97568
+ return {
97569
+ resolve: async (refs) => {
97570
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
97571
+ const out = {};
97572
+ for (const ref of refs) {
97573
+ const value = values[ref];
97574
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
97575
+ kind: "value",
97576
+ value,
97577
+ version: 0
97578
+ };
97579
+ }
97580
+ return out;
97581
+ },
97582
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
97583
+ };
97584
+ }
97585
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
97586
+ function recordsOverMigrationApi(api) {
97587
+ return { kind: (definition) => {
97588
+ const handle = api.records.kind(definition);
97589
+ return {
97590
+ get: (id) => handle.get({ id }),
97591
+ getResolved: (id) => handle.getResolved({ id }),
97592
+ put: (input, opts) => handle.put({
97593
+ ...input,
97594
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
97595
+ }),
97596
+ delete: (id) => handle.delete({ id })
97597
+ };
97598
+ } };
97599
+ }
97600
+ function integrationRowsApiOver(api) {
97601
+ return {
97602
+ list: async () => (await api.integrations.list({})).integrations,
97603
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
97604
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
97605
+ };
97606
+ }
97607
+ /**
97608
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
97609
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
97610
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
97611
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
97612
+ */
97613
+ var lanes = /* @__PURE__ */ new WeakMap();
97614
+ function deliver(api, send) {
97615
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
97616
+ const reason = error instanceof Error ? error.message : String(error);
97617
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
97618
+ });
97619
+ lanes.set(api, next);
97620
+ return next;
97621
+ }
97622
+ function warnOver(api) {
97623
+ return (message) => deliver(api, () => api.log.warn({ message }));
97624
+ }
97625
+ /** What the rows-to-records move needs, over the migration API. */
97626
+ function rowsDepsOver(api) {
97627
+ return {
97628
+ api: integrationRowsApiOver(api),
97629
+ records: recordsOverMigrationApi(api),
97630
+ secrets: secretsOverMigrationApi(api),
97631
+ warn: warnOver(api)
97632
+ };
97633
+ }
97489
97634
  //#endregion
97490
97635
  //#region src/config.ts
97491
97636
  /**
@@ -97556,7 +97701,7 @@ function connectionFromSettings(settings, tokenLocked) {
97556
97701
  function sameConnection(a, b) {
97557
97702
  return JSON.stringify(a) === JSON.stringify(b);
97558
97703
  }
97559
- /** The integration's settings form (`globalSettingsSchema`); the integration carries the name. */
97704
+ /** The integration instance form (the `formSchema` of its instances); the integration carries the name. */
97560
97705
  function buildConnectionFormSchema() {
97561
97706
  return { sections: [
97562
97707
  {
@@ -99254,18 +99399,15 @@ var EnpalProviderAddon = class extends BaseDeviceProvider {
99254
99399
  const records = this.ctx.records;
99255
99400
  if (records === void 0) throw new Error("provider-enpal: ctx.records is required (hub-only addon)");
99256
99401
  await records.declare(enpalRecordKinds);
99257
- await this.runMigrations(defineAddonMigrations([integrationRowsMigration({
99402
+ await this.runMigrations([integrationRowsMigration({
99258
99403
  addonId: this.addonId,
99259
99404
  date: ENPAL_MIGRATIONS_DATE,
99260
99405
  kind: enpalConnectionsEntryKind,
99261
99406
  fixtureMark: "host"
99262
- })], integrationRowsPortsOver({
99263
- api: defaultIntegrationApiOver(this.ctx.api),
99264
- secrets: this.ctx.secrets ?? null,
99265
- records,
99266
- kind: enpalConnectionsEntryKind,
99267
- warn: (message) => this.ctx.logger.warn(message)
99268
- })));
99407
+ })], (api) => integrationRowsPortsOver({
99408
+ ...rowsDepsOver(api),
99409
+ kind: enpalConnectionsEntryKind
99410
+ }));
99269
99411
  this.instances = buildEnpalInstances(records, { onChanged: () => this.reconcileIntegrations() });
99270
99412
  this.clients = new EnpalClientRegistry(this.ctx.logger, {
99271
99413
  onConnected: (integrationId) => this.setIntegrationDevicesOnline(integrationId, true),