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