@camstack/server 1.2.801 → 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 (94) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/trpc/generated-cap-routers.js +26 -0
  3. package/dist/core/addon/addon-settings-provider.js +25 -0
  4. package/package.json +10 -9
  5. package/system/dist/addon-runner.js +1 -0
  6. package/system/dist/addon-runner.mjs +1 -0
  7. package/system/dist/{agent-https-BnKdN7Rx.mjs → agent-https-BRfJO9ZR.mjs} +1 -1
  8. package/system/dist/{agent-https-BjJ2cnwd.js → agent-https-DtYiXPGm.js} +1 -1
  9. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  10. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  11. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  12. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  13. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  14. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  15. package/system/dist/builtins/autotrack/index.js +1 -1
  16. package/system/dist/builtins/autotrack/index.mjs +1 -1
  17. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  18. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  19. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  20. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  21. package/system/dist/builtins/camera-grid/index.js +1 -1
  22. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  23. package/system/dist/builtins/composer/composer.addon.js +6 -5
  24. package/system/dist/builtins/composer/composer.addon.mjs +6 -5
  25. package/system/dist/builtins/console-logging/index.js +1 -1
  26. package/system/dist/builtins/console-logging/index.mjs +1 -1
  27. package/system/dist/builtins/core-blocks/core-blocks.addon.js +65 -6
  28. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +65 -6
  29. package/system/dist/builtins/core-blocks/timed-run/timed-run-service.d.ts +17 -0
  30. package/system/dist/builtins/core-blocks/timed-run/timed-run-wiring.d.ts +6 -0
  31. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  32. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  33. package/system/dist/builtins/device-manager/device-config-contribution.d.ts +1 -0
  34. package/system/dist/builtins/device-manager/device-manager.addon.js +47 -2
  35. package/system/dist/builtins/device-manager/device-manager.addon.mjs +47 -2
  36. package/system/dist/builtins/device-manager/timed-run-config-schema.d.ts +18 -0
  37. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  38. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  39. package/system/dist/builtins/keychain/index.js +4 -4
  40. package/system/dist/builtins/keychain/index.mjs +4 -4
  41. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  42. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  43. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  44. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  45. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  46. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  47. package/system/dist/builtins/loki-logging/index.js +1 -1
  48. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  49. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  50. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  51. package/system/dist/builtins/platform-probe/index.js +1 -1
  52. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  53. package/system/dist/builtins/record-entries/index.js +1 -1
  54. package/system/dist/builtins/record-entries/index.mjs +1 -1
  55. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  56. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  57. package/system/dist/builtins/snapshot/index.js +1 -1
  58. package/system/dist/builtins/snapshot/index.mjs +1 -1
  59. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  60. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  61. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  62. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  63. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  64. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  65. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  66. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  67. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  68. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  69. package/system/dist/builtins/winston-logging/index.js +1 -1
  70. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  71. package/system/dist/{capture-engine-B9__aDmc.mjs → capture-engine-BFgeAHa9.mjs} +1 -1
  72. package/system/dist/{capture-engine-DfPZm5jP.js → capture-engine-BQ08XTnZ.js} +1 -1
  73. package/system/dist/{composition-sources-CcikkVOX.js → composition-sources-DNHNUvTr.js} +1 -1
  74. package/system/dist/{composition-sources-CjT_EsId.mjs → composition-sources-DkOfzgpS.mjs} +1 -1
  75. package/system/dist/{constants-Iha5kSgS.js → constants-D5CG3Gvc.js} +1 -1
  76. package/system/dist/{constants-D09uTsrc.mjs → constants-GCrIKhD_.mjs} +1 -1
  77. package/system/dist/{device-ca-C1pfeZfN.js → device-ca-DgZeLVC1.js} +1 -1
  78. package/system/dist/{device-ca-DM2h_Qrk.mjs → device-ca-Dk2sx_18.mjs} +1 -1
  79. package/system/dist/{dist--HaCM746.js → dist-D5nGm8Sd.js} +602 -372
  80. package/system/dist/{dist-ysMqEeaW.mjs → dist-ze-qVU7x.mjs} +585 -373
  81. package/system/dist/file-host-worker.js +1 -1
  82. package/system/dist/file-host-worker.mjs +1 -1
  83. package/system/dist/{hub-mdns-ciao-CUZ6phZn.js → hub-mdns-ciao-D4g9qsNL.js} +2 -2
  84. package/system/dist/{hub-mdns-ciao-C3jwbb5f.mjs → hub-mdns-ciao-DD2QP3w5.mjs} +2 -2
  85. package/system/dist/index.js +16 -10
  86. package/system/dist/index.mjs +16 -10
  87. package/system/dist/kernel/transport/child-cap-protocol.d.ts +1 -1
  88. package/system/dist/{legacy-integration-rows-door-B1ZSr6jn.mjs → legacy-integration-rows-door-BvEFQrAa.mjs} +1 -1
  89. package/system/dist/{legacy-integration-rows-door-CCZw-yoA.js → legacy-integration-rows-door-MRr8Ncb_.js} +1 -1
  90. package/system/dist/{restore-archive-wzwpsuCo.mjs → restore-archive-DBc5sNQS.mjs} +82 -82
  91. package/system/dist/{restore-archive-rBEGddHB.js → restore-archive-aG7OlQNo.js} +1 -1
  92. package/system/dist/{wal-maintenance-EhxZt6T-.js → wal-maintenance-C-ddHy-q.js} +0 -0
  93. package/system/dist/{wal-maintenance-_PPIgcP4.mjs → wal-maintenance-vQHsOLGg.mjs} +0 -0
  94. 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-CQP-REJp.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).
@@ -4288,6 +4288,19 @@ var BaseAddon = class {
4288
4288
  const overlay = await this.scopedSettingsOverlay(scope, cap, nodeId);
4289
4289
  return hydrateSchema(schema, overlay ? await this.overlayKeepingMarkers(stored, overlay) : stored, { inlineSecretsAsViews: true });
4290
4290
  }
4291
+ /**
4292
+ * The scoped schemas this addon serves: one entry per loaded (capability, scope), capabilities
4293
+ * in declaration order, scopes in {@link SCOPED_SETTINGS_SCOPES} order. `[]` when it declares
4294
+ * nothing.
4295
+ */
4296
+ async listScopedSettings() {
4297
+ await this.loadScopedSchemas();
4298
+ return [...this._scopedByCap].flatMap(([cap, entries]) => entries.map((entry) => ({
4299
+ cap,
4300
+ scope: entry.scope,
4301
+ sectionIds: entry.schema.sections.map((section) => section.id)
4302
+ })));
4303
+ }
4291
4304
  /** The OPERATOR's write of declared keys of one scope (D787 secret semantics). */
4292
4305
  async updateScopedSettings(scope, cap, patch, nodeId) {
4293
4306
  this._operatorWriteDepth++;
@@ -8766,13 +8779,25 @@ Object.freeze({
8766
8779
  "path": "temperature",
8767
8780
  "valueType": "number"
8768
8781
  }],
8769
- "timed-run": [{
8770
- "path": "activeUntil",
8771
- "valueType": "number"
8772
- }, {
8773
- "path": "requestedBy",
8774
- "valueType": "string"
8775
- }],
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
+ ],
8776
8801
  "update": [
8777
8802
  {
8778
8803
  "path": "currentVersion",
@@ -45704,6 +45729,12 @@ var SettingsSchemaWithValuesSchema = zod.z.object({
45704
45729
  var SettingsPatchSchema = zod.z.record(zod.z.string(), zod.z.unknown());
45705
45730
  /** The scope of a scoped-settings call (D986): where the capability declared the values. */
45706
45731
  var ScopedSettingsScopeSchema = zod.z.enum(SCOPED_SETTINGS_SCOPES);
45732
+ /** One scoped schema an addon serves: its capability, scope and section ids. */
45733
+ var ScopedSettingsDeclarationSchema = zod.z.object({
45734
+ cap: zod.z.string(),
45735
+ scope: ScopedSettingsScopeSchema,
45736
+ sectionIds: zod.z.array(zod.z.string())
45737
+ });
45707
45738
  /** Standard success response for update operations. */
45708
45739
  var SettingsUpdateResultSchema = zod.z.object({ success: zod.z.literal(true) });
45709
45740
  /**
@@ -45758,6 +45789,10 @@ var addonSettingsCapability = {
45758
45789
  scope: ScopedSettingsScopeSchema,
45759
45790
  nodeId: zod.z.string().optional()
45760
45791
  }), SettingsSchemaWithValuesSchema.nullable()),
45792
+ listScopedSettings: method(zod.z.object({
45793
+ addonId: zod.z.string(),
45794
+ nodeId: zod.z.string().optional()
45795
+ }), zod.z.array(ScopedSettingsDeclarationSchema).nullable()),
45761
45796
  updateScopedSettings: method(zod.z.object({
45762
45797
  addonId: zod.z.string(),
45763
45798
  cap: zod.z.string(),
@@ -54929,8 +54964,9 @@ function planComposition(composition, lookupCap, target) {
54929
54964
  }, lookupCap, servedCommands));
54930
54965
  }
54931
54966
  const result = planFeature(feature, index, featureTarget, lookupCap, servedCommands);
54932
- return compositionFeatureEnabled(feature) ? result : {
54933
- 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,
54934
54970
  fields: [],
54935
54971
  features: [],
54936
54972
  events: []
@@ -85711,93 +85747,27 @@ var RunningFlipEventDataSchema = zod.z.object({
85711
85747
  phase: zod.z.string().nullable()
85712
85748
  });
85713
85749
  var RUNNING_DEVICE_TYPES = Object.values(DeviceType);
85714
- /** Generic Customize target for the running boolean (D936). */
85715
- var runningCustomize = {
85716
- version: 1,
85717
- overridable: [{
85718
- path: "running",
85719
- by: "running"
85720
- }],
85721
- targets: [{
85722
- id: "running",
85723
- cardinality: "scalar",
85724
- vocabulary: {
85725
- cap: "running-state",
85726
- stateField: "running"
85727
- },
85728
- deviceTypes: [
85729
- DeviceType.Washer,
85730
- DeviceType.Dryer,
85731
- DeviceType.Dishwasher,
85732
- DeviceType.Vacuum,
85733
- DeviceType.LawnMower,
85734
- DeviceType.MediaPlayer,
85735
- DeviceType.WaterHeater,
85736
- DeviceType.Humidifier,
85737
- DeviceType.Fan,
85738
- DeviceType.Climate,
85739
- DeviceType.Thermostat,
85740
- DeviceType.PetFeeder,
85741
- DeviceType.Heater
85742
- ],
85743
- apply: "add",
85744
- path: "running",
85745
- sources: [
85746
- {
85747
- kind: "switch",
85748
- transforms: [{ kind: "identity" }]
85749
- },
85750
- {
85751
- kind: "binary",
85752
- transforms: [{ kind: "identity" }, { kind: "invert" }]
85753
- },
85754
- {
85755
- kind: "numeric",
85756
- requiredUnit: "W",
85757
- transforms: [{
85758
- kind: "threshold",
85759
- comparisons: ["gte", "lte"],
85760
- comparison: "gte",
85761
- defaultThreshold: 5,
85762
- defaultStartDwellMs: RUNNING_POWER_START_DELAY_MS,
85763
- defaultStopDwellMs: RUNNING_POWER_STOP_DELAY_MS,
85764
- thresholdUnit: "W"
85765
- }]
85766
- }
85767
- ],
85768
- companions: [
85769
- {
85770
- kind: "constant",
85771
- path: "source",
85772
- value: "assigned",
85773
- when: "always"
85774
- },
85775
- {
85776
- kind: "constant",
85777
- path: "phase",
85778
- value: null,
85779
- when: "add"
85780
- },
85781
- {
85782
- kind: "clock",
85783
- path: "lastFetchedAt",
85784
- when: "always"
85785
- },
85786
- {
85787
- kind: "transition-time",
85788
- path: "since",
85789
- sourceChangedAt: "prefer"
85790
- }
85791
- ],
85792
- sourceReport: {
85793
- status: "assignment-status",
85794
- runtimeField: "source",
85795
- nativeValue: "native",
85796
- assignedValue: "assigned"
85797
- },
85798
- advancedExpression: true
85799
- }]
85800
- };
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
+ ];
85801
85771
  var runningStateCapability = {
85802
85772
  name: "running-state",
85803
85773
  scope: "device",
@@ -85817,7 +85787,78 @@ var runningStateCapability = {
85817
85787
  durability: "restored",
85818
85788
  history: { fields: { running: { kind: "boolean" } } },
85819
85789
  volatileStateFields: ["lastFetchedAt"],
85820
- 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
+ }
85821
85862
  };
85822
85863
  /**
85823
85864
  * scene-monitor — device-scoped reference-region state cap. An operator marks
@@ -89488,12 +89529,14 @@ var TIMED_RUN_LIMITS = {
89488
89529
  [DeviceType.Heater]: {
89489
89530
  actuator: "switch",
89490
89531
  maxSeconds: 10800,
89491
- unit: "min"
89532
+ unit: "min",
89533
+ quickRunDefault: 30
89492
89534
  },
89493
89535
  [DeviceType.PetFountain]: {
89494
89536
  actuator: "pet-fountain",
89495
89537
  maxSeconds: 300,
89496
- unit: "s"
89538
+ unit: "s",
89539
+ quickRunDefault: 60
89497
89540
  }
89498
89541
  };
89499
89542
  var TIMED_RUN_DEVICE_TYPES = [DeviceType.Heater, DeviceType.PetFountain];
@@ -89504,6 +89547,27 @@ function timedRunLimitOf(deviceType) {
89504
89547
  function timedRunSeconds(duration, unit) {
89505
89548
  return unit === "min" ? duration * 60 : duration;
89506
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
+ }
89507
89571
  /** Why a request was not carried out. Typed, so a caller can say it in words. */
89508
89572
  var TimedRunRefusalSchema = zod.z.enum([
89509
89573
  "unsupported-device",
@@ -89524,8 +89588,23 @@ var TimedRunStatusSchema = zod.z.object({
89524
89588
  activeUntil: zod.z.number().nullable(),
89525
89589
  /** Who asked for the run (a user id or an addon id); `null` when nothing is armed or it did not say. */
89526
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(),
89527
89597
  lastFetchedAt: zod.z.number()
89528
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() });
89529
89608
  var timedRunCapability = {
89530
89609
  name: "timed-run",
89531
89610
  scope: "device",
@@ -89533,7 +89612,24 @@ var timedRunCapability = {
89533
89612
  kind: "wrapper",
89534
89613
  defaultActive: true,
89535
89614
  deviceTypes: TIMED_RUN_DEVICE_TYPES,
89615
+ deviceConfig: { ui: {
89616
+ kind: "derived-form",
89617
+ builderId: "timed-run",
89618
+ tab: "general"
89619
+ } },
89536
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
+ }),
89537
89633
  /**
89538
89634
  * Turn the device on and arm its off. A run already armed is replaced (the
89539
89635
  * new deadline wins). Refuses with a typed reason above the type's maximum.
@@ -94110,255 +94206,6 @@ function evaluateAggregate(input) {
94110
94206
  counts
94111
94207
  };
94112
94208
  }
94113
- /**
94114
- * One composed field, evaluated from what its sources say NOW (D659).
94115
- *
94116
- * Pure. The composer calls it on every source change, and the slice-5 editor
94117
- * will call it for its live preview, so both see the same answer.
94118
- *
94119
- * The rules (spec §2):
94120
- * - a source that is offline or unreadable keeps its last value and is marked
94121
- * STALE; the field is stale and keeps computing (D49);
94122
- * - a source that is GONE makes the field UNAVAILABLE, `fatal`, and never a
94123
- * plausible number (D393);
94124
- * - a source that is unavailable but NOT gone (e.g. a cap unregistered at
94125
- * runtime, R7b) makes the field UNAVAILABLE, non-fatal, `value: null`: it
94126
- * may come back on its own, no block failure is raised for it;
94127
- * - an expression that fails on a value makes the field unavailable for that
94128
- * value, and NOT fatal: the next value may compute.
94129
- *
94130
- * `confirmed` (D663, D49): whether a NON-fatal unavailability is an ANSWER — a
94131
- * cap the provider unregistered and a re-read agreed, a field the source
94132
- * reported without, an expression that failed on a value — or only the
94133
- * absence of one (a failed read, a first or empty read, a source not tracked
94134
- * yet). Only a confirmed unavailability may hand a `release`-mode field back
94135
- * to the native provider; an unconfirmed one holds it on its last value.
94136
- * Absent means NOT confirmed. Fatal is always confirmed.
94137
- *
94138
- * When an expression has more than one unavailable binding, a FATAL one always
94139
- * wins the outcome, regardless of position: every binding is scanned before
94140
- * the field is judged, so an earlier non-fatal binding (e.g. a cap that is
94141
- * momentarily unregistered) can never hide a later fatal one (a deleted
94142
- * source) behind an early return.
94143
- */
94144
- function describeRead(read) {
94145
- return `${compositionSourceKey(read.source)} ${read.cap}.${read.fieldPath}`;
94146
- }
94147
- function isConfirmed(reading) {
94148
- return reading.fatal || reading.confirmed === true;
94149
- }
94150
- function fromReading(reading, read) {
94151
- if (reading.state === "unavailable") return {
94152
- state: "unavailable",
94153
- value: null,
94154
- reason: `${describeRead(read)}: ${reading.reason}`,
94155
- fatal: reading.fatal,
94156
- confirmed: isConfirmed(reading)
94157
- };
94158
- return {
94159
- state: reading.state,
94160
- value: reading.value,
94161
- reason: reading.state === "stale" ? `${describeRead(read)}: ${reading.reason}` : null,
94162
- deadline: null
94163
- };
94164
- }
94165
- function expressionOutcome(source, read, now, stateful) {
94166
- const values = {};
94167
- const staleReasons = [];
94168
- let fatalUnavailable = null;
94169
- let nonFatalUnavailable = null;
94170
- for (const [name, binding] of Object.entries(source.bindings)) {
94171
- if (binding.kind === "literal") {
94172
- values[name] = binding.value;
94173
- continue;
94174
- }
94175
- const reading = read(binding);
94176
- if (reading.state === "unavailable") {
94177
- const outcome = {
94178
- state: "unavailable",
94179
- value: null,
94180
- reason: `binding \`${name}\` (${describeRead(binding)}): ${reading.reason}`,
94181
- fatal: reading.fatal,
94182
- confirmed: isConfirmed(reading)
94183
- };
94184
- if (reading.fatal) {
94185
- fatalUnavailable = outcome;
94186
- break;
94187
- }
94188
- if (nonFatalUnavailable === null || outcome.confirmed && !nonFatalUnavailable.confirmed) nonFatalUnavailable = outcome;
94189
- continue;
94190
- }
94191
- values[name] = reading.value;
94192
- if (reading.state === "fresh" && reading.transition !== void 0 && stateful !== void 0) stateful.expressionMemory.dwellTransition = reading.transition;
94193
- if (reading.state === "stale") staleReasons.push(`\`${name}\`: ${reading.reason}`);
94194
- }
94195
- const unavailable = fatalUnavailable ?? nonFatalUnavailable;
94196
- if (unavailable !== null) {
94197
- if (stateful !== void 0 && stateful.currentOutput !== void 0 && expressionContainsBuiltinCall(source.expr, "count")) return {
94198
- state: "stale",
94199
- value: evaluateCount(null, {
94200
- kind: "count",
94201
- highWater: null,
94202
- primed: false
94203
- }, stateful.currentOutput),
94204
- reason: `${unavailable.reason}; holding the last accumulator value`,
94205
- deadline: null
94206
- };
94207
- return unavailable;
94208
- }
94209
- const deadlines = [];
94210
- const hooks = {
94211
- noteDeadline: (at) => deadlines.push(at),
94212
- ...stateful?.timerDriven === true ? { timerDriven: true } : {},
94213
- convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
94214
- };
94215
- const result = evaluateExpressionSource(source.expr, values, now, {
94216
- hooks,
94217
- ...stateful === void 0 ? {} : { invokeStateful: (invocation) => evaluateStatefulExpressionCall(stateful.callPathPrefix === void 0 ? invocation : {
94218
- ...invocation,
94219
- path: `${stateful.callPathPrefix}@${invocation.path}`
94220
- }, stateful.expressionMemory, {
94221
- currentOutput: stateful.currentOutput,
94222
- startedAtMs: stateful.startedAtMs,
94223
- nowMs: now
94224
- }, hooks) }
94225
- });
94226
- const transition = stateful?.expressionMemory.dwellTransition ?? null;
94227
- if (stateful !== void 0) stateful.expressionMemory.dwellTransition = null;
94228
- if (!result.ok) return {
94229
- state: "unavailable",
94230
- value: null,
94231
- reason: `the expression failed: ${result.error}`,
94232
- fatal: false,
94233
- confirmed: true,
94234
- expressionFailed: true
94235
- };
94236
- return {
94237
- state: staleReasons.length > 0 ? "stale" : "fresh",
94238
- value: result.value,
94239
- reason: staleReasons.length > 0 ? staleReasons.join("; ") : null,
94240
- deadline: deadlines.length > 0 ? Math.min(...deadlines) : null,
94241
- ...transition === null ? {} : { transition }
94242
- };
94243
- }
94244
- function aggregateRead(reading) {
94245
- if (reading.state === "unavailable") return {
94246
- state: "unavailable",
94247
- fatal: reading.fatal,
94248
- reason: reading.reason
94249
- };
94250
- return {
94251
- state: reading.state,
94252
- value: reading.value,
94253
- ...reading.state === "stale" ? { reason: reading.reason } : {}
94254
- };
94255
- }
94256
- function aggregateField(source, read) {
94257
- const outcome = evaluateAggregate({
94258
- reducer: source.reducer,
94259
- ...source.activeWhen === void 0 ? {} : { activeWhen: source.activeWhen },
94260
- members: source.reads.map((item) => aggregateRead(read(item))),
94261
- publish: source.publish,
94262
- empty: source.empty
94263
- });
94264
- if (outcome.kind === "value") return {
94265
- state: "fresh",
94266
- value: outcome.value,
94267
- reason: null,
94268
- deadline: null
94269
- };
94270
- return {
94271
- state: "unavailable",
94272
- value: null,
94273
- reason: outcome.reason,
94274
- fatal: outcome.fatal,
94275
- confirmed: true
94276
- };
94277
- }
94278
- function evaluateCompositionField(input) {
94279
- const { source } = input;
94280
- switch (source.kind) {
94281
- case "from": return fromReading(input.read(source), source);
94282
- case "expression": return expressionOutcome(source, input.read, input.now, input.stateful);
94283
- case "aggregate": return aggregateField(source, input.read);
94284
- case "series": return {
94285
- state: "unavailable",
94286
- value: null,
94287
- reason: "a series field is written from device history",
94288
- fatal: false,
94289
- confirmed: false
94290
- };
94291
- case "code": return {
94292
- state: "unavailable",
94293
- value: null,
94294
- reason: "code fields are not runnable in the composer — they arrive in slice 4",
94295
- fatal: true,
94296
- confirmed: true
94297
- };
94298
- }
94299
- }
94300
- function lockDoorLinkOfComposition(composition) {
94301
- if (composition === null || composition.target.kind !== "existing") return null;
94302
- const feature = composition.features.find((f) => f.cap === "lock-control");
94303
- if (feature === void 0 || feature.kind !== "fields") return null;
94304
- const state = feature.fields["state"];
94305
- if (state === void 0 || state.kind !== "expression") return null;
94306
- const x = state.bindings["x"];
94307
- if (x === void 0 || x.kind !== "from") return null;
94308
- return {
94309
- lock: composition.target.device,
94310
- sensor: x.source
94311
- };
94312
- }
94313
- /**
94314
- * Which smart switch powers a device (the `power-source` Customize extension):
94315
- * the source its stored `power-source.switchOn` field reads, and the off time of
94316
- * a forced restart stored beside it. Read from the STORED composition, never kept
94317
- * as a second copy (D676). Shared by the hub (which acts on the switch) and the
94318
- * admin UI (which shows it).
94319
- */
94320
- /**
94321
- * The stored off time, or the default when none is stored. A stored number out
94322
- * of range is CLAMPED to the bounds (a hand-written value never refuses the
94323
- * link, it just cannot cut power for an absurd time); a non-integer is rounded.
94324
- */
94325
- function normalizeOffSeconds(value) {
94326
- if (typeof value !== "number" || !Number.isFinite(value)) return 10;
94327
- return Math.min(120, Math.max(3, Math.round(value)));
94328
- }
94329
- /** The constant a stored `offSeconds` field carries, or undefined when it is not a literal number. */
94330
- function storedOffSeconds(composition) {
94331
- const feature = composition.features.find((f) => f.cap === "power-source");
94332
- if (feature === void 0 || feature.kind !== "fields") return void 0;
94333
- const field = feature.fields["offSeconds"];
94334
- if (field === void 0 || field.kind !== "expression") return void 0;
94335
- const n = Number(field.expr);
94336
- return field.expr.trim() === "" || !Number.isFinite(n) ? void 0 : n;
94337
- }
94338
- /**
94339
- * The link a composition stores. An `existing` target names its own device; a
94340
- * `new` target (a composed device) is the composer's own device, so the caller
94341
- * passes the block id and a new-target composition without one has no link.
94342
- */
94343
- function powerSourceLinkOfComposition(composition, blockId) {
94344
- if (composition === null) return null;
94345
- let device;
94346
- if (composition.target.kind === "existing") device = composition.target.device;
94347
- else if (blockId !== void 0) device = composedDeviceRef(blockId);
94348
- else return null;
94349
- const feature = composition.features.find((f) => f.cap === "power-source");
94350
- if (feature === void 0 || feature.kind !== "fields" || feature.enabled === false) return null;
94351
- const field = feature.fields["switchOn"];
94352
- if (field === void 0) return null;
94353
- const read = fieldReads(field).find((r) => r.cap === "switch");
94354
- if (read === void 0) return null;
94355
- return {
94356
- device,
94357
- switch: read.source,
94358
- offSeconds: normalizeOffSeconds(storedOffSeconds(composition))
94359
- };
94360
- }
94361
- SOURCE_CAPS.filter((cap) => cap !== "switch" && cap !== "motion");
94362
94209
  function fromRead(source, cap, fieldPath) {
94363
94210
  return {
94364
94211
  kind: "from",
@@ -94377,17 +94224,16 @@ function expression(expr, bindings) {
94377
94224
  function literal(expr) {
94378
94225
  return expression(expr, {});
94379
94226
  }
94380
- String.raw`rose\(active(\d+), changed(\d+), (\d+(?:\.\d+)?)\)`;
94381
- var catalog$4 = CAP_CUSTOMIZE_CATALOG;
94227
+ var catalog$5 = CAP_CUSTOMIZE_CATALOG;
94382
94228
  function compileScalarOverride(input) {
94383
- const target = catalogTarget$3(input.draft.cap, input.draft.targetId);
94384
- if (target === null || target.cardinality !== "scalar" || target.path === void 0) return fail$1("target");
94385
- 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");
94386
94232
  const source = sourceSpec$1(target, input.sourceValueKind, input.draft.source.cap);
94387
- if (source === null) return fail$1("source-kind");
94388
- 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");
94389
94235
  const allowed = input.draft.transform.kind === "number" ? "identity" : input.draft.transform.kind;
94390
- if (!source.transformKinds.includes(allowed)) return fail$1("transform");
94236
+ if (!source.transformKinds.includes(allowed)) return fail$2("transform");
94391
94237
  if (target.override !== void 0) return compileOverride(input, target.path, target.override);
94392
94238
  const value = compileValue$1(input);
94393
94239
  if (!value.ok) return value;
@@ -94408,7 +94254,7 @@ function compileScalarOverride(input) {
94408
94254
  * companion — the native slice keeps its own clock.
94409
94255
  */
94410
94256
  function compileOverride(input, path, rule) {
94411
- 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");
94412
94258
  const read = fromRead(refOf$1(input.draft), input.draft.source.cap, input.draft.source.fieldPath);
94413
94259
  const field = expression(overrideExpr(rule.whenSourceTrue, rule.unlessNative), {
94414
94260
  x: read,
@@ -94423,14 +94269,14 @@ function compileOverride(input, path, rule) {
94423
94269
  }
94424
94270
  };
94425
94271
  }
94426
- function fail$1(reason) {
94272
+ function fail$2(reason) {
94427
94273
  return {
94428
94274
  ok: false,
94429
94275
  reason
94430
94276
  };
94431
94277
  }
94432
- function catalogTarget$3(cap, targetId) {
94433
- const entry = catalog$4[cap];
94278
+ function catalogTarget$4(cap, targetId) {
94279
+ const entry = catalog$5[cap];
94434
94280
  if (entry === void 0) return null;
94435
94281
  return entry.targets.find((target) => target.id === targetId) ?? null;
94436
94282
  }
@@ -94451,7 +94297,7 @@ function compileValue$1(input) {
94451
94297
  value: identityValue(read, input.sourceValueKind)
94452
94298
  };
94453
94299
  if (transform.kind === "invert") {
94454
- if (input.sourceValueKind !== "boolean") return fail$1("source-kind");
94300
+ if (input.sourceValueKind !== "boolean") return fail$2("source-kind");
94455
94301
  return {
94456
94302
  ok: true,
94457
94303
  value: expression("!x", { x: read })
@@ -94459,7 +94305,7 @@ function compileValue$1(input) {
94459
94305
  }
94460
94306
  if (transform.kind === "threshold") return thresholdValue(transform, read, transform.minSamples ?? evidenceSamples(input));
94461
94307
  if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
94462
- return fail$1("transform");
94308
+ return fail$2("transform");
94463
94309
  }
94464
94310
  function identityValue(read, valueKind) {
94465
94311
  if (valueKind === "string") return expression("number(x)", { x: read });
@@ -94481,10 +94327,10 @@ function defaultThresholdSamples(cap, targetId, sourceCap) {
94481
94327
  }
94482
94328
  function thresholdValue(transform, read, minSamples) {
94483
94329
  const threshold = unsignedToken(transform.threshold);
94484
- if (threshold === null) return fail$1("threshold");
94330
+ if (threshold === null) return fail$2("threshold");
94485
94331
  const start = unsignedToken(transform.startDwellMs);
94486
94332
  const stop = unsignedToken(transform.stopDwellMs);
94487
- if (start === null || stop === null) return fail$1("dwell");
94333
+ if (start === null || stop === null) return fail$2("dwell");
94488
94334
  return {
94489
94335
  ok: true,
94490
94336
  value: expression(dwellExpr(transform.comparison, threshold, start, stop, minSamples), { x: read })
@@ -94493,7 +94339,7 @@ function thresholdValue(transform, read, minSamples) {
94493
94339
  function linearValue$1(transform, read, valueKind) {
94494
94340
  const scale = signedToken(transform.scale);
94495
94341
  const offset = signedToken(transform.offset);
94496
- if (scale === null || offset === null) return fail$1("scale");
94342
+ if (scale === null || offset === null) return fail$2("scale");
94497
94343
  const clamps = clampTokens$1(transform.clampMin, transform.clampMax);
94498
94344
  if (!clamps.ok) return clamps;
94499
94345
  return {
@@ -94509,10 +94355,10 @@ function clampTokens$1(clampMin, clampMax) {
94509
94355
  max: null
94510
94356
  }
94511
94357
  };
94512
- if (clampMin === void 0 || clampMax === void 0) return fail$1("clamp");
94358
+ if (clampMin === void 0 || clampMax === void 0) return fail$2("clamp");
94513
94359
  const min = signedToken(clampMin);
94514
94360
  const max = signedToken(clampMax);
94515
- if (min === null || max === null || clampMin > clampMax) return fail$1("clamp");
94361
+ if (min === null || max === null || clampMin > clampMax) return fail$2("clamp");
94516
94362
  return {
94517
94363
  ok: true,
94518
94364
  value: {
@@ -94522,7 +94368,7 @@ function clampTokens$1(clampMin, clampMax) {
94522
94368
  };
94523
94369
  }
94524
94370
  function compileCompanions$1(input, target, value) {
94525
- if (target.path === void 0) return fail$1("target");
94371
+ if (target.path === void 0) return fail$2("target");
94526
94372
  const path = target.path;
94527
94373
  return (target.companions ?? []).filter((companion) => companionIncluded$1(companion, input.apply)).reduce((acc, companion) => {
94528
94374
  if (!acc.ok) return acc;
@@ -94550,7 +94396,7 @@ function companionIncluded$1(companion, apply) {
94550
94396
  function companionField(input, path, companion, value) {
94551
94397
  if (companion.kind === "constant") {
94552
94398
  const expr = constantExpr(companion.value);
94553
- if (expr === null) return fail$1("scale");
94399
+ if (expr === null) return fail$2("scale");
94554
94400
  return {
94555
94401
  ok: true,
94556
94402
  value: literal(expr)
@@ -94568,7 +94414,7 @@ function transitionField(input, path, sourceChangedAt, value) {
94568
94414
  value: fromRead(refOf$1(input.draft), input.draft.source.cap, input.changedAtField)
94569
94415
  };
94570
94416
  if (input.apply === "replace") return stampOfValue(value);
94571
- if (!isIdentifier(path)) return fail$1("transform");
94417
+ if (!isIdentifier(path)) return fail$2("transform");
94572
94418
  const bindings = { [path]: fromRead(input.device, input.draft.cap, path) };
94573
94419
  return {
94574
94420
  ok: true,
@@ -94584,7 +94430,7 @@ function stampOfValue(value) {
94584
94430
  ok: true,
94585
94431
  value: expression("latchedAt(x)", { x: value })
94586
94432
  };
94587
- return fail$1("transform");
94433
+ return fail$2("transform");
94588
94434
  }
94589
94435
  function refOf$1(draft) {
94590
94436
  return {
@@ -94592,6 +94438,340 @@ function refOf$1(draft) {
94592
94438
  stableId: draft.source.stableId
94593
94439
  };
94594
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+)?)\)`;
94595
94775
  DeviceRole.BinarySensor, DeviceRole.MotionSensor;
94596
94776
  new Set(CAP_NAMES);
94597
94777
  function isUnfilledRequiredProblem(problem) {
@@ -96409,6 +96589,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
96409
96589
  access: "view",
96410
96590
  role: "admin"
96411
96591
  },
96592
+ "addonSettings.listScopedSettings": {
96593
+ capName: "addon-settings",
96594
+ capScope: "system",
96595
+ addonId: null,
96596
+ access: "view",
96597
+ role: "admin"
96598
+ },
96412
96599
  "addonSettings.readScopedValues": {
96413
96600
  capName: "addon-settings",
96414
96601
  capScope: "system",
@@ -105390,6 +105577,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
105390
105577
  access: "create",
105391
105578
  role: "viewer"
105392
105579
  },
105580
+ "timedRun.getOptions": {
105581
+ capName: "timed-run",
105582
+ capScope: "device",
105583
+ addonId: null,
105584
+ access: "view",
105585
+ role: "viewer"
105586
+ },
105393
105587
  "timedRun.getStatus": {
105394
105588
  capName: "timed-run",
105395
105589
  capScope: "device",
@@ -105404,6 +105598,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
105404
105598
  access: "create",
105405
105599
  role: "viewer"
105406
105600
  },
105601
+ "timedRun.setSettings": {
105602
+ capName: "timed-run",
105603
+ capScope: "device",
105604
+ addonId: null,
105605
+ access: "create",
105606
+ role: "admin"
105607
+ },
105407
105608
  "toast.onToast": {
105408
105609
  capName: "toast",
105409
105610
  capScope: "system",
@@ -109171,6 +109372,11 @@ Object.freeze({
109171
109372
  form: "single",
109172
109373
  optional: false
109173
109374
  }],
109375
+ "timedRun.getOptions": [{
109376
+ name: "deviceId",
109377
+ form: "single",
109378
+ optional: false
109379
+ }],
109174
109380
  "timedRun.getStatus": [{
109175
109381
  name: "deviceId",
109176
109382
  form: "single",
@@ -109181,6 +109387,11 @@ Object.freeze({
109181
109387
  form: "single",
109182
109388
  optional: false
109183
109389
  }],
109390
+ "timedRun.setSettings": [{
109391
+ name: "deviceId",
109392
+ form: "single",
109393
+ optional: false
109394
+ }],
109184
109395
  "update.getStatus": [{
109185
109396
  name: "deviceId",
109186
109397
  form: "single",
@@ -110433,6 +110644,7 @@ var STATE_SUMMARY_VARS = [
110433
110644
  [...RULE_TEXT],
110434
110645
  [...RULE_TEXT],
110435
110646
  [...RULE_TEXT],
110647
+ [...RULE_TEXT],
110436
110648
  [...RULE_BODY_ONLY],
110437
110649
  [...RULE_TEXT],
110438
110650
  ([...RULE_TEXT], [...DEVICE_EVENTS]),
@@ -114222,6 +114434,18 @@ Object.defineProperty(exports, "timedRunLimitOf", {
114222
114434
  return timedRunLimitOf;
114223
114435
  }
114224
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
+ });
114225
114449
  Object.defineProperty(exports, "timedRunSeconds", {
114226
114450
  enumerable: true,
114227
114451
  get: function() {
@@ -114330,6 +114554,12 @@ Object.defineProperty(exports, "weekdayOfLocalDate", {
114330
114554
  return weekdayOfLocalDate;
114331
114555
  }
114332
114556
  });
114557
+ Object.defineProperty(exports, "withDefaultRunning", {
114558
+ enumerable: true,
114559
+ get: function() {
114560
+ return withDefaultRunning;
114561
+ }
114562
+ });
114333
114563
  Object.defineProperty(exports, "withLocationMode", {
114334
114564
  enumerable: true,
114335
114565
  get: function() {