@camstack/server 1.2.802 → 1.2.803

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 (90) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/trpc/generated-cap-routers.js +18 -0
  3. package/package.json +9 -10
  4. package/system/dist/{agent-https-CfPGbJ21.mjs → agent-https-BRfJO9ZR.mjs} +1 -1
  5. package/system/dist/{agent-https-CzMpclQr.js → agent-https-DtYiXPGm.js} +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  7. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  9. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  11. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  12. package/system/dist/builtins/autotrack/index.js +1 -1
  13. package/system/dist/builtins/autotrack/index.mjs +1 -1
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  15. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  16. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  17. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  18. package/system/dist/builtins/camera-grid/index.js +1 -1
  19. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  20. package/system/dist/builtins/composer/composer.addon.js +6 -5
  21. package/system/dist/builtins/composer/composer.addon.mjs +6 -5
  22. package/system/dist/builtins/console-logging/index.js +1 -1
  23. package/system/dist/builtins/console-logging/index.mjs +1 -1
  24. package/system/dist/builtins/core-blocks/core-blocks.addon.js +65 -6
  25. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +65 -6
  26. package/system/dist/builtins/core-blocks/timed-run/timed-run-service.d.ts +17 -0
  27. package/system/dist/builtins/core-blocks/timed-run/timed-run-wiring.d.ts +6 -0
  28. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  29. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  30. package/system/dist/builtins/device-manager/device-config-contribution.d.ts +1 -0
  31. package/system/dist/builtins/device-manager/device-manager.addon.js +47 -2
  32. package/system/dist/builtins/device-manager/device-manager.addon.mjs +47 -2
  33. package/system/dist/builtins/device-manager/timed-run-config-schema.d.ts +18 -0
  34. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  35. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  36. package/system/dist/builtins/keychain/index.js +4 -4
  37. package/system/dist/builtins/keychain/index.mjs +4 -4
  38. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  39. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  40. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  41. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  42. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  43. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  44. package/system/dist/builtins/loki-logging/index.js +1 -1
  45. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  46. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  47. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  48. package/system/dist/builtins/platform-probe/index.js +1 -1
  49. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  50. package/system/dist/builtins/record-entries/index.js +1 -1
  51. package/system/dist/builtins/record-entries/index.mjs +1 -1
  52. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  53. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  54. package/system/dist/builtins/snapshot/index.js +1 -1
  55. package/system/dist/builtins/snapshot/index.mjs +1 -1
  56. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  57. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  58. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  59. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  60. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  61. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  62. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  63. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  64. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  65. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  66. package/system/dist/builtins/winston-logging/index.js +1 -1
  67. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  68. package/system/dist/{capture-engine-CJxojquW.mjs → capture-engine-BFgeAHa9.mjs} +1 -1
  69. package/system/dist/{capture-engine-Us8Ocffb.js → capture-engine-BQ08XTnZ.js} +1 -1
  70. package/system/dist/{composition-sources-D2z7D7bY.js → composition-sources-DNHNUvTr.js} +1 -1
  71. package/system/dist/{composition-sources-DcsjjTIu.mjs → composition-sources-DkOfzgpS.mjs} +1 -1
  72. package/system/dist/{constants-BOMAH5bO.js → constants-D5CG3Gvc.js} +1 -1
  73. package/system/dist/{constants-DVqHyOzQ.mjs → constants-GCrIKhD_.mjs} +1 -1
  74. package/system/dist/{device-ca-NlhUUsex.js → device-ca-DgZeLVC1.js} +1 -1
  75. package/system/dist/{device-ca-zAWpen18.mjs → device-ca-Dk2sx_18.mjs} +1 -1
  76. package/system/dist/{dist-BccX5DOW.js → dist-D5nGm8Sd.js} +571 -372
  77. package/system/dist/{dist-DYrP8WdD.mjs → dist-ze-qVU7x.mjs} +554 -373
  78. package/system/dist/file-host-worker.js +1 -1
  79. package/system/dist/file-host-worker.mjs +1 -1
  80. package/system/dist/{hub-mdns-ciao-DpRlDWJY.js → hub-mdns-ciao-D4g9qsNL.js} +2 -2
  81. package/system/dist/{hub-mdns-ciao-BleXDm2r.mjs → hub-mdns-ciao-DD2QP3w5.mjs} +2 -2
  82. package/system/dist/index.js +16 -10
  83. package/system/dist/index.mjs +16 -10
  84. package/system/dist/{legacy-integration-rows-door-BUyPyv8f.mjs → legacy-integration-rows-door-BvEFQrAa.mjs} +1 -1
  85. package/system/dist/{legacy-integration-rows-door-D2ZrX431.js → legacy-integration-rows-door-MRr8Ncb_.js} +1 -1
  86. package/system/dist/{restore-archive-B1PE_1S2.mjs → restore-archive-DBc5sNQS.mjs} +82 -82
  87. package/system/dist/{restore-archive-DMUCmY3H.js → restore-archive-aG7OlQNo.js} +1 -1
  88. package/system/dist/{wal-maintenance-CmNAtKgj.js → wal-maintenance-C-ddHy-q.js} +0 -0
  89. package/system/dist/{wal-maintenance-Ce71BVDk.mjs → wal-maintenance-vQHsOLGg.mjs} +0 -0
  90. package/system/package.json +1 -1
@@ -1188,7 +1188,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
1188
1188
  return DeviceRole;
1189
1189
  }({});
1190
1190
  //#endregion
1191
- //#region ../types/dist/sleep-B_dgCAyx.mjs
1191
+ //#region ../types/dist/sleep-D4UJY10i.mjs
1192
1192
  /**
1193
1193
  * The audio chunk plane's byte format, and the ONE expansion from a coded
1194
1194
  * window to float samples (D455).
@@ -8779,13 +8779,25 @@ Object.freeze({
8779
8779
  "path": "temperature",
8780
8780
  "valueType": "number"
8781
8781
  }],
8782
- "timed-run": [{
8783
- "path": "activeUntil",
8784
- "valueType": "number"
8785
- }, {
8786
- "path": "requestedBy",
8787
- "valueType": "string"
8788
- }],
8782
+ "timed-run": [
8783
+ {
8784
+ "path": "activeUntil",
8785
+ "valueType": "number"
8786
+ },
8787
+ {
8788
+ "path": "requestedBy",
8789
+ "valueType": "string"
8790
+ },
8791
+ {
8792
+ "path": "quickRun.duration",
8793
+ "valueType": "number"
8794
+ },
8795
+ {
8796
+ "path": "quickRun.unit",
8797
+ "valueType": "enum",
8798
+ "enumValues": ["s", "min"]
8799
+ }
8800
+ ],
8789
8801
  "update": [
8790
8802
  {
8791
8803
  "path": "currentVersion",
@@ -54952,8 +54964,9 @@ function planComposition(composition, lookupCap, target) {
54952
54964
  }, lookupCap, servedCommands));
54953
54965
  }
54954
54966
  const result = planFeature(feature, index, featureTarget, lookupCap, servedCommands);
54955
- return compositionFeatureEnabled(feature) ? result : {
54956
- problems: result.problems,
54967
+ if (compositionFeatureEnabled(feature)) return result;
54968
+ return {
54969
+ problems: Object.keys(feature.fields).length === 0 ? result.problems.filter((p) => p.code !== "missing-field") : result.problems,
54957
54970
  fields: [],
54958
54971
  features: [],
54959
54972
  events: []
@@ -85734,93 +85747,27 @@ var RunningFlipEventDataSchema = zod.z.object({
85734
85747
  phase: zod.z.string().nullable()
85735
85748
  });
85736
85749
  var RUNNING_DEVICE_TYPES = Object.values(DeviceType);
85737
- /** Generic Customize target for the running boolean (D936). */
85738
- var runningCustomize = {
85739
- version: 1,
85740
- overridable: [{
85741
- path: "running",
85742
- by: "running"
85743
- }],
85744
- targets: [{
85745
- id: "running",
85746
- cardinality: "scalar",
85747
- vocabulary: {
85748
- cap: "running-state",
85749
- stateField: "running"
85750
- },
85751
- deviceTypes: [
85752
- DeviceType.Washer,
85753
- DeviceType.Dryer,
85754
- DeviceType.Dishwasher,
85755
- DeviceType.Vacuum,
85756
- DeviceType.LawnMower,
85757
- DeviceType.MediaPlayer,
85758
- DeviceType.WaterHeater,
85759
- DeviceType.Humidifier,
85760
- DeviceType.Fan,
85761
- DeviceType.Climate,
85762
- DeviceType.Thermostat,
85763
- DeviceType.PetFeeder,
85764
- DeviceType.Heater
85765
- ],
85766
- apply: "add",
85767
- path: "running",
85768
- sources: [
85769
- {
85770
- kind: "switch",
85771
- transforms: [{ kind: "identity" }]
85772
- },
85773
- {
85774
- kind: "binary",
85775
- transforms: [{ kind: "identity" }, { kind: "invert" }]
85776
- },
85777
- {
85778
- kind: "numeric",
85779
- requiredUnit: "W",
85780
- transforms: [{
85781
- kind: "threshold",
85782
- comparisons: ["gte", "lte"],
85783
- comparison: "gte",
85784
- defaultThreshold: 5,
85785
- defaultStartDwellMs: RUNNING_POWER_START_DELAY_MS,
85786
- defaultStopDwellMs: RUNNING_POWER_STOP_DELAY_MS,
85787
- thresholdUnit: "W"
85788
- }]
85789
- }
85790
- ],
85791
- companions: [
85792
- {
85793
- kind: "constant",
85794
- path: "source",
85795
- value: "assigned",
85796
- when: "always"
85797
- },
85798
- {
85799
- kind: "constant",
85800
- path: "phase",
85801
- value: null,
85802
- when: "add"
85803
- },
85804
- {
85805
- kind: "clock",
85806
- path: "lastFetchedAt",
85807
- when: "always"
85808
- },
85809
- {
85810
- kind: "transition-time",
85811
- path: "since",
85812
- sourceChangedAt: "prefer"
85813
- }
85814
- ],
85815
- sourceReport: {
85816
- status: "assignment-status",
85817
- runtimeField: "source",
85818
- nativeValue: "native",
85819
- assignedValue: "assigned"
85820
- },
85821
- advancedExpression: true
85822
- }]
85823
- };
85750
+ /**
85751
+ * Customize offers "running" only where a job makes sense (D933): a cycle,
85752
+ * a clean, a mow, playback, or another appliance that is on and working.
85753
+ * The cap itself stays on every type — a camera can still report running
85754
+ * natively; it just has no card.
85755
+ */
85756
+ var RUNNING_CUSTOMIZE_DEVICE_TYPES = [
85757
+ DeviceType.Washer,
85758
+ DeviceType.Dryer,
85759
+ DeviceType.Dishwasher,
85760
+ DeviceType.Vacuum,
85761
+ DeviceType.LawnMower,
85762
+ DeviceType.MediaPlayer,
85763
+ DeviceType.WaterHeater,
85764
+ DeviceType.Humidifier,
85765
+ DeviceType.Fan,
85766
+ DeviceType.Climate,
85767
+ DeviceType.Thermostat,
85768
+ DeviceType.PetFeeder,
85769
+ DeviceType.Heater
85770
+ ];
85824
85771
  var runningStateCapability = {
85825
85772
  name: "running-state",
85826
85773
  scope: "device",
@@ -85840,7 +85787,78 @@ var runningStateCapability = {
85840
85787
  durability: "restored",
85841
85788
  history: { fields: { running: { kind: "boolean" } } },
85842
85789
  volatileStateFields: ["lastFetchedAt"],
85843
- customize: runningCustomize
85790
+ customize: {
85791
+ version: 1,
85792
+ overridable: [{
85793
+ path: "running",
85794
+ by: "running"
85795
+ }],
85796
+ targets: [{
85797
+ id: "running",
85798
+ cardinality: "scalar",
85799
+ vocabulary: {
85800
+ cap: "running-state",
85801
+ stateField: "running"
85802
+ },
85803
+ deviceTypes: RUNNING_CUSTOMIZE_DEVICE_TYPES,
85804
+ apply: "add",
85805
+ path: "running",
85806
+ sources: [
85807
+ {
85808
+ kind: "switch",
85809
+ transforms: [{ kind: "identity" }]
85810
+ },
85811
+ {
85812
+ kind: "binary",
85813
+ transforms: [{ kind: "identity" }, { kind: "invert" }]
85814
+ },
85815
+ {
85816
+ kind: "numeric",
85817
+ requiredUnit: "W",
85818
+ transforms: [{
85819
+ kind: "threshold",
85820
+ comparisons: ["gte", "lte"],
85821
+ comparison: "gte",
85822
+ defaultThreshold: 5,
85823
+ defaultStartDwellMs: RUNNING_POWER_START_DELAY_MS,
85824
+ defaultStopDwellMs: RUNNING_POWER_STOP_DELAY_MS,
85825
+ thresholdUnit: "W"
85826
+ }]
85827
+ }
85828
+ ],
85829
+ companions: [
85830
+ {
85831
+ kind: "constant",
85832
+ path: "source",
85833
+ value: "assigned",
85834
+ when: "always"
85835
+ },
85836
+ {
85837
+ kind: "constant",
85838
+ path: "phase",
85839
+ value: null,
85840
+ when: "add"
85841
+ },
85842
+ {
85843
+ kind: "clock",
85844
+ path: "lastFetchedAt",
85845
+ when: "always"
85846
+ },
85847
+ {
85848
+ kind: "transition-time",
85849
+ path: "since",
85850
+ sourceChangedAt: "prefer"
85851
+ }
85852
+ ],
85853
+ sourceReport: {
85854
+ status: "assignment-status",
85855
+ runtimeField: "source",
85856
+ nativeValue: "native",
85857
+ assignedValue: "assigned"
85858
+ },
85859
+ advancedExpression: true
85860
+ }]
85861
+ }
85844
85862
  };
85845
85863
  /**
85846
85864
  * scene-monitor — device-scoped reference-region state cap. An operator marks
@@ -89511,12 +89529,14 @@ var TIMED_RUN_LIMITS = {
89511
89529
  [DeviceType.Heater]: {
89512
89530
  actuator: "switch",
89513
89531
  maxSeconds: 10800,
89514
- unit: "min"
89532
+ unit: "min",
89533
+ quickRunDefault: 30
89515
89534
  },
89516
89535
  [DeviceType.PetFountain]: {
89517
89536
  actuator: "pet-fountain",
89518
89537
  maxSeconds: 300,
89519
- unit: "s"
89538
+ unit: "s",
89539
+ quickRunDefault: 60
89520
89540
  }
89521
89541
  };
89522
89542
  var TIMED_RUN_DEVICE_TYPES = [DeviceType.Heater, DeviceType.PetFountain];
@@ -89527,6 +89547,27 @@ function timedRunLimitOf(deviceType) {
89527
89547
  function timedRunSeconds(duration, unit) {
89528
89548
  return unit === "min" ? duration * 60 : duration;
89529
89549
  }
89550
+ /** The longest run of a limit, in the unit the operator thinks of it in. */
89551
+ function timedRunMaxIn(limit) {
89552
+ return limit.unit === "min" ? Math.floor(limit.maxSeconds / 60) : limit.maxSeconds;
89553
+ }
89554
+ /** One duration, as the one-tap run asks for it. */
89555
+ var TimedRunQuickRunSchema = zod.z.object({
89556
+ duration: zod.z.number().positive().finite(),
89557
+ unit: TimedRunUnitSchema
89558
+ });
89559
+ /**
89560
+ * The one-tap run of a device: the duration the operator stored for it, else the
89561
+ * type's default, never above the type's maximum. A stored value that is not a
89562
+ * usable number is the default (a hand-edited row never breaks the button).
89563
+ */
89564
+ function timedRunQuickRun(limit, stored) {
89565
+ const max = timedRunMaxIn(limit);
89566
+ return {
89567
+ duration: Math.min((stored !== null && Number.isFinite(stored) && stored > 0 ? stored : null) ?? limit.quickRunDefault, max),
89568
+ unit: limit.unit
89569
+ };
89570
+ }
89530
89571
  /** Why a request was not carried out. Typed, so a caller can say it in words. */
89531
89572
  var TimedRunRefusalSchema = zod.z.enum([
89532
89573
  "unsupported-device",
@@ -89547,8 +89588,23 @@ var TimedRunStatusSchema = zod.z.object({
89547
89588
  activeUntil: zod.z.number().nullable(),
89548
89589
  /** Who asked for the run (a user id or an addon id); `null` when nothing is armed or it did not say. */
89549
89590
  requestedBy: zod.z.string().nullable(),
89591
+ /**
89592
+ * The one-tap run of THIS device: what a "Run" button on any surface starts. `null` when
89593
+ * the device is gone or its type has no timed run; a status from before this field
89594
+ * existed has none, and a surface falls back to the type's default.
89595
+ */
89596
+ quickRun: TimedRunQuickRunSchema.nullable(),
89550
89597
  lastFetchedAt: zod.z.number()
89551
89598
  });
89599
+ /** What the settings form needs: the unit, the bounds and the type's default. */
89600
+ var TimedRunOptionsSchema = zod.z.object({
89601
+ unit: TimedRunUnitSchema,
89602
+ /** The longest run, in `unit`. */
89603
+ maxDuration: zod.z.number(),
89604
+ defaultDuration: zod.z.number()
89605
+ });
89606
+ /** The one-tap run duration, in the type's unit; `null` returns to the type's default. */
89607
+ var TimedRunSettingsPatchSchema = zod.z.object({ quickRunDuration: zod.z.number().positive().finite().nullable().optional() });
89552
89608
  var timedRunCapability = {
89553
89609
  name: "timed-run",
89554
89610
  scope: "device",
@@ -89556,7 +89612,24 @@ var timedRunCapability = {
89556
89612
  kind: "wrapper",
89557
89613
  defaultActive: true,
89558
89614
  deviceTypes: TIMED_RUN_DEVICE_TYPES,
89615
+ deviceConfig: { ui: {
89616
+ kind: "derived-form",
89617
+ builderId: "timed-run",
89618
+ tab: "general"
89619
+ } },
89559
89620
  methods: {
89621
+ getOptions: method(zod.z.object({ deviceId: zod.z.number().int() }), TimedRunOptionsSchema),
89622
+ /**
89623
+ * The one-tap run of this device. A duration above the type's maximum is
89624
+ * REFUSED (thrown), like `runFor`: the maximum is a safety bound.
89625
+ */
89626
+ setSettings: method(zod.z.object({
89627
+ deviceId: zod.z.number().int(),
89628
+ settings: TimedRunSettingsPatchSchema
89629
+ }), zod.z.void(), {
89630
+ kind: "mutation",
89631
+ auth: "admin"
89632
+ }),
89560
89633
  /**
89561
89634
  * Turn the device on and arm its off. A run already armed is replaced (the
89562
89635
  * new deadline wins). Refuses with a typed reason above the type's maximum.
@@ -94133,255 +94206,6 @@ function evaluateAggregate(input) {
94133
94206
  counts
94134
94207
  };
94135
94208
  }
94136
- /**
94137
- * One composed field, evaluated from what its sources say NOW (D659).
94138
- *
94139
- * Pure. The composer calls it on every source change, and the slice-5 editor
94140
- * will call it for its live preview, so both see the same answer.
94141
- *
94142
- * The rules (spec §2):
94143
- * - a source that is offline or unreadable keeps its last value and is marked
94144
- * STALE; the field is stale and keeps computing (D49);
94145
- * - a source that is GONE makes the field UNAVAILABLE, `fatal`, and never a
94146
- * plausible number (D393);
94147
- * - a source that is unavailable but NOT gone (e.g. a cap unregistered at
94148
- * runtime, R7b) makes the field UNAVAILABLE, non-fatal, `value: null`: it
94149
- * may come back on its own, no block failure is raised for it;
94150
- * - an expression that fails on a value makes the field unavailable for that
94151
- * value, and NOT fatal: the next value may compute.
94152
- *
94153
- * `confirmed` (D663, D49): whether a NON-fatal unavailability is an ANSWER — a
94154
- * cap the provider unregistered and a re-read agreed, a field the source
94155
- * reported without, an expression that failed on a value — or only the
94156
- * absence of one (a failed read, a first or empty read, a source not tracked
94157
- * yet). Only a confirmed unavailability may hand a `release`-mode field back
94158
- * to the native provider; an unconfirmed one holds it on its last value.
94159
- * Absent means NOT confirmed. Fatal is always confirmed.
94160
- *
94161
- * When an expression has more than one unavailable binding, a FATAL one always
94162
- * wins the outcome, regardless of position: every binding is scanned before
94163
- * the field is judged, so an earlier non-fatal binding (e.g. a cap that is
94164
- * momentarily unregistered) can never hide a later fatal one (a deleted
94165
- * source) behind an early return.
94166
- */
94167
- function describeRead(read) {
94168
- return `${compositionSourceKey(read.source)} ${read.cap}.${read.fieldPath}`;
94169
- }
94170
- function isConfirmed(reading) {
94171
- return reading.fatal || reading.confirmed === true;
94172
- }
94173
- function fromReading(reading, read) {
94174
- if (reading.state === "unavailable") return {
94175
- state: "unavailable",
94176
- value: null,
94177
- reason: `${describeRead(read)}: ${reading.reason}`,
94178
- fatal: reading.fatal,
94179
- confirmed: isConfirmed(reading)
94180
- };
94181
- return {
94182
- state: reading.state,
94183
- value: reading.value,
94184
- reason: reading.state === "stale" ? `${describeRead(read)}: ${reading.reason}` : null,
94185
- deadline: null
94186
- };
94187
- }
94188
- function expressionOutcome(source, read, now, stateful) {
94189
- const values = {};
94190
- const staleReasons = [];
94191
- let fatalUnavailable = null;
94192
- let nonFatalUnavailable = null;
94193
- for (const [name, binding] of Object.entries(source.bindings)) {
94194
- if (binding.kind === "literal") {
94195
- values[name] = binding.value;
94196
- continue;
94197
- }
94198
- const reading = read(binding);
94199
- if (reading.state === "unavailable") {
94200
- const outcome = {
94201
- state: "unavailable",
94202
- value: null,
94203
- reason: `binding \`${name}\` (${describeRead(binding)}): ${reading.reason}`,
94204
- fatal: reading.fatal,
94205
- confirmed: isConfirmed(reading)
94206
- };
94207
- if (reading.fatal) {
94208
- fatalUnavailable = outcome;
94209
- break;
94210
- }
94211
- if (nonFatalUnavailable === null || outcome.confirmed && !nonFatalUnavailable.confirmed) nonFatalUnavailable = outcome;
94212
- continue;
94213
- }
94214
- values[name] = reading.value;
94215
- if (reading.state === "fresh" && reading.transition !== void 0 && stateful !== void 0) stateful.expressionMemory.dwellTransition = reading.transition;
94216
- if (reading.state === "stale") staleReasons.push(`\`${name}\`: ${reading.reason}`);
94217
- }
94218
- const unavailable = fatalUnavailable ?? nonFatalUnavailable;
94219
- if (unavailable !== null) {
94220
- if (stateful !== void 0 && stateful.currentOutput !== void 0 && expressionContainsBuiltinCall(source.expr, "count")) return {
94221
- state: "stale",
94222
- value: evaluateCount(null, {
94223
- kind: "count",
94224
- highWater: null,
94225
- primed: false
94226
- }, stateful.currentOutput),
94227
- reason: `${unavailable.reason}; holding the last accumulator value`,
94228
- deadline: null
94229
- };
94230
- return unavailable;
94231
- }
94232
- const deadlines = [];
94233
- const hooks = {
94234
- noteDeadline: (at) => deadlines.push(at),
94235
- ...stateful?.timerDriven === true ? { timerDriven: true } : {},
94236
- convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
94237
- };
94238
- const result = evaluateExpressionSource(source.expr, values, now, {
94239
- hooks,
94240
- ...stateful === void 0 ? {} : { invokeStateful: (invocation) => evaluateStatefulExpressionCall(stateful.callPathPrefix === void 0 ? invocation : {
94241
- ...invocation,
94242
- path: `${stateful.callPathPrefix}@${invocation.path}`
94243
- }, stateful.expressionMemory, {
94244
- currentOutput: stateful.currentOutput,
94245
- startedAtMs: stateful.startedAtMs,
94246
- nowMs: now
94247
- }, hooks) }
94248
- });
94249
- const transition = stateful?.expressionMemory.dwellTransition ?? null;
94250
- if (stateful !== void 0) stateful.expressionMemory.dwellTransition = null;
94251
- if (!result.ok) return {
94252
- state: "unavailable",
94253
- value: null,
94254
- reason: `the expression failed: ${result.error}`,
94255
- fatal: false,
94256
- confirmed: true,
94257
- expressionFailed: true
94258
- };
94259
- return {
94260
- state: staleReasons.length > 0 ? "stale" : "fresh",
94261
- value: result.value,
94262
- reason: staleReasons.length > 0 ? staleReasons.join("; ") : null,
94263
- deadline: deadlines.length > 0 ? Math.min(...deadlines) : null,
94264
- ...transition === null ? {} : { transition }
94265
- };
94266
- }
94267
- function aggregateRead(reading) {
94268
- if (reading.state === "unavailable") return {
94269
- state: "unavailable",
94270
- fatal: reading.fatal,
94271
- reason: reading.reason
94272
- };
94273
- return {
94274
- state: reading.state,
94275
- value: reading.value,
94276
- ...reading.state === "stale" ? { reason: reading.reason } : {}
94277
- };
94278
- }
94279
- function aggregateField(source, read) {
94280
- const outcome = evaluateAggregate({
94281
- reducer: source.reducer,
94282
- ...source.activeWhen === void 0 ? {} : { activeWhen: source.activeWhen },
94283
- members: source.reads.map((item) => aggregateRead(read(item))),
94284
- publish: source.publish,
94285
- empty: source.empty
94286
- });
94287
- if (outcome.kind === "value") return {
94288
- state: "fresh",
94289
- value: outcome.value,
94290
- reason: null,
94291
- deadline: null
94292
- };
94293
- return {
94294
- state: "unavailable",
94295
- value: null,
94296
- reason: outcome.reason,
94297
- fatal: outcome.fatal,
94298
- confirmed: true
94299
- };
94300
- }
94301
- function evaluateCompositionField(input) {
94302
- const { source } = input;
94303
- switch (source.kind) {
94304
- case "from": return fromReading(input.read(source), source);
94305
- case "expression": return expressionOutcome(source, input.read, input.now, input.stateful);
94306
- case "aggregate": return aggregateField(source, input.read);
94307
- case "series": return {
94308
- state: "unavailable",
94309
- value: null,
94310
- reason: "a series field is written from device history",
94311
- fatal: false,
94312
- confirmed: false
94313
- };
94314
- case "code": return {
94315
- state: "unavailable",
94316
- value: null,
94317
- reason: "code fields are not runnable in the composer — they arrive in slice 4",
94318
- fatal: true,
94319
- confirmed: true
94320
- };
94321
- }
94322
- }
94323
- function lockDoorLinkOfComposition(composition) {
94324
- if (composition === null || composition.target.kind !== "existing") return null;
94325
- const feature = composition.features.find((f) => f.cap === "lock-control");
94326
- if (feature === void 0 || feature.kind !== "fields") return null;
94327
- const state = feature.fields["state"];
94328
- if (state === void 0 || state.kind !== "expression") return null;
94329
- const x = state.bindings["x"];
94330
- if (x === void 0 || x.kind !== "from") return null;
94331
- return {
94332
- lock: composition.target.device,
94333
- sensor: x.source
94334
- };
94335
- }
94336
- /**
94337
- * Which smart switch powers a device (the `power-source` Customize extension):
94338
- * the source its stored `power-source.switchOn` field reads, and the off time of
94339
- * a forced restart stored beside it. Read from the STORED composition, never kept
94340
- * as a second copy (D676). Shared by the hub (which acts on the switch) and the
94341
- * admin UI (which shows it).
94342
- */
94343
- /**
94344
- * The stored off time, or the default when none is stored. A stored number out
94345
- * of range is CLAMPED to the bounds (a hand-written value never refuses the
94346
- * link, it just cannot cut power for an absurd time); a non-integer is rounded.
94347
- */
94348
- function normalizeOffSeconds(value) {
94349
- if (typeof value !== "number" || !Number.isFinite(value)) return 10;
94350
- return Math.min(120, Math.max(3, Math.round(value)));
94351
- }
94352
- /** The constant a stored `offSeconds` field carries, or undefined when it is not a literal number. */
94353
- function storedOffSeconds(composition) {
94354
- const feature = composition.features.find((f) => f.cap === "power-source");
94355
- if (feature === void 0 || feature.kind !== "fields") return void 0;
94356
- const field = feature.fields["offSeconds"];
94357
- if (field === void 0 || field.kind !== "expression") return void 0;
94358
- const n = Number(field.expr);
94359
- return field.expr.trim() === "" || !Number.isFinite(n) ? void 0 : n;
94360
- }
94361
- /**
94362
- * The link a composition stores. An `existing` target names its own device; a
94363
- * `new` target (a composed device) is the composer's own device, so the caller
94364
- * passes the block id and a new-target composition without one has no link.
94365
- */
94366
- function powerSourceLinkOfComposition(composition, blockId) {
94367
- if (composition === null) return null;
94368
- let device;
94369
- if (composition.target.kind === "existing") device = composition.target.device;
94370
- else if (blockId !== void 0) device = composedDeviceRef(blockId);
94371
- else return null;
94372
- const feature = composition.features.find((f) => f.cap === "power-source");
94373
- if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return null;
94374
- const field = feature.fields["switchOn"];
94375
- if (field === void 0) return null;
94376
- const read = fieldReads(field).find((r) => r.cap === "switch");
94377
- if (read === void 0) return null;
94378
- return {
94379
- device,
94380
- switch: read.source,
94381
- offSeconds: normalizeOffSeconds(storedOffSeconds(composition))
94382
- };
94383
- }
94384
- SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
94385
94209
  function fromRead(source, cap, fieldPath) {
94386
94210
  return {
94387
94211
  kind: "from",
@@ -94400,17 +94224,16 @@ function expression(expr, bindings) {
94400
94224
  function literal(expr) {
94401
94225
  return expression(expr, {});
94402
94226
  }
94403
- String.raw`rose\(active(\d+), changed(\d+), (\d+(?:\.\d+)?)\)`;
94404
- var catalog$4 = CAP_CUSTOMIZE_CATALOG;
94227
+ var catalog$5 = CAP_CUSTOMIZE_CATALOG;
94405
94228
  function compileScalarOverride(input) {
94406
- const target = catalogTarget$3(input.draft.cap, input.draft.targetId);
94407
- if (target === null || target.cardinality !== "scalar" || target.path === void 0) return fail$1("target");
94408
- if (input.draft.transform.kind === "enum-map") return fail$1("enum");
94229
+ const target = catalogTarget$4(input.draft.cap, input.draft.targetId);
94230
+ if (target === null || target.cardinality !== "scalar" || target.path === void 0) return fail$2("target");
94231
+ if (input.draft.transform.kind === "enum-map") return fail$2("enum");
94409
94232
  const source = sourceSpec$1(target, input.sourceValueKind, input.draft.source.cap);
94410
- if (source === null) return fail$1("source-kind");
94411
- if (source.requiredUnit !== void 0 && input.sourceUnit !== source.requiredUnit) return fail$1("unit");
94233
+ if (source === null) return fail$2("source-kind");
94234
+ if (source.requiredUnit !== void 0 && input.sourceUnit !== source.requiredUnit) return fail$2("unit");
94412
94235
  const allowed = input.draft.transform.kind === "number" ? "identity" : input.draft.transform.kind;
94413
- if (!source.transformKinds.includes(allowed)) return fail$1("transform");
94236
+ if (!source.transformKinds.includes(allowed)) return fail$2("transform");
94414
94237
  if (target.override !== void 0) return compileOverride(input, target.path, target.override);
94415
94238
  const value = compileValue$1(input);
94416
94239
  if (!value.ok) return value;
@@ -94431,7 +94254,7 @@ function compileScalarOverride(input) {
94431
94254
  * companion — the native slice keeps its own clock.
94432
94255
  */
94433
94256
  function compileOverride(input, path, rule) {
94434
- if (input.sourceValueKind !== "boolean" || input.draft.transform.kind !== "identity") return fail$1("source-kind");
94257
+ if (input.sourceValueKind !== "boolean" || input.draft.transform.kind !== "identity") return fail$2("source-kind");
94435
94258
  const read = fromRead(refOf$1(input.draft), input.draft.source.cap, input.draft.source.fieldPath);
94436
94259
  const field = expression(overrideExpr(rule.whenSourceTrue, rule.unlessNative), {
94437
94260
  x: read,
@@ -94446,14 +94269,14 @@ function compileOverride(input, path, rule) {
94446
94269
  }
94447
94270
  };
94448
94271
  }
94449
- function fail$1(reason) {
94272
+ function fail$2(reason) {
94450
94273
  return {
94451
94274
  ok: false,
94452
94275
  reason
94453
94276
  };
94454
94277
  }
94455
- function catalogTarget$3(cap, targetId) {
94456
- const entry = catalog$4[cap];
94278
+ function catalogTarget$4(cap, targetId) {
94279
+ const entry = catalog$5[cap];
94457
94280
  if (entry === void 0) return null;
94458
94281
  return entry.targets.find((target) => target.id === targetId) ?? null;
94459
94282
  }
@@ -94474,7 +94297,7 @@ function compileValue$1(input) {
94474
94297
  value: identityValue(read, input.sourceValueKind)
94475
94298
  };
94476
94299
  if (transform.kind === "invert") {
94477
- if (input.sourceValueKind !== "boolean") return fail$1("source-kind");
94300
+ if (input.sourceValueKind !== "boolean") return fail$2("source-kind");
94478
94301
  return {
94479
94302
  ok: true,
94480
94303
  value: expression("!x", { x: read })
@@ -94482,7 +94305,7 @@ function compileValue$1(input) {
94482
94305
  }
94483
94306
  if (transform.kind === "threshold") return thresholdValue(transform, read, transform.minSamples ?? evidenceSamples(input));
94484
94307
  if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
94485
- return fail$1("transform");
94308
+ return fail$2("transform");
94486
94309
  }
94487
94310
  function identityValue(read, valueKind) {
94488
94311
  if (valueKind === "string") return expression("number(x)", { x: read });
@@ -94504,10 +94327,10 @@ function defaultThresholdSamples(cap, targetId, sourceCap) {
94504
94327
  }
94505
94328
  function thresholdValue(transform, read, minSamples) {
94506
94329
  const threshold = unsignedToken(transform.threshold);
94507
- if (threshold === null) return fail$1("threshold");
94330
+ if (threshold === null) return fail$2("threshold");
94508
94331
  const start = unsignedToken(transform.startDwellMs);
94509
94332
  const stop = unsignedToken(transform.stopDwellMs);
94510
- if (start === null || stop === null) return fail$1("dwell");
94333
+ if (start === null || stop === null) return fail$2("dwell");
94511
94334
  return {
94512
94335
  ok: true,
94513
94336
  value: expression(dwellExpr(transform.comparison, threshold, start, stop, minSamples), { x: read })
@@ -94516,7 +94339,7 @@ function thresholdValue(transform, read, minSamples) {
94516
94339
  function linearValue$1(transform, read, valueKind) {
94517
94340
  const scale = signedToken(transform.scale);
94518
94341
  const offset = signedToken(transform.offset);
94519
- if (scale === null || offset === null) return fail$1("scale");
94342
+ if (scale === null || offset === null) return fail$2("scale");
94520
94343
  const clamps = clampTokens$1(transform.clampMin, transform.clampMax);
94521
94344
  if (!clamps.ok) return clamps;
94522
94345
  return {
@@ -94532,10 +94355,10 @@ function clampTokens$1(clampMin, clampMax) {
94532
94355
  max: null
94533
94356
  }
94534
94357
  };
94535
- if (clampMin === void 0 || clampMax === void 0) return fail$1("clamp");
94358
+ if (clampMin === void 0 || clampMax === void 0) return fail$2("clamp");
94536
94359
  const min = signedToken(clampMin);
94537
94360
  const max = signedToken(clampMax);
94538
- if (min === null || max === null || clampMin > clampMax) return fail$1("clamp");
94361
+ if (min === null || max === null || clampMin > clampMax) return fail$2("clamp");
94539
94362
  return {
94540
94363
  ok: true,
94541
94364
  value: {
@@ -94545,7 +94368,7 @@ function clampTokens$1(clampMin, clampMax) {
94545
94368
  };
94546
94369
  }
94547
94370
  function compileCompanions$1(input, target, value) {
94548
- if (target.path === void 0) return fail$1("target");
94371
+ if (target.path === void 0) return fail$2("target");
94549
94372
  const path = target.path;
94550
94373
  return (target.companions ?? []).filter((companion) => companionIncluded$1(companion, input.apply)).reduce((acc, companion) => {
94551
94374
  if (!acc.ok) return acc;
@@ -94573,7 +94396,7 @@ function companionIncluded$1(companion, apply) {
94573
94396
  function companionField(input, path, companion, value) {
94574
94397
  if (companion.kind === "constant") {
94575
94398
  const expr = constantExpr(companion.value);
94576
- if (expr === null) return fail$1("scale");
94399
+ if (expr === null) return fail$2("scale");
94577
94400
  return {
94578
94401
  ok: true,
94579
94402
  value: literal(expr)
@@ -94591,7 +94414,7 @@ function transitionField(input, path, sourceChangedAt, value) {
94591
94414
  value: fromRead(refOf$1(input.draft), input.draft.source.cap, input.changedAtField)
94592
94415
  };
94593
94416
  if (input.apply === "replace") return stampOfValue(value);
94594
- if (!isIdentifier(path)) return fail$1("transform");
94417
+ if (!isIdentifier(path)) return fail$2("transform");
94595
94418
  const bindings = { [path]: fromRead(input.device, input.draft.cap, path) };
94596
94419
  return {
94597
94420
  ok: true,
@@ -94607,7 +94430,7 @@ function stampOfValue(value) {
94607
94430
  ok: true,
94608
94431
  value: expression("latchedAt(x)", { x: value })
94609
94432
  };
94610
- return fail$1("transform");
94433
+ return fail$2("transform");
94611
94434
  }
94612
94435
  function refOf$1(draft) {
94613
94436
  return {
@@ -94615,6 +94438,340 @@ function refOf$1(draft) {
94615
94438
  stableId: draft.source.stableId
94616
94439
  };
94617
94440
  }
94441
+ /**
94442
+ * Switch on = device on (D933, amended): a device with an ACTUATOR switch - its
94443
+ * own `switch`, the one that turns its function on - runs while that switch is on.
94444
+ * A SUPPLY switch (`power-source.switchOn`, an appliance on a plug) is never a
94445
+ * running source: the appliance keeps its power while it is idle.
94446
+ *
94447
+ * The default is derived from STRUCTURE (an actuator switch is present and no
94448
+ * supply relation is), computed at plan time and never written into the stored
94449
+ * composition: a stored composition is never rewritten silently, and an
94450
+ * authored `running` field always wins. The operator turns the default on and
94451
+ * off in the Customize running row ("Follow the device's switch").
94452
+ */
94453
+ var RUNNING_CAP = "running-state";
94454
+ var SWITCH_CAP = "switch";
94455
+ var ON_FIELD = "on";
94456
+ var CHANGED_AT_FIELD = "lastChangedAt";
94457
+ function fieldsFeatureOf(composition, cap) {
94458
+ const feature = composition.features.find((f) => f.cap === cap);
94459
+ return feature !== void 0 && feature.kind === "fields" ? feature : null;
94460
+ }
94461
+ /** The device switch the composed `switch.on` reads, when it is one plain `from` of a switch. */
94462
+ function actuatorSwitchRead(composition) {
94463
+ const feature = fieldsFeatureOf(composition, SWITCH_CAP);
94464
+ if (feature === null || !compositionFeatureEnabled(feature)) return null;
94465
+ const field = feature.fields[ON_FIELD];
94466
+ if (field === void 0 || field.kind !== "from" || field.cap !== SWITCH_CAP) return null;
94467
+ return {
94468
+ source: field.source,
94469
+ cap: field.cap,
94470
+ fieldPath: field.fieldPath
94471
+ };
94472
+ }
94473
+ function hasSupplyRelation(composition) {
94474
+ const feature = fieldsFeatureOf(composition, "power-source");
94475
+ return feature !== null && compositionFeatureEnabled(feature) && feature.fields["switchOn"] !== void 0;
94476
+ }
94477
+ /** Anything stored for running - a rule, or the opt-out - is the operator's, and the default stays out of it. */
94478
+ function hasAuthoredRunning(composition) {
94479
+ return fieldsFeatureOf(composition, RUNNING_CAP) !== null;
94480
+ }
94481
+ /** A NEW device of a type that offers "running", with an actuator switch and no supply relation. */
94482
+ function actuatorSwitchDrivesRunning(composition) {
94483
+ const target = composition.target;
94484
+ if (target.kind !== "new") return false;
94485
+ if (!RUNNING_CUSTOMIZE_DEVICE_TYPES.some((type) => type === target.type)) return false;
94486
+ return actuatorSwitchRead(composition) !== null && !hasSupplyRelation(composition);
94487
+ }
94488
+ /** The `running-state` feature that reads the actuator switch: the one the scalar compiler stores. */
94489
+ function followSwitchRunningFeature(composition, host) {
94490
+ const read = actuatorSwitchRead(composition);
94491
+ if (read === null) return null;
94492
+ const compiled = compileScalarOverride({
94493
+ draft: {
94494
+ kind: "scalar",
94495
+ cap: RUNNING_CAP,
94496
+ targetId: "running",
94497
+ source: {
94498
+ ...read.source,
94499
+ cap: read.cap,
94500
+ fieldPath: read.fieldPath
94501
+ },
94502
+ transform: { kind: "identity" }
94503
+ },
94504
+ device: host,
94505
+ apply: "add",
94506
+ sourceValueKind: "boolean",
94507
+ changedAtField: CHANGED_AT_FIELD,
94508
+ sourceUnit: null
94509
+ });
94510
+ return compiled.ok ? compiled.value : null;
94511
+ }
94512
+ /**
94513
+ * The composition the composer PLANS: the stored one, plus the derived running
94514
+ * field when nothing is authored for it. The input is never changed; with nothing
94515
+ * to add it is returned as it is.
94516
+ */
94517
+ function withDefaultRunning(composition, blockId) {
94518
+ if (hasAuthoredRunning(composition) || !actuatorSwitchDrivesRunning(composition)) return composition;
94519
+ const feature = followSwitchRunningFeature(composition, composedDeviceRef(blockId));
94520
+ return feature === null ? composition : {
94521
+ ...composition,
94522
+ features: [...composition.features, feature]
94523
+ };
94524
+ }
94525
+ /**
94526
+ * One composed field, evaluated from what its sources say NOW (D659).
94527
+ *
94528
+ * Pure. The composer calls it on every source change, and the slice-5 editor
94529
+ * will call it for its live preview, so both see the same answer.
94530
+ *
94531
+ * The rules (spec §2):
94532
+ * - a source that is offline or unreadable keeps its last value and is marked
94533
+ * STALE; the field is stale and keeps computing (D49);
94534
+ * - a source that is GONE makes the field UNAVAILABLE, `fatal`, and never a
94535
+ * plausible number (D393);
94536
+ * - a source that is unavailable but NOT gone (e.g. a cap unregistered at
94537
+ * runtime, R7b) makes the field UNAVAILABLE, non-fatal, `value: null`: it
94538
+ * may come back on its own, no block failure is raised for it;
94539
+ * - an expression that fails on a value makes the field unavailable for that
94540
+ * value, and NOT fatal: the next value may compute.
94541
+ *
94542
+ * `confirmed` (D663, D49): whether a NON-fatal unavailability is an ANSWER — a
94543
+ * cap the provider unregistered and a re-read agreed, a field the source
94544
+ * reported without, an expression that failed on a value — or only the
94545
+ * absence of one (a failed read, a first or empty read, a source not tracked
94546
+ * yet). Only a confirmed unavailability may hand a `release`-mode field back
94547
+ * to the native provider; an unconfirmed one holds it on its last value.
94548
+ * Absent means NOT confirmed. Fatal is always confirmed.
94549
+ *
94550
+ * When an expression has more than one unavailable binding, a FATAL one always
94551
+ * wins the outcome, regardless of position: every binding is scanned before
94552
+ * the field is judged, so an earlier non-fatal binding (e.g. a cap that is
94553
+ * momentarily unregistered) can never hide a later fatal one (a deleted
94554
+ * source) behind an early return.
94555
+ */
94556
+ function describeRead(read) {
94557
+ return `${compositionSourceKey(read.source)} ${read.cap}.${read.fieldPath}`;
94558
+ }
94559
+ function isConfirmed(reading) {
94560
+ return reading.fatal || reading.confirmed === true;
94561
+ }
94562
+ function fromReading(reading, read) {
94563
+ if (reading.state === "unavailable") return {
94564
+ state: "unavailable",
94565
+ value: null,
94566
+ reason: `${describeRead(read)}: ${reading.reason}`,
94567
+ fatal: reading.fatal,
94568
+ confirmed: isConfirmed(reading)
94569
+ };
94570
+ return {
94571
+ state: reading.state,
94572
+ value: reading.value,
94573
+ reason: reading.state === "stale" ? `${describeRead(read)}: ${reading.reason}` : null,
94574
+ deadline: null
94575
+ };
94576
+ }
94577
+ function expressionOutcome(source, read, now, stateful) {
94578
+ const values = {};
94579
+ const staleReasons = [];
94580
+ let fatalUnavailable = null;
94581
+ let nonFatalUnavailable = null;
94582
+ for (const [name, binding] of Object.entries(source.bindings)) {
94583
+ if (binding.kind === "literal") {
94584
+ values[name] = binding.value;
94585
+ continue;
94586
+ }
94587
+ const reading = read(binding);
94588
+ if (reading.state === "unavailable") {
94589
+ const outcome = {
94590
+ state: "unavailable",
94591
+ value: null,
94592
+ reason: `binding \`${name}\` (${describeRead(binding)}): ${reading.reason}`,
94593
+ fatal: reading.fatal,
94594
+ confirmed: isConfirmed(reading)
94595
+ };
94596
+ if (reading.fatal) {
94597
+ fatalUnavailable = outcome;
94598
+ break;
94599
+ }
94600
+ if (nonFatalUnavailable === null || outcome.confirmed && !nonFatalUnavailable.confirmed) nonFatalUnavailable = outcome;
94601
+ continue;
94602
+ }
94603
+ values[name] = reading.value;
94604
+ if (reading.state === "fresh" && reading.transition !== void 0 && stateful !== void 0) stateful.expressionMemory.dwellTransition = reading.transition;
94605
+ if (reading.state === "stale") staleReasons.push(`\`${name}\`: ${reading.reason}`);
94606
+ }
94607
+ const unavailable = fatalUnavailable ?? nonFatalUnavailable;
94608
+ if (unavailable !== null) {
94609
+ if (stateful !== void 0 && stateful.currentOutput !== void 0 && expressionContainsBuiltinCall(source.expr, "count")) return {
94610
+ state: "stale",
94611
+ value: evaluateCount(null, {
94612
+ kind: "count",
94613
+ highWater: null,
94614
+ primed: false
94615
+ }, stateful.currentOutput),
94616
+ reason: `${unavailable.reason}; holding the last accumulator value`,
94617
+ deadline: null
94618
+ };
94619
+ return unavailable;
94620
+ }
94621
+ const deadlines = [];
94622
+ const hooks = {
94623
+ noteDeadline: (at) => deadlines.push(at),
94624
+ ...stateful?.timerDriven === true ? { timerDriven: true } : {},
94625
+ convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
94626
+ };
94627
+ const result = evaluateExpressionSource(source.expr, values, now, {
94628
+ hooks,
94629
+ ...stateful === void 0 ? {} : { invokeStateful: (invocation) => evaluateStatefulExpressionCall(stateful.callPathPrefix === void 0 ? invocation : {
94630
+ ...invocation,
94631
+ path: `${stateful.callPathPrefix}@${invocation.path}`
94632
+ }, stateful.expressionMemory, {
94633
+ currentOutput: stateful.currentOutput,
94634
+ startedAtMs: stateful.startedAtMs,
94635
+ nowMs: now
94636
+ }, hooks) }
94637
+ });
94638
+ const transition = stateful?.expressionMemory.dwellTransition ?? null;
94639
+ if (stateful !== void 0) stateful.expressionMemory.dwellTransition = null;
94640
+ if (!result.ok) return {
94641
+ state: "unavailable",
94642
+ value: null,
94643
+ reason: `the expression failed: ${result.error}`,
94644
+ fatal: false,
94645
+ confirmed: true,
94646
+ expressionFailed: true
94647
+ };
94648
+ return {
94649
+ state: staleReasons.length > 0 ? "stale" : "fresh",
94650
+ value: result.value,
94651
+ reason: staleReasons.length > 0 ? staleReasons.join("; ") : null,
94652
+ deadline: deadlines.length > 0 ? Math.min(...deadlines) : null,
94653
+ ...transition === null ? {} : { transition }
94654
+ };
94655
+ }
94656
+ function aggregateRead(reading) {
94657
+ if (reading.state === "unavailable") return {
94658
+ state: "unavailable",
94659
+ fatal: reading.fatal,
94660
+ reason: reading.reason
94661
+ };
94662
+ return {
94663
+ state: reading.state,
94664
+ value: reading.value,
94665
+ ...reading.state === "stale" ? { reason: reading.reason } : {}
94666
+ };
94667
+ }
94668
+ function aggregateField(source, read) {
94669
+ const outcome = evaluateAggregate({
94670
+ reducer: source.reducer,
94671
+ ...source.activeWhen === void 0 ? {} : { activeWhen: source.activeWhen },
94672
+ members: source.reads.map((item) => aggregateRead(read(item))),
94673
+ publish: source.publish,
94674
+ empty: source.empty
94675
+ });
94676
+ if (outcome.kind === "value") return {
94677
+ state: "fresh",
94678
+ value: outcome.value,
94679
+ reason: null,
94680
+ deadline: null
94681
+ };
94682
+ return {
94683
+ state: "unavailable",
94684
+ value: null,
94685
+ reason: outcome.reason,
94686
+ fatal: outcome.fatal,
94687
+ confirmed: true
94688
+ };
94689
+ }
94690
+ function evaluateCompositionField(input) {
94691
+ const { source } = input;
94692
+ switch (source.kind) {
94693
+ case "from": return fromReading(input.read(source), source);
94694
+ case "expression": return expressionOutcome(source, input.read, input.now, input.stateful);
94695
+ case "aggregate": return aggregateField(source, input.read);
94696
+ case "series": return {
94697
+ state: "unavailable",
94698
+ value: null,
94699
+ reason: "a series field is written from device history",
94700
+ fatal: false,
94701
+ confirmed: false
94702
+ };
94703
+ case "code": return {
94704
+ state: "unavailable",
94705
+ value: null,
94706
+ reason: "code fields are not runnable in the composer — they arrive in slice 4",
94707
+ fatal: true,
94708
+ confirmed: true
94709
+ };
94710
+ }
94711
+ }
94712
+ function lockDoorLinkOfComposition(composition) {
94713
+ if (composition === null || composition.target.kind !== "existing") return null;
94714
+ const feature = composition.features.find((f) => f.cap === "lock-control");
94715
+ if (feature === void 0 || feature.kind !== "fields") return null;
94716
+ const state = feature.fields["state"];
94717
+ if (state === void 0 || state.kind !== "expression") return null;
94718
+ const x = state.bindings["x"];
94719
+ if (x === void 0 || x.kind !== "from") return null;
94720
+ return {
94721
+ lock: composition.target.device,
94722
+ sensor: x.source
94723
+ };
94724
+ }
94725
+ /**
94726
+ * Which smart switch powers a device (the `power-source` Customize extension):
94727
+ * the source its stored `power-source.switchOn` field reads, and the off time of
94728
+ * a forced restart stored beside it. Read from the STORED composition, never kept
94729
+ * as a second copy (D676). Shared by the hub (which acts on the switch) and the
94730
+ * admin UI (which shows it).
94731
+ */
94732
+ /**
94733
+ * The stored off time, or the default when none is stored. A stored number out
94734
+ * of range is CLAMPED to the bounds (a hand-written value never refuses the
94735
+ * link, it just cannot cut power for an absurd time); a non-integer is rounded.
94736
+ */
94737
+ function normalizeOffSeconds(value) {
94738
+ if (typeof value !== "number" || !Number.isFinite(value)) return 10;
94739
+ return Math.min(120, Math.max(3, Math.round(value)));
94740
+ }
94741
+ /** The constant a stored `offSeconds` field carries, or undefined when it is not a literal number. */
94742
+ function storedOffSeconds(composition) {
94743
+ const feature = composition.features.find((f) => f.cap === "power-source");
94744
+ if (feature === void 0 || feature.kind !== "fields") return void 0;
94745
+ const field = feature.fields["offSeconds"];
94746
+ if (field === void 0 || field.kind !== "expression") return void 0;
94747
+ const n = Number(field.expr);
94748
+ return field.expr.trim() === "" || !Number.isFinite(n) ? void 0 : n;
94749
+ }
94750
+ /**
94751
+ * The link a composition stores. An `existing` target names its own device; a
94752
+ * `new` target (a composed device) is the composer's own device, so the caller
94753
+ * passes the block id and a new-target composition without one has no link.
94754
+ */
94755
+ function powerSourceLinkOfComposition(composition, blockId) {
94756
+ if (composition === null) return null;
94757
+ let device;
94758
+ if (composition.target.kind === "existing") device = composition.target.device;
94759
+ else if (blockId !== void 0) device = composedDeviceRef(blockId);
94760
+ else return null;
94761
+ const feature = composition.features.find((f) => f.cap === "power-source");
94762
+ if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return null;
94763
+ const field = feature.fields["switchOn"];
94764
+ if (field === void 0) return null;
94765
+ const read = fieldReads(field).find((r) => r.cap === "switch");
94766
+ if (read === void 0) return null;
94767
+ return {
94768
+ device,
94769
+ switch: read.source,
94770
+ offSeconds: normalizeOffSeconds(storedOffSeconds(composition))
94771
+ };
94772
+ }
94773
+ SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
94774
+ String.raw`rose\(active(\d+), changed(\d+), (\d+(?:\.\d+)?)\)`;
94618
94775
  DeviceRole.BinarySensor, DeviceRole.MotionSensor;
94619
94776
  new Set(CAP_NAMES);
94620
94777
  function isUnfilledRequiredProblem(problem) {
@@ -105420,6 +105577,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
105420
105577
  access: "create",
105421
105578
  role: "viewer"
105422
105579
  },
105580
+ "timedRun.getOptions": {
105581
+ capName: "timed-run",
105582
+ capScope: "device",
105583
+ addonId: null,
105584
+ access: "view",
105585
+ role: "viewer"
105586
+ },
105423
105587
  "timedRun.getStatus": {
105424
105588
  capName: "timed-run",
105425
105589
  capScope: "device",
@@ -105434,6 +105598,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
105434
105598
  access: "create",
105435
105599
  role: "viewer"
105436
105600
  },
105601
+ "timedRun.setSettings": {
105602
+ capName: "timed-run",
105603
+ capScope: "device",
105604
+ addonId: null,
105605
+ access: "create",
105606
+ role: "admin"
105607
+ },
105437
105608
  "toast.onToast": {
105438
105609
  capName: "toast",
105439
105610
  capScope: "system",
@@ -109201,6 +109372,11 @@ Object.freeze({
109201
109372
  form: "single",
109202
109373
  optional: false
109203
109374
  }],
109375
+ "timedRun.getOptions": [{
109376
+ name: "deviceId",
109377
+ form: "single",
109378
+ optional: false
109379
+ }],
109204
109380
  "timedRun.getStatus": [{
109205
109381
  name: "deviceId",
109206
109382
  form: "single",
@@ -109211,6 +109387,11 @@ Object.freeze({
109211
109387
  form: "single",
109212
109388
  optional: false
109213
109389
  }],
109390
+ "timedRun.setSettings": [{
109391
+ name: "deviceId",
109392
+ form: "single",
109393
+ optional: false
109394
+ }],
109214
109395
  "update.getStatus": [{
109215
109396
  name: "deviceId",
109216
109397
  form: "single",
@@ -114253,6 +114434,18 @@ Object.defineProperty(exports, "timedRunLimitOf", {
114253
114434
  return timedRunLimitOf;
114254
114435
  }
114255
114436
  });
114437
+ Object.defineProperty(exports, "timedRunMaxIn", {
114438
+ enumerable: true,
114439
+ get: function() {
114440
+ return timedRunMaxIn;
114441
+ }
114442
+ });
114443
+ Object.defineProperty(exports, "timedRunQuickRun", {
114444
+ enumerable: true,
114445
+ get: function() {
114446
+ return timedRunQuickRun;
114447
+ }
114448
+ });
114256
114449
  Object.defineProperty(exports, "timedRunSeconds", {
114257
114450
  enumerable: true,
114258
114451
  get: function() {
@@ -114361,6 +114554,12 @@ Object.defineProperty(exports, "weekdayOfLocalDate", {
114361
114554
  return weekdayOfLocalDate;
114362
114555
  }
114363
114556
  });
114557
+ Object.defineProperty(exports, "withDefaultRunning", {
114558
+ enumerable: true,
114559
+ get: function() {
114560
+ return withDefaultRunning;
114561
+ }
114562
+ });
114364
114563
  Object.defineProperty(exports, "withLocationMode", {
114365
114564
  enumerable: true,
114366
114565
  get: function() {