@camstack/server 1.2.810 → 1.2.811

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 (116) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/api/trpc/cap-router-runtime.js +3 -0
  3. package/dist/api/trpc/generated-cap-mounts.js +3 -1
  4. package/dist/api/trpc/generated-cap-routers.js +1869 -1789
  5. package/dist/core/addon/hub-addon-api.js +8 -1
  6. package/dist/core/moleculer/moleculer.service.js +3 -0
  7. package/package.json +9 -41
  8. package/system/dist/addon-runner.js +4 -1
  9. package/system/dist/addon-runner.mjs +5 -2
  10. package/system/dist/{agent-https-B5cYxyQW.mjs → agent-https-CyEBY3RB.mjs} +1 -1
  11. package/system/dist/{agent-https-C0QE8tXs.js → agent-https-a3mE4PW4.js} +1 -1
  12. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  13. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  14. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  15. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  16. package/system/dist/builtins/alerts/alerts.addon.js +3 -101
  17. package/system/dist/builtins/alerts/alerts.addon.mjs +40 -134
  18. package/system/dist/builtins/autotrack/index.js +1 -1
  19. package/system/dist/builtins/autotrack/index.mjs +1 -1
  20. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  21. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  22. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  23. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  24. package/system/dist/builtins/camera-grid/index.js +1 -1
  25. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  26. package/system/dist/builtins/composer/composer.addon.js +6 -5
  27. package/system/dist/builtins/composer/composer.addon.mjs +6 -5
  28. package/system/dist/builtins/console-logging/index.js +1 -1
  29. package/system/dist/builtins/console-logging/index.mjs +1 -1
  30. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +2 -0
  31. package/system/dist/builtins/core-blocks/core-blocks.addon.js +358 -32
  32. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +361 -35
  33. package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +42 -0
  34. package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +1 -1
  35. package/system/dist/builtins/core-blocks/remote-service.d.ts +38 -0
  36. package/system/dist/builtins/device-history/device-history.addon.d.ts +5 -0
  37. package/system/dist/builtins/device-history/device-history.addon.js +357 -18
  38. package/system/dist/builtins/device-history/device-history.addon.mjs +357 -18
  39. package/system/dist/builtins/device-history/retention/retention.d.ts +14 -1
  40. package/system/dist/builtins/device-history/transitions/device-transitions-record-kinds.d.ts +14 -0
  41. package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +80 -0
  42. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
  43. package/system/dist/builtins/device-manager/device-manager.addon.js +712 -18
  44. package/system/dist/builtins/device-manager/device-manager.addon.mjs +780 -95
  45. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
  46. package/system/dist/builtins/device-manager/transitions/command-args.d.ts +4 -0
  47. package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +68 -0
  48. package/system/dist/builtins/device-manager/transitions/transitions-sender.d.ts +37 -0
  49. package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +25 -0
  50. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  51. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  52. package/system/dist/builtins/keychain/index.js +4 -4
  53. package/system/dist/builtins/keychain/index.mjs +4 -4
  54. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  56. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  57. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  58. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  60. package/system/dist/builtins/loki-logging/index.js +1 -1
  61. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  62. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  64. package/system/dist/builtins/platform-probe/index.js +1 -1
  65. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  66. package/system/dist/builtins/record-entries/index.js +1 -1
  67. package/system/dist/builtins/record-entries/index.mjs +1 -1
  68. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  70. package/system/dist/builtins/snapshot/index.js +1 -1
  71. package/system/dist/builtins/snapshot/index.mjs +1 -1
  72. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  74. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  76. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  78. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  80. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  81. package/system/dist/builtins/system-config/system-config.addon.mjs +280 -280
  82. package/system/dist/builtins/winston-logging/index.js +1 -1
  83. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  84. package/system/dist/{capture-engine-DHvJXvuV.js → capture-engine-BO9mSlY-.js} +1 -1
  85. package/system/dist/{capture-engine-Ci4GwgjQ.mjs → capture-engine-ByF-6AFH.mjs} +1 -1
  86. package/system/dist/{composition-sources-CXJ0SzYJ.mjs → composition-sources-AziMFo7T.mjs} +1 -1
  87. package/system/dist/{composition-sources-B-WY9L7z.js → composition-sources-BMJUPUh2.js} +1 -1
  88. package/system/dist/{constants-DAuOjW5K.mjs → constants-CTikgsC_.mjs} +1 -1
  89. package/system/dist/{constants-DnJ2vuC7.js → constants-CjRlgRlu.js} +1 -1
  90. package/system/dist/{device-ca-D0HejZGK.mjs → device-ca-CNRlFqFC.mjs} +1 -1
  91. package/system/dist/{device-ca-BRpXm-B0.js → device-ca-Dxl6kVcJ.js} +1 -1
  92. package/system/dist/{dist-BLxWQm_m.mjs → dist-BPq13Y8j.mjs} +17392 -15506
  93. package/system/dist/{dist-DZQowBDF.js → dist-CkJnelZr.js} +17463 -15511
  94. package/system/dist/file-host-worker.js +1 -1
  95. package/system/dist/file-host-worker.mjs +1 -1
  96. package/system/dist/{hub-mdns-ciao-BJx5WmFx.mjs → hub-mdns-ciao-CrjItezp.mjs} +2 -2
  97. package/system/dist/{hub-mdns-ciao-ClSuN_QT.js → hub-mdns-ciao-Cx6yJBl9.js} +2 -2
  98. package/system/dist/index.js +67 -75
  99. package/system/dist/index.mjs +53 -68
  100. package/system/dist/kernel/cap-router-builder.d.ts +9 -0
  101. package/system/dist/kernel/command-observation.d.ts +76 -0
  102. package/system/dist/kernel/index.d.ts +2 -0
  103. package/system/dist/kernel/transport/child-cap-protocol.d.ts +10 -1
  104. package/system/dist/kernel/transport/local-child-registry.d.ts +15 -0
  105. package/system/dist/{legacy-integration-rows-door-BiNKE2zW.js → legacy-integration-rows-door-CKM-LxvL.js} +1 -1
  106. package/system/dist/{legacy-integration-rows-door-CN84_M7B.mjs → legacy-integration-rows-door-Dxcqwc-w.mjs} +1 -1
  107. package/system/dist/log-redactor-BhIEMaG9.js +149 -0
  108. package/system/dist/log-redactor-XLDrPzOi.mjs +120 -0
  109. package/system/dist/logging/log-redactor.d.ts +2 -0
  110. package/system/dist/{restore-archive-gLW5oc1w.mjs → restore-archive-BFA-hEhX.mjs} +78 -78
  111. package/system/dist/{restore-archive-Co1yYMV3.js → restore-archive-BQWOdGAB.js} +1 -1
  112. package/system/dist/{retention-BNONb5X_.js → retention-BcOSL6b9.js} +33 -2
  113. package/system/dist/{retention-B9l9TnGE.mjs → retention-CUOVI1p7.mjs} +33 -2
  114. package/system/dist/{wal-maintenance-BQaIM_cY.js → wal-maintenance-CiCgL4Hp.js} +0 -0
  115. package/system/dist/{wal-maintenance-Zji_8sLK.mjs → wal-maintenance-zJ4-ORo6.mjs} +0 -0
  116. package/system/package.json +7 -1
@@ -1,7 +1,7 @@
1
- import { $ as EMPTY_AUTOMATION_STATE, $i as proposeRunningThreshold, $n as coreBlockSourceKind, $r as isInternalActionId, A as ControlStatusSchema, Ai as normalizeActionUnits, Bn as checkTemplatePayload, C as CORE_BLOCKS_ADDON_ID, Cc as secretTreeFromSchema, Co as composedDeviceRef, Er as evaluateWhenTree, Et as MediaPlayerStatusSchema, Fa as stableIdMapOf, Fs as collectSecretMarkerRefs, Ft as PowerSourceInfoSchema, Gi as planComposition, Gn as compileScalarOverride, Gt as RemoteConfigSchema, Hn as collectWhenMirrorSources, Hs as defineRecordKinds, Ic as EventCategory$1, In as capUnitResolver, J as DeclaredDevices, Ja as timedRunLimitOf, Ji as powerSourceLinkOfComposition, Jn as compositionSourceRefs, Ka as templateCapability, Ko as BaseAddon, Kt as RunningStateStatusSchema, Li as occurrenceOn, Mi as normalizeCoreBlockWrite, Nc as DeviceType$1, Ni as normalizeStepTargets, No as helperMembers, Nr as fanPresetsCapability, O as ConditionMirror, Oc as transformSecretWrite, On as buildActionSteps, Oo as compositionSourceKey, Pc as errMsg$1, Po as historyRetentionFromSettings, Qn as coreBlockIdFromAddonId, R as DEFAULT_HOLD_OVERRIDE, S as COMPOSER_RUNNER_ID, Sa as schedulersCapability, Vt as REMOTE_MEDIA_COMMANDS, Wr as internalActionId, Wt as RemoteAssumedStateSchema, Xa as timedRunQuickRun, Xi as problemsBlockSave, Xn as coreBlockAddonId, Xs as hydrateSchema, Xt as SchedulerError, Ya as timedRunMaxIn, Za as timedRunSeconds, Zn as coreBlockComposition, Zt as SchedulerSchema, aa as remoteLayoutComponentsCapability, ac as isSecretMarker, an as SwitchStatusSchema, ba as runSteps, bc as resolveSecretMarkers, c as ActionError, co as weekdayOfLocalDate, d as ActionVariableSchema, da as resolveCoreBlockFiles, dn as actionSourceCapability, do as zoneOnlySite, eo as validateComposition, er as coreBlocksCapability, et as EMPTY_REMOTE_ASSUMED_STATE, fn as actionWaitTotalMs, fr as describeComposableCaps, gt as INTERNAL_ACTION_PREFIX, ht as IDLE_ACTION_STATUS, ia as remoteCapability, ii as kebabToCamel, ir as customRole, it as FanControlStatusSchema, j as CoreBlockSchema, ja as siteFor, ji as normalizeCapStep, ki as nextOccurrence, kn as buildCapabilityLookup, l as ActionStepSchema, m as BUILTIN_REMOTE_COMPONENTS, mi as lockDoorLinkOfComposition, mn as addonIdOfActionId, mo as DAY_MS, n as ACTION_TARGET_INVALIDATION_EVENTS, no as validateSchedulerInput, nt as FAN_CAPTURE_FIELDS, oa as replacedFieldKeys, on as TemplateKindSchema, ot as FanPresetSchema, p as AutomationStateDocSchema, pn as actionsCapability, po as CompositionSchema, qa as timedRunCapability, qi as powerSourceCapability, rr as customKeyOfRole, s as ALL_CAPABILITY_DEFINITIONS, sa as resolveActionVariables, sc as isSecretRefOwnedBy, so as vocabActionIdFor, tt as EMPTY_REMOTE_CONFIG, u as ActionTargetResolver, ua as resolveCoreBlockEntry, ui as localDateOf, un as actionEffect, va as resolveStepArgs, w as CORE_BLOCK_ADDON_PREFIX, xn as appendTrace, yo as HelperMemberSchema, zs as defineAddonMigrations, zt as QuantityUnitError } from "../../dist-BLxWQm_m.mjs";
1
+ import { $ as EMPTY_AUTOMATION_STATE, $a as timedRunLimitOf, $n as coreBlockSourceKind, A as ControlStatusSchema, Ac as resolveSecretMarkers, Ba as stableIdMapOf, Bc as vocabActionIdFor, Bn as checkTemplatePayload, C as CORE_BLOCKS_ADDON_ID, Ca as resolveStepArgs, Co as HelperMemberSchema, Da as schedulersCapability, Dn as buildActionSteps, Do as composedDeviceRef, Er as evaluateWhenTree, Et as MediaPlayerStatusSchema, Fi as normalizeStepTargets, Ft as PowerSourceInfoSchema, Gc as errMsg$1, Gn as compileScalarOverride, Gs as commandOrigin, Gt as RemoteConfigSchema, Hn as collectWhenMirrorSources, Hs as collectSecretMarkerRefs, Ia as siteFor, In as capUnitResolver, Ir as findChannelSource, J as DeclaredDevices, Jn as compositionSourceRefs, Js as defineAddonMigrations, Kr as internalActionId, Kt as RunningStateStatusSchema, Lo as helperMembers, Mi as normalizeActionUnits, Mo as compositionSourceKey, Ms as actionEffect, Nc as secretTreeFromSchema, Ni as normalizeCapStep, Nr as fanPresetsCapability, O as ConditionMirror, On as buildCapabilityLookup, Pi as normalizeCoreBlockWrite, Qa as timedRunCapability, Qi as problemsBlockSave, Qn as coreBlockIdFromAddonId, R as DEFAULT_HOLD_OVERRIDE, Rc as transformSecretWrite, Ro as historyRetentionFromSettings, S as COMPOSER_RUNNER_ID, Ta as runSteps, Vt as REMOTE_MEDIA_COMMANDS, Wc as DeviceType$1, Wr as heroLayoutCapability, Wt as RemoteAssumedStateSchema, Xi as powerSourceLinkOfComposition, Xn as coreBlockAddonId, Xo as BaseAddon, Xt as SchedulerError, Yi as powerSourceCapability, Za as templateCapability, Zn as coreBlockComposition, Zs as defineRecordKinds, Zt as SchedulerSchema, _c as isSecretRefOwnedBy, _o as CompositionSchema, ac as hydrateSchema, an as SwitchStatusSchema, ao as validateComposition, bn as appendTrace, c as ActionError, ca as remoteSourceSteps, d as ActionVariableSchema, dn as actionWaitTotalMs, dr as describeComposableCaps, eo as timedRunMaxIn, er as coreBlocksCapability, et as EMPTY_REMOTE_ASSUMED_STATE, fi as localDateOf, fn as actionsCapability, fo as weekdayOfLocalDate, gi as lockDoorLinkOfComposition, gt as INTERNAL_ACTION_PREFIX, ha as resolveHeroLayout, hc as isSecretMarker, ho as zoneOnlySite, ht as IDLE_ACTION_STATUS, it as FanControlStatusSchema, j as CoreBlockSchema, ji as nextOccurrence, jn as buildHeroModel, l as ActionStepSchema, la as replacedFieldKeys, m as BUILTIN_REMOTE_COMPONENTS, ma as resolveCoreBlockFiles, n as ACTION_TARGET_INVALIDATION_EVENTS, no as timedRunSeconds, nt as FAN_CAPTURE_FIELDS, oa as remoteCapability, oi as kebabToCamel, on as TemplateKindSchema, ot as FanPresetSchema, p as AutomationStateDocSchema, pa as resolveCoreBlockEntry, pn as addonIdOfActionId, qc as EventCategory$1, qi as planComposition, rr as customKeyOfRole, s as ALL_CAPABILITY_DEFINITIONS, sa as remoteLayoutComponentsCapability, so as validateSchedulerInput, ta as proposeRunningThreshold, ti as isInternalActionId, to as timedRunQuickRun, tt as EMPTY_REMOTE_CONFIG, u as ActionTargetResolver, ua as resolveActionVariables, un as actionSourceCapability, vo as DAY_MS, w as CORE_BLOCK_ADDON_PREFIX, xa as resolveRemoteSource, zi as occurrenceOn, zt as QuantityUnitError } from "../../dist-BPq13Y8j.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-CXJ0SzYJ.mjs";
4
- import { i as capSeriesKey } from "../../capture-engine-Ci4GwgjQ.mjs";
3
+ import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-AziMFo7T.mjs";
4
+ import { i as capSeriesKey } from "../../capture-engine-ByF-6AFH.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 { createRequire } from "node:module";
@@ -2852,7 +2852,7 @@ var ActionsService = class {
2852
2852
  let message;
2853
2853
  const deadline = this.armDeadline(entry.id, runId, token);
2854
2854
  try {
2855
- const running = runSteps(this.runnableFor(entry, values, token), {
2855
+ const running = runSteps(this.runnableFor(entry, values, token, runId), {
2856
2856
  pathPrefix: "steps",
2857
2857
  isAborted: () => token.aborted,
2858
2858
  abortReason: "the run was stopped",
@@ -2956,9 +2956,16 @@ var ActionsService = class {
2956
2956
  }
2957
2957
  };
2958
2958
  }
2959
- runnableFor(entry, values, token) {
2959
+ runnableFor(entry, values, token, runId) {
2960
2960
  if (entry.source === "internal") return buildActionSteps(entry.steps ?? [], values, {
2961
- invokeCap: (call) => this.invokeCap(call),
2961
+ invokeCap: (call) => this.invokeCap({
2962
+ ...call,
2963
+ origin: {
2964
+ kind: "action",
2965
+ actionId: entry.id,
2966
+ runId
2967
+ }
2968
+ }),
2962
2969
  sleep: (ms) => token.sleep(ms),
2963
2970
  resolveTarget: (target, actionId, vars, origin) => this.targets.resolve(target, actionId, vars, origin),
2964
2971
  owner: entry.id,
@@ -3395,10 +3402,11 @@ function invokeCapOver(api) {
3395
3402
  const procedure = client !== null && client !== void 0 ? Reflect.get(Object(client), call.method) : void 0;
3396
3403
  const mutate = procedure !== null && procedure !== void 0 ? Reflect.get(Object(procedure), "mutate") : void 0;
3397
3404
  if (typeof mutate !== "function") throw new Error(`no such device method: ${call.cap}.${call.method}`);
3398
- await Reflect.apply(mutate, procedure, [{
3405
+ const input = {
3399
3406
  ...call.args,
3400
3407
  deviceId: call.deviceId
3401
- }]);
3408
+ };
3409
+ await Reflect.apply(mutate, procedure, call.origin === void 0 ? [input] : [input, commandOrigin(call.origin)]);
3402
3410
  };
3403
3411
  }
3404
3412
  /**
@@ -4897,7 +4905,13 @@ var SchedulerEngine = class {
4897
4905
  throw new OverriddenError(refusal);
4898
4906
  }
4899
4907
  try {
4900
- await this.deps.host.invokeCap(call);
4908
+ await this.deps.host.invokeCap({
4909
+ ...call,
4910
+ origin: {
4911
+ kind: "scheduler",
4912
+ schedulerId: scheduler.id
4913
+ }
4914
+ });
4901
4915
  } catch (err) {
4902
4916
  failedCalls += 1;
4903
4917
  throw err;
@@ -5429,6 +5443,79 @@ var RemoteComponentsService = class {
5429
5443
  }
5430
5444
  };
5431
5445
  //#endregion
5446
+ //#region src/builtins/core-blocks/hero-layout-service.ts
5447
+ /**
5448
+ * The `hero-layout` provider of core-blocks (D1023): serves the FIXED layouts
5449
+ * and the built hero model. Read-only — it stores nothing and edits nothing.
5450
+ *
5451
+ * `getHeroModel` reads the device, its bindings (per device, D12) and one slice
5452
+ * per bound cap through an injected reader, then hands everything to the pure
5453
+ * `buildHeroModel`. A slice that cannot be read is simply absent: the model
5454
+ * says "not answered", never "off" (D315/D393). The remote's saved command
5455
+ * count comes from the remote cap and is `null` when it cannot be asked.
5456
+ */
5457
+ var REMOTE_CAP = "remote";
5458
+ var HeroLayoutService = class {
5459
+ deps;
5460
+ constructor(deps) {
5461
+ this.deps = deps;
5462
+ }
5463
+ getLayout = async ({ deviceType }) => ({
5464
+ type: deviceType,
5465
+ rows: [...resolveHeroLayout(deviceType).rows]
5466
+ });
5467
+ getHeroModel = async ({ deviceId, canActuate }) => {
5468
+ const { reader, logger } = this.deps;
5469
+ const device = await reader.device(deviceId);
5470
+ if (device === null) {
5471
+ logger.warn("hero model: device not found", { tags: { deviceId } });
5472
+ return null;
5473
+ }
5474
+ const bound = await reader.caps(deviceId);
5475
+ const slices = {};
5476
+ await Promise.all(bound.filter((cap) => cap !== REMOTE_CAP).map(async (cap) => {
5477
+ try {
5478
+ slices[cap] = await reader.slice(deviceId, cap);
5479
+ } catch (error) {
5480
+ logger.warn("hero model: a cap slice could not be read; drawn as not answered", {
5481
+ tags: { deviceId },
5482
+ meta: {
5483
+ cap,
5484
+ error: error instanceof Error ? error.message : String(error)
5485
+ }
5486
+ });
5487
+ }
5488
+ }));
5489
+ const remoteCommands = await this.remoteCommands(deviceId);
5490
+ return buildHeroModel({
5491
+ device: {
5492
+ id: deviceId,
5493
+ type: device.type,
5494
+ role: device.role,
5495
+ name: device.name,
5496
+ online: device.online
5497
+ },
5498
+ caps: [...bound.filter((cap) => cap !== REMOTE_CAP), REMOTE_CAP],
5499
+ features: device.features,
5500
+ slices,
5501
+ now: this.deps.now(),
5502
+ remoteCommands,
5503
+ access: { canActuate: canActuate ?? true }
5504
+ });
5505
+ };
5506
+ async remoteCommands(deviceId) {
5507
+ try {
5508
+ return await this.deps.reader.remoteCommands(deviceId);
5509
+ } catch (error) {
5510
+ this.deps.logger.warn("hero model: the remote could not be asked; its button shows without a count", {
5511
+ tags: { deviceId },
5512
+ meta: { error: error instanceof Error ? error.message : String(error) }
5513
+ });
5514
+ return null;
5515
+ }
5516
+ }
5517
+ };
5518
+ //#endregion
5432
5519
  //#region src/builtins/core-blocks/lock-door-gate.ts
5433
5520
  var LOCK_CONTROL = "lock-control";
5434
5521
  var DOOR_OPEN = "door-open";
@@ -5547,7 +5634,7 @@ async function seedLockDoors(deps) {
5547
5634
  * an automation, an exporter, a forked addon — never in a UI.
5548
5635
  *
5549
5636
  * - A media-player command (`play`, `pause`, `stop`, `next`, `previous`,
5550
- * `setMute`, `selectSource`) on a device whose remote binds the command's
5637
+ * `setMute`, `selectSource`, `playMedia` of a channel) on a device whose remote binds the command's
5551
5638
  * role runs the binding. An unbound role falls through to the native cap.
5552
5639
  * A binding that FAILS fails the call: the native cap never silently runs in
5553
5640
  * its place. `repeat`, where the caller supplies one, is passed through.
@@ -5560,7 +5647,7 @@ async function seedLockDoors(deps) {
5560
5647
  */
5561
5648
  var MEDIA_PLAYER = "media-player";
5562
5649
  var COMMANDS = new Set(REMOTE_MEDIA_COMMANDS);
5563
- function isCommand(method) {
5650
+ function isCommand$1(method) {
5564
5651
  return COMMANDS.has(method);
5565
5652
  }
5566
5653
  function field(args, key) {
@@ -5584,11 +5671,15 @@ function remoteCallRedirect(deps) {
5584
5671
  const command = async (call, name) => {
5585
5672
  const muted = field(call.args, "muted");
5586
5673
  const source = field(call.args, "source");
5674
+ const mediaType = field(call.args, "mediaType");
5675
+ const mediaId = field(call.args, "mediaId");
5587
5676
  const result = await deps.remote.sendMediaCommand({
5588
5677
  deviceId: call.deviceId,
5589
5678
  command: name,
5590
5679
  ...typeof muted === "boolean" ? { muted } : {},
5591
5680
  ...typeof source === "string" ? { source } : {},
5681
+ ...typeof mediaType === "string" ? { mediaType } : {},
5682
+ ...typeof mediaId === "string" ? { mediaId } : {},
5592
5683
  repeat: repeatOf(call.args)
5593
5684
  });
5594
5685
  switch (result.status) {
@@ -5611,10 +5702,10 @@ function remoteCallRedirect(deps) {
5611
5702
  }
5612
5703
  };
5613
5704
  return {
5614
- covers: (capName, method) => capName === MEDIA_PLAYER && (method === "getStatus" || isCommand(method)),
5705
+ covers: (capName, method) => capName === MEDIA_PLAYER && (method === "getStatus" || isCommand$1(method)),
5615
5706
  attempt: async (call) => {
5616
5707
  if (call.method === "getStatus") return status(call);
5617
- return isCommand(call.method) ? command(call, call.method) : { kind: "not-redirected" };
5708
+ return isCommand$1(call.method) ? command(call, call.method) : { kind: "not-redirected" };
5618
5709
  }
5619
5710
  };
5620
5711
  }
@@ -5637,7 +5728,8 @@ function rolesFor(command) {
5637
5728
  case "volumeDown": return ["volume_down"];
5638
5729
  case "channelUp": return ["channel_up"];
5639
5730
  case "channelDown": return ["channel_down"];
5640
- case "selectSource": return [];
5731
+ case "selectSource":
5732
+ case "playMedia": return [];
5641
5733
  }
5642
5734
  }
5643
5735
  function errorText(err) {
@@ -5647,14 +5739,18 @@ var RemoteService = class {
5647
5739
  deps;
5648
5740
  now;
5649
5741
  sleep;
5742
+ lockTimeoutMs;
5650
5743
  /** Remote devices seen so far, and the plug each one waits on: who an input event affects. */
5651
5744
  plugOf = /* @__PURE__ */ new Map();
5652
5745
  sliceRuns = /* @__PURE__ */ new Map();
5653
5746
  slicePending = /* @__PURE__ */ new Set();
5747
+ /** The tail of each device's presses: a sequence is never interleaved with another press. */
5748
+ locks = /* @__PURE__ */ new Map();
5654
5749
  constructor(deps) {
5655
5750
  this.deps = deps;
5656
5751
  this.now = deps.now ?? Date.now;
5657
5752
  this.sleep = deps.sleep ?? realSleep;
5753
+ this.lockTimeoutMs = deps.lockTimeoutMs ?? 6e4;
5658
5754
  }
5659
5755
  getConfig = async ({ deviceId }) => this.deps.store.read(deviceId);
5660
5756
  setConfig = async ({ deviceId, config }) => {
@@ -5686,7 +5782,8 @@ var RemoteService = class {
5686
5782
  return {
5687
5783
  layoutTemplateId: config.layoutTemplateId,
5688
5784
  power: config.power,
5689
- commands
5785
+ commands,
5786
+ sources: config.sources
5690
5787
  };
5691
5788
  };
5692
5789
  sendCommand = async ({ deviceId, role, repeat }) => {
@@ -5696,6 +5793,8 @@ var RemoteService = class {
5696
5793
  sendMediaCommand = async (input) => {
5697
5794
  const { deviceId, repeat } = input;
5698
5795
  const config = await this.deps.store.read(deviceId);
5796
+ if (input.command === "selectSource") return this.selectSource(deviceId, config, input.source);
5797
+ if (input.command === "playMedia") return this.playMedia(deviceId, config, input.mediaType, input.mediaId);
5699
5798
  const role = this.mediaRole(config, input);
5700
5799
  if (role === null) return { status: "not-routed" };
5701
5800
  if (input.command === "setMute" && input.muted !== void 0) return this.setMute(deviceId, config, role, input.muted);
@@ -5761,17 +5860,19 @@ var RemoteService = class {
5761
5860
  */
5762
5861
  getAssumedStatus = async ({ deviceId }) => {
5763
5862
  const kept = await this.readAssumed(deviceId);
5764
- if (kept.power === null && kept.muted === null) return null;
5863
+ if (kept.power === null && kept.muted === null && kept.source === null) return null;
5765
5864
  const config = await this.deps.store.read(deviceId);
5766
5865
  const assumedFields = [];
5767
5866
  if (kept.power !== null) assumedFields.push("state");
5768
5867
  if (kept.muted !== null) assumedFields.push("isMuted");
5868
+ if (kept.source !== null) assumedFields.push("source");
5769
5869
  return this.buildStatus({
5770
5870
  state: kept.power?.state ?? "standby",
5771
5871
  assumedFields,
5772
5872
  muted: kept.muted?.value ?? null,
5773
- changedAt: Math.max(kept.power?.at ?? 0, kept.muted?.at ?? 0),
5774
- sources: config.customButtons.map((b) => b.name)
5873
+ source: kept.source?.name ?? "",
5874
+ changedAt: Math.max(kept.power?.at ?? 0, kept.muted?.at ?? 0, kept.source?.at ?? 0),
5875
+ sources: config.sources
5775
5876
  });
5776
5877
  };
5777
5878
  /**
@@ -5794,13 +5895,16 @@ var RemoteService = class {
5794
5895
  const changedAt = truth.at;
5795
5896
  const mute = state === "off" ? null : kept.muted ?? null;
5796
5897
  if (mute !== null) assumedFields.push("isMuted");
5898
+ const source = state === "off" ? null : kept.source ?? null;
5899
+ if (source !== null) assumedFields.push("source");
5797
5900
  const config = await this.deps.store.read(deviceId);
5798
5901
  return this.buildStatus({
5799
5902
  state,
5800
5903
  assumedFields,
5801
5904
  muted: mute?.value ?? null,
5802
- changedAt: Math.max(changedAt, mute?.at ?? 0),
5803
- sources: config.customButtons.map((b) => b.name)
5905
+ source: source?.name ?? "",
5906
+ changedAt: Math.max(changedAt, mute?.at ?? 0, source?.at ?? 0),
5907
+ sources: config.sources
5804
5908
  });
5805
5909
  }
5806
5910
  buildStatus(input) {
@@ -5810,8 +5914,16 @@ var RemoteService = class {
5810
5914
  assumedFields: [...input.assumedFields],
5811
5915
  volumeLevel: null,
5812
5916
  isMuted: input.muted,
5813
- source: "",
5814
- availableSources: [...input.sources],
5917
+ source: input.source,
5918
+ availableSources: input.sources.map((source) => source.name),
5919
+ declaredSources: input.sources.map((source) => source.kind === "digits" ? {
5920
+ name: source.name,
5921
+ kind: source.kind,
5922
+ number: source.number
5923
+ } : {
5924
+ name: source.name,
5925
+ kind: source.kind
5926
+ }),
5815
5927
  currentMedia: null,
5816
5928
  position: null,
5817
5929
  duration: null,
@@ -5822,13 +5934,6 @@ var RemoteService = class {
5822
5934
  };
5823
5935
  }
5824
5936
  mediaRole(config, input) {
5825
- if (input.command === "selectSource") {
5826
- const wanted = input.source;
5827
- const button = config.customButtons.find((b) => b.name === wanted || b.key === wanted);
5828
- if (button === void 0) return null;
5829
- const role = customRole(button.key);
5830
- return config.bindings[role] === void 0 ? null : role;
5831
- }
5832
5937
  for (const role of rolesFor(input.command)) if (this.isBound(config, role)) return role;
5833
5938
  return null;
5834
5939
  }
@@ -5863,9 +5968,10 @@ var RemoteService = class {
5863
5968
  const plug = await this.deps.plugOn(deviceId);
5864
5969
  const kept = await this.readAssumed(deviceId);
5865
5970
  if (plug === false) {
5866
- if (forget && kept.power !== null) await this.deps.assumptions.write(deviceId, {
5971
+ if (forget && (kept.power !== null || kept.source !== null)) await this.deps.assumptions.write(deviceId, {
5867
5972
  ...kept,
5868
- power: null
5973
+ power: null,
5974
+ source: null
5869
5975
  });
5870
5976
  return {
5871
5977
  state: "off",
@@ -5925,7 +6031,183 @@ var RemoteService = class {
5925
6031
  }
5926
6032
  return result;
5927
6033
  }
5928
- async run(deviceId, config, role, repeat) {
6034
+ /**
6035
+ * Runs `fn` after every earlier press of the device has finished. A press that
6036
+ * does not finish within `lockTimeoutMs` is given up: the caller is told
6037
+ * (`press-timeout`) and the lock is released, so one hung press never wedges
6038
+ * the presses behind it.
6039
+ */
6040
+ async withLock(deviceId, fn) {
6041
+ const result = (this.locks.get(deviceId) ?? Promise.resolve()).then(() => this.boundedPress(deviceId, fn));
6042
+ const tail = result.then(() => void 0, () => void 0);
6043
+ this.locks.set(deviceId, tail);
6044
+ try {
6045
+ return await result;
6046
+ } finally {
6047
+ if (this.locks.get(deviceId) === tail) this.locks.delete(deviceId);
6048
+ }
6049
+ }
6050
+ async boundedPress(deviceId, fn) {
6051
+ const giveUp = new AbortController();
6052
+ let timer;
6053
+ const expired = new Promise((resolve) => {
6054
+ timer = setTimeout(() => resolve("timeout"), this.lockTimeoutMs);
6055
+ });
6056
+ const started = fn(giveUp.signal);
6057
+ try {
6058
+ const outcome = await Promise.race([started, expired]);
6059
+ if (outcome !== "timeout") return outcome;
6060
+ giveUp.abort();
6061
+ started.catch(() => void 0);
6062
+ this.deps.logger.warn("remote: a press never finished, it was given up", {
6063
+ tags: { deviceId },
6064
+ meta: { timeoutMs: this.lockTimeoutMs }
6065
+ });
6066
+ return {
6067
+ status: "refused",
6068
+ reason: "press-timeout",
6069
+ detail: `the press did not finish within ${this.lockTimeoutMs} ms`
6070
+ };
6071
+ } finally {
6072
+ clearTimeout(timer);
6073
+ }
6074
+ }
6075
+ run(deviceId, config, role, repeat) {
6076
+ return this.withLock(deviceId, () => this.runRole(deviceId, config, role, repeat));
6077
+ }
6078
+ /**
6079
+ * `selectSource(name)`: the declared source a name (or its channel number)
6080
+ * points at. A remote that declares none leaves the call to the native cap.
6081
+ */
6082
+ async selectSource(deviceId, config, wanted) {
6083
+ if (config.sources.length === 0) return { status: "not-routed" };
6084
+ const source = wanted === void 0 ? null : resolveRemoteSource(config.sources, wanted);
6085
+ if (source === null) {
6086
+ this.deps.logger.warn("remote: no declared source answers to that name, nothing was sent", {
6087
+ tags: { deviceId },
6088
+ meta: { wanted: wanted ?? null }
6089
+ });
6090
+ return {
6091
+ status: "refused",
6092
+ reason: "unknown-source",
6093
+ detail: `no source "${wanted ?? ""}" is declared`
6094
+ };
6095
+ }
6096
+ return this.runSource(deviceId, config, source);
6097
+ }
6098
+ /** `playMedia` of a channel: the `digits` source that declares the number, else a refusal. */
6099
+ async playMedia(deviceId, config, mediaType, mediaId) {
6100
+ if (mediaType !== "channel" || config.sources.length === 0) return { status: "not-routed" };
6101
+ const source = mediaId === void 0 ? null : findChannelSource(config.sources, mediaId);
6102
+ if (source === null) {
6103
+ this.deps.logger.warn("remote: no source declares that channel, nothing was sent", {
6104
+ tags: { deviceId },
6105
+ meta: { channel: mediaId ?? null }
6106
+ });
6107
+ return {
6108
+ status: "refused",
6109
+ reason: "undeclared-channel",
6110
+ detail: `channel ${mediaId ?? ""} is not declared`
6111
+ };
6112
+ }
6113
+ return this.runSource(deviceId, config, source);
6114
+ }
6115
+ /**
6116
+ * Presses a source's steps in order, one lock for the whole sequence,
6117
+ * `stepDelayMs` apart. Every step is checked bound BEFORE the first press, so
6118
+ * a half-bound source sends nothing. A step that fails stops the sequence.
6119
+ */
6120
+ async runSource(deviceId, config, source) {
6121
+ const steps = remoteSourceSteps(source);
6122
+ const missing = steps.findIndex((role) => !this.isBound(config, role));
6123
+ if (missing >= 0) {
6124
+ const role = steps[missing] ?? "";
6125
+ this.deps.logger.warn("remote: a step of the source is not bound, nothing was sent", {
6126
+ tags: { deviceId },
6127
+ meta: {
6128
+ source: source.name,
6129
+ step: missing + 1,
6130
+ role
6131
+ }
6132
+ });
6133
+ return {
6134
+ status: "refused",
6135
+ reason: "unbound-step",
6136
+ detail: `step ${missing + 1}/${steps.length} (${role}) is not bound`,
6137
+ step: {
6138
+ index: missing + 1,
6139
+ role
6140
+ }
6141
+ };
6142
+ }
6143
+ return this.withLock(deviceId, async (abandoned) => {
6144
+ for (const [at, role] of steps.entries()) {
6145
+ if (at > 0) await this.sleep(config.stepDelayMs);
6146
+ if (abandoned.aborted) {
6147
+ this.deps.logger.warn("remote: the sequence was abandoned, no further step was sent", {
6148
+ tags: { deviceId },
6149
+ meta: {
6150
+ source: source.name,
6151
+ step: at + 1,
6152
+ role
6153
+ }
6154
+ });
6155
+ if (at > 0) await this.forgetSource(deviceId);
6156
+ return {
6157
+ status: "refused",
6158
+ reason: "press-timeout",
6159
+ detail: `abandoned before step ${at + 1}/${steps.length} (${role})`,
6160
+ step: {
6161
+ index: at + 1,
6162
+ role
6163
+ }
6164
+ };
6165
+ }
6166
+ const result = await this.runRole(deviceId, config, role, 1);
6167
+ if (result.status === "refused") {
6168
+ if (at > 0) await this.forgetSource(deviceId);
6169
+ this.deps.logger.warn("remote: a step of the source failed, the sequence stopped", {
6170
+ tags: { deviceId },
6171
+ meta: {
6172
+ source: source.name,
6173
+ step: at + 1,
6174
+ role,
6175
+ reason: result.reason
6176
+ }
6177
+ });
6178
+ return {
6179
+ ...result,
6180
+ detail: `step ${at + 1}/${steps.length} (${role}): ${result.detail ?? result.reason}`,
6181
+ step: {
6182
+ index: at + 1,
6183
+ role
6184
+ }
6185
+ };
6186
+ }
6187
+ }
6188
+ const kept = await this.readAssumed(deviceId);
6189
+ await this.deps.assumptions.write(deviceId, {
6190
+ ...kept,
6191
+ source: {
6192
+ name: source.name,
6193
+ at: this.now()
6194
+ }
6195
+ });
6196
+ await this.refreshSlice(deviceId);
6197
+ return {
6198
+ status: "sent",
6199
+ sends: steps.length
6200
+ };
6201
+ });
6202
+ }
6203
+ async forgetSource(deviceId) {
6204
+ const kept = await this.readAssumed(deviceId);
6205
+ if (kept.source !== null) await this.deps.assumptions.write(deviceId, {
6206
+ ...kept,
6207
+ source: null
6208
+ });
6209
+ }
6210
+ async runRole(deviceId, config, role, repeat) {
5929
6211
  const wantsState = role === "power_on" ? "on" : role === "power_off" ? "off" : null;
5930
6212
  const viaToggle = wantsState !== null && config.bindings[role] === void 0;
5931
6213
  const bound = viaToggle ? config.bindings["power"] : config.bindings[role];
@@ -5993,19 +6275,29 @@ var RemoteService = class {
5993
6275
  power: {
5994
6276
  state: wantsState,
5995
6277
  at: this.now()
5996
- }
6278
+ },
6279
+ source: wantsState === "off" ? null : kept.source
5997
6280
  });
5998
6281
  return;
5999
6282
  }
6000
6283
  if (role === "power") {
6001
6284
  const before = await this.currentState(deviceId);
6002
6285
  if (before === null) return;
6286
+ const next = before === "on" ? "off" : "on";
6003
6287
  await this.deps.assumptions.write(deviceId, {
6004
6288
  ...kept,
6005
6289
  power: {
6006
- state: before === "on" ? "off" : "on",
6290
+ state: next,
6007
6291
  at: this.now()
6008
- }
6292
+ },
6293
+ source: next === "off" ? null : kept.source
6294
+ });
6295
+ return;
6296
+ }
6297
+ if (role === "channel_up" || role === "channel_down") {
6298
+ if (kept.source !== null) await this.deps.assumptions.write(deviceId, {
6299
+ ...kept,
6300
+ source: null
6009
6301
  });
6010
6302
  return;
6011
6303
  }
@@ -7872,10 +8164,44 @@ var CoreBlocksAddon = class extends BaseAddon {
7872
8164
  capability: remoteLayoutComponentsCapability,
7873
8165
  provider: new RemoteComponentsService()
7874
8166
  },
8167
+ {
8168
+ capability: heroLayoutCapability,
8169
+ provider: this.buildHeroLayout()
8170
+ },
7875
8171
  ...this.remoteRegistrations(),
7876
8172
  ...this.fanPresetRegistrations()
7877
8173
  ];
7878
8174
  }
8175
+ /** Read-only: the fixed layouts and the model built from the device's bindings and slices. */
8176
+ buildHeroLayout() {
8177
+ const requireApi = () => {
8178
+ const api = this.ctx.api;
8179
+ if (!api) throw new Error("core-blocks: no ctx.api on this node — hero-layout cannot reach devices");
8180
+ return api;
8181
+ };
8182
+ return new HeroLayoutService({
8183
+ logger: this.ctx.logger.child("hero-layout"),
8184
+ now: () => Date.now(),
8185
+ reader: {
8186
+ device: async (deviceId) => {
8187
+ const found = await requireApi().deviceManager.getDevice.query({ deviceId });
8188
+ return found === null ? null : {
8189
+ type: found.type,
8190
+ role: found.role ?? null,
8191
+ name: found.name,
8192
+ online: found.online,
8193
+ features: found.features
8194
+ };
8195
+ },
8196
+ caps: async (deviceId) => (await requireApi().deviceManager.getBindings.query({ deviceId })).entries.map((e) => e.capName),
8197
+ slice: (deviceId, capName) => requireApi().deviceState.getCapSlice.query({
8198
+ deviceId,
8199
+ capName
8200
+ }),
8201
+ remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length
8202
+ }
8203
+ });
8204
+ }
7879
8205
  buildPowerSource() {
7880
8206
  const service = new PowerSourceService({
7881
8207
  blocks: () => this.store?.list() ?? [],
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The `hero-layout` provider of core-blocks (D1023): serves the FIXED layouts
3
+ * and the built hero model. Read-only — it stores nothing and edits nothing.
4
+ *
5
+ * `getHeroModel` reads the device, its bindings (per device, D12) and one slice
6
+ * per bound cap through an injected reader, then hands everything to the pure
7
+ * `buildHeroModel`. A slice that cannot be read is simply absent: the model
8
+ * says "not answered", never "off" (D315/D393). The remote's saved command
9
+ * count comes from the remote cap and is `null` when it cannot be asked.
10
+ */
11
+ import { type IHeroLayoutProvider, type IScopedLogger } from "@camstack/types";
12
+ /** What the registry says about the device. */
13
+ export interface HeroDeviceFacts {
14
+ readonly type: string;
15
+ readonly role: string | null;
16
+ readonly name: string;
17
+ readonly online: boolean;
18
+ readonly features: readonly string[];
19
+ }
20
+ /** The reads the service needs; the addon wires them to `ctx.api`. */
21
+ export interface HeroLayoutReader {
22
+ /** The device facts, or null when the registry does not know it. */
23
+ readonly device: (deviceId: number) => Promise<HeroDeviceFacts | null>;
24
+ /** Kebab cap names the device is bound to. */
25
+ readonly caps: (deviceId: number) => Promise<readonly string[]>;
26
+ /** The raw slice of one cap on the device; throws when it cannot be read. */
27
+ readonly slice: (deviceId: number, capName: string) => Promise<unknown>;
28
+ /** Saved remote commands; throws when the remote cannot be asked. */
29
+ readonly remoteCommands: (deviceId: number) => Promise<number>;
30
+ }
31
+ export interface HeroLayoutServiceDeps {
32
+ readonly reader: HeroLayoutReader;
33
+ readonly logger: IScopedLogger;
34
+ readonly now: () => number;
35
+ }
36
+ export declare class HeroLayoutService implements IHeroLayoutProvider {
37
+ private readonly deps;
38
+ constructor(deps: HeroLayoutServiceDeps);
39
+ readonly getLayout: IHeroLayoutProvider["getLayout"];
40
+ readonly getHeroModel: IHeroLayoutProvider["getHeroModel"];
41
+ private remoteCommands;
42
+ }
@@ -4,7 +4,7 @@
4
4
  * an automation, an exporter, a forked addon — never in a UI.
5
5
  *
6
6
  * - A media-player command (`play`, `pause`, `stop`, `next`, `previous`,
7
- * `setMute`, `selectSource`) on a device whose remote binds the command's
7
+ * `setMute`, `selectSource`, `playMedia` of a channel) on a device whose remote binds the command's
8
8
  * role runs the binding. An unbound role falls through to the native cap.
9
9
  * A binding that FAILS fails the call: the native cap never silently runs in
10
10
  * its place. `repeat`, where the caller supplies one, is passed through.