@camstack/addon-export-hap 1.2.196 → 1.2.198

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.
@@ -842,7 +842,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
842
842
  return EventCategory;
843
843
  }({});
844
844
  //#endregion
845
- //#region ../types/dist/device-type-D1fH5kaC.mjs
845
+ //#region ../types/dist/device-type-DxCT0krO.mjs
846
846
  /**
847
847
  import { errMsg } from '@camstack/types'
848
848
  * Extract a human-readable message from an unknown error value.
@@ -1004,6 +1004,13 @@ var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
1004
1004
  * filters that want "all devices with on-motion behaviour".
1005
1005
  */
1006
1006
  DeviceFeature["MotionTrigger"] = "motion-trigger";
1007
+ /**
1008
+ * Device can be run for a chosen time and then stopped. Mirrors the
1009
+ * `timed-run` wrapper cap — the cap is bound by the core-blocks addon, not by
1010
+ * a driver, so the flag is derived from the device's bindings
1011
+ * (`featuresOfBoundCaps`). Gates the quick-run control in the viewer.
1012
+ */
1013
+ DeviceFeature["TimedRun"] = "timed-run";
1007
1014
  /** Light supports rgb-triplet color via `color` cap. */
1008
1015
  DeviceFeature["LightColorRgb"] = "light-color-rgb";
1009
1016
  /** Light supports HSV color via `color` cap. */
@@ -6038,7 +6045,7 @@ var ZodIssueCode = {
6038
6045
  var ZodFirstPartyTypeKind;
6039
6046
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6040
6047
  //#endregion
6041
- //#region ../types/dist/sleep-AEnTN3b4.mjs
6048
+ //#region ../types/dist/sleep-CGPZyzB5.mjs
6042
6049
  /**
6043
6050
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6044
6051
  * window to float samples (D455).
@@ -6402,6 +6409,59 @@ Object.fromEntries([
6402
6409
  function isValuelessField(field) {
6403
6410
  return field.type === "separator" || field.type === "info" || field.type === "qr-code" || field.type === "button" || field.type === "object-array" || field.type === "widget" || field.type === "addon-action-button" || field.type === "device-action-button" || field.type === "account-sign-in" || field.type === "secret-presence";
6404
6411
  }
6412
+ /**
6413
+ * Base collector: flatten a hydrated `ConfigUISchemaWithValues` into
6414
+ * `key → { value, default }`, recursing through `group` and `sub-tabs`
6415
+ * layout fields. Keeping `value` and `default` SEPARATE (rather than
6416
+ * pre-resolving) lets callers both read the effective value AND detect
6417
+ * overrides (`value` differs from `default`). Structural over `unknown`;
6418
+ * malformed input yields an empty map, never throws.
6419
+ */
6420
+ function collectHydratedFieldEntries(schema) {
6421
+ const out = /* @__PURE__ */ new Map();
6422
+ if (typeof schema !== "object" || schema === null) return out;
6423
+ const sections = schema.sections;
6424
+ if (!Array.isArray(sections)) return out;
6425
+ for (const section of sections) if (typeof section === "object" && section !== null) collectFieldEntriesInto(section.fields, out);
6426
+ return out;
6427
+ }
6428
+ /** Recursive field walker for {@link collectHydratedFieldEntries}. */
6429
+ function collectFieldEntriesInto(fields, into) {
6430
+ if (!Array.isArray(fields)) return;
6431
+ for (const field of fields) {
6432
+ if (typeof field !== "object" || field === null) continue;
6433
+ const type = field.type;
6434
+ if (type === "group") {
6435
+ collectFieldEntriesInto(field.fields, into);
6436
+ continue;
6437
+ }
6438
+ if (type === "sub-tabs") {
6439
+ const tabs = field.tabs;
6440
+ if (Array.isArray(tabs)) {
6441
+ for (const tab of tabs) if (typeof tab === "object" && tab !== null) collectFieldEntriesInto(tab.fields, into);
6442
+ }
6443
+ continue;
6444
+ }
6445
+ const key = field.key;
6446
+ if (typeof key !== "string" || key.length === 0) continue;
6447
+ if (!("value" in field)) continue;
6448
+ into.set(key, {
6449
+ value: field.value,
6450
+ default: field.default
6451
+ });
6452
+ }
6453
+ }
6454
+ /**
6455
+ * Flatten a hydrated settings payload into `key → EFFECTIVE value`
6456
+ * (`value ?? default`). The read-side inverse of `hydrateSchema` for the
6457
+ * common "just give me the resolved values" case. Built on
6458
+ * {@link collectHydratedFieldEntries}.
6459
+ */
6460
+ function collectHydratedFieldValues(schema) {
6461
+ const out = /* @__PURE__ */ new Map();
6462
+ for (const [key, entry] of collectHydratedFieldEntries(schema)) out.set(key, entry.value ?? entry.default);
6463
+ return out;
6464
+ }
6405
6465
  function hydrateSchema(schema, values, options = {}) {
6406
6466
  return {
6407
6467
  ...schema.tabs ? { tabs: [...schema.tabs] } : {},
@@ -7201,6 +7261,7 @@ var RecordIntegrationInstances = class {
7201
7261
  this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
7202
7262
  this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
7203
7263
  this.nameField = kind.declaration.entry?.nameField ?? "name";
7264
+ if (hooks.kindOf === void 0 && hooks.description.kinds.length !== 1) throw new Error(`record kind '${kind.name}': describe().kinds has ${hooks.description.kinds.length} entries, so kindOf is required to say which one an instance is`);
7204
7265
  }
7205
7266
  /**
7206
7267
  * One instance read for the addon's own runtime; null when absent. When the keychain is
@@ -7242,10 +7303,21 @@ var RecordIntegrationInstances = class {
7242
7303
  }
7243
7304
  return out;
7244
7305
  }
7306
+ /** The kind an instance body is of: the provider's `kindOf`, else its one declared kind. */
7307
+ kindOfBody(body) {
7308
+ if (this.hooks.kindOf !== void 0) {
7309
+ const id = this.hooks.kindOf(body);
7310
+ if (!this.hooks.description.kinds.some((declared) => declared.id === id)) throw new Error(`record kind '${this.kind.name}': kindOf returned '${id}', which describe().kinds does not declare (D1013)`);
7311
+ return id;
7312
+ }
7313
+ const only = this.hooks.description.kinds[0];
7314
+ if (only === void 0) throw new Error(`record kind '${this.kind.name}' declares no kinds`);
7315
+ return only.id;
7316
+ }
7245
7317
  viewOf(record) {
7246
7318
  const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
7247
7319
  const rawName = record.data[this.nameField];
7248
- const kind = this.hooks.kindOf?.(record.data);
7320
+ const kind = this.kindOfBody(record.data);
7249
7321
  const health = this.hooks.health?.(record.data, record.id);
7250
7322
  return {
7251
7323
  id: record.id,
@@ -7253,7 +7325,7 @@ var RecordIntegrationInstances = class {
7253
7325
  configured: this.hooks.configured(record.data),
7254
7326
  enabled: isInstanceEnabled(record.data),
7255
7327
  formValues: shown,
7256
- ...kind !== void 0 ? { kind } : {},
7328
+ kind,
7257
7329
  ...health?.status !== void 0 ? { status: health.status } : {},
7258
7330
  ...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
7259
7331
  };
@@ -7625,6 +7697,21 @@ var SCOPED_SETTINGS_SCOPES = [
7625
7697
  "device-defaults",
7626
7698
  "node"
7627
7699
  ];
7700
+ /** The one refusal of a key a scope did not declare. */
7701
+ function assertDeclaredKeys(keys, declared) {
7702
+ const undeclared = keys.filter((key) => !declared.has(key));
7703
+ if (undeclared.length > 0) throw new Error(`scoped settings: [${undeclared.join(", ")}] not declared for this scope (declared: [${[...declared].join(", ")}])`);
7704
+ }
7705
+ /** Build the handle over an addon's scoped read, write and unset. */
7706
+ function createScopedSettings(deps) {
7707
+ return {
7708
+ async get() {
7709
+ return deps.schema.parse(await deps.read());
7710
+ },
7711
+ patch: (patch) => deps.write(Object.fromEntries(Object.entries(patch))),
7712
+ unset: (keys) => deps.unset(keys)
7713
+ };
7714
+ }
7628
7715
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
7629
7716
  var KeychainWriteRefusedError = class extends Error {
7630
7717
  fieldPath;
@@ -8200,7 +8287,16 @@ function createHandle(raw, opts) {
8200
8287
  return blob;
8201
8288
  }
8202
8289
  },
8203
- writeAddonStore: writeAddon
8290
+ writeAddonStore: writeAddon,
8291
+ removeClearedKeys: (keys) => serialize("addon", async () => {
8292
+ const stored = await readStoredAddonBlob(raw);
8293
+ index.seen("addon", stored);
8294
+ const removable = keys.filter((key) => collectSecretMarkerRefs(stored[key]).length === 0);
8295
+ if (removable.length === 0) return;
8296
+ const patch = Object.fromEntries(removable.map((key) => [key, void 0]));
8297
+ await raw.writeAddonStore(patch);
8298
+ index.wrote("addon", patch);
8299
+ })
8204
8300
  };
8205
8301
  }
8206
8302
  /** The context the addon sees, plus the private raw view and write outcome. */
@@ -8330,7 +8426,7 @@ function boundOf(list) {
8330
8426
  * Base class for CamStack addons. Eliminates settings boilerplate:
8331
8427
  *
8332
8428
  * - Typed `config` property with automatic resolution from store + defaults
8333
- * - `getGlobalSettings()` / `updateGlobalSettings()` auto-implemented
8429
+ * - the scoped settings API (`clusterSettings` / `nodeSettings` / `deviceDefaults`) auto-implemented
8334
8430
  * - `getAddonSettings()` / `updateAddonSettings()` auto-implemented
8335
8431
  * - `getDeviceSettings()` / `updateDeviceSettings()` auto-implemented
8336
8432
  * - `ctx` accessor for the AddonContext (no manual `this.ctxRef` storage)
@@ -8340,7 +8436,7 @@ function boundOf(list) {
8340
8436
  * Subclasses override:
8341
8437
  * - `onInitialize()` — addon-specific init logic, return ProviderRegistration[]
8342
8438
  * - `onShutdown()` — cleanup
8343
- * - `globalSettingsSchema()` / `deviceSettingsSchema()` — UI schemas
8439
+ * - `clusterSettingsSchema()` / `nodeSettingsSchema()` / `deviceSettingsSchema()` — UI schemas
8344
8440
  *
8345
8441
  * @example
8346
8442
  * ```ts
@@ -8354,7 +8450,7 @@ function boundOf(list) {
8354
8450
  * super({ maxRetries: 3, endpoint: 'http://localhost' })
8355
8451
  * }
8356
8452
  *
8357
- * protected globalSettingsSchema() {
8453
+ * protected clusterSettingsSchema() {
8358
8454
  * return this.schema({
8359
8455
  * sections: [{
8360
8456
  * id: 'main', title: 'Settings',
@@ -8397,7 +8493,7 @@ var BaseAddon = class {
8397
8493
  defaults;
8398
8494
  /**
8399
8495
  * Hidden-state paths that hold secrets (D787) — values the addon writes
8400
- * itself (`updateGlobalSettings`, `state()`) that no form field declares.
8496
+ * itself (`state()`, the scoped writers) that no form field declares.
8401
8497
  * Stored in the keychain exactly like a `password` field. Syntax:
8402
8498
  * `'snapshotSigningKey'`, `'identity.pincode'`, `'tokens[userId].accessToken'`
8403
8499
  * (`key[<id field>]` addresses array items by id, never by index).
@@ -8407,7 +8503,7 @@ var BaseAddon = class {
8407
8503
  /**
8408
8504
  * D986 M4: the scoped schemas this addon declared, resolved once per capability
8409
8505
  * (`loadScopedSchemas`) so the sync readers (`perNodeKeys`, the secret tree, the restart check)
8410
- * see them. Empty until loaded: the readers then fall back to {@link globalSettingsSchema}.
8506
+ * see them. Empty until loaded.
8411
8507
  */
8412
8508
  _scopedByCap = /* @__PURE__ */ new Map();
8413
8509
  _nodeKeysByCap = /* @__PURE__ */ new Map();
@@ -8593,7 +8689,7 @@ var BaseAddon = class {
8593
8689
  /** Addon-specific cleanup. Override if needed. */
8594
8690
  async onShutdown() {}
8595
8691
  /**
8596
- * Called after config is resolved during updateGlobalSettings/updateAddonSettings.
8692
+ * Called after config is resolved during a settings write.
8597
8693
  * Override to react to config changes (e.g. restart a sampler, reconnect a service).
8598
8694
  * Not called during initialize() — use onInitialize() for initial setup.
8599
8695
  */
@@ -8622,82 +8718,12 @@ var BaseAddon = class {
8622
8718
  scopedSettingsCapabilities() {
8623
8719
  return [];
8624
8720
  }
8625
- /** Override to provide global-level settings UI schema. */
8626
- globalSettingsSchema(_cap) {
8627
- return null;
8628
- }
8629
8721
  /** Override to provide device-level settings UI schema. */
8630
8722
  deviceSettingsSchema() {
8631
8723
  return null;
8632
8724
  }
8633
8725
  /**
8634
- * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
8635
- * ARE the configuration of its integration.
8636
- *
8637
- * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
8638
- * operator should find on the addon's integration page (System →
8639
- * Integrations → <name>) rather than only in the cluster-wide list of every
8640
- * addon. Empty (the default) means the addon has no integration-level
8641
- * settings and no such surface is offered — this is opt-in, because whether
8642
- * an addon's configuration IS its integration's configuration depends on the
8643
- * nature of the integration.
8644
- *
8645
- * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
8646
- * the ONE global schema, in the ONE addon store, written by the ONE
8647
- * `updateGlobalSettings` path. There is deliberately no
8648
- * `updateIntegrationSettings`: a second write path is how a surface acquires
8649
- * a second store key, and this repo has shipped that twice (`btmPath@hub`,
8650
- * D266). Selecting sections cannot introduce a key that selecting cannot.
8651
- *
8652
- * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
8653
- * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
8654
- * removed with the reason recorded at
8655
- * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
8656
- * determined by WHICH schema it lives in, not by a field-level marker."* A
8657
- * marker sprinkled across sections also has to borrow a field that already
8658
- * means something else; borrowing `section.tab` put the literal word
8659
- * "integration" into an operator-facing tab bar, because `tab` means "how to
8660
- * GROUP this visually" and cannot also mean "where this lives" (D269
8661
- * supersedes D268). One declaration, in one place, next to the schema whose
8662
- * ids it names.
8663
- */
8664
- integrationSettingSections() {
8665
- return [];
8666
- }
8667
- async getGlobalSettings(overlay, cap, nodeId) {
8668
- await this.loadScopedSchemas(cap);
8669
- const schema = this.globalSettingsSchema(cap) ?? this.scopedFormSchema(cap);
8670
- if (!schema) return { sections: [] };
8671
- const projected = await this.readRawProjectedStore(nodeId, cap);
8672
- return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(projected, overlay) : projected, { inlineSecretsAsViews: true });
8673
- }
8674
- /**
8675
- * The integration-level view of this addon's settings: exactly the sections
8676
- * named by {@link integrationSettingSections}, hydrated from the SAME store
8677
- * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
8678
- *
8679
- * Returns `null` when the addon declared nothing — an addon that opts out has
8680
- * no integration settings surface at all, rather than an empty one that reads
8681
- * as a failed load.
8682
- *
8683
- * Three properties hold BY CONSTRUCTION, which is why they are here in core
8684
- * and not in whichever UI happens to render this:
8685
- *
8686
- * 1. **One key.** The payload is a SUBSET of the global schema, so a field
8687
- * shown here is the same field, with the same bare key, that the addon's
8688
- * own page shows. There is no integration-specific writer — callers save
8689
- * through `updateGlobalSettings` — so a second store key is unreachable,
8690
- * not merely discouraged.
8691
- * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
8692
- * is `<key>@<nodeId>` and an integration is not a node; whichever node
8693
- * such a field silently picked would be a wrong answer for the operator
8694
- * who opened the page (D266).
8695
- * 3. **No silent typo.** A declared id that names no section throws. The
8696
- * alternative — skip it — turns a rename into a surface that quietly
8697
- * empties, which looks exactly like an addon with nothing to configure.
8698
- */
8699
- /**
8700
- * The form schema of ONE integration instance, or `null` to use {@link globalSettingsSchema}.
8726
+ * The form schema of ONE integration instance, or `null` to use the scoped form.
8701
8727
  *
8702
8728
  * Override it only when an `instanceMode: multiple` addon's instances differ: an NVR integration
8703
8729
  * needs its connection fields, the default integration the addon's own sections. It is the
@@ -8745,37 +8771,178 @@ var BaseAddon = class {
8745
8771
  }
8746
8772
  }
8747
8773
  /**
8774
+ * Hook: values layered over the stored ones when the FORM of one scope is served
8775
+ * ({@link getScopedSettings}) — a preview that derives dependent options without writing.
8776
+ * Never applied to {@link ScopedSettings.get} or to a write. `null` ⇒ no overlay.
8777
+ */
8778
+ async scopedSettingsOverlay(_scope, _cap, _nodeId) {
8779
+ return null;
8780
+ }
8781
+ /**
8782
+ * Hook: a write of one scope changed stored values (not called when the store reports no change,
8783
+ * e.g. the write-back of a stored secret). `keys` are the bare field keys of the write, node keys included.
8784
+ */
8785
+ async onScopedSettingsChanged(_scope, _cap, _keys) {}
8786
+ /** Typed handle over the CLUSTER settings `cap` declares (`clusterSettingsSchema`). */
8787
+ clusterSettings(cap, schema) {
8788
+ return this.scopedHandle("cluster", cap, schema);
8789
+ }
8790
+ /** Typed handle over the fleet defaults of the per-device settings `cap` declares. */
8791
+ deviceDefaults(cap, schema) {
8792
+ return this.scopedHandle("device-defaults", cap, schema);
8793
+ }
8794
+ /**
8795
+ * Typed handle over the settings `cap` owns PER NODE. `nodeId` omitted ⇒ the local node. A node
8796
+ * with no row yields the schema defaults — never a bare-key fallback.
8797
+ */
8798
+ nodeSettings(cap, schema, nodeId) {
8799
+ return this.scopedHandle("node", cap, schema, nodeId);
8800
+ }
8801
+ /**
8802
+ * {@link state} for a value that is kept per node: stored under `<key>@<nodeId>`, and the
8803
+ * settings store carries `nodeId` in the row data (D986 §1), so a forgotten node's rows go in one
8804
+ * central delete. `nodeId` omitted ⇒ the local node.
8805
+ */
8806
+ nodeState(key, schema, fallback, nodeId) {
8807
+ this._declaredStateKeys.add(key);
8808
+ return createDurableState({
8809
+ key: nodeScopedKey(key, nodeId ?? this._ctx?.kernel?.localNodeId ?? ""),
8810
+ schema,
8811
+ fallback,
8812
+ read: async () => this.resolveStoredSecrets(await this.readAddonStoreWithRetry()),
8813
+ write: async (patch) => {
8814
+ await this._ctx?.settings?.writeAddonStore(patch);
8815
+ },
8816
+ onParseError: (k, e) => this._ctx?.logger?.warn?.(`durable-state: stored "${k}" failed validation — using fallback`, { meta: {
8817
+ addonId: this._ctx?.id,
8818
+ key: k,
8819
+ error: String(e)
8820
+ } })
8821
+ });
8822
+ }
8823
+ /** The loaded schema `cap` declares for `scope`, or `null`. */
8824
+ async declaredScopedSchema(scope, cap) {
8825
+ await this.loadScopedSchemas(cap);
8826
+ return this.loadedScopedSchemas(cap).find((entry) => entry.scope === scope)?.schema ?? null;
8827
+ }
8828
+ async requireScopedSchema(scope, cap) {
8829
+ const schema = await this.declaredScopedSchema(scope, cap);
8830
+ if (schema === null) throw new Error(`${this.constructor.name}: cap "${cap}" declares no ${scope} settings`);
8831
+ return schema;
8832
+ }
8833
+ scopedKeys(schema) {
8834
+ return new Set(schema.sections.flatMap((section) => collectValueFieldKeys(section.fields)));
8835
+ }
8836
+ /** `store` narrowed to the keys `schema` declares. */
8837
+ narrowToScope(store, schema) {
8838
+ const keys = this.scopedKeys(schema);
8839
+ return Object.fromEntries(Object.entries(store).filter(([key]) => keys.has(key)));
8840
+ }
8841
+ scopedHandle(scope, cap, schema, nodeId) {
8842
+ return createScopedSettings({
8843
+ schema,
8844
+ read: async () => {
8845
+ const declared = await this.requireScopedSchema(scope, cap);
8846
+ const stored = this.narrowToScope(await this.resolveGlobalStore(nodeId, cap), declared);
8847
+ const effective = collectHydratedFieldValues(hydrateSchema(declared, stored));
8848
+ return {
8849
+ ...Object.fromEntries([...effective].filter(([, value]) => value !== void 0)),
8850
+ ...stored
8851
+ };
8852
+ },
8853
+ write: (patch) => this.writeScoped(scope, cap, patch, nodeId),
8854
+ unset: (keys) => this.unsetScoped(scope, cap, keys, nodeId)
8855
+ });
8856
+ }
8857
+ /** The one write path of the scoped API: declared keys only, then the global patch. */
8858
+ async writeScoped(scope, cap, patch, nodeId) {
8859
+ assertDeclaredKeys(Object.keys(patch), this.scopedKeys(await this.requireScopedSchema(scope, cap)));
8860
+ if (await this.applyGlobalPatch(patch, scope === "node" ? nodeId : void 0, cap)) await this.onScopedSettingsChanged(scope, cap, Object.keys(patch));
8861
+ }
8862
+ /**
8863
+ * Remove declared keys of one scope. A secret goes through {@link clearSecrets} — its keychain
8864
+ * value is released exactly as there — and the emptied row is then removed; every other key is
8865
+ * removed by an `undefined` patch (which a secret transform would read as "keep").
8866
+ */
8867
+ async unsetScoped(scope, cap, keys, nodeId) {
8868
+ assertDeclaredKeys(keys, this.scopedKeys(await this.requireScopedSchema(scope, cap)));
8869
+ const target = scope === "node" ? nodeId : void 0;
8870
+ const tree = this.addonSecretTree();
8871
+ const secretKeys = keys.filter((key) => tree.has(key));
8872
+ const plainKeys = keys.filter((key) => !tree.has(key));
8873
+ let changed = false;
8874
+ if (plainKeys.length > 0) {
8875
+ const patch = Object.fromEntries(plainKeys.map((key) => [key, void 0]));
8876
+ changed = await this.applyGlobalPatch(patch, target, cap) || changed;
8877
+ }
8878
+ if (secretKeys.length > 0) {
8879
+ await this.clearSecretKeys(secretKeys, target, cap);
8880
+ const node = normalizeNodeId(target ?? this._ctx?.kernel?.localNodeId);
8881
+ const rows = secretKeys.map((key) => scope === "node" ? nodeScopedKey(key, node) : key);
8882
+ if (this._secretSettings !== null) await this._secretSettings.removeClearedKeys(rows);
8883
+ else await this._ctx?.settings?.writeAddonStore(Object.fromEntries(rows.map((row) => [row, void 0])));
8884
+ changed = true;
8885
+ }
8886
+ if (changed) await this.onScopedSettingsChanged(scope, cap, [...keys]);
8887
+ }
8888
+ /**
8889
+ * The hydrated form of one scope of one capability's settings (any
8890
+ * {@link scopedSettingsOverlay} applied), or `null` when the capability declares nothing there.
8891
+ */
8892
+ async getScopedSettings(scope, cap, nodeId) {
8893
+ const schema = await this.declaredScopedSchema(scope, cap);
8894
+ if (schema === null) return null;
8895
+ const stored = this.narrowToScope(await this.readRawProjectedStore(nodeId, cap), schema);
8896
+ const overlay = await this.scopedSettingsOverlay(scope, cap, nodeId);
8897
+ return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(stored, overlay) : stored, { inlineSecretsAsViews: true });
8898
+ }
8899
+ /**
8900
+ * The scoped schemas this addon serves: one entry per loaded (capability, scope), capabilities
8901
+ * in declaration order, scopes in {@link SCOPED_SETTINGS_SCOPES} order. `[]` when it declares
8902
+ * nothing.
8903
+ */
8904
+ async listScopedSettings() {
8905
+ await this.loadScopedSchemas();
8906
+ return [...this._scopedByCap].flatMap(([cap, entries]) => entries.map((entry) => ({
8907
+ cap,
8908
+ scope: entry.scope,
8909
+ sectionIds: entry.schema.sections.map((section) => section.id)
8910
+ })));
8911
+ }
8912
+ /** The OPERATOR's write of declared keys of one scope (D787 secret semantics). */
8913
+ async updateScopedSettings(scope, cap, patch, nodeId) {
8914
+ this._operatorWriteDepth++;
8915
+ try {
8916
+ await this.writeScoped(scope, cap, patch, nodeId);
8917
+ } finally {
8918
+ this._operatorWriteDepth--;
8919
+ }
8920
+ }
8921
+ /**
8922
+ * The effective values (`stored ?? default`) of one scope, a secret as its `set` view — never
8923
+ * its value. `null` when the capability declares nothing for the scope.
8924
+ */
8925
+ async readScopedValues(scope, cap, nodeId) {
8926
+ const schema = await this.declaredScopedSchema(scope, cap);
8927
+ if (schema === null) return null;
8928
+ const form = hydrateSchema(schema, this.narrowToScope(await this.readRawProjectedStore(nodeId, cap), schema), { inlineSecretsAsViews: true });
8929
+ return Object.fromEntries([...collectHydratedFieldValues(form)].filter(([, value]) => value !== void 0));
8930
+ }
8931
+ /**
8748
8932
  * What the create wizard and the integration edit page render for one instance: the addon's
8749
8933
  * per-instance schema when it declares one, else its global schema (what they always showed).
8750
8934
  */
8751
8935
  async getIntegrationFormSchema(instance, nodeId) {
8752
8936
  const scoped = await this.integrationFormSchema(instance);
8753
- if (scoped === null) return this.getGlobalSettings(void 0, void 0, nodeId);
8937
+ if (scoped === null) return this.scopedForm(nodeId);
8754
8938
  return hydrateSchema(scoped, {}, { inlineSecretsAsViews: true });
8755
8939
  }
8756
- async getIntegrationSettings(nodeId) {
8757
- const declared = this.integrationSettingSections();
8758
- if (declared.length === 0) return null;
8759
- const schema = this.globalSettingsSchema();
8760
- if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
8761
- const byId = new Map(schema.sections.map((section) => [section.id, section]));
8762
- const sections = [];
8763
- for (const id of declared) {
8764
- const section = byId.get(id);
8765
- if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
8766
- const fields = dropPerNodeFields(section.fields);
8767
- if (fields.length === 0) continue;
8768
- sections.push({
8769
- ...section,
8770
- fields
8771
- });
8772
- }
8773
- if (sections.length === 0) return null;
8774
- const projected = await this.readRawProjectedStore(nodeId);
8775
- return hydrateSchema({
8776
- ...schema,
8777
- sections
8778
- }, projected, { inlineSecretsAsViews: true });
8940
+ /** The form of the scoped schemas this addon declared, hydrated from its store. */
8941
+ async scopedForm(nodeId) {
8942
+ await this.loadScopedSchemas();
8943
+ const schema = this.scopedFormSchema();
8944
+ if (!schema) return { sections: [] };
8945
+ return hydrateSchema(schema, await this.readRawProjectedStore(nodeId), { inlineSecretsAsViews: true });
8779
8946
  }
8780
8947
  /**
8781
8948
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
@@ -8784,8 +8951,8 @@ var BaseAddon = class {
8784
8951
  * bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
8785
8952
  * A no-op passthrough when the schema declares no `perNode` field.
8786
8953
  *
8787
- * This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
8788
- * the store for custom option logic (option narrowing, value snapping) to
8954
+ * This is the sanctioned way for an addon that needs
8955
+ * the store for custom logic (option narrowing, value snapping) to
8789
8956
  * read it per-node — never `ctx.settings.readAddonStore()` directly.
8790
8957
  * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
8791
8958
  *
@@ -8837,7 +9004,7 @@ var BaseAddon = class {
8837
9004
  }
8838
9005
  /**
8839
9006
  * Whether ONE global key of this addon's store was written, read three-way
8840
- * (D651). For a question a hydrated view cannot answer: `getGlobalSettings`
9007
+ * (D651). For a question a hydrated view cannot answer: a hydrated form
8841
9008
  * reports `value ?? default`, so "the operator chose the default" and "nobody
8842
9009
  * chose" look the same, and a failed read looks like both. A `perNode` key is
8843
9010
  * not supported here: its stored name is scoped.
@@ -8871,7 +9038,7 @@ var BaseAddon = class {
8871
9038
  }
8872
9039
  /**
8873
9040
  * The OPERATOR's write — a settings form or an admin API call, dispatched by
8874
- * the kernel. Identical to {@link updateGlobalSettings}, except that a secret
9041
+ * the kernel. The one in-process write of the addon blob that is not a scoped write; a secret
8875
9042
  * the operator sends is stored as sent even when it equals a pre-keychain
8876
9043
  * inline value: the operator re-entering a password is a change, an addon
8877
9044
  * writing back what it read is not (D787).
@@ -8884,9 +9051,6 @@ var BaseAddon = class {
8884
9051
  this._operatorWriteDepth--;
8885
9052
  }
8886
9053
  }
8887
- async updateGlobalSettings(patch, nodeId) {
8888
- await this.applyGlobalPatch(patch, nodeId);
8889
- }
8890
9054
  /**
8891
9055
  * REMOVE stored secrets — their keychain values and their markers (D787).
8892
9056
  *
@@ -8896,6 +9060,9 @@ var BaseAddon = class {
8896
9060
  * a keychain (an older kernel) it writes `''`, as such code always did.
8897
9061
  */
8898
9062
  async clearSecrets(keys, nodeId) {
9063
+ await this.clearSecretKeys(keys, nodeId);
9064
+ }
9065
+ async clearSecretKeys(keys, nodeId, cap) {
8899
9066
  const tree = this.addonSecretTree();
8900
9067
  const keychain = this._ctx?.secrets !== void 0;
8901
9068
  const stored = keychain ? await this.readAddonStoreWithRetry() : {};
@@ -8908,25 +9075,26 @@ var BaseAddon = class {
8908
9075
  const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
8909
9076
  patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
8910
9077
  }
8911
- await this.applyGlobalPatch(patch, nodeId);
9078
+ await this.applyGlobalPatch(patch, nodeId, cap);
8912
9079
  }
8913
- async applyGlobalPatch(barePatch, nodeId) {
8914
- await this.loadScopedSchemas();
8915
- const keys = this.perNodeKeys();
9080
+ /** Resolves `true` when the write changed stored values. */
9081
+ async applyGlobalPatch(barePatch, nodeId, cap) {
9082
+ await this.loadScopedSchemas(cap);
9083
+ const keys = this.perNodeKeys(cap);
8916
9084
  const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
8917
9085
  const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
8918
9086
  const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
8919
9087
  const handle = this._secretSettings;
8920
9088
  if (handle !== null) {
8921
9089
  const { changed } = await handle.writeAddonStore(scoped);
8922
- if (!changed) return;
9090
+ if (!changed) return false;
8923
9091
  } else await this._ctx?.settings?.writeAddonStore(scoped);
8924
- if (target !== localNode) return;
9092
+ if (target !== localNode) return true;
8925
9093
  await this.resolveConfig();
8926
9094
  await this.onConfigChanged();
8927
9095
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
8928
- const legacy = this.globalSettingsSchema();
8929
- this.maybeAutoRestart(Object.keys(barePatch), [...legacy === null ? [] : [legacy], ...this.loadedScopedSchemas().map((entry) => entry.schema)]);
9096
+ this.maybeAutoRestart(Object.keys(barePatch), this.loadedScopedSchemas().map((entry) => entry.schema));
9097
+ return true;
8930
9098
  }
8931
9099
  /**
8932
9100
  * The set of field keys the global settings schema declares `perNode: true`
@@ -8963,10 +9131,7 @@ var BaseAddon = class {
8963
9131
  this._nodeKeysByCap = /* @__PURE__ */ new Map();
8964
9132
  this._addonSecretTree = null;
8965
9133
  }
8966
- /**
8967
- * The form the settings API serves while an addon declares no {@link globalSettingsSchema}: the
8968
- * sections of its scoped schemas, so dropping the old hook does not blank the form.
8969
- */
9134
+ /** The form of an addon's scoped schemas: their sections, each shown once. */
8970
9135
  scopedFormSchema(cap) {
8971
9136
  const byId = /* @__PURE__ */ new Map();
8972
9137
  for (const entry of this.loadedScopedSchemas(cap)) for (const section of entry.schema.sections) if (!byId.has(section.id)) byId.set(section.id, section);
@@ -8978,8 +9143,7 @@ var BaseAddon = class {
8978
9143
  return [...this._scopedByCap.values()].flat();
8979
9144
  }
8980
9145
  /**
8981
- * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}, plus
8982
- * the fields the legacy {@link globalSettingsSchema} still marks `perNode: true`. Derived once
9146
+ * The field keys that are stored per node: every field of a {@link nodeSettingsSchema}. Derived once
8983
9147
  * per `cap` argument and memoized (schemas are static declarations). Empty set ⇒ every
8984
9148
  * per-node code path is bypassed and the settings API behaves like the node-agnostic one.
8985
9149
  * Call {@link loadScopedSchemas} first (the async seams do).
@@ -8988,8 +9152,7 @@ var BaseAddon = class {
8988
9152
  const cacheKey = cap ?? "";
8989
9153
  const cached = this._nodeKeysByCap.get(cacheKey);
8990
9154
  if (cached) return cached;
8991
- const legacy = this.globalSettingsSchema(cap);
8992
- const keys = new Set(legacy ? legacy.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
9155
+ const keys = /* @__PURE__ */ new Set();
8993
9156
  for (const { scope, schema } of this.loadedScopedSchemas(cap)) {
8994
9157
  if (scope !== "node") continue;
8995
9158
  for (const section of schema.sections) for (const key of collectValueFieldKeys(section.fields)) keys.add(key);
@@ -9207,8 +9370,6 @@ var BaseAddon = class {
9207
9370
  }
9208
9371
  declaredKeySet() {
9209
9372
  const keys = new Set(Object.keys(this.defaults));
9210
- const schema = this.globalSettingsSchema();
9211
- if (schema) for (const section of schema.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
9212
9373
  for (const { schema: scoped } of this.loadedScopedSchemas()) for (const section of scoped.sections) for (const key of collectFieldKeys(section.fields)) keys.add(key);
9213
9374
  for (const key of this._declaredStateKeys) keys.add(key);
9214
9375
  for (const path of this.secretStatePaths) {
@@ -9306,7 +9467,7 @@ var BaseAddon = class {
9306
9467
  /** The addon store's secret tree: schema fields by TYPE, plus `secretStatePaths`. */
9307
9468
  addonSecretTree() {
9308
9469
  if (this._addonSecretTree === null) {
9309
- const tree = new Map(secretTreeFromSchema(this.globalSettingsSchema()));
9470
+ const tree = /* @__PURE__ */ new Map();
9310
9471
  for (const { schema } of this.loadedScopedSchemas()) for (const [key, node] of secretTreeFromSchema(schema)) tree.set(key, node);
9311
9472
  this._addonSecretTree = mergeSecretStatePaths(tree, this.secretStatePaths);
9312
9473
  }
@@ -9518,47 +9679,6 @@ function classifyStoreError(err) {
9518
9679
  if (TRANSPORT_PHRASES.some((f) => message.includes(f))) return "transport";
9519
9680
  return "permanent";
9520
9681
  }
9521
- /**
9522
- * Collect the keys of every field marked `perNode: true`, recursing into
9523
- * layout containers (`group` fields and `sub-tabs` tabs) the same way
9524
- * `hydrateSchema` does. Valueless structural fields (separator/info/…)
9525
- * don't declare `perNode` and are excluded by the `in` narrowing.
9526
- */
9527
- /**
9528
- * The same fields with every `perNode: true` one removed, recursing into layout
9529
- * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
9530
- * with no child is dropped rather than rendered empty.
9531
- *
9532
- * Used by `getIntegrationSettings`: an integration is not a node, so a field
9533
- * whose store key is `<key>@<nodeId>` has no node to belong to there.
9534
- */
9535
- function dropPerNodeFields(fields) {
9536
- const kept = [];
9537
- for (const field of fields) {
9538
- if (field.type === "group") {
9539
- const inner = dropPerNodeFields(field.fields);
9540
- if (inner.length > 0) kept.push({
9541
- ...field,
9542
- fields: inner
9543
- });
9544
- continue;
9545
- }
9546
- if (field.type === "sub-tabs") {
9547
- const tabs = field.tabs.map((tab) => ({
9548
- ...tab,
9549
- fields: dropPerNodeFields(tab.fields)
9550
- })).filter((tab) => tab.fields.length > 0);
9551
- if (tabs.length > 0) kept.push({
9552
- ...field,
9553
- tabs
9554
- });
9555
- continue;
9556
- }
9557
- if ("perNode" in field && field.perNode === true) continue;
9558
- kept.push(field);
9559
- }
9560
- return kept;
9561
- }
9562
9682
  /** The keys of the value-holding fields, recursing into layout containers. */
9563
9683
  function collectValueFieldKeys(fields) {
9564
9684
  const collected = [];
@@ -9591,21 +9711,6 @@ function collectFieldKeys(fields) {
9591
9711
  }
9592
9712
  return collected;
9593
9713
  }
9594
- function collectPerNodeFieldKeys(fields) {
9595
- const collected = [];
9596
- for (const field of fields) {
9597
- if (field.type === "group") {
9598
- collected.push(...collectPerNodeFieldKeys(field.fields));
9599
- continue;
9600
- }
9601
- if (field.type === "sub-tabs") {
9602
- for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
9603
- continue;
9604
- }
9605
- if ("perNode" in field && field.perNode === true) collected.push(field.key);
9606
- }
9607
- return collected;
9608
- }
9609
9714
  /**
9610
9715
  * Normalize an `ICamstackAddon.initialize()` return value into the
9611
9716
  * `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
@@ -12428,13 +12533,25 @@ Object.freeze({
12428
12533
  "path": "temperature",
12429
12534
  "valueType": "number"
12430
12535
  }],
12431
- "timed-run": [{
12432
- "path": "activeUntil",
12433
- "valueType": "number"
12434
- }, {
12435
- "path": "requestedBy",
12436
- "valueType": "string"
12437
- }],
12536
+ "timed-run": [
12537
+ {
12538
+ "path": "activeUntil",
12539
+ "valueType": "number"
12540
+ },
12541
+ {
12542
+ "path": "requestedBy",
12543
+ "valueType": "string"
12544
+ },
12545
+ {
12546
+ "path": "quickRun.duration",
12547
+ "valueType": "number"
12548
+ },
12549
+ {
12550
+ "path": "quickRun.unit",
12551
+ "valueType": "enum",
12552
+ "enumValues": ["s", "min"]
12553
+ }
12554
+ ],
12438
12555
  "update": [
12439
12556
  {
12440
12557
  "path": "currentVersion",
@@ -12658,7 +12775,7 @@ object({
12658
12775
  params: record(string(), union([string(), number()])).optional()
12659
12776
  });
12660
12777
  //#endregion
12661
- //#region ../types/dist/composition-BmBHuDTQ.mjs
12778
+ //#region ../types/dist/composition-Bx0JvKUU.mjs
12662
12779
  var AUDIO_ENCODER_BY_CODEC = {
12663
12780
  opus: "libopus",
12664
12781
  aac: "aac",
@@ -14416,6 +14533,387 @@ var NodeColorIdSchema = _enum([
14416
14533
  "node-h"
14417
14534
  ]);
14418
14535
  //#endregion
14536
+ //#region ../types/dist/convert-BAzH15HU.mjs
14537
+ /**
14538
+ * Frozen unit → spec table. `•` in the doc marks each dimension's canonical
14539
+ * unit (`factor: 1, offset: 0`). °F derives from `°C = (°F − 32) × 5/9` ⇒
14540
+ * `factor = 5/9`, `offset = -160/9` (kept as exact expressions, not rounded
14541
+ * decimals). K derives from `°C = K − 273.15`.
14542
+ */
14543
+ var UNIT_TABLE = {
14544
+ "°C": {
14545
+ dimension: "temperature",
14546
+ factor: 1,
14547
+ offset: 0
14548
+ },
14549
+ "°F": {
14550
+ dimension: "temperature",
14551
+ factor: 5 / 9,
14552
+ offset: -160 / 9
14553
+ },
14554
+ K: {
14555
+ dimension: "temperature",
14556
+ factor: 1,
14557
+ offset: -273.15
14558
+ },
14559
+ hPa: {
14560
+ dimension: "pressure",
14561
+ factor: 1,
14562
+ offset: 0
14563
+ },
14564
+ kPa: {
14565
+ dimension: "pressure",
14566
+ factor: 10,
14567
+ offset: 0
14568
+ },
14569
+ Pa: {
14570
+ dimension: "pressure",
14571
+ factor: .01,
14572
+ offset: 0
14573
+ },
14574
+ mbar: {
14575
+ dimension: "pressure",
14576
+ factor: 1,
14577
+ offset: 0
14578
+ },
14579
+ bar: {
14580
+ dimension: "pressure",
14581
+ factor: 1e3,
14582
+ offset: 0
14583
+ },
14584
+ inHg: {
14585
+ dimension: "pressure",
14586
+ factor: 33.8639,
14587
+ offset: 0
14588
+ },
14589
+ mmHg: {
14590
+ dimension: "pressure",
14591
+ factor: 1.33322,
14592
+ offset: 0
14593
+ },
14594
+ psi: {
14595
+ dimension: "pressure",
14596
+ factor: 68.9476,
14597
+ offset: 0
14598
+ },
14599
+ "m/s": {
14600
+ dimension: "speed",
14601
+ factor: 1,
14602
+ offset: 0
14603
+ },
14604
+ "km/h": {
14605
+ dimension: "speed",
14606
+ factor: 1 / 3.6,
14607
+ offset: 0
14608
+ },
14609
+ mph: {
14610
+ dimension: "speed",
14611
+ factor: .44704,
14612
+ offset: 0
14613
+ },
14614
+ kn: {
14615
+ dimension: "speed",
14616
+ factor: .514444,
14617
+ offset: 0
14618
+ },
14619
+ "mm/h": {
14620
+ dimension: "precipitation-rate",
14621
+ factor: 1,
14622
+ offset: 0
14623
+ },
14624
+ "in/h": {
14625
+ dimension: "precipitation-rate",
14626
+ factor: 25.4,
14627
+ offset: 0
14628
+ },
14629
+ m: {
14630
+ dimension: "length",
14631
+ factor: 1,
14632
+ offset: 0
14633
+ },
14634
+ mm: {
14635
+ dimension: "length",
14636
+ factor: .001,
14637
+ offset: 0
14638
+ },
14639
+ cm: {
14640
+ dimension: "length",
14641
+ factor: .01,
14642
+ offset: 0
14643
+ },
14644
+ km: {
14645
+ dimension: "length",
14646
+ factor: 1e3,
14647
+ offset: 0
14648
+ },
14649
+ in: {
14650
+ dimension: "length",
14651
+ factor: .0254,
14652
+ offset: 0
14653
+ },
14654
+ ft: {
14655
+ dimension: "length",
14656
+ factor: .3048,
14657
+ offset: 0
14658
+ },
14659
+ mi: {
14660
+ dimension: "length",
14661
+ factor: 1609.344,
14662
+ offset: 0
14663
+ },
14664
+ "m²": {
14665
+ dimension: "area",
14666
+ factor: 1,
14667
+ offset: 0
14668
+ },
14669
+ lx: {
14670
+ dimension: "illuminance",
14671
+ factor: 1,
14672
+ offset: 0
14673
+ },
14674
+ "W/m²": {
14675
+ dimension: "irradiance",
14676
+ factor: 1,
14677
+ offset: 0
14678
+ },
14679
+ W: {
14680
+ dimension: "power",
14681
+ factor: 1,
14682
+ offset: 0
14683
+ },
14684
+ kW: {
14685
+ dimension: "power",
14686
+ factor: 1e3,
14687
+ offset: 0
14688
+ },
14689
+ VA: {
14690
+ dimension: "apparent-power",
14691
+ factor: 1,
14692
+ offset: 0
14693
+ },
14694
+ Wh: {
14695
+ dimension: "energy",
14696
+ factor: 1,
14697
+ offset: 0
14698
+ },
14699
+ kWh: {
14700
+ dimension: "energy",
14701
+ factor: 1e3,
14702
+ offset: 0
14703
+ },
14704
+ MWh: {
14705
+ dimension: "energy",
14706
+ factor: 1e6,
14707
+ offset: 0
14708
+ },
14709
+ V: {
14710
+ dimension: "voltage",
14711
+ factor: 1,
14712
+ offset: 0
14713
+ },
14714
+ mV: {
14715
+ dimension: "voltage",
14716
+ factor: .001,
14717
+ offset: 0
14718
+ },
14719
+ A: {
14720
+ dimension: "current",
14721
+ factor: 1,
14722
+ offset: 0
14723
+ },
14724
+ mA: {
14725
+ dimension: "current",
14726
+ factor: .001,
14727
+ offset: 0
14728
+ },
14729
+ ppm: {
14730
+ dimension: "concentration-volume",
14731
+ factor: 1,
14732
+ offset: 0
14733
+ },
14734
+ ppb: {
14735
+ dimension: "concentration-volume",
14736
+ factor: .001,
14737
+ offset: 0
14738
+ },
14739
+ "µg/m³": {
14740
+ dimension: "concentration-mass",
14741
+ factor: 1,
14742
+ offset: 0
14743
+ },
14744
+ "mg/m³": {
14745
+ dimension: "concentration-mass",
14746
+ factor: 1e3,
14747
+ offset: 0
14748
+ },
14749
+ kg: {
14750
+ dimension: "mass",
14751
+ factor: 1,
14752
+ offset: 0
14753
+ },
14754
+ g: {
14755
+ dimension: "mass",
14756
+ factor: .001,
14757
+ offset: 0
14758
+ },
14759
+ lb: {
14760
+ dimension: "mass",
14761
+ factor: .453592,
14762
+ offset: 0
14763
+ },
14764
+ oz: {
14765
+ dimension: "mass",
14766
+ factor: .0283495,
14767
+ offset: 0
14768
+ },
14769
+ "%": {
14770
+ dimension: "percentage",
14771
+ factor: 1,
14772
+ offset: 0
14773
+ },
14774
+ L: {
14775
+ dimension: "volume",
14776
+ factor: 1,
14777
+ offset: 0
14778
+ },
14779
+ mL: {
14780
+ dimension: "volume",
14781
+ factor: .001,
14782
+ offset: 0
14783
+ },
14784
+ gal: {
14785
+ dimension: "volume",
14786
+ factor: 3.785411784,
14787
+ offset: 0
14788
+ },
14789
+ s: {
14790
+ dimension: "duration",
14791
+ factor: 1,
14792
+ offset: 0
14793
+ },
14794
+ ms: {
14795
+ dimension: "duration",
14796
+ factor: .001,
14797
+ offset: 0
14798
+ },
14799
+ min: {
14800
+ dimension: "duration",
14801
+ factor: 60,
14802
+ offset: 0
14803
+ },
14804
+ h: {
14805
+ dimension: "duration",
14806
+ factor: 3600,
14807
+ offset: 0
14808
+ },
14809
+ d: {
14810
+ dimension: "duration",
14811
+ factor: 86400,
14812
+ offset: 0
14813
+ },
14814
+ B: {
14815
+ dimension: "information",
14816
+ factor: 1,
14817
+ offset: 0
14818
+ },
14819
+ KiB: {
14820
+ dimension: "information",
14821
+ factor: 1024,
14822
+ offset: 0
14823
+ },
14824
+ MiB: {
14825
+ dimension: "information",
14826
+ factor: 1024 ** 2,
14827
+ offset: 0
14828
+ },
14829
+ GiB: {
14830
+ dimension: "information",
14831
+ factor: 1024 ** 3,
14832
+ offset: 0
14833
+ },
14834
+ TiB: {
14835
+ dimension: "information",
14836
+ factor: 1024 ** 4,
14837
+ offset: 0
14838
+ },
14839
+ kB: {
14840
+ dimension: "information",
14841
+ factor: 1e3,
14842
+ offset: 0
14843
+ },
14844
+ MB: {
14845
+ dimension: "information",
14846
+ factor: 1e6,
14847
+ offset: 0
14848
+ },
14849
+ GB: {
14850
+ dimension: "information",
14851
+ factor: 1e9,
14852
+ offset: 0
14853
+ },
14854
+ "°": {
14855
+ dimension: "angle",
14856
+ factor: 1,
14857
+ offset: 0
14858
+ },
14859
+ dBFS: {
14860
+ dimension: "sound-level",
14861
+ factor: 1,
14862
+ offset: 0
14863
+ },
14864
+ dBm: {
14865
+ dimension: "signal-level",
14866
+ factor: 1,
14867
+ offset: 0
14868
+ },
14869
+ mired: {
14870
+ dimension: "colour-temperature",
14871
+ factor: 1,
14872
+ offset: 0
14873
+ },
14874
+ kbps: {
14875
+ dimension: "bitrate",
14876
+ factor: 1,
14877
+ offset: 0
14878
+ },
14879
+ Mbps: {
14880
+ dimension: "bitrate",
14881
+ factor: 1e3,
14882
+ offset: 0
14883
+ },
14884
+ fps: {
14885
+ dimension: "rate",
14886
+ factor: 1,
14887
+ offset: 0
14888
+ }
14889
+ };
14890
+ /** Resolve a unit's `UnitSpec`, or `undefined` when the spelling is unknown. */
14891
+ function specFor(unit) {
14892
+ return Object.hasOwn(UNIT_TABLE, unit) ? UNIT_TABLE[unit] : void 0;
14893
+ }
14894
+ /** Value in `spec`'s unit → its dimension's canonical unit. */
14895
+ function toCanonical(value, spec) {
14896
+ return value * spec.factor + spec.offset;
14897
+ }
14898
+ /** Canonical-unit value → the unit described by `spec`. */
14899
+ function fromCanonical(canonical, spec) {
14900
+ return (canonical - spec.offset) / spec.factor;
14901
+ }
14902
+ /**
14903
+ * Graceful variant for the render path: returns the converted value, or
14904
+ * `undefined` when the conversion is refused (unknown unit / cross-dimension).
14905
+ * Never throws — a render caller falls back to the raw value + source unit.
14906
+ */
14907
+ function tryConvertUnit(value, from, to) {
14908
+ if (from === to) return value;
14909
+ const fromSpec = specFor(from);
14910
+ if (!fromSpec) return void 0;
14911
+ const toSpec = specFor(to);
14912
+ if (!toSpec) return void 0;
14913
+ if (fromSpec.dimension !== toSpec.dimension) return void 0;
14914
+ return fromCanonical(toCanonical(value, fromSpec), toSpec);
14915
+ }
14916
+ //#endregion
14419
14917
  //#region ../types/dist/index.mjs
14420
14918
  var SMTP_INBOUND_DEFAULT_PORT = 2525;
14421
14919
  var SMTP_INBOUND_DEFAULT_DOMAIN = "camstack.local";
@@ -43514,6 +44012,7 @@ var ExpressionBindingSourceSchema = union([
43514
44012
  object({
43515
44013
  kind: literal("global"),
43516
44014
  sourceStableId: string(),
44015
+ addonId: string().optional(),
43517
44016
  cap: string(),
43518
44017
  fieldPath: string()
43519
44018
  })
@@ -43580,385 +44079,6 @@ var SourceInfoSchema = object({
43580
44079
  raw: record(string(), unknown()).optional()
43581
44080
  });
43582
44081
  /**
43583
- * Frozen unit → spec table. `•` in the doc marks each dimension's canonical
43584
- * unit (`factor: 1, offset: 0`). °F derives from `°C = (°F − 32) × 5/9` ⇒
43585
- * `factor = 5/9`, `offset = -160/9` (kept as exact expressions, not rounded
43586
- * decimals). K derives from `°C = K − 273.15`.
43587
- */
43588
- var UNIT_TABLE = {
43589
- "°C": {
43590
- dimension: "temperature",
43591
- factor: 1,
43592
- offset: 0
43593
- },
43594
- "°F": {
43595
- dimension: "temperature",
43596
- factor: 5 / 9,
43597
- offset: -160 / 9
43598
- },
43599
- K: {
43600
- dimension: "temperature",
43601
- factor: 1,
43602
- offset: -273.15
43603
- },
43604
- hPa: {
43605
- dimension: "pressure",
43606
- factor: 1,
43607
- offset: 0
43608
- },
43609
- kPa: {
43610
- dimension: "pressure",
43611
- factor: 10,
43612
- offset: 0
43613
- },
43614
- Pa: {
43615
- dimension: "pressure",
43616
- factor: .01,
43617
- offset: 0
43618
- },
43619
- mbar: {
43620
- dimension: "pressure",
43621
- factor: 1,
43622
- offset: 0
43623
- },
43624
- bar: {
43625
- dimension: "pressure",
43626
- factor: 1e3,
43627
- offset: 0
43628
- },
43629
- inHg: {
43630
- dimension: "pressure",
43631
- factor: 33.8639,
43632
- offset: 0
43633
- },
43634
- mmHg: {
43635
- dimension: "pressure",
43636
- factor: 1.33322,
43637
- offset: 0
43638
- },
43639
- psi: {
43640
- dimension: "pressure",
43641
- factor: 68.9476,
43642
- offset: 0
43643
- },
43644
- "m/s": {
43645
- dimension: "speed",
43646
- factor: 1,
43647
- offset: 0
43648
- },
43649
- "km/h": {
43650
- dimension: "speed",
43651
- factor: 1 / 3.6,
43652
- offset: 0
43653
- },
43654
- mph: {
43655
- dimension: "speed",
43656
- factor: .44704,
43657
- offset: 0
43658
- },
43659
- kn: {
43660
- dimension: "speed",
43661
- factor: .514444,
43662
- offset: 0
43663
- },
43664
- "mm/h": {
43665
- dimension: "precipitation-rate",
43666
- factor: 1,
43667
- offset: 0
43668
- },
43669
- "in/h": {
43670
- dimension: "precipitation-rate",
43671
- factor: 25.4,
43672
- offset: 0
43673
- },
43674
- m: {
43675
- dimension: "length",
43676
- factor: 1,
43677
- offset: 0
43678
- },
43679
- mm: {
43680
- dimension: "length",
43681
- factor: .001,
43682
- offset: 0
43683
- },
43684
- cm: {
43685
- dimension: "length",
43686
- factor: .01,
43687
- offset: 0
43688
- },
43689
- km: {
43690
- dimension: "length",
43691
- factor: 1e3,
43692
- offset: 0
43693
- },
43694
- in: {
43695
- dimension: "length",
43696
- factor: .0254,
43697
- offset: 0
43698
- },
43699
- ft: {
43700
- dimension: "length",
43701
- factor: .3048,
43702
- offset: 0
43703
- },
43704
- mi: {
43705
- dimension: "length",
43706
- factor: 1609.344,
43707
- offset: 0
43708
- },
43709
- "m²": {
43710
- dimension: "area",
43711
- factor: 1,
43712
- offset: 0
43713
- },
43714
- lx: {
43715
- dimension: "illuminance",
43716
- factor: 1,
43717
- offset: 0
43718
- },
43719
- "W/m²": {
43720
- dimension: "irradiance",
43721
- factor: 1,
43722
- offset: 0
43723
- },
43724
- W: {
43725
- dimension: "power",
43726
- factor: 1,
43727
- offset: 0
43728
- },
43729
- kW: {
43730
- dimension: "power",
43731
- factor: 1e3,
43732
- offset: 0
43733
- },
43734
- VA: {
43735
- dimension: "apparent-power",
43736
- factor: 1,
43737
- offset: 0
43738
- },
43739
- Wh: {
43740
- dimension: "energy",
43741
- factor: 1,
43742
- offset: 0
43743
- },
43744
- kWh: {
43745
- dimension: "energy",
43746
- factor: 1e3,
43747
- offset: 0
43748
- },
43749
- MWh: {
43750
- dimension: "energy",
43751
- factor: 1e6,
43752
- offset: 0
43753
- },
43754
- V: {
43755
- dimension: "voltage",
43756
- factor: 1,
43757
- offset: 0
43758
- },
43759
- mV: {
43760
- dimension: "voltage",
43761
- factor: .001,
43762
- offset: 0
43763
- },
43764
- A: {
43765
- dimension: "current",
43766
- factor: 1,
43767
- offset: 0
43768
- },
43769
- mA: {
43770
- dimension: "current",
43771
- factor: .001,
43772
- offset: 0
43773
- },
43774
- ppm: {
43775
- dimension: "concentration-volume",
43776
- factor: 1,
43777
- offset: 0
43778
- },
43779
- ppb: {
43780
- dimension: "concentration-volume",
43781
- factor: .001,
43782
- offset: 0
43783
- },
43784
- "µg/m³": {
43785
- dimension: "concentration-mass",
43786
- factor: 1,
43787
- offset: 0
43788
- },
43789
- "mg/m³": {
43790
- dimension: "concentration-mass",
43791
- factor: 1e3,
43792
- offset: 0
43793
- },
43794
- kg: {
43795
- dimension: "mass",
43796
- factor: 1,
43797
- offset: 0
43798
- },
43799
- g: {
43800
- dimension: "mass",
43801
- factor: .001,
43802
- offset: 0
43803
- },
43804
- lb: {
43805
- dimension: "mass",
43806
- factor: .453592,
43807
- offset: 0
43808
- },
43809
- oz: {
43810
- dimension: "mass",
43811
- factor: .0283495,
43812
- offset: 0
43813
- },
43814
- "%": {
43815
- dimension: "percentage",
43816
- factor: 1,
43817
- offset: 0
43818
- },
43819
- L: {
43820
- dimension: "volume",
43821
- factor: 1,
43822
- offset: 0
43823
- },
43824
- mL: {
43825
- dimension: "volume",
43826
- factor: .001,
43827
- offset: 0
43828
- },
43829
- gal: {
43830
- dimension: "volume",
43831
- factor: 3.785411784,
43832
- offset: 0
43833
- },
43834
- s: {
43835
- dimension: "duration",
43836
- factor: 1,
43837
- offset: 0
43838
- },
43839
- ms: {
43840
- dimension: "duration",
43841
- factor: .001,
43842
- offset: 0
43843
- },
43844
- min: {
43845
- dimension: "duration",
43846
- factor: 60,
43847
- offset: 0
43848
- },
43849
- h: {
43850
- dimension: "duration",
43851
- factor: 3600,
43852
- offset: 0
43853
- },
43854
- d: {
43855
- dimension: "duration",
43856
- factor: 86400,
43857
- offset: 0
43858
- },
43859
- B: {
43860
- dimension: "information",
43861
- factor: 1,
43862
- offset: 0
43863
- },
43864
- KiB: {
43865
- dimension: "information",
43866
- factor: 1024,
43867
- offset: 0
43868
- },
43869
- MiB: {
43870
- dimension: "information",
43871
- factor: 1024 ** 2,
43872
- offset: 0
43873
- },
43874
- GiB: {
43875
- dimension: "information",
43876
- factor: 1024 ** 3,
43877
- offset: 0
43878
- },
43879
- TiB: {
43880
- dimension: "information",
43881
- factor: 1024 ** 4,
43882
- offset: 0
43883
- },
43884
- kB: {
43885
- dimension: "information",
43886
- factor: 1e3,
43887
- offset: 0
43888
- },
43889
- MB: {
43890
- dimension: "information",
43891
- factor: 1e6,
43892
- offset: 0
43893
- },
43894
- GB: {
43895
- dimension: "information",
43896
- factor: 1e9,
43897
- offset: 0
43898
- },
43899
- "°": {
43900
- dimension: "angle",
43901
- factor: 1,
43902
- offset: 0
43903
- },
43904
- dBFS: {
43905
- dimension: "sound-level",
43906
- factor: 1,
43907
- offset: 0
43908
- },
43909
- dBm: {
43910
- dimension: "signal-level",
43911
- factor: 1,
43912
- offset: 0
43913
- },
43914
- mired: {
43915
- dimension: "colour-temperature",
43916
- factor: 1,
43917
- offset: 0
43918
- },
43919
- kbps: {
43920
- dimension: "bitrate",
43921
- factor: 1,
43922
- offset: 0
43923
- },
43924
- Mbps: {
43925
- dimension: "bitrate",
43926
- factor: 1e3,
43927
- offset: 0
43928
- },
43929
- fps: {
43930
- dimension: "rate",
43931
- factor: 1,
43932
- offset: 0
43933
- }
43934
- };
43935
- /** Resolve a unit's `UnitSpec`, or `undefined` when the spelling is unknown. */
43936
- function specFor(unit) {
43937
- return Object.hasOwn(UNIT_TABLE, unit) ? UNIT_TABLE[unit] : void 0;
43938
- }
43939
- /** Value in `spec`'s unit → its dimension's canonical unit. */
43940
- function toCanonical(value, spec) {
43941
- return value * spec.factor + spec.offset;
43942
- }
43943
- /** Canonical-unit value → the unit described by `spec`. */
43944
- function fromCanonical(canonical, spec) {
43945
- return (canonical - spec.offset) / spec.factor;
43946
- }
43947
- /**
43948
- * Graceful variant for the render path: returns the converted value, or
43949
- * `undefined` when the conversion is refused (unknown unit / cross-dimension).
43950
- * Never throws — a render caller falls back to the raw value + source unit.
43951
- */
43952
- function tryConvertUnit(value, from, to) {
43953
- if (from === to) return value;
43954
- const fromSpec = specFor(from);
43955
- if (!fromSpec) return void 0;
43956
- const toSpec = specFor(to);
43957
- if (!toSpec) return void 0;
43958
- if (fromSpec.dimension !== toSpec.dimension) return void 0;
43959
- return fromCanonical(toCanonical(value, fromSpec), toSpec);
43960
- }
43961
- /**
43962
44082
  * A number a person types for a physical quantity — the input side of the
43963
44083
  * value + unit contract (D972).
43964
44084
  *
@@ -45718,15 +45838,28 @@ var SettingsSchemaWithValuesSchema = object({
45718
45838
  });
45719
45839
  /** Patch object — keys are field names, values are the new field values. */
45720
45840
  var SettingsPatchSchema = record(string(), unknown());
45841
+ /** The scope of a scoped-settings call (D986): where the capability declared the values. */
45842
+ var ScopedSettingsScopeSchema = _enum(SCOPED_SETTINGS_SCOPES);
45843
+ /** One scoped schema an addon serves: its capability, scope and section ids. */
45844
+ var ScopedSettingsDeclarationSchema = object({
45845
+ cap: string(),
45846
+ scope: ScopedSettingsScopeSchema,
45847
+ sectionIds: array(string())
45848
+ });
45721
45849
  /** Standard success response for update operations. */
45722
45850
  var SettingsUpdateResultSchema = object({ success: literal(true) });
45723
45851
  method(object({
45724
45852
  addonId: string(),
45725
- nodeId: string().optional(),
45726
- overlay: record(string(), unknown()).optional(),
45727
- cap: string().optional()
45853
+ cap: string(),
45854
+ scope: ScopedSettingsScopeSchema,
45855
+ nodeId: string().optional()
45728
45856
  }), SettingsSchemaWithValuesSchema.nullable()), method(object({
45729
45857
  addonId: string(),
45858
+ nodeId: string().optional()
45859
+ }), array(ScopedSettingsDeclarationSchema).nullable()), method(object({
45860
+ addonId: string(),
45861
+ cap: string(),
45862
+ scope: ScopedSettingsScopeSchema,
45730
45863
  nodeId: string().optional(),
45731
45864
  patch: SettingsPatchSchema
45732
45865
  }), SettingsUpdateResultSchema, {
@@ -45734,8 +45867,10 @@ method(object({
45734
45867
  auth: "admin"
45735
45868
  }), method(object({
45736
45869
  addonId: string(),
45870
+ cap: string(),
45871
+ scope: ScopedSettingsScopeSchema,
45737
45872
  nodeId: string().optional()
45738
- }), SettingsSchemaWithValuesSchema.nullable()), method(object({
45873
+ }), record(string(), unknown()).nullable()), method(object({
45739
45874
  addonId: string(),
45740
45875
  nodeId: string().optional(),
45741
45876
  instance: IntegrationInstanceRefSchema
@@ -47079,7 +47214,7 @@ var BackupDestinationInfoSchema = object({
47079
47214
  id: string(),
47080
47215
  /**
47081
47216
  * Manifest id of the owning addon. The Settings button on the
47082
- * destination card opens that addon's `globalSettingsSchema` panel.
47217
+ * destination card opens that addon's scoped settings panel.
47083
47218
  */
47084
47219
  addonId: string(),
47085
47220
  /** Operator-toggled enable flag from the destination-policy table. */
@@ -49666,7 +49801,7 @@ DeviceType.MediaPlayer, method(deviceOnly, _void(), {
49666
49801
  kind: "mutation",
49667
49802
  auth: "protected"
49668
49803
  });
49669
- DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.PetFeeder, DeviceType.Container, DeviceType.Thermostat, DeviceType.EventEmitter, DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Thermostat, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Heater, DeviceType.Dryer, DeviceType.Gateway, DeviceType.Camera, DeviceType.Fan, DeviceType.Lock, DeviceType.Camera, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Gateway, DeviceType.Hub, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer, DeviceType.WaterHeater, DeviceType.Humidifier, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.PetFeeder, DeviceType.Heater;
49804
+ DeviceType.Camera, DeviceType.Sensor, DeviceType.Button, DeviceType.Switch, DeviceType.PetFeeder, DeviceType.Container, DeviceType.Thermostat, DeviceType.EventEmitter, DeviceType.Camera, DeviceType.Hub, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Thermostat, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Heater, DeviceType.Dryer, DeviceType.Gateway, DeviceType.Camera, DeviceType.Fan, DeviceType.Lock, DeviceType.Camera, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Switch, DeviceType.Light, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.Gateway, DeviceType.Hub, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater, DeviceType.MediaPlayer, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.MediaPlayer, DeviceType.WaterHeater, DeviceType.Humidifier, DeviceType.Fan, DeviceType.Climate, DeviceType.Thermostat, DeviceType.PetFeeder, DeviceType.Heater, DeviceType.MediaPlayer;
49670
49805
  var NUMBER = {
49671
49806
  kind: "fixed",
49672
49807
  result: ["number"]
@@ -50959,7 +51094,7 @@ DeviceType.Camera, method(object({ deviceId: number() }), DayNightOptionsSchema)
50959
51094
  });
50960
51095
  /**
50961
51096
  * Stable UI option list for the `hwaccel` setting. Decoder addons
50962
- * reuse this for `globalSettingsSchema()` so the dropdown is
51097
+ * reuse this in their scoped settings form so the dropdown is
50963
51098
  * identical everywhere. Order: auto → off → common backends by
50964
51099
  * platform affinity (macOS, NVIDIA, Intel/AMD, Windows, Linux).
50965
51100
  */
@@ -51642,6 +51777,7 @@ var deviceExportCapability = {
51642
51777
  })
51643
51778
  }
51644
51779
  };
51780
+ var DeviceAliasSchema = string().max(64).regex(/^[a-z][a-z0-9_]*$/);
51645
51781
  /**
51646
51782
  * A SITE ZONE — a named part of the property that several locations belong to.
51647
51783
  *
@@ -52035,6 +52171,12 @@ var DeviceInfoSchema = object({
52035
52171
  addonId: string(),
52036
52172
  type: _enum(DeviceType),
52037
52173
  name: string(),
52174
+ /** The name a value template uses for this device (`{{ stufa_veranda.temperature }}`),
52175
+ * entity_id style. Generated once from the name at first registration, unique
52176
+ * cluster-wide, editable through `setAlias`, NOT changed by a rename (D1021).
52177
+ * Optional: a record produced by an older build omits it until the boot
52178
+ * backfill has run. */
52179
+ alias: DeviceAliasSchema.optional(),
52038
52180
  /** Operator-organisational location label. `null` when unset. */
52039
52181
  location: string().nullable(),
52040
52182
  /** Soft-disabled flag. */
@@ -52354,6 +52496,25 @@ method(object({
52354
52496
  }), _void(), {
52355
52497
  kind: "mutation",
52356
52498
  auth: "admin"
52499
+ }), method(object({
52500
+ deviceId: number(),
52501
+ alias: string()
52502
+ }), discriminatedUnion("ok", [object({
52503
+ ok: literal(true),
52504
+ alias: DeviceAliasSchema
52505
+ }), object({
52506
+ ok: literal(false),
52507
+ reason: _enum([
52508
+ "empty",
52509
+ "too-long",
52510
+ "grammar",
52511
+ "reserved",
52512
+ "taken"
52513
+ ]),
52514
+ takenBy: number().optional()
52515
+ })]), {
52516
+ kind: "mutation",
52517
+ auth: "admin"
52357
52518
  }), method(object({
52358
52519
  deviceId: number(),
52359
52520
  location: string().nullable()
@@ -55491,10 +55652,11 @@ var IntegrationInstanceDescriptionSchema = object({
55491
55652
  /** True when `testInstance` really probes the remote. */
55492
55653
  canTest: boolean(),
55493
55654
  /**
55494
- * The kinds an instance can be of. Absent or one entry: nothing to choose; more than one: the
55495
- * Add flow asks which first and sends it as `createInstance.kind`.
55655
+ * The kinds an instance can be of (D1013 rule 1), each naming its `functionCap`. One entry:
55656
+ * nothing to choose; more than one: the Add flow asks which first and sends it as
55657
+ * `createInstance.kind`. Never empty: every instance belongs to exactly one kind.
55496
55658
  */
55497
- kinds: array(IntegrationInstanceKindSchema).optional(),
55659
+ kinds: array(IntegrationInstanceKindSchema).min(1),
55498
55660
  /**
55499
55661
  * The provider accepts `createInstance.id` for an id that once existed (an adopted id, because
55500
55662
  * devices carry it). The UI then offers "restore under its old id" on Add. Absent means no.
@@ -55530,8 +55692,8 @@ var IntegrationInstanceSchema = object({
55530
55692
  * the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
55531
55693
  */
55532
55694
  enabled: boolean().optional(),
55533
- /** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
55534
- kind: string().optional(),
55695
+ /** The kind of this instance: exactly one of `describe().kinds[].id` (D1013 rule 2). */
55696
+ kind: string().min(1),
55535
55697
  /** Values for the instance form; a secret is a `SecretFieldView`, never text. */
55536
55698
  formValues: record(string(), unknown()),
55537
55699
  status: IntegrationInstanceStatusSchema.optional(),
@@ -65101,6 +65263,11 @@ var NcScheduleSchema = object({
65101
65263
  * as a STATE SUMMARY at the end of each window of `schedule`.
65102
65264
  */
65103
65265
  var NcSystemEventDeliveryModeSchema = _enum(["instant", "summary"]);
65266
+ _enum([
65267
+ "activation",
65268
+ "deactivation",
65269
+ "schedule"
65270
+ ]);
65104
65271
  /**
65105
65272
  * How a summary window is SENT (D698): `rule` (absent) = ONE notification with
65106
65273
  * every section; `section` = one notification per section with something to
@@ -65117,11 +65284,26 @@ var NcStateSummarySplitSchema = _enum(["rule", "section"]);
65117
65284
  * midnight crossing); the send time is each window's END. Refused on the
65118
65285
  * `alarm` family, which stays instant (`systemEventDeliveryProblems`).
65119
65286
  */
65120
- var NcSystemEventDeliverySchema = discriminatedUnion("mode", [object({ mode: literal("instant") }), object({
65121
- mode: literal("summary"),
65122
- schedule: NcScheduleSchema,
65123
- split: NcStateSummarySplitSchema.optional()
65124
- })]);
65287
+ var NcSystemEventDeliverySchema = discriminatedUnion("mode", [
65288
+ object({ mode: literal("instant") }),
65289
+ object({
65290
+ mode: literal("summary"),
65291
+ schedule: NcScheduleSchema,
65292
+ split: NcStateSummarySplitSchema.optional()
65293
+ }),
65294
+ object({
65295
+ mode: literal("modes"),
65296
+ /** The bad edge, and every kind that has a single edge. */
65297
+ onActivation: boolean(),
65298
+ /** The recovery edges of the classes of the selected kinds (derived, never stored per kind). */
65299
+ onDeactivation: boolean(),
65300
+ /** A state summary at the end of each window; absent = no summary. */
65301
+ onSchedule: object({
65302
+ schedule: NcScheduleSchema,
65303
+ grouping: NcStateSummarySplitSchema
65304
+ }).optional()
65305
+ })
65306
+ ]);
65125
65307
  /** Fuzzy plate matcher — OCR noise makes exact match useless (spec row 12/13). */
65126
65308
  var NcPlateMatcherSchema = object({
65127
65309
  /**
@@ -72641,6 +72823,7 @@ var RemoteLayoutComponentSchema = object({
72641
72823
  });
72642
72824
  });
72643
72825
  method(object({}), array(RemoteLayoutComponentSchema), { auth: "protected" });
72826
+ DeviceType.MediaPlayer;
72644
72827
  var RunningStateSourceSchema = _enum(["native", "assigned"]);
72645
72828
  object({
72646
72829
  /** null = unknown — never coerced to false (D393). */
@@ -75076,7 +75259,7 @@ var TerminalInstanceInfoSchema = object({
75076
75259
  /**
75077
75260
  * False while the node the instance is bound to is not in the cluster
75078
75261
  * topology (forgotten, renamed, re-paired). The instance is kept; the
75079
- * operator re-points it with `updateInstance({ targetNodeId })`.
75262
+ * operator re-points it on the Terminal page.
75080
75263
  */
75081
75264
  nodeInCluster: boolean(),
75082
75265
  profileId: string(),
@@ -75114,41 +75297,7 @@ var TerminalOutputBatchSchema = object({
75114
75297
  snapshot: string().optional(),
75115
75298
  events: array(TerminalOutputEventSchema).readonly()
75116
75299
  });
75117
- method(_void(), array(TerminalProfileInfoSchema).readonly(), { auth: "admin" }), method(_void(), array(TerminalInstanceInfoSchema).readonly(), { auth: "admin" }), method(object({
75118
- targetNodeId: string().min(1),
75119
- profileId: string().min(1),
75120
- name: string().trim().min(1).max(160).optional(),
75121
- executable: string().max(1024).optional(),
75122
- args: array(string().max(2048)).max(64).optional(),
75123
- cwd: string().max(1024).optional(),
75124
- environment: array(string().max(4096)).max(64).optional(),
75125
- profileSettings: ProfileSettingsBagSchema.optional()
75126
- }), TerminalInstanceInfoSchema, {
75127
- kind: "mutation",
75128
- auth: "admin"
75129
- }), method(object({
75130
- instanceId: string().min(1),
75131
- /** Re-point the instance to another node; the profile must exist there. */
75132
- targetNodeId: string().min(1).max(256).optional(),
75133
- name: string().trim().min(1).max(160).optional(),
75134
- executable: string().max(1024).optional(),
75135
- args: array(string().max(2048)).max(64).optional(),
75136
- cwd: string().max(1024).optional(),
75137
- environment: array(string().max(4096)).max(64).optional(),
75138
- profileSettings: ProfileSettingsBagSchema.optional()
75139
- }), TerminalInstanceInfoSchema, {
75140
- kind: "mutation",
75141
- auth: "admin"
75142
- }), method(object({ instanceId: string().min(1) }), _void(), {
75143
- kind: "mutation",
75144
- auth: "admin"
75145
- }), method(object({
75146
- instanceId: string().min(1),
75147
- enabled: boolean()
75148
- }), TerminalInstanceInfoSchema, {
75149
- kind: "mutation",
75150
- auth: "admin"
75151
- }), method(_void(), array(TerminalLegacyCameraSchema).readonly(), { auth: "admin" }), method(object({
75300
+ method(_void(), array(TerminalProfileInfoSchema).readonly(), { auth: "admin" }), method(_void(), array(TerminalLegacyCameraSchema).readonly(), { auth: "admin" }), method(object({
75152
75301
  stableId: string().min(1),
75153
75302
  name: string().trim().min(1).max(160).optional()
75154
75303
  }), TerminalInstanceInfoSchema, {
@@ -75217,6 +75366,11 @@ var TimedRunUnitSchema = _enum(["s", "min"]);
75217
75366
  _enum(["switch", "pet-fountain"]);
75218
75367
  DeviceType.Heater, DeviceType.PetFountain;
75219
75368
  DeviceType.Heater, DeviceType.PetFountain;
75369
+ /** One duration, as the one-tap run asks for it. */
75370
+ var TimedRunQuickRunSchema = object({
75371
+ duration: number().positive().finite(),
75372
+ unit: TimedRunUnitSchema
75373
+ });
75220
75374
  /** Why a request was not carried out. Typed, so a caller can say it in words. */
75221
75375
  var TimedRunRefusalSchema = _enum([
75222
75376
  "unsupported-device",
@@ -75237,9 +75391,30 @@ object({
75237
75391
  activeUntil: number().nullable(),
75238
75392
  /** Who asked for the run (a user id or an addon id); `null` when nothing is armed or it did not say. */
75239
75393
  requestedBy: string().nullable(),
75394
+ /**
75395
+ * The one-tap run of THIS device: what a "Run" button on any surface starts. `null` when
75396
+ * the device is gone or its type has no timed run; a status from before this field
75397
+ * existed has none, and a surface falls back to the type's default.
75398
+ */
75399
+ quickRun: TimedRunQuickRunSchema.nullable(),
75240
75400
  lastFetchedAt: number()
75241
75401
  });
75242
- method(object({
75402
+ /** What the settings form needs: the unit, the bounds and the type's default. */
75403
+ var TimedRunOptionsSchema = object({
75404
+ unit: TimedRunUnitSchema,
75405
+ /** The longest run, in `unit`. */
75406
+ maxDuration: number(),
75407
+ defaultDuration: number()
75408
+ });
75409
+ /** The one-tap run duration, in the type's unit; `null` returns to the type's default. */
75410
+ var TimedRunSettingsPatchSchema = object({ quickRunDuration: number().positive().finite().nullable().optional() });
75411
+ method(object({ deviceId: number().int() }), TimedRunOptionsSchema), method(object({
75412
+ deviceId: number().int(),
75413
+ settings: TimedRunSettingsPatchSchema
75414
+ }), _void(), {
75415
+ kind: "mutation",
75416
+ auth: "admin"
75417
+ }), method(object({
75243
75418
  deviceId: number().int(),
75244
75419
  duration: number().positive().finite(),
75245
75420
  unit: TimedRunUnitSchema
@@ -77945,21 +78120,28 @@ Object.freeze({
77945
78120
  access: "view",
77946
78121
  role: "admin"
77947
78122
  },
77948
- "addonSettings.getGlobalSettings": {
78123
+ "addonSettings.getIntegrationFormSchema": {
77949
78124
  capName: "addon-settings",
77950
78125
  capScope: "system",
77951
78126
  addonId: null,
77952
78127
  access: "view",
77953
78128
  role: "admin"
77954
78129
  },
77955
- "addonSettings.getIntegrationFormSchema": {
78130
+ "addonSettings.getScopedSettings": {
77956
78131
  capName: "addon-settings",
77957
78132
  capScope: "system",
77958
78133
  addonId: null,
77959
78134
  access: "view",
77960
78135
  role: "admin"
77961
78136
  },
77962
- "addonSettings.getIntegrationSettings": {
78137
+ "addonSettings.listScopedSettings": {
78138
+ capName: "addon-settings",
78139
+ capScope: "system",
78140
+ addonId: null,
78141
+ access: "view",
78142
+ role: "admin"
78143
+ },
78144
+ "addonSettings.readScopedValues": {
77963
78145
  capName: "addon-settings",
77964
78146
  capScope: "system",
77965
78147
  addonId: null,
@@ -77980,7 +78162,7 @@ Object.freeze({
77980
78162
  access: "create",
77981
78163
  role: "admin"
77982
78164
  },
77983
- "addonSettings.updateGlobalSettings": {
78165
+ "addonSettings.updateScopedSettings": {
77984
78166
  capName: "addon-settings",
77985
78167
  capScope: "system",
77986
78168
  addonId: null,
@@ -80150,6 +80332,13 @@ Object.freeze({
80150
80332
  access: "create",
80151
80333
  role: "admin"
80152
80334
  },
80335
+ "deviceManager.setAlias": {
80336
+ capName: "device-manager",
80337
+ capScope: "system",
80338
+ addonId: null,
80339
+ access: "create",
80340
+ role: "admin"
80341
+ },
80153
80342
  "deviceManager.setChildLayout": {
80154
80343
  capName: "device-manager",
80155
80344
  capScope: "system",
@@ -86877,27 +87066,6 @@ Object.freeze({
86877
87066
  access: "create",
86878
87067
  role: "admin"
86879
87068
  },
86880
- "terminalSession.createInstance": {
86881
- capName: "terminal-session",
86882
- capScope: "system",
86883
- addonId: null,
86884
- access: "create",
86885
- role: "admin"
86886
- },
86887
- "terminalSession.deleteInstance": {
86888
- capName: "terminal-session",
86889
- capScope: "system",
86890
- addonId: null,
86891
- access: "delete",
86892
- role: "admin"
86893
- },
86894
- "terminalSession.listInstances": {
86895
- capName: "terminal-session",
86896
- capScope: "system",
86897
- addonId: null,
86898
- access: "view",
86899
- role: "admin"
86900
- },
86901
87069
  "terminalSession.listLegacyCameras": {
86902
87070
  capName: "terminal-session",
86903
87071
  capScope: "system",
@@ -86940,20 +87108,6 @@ Object.freeze({
86940
87108
  access: "create",
86941
87109
  role: "admin"
86942
87110
  },
86943
- "terminalSession.setInstanceEnabled": {
86944
- capName: "terminal-session",
86945
- capScope: "system",
86946
- addonId: null,
86947
- access: "create",
86948
- role: "admin"
86949
- },
86950
- "terminalSession.updateInstance": {
86951
- capName: "terminal-session",
86952
- capScope: "system",
86953
- addonId: null,
86954
- access: "create",
86955
- role: "admin"
86956
- },
86957
87111
  "terminalSession.writeInput": {
86958
87112
  capName: "terminal-session",
86959
87113
  capScope: "system",
@@ -86968,6 +87122,13 @@ Object.freeze({
86968
87122
  access: "create",
86969
87123
  role: "viewer"
86970
87124
  },
87125
+ "timedRun.getOptions": {
87126
+ capName: "timed-run",
87127
+ capScope: "device",
87128
+ addonId: null,
87129
+ access: "view",
87130
+ role: "viewer"
87131
+ },
86971
87132
  "timedRun.getStatus": {
86972
87133
  capName: "timed-run",
86973
87134
  capScope: "device",
@@ -86982,6 +87143,13 @@ Object.freeze({
86982
87143
  access: "create",
86983
87144
  role: "viewer"
86984
87145
  },
87146
+ "timedRun.setSettings": {
87147
+ capName: "timed-run",
87148
+ capScope: "device",
87149
+ addonId: null,
87150
+ access: "create",
87151
+ role: "admin"
87152
+ },
86985
87153
  "toast.onToast": {
86986
87154
  capName: "toast",
86987
87155
  capScope: "system",
@@ -87937,6 +88105,7 @@ function applianceExport(ecosystem, deviceType) {
87937
88105
  if (!isPlugApplianceType(deviceType)) return null;
87938
88106
  return APPLIANCE_EXPORT[ecosystem][deviceType];
87939
88107
  }
88108
+ string().min(1).max(4096);
87940
88109
  Object.freeze({
87941
88110
  "accessories.getStatus": [{
87942
88111
  name: "deviceId",
@@ -88620,6 +88789,11 @@ Object.freeze({
88620
88789
  form: "single",
88621
88790
  optional: false
88622
88791
  }],
88792
+ "deviceManager.setAlias": [{
88793
+ name: "deviceId",
88794
+ form: "single",
88795
+ optional: false
88796
+ }],
88623
88797
  "deviceManager.setChildLayout": [{
88624
88798
  name: "deviceId",
88625
88799
  form: "single",
@@ -90684,6 +90858,11 @@ Object.freeze({
90684
90858
  form: "single",
90685
90859
  optional: false
90686
90860
  }],
90861
+ "timedRun.getOptions": [{
90862
+ name: "deviceId",
90863
+ form: "single",
90864
+ optional: false
90865
+ }],
90687
90866
  "timedRun.getStatus": [{
90688
90867
  name: "deviceId",
90689
90868
  form: "single",
@@ -90694,6 +90873,11 @@ Object.freeze({
90694
90873
  form: "single",
90695
90874
  optional: false
90696
90875
  }],
90876
+ "timedRun.setSettings": [{
90877
+ name: "deviceId",
90878
+ form: "single",
90879
+ optional: false
90880
+ }],
90697
90881
  "update.getStatus": [{
90698
90882
  name: "deviceId",
90699
90883
  form: "single",
@@ -91556,6 +91740,7 @@ var STATE_SUMMARY_VARS = [
91556
91740
  [...RULE_TEXT],
91557
91741
  [...RULE_TEXT],
91558
91742
  [...RULE_TEXT],
91743
+ [...RULE_TEXT],
91559
91744
  [...RULE_BODY_ONLY],
91560
91745
  [...RULE_TEXT],
91561
91746
  ([...RULE_TEXT], [...DEVICE_EVENTS]),
@@ -159460,10 +159645,23 @@ var HAP_STREAM_PREFERENCE_OPTIONS = [
159460
159645
  label: "Low"
159461
159646
  }
159462
159647
  ];
159648
+ /** One device's advertised HAP state, persisted in the addon store. JSON-plain
159649
+ * mirror of `ExportTargetEntry` from `@camstack/types/node`. Keyed by
159650
+ * `String(deviceId)` in the `exportSyncState` store key. `externalIds` holds
159651
+ * the deterministic accessory UUID (diagnostic; rebuild uses the live mapper). */
159652
+ var ExportTargetEntrySchema = object({
159653
+ fingerprint: string(),
159654
+ externalIds: array(string())
159655
+ });
159656
+ /** Durable per-device export sync state — the Phase-C reconciler cache, kept under the
159657
+ * addon-store key `exportSyncState` (the key the addon always used).
159658
+ * Key = `String(deviceId)`, value = the device's export fingerprint at last
159659
+ * attach. Drives `diffExportTargets`: an unchanged restart hashes to the same
159660
+ * fingerprint → no rebuild. */
159661
+ var ExportSyncStateSchema = record(string(), ExportTargetEntrySchema);
159463
159662
  var DEFAULT_CONFIG = {
159464
159663
  interfaceName: "",
159465
- clipRetentionDays: 14,
159466
- exportSyncState: {}
159664
+ clipRetentionDays: 14
159467
159665
  };
159468
159666
  var BANNED_PINCODES = new Set([
159469
159667
  "000-00-000",
@@ -159568,7 +159766,13 @@ var ExportHapAddon = class extends BaseAddon {
159568
159766
  role: "services",
159569
159767
  instanceMode: "multiple",
159570
159768
  kind: "bridge",
159571
- canTest: false
159769
+ canTest: false,
159770
+ kinds: [{
159771
+ id: "bridge",
159772
+ label: "HomeKit bridge",
159773
+ functionCap: "device-export",
159774
+ role: "services"
159775
+ }]
159572
159776
  },
159573
159777
  formSchema: (id) => this.bridgeForm(id),
159574
159778
  initialBody: (name) => ({
@@ -159782,7 +159986,7 @@ var ExportHapAddon = class extends BaseAddon {
159782
159986
  await this.stopInstance(id);
159783
159987
  for (const uuid of uuids) clearPairingFiles(uuid, this.ctx.logger);
159784
159988
  await this.exposureHandle().delete(id);
159785
- if (id === "export-hap") await this.updateGlobalSettings({ exportSyncState: {} });
159989
+ if (id === "export-hap") await this.exportSyncState.set({});
159786
159990
  this.ctx.logger.info("export-hap: bridge removed", { meta: { instanceId: id } });
159787
159991
  }
159788
159992
  /**
@@ -160154,9 +160358,11 @@ var ExportHapAddon = class extends BaseAddon {
160154
160358
  return inst.accessoryUuidOf(inst.findEntry(deviceId)?.mapperKind ?? "camera", deviceId);
160155
160359
  }
160156
160360
  /** The reconcile cache of a bridge: the default one is persisted, the others live in memory (boot re-attach seeds them). */
160157
- syncStateOf(inst) {
160158
- return inst.id === "export-hap" ? syncStateFromJson(this.config.exportSyncState) : inst.syncState;
160361
+ async syncStateOf(inst) {
160362
+ return inst.id === "export-hap" ? syncStateFromJson(await this.exportSyncState.get()) : inst.syncState;
160159
160363
  }
160364
+ /** The persisted reconcile cache of the default bridge (store key `exportSyncState`). */
160365
+ exportSyncState = this.state("exportSyncState", ExportSyncStateSchema, {});
160160
160366
  /**
160161
160367
  * Export fingerprint of a device from its PERSISTED features + type
160162
160368
  * (`canonicalDeviceFingerprint`). Returns `null` on a transient API error or
@@ -160182,7 +160388,7 @@ var ExportHapAddon = class extends BaseAddon {
160182
160388
  deviceType: device.type,
160183
160389
  features: device.features
160184
160390
  });
160185
- const persisted = this.syncStateOf(inst).get(deviceId)?.fingerprint;
160391
+ const persisted = (await this.syncStateOf(inst)).get(deviceId)?.fingerprint;
160186
160392
  const withToken = withRecordabilityToken({
160187
160393
  base: fresh,
160188
160394
  token: await this.readRecordabilityToken(inst, deviceId, device.type),
@@ -160217,22 +160423,35 @@ var ExportHapAddon = class extends BaseAddon {
160217
160423
  return null;
160218
160424
  }
160219
160425
  }
160426
+ /** Tail of the pending cache writes of each bridge: a read-modify-write of one bridge never overlaps another. */
160427
+ syncWrites = /* @__PURE__ */ new Map();
160428
+ /** Run one read-modify-write of a bridge's reconcile cache after the previous one finished. */
160429
+ serialisedSyncWrite(inst, write) {
160430
+ const next = (this.syncWrites.get(inst.id) ?? Promise.resolve()).then(write);
160431
+ this.syncWrites.set(inst.id, next.catch(() => void 0));
160432
+ return next;
160433
+ }
160220
160434
  /** Persist a device's current export fingerprint into `exportSyncState`
160221
- * (best-effort; called after a successful attach). */
160222
- async persistFingerprint(inst, deviceId, fingerprint) {
160223
- const state = this.syncStateOf(inst);
160224
- state.set(deviceId, {
160225
- fingerprint,
160226
- externalIds: [this.hapAccessoryUuid(inst, deviceId)]
160435
+ * (best-effort; called after a successful attach). Serialised per bridge, so two attaches
160436
+ * finishing together cannot each write back a cache that lacks the other's entry. */
160437
+ persistFingerprint(inst, deviceId, fingerprint) {
160438
+ return this.serialisedSyncWrite(inst, async () => {
160439
+ const state = await this.syncStateOf(inst);
160440
+ state.set(deviceId, {
160441
+ fingerprint,
160442
+ externalIds: [this.hapAccessoryUuid(inst, deviceId)]
160443
+ });
160444
+ if (inst.id === "export-hap") await this.exportSyncState.set(syncStateToJson(state));
160227
160445
  });
160228
- if (inst.id === "export-hap") await this.updateGlobalSettings({ exportSyncState: syncStateToJson(state) });
160229
160446
  }
160230
- /** Drop a device's `exportSyncState` entry (on unexpose). */
160231
- async forgetFingerprint(inst, deviceId) {
160232
- const state = this.syncStateOf(inst);
160233
- if (!state.has(deviceId)) return;
160234
- state.delete(deviceId);
160235
- if (inst.id === "export-hap") await this.updateGlobalSettings({ exportSyncState: syncStateToJson(state) });
160447
+ /** Drop a device's `exportSyncState` entry (on unexpose). Serialised with the writes above. */
160448
+ forgetFingerprint(inst, deviceId) {
160449
+ return this.serialisedSyncWrite(inst, async () => {
160450
+ const state = await this.syncStateOf(inst);
160451
+ if (!state.has(deviceId)) return;
160452
+ state.delete(deviceId);
160453
+ if (inst.id === "export-hap") await this.exportSyncState.set(syncStateToJson(state));
160454
+ });
160236
160455
  }
160237
160456
  /**
160238
160457
  * Subscribe to a device-lifecycle event category and reconcile the exposed
@@ -160320,7 +160539,7 @@ var ExportHapAddon = class extends BaseAddon {
160320
160539
  log.debug("export-hap: reconcile skipped — fingerprint unavailable (transient)");
160321
160540
  return;
160322
160541
  }
160323
- const last = this.syncStateOf(inst).get(numericId);
160542
+ const last = (await this.syncStateOf(inst)).get(numericId);
160324
160543
  if (last?.fingerprint === current) {
160325
160544
  if (!inst.exposed.has(deviceId)) try {
160326
160545
  await this.attachMapper(inst, entry);
@@ -160837,4 +161056,4 @@ function errMsg(err) {
160837
161056
  return err instanceof Error ? err.message : String(err);
160838
161057
  }
160839
161058
  //#endregion
160840
- export { DEFAULT_CLIP_RETENTION_DAYS, DEFAULT_DEVICE_SETTINGS, EXPORT_HAP_ADDON_ID, ExportHapAddon, ExportHapAddon as default, exportHapActions as a, describeHksvCamera, unpublishAccessory as i, initHapStorage as n, publishStandalone as r, resolveClipRetentionDays, resolveKeepHomekitClips, resolveMultiTierService, deriveUsername as t };
161059
+ export { DEFAULT_CLIP_RETENTION_DAYS, DEFAULT_DEVICE_SETTINGS, EXPORT_HAP_ADDON_ID, ExportHapAddon, ExportHapAddon as default, ExportSyncStateSchema, exportHapActions as a, describeHksvCamera, unpublishAccessory as i, initHapStorage as n, publishStandalone as r, resolveClipRetentionDays, resolveKeepHomekitClips, resolveMultiTierService, deriveUsername as t };