@camstack/server 1.2.809 → 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 (118) hide show
  1. package/CHANGELOG.md +17 -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 +10 -8
  8. package/system/dist/addon-runner.js +4 -1
  9. package/system/dist/addon-runner.mjs +5 -2
  10. package/system/dist/{agent-https-DS4b0ucn.mjs → agent-https-CyEBY3RB.mjs} +1 -1
  11. package/system/dist/{agent-https-CuChFRA2.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/backup-orchestrator/destination-policy.d.ts +1 -1
  23. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  24. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  25. package/system/dist/builtins/camera-grid/index.js +1 -1
  26. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  27. package/system/dist/builtins/composer/composer.addon.js +6 -5
  28. package/system/dist/builtins/composer/composer.addon.mjs +6 -5
  29. package/system/dist/builtins/console-logging/index.js +1 -1
  30. package/system/dist/builtins/console-logging/index.mjs +1 -1
  31. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +2 -0
  32. package/system/dist/builtins/core-blocks/core-blocks.addon.js +358 -32
  33. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +361 -35
  34. package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +42 -0
  35. package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +1 -1
  36. package/system/dist/builtins/core-blocks/remote-service.d.ts +38 -0
  37. package/system/dist/builtins/device-history/device-history.addon.d.ts +5 -0
  38. package/system/dist/builtins/device-history/device-history.addon.js +357 -18
  39. package/system/dist/builtins/device-history/device-history.addon.mjs +357 -18
  40. package/system/dist/builtins/device-history/retention/retention.d.ts +14 -1
  41. package/system/dist/builtins/device-history/transitions/device-transitions-record-kinds.d.ts +14 -0
  42. package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +80 -0
  43. package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
  44. package/system/dist/builtins/device-manager/device-manager.addon.js +712 -18
  45. package/system/dist/builtins/device-manager/device-manager.addon.mjs +780 -95
  46. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
  47. package/system/dist/builtins/device-manager/transitions/command-args.d.ts +4 -0
  48. package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +68 -0
  49. package/system/dist/builtins/device-manager/transitions/transitions-sender.d.ts +37 -0
  50. package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +25 -0
  51. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  52. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  53. package/system/dist/builtins/keychain/index.js +4 -4
  54. package/system/dist/builtins/keychain/index.mjs +4 -4
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  56. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  57. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  58. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  60. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  61. package/system/dist/builtins/loki-logging/index.js +8 -2
  62. package/system/dist/builtins/loki-logging/index.mjs +8 -2
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  64. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  65. package/system/dist/builtins/platform-probe/index.js +1 -1
  66. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  67. package/system/dist/builtins/record-entries/index.js +1 -1
  68. package/system/dist/builtins/record-entries/index.mjs +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  70. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  71. package/system/dist/builtins/snapshot/index.js +1 -1
  72. package/system/dist/builtins/snapshot/index.mjs +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  74. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  76. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  79. package/system/dist/builtins/storage-orchestrator/location-store.d.ts +0 -6
  80. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  81. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  82. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  83. package/system/dist/builtins/system-config/system-config.addon.mjs +7 -7
  84. package/system/dist/builtins/winston-logging/index.js +1 -1
  85. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  86. package/system/dist/{capture-engine-Byc5Fkp0.js → capture-engine-BO9mSlY-.js} +1 -1
  87. package/system/dist/{capture-engine-CnVIcnyN.mjs → capture-engine-ByF-6AFH.mjs} +1 -1
  88. package/system/dist/{composition-sources-BhM6G9QT.mjs → composition-sources-AziMFo7T.mjs} +1 -1
  89. package/system/dist/{composition-sources-BxK6ttP9.js → composition-sources-BMJUPUh2.js} +1 -1
  90. package/system/dist/{constants-Bf1PEHRU.mjs → constants-CTikgsC_.mjs} +1 -1
  91. package/system/dist/{constants--xo6Q-KA.js → constants-CjRlgRlu.js} +1 -1
  92. package/system/dist/{device-ca-Do0-HV_h.mjs → device-ca-CNRlFqFC.mjs} +1 -1
  93. package/system/dist/{device-ca-Uq5KGFSq.js → device-ca-Dxl6kVcJ.js} +1 -1
  94. package/system/dist/{dist-CogtCQxu.mjs → dist-BPq13Y8j.mjs} +17544 -15612
  95. package/system/dist/{dist-2SHQaxaS.js → dist-CkJnelZr.js} +17615 -15617
  96. package/system/dist/file-host-worker.js +1 -1
  97. package/system/dist/file-host-worker.mjs +1 -1
  98. package/system/dist/{hub-mdns-ciao-aFHCKrif.mjs → hub-mdns-ciao-CrjItezp.mjs} +2 -2
  99. package/system/dist/{hub-mdns-ciao-DqPrLiYH.js → hub-mdns-ciao-Cx6yJBl9.js} +2 -2
  100. package/system/dist/index.js +67 -75
  101. package/system/dist/index.mjs +53 -68
  102. package/system/dist/kernel/cap-router-builder.d.ts +9 -0
  103. package/system/dist/kernel/command-observation.d.ts +76 -0
  104. package/system/dist/kernel/index.d.ts +2 -0
  105. package/system/dist/kernel/transport/child-cap-protocol.d.ts +10 -1
  106. package/system/dist/kernel/transport/local-child-registry.d.ts +15 -0
  107. package/system/dist/{legacy-integration-rows-door-Bz8rivxI.js → legacy-integration-rows-door-CKM-LxvL.js} +1 -1
  108. package/system/dist/{legacy-integration-rows-door-CiuxDLoc.mjs → legacy-integration-rows-door-Dxcqwc-w.mjs} +1 -1
  109. package/system/dist/log-redactor-BhIEMaG9.js +149 -0
  110. package/system/dist/log-redactor-XLDrPzOi.mjs +120 -0
  111. package/system/dist/logging/log-redactor.d.ts +2 -0
  112. package/system/dist/{restore-archive-PlBC2NwT.mjs → restore-archive-BFA-hEhX.mjs} +5 -5
  113. package/system/dist/{restore-archive-D-3wmHDq.js → restore-archive-BQWOdGAB.js} +1 -1
  114. package/system/dist/{retention-BNONb5X_.js → retention-BcOSL6b9.js} +33 -2
  115. package/system/dist/{retention-B9l9TnGE.mjs → retention-CUOVI1p7.mjs} +33 -2
  116. package/system/dist/{wal-maintenance-BTR55y--.js → wal-maintenance-CiCgL4Hp.js} +0 -0
  117. package/system/dist/{wal-maintenance-jrhYTCn2.mjs → wal-maintenance-zJ4-ORo6.mjs} +0 -0
  118. package/system/package.json +7 -1
@@ -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-2SHQaxaS.js");
3
+ const require_dist = require("../../dist-CkJnelZr.js");
4
4
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
5
- const require_composition_sources = require("../../composition-sources-BxK6ttP9.js");
6
- const require_capture_engine = require("../../capture-engine-Byc5Fkp0.js");
5
+ const require_composition_sources = require("../../composition-sources-BMJUPUh2.js");
6
+ const require_capture_engine = require("../../capture-engine-BO9mSlY-.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
  let zod = require("zod");
@@ -2858,7 +2858,7 @@ var ActionsService = class {
2858
2858
  let message;
2859
2859
  const deadline = this.armDeadline(entry.id, runId, token);
2860
2860
  try {
2861
- const running = require_dist.runSteps(this.runnableFor(entry, values, token), {
2861
+ const running = require_dist.runSteps(this.runnableFor(entry, values, token, runId), {
2862
2862
  pathPrefix: "steps",
2863
2863
  isAborted: () => token.aborted,
2864
2864
  abortReason: "the run was stopped",
@@ -2962,9 +2962,16 @@ var ActionsService = class {
2962
2962
  }
2963
2963
  };
2964
2964
  }
2965
- runnableFor(entry, values, token) {
2965
+ runnableFor(entry, values, token, runId) {
2966
2966
  if (entry.source === "internal") return require_dist.buildActionSteps(entry.steps ?? [], values, {
2967
- invokeCap: (call) => this.invokeCap(call),
2967
+ invokeCap: (call) => this.invokeCap({
2968
+ ...call,
2969
+ origin: {
2970
+ kind: "action",
2971
+ actionId: entry.id,
2972
+ runId
2973
+ }
2974
+ }),
2968
2975
  sleep: (ms) => token.sleep(ms),
2969
2976
  resolveTarget: (target, actionId, vars, origin) => this.targets.resolve(target, actionId, vars, origin),
2970
2977
  owner: entry.id,
@@ -3401,10 +3408,11 @@ function invokeCapOver(api) {
3401
3408
  const procedure = client !== null && client !== void 0 ? Reflect.get(Object(client), call.method) : void 0;
3402
3409
  const mutate = procedure !== null && procedure !== void 0 ? Reflect.get(Object(procedure), "mutate") : void 0;
3403
3410
  if (typeof mutate !== "function") throw new Error(`no such device method: ${call.cap}.${call.method}`);
3404
- await Reflect.apply(mutate, procedure, [{
3411
+ const input = {
3405
3412
  ...call.args,
3406
3413
  deviceId: call.deviceId
3407
- }]);
3414
+ };
3415
+ await Reflect.apply(mutate, procedure, call.origin === void 0 ? [input] : [input, require_dist.commandOrigin(call.origin)]);
3408
3416
  };
3409
3417
  }
3410
3418
  /**
@@ -4903,7 +4911,13 @@ var SchedulerEngine = class {
4903
4911
  throw new OverriddenError(refusal);
4904
4912
  }
4905
4913
  try {
4906
- await this.deps.host.invokeCap(call);
4914
+ await this.deps.host.invokeCap({
4915
+ ...call,
4916
+ origin: {
4917
+ kind: "scheduler",
4918
+ schedulerId: scheduler.id
4919
+ }
4920
+ });
4907
4921
  } catch (err) {
4908
4922
  failedCalls += 1;
4909
4923
  throw err;
@@ -5435,6 +5449,79 @@ var RemoteComponentsService = class {
5435
5449
  }
5436
5450
  };
5437
5451
  //#endregion
5452
+ //#region src/builtins/core-blocks/hero-layout-service.ts
5453
+ /**
5454
+ * The `hero-layout` provider of core-blocks (D1023): serves the FIXED layouts
5455
+ * and the built hero model. Read-only — it stores nothing and edits nothing.
5456
+ *
5457
+ * `getHeroModel` reads the device, its bindings (per device, D12) and one slice
5458
+ * per bound cap through an injected reader, then hands everything to the pure
5459
+ * `buildHeroModel`. A slice that cannot be read is simply absent: the model
5460
+ * says "not answered", never "off" (D315/D393). The remote's saved command
5461
+ * count comes from the remote cap and is `null` when it cannot be asked.
5462
+ */
5463
+ var REMOTE_CAP = "remote";
5464
+ var HeroLayoutService = class {
5465
+ deps;
5466
+ constructor(deps) {
5467
+ this.deps = deps;
5468
+ }
5469
+ getLayout = async ({ deviceType }) => ({
5470
+ type: deviceType,
5471
+ rows: [...require_dist.resolveHeroLayout(deviceType).rows]
5472
+ });
5473
+ getHeroModel = async ({ deviceId, canActuate }) => {
5474
+ const { reader, logger } = this.deps;
5475
+ const device = await reader.device(deviceId);
5476
+ if (device === null) {
5477
+ logger.warn("hero model: device not found", { tags: { deviceId } });
5478
+ return null;
5479
+ }
5480
+ const bound = await reader.caps(deviceId);
5481
+ const slices = {};
5482
+ await Promise.all(bound.filter((cap) => cap !== REMOTE_CAP).map(async (cap) => {
5483
+ try {
5484
+ slices[cap] = await reader.slice(deviceId, cap);
5485
+ } catch (error) {
5486
+ logger.warn("hero model: a cap slice could not be read; drawn as not answered", {
5487
+ tags: { deviceId },
5488
+ meta: {
5489
+ cap,
5490
+ error: error instanceof Error ? error.message : String(error)
5491
+ }
5492
+ });
5493
+ }
5494
+ }));
5495
+ const remoteCommands = await this.remoteCommands(deviceId);
5496
+ return require_dist.buildHeroModel({
5497
+ device: {
5498
+ id: deviceId,
5499
+ type: device.type,
5500
+ role: device.role,
5501
+ name: device.name,
5502
+ online: device.online
5503
+ },
5504
+ caps: [...bound.filter((cap) => cap !== REMOTE_CAP), REMOTE_CAP],
5505
+ features: device.features,
5506
+ slices,
5507
+ now: this.deps.now(),
5508
+ remoteCommands,
5509
+ access: { canActuate: canActuate ?? true }
5510
+ });
5511
+ };
5512
+ async remoteCommands(deviceId) {
5513
+ try {
5514
+ return await this.deps.reader.remoteCommands(deviceId);
5515
+ } catch (error) {
5516
+ this.deps.logger.warn("hero model: the remote could not be asked; its button shows without a count", {
5517
+ tags: { deviceId },
5518
+ meta: { error: error instanceof Error ? error.message : String(error) }
5519
+ });
5520
+ return null;
5521
+ }
5522
+ }
5523
+ };
5524
+ //#endregion
5438
5525
  //#region src/builtins/core-blocks/lock-door-gate.ts
5439
5526
  var LOCK_CONTROL = "lock-control";
5440
5527
  var DOOR_OPEN = "door-open";
@@ -5553,7 +5640,7 @@ async function seedLockDoors(deps) {
5553
5640
  * an automation, an exporter, a forked addon — never in a UI.
5554
5641
  *
5555
5642
  * - A media-player command (`play`, `pause`, `stop`, `next`, `previous`,
5556
- * `setMute`, `selectSource`) on a device whose remote binds the command's
5643
+ * `setMute`, `selectSource`, `playMedia` of a channel) on a device whose remote binds the command's
5557
5644
  * role runs the binding. An unbound role falls through to the native cap.
5558
5645
  * A binding that FAILS fails the call: the native cap never silently runs in
5559
5646
  * its place. `repeat`, where the caller supplies one, is passed through.
@@ -5590,11 +5677,15 @@ function remoteCallRedirect(deps) {
5590
5677
  const command = async (call, name) => {
5591
5678
  const muted = field(call.args, "muted");
5592
5679
  const source = field(call.args, "source");
5680
+ const mediaType = field(call.args, "mediaType");
5681
+ const mediaId = field(call.args, "mediaId");
5593
5682
  const result = await deps.remote.sendMediaCommand({
5594
5683
  deviceId: call.deviceId,
5595
5684
  command: name,
5596
5685
  ...typeof muted === "boolean" ? { muted } : {},
5597
5686
  ...typeof source === "string" ? { source } : {},
5687
+ ...typeof mediaType === "string" ? { mediaType } : {},
5688
+ ...typeof mediaId === "string" ? { mediaId } : {},
5598
5689
  repeat: repeatOf(call.args)
5599
5690
  });
5600
5691
  switch (result.status) {
@@ -5643,7 +5734,8 @@ function rolesFor(command) {
5643
5734
  case "volumeDown": return ["volume_down"];
5644
5735
  case "channelUp": return ["channel_up"];
5645
5736
  case "channelDown": return ["channel_down"];
5646
- case "selectSource": return [];
5737
+ case "selectSource":
5738
+ case "playMedia": return [];
5647
5739
  }
5648
5740
  }
5649
5741
  function errorText(err) {
@@ -5653,14 +5745,18 @@ var RemoteService = class {
5653
5745
  deps;
5654
5746
  now;
5655
5747
  sleep;
5748
+ lockTimeoutMs;
5656
5749
  /** Remote devices seen so far, and the plug each one waits on: who an input event affects. */
5657
5750
  plugOf = /* @__PURE__ */ new Map();
5658
5751
  sliceRuns = /* @__PURE__ */ new Map();
5659
5752
  slicePending = /* @__PURE__ */ new Set();
5753
+ /** The tail of each device's presses: a sequence is never interleaved with another press. */
5754
+ locks = /* @__PURE__ */ new Map();
5660
5755
  constructor(deps) {
5661
5756
  this.deps = deps;
5662
5757
  this.now = deps.now ?? Date.now;
5663
5758
  this.sleep = deps.sleep ?? realSleep;
5759
+ this.lockTimeoutMs = deps.lockTimeoutMs ?? 6e4;
5664
5760
  }
5665
5761
  getConfig = async ({ deviceId }) => this.deps.store.read(deviceId);
5666
5762
  setConfig = async ({ deviceId, config }) => {
@@ -5692,7 +5788,8 @@ var RemoteService = class {
5692
5788
  return {
5693
5789
  layoutTemplateId: config.layoutTemplateId,
5694
5790
  power: config.power,
5695
- commands
5791
+ commands,
5792
+ sources: config.sources
5696
5793
  };
5697
5794
  };
5698
5795
  sendCommand = async ({ deviceId, role, repeat }) => {
@@ -5702,6 +5799,8 @@ var RemoteService = class {
5702
5799
  sendMediaCommand = async (input) => {
5703
5800
  const { deviceId, repeat } = input;
5704
5801
  const config = await this.deps.store.read(deviceId);
5802
+ if (input.command === "selectSource") return this.selectSource(deviceId, config, input.source);
5803
+ if (input.command === "playMedia") return this.playMedia(deviceId, config, input.mediaType, input.mediaId);
5705
5804
  const role = this.mediaRole(config, input);
5706
5805
  if (role === null) return { status: "not-routed" };
5707
5806
  if (input.command === "setMute" && input.muted !== void 0) return this.setMute(deviceId, config, role, input.muted);
@@ -5767,17 +5866,19 @@ var RemoteService = class {
5767
5866
  */
5768
5867
  getAssumedStatus = async ({ deviceId }) => {
5769
5868
  const kept = await this.readAssumed(deviceId);
5770
- if (kept.power === null && kept.muted === null) return null;
5869
+ if (kept.power === null && kept.muted === null && kept.source === null) return null;
5771
5870
  const config = await this.deps.store.read(deviceId);
5772
5871
  const assumedFields = [];
5773
5872
  if (kept.power !== null) assumedFields.push("state");
5774
5873
  if (kept.muted !== null) assumedFields.push("isMuted");
5874
+ if (kept.source !== null) assumedFields.push("source");
5775
5875
  return this.buildStatus({
5776
5876
  state: kept.power?.state ?? "standby",
5777
5877
  assumedFields,
5778
5878
  muted: kept.muted?.value ?? null,
5779
- changedAt: Math.max(kept.power?.at ?? 0, kept.muted?.at ?? 0),
5780
- sources: config.customButtons.map((b) => b.name)
5879
+ source: kept.source?.name ?? "",
5880
+ changedAt: Math.max(kept.power?.at ?? 0, kept.muted?.at ?? 0, kept.source?.at ?? 0),
5881
+ sources: config.sources
5781
5882
  });
5782
5883
  };
5783
5884
  /**
@@ -5800,13 +5901,16 @@ var RemoteService = class {
5800
5901
  const changedAt = truth.at;
5801
5902
  const mute = state === "off" ? null : kept.muted ?? null;
5802
5903
  if (mute !== null) assumedFields.push("isMuted");
5904
+ const source = state === "off" ? null : kept.source ?? null;
5905
+ if (source !== null) assumedFields.push("source");
5803
5906
  const config = await this.deps.store.read(deviceId);
5804
5907
  return this.buildStatus({
5805
5908
  state,
5806
5909
  assumedFields,
5807
5910
  muted: mute?.value ?? null,
5808
- changedAt: Math.max(changedAt, mute?.at ?? 0),
5809
- sources: config.customButtons.map((b) => b.name)
5911
+ source: source?.name ?? "",
5912
+ changedAt: Math.max(changedAt, mute?.at ?? 0, source?.at ?? 0),
5913
+ sources: config.sources
5810
5914
  });
5811
5915
  }
5812
5916
  buildStatus(input) {
@@ -5816,8 +5920,16 @@ var RemoteService = class {
5816
5920
  assumedFields: [...input.assumedFields],
5817
5921
  volumeLevel: null,
5818
5922
  isMuted: input.muted,
5819
- source: "",
5820
- availableSources: [...input.sources],
5923
+ source: input.source,
5924
+ availableSources: input.sources.map((source) => source.name),
5925
+ declaredSources: input.sources.map((source) => source.kind === "digits" ? {
5926
+ name: source.name,
5927
+ kind: source.kind,
5928
+ number: source.number
5929
+ } : {
5930
+ name: source.name,
5931
+ kind: source.kind
5932
+ }),
5821
5933
  currentMedia: null,
5822
5934
  position: null,
5823
5935
  duration: null,
@@ -5828,13 +5940,6 @@ var RemoteService = class {
5828
5940
  };
5829
5941
  }
5830
5942
  mediaRole(config, input) {
5831
- if (input.command === "selectSource") {
5832
- const wanted = input.source;
5833
- const button = config.customButtons.find((b) => b.name === wanted || b.key === wanted);
5834
- if (button === void 0) return null;
5835
- const role = require_dist.customRole(button.key);
5836
- return config.bindings[role] === void 0 ? null : role;
5837
- }
5838
5943
  for (const role of rolesFor(input.command)) if (this.isBound(config, role)) return role;
5839
5944
  return null;
5840
5945
  }
@@ -5869,9 +5974,10 @@ var RemoteService = class {
5869
5974
  const plug = await this.deps.plugOn(deviceId);
5870
5975
  const kept = await this.readAssumed(deviceId);
5871
5976
  if (plug === false) {
5872
- if (forget && kept.power !== null) await this.deps.assumptions.write(deviceId, {
5977
+ if (forget && (kept.power !== null || kept.source !== null)) await this.deps.assumptions.write(deviceId, {
5873
5978
  ...kept,
5874
- power: null
5979
+ power: null,
5980
+ source: null
5875
5981
  });
5876
5982
  return {
5877
5983
  state: "off",
@@ -5931,7 +6037,183 @@ var RemoteService = class {
5931
6037
  }
5932
6038
  return result;
5933
6039
  }
5934
- async run(deviceId, config, role, repeat) {
6040
+ /**
6041
+ * Runs `fn` after every earlier press of the device has finished. A press that
6042
+ * does not finish within `lockTimeoutMs` is given up: the caller is told
6043
+ * (`press-timeout`) and the lock is released, so one hung press never wedges
6044
+ * the presses behind it.
6045
+ */
6046
+ async withLock(deviceId, fn) {
6047
+ const result = (this.locks.get(deviceId) ?? Promise.resolve()).then(() => this.boundedPress(deviceId, fn));
6048
+ const tail = result.then(() => void 0, () => void 0);
6049
+ this.locks.set(deviceId, tail);
6050
+ try {
6051
+ return await result;
6052
+ } finally {
6053
+ if (this.locks.get(deviceId) === tail) this.locks.delete(deviceId);
6054
+ }
6055
+ }
6056
+ async boundedPress(deviceId, fn) {
6057
+ const giveUp = new AbortController();
6058
+ let timer;
6059
+ const expired = new Promise((resolve) => {
6060
+ timer = setTimeout(() => resolve("timeout"), this.lockTimeoutMs);
6061
+ });
6062
+ const started = fn(giveUp.signal);
6063
+ try {
6064
+ const outcome = await Promise.race([started, expired]);
6065
+ if (outcome !== "timeout") return outcome;
6066
+ giveUp.abort();
6067
+ started.catch(() => void 0);
6068
+ this.deps.logger.warn("remote: a press never finished, it was given up", {
6069
+ tags: { deviceId },
6070
+ meta: { timeoutMs: this.lockTimeoutMs }
6071
+ });
6072
+ return {
6073
+ status: "refused",
6074
+ reason: "press-timeout",
6075
+ detail: `the press did not finish within ${this.lockTimeoutMs} ms`
6076
+ };
6077
+ } finally {
6078
+ clearTimeout(timer);
6079
+ }
6080
+ }
6081
+ run(deviceId, config, role, repeat) {
6082
+ return this.withLock(deviceId, () => this.runRole(deviceId, config, role, repeat));
6083
+ }
6084
+ /**
6085
+ * `selectSource(name)`: the declared source a name (or its channel number)
6086
+ * points at. A remote that declares none leaves the call to the native cap.
6087
+ */
6088
+ async selectSource(deviceId, config, wanted) {
6089
+ if (config.sources.length === 0) return { status: "not-routed" };
6090
+ const source = wanted === void 0 ? null : require_dist.resolveRemoteSource(config.sources, wanted);
6091
+ if (source === null) {
6092
+ this.deps.logger.warn("remote: no declared source answers to that name, nothing was sent", {
6093
+ tags: { deviceId },
6094
+ meta: { wanted: wanted ?? null }
6095
+ });
6096
+ return {
6097
+ status: "refused",
6098
+ reason: "unknown-source",
6099
+ detail: `no source "${wanted ?? ""}" is declared`
6100
+ };
6101
+ }
6102
+ return this.runSource(deviceId, config, source);
6103
+ }
6104
+ /** `playMedia` of a channel: the `digits` source that declares the number, else a refusal. */
6105
+ async playMedia(deviceId, config, mediaType, mediaId) {
6106
+ if (mediaType !== "channel" || config.sources.length === 0) return { status: "not-routed" };
6107
+ const source = mediaId === void 0 ? null : require_dist.findChannelSource(config.sources, mediaId);
6108
+ if (source === null) {
6109
+ this.deps.logger.warn("remote: no source declares that channel, nothing was sent", {
6110
+ tags: { deviceId },
6111
+ meta: { channel: mediaId ?? null }
6112
+ });
6113
+ return {
6114
+ status: "refused",
6115
+ reason: "undeclared-channel",
6116
+ detail: `channel ${mediaId ?? ""} is not declared`
6117
+ };
6118
+ }
6119
+ return this.runSource(deviceId, config, source);
6120
+ }
6121
+ /**
6122
+ * Presses a source's steps in order, one lock for the whole sequence,
6123
+ * `stepDelayMs` apart. Every step is checked bound BEFORE the first press, so
6124
+ * a half-bound source sends nothing. A step that fails stops the sequence.
6125
+ */
6126
+ async runSource(deviceId, config, source) {
6127
+ const steps = require_dist.remoteSourceSteps(source);
6128
+ const missing = steps.findIndex((role) => !this.isBound(config, role));
6129
+ if (missing >= 0) {
6130
+ const role = steps[missing] ?? "";
6131
+ this.deps.logger.warn("remote: a step of the source is not bound, nothing was sent", {
6132
+ tags: { deviceId },
6133
+ meta: {
6134
+ source: source.name,
6135
+ step: missing + 1,
6136
+ role
6137
+ }
6138
+ });
6139
+ return {
6140
+ status: "refused",
6141
+ reason: "unbound-step",
6142
+ detail: `step ${missing + 1}/${steps.length} (${role}) is not bound`,
6143
+ step: {
6144
+ index: missing + 1,
6145
+ role
6146
+ }
6147
+ };
6148
+ }
6149
+ return this.withLock(deviceId, async (abandoned) => {
6150
+ for (const [at, role] of steps.entries()) {
6151
+ if (at > 0) await this.sleep(config.stepDelayMs);
6152
+ if (abandoned.aborted) {
6153
+ this.deps.logger.warn("remote: the sequence was abandoned, no further step was sent", {
6154
+ tags: { deviceId },
6155
+ meta: {
6156
+ source: source.name,
6157
+ step: at + 1,
6158
+ role
6159
+ }
6160
+ });
6161
+ if (at > 0) await this.forgetSource(deviceId);
6162
+ return {
6163
+ status: "refused",
6164
+ reason: "press-timeout",
6165
+ detail: `abandoned before step ${at + 1}/${steps.length} (${role})`,
6166
+ step: {
6167
+ index: at + 1,
6168
+ role
6169
+ }
6170
+ };
6171
+ }
6172
+ const result = await this.runRole(deviceId, config, role, 1);
6173
+ if (result.status === "refused") {
6174
+ if (at > 0) await this.forgetSource(deviceId);
6175
+ this.deps.logger.warn("remote: a step of the source failed, the sequence stopped", {
6176
+ tags: { deviceId },
6177
+ meta: {
6178
+ source: source.name,
6179
+ step: at + 1,
6180
+ role,
6181
+ reason: result.reason
6182
+ }
6183
+ });
6184
+ return {
6185
+ ...result,
6186
+ detail: `step ${at + 1}/${steps.length} (${role}): ${result.detail ?? result.reason}`,
6187
+ step: {
6188
+ index: at + 1,
6189
+ role
6190
+ }
6191
+ };
6192
+ }
6193
+ }
6194
+ const kept = await this.readAssumed(deviceId);
6195
+ await this.deps.assumptions.write(deviceId, {
6196
+ ...kept,
6197
+ source: {
6198
+ name: source.name,
6199
+ at: this.now()
6200
+ }
6201
+ });
6202
+ await this.refreshSlice(deviceId);
6203
+ return {
6204
+ status: "sent",
6205
+ sends: steps.length
6206
+ };
6207
+ });
6208
+ }
6209
+ async forgetSource(deviceId) {
6210
+ const kept = await this.readAssumed(deviceId);
6211
+ if (kept.source !== null) await this.deps.assumptions.write(deviceId, {
6212
+ ...kept,
6213
+ source: null
6214
+ });
6215
+ }
6216
+ async runRole(deviceId, config, role, repeat) {
5935
6217
  const wantsState = role === "power_on" ? "on" : role === "power_off" ? "off" : null;
5936
6218
  const viaToggle = wantsState !== null && config.bindings[role] === void 0;
5937
6219
  const bound = viaToggle ? config.bindings["power"] : config.bindings[role];
@@ -5999,19 +6281,29 @@ var RemoteService = class {
5999
6281
  power: {
6000
6282
  state: wantsState,
6001
6283
  at: this.now()
6002
- }
6284
+ },
6285
+ source: wantsState === "off" ? null : kept.source
6003
6286
  });
6004
6287
  return;
6005
6288
  }
6006
6289
  if (role === "power") {
6007
6290
  const before = await this.currentState(deviceId);
6008
6291
  if (before === null) return;
6292
+ const next = before === "on" ? "off" : "on";
6009
6293
  await this.deps.assumptions.write(deviceId, {
6010
6294
  ...kept,
6011
6295
  power: {
6012
- state: before === "on" ? "off" : "on",
6296
+ state: next,
6013
6297
  at: this.now()
6014
- }
6298
+ },
6299
+ source: next === "off" ? null : kept.source
6300
+ });
6301
+ return;
6302
+ }
6303
+ if (role === "channel_up" || role === "channel_down") {
6304
+ if (kept.source !== null) await this.deps.assumptions.write(deviceId, {
6305
+ ...kept,
6306
+ source: null
6015
6307
  });
6016
6308
  return;
6017
6309
  }
@@ -7878,10 +8170,44 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
7878
8170
  capability: require_dist.remoteLayoutComponentsCapability,
7879
8171
  provider: new RemoteComponentsService()
7880
8172
  },
8173
+ {
8174
+ capability: require_dist.heroLayoutCapability,
8175
+ provider: this.buildHeroLayout()
8176
+ },
7881
8177
  ...this.remoteRegistrations(),
7882
8178
  ...this.fanPresetRegistrations()
7883
8179
  ];
7884
8180
  }
8181
+ /** Read-only: the fixed layouts and the model built from the device's bindings and slices. */
8182
+ buildHeroLayout() {
8183
+ const requireApi = () => {
8184
+ const api = this.ctx.api;
8185
+ if (!api) throw new Error("core-blocks: no ctx.api on this node — hero-layout cannot reach devices");
8186
+ return api;
8187
+ };
8188
+ return new HeroLayoutService({
8189
+ logger: this.ctx.logger.child("hero-layout"),
8190
+ now: () => Date.now(),
8191
+ reader: {
8192
+ device: async (deviceId) => {
8193
+ const found = await requireApi().deviceManager.getDevice.query({ deviceId });
8194
+ return found === null ? null : {
8195
+ type: found.type,
8196
+ role: found.role ?? null,
8197
+ name: found.name,
8198
+ online: found.online,
8199
+ features: found.features
8200
+ };
8201
+ },
8202
+ caps: async (deviceId) => (await requireApi().deviceManager.getBindings.query({ deviceId })).entries.map((e) => e.capName),
8203
+ slice: (deviceId, capName) => requireApi().deviceState.getCapSlice.query({
8204
+ deviceId,
8205
+ capName
8206
+ }),
8207
+ remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length
8208
+ }
8209
+ });
8210
+ }
7885
8211
  buildPowerSource() {
7886
8212
  const service = new PowerSourceService({
7887
8213
  blocks: () => this.store?.list() ?? [],