@camstack/system 1.2.313 → 1.2.315

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.
Files changed (111) hide show
  1. package/dist/addon-runner.js +1 -1
  2. package/dist/addon-runner.mjs +1 -1
  3. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  4. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  5. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  6. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  7. package/dist/builtins/alerts/alerts.addon.js +1 -1
  8. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  9. package/dist/builtins/autotrack/index.js +1 -1
  10. package/dist/builtins/autotrack/index.mjs +1 -1
  11. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  12. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  13. package/dist/builtins/camera-grid/index.js +1 -1
  14. package/dist/builtins/camera-grid/index.mjs +1 -1
  15. package/dist/builtins/composer/claim-gate.d.ts +32 -0
  16. package/dist/builtins/composer/composed-device-set.d.ts +38 -0
  17. package/dist/builtins/composer/composed-device.d.ts +4 -3
  18. package/dist/builtins/composer/composer-grafts.d.ts +54 -0
  19. package/dist/builtins/composer/composer-plan.d.ts +96 -0
  20. package/dist/builtins/composer/composer-verdict.d.ts +19 -0
  21. package/dist/builtins/composer/composer.addon.js +2717 -477
  22. package/dist/builtins/composer/composer.addon.mjs +2722 -482
  23. package/dist/builtins/composer/composer.d.ts +71 -52
  24. package/dist/builtins/composer/composition-runtime.d.ts +93 -9
  25. package/dist/builtins/composer/confirmed-seed.d.ts +32 -0
  26. package/dist/builtins/composer/existing-target.d.ts +96 -0
  27. package/dist/builtins/composer/field-record.d.ts +50 -0
  28. package/dist/builtins/composer/graft-host.d.ts +47 -0
  29. package/dist/builtins/composer/held-claims.d.ts +12 -0
  30. package/dist/builtins/composer/owned-fields-target.d.ts +55 -0
  31. package/dist/builtins/composer/slice-assembler.d.ts +10 -0
  32. package/dist/builtins/composer/source-readings.d.ts +122 -0
  33. package/dist/builtins/composer/source-tracker.d.ts +35 -42
  34. package/dist/builtins/console-logging/index.js +1 -1
  35. package/dist/builtins/console-logging/index.mjs +1 -1
  36. package/dist/builtins/core-blocks/composition-api.d.ts +7 -4
  37. package/dist/builtins/core-blocks/composition-peers.d.ts +9 -0
  38. package/dist/builtins/core-blocks/composition-sources.d.ts +16 -3
  39. package/dist/builtins/core-blocks/core-block-store.d.ts +8 -1
  40. package/dist/builtins/core-blocks/core-blocks.addon.d.ts +4 -3
  41. package/dist/builtins/core-blocks/core-blocks.addon.js +255 -79
  42. package/dist/builtins/core-blocks/core-blocks.addon.mjs +255 -79
  43. package/dist/builtins/device-manager/claimed-status-overlay.d.ts +12 -0
  44. package/dist/builtins/device-manager/device-manager.addon.d.ts +16 -0
  45. package/dist/builtins/device-manager/device-manager.addon.js +1825 -317
  46. package/dist/builtins/device-manager/device-manager.addon.mjs +1825 -317
  47. package/dist/builtins/device-manager/device-provider-context.d.ts +24 -2
  48. package/dist/builtins/device-manager/device-row-store.d.ts +2 -0
  49. package/dist/builtins/device-manager/device-state-claim-views.d.ts +77 -0
  50. package/dist/builtins/device-manager/device-state-claims.d.ts +43 -0
  51. package/dist/builtins/device-manager/device-state-mirror.d.ts +145 -61
  52. package/dist/builtins/device-manager/field-claims-index.d.ts +69 -0
  53. package/dist/builtins/device-manager/field-ownership.d.ts +53 -0
  54. package/dist/builtins/device-manager/migrate-device.d.ts +27 -0
  55. package/dist/builtins/device-manager/migrate-guard.d.ts +7 -0
  56. package/dist/builtins/device-manager/migrate-hardware-state.d.ts +55 -0
  57. package/dist/builtins/device-manager/migration-refused.d.ts +23 -0
  58. package/dist/builtins/device-manager/mirror-row-writer.d.ts +138 -0
  59. package/dist/builtins/device-manager/runtime-state-persist-gate.d.ts +4 -0
  60. package/dist/builtins/doorbell/binding-mirror.d.ts +1 -0
  61. package/dist/builtins/doorbell/doorbell-composition-migration.d.ts +59 -0
  62. package/dist/builtins/doorbell/virtual-doorbell.addon.d.ts +3 -0
  63. package/dist/builtins/doorbell/virtual-doorbell.addon.js +315 -10
  64. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +315 -10
  65. package/dist/builtins/hub-forwarder/index.js +1 -1
  66. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  67. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  68. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  69. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  70. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  71. package/dist/builtins/local-network/local-network.addon.js +1 -1
  72. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  73. package/dist/builtins/loki-logging/index.js +1 -1
  74. package/dist/builtins/loki-logging/index.mjs +1 -1
  75. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  76. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  77. package/dist/builtins/platform-probe/index.js +1 -1
  78. package/dist/builtins/platform-probe/index.mjs +1 -1
  79. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  80. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  81. package/dist/builtins/snapshot/index.js +1 -1
  82. package/dist/builtins/snapshot/index.mjs +1 -1
  83. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  84. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  85. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  86. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  87. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  88. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  89. package/dist/builtins/system-config/system-config.addon.js +1 -1
  90. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  91. package/dist/builtins/winston-logging/index.js +1 -1
  92. package/dist/builtins/winston-logging/index.mjs +1 -1
  93. package/dist/{child-cap-dispatch-CHTiHbsv.mjs → child-cap-dispatch-AAltfBUH.mjs} +1484 -1417
  94. package/dist/{child-cap-dispatch-Dyn_7ezH.js → child-cap-dispatch-DzcUd_ct.js} +1503 -1424
  95. package/dist/composition-sources-DYqQLRzF.js +122 -0
  96. package/dist/composition-sources-yonsRneP.mjs +111 -0
  97. package/dist/{dist-CkRwnhbo.js → dist-DVKv5i-e.js} +5396 -4331
  98. package/dist/{dist-Cj7pJmXq.mjs → dist-MzYJVCLE.mjs} +5330 -4331
  99. package/dist/index.js +137 -8
  100. package/dist/index.mjs +133 -8
  101. package/dist/kernel/capability-registry.d.ts +43 -1
  102. package/dist/kernel/index.d.ts +3 -1
  103. package/dist/kernel/moleculer/device-cap-proxy.d.ts +0 -10
  104. package/dist/kernel/status-overlay.d.ts +18 -0
  105. package/dist/kernel/transport/claimed-get-status.d.ts +15 -0
  106. package/dist/kernel/transport/index.d.ts +2 -0
  107. package/dist/kernel/transport/local-child-registry.d.ts +23 -0
  108. package/dist/kernel/transport/parent-unowned-call.d.ts +25 -0
  109. package/dist/{retired-settings-keys-C1duPikd.mjs → retired-settings-keys-8yY2sTc-.mjs} +1 -1
  110. package/dist/{retired-settings-keys-CGSuXhP8.js → retired-settings-keys-iY5I0nKM.js} +1 -1
  111. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
- import { Ft as isSourceCap, Ln as DeviceType, Pt as isSameAddonId, St as evaluateSensorEdge, W as bareAddonId, Wn as createEvent, _t as doorbellCapability, dt as defineExtensionSlotProvider, ir as EventCategory, jn as BaseAddon, k as SOURCE_CAPS, kn as errMsg, pt as deviceExtensionCapability, st as createDeviceExtensionProvider } from "../../dist-Cj7pJmXq.mjs";
1
+ import { At as isSameAddonId, Dn as SOURCE_CAP_ACTIVE_FIELD, En as SOURCE_CAPS, Gn as BaseAddon, On as SOURCE_CAP_CHANGED_AT_FIELD, Rn as evaluateSensorEdge, Un as DeviceType, W as bareAddonId, Wn as errMsg, ct as defineExtensionSlotProvider, hr as EventCategory, it as createDeviceExtensionProvider, mt as doorbellCapability, tr as createEvent, ut as deviceExtensionCapability, zn as isSourceCap } from "../../dist-MzYJVCLE.mjs";
2
2
  import { n as parseDeviceStateChanged } from "../../device-state-changed-DoBbkyEI.mjs";
3
+ import { z } from "zod";
3
4
  //#region src/builtins/doorbell/trigger-engine.ts
4
5
  /**
5
6
  * Pure trigger logic for the virtual-doorbell builtin — edge detection over
@@ -237,7 +238,7 @@ function entriesBindWrapper(entries, capName, ownAddonId) {
237
238
  function summariseEntries(entries) {
238
239
  return entries.map((entry) => `${entry.capName}:${entry.kind}:${entry.providerAddonId}`);
239
240
  }
240
- function isRecord$1(value) {
241
+ function isRecord$2(value) {
241
242
  return typeof value === "object" && value !== null && !Array.isArray(value);
242
243
  }
243
244
  /**
@@ -253,13 +254,13 @@ function isRecord$1(value) {
253
254
  * from an empty snapshot, whereas a genuine unbind leaves the key present.
254
255
  */
255
256
  function readDurableWrapperBinding(record, deviceId, capName, ownAddonId) {
256
- if (!isRecord$1(record)) return "unreadable";
257
+ if (!isRecord$2(record)) return "unreadable";
257
258
  const deviceBindings = record["deviceBindings"];
258
- if (!isRecord$1(deviceBindings)) return "unreadable";
259
+ if (!isRecord$2(deviceBindings)) return "unreadable";
259
260
  const perDevice = deviceBindings[String(deviceId)];
260
- if (!isRecord$1(perDevice)) return "unbound";
261
+ if (!isRecord$2(perDevice)) return "unbound";
261
262
  const activation = perDevice[capName];
262
- if (!isRecord$1(activation)) return "unbound";
263
+ if (!isRecord$2(activation)) return "unbound";
263
264
  const wrapperAddonId = activation["wrapperAddonId"];
264
265
  if (typeof wrapperAddonId !== "string") return "unbound";
265
266
  return isSameAddonId(wrapperAddonId, ownAddonId) ? "bound" : "unbound";
@@ -314,7 +315,7 @@ var KEY_SOURCES = "doorbellSources";
314
315
  var LEGACY_KEY_SOURCE = "doorbellSourceDeviceId";
315
316
  var LEGACY_KEY_TRIGGER = "doorbellTrigger";
316
317
  var LEGACY_KEY_EVENT_TYPE = "doorbellEventType";
317
- function isRecord(value) {
318
+ function isRecord$1(value) {
318
319
  return typeof value === "object" && value !== null && !Array.isArray(value);
319
320
  }
320
321
  /** Coerce a persisted / form-supplied id (number or numeric string) to a
@@ -332,7 +333,7 @@ function collectSources(items) {
332
333
  const out = [];
333
334
  const seen = /* @__PURE__ */ new Set();
334
335
  for (const item of items) {
335
- const id = isRecord(item) ? coerceDeviceId(item["deviceId"]) : coerceDeviceId(item);
336
+ const id = isRecord$1(item) ? coerceDeviceId(item["deviceId"]) : coerceDeviceId(item);
336
337
  if (id !== null && !seen.has(id)) {
337
338
  seen.add(id);
338
339
  out.push({ deviceId: id });
@@ -533,7 +534,6 @@ function createDoorbellExtensionProvider(deps) {
533
534
  const ids = (await deps.readSources(deviceId)).map((s) => s.deviceId);
534
535
  if (ids.length === 0) return {
535
536
  authority: DOORBELL_SOURCES_AUTHORITY,
536
- enabled: null,
537
537
  activation: null,
538
538
  value: {
539
539
  slot: "doorbell-source",
@@ -545,7 +545,6 @@ function createDoorbellExtensionProvider(deps) {
545
545
  const byId = new Map(devices.map((d) => [d.id, d]));
546
546
  return {
547
547
  authority: DOORBELL_SOURCES_AUTHORITY,
548
- enabled: null,
549
548
  activation,
550
549
  value: {
551
550
  slot: "doorbell-source",
@@ -576,6 +575,278 @@ function createDoorbellExtensionProvider(deps) {
576
575
  });
577
576
  }
578
577
  //#endregion
578
+ //#region src/builtins/doorbell/doorbell-composition-migration.ts
579
+ var DOORBELL_COMPOSITION_MIGRATION_STATE_KEY = "doorbell-source-composition-migration-v1";
580
+ var DOORBELL_COMPOSITION_MIGRATION_CALLER = {
581
+ userId: "system:doorbell-source-migration",
582
+ isAdmin: true
583
+ };
584
+ function buildDoorbellCompositionFeature(input) {
585
+ const sources = [...input.sources].toSorted((a, b) => `${a.source.addonId}/${a.source.stableId}#${a.cap}`.localeCompare(`${b.source.addonId}/${b.source.stableId}#${b.cap}`));
586
+ if (sources.length === 0) throw new Error("doorbell composition needs at least one source");
587
+ const edgeBindings = {};
588
+ sources.forEach((entry, index) => {
589
+ edgeBindings[`active${index}`] = {
590
+ kind: "from",
591
+ source: entry.source,
592
+ cap: entry.cap,
593
+ fieldPath: entry.activeField
594
+ };
595
+ edgeBindings[`changed${index}`] = {
596
+ kind: "from",
597
+ source: entry.source,
598
+ cap: entry.cap,
599
+ fieldPath: entry.changedAtField
600
+ };
601
+ });
602
+ return {
603
+ kind: "fields",
604
+ cap: "doorbell",
605
+ enabled: input.enabled,
606
+ fields: {
607
+ lastPressedAt: {
608
+ kind: "expression",
609
+ expr: `latest(${sources.map((_, index) => `rose(active${index}, changed${index}, 2000)`).join(", ")})`,
610
+ bindings: edgeBindings
611
+ },
612
+ pressCountSinceStart: {
613
+ kind: "expression",
614
+ expr: "count(lastPressedAt)",
615
+ bindings: { lastPressedAt: {
616
+ kind: "from",
617
+ source: {
618
+ addonId: input.camera.addonId,
619
+ stableId: input.camera.stableId
620
+ },
621
+ cap: "doorbell",
622
+ fieldPath: "lastPressedAt"
623
+ } }
624
+ }
625
+ }
626
+ };
627
+ }
628
+ function isRecord(value) {
629
+ return typeof value === "object" && value !== null && !Array.isArray(value);
630
+ }
631
+ function stableValue(value) {
632
+ if (Array.isArray(value)) return value.map(stableValue);
633
+ if (!isRecord(value)) return value;
634
+ return Object.fromEntries(Object.keys(value).toSorted().map((key) => [key, stableValue(value[key])]));
635
+ }
636
+ function sameJson(a, b) {
637
+ return JSON.stringify(stableValue(a)) === JSON.stringify(stableValue(b));
638
+ }
639
+ function withoutEnabled(feature) {
640
+ const { enabled: _enabled, ...rest } = feature;
641
+ return rest;
642
+ }
643
+ function bindingHasCap(entries, cap) {
644
+ return entries.some((entry) => entry.capName === cap);
645
+ }
646
+ function migrationSources(camera, configured, devicesById, bindingsById) {
647
+ const sources = [];
648
+ for (const configuredSource of configured) {
649
+ const device = devicesById.get(configuredSource.deviceId);
650
+ const entries = bindingsById.get(configuredSource.deviceId);
651
+ if (device === void 0 || entries === void 0) throw new Error(`source device ${configuredSource.deviceId} could not be resolved and read`);
652
+ const ref = {
653
+ addonId: device.addonId,
654
+ stableId: device.stableId
655
+ };
656
+ const supportedCaps = Object.keys(SOURCE_CAP_ACTIVE_FIELD).filter((cap) => Object.hasOwn(SOURCE_CAP_CHANGED_AT_FIELD, cap) && bindingHasCap(entries, cap)).toSorted();
657
+ if (supportedCaps.length === 0) throw new Error(`source device ${configuredSource.deviceId} has no supported source capability`);
658
+ for (const cap of supportedCaps) {
659
+ const activeField = SOURCE_CAP_ACTIVE_FIELD[cap];
660
+ const changedAtField = SOURCE_CAP_CHANGED_AT_FIELD[cap];
661
+ if (activeField === void 0 || changedAtField === void 0) throw new Error(`source capability ${cap} has no transition field mapping`);
662
+ sources.push({
663
+ source: ref,
664
+ cap,
665
+ activeField,
666
+ changedAtField
667
+ });
668
+ }
669
+ }
670
+ if (sources.length === 0) throw new Error(`camera ${camera.id} has no resolvable doorbell sources`);
671
+ return sources;
672
+ }
673
+ function wrapperIsActive(entries) {
674
+ return entries.some((entry) => entry.capName === "doorbell" && entry.kind === "wrapped" && entry.providerAddonId === "virtual-doorbell");
675
+ }
676
+ function composerIsBound(entries) {
677
+ return entries.some((entry) => entry.capName === "doorbell" && (entry.providerAddonId === "composer" || entry.nativeAddonId === "composer"));
678
+ }
679
+ var DoorbellCompositionMigration = class {
680
+ deps;
681
+ rerunRequested = false;
682
+ inFlight = null;
683
+ stopped = false;
684
+ constructor(deps) {
685
+ this.deps = deps;
686
+ }
687
+ request(reason) {
688
+ if (this.stopped) return;
689
+ this.rerunRequested = true;
690
+ if (this.inFlight !== null) return;
691
+ this.inFlight = this.runUntilQuiet(reason).finally(() => {
692
+ this.inFlight = null;
693
+ if (this.rerunRequested && !this.stopped) this.request("coalesced lifecycle event");
694
+ });
695
+ }
696
+ async waitForIdle() {
697
+ while (this.inFlight !== null || this.rerunRequested) {
698
+ const current = this.inFlight;
699
+ if (current !== null) await current;
700
+ else await Promise.resolve();
701
+ }
702
+ }
703
+ shutdown() {
704
+ this.stopped = true;
705
+ this.rerunRequested = false;
706
+ }
707
+ async runUntilQuiet(reason) {
708
+ while (this.rerunRequested && !this.stopped) {
709
+ this.rerunRequested = false;
710
+ try {
711
+ await this.runAttempt(reason);
712
+ } catch (err) {
713
+ this.deps.logger.warn("doorbell-source migration: attempt failed", { meta: {
714
+ reason,
715
+ error: err instanceof Error ? err.message : String(err)
716
+ } });
717
+ }
718
+ }
719
+ }
720
+ async runAttempt(reason) {
721
+ if (await this.deps.isComplete()) return;
722
+ const cameras = await this.deps.listCameras();
723
+ const configuredByCamera = /* @__PURE__ */ new Map();
724
+ const failedReads = /* @__PURE__ */ new Set();
725
+ for (const camera of cameras) try {
726
+ const sources = await this.deps.readSources(camera.id);
727
+ if (sources.length > 0) configuredByCamera.set(camera.id, sources);
728
+ } catch (err) {
729
+ failedReads.add(camera.id);
730
+ this.warnCamera(camera.id, `could not read source settings (${errorText(err)})`);
731
+ }
732
+ if (failedReads.size > 0) return;
733
+ if (configuredByCamera.size === 0) {
734
+ await this.deps.markComplete();
735
+ return;
736
+ }
737
+ const camerasById = new Map(cameras.map((camera) => [camera.id, camera]));
738
+ const sourceIds = [...new Set([...configuredByCamera.values()].flatMap((sources) => sources.map((s) => s.deviceId)))].toSorted((a, b) => a - b);
739
+ const sourceDevices = await this.deps.listSourceDevices(sourceIds);
740
+ const devicesById = new Map(sourceDevices.map((device) => [device.id, device]));
741
+ const bindingIds = [...new Set([...configuredByCamera.keys(), ...sourceIds])].toSorted((a, b) => a - b);
742
+ const bindingRows = await this.deps.getBindingsBatch(bindingIds);
743
+ const bindingsById = new Map(bindingRows.map((row) => [row.deviceId, row.entries]));
744
+ const coreBlocks = this.deps.coreBlocks();
745
+ if (coreBlocks === null) {
746
+ for (const cameraId of configuredByCamera.keys()) this.warnCamera(cameraId, "core-blocks provider is not ready");
747
+ return;
748
+ }
749
+ let allSettled = true;
750
+ for (const [cameraId, configured] of configuredByCamera) {
751
+ const camera = camerasById.get(cameraId);
752
+ const entries = bindingsById.get(cameraId);
753
+ if (camera === void 0 || entries === void 0) {
754
+ allSettled = false;
755
+ this.warnCamera(cameraId, "camera or binding row could not be read");
756
+ continue;
757
+ }
758
+ try {
759
+ const sources = migrationSources(camera, configured, devicesById, bindingsById);
760
+ const cameraRef = {
761
+ addonId: camera.addonId,
762
+ stableId: camera.stableId
763
+ };
764
+ const read = await coreBlocks.getCustomization({ ...cameraRef });
765
+ if (read.state !== "loaded") throw new Error(`customizations are not loaded (${read.reason})`);
766
+ const view = read.view;
767
+ if (view !== null && !view.block.enabled) throw new Error(`customization block ${view.block.id} is disabled`);
768
+ const existingComposition = view?.block.source?.kind === "composition" ? view.block.source.composition : null;
769
+ if (view !== null && existingComposition === null) throw new Error(`customization block ${view.block.id} has no readable composition`);
770
+ const existingDoorbell = existingComposition?.features.find((feature) => feature.cap === "doorbell");
771
+ const wrapperActive = wrapperIsActive(entries);
772
+ const composerBound = composerIsBound(entries);
773
+ const crashRecovery = !wrapperActive && composerBound && existingDoorbell?.kind === "fields" && existingDoorbell.enabled === true;
774
+ const enabled = wrapperActive || crashRecovery;
775
+ const canonical = buildDoorbellCompositionFeature({
776
+ camera: cameraRef,
777
+ sources,
778
+ enabled
779
+ });
780
+ let needsSave = view === null;
781
+ let composition;
782
+ if (existingComposition === null) composition = {
783
+ target: {
784
+ kind: "existing",
785
+ device: cameraRef
786
+ },
787
+ features: [canonical]
788
+ };
789
+ else if (existingDoorbell === void 0) {
790
+ composition = {
791
+ ...existingComposition,
792
+ features: [...existingComposition.features, canonical]
793
+ };
794
+ needsSave = true;
795
+ } else if (existingDoorbell.kind === "fields" && sameJson(withoutEnabled(existingDoorbell), withoutEnabled(canonical))) {
796
+ composition = {
797
+ ...existingComposition,
798
+ features: existingComposition.features.map((feature) => feature.cap === "doorbell" ? canonical : feature)
799
+ };
800
+ needsSave ||= existingDoorbell.enabled !== canonical.enabled;
801
+ } else throw new Error("an existing doorbell feature is not owned by this migration");
802
+ if (needsSave) if (view === null) await coreBlocks.createComposition({
803
+ block: {
804
+ enabled: true,
805
+ composition
806
+ },
807
+ caller: DOORBELL_COMPOSITION_MIGRATION_CALLER
808
+ });
809
+ else await coreBlocks.updateComposition({
810
+ blockId: view.block.id,
811
+ expectedUpdatedAt: view.block.updatedAt,
812
+ block: { composition },
813
+ caller: DOORBELL_COMPOSITION_MIGRATION_CALLER
814
+ });
815
+ if (!enabled) continue;
816
+ if (!composerBound) {
817
+ allSettled = false;
818
+ continue;
819
+ }
820
+ if (wrapperActive) {
821
+ await this.deps.setWrapperActive({
822
+ deviceId: camera.id,
823
+ capName: "doorbell",
824
+ wrapperAddonId: "virtual-doorbell",
825
+ active: false
826
+ });
827
+ this.deps.logger.info("doorbell-source migration: composer owns doorbell; wrapper deactivated", {
828
+ tags: { deviceId: camera.id },
829
+ meta: { reason }
830
+ });
831
+ }
832
+ } catch (err) {
833
+ allSettled = false;
834
+ this.warnCamera(cameraId, errorText(err));
835
+ }
836
+ }
837
+ if (allSettled) await this.deps.markComplete();
838
+ }
839
+ warnCamera(cameraId, reason) {
840
+ this.deps.logger.warn("doorbell-source migration: camera not migrated", {
841
+ tags: { deviceId: cameraId },
842
+ meta: { reason }
843
+ });
844
+ }
845
+ };
846
+ function errorText(err) {
847
+ return err instanceof Error ? err.message : String(err);
848
+ }
849
+ //#endregion
579
850
  //#region src/builtins/doorbell/virtual-doorbell.addon.ts
580
851
  /**
581
852
  * The addon whose store IS the durable authority on wrapper activations.
@@ -625,6 +896,8 @@ function parseDoorbellSlice(slice) {
625
896
  */
626
897
  var VirtualDoorbellAddon = class extends BaseAddon {
627
898
  engine;
899
+ compositionMigration = null;
900
+ providerRegisteredUnsubscribe = null;
628
901
  /** Monotonic guard: assignments are reloaded lazily on trigger traffic. */
629
902
  assignmentsLoadedAt = 0;
630
903
  assignmentsLoading = null;
@@ -649,6 +922,32 @@ var VirtualDoorbellAddon = class extends BaseAddon {
649
922
  if (!data) return;
650
923
  this.handleStateChanged(data);
651
924
  });
925
+ const migrationState = this.state(DOORBELL_COMPOSITION_MIGRATION_STATE_KEY, z.object({ complete: z.boolean() }), { complete: false });
926
+ this.compositionMigration = new DoorbellCompositionMigration({
927
+ logger: this.ctx.logger.child("doorbell-source-migration"),
928
+ listCameras: async () => this.ctx.api.deviceManager.listAll.query({
929
+ isCamera: true,
930
+ projection: "slim"
931
+ }),
932
+ listSourceDevices: async (deviceIds) => this.ctx.api.deviceManager.listAll.query({
933
+ deviceIds: [...deviceIds],
934
+ projection: "slim"
935
+ }),
936
+ readSources: (cameraId) => this.readDeviceSources(cameraId),
937
+ getBindingsBatch: async (deviceIds) => this.ctx.api.deviceManager.getBindingsBatch.query({ deviceIds: [...deviceIds] }),
938
+ coreBlocks: () => this.ctx.capabilities?.get("core-blocks") ?? null,
939
+ setWrapperActive: (input) => this.ctx.api.deviceManager.setWrapperActive.mutate(input),
940
+ isComplete: async () => (await migrationState.get()).complete,
941
+ markComplete: async () => migrationState.set({ complete: true })
942
+ });
943
+ this.providerRegisteredUnsubscribe = this.ctx.eventBus.subscribe({ category: "capability:provider-registered" }, (event) => {
944
+ if (event.data["capability"] !== "core-blocks") return;
945
+ this.compositionMigration?.request("core-blocks registered");
946
+ });
947
+ this.subscribe({ category: EventCategory.DeviceBindingsChanged }, () => {
948
+ this.compositionMigration?.request("device bindings changed");
949
+ });
950
+ this.compositionMigration.request("addon initialized");
652
951
  return [{
653
952
  capability: doorbellCapability,
654
953
  provider: { getStatus: (input) => this.getStatus(input.deviceId) }
@@ -657,6 +956,12 @@ var VirtualDoorbellAddon = class extends BaseAddon {
657
956
  provider: this.buildExtensionProvider()
658
957
  }];
659
958
  }
959
+ async onShutdown() {
960
+ this.providerRegisteredUnsubscribe?.();
961
+ this.providerRegisteredUnsubscribe = null;
962
+ this.compositionMigration?.shutdown();
963
+ this.compositionMigration = null;
964
+ }
660
965
  /**
661
966
  * The `device-extension` provider: the only editor of a camera's trigger
662
967
  * devices since D655 (see `doorbell-extension-slot.ts`).
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  const require_formatter = require("../../formatter-DqAKDlvN.js");
8
8
  //#region src/builtins/hub-forwarder/hub-forwarder-destination.ts
9
9
  var DEFAULT_OUTBOUND_BUFFER_SIZE = 500;
@@ -1,4 +1,4 @@
1
- import { Ut as logDestinationCapability, jn as BaseAddon } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, Rt as logDestinationCapability } from "../../dist-MzYJVCLE.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-B7qW8bPJ.mjs";
3
3
  //#region src/builtins/hub-forwarder/hub-forwarder-destination.ts
4
4
  var DEFAULT_OUTBOUND_BUFFER_SIZE = 500;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-CkRwnhbo.js");
3
+ const require_dist = require("../../dist-DVKv5i-e.js");
4
4
  //#region src/builtins/liveness-monitor/liveness-checks.ts
5
5
  var NO_DEVICES = "liveness:no-devices";
6
6
  var ALL_OFFLINE = "liveness:all-devices-offline";
@@ -1,4 +1,4 @@
1
- import { O as RecordingStatusSchema, T as RECORDING_SOURCE_CAMSTACK_ADDON, Wn as createEvent, ir as EventCategory, jn as BaseAddon, kn as errMsg } from "../../dist-Cj7pJmXq.mjs";
1
+ import { E as RECORDING_SOURCE_CAMSTACK_ADDON, Gn as BaseAddon, Wn as errMsg, hr as EventCategory, k as RecordingStatusSchema, tr as createEvent } from "../../dist-MzYJVCLE.mjs";
2
2
  //#region src/builtins/liveness-monitor/liveness-checks.ts
3
3
  var NO_DEVICES = "liveness:no-devices";
4
4
  var ALL_OFFLINE = "liveness:all-devices-offline";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  node_crypto = require_chunk.__toESM(node_crypto);
9
9
  let crypto$1 = require("crypto");
@@ -1,5 +1,5 @@
1
1
  import { i as __require, o as __toESM, t as __commonJSMin } from "../../chunk-CNf5ZN-e.mjs";
2
- import { Cn as userManagementCapability, H as authProviderCapability, L as UserRecordSchema, M as ScopedTokenSchema, jn as BaseAddon, r as ApiKeyRecordSchema } from "../../dist-Cj7pJmXq.mjs";
2
+ import { Gn as BaseAddon, H as authProviderCapability, L as UserRecordSchema, M as ScopedTokenSchema, r as ApiKeyRecordSchema, vn as userManagementCapability } from "../../dist-MzYJVCLE.mjs";
3
3
  import * as crypto$2 from "node:crypto";
4
4
  import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
5
5
  import nodeCrypto from "crypto";
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-CkRwnhbo.js");
3
+ const require_dist = require("../../dist-DVKv5i-e.js");
4
4
  const require_tls = require("../../tls-D_wUeOTD.js");
5
5
  let node_fs_promises = require("node:fs/promises");
6
6
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Vt as localNetworkCapability, ir as EventCategory, jn as BaseAddon } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, It as localNetworkCapability, hr as EventCategory } from "../../dist-MzYJVCLE.mjs";
2
2
  import { S as readLanHttpState, _ as DEFAULT_LAN_HTTP_PORT, a as writeTlsMode, i as writeExtraSans, l as reissueTlsLeaf, n as readTlsAccessStatus, o as validateUploadedTls, r as readTlsMode, s as ensureTlsCert, t as readExtraSans, y as applyLanHttp } from "../../tls-IM-v7JV4.mjs";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  //#region src/builtins/loki-logging/loki-payload.ts
8
8
  /**
9
9
  * Loki rejects a label name that is not a valid Prometheus label
@@ -1,4 +1,4 @@
1
- import { Ut as logDestinationCapability, jn as BaseAddon } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, Rt as logDestinationCapability } from "../../dist-MzYJVCLE.mjs";
2
2
  //#region src/builtins/loki-logging/loki-payload.ts
3
3
  /**
4
4
  * Loki rejects a label name that is not a valid Prometheus label
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  const require_proc_stat = require("../../proc-stat-DL-WUOhl.js");
8
8
  let node_fs_promises = require("node:fs/promises");
9
9
  let node_fs = require("node:fs");
@@ -1,4 +1,4 @@
1
- import { Dt as foldSnapshotByFunction, Jt as metricsProviderCapability, Wn as createEvent, an as reducePoints, ir as EventCategory, jn as BaseAddon, kn as errMsg, on as resolveBucketMs } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Ct as foldSnapshotByFunction, Gn as BaseAddon, Ut as metricsProviderCapability, Wn as errMsg, en as reducePoints, hr as EventCategory, nn as resolveBucketMs, tr as createEvent } from "../../dist-MzYJVCLE.mjs";
2
2
  import { a as parseProcStat, i as nodeProcReader, n as elapsedSecSince, o as parseProcStatusRss, r as lifetimeCpuPercent, t as commandFromCmdline } from "../../proc-stat-CbC55Kqi.mjs";
3
3
  import { access, readFile, readdir } from "node:fs/promises";
4
4
  import * as fs from "node:fs";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  let node_fs = require("node:fs");
8
8
  node_fs = require_chunk.__toESM(node_fs);
9
9
  let node_child_process = require("node:child_process");
@@ -1,5 +1,5 @@
1
1
  import { o as __toESM } from "../../chunk-CNf5ZN-e.mjs";
2
- import { Kn as emitReadiness, fn as scoreRuntimes, ir as EventCategory, jn as BaseAddon, kn as errMsg, nn as platformProbeCapability, vt as enumerateInferenceDevices } from "../../dist-Cj7pJmXq.mjs";
2
+ import { Gn as BaseAddon, Wn as errMsg, Zt as platformProbeCapability, cn as scoreRuntimes, hr as EventCategory, ht as enumerateInferenceDevices, rr as emitReadiness } from "../../dist-MzYJVCLE.mjs";
3
3
  import * as fs from "node:fs";
4
4
  import { execFile } from "node:child_process";
5
5
  import * as os from "node:os";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  //#region src/builtins/remote-access-orchestrator/enabled-providers-reconcile.ts
8
8
  /**
9
9
  * Reconcile the durable `enabledProviders` set against authoritative
@@ -1,4 +1,4 @@
1
- import { ir as EventCategory, jn as BaseAddon } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, hr as EventCategory } from "../../dist-MzYJVCLE.mjs";
2
2
  //#region src/builtins/remote-access-orchestrator/enabled-providers-reconcile.ts
3
3
  /**
4
4
  * Reconcile the durable `enabledProviders` set against authoritative
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  const require_snapshot_courtesy = require("../../snapshot-courtesy-Cqs7GkOV.js");
8
8
  let zod = require("zod");
9
9
  let node_crypto = require("node:crypto");
@@ -1,4 +1,4 @@
1
- import { Fn as DeviceFeature, G as batteryCapability, Ln as DeviceType, W as bareAddonId, Zn as nodePin, a as BatteryStatusSchema, ft as deriveBatteryPresence, hn as snapshotCapability, ir as EventCategory, jn as BaseAddon, kn as errMsg, xn as streamQualityLabel } from "../../dist-Cj7pJmXq.mjs";
1
+ import { G as batteryCapability, Gn as BaseAddon, Un as DeviceType, Vn as DeviceFeature, W as bareAddonId, Wn as errMsg, _n as streamQualityLabel, a as BatteryStatusSchema, cr as nodePin, dn as snapshotCapability, hr as EventCategory, lt as deriveBatteryPresence } from "../../dist-MzYJVCLE.mjs";
2
2
  import { i as renderCourtesyOverlayJpeg, n as courtesyCacheKey, r as renderCourtesyJpeg } from "../../snapshot-courtesy-CZPvteq2.mjs";
3
3
  import { z } from "zod";
4
4
  import { randomUUID } from "node:crypto";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  let node_fs_promises = require("node:fs/promises");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Et as filesystemBrowseCapability, jn as BaseAddon, yn as storageProviderCapability } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, St as filesystemBrowseCapability, hn as storageProviderCapability } from "../../dist-MzYJVCLE.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { mkdir, readdir, realpath, statfs } from "node:fs/promises";
4
4
  import * as path$1 from "node:path";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  const require_hub_cap_forward = require("../../hub-cap-forward-DmHNjbB0.js");
8
8
  let zod = require("zod");
9
9
  let node_crypto = require("node:crypto");
@@ -1,4 +1,4 @@
1
- import { Ct as evictionPolicyOfLocation, E as REDACTED_SECRET, F as StorageLocationTypeSchema, I as StorageMigrationJobSchema, Kt as mayReadLocation, Mt as isLocationEnabled, N as StorageCleanupJobSchema, On as withLocationMode, P as StorageLocationModeSchema, Qn as parseJsonObject, Y as collectSecretConfigKeys, Yt as modeMayWrite, _n as storageMigrationCapability, b as LegacyStorageLocationDefaultSchema, gn as storageCapability, ir as EventCategory, jn as BaseAddon, kt as gbToBytes, pn as settingsStoreCapability, qt as mayWriteToLocation, sn as resolveLocationMode, zt as legacyModeOf } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Cn as withLocationMode, D as REDACTED_SECRET, F as StorageLocationTypeSchema, Gn as BaseAddon, Ht as mayWriteToLocation, I as StorageMigrationJobSchema, N as StorageCleanupJobSchema, Ot as isLocationEnabled, P as StorageLocationModeSchema, Pt as legacyModeOf, Tt as gbToBytes, Vt as mayReadLocation, Wt as modeMayWrite, Y as collectSecretConfigKeys, fn as storageCapability, hr as EventCategory, ln as settingsStoreCapability, lr as parseJsonObject, pn as storageMigrationCapability, rn as resolveLocationMode, x as LegacyStorageLocationDefaultSchema, yt as evictionPolicyOfLocation } from "../../dist-MzYJVCLE.mjs";
2
2
  import { t as HUB_CAP_FWD_ACTION } from "../../hub-cap-forward-BdT320dq.mjs";
3
3
  import { z } from "zod";
4
4
  import { randomUUID } from "node:crypto";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  //#region src/builtins/system-config/system-config.addon.ts
8
8
  /**
9
9
  * Built-in `system-config` addon — Phase 4 of the settings redesign.
@@ -1,4 +1,4 @@
1
- import { Jn as hydrateSchema, jn as BaseAddon, kn as errMsg } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, Wn as errMsg, ar as hydrateSchema } from "../../dist-MzYJVCLE.mjs";
2
2
  //#region src/builtins/system-config/system-config.addon.ts
3
3
  /**
4
4
  * Built-in `system-config` addon — Phase 4 of the settings redesign.
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CkRwnhbo.js");
6
+ const require_dist = require("../../dist-DVKv5i-e.js");
7
7
  const require_formatter = require("../../formatter-DqAKDlvN.js");
8
8
  let node_path = require("node:path");
9
9
  node_path = require_chunk.__toESM(node_path);
@@ -1,4 +1,4 @@
1
- import { Ut as logDestinationCapability, jn as BaseAddon } from "../../dist-Cj7pJmXq.mjs";
1
+ import { Gn as BaseAddon, Rt as logDestinationCapability } from "../../dist-MzYJVCLE.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-B7qW8bPJ.mjs";
3
3
  import * as path$1 from "node:path";
4
4
  import path from "node:path";