@camstack/addon-provider-hikvision 1.2.182 → 1.2.183

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.js CHANGED
@@ -6014,7 +6014,7 @@ var ZodIssueCode = {
6014
6014
  var ZodFirstPartyTypeKind;
6015
6015
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6016
6016
  //#endregion
6017
- //#region ../types/dist/sleep-9TIHFj1w.mjs
6017
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
6018
6018
  /**
6019
6019
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6020
6020
  * window to float samples (D455).
@@ -6823,6 +6823,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6823
6823
  }
6824
6824
  return out;
6825
6825
  }
6826
+ /** Every scope, in the order the guard and the docs list them. */
6827
+ var SCOPED_SETTINGS_SCOPES = [
6828
+ "cluster",
6829
+ "device-defaults",
6830
+ "node"
6831
+ ];
6826
6832
  /**
6827
6833
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6828
6834
  *
@@ -7637,6 +7643,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7637
7643
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7638
7644
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7639
7645
  /**
7646
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7647
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7648
+ * through `api` (guard `check-migration-ports-surface`).
7649
+ */
7650
+ function migrationSet(catalogue, bindPorts) {
7651
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7652
+ }
7653
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7654
+ function refuseMixed(form, kept, dropped) {
7655
+ 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`);
7656
+ }
7657
+ function catalogueOf(list) {
7658
+ const kept = list.filter((entry) => !("execute" in entry));
7659
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7660
+ return kept;
7661
+ }
7662
+ function boundOf(list) {
7663
+ const kept = list.filter((entry) => "execute" in entry);
7664
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7665
+ return kept;
7666
+ }
7667
+ /**
7640
7668
  * Base class for CamStack addons. Eliminates settings boilerplate:
7641
7669
  *
7642
7670
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7714,6 +7742,13 @@ var BaseAddon = class {
7714
7742
  */
7715
7743
  secretStatePaths = [];
7716
7744
  _addonSecretTree = null;
7745
+ /**
7746
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7747
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7748
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7749
+ */
7750
+ _scopedByCap = /* @__PURE__ */ new Map();
7751
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7717
7752
  _deviceSecretTree = null;
7718
7753
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7719
7754
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7783,6 +7818,7 @@ var BaseAddon = class {
7783
7818
  this._ctx = context;
7784
7819
  this._secretSettings = null;
7785
7820
  }
7821
+ await this.loadScopedSchemas();
7786
7822
  await this.resolveConfig();
7787
7823
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7788
7824
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7792,25 +7828,24 @@ var BaseAddon = class {
7792
7828
  const normalized = normalizeAddonInitResult(result);
7793
7829
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7794
7830
  this._registeredCapNames = providers.map((p) => p.capability.name);
7831
+ await this.loadScopedSchemas();
7795
7832
  return normalized;
7796
7833
  }
7834
+ async runMigrations(first, second, third) {
7835
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7836
+ return this.runBound(boundOf(first), second);
7837
+ }
7797
7838
  /**
7798
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7799
- * engine. Call it at the point of the boot where the data must already have the new
7800
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7801
- * restored devices — with the catalogue bound to the addon's ports
7802
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7803
- *
7804
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7805
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7806
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7807
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7808
- *
7809
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7810
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7811
- * omitted applied ids "newer").
7839
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7840
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7841
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7812
7842
  */
7813
- async runMigrations(migrations, options) {
7843
+ async runMigrationSets(sets, options) {
7844
+ const api = this.ctx.migrationApi;
7845
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7846
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7847
+ }
7848
+ async runBound(migrations, options) {
7814
7849
  const api = this.ctx.api.migrations;
7815
7850
  const report = await runAddonMigrations({
7816
7851
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7880,6 +7915,16 @@ var BaseAddon = class {
7880
7915
  schema(schema) {
7881
7916
  return schema;
7882
7917
  }
7918
+ /**
7919
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7920
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7921
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7922
+ * must already know which keys are per node. Names the providers register at init are added
7923
+ * once known.
7924
+ */
7925
+ scopedSettingsCapabilities() {
7926
+ return [];
7927
+ }
7883
7928
  /** Override to provide global-level settings UI schema. */
7884
7929
  globalSettingsSchema(_cap) {
7885
7930
  return null;
@@ -7923,7 +7968,8 @@ var BaseAddon = class {
7923
7968
  return [];
7924
7969
  }
7925
7970
  async getGlobalSettings(overlay, cap, nodeId) {
7926
- const schema = this.globalSettingsSchema(cap);
7971
+ await this.loadScopedSchemas(cap);
7972
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7927
7973
  if (!schema) return { sections: [] };
7928
7974
  const projected = await this.readRawProjectedStore(nodeId, cap);
7929
7975
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -8054,6 +8100,7 @@ var BaseAddon = class {
8054
8100
  * resolved blob back is a no-op for every unchanged secret.
8055
8101
  */
8056
8102
  async resolveGlobalStore(nodeId, cap) {
8103
+ await this.loadScopedSchemas(cap);
8057
8104
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8058
8105
  return this.projectForNode(raw, nodeId, cap);
8059
8106
  }
@@ -8064,6 +8111,7 @@ var BaseAddon = class {
8064
8111
  }
8065
8112
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8066
8113
  async readRawProjectedStore(nodeId, cap) {
8114
+ await this.loadScopedSchemas(cap);
8067
8115
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8068
8116
  return this.projectForNode(raw, nodeId, cap);
8069
8117
  }
@@ -8166,6 +8214,7 @@ var BaseAddon = class {
8166
8214
  await this.applyGlobalPatch(patch, nodeId);
8167
8215
  }
8168
8216
  async applyGlobalPatch(barePatch, nodeId) {
8217
+ await this.loadScopedSchemas();
8169
8218
  const keys = this.perNodeKeys();
8170
8219
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8171
8220
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8179,7 +8228,8 @@ var BaseAddon = class {
8179
8228
  await this.resolveConfig();
8180
8229
  await this.onConfigChanged();
8181
8230
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8182
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8231
+ const legacy = this.globalSettingsSchema();
8232
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8183
8233
  }
8184
8234
  /**
8185
8235
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8187,14 +8237,67 @@ var BaseAddon = class {
8187
8237
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8188
8238
  * settings API behaves exactly like the legacy node-agnostic one.
8189
8239
  */
8190
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8240
+ /**
8241
+ * Load the scoped schemas of every capability this addon declares (the override and the
8242
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8243
+ * derived from the previous set. Idempotent.
8244
+ */
8245
+ async loadScopedSchemas(extraCap) {
8246
+ const caps = new Set([
8247
+ ...this.scopedSettingsCapabilities(),
8248
+ ...this._registeredCapNames,
8249
+ ...extraCap === void 0 ? [] : [extraCap]
8250
+ ]);
8251
+ let added = false;
8252
+ for (const cap of caps) {
8253
+ if (this._scopedByCap.has(cap)) continue;
8254
+ const loaded = [];
8255
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8256
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8257
+ if (schema !== null) loaded.push({
8258
+ scope,
8259
+ schema
8260
+ });
8261
+ }
8262
+ this._scopedByCap.set(cap, loaded);
8263
+ added = true;
8264
+ }
8265
+ if (!added) return;
8266
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8267
+ this._addonSecretTree = null;
8268
+ }
8269
+ /**
8270
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8271
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8272
+ */
8273
+ scopedFormSchema(cap) {
8274
+ const byId = /* @__PURE__ */ new Map();
8275
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8276
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8277
+ }
8278
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8279
+ loadedScopedSchemas(cap) {
8280
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8281
+ return [...this._scopedByCap.values()].flat();
8282
+ }
8283
+ /**
8284
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8285
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8286
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8287
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8288
+ * Call {@link loadScopedSchemas} first (the async seams do).
8289
+ */
8191
8290
  perNodeKeys(cap) {
8192
8291
  const cacheKey = cap ?? "";
8193
- const cached = this._perNodeKeysCache.get(cacheKey);
8292
+ const cached = this._nodeKeysByCap.get(cacheKey);
8194
8293
  if (cached) return cached;
8195
- const schema = this.globalSettingsSchema(cap);
8196
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8197
- this._perNodeKeysCache.set(cacheKey, keys);
8294
+ const legacy = this.globalSettingsSchema(cap);
8295
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8296
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8297
+ if (scope !== "node") continue;
8298
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8299
+ }
8300
+ this._nodeKeysByCap.set(cacheKey, keys);
8198
8301
  return keys;
8199
8302
  }
8200
8303
  /**
@@ -8204,10 +8307,9 @@ var BaseAddon = class {
8204
8307
  * time to return its response before the addon is torn down and
8205
8308
  * re-initialised by `AddonRegistryService.restartAddon`.
8206
8309
  */
8207
- maybeAutoRestart(patchKeys, schema) {
8208
- if (!schema) return;
8310
+ maybeAutoRestart(patchKeys, schemas) {
8209
8311
  const restartKeys = /* @__PURE__ */ new Set();
8210
- for (const section of schema.sections) for (const field of section.fields) {
8312
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8211
8313
  if (field.type === "separator" || field.type === "info") continue;
8212
8314
  if (field.requiresRestart) restartKeys.add(field.key);
8213
8315
  }
@@ -8403,12 +8505,14 @@ var BaseAddon = class {
8403
8505
  * here, in the addon's own process, so the hub keeps no copy of it.
8404
8506
  */
8405
8507
  async getDeclaredSettingsKeys() {
8508
+ await this.loadScopedSchemas();
8406
8509
  return { keys: [...this.declaredKeySet()].toSorted() };
8407
8510
  }
8408
8511
  declaredKeySet() {
8409
8512
  const keys = new Set(Object.keys(this.defaults));
8410
8513
  const schema = this.globalSettingsSchema();
8411
8514
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8515
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8412
8516
  for (const key of this._declaredStateKeys) keys.add(key);
8413
8517
  for (const path of this.secretStatePaths) {
8414
8518
  const root = path.split(/[.[]/, 1)[0];
@@ -8504,7 +8608,11 @@ var BaseAddon = class {
8504
8608
  }
8505
8609
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8506
8610
  addonSecretTree() {
8507
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8611
+ if (this._addonSecretTree === null) {
8612
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8613
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8614
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8615
+ }
8508
8616
  return this._addonSecretTree;
8509
8617
  }
8510
8618
  deviceSecretTree() {
@@ -8754,6 +8862,23 @@ function dropPerNodeFields(fields) {
8754
8862
  }
8755
8863
  return kept;
8756
8864
  }
8865
+ /** The keys of the value-holding fields, recursing into layout containers. */
8866
+ function collectValueFieldKeys(fields) {
8867
+ const collected = [];
8868
+ for (const field of fields) {
8869
+ if (field.type === "group") {
8870
+ collected.push(...collectValueFieldKeys(field.fields));
8871
+ continue;
8872
+ }
8873
+ if (field.type === "sub-tabs") {
8874
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8875
+ continue;
8876
+ }
8877
+ if (field.type === "separator" || field.type === "info") continue;
8878
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8879
+ }
8880
+ return collected;
8881
+ }
8757
8882
  function collectFieldKeys(fields) {
8758
8883
  const collected = [];
8759
8884
  for (const field of fields) {
@@ -13473,7 +13598,7 @@ var RecordIntegrationInstances = class {
13473
13598
  return record === null ? null : this.viewOf(record);
13474
13599
  };
13475
13600
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13476
- createInstance = async ({ id, name, kind }) => {
13601
+ createInstance = async ({ id, name, kind, values }) => {
13477
13602
  const minted = id ?? this.hooks.mintId?.({
13478
13603
  name,
13479
13604
  ...kind !== void 0 ? { kind } : {}
@@ -13483,10 +13608,20 @@ var RecordIntegrationInstances = class {
13483
13608
  id: minted,
13484
13609
  data: this.hooks.initialBody(name, kind)
13485
13610
  }, { ifRev: 0 });
13611
+ const patch = this.patchOf(values ?? {});
13612
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13486
13613
  await this.hooks.onChanged?.(minted, "created");
13487
13614
  return { id: minted };
13488
13615
  };
13489
13616
  updateInstance = async ({ id, name, values }) => {
13617
+ const patch = this.patchOf(values);
13618
+ if (name !== void 0) patch[this.nameField] = name;
13619
+ await this.handle.patch(id, patch);
13620
+ await this.hooks.onChanged?.(id, "updated");
13621
+ return { ok: true };
13622
+ };
13623
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13624
+ patchOf(values) {
13490
13625
  const patch = {};
13491
13626
  for (const [key, value] of Object.entries(values)) {
13492
13627
  if (value === void 0) continue;
@@ -13497,11 +13632,8 @@ var RecordIntegrationInstances = class {
13497
13632
  else if (isSecretClear(value)) patch[key] = null;
13498
13633
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13499
13634
  }
13500
- if (name !== void 0) patch[this.nameField] = name;
13501
- await this.handle.patch(id, patch);
13502
- await this.hooks.onChanged?.(id, "updated");
13503
- return { ok: true };
13504
- };
13635
+ return patch;
13636
+ }
13505
13637
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13506
13638
  setInstanceEnabled = async ({ id, enabled }) => {
13507
13639
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14824,13 +14956,13 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14824
14956
  };
14825
14957
  if (orphans.some((d) => (d.parentDeviceId ?? null) === null) && fallback === null) throw new Error(`${orphans.length} device(s) of '${spec.addonId}' carry no integration and the addon has no integration to claim them to`);
14826
14958
  for (const device of orphans) if (resolve(device, new Set([device.id])) === null) unresolved.add(device.id);
14827
- for (const id of unresolved) ports.warnDevice(`device ${id} of '${spec.addonId}' carries no integration and its owner chain does not resolve to one: left unstamped`, id);
14959
+ for (const id of unresolved) await ports.warnDevice(`device ${id} of '${spec.addonId}' carries no integration and its owner chain does not resolve to one: left unstamped`, id);
14828
14960
  for (const [deviceId, integrationId] of plan) await ports.setIntegrationId(deviceId, integrationId);
14829
14961
  const wrong = [];
14830
14962
  for (const [deviceId, integrationId] of plan) if (await ports.readIntegrationId(deviceId) !== integrationId) wrong.push(deviceId);
14831
14963
  if (wrong.length > 0) throw new Error(`device(s) ${wrong.join(", ")} did not read back their integration after the claim`);
14832
14964
  const claimed = plan.size;
14833
- ports.info(`${claimed} device(s) of '${spec.addonId}' claimed to their owner's integration or the default; ${unresolved.size} unresolved, ${reservations.size} reservation(s) skipped`);
14965
+ await ports.info(`${claimed} device(s) of '${spec.addonId}' claimed to their owner's integration or the default; ${unresolved.size} unresolved, ${reservations.size} reservation(s) skipped`);
14834
14966
  return {
14835
14967
  outcome: claimed > 0 ? "done" : "already-done",
14836
14968
  summary: {
@@ -14956,25 +15088,6 @@ function defaultIntegrationMigrations(spec) {
14956
15088
  ...spec.eligible !== void 0 ? { eligible: spec.eligible } : {}
14957
15089
  })];
14958
15090
  }
14959
- function defaultIntegrationApiOver(api) {
14960
- return {
14961
- list: () => api.integrations.list.query(),
14962
- readLegacyIntegrationRows: (input) => api.migrations.readLegacyIntegrationRows.query(input),
14963
- clearLegacyIntegrationRows: (input) => api.migrations.clearLegacyIntegrationRows.mutate(input),
14964
- listDevices: (addonId) => api.deviceManager.listAll.query({
14965
- addonId,
14966
- projection: "slim"
14967
- }),
14968
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14969
- await api.deviceManager.setIntegrationId.mutate({
14970
- deviceId,
14971
- integrationId
14972
- });
14973
- },
14974
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14975
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14976
- };
14977
- }
14978
15091
  /**
14979
15092
  * The trainer contract — what the hub hands the cloud trainer and what it
14980
15093
  * gets back (cloud training, D805+).
@@ -16081,6 +16194,39 @@ var UnstampedEventMediaCountSchema = object({
16081
16194
  /** Sum across both, or `null` when either lane could not be counted. */
16082
16195
  total: number().int().nonnegative().nullable()
16083
16196
  }).nullable();
16197
+ /**
16198
+ * Where the stored event media sits, per storage location: how many media rows
16199
+ * and how many bytes carry each location id, how many carry none (legacy,
16200
+ * resolved to the default `eventMedia` location), and how many name a location
16201
+ * that was not asked about (a deleted or never-listed one).
16202
+ *
16203
+ * One covering-index aggregate per asked location plus the NULL one, and one
16204
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
16205
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
16206
+ * it is a deleted location only when every location id was asked.
16207
+ * `null` is "could not be measured", never zero.
16208
+ */
16209
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
16210
+ var MediaLocationCensusSchema = object({
16211
+ locations: array(object({
16212
+ locationId: string(),
16213
+ rows: number().int().nonnegative(),
16214
+ bytes: number().nonnegative()
16215
+ })).readonly(),
16216
+ unstamped: object({
16217
+ rows: number().int().nonnegative(),
16218
+ bytes: number().nonnegative()
16219
+ }),
16220
+ /** Rows stamped with a location id that was not in the asked list. */
16221
+ unlisted: object({
16222
+ rows: number().int().nonnegative(),
16223
+ bytes: number().nonnegative()
16224
+ }),
16225
+ total: object({
16226
+ rows: number().int().nonnegative(),
16227
+ bytes: number().nonnegative()
16228
+ })
16229
+ });
16084
16230
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
16085
16231
  /** The independently selectable logical storage classes — every class
16086
16232
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -47398,52 +47544,7 @@ onBrightnessChanged: { data: object({
47398
47544
  minIntervalMs: 0
47399
47545
  } } }
47400
47546
  };
47401
- /**
47402
- * `broker` — unified pub/sub broker registry, system-scoped collection.
47403
- *
47404
- * The cap models any kind-tagged message broker the user wants to
47405
- * register and that other addons might consume. The first two kinds
47406
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
47407
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
47408
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
47409
- * the same surface.
47410
- *
47411
- * Why one cap, not one cap per kind:
47412
- * - The integrations page wants a single table of "every broker"
47413
- * across kinds; a unified cap drives it without join logic.
47414
- * - Generic admin operations (add / remove / test / status) are
47415
- * identical across kinds — duplicating them per cap was busywork.
47416
- * - The `network-access` cap precedent: same interface, many
47417
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47418
- *
47419
- * What stays kind-specific:
47420
- * - `getBrokerConfig` payload (kind decides whether it returns
47421
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47422
- * `Record<string, unknown>` at the wire; consumers narrow.
47423
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47424
- * key) — also typed as `Record<string, unknown>` so each kind can
47425
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47426
- * without rebreaking the cap signature.
47427
- * - `add` `settings` payload (different fields per kind, validated by
47428
- * the kind-specific provider).
47429
- *
47430
- * Bidirectionality:
47431
- * - `publish` is RPC — synchronous result (provider-defined).
47432
- * - `subscribe` returns a subscription handle; the actual message
47433
- * stream flows over the typed event-bus as `broker.message` events
47434
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47435
- * event handler. Subscriptions persist across reconnects — the
47436
- * provider re-subscribes upstream after a transport drop.
47437
- *
47438
- * Why event-bus push (not a subscription RPC stream):
47439
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47440
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47441
- * drop is recoverable via `getState({key})`).
47442
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47443
- * - Cross-process: events already route through `$event-bus`; no
47444
- * per-broker wire-shaping needed.
47445
- */
47446
- var BrokerStatusEnum = _enum([
47547
+ _enum([
47447
47548
  "connected",
47448
47549
  "disconnected",
47449
47550
  "connecting",
@@ -47451,141 +47552,12 @@ var BrokerStatusEnum = _enum([
47451
47552
  "unreachable",
47452
47553
  "error"
47453
47554
  ]);
47454
- var BrokerInfoSchema = object({
47455
- /** Stable broker id. Persisted; survives addon restarts. */
47456
- id: string(),
47457
- /** Addon id of the provider that OWNS this broker.
47458
- *
47459
- * The `broker` cap is a system-scoped collection: several addons
47460
- * register a `broker` provider, each owning a DISJOINT set of
47461
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47462
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47463
- * device belongs to one integration. The admin UI threads this id
47464
- * back as the `{ addonId }` system-collection selector on every
47465
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47466
- * `testConnection`), so the call routes to the OWNING provider
47467
- * instead of defaulting to the first-registered one. */
47468
- addonId: string(),
47469
- /** Human-readable name (operator-chosen at add-time). */
47470
- name: string(),
47471
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47472
- kind: string(),
47473
- status: BrokerStatusEnum,
47474
- /** Free-form provider-specific info (HA version, MQTT broker
47475
- * flavour, latency, mTLS active, …). */
47476
- info: record(string(), unknown()),
47477
- /** Ms epoch of the last connection probe / status update. */
47478
- lastCheckedAt: number().nullable(),
47479
- /** Last error message, when `status` indicates failure. */
47480
- error: string().nullable()
47481
- });
47482
47555
  var RegistryStatusSchema = object({
47483
47556
  brokerCount: number().int().nonnegative(),
47484
47557
  connectedCount: number().int().nonnegative()
47485
47558
  });
47486
- /**
47487
- * One entry per `broker` provider — which addon provides which broker
47488
- * kind(s). The unified create picker reads this to know, for each
47489
- * (addonId, kind) pair the operator can pick, where to route the
47490
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47491
- * `{ addonId }` selector). A provider only advertises a kind here when
47492
- * it implements `getSettingsSchema` for that kind (so the picker never
47493
- * offers a kind whose creation form can't be rendered).
47494
- */
47495
- var BrokerProviderInfoSchema = object({
47496
- /** Addon id of the `broker` provider this entry describes. */
47497
- addonId: string(),
47498
- /** Broker kinds this provider can create, with a display label. */
47499
- kinds: array(object({
47500
- kind: string(),
47501
- label: string(),
47502
- /**
47503
- * Relative hub path to start an interactive account link (OAuth popup).
47504
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47505
- */
47506
- interactiveConnectPath: string().min(1).optional(),
47507
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47508
- interactiveDisconnectPath: string().min(1).optional(),
47509
- /**
47510
- * The kind signs in through a server-held interactive session instead of
47511
- * (or before) typed credentials. `basePath` is a hub-relative route set
47512
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47513
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47514
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47515
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47516
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47517
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47518
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47519
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47520
- * offers it as the default path; the fields the session fills are
47521
- * marked `filledBySignIn` in the kind's settings schema.
47522
- *
47523
- * `methods` lists the ways the session can sign in, recommended first:
47524
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47525
- * settings) answering `{ sessionId, userCode, verificationUrl,
47526
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47527
- * any device, and the same `status` / `commit` / `cancel` routes follow
47528
- * (status then carries `method`, `userCode`, `verificationUrl`,
47529
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47530
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47531
- * `['proxy']`.
47532
- */
47533
- signIn: object({
47534
- basePath: string().min(1),
47535
- methods: array(_enum(["device-code", "proxy"])).optional()
47536
- }).optional()
47537
- }))
47538
- });
47539
- var ListInputSchema = object({
47540
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47541
- * only HA brokers. Omit to list every broker. */
47542
- kind: string().optional() });
47543
47559
  var GetInputSchema = object({ id: string() });
47544
- var AddInputSchema = object({
47545
- kind: string().min(1),
47546
- name: string().min(1),
47547
- /**
47548
- * ADOPT an existing id instead of minting a new one.
47549
- *
47550
- * Written the day this cost an outage. A broker's id is not a detail: HA
47551
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47552
- * lost from config and re-added as `ha_001` leaves every one of its devices
47553
- * bound to a broker that no longer exists. Re-entering the password under the
47554
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47555
- * password.
47556
- *
47557
- * A provider MUST refuse an id that is already in use — adopting a live
47558
- * broker's id would silently take it over.
47559
- */
47560
- id: string().min(1).optional(),
47561
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47562
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47563
- * branch on receipt — invalid shape rejects the add. */
47564
- settings: record(string(), unknown())
47565
- });
47566
- var AddResultSchema = object({ id: string() });
47567
- var RemoveInputSchema = object({ id: string() });
47568
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47569
- ok: literal(true),
47570
- latencyMs: number().nonnegative()
47571
- }), object({
47572
- ok: literal(false),
47573
- error: string()
47574
- })]);
47575
47560
  var SettingsRecordSchema$1 = record(string(), unknown());
47576
- var SettingsSchemaInputSchema = object({ kind: string() });
47577
- var TestSettingsInputSchema = object({
47578
- kind: string(),
47579
- settings: SettingsRecordSchema$1
47580
- });
47581
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47582
- ok: literal(true),
47583
- latencyMs: number().nonnegative().optional()
47584
- }).strict(), object({
47585
- ok: literal(false),
47586
- error: string()
47587
- })]);
47588
- var SettingsSchemaResultSchema = unknown().nullable();
47589
47561
  var PublishInputSchema = object({
47590
47562
  brokerId: string(),
47591
47563
  /** Kind-specific routing target.
@@ -47619,25 +47591,7 @@ var GetStateInputSchema = object({
47619
47591
  * HA: entity_id (returns the cached entity state). */
47620
47592
  key: string()
47621
47593
  });
47622
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47623
- kind: "mutation",
47624
- auth: "admin"
47625
- }), method(RemoveInputSchema, _void(), {
47626
- kind: "mutation",
47627
- auth: "admin"
47628
- }), method(GetInputSchema, TestConnectionResultSchema, {
47629
- kind: "mutation",
47630
- auth: "admin"
47631
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47632
- id: string(),
47633
- settings: SettingsRecordSchema$1
47634
- }), _void(), {
47635
- kind: "mutation",
47636
- auth: "admin"
47637
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47638
- kind: "mutation",
47639
- auth: "admin"
47640
- }), method(PublishInputSchema, unknown(), {
47594
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47641
47595
  kind: "mutation",
47642
47596
  auth: "admin"
47643
47597
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -52458,7 +52412,14 @@ var DiscoveryCandidateSchema = object({
52458
52412
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52459
52413
  parentStableId: string().optional(),
52460
52414
  /** `false` = shown for context but not pickable. Default true. */
52461
- selectable: boolean().optional()
52415
+ selectable: boolean().optional(),
52416
+ /**
52417
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52418
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52419
+ * admin asks for exactly these, on the creation form prefilled with
52420
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52421
+ */
52422
+ needsParams: array(string()).optional()
52462
52423
  });
52463
52424
  /**
52464
52425
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52585,8 +52546,14 @@ var deviceProviderCapability = {
52585
52546
  * provider does not support manual creation. Lets the Add-Device dialog
52586
52547
  * pick the right type instead of assuming Camera.
52587
52548
  */
52588
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52589
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52549
+ getManualCreationType: method(object({
52550
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52551
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52552
+ adoptDiscoveredDevice: method(object({
52553
+ candidate: DiscoveryCandidateSchema,
52554
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52555
+ integrationId: string().optional()
52556
+ }), DeviceSummarySchema, {
52590
52557
  kind: "mutation",
52591
52558
  auth: "admin"
52592
52559
  }),
@@ -52597,10 +52564,16 @@ var deviceProviderCapability = {
52597
52564
  * devices of that type. The output is a `ConfigUISchema` — the
52598
52565
  * router type-asserts it at the boundary.
52599
52566
  */
52600
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52567
+ getChildCreationSchema: method(object({
52568
+ type: _enum(DeviceType),
52569
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52570
+ integrationId: string().optional()
52571
+ }), CreationSchemaOutputSchema),
52601
52572
  createDevice: method(object({
52602
52573
  type: _enum(DeviceType),
52603
- config: record(string(), unknown())
52574
+ config: record(string(), unknown()),
52575
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52576
+ integrationId: string().optional()
52604
52577
  }), DeviceSummarySchema, {
52605
52578
  kind: "mutation",
52606
52579
  auth: "admin"
@@ -53325,7 +53298,10 @@ method(object({
53325
53298
  auth: "admin"
53326
53299
  }), method(object({
53327
53300
  addonId: string(),
53328
- type: _enum(DeviceType)
53301
+ type: _enum(DeviceType),
53302
+ /** The integration the form is for; a provider whose integrations differ (a hub
53303
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
53304
+ integrationId: string().optional()
53329
53305
  }), unknown().nullable()), method(object({
53330
53306
  addonId: string(),
53331
53307
  type: _enum(DeviceType),
@@ -53409,7 +53385,11 @@ method(object({
53409
53385
  kind: "mutation",
53410
53386
  auth: "admin",
53411
53387
  timeoutMs: 12e4
53412
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53388
+ }), method(object({
53389
+ addonId: string(),
53390
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
53391
+ integrationId: string().optional()
53392
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53413
53393
  deviceId: number(),
53414
53394
  key: string(),
53415
53395
  value: unknown()
@@ -56708,7 +56688,7 @@ var TestConnectionStatusEnum = _enum([
56708
56688
  "inconclusive",
56709
56689
  "unsupported"
56710
56690
  ]);
56711
- var TestConnectionResultSchema$1 = object({
56691
+ var TestConnectionResultSchema = object({
56712
56692
  /** True ONLY for `validated`. Never true for a test that did not run. */
56713
56693
  success: boolean(),
56714
56694
  error: string().optional(),
@@ -56753,7 +56733,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56753
56733
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56754
56734
  addonId: string(),
56755
56735
  settings: record(string(), unknown())
56756
- }), TestConnectionResultSchema$1, {
56736
+ }), TestConnectionResultSchema, {
56757
56737
  kind: "mutation",
56758
56738
  auth: "admin"
56759
56739
  });
@@ -56780,6 +56760,14 @@ var ConfigSchemaPassthrough$3 = custom();
56780
56760
  var IntegrationInstanceIdSchema = string().min(1);
56781
56761
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56782
56762
  /**
56763
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56764
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56765
+ * `services`: a connection configured from the addon's own function page, never listed on
56766
+ * Integrations.
56767
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56768
+ */
56769
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56770
+ /**
56783
56771
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56784
56772
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56785
56773
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56790,6 +56778,22 @@ var IntegrationInstanceKindSchema = object({
56790
56778
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56791
56779
  id: string().min(1),
56792
56780
  label: string().min(1),
56781
+ /**
56782
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56783
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56784
+ * provider with more than one section must name it on every kind.
56785
+ */
56786
+ functionCap: string().min(1),
56787
+ /**
56788
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56789
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56790
+ * finds the instances whose kind names it; absent takes the kind `id`.
56791
+ */
56792
+ brokerKind: string().min(1).optional(),
56793
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56794
+ role: IntegrationInstanceRoleSchema.optional(),
56795
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56796
+ canTest: boolean().optional(),
56793
56797
  /** The kind signs in through a server-held interactive session. */
56794
56798
  signIn: object({
56795
56799
  basePath: string().min(1),
@@ -56802,11 +56806,7 @@ var IntegrationInstanceKindSchema = object({
56802
56806
  });
56803
56807
  var IntegrationInstanceDescriptionSchema = object({
56804
56808
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56805
- role: _enum([
56806
- "devices",
56807
- "services",
56808
- "both"
56809
- ]),
56809
+ role: IntegrationInstanceRoleSchema,
56810
56810
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56811
56811
  discovery: object({
56812
56812
  mode: _enum([
@@ -56881,7 +56881,11 @@ var integrationInstancesCapability = {
56881
56881
  methods: {
56882
56882
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56883
56883
  /** The form; `id: null` is the create form. */
56884
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56884
+ instanceFormSchema: method(object({
56885
+ id: IntegrationInstanceIdSchema.nullable(),
56886
+ /** The kind of the create form (`id: null`) of a provider with several. */
56887
+ kind: string().min(1).optional()
56888
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56885
56889
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56886
56890
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56887
56891
  /**
@@ -56891,7 +56895,9 @@ var integrationInstancesCapability = {
56891
56895
  createInstance: method(object({
56892
56896
  id: IntegrationInstanceIdSchema.optional(),
56893
56897
  name: string().min(1),
56894
- kind: string().min(1).optional()
56898
+ kind: string().min(1).optional(),
56899
+ /** Form values written with the record (a link picked in the create dialog). */
56900
+ values: record(string(), unknown()).optional()
56895
56901
  }), object({ id: string() }), {
56896
56902
  kind: "mutation",
56897
56903
  auth: "admin"
@@ -56918,8 +56924,10 @@ var integrationInstancesCapability = {
56918
56924
  }),
56919
56925
  testInstance: optionalMethod(object({
56920
56926
  id: IntegrationInstanceIdSchema.nullable(),
56921
- values: record(string(), unknown())
56922
- }), TestConnectionResultSchema$1, {
56927
+ values: record(string(), unknown()),
56928
+ /** The kind to test when `id` is null and the provider has several. */
56929
+ kind: string().min(1).optional()
56930
+ }), TestConnectionResultSchema, {
56923
56931
  kind: "mutation",
56924
56932
  auth: "admin"
56925
56933
  })
@@ -59676,6 +59684,380 @@ var SystemMetricsSchema = object({
59676
59684
  gpuMemoryPercent: number().optional()
59677
59685
  });
59678
59686
  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);
59687
+ /**
59688
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59689
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59690
+ * (operator intent, D870) and device-history (numbers over time, D850).
59691
+ *
59692
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59693
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59694
+ * that with the addon id closed over). It is deliberately NOT in any input
59695
+ * schema, so a session can never supply it, and a call with no stamp is refused
59696
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59697
+ * addons go through the owner's capability.
59698
+ *
59699
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59700
+ * never `[]`. Secret fields are never on the wire: a read shows the
59701
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59702
+ * resolves itself, and a write may carry only a keychain marker bound to the
59703
+ * row's own ref.
59704
+ *
59705
+ * Internal: addons reach it through `ctx.records`, never directly.
59706
+ */
59707
+ var RecordIdSchema = string().min(1).max(256);
59708
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59709
+ var RecordBodySchema = record(string(), unknown());
59710
+ var RecordInputSchema = object({
59711
+ id: RecordIdSchema,
59712
+ /** The device this row belongs to (D865 removal, per-device reads). */
59713
+ deviceId: number().int().optional(),
59714
+ /** The domain clock, ms: observed / created / opened. */
59715
+ at: number().int().optional(),
59716
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59717
+ expiresAt: number().int().optional(),
59718
+ data: RecordBodySchema
59719
+ });
59720
+ var RecordViewSchema = object({
59721
+ id: string(),
59722
+ deviceId: number().int().nullable(),
59723
+ at: number().nullable(),
59724
+ expiresAt: number().nullable(),
59725
+ rev: number().int(),
59726
+ updatedAt: number(),
59727
+ data: RecordBodySchema
59728
+ });
59729
+ /** Declared index fields only. Anything else does not compile, by design. */
59730
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59731
+ string(),
59732
+ number(),
59733
+ boolean(),
59734
+ object({ in: array(union([
59735
+ string(),
59736
+ number(),
59737
+ boolean()
59738
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59739
+ object({
59740
+ gt: union([string(), number()]).optional(),
59741
+ gte: union([string(), number()]).optional(),
59742
+ lt: union([string(), number()]).optional(),
59743
+ lte: union([string(), number()]).optional()
59744
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59745
+ ]));
59746
+ var KindShape = { kind: RecordKindNameSchema };
59747
+ var TimeWindowShape = {
59748
+ deviceId: number().int().optional(),
59749
+ atFrom: number().optional(),
59750
+ atTo: number().optional()
59751
+ };
59752
+ var RecordQueryInputSchema = object({
59753
+ ...KindShape,
59754
+ ...TimeWindowShape,
59755
+ where: RecordWhereSchema.optional(),
59756
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59757
+ order: _enum(["at", "id"]).optional(),
59758
+ desc: boolean().optional(),
59759
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59760
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59761
+ cursor: string().min(1).optional()
59762
+ });
59763
+ var RecordQueryResultSchema = object({
59764
+ records: array(RecordViewSchema),
59765
+ nextCursor: string().nullable()
59766
+ });
59767
+ var RecordKindStateSchema = _enum([
59768
+ "created",
59769
+ "unchanged",
59770
+ "updated"
59771
+ ]);
59772
+ var DeclareKindResultSchema = object({
59773
+ kindId: number().int(),
59774
+ state: RecordKindStateSchema,
59775
+ createdIndexes: array(string())
59776
+ });
59777
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59778
+ var SecretRefsList = array(string());
59779
+ /**
59780
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59781
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59782
+ */
59783
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59784
+ object({
59785
+ op: literal("put"),
59786
+ kind: RecordKindNameSchema,
59787
+ record: RecordInputSchema,
59788
+ ifRev: number().int().min(0).optional()
59789
+ }),
59790
+ object({
59791
+ op: literal("patch"),
59792
+ kind: RecordKindNameSchema,
59793
+ id: RecordIdSchema,
59794
+ data: RecordBodySchema,
59795
+ at: number().int().nullable().optional(),
59796
+ expiresAt: number().int().nullable().optional(),
59797
+ ifRev: number().int().min(1).optional()
59798
+ }),
59799
+ object({
59800
+ op: literal("delete"),
59801
+ kind: RecordKindNameSchema,
59802
+ id: RecordIdSchema
59803
+ })
59804
+ ]);
59805
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59806
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59807
+ kind: "mutation",
59808
+ auth: "admin"
59809
+ }), method(object({
59810
+ ...KindShape,
59811
+ id: RecordIdSchema
59812
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59813
+ ...KindShape,
59814
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59815
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59816
+ ...KindShape,
59817
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59818
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59819
+ ...KindShape,
59820
+ record: RecordInputSchema,
59821
+ /** Compare-and-set. `0` means "the row must not exist". */
59822
+ ifRev: number().int().min(0).optional()
59823
+ }), object({
59824
+ rev: number().int(),
59825
+ releasedRefs: SecretRefsList
59826
+ }), {
59827
+ kind: "mutation",
59828
+ auth: "admin"
59829
+ }), method(object({
59830
+ ...KindShape,
59831
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59832
+ }), object({
59833
+ count: number().int(),
59834
+ releasedRefs: SecretRefsList
59835
+ }), {
59836
+ kind: "mutation",
59837
+ auth: "admin"
59838
+ }), method(object({
59839
+ ...KindShape,
59840
+ id: RecordIdSchema,
59841
+ data: RecordBodySchema,
59842
+ at: number().int().nullable().optional(),
59843
+ expiresAt: number().int().nullable().optional(),
59844
+ ifRev: number().int().min(1).optional()
59845
+ }), object({
59846
+ rev: number().int(),
59847
+ releasedRefs: SecretRefsList
59848
+ }), {
59849
+ kind: "mutation",
59850
+ auth: "admin"
59851
+ }), method(object({
59852
+ ...KindShape,
59853
+ id: RecordIdSchema
59854
+ }), object({
59855
+ deleted: boolean(),
59856
+ secretRefs: SecretRefsList
59857
+ }), {
59858
+ kind: "mutation",
59859
+ auth: "admin"
59860
+ }), method(object({
59861
+ ...KindShape,
59862
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59863
+ }), object({
59864
+ deleted: number().int(),
59865
+ secretRefs: SecretRefsList
59866
+ }), {
59867
+ kind: "mutation",
59868
+ auth: "admin"
59869
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59870
+ ...KindShape,
59871
+ ...TimeWindowShape,
59872
+ where: RecordWhereSchema.optional()
59873
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59874
+ ...KindShape,
59875
+ deviceId: number().int().optional(),
59876
+ from: number(),
59877
+ to: number(),
59878
+ bucketMs: number().int().positive()
59879
+ }), object({ buckets: array(object({
59880
+ bucketStart: number(),
59881
+ count: number().int()
59882
+ })) }), { auth: "admin" }), method(object({
59883
+ ...KindShape,
59884
+ op: _enum([
59885
+ "sum",
59886
+ "min",
59887
+ "max",
59888
+ "count"
59889
+ ]),
59890
+ field: RecordFieldPathSchema.optional(),
59891
+ groupBy: RecordFieldPathSchema.optional(),
59892
+ where: RecordWhereSchema.optional()
59893
+ }), object({ rows: array(object({
59894
+ group: union([
59895
+ string(),
59896
+ number(),
59897
+ _null()
59898
+ ]),
59899
+ value: number().nullable()
59900
+ })) }), { auth: "admin" }), method(object({
59901
+ ...KindShape,
59902
+ deviceId: number().int().optional(),
59903
+ atBefore: number().optional(),
59904
+ where: RecordWhereSchema.optional()
59905
+ }), object({
59906
+ deleted: number().int(),
59907
+ secretRefs: SecretRefsList
59908
+ }), {
59909
+ kind: "mutation",
59910
+ auth: "admin"
59911
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59912
+ results: array(object({
59913
+ rev: number().int().nullable(),
59914
+ deleted: boolean()
59915
+ })),
59916
+ releasedRefs: SecretRefsList,
59917
+ secretRefs: SecretRefsList
59918
+ }), {
59919
+ kind: "mutation",
59920
+ auth: "admin"
59921
+ }), method(object({
59922
+ deviceId: number().int(),
59923
+ kinds: array(RecordKindNameSchema).optional()
59924
+ }), object({
59925
+ deleted: record(string(), number().int()),
59926
+ secretRefs: SecretRefsList
59927
+ }), {
59928
+ kind: "mutation",
59929
+ auth: "admin"
59930
+ }), method(object(KindShape), object({ id: number().int() }), {
59931
+ kind: "mutation",
59932
+ auth: "admin"
59933
+ });
59934
+ /**
59935
+ * The wire shapes of the migration API, version 1 (planning#447).
59936
+ *
59937
+ * A migration is code that outlives the server it was written against: an addon at
59938
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59939
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59940
+ * is the contract of every method of it, one Zod pair per method.
59941
+ *
59942
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59943
+ * field is never removed or made required, an enum never narrows, an output field is
59944
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59945
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59946
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59947
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59948
+ */
59949
+ var Rows = record(string(), unknown());
59950
+ var IntegrationId = object({ integrationId: string().min(1) });
59951
+ var RecordId = object({ id: string().min(1) });
59952
+ var RecordRowSchema = object({
59953
+ id: string(),
59954
+ deviceId: number().int().nullable(),
59955
+ at: number().nullable(),
59956
+ expiresAt: number().nullable(),
59957
+ rev: number().int(),
59958
+ updatedAt: number(),
59959
+ data: Rows
59960
+ });
59961
+ var RecordPutShape = {
59962
+ id: string().min(1),
59963
+ deviceId: number().int().optional(),
59964
+ at: number().int().optional(),
59965
+ expiresAt: number().int().optional(),
59966
+ data: Rows
59967
+ };
59968
+ var MigrationIntegrationSchema = object({
59969
+ id: string(),
59970
+ addonId: string(),
59971
+ name: string(),
59972
+ info: Rows,
59973
+ originStableId: string().optional()
59974
+ });
59975
+ var MigrationDeviceSchema = object({
59976
+ id: number().int(),
59977
+ integrationId: string().nullable().optional(),
59978
+ /** The owning device; null or absent for a root. */
59979
+ parentDeviceId: number().int().nullable().optional(),
59980
+ type: string().optional(),
59981
+ name: string().optional(),
59982
+ stableId: string().optional()
59983
+ });
59984
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59985
+ var MigrationApiInfoSchema = object({
59986
+ version: number().int(),
59987
+ methods: array(string())
59988
+ });
59989
+ object({
59990
+ message: string(),
59991
+ meta: Rows.optional(),
59992
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59993
+ tags: object({ deviceId: number().int().optional() }).optional()
59994
+ });
59995
+ object({
59996
+ owner: string().min(1),
59997
+ metas: array(MigrationMetaSchema)
59998
+ }), object({
59999
+ bootId: string(),
60000
+ snapshot: _enum([
60001
+ "none",
60002
+ "written",
60003
+ "refused"
60004
+ ]),
60005
+ steps: array(MigrationOwnerStepSchema),
60006
+ /** The migration API the engine serves; absent from a server that predates it. */
60007
+ migrationApi: MigrationApiInfoSchema.optional()
60008
+ }), object({ id: string().min(1) }), object({
60009
+ proceed: boolean(),
60010
+ state: union([literal("pending"), MigrationStatusSchema]),
60011
+ reason: string().nullable()
60012
+ }), object({
60013
+ id: string().min(1),
60014
+ result: MigrationOwnerResultSchema
60015
+ }), object({
60016
+ status: MigrationStatusSchema,
60017
+ error: string().nullable(),
60018
+ rowsChanged: number().int().nonnegative()
60019
+ }), object({
60020
+ rows: number().int().nonnegative(),
60021
+ secrets: number().int().nonnegative()
60022
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
60023
+ present: boolean(),
60024
+ removed: Rows
60025
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
60026
+ ...RecordPutShape,
60027
+ ifRev: number().int().optional()
60028
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
60029
+ partial: Rows,
60030
+ ifRev: number().int().optional()
60031
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
60032
+ deviceId: number().int().optional(),
60033
+ atFrom: number().optional(),
60034
+ atTo: number().optional(),
60035
+ where: RecordWhereSchema.optional(),
60036
+ limit: number().int().min(1).optional(),
60037
+ cursor: string().min(1).optional(),
60038
+ resolveSecrets: boolean().optional()
60039
+ }), object({
60040
+ records: array(RecordRowSchema),
60041
+ nextCursor: string().nullable()
60042
+ }), object({
60043
+ deviceId: number().int().optional(),
60044
+ atBefore: number().optional(),
60045
+ where: RecordWhereSchema.optional()
60046
+ }), 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({
60047
+ ref: string().min(1),
60048
+ value: string()
60049
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
60050
+ addonId: string().min(1),
60051
+ integrationId: string().min(1).optional()
60052
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
60053
+ id: number().int(),
60054
+ integrationId: string().nullable(),
60055
+ /** Whether the device carries any stored config; its content is not offered. */
60056
+ hasConfig: boolean()
60057
+ }).nullable(), object({
60058
+ deviceId: number().int(),
60059
+ integrationId: string().min(1)
60060
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59679
60061
  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({
59680
60062
  id: string().min(1),
59681
60063
  error: string().min(1)
@@ -59705,7 +60087,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59705
60087
  "written",
59706
60088
  "refused"
59707
60089
  ]),
59708
- steps: array(MigrationOwnerStepSchema)
60090
+ steps: array(MigrationOwnerStepSchema),
60091
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
60092
+ migrationApi: MigrationApiInfoSchema.optional()
59709
60093
  }), {
59710
60094
  kind: "mutation",
59711
60095
  auth: "admin"
@@ -62372,7 +62756,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
62372
62756
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
62373
62757
  kind: "mutation",
62374
62758
  auth: "admin"
62375
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62759
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62760
+ kind: "query",
62761
+ auth: "admin"
62762
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62376
62763
  kind: "query",
62377
62764
  auth: "admin"
62378
62765
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -65027,7 +65414,7 @@ var BrokerStatusSchema$1 = _enum([
65027
65414
  "unreachable",
65028
65415
  "tls-error"
65029
65416
  ]);
65030
- var BrokerInfoSchema$1 = object({
65417
+ var BrokerInfoSchema = object({
65031
65418
  id: string(),
65032
65419
  name: string(),
65033
65420
  url: string(),
@@ -65090,7 +65477,7 @@ var StatusSchema = object({
65090
65477
  brokerCount: number(),
65091
65478
  embeddedRunning: boolean()
65092
65479
  });
65093
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65480
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65094
65481
  kind: "mutation",
65095
65482
  auth: "admin"
65096
65483
  }), method(IdInputSchema, _void(), {
@@ -72456,253 +72843,6 @@ var rebootCapability = {
72456
72843
  }) }
72457
72844
  };
72458
72845
  /**
72459
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
72460
- * config documents, mirrors. The third storage API next to `ctx.settings`
72461
- * (operator intent, D870) and device-history (numbers over time, D850).
72462
- *
72463
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
72464
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
72465
- * that with the addon id closed over). It is deliberately NOT in any input
72466
- * schema, so a session can never supply it, and a call with no stamp is refused
72467
- * `records/no-caller`. A kind is readable and writable only by its owner; other
72468
- * addons go through the owner's capability.
72469
- *
72470
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
72471
- * never `[]`. Secret fields are never on the wire: a read shows the
72472
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
72473
- * resolves itself, and a write may carry only a keychain marker bound to the
72474
- * row's own ref.
72475
- *
72476
- * Internal: addons reach it through `ctx.records`, never directly.
72477
- */
72478
- var RecordIdSchema = string().min(1).max(256);
72479
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
72480
- var RecordBodySchema = record(string(), unknown());
72481
- var RecordInputSchema = object({
72482
- id: RecordIdSchema,
72483
- /** The device this row belongs to (D865 removal, per-device reads). */
72484
- deviceId: number().int().optional(),
72485
- /** The domain clock, ms: observed / created / opened. */
72486
- at: number().int().optional(),
72487
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
72488
- expiresAt: number().int().optional(),
72489
- data: RecordBodySchema
72490
- });
72491
- var RecordViewSchema = object({
72492
- id: string(),
72493
- deviceId: number().int().nullable(),
72494
- at: number().nullable(),
72495
- expiresAt: number().nullable(),
72496
- rev: number().int(),
72497
- updatedAt: number(),
72498
- data: RecordBodySchema
72499
- });
72500
- /** Declared index fields only. Anything else does not compile, by design. */
72501
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
72502
- string(),
72503
- number(),
72504
- boolean(),
72505
- object({ in: array(union([
72506
- string(),
72507
- number(),
72508
- boolean()
72509
- ])).min(1).max(RECORD_BATCH_MAX) }),
72510
- object({
72511
- gt: union([string(), number()]).optional(),
72512
- gte: union([string(), number()]).optional(),
72513
- lt: union([string(), number()]).optional(),
72514
- lte: union([string(), number()]).optional()
72515
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
72516
- ]));
72517
- var KindShape = { kind: RecordKindNameSchema };
72518
- var TimeWindowShape = {
72519
- deviceId: number().int().optional(),
72520
- atFrom: number().optional(),
72521
- atTo: number().optional()
72522
- };
72523
- var RecordQueryInputSchema = object({
72524
- ...KindShape,
72525
- ...TimeWindowShape,
72526
- where: RecordWhereSchema.optional(),
72527
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
72528
- order: _enum(["at", "id"]).optional(),
72529
- desc: boolean().optional(),
72530
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
72531
- /** Opaque keyset cursor from a previous answer. There is no offset. */
72532
- cursor: string().min(1).optional()
72533
- });
72534
- var RecordQueryResultSchema = object({
72535
- records: array(RecordViewSchema),
72536
- nextCursor: string().nullable()
72537
- });
72538
- var RecordKindStateSchema = _enum([
72539
- "created",
72540
- "unchanged",
72541
- "updated"
72542
- ]);
72543
- var DeclareKindResultSchema = object({
72544
- kindId: number().int(),
72545
- state: RecordKindStateSchema,
72546
- createdIndexes: array(string())
72547
- });
72548
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
72549
- var SecretRefsList = array(string());
72550
- /**
72551
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
72552
- * All ops of one call share ONE database file and ONE `transactFamily`.
72553
- */
72554
- var RecordTransactOpSchema = discriminatedUnion("op", [
72555
- object({
72556
- op: literal("put"),
72557
- kind: RecordKindNameSchema,
72558
- record: RecordInputSchema,
72559
- ifRev: number().int().min(0).optional()
72560
- }),
72561
- object({
72562
- op: literal("patch"),
72563
- kind: RecordKindNameSchema,
72564
- id: RecordIdSchema,
72565
- data: RecordBodySchema,
72566
- at: number().int().nullable().optional(),
72567
- expiresAt: number().int().nullable().optional(),
72568
- ifRev: number().int().min(1).optional()
72569
- }),
72570
- object({
72571
- op: literal("delete"),
72572
- kind: RecordKindNameSchema,
72573
- id: RecordIdSchema
72574
- })
72575
- ]);
72576
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
72577
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
72578
- kind: "mutation",
72579
- auth: "admin"
72580
- }), method(object({
72581
- ...KindShape,
72582
- id: RecordIdSchema
72583
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
72584
- ...KindShape,
72585
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72586
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
72587
- ...KindShape,
72588
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72589
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
72590
- ...KindShape,
72591
- record: RecordInputSchema,
72592
- /** Compare-and-set. `0` means "the row must not exist". */
72593
- ifRev: number().int().min(0).optional()
72594
- }), object({
72595
- rev: number().int(),
72596
- releasedRefs: SecretRefsList
72597
- }), {
72598
- kind: "mutation",
72599
- auth: "admin"
72600
- }), method(object({
72601
- ...KindShape,
72602
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72603
- }), object({
72604
- count: number().int(),
72605
- releasedRefs: SecretRefsList
72606
- }), {
72607
- kind: "mutation",
72608
- auth: "admin"
72609
- }), method(object({
72610
- ...KindShape,
72611
- id: RecordIdSchema,
72612
- data: RecordBodySchema,
72613
- at: number().int().nullable().optional(),
72614
- expiresAt: number().int().nullable().optional(),
72615
- ifRev: number().int().min(1).optional()
72616
- }), object({
72617
- rev: number().int(),
72618
- releasedRefs: SecretRefsList
72619
- }), {
72620
- kind: "mutation",
72621
- auth: "admin"
72622
- }), method(object({
72623
- ...KindShape,
72624
- id: RecordIdSchema
72625
- }), object({
72626
- deleted: boolean(),
72627
- secretRefs: SecretRefsList
72628
- }), {
72629
- kind: "mutation",
72630
- auth: "admin"
72631
- }), method(object({
72632
- ...KindShape,
72633
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72634
- }), object({
72635
- deleted: number().int(),
72636
- secretRefs: SecretRefsList
72637
- }), {
72638
- kind: "mutation",
72639
- auth: "admin"
72640
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72641
- ...KindShape,
72642
- ...TimeWindowShape,
72643
- where: RecordWhereSchema.optional()
72644
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72645
- ...KindShape,
72646
- deviceId: number().int().optional(),
72647
- from: number(),
72648
- to: number(),
72649
- bucketMs: number().int().positive()
72650
- }), object({ buckets: array(object({
72651
- bucketStart: number(),
72652
- count: number().int()
72653
- })) }), { auth: "admin" }), method(object({
72654
- ...KindShape,
72655
- op: _enum([
72656
- "sum",
72657
- "min",
72658
- "max",
72659
- "count"
72660
- ]),
72661
- field: RecordFieldPathSchema.optional(),
72662
- groupBy: RecordFieldPathSchema.optional(),
72663
- where: RecordWhereSchema.optional()
72664
- }), object({ rows: array(object({
72665
- group: union([
72666
- string(),
72667
- number(),
72668
- _null()
72669
- ]),
72670
- value: number().nullable()
72671
- })) }), { auth: "admin" }), method(object({
72672
- ...KindShape,
72673
- deviceId: number().int().optional(),
72674
- atBefore: number().optional(),
72675
- where: RecordWhereSchema.optional()
72676
- }), object({
72677
- deleted: number().int(),
72678
- secretRefs: SecretRefsList
72679
- }), {
72680
- kind: "mutation",
72681
- auth: "admin"
72682
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72683
- results: array(object({
72684
- rev: number().int().nullable(),
72685
- deleted: boolean()
72686
- })),
72687
- releasedRefs: SecretRefsList,
72688
- secretRefs: SecretRefsList
72689
- }), {
72690
- kind: "mutation",
72691
- auth: "admin"
72692
- }), method(object({
72693
- deviceId: number().int(),
72694
- kinds: array(RecordKindNameSchema).optional()
72695
- }), object({
72696
- deleted: record(string(), number().int()),
72697
- secretRefs: SecretRefsList
72698
- }), {
72699
- kind: "mutation",
72700
- auth: "admin"
72701
- }), method(object(KindShape), object({ id: number().int() }), {
72702
- kind: "mutation",
72703
- auth: "admin"
72704
- });
72705
- /**
72706
72846
  * record-entries - the ONE admin surface for every list of user-created entries
72707
72847
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72708
72848
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -83570,7 +83710,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83570
83710
  * `deviceClasses` map (first registered type). `null` when manual creation is
83571
83711
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
83572
83712
  */
83573
- async getManualCreationType() {
83713
+ async getManualCreationType(_input) {
83574
83714
  if (!await this.supportsManualCreation()) return { deviceType: null };
83575
83715
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
83576
83716
  }
@@ -83581,7 +83721,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83581
83721
  return true;
83582
83722
  }
83583
83723
  async getChildCreationSchema(input) {
83584
- return this.onGetCreationSchema(input.type);
83724
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
83585
83725
  }
83586
83726
  /**
83587
83727
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -83593,7 +83733,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83593
83733
  * `deviceClasses` instead.
83594
83734
  */
83595
83735
  async createDevice(input) {
83596
- const spec = await this.onCreateDevice(input.type, input.config);
83736
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
83597
83737
  const Class = this.deviceClasses[spec.meta.type];
83598
83738
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
83599
83739
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -85006,20 +85146,6 @@ Object.freeze({
85006
85146
  access: "create",
85007
85147
  role: "viewer"
85008
85148
  },
85009
- "broker.add": {
85010
- capName: "broker",
85011
- capScope: "system",
85012
- addonId: null,
85013
- access: "create",
85014
- role: "admin"
85015
- },
85016
- "broker.get": {
85017
- capName: "broker",
85018
- capScope: "system",
85019
- addonId: null,
85020
- access: "view",
85021
- role: "admin"
85022
- },
85023
85149
  "broker.getBrokerConfig": {
85024
85150
  capName: "broker",
85025
85151
  capScope: "system",
@@ -85027,20 +85153,6 @@ Object.freeze({
85027
85153
  access: "view",
85028
85154
  role: "admin"
85029
85155
  },
85030
- "broker.getSettings": {
85031
- capName: "broker",
85032
- capScope: "system",
85033
- addonId: null,
85034
- access: "view",
85035
- role: "admin"
85036
- },
85037
- "broker.getSettingsSchema": {
85038
- capName: "broker",
85039
- capScope: "system",
85040
- addonId: null,
85041
- access: "view",
85042
- role: "admin"
85043
- },
85044
85156
  "broker.getState": {
85045
85157
  capName: "broker",
85046
85158
  capScope: "system",
@@ -85055,20 +85167,6 @@ Object.freeze({
85055
85167
  access: "view",
85056
85168
  role: "admin"
85057
85169
  },
85058
- "broker.list": {
85059
- capName: "broker",
85060
- capScope: "system",
85061
- addonId: null,
85062
- access: "view",
85063
- role: "admin"
85064
- },
85065
- "broker.listProviders": {
85066
- capName: "broker",
85067
- capScope: "system",
85068
- addonId: null,
85069
- access: "view",
85070
- role: "admin"
85071
- },
85072
85170
  "broker.publish": {
85073
85171
  capName: "broker",
85074
85172
  capScope: "system",
@@ -85076,20 +85174,6 @@ Object.freeze({
85076
85174
  access: "create",
85077
85175
  role: "admin"
85078
85176
  },
85079
- "broker.remove": {
85080
- capName: "broker",
85081
- capScope: "system",
85082
- addonId: null,
85083
- access: "delete",
85084
- role: "admin"
85085
- },
85086
- "broker.setSettings": {
85087
- capName: "broker",
85088
- capScope: "system",
85089
- addonId: null,
85090
- access: "create",
85091
- role: "admin"
85092
- },
85093
85177
  "broker.subscribe": {
85094
85178
  capName: "broker",
85095
85179
  capScope: "system",
@@ -85097,20 +85181,6 @@ Object.freeze({
85097
85181
  access: "create",
85098
85182
  role: "admin"
85099
85183
  },
85100
- "broker.testConnection": {
85101
- capName: "broker",
85102
- capScope: "system",
85103
- addonId: null,
85104
- access: "create",
85105
- role: "admin"
85106
- },
85107
- "broker.testSettings": {
85108
- capName: "broker",
85109
- capScope: "system",
85110
- addonId: null,
85111
- access: "create",
85112
- role: "admin"
85113
- },
85114
85184
  "broker.unsubscribe": {
85115
85185
  capName: "broker",
85116
85186
  capScope: "system",
@@ -90074,6 +90144,13 @@ Object.freeze({
90074
90144
  access: "view",
90075
90145
  role: "viewer"
90076
90146
  },
90147
+ "pipelineAnalytics.getMediaLocationCensus": {
90148
+ capName: "pipeline-analytics",
90149
+ capScope: "device",
90150
+ addonId: null,
90151
+ access: "view",
90152
+ role: "admin"
90153
+ },
90077
90154
  "pipelineAnalytics.getMediaReclaimStatus": {
90078
90155
  capName: "pipeline-analytics",
90079
90156
  capScope: "device",
@@ -99284,6 +99361,100 @@ object({
99284
99361
  delay: number().nonnegative().optional(),
99285
99362
  commands: record(string(), unknown())
99286
99363
  });
99364
+ entryBody({ brokerId: string() });
99365
+ function secretsOverMigrationApi(api) {
99366
+ return {
99367
+ resolve: async (refs) => {
99368
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
99369
+ const out = {};
99370
+ for (const ref of refs) {
99371
+ const value = values[ref];
99372
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
99373
+ kind: "value",
99374
+ value,
99375
+ version: 0
99376
+ };
99377
+ }
99378
+ return out;
99379
+ },
99380
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
99381
+ };
99382
+ }
99383
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
99384
+ function recordsOverMigrationApi(api) {
99385
+ return { kind: (definition) => {
99386
+ const handle = api.records.kind(definition);
99387
+ return {
99388
+ get: (id) => handle.get({ id }),
99389
+ getResolved: (id) => handle.getResolved({ id }),
99390
+ put: (input, opts) => handle.put({
99391
+ ...input,
99392
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
99393
+ }),
99394
+ delete: (id) => handle.delete({ id })
99395
+ };
99396
+ } };
99397
+ }
99398
+ function integrationRowsApiOver(api) {
99399
+ return {
99400
+ list: async () => (await api.integrations.list({})).integrations,
99401
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
99402
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
99403
+ };
99404
+ }
99405
+ /**
99406
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
99407
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
99408
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
99409
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
99410
+ */
99411
+ var lanes = /* @__PURE__ */ new WeakMap();
99412
+ function deliver(api, send) {
99413
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
99414
+ const reason = error instanceof Error ? error.message : String(error);
99415
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
99416
+ });
99417
+ lanes.set(api, next);
99418
+ return next;
99419
+ }
99420
+ function warnOver(api) {
99421
+ return (message) => deliver(api, () => api.log.warn({ message }));
99422
+ }
99423
+ /** What the rows-to-records move needs, over the migration API. */
99424
+ function rowsDepsOver(api) {
99425
+ return {
99426
+ api: integrationRowsApiOver(api),
99427
+ records: recordsOverMigrationApi(api),
99428
+ secrets: secretsOverMigrationApi(api),
99429
+ warn: warnOver(api)
99430
+ };
99431
+ }
99432
+ function defaultIntegrationApiOver$1(api) {
99433
+ return {
99434
+ ...integrationRowsApiOver(api),
99435
+ listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
99436
+ readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
99437
+ setDeviceIntegrationId: async (deviceId, integrationId) => {
99438
+ await api.devices.setIntegrationId({
99439
+ deviceId,
99440
+ integrationId
99441
+ });
99442
+ },
99443
+ readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
99444
+ };
99445
+ }
99446
+ /** What the rows-to-records move and the device claim need, over the migration API. */
99447
+ function defaultIntegrationDepsOver(api) {
99448
+ return {
99449
+ ...rowsDepsOver(api),
99450
+ api: defaultIntegrationApiOver$1(api),
99451
+ info: (message) => deliver(api, () => api.log.info({ message })),
99452
+ warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
99453
+ message,
99454
+ tags: { deviceId }
99455
+ }))
99456
+ };
99457
+ }
99287
99458
  /**
99288
99459
  * Per-device bounds for the STILLS, which are a different artifact entirely.
99289
99460
  *
@@ -113010,18 +113181,13 @@ var HikvisionProviderAddon = class extends BaseDeviceProvider {
113010
113181
  const records = this.ctx.records;
113011
113182
  if (records === void 0) throw new Error("provider-hikvision: ctx.records is required (hub-only addon)");
113012
113183
  await records.declare(hikvisionRecordKinds);
113013
- await this.runMigrations(defineAddonMigrations(defaultIntegrationMigrations({
113184
+ await this.runMigrations(defaultIntegrationMigrations({
113014
113185
  addonId: this.addonId,
113015
113186
  date: HIKVISION_MIGRATIONS_DATE
113016
- }), defaultIntegrationPortsOver({
113017
- api: defaultIntegrationApiOver(this.ctx.api),
113018
- secrets: this.ctx.secrets ?? null,
113019
- records,
113020
- kind: hikvisionConnectionsEntryKind,
113021
- info: (message) => this.ctx.logger.info(message),
113022
- warn: (message) => this.ctx.logger.warn(message),
113023
- warnDevice: (message, deviceId) => this.ctx.logger.warn(message, { tags: { deviceId } })
113024
- })));
113187
+ }), (api) => defaultIntegrationPortsOver({
113188
+ ...defaultIntegrationDepsOver(api),
113189
+ kind: hikvisionConnectionsEntryKind
113190
+ }));
113025
113191
  regs.push({
113026
113192
  capability: failureContributionCapability,
113027
113193
  provider: { list: () => intercomFailureReport.list() }