@camstack/server 1.2.828 → 1.2.830

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 (126) hide show
  1. package/CHANGELOG.md +20 -3
  2. package/dist/agent/agent-boot-mode.js +14 -1
  3. package/dist/agent/agent-http.js +12 -0
  4. package/dist/agent/agent-hub-rediscovery.js +205 -0
  5. package/dist/agent/agent-membership-watch.js +29 -1
  6. package/dist/agent/agent-pairing-store.js +47 -3
  7. package/dist/agent/hubs-found.js +1 -0
  8. package/dist/agent/main.js +64 -6
  9. package/dist/api/core/agent-pairing.router.js +9 -0
  10. package/dist/api/core/cluster-update.provider.js +98 -0
  11. package/dist/api/mesh-membership-routes.js +3 -2
  12. package/dist/api/trpc/generated-cap-mounts.js +2 -1
  13. package/dist/api/trpc/generated-cap-routers.js +2339 -2286
  14. package/dist/api/trpc/server-provided-caps.js +1 -0
  15. package/dist/api/trpc/trpc.router.js +5 -0
  16. package/dist/auth/auth-provider-gate.js +6 -2
  17. package/dist/core/addon/device-meta-mirror.js +1 -0
  18. package/dist/core/cluster-update/cluster-update-job-store.js +106 -0
  19. package/dist/core/cluster-update/cluster-update-plan.js +147 -0
  20. package/dist/core/cluster-update/cluster-update-seams.js +13 -0
  21. package/dist/core/cluster-update/cluster-update-steps.js +293 -0
  22. package/dist/core/cluster-update/cluster-update.service.js +319 -0
  23. package/dist/main.js +3 -0
  24. package/dist/manual-boot.js +19 -0
  25. package/package.json +12 -11
  26. package/system/dist/addon-runner.js +12 -0
  27. package/system/dist/addon-runner.mjs +12 -0
  28. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  29. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  30. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  31. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  32. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  33. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  34. package/system/dist/builtins/autotrack/index.js +1 -1
  35. package/system/dist/builtins/autotrack/index.mjs +1 -1
  36. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  37. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  38. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  39. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  40. package/system/dist/builtins/camera-grid/index.js +1 -1
  41. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  42. package/system/dist/builtins/composer/composer.addon.js +4 -4
  43. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  44. package/system/dist/builtins/console-logging/index.js +1 -1
  45. package/system/dist/builtins/console-logging/index.mjs +1 -1
  46. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  47. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  48. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  49. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  50. package/system/dist/builtins/device-manager/device-aggregation.d.ts +25 -1
  51. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +6 -0
  52. package/system/dist/builtins/device-manager/device-manager.addon.js +354 -7
  53. package/system/dist/builtins/device-manager/device-manager.addon.mjs +354 -7
  54. package/system/dist/builtins/device-manager/device-meta-actions.d.ts +6 -0
  55. package/system/dist/builtins/device-manager/device-meta-types.d.ts +4 -0
  56. package/system/dist/builtins/device-manager/device-row-store.d.ts +2 -1
  57. package/system/dist/builtins/device-manager/device-search.d.ts +42 -0
  58. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  59. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  60. package/system/dist/builtins/keychain/index.js +4 -4
  61. package/system/dist/builtins/keychain/index.mjs +4 -4
  62. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  63. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  64. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  65. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  66. package/system/dist/builtins/local-network/hub-mdns.d.ts +5 -1
  67. package/system/dist/builtins/local-network/local-network.addon.js +24 -13
  68. package/system/dist/builtins/local-network/local-network.addon.mjs +24 -13
  69. package/system/dist/builtins/loki-logging/index.js +1 -1
  70. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  71. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  72. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  73. package/system/dist/builtins/platform-probe/index.js +1 -1
  74. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  75. package/system/dist/builtins/record-entries/index.js +1 -1
  76. package/system/dist/builtins/record-entries/index.mjs +1 -1
  77. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  78. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  79. package/system/dist/builtins/snapshot/index.js +1 -1
  80. package/system/dist/builtins/snapshot/index.mjs +1 -1
  81. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  82. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  83. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  84. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  85. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  86. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  87. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  88. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  89. package/system/dist/builtins/system-config/system-config.addon.js +59 -20
  90. package/system/dist/builtins/system-config/system-config.addon.mjs +48 -10
  91. package/system/dist/builtins/winston-logging/index.js +1 -1
  92. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  93. package/system/dist/{capture-engine-1A7HAX3x.js → capture-engine-6_V-PR8O.js} +1 -1
  94. package/system/dist/{capture-engine-B0yQx6hA.mjs → capture-engine-cp3my4VK.mjs} +1 -1
  95. package/system/dist/{composition-sources-CyJ0d6Sc.mjs → composition-sources-C-iX_Uuu.mjs} +1 -1
  96. package/system/dist/{composition-sources-BzM19ASO.js → composition-sources-JwBPIhdO.js} +1 -1
  97. package/system/dist/{constants-DSO4ZEO3.js → constants-C4V2z-GT.js} +1 -1
  98. package/system/dist/{constants-B_FLEjP_.mjs → constants-D5oNuYLD.mjs} +1 -1
  99. package/system/dist/{device-ca-CveuNCHp.mjs → device-ca-CXPTrORC.mjs} +1 -1
  100. package/system/dist/{device-ca-DLTDsonl.js → device-ca-DAuMNieL.js} +1 -1
  101. package/system/dist/{dist-CIyyHwVx.mjs → dist-B8dBvJJK.mjs} +469 -27
  102. package/system/dist/{dist-DhbzVygm.js → dist-DVrLQr6W.js} +469 -27
  103. package/system/dist/file-host-worker.js +1 -1
  104. package/system/dist/file-host-worker.mjs +1 -1
  105. package/system/dist/{agent-https-BlLVD9hG.js → hub-identity-Cg1_bzoY.js} +120 -1
  106. package/system/dist/{agent-https-BSxTUzKT.mjs → hub-identity-D2sSTELW.mjs} +97 -2
  107. package/system/dist/{hub-mdns-ciao-C_ITDs0-.js → hub-mdns-ciao-DCHShuFh.js} +18 -18
  108. package/system/dist/{hub-mdns-ciao-CQdCUsrI.mjs → hub-mdns-ciao-Twxwj9Vh.mjs} +2 -2
  109. package/system/dist/index.js +61 -44
  110. package/system/dist/index.mjs +22 -10
  111. package/system/dist/kernel/hub-identity.d.ts +17 -0
  112. package/system/dist/kernel/index.d.ts +2 -0
  113. package/system/dist/kernel/moleculer/mesh-mtls/mesh-membership.d.ts +7 -0
  114. package/system/dist/kernel/moleculer/mesh-mtls/pairing/agent-pairing.d.ts +11 -1
  115. package/system/dist/kernel/moleculer/mesh-mtls/pairing/hub-pairing.d.ts +5 -0
  116. package/system/dist/kernel/moleculer/mesh-mtls/pairing/index.d.ts +1 -1
  117. package/system/dist/kernel/moleculer/mesh-mtls/pairing/pairing-protocol.d.ts +2 -0
  118. package/system/dist/{legacy-integration-rows-door-D_tfRhsx.js → legacy-integration-rows-door-i0gANn4l.js} +1 -1
  119. package/system/dist/{legacy-integration-rows-door-tX6Qktxd.mjs → legacy-integration-rows-door-lRhfbNBc.mjs} +1 -1
  120. package/system/dist/{rename-composition-block-DNhbAonr.js → rename-composition-block-BRy-9srI.js} +1 -1
  121. package/system/dist/{rename-composition-block-COaMxshT.mjs → rename-composition-block-C2IbabFp.mjs} +1 -1
  122. package/system/dist/{restore-archive-BMqp_hMT.mjs → restore-archive-CkyWtDIi.mjs} +1 -1
  123. package/system/dist/{restore-archive-Dbzuv5hK.js → restore-archive-_y4JaVgy.js} +1 -1
  124. package/system/dist/{wal-maintenance-CWODOTsa.js → wal-maintenance-BfkwceLa.js} +0 -0
  125. package/system/dist/{wal-maintenance-ITsLGvFA.mjs → wal-maintenance-Dn2cx4Km.mjs} +0 -0
  126. package/system/package.json +1 -1
@@ -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-DhbzVygm.js");
6
+ const require_dist = require("../../dist-DVrLQr6W.js");
7
7
  const require_formatter = require("../../formatter-xbxeV4GD.js");
8
8
  //#region src/builtins/console-logging/console-destination.ts
9
9
  var LEVEL_RANK = {
@@ -1,4 +1,4 @@
1
- import { Ti as logDestinationCapability, ps as BaseAddon } from "../../dist-CIyyHwVx.mjs";
1
+ import { Ti as logDestinationCapability, ps as BaseAddon } from "../../dist-B8dBvJJK.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-DkYZ4LXp.mjs";
3
3
  //#region src/builtins/console-logging/console-destination.ts
4
4
  var LEVEL_RANK = {
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-DhbzVygm.js");
3
+ const require_dist = require("../../dist-DVrLQr6W.js");
4
4
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
5
- const require_composition_sources = require("../../composition-sources-BzM19ASO.js");
6
- const require_capture_engine = require("../../capture-engine-1A7HAX3x.js");
5
+ const require_composition_sources = require("../../composition-sources-JwBPIhdO.js");
6
+ const require_capture_engine = require("../../capture-engine-6_V-PR8O.js");
7
7
  const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
8
8
  const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
9
9
  const require_cap_call_scope = require("../../cap-call-scope-8eiugfLl.js");
@@ -1,7 +1,7 @@
1
- import { $o as helperMembers, $r as internalActionId, Ba as schedulersCapability, Bi as normalizeActionUnits, Br as fanPresetsCapability, Bt as PowerSourceInfoSchema, C as COMPOSER_RUNNER_ID, Cc as hydrateSchema, Co as validateSchedulerInput, Ea as resolveHeroLayout, Fc as isSecretRefOwnedBy, Gn as checkTemplatePayload, Hi as normalizeCoreBlockWrite, In as buildHeroModel, Jc as resolveSecretMarkers, Jn as collectWhenMirrorSources, Jo as compositionSourceKey, Kt as REMOTE_MEDIA_COMMANDS, La as runSteps, Ls as RecordIntegrationInstances, M as CoreBlockSchema, Ma as resolveRemoteSource, Mn as buildActionSteps, Mo as COMPOSER_ADDON_ID, Mr as evaluateStepCondition, Nc as isSecretMarker, Nn as buildCapabilityLookup, No as CompositionSchema, Nr as evaluateWhenTree, Oo as weekdayOfLocalDate, Pa as resolveStepArgs, Po as DAY_MS, Qc as secretTreeFromSchema, Qr as integrationInstancesCapability, St as INTERNAL_ACTION_PREFIX, T as CORE_BLOCK_ADDON_PREFIX, Ta as resolveCoreBlockFiles, Tn as appendTrace, Ui as normalizeStepTargets, Uo as composedDeviceRef, Ur as findChannelSource, Vi as normalizeCapStep, Vn as capUnitResolver, Wa as seedInstanceOnce, Wo as composedDeviceStableId, Wt as QuantityUnitError, Xt as RemoteLayoutPayloadSchema, Yc as ruleFireOfClaim, Ys as actionEffect, Yt as RemoteAssumedStateSchema, Za as siteFor, Zn as compileScalarOverride, Zr as heroLayoutCapability, Zt as RunningStateStatusSchema, _a as remoteCapability, _c as entryBody, _n as actionsCapability, _o as timedRunSeconds, _r as describeComposableCaps, ac as collectSecretMarkerRefs, al as vocabActionIdFor, ar as coreBlockSourceKind, at as EMPTY_AUTOMATION_STATE, ba as replacedFieldKeys, bi as localDateOf, c as ActionError, cc as commandOrigin$1, ci as isInternalActionId, ct as FAN_CAPTURE_FIELDS, d as ActionTargetResolver, dc as defineAddonMigrations, dl as errMsg$1, dn as TemplateKindSchema, er as compositionSourceRefs, es as historyRetentionFromSettings, et as DeclaredDevices, f as ActionVariableSchema, fa as readStoredRemoteConfig, fo as templateCapability, ft as FanPresetSchema, gn as actionWaitTotalMs, go as timedRunQuickRun, h as BUILTIN_REMOTE_COMPONENTS, hn as actionSourceCapability, ho as timedRunMaxIn, ia as powerSourceLinkOfComposition, ir as coreBlockIdFromAddonId, j as ControlStatusSchema, jo as zoneOnlySite, jt as MediaPlayerStatusSchema, k as ConditionMirror, l as ActionMinDelaySecSchema, la as projectDeviceRow, lr as customKeyOfRole, m as AutomationStateDocSchema, mc as defineRecordKinds, mi as kebabToCamel, mo as timedRunLimitOf, n as ACTION_TARGET_INVALIDATION_EVENTS, nn as SchedulerSchema, nr as coreBlockAddonId, oa as problemsBlockSave, or as coreBlocksCapability, ot as EMPTY_REMOTE_ASSUMED_STATE, pc as defineEntryKind, pl as EventCategory$1, po as timedRunCapability, ps as BaseAddon, qi as occurrenceOn, qn as collectDeviceTemplates, ra as powerSourceCapability, rl as transformSecretWrite, rr as coreBlockComposition, s as ALL_CAPABILITY_DEFINITIONS, st as EMPTY_REMOTE_CONFIG, ta as planComposition, tn as SchedulerError, to as stableIdMapOf, u as ActionStepSchema, ua as proposeRunningThreshold, ul as DeviceType$1, un as SwitchStatusSchema, ut as FanControlStatusSchema, va as remoteLayoutComponentsCapability, vn as addonIdOfActionId, vo as toTimings, w as CORE_BLOCKS_ADDON_ID, wa as resolveCoreBlockEntry, wi as lockDoorLinkOfComposition, xa as resolveActionVariables, xo as validateComposition, xt as IDLE_ACTION_STATUS, ya as remoteSourceSteps, z as DEFAULT_HOLD_OVERRIDE, zi as nextOccurrence, zo as HelperMemberSchema } from "../../dist-CIyyHwVx.mjs";
1
+ import { $o as helperMembers, $r as internalActionId, Ba as schedulersCapability, Bi as normalizeActionUnits, Br as fanPresetsCapability, Bt as PowerSourceInfoSchema, C as COMPOSER_RUNNER_ID, Cc as hydrateSchema, Co as validateSchedulerInput, Ea as resolveHeroLayout, Fc as isSecretRefOwnedBy, Gn as checkTemplatePayload, Hi as normalizeCoreBlockWrite, In as buildHeroModel, Jc as resolveSecretMarkers, Jn as collectWhenMirrorSources, Jo as compositionSourceKey, Kt as REMOTE_MEDIA_COMMANDS, La as runSteps, Ls as RecordIntegrationInstances, M as CoreBlockSchema, Ma as resolveRemoteSource, Mn as buildActionSteps, Mo as COMPOSER_ADDON_ID, Mr as evaluateStepCondition, Nc as isSecretMarker, Nn as buildCapabilityLookup, No as CompositionSchema, Nr as evaluateWhenTree, Oo as weekdayOfLocalDate, Pa as resolveStepArgs, Po as DAY_MS, Qc as secretTreeFromSchema, Qr as integrationInstancesCapability, St as INTERNAL_ACTION_PREFIX, T as CORE_BLOCK_ADDON_PREFIX, Ta as resolveCoreBlockFiles, Tn as appendTrace, Ui as normalizeStepTargets, Uo as composedDeviceRef, Ur as findChannelSource, Vi as normalizeCapStep, Vn as capUnitResolver, Wa as seedInstanceOnce, Wo as composedDeviceStableId, Wt as QuantityUnitError, Xt as RemoteLayoutPayloadSchema, Yc as ruleFireOfClaim, Ys as actionEffect, Yt as RemoteAssumedStateSchema, Za as siteFor, Zn as compileScalarOverride, Zr as heroLayoutCapability, Zt as RunningStateStatusSchema, _a as remoteCapability, _c as entryBody, _n as actionsCapability, _o as timedRunSeconds, _r as describeComposableCaps, ac as collectSecretMarkerRefs, al as vocabActionIdFor, ar as coreBlockSourceKind, at as EMPTY_AUTOMATION_STATE, ba as replacedFieldKeys, bi as localDateOf, c as ActionError, cc as commandOrigin$1, ci as isInternalActionId, ct as FAN_CAPTURE_FIELDS, d as ActionTargetResolver, dc as defineAddonMigrations, dl as errMsg$1, dn as TemplateKindSchema, er as compositionSourceRefs, es as historyRetentionFromSettings, et as DeclaredDevices, f as ActionVariableSchema, fa as readStoredRemoteConfig, fo as templateCapability, ft as FanPresetSchema, gn as actionWaitTotalMs, go as timedRunQuickRun, h as BUILTIN_REMOTE_COMPONENTS, hn as actionSourceCapability, ho as timedRunMaxIn, ia as powerSourceLinkOfComposition, ir as coreBlockIdFromAddonId, j as ControlStatusSchema, jo as zoneOnlySite, jt as MediaPlayerStatusSchema, k as ConditionMirror, l as ActionMinDelaySecSchema, la as projectDeviceRow, lr as customKeyOfRole, m as AutomationStateDocSchema, mc as defineRecordKinds, mi as kebabToCamel, mo as timedRunLimitOf, n as ACTION_TARGET_INVALIDATION_EVENTS, nn as SchedulerSchema, nr as coreBlockAddonId, oa as problemsBlockSave, or as coreBlocksCapability, ot as EMPTY_REMOTE_ASSUMED_STATE, pc as defineEntryKind, pl as EventCategory$1, po as timedRunCapability, ps as BaseAddon, qi as occurrenceOn, qn as collectDeviceTemplates, ra as powerSourceCapability, rl as transformSecretWrite, rr as coreBlockComposition, s as ALL_CAPABILITY_DEFINITIONS, st as EMPTY_REMOTE_CONFIG, ta as planComposition, tn as SchedulerError, to as stableIdMapOf, u as ActionStepSchema, ua as proposeRunningThreshold, ul as DeviceType$1, un as SwitchStatusSchema, ut as FanControlStatusSchema, va as remoteLayoutComponentsCapability, vn as addonIdOfActionId, vo as toTimings, w as CORE_BLOCKS_ADDON_ID, wa as resolveCoreBlockEntry, wi as lockDoorLinkOfComposition, xa as resolveActionVariables, xo as validateComposition, xt as IDLE_ACTION_STATUS, ya as remoteSourceSteps, z as DEFAULT_HOLD_OVERRIDE, zi as nextOccurrence, zo as HelperMemberSchema } from "../../dist-B8dBvJJK.mjs";
2
2
  import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
3
- import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-CyJ0d6Sc.mjs";
4
- import { i as capSeriesKey } from "../../capture-engine-B0yQx6hA.mjs";
3
+ import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-C-iX_Uuu.mjs";
4
+ import { i as capSeriesKey } from "../../capture-engine-cp3my4VK.mjs";
5
5
  import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
6
6
  import { n as unwrapStoredValue, t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
7
7
  import { n as readCurrentCommandOrigin } from "../../cap-call-scope-Bic6Ekfw.mjs";
@@ -3,8 +3,8 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-DhbzVygm.js");
7
- const require_capture_engine = require("../../capture-engine-1A7HAX3x.js");
6
+ const require_dist = require("../../dist-DVrLQr6W.js");
7
+ const require_capture_engine = require("../../capture-engine-6_V-PR8O.js");
8
8
  const require_retention = require("../../retention-BcOSL6b9.js");
9
9
  let node_crypto = require("node:crypto");
10
10
  //#region src/builtins/device-history/capture/point-writer.ts
@@ -1,5 +1,5 @@
1
- import { Ac as isReadingQuantity, Bs as RecordTooLargeError, Cr as deviceRemovalHookCapability, Dr as deviceTransitionsCapability, En as armRemovalReconcile, H as DEVICE_HISTORY_ENERGY_KEY, Sc as historyUnitFor, _t as HISTORY_ITEM_CATALOG, bs as DeviceTransitionSchema, fs as wattMillisecondsToKwh, gc as emitReadiness, gt as HISTORY_CATALOG, mc as defineRecordKinds, pl as EventCategory, ps as BaseAddon, tt as DeviceRunSchema, ul as DeviceType, wr as deviceRunsCapability, ws as InvalidRecordError, xr as deviceHistoryCapability } from "../../dist-CIyyHwVx.mjs";
2
- import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-B0yQx6hA.mjs";
1
+ import { Ac as isReadingQuantity, Bs as RecordTooLargeError, Cr as deviceRemovalHookCapability, Dr as deviceTransitionsCapability, En as armRemovalReconcile, H as DEVICE_HISTORY_ENERGY_KEY, Sc as historyUnitFor, _t as HISTORY_ITEM_CATALOG, bs as DeviceTransitionSchema, fs as wattMillisecondsToKwh, gc as emitReadiness, gt as HISTORY_CATALOG, mc as defineRecordKinds, pl as EventCategory, ps as BaseAddon, tt as DeviceRunSchema, ul as DeviceType, wr as deviceRunsCapability, ws as InvalidRecordError, xr as deviceHistoryCapability } from "../../dist-B8dBvJJK.mjs";
2
+ import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-cp3my4VK.mjs";
3
3
  import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-CUOVI1p7.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  //#region src/builtins/device-history/capture/point-writer.ts
@@ -20,7 +20,7 @@
20
20
  * original class methods are preserved; the addon keeps thin delegator
21
21
  * methods over these functions.
22
22
  */
23
- import type { AddonContext, CapabilityDefinition, DeviceBindingEntry, DeviceConfigSpec, DeviceSettingsContribution, ICapabilityRegistry, IDevice, InferProvider, StreamProfile, StreamProfilePatch } from "@camstack/types";
23
+ import type { AddonContext, CapabilityDefinition, DeviceBindingEntry, DeviceConfigSpec, DeviceSettingsContribution, ICapabilityRegistry, IDevice, InferProvider, StreamProfile, StreamProfilePatch, WireableField } from "@camstack/types";
24
24
  import { deviceManagerCapability } from "@camstack/types";
25
25
  import { type BindingsDeps, type RemoteNativeCaps } from "./device-bindings-store.js";
26
26
  import type { ContributionShape, DriverConfigSchemaResult } from "./device-meta-types.js";
@@ -317,6 +317,30 @@ export declare function listBindableCapsForDeviceType(deps: AggregationDeps, inp
317
317
  capName: string;
318
318
  wrappers: string[];
319
319
  }>>;
320
+ /** One wireable-cap entry of the `getWireableFields` wire shape. */
321
+ interface WireableCapEntry {
322
+ cap: string;
323
+ fields: Array<{
324
+ path: string;
325
+ kind: WireableField["kind"];
326
+ enumValues?: string[];
327
+ item?: boolean;
328
+ quantity?: WireableField["quantity"];
329
+ }>;
330
+ itemArray?: {
331
+ path: string;
332
+ keyField: string;
333
+ };
334
+ }
335
+ /**
336
+ * Build the wireable-cap entry for one capability definition: the status
337
+ * schema's scalar leaf fields plus — for an item-array cap
338
+ * (`status.itemArray`) — the per-item fields tagged `item: true` (a link
339
+ * targeting one must carry a `target.itemKey`) and the cap-level `itemArray`
340
+ * descriptor so the UI can address items. Returns null when the cap exposes
341
+ * nothing wireable (no status schema / no leaf fields).
342
+ */
343
+ export declare function wireableEntryForDef(capName: string, def: CapabilityDefinition): WireableCapEntry | null;
320
344
  /**
321
345
  * Per-device wireable-field catalog — the domain status fields a device's
322
346
  * bound caps expose, for the operator's cross-device wiring UI. Binding-driven:
@@ -186,6 +186,12 @@ export declare class DeviceManagerAddon extends BaseAddon {
186
186
  listDeviceIdsByCaps(input: ListDeviceIdsByCapsInput): Promise<number[]>;
187
187
  /** Build the dependency context the extracted aggregation functions consume. */
188
188
  private get aggregationDeps();
189
+ /**
190
+ * `deviceManager.search` — the picker query (see `device-search.ts`). The
191
+ * fleet is `listAll`, the values are the `getWireableFields` derivation over
192
+ * each device's own bindings, the readings are the status aggregate.
193
+ */
194
+ private searchDevices;
189
195
  getDeviceAggregate(deviceId: number, kind: "settings" | "live"): Promise<ContributionShape | null>;
190
196
  private getDeviceStatusAggregate;
191
197
  updateDeviceField(input: {
@@ -3,10 +3,10 @@ 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-DhbzVygm.js");
6
+ const require_dist = require("../../dist-DVrLQr6W.js");
7
7
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
8
8
  const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
9
- const require_rename_composition_block = require("../../rename-composition-block-DNhbAonr.js");
9
+ const require_rename_composition_block = require("../../rename-composition-block-BRy-9srI.js");
10
10
  const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
11
11
  const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
12
12
  const require_retired_settings_keys = require("../../retired-settings-keys-C8nOOr5H.js");
@@ -457,6 +457,7 @@ function toDeviceInfo(addonId, device, metadata = null, metaRow = null) {
457
457
  ...metaRow?.linkDeviceId !== void 0 ? { linkDeviceId: metaRow.linkDeviceId } : {},
458
458
  ...metaRow?.primaryChildEntityId !== void 0 ? { primaryChildEntityId: metaRow.primaryChildEntityId } : {},
459
459
  ...metaRow?.childLayout !== void 0 ? { childLayout: metaRow.childLayout } : {},
460
+ ...metaRow?.primaryChildPreference !== void 0 ? { primaryChildPreference: metaRow.primaryChildPreference } : {},
460
461
  ...metaRow?.display !== void 0 ? { display: metaRow.display } : {}
461
462
  };
462
463
  }
@@ -2901,6 +2902,7 @@ async function listAll(pctx, input) {
2901
2902
  ...m.linkDeviceId !== void 0 ? { linkDeviceId: m.linkDeviceId } : {},
2902
2903
  ...m.primaryChildEntityId !== void 0 ? { primaryChildEntityId: m.primaryChildEntityId } : {},
2903
2904
  ...m.childLayout !== void 0 ? { childLayout: m.childLayout } : {},
2905
+ ...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
2904
2906
  ...m.display !== void 0 ? { display: m.display } : {},
2905
2907
  ...(() => {
2906
2908
  if (slim) return {};
@@ -2952,6 +2954,7 @@ async function getDevice(pctx, input) {
2952
2954
  ...m.linkDeviceId !== void 0 ? { linkDeviceId: m.linkDeviceId } : {},
2953
2955
  ...m.primaryChildEntityId !== void 0 ? { primaryChildEntityId: m.primaryChildEntityId } : {},
2954
2956
  ...m.childLayout !== void 0 ? { childLayout: m.childLayout } : {},
2957
+ ...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
2955
2958
  ...m.display !== void 0 ? { display: m.display } : {},
2956
2959
  ...sourceInfoGetDevice !== void 0 ? { sourceInfo: sourceInfoGetDevice } : {}
2957
2960
  };
@@ -3030,6 +3033,7 @@ function projectChildren(pctx, parentDeviceId, ownerAddonId, childRows, liveChil
3030
3033
  ...m.linkDeviceId !== void 0 ? { linkDeviceId: m.linkDeviceId } : {},
3031
3034
  ...m.primaryChildEntityId !== void 0 ? { primaryChildEntityId: m.primaryChildEntityId } : {},
3032
3035
  ...m.childLayout !== void 0 ? { childLayout: m.childLayout } : {},
3036
+ ...m.primaryChildPreference !== void 0 ? { primaryChildPreference: m.primaryChildPreference } : {},
3033
3037
  ...m.display !== void 0 ? { display: m.display } : {},
3034
3038
  ...sourceInfoChild !== void 0 ? { sourceInfo: sourceInfoChild } : {}
3035
3039
  });
@@ -4512,6 +4516,273 @@ async function getWireableFields(deps, input) {
4512
4516
  return { caps };
4513
4517
  }
4514
4518
  //#endregion
4519
+ //#region src/builtins/device-manager/device-search.ts
4520
+ /** A shortlist, not a second list. */
4521
+ var SUGGESTED_MAX = 8;
4522
+ function sortKeyOf(c) {
4523
+ return [
4524
+ c.compatible ? 0 : 1,
4525
+ c.device.type,
4526
+ c.device.name.toLowerCase(),
4527
+ c.device.id
4528
+ ];
4529
+ }
4530
+ function compareKeys(a, b) {
4531
+ if (a[0] !== b[0]) return a[0] - b[0];
4532
+ if (a[1] !== b[1]) return a[1] < b[1] ? -1 : 1;
4533
+ if (a[2] !== b[2]) return a[2] < b[2] ? -1 : 1;
4534
+ return a[3] - b[3];
4535
+ }
4536
+ function encodeCursor(key) {
4537
+ return Buffer.from(JSON.stringify(key), "utf8").toString("base64url");
4538
+ }
4539
+ function decodeCursor(cursor) {
4540
+ try {
4541
+ const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
4542
+ if (!Array.isArray(parsed) || parsed.length !== 4) return null;
4543
+ const c = parsed[0];
4544
+ const t = parsed[1];
4545
+ const n = parsed[2];
4546
+ const i = parsed[3];
4547
+ if (typeof c !== "number" || typeof t !== "string" || typeof n !== "string") return null;
4548
+ if (typeof i !== "number") return null;
4549
+ return [
4550
+ c,
4551
+ t,
4552
+ n,
4553
+ i
4554
+ ];
4555
+ } catch {
4556
+ return null;
4557
+ }
4558
+ }
4559
+ /** `colourTemperature` / `battery_level` → `Colour temperature` / `Battery level`. */
4560
+ function labelOfPath(path) {
4561
+ const words = (path.split(".").pop() ?? path).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim().toLowerCase();
4562
+ return words.length === 0 ? path : words.charAt(0).toUpperCase() + words.slice(1);
4563
+ }
4564
+ function readAtPath(status, path) {
4565
+ let cursor = status;
4566
+ for (const segment of path.split(".")) {
4567
+ if (cursor === null || typeof cursor !== "object") return null;
4568
+ cursor = Reflect.get(cursor, segment);
4569
+ }
4570
+ if (typeof cursor === "string") return cursor;
4571
+ if (typeof cursor === "number" || typeof cursor === "boolean") return String(cursor);
4572
+ return null;
4573
+ }
4574
+ function matches(selected, value) {
4575
+ if (selected === void 0 || selected.length === 0) return true;
4576
+ return value !== null && selected.includes(value);
4577
+ }
4578
+ function facetList(counts) {
4579
+ return [...counts.entries()].map(([value, count]) => ({
4580
+ value,
4581
+ count
4582
+ })).sort((a, b) => b.count - a.count || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0));
4583
+ }
4584
+ function bump(counts, key) {
4585
+ if (key === null) return;
4586
+ counts.set(key, (counts.get(key) ?? 0) + 1);
4587
+ }
4588
+ async function searchDevices(deps, input) {
4589
+ const [fleet, labels] = await Promise.all([deps.listDevices(), deps.integrationLabels()]);
4590
+ const requiredCaps = input.requires?.caps ?? [];
4591
+ const mode = input.requires?.mode ?? "any";
4592
+ const candidates = fleet.map((device) => {
4593
+ const integrationId = device.integrationId ?? null;
4594
+ const integrationLabel = integrationId === null ? null : labels.get(integrationId) ?? null;
4595
+ return {
4596
+ device,
4597
+ integrationId,
4598
+ integrationLabel,
4599
+ haystack: [
4600
+ device.name,
4601
+ device.location ?? "",
4602
+ device.type,
4603
+ integrationId ?? "",
4604
+ integrationLabel ?? "",
4605
+ String(device.id)
4606
+ ].join("\0").toLowerCase(),
4607
+ matchedCaps: [],
4608
+ compatible: requiredCaps.length === 0
4609
+ };
4610
+ });
4611
+ if (input.ids !== void 0) return resolveIds(deps, input, candidates);
4612
+ const needle = (input.text ?? "").trim().toLowerCase();
4613
+ const textPass = needle === "" ? candidates : candidates.filter((c) => c.haystack.includes(needle));
4614
+ if (requiredCaps.length > 0) {
4615
+ const bound = await deps.boundCaps(textPass.map((c) => c.device.id));
4616
+ for (const c of textPass) {
4617
+ const have = new Set(bound.get(c.device.id) ?? []);
4618
+ const matched = requiredCaps.filter((cap) => have.has(cap));
4619
+ c.matchedCaps = matched;
4620
+ c.compatible = mode === "all" ? matched.length === requiredCaps.length : matched.length > 0;
4621
+ }
4622
+ }
4623
+ const locationCounts = /* @__PURE__ */ new Map();
4624
+ const integrationCounts = /* @__PURE__ */ new Map();
4625
+ const typeCounts = /* @__PURE__ */ new Map();
4626
+ const listed = [];
4627
+ let compatibleTotal = 0;
4628
+ let hiddenIncompatible = 0;
4629
+ const filters = input.filters;
4630
+ for (const c of textPass) {
4631
+ const okLocation = matches(filters?.locations, c.device.location);
4632
+ const okIntegration = matches(filters?.integrationIds, c.integrationId);
4633
+ const okType = matches(filters?.types, c.device.type);
4634
+ if (c.compatible) {
4635
+ if (okIntegration && okType) bump(locationCounts, c.device.location);
4636
+ if (okLocation && okType) bump(integrationCounts, c.integrationId);
4637
+ if (okLocation && okIntegration) bump(typeCounts, c.device.type);
4638
+ }
4639
+ if (!(okLocation && okIntegration && okType)) continue;
4640
+ if (c.compatible) {
4641
+ compatibleTotal += 1;
4642
+ listed.push(c);
4643
+ } else {
4644
+ hiddenIncompatible += 1;
4645
+ if (input.includeIncompatible === true) listed.push(c);
4646
+ }
4647
+ }
4648
+ const keyed = listed.map((c) => ({
4649
+ c,
4650
+ key: sortKeyOf(c)
4651
+ })).sort((a, b) => compareKeys(a.key, b.key));
4652
+ const limit = Math.min(input.limit ?? 50, 200);
4653
+ let start = 0;
4654
+ if (input.cursor !== void 0 && input.cursor !== null) {
4655
+ const after = decodeCursor(input.cursor);
4656
+ if (after === null) deps.logger.warn("deviceManager.search: undecodable cursor — restarting from the first page");
4657
+ else {
4658
+ const next = keyed.findIndex((k) => compareKeys(k.key, after) > 0);
4659
+ start = next === -1 ? keyed.length : next;
4660
+ }
4661
+ }
4662
+ const page = keyed.slice(start, start + limit).map((k) => k.c);
4663
+ const last = keyed[start + limit - 1];
4664
+ const nextCursor = start + limit < keyed.length && last !== void 0 ? encodeCursor(last.key) : null;
4665
+ const suggestedCandidates = start === 0 ? suggestFor(input, keyed, fleet) : [];
4666
+ const items = await withValues(deps, [...page, ...suggestedCandidates], requiredCaps);
4667
+ const byId = new Map(items.map((i) => [i.id, i]));
4668
+ const facets = {
4669
+ locations: facetList(locationCounts),
4670
+ integrations: [...integrationCounts.entries()].map(([id, count]) => ({
4671
+ id,
4672
+ label: labels.get(id) ?? id,
4673
+ count
4674
+ })).sort((a, b) => b.count - a.count || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)),
4675
+ types: facetList(typeCounts)
4676
+ };
4677
+ return {
4678
+ items: page.map((c) => byId.get(c.device.id)).filter(isItem),
4679
+ nextCursor,
4680
+ total: listed.length,
4681
+ compatibleTotal,
4682
+ fleetTotal: fleet.length,
4683
+ hiddenIncompatible,
4684
+ facets,
4685
+ suggested: suggestedCandidates.map((c) => byId.get(c.device.id)).filter(isItem),
4686
+ missingIds: []
4687
+ };
4688
+ }
4689
+ function isItem(value) {
4690
+ return value !== void 0;
4691
+ }
4692
+ /** Compatible devices at the context device's location, in list order. */
4693
+ function suggestFor(input, keyed, fleet) {
4694
+ if (input.contextDeviceId === void 0) return [];
4695
+ const context = fleet.find((d) => d.id === input.contextDeviceId);
4696
+ if (context === void 0 || context.location === null) return [];
4697
+ return keyed.map((k) => k.c).filter((c) => c.compatible && c.device.location === context.location && c.device.id !== context.id).slice(0, SUGGESTED_MAX);
4698
+ }
4699
+ async function resolveIds(deps, input, candidates) {
4700
+ const requiredCaps = input.requires?.caps ?? [];
4701
+ const mode = input.requires?.mode ?? "any";
4702
+ const byId = new Map(candidates.map((c) => [c.device.id, c]));
4703
+ const asked = [...new Set(input.ids ?? [])];
4704
+ const found = [];
4705
+ const missingIds = [];
4706
+ for (const id of asked) {
4707
+ const c = byId.get(id);
4708
+ if (c === void 0) missingIds.push(id);
4709
+ else found.push(c);
4710
+ }
4711
+ if (requiredCaps.length > 0 && found.length > 0) {
4712
+ const bound = await deps.boundCaps(found.map((c) => c.device.id));
4713
+ for (const c of found) {
4714
+ const have = new Set(bound.get(c.device.id) ?? []);
4715
+ c.matchedCaps = requiredCaps.filter((cap) => have.has(cap));
4716
+ c.compatible = mode === "all" ? c.matchedCaps.length === requiredCaps.length : c.matchedCaps.length > 0;
4717
+ }
4718
+ }
4719
+ const items = await withValues(deps, found, requiredCaps);
4720
+ return {
4721
+ items,
4722
+ nextCursor: null,
4723
+ total: items.length,
4724
+ compatibleTotal: found.filter((c) => c.compatible).length,
4725
+ fleetTotal: candidates.length,
4726
+ hiddenIncompatible: found.filter((c) => !c.compatible).length,
4727
+ facets: {
4728
+ locations: [],
4729
+ integrations: [],
4730
+ types: []
4731
+ },
4732
+ suggested: [],
4733
+ missingIds
4734
+ };
4735
+ }
4736
+ /**
4737
+ * Build the wire items for a set of candidates, reading live status once for
4738
+ * the whole set. A failed read is `reading: null` on that value — the device
4739
+ * and its values stay listed.
4740
+ */
4741
+ async function withValues(deps, candidates, requiredCaps) {
4742
+ const unique = [...new Map(candidates.map((c) => [c.device.id, c])).values()];
4743
+ let status = {};
4744
+ if (requiredCaps.length > 0 && unique.some((c) => c.compatible && c.matchedCaps.length > 0)) try {
4745
+ status = await deps.readStatus(unique.filter((c) => c.compatible && c.matchedCaps.length > 0).map((c) => c.device.id), requiredCaps);
4746
+ } catch (err) {
4747
+ deps.logger.warn("deviceManager.search: status read failed — readings left empty", { meta: {
4748
+ error: require_dist.errMsg(err),
4749
+ devices: unique.length
4750
+ } });
4751
+ }
4752
+ return unique.map((c) => {
4753
+ const values = [];
4754
+ for (const cap of c.compatible ? c.matchedCaps : []) {
4755
+ const fields = deps.fieldsOf(cap);
4756
+ if (fields === null) continue;
4757
+ const capStatus = status[String(c.device.id)]?.[cap];
4758
+ for (const f of fields.fields) {
4759
+ if (f.item === true) continue;
4760
+ values.push({
4761
+ cap,
4762
+ path: f.path,
4763
+ label: labelOfPath(f.path),
4764
+ reading: readAtPath(capStatus, f.path),
4765
+ unit: null,
4766
+ ...f.quantity !== void 0 ? { quantity: f.quantity } : {}
4767
+ });
4768
+ }
4769
+ }
4770
+ const d = c.device;
4771
+ return {
4772
+ id: d.id,
4773
+ name: d.name,
4774
+ type: d.type,
4775
+ location: d.location,
4776
+ integrationId: c.integrationId,
4777
+ integrationLabel: c.integrationLabel,
4778
+ online: d.online,
4779
+ disabled: d.disabled,
4780
+ compatible: c.compatible,
4781
+ values
4782
+ };
4783
+ });
4784
+ }
4785
+ //#endregion
4515
4786
  //#region src/builtins/device-manager/discovery-orchestrator.ts
4516
4787
  /** A provider without the method (an older addon) or one that fails it is a legacy provider. */
4517
4788
  async function declaredModes(provider) {
@@ -5046,6 +5317,7 @@ function toLinkCandidate(row) {
5046
5317
  type,
5047
5318
  stableId: row.meta.stableId,
5048
5319
  ...row.meta.primaryChildEntityId !== void 0 ? { primaryChildEntityId: row.meta.primaryChildEntityId } : {},
5320
+ ...row.meta.primaryChildPreference !== void 0 ? { primaryChildPreference: row.meta.primaryChildPreference } : {},
5049
5321
  ...row.meta.role !== void 0 ? { role: row.meta.role } : {},
5050
5322
  name: row.meta.name
5051
5323
  };
@@ -6466,10 +6738,10 @@ async function reloadMigratedDevices(pctx, targets) {
6466
6738
  * removeDevice), config persistence (persistConfig, loadConfig), the meta
6467
6739
  * surface load (loadMeta, loadRuntimeState), every meta setter (setName,
6468
6740
  * setLocation, setType, setIntegrationId, setLinkDeviceId,
6469
- * setPrimaryChildEntityId, setChildLayout, setRole, setDisplay,
6470
- * applyInitialMeta, setMetadata, setDisabled), and the location registry
6471
- * (listLocations, addLocation, removeLocation, renameLocation) with its icon
6472
- * map (listLocationIcons, setLocationIcon).
6741
+ * setPrimaryChildEntityId, setChildLayout, setPrimaryChildPreference,
6742
+ * setRole, setDisplay, applyInitialMeta, setMetadata, setDisabled), and the
6743
+ * location registry (listLocations, addLocation, removeLocation,
6744
+ * renameLocation) with its icon map (listLocationIcons, setLocationIcon).
6473
6745
  *
6474
6746
  * EXACT ordering and side effects preserved — notably registerDevice's
6475
6747
  * name-precedence reconcile + field-preservation spreads, the
@@ -7448,6 +7720,32 @@ async function setChildLayout(pctx, input) {
7448
7720
  });
7449
7721
  }
7450
7722
  /**
7723
+ * Set (or replace) a container's provider-declared primary-child preference:
7724
+ * accessory `childKey`s, most preferred first. Mirrors {@link setChildLayout}.
7725
+ * The operator's `primaryChildEntityId` still wins over it at resolution.
7726
+ */
7727
+ async function setPrimaryChildPreference(pctx, input) {
7728
+ const { deviceId, primaryChildPreference } = input;
7729
+ await pctx.metaStore.withMetaWriteLock(async () => {
7730
+ if (!await pctx.metaStore.resolvePersistedById(deviceId)) throw new Error(`[device-manager] setPrimaryChildPreference: unknown device id=${deviceId}`);
7731
+ await pctx.metaStore.rows.patch(deviceId, { primaryChildPreference });
7732
+ });
7733
+ pctx.host.ctx.eventBus.emit({
7734
+ id: (0, node_crypto.randomUUID)(),
7735
+ timestamp: /* @__PURE__ */ new Date(),
7736
+ source: {
7737
+ type: "device",
7738
+ id: deviceId
7739
+ },
7740
+ category: require_dist.EventCategory.DeviceMetaChanged,
7741
+ data: {
7742
+ deviceId,
7743
+ field: "primaryChildPreference",
7744
+ value: primaryChildPreference
7745
+ }
7746
+ });
7747
+ }
7748
+ /**
7451
7749
  * Stamp (or update) the semantic role on the device's meta row.
7452
7750
  * Called by the kernel's `create()` / `spawnAccessoryChild`
7453
7751
  * pre-seed when `initialMeta.role` is set (analogous to
@@ -9643,6 +9941,10 @@ var DEVICE_ROWS_COLUMNS = [
9643
9941
  name: "childLayout",
9644
9942
  type: "JSON"
9645
9943
  },
9944
+ {
9945
+ name: "primaryChildPreference",
9946
+ type: "JSON"
9947
+ },
9646
9948
  {
9647
9949
  name: "role",
9648
9950
  type: "TEXT"
@@ -9768,6 +10070,7 @@ function decodeDeviceRow(data) {
9768
10070
  const role = readString(data["role"]);
9769
10071
  const alias = readString(data["alias"]);
9770
10072
  const rawChildLayout = data["childLayout"];
10073
+ const primaryChildPreference = readStringArray(data["primaryChildPreference"]);
9771
10074
  const rawDisplay = data["display"];
9772
10075
  const rawMetadata = data["metadata"];
9773
10076
  return {
@@ -9788,6 +10091,7 @@ function decodeDeviceRow(data) {
9788
10091
  ...linkDeviceId !== void 0 ? { linkDeviceId } : {},
9789
10092
  ...primaryChildEntityId !== void 0 ? { primaryChildEntityId } : {},
9790
10093
  ...isChildLayout(rawChildLayout) ? { childLayout: rawChildLayout } : {},
10094
+ ...primaryChildPreference !== void 0 ? { primaryChildPreference } : {},
9791
10095
  ...role !== void 0 ? { role } : {},
9792
10096
  ...isPlainObject$1(rawDisplay) ? { display: toDisplayOverride(rawDisplay) } : {}
9793
10097
  },
@@ -9832,6 +10136,7 @@ function encodeDeviceRow(meta, extra = {}) {
9832
10136
  linkDeviceId: meta.linkDeviceId ?? null,
9833
10137
  primaryChildEntityId: meta.primaryChildEntityId ?? null,
9834
10138
  childLayout: meta.childLayout ?? null,
10139
+ primaryChildPreference: meta.primaryChildPreference === void 0 ? null : [...meta.primaryChildPreference],
9835
10140
  role: meta.role ?? null,
9836
10141
  display: meta.display ?? null
9837
10142
  };
@@ -13024,6 +13329,46 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
13024
13329
  ...this.deviceFormSecrets ? { deviceFormSecrets: this.deviceFormSecrets } : {}
13025
13330
  };
13026
13331
  }
13332
+ /**
13333
+ * `deviceManager.search` — the picker query (see `device-search.ts`). The
13334
+ * fleet is `listAll`, the values are the `getWireableFields` derivation over
13335
+ * each device's own bindings, the readings are the status aggregate.
13336
+ */
13337
+ searchDevices(pctx, input) {
13338
+ const registry = this.capabilityRegistry;
13339
+ return searchDevices({
13340
+ listDevices: () => listAll(pctx, { projection: "slim" }),
13341
+ boundCaps: async (deviceIds) => {
13342
+ const batch = await getBindingsBatch(this.bindingsDeps, { deviceIds });
13343
+ const out = /* @__PURE__ */ new Map();
13344
+ for (const { deviceId, entries } of batch) out.set(deviceId, entries.map((e) => e.capName).filter((cap) => {
13345
+ const def = registry?.getDefinition(cap);
13346
+ return def !== void 0 && def !== null && def.kind !== "wrapper";
13347
+ }));
13348
+ return out;
13349
+ },
13350
+ fieldsOf: (cap) => {
13351
+ const def = registry?.getDefinition(cap);
13352
+ return def ? wireableEntryForDef(cap, def) : null;
13353
+ },
13354
+ readStatus: (deviceIds, caps) => getDeviceStatusAggregateBatch(this.aggregationDeps, {
13355
+ deviceIds,
13356
+ caps
13357
+ }),
13358
+ integrationLabels: async () => {
13359
+ const api = this.ctx.api;
13360
+ if (api === void 0) return /* @__PURE__ */ new Map();
13361
+ try {
13362
+ const list = await api.integrations.list.query();
13363
+ return new Map(list.map((i) => [i.id, i.name]));
13364
+ } catch (err) {
13365
+ this.ctx.logger.warn("deviceManager.search: integration names unavailable", { meta: { error: require_dist.errMsg(err) } });
13366
+ return /* @__PURE__ */ new Map();
13367
+ }
13368
+ },
13369
+ logger: this.ctx.logger
13370
+ }, input);
13371
+ }
13027
13372
  async getDeviceAggregate(deviceId, kind) {
13028
13373
  return getDeviceAggregate(this.aggregationDeps, deviceId, kind);
13029
13374
  }
@@ -13205,6 +13550,7 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
13205
13550
  setLinkDeviceId: (input) => setLinkDeviceId(pctx, input),
13206
13551
  setPrimaryChildEntityId: (input) => setPrimaryChildEntityId(pctx, input),
13207
13552
  setChildLayout: (input) => setChildLayout(pctx, input),
13553
+ setPrimaryChildPreference: (input) => setPrimaryChildPreference(pctx, input),
13208
13554
  setRole: (input) => setRole(pctx, input),
13209
13555
  setDisplay: (input) => setDisplay(pctx, input),
13210
13556
  getRoleDisplayDefaults: (input) => getRoleDisplayDefaults(pctx, input),
@@ -13357,7 +13703,8 @@ var DeviceManagerAddon = class extends require_dist.BaseAddon {
13357
13703
  },
13358
13704
  getDeviceStatusAggregate: async (input) => this.getDeviceStatusAggregate(input),
13359
13705
  getDeviceStatusAggregateBatch: async (input) => getDeviceStatusAggregateBatch(this.aggregationDeps, input),
13360
- getWireableFields: (input) => getWireableFields(this.aggregationDeps, input)
13706
+ getWireableFields: (input) => getWireableFields(this.aggregationDeps, input),
13707
+ search: (input) => this.searchDevices(pctx, input)
13361
13708
  };
13362
13709
  this.ctx.logger.info("registered device-manager capability", { meta: { liveRegistry: registry !== null } });
13363
13710
  if (registry) {