@camstack/addon-provider-amcrest 0.2.166 → 0.2.167

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/addon.js CHANGED
@@ -6015,7 +6015,7 @@ var ZodIssueCode = {
6015
6015
  var ZodFirstPartyTypeKind;
6016
6016
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6017
6017
  //#endregion
6018
- //#region ../types/dist/sleep-9TIHFj1w.mjs
6018
+ //#region ../types/dist/sleep-BX_MqzUe.mjs
6019
6019
  /**
6020
6020
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6021
6021
  * window to float samples (D455).
@@ -6824,6 +6824,12 @@ function projectStore(store, perNodeKeys, nodeId) {
6824
6824
  }
6825
6825
  return out;
6826
6826
  }
6827
+ /** Every scope, in the order the guard and the docs list them. */
6828
+ var SCOPED_SETTINGS_SCOPES = [
6829
+ "cluster",
6830
+ "device-defaults",
6831
+ "node"
6832
+ ];
6827
6833
  /**
6828
6834
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6829
6835
  *
@@ -7638,6 +7644,28 @@ var SECRET_RETRY_MAX_MS = 5 * 6e4;
7638
7644
  /** Coalesces a burst of `keychain.changed` events into one re-resolve. */
7639
7645
  var SECRET_CHANGE_DEBOUNCE_MS = 250;
7640
7646
  /**
7647
+ * Pair a catalogue with the function that builds its ports FROM THE MIGRATION API. The one
7648
+ * place a catalogue is bound: a migration reaches nothing a ports binder cannot reach
7649
+ * through `api` (guard `check-migration-ports-surface`).
7650
+ */
7651
+ function migrationSet(catalogue, bindPorts) {
7652
+ return { bind: (api) => defineAddonMigrations(catalogue, bindPorts(api)) };
7653
+ }
7654
+ /** A mixed array is a mistake: the other kind would be dropped without a word. */
7655
+ function refuseMixed(form, kept, dropped) {
7656
+ 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`);
7657
+ }
7658
+ function catalogueOf(list) {
7659
+ const kept = list.filter((entry) => !("execute" in entry));
7660
+ refuseMixed("catalogue, (api) => ports", kept.length, list.length - kept.length);
7661
+ return kept;
7662
+ }
7663
+ function boundOf(list) {
7664
+ const kept = list.filter((entry) => "execute" in entry);
7665
+ refuseMixed("bound migrations", kept.length, list.length - kept.length);
7666
+ return kept;
7667
+ }
7668
+ /**
7641
7669
  * Base class for CamStack addons. Eliminates settings boilerplate:
7642
7670
  *
7643
7671
  * - Typed `config` property with automatic resolution from store + defaults
@@ -7715,6 +7743,13 @@ var BaseAddon = class {
7715
7743
  */
7716
7744
  secretStatePaths = [];
7717
7745
  _addonSecretTree = null;
7746
+ /**
7747
+ * D986 M4: the scoped schemas this addon declared, resolved once per capability
7748
+ * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
7749
+ * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
7750
+ */
7751
+ _scopedByCap = /* @__PURE__ */ new Map();
7752
+ _nodeKeysByCap = /* @__PURE__ */ new Map();
7718
7753
  _deviceSecretTree = null;
7719
7754
  /** Refs the last resolved config pointed at — a change to one re-resolves. */
7720
7755
  _configSecretRefs = /* @__PURE__ */ new Set();
@@ -7784,6 +7819,7 @@ var BaseAddon = class {
7784
7819
  this._ctx = context;
7785
7820
  this._secretSettings = null;
7786
7821
  }
7822
+ await this.loadScopedSchemas();
7787
7823
  await this.resolveConfig();
7788
7824
  if (secrets !== void 0) this._secretChangeUnsub = secrets.onChange((ref) => {
7789
7825
  if (this._configSecretRefs.has(ref)) this.scheduleSecretReresolve(SECRET_CHANGE_DEBOUNCE_MS);
@@ -7793,25 +7829,24 @@ var BaseAddon = class {
7793
7829
  const normalized = normalizeAddonInitResult(result);
7794
7830
  const providers = normalized && "providers" in normalized && normalized.providers ? normalized.providers : [];
7795
7831
  this._registeredCapNames = providers.map((p) => p.capability.name);
7832
+ await this.loadScopedSchemas();
7796
7833
  return normalized;
7797
7834
  }
7835
+ async runMigrations(first, second, third) {
7836
+ if (typeof second === "function") return this.runMigrationSets([migrationSet(catalogueOf(first), second)], third);
7837
+ return this.runBound(boundOf(first), second);
7838
+ }
7798
7839
  /**
7799
- * Run this addon's migration catalogue (D987 M3) through the hub's `migrations`
7800
- * engine. Call it at the point of the boot where the data must already have the new
7801
- * shape — `onInitialize`, or `onRestoreDevices` for a migration that needs the
7802
- * restored devices — with the catalogue bound to the addon's ports
7803
- * (`defineAddonMigrations(ADDON_MIGRATIONS, ports)`).
7804
- *
7805
- * An engine that cannot be reached or refuses the catalogue is logged and runs
7806
- * nothing; the boot continues. A migration that FAILED (or was blocked by one)
7807
- * and declares `onFailure: 'block-owner'` makes this throw, so the addon does not
7808
- * serve data whose shape it cannot trust; `tolerate` migrations never do.
7809
- *
7810
- * ALWAYS pass the whole catalogue; a phase that must run only some of it passes
7811
- * `{ only: [ids] }` — never a filtered catalogue (the engine would judge the
7812
- * omitted applied ids "newer").
7840
+ * Several catalogues of ONE owner in one declaration (the engine replaces an owner's
7841
+ * catalogue on every declare, so two calls would each judge the other's ids "newer").
7842
+ * Build each entry with `migrationSet(catalogue, (api) => ports)`.
7813
7843
  */
7814
- async runMigrations(migrations, options) {
7844
+ async runMigrationSets(sets, options) {
7845
+ const api = this.ctx.migrationApi;
7846
+ if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7847
+ return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7848
+ }
7849
+ async runBound(migrations, options) {
7815
7850
  const api = this.ctx.api.migrations;
7816
7851
  const report = await runAddonMigrations({
7817
7852
  declareOwner: (input) => api.declareOwner.mutate(input),
@@ -7881,6 +7916,16 @@ var BaseAddon = class {
7881
7916
  schema(schema) {
7882
7917
  return schema;
7883
7918
  }
7919
+ /**
7920
+ * The capability names whose scoped settings schemas ({@link clusterSettingsSchema},
7921
+ * {@link nodeSettingsSchema}, {@link deviceDefaultsSchema}) this addon declares. Read BEFORE
7922
+ * `onInitialize`, when the providers it registers are not known yet: the first config resolve
7923
+ * must already know which keys are per node. Names the providers register at init are added
7924
+ * once known.
7925
+ */
7926
+ scopedSettingsCapabilities() {
7927
+ return [];
7928
+ }
7884
7929
  /** Override to provide global-level settings UI schema. */
7885
7930
  globalSettingsSchema(_cap) {
7886
7931
  return null;
@@ -7924,7 +7969,8 @@ var BaseAddon = class {
7924
7969
  return [];
7925
7970
  }
7926
7971
  async getGlobalSettings(overlay, cap, nodeId) {
7927
- const schema = this.globalSettingsSchema(cap);
7972
+ await this.loadScopedSchemas(cap);
7973
+ const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
7928
7974
  if (!schema) return { sections: [] };
7929
7975
  const projected = await this.readRawProjectedStore(nodeId, cap);
7930
7976
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
@@ -8055,6 +8101,7 @@ var BaseAddon = class {
8055
8101
  * resolved blob back is a no-op for every unchanged secret.
8056
8102
  */
8057
8103
  async resolveGlobalStore(nodeId, cap) {
8104
+ await this.loadScopedSchemas(cap);
8058
8105
  const raw = await this._ctx?.settings?.readAddonStore() ?? {};
8059
8106
  return this.projectForNode(raw, nodeId, cap);
8060
8107
  }
@@ -8065,6 +8112,7 @@ var BaseAddon = class {
8065
8112
  }
8066
8113
  /** The PROJECTED store with its markers — the form hydrate only (D798). */
8067
8114
  async readRawProjectedStore(nodeId, cap) {
8115
+ await this.loadScopedSchemas(cap);
8068
8116
  const raw = await this.rawSettings()?.readAddonStore() ?? {};
8069
8117
  return this.projectForNode(raw, nodeId, cap);
8070
8118
  }
@@ -8167,6 +8215,7 @@ var BaseAddon = class {
8167
8215
  await this.applyGlobalPatch(patch, nodeId);
8168
8216
  }
8169
8217
  async applyGlobalPatch(barePatch, nodeId) {
8218
+ await this.loadScopedSchemas();
8170
8219
  const keys = this.perNodeKeys();
8171
8220
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8172
8221
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
@@ -8180,7 +8229,8 @@ var BaseAddon = class {
8180
8229
  await this.resolveConfig();
8181
8230
  await this.onConfigChanged();
8182
8231
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8183
- this.maybeAutoRestart(Object.keys(barePatch), this.globalSettingsSchema());
8232
+ const legacy = this.globalSettingsSchema();
8233
+ this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
8184
8234
  }
8185
8235
  /**
8186
8236
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8188,14 +8238,67 @@ var BaseAddon = class {
8188
8238
  * declarations). Empty set ⇒ every per-node code path is bypassed and the
8189
8239
  * settings API behaves exactly like the legacy node-agnostic one.
8190
8240
  */
8191
- _perNodeKeysCache = /* @__PURE__ */ new Map();
8241
+ /**
8242
+ * Load the scoped schemas of every capability this addon declares (the override and the
8243
+ * providers registered at init, plus `extraCap`) that is not loaded yet, then drop what was
8244
+ * derived from the previous set. Idempotent.
8245
+ */
8246
+ async loadScopedSchemas(extraCap) {
8247
+ const caps = new Set([
8248
+ ...this.scopedSettingsCapabilities(),
8249
+ ...this._registeredCapNames,
8250
+ ...extraCap === void 0 ? [] : [extraCap]
8251
+ ]);
8252
+ let added = false;
8253
+ for (const cap of caps) {
8254
+ if (this._scopedByCap.has(cap)) continue;
8255
+ const loaded = [];
8256
+ for (const scope of SCOPED_SETTINGS_SCOPES) {
8257
+ const schema = await this.getScopedSettingsSchema(scope, cap);
8258
+ if (schema !== null) loaded.push({
8259
+ scope,
8260
+ schema
8261
+ });
8262
+ }
8263
+ this._scopedByCap.set(cap, loaded);
8264
+ added = true;
8265
+ }
8266
+ if (!added) return;
8267
+ this._nodeKeysByCap = /* @__PURE__ */ new Map();
8268
+ this._addonSecretTree = null;
8269
+ }
8270
+ /**
8271
+ * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8272
+ * sections of its scoped schemas, so dropping the old hook does not blank the form.
8273
+ */
8274
+ scopedFormSchema(cap) {
8275
+ const byId = /* @__PURE__ */ new Map();
8276
+ for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
8277
+ return byId.size === 0 ? null : { sections: [...byId.values()] };
8278
+ }
8279
+ /** Every loaded scoped schema of `cap`, or of every loaded capability. */
8280
+ loadedScopedSchemas(cap) {
8281
+ if (cap !== void 0) return this._scopedByCap.get(cap) ?? [];
8282
+ return [...this._scopedByCap.values()].flat();
8283
+ }
8284
+ /**
8285
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8286
+ * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
8287
+ * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8288
+ * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8289
+ * Call {@link loadScopedSchemas} first (the async seams do).
8290
+ */
8192
8291
  perNodeKeys(cap) {
8193
8292
  const cacheKey = cap ?? "";
8194
- const cached = this._perNodeKeysCache.get(cacheKey);
8293
+ const cached = this._nodeKeysByCap.get(cacheKey);
8195
8294
  if (cached) return cached;
8196
- const schema = this.globalSettingsSchema(cap);
8197
- const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8198
- this._perNodeKeysCache.set(cacheKey, keys);
8295
+ const legacy = this.globalSettingsSchema(cap);
8296
+ const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
8297
+ for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8298
+ if (scope !== "node") continue;
8299
+ for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
8300
+ }
8301
+ this._nodeKeysByCap.set(cacheKey, keys);
8199
8302
  return keys;
8200
8303
  }
8201
8304
  /**
@@ -8205,10 +8308,9 @@ var BaseAddon = class {
8205
8308
  * time to return its response before the addon is torn down and
8206
8309
  * re-initialised by `AddonRegistryService.restartAddon`.
8207
8310
  */
8208
- maybeAutoRestart(patchKeys, schema) {
8209
- if (!schema) return;
8311
+ maybeAutoRestart(patchKeys, schemas) {
8210
8312
  const restartKeys = /* @__PURE__ */ new Set();
8211
- for (const section of schema.sections) for (const field of section.fields) {
8313
+ for (const schema of schemas) for (const section of schema.sections) for (const field of section.fields) {
8212
8314
  if (field.type === "separator" || field.type === "info") continue;
8213
8315
  if (field.requiresRestart) restartKeys.add(field.key);
8214
8316
  }
@@ -8404,12 +8506,14 @@ var BaseAddon = class {
8404
8506
  * here, in the addon's own process, so the hub keeps no copy of it.
8405
8507
  */
8406
8508
  async getDeclaredSettingsKeys() {
8509
+ await this.loadScopedSchemas();
8407
8510
  return { keys: [...this.declaredKeySet()].toSorted() };
8408
8511
  }
8409
8512
  declaredKeySet() {
8410
8513
  const keys = new Set(Object.keys(this.defaults));
8411
8514
  const schema = this.globalSettingsSchema();
8412
8515
  if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8516
+ for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
8413
8517
  for (const key of this._declaredStateKeys) keys.add(key);
8414
8518
  for (const path of this.secretStatePaths) {
8415
8519
  const root = path.split(/[.[]/, 1)[0];
@@ -8505,7 +8609,11 @@ var BaseAddon = class {
8505
8609
  }
8506
8610
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
8507
8611
  addonSecretTree() {
8508
- this._addonSecretTree ??= mergeSecretStatePaths(secretTreeFromSchema(this.globalSettingsSchema()), this.secretStatePaths);
8612
+ if (this._addonSecretTree === null) {
8613
+ const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
8614
+ for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
8615
+ this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
8616
+ }
8509
8617
  return this._addonSecretTree;
8510
8618
  }
8511
8619
  deviceSecretTree() {
@@ -8755,6 +8863,23 @@ function dropPerNodeFields(fields) {
8755
8863
  }
8756
8864
  return kept;
8757
8865
  }
8866
+ /** The keys of the value-holding fields, recursing into layout containers. */
8867
+ function collectValueFieldKeys(fields) {
8868
+ const collected = [];
8869
+ for (const field of fields) {
8870
+ if (field.type === "group") {
8871
+ collected.push(...collectValueFieldKeys(field.fields));
8872
+ continue;
8873
+ }
8874
+ if (field.type === "sub-tabs") {
8875
+ for (const tab of field.tabs) collected.push(...collectValueFieldKeys(tab.fields));
8876
+ continue;
8877
+ }
8878
+ if (field.type === "separator" || field.type === "info") continue;
8879
+ if ("key" in field && typeof field.key === "string") collected.push(field.key);
8880
+ }
8881
+ return collected;
8882
+ }
8758
8883
  function collectFieldKeys(fields) {
8759
8884
  const collected = [];
8760
8885
  for (const field of fields) {
@@ -13462,7 +13587,7 @@ var RecordIntegrationInstances = class {
13462
13587
  return record === null ? null : this.viewOf(record);
13463
13588
  };
13464
13589
  /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13465
- createInstance = async ({ id, name, kind }) => {
13590
+ createInstance = async ({ id, name, kind, values }) => {
13466
13591
  const minted = id ?? this.hooks.mintId?.({
13467
13592
  name,
13468
13593
  ...kind !== void 0 ? { kind } : {}
@@ -13472,10 +13597,20 @@ var RecordIntegrationInstances = class {
13472
13597
  id: minted,
13473
13598
  data: this.hooks.initialBody(name, kind)
13474
13599
  }, { ifRev: 0 });
13600
+ const patch = this.patchOf(values ?? {});
13601
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13475
13602
  await this.hooks.onChanged?.(minted, "created");
13476
13603
  return { id: minted };
13477
13604
  };
13478
13605
  updateInstance = async ({ id, name, values }) => {
13606
+ const patch = this.patchOf(values);
13607
+ if (name !== void 0) patch[this.nameField] = name;
13608
+ await this.handle.patch(id, patch);
13609
+ await this.hooks.onChanged?.(id, "updated");
13610
+ return { ok: true };
13611
+ };
13612
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13613
+ patchOf(values) {
13479
13614
  const patch = {};
13480
13615
  for (const [key, value] of Object.entries(values)) {
13481
13616
  if (value === void 0) continue;
@@ -13486,11 +13621,8 @@ var RecordIntegrationInstances = class {
13486
13621
  else if (isSecretClear(value)) patch[key] = null;
13487
13622
  else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13488
13623
  }
13489
- if (name !== void 0) patch[this.nameField] = name;
13490
- await this.handle.patch(id, patch);
13491
- await this.hooks.onChanged?.(id, "updated");
13492
- return { ok: true };
13493
- };
13624
+ return patch;
13625
+ }
13494
13626
  /** The switch lives in the record body; the addon is told so it applies it (D996). */
13495
13627
  setInstanceEnabled = async ({ id, enabled }) => {
13496
13628
  if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
@@ -14813,13 +14945,13 @@ async function claimDevicesToDefaultIntegration(ports, spec) {
14813
14945
  };
14814
14946
  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`);
14815
14947
  for (const device of orphans) if (resolve(device, new Set([device.id])) === null) unresolved.add(device.id);
14816
- 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);
14948
+ 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);
14817
14949
  for (const [deviceId, integrationId] of plan) await ports.setIntegrationId(deviceId, integrationId);
14818
14950
  const wrong = [];
14819
14951
  for (const [deviceId, integrationId] of plan) if (await ports.readIntegrationId(deviceId) !== integrationId) wrong.push(deviceId);
14820
14952
  if (wrong.length > 0) throw new Error(`device(s) ${wrong.join(", ")} did not read back their integration after the claim`);
14821
14953
  const claimed = plan.size;
14822
- 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`);
14954
+ 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`);
14823
14955
  return {
14824
14956
  outcome: claimed > 0 ? "done" : "already-done",
14825
14957
  summary: {
@@ -14945,25 +15077,6 @@ function defaultIntegrationMigrations(spec) {
14945
15077
  ...spec.eligible !== void 0 ? { eligible: spec.eligible } : {}
14946
15078
  })];
14947
15079
  }
14948
- function defaultIntegrationApiOver(api) {
14949
- return {
14950
- list: () => api.integrations.list.query(),
14951
- readLegacyIntegrationRows: (input) => api.migrations.readLegacyIntegrationRows.query(input),
14952
- clearLegacyIntegrationRows: (input) => api.migrations.clearLegacyIntegrationRows.mutate(input),
14953
- listDevices: (addonId) => api.deviceManager.listAll.query({
14954
- addonId,
14955
- projection: "slim"
14956
- }),
14957
- setDeviceIntegrationId: async (deviceId, integrationId) => {
14958
- await api.deviceManager.setIntegrationId.mutate({
14959
- deviceId,
14960
- integrationId
14961
- });
14962
- },
14963
- readDeviceHasConfig: async (deviceId) => Object.keys((await api.deviceManager.getDevice.query({ deviceId }))?.config ?? {}).length > 0,
14964
- readDeviceIntegrationId: async (deviceId) => (await api.deviceManager.getDevice.query({ deviceId }))?.integrationId ?? null
14965
- };
14966
- }
14967
15080
  /**
14968
15081
  * The trainer contract — what the hub hands the cloud trainer and what it
14969
15082
  * gets back (cloud training, D805+).
@@ -16070,6 +16183,39 @@ var UnstampedEventMediaCountSchema = object({
16070
16183
  /** Sum across both, or `null` when either lane could not be counted. */
16071
16184
  total: number().int().nonnegative().nullable()
16072
16185
  }).nullable();
16186
+ /**
16187
+ * Where the stored event media sits, per storage location: how many media rows
16188
+ * and how many bytes carry each location id, how many carry none (legacy,
16189
+ * resolved to the default `eventMedia` location), and how many name a location
16190
+ * that was not asked about (a deleted or never-listed one).
16191
+ *
16192
+ * One covering-index aggregate per asked location plus the NULL one, and one
16193
+ * unfiltered total that scans the covering index: O(rows), not a walk of the
16194
+ * rows themselves. `unlisted` is total minus the ASKED locations minus NULL, so
16195
+ * it is a deleted location only when every location id was asked.
16196
+ * `null` is "could not be measured", never zero.
16197
+ */
16198
+ var MediaLocationCensusInputSchema = object({ locationIds: array(string().min(1)).max(50).readonly() });
16199
+ var MediaLocationCensusSchema = object({
16200
+ locations: array(object({
16201
+ locationId: string(),
16202
+ rows: number().int().nonnegative(),
16203
+ bytes: number().nonnegative()
16204
+ })).readonly(),
16205
+ unstamped: object({
16206
+ rows: number().int().nonnegative(),
16207
+ bytes: number().nonnegative()
16208
+ }),
16209
+ /** Rows stamped with a location id that was not in the asked list. */
16210
+ unlisted: object({
16211
+ rows: number().int().nonnegative(),
16212
+ bytes: number().nonnegative()
16213
+ }),
16214
+ total: object({
16215
+ rows: number().int().nonnegative(),
16216
+ bytes: number().nonnegative()
16217
+ })
16218
+ });
16073
16219
  var StorageMigrationMediaMoveInputSchema = RelocateMediaInputSchema.extend({ leaseId: string().min(1) });
16074
16220
  /** The independently selectable logical storage classes — every class
16075
16221
  * `storage.listLocationDeclarations` reports, so an operator never meets a
@@ -47106,52 +47252,7 @@ onBrightnessChanged: { data: object({
47106
47252
  minIntervalMs: 0
47107
47253
  } } }
47108
47254
  };
47109
- /**
47110
- * `broker` — unified pub/sub broker registry, system-scoped collection.
47111
- *
47112
- * The cap models any kind-tagged message broker the user wants to
47113
- * register and that other addons might consume. The first two kinds
47114
- * are MQTT (mosquitto / aedes embedded / cloud bridge) and
47115
- * Home Assistant (HA WebSocket — subscribe_entities + call_service).
47116
- * Future kinds (Zigbee2MQTT bridge, ZHA, KNX, Telegram, …) plug in
47117
- * the same surface.
47118
- *
47119
- * Why one cap, not one cap per kind:
47120
- * - The integrations page wants a single table of "every broker"
47121
- * across kinds; a unified cap drives it without join logic.
47122
- * - Generic admin operations (add / remove / test / status) are
47123
- * identical across kinds — duplicating them per cap was busywork.
47124
- * - The `network-access` cap precedent: same interface, many
47125
- * `providerKind: 'ingress'` implementations (Tailscale, ngrok, …).
47126
- *
47127
- * What stays kind-specific:
47128
- * - `getBrokerConfig` payload (kind decides whether it returns
47129
- * mqtt URL+creds, HA baseUrl+token, …) — typed as
47130
- * `Record<string, unknown>` at the wire; consumers narrow.
47131
- * - `publish` / `subscribe` / `getState` arguments (target / filter /
47132
- * key) — also typed as `Record<string, unknown>` so each kind can
47133
- * evolve its surface (MQTT topic+qos vs HA entity_id+domain)
47134
- * without rebreaking the cap signature.
47135
- * - `add` `settings` payload (different fields per kind, validated by
47136
- * the kind-specific provider).
47137
- *
47138
- * Bidirectionality:
47139
- * - `publish` is RPC — synchronous result (provider-defined).
47140
- * - `subscribe` returns a subscription handle; the actual message
47141
- * stream flows over the typed event-bus as `broker.message` events
47142
- * keyed by `(brokerId, subscriptionId)`. Consumers filter in their
47143
- * event handler. Subscriptions persist across reconnects — the
47144
- * provider re-subscribes upstream after a transport drop.
47145
- *
47146
- * Why event-bus push (not a subscription RPC stream):
47147
- * - Matches the rest of CamStack's D8 contract — events for telemetry,
47148
- * RPC for loss-is-a-bug. Broker messages are telemetry (a single
47149
- * drop is recoverable via `getState({key})`).
47150
- * - Frees `broker.subscribe` from holding a long-lived RPC channel.
47151
- * - Cross-process: events already route through `$event-bus`; no
47152
- * per-broker wire-shaping needed.
47153
- */
47154
- var BrokerStatusEnum = _enum([
47255
+ _enum([
47155
47256
  "connected",
47156
47257
  "disconnected",
47157
47258
  "connecting",
@@ -47159,141 +47260,12 @@ var BrokerStatusEnum = _enum([
47159
47260
  "unreachable",
47160
47261
  "error"
47161
47262
  ]);
47162
- var BrokerInfoSchema = object({
47163
- /** Stable broker id. Persisted; survives addon restarts. */
47164
- id: string(),
47165
- /** Addon id of the provider that OWNS this broker.
47166
- *
47167
- * The `broker` cap is a system-scoped collection: several addons
47168
- * register a `broker` provider, each owning a DISJOINT set of
47169
- * brokers (mqtt-broker owns `mqtt_*`, provider-homeassistant owns
47170
- * `ha_*`). A broker therefore belongs to exactly one addon — like a
47171
- * device belongs to one integration. The admin UI threads this id
47172
- * back as the `{ addonId }` system-collection selector on every
47173
- * id-keyed call (`get` / `getSettings` / `setSettings` / `remove` /
47174
- * `testConnection`), so the call routes to the OWNING provider
47175
- * instead of defaulting to the first-registered one. */
47176
- addonId: string(),
47177
- /** Human-readable name (operator-chosen at add-time). */
47178
- name: string(),
47179
- /** Provider-defined kind tag — `mqtt` / `home-assistant` / future. */
47180
- kind: string(),
47181
- status: BrokerStatusEnum,
47182
- /** Free-form provider-specific info (HA version, MQTT broker
47183
- * flavour, latency, mTLS active, …). */
47184
- info: record(string(), unknown()),
47185
- /** Ms epoch of the last connection probe / status update. */
47186
- lastCheckedAt: number().nullable(),
47187
- /** Last error message, when `status` indicates failure. */
47188
- error: string().nullable()
47189
- });
47190
47263
  var RegistryStatusSchema = object({
47191
47264
  brokerCount: number().int().nonnegative(),
47192
47265
  connectedCount: number().int().nonnegative()
47193
47266
  });
47194
- /**
47195
- * One entry per `broker` provider — which addon provides which broker
47196
- * kind(s). The unified create picker reads this to know, for each
47197
- * (addonId, kind) pair the operator can pick, where to route the
47198
- * follow-up `getSettingsSchema` / `testSettings` / `add` calls (via the
47199
- * `{ addonId }` selector). A provider only advertises a kind here when
47200
- * it implements `getSettingsSchema` for that kind (so the picker never
47201
- * offers a kind whose creation form can't be rendered).
47202
- */
47203
- var BrokerProviderInfoSchema = object({
47204
- /** Addon id of the `broker` provider this entry describes. */
47205
- addonId: string(),
47206
- /** Broker kinds this provider can create, with a display label. */
47207
- kinds: array(object({
47208
- kind: string(),
47209
- label: string(),
47210
- /**
47211
- * Relative hub path to start an interactive account link (OAuth popup).
47212
- * May include `{{brokerId}}`; admin-ui substitutes and appends `?popup=1`.
47213
- */
47214
- interactiveConnectPath: string().min(1).optional(),
47215
- /** Relative hub path to disconnect the linked account (same popup pattern). */
47216
- interactiveDisconnectPath: string().min(1).optional(),
47217
- /**
47218
- * The kind signs in through a server-held interactive session instead of
47219
- * (or before) typed credentials. `basePath` is a hub-relative route set
47220
- * served by the owning addon (`/addon/<id>/...`) speaking the sign-in
47221
- * contract: `POST {basePath}/start` (body: the form's settings) answers
47222
- * `{ sessionId, loginUrl }`; `GET {basePath}/status?sessionId=` answers
47223
- * `{ phase: 'starting' | 'awaiting-login' | 'captured' | 'error' |
47224
- * 'cancelled', loginUrl, error }`; `POST {basePath}/commit`
47225
- * (`{ sessionId, name, brokerId? }`) stores the credentials on a new or
47226
- * existing broker and answers `{ brokerId }`; `POST {basePath}/cancel`
47227
- * (`{ sessionId }`) drops the session. The dialog that edits a broker
47228
- * offers it as the default path; the fields the session fills are
47229
- * marked `filledBySignIn` in the kind's settings schema.
47230
- *
47231
- * `methods` lists the ways the session can sign in, recommended first:
47232
- * `'device-code'` adds `POST {basePath}/code/start` (body: the form's
47233
- * settings) answering `{ sessionId, userCode, verificationUrl,
47234
- * expiresAt }` — the operator types `userCode` at `verificationUrl` on
47235
- * any device, and the same `status` / `commit` / `cancel` routes follow
47236
- * (status then carries `method`, `userCode`, `verificationUrl`,
47237
- * `expiresAt` and the phases `'awaiting-code'` / `'expired'`);
47238
- * `'proxy'` is the `{basePath}/start` flow above. Absent means
47239
- * `['proxy']`.
47240
- */
47241
- signIn: object({
47242
- basePath: string().min(1),
47243
- methods: array(_enum(["device-code", "proxy"])).optional()
47244
- }).optional()
47245
- }))
47246
- });
47247
- var ListInputSchema = object({
47248
- /** Optional kind filter — `list({kind:'home-assistant'})` returns
47249
- * only HA brokers. Omit to list every broker. */
47250
- kind: string().optional() });
47251
47267
  var GetInputSchema = object({ id: string() });
47252
- var AddInputSchema = object({
47253
- kind: string().min(1),
47254
- name: string().min(1),
47255
- /**
47256
- * ADOPT an existing id instead of minting a new one.
47257
- *
47258
- * Written the day this cost an outage. A broker's id is not a detail: HA
47259
- * devices carry it inside their `stableId` (`ha:ha_004:dev:…`), so a broker
47260
- * lost from config and re-added as `ha_001` leaves every one of its devices
47261
- * bound to a broker that no longer exists. Re-entering the password under the
47262
- * ORIGINAL id turns a multi-step device migration back into re-entering a
47263
- * password.
47264
- *
47265
- * A provider MUST refuse an id that is already in use — adopting a live
47266
- * broker's id would silently take it over.
47267
- */
47268
- id: string().min(1).optional(),
47269
- /** Kind-specific settings (e.g. MQTT `{url,username,password}` or HA
47270
- * `{baseUrl,accessToken}`). Validated by the kind-specific provider
47271
- * branch on receipt — invalid shape rejects the add. */
47272
- settings: record(string(), unknown())
47273
- });
47274
- var AddResultSchema = object({ id: string() });
47275
- var RemoveInputSchema = object({ id: string() });
47276
- var TestConnectionResultSchema = discriminatedUnion("ok", [object({
47277
- ok: literal(true),
47278
- latencyMs: number().nonnegative()
47279
- }), object({
47280
- ok: literal(false),
47281
- error: string()
47282
- })]);
47283
47268
  var SettingsRecordSchema$1 = record(string(), unknown());
47284
- var SettingsSchemaInputSchema = object({ kind: string() });
47285
- var TestSettingsInputSchema = object({
47286
- kind: string(),
47287
- settings: SettingsRecordSchema$1
47288
- });
47289
- var TestSettingsResultSchema = discriminatedUnion("ok", [object({
47290
- ok: literal(true),
47291
- latencyMs: number().nonnegative().optional()
47292
- }).strict(), object({
47293
- ok: literal(false),
47294
- error: string()
47295
- })]);
47296
- var SettingsSchemaResultSchema = unknown().nullable();
47297
47269
  var PublishInputSchema = object({
47298
47270
  brokerId: string(),
47299
47271
  /** Kind-specific routing target.
@@ -47327,25 +47299,7 @@ var GetStateInputSchema = object({
47327
47299
  * HA: entity_id (returns the cached entity state). */
47328
47300
  key: string()
47329
47301
  });
47330
- method(ListInputSchema, array(BrokerInfoSchema)), method(GetInputSchema, BrokerInfoSchema.nullable()), method(_void(), array(BrokerProviderInfoSchema), { auth: "admin" }), method(AddInputSchema, AddResultSchema, {
47331
- kind: "mutation",
47332
- auth: "admin"
47333
- }), method(RemoveInputSchema, _void(), {
47334
- kind: "mutation",
47335
- auth: "admin"
47336
- }), method(GetInputSchema, TestConnectionResultSchema, {
47337
- kind: "mutation",
47338
- auth: "admin"
47339
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(object({
47340
- id: string(),
47341
- settings: SettingsRecordSchema$1
47342
- }), _void(), {
47343
- kind: "mutation",
47344
- auth: "admin"
47345
- }), method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(SettingsSchemaInputSchema, SettingsSchemaResultSchema, { auth: "admin" }), method(TestSettingsInputSchema, TestSettingsResultSchema, {
47346
- kind: "mutation",
47347
- auth: "admin"
47348
- }), method(PublishInputSchema, unknown(), {
47302
+ method(GetInputSchema, SettingsRecordSchema$1.nullable(), { auth: "admin" }), method(PublishInputSchema, unknown(), {
47349
47303
  kind: "mutation",
47350
47304
  auth: "admin"
47351
47305
  }), method(SubscribeInputSchema, SubscribeResultSchema, {
@@ -52166,7 +52120,14 @@ var DiscoveryCandidateSchema = object({
52166
52120
  /** `stableId` of the gateway candidate this device was found BEHIND. */
52167
52121
  parentStableId: string().optional(),
52168
52122
  /** `false` = shown for context but not pickable. Default true. */
52169
- selectable: boolean().optional()
52123
+ selectable: boolean().optional(),
52124
+ /**
52125
+ * Keys of the provider's creation form (`getChildCreationSchema`) this candidate
52126
+ * cannot be adopted without — a key for an encrypted board, a pairing code. The
52127
+ * admin asks for exactly these, on the creation form prefilled with
52128
+ * `prefilledConfig`, before it adopts. Absent or empty = adopt as it is.
52129
+ */
52130
+ needsParams: array(string()).optional()
52170
52131
  });
52171
52132
  /**
52172
52133
  * Flat device summary returned by `createDevice` / `adoptDiscoveredDevice`.
@@ -52293,8 +52254,14 @@ var deviceProviderCapability = {
52293
52254
  * provider does not support manual creation. Lets the Add-Device dialog
52294
52255
  * pick the right type instead of assuming Camera.
52295
52256
  */
52296
- getManualCreationType: method(object({}), object({ deviceType: _enum(DeviceType).nullable() })),
52297
- adoptDiscoveredDevice: method(object({ candidate: DiscoveryCandidateSchema }), DeviceSummarySchema, {
52257
+ getManualCreationType: method(object({
52258
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52259
+ integrationId: string().optional() }), object({ deviceType: _enum(DeviceType).nullable() })),
52260
+ adoptDiscoveredDevice: method(object({
52261
+ candidate: DiscoveryCandidateSchema,
52262
+ /** The integration the operator adopts into; a provider with several instances needs it. */
52263
+ integrationId: string().optional()
52264
+ }), DeviceSummarySchema, {
52298
52265
  kind: "mutation",
52299
52266
  auth: "admin"
52300
52267
  }),
@@ -52305,10 +52272,16 @@ var deviceProviderCapability = {
52305
52272
  * devices of that type. The output is a `ConfigUISchema` — the
52306
52273
  * router type-asserts it at the boundary.
52307
52274
  */
52308
- getChildCreationSchema: method(object({ type: _enum(DeviceType) }), CreationSchemaOutputSchema),
52275
+ getChildCreationSchema: method(object({
52276
+ type: _enum(DeviceType),
52277
+ /** The integration asked about; a provider whose integrations differ answers per one. */
52278
+ integrationId: string().optional()
52279
+ }), CreationSchemaOutputSchema),
52309
52280
  createDevice: method(object({
52310
52281
  type: _enum(DeviceType),
52311
- config: record(string(), unknown())
52282
+ config: record(string(), unknown()),
52283
+ /** The integration the operator adds the device to; a provider with several instances needs it. */
52284
+ integrationId: string().optional()
52312
52285
  }), DeviceSummarySchema, {
52313
52286
  kind: "mutation",
52314
52287
  auth: "admin"
@@ -53033,7 +53006,10 @@ method(object({
53033
53006
  auth: "admin"
53034
53007
  }), method(object({
53035
53008
  addonId: string(),
53036
- type: _enum(DeviceType)
53009
+ type: _enum(DeviceType),
53010
+ /** The integration the form is for; a provider whose integrations differ (a hub
53011
+ * integration takes no manual add) answers per integration. Absent = the addon's own. */
53012
+ integrationId: string().optional()
53037
53013
  }), unknown().nullable()), method(object({
53038
53014
  addonId: string(),
53039
53015
  type: _enum(DeviceType),
@@ -53117,7 +53093,11 @@ method(object({
53117
53093
  kind: "mutation",
53118
53094
  auth: "admin",
53119
53095
  timeoutMs: 12e4
53120
- }), method(object({ addonId: string() }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53096
+ }), method(object({
53097
+ addonId: string(),
53098
+ /** The integration the Add-Device dialog is open on; absent = the addon's own. */
53099
+ integrationId: string().optional()
53100
+ }), object({ deviceType: _enum(DeviceType).nullable() }), { auth: "admin" }), method(object({ addonId: string() }), unknown(), { auth: "admin" }), method(object({
53121
53101
  deviceId: number(),
53122
53102
  key: string(),
53123
53103
  value: unknown()
@@ -56397,7 +56377,7 @@ var TestConnectionStatusEnum = _enum([
56397
56377
  "inconclusive",
56398
56378
  "unsupported"
56399
56379
  ]);
56400
- var TestConnectionResultSchema$1 = object({
56380
+ var TestConnectionResultSchema = object({
56401
56381
  /** True ONLY for `validated`. Never true for a test that did not run. */
56402
56382
  success: boolean(),
56403
56383
  error: string().optional(),
@@ -56442,7 +56422,7 @@ method(_void(), array(IntegrationWithStateSchema)), method(object({ id: string()
56442
56422
  }), method(_void(), array(AvailableIntegrationTypeSchema), { auth: "admin" }), method(object({
56443
56423
  addonId: string(),
56444
56424
  settings: record(string(), unknown())
56445
- }), TestConnectionResultSchema$1, {
56425
+ }), TestConnectionResultSchema, {
56446
56426
  kind: "mutation",
56447
56427
  auth: "admin"
56448
56428
  });
@@ -56469,6 +56449,14 @@ var ConfigSchemaPassthrough$3 = custom();
56469
56449
  var IntegrationInstanceIdSchema = string().min(1);
56470
56450
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
56471
56451
  /**
56452
+ * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
56453
+ * instance is an integration that brings devices (the registry owns its on/off switch);
56454
+ * `services`: a connection configured from the addon's own function page, never listed on
56455
+ * Integrations.
56456
+ * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
56457
+ */
56458
+ var IntegrationInstanceRoleSchema = _enum(["devices", "services"]);
56459
+ /**
56472
56460
  * One kind of instance a provider can create (an adapter, an account type). The sign-in and
56473
56461
  * connect fields follow the `broker` contract (`broker.cap.ts`): `signIn.basePath` is a
56474
56462
  * hub-relative route set speaking the sign-in contract, `connectPath` / `disconnectPath` open an
@@ -56479,6 +56467,22 @@ var IntegrationInstanceKindSchema = object({
56479
56467
  /** Stable id of the kind, sent back as `createInstance.kind`. */
56480
56468
  id: string().min(1),
56481
56469
  label: string().min(1),
56470
+ /**
56471
+ * The function capability this kind is configured for (`broker`, `smtp-provider`,
56472
+ * `device-provider`, ...). A page section is the kinds whose `functionCap` it names (D1013); a
56473
+ * provider with more than one section must name it on every kind.
56474
+ */
56475
+ functionCap: string().min(1),
56476
+ /**
56477
+ * For `functionCap: 'broker'`: the registry kind of the broker an instance of this kind is
56478
+ * (`matter`, `home-assistant`, ...). A caller that needs a broker of one kind (a link field)
56479
+ * finds the instances whose kind names it; absent takes the kind `id`.
56480
+ */
56481
+ brokerKind: string().min(1).optional(),
56482
+ /** What instances of this kind are for the Integrations page; absent takes the provider's `role`. */
56483
+ role: IntegrationInstanceRoleSchema.optional(),
56484
+ /** `testInstance` really probes the remote for this kind; absent takes the provider's `canTest`. */
56485
+ canTest: boolean().optional(),
56482
56486
  /** The kind signs in through a server-held interactive session. */
56483
56487
  signIn: object({
56484
56488
  basePath: string().min(1),
@@ -56491,11 +56495,7 @@ var IntegrationInstanceKindSchema = object({
56491
56495
  });
56492
56496
  var IntegrationInstanceDescriptionSchema = object({
56493
56497
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
56494
- role: _enum([
56495
- "devices",
56496
- "services",
56497
- "both"
56498
- ]),
56498
+ role: IntegrationInstanceRoleSchema,
56499
56499
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
56500
56500
  discovery: object({
56501
56501
  mode: _enum([
@@ -56570,7 +56570,11 @@ var integrationInstancesCapability = {
56570
56570
  methods: {
56571
56571
  describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
56572
56572
  /** The form; `id: null` is the create form. */
56573
- instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56573
+ instanceFormSchema: method(object({
56574
+ id: IntegrationInstanceIdSchema.nullable(),
56575
+ /** The kind of the create form (`id: null`) of a provider with several. */
56576
+ kind: string().min(1).optional()
56577
+ }), ConfigSchemaPassthrough$3, { auth: "admin" }),
56574
56578
  listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
56575
56579
  getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
56576
56580
  /**
@@ -56580,7 +56584,9 @@ var integrationInstancesCapability = {
56580
56584
  createInstance: method(object({
56581
56585
  id: IntegrationInstanceIdSchema.optional(),
56582
56586
  name: string().min(1),
56583
- kind: string().min(1).optional()
56587
+ kind: string().min(1).optional(),
56588
+ /** Form values written with the record (a link picked in the create dialog). */
56589
+ values: record(string(), unknown()).optional()
56584
56590
  }), object({ id: string() }), {
56585
56591
  kind: "mutation",
56586
56592
  auth: "admin"
@@ -56607,8 +56613,10 @@ var integrationInstancesCapability = {
56607
56613
  }),
56608
56614
  testInstance: optionalMethod(object({
56609
56615
  id: IntegrationInstanceIdSchema.nullable(),
56610
- values: record(string(), unknown())
56611
- }), TestConnectionResultSchema$1, {
56616
+ values: record(string(), unknown()),
56617
+ /** The kind to test when `id` is null and the provider has several. */
56618
+ kind: string().min(1).optional()
56619
+ }), TestConnectionResultSchema, {
56612
56620
  kind: "mutation",
56613
56621
  auth: "admin"
56614
56622
  })
@@ -59365,6 +59373,380 @@ var SystemMetricsSchema = object({
59365
59373
  gpuMemoryPercent: number().optional()
59366
59374
  });
59367
59375
  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);
59376
+ /**
59377
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
59378
+ * config documents, mirrors. The third storage API next to `ctx.settings`
59379
+ * (operator intent, D870) and device-history (numbers over time, D850).
59380
+ *
59381
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
59382
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
59383
+ * that with the addon id closed over). It is deliberately NOT in any input
59384
+ * schema, so a session can never supply it, and a call with no stamp is refused
59385
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
59386
+ * addons go through the owner's capability.
59387
+ *
59388
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
59389
+ * never `[]`. Secret fields are never on the wire: a read shows the
59390
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
59391
+ * resolves itself, and a write may carry only a keychain marker bound to the
59392
+ * row's own ref.
59393
+ *
59394
+ * Internal: addons reach it through `ctx.records`, never directly.
59395
+ */
59396
+ var RecordIdSchema = string().min(1).max(256);
59397
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
59398
+ var RecordBodySchema = record(string(), unknown());
59399
+ var RecordInputSchema = object({
59400
+ id: RecordIdSchema,
59401
+ /** The device this row belongs to (D865 removal, per-device reads). */
59402
+ deviceId: number().int().optional(),
59403
+ /** The domain clock, ms: observed / created / opened. */
59404
+ at: number().int().optional(),
59405
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
59406
+ expiresAt: number().int().optional(),
59407
+ data: RecordBodySchema
59408
+ });
59409
+ var RecordViewSchema = object({
59410
+ id: string(),
59411
+ deviceId: number().int().nullable(),
59412
+ at: number().nullable(),
59413
+ expiresAt: number().nullable(),
59414
+ rev: number().int(),
59415
+ updatedAt: number(),
59416
+ data: RecordBodySchema
59417
+ });
59418
+ /** Declared index fields only. Anything else does not compile, by design. */
59419
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
59420
+ string(),
59421
+ number(),
59422
+ boolean(),
59423
+ object({ in: array(union([
59424
+ string(),
59425
+ number(),
59426
+ boolean()
59427
+ ])).min(1).max(RECORD_BATCH_MAX) }),
59428
+ object({
59429
+ gt: union([string(), number()]).optional(),
59430
+ gte: union([string(), number()]).optional(),
59431
+ lt: union([string(), number()]).optional(),
59432
+ lte: union([string(), number()]).optional()
59433
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
59434
+ ]));
59435
+ var KindShape = { kind: RecordKindNameSchema };
59436
+ var TimeWindowShape = {
59437
+ deviceId: number().int().optional(),
59438
+ atFrom: number().optional(),
59439
+ atTo: number().optional()
59440
+ };
59441
+ var RecordQueryInputSchema = object({
59442
+ ...KindShape,
59443
+ ...TimeWindowShape,
59444
+ where: RecordWhereSchema.optional(),
59445
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
59446
+ order: _enum(["at", "id"]).optional(),
59447
+ desc: boolean().optional(),
59448
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
59449
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
59450
+ cursor: string().min(1).optional()
59451
+ });
59452
+ var RecordQueryResultSchema = object({
59453
+ records: array(RecordViewSchema),
59454
+ nextCursor: string().nullable()
59455
+ });
59456
+ var RecordKindStateSchema = _enum([
59457
+ "created",
59458
+ "unchanged",
59459
+ "updated"
59460
+ ]);
59461
+ var DeclareKindResultSchema = object({
59462
+ kindId: number().int(),
59463
+ state: RecordKindStateSchema,
59464
+ createdIndexes: array(string())
59465
+ });
59466
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
59467
+ var SecretRefsList = array(string());
59468
+ /**
59469
+ * One op of a `transact`: the single-row writes, each on a kind of the caller.
59470
+ * All ops of one call share ONE database file and ONE `transactFamily`.
59471
+ */
59472
+ var RecordTransactOpSchema = discriminatedUnion("op", [
59473
+ object({
59474
+ op: literal("put"),
59475
+ kind: RecordKindNameSchema,
59476
+ record: RecordInputSchema,
59477
+ ifRev: number().int().min(0).optional()
59478
+ }),
59479
+ object({
59480
+ op: literal("patch"),
59481
+ kind: RecordKindNameSchema,
59482
+ id: RecordIdSchema,
59483
+ data: RecordBodySchema,
59484
+ at: number().int().nullable().optional(),
59485
+ expiresAt: number().int().nullable().optional(),
59486
+ ifRev: number().int().min(1).optional()
59487
+ }),
59488
+ object({
59489
+ op: literal("delete"),
59490
+ kind: RecordKindNameSchema,
59491
+ id: RecordIdSchema
59492
+ })
59493
+ ]);
59494
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
59495
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
59496
+ kind: "mutation",
59497
+ auth: "admin"
59498
+ }), method(object({
59499
+ ...KindShape,
59500
+ id: RecordIdSchema
59501
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
59502
+ ...KindShape,
59503
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59504
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
59505
+ ...KindShape,
59506
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59507
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
59508
+ ...KindShape,
59509
+ record: RecordInputSchema,
59510
+ /** Compare-and-set. `0` means "the row must not exist". */
59511
+ ifRev: number().int().min(0).optional()
59512
+ }), object({
59513
+ rev: number().int(),
59514
+ releasedRefs: SecretRefsList
59515
+ }), {
59516
+ kind: "mutation",
59517
+ auth: "admin"
59518
+ }), method(object({
59519
+ ...KindShape,
59520
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
59521
+ }), object({
59522
+ count: number().int(),
59523
+ releasedRefs: SecretRefsList
59524
+ }), {
59525
+ kind: "mutation",
59526
+ auth: "admin"
59527
+ }), method(object({
59528
+ ...KindShape,
59529
+ id: RecordIdSchema,
59530
+ data: RecordBodySchema,
59531
+ at: number().int().nullable().optional(),
59532
+ expiresAt: number().int().nullable().optional(),
59533
+ ifRev: number().int().min(1).optional()
59534
+ }), object({
59535
+ rev: number().int(),
59536
+ releasedRefs: SecretRefsList
59537
+ }), {
59538
+ kind: "mutation",
59539
+ auth: "admin"
59540
+ }), method(object({
59541
+ ...KindShape,
59542
+ id: RecordIdSchema
59543
+ }), object({
59544
+ deleted: boolean(),
59545
+ secretRefs: SecretRefsList
59546
+ }), {
59547
+ kind: "mutation",
59548
+ auth: "admin"
59549
+ }), method(object({
59550
+ ...KindShape,
59551
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
59552
+ }), object({
59553
+ deleted: number().int(),
59554
+ secretRefs: SecretRefsList
59555
+ }), {
59556
+ kind: "mutation",
59557
+ auth: "admin"
59558
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
59559
+ ...KindShape,
59560
+ ...TimeWindowShape,
59561
+ where: RecordWhereSchema.optional()
59562
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
59563
+ ...KindShape,
59564
+ deviceId: number().int().optional(),
59565
+ from: number(),
59566
+ to: number(),
59567
+ bucketMs: number().int().positive()
59568
+ }), object({ buckets: array(object({
59569
+ bucketStart: number(),
59570
+ count: number().int()
59571
+ })) }), { auth: "admin" }), method(object({
59572
+ ...KindShape,
59573
+ op: _enum([
59574
+ "sum",
59575
+ "min",
59576
+ "max",
59577
+ "count"
59578
+ ]),
59579
+ field: RecordFieldPathSchema.optional(),
59580
+ groupBy: RecordFieldPathSchema.optional(),
59581
+ where: RecordWhereSchema.optional()
59582
+ }), object({ rows: array(object({
59583
+ group: union([
59584
+ string(),
59585
+ number(),
59586
+ _null()
59587
+ ]),
59588
+ value: number().nullable()
59589
+ })) }), { auth: "admin" }), method(object({
59590
+ ...KindShape,
59591
+ deviceId: number().int().optional(),
59592
+ atBefore: number().optional(),
59593
+ where: RecordWhereSchema.optional()
59594
+ }), object({
59595
+ deleted: number().int(),
59596
+ secretRefs: SecretRefsList
59597
+ }), {
59598
+ kind: "mutation",
59599
+ auth: "admin"
59600
+ }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
59601
+ results: array(object({
59602
+ rev: number().int().nullable(),
59603
+ deleted: boolean()
59604
+ })),
59605
+ releasedRefs: SecretRefsList,
59606
+ secretRefs: SecretRefsList
59607
+ }), {
59608
+ kind: "mutation",
59609
+ auth: "admin"
59610
+ }), method(object({
59611
+ deviceId: number().int(),
59612
+ kinds: array(RecordKindNameSchema).optional()
59613
+ }), object({
59614
+ deleted: record(string(), number().int()),
59615
+ secretRefs: SecretRefsList
59616
+ }), {
59617
+ kind: "mutation",
59618
+ auth: "admin"
59619
+ }), method(object(KindShape), object({ id: number().int() }), {
59620
+ kind: "mutation",
59621
+ auth: "admin"
59622
+ });
59623
+ /**
59624
+ * The wire shapes of the migration API, version 1 (planning#447).
59625
+ *
59626
+ * A migration is code that outlives the server it was written against: an addon at
59627
+ * version 1.4 that is brought to 1.9 in one jump still runs its 1.4 catalogue, against
59628
+ * the 1.9 kernel. The only thing that code may call is {@link MigrationApiV1}; this file
59629
+ * is the contract of every method of it, one Zod pair per method.
59630
+ *
59631
+ * APPEND-ONLY. A released method is never removed and never changes meaning: an input
59632
+ * field is never removed or made required, an enum never narrows, an output field is
59633
+ * never removed. A change that cannot be expressed that way is `migration-api.v2`, next
59634
+ * to this file. `scripts/check-migration-api-append-only.ts` holds the line against
59635
+ * `scripts/migration-api-contract.json`, and every `behaviours` id below must have an
59636
+ * `it('<id>'` in `migration-api.contract.spec.ts`.
59637
+ */
59638
+ var Rows = record(string(), unknown());
59639
+ var IntegrationId = object({ integrationId: string().min(1) });
59640
+ var RecordId = object({ id: string().min(1) });
59641
+ var RecordRowSchema = object({
59642
+ id: string(),
59643
+ deviceId: number().int().nullable(),
59644
+ at: number().nullable(),
59645
+ expiresAt: number().nullable(),
59646
+ rev: number().int(),
59647
+ updatedAt: number(),
59648
+ data: Rows
59649
+ });
59650
+ var RecordPutShape = {
59651
+ id: string().min(1),
59652
+ deviceId: number().int().optional(),
59653
+ at: number().int().optional(),
59654
+ expiresAt: number().int().optional(),
59655
+ data: Rows
59656
+ };
59657
+ var MigrationIntegrationSchema = object({
59658
+ id: string(),
59659
+ addonId: string(),
59660
+ name: string(),
59661
+ info: Rows,
59662
+ originStableId: string().optional()
59663
+ });
59664
+ var MigrationDeviceSchema = object({
59665
+ id: number().int(),
59666
+ integrationId: string().nullable().optional(),
59667
+ /** The owning device; null or absent for a root. */
59668
+ parentDeviceId: number().int().nullable().optional(),
59669
+ type: string().optional(),
59670
+ name: string().optional(),
59671
+ stableId: string().optional()
59672
+ });
59673
+ /** What the engine says about the migration API it serves: lets an addon notice an older server. */
59674
+ var MigrationApiInfoSchema = object({
59675
+ version: number().int(),
59676
+ methods: array(string())
59677
+ });
59678
+ object({
59679
+ message: string(),
59680
+ meta: Rows.optional(),
59681
+ /** Grouping tags of the line; a line about a device carries `{ deviceId }`. */
59682
+ tags: object({ deviceId: number().int().optional() }).optional()
59683
+ });
59684
+ object({
59685
+ owner: string().min(1),
59686
+ metas: array(MigrationMetaSchema)
59687
+ }), object({
59688
+ bootId: string(),
59689
+ snapshot: _enum([
59690
+ "none",
59691
+ "written",
59692
+ "refused"
59693
+ ]),
59694
+ steps: array(MigrationOwnerStepSchema),
59695
+ /** The migration API the engine serves; absent from a server that predates it. */
59696
+ migrationApi: MigrationApiInfoSchema.optional()
59697
+ }), object({ id: string().min(1) }), object({
59698
+ proceed: boolean(),
59699
+ state: union([literal("pending"), MigrationStatusSchema]),
59700
+ reason: string().nullable()
59701
+ }), object({
59702
+ id: string().min(1),
59703
+ result: MigrationOwnerResultSchema
59704
+ }), object({
59705
+ status: MigrationStatusSchema,
59706
+ error: string().nullable(),
59707
+ rowsChanged: number().int().nonnegative()
59708
+ }), object({
59709
+ rows: number().int().nonnegative(),
59710
+ secrets: number().int().nonnegative()
59711
+ }), IntegrationId.extend({ patch: Rows }), object({ written: boolean() }), IntegrationId.extend({ keys: array(string().min(1)) }), object({
59712
+ present: boolean(),
59713
+ removed: Rows
59714
+ }), RecordRowSchema.nullable(), RecordRowSchema.nullable(), object({
59715
+ ...RecordPutShape,
59716
+ ifRev: number().int().optional()
59717
+ }), object({ rev: number().int() }), object({ records: array(object(RecordPutShape)) }), object({ count: number().int().nonnegative() }), RecordId.extend({
59718
+ partial: Rows,
59719
+ ifRev: number().int().optional()
59720
+ }), object({ rev: number().int() }), object({ deleted: boolean() }), object({
59721
+ deviceId: number().int().optional(),
59722
+ atFrom: number().optional(),
59723
+ atTo: number().optional(),
59724
+ where: RecordWhereSchema.optional(),
59725
+ limit: number().int().min(1).optional(),
59726
+ cursor: string().min(1).optional(),
59727
+ resolveSecrets: boolean().optional()
59728
+ }), object({
59729
+ records: array(RecordRowSchema),
59730
+ nextCursor: string().nullable()
59731
+ }), object({
59732
+ deviceId: number().int().optional(),
59733
+ atBefore: number().optional(),
59734
+ where: RecordWhereSchema.optional()
59735
+ }), 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({
59736
+ ref: string().min(1),
59737
+ value: string()
59738
+ }), object({}), object({ refs: array(string()) }), object({ deleted: number().int().nonnegative() }), object({}), object({ integrations: array(MigrationIntegrationSchema) }), object({ id: string().min(1) }), MigrationIntegrationSchema.nullable(), object({
59739
+ addonId: string().min(1),
59740
+ integrationId: string().min(1).optional()
59741
+ }), object({ devices: array(MigrationDeviceSchema) }), object({ deviceId: number().int() }), object({
59742
+ id: number().int(),
59743
+ integrationId: string().nullable(),
59744
+ /** Whether the device carries any stored config; its content is not offered. */
59745
+ hasConfig: boolean()
59746
+ }).nullable(), object({
59747
+ deviceId: number().int(),
59748
+ integrationId: string().min(1)
59749
+ }), object({}), object({}), object({ nodeId: string() }), object({}), object({});
59368
59750
  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({
59369
59751
  id: string().min(1),
59370
59752
  error: string().min(1)
@@ -59394,7 +59776,9 @@ method(object({}), object({ entries: array(MigrationLedgerEntrySchema) }), { aut
59394
59776
  "written",
59395
59777
  "refused"
59396
59778
  ]),
59397
- steps: array(MigrationOwnerStepSchema)
59779
+ steps: array(MigrationOwnerStepSchema),
59780
+ /** The migration API this engine serves (additive: a server that predates it omits it). */
59781
+ migrationApi: MigrationApiInfoSchema.optional()
59398
59782
  }), {
59399
59783
  kind: "mutation",
59400
59784
  auth: "admin"
@@ -62061,7 +62445,10 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
62061
62445
  }), method(RelocateMediaInputSchema, object({ jobId: string() }), {
62062
62446
  kind: "mutation",
62063
62447
  auth: "admin"
62064
- }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62448
+ }), method(object({}), UnstampedEventMediaCountSchema, { auth: "admin" }), method(MediaLocationCensusInputSchema, MediaLocationCensusSchema, {
62449
+ kind: "query",
62450
+ auth: "admin"
62451
+ }), method(RelocatableMediaCountInputSchema, RelocatableMediaCountSchema, {
62065
62452
  kind: "query",
62066
62453
  auth: "admin"
62067
62454
  }), method(object({}), array(RelocateJobSchema).readonly(), {
@@ -64716,7 +65103,7 @@ var BrokerStatusSchema$1 = _enum([
64716
65103
  "unreachable",
64717
65104
  "tls-error"
64718
65105
  ]);
64719
- var BrokerInfoSchema$1 = object({
65106
+ var BrokerInfoSchema = object({
64720
65107
  id: string(),
64721
65108
  name: string(),
64722
65109
  url: string(),
@@ -64779,7 +65166,7 @@ var StatusSchema = object({
64779
65166
  brokerCount: number(),
64780
65167
  embeddedRunning: boolean()
64781
65168
  });
64782
- method(_void(), array(BrokerInfoSchema$1)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
65169
+ method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema, { auth: "admin" }), method(AddBrokerInputSchema, AddBrokerResultSchema, {
64783
65170
  kind: "mutation",
64784
65171
  auth: "admin"
64785
65172
  }), method(IdInputSchema, _void(), {
@@ -72119,253 +72506,6 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, DeviceType.Gateway, met
72119
72506
  auth: "admin"
72120
72507
  });
72121
72508
  /**
72122
- * records - an addon's own facts and documents (D881): ledgers, audit rows,
72123
- * config documents, mirrors. The third storage API next to `ctx.settings`
72124
- * (operator intent, D870) and device-history (numbers over time, D850).
72125
- *
72126
- * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
72127
- * crossed a process and stated by a hub in-process caller (`ctx.records` does
72128
- * that with the addon id closed over). It is deliberately NOT in any input
72129
- * schema, so a session can never supply it, and a call with no stamp is refused
72130
- * `records/no-caller`. A kind is readable and writable only by its owner; other
72131
- * addons go through the owner's capability.
72132
- *
72133
- * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
72134
- * never `[]`. Secret fields are never on the wire: a read shows the
72135
- * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
72136
- * resolves itself, and a write may carry only a keychain marker bound to the
72137
- * row's own ref.
72138
- *
72139
- * Internal: addons reach it through `ctx.records`, never directly.
72140
- */
72141
- var RecordIdSchema = string().min(1).max(256);
72142
- /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
72143
- var RecordBodySchema = record(string(), unknown());
72144
- var RecordInputSchema = object({
72145
- id: RecordIdSchema,
72146
- /** The device this row belongs to (D865 removal, per-device reads). */
72147
- deviceId: number().int().optional(),
72148
- /** The domain clock, ms: observed / created / opened. */
72149
- at: number().int().optional(),
72150
- /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
72151
- expiresAt: number().int().optional(),
72152
- data: RecordBodySchema
72153
- });
72154
- var RecordViewSchema = object({
72155
- id: string(),
72156
- deviceId: number().int().nullable(),
72157
- at: number().nullable(),
72158
- expiresAt: number().nullable(),
72159
- rev: number().int(),
72160
- updatedAt: number(),
72161
- data: RecordBodySchema
72162
- });
72163
- /** Declared index fields only. Anything else does not compile, by design. */
72164
- var RecordWhereSchema = record(RecordFieldPathSchema, union([
72165
- string(),
72166
- number(),
72167
- boolean(),
72168
- object({ in: array(union([
72169
- string(),
72170
- number(),
72171
- boolean()
72172
- ])).min(1).max(RECORD_BATCH_MAX) }),
72173
- object({
72174
- gt: union([string(), number()]).optional(),
72175
- gte: union([string(), number()]).optional(),
72176
- lt: union([string(), number()]).optional(),
72177
- lte: union([string(), number()]).optional()
72178
- }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
72179
- ]));
72180
- var KindShape = { kind: RecordKindNameSchema };
72181
- var TimeWindowShape = {
72182
- deviceId: number().int().optional(),
72183
- atFrom: number().optional(),
72184
- atTo: number().optional()
72185
- };
72186
- var RecordQueryInputSchema = object({
72187
- ...KindShape,
72188
- ...TimeWindowShape,
72189
- where: RecordWhereSchema.optional(),
72190
- /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
72191
- order: _enum(["at", "id"]).optional(),
72192
- desc: boolean().optional(),
72193
- limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
72194
- /** Opaque keyset cursor from a previous answer. There is no offset. */
72195
- cursor: string().min(1).optional()
72196
- });
72197
- var RecordQueryResultSchema = object({
72198
- records: array(RecordViewSchema),
72199
- nextCursor: string().nullable()
72200
- });
72201
- var RecordKindStateSchema = _enum([
72202
- "created",
72203
- "unchanged",
72204
- "updated"
72205
- ]);
72206
- var DeclareKindResultSchema = object({
72207
- kindId: number().int(),
72208
- state: RecordKindStateSchema,
72209
- createdIndexes: array(string())
72210
- });
72211
- /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
72212
- var SecretRefsList = array(string());
72213
- /**
72214
- * One op of a `transact`: the single-row writes, each on a kind of the caller.
72215
- * All ops of one call share ONE database file and ONE `transactFamily`.
72216
- */
72217
- var RecordTransactOpSchema = discriminatedUnion("op", [
72218
- object({
72219
- op: literal("put"),
72220
- kind: RecordKindNameSchema,
72221
- record: RecordInputSchema,
72222
- ifRev: number().int().min(0).optional()
72223
- }),
72224
- object({
72225
- op: literal("patch"),
72226
- kind: RecordKindNameSchema,
72227
- id: RecordIdSchema,
72228
- data: RecordBodySchema,
72229
- at: number().int().nullable().optional(),
72230
- expiresAt: number().int().nullable().optional(),
72231
- ifRev: number().int().min(1).optional()
72232
- }),
72233
- object({
72234
- op: literal("delete"),
72235
- kind: RecordKindNameSchema,
72236
- id: RecordIdSchema
72237
- })
72238
- ]);
72239
- var RecordSecretRefsSchema = record(string(), record(string(), string()));
72240
- method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
72241
- kind: "mutation",
72242
- auth: "admin"
72243
- }), method(object({
72244
- ...KindShape,
72245
- id: RecordIdSchema
72246
- }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
72247
- ...KindShape,
72248
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72249
- }), array(RecordViewSchema), { auth: "admin" }), method(object({
72250
- ...KindShape,
72251
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72252
- }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
72253
- ...KindShape,
72254
- record: RecordInputSchema,
72255
- /** Compare-and-set. `0` means "the row must not exist". */
72256
- ifRev: number().int().min(0).optional()
72257
- }), object({
72258
- rev: number().int(),
72259
- releasedRefs: SecretRefsList
72260
- }), {
72261
- kind: "mutation",
72262
- auth: "admin"
72263
- }), method(object({
72264
- ...KindShape,
72265
- records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
72266
- }), object({
72267
- count: number().int(),
72268
- releasedRefs: SecretRefsList
72269
- }), {
72270
- kind: "mutation",
72271
- auth: "admin"
72272
- }), method(object({
72273
- ...KindShape,
72274
- id: RecordIdSchema,
72275
- data: RecordBodySchema,
72276
- at: number().int().nullable().optional(),
72277
- expiresAt: number().int().nullable().optional(),
72278
- ifRev: number().int().min(1).optional()
72279
- }), object({
72280
- rev: number().int(),
72281
- releasedRefs: SecretRefsList
72282
- }), {
72283
- kind: "mutation",
72284
- auth: "admin"
72285
- }), method(object({
72286
- ...KindShape,
72287
- id: RecordIdSchema
72288
- }), object({
72289
- deleted: boolean(),
72290
- secretRefs: SecretRefsList
72291
- }), {
72292
- kind: "mutation",
72293
- auth: "admin"
72294
- }), method(object({
72295
- ...KindShape,
72296
- ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
72297
- }), object({
72298
- deleted: number().int(),
72299
- secretRefs: SecretRefsList
72300
- }), {
72301
- kind: "mutation",
72302
- auth: "admin"
72303
- }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
72304
- ...KindShape,
72305
- ...TimeWindowShape,
72306
- where: RecordWhereSchema.optional()
72307
- }), object({ count: number().int() }), { auth: "admin" }), method(object({
72308
- ...KindShape,
72309
- deviceId: number().int().optional(),
72310
- from: number(),
72311
- to: number(),
72312
- bucketMs: number().int().positive()
72313
- }), object({ buckets: array(object({
72314
- bucketStart: number(),
72315
- count: number().int()
72316
- })) }), { auth: "admin" }), method(object({
72317
- ...KindShape,
72318
- op: _enum([
72319
- "sum",
72320
- "min",
72321
- "max",
72322
- "count"
72323
- ]),
72324
- field: RecordFieldPathSchema.optional(),
72325
- groupBy: RecordFieldPathSchema.optional(),
72326
- where: RecordWhereSchema.optional()
72327
- }), object({ rows: array(object({
72328
- group: union([
72329
- string(),
72330
- number(),
72331
- _null()
72332
- ]),
72333
- value: number().nullable()
72334
- })) }), { auth: "admin" }), method(object({
72335
- ...KindShape,
72336
- deviceId: number().int().optional(),
72337
- atBefore: number().optional(),
72338
- where: RecordWhereSchema.optional()
72339
- }), object({
72340
- deleted: number().int(),
72341
- secretRefs: SecretRefsList
72342
- }), {
72343
- kind: "mutation",
72344
- auth: "admin"
72345
- }), method(object({ ops: array(RecordTransactOpSchema).min(1).max(RECORD_BATCH_MAX) }), object({
72346
- results: array(object({
72347
- rev: number().int().nullable(),
72348
- deleted: boolean()
72349
- })),
72350
- releasedRefs: SecretRefsList,
72351
- secretRefs: SecretRefsList
72352
- }), {
72353
- kind: "mutation",
72354
- auth: "admin"
72355
- }), method(object({
72356
- deviceId: number().int(),
72357
- kinds: array(RecordKindNameSchema).optional()
72358
- }), object({
72359
- deleted: record(string(), number().int()),
72360
- secretRefs: SecretRefsList
72361
- }), {
72362
- kind: "mutation",
72363
- auth: "admin"
72364
- }), method(object(KindShape), object({ id: number().int() }), {
72365
- kind: "mutation",
72366
- auth: "admin"
72367
- });
72368
- /**
72369
72509
  * record-entries - the ONE admin surface for every list of user-created entries
72370
72510
  * (D881): notification targets, brokers, LLM profiles, anything an addon
72371
72511
  * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
@@ -83135,7 +83275,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83135
83275
  * `deviceClasses` map (first registered type). `null` when manual creation is
83136
83276
  * unsupported. Lets the Add-Device dialog pick the right type per provider.
83137
83277
  */
83138
- async getManualCreationType() {
83278
+ async getManualCreationType(_input) {
83139
83279
  if (!await this.supportsManualCreation()) return { deviceType: null };
83140
83280
  return { deviceType: Object.values(DeviceType).find((t) => this.deviceClasses[t] !== void 0) ?? null };
83141
83281
  }
@@ -83146,7 +83286,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83146
83286
  return true;
83147
83287
  }
83148
83288
  async getChildCreationSchema(input) {
83149
- return this.onGetCreationSchema(input.type);
83289
+ return this.onGetCreationSchema(input.type, { integrationId: input.integrationId });
83150
83290
  }
83151
83291
  /**
83152
83292
  * Default kernel-orchestrated `createDevice` implementation. The
@@ -83158,7 +83298,7 @@ var BaseDeviceProvider = class extends BaseAddon {
83158
83298
  * `deviceClasses` instead.
83159
83299
  */
83160
83300
  async createDevice(input) {
83161
- const spec = await this.onCreateDevice(input.type, input.config);
83301
+ const spec = await this.onCreateDevice(input.type, input.config, { ...input.integrationId !== void 0 ? { integrationId: input.integrationId } : {} });
83162
83302
  const Class = this.deviceClasses[spec.meta.type];
83163
83303
  if (!Class) throw new Error(`${this.providerName} provider: no device class registered for type "${spec.meta.type}" — add it to the deviceClasses map`);
83164
83304
  const stableId = this.generateStableId(spec.meta.type, spec.config);
@@ -84571,20 +84711,6 @@ Object.freeze({
84571
84711
  access: "create",
84572
84712
  role: "viewer"
84573
84713
  },
84574
- "broker.add": {
84575
- capName: "broker",
84576
- capScope: "system",
84577
- addonId: null,
84578
- access: "create",
84579
- role: "admin"
84580
- },
84581
- "broker.get": {
84582
- capName: "broker",
84583
- capScope: "system",
84584
- addonId: null,
84585
- access: "view",
84586
- role: "admin"
84587
- },
84588
84714
  "broker.getBrokerConfig": {
84589
84715
  capName: "broker",
84590
84716
  capScope: "system",
@@ -84592,20 +84718,6 @@ Object.freeze({
84592
84718
  access: "view",
84593
84719
  role: "admin"
84594
84720
  },
84595
- "broker.getSettings": {
84596
- capName: "broker",
84597
- capScope: "system",
84598
- addonId: null,
84599
- access: "view",
84600
- role: "admin"
84601
- },
84602
- "broker.getSettingsSchema": {
84603
- capName: "broker",
84604
- capScope: "system",
84605
- addonId: null,
84606
- access: "view",
84607
- role: "admin"
84608
- },
84609
84721
  "broker.getState": {
84610
84722
  capName: "broker",
84611
84723
  capScope: "system",
@@ -84620,20 +84732,6 @@ Object.freeze({
84620
84732
  access: "view",
84621
84733
  role: "admin"
84622
84734
  },
84623
- "broker.list": {
84624
- capName: "broker",
84625
- capScope: "system",
84626
- addonId: null,
84627
- access: "view",
84628
- role: "admin"
84629
- },
84630
- "broker.listProviders": {
84631
- capName: "broker",
84632
- capScope: "system",
84633
- addonId: null,
84634
- access: "view",
84635
- role: "admin"
84636
- },
84637
84735
  "broker.publish": {
84638
84736
  capName: "broker",
84639
84737
  capScope: "system",
@@ -84641,20 +84739,6 @@ Object.freeze({
84641
84739
  access: "create",
84642
84740
  role: "admin"
84643
84741
  },
84644
- "broker.remove": {
84645
- capName: "broker",
84646
- capScope: "system",
84647
- addonId: null,
84648
- access: "delete",
84649
- role: "admin"
84650
- },
84651
- "broker.setSettings": {
84652
- capName: "broker",
84653
- capScope: "system",
84654
- addonId: null,
84655
- access: "create",
84656
- role: "admin"
84657
- },
84658
84742
  "broker.subscribe": {
84659
84743
  capName: "broker",
84660
84744
  capScope: "system",
@@ -84662,20 +84746,6 @@ Object.freeze({
84662
84746
  access: "create",
84663
84747
  role: "admin"
84664
84748
  },
84665
- "broker.testConnection": {
84666
- capName: "broker",
84667
- capScope: "system",
84668
- addonId: null,
84669
- access: "create",
84670
- role: "admin"
84671
- },
84672
- "broker.testSettings": {
84673
- capName: "broker",
84674
- capScope: "system",
84675
- addonId: null,
84676
- access: "create",
84677
- role: "admin"
84678
- },
84679
84749
  "broker.unsubscribe": {
84680
84750
  capName: "broker",
84681
84751
  capScope: "system",
@@ -89639,6 +89709,13 @@ Object.freeze({
89639
89709
  access: "view",
89640
89710
  role: "viewer"
89641
89711
  },
89712
+ "pipelineAnalytics.getMediaLocationCensus": {
89713
+ capName: "pipeline-analytics",
89714
+ capScope: "device",
89715
+ addonId: null,
89716
+ access: "view",
89717
+ role: "admin"
89718
+ },
89642
89719
  "pipelineAnalytics.getMediaReclaimStatus": {
89643
89720
  capName: "pipeline-analytics",
89644
89721
  capScope: "device",
@@ -98837,6 +98914,100 @@ object({
98837
98914
  delay: number().nonnegative().optional(),
98838
98915
  commands: record(string(), unknown())
98839
98916
  });
98917
+ entryBody({ brokerId: string() });
98918
+ function secretsOverMigrationApi(api) {
98919
+ return {
98920
+ resolve: async (refs) => {
98921
+ const { values } = await api.secrets.resolve({ refs: [...refs] });
98922
+ const out = {};
98923
+ for (const ref of refs) {
98924
+ const value = values[ref];
98925
+ out[ref] = value === null || value === void 0 ? { kind: "missing" } : {
98926
+ kind: "value",
98927
+ value,
98928
+ version: 0
98929
+ };
98930
+ }
98931
+ return out;
98932
+ },
98933
+ delete: async (refs) => (await api.secrets.delete({ refs: [...refs] })).deleted
98934
+ };
98935
+ }
98936
+ /** `ctx.records` as the migration API offers it: bind a kind, read and write by id. */
98937
+ function recordsOverMigrationApi(api) {
98938
+ return { kind: (definition) => {
98939
+ const handle = api.records.kind(definition);
98940
+ return {
98941
+ get: (id) => handle.get({ id }),
98942
+ getResolved: (id) => handle.getResolved({ id }),
98943
+ put: (input, opts) => handle.put({
98944
+ ...input,
98945
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
98946
+ }),
98947
+ delete: (id) => handle.delete({ id })
98948
+ };
98949
+ } };
98950
+ }
98951
+ function integrationRowsApiOver(api) {
98952
+ return {
98953
+ list: async () => (await api.integrations.list({})).integrations,
98954
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
98955
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
98956
+ };
98957
+ }
98958
+ /**
98959
+ * One serial lane per migration API: a log line is delivered after the line before it, so the
98960
+ * order the steps wrote them in is the order the hub reads them in. A delivery that fails
98961
+ * is reported once through the same door; if that fails too nothing is left to tell, and the
98962
+ * line is dropped rather than thrown into a migration step or left as an unhandled rejection.
98963
+ */
98964
+ var lanes = /* @__PURE__ */ new WeakMap();
98965
+ function deliver(api, send) {
98966
+ const next = (lanes.get(api) ?? Promise.resolve()).then(send).then(() => void 0).catch(async (error) => {
98967
+ const reason = error instanceof Error ? error.message : String(error);
98968
+ await api.log.warn({ message: `a migration log line could not be delivered: ${reason}` }).catch(() => void 0);
98969
+ });
98970
+ lanes.set(api, next);
98971
+ return next;
98972
+ }
98973
+ function warnOver(api) {
98974
+ return (message) => deliver(api, () => api.log.warn({ message }));
98975
+ }
98976
+ /** What the rows-to-records move needs, over the migration API. */
98977
+ function rowsDepsOver(api) {
98978
+ return {
98979
+ api: integrationRowsApiOver(api),
98980
+ records: recordsOverMigrationApi(api),
98981
+ secrets: secretsOverMigrationApi(api),
98982
+ warn: warnOver(api)
98983
+ };
98984
+ }
98985
+ function defaultIntegrationApiOver$1(api) {
98986
+ return {
98987
+ ...integrationRowsApiOver(api),
98988
+ listDevices: async (addonId) => (await api.devices.list({ addonId })).devices,
98989
+ readDeviceHasConfig: async (deviceId) => (await api.devices.get({ deviceId }))?.hasConfig ?? false,
98990
+ setDeviceIntegrationId: async (deviceId, integrationId) => {
98991
+ await api.devices.setIntegrationId({
98992
+ deviceId,
98993
+ integrationId
98994
+ });
98995
+ },
98996
+ readDeviceIntegrationId: async (deviceId) => (await api.devices.get({ deviceId }))?.integrationId ?? null
98997
+ };
98998
+ }
98999
+ /** What the rows-to-records move and the device claim need, over the migration API. */
99000
+ function defaultIntegrationDepsOver(api) {
99001
+ return {
99002
+ ...rowsDepsOver(api),
99003
+ api: defaultIntegrationApiOver$1(api),
99004
+ info: (message) => deliver(api, () => api.log.info({ message })),
99005
+ warnDevice: (message, deviceId) => deliver(api, () => api.log.warn({
99006
+ message,
99007
+ tags: { deviceId }
99008
+ }))
99009
+ };
99010
+ }
98840
99011
  //#endregion
98841
99012
  //#region src/amcrest-instances.ts
98842
99013
  /**
@@ -106910,19 +107081,13 @@ var AmcrestProviderAddon = class extends BaseDeviceProvider {
106910
107081
  const records = this.ctx.records;
106911
107082
  if (records === void 0) throw new Error("provider-amcrest: ctx.records is required (hub-only addon)");
106912
107083
  await records.declare(amcrestRecordKinds);
106913
- const defaultIntegration = defineAddonMigrations(defaultIntegrationMigrations({
107084
+ await this.runMigrations(defaultIntegrationMigrations({
106914
107085
  addonId: this.addonId,
106915
107086
  date: "2026-11-04"
106916
- }), defaultIntegrationPortsOver({
106917
- api: defaultIntegrationApiOver(this.ctx.api),
106918
- secrets: this.ctx.secrets ?? null,
106919
- records,
106920
- kind: amcrestConnectionsEntryKind,
106921
- info: (message) => this.ctx.logger.info(message),
106922
- warn: (message) => this.ctx.logger.warn(message),
106923
- warnDevice: (message, deviceId) => this.ctx.logger.warn(message, { tags: { deviceId } })
107087
+ }), (api) => defaultIntegrationPortsOver({
107088
+ ...defaultIntegrationDepsOver(api),
107089
+ kind: amcrestConnectionsEntryKind
106924
107090
  }));
106925
- await this.runMigrations(defaultIntegration);
106926
107091
  this.clipService = createClipService({
106927
107092
  dataDir: this.ctx.dataDir,
106928
107093
  logger: this.ctx.logger,