@camstack/addon-provider-bosch 0.1.37 → 0.1.39

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.
@@ -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) {
@@ -13436,7 +13561,7 @@ var RecordIntegrationInstances = class {
13436
13561
  return record === null ? null : this.viewOf(record);
13437
13562
  };
13438
13563
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13439
- createInstance = async ({ id, name, kind }) => {
13564
+ createInstance = async ({ id, name, kind, values }) => {
13440
13565
  const minted = id ?? this.hooks.mintId?.({
13441
13566
  name,
13442
13567
  ...kind !== void 0 ? { kind } : {}
@@ -13446,10 +13571,20 @@ var RecordIntegrationInstances = class {
13446
13571
  id: minted,
13447
13572
  data: this.hooks.initialBody(name, kind)
13448
13573
  }, { ifRev: 0 });
13574
+ const patch = this.patchOf(values ?? {});
13575
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13449
13576
  await this.hooks.onChanged?.(minted, "created");
13450
13577
  return { id: minted };
13451
13578
  };
13452
13579
  updateInstance = async ({ id, name, values }) => {
13580
+ const patch = this.patchOf(values);
13581
+ if (name !== void 0) patch[this.nameField] = name;
13582
+ await this.handle.patch(id, patch);
13583
+ await this.hooks.onChanged?.(id, "updated");
13584
+ return { ok: true };
13585
+ };
13586
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13587
+ patchOf(values) {
13453
13588
  const patch = {};
13454
13589
  for (const [key, value] of Object.entries(values)) {
13455
13590
  if (value === void 0) continue;
@@ -13460,11 +13595,8 @@ var RecordIntegrationInstances = class {
13460
13595
  else if (isSecretClear(value)) patch[key] = null;
13461
13596
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13462
13597
  }
13463
- if (name !== void 0) patch[this.nameField] = name;
13464
- await this.handle.patch(id, patch);
13465
- await this.hooks.onChanged?.(id, "updated");
13466
- return { ok: true };
13467
- };
13598
+ return patch;
13599
+ }
13468
13600
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13469
13601
  setInstanceEnabled = async ({ id, enabled }) => {
13470
13602
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14709,25 +14841,6 @@ function integrationRowsPortsOverApi(deps) {
14709
14841
  }
14710
14842
  };
14711
14843
  }
14712
- function defaultIntegrationApiOver(api) {
14713
- return {
14714
- list: () => api.integrations.list.query(),
14715
- readLegacyIntegrationRows: (input) => api.migrations.readLegacyIntegrationRows.query(input),
14716
- clearLegacyIntegrationRows: (input) => api.migrations.clearLegacyIntegrationRows.mutate(input),
14717
- listDevices: (addonId) => api.deviceManager.listAll.query({
14718
- addonId,
14719
- projection: "slim"
14720
- }),
14721
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14722
- await api.deviceManager.setIntegrationId.mutate({
14723
- deviceId,
14724
- integrationId
14725
- });
14726
- },
14727
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14728
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14729
- };
14730
- }
14731
14844
  /**
14732
14845
  * The trainer contract — what the hub hands the cloud trainer and what it
14733
14846
  * gets back (cloud training, D805+).
@@ -15816,6 +15929,39 @@ var UnstampedEventMediaCountSchema = object({
15816
15929
  /** Sum across both, or `null` when either lane could not be counted. */
15817
15930
  total: number().int().nonnegative().nullable()
15818
15931
  }).nullable();
15932
+ /**
15933
+ * Where the stored event media sits, per storage location: how many media rows
15934
+ * and how many bytes carry each location id, how many carry none (legacy,
15935
+ * resolved to the default `eventMedia` location), and how many name a location
15936
+ * that was not asked about (a deleted or never-listed one).
15937
+ *
15938
+ * One covering-index aggregate per asked location plus the NULL one, and one
15939
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
15940
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
15941
+ * it is a deleted location only when every location id was asked.
15942
+ * `null` is "could not be measured", never zero.
15943
+ */
15944
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
15945
+ var MediaLocationCensusSchema = object({
15946
+ locations: array(object({
15947
+ locationId: string(),
15948
+ rows: number().int().nonnegative(),
15949
+ bytes: number().nonnegative()
15950
+ })).readonly(),
15951
+ unstamped: object({
15952
+ rows: number().int().nonnegative(),
15953
+ bytes: number().nonnegative()
15954
+ }),
15955
+ /** Rows stamped with a location id that was not in the asked list. */
15956
+ unlisted: object({
15957
+ rows: number().int().nonnegative(),
15958
+ bytes: number().nonnegative()
15959
+ }),
15960
+ total: object({
15961
+ rows: number().int().nonnegative(),
15962
+ bytes: number().nonnegative()
15963
+ })
15964
+ });
15819
15965
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
15820
15966
  /** The independently selectable logical storage classes — every class
15821
15967
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -46931,52 +47077,7 @@ onBrightnessChanged: { data: object({
46931
47077
  minIntervalMs: 0
46932
47078
  } } }
46933
47079
  };
46934
- /**
46935
- * `broker` — unified pub/sub broker registry, system-scoped collection.
46936
- *
46937
- * The cap models any kind-tagged message broker the user wants to
46938
- * register and that other addons might consume. The first two kinds
46939
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
46940
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
46941
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
46942
- * the same surface.
46943
- *
46944
- * Why one cap, not one cap per kind:
46945
- * - The integrations page wants a single table of "every broker"
46946
- * across kinds; a unified cap drives it without join logic.
46947
- * - Generic admin operations (add / remove / test / status) are
46948
- * identical across kinds — duplicating them per cap was busywork.
46949
- * - The `network-access` cap precedent: same interface, many
46950
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
46951
- *
46952
- * What stays kind-specific:
46953
- * - `getBrokerConfig` payload (kind decides whether it returns
46954
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
46955
- * `Record<string, unknown>` at the wire; consumers narrow.
46956
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
46957
- * key) — also typed as `Record<string, unknown>` so each kind can
46958
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
46959
- * without rebreaking the cap signature.
46960
- * - `add` `settings` payload (different fields per kind, validated by
46961
- * the kind-specific provider).
46962
- *
46963
- * Bidirectionality:
46964
- * - `publish` is RPC — synchronous result (provider-defined).
46965
- * - `subscribe` returns a subscription handle; the actual message
46966
- * stream flows over the typed event-bus as `broker.message` events
46967
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
46968
- * event handler. Subscriptions persist across reconnects — the
46969
- * provider re-subscribes upstream after a transport drop.
46970
- *
46971
- * Why event-bus push (not a subscription RPC stream):
46972
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
46973
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
46974
- * drop is recoverable via `getState({key})`).
46975
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
46976
- * - Cross-process: events already route through `$event-bus`; no
46977
- * per-broker wire-shaping needed.
46978
- */
46979
- var BrokerStatusEnum = _enum([
47080
+ _enum([
46980
47081
  "connected",
46981
47082
  "disconnected",
46982
47083
  "connecting",
@@ -46984,141 +47085,12 @@ var BrokerStatusEnum = _enum([
46984
47085
  "unreachable",
46985
47086
  "error"
46986
47087
  ]);
46987
- var BrokerInfoSchema = object({
46988
- /** Stable broker id. Persisted; survives addon restarts. */
46989
- id: string(),
46990
- /** Addon id of the provider that OWNS this broker.
46991
- *
46992
- * The `broker` cap is a system-scoped collection: several addons
46993
- * register a `broker` provider, each owning a DISJOINT set of
46994
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
46995
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
46996
- * device belongs to one integration. The admin UI threads this id
46997
- * back as the `{ addonId }` system-collection selector on every
46998
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
46999
- * `testConnection`), so the call routes to the OWNING provider
47000
- * instead of defaulting to the first-registered one. */
47001
- addonId: string(),
47002
- /** Human-readable name (operator-chosen at add-time). */
47003
- name: string(),
47004
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47005
- kind: string(),
47006
- status: BrokerStatusEnum,
47007
- /** Free-form provider-specific info (HA version, MQTT broker
47008
- * flavour, latency, mTLS active, …). */
47009
- info: record(string(), unknown()),
47010
- /** Ms epoch of the last connection probe / status update. */
47011
- lastCheckedAt: number().nullable(),
47012
- /** Last error message, when `status` indicates failure. */
47013
- error: string().nullable()
47014
- });
47015
47088
  var RegistryStatusSchema = object({
47016
47089
  brokerCount: number().int().nonnegative(),
47017
47090
  connectedCount: number().int().nonnegative()
47018
47091
  });
47019
- /**
47020
- * One entry per `broker` provider — which addon provides which broker
47021
- * kind(s). The unified create picker reads this to know, for each
47022
- * (addonId, kind) pair the operator can pick, where to route the
47023
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47024
- * `{ addonId }` selector). A provider only advertises a kind here when
47025
- * it implements `getSettingsSchema` for that kind (so the picker never
47026
- * offers a kind whose creation form can't be rendered).
47027
- */
47028
- var BrokerProviderInfoSchema = object({
47029
- /** Addon id of the `broker` provider this entry describes. */
47030
- addonId: string(),
47031
- /** Broker kinds this provider can create, with a display label. */
47032
- kinds: array(object({
47033
- kind: string(),
47034
- label: string(),
47035
- /**
47036
- * Relative hub path to start an interactive account link (OAuth popup).
47037
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47038
- */
47039
- interactiveConnectPath: string().min(1).optional(),
47040
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47041
- interactiveDisconnectPath: string().min(1).optional(),
47042
- /**
47043
- * The kind signs in through a server-held interactive session instead of
47044
- * (or before) typed credentials. `basePath` is a hub-relative route set
47045
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47046
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47047
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47048
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47049
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47050
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47051
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47052
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47053
- * offers it as the default path; the fields the session fills are
47054
- * marked `filledBySignIn` in the kind's settings schema.
47055
- *
47056
- * `methods` lists the ways the session can sign in, recommended first:
47057
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47058
- * settings) answering `{ sessionId, userCode, verificationUrl,
47059
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47060
- * any device, and the same `status` / `commit` / `cancel` routes follow
47061
- * (status then carries `method`, `userCode`, `verificationUrl`,
47062
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47063
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47064
- * `['proxy']`.
47065
- */
47066
- signIn: object({
47067
- basePath: string().min(1),
47068
- methods: array(_enum(["device-code", "proxy"])).optional()
47069
- }).optional()
47070
- }))
47071
- });
47072
- var ListInputSchema = object({
47073
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47074
- * only HA brokers. Omit to list every broker. */
47075
- kind: string().optional() });
47076
47092
  var GetInputSchema = object({ id: string() });
47077
- var AddInputSchema = object({
47078
- kind: string().min(1),
47079
- name: string().min(1),
47080
- /**
47081
- * ADOPT an existing id instead of minting a new one.
47082
- *
47083
- * Written the day this cost an outage. A broker's id is not a detail: HA
47084
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47085
- * lost from config and re-added as `ha_001` leaves every one of its devices
47086
- * bound to a broker that no longer exists. Re-entering the password under the
47087
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47088
- * password.
47089
- *
47090
- * A provider MUST refuse an id that is already in use — adopting a live
47091
- * broker's id would silently take it over.
47092
- */
47093
- id: string().min(1).optional(),
47094
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47095
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47096
- * branch on receipt — invalid shape rejects the add. */
47097
- settings: record(string(), unknown())
47098
- });
47099
- var AddResultSchema = object({ id: string() });
47100
- var RemoveInputSchema = object({ id: string() });
47101
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47102
- ok: literal(true),
47103
- latencyMs: number().nonnegative()
47104
- }), object({
47105
- ok: literal(false),
47106
- error: string()
47107
- })]);
47108
47093
  var SettingsRecordSchema$1 = record(string(), unknown());
47109
- var SettingsSchemaInputSchema = object({ kind: string() });
47110
- var TestSettingsInputSchema = object({
47111
- kind: string(),
47112
- settings: SettingsRecordSchema$1
47113
- });
47114
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47115
- ok: literal(true),
47116
- latencyMs: number().nonnegative().optional()
47117
- }).strict(), object({
47118
- ok: literal(false),
47119
- error: string()
47120
- })]);
47121
- var SettingsSchemaResultSchema = unknown().nullable();
47122
47094
  var PublishInputSchema = object({
47123
47095
  brokerId: string(),
47124
47096
  /** Kind-specific routing target.
@@ -47152,25 +47124,7 @@ var GetStateInputSchema = object({
47152
47124
  * HA: entity_id (returns the cached entity state). */
47153
47125
  key: string()
47154
47126
  });
47155
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47156
- kind: "mutation",
47157
- auth: "admin"
47158
- }), method(RemoveInputSchema, _void(), {
47159
- kind: "mutation",
47160
- auth: "admin"
47161
- }), method(GetInputSchema, TestConnectionResultSchema, {
47162
- kind: "mutation",
47163
- auth: "admin"
47164
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47165
- id: string(),
47166
- settings: SettingsRecordSchema$1
47167
- }), _void(), {
47168
- kind: "mutation",
47169
- auth: "admin"
47170
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47171
- kind: "mutation",
47172
- auth: "admin"
47173
- }), method(PublishInputSchema, unknown(), {
47127
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47174
47128
  kind: "mutation",
47175
47129
  auth: "admin"
47176
47130
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -51995,7 +51949,14 @@ var DiscoveryCandidateSchema = object({
51995
51949
  /** `stableId` of the gateway candidate this device was found BEHIND. */
51996
51950
  parentStableId: string().optional(),
51997
51951
  /** `false` = shown for context but not pickable. Default true. */
51998
- selectable: boolean().optional()
51952
+ selectable: boolean().optional(),
51953
+ /**
51954
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
51955
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
51956
+ * admin asks for exactly these, on the creation form prefilled with
51957
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
51958
+ */
51959
+ needsParams: array(string()).optional()
51999
51960
  });
52000
51961
  /**
52001
51962
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52122,8 +52083,14 @@ var deviceProviderCapability = {
52122
52083
  * provider does not support manual creation. Lets the Add-Device dialog
52123
52084
  * pick the right type instead of assuming Camera.
52124
52085
  */
52125
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52126
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52086
+ getManualCreationType: method(object({
52087
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52088
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52089
+ adoptDiscoveredDevice: method(object({
52090
+ candidate: DiscoveryCandidateSchema,
52091
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52092
+ integrationId: string().optional()
52093
+ }), DeviceSummarySchema, {
52127
52094
  kind: "mutation",
52128
52095
  auth: "admin"
52129
52096
  }),
@@ -52134,10 +52101,16 @@ var deviceProviderCapability = {
52134
52101
  * devices of that type. The output is a `ConfigUISchema` — the
52135
52102
  * router type-asserts it at the boundary.
52136
52103
  */
52137
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52104
+ getChildCreationSchema: method(object({
52105
+ type: _enum(DeviceType),
52106
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52107
+ integrationId: string().optional()
52108
+ }), CreationSchemaOutputSchema),
52138
52109
  createDevice: method(object({
52139
52110
  type: _enum(DeviceType),
52140
- config: record(string(), unknown())
52111
+ config: record(string(), unknown()),
52112
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52113
+ integrationId: string().optional()
52141
52114
  }), DeviceSummarySchema, {
52142
52115
  kind: "mutation",
52143
52116
  auth: "admin"
@@ -52862,7 +52835,10 @@ method(object({
52862
52835
  auth: "admin"
52863
52836
  }), method(object({
52864
52837
  addonId: string(),
52865
- type: _enum(DeviceType)
52838
+ type: _enum(DeviceType),
52839
+ /** The integration the form is for; a provider whose integrations differ (a hub
52840
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
52841
+ integrationId: string().optional()
52866
52842
  }), unknown().nullable()), method(object({
52867
52843
  addonId: string(),
52868
52844
  type: _enum(DeviceType),
@@ -52946,7 +52922,11 @@ method(object({
52946
52922
  kind: "mutation",
52947
52923
  auth: "admin",
52948
52924
  timeoutMs: 12e4
52949
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
52925
+ }), method(object({
52926
+ addonId: string(),
52927
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
52928
+ integrationId: string().optional()
52929
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
52950
52930
  deviceId: number(),
52951
52931
  key: string(),
52952
52932
  value: unknown()
@@ -56226,7 +56206,7 @@ var TestConnectionStatusEnum = _enum([
56226
56206
  "inconclusive",
56227
56207
  "unsupported"
56228
56208
  ]);
56229
- var TestConnectionResultSchema$1 = object({
56209
+ var TestConnectionResultSchema = object({
56230
56210
  /** True ONLY for `validated`. Never true for a test that did not run. */
56231
56211
  success: boolean(),
56232
56212
  error: string().optional(),
@@ -56271,7 +56251,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56271
56251
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56272
56252
  addonId: string(),
56273
56253
  settings: record(string(), unknown())
56274
- }), TestConnectionResultSchema$1, {
56254
+ }), TestConnectionResultSchema, {
56275
56255
  kind: "mutation",
56276
56256
  auth: "admin"
56277
56257
  });
@@ -56298,6 +56278,14 @@ var ConfigSchemaPassthrough$3 = custom();
56298
56278
  var IntegrationInstanceIdSchema = string().min(1);
56299
56279
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56300
56280
  /**
56281
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56282
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56283
+ * `services`: a connection configured from the addon's own function page, never listed on
56284
+ * Integrations.
56285
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56286
+ */
56287
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56288
+ /**
56301
56289
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56302
56290
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56303
56291
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56308,6 +56296,22 @@ var IntegrationInstanceKindSchema = object({
56308
56296
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56309
56297
  id: string().min(1),
56310
56298
  label: string().min(1),
56299
+ /**
56300
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56301
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56302
+ * provider with more than one section must name it on every kind.
56303
+ */
56304
+ functionCap: string().min(1),
56305
+ /**
56306
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56307
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56308
+ * finds the instances whose kind names it; absent takes the kind `id`.
56309
+ */
56310
+ brokerKind: string().min(1).optional(),
56311
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56312
+ role: IntegrationInstanceRoleSchema.optional(),
56313
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56314
+ canTest: boolean().optional(),
56311
56315
  /** The kind signs in through a server-held interactive session. */
56312
56316
  signIn: object({
56313
56317
  basePath: string().min(1),
@@ -56320,11 +56324,7 @@ var IntegrationInstanceKindSchema = object({
56320
56324
  });
56321
56325
  var IntegrationInstanceDescriptionSchema = object({
56322
56326
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56323
- role: _enum([
56324
- "devices",
56325
- "services",
56326
- "both"
56327
- ]),
56327
+ role: IntegrationInstanceRoleSchema,
56328
56328
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56329
56329
  discovery: object({
56330
56330
  mode: _enum([
@@ -56399,7 +56399,11 @@ var integrationInstancesCapability = {
56399
56399
  methods: {
56400
56400
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56401
56401
  /** The form; `id: null` is the create form. */
56402
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56402
+ instanceFormSchema: method(object({
56403
+ id: IntegrationInstanceIdSchema.nullable(),
56404
+ /** The kind of the create form (`id: null`) of a provider with several. */
56405
+ kind: string().min(1).optional()
56406
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56403
56407
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56404
56408
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56405
56409
  /**
@@ -56409,7 +56413,9 @@ var integrationInstancesCapability = {
56409
56413
  createInstance: method(object({
56410
56414
  id: IntegrationInstanceIdSchema.optional(),
56411
56415
  name: string().min(1),
56412
- kind: string().min(1).optional()
56416
+ kind: string().min(1).optional(),
56417
+ /** Form values written with the record (a link picked in the create dialog). */
56418
+ values: record(string(), unknown()).optional()
56413
56419
  }), object({ id: string() }), {
56414
56420
  kind: "mutation",
56415
56421
  auth: "admin"
@@ -56436,8 +56442,10 @@ var integrationInstancesCapability = {
56436
56442
  }),
56437
56443
  testInstance: optionalMethod(object({
56438
56444
  id: IntegrationInstanceIdSchema.nullable(),
56439
- values: record(string(), unknown())
56440
- }), TestConnectionResultSchema$1, {
56445
+ values: record(string(), unknown()),
56446
+ /** The kind to test when `id` is null and the provider has several. */
56447
+ kind: string().min(1).optional()
56448
+ }), TestConnectionResultSchema, {
56441
56449
  kind: "mutation",
56442
56450
  auth: "admin"
56443
56451
  })
@@ -59194,6 +59202,380 @@ var SystemMetricsSchema = object({
59194
59202
  gpuMemoryPercent: number().optional()
59195
59203
  });
59196
59204
  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);
59205
+ /**
59206
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59207
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59208
+ * (operator intent, D870) and device-history (numbers over time, D850).
59209
+ *
59210
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59211
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59212
+ * that with the addon id closed over). It is deliberately NOT in any input
59213
+ * schema, so a session can never supply it, and a call with no stamp is refused
59214
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59215
+ * addons go through the owner's capability.
59216
+ *
59217
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59218
+ * never `[]`. Secret fields are never on the wire: a read shows the
59219
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59220
+ * resolves itself, and a write may carry only a keychain marker bound to the
59221
+ * row's own ref.
59222
+ *
59223
+ * Internal: addons reach it through `ctx.records`, never directly.
59224
+ */
59225
+ var RecordIdSchema = string().min(1).max(256);
59226
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59227
+ var RecordBodySchema = record(string(), unknown());
59228
+ var RecordInputSchema = object({
59229
+ id: RecordIdSchema,
59230
+ /** The device this row belongs to (D865 removal, per-device reads). */
59231
+ deviceId: number().int().optional(),
59232
+ /** The domain clock, ms: observed / created / opened. */
59233
+ at: number().int().optional(),
59234
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59235
+ expiresAt: number().int().optional(),
59236
+ data: RecordBodySchema
59237
+ });
59238
+ var RecordViewSchema = object({
59239
+ id: string(),
59240
+ deviceId: number().int().nullable(),
59241
+ at: number().nullable(),
59242
+ expiresAt: number().nullable(),
59243
+ rev: number().int(),
59244
+ updatedAt: number(),
59245
+ data: RecordBodySchema
59246
+ });
59247
+ /** Declared index fields only. Anything else does not compile, by design. */
59248
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59249
+ string(),
59250
+ number(),
59251
+ boolean(),
59252
+ object({ in: array(union([
59253
+ string(),
59254
+ number(),
59255
+ boolean()
59256
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59257
+ object({
59258
+ gt: union([string(), number()]).optional(),
59259
+ gte: union([string(), number()]).optional(),
59260
+ lt: union([string(), number()]).optional(),
59261
+ lte: union([string(), number()]).optional()
59262
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59263
+ ]));
59264
+ var KindShape = { kind: RecordKindNameSchema };
59265
+ var TimeWindowShape = {
59266
+ deviceId: number().int().optional(),
59267
+ atFrom: number().optional(),
59268
+ atTo: number().optional()
59269
+ };
59270
+ var RecordQueryInputSchema = object({
59271
+ ...KindShape,
59272
+ ...TimeWindowShape,
59273
+ where: RecordWhereSchema.optional(),
59274
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59275
+ order: _enum(["at", "id"]).optional(),
59276
+ desc: boolean().optional(),
59277
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59278
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59279
+ cursor: string().min(1).optional()
59280
+ });
59281
+ var RecordQueryResultSchema = object({
59282
+ records: array(RecordViewSchema),
59283
+ nextCursor: string().nullable()
59284
+ });
59285
+ var RecordKindStateSchema = _enum([
59286
+ "created",
59287
+ "unchanged",
59288
+ "updated"
59289
+ ]);
59290
+ var DeclareKindResultSchema = object({
59291
+ kindId: number().int(),
59292
+ state: RecordKindStateSchema,
59293
+ createdIndexes: array(string())
59294
+ });
59295
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59296
+ var SecretRefsList = array(string());
59297
+ /**
59298
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59299
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59300
+ */
59301
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59302
+ object({
59303
+ op: literal("put"),
59304
+ kind: RecordKindNameSchema,
59305
+ record: RecordInputSchema,
59306
+ ifRev: number().int().min(0).optional()
59307
+ }),
59308
+ object({
59309
+ op: literal("patch"),
59310
+ kind: RecordKindNameSchema,
59311
+ id: RecordIdSchema,
59312
+ data: RecordBodySchema,
59313
+ at: number().int().nullable().optional(),
59314
+ expiresAt: number().int().nullable().optional(),
59315
+ ifRev: number().int().min(1).optional()
59316
+ }),
59317
+ object({
59318
+ op: literal("delete"),
59319
+ kind: RecordKindNameSchema,
59320
+ id: RecordIdSchema
59321
+ })
59322
+ ]);
59323
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59324
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59325
+ kind: "mutation",
59326
+ auth: "admin"
59327
+ }), method(object({
59328
+ ...KindShape,
59329
+ id: RecordIdSchema
59330
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59331
+ ...KindShape,
59332
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59333
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59334
+ ...KindShape,
59335
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59336
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59337
+ ...KindShape,
59338
+ record: RecordInputSchema,
59339
+ /** Compare-and-set. `0` means "the row must not exist". */
59340
+ ifRev: number().int().min(0).optional()
59341
+ }), object({
59342
+ rev: number().int(),
59343
+ releasedRefs: SecretRefsList
59344
+ }), {
59345
+ kind: "mutation",
59346
+ auth: "admin"
59347
+ }), method(object({
59348
+ ...KindShape,
59349
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59350
+ }), object({
59351
+ count: number().int(),
59352
+ releasedRefs: SecretRefsList
59353
+ }), {
59354
+ kind: "mutation",
59355
+ auth: "admin"
59356
+ }), method(object({
59357
+ ...KindShape,
59358
+ id: RecordIdSchema,
59359
+ data: RecordBodySchema,
59360
+ at: number().int().nullable().optional(),
59361
+ expiresAt: number().int().nullable().optional(),
59362
+ ifRev: number().int().min(1).optional()
59363
+ }), object({
59364
+ rev: number().int(),
59365
+ releasedRefs: SecretRefsList
59366
+ }), {
59367
+ kind: "mutation",
59368
+ auth: "admin"
59369
+ }), method(object({
59370
+ ...KindShape,
59371
+ id: RecordIdSchema
59372
+ }), object({
59373
+ deleted: boolean(),
59374
+ secretRefs: SecretRefsList
59375
+ }), {
59376
+ kind: "mutation",
59377
+ auth: "admin"
59378
+ }), method(object({
59379
+ ...KindShape,
59380
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59381
+ }), object({
59382
+ deleted: number().int(),
59383
+ secretRefs: SecretRefsList
59384
+ }), {
59385
+ kind: "mutation",
59386
+ auth: "admin"
59387
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59388
+ ...KindShape,
59389
+ ...TimeWindowShape,
59390
+ where: RecordWhereSchema.optional()
59391
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59392
+ ...KindShape,
59393
+ deviceId: number().int().optional(),
59394
+ from: number(),
59395
+ to: number(),
59396
+ bucketMs: number().int().positive()
59397
+ }), object({ buckets: array(object({
59398
+ bucketStart: number(),
59399
+ count: number().int()
59400
+ })) }), { auth: "admin" }), method(object({
59401
+ ...KindShape,
59402
+ op: _enum([
59403
+ "sum",
59404
+ "min",
59405
+ "max",
59406
+ "count"
59407
+ ]),
59408
+ field: RecordFieldPathSchema.optional(),
59409
+ groupBy: RecordFieldPathSchema.optional(),
59410
+ where: RecordWhereSchema.optional()
59411
+ }), object({ rows: array(object({
59412
+ group: union([
59413
+ string(),
59414
+ number(),
59415
+ _null()
59416
+ ]),
59417
+ value: number().nullable()
59418
+ })) }), { auth: "admin" }), method(object({
59419
+ ...KindShape,
59420
+ deviceId: number().int().optional(),
59421
+ atBefore: number().optional(),
59422
+ where: RecordWhereSchema.optional()
59423
+ }), object({
59424
+ deleted: number().int(),
59425
+ secretRefs: SecretRefsList
59426
+ }), {
59427
+ kind: "mutation",
59428
+ auth: "admin"
59429
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59430
+ results: array(object({
59431
+ rev: number().int().nullable(),
59432
+ deleted: boolean()
59433
+ })),
59434
+ releasedRefs: SecretRefsList,
59435
+ secretRefs: SecretRefsList
59436
+ }), {
59437
+ kind: "mutation",
59438
+ auth: "admin"
59439
+ }), method(object({
59440
+ deviceId: number().int(),
59441
+ kinds: array(RecordKindNameSchema).optional()
59442
+ }), object({
59443
+ deleted: record(string(), number().int()),
59444
+ secretRefs: SecretRefsList
59445
+ }), {
59446
+ kind: "mutation",
59447
+ auth: "admin"
59448
+ }), method(object(KindShape), object({ id: number().int() }), {
59449
+ kind: "mutation",
59450
+ auth: "admin"
59451
+ });
59452
+ /**
59453
+ * The wire shapes of the migration API, version 1 (planning#447).
59454
+ *
59455
+ * A migration is code that outlives the server it was written against: an addon at
59456
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59457
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59458
+ * is the contract of every method of it, one Zod pair per method.
59459
+ *
59460
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59461
+ * field is never removed or made required, an enum never narrows, an output field is
59462
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59463
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59464
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59465
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59466
+ */
59467
+ var Rows = record(string(), unknown());
59468
+ var IntegrationId = object({ integrationId: string().min(1) });
59469
+ var RecordId = object({ id: string().min(1) });
59470
+ var RecordRowSchema = object({
59471
+ id: string(),
59472
+ deviceId: number().int().nullable(),
59473
+ at: number().nullable(),
59474
+ expiresAt: number().nullable(),
59475
+ rev: number().int(),
59476
+ updatedAt: number(),
59477
+ data: Rows
59478
+ });
59479
+ var RecordPutShape = {
59480
+ id: string().min(1),
59481
+ deviceId: number().int().optional(),
59482
+ at: number().int().optional(),
59483
+ expiresAt: number().int().optional(),
59484
+ data: Rows
59485
+ };
59486
+ var MigrationIntegrationSchema = object({
59487
+ id: string(),
59488
+ addonId: string(),
59489
+ name: string(),
59490
+ info: Rows,
59491
+ originStableId: string().optional()
59492
+ });
59493
+ var MigrationDeviceSchema = object({
59494
+ id: number().int(),
59495
+ integrationId: string().nullable().optional(),
59496
+ /** The owning device; null or absent for a root. */
59497
+ parentDeviceId: number().int().nullable().optional(),
59498
+ type: string().optional(),
59499
+ name: string().optional(),
59500
+ stableId: string().optional()
59501
+ });
59502
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59503
+ var MigrationApiInfoSchema = object({
59504
+ version: number().int(),
59505
+ methods: array(string())
59506
+ });
59507
+ object({
59508
+ message: string(),
59509
+ meta: Rows.optional(),
59510
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59511
+ tags: object({ deviceId: number().int().optional() }).optional()
59512
+ });
59513
+ object({
59514
+ owner: string().min(1),
59515
+ metas: array(MigrationMetaSchema)
59516
+ }), object({
59517
+ bootId: string(),
59518
+ snapshot: _enum([
59519
+ "none",
59520
+ "written",
59521
+ "refused"
59522
+ ]),
59523
+ steps: array(MigrationOwnerStepSchema),
59524
+ /** The migration API the engine serves; absent from a server that predates it. */
59525
+ migrationApi: MigrationApiInfoSchema.optional()
59526
+ }), object({ id: string().min(1) }), object({
59527
+ proceed: boolean(),
59528
+ state: union([literal("pending"), MigrationStatusSchema]),
59529
+ reason: string().nullable()
59530
+ }), object({
59531
+ id: string().min(1),
59532
+ result: MigrationOwnerResultSchema
59533
+ }), object({
59534
+ status: MigrationStatusSchema,
59535
+ error: string().nullable(),
59536
+ rowsChanged: number().int().nonnegative()
59537
+ }), object({
59538
+ rows: number().int().nonnegative(),
59539
+ secrets: number().int().nonnegative()
59540
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59541
+ present: boolean(),
59542
+ removed: Rows
59543
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
59544
+ ...RecordPutShape,
59545
+ ifRev: number().int().optional()
59546
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
59547
+ partial: Rows,
59548
+ ifRev: number().int().optional()
59549
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
59550
+ deviceId: number().int().optional(),
59551
+ atFrom: number().optional(),
59552
+ atTo: number().optional(),
59553
+ where: RecordWhereSchema.optional(),
59554
+ limit: number().int().min(1).optional(),
59555
+ cursor: string().min(1).optional(),
59556
+ resolveSecrets: boolean().optional()
59557
+ }), object({
59558
+ records: array(RecordRowSchema),
59559
+ nextCursor: string().nullable()
59560
+ }), object({
59561
+ deviceId: number().int().optional(),
59562
+ atBefore: number().optional(),
59563
+ where: RecordWhereSchema.optional()
59564
+ }), 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({
59565
+ ref: string().min(1),
59566
+ value: string()
59567
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
59568
+ addonId: string().min(1),
59569
+ integrationId: string().min(1).optional()
59570
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
59571
+ id: number().int(),
59572
+ integrationId: string().nullable(),
59573
+ /** Whether the device carries any stored config; its content is not offered. */
59574
+ hasConfig: boolean()
59575
+ }).nullable(), object({
59576
+ deviceId: number().int(),
59577
+ integrationId: string().min(1)
59578
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59197
59579
  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({
59198
59580
  id: string().min(1),
59199
59581
  error: string().min(1)
@@ -59223,7 +59605,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59223
59605
  "written",
59224
59606
  "refused"
59225
59607
  ]),
59226
- steps: array(MigrationOwnerStepSchema)
59608
+ steps: array(MigrationOwnerStepSchema),
59609
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
59610
+ migrationApi: MigrationApiInfoSchema.optional()
59227
59611
  }), {
59228
59612
  kind: "mutation",
59229
59613
  auth: "admin"
@@ -61890,7 +62274,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
61890
62274
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
61891
62275
  kind: "mutation",
61892
62276
  auth: "admin"
61893
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62277
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62278
+ kind: "query",
62279
+ auth: "admin"
62280
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
61894
62281
  kind: "query",
61895
62282
  auth: "admin"
61896
62283
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64545,7 +64932,7 @@ var BrokerStatusSchema$1 = _enum([
64545
64932
  "unreachable",
64546
64933
  "tls-error"
64547
64934
  ]);
64548
- var BrokerInfoSchema$1 = object({
64935
+ var BrokerInfoSchema = object({
64549
64936
  id: string(),
64550
64937
  name: string(),
64551
64938
  url: string(),
@@ -64608,7 +64995,7 @@ var StatusSchema = object({
64608
64995
  brokerCount: number(),
64609
64996
  embeddedRunning: boolean()
64610
64997
  });
64611
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64998
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64612
64999
  kind: "mutation",
64613
65000
  auth: "admin"
64614
65001
  }), method(IdInputSchema, _void(), {
@@ -71790,253 +72177,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, DeviceType.Gateway, met
71790
72177
  auth: "admin"
71791
72178
  });
71792
72179
  /**
71793
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
71794
- * config documents, mirrors. The third storage API next to `ctx.settings`
71795
- * (operator intent, D870) and device-history (numbers over time, D850).
71796
- *
71797
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
71798
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
71799
- * that with the addon id closed over). It is deliberately NOT in any input
71800
- * schema, so a session can never supply it, and a call with no stamp is refused
71801
- * `records/no-caller`. A kind is readable and writable only by its owner; other
71802
- * addons go through the owner's capability.
71803
- *
71804
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
71805
- * never `[]`. Secret fields are never on the wire: a read shows the
71806
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
71807
- * resolves itself, and a write may carry only a keychain marker bound to the
71808
- * row's own ref.
71809
- *
71810
- * Internal: addons reach it through `ctx.records`, never directly.
71811
- */
71812
- var RecordIdSchema = string().min(1).max(256);
71813
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
71814
- var RecordBodySchema = record(string(), unknown());
71815
- var RecordInputSchema = object({
71816
- id: RecordIdSchema,
71817
- /** The device this row belongs to (D865 removal, per-device reads). */
71818
- deviceId: number().int().optional(),
71819
- /** The domain clock, ms: observed / created / opened. */
71820
- at: number().int().optional(),
71821
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
71822
- expiresAt: number().int().optional(),
71823
- data: RecordBodySchema
71824
- });
71825
- var RecordViewSchema = object({
71826
- id: string(),
71827
- deviceId: number().int().nullable(),
71828
- at: number().nullable(),
71829
- expiresAt: number().nullable(),
71830
- rev: number().int(),
71831
- updatedAt: number(),
71832
- data: RecordBodySchema
71833
- });
71834
- /** Declared index fields only. Anything else does not compile, by design. */
71835
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
71836
- string(),
71837
- number(),
71838
- boolean(),
71839
- object({ in: array(union([
71840
- string(),
71841
- number(),
71842
- boolean()
71843
- ])).min(1).max(RECORD_BATCH_MAX) }),
71844
- object({
71845
- gt: union([string(), number()]).optional(),
71846
- gte: union([string(), number()]).optional(),
71847
- lt: union([string(), number()]).optional(),
71848
- lte: union([string(), number()]).optional()
71849
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
71850
- ]));
71851
- var KindShape = { kind: RecordKindNameSchema };
71852
- var TimeWindowShape = {
71853
- deviceId: number().int().optional(),
71854
- atFrom: number().optional(),
71855
- atTo: number().optional()
71856
- };
71857
- var RecordQueryInputSchema = object({
71858
- ...KindShape,
71859
- ...TimeWindowShape,
71860
- where: RecordWhereSchema.optional(),
71861
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
71862
- order: _enum(["at", "id"]).optional(),
71863
- desc: boolean().optional(),
71864
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
71865
- /** Opaque keyset cursor from a previous answer. There is no offset. */
71866
- cursor: string().min(1).optional()
71867
- });
71868
- var RecordQueryResultSchema = object({
71869
- records: array(RecordViewSchema),
71870
- nextCursor: string().nullable()
71871
- });
71872
- var RecordKindStateSchema = _enum([
71873
- "created",
71874
- "unchanged",
71875
- "updated"
71876
- ]);
71877
- var DeclareKindResultSchema = object({
71878
- kindId: number().int(),
71879
- state: RecordKindStateSchema,
71880
- createdIndexes: array(string())
71881
- });
71882
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
71883
- var SecretRefsList = array(string());
71884
- /**
71885
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
71886
- * All ops of one call share ONE database file and ONE `transactFamily`.
71887
- */
71888
- var RecordTransactOpSchema = discriminatedUnion("op", [
71889
- object({
71890
- op: literal("put"),
71891
- kind: RecordKindNameSchema,
71892
- record: RecordInputSchema,
71893
- ifRev: number().int().min(0).optional()
71894
- }),
71895
- object({
71896
- op: literal("patch"),
71897
- kind: RecordKindNameSchema,
71898
- id: RecordIdSchema,
71899
- data: RecordBodySchema,
71900
- at: number().int().nullable().optional(),
71901
- expiresAt: number().int().nullable().optional(),
71902
- ifRev: number().int().min(1).optional()
71903
- }),
71904
- object({
71905
- op: literal("delete"),
71906
- kind: RecordKindNameSchema,
71907
- id: RecordIdSchema
71908
- })
71909
- ]);
71910
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
71911
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
71912
- kind: "mutation",
71913
- auth: "admin"
71914
- }), method(object({
71915
- ...KindShape,
71916
- id: RecordIdSchema
71917
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
71918
- ...KindShape,
71919
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
71920
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
71921
- ...KindShape,
71922
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
71923
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
71924
- ...KindShape,
71925
- record: RecordInputSchema,
71926
- /** Compare-and-set. `0` means "the row must not exist". */
71927
- ifRev: number().int().min(0).optional()
71928
- }), object({
71929
- rev: number().int(),
71930
- releasedRefs: SecretRefsList
71931
- }), {
71932
- kind: "mutation",
71933
- auth: "admin"
71934
- }), method(object({
71935
- ...KindShape,
71936
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
71937
- }), object({
71938
- count: number().int(),
71939
- releasedRefs: SecretRefsList
71940
- }), {
71941
- kind: "mutation",
71942
- auth: "admin"
71943
- }), method(object({
71944
- ...KindShape,
71945
- id: RecordIdSchema,
71946
- data: RecordBodySchema,
71947
- at: number().int().nullable().optional(),
71948
- expiresAt: number().int().nullable().optional(),
71949
- ifRev: number().int().min(1).optional()
71950
- }), object({
71951
- rev: number().int(),
71952
- releasedRefs: SecretRefsList
71953
- }), {
71954
- kind: "mutation",
71955
- auth: "admin"
71956
- }), method(object({
71957
- ...KindShape,
71958
- id: RecordIdSchema
71959
- }), object({
71960
- deleted: boolean(),
71961
- secretRefs: SecretRefsList
71962
- }), {
71963
- kind: "mutation",
71964
- auth: "admin"
71965
- }), method(object({
71966
- ...KindShape,
71967
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
71968
- }), object({
71969
- deleted: number().int(),
71970
- secretRefs: SecretRefsList
71971
- }), {
71972
- kind: "mutation",
71973
- auth: "admin"
71974
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
71975
- ...KindShape,
71976
- ...TimeWindowShape,
71977
- where: RecordWhereSchema.optional()
71978
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
71979
- ...KindShape,
71980
- deviceId: number().int().optional(),
71981
- from: number(),
71982
- to: number(),
71983
- bucketMs: number().int().positive()
71984
- }), object({ buckets: array(object({
71985
- bucketStart: number(),
71986
- count: number().int()
71987
- })) }), { auth: "admin" }), method(object({
71988
- ...KindShape,
71989
- op: _enum([
71990
- "sum",
71991
- "min",
71992
- "max",
71993
- "count"
71994
- ]),
71995
- field: RecordFieldPathSchema.optional(),
71996
- groupBy: RecordFieldPathSchema.optional(),
71997
- where: RecordWhereSchema.optional()
71998
- }), object({ rows: array(object({
71999
- group: union([
72000
- string(),
72001
- number(),
72002
- _null()
72003
- ]),
72004
- value: number().nullable()
72005
- })) }), { auth: "admin" }), method(object({
72006
- ...KindShape,
72007
- deviceId: number().int().optional(),
72008
- atBefore: number().optional(),
72009
- where: RecordWhereSchema.optional()
72010
- }), object({
72011
- deleted: number().int(),
72012
- secretRefs: SecretRefsList
72013
- }), {
72014
- kind: "mutation",
72015
- auth: "admin"
72016
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72017
- results: array(object({
72018
- rev: number().int().nullable(),
72019
- deleted: boolean()
72020
- })),
72021
- releasedRefs: SecretRefsList,
72022
- secretRefs: SecretRefsList
72023
- }), {
72024
- kind: "mutation",
72025
- auth: "admin"
72026
- }), method(object({
72027
- deviceId: number().int(),
72028
- kinds: array(RecordKindNameSchema).optional()
72029
- }), object({
72030
- deleted: record(string(), number().int()),
72031
- secretRefs: SecretRefsList
72032
- }), {
72033
- kind: "mutation",
72034
- auth: "admin"
72035
- }), method(object(KindShape), object({ id: number().int() }), {
72036
- kind: "mutation",
72037
- auth: "admin"
72038
- });
72039
- /**
72040
72180
  * record-entries - the ONE admin surface for every list of user-created entries
72041
72181
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72042
72182
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -81803,7 +81943,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81803
81943
  * `deviceClasses` map (first registered type). `null` when manual creation is
81804
81944
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
81805
81945
  */
81806
- async getManualCreationType() {
81946
+ async getManualCreationType(_input) {
81807
81947
  if (!await this.supportsManualCreation()) return { deviceType: null };
81808
81948
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
81809
81949
  }
@@ -81814,7 +81954,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81814
81954
  return true;
81815
81955
  }
81816
81956
  async getChildCreationSchema(input) {
81817
- return this.onGetCreationSchema(input.type);
81957
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
81818
81958
  }
81819
81959
  /**
81820
81960
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -81826,7 +81966,7 @@ var BaseDeviceProvider = class extends BaseAddon {
81826
81966
  * `deviceClasses` instead.
81827
81967
  */
81828
81968
  async createDevice(input) {
81829
- const spec = await this.onCreateDevice(input.type, input.config);
81969
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
81830
81970
  const Class = this.deviceClasses[spec.meta.type];
81831
81971
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
81832
81972
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -83235,20 +83375,6 @@ Object.freeze({
83235
83375
  access: "create",
83236
83376
  role: "viewer"
83237
83377
  },
83238
- "broker.add": {
83239
- capName: "broker",
83240
- capScope: "system",
83241
- addonId: null,
83242
- access: "create",
83243
- role: "admin"
83244
- },
83245
- "broker.get": {
83246
- capName: "broker",
83247
- capScope: "system",
83248
- addonId: null,
83249
- access: "view",
83250
- role: "admin"
83251
- },
83252
83378
  "broker.getBrokerConfig": {
83253
83379
  capName: "broker",
83254
83380
  capScope: "system",
@@ -83256,20 +83382,6 @@ Object.freeze({
83256
83382
  access: "view",
83257
83383
  role: "admin"
83258
83384
  },
83259
- "broker.getSettings": {
83260
- capName: "broker",
83261
- capScope: "system",
83262
- addonId: null,
83263
- access: "view",
83264
- role: "admin"
83265
- },
83266
- "broker.getSettingsSchema": {
83267
- capName: "broker",
83268
- capScope: "system",
83269
- addonId: null,
83270
- access: "view",
83271
- role: "admin"
83272
- },
83273
83385
  "broker.getState": {
83274
83386
  capName: "broker",
83275
83387
  capScope: "system",
@@ -83284,20 +83396,6 @@ Object.freeze({
83284
83396
  access: "view",
83285
83397
  role: "admin"
83286
83398
  },
83287
- "broker.list": {
83288
- capName: "broker",
83289
- capScope: "system",
83290
- addonId: null,
83291
- access: "view",
83292
- role: "admin"
83293
- },
83294
- "broker.listProviders": {
83295
- capName: "broker",
83296
- capScope: "system",
83297
- addonId: null,
83298
- access: "view",
83299
- role: "admin"
83300
- },
83301
83399
  "broker.publish": {
83302
83400
  capName: "broker",
83303
83401
  capScope: "system",
@@ -83305,20 +83403,6 @@ Object.freeze({
83305
83403
  access: "create",
83306
83404
  role: "admin"
83307
83405
  },
83308
- "broker.remove": {
83309
- capName: "broker",
83310
- capScope: "system",
83311
- addonId: null,
83312
- access: "delete",
83313
- role: "admin"
83314
- },
83315
- "broker.setSettings": {
83316
- capName: "broker",
83317
- capScope: "system",
83318
- addonId: null,
83319
- access: "create",
83320
- role: "admin"
83321
- },
83322
83406
  "broker.subscribe": {
83323
83407
  capName: "broker",
83324
83408
  capScope: "system",
@@ -83326,20 +83410,6 @@ Object.freeze({
83326
83410
  access: "create",
83327
83411
  role: "admin"
83328
83412
  },
83329
- "broker.testConnection": {
83330
- capName: "broker",
83331
- capScope: "system",
83332
- addonId: null,
83333
- access: "create",
83334
- role: "admin"
83335
- },
83336
- "broker.testSettings": {
83337
- capName: "broker",
83338
- capScope: "system",
83339
- addonId: null,
83340
- access: "create",
83341
- role: "admin"
83342
- },
83343
83413
  "broker.unsubscribe": {
83344
83414
  capName: "broker",
83345
83415
  capScope: "system",
@@ -88303,6 +88373,13 @@ Object.freeze({
88303
88373
  access: "view",
88304
88374
  role: "viewer"
88305
88375
  },
88376
+ "pipelineAnalytics.getMediaLocationCensus": {
88377
+ capName: "pipeline-analytics",
88378
+ capScope: "device",
88379
+ addonId: null,
88380
+ access: "view",
88381
+ role: "admin"
88382
+ },
88306
88383
  "pipelineAnalytics.getMediaReclaimStatus": {
88307
88384
  capName: "pipeline-analytics",
88308
88385
  capScope: "device",
@@ -97436,6 +97513,15 @@ function rewriteLocation(location, currentUpstream, route) {
97436
97513
  /** Characters that may precede a URL that STARTS a value (never `=`, `?`, `&`, `%3D`). */
97437
97514
  var VALUE_START = String.raw`(?<=^|["'(\s>,\[{])`;
97438
97515
  /**
97516
+ * Subresource Integrity pins the bytes of a script or stylesheet. The proxy rewrites vendor
97517
+ * URLs inside those bytes (and re-serves them from another origin), so the hash can no longer
97518
+ * match and the browser refuses the file: the page renders with no script at all. The hub
97519
+ * already drops the CSP that would have enforced the same pin; the attribute goes with it.
97520
+ */
97521
+ function stripIntegrity(html) {
97522
+ return html.replace(/\s+integrity\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "");
97523
+ }
97524
+ /**
97439
97525
  * Rewrite vendor URLs in a text body: absolute (`https://host/…`), protocol-relative
97440
97526
  * (`//host/…`) and JSON-escaped (`https:\/\/host\/…`) when they start a value; and, in
97441
97527
  * HTML/CSS, root-relative references (`href="/x"`, `url(/x)`) which would otherwise
@@ -97451,6 +97537,7 @@ function rewriteBody(body, kind, currentUpstream, route) {
97451
97537
  const escaped = new RegExp(`${VALUE_START}(?:https?:)?\\\\/\\\\/${host}(?=\\\\/|["'?#\\s)\\]},<]|$)`, "g");
97452
97538
  out = out.replace(escaped, escapedBase);
97453
97539
  }
97540
+ if (kind === "html") out = stripIntegrity(out);
97454
97541
  const current = `${route.basePath}/${currentUpstream.host}/`;
97455
97542
  const notMounted = `(?!/)(?!${escapeRegex(route.basePath.slice(1))}/)`;
97456
97543
  if (kind === "html") {
@@ -98075,6 +98162,74 @@ object({
98075
98162
  delay: number().nonnegative().optional(),
98076
98163
  commands: record(string(), unknown())
98077
98164
  });
98165
+ entryBody({ brokerId: string() });
98166
+ function secretsOverMigrationApi(api) {
98167
+ return {
98168
+ resolve: async (refs) => {
98169
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
98170
+ const out = {};
98171
+ for (const ref of refs) {
98172
+ const value = values[ref];
98173
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
98174
+ kind: "value",
98175
+ value,
98176
+ version: 0
98177
+ };
98178
+ }
98179
+ return out;
98180
+ },
98181
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
98182
+ };
98183
+ }
98184
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
98185
+ function recordsOverMigrationApi(api) {
98186
+ return { kind: (definition) => {
98187
+ const handle = api.records.kind(definition);
98188
+ return {
98189
+ get: (id) => handle.get({ id }),
98190
+ getResolved: (id) => handle.getResolved({ id }),
98191
+ put: (input, opts) => handle.put({
98192
+ ...input,
98193
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
98194
+ }),
98195
+ delete: (id) => handle.delete({ id })
98196
+ };
98197
+ } };
98198
+ }
98199
+ function integrationRowsApiOver(api) {
98200
+ return {
98201
+ list: async () => (await api.integrations.list({})).integrations,
98202
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
98203
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
98204
+ };
98205
+ }
98206
+ /**
98207
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
98208
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
98209
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
98210
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
98211
+ */
98212
+ var lanes = /* @__PURE__ */ new WeakMap();
98213
+ function deliver(api, send) {
98214
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
98215
+ const reason = error instanceof Error ? error.message : String(error);
98216
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
98217
+ });
98218
+ lanes.set(api, next);
98219
+ return next;
98220
+ }
98221
+ function warnOver(api) {
98222
+ return (message) => deliver(api, () => api.log.warn({ message }));
98223
+ }
98224
+ /** What the rows-to-records move needs, over the migration API. */
98225
+ function rowsDepsOver(api) {
98226
+ return {
98227
+ api: integrationRowsApiOver(api),
98228
+ records: recordsOverMigrationApi(api),
98229
+ secrets: secretsOverMigrationApi(api),
98230
+ warn: warnOver(api)
98231
+ };
98232
+ }
98078
98233
  //#endregion
98079
98234
  //#region src/shared/bosch-instances.ts
98080
98235
  /**
@@ -98172,4 +98327,4 @@ function keepBodyKeys(provider, keys) {
98172
98327
  };
98173
98328
  }
98174
98329
  //#endregion
98175
- export { errMsg as $, switchCapability as A, isSecretMarkerLike as B, ingestReading as C, quantityFromUnit as D, powerMeterCapability as E, defineAddonMigrations as F, number as G, array as H, defineCustomActions as I, string as J, object as K, defineEntryKind as L, waterHeaterCapability as M, createEvent as N, runningFromDishwasherOperation as O, customAction as P, DeviceType as Q, entryBody as R, heatingValveCapability as S, numericSensorCapability as T, boolean as U, _enum as V, literal as W, unknown as X, union as Y, DeviceRole as Z, defaultIntegrationApiOver as _, BaseDevice as a, enumSensorCapability as b, RUNNING_STATE_COLD as c, VendorLoginProxy as d, EventCategory as et, batteryCapability as f, consumablesCapability as g, connectionTestCapability as h, testBoschInstance as i, temperatureSensorCapability as j, runningStateCapability as k, RecordIntegrationInstances as l, climateControlCapability as m, boschRowsPorts as n, BaseDeviceProvider as o, binaryCapability as p, record as q, keepBodyKeys as r, DishwasherOperationStateSchema as s, boschRowsMigration as t, VENDOR_LOGIN_PROXY_PREFIX as u, deviceAdoptionCapability as v, integrationInstancesCapability as w, eventEmitterCapability as x, dishwasherCapability as y, isSecretMarker as z };
98330
+ export { EventCategory as $, switchCapability as A, _enum as B, integrationInstancesCapability as C, rowsDepsOver as D, quantityFromUnit as E, defineCustomActions as F, object as G, boolean as H, defineEntryKind as I, union as J, record as K, entryBody as L, waterHeaterCapability as M, createEvent as N, runningFromDishwasherOperation as O, customAction as P, errMsg as Q, isSecretMarker as R, ingestReading as S, powerMeterCapability as T, literal as U, array as V, number as W, DeviceRole as X, unknown as Y, DeviceType as Z, deviceAdoptionCapability as _, BaseDevice as a, eventEmitterCapability as b, RUNNING_STATE_COLD as c, VendorLoginProxy as d, batteryCapability as f, consumablesCapability as g, connectionTestCapability as h, testBoschInstance as i, temperatureSensorCapability as j, runningStateCapability as k, RecordIntegrationInstances as l, climateControlCapability as m, boschRowsPorts as n, BaseDeviceProvider as o, binaryCapability as p, string as q, keepBodyKeys as r, DishwasherOperationStateSchema as s, boschRowsMigration as t, VENDOR_LOGIN_PROXY_PREFIX as u, dishwasherCapability as v, numericSensorCapability as w, heatingValveCapability as x, enumSensorCapability as y, isSecretMarkerLike as z };