@camstack/server 1.2.931 → 1.2.933

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 (30) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/api/trpc/generated-cap-routers.js +20 -0
  3. package/package.json +7 -51
  4. package/system/dist/{base-device-IuM1AwXZ.mjs → base-device-Bwiblqmn.mjs} +1 -1
  5. package/system/dist/{base-device-2sL1DMm1.js → base-device-C1z4zYGR.js} +1 -1
  6. package/system/dist/builtins/alerts/alerts.addon.js +2 -2
  7. package/system/dist/builtins/alerts/alerts.addon.mjs +2 -2
  8. package/system/dist/builtins/camera-grid/index.js +2 -2
  9. package/system/dist/builtins/camera-grid/index.mjs +2 -2
  10. package/system/dist/builtins/composer/composer.addon.js +5 -5
  11. package/system/dist/builtins/composer/composer.addon.mjs +5 -5
  12. package/system/dist/builtins/core-blocks/cap-links.d.ts +34 -0
  13. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +4 -0
  14. package/system/dist/builtins/core-blocks/core-blocks.addon.js +282 -8
  15. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +282 -8
  16. package/system/dist/builtins/device-manager/device-manager.addon.js +18 -4
  17. package/system/dist/builtins/device-manager/device-manager.addon.mjs +18 -4
  18. package/system/dist/{composition-sources-BEUWn2s_.mjs → composition-sources-B0QW4g86.mjs} +2 -2
  19. package/system/dist/{composition-sources-acfR4hDq.js → composition-sources-BtUx1MfU.js} +2 -2
  20. package/system/dist/{core-blocks.cap-BRPsLAij.mjs → core-blocks.cap-CnwBuf7E.mjs} +1524 -1267
  21. package/system/dist/{core-blocks.cap-BMeMCBrx.js → core-blocks.cap-DlEuHq-S.js} +1555 -1268
  22. package/system/dist/{error.cap-CSM_SRfR.mjs → error.cap-5zNPAgU2.mjs} +19 -2
  23. package/system/dist/{error.cap-DBhgPeWK.js → error.cap-BCqzFlo2.js} +24 -1
  24. package/system/dist/index.js +2 -2
  25. package/system/dist/index.mjs +2 -2
  26. package/system/dist/{prefix-walk-ifwg_ukx.mjs → prefix-walk-CRnbYJcC.mjs} +2 -2
  27. package/system/dist/{prefix-walk-BkMxoXpL.js → prefix-walk-DD1BM923.js} +2 -2
  28. package/system/dist/{rename-composition-block-BJsL58Ih.js → rename-composition-block-BRgyBO25.js} +20 -2
  29. package/system/dist/{rename-composition-block-OAtErZgq.mjs → rename-composition-block-BYRBlx-V.mjs} +20 -2
  30. package/system/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { r as MotionStatusSchema } from "../../stream-catalog.cap-Bp7SkgIf.mjs";
2
2
  import { _ as hydrateSchema, a as isSecretRefOwnedBy, b as EventCategory$1, f as defineAddonMigrations, i as collectSecretMarkerRefs, l as RecordIntegrationInstances, o as resolveSecretMarkers, r as secretTreeFromSchema, s as transformSecretWrite, t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
3
3
  import { W as isSecretMarker, Z as errMsg$1 } from "../../scoped-settings-DVWUIP7Z.mjs";
4
- import { $ as RemoteLayoutPayloadSchema, $n as unitsForQuantity, $t as FanPresetSchema, A as TemplateKindSchema, At as measurementFitsRole, B as SmokeStatusSchema, Bn as AutomationControlStatusSchema, Bt as timedRunRemaining, C as WaterHeaterStatusSchema, Cn as ContactStatusSchema, Ct as projectDeviceRow, D as VacuumControlStatusSchema, Dn as COMPOSER_RUNNER_ID, Dt as contactMeasurement, Et as resolveHeroSceneId, F as TamperStatusSchema, Fn as CarbonMonoxideStatusSchema, Ft as TimedRunStatusSchema, G as hasOwnRunningPowerDefaults, Gt as GroupStatusSchema, H as schedulersCapability, Hn as AirQualitySensorStatusSchema, Ht as HeatingValveStatusSchema, I as tagsCapability, In as BrightnessStatusSchema, It as timedRunCapability, J as REMOTE_MEDIA_COMMANDS, K as runningPowerDefaultsFor, Kn as actionWaitTotalMs, L as SWITCH_DEFAULT_OPTIONS, Lt as timedRunLimitOf, M as AutomationTemplatePayloadSchema, Mn as ClimateControlStatusSchema, Mt as temperatureMeasurement, N as reexpandAutomationInstance, Nt as textMeasurement, O as UpdateStatusSchema, Ot as emptyMeasurement, P as TemperatureSensorStatusSchema, Pt as NOT_REPORTED, Q as RemoteAssumedStateSchema, Qn as baseUnitForQuantity, Qt as FAN_CAPTURE_FIELDS, R as SwitchStatusSchema, Rn as BinaryStatusSchema, Rt as timedRunMaxIn, S as WeatherStatusSchema, Sn as ControlStatusSchema, St as ROW_READING_FACT_IDS, T as ValveStatusSchema, Tn as ConsumablesStatusSchema, Tt as REMOTE_OPEN_ACTION_ID, Ut as HeatPumpStatusSchema, V as ScriptRunnerStatusSchema, Vn as AmbientLightSensorStatusSchema, Vt as timedRunSeconds, W as RunningStateStatusSchema, Wn as actionsCapability, Wt as heatPumpInstantCop, X as EMPTY_REMOTE_ASSUMED_STATE, Xn as normalizeActionUnits, Xt as GasStatusSchema, Y as remoteCapability, Yn as capUnitResolver, Yt as GroupActiveSchema, Z as EMPTY_REMOTE_CONFIG, Zn as normalizeRecipeUnits, Zt as FloodStatusSchema, _ as WorkloadStatusSchema, _t as LawnMowerControlStatusSchema, an as SetOscillationAxisInputSchema, ar as addonIdOfActionId, bn as CoverStatusSchema, bt as HumidifierStatusSchema, c as kebabToCamel, cn as EnumSensorStatusSchema, cr as resolveActionVariables, dn as DishwasherStatusSchema, dt as NumericSensorStatusSchema, en as fanPresetsCapability, er as ActionError, et as readStoredRemoteConfig, ft as NetworkLinkStatusSchema, ht as LockControlStatusSchema, ir as INTERNAL_ACTION_PREFIX, it as PowerMeterStatusSchema, j as checkTemplatePayload, jt as powerMeasurement, k as templateCapability, kn as ColorStatusSchema, kt as humidityMeasurement, ln as DoorbellStatusSchema, lr as EventEmitterStatusSchema, lt as PetFeederStatusSchema, m as ALL_CAPABILITY_DEFINITIONS, mt as MeterStatusSchema, nn as FAN_OSCILLATION_AXIS_SETTABLE, nr as ActionVariableSchema, nt as PressureSensorStatusSchema, on as fanAxisPath, or as internalActionId, ot as PetFountainStatusSchema, pt as MotionTriggerStatusSchema, q as remoteLayoutComponentsCapability, qn as actionSourceCapability, qt as GroupCommandsSchema, rn as FanControlStatusSchema, rr as IDLE_ACTION_STATUS, rt as PresenceStatusSchema, sr as isInternalActionId, t as composedBlockIdOf, tn as FAN_OSCILLATION_AXES, tr as ActionMinDelaySecSchema, tt as PumpCycleStatusSchema, un as DoNotDisturbStatusSchema, vt as ImageStatusSchema, w as VibrationStatusSchema, wt as HERO_SCENE_ROW_IDS, x as WeatherStationStatusSchema, xt as heroLayoutCapability, yt as HumiditySensorStatusSchema, zn as BatteryStatusSchema, zt as timedRunQuickRun } from "../../rename-composition-block-OAtErZgq.mjs";
4
+ import { $ as RemoteLayoutPayloadSchema, $n as unitsForQuantity, $t as FanPresetSchema, A as TemplateKindSchema, At as measurementFitsRole, B as SmokeStatusSchema, Bn as AutomationControlStatusSchema, Bt as timedRunRemaining, C as WaterHeaterStatusSchema, Cn as ContactStatusSchema, Ct as projectDeviceRow, D as VacuumControlStatusSchema, Dn as COMPOSER_RUNNER_ID, Dt as contactMeasurement, Et as resolveHeroSceneId, F as TamperStatusSchema, Fn as CarbonMonoxideStatusSchema, Ft as TimedRunStatusSchema, G as hasOwnRunningPowerDefaults, Gt as GroupStatusSchema, H as schedulersCapability, Hn as AirQualitySensorStatusSchema, Ht as HeatingValveStatusSchema, I as tagsCapability, In as BrightnessStatusSchema, It as timedRunCapability, J as REMOTE_MEDIA_COMMANDS, K as runningPowerDefaultsFor, Kn as actionWaitTotalMs, L as SWITCH_DEFAULT_OPTIONS, Lt as timedRunLimitOf, M as AutomationTemplatePayloadSchema, Mn as ClimateControlStatusSchema, Mt as temperatureMeasurement, N as reexpandAutomationInstance, Nt as textMeasurement, O as UpdateStatusSchema, Ot as emptyMeasurement, P as TemperatureSensorStatusSchema, Pt as NOT_REPORTED, Q as RemoteAssumedStateSchema, Qn as baseUnitForQuantity, Qt as FAN_CAPTURE_FIELDS, R as SwitchStatusSchema, Rn as BinaryStatusSchema, Rt as timedRunMaxIn, S as WeatherStatusSchema, Sn as ControlStatusSchema, St as ROW_READING_FACT_IDS, T as ValveStatusSchema, Tn as ConsumablesStatusSchema, Tt as REMOTE_OPEN_ACTION_ID, Ut as HeatPumpStatusSchema, V as ScriptRunnerStatusSchema, Vn as AmbientLightSensorStatusSchema, Vt as timedRunSeconds, W as RunningStateStatusSchema, Wn as actionsCapability, Wt as heatPumpInstantCop, X as EMPTY_REMOTE_ASSUMED_STATE, Xn as normalizeActionUnits, Xt as GasStatusSchema, Y as remoteCapability, Yn as capUnitResolver, Yt as GroupActiveSchema, Z as EMPTY_REMOTE_CONFIG, Zn as normalizeRecipeUnits, Zt as FloodStatusSchema, _ as WorkloadStatusSchema, _t as LawnMowerControlStatusSchema, an as SetOscillationAxisInputSchema, ar as addonIdOfActionId, bn as CoverStatusSchema, bt as HumidifierStatusSchema, c as kebabToCamel, cn as EnumSensorStatusSchema, cr as resolveActionVariables, dn as DishwasherStatusSchema, dt as NumericSensorStatusSchema, en as fanPresetsCapability, er as ActionError, et as readStoredRemoteConfig, ft as NetworkLinkStatusSchema, ht as LockControlStatusSchema, ir as INTERNAL_ACTION_PREFIX, it as PowerMeterStatusSchema, j as checkTemplatePayload, jt as powerMeasurement, k as templateCapability, kn as ColorStatusSchema, kt as humidityMeasurement, ln as DoorbellStatusSchema, lr as EventEmitterStatusSchema, lt as PetFeederStatusSchema, m as ALL_CAPABILITY_DEFINITIONS, mt as MeterStatusSchema, nn as FAN_OSCILLATION_AXIS_SETTABLE, nr as ActionVariableSchema, nt as PressureSensorStatusSchema, on as fanAxisPath, or as internalActionId, ot as PetFountainStatusSchema, pt as MotionTriggerStatusSchema, q as remoteLayoutComponentsCapability, qn as actionSourceCapability, qt as GroupCommandsSchema, rn as FanControlStatusSchema, rr as IDLE_ACTION_STATUS, rt as PresenceStatusSchema, sr as isInternalActionId, t as composedBlockIdOf, tn as FAN_OSCILLATION_AXES, tr as ActionMinDelaySecSchema, tt as PumpCycleStatusSchema, un as DoNotDisturbStatusSchema, vt as ImageStatusSchema, w as VibrationStatusSchema, wt as HERO_SCENE_ROW_IDS, x as WeatherStationStatusSchema, xt as heroLayoutCapability, yt as HumiditySensorStatusSchema, zn as BatteryStatusSchema, zt as timedRunQuickRun } from "../../rename-composition-block-BYRBlx-V.mjs";
5
5
  import { r as listNotificationTargets } from "../../notification-targets-DaNE-pIt.mjs";
6
6
  import { i as NcTaggedRuleKindSchema, o as AlarmPanelStatusSchema, u as NotificationSchema } from "../../notification-rules.cap-DUmiMBQB.mjs";
7
7
  import { s as defineRecordKinds } from "../../record-kind-ub6NXqfh.mjs";
@@ -12,13 +12,13 @@ import { n as baseUnitOf } from "../../quantity-D3g5SxsZ.mjs";
12
12
  import { a as defaultTagColorId, c as renameInTags, i as TagsFieldSchema, l as tagKey, n as TagNameSchema, o as normalizeTags, r as TagStyleSchema, s as removeFromTags } from "../../tag-uZBAq6ox.mjs";
13
13
  import { n as DeviceRole, r as DeviceType$1, t as DeviceFeature } from "../../device-type-DgEvK3ch.mjs";
14
14
  import { r as isAirConditioner, t as canonicalStoredDeviceType } from "../../device-kind-BJ2pfsjw.mjs";
15
- import { $t as siteFor, B as customKeyOfRole, C as powerSourceCapability, Ct as validateRecipeBounds, F as findChannelSource, It as holdOf, L as remoteSourceSteps, Mt as hasEventLeaves, Nt as isEventLeaf, Pt as compareValues, Qt as occurrenceOn, R as resolveRemoteSource, S as PowerSourceStateSchema, St as stepGuardOf, Vt as QuantityUnitError, W as toTimings, Xt as localDateOf, Zt as nextOccurrence, _ as replacedFieldKeys, _t as AutomationRecipeSchema, a as coreBlockComposition, an as canonicalStoredStepTargets, at as buildStepArgsTrace, b as powerSourceLinkOfComposition, bt as nestedStepsOf, c as coreBlocksCapability, d as resolveCoreBlockFiles, dn as vocabActionIdFor, en as weekdayOfLocalDate, f as describeComposableCaps, fn as vocabCall, ft as SchedulerSchema, g as planComposition, h as compositionUnionReads, ht as ActionStepSchema, i as coreBlockAddonId, in as ActionTargetResolver, it as appendTrace, j as MediaPlayerStatusSchema, jt as forEachLeaf, k as CAP_CUSTOMIZE_CATALOG, l as normalizeCoreBlockWrite, ln as assertDeviceOffers, lt as SchedulerError, m as compositionSourceRefs, mt as validateSchedulerInput, n as CORE_BLOCK_ADDON_PREFIX, nt as AutomationStateDocSchema, o as coreBlockIdFromAddonId, on as VocabActionError, ot as DEFAULT_HOLD_OVERRIDE, p as buildCapabilityLookup, r as CoreBlockSchema, rn as ACTION_TARGET_INVALIDATION_EVENTS, rt as EMPTY_AUTOMATION_STATE, s as coreBlockSourceKind, sn as actionEffect, t as CORE_BLOCKS_ADDON_ID, tn as zoneOnlySite, u as resolveCoreBlockEntry, un as findVocabAction, v as validateComposition, vt as HTTP_TEXT_CAP, x as PowerSourceInfoSchema, xt as stepConditionsOf, y as powerSourceActuatorConflicts, yt as REPEAT_ITEM_VAR } from "../../core-blocks.cap-BRPsLAij.mjs";
16
- import { B as helperMembers, D as composedDeviceRef, E as canonicalStoredBlockTarget, N as compositionSourceKey, O as composedDeviceStableId, T as CompositionSchema, U as DAY_MS, Y as historyRetentionFromSettings, _t as evaluateDwell, k as compositionFeatureEnabled, x as COMPOSER_ADDON_ID, z as HelperMemberSchema } from "../../error.cap-CSM_SRfR.mjs";
17
- import { a as evaluateWhenTree, c as nextTimeBoundaryInMs, i as collectWhenMirrorSources, l as stableIdMapOf, n as unwrapStoredValue, o as hasHoldLeaves, r as ConditionMirror, s as hasTimeLeaves, t as loadPrefixed } from "../../prefix-walk-ifwg_ukx.mjs";
15
+ import { A as MediaPlayerStatusSchema, C as PowerSourceStateSchema, Ct as HTTP_TEXT_CAP, Dt as stepGuardOf, Et as stepConditionsOf, I as remoteSourceSteps, It as forEachLeaf, J as capLinkServedFields, Kt as QuantityUnitError, L as resolveRemoteSource, Lt as hasEventLeaves, Ot as validateRecipeBounds, P as findChannelSource, Q as CAP_CUSTOMIZE_CATALOG, Rt as isEventLeaf, S as PowerSourceInfoSchema, St as AutomationRecipeSchema, Tt as nestedStepsOf, U as toTimings, Vt as holdOf, X as expandCapLinks, Y as declaredCapLink, Z as projectCapLinkOf, _ as replacedFieldKeys, _n as vocabCall, _t as SchedulerSchema, a as coreBlockComposition, an as weekdayOfLocalDate, b as powerSourceActuatorConflicts, bt as ActionStepSchema, c as coreBlocksCapability, cn as ACTION_TARGET_INVALIDATION_EVENTS, ct as EMPTY_AUTOMATION_STATE, d as resolveCoreBlockFiles, dn as VocabActionError, dt as DEFAULT_HOLD_OVERRIDE, f as describeComposableCaps, fn as actionEffect, g as planComposition, gn as vocabActionIdFor, h as compositionUnionReads, hn as findVocabAction, i as coreBlockAddonId, in as siteFor, l as normalizeCoreBlockWrite, ln as ActionTargetResolver, lt as appendTrace, m as compositionSourceRefs, mn as assertDeviceOffers, mt as SchedulerError, n as CORE_BLOCK_ADDON_PREFIX, nn as nextOccurrence, o as coreBlockIdFromAddonId, on as zoneOnlySite, p as buildCapabilityLookup, r as CoreBlockSchema, rn as occurrenceOn, s as coreBlockSourceKind, st as AutomationStateDocSchema, t as CORE_BLOCKS_ADDON_ID, tn as localDateOf, u as resolveCoreBlockEntry, un as canonicalStoredStepTargets, ut as buildStepArgsTrace, v as topLevelFieldsOf, w as powerSourceCapability, wt as REPEAT_ITEM_VAR, x as powerSourceLinkOfComposition, y as validateComposition, yt as validateSchedulerInput, z as customKeyOfRole, zt as compareValues } from "../../core-blocks.cap-CnwBuf7E.mjs";
16
+ import { B as helperMembers, D as composedDeviceRef, E as canonicalStoredBlockTarget, N as compositionSourceKey, O as composedDeviceStableId, T as CompositionSchema, W as DAY_MS, X as historyRetentionFromSettings, k as compositionFeatureEnabled, vt as evaluateDwell, x as COMPOSER_ADDON_ID, z as HelperMemberSchema } from "../../error.cap-5zNPAgU2.mjs";
17
+ import { a as evaluateWhenTree, c as nextTimeBoundaryInMs, i as collectWhenMirrorSources, l as stableIdMapOf, n as unwrapStoredValue, o as hasHoldLeaves, r as ConditionMirror, s as hasTimeLeaves, t as loadPrefixed } from "../../prefix-walk-CRnbYJcC.mjs";
18
18
  import { t } from "../../l10n-Bu6aUvSY.mjs";
19
19
  import { t as integrationInstancesCapability } from "../../integration-instances.cap-Cl9O-k4h.mjs";
20
20
  import { t as commandOrigin$1 } from "../../cap-call-context-DNwdgGSQ.mjs";
21
- import { r as compileScalarOverride, t as describeCompositionSources } from "../../composition-sources-BEUWn2s_.mjs";
21
+ import { r as compileScalarOverride, t as describeCompositionSources } from "../../composition-sources-B0QW4g86.mjs";
22
22
  import { r as seedInstanceOnce, t as DeclaredDevices } from "../../declared-device-CKERA1Hi.mjs";
23
23
  import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
24
24
  import { i as capSeriesKey, m as parseConfirmedStateChanged, p as isRecord$1 } from "../../capture-engine-DiwbjoWp.mjs";
@@ -14745,6 +14745,233 @@ var RemoteComponentsService = class {
14745
14745
  }
14746
14746
  };
14747
14747
  //#endregion
14748
+ //#region src/builtins/core-blocks/cap-links.ts
14749
+ /**
14750
+ * Whole-capability links at runtime (D1076): the read behind `getCapLinks` and
14751
+ * the one-off conversion behind `migrateCapLinks`.
14752
+ *
14753
+ * The compile path is not here: a `capLink` is expanded by `planComposition`
14754
+ * into the field claims the composer already runs. This file only READS the
14755
+ * stored links (state per link, `not-loaded` until the compositions were read,
14756
+ * D315) and REWRITES plain per-field links into one link (bounded, idempotent,
14757
+ * D345).
14758
+ */
14759
+ function hostBlock(blocks, host) {
14760
+ const key = compositionSourceKey(host);
14761
+ return blocks.find((block) => {
14762
+ const target = coreBlockComposition(block)?.target;
14763
+ return target?.kind === "existing" && compositionSourceKey(target.device) === key;
14764
+ }) ?? null;
14765
+ }
14766
+ function capLinkFeatures(composition) {
14767
+ return (composition?.features ?? []).flatMap((feature) => feature.kind === "capLink" ? [feature] : []);
14768
+ }
14769
+ var CapLinksService = class {
14770
+ ports;
14771
+ /** `host:cap:link` keys whose source-gone was already logged: one line per loss, not per read. */
14772
+ goneLogged = /* @__PURE__ */ new Set();
14773
+ constructor(ports) {
14774
+ this.ports = ports;
14775
+ }
14776
+ async read(deviceId) {
14777
+ const blocks = this.ports.blocks();
14778
+ if (blocks === null) return { status: "not-loaded" };
14779
+ const host = await this.ports.refOfDevice(deviceId);
14780
+ if (host === null) return {
14781
+ status: "ok",
14782
+ links: []
14783
+ };
14784
+ const block = hostBlock(blocks, host);
14785
+ const features = capLinkFeatures(block === null ? null : coreBlockComposition(block));
14786
+ const links = [];
14787
+ for (const feature of features) {
14788
+ const declared = declaredCapLink(feature.cap, feature.linkId);
14789
+ if (declared === void 0) continue;
14790
+ const sourceId = await this.ports.deviceIdOf(feature.source);
14791
+ const gone = sourceId === null;
14792
+ const state = !compositionFeatureEnabled(feature) ? "disabled" : gone ? "source-gone" : "linked";
14793
+ if (state === "source-gone") this.logGone(deviceId, feature);
14794
+ else this.goneLogged.delete(goneKey(deviceId, feature));
14795
+ links.push({
14796
+ linkId: feature.linkId,
14797
+ cap: feature.cap,
14798
+ slot: declared.slot ?? null,
14799
+ mode: declared.mode,
14800
+ source: {
14801
+ deviceId: sourceId,
14802
+ cap: declared.sourceCap
14803
+ },
14804
+ state
14805
+ });
14806
+ }
14807
+ return {
14808
+ status: "ok",
14809
+ links
14810
+ };
14811
+ }
14812
+ logGone(deviceId, feature) {
14813
+ const key = goneKey(deviceId, feature);
14814
+ if (this.goneLogged.has(key)) return;
14815
+ this.goneLogged.add(key);
14816
+ this.ports.logger.warn("cap link: the source device is gone — the linked cap reads unknown", {
14817
+ tags: { deviceId },
14818
+ meta: {
14819
+ cap: feature.cap,
14820
+ linkId: feature.linkId,
14821
+ source: feature.source
14822
+ }
14823
+ });
14824
+ }
14825
+ async migrate(dryRun) {
14826
+ const blocks = this.ports.blocks();
14827
+ if (blocks === null) throw new Error("core-blocks: the compositions have not loaded yet — migrateCapLinks refused");
14828
+ const report = {
14829
+ dryRun,
14830
+ converted: [],
14831
+ mixed: [],
14832
+ skipped: 0,
14833
+ alreadyLinked: 0
14834
+ };
14835
+ for (const block of blocks) {
14836
+ const composition = coreBlockComposition(block);
14837
+ if (composition === null || composition.target.kind !== "existing") continue;
14838
+ const deviceId = await this.ports.deviceIdOf(composition.target.device);
14839
+ if (deviceId === null) {
14840
+ this.ports.logger.warn("cap link migration: host device not found — customization left as is", { meta: { blockId: block.id } });
14841
+ continue;
14842
+ }
14843
+ await this.migrateBlock(block, composition, deviceId, dryRun, report);
14844
+ }
14845
+ return report;
14846
+ }
14847
+ async migrateBlock(stored, composition, deviceId, dryRun, report) {
14848
+ const caps = [...new Set(composition.features.flatMap((f) => f.kind === "fields" || f.kind === "capLink" ? [f.cap] : []))];
14849
+ let block = stored;
14850
+ let next = composition;
14851
+ for (const cap of caps) {
14852
+ const link = projectCapLinkOf(cap);
14853
+ if (link === void 0) continue;
14854
+ if (capLinkFeatures(next).some((f) => f.cap === cap)) {
14855
+ report.alreadyLinked += 1;
14856
+ continue;
14857
+ }
14858
+ const plain = next.features.filter((f) => f.kind === "fields" && f.cap === cap);
14859
+ const candidates = plain.filter((f) => f.contributedBy === void 0 && compositionFeatureEnabled(f));
14860
+ report.skipped += plain.length - candidates.length;
14861
+ if (candidates.length === 0) continue;
14862
+ const verdict = identityGroup(candidates, link.sourceCap, link.map);
14863
+ const hostFields = this.ports.hostFieldsOf(cap);
14864
+ const reasons = "reasons" in verdict ? verdict.reasons : hostFields === null ? [`the capability ${cap} is unknown here`] : widening(capLinkServedFields(link, hostFields), verdict.fields, next, candidates);
14865
+ if ("reasons" in verdict || reasons.length > 0) {
14866
+ report.mixed.push({
14867
+ deviceId,
14868
+ cap,
14869
+ reasons
14870
+ });
14871
+ continue;
14872
+ }
14873
+ if ("reasons" in verdict) continue;
14874
+ const feature = {
14875
+ kind: "capLink",
14876
+ cap,
14877
+ linkId: link.id,
14878
+ source: verdict.source
14879
+ };
14880
+ const replaced = new Set(candidates);
14881
+ const kept = next.features.filter((f) => !replaced.has(f));
14882
+ const candidate = {
14883
+ ...next,
14884
+ features: kept.concat(feature)
14885
+ };
14886
+ const converted = {
14887
+ deviceId,
14888
+ cap,
14889
+ linkId: link.id,
14890
+ source: verdict.source,
14891
+ fields: verdict.fields
14892
+ };
14893
+ if (!dryRun) try {
14894
+ block = await this.ports.rewrite(block, candidate);
14895
+ } catch (err) {
14896
+ report.mixed.push({
14897
+ deviceId,
14898
+ cap,
14899
+ reasons: [`the link was refused: ${errMsg$1(err)}`]
14900
+ });
14901
+ this.ports.logger.warn("cap link migration: conversion refused — left as it was", {
14902
+ tags: { deviceId },
14903
+ meta: {
14904
+ cap,
14905
+ error: errMsg$1(err)
14906
+ }
14907
+ });
14908
+ continue;
14909
+ }
14910
+ next = candidate;
14911
+ report.converted.push(converted);
14912
+ }
14913
+ }
14914
+ };
14915
+ /**
14916
+ * Why converting would change what the device claims. The link serves EVERY host
14917
+ * field of the cap (and the clock as `now`): a set that covers fewer would newly
14918
+ * take the rest from the source, and an enabled feature another writer left on
14919
+ * the cap would overlap the link. The operator decides per device.
14920
+ */
14921
+ function widening(served, carried, next, candidates) {
14922
+ const reasons = [];
14923
+ const missing = served.filter((path) => !carried.includes(path));
14924
+ if (missing.length > 0) reasons.push(`partial-set: would also take ${missing.join(", ")}`);
14925
+ const taken = new Set(candidates);
14926
+ for (const other of next.features) {
14927
+ if (other.kind !== "fields" || taken.has(other) || !compositionFeatureEnabled(other)) continue;
14928
+ const clash = Object.keys(other.fields).filter((path) => served.includes(path));
14929
+ if (clash.length > 0) {
14930
+ const by = other.contributedBy === void 0 ? "another feature" : `the device link ${other.contributedBy.linkId}`;
14931
+ reasons.push(`overlap: ${by} also writes ${clash.join(", ")}, which the link would serve`);
14932
+ }
14933
+ }
14934
+ return reasons;
14935
+ }
14936
+ function goneKey(deviceId, feature) {
14937
+ return `${deviceId}:${feature.cap}:${feature.linkId}`;
14938
+ }
14939
+ /**
14940
+ * The features are ONE link when every field is a plain read of the SAME source
14941
+ * device's `sourceCap`, at the path the link maps it to (the same path without a
14942
+ * map), plus the `now` clock. Anything else is named, per field.
14943
+ */
14944
+ function identityGroup(features, sourceCap, map) {
14945
+ const reasons = [];
14946
+ const sources = /* @__PURE__ */ new Map();
14947
+ const fields = [];
14948
+ for (const feature of features) {
14949
+ for (const [path, value] of Object.entries(feature.fields)) {
14950
+ fields.push(path);
14951
+ if (value.kind === "expression" && value.expr === "now" && path === "lastFetchedAt") continue;
14952
+ if (path === "lastFetchedAt") {
14953
+ reasons.push("lastFetchedAt: reads the source clock, the link writes now");
14954
+ continue;
14955
+ }
14956
+ if (value.kind !== "from") {
14957
+ reasons.push(`${path}: a ${value.kind} source`);
14958
+ continue;
14959
+ }
14960
+ if (value.cap !== sourceCap) reasons.push(`${path}: reads ${value.cap}, not ${sourceCap}`);
14961
+ else if (value.fieldPath !== (map?.[path] ?? path)) reasons.push(`${path}: reads ${value.fieldPath}, not the same path`);
14962
+ sources.set(compositionSourceKey(value.source), value.source);
14963
+ }
14964
+ for (const extra of ["items", "commands"]) if (feature[extra] !== void 0) reasons.push(`the feature carries ${extra}`);
14965
+ }
14966
+ const [first] = [...sources.values()];
14967
+ if (sources.size > 1) reasons.push(`${sources.size} different source devices`);
14968
+ if (first === void 0 && reasons.length === 0) reasons.push("no source device");
14969
+ return reasons.length > 0 || first === void 0 ? { reasons } : {
14970
+ source: first,
14971
+ fields
14972
+ };
14973
+ }
14974
+ //#endregion
14748
14975
  //#region src/builtins/core-blocks/hero-layout-service.ts
14749
14976
  /**
14750
14977
  * The `hero-layout` provider of core-blocks (D1023): serves the FIXED layouts
@@ -17275,7 +17502,8 @@ function replacedOf(stored, description, lookupCap) {
17275
17502
  return replacedFieldKeys(planComposition(stored.composition, lookupCap, description));
17276
17503
  }
17277
17504
  function peerOf(stored, targets, lookupCap, candidateBlockId) {
17278
- const { blockId, composition } = stored;
17505
+ const { blockId } = stored;
17506
+ const composition = expandCapLinks(stored.composition, (cap) => topLevelFieldsOf(cap, lookupCap));
17279
17507
  if (composition.target.kind === "new") return {
17280
17508
  peer: {
17281
17509
  blockId,
@@ -17286,7 +17514,10 @@ function peerOf(stored, targets, lookupCap, candidateBlockId) {
17286
17514
  };
17287
17515
  const device = composition.target.device;
17288
17516
  const key = compositionSourceKey(device);
17289
- const replaced = replacedOf(stored, targets.get(key), lookupCap);
17517
+ const replaced = replacedOf({
17518
+ blockId,
17519
+ composition
17520
+ }, targets.get(key), lookupCap);
17290
17521
  if (!("error" in replaced)) return {
17291
17522
  peer: {
17292
17523
  blockId,
@@ -19521,8 +19752,51 @@ var CoreBlocksAddon = class extends BaseAddon {
19521
19752
  })) };
19522
19753
  },
19523
19754
  ...this.requireActions().runsApi,
19524
- ...this.sharedCompositionApi()
19755
+ ...this.sharedCompositionApi(),
19756
+ getCapLinks: async ({ deviceId }) => this.sharedCapLinks().read(deviceId),
19757
+ migrateCapLinks: async ({ dryRun }) => this.sharedCapLinks().migrate(dryRun)
19758
+ };
19759
+ }
19760
+ capLinks = null;
19761
+ /** Whole-capability links (D1076): the read and the one-off migration, over `ctx.api`. */
19762
+ sharedCapLinks() {
19763
+ this.capLinks ??= this.buildCapLinks();
19764
+ return this.capLinks;
19765
+ }
19766
+ buildCapLinks() {
19767
+ const requireApi = () => {
19768
+ const api = this.ctx.api;
19769
+ if (!api) throw new Error("core-blocks: no ctx.api on this node — cap links cannot be read");
19770
+ return api;
19525
19771
  };
19772
+ const store = this.requireStore();
19773
+ const compositions = this.sharedCompositionApi();
19774
+ const lookupCap = buildCapabilityLookup(ALL_CAPABILITY_DEFINITIONS);
19775
+ return new CapLinksService({
19776
+ blocks: () => store.isLoaded() ? store.list() : null,
19777
+ refOfDevice: async (deviceId) => {
19778
+ const found = await requireApi().deviceManager.getDevice.query({ deviceId });
19779
+ return found === null ? null : {
19780
+ addonId: found.addonId,
19781
+ stableId: found.stableId
19782
+ };
19783
+ },
19784
+ deviceIdOf: (ref) => this.deviceIdOfRef(ref),
19785
+ hostFieldsOf: (cap) => topLevelFieldsOf(cap, lookupCap),
19786
+ rewrite: async (block, composition) => {
19787
+ const { block: updated } = await compositions.updateComposition({
19788
+ blockId: block.id,
19789
+ expectedUpdatedAt: block.updatedAt,
19790
+ block: { composition },
19791
+ caller: {
19792
+ userId: "cap-links-migration",
19793
+ isAdmin: true
19794
+ }
19795
+ });
19796
+ return updated;
19797
+ },
19798
+ logger: this.ctx.logger.child("cap-links")
19799
+ });
19526
19800
  }
19527
19801
  sharedCompositionApi() {
19528
19802
  this.compositionApi ??= this.buildCompositionApi();
@@ -6,7 +6,7 @@ const require_chunk = require("../../chunk-Cek0wNdY.js");
6
6
  const require_stream_catalog_cap = require("../../stream-catalog.cap-D3uwePiA.js");
7
7
  const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
8
8
  const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
9
- const require_rename_composition_block = require("../../rename-composition-block-BJsL58Ih.js");
9
+ const require_rename_composition_block = require("../../rename-composition-block-BRgyBO25.js");
10
10
  const require_camstack_error = require("../../camstack-error-DJ-TUAi1.js");
11
11
  const require_capability_definition = require("../../capability-definition-HCmTem8c.js");
12
12
  const require_zod_secret = require("../../zod-secret-DS7mj1bk.js");
@@ -15,11 +15,11 @@ const require_device_identifiers = require("../../device-identifiers-BQg9EQi1.js
15
15
  const require_tag = require("../../tag-BxLazvVb.js");
16
16
  const require_device_type = require("../../device-type-CbQsnFdC.js");
17
17
  const require_device_kind = require("../../device-kind-CsSiv_YF.js");
18
- const require_core_blocks_cap = require("../../core-blocks.cap-BMeMCBrx.js");
18
+ const require_core_blocks_cap = require("../../core-blocks.cap-DlEuHq-S.js");
19
19
  const require_addon_settings_cap = require("../../addon-settings.cap-DAiE0Nb0.js");
20
- require("../../error.cap-DBhgPeWK.js");
20
+ require("../../error.cap-BCqzFlo2.js");
21
21
  const require_source_info = require("../../source-info-DtWf4k2j.js");
22
- const require_prefix_walk = require("../../prefix-walk-BkMxoXpL.js");
22
+ const require_prefix_walk = require("../../prefix-walk-DD1BM923.js");
23
23
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
24
24
  const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
25
25
  const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
@@ -2095,6 +2095,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
2095
2095
  access: "view",
2096
2096
  role: "admin"
2097
2097
  },
2098
+ "coreBlocks.getCapLinks": {
2099
+ capName: "core-blocks",
2100
+ capScope: "system",
2101
+ addonId: null,
2102
+ access: "view",
2103
+ role: "admin"
2104
+ },
2098
2105
  "coreBlocks.getComposition": {
2099
2106
  capName: "core-blocks",
2100
2107
  capScope: "system",
@@ -2144,6 +2151,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
2144
2151
  access: "view",
2145
2152
  role: "admin"
2146
2153
  },
2154
+ "coreBlocks.migrateCapLinks": {
2155
+ capName: "core-blocks",
2156
+ capScope: "system",
2157
+ addonId: null,
2158
+ access: "create",
2159
+ role: "admin"
2160
+ },
2147
2161
  "coreBlocks.migrateRawSecrets": {
2148
2162
  capName: "core-blocks",
2149
2163
  capScope: "system",
@@ -1,7 +1,7 @@
1
1
  import { T as deviceStatusCapability, w as DeviceStatusSchema } from "../../stream-catalog.cap-Bp7SkgIf.mjs";
2
2
  import { b as EventCategory$1, g as WELL_KNOWN_TAB_MAP, n as secretTreeFromPaths, o as resolveSecretMarkers, s as transformSecretWrite, t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
3
3
  import { B as SECRET_CLEAR, G as isSecretMarkerLike, H as isSecretClear, W as isSecretMarker, X as isKeychainStoredField, Z as errMsg$1, q as toSecretFieldView } from "../../scoped-settings-DVWUIP7Z.mjs";
4
- import { Jn as ExportNameRefusedError, _n as deviceStateCapability, b as workloadTransition, c as kebabToCamel, fn as PUSH_CONFIRM_WINDOW_MS, g as WorkloadStateSchema, gn as FieldClaimSchema, h as WORKLOAD_TRANSITION_CATEGORY, hn as FieldClaimModeSchema, m as ALL_CAPABILITY_DEFINITIONS, mn as effectiveRefreshIntervalMs, n as renameCompositionBlock, pn as commandBurstOffsets, t as composedBlockIdOf, v as isWorkloadSettled, vn as deviceExtensionCapability, y as workloadCapability, yn as EXTENSION_SLOTS } from "../../rename-composition-block-OAtErZgq.mjs";
4
+ import { Jn as ExportNameRefusedError, _n as deviceStateCapability, b as workloadTransition, c as kebabToCamel, fn as PUSH_CONFIRM_WINDOW_MS, g as WorkloadStateSchema, gn as FieldClaimSchema, h as WORKLOAD_TRANSITION_CATEGORY, hn as FieldClaimModeSchema, m as ALL_CAPABILITY_DEFINITIONS, mn as effectiveRefreshIntervalMs, n as renameCompositionBlock, pn as commandBurstOffsets, t as composedBlockIdOf, v as isWorkloadSettled, vn as deviceExtensionCapability, y as workloadCapability, yn as EXTENSION_SLOTS } from "../../rename-composition-block-BYRBlx-V.mjs";
5
5
  import { t as userError } from "../../camstack-error-viZYfcj9.mjs";
6
6
  import { a as expandCapMethods$1, s as isDeviceConfigCap } from "../../capability-definition-C2rJdVeX.mjs";
7
7
  import { t as collectZodSecretPaths$1 } from "../../zod-secret-zY4nM61M.mjs";
@@ -10,11 +10,11 @@ import { a as isEmptyIdentifiers, c as sameIdentifiers, i as identifierStrength,
10
10
  import { d as canonicalIconKey, o as normalizeTags } from "../../tag-uZBAq6ox.mjs";
11
11
  import { n as DeviceRole, r as DeviceType$1, t as DeviceFeature } from "../../device-type-DgEvK3ch.mjs";
12
12
  import { n as capAppliesToDeviceKind } from "../../device-kind-BJ2pfsjw.mjs";
13
- import { A as CAP_RUNTIME_FIELD_UNITS, Kt as enumerateItemArrayFields, cn as allVocabActions, dn as vocabActionIdFor, pn as CAP_VOCABULARY_BY_NAME, qt as enumerateSchemaFields, sn as actionEffect, un as findVocabAction } from "../../core-blocks.cap-BRPsLAij.mjs";
13
+ import { $ as CAP_RUNTIME_FIELD_UNITS, Qt as enumerateSchemaFields, Zt as enumerateItemArrayFields, fn as actionEffect, gn as vocabActionIdFor, hn as findVocabAction, pn as allVocabActions, vn as CAP_VOCABULARY_BY_NAME } from "../../core-blocks.cap-CnwBuf7E.mjs";
14
14
  import { u as locationIconKey } from "../../addon-settings.cap-3-TIIMq_.mjs";
15
- import "../../error.cap-CSM_SRfR.mjs";
15
+ import "../../error.cap-5zNPAgU2.mjs";
16
16
  import { a as normalizeUnit, r as extractSourceInfoFromMetadata } from "../../source-info-DGB7SdB_.mjs";
17
- import { r as ConditionMirror, t as loadPrefixed } from "../../prefix-walk-ifwg_ukx.mjs";
17
+ import { r as ConditionMirror, t as loadPrefixed } from "../../prefix-walk-CRnbYJcC.mjs";
18
18
  import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
19
19
  import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
20
20
  import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
@@ -2089,6 +2089,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
2089
2089
  access: "view",
2090
2090
  role: "admin"
2091
2091
  },
2092
+ "coreBlocks.getCapLinks": {
2093
+ capName: "core-blocks",
2094
+ capScope: "system",
2095
+ addonId: null,
2096
+ access: "view",
2097
+ role: "admin"
2098
+ },
2092
2099
  "coreBlocks.getComposition": {
2093
2100
  capName: "core-blocks",
2094
2101
  capScope: "system",
@@ -2138,6 +2145,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
2138
2145
  access: "view",
2139
2146
  role: "admin"
2140
2147
  },
2148
+ "coreBlocks.migrateCapLinks": {
2149
+ capName: "core-blocks",
2150
+ capScope: "system",
2151
+ addonId: null,
2152
+ access: "create",
2153
+ role: "admin"
2154
+ },
2141
2155
  "coreBlocks.migrateRawSecrets": {
2142
2156
  capName: "core-blocks",
2143
2157
  capScope: "system",
@@ -1,6 +1,6 @@
1
1
  import { Z as errMsg } from "./scoped-settings-DVWUIP7Z.mjs";
2
- import { k as CAP_CUSTOMIZE_CATALOG } from "./core-blocks.cap-BRPsLAij.mjs";
3
- import { N as compositionSourceKey, c as isIdentifier, d as signedToken, f as unsignedToken, l as linearExpr, o as constantExpr, s as dwellExpr, u as overrideExpr } from "./error.cap-CSM_SRfR.mjs";
2
+ import { Q as CAP_CUSTOMIZE_CATALOG } from "./core-blocks.cap-CnwBuf7E.mjs";
3
+ import { N as compositionSourceKey, c as isIdentifier, d as signedToken, f as unsignedToken, l as linearExpr, o as constantExpr, s as dwellExpr, u as overrideExpr } from "./error.cap-5zNPAgU2.mjs";
4
4
  //#region ../types/dist/esm/composition/customize/field-source.mjs
5
5
  function fromRead(source, cap, fieldPath) {
6
6
  return {
@@ -1,6 +1,6 @@
1
1
  const require_scoped_settings = require("./scoped-settings-CylSSq_8.js");
2
- const require_core_blocks_cap = require("./core-blocks.cap-BMeMCBrx.js");
3
- const require_error_cap = require("./error.cap-DBhgPeWK.js");
2
+ const require_core_blocks_cap = require("./core-blocks.cap-DlEuHq-S.js");
3
+ const require_error_cap = require("./error.cap-BCqzFlo2.js");
4
4
  //#region ../types/dist/esm/composition/customize/field-source.mjs
5
5
  function fromRead(source, cap, fieldPath) {
6
6
  return {