@camstack/server 1.2.784 → 1.2.785

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 (86) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +11 -14
  3. package/system/dist/{agent-https-BobAhSU6.js → agent-https-B7lqIrF1.js} +1 -1
  4. package/system/dist/{agent-https-Ds3-zbz-.mjs → agent-https-CACfLh65.mjs} +1 -1
  5. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/system/dist/builtins/autotrack/index.js +1 -1
  12. package/system/dist/builtins/autotrack/index.mjs +1 -1
  13. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  15. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  16. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  17. package/system/dist/builtins/camera-grid/index.js +1 -1
  18. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  19. package/system/dist/builtins/composer/composer.addon.js +9 -8
  20. package/system/dist/builtins/composer/composer.addon.mjs +9 -8
  21. package/system/dist/builtins/composer/composition-evaluation.d.ts +2 -2
  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 +3 -3
  25. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  26. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  27. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  28. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  29. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  30. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  31. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  32. package/system/dist/builtins/keychain/index.js +4 -4
  33. package/system/dist/builtins/keychain/index.mjs +4 -4
  34. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  35. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  36. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  37. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  38. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  39. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  40. package/system/dist/builtins/loki-logging/index.js +1 -1
  41. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  42. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  43. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  44. package/system/dist/builtins/platform-probe/index.js +1 -1
  45. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  46. package/system/dist/builtins/record-entries/index.js +1 -1
  47. package/system/dist/builtins/record-entries/index.mjs +1 -1
  48. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  49. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  50. package/system/dist/builtins/snapshot/index.js +1 -1
  51. package/system/dist/builtins/snapshot/index.mjs +1 -1
  52. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  53. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  54. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  55. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  56. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  57. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  58. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  59. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  60. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  61. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  62. package/system/dist/builtins/winston-logging/index.js +1 -1
  63. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  64. package/system/dist/{capture-engine-7_Barr9F.mjs → capture-engine-Dw82x5UW.mjs} +1 -1
  65. package/system/dist/{capture-engine-cNrHuwWH.js → capture-engine-n5mJUHzf.js} +1 -1
  66. package/system/dist/{composition-sources-7wEQtB6b.js → composition-sources-Cdow6PNn.js} +1 -1
  67. package/system/dist/{composition-sources-QUbTSbQL.mjs → composition-sources-D-bbLadz.mjs} +1 -1
  68. package/system/dist/{constants-BmX7aeHq.mjs → constants-C6UsfDdP.mjs} +1 -1
  69. package/system/dist/{constants-_Zq5aGIs.js → constants-Dmc-T4Zw.js} +1 -1
  70. package/system/dist/{device-ca-DqNfUZx4.mjs → device-ca-OQqtK7Yy.mjs} +1 -1
  71. package/system/dist/{device-ca-D9nNDHW_.js → device-ca-v8lGdWVk.js} +1 -1
  72. package/system/dist/{dist-CA672buZ.js → dist-1X5ccoX2.js} +70 -22
  73. package/system/dist/{dist-W0Eyg7Fm.mjs → dist-CRWinpyX.mjs} +70 -22
  74. package/system/dist/file-host-worker.js +1 -1
  75. package/system/dist/file-host-worker.mjs +1 -1
  76. package/system/dist/{hub-mdns-ciao-VOfs7CqC.mjs → hub-mdns-ciao-BQqm5eSM.mjs} +2 -2
  77. package/system/dist/{hub-mdns-ciao-DYD3STlf.js → hub-mdns-ciao-hBZgojNT.js} +2 -2
  78. package/system/dist/index.js +8 -8
  79. package/system/dist/index.mjs +8 -8
  80. package/system/dist/{legacy-integration-rows-door-CF_0_-U9.mjs → legacy-integration-rows-door-B7bwfRev.mjs} +1 -1
  81. package/system/dist/{legacy-integration-rows-door-BzVepX_e.js → legacy-integration-rows-door-BUjw8YoW.js} +1 -1
  82. package/system/dist/{restore-archive-BCXQaw89.js → restore-archive-D9vM-Kzb.js} +1 -1
  83. package/system/dist/{restore-archive-B2l00XlI.mjs → restore-archive-TST7tvBk.mjs} +82 -82
  84. package/system/dist/{wal-maintenance-bvjbNKbx.mjs → wal-maintenance-C7dJSaPS.mjs} +0 -0
  85. package/system/dist/{wal-maintenance-Z4MNv6Vn.js → wal-maintenance-wfVwXxO4.js} +0 -0
  86. package/system/package.json +1 -1
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CA672buZ.js");
6
+ const require_dist = require("../../dist-1X5ccoX2.js");
7
7
  const require_formatter = require("../../formatter-xbxeV4GD.js");
8
8
  const require_log_file_read_protocol = require("../../log-file-read-protocol-DSV_vQRb.js");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Ao as BaseAddon, si as logDestinationCapability } from "../../dist-W0Eyg7Fm.mjs";
1
+ import { Ao as BaseAddon, si as logDestinationCapability } from "../../dist-CRWinpyX.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-DkYZ4LXp.mjs";
3
3
  import { a as LogFileIndexStore, i as serveRead, n as isFromReader, t as CancelBook } from "../../log-file-read-protocol-hTaAsYlX.mjs";
4
4
  import { createRequire } from "node:module";
@@ -1,4 +1,4 @@
1
- import { hc as DeviceType, js as historyItemFieldPath, zo as HISTORY_DEFAULT_MIN_INTERVAL_MS } from "./dist-W0Eyg7Fm.mjs";
1
+ import { hc as DeviceType, js as historyItemFieldPath, zo as HISTORY_DEFAULT_MIN_INTERVAL_MS } from "./dist-CRWinpyX.mjs";
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CA672buZ.js");
1
+ const require_dist = require("./dist-1X5ccoX2.js");
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CA672buZ.js");
1
+ const require_dist = require("./dist-1X5ccoX2.js");
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { fo as compositionSourceKey, gc as errMsg } from "./dist-W0Eyg7Fm.mjs";
1
+ import { fo as compositionSourceKey, gc as errMsg } from "./dist-CRWinpyX.mjs";
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { hs as buildSecretRef } from "./dist-W0Eyg7Fm.mjs";
1
+ import { hs as buildSecretRef } from "./dist-CRWinpyX.mjs";
2
2
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
3
3
  var MESH_CA_KEY_REF = buildSecretRef({
4
4
  owner: "system",
@@ -1,5 +1,5 @@
1
1
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
2
- var MESH_CA_KEY_REF = require("./dist-CA672buZ.js").buildSecretRef({
2
+ var MESH_CA_KEY_REF = require("./dist-1X5ccoX2.js").buildSecretRef({
3
3
  owner: "system",
4
4
  scope: { kind: "global" },
5
5
  fieldPath: "meshCaKey"
@@ -1,4 +1,4 @@
1
- import { H as DEVICE_SAN_CREDENTIAL_PREFIX, U as DEVICE_SAN_USER_PREFIX, hs as buildSecretRef } from "./dist-W0Eyg7Fm.mjs";
1
+ import { H as DEVICE_SAN_CREDENTIAL_PREFIX, U as DEVICE_SAN_USER_PREFIX, hs as buildSecretRef } from "./dist-CRWinpyX.mjs";
2
2
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, a as KeyUsageFlags, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension } from "./x509.es-BRiJgOvu.mjs";
3
3
  import { X509Certificate, createPublicKey, randomBytes, verify, webcrypto } from "node:crypto";
4
4
  //#region src/auth/jwt-signing-key.ts
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CA672buZ.js");
1
+ const require_dist = require("./dist-1X5ccoX2.js");
2
2
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
3
3
  let node_crypto = require("node:crypto");
4
4
  //#region src/auth/jwt-signing-key.ts
@@ -8375,7 +8375,7 @@ function sleep(ms) {
8375
8375
  return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
8376
8376
  }
8377
8377
  //#endregion
8378
- //#region ../types/dist/composition-pOHbTzRB.mjs
8378
+ //#region ../types/dist/composition-BmBHuDTQ.mjs
8379
8379
  var AUDIO_ENCODER_BY_CODEC = {
8380
8380
  opus: "libopus",
8381
8381
  aac: "aac",
@@ -9004,34 +9004,62 @@ function asNonNegativeMs(value, name, index) {
9004
9004
  return ms;
9005
9005
  }
9006
9006
  /**
9007
- * `dwell(active, onForMs, offForMs)`: unknown until a delay elapses, then holds
9007
+ * `dwell(active, onForMs, offForMs[, minSamples])`: unknown until a delay elapses, then holds
9008
9008
  * the latched boolean through gaps shorter than the opposing delay (D933). A new
9009
9009
  * call state seeded with the restored output starts latched on it, so it is never
9010
9010
  * unknown after a boot.
9011
- */
9012
- function evaluateDwell(activeRaw, onForMsRaw, offForMsRaw, call, nowMs, hooks) {
9011
+ *
9012
+ * With `minSamples` above 1 (opt-in; default 1 = time only, as a single-event
9013
+ * binary sensor needs) a flip to ON needs EVIDENCE, not only time: at least that
9014
+ * many input samples that satisfy the condition (the one that opened the pending transition and later
9015
+ * ones, all from source readings), so a deadline timer firing over one held
9016
+ * value never starts a run. A standby plug reports one 5-9 W sample and then
9017
+ * stays silent; the held value used to confirm a start 30 s later. A flip to OFF
9018
+ * is deliberately NOT symmetric: a quiet sensor is how a finished run looks (the
9019
+ * plug reports the drop once and goes silent), so the held "off" value must still
9020
+ * confirm after `offForMs`. A zero ON delay asks for no persistence, so one
9021
+ * sample is enough.
9022
+ */
9023
+ function evaluateDwell(activeRaw, onForMsRaw, offForMsRaw, minSamplesRaw, call, nowMs, hooks) {
9013
9024
  const active = asBoolean(activeRaw, "dwell", 0);
9014
9025
  const onForMs = asNonNegativeMs(onForMsRaw, "dwell", 1);
9015
9026
  const offForMs = asNonNegativeMs(offForMsRaw, "dwell", 2);
9027
+ const minSamples = minSamplesRaw === void 0 ? 1 : asMinSamples(minSamplesRaw);
9016
9028
  call.transition = null;
9017
9029
  if (call.latched === null) {
9018
- if (call.seenSince === null) call.seenSince = nowMs;
9030
+ if (call.seenSince === null) {
9031
+ call.seenSince = nowMs;
9032
+ call.pendingSamples = 0;
9033
+ }
9034
+ if (hooks?.timerDriven !== true) call.pendingSamples += 1;
9019
9035
  const delay = active ? onForMs : offForMs;
9020
- if (nowMs - call.seenSince >= delay) {
9036
+ const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
9037
+ if (nowMs - call.seenSince >= delay && sustained) {
9021
9038
  call.latched = active;
9039
+ call.pendingSamples = 0;
9022
9040
  return call.latched;
9023
9041
  }
9024
- hooks?.noteDeadline?.(call.seenSince + delay);
9042
+ if (nowMs - call.seenSince < delay) hooks?.noteDeadline?.(call.seenSince + delay);
9025
9043
  return null;
9026
9044
  }
9027
9045
  if (active === call.latched) return holdAgainstReturn(call, active, onForMs, nowMs, hooks);
9028
9046
  call.returnSince = null;
9029
- if (call.pendingSince === null) call.pendingSince = nowMs;
9047
+ if (call.pendingSince === null) {
9048
+ call.pendingSince = nowMs;
9049
+ call.pendingSamples = 0;
9050
+ }
9051
+ if (hooks?.timerDriven !== true) call.pendingSamples += 1;
9030
9052
  const delay = active ? onForMs : offForMs;
9031
- if (nowMs - call.pendingSince >= delay) return flip(call, active, call.pendingSince);
9032
- hooks?.noteDeadline?.(call.pendingSince + delay);
9053
+ const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
9054
+ if (nowMs - call.pendingSince >= delay && sustained) return flip(call, active, call.pendingSince);
9055
+ if (nowMs - call.pendingSince < delay) hooks?.noteDeadline?.(call.pendingSince + delay);
9033
9056
  return call.latched;
9034
9057
  }
9058
+ function asMinSamples(value) {
9059
+ const n = asFiniteNumber(value, "dwell", 3);
9060
+ if (!Number.isInteger(n) || n < 1) throw new ExpressionEvalError("dwell: minSamples must be a whole number of at least 1");
9061
+ return n;
9062
+ }
9035
9063
  function flip(call, to, startedAt) {
9036
9064
  const transition = {
9037
9065
  value: to,
@@ -9039,6 +9067,7 @@ function flip(call, to, startedAt) {
9039
9067
  };
9040
9068
  call.latched = to;
9041
9069
  call.pendingSince = null;
9070
+ call.pendingSamples = 0;
9042
9071
  call.returnSince = null;
9043
9072
  call.transition = transition;
9044
9073
  return to;
@@ -9291,7 +9320,7 @@ var table = {
9291
9320
  },
9292
9321
  dwell: {
9293
9322
  minArgs: 3,
9294
- maxArgs: 3,
9323
+ maxArgs: 4,
9295
9324
  apply: () => {
9296
9325
  throw new ExpressionEvalError("dwell: stateful evaluation context is required");
9297
9326
  }
@@ -9882,13 +9911,14 @@ function evaluateStatefulExpressionCall(invocation, memory, env, hooks) {
9882
9911
  const call = existing?.kind === "dwell" ? existing : {
9883
9912
  kind: "dwell",
9884
9913
  pendingSince: null,
9914
+ pendingSamples: 0,
9885
9915
  returnSince: null,
9886
9916
  transition: null,
9887
9917
  latched: typeof env.currentOutput === "boolean" ? env.currentOutput : null,
9888
9918
  seenSince: null
9889
9919
  };
9890
9920
  memory.calls.set(invocation.path, call);
9891
- const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], call, env.nowMs, hooks);
9921
+ const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], invocation.args[3], call, env.nowMs, hooks);
9892
9922
  memory.dwellTransition = call.transition;
9893
9923
  return dwelled;
9894
9924
  }
@@ -53617,8 +53647,8 @@ function overrideExpr(whenSourceTrue, unlessNative) {
53617
53647
  function isIdentifier(path) {
53618
53648
  return IDENT.test(path);
53619
53649
  }
53620
- function dwellExpr(comparison, threshold, start, stop) {
53621
- return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop})`;
53650
+ function dwellExpr(comparison, threshold, start, stop, minSamples = 1) {
53651
+ return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop}${minSamples > 1 ? `, ${minSamples}` : ""})`;
53622
53652
  }
53623
53653
  function linearExpr(inner, scale, offset, clampMin, clampMax) {
53624
53654
  const arithmetic = `${inner} * ${scale} + ${offset}`;
@@ -54636,7 +54666,9 @@ var ThresholdTransformDraftSchema = zod.z.object({
54636
54666
  comparison: zod.z.enum(["gte", "lte"]),
54637
54667
  threshold: zod.z.number(),
54638
54668
  startDwellMs: zod.z.number().nonnegative(),
54639
- stopDwellMs: zod.z.number().nonnegative()
54669
+ stopDwellMs: zod.z.number().nonnegative(),
54670
+ /** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
54671
+ minSamples: zod.z.number().int().min(1).optional()
54640
54672
  });
54641
54673
  var LinearTransformDraftSchema = zod.z.object({
54642
54674
  kind: zod.z.literal("linear"),
@@ -93504,6 +93536,7 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93504
93536
  const call = {
93505
93537
  kind: "dwell",
93506
93538
  pendingSince: null,
93539
+ pendingSamples: 0,
93507
93540
  returnSince: null,
93508
93541
  latched: null,
93509
93542
  seenSince: null,
@@ -93513,11 +93546,15 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93513
93546
  const hooks = { noteDeadline: (at) => {
93514
93547
  deadline = deadline === null ? at : Math.min(deadline, at);
93515
93548
  } };
93549
+ const timerHooks = {
93550
+ ...hooks,
93551
+ timerDriven: true
93552
+ };
93516
93553
  const intervals = [];
93517
93554
  let openAt = null;
93518
- const evaluate = (active, at) => {
93555
+ const evaluate = (active, at, timer) => {
93519
93556
  deadline = null;
93520
- const answer = evaluateDwell(active, startMs, stopMs, call, at, hooks);
93557
+ const answer = evaluateDwell(active, startMs, stopMs, 2, call, at, timer ? timerHooks : hooks);
93521
93558
  if (answer === true && openAt === null) openAt = at;
93522
93559
  if (answer !== true && openAt !== null) {
93523
93560
  intervals.push({
@@ -93529,9 +93566,9 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93529
93566
  };
93530
93567
  segments.forEach((segment, i) => {
93531
93568
  const active = segment.value >= threshold;
93532
- evaluate(active, segment.start);
93569
+ evaluate(active, segment.start, false);
93533
93570
  const next = segments[i + 1]?.start ?? to;
93534
- while (deadline !== null && deadline <= next) evaluate(active, deadline);
93571
+ while (deadline !== null && deadline <= next) evaluate(active, deadline, true);
93535
93572
  });
93536
93573
  if (openAt !== null) intervals.push({
93537
93574
  start: openAt,
@@ -93935,6 +93972,7 @@ function expressionOutcome(source, read, now, stateful) {
93935
93972
  const deadlines = [];
93936
93973
  const hooks = {
93937
93974
  noteDeadline: (at) => deadlines.push(at),
93975
+ ...stateful?.timerDriven === true ? { timerDriven: true } : {},
93938
93976
  convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
93939
93977
  };
93940
93978
  const result = evaluateExpressionSource(source.expr, values, now, {
@@ -94182,7 +94220,7 @@ function compileValue$1(input) {
94182
94220
  value: expression("!x", { x: read })
94183
94221
  };
94184
94222
  }
94185
- if (transform.kind === "threshold") return thresholdValue(transform, read);
94223
+ if (transform.kind === "threshold") return thresholdValue(transform, read, transform.minSamples ?? evidenceSamples(input));
94186
94224
  if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
94187
94225
  return fail$1("transform");
94188
94226
  }
@@ -94190,7 +94228,17 @@ function identityValue(read, valueKind) {
94190
94228
  if (valueKind === "string") return expression("number(x)", { x: read });
94191
94229
  return read;
94192
94230
  }
94193
- function thresholdValue(transform, read) {
94231
+ /**
94232
+ * Only a POWER reading that drives `running-state.running` asks for sample
94233
+ * evidence: a standby plug sends one blip and goes quiet, and the timer over
94234
+ * that held value must not start a run. Any other threshold (a temperature, a
94235
+ * level, a binary contact) confirms on time alone, as it always did.
94236
+ */
94237
+ function evidenceSamples(input) {
94238
+ const { cap, targetId, source } = input.draft;
94239
+ return cap === "running-state" && targetId === "running" && source.cap === "power-meter" ? 2 : 1;
94240
+ }
94241
+ function thresholdValue(transform, read, minSamples) {
94194
94242
  const threshold = unsignedToken(transform.threshold);
94195
94243
  if (threshold === null) return fail$1("threshold");
94196
94244
  const start = unsignedToken(transform.startDwellMs);
@@ -94198,7 +94246,7 @@ function thresholdValue(transform, read) {
94198
94246
  if (start === null || stop === null) return fail$1("dwell");
94199
94247
  return {
94200
94248
  ok: true,
94201
- value: expression(dwellExpr(transform.comparison, threshold, start, stop), { x: read })
94249
+ value: expression(dwellExpr(transform.comparison, threshold, start, stop, minSamples), { x: read })
94202
94250
  };
94203
94251
  }
94204
94252
  function linearValue$1(transform, read, valueKind) {
@@ -8375,7 +8375,7 @@ function sleep(ms) {
8375
8375
  return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
8376
8376
  }
8377
8377
  //#endregion
8378
- //#region ../types/dist/composition-pOHbTzRB.mjs
8378
+ //#region ../types/dist/composition-BmBHuDTQ.mjs
8379
8379
  var AUDIO_ENCODER_BY_CODEC = {
8380
8380
  opus: "libopus",
8381
8381
  aac: "aac",
@@ -9004,34 +9004,62 @@ function asNonNegativeMs(value, name, index) {
9004
9004
  return ms;
9005
9005
  }
9006
9006
  /**
9007
- * `dwell(active, onForMs, offForMs)`: unknown until a delay elapses, then holds
9007
+ * `dwell(active, onForMs, offForMs[, minSamples])`: unknown until a delay elapses, then holds
9008
9008
  * the latched boolean through gaps shorter than the opposing delay (D933). A new
9009
9009
  * call state seeded with the restored output starts latched on it, so it is never
9010
9010
  * unknown after a boot.
9011
- */
9012
- function evaluateDwell(activeRaw, onForMsRaw, offForMsRaw, call, nowMs, hooks) {
9011
+ *
9012
+ * With `minSamples` above 1 (opt-in; default 1 = time only, as a single-event
9013
+ * binary sensor needs) a flip to ON needs EVIDENCE, not only time: at least that
9014
+ * many input samples that satisfy the condition (the one that opened the pending transition and later
9015
+ * ones, all from source readings), so a deadline timer firing over one held
9016
+ * value never starts a run. A standby plug reports one 5-9 W sample and then
9017
+ * stays silent; the held value used to confirm a start 30 s later. A flip to OFF
9018
+ * is deliberately NOT symmetric: a quiet sensor is how a finished run looks (the
9019
+ * plug reports the drop once and goes silent), so the held "off" value must still
9020
+ * confirm after `offForMs`. A zero ON delay asks for no persistence, so one
9021
+ * sample is enough.
9022
+ */
9023
+ function evaluateDwell(activeRaw, onForMsRaw, offForMsRaw, minSamplesRaw, call, nowMs, hooks) {
9013
9024
  const active = asBoolean(activeRaw, "dwell", 0);
9014
9025
  const onForMs = asNonNegativeMs(onForMsRaw, "dwell", 1);
9015
9026
  const offForMs = asNonNegativeMs(offForMsRaw, "dwell", 2);
9027
+ const minSamples = minSamplesRaw === void 0 ? 1 : asMinSamples(minSamplesRaw);
9016
9028
  call.transition = null;
9017
9029
  if (call.latched === null) {
9018
- if (call.seenSince === null) call.seenSince = nowMs;
9030
+ if (call.seenSince === null) {
9031
+ call.seenSince = nowMs;
9032
+ call.pendingSamples = 0;
9033
+ }
9034
+ if (hooks?.timerDriven !== true) call.pendingSamples += 1;
9019
9035
  const delay = active ? onForMs : offForMs;
9020
- if (nowMs - call.seenSince >= delay) {
9036
+ const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
9037
+ if (nowMs - call.seenSince >= delay && sustained) {
9021
9038
  call.latched = active;
9039
+ call.pendingSamples = 0;
9022
9040
  return call.latched;
9023
9041
  }
9024
- hooks?.noteDeadline?.(call.seenSince + delay);
9042
+ if (nowMs - call.seenSince < delay) hooks?.noteDeadline?.(call.seenSince + delay);
9025
9043
  return null;
9026
9044
  }
9027
9045
  if (active === call.latched) return holdAgainstReturn(call, active, onForMs, nowMs, hooks);
9028
9046
  call.returnSince = null;
9029
- if (call.pendingSince === null) call.pendingSince = nowMs;
9047
+ if (call.pendingSince === null) {
9048
+ call.pendingSince = nowMs;
9049
+ call.pendingSamples = 0;
9050
+ }
9051
+ if (hooks?.timerDriven !== true) call.pendingSamples += 1;
9030
9052
  const delay = active ? onForMs : offForMs;
9031
- if (nowMs - call.pendingSince >= delay) return flip(call, active, call.pendingSince);
9032
- hooks?.noteDeadline?.(call.pendingSince + delay);
9053
+ const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
9054
+ if (nowMs - call.pendingSince >= delay && sustained) return flip(call, active, call.pendingSince);
9055
+ if (nowMs - call.pendingSince < delay) hooks?.noteDeadline?.(call.pendingSince + delay);
9033
9056
  return call.latched;
9034
9057
  }
9058
+ function asMinSamples(value) {
9059
+ const n = asFiniteNumber(value, "dwell", 3);
9060
+ if (!Number.isInteger(n) || n < 1) throw new ExpressionEvalError("dwell: minSamples must be a whole number of at least 1");
9061
+ return n;
9062
+ }
9035
9063
  function flip(call, to, startedAt) {
9036
9064
  const transition = {
9037
9065
  value: to,
@@ -9039,6 +9067,7 @@ function flip(call, to, startedAt) {
9039
9067
  };
9040
9068
  call.latched = to;
9041
9069
  call.pendingSince = null;
9070
+ call.pendingSamples = 0;
9042
9071
  call.returnSince = null;
9043
9072
  call.transition = transition;
9044
9073
  return to;
@@ -9291,7 +9320,7 @@ var table = {
9291
9320
  },
9292
9321
  dwell: {
9293
9322
  minArgs: 3,
9294
- maxArgs: 3,
9323
+ maxArgs: 4,
9295
9324
  apply: () => {
9296
9325
  throw new ExpressionEvalError("dwell: stateful evaluation context is required");
9297
9326
  }
@@ -9882,13 +9911,14 @@ function evaluateStatefulExpressionCall(invocation, memory, env, hooks) {
9882
9911
  const call = existing?.kind === "dwell" ? existing : {
9883
9912
  kind: "dwell",
9884
9913
  pendingSince: null,
9914
+ pendingSamples: 0,
9885
9915
  returnSince: null,
9886
9916
  transition: null,
9887
9917
  latched: typeof env.currentOutput === "boolean" ? env.currentOutput : null,
9888
9918
  seenSince: null
9889
9919
  };
9890
9920
  memory.calls.set(invocation.path, call);
9891
- const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], call, env.nowMs, hooks);
9921
+ const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], invocation.args[3], call, env.nowMs, hooks);
9892
9922
  memory.dwellTransition = call.transition;
9893
9923
  return dwelled;
9894
9924
  }
@@ -53617,8 +53647,8 @@ function overrideExpr(whenSourceTrue, unlessNative) {
53617
53647
  function isIdentifier(path) {
53618
53648
  return IDENT.test(path);
53619
53649
  }
53620
- function dwellExpr(comparison, threshold, start, stop) {
53621
- return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop})`;
53650
+ function dwellExpr(comparison, threshold, start, stop, minSamples = 1) {
53651
+ return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop}${minSamples > 1 ? `, ${minSamples}` : ""})`;
53622
53652
  }
53623
53653
  function linearExpr(inner, scale, offset, clampMin, clampMax) {
53624
53654
  const arithmetic = `${inner} * ${scale} + ${offset}`;
@@ -54636,7 +54666,9 @@ var ThresholdTransformDraftSchema = z.object({
54636
54666
  comparison: z.enum(["gte", "lte"]),
54637
54667
  threshold: z.number(),
54638
54668
  startDwellMs: z.number().nonnegative(),
54639
- stopDwellMs: z.number().nonnegative()
54669
+ stopDwellMs: z.number().nonnegative(),
54670
+ /** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
54671
+ minSamples: z.number().int().min(1).optional()
54640
54672
  });
54641
54673
  var LinearTransformDraftSchema = z.object({
54642
54674
  kind: z.literal("linear"),
@@ -93504,6 +93536,7 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93504
93536
  const call = {
93505
93537
  kind: "dwell",
93506
93538
  pendingSince: null,
93539
+ pendingSamples: 0,
93507
93540
  returnSince: null,
93508
93541
  latched: null,
93509
93542
  seenSince: null,
@@ -93513,11 +93546,15 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93513
93546
  const hooks = { noteDeadline: (at) => {
93514
93547
  deadline = deadline === null ? at : Math.min(deadline, at);
93515
93548
  } };
93549
+ const timerHooks = {
93550
+ ...hooks,
93551
+ timerDriven: true
93552
+ };
93516
93553
  const intervals = [];
93517
93554
  let openAt = null;
93518
- const evaluate = (active, at) => {
93555
+ const evaluate = (active, at, timer) => {
93519
93556
  deadline = null;
93520
- const answer = evaluateDwell(active, startMs, stopMs, call, at, hooks);
93557
+ const answer = evaluateDwell(active, startMs, stopMs, 2, call, at, timer ? timerHooks : hooks);
93521
93558
  if (answer === true && openAt === null) openAt = at;
93522
93559
  if (answer !== true && openAt !== null) {
93523
93560
  intervals.push({
@@ -93529,9 +93566,9 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
93529
93566
  };
93530
93567
  segments.forEach((segment, i) => {
93531
93568
  const active = segment.value >= threshold;
93532
- evaluate(active, segment.start);
93569
+ evaluate(active, segment.start, false);
93533
93570
  const next = segments[i + 1]?.start ?? to;
93534
- while (deadline !== null && deadline <= next) evaluate(active, deadline);
93571
+ while (deadline !== null && deadline <= next) evaluate(active, deadline, true);
93535
93572
  });
93536
93573
  if (openAt !== null) intervals.push({
93537
93574
  start: openAt,
@@ -93935,6 +93972,7 @@ function expressionOutcome(source, read, now, stateful) {
93935
93972
  const deadlines = [];
93936
93973
  const hooks = {
93937
93974
  noteDeadline: (at) => deadlines.push(at),
93975
+ ...stateful?.timerDriven === true ? { timerDriven: true } : {},
93938
93976
  convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
93939
93977
  };
93940
93978
  const result = evaluateExpressionSource(source.expr, values, now, {
@@ -94182,7 +94220,7 @@ function compileValue$1(input) {
94182
94220
  value: expression("!x", { x: read })
94183
94221
  };
94184
94222
  }
94185
- if (transform.kind === "threshold") return thresholdValue(transform, read);
94223
+ if (transform.kind === "threshold") return thresholdValue(transform, read, transform.minSamples ?? evidenceSamples(input));
94186
94224
  if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
94187
94225
  return fail$1("transform");
94188
94226
  }
@@ -94190,7 +94228,17 @@ function identityValue(read, valueKind) {
94190
94228
  if (valueKind === "string") return expression("number(x)", { x: read });
94191
94229
  return read;
94192
94230
  }
94193
- function thresholdValue(transform, read) {
94231
+ /**
94232
+ * Only a POWER reading that drives `running-state.running` asks for sample
94233
+ * evidence: a standby plug sends one blip and goes quiet, and the timer over
94234
+ * that held value must not start a run. Any other threshold (a temperature, a
94235
+ * level, a binary contact) confirms on time alone, as it always did.
94236
+ */
94237
+ function evidenceSamples(input) {
94238
+ const { cap, targetId, source } = input.draft;
94239
+ return cap === "running-state" && targetId === "running" && source.cap === "power-meter" ? 2 : 1;
94240
+ }
94241
+ function thresholdValue(transform, read, minSamples) {
94194
94242
  const threshold = unsignedToken(transform.threshold);
94195
94243
  if (threshold === null) return fail$1("threshold");
94196
94244
  const start = unsignedToken(transform.startDwellMs);
@@ -94198,7 +94246,7 @@ function thresholdValue(transform, read) {
94198
94246
  if (start === null || stop === null) return fail$1("dwell");
94199
94247
  return {
94200
94248
  ok: true,
94201
- value: expression(dwellExpr(transform.comparison, threshold, start, stop), { x: read })
94249
+ value: expression(dwellExpr(transform.comparison, threshold, start, stop, minSamples), { x: read })
94202
94250
  };
94203
94251
  }
94204
94252
  function linearValue$1(transform, read, valueKind) {
@@ -1,5 +1,5 @@
1
1
  require("./chunk-Cek0wNdY.js");
2
- const require_wal_maintenance = require("./wal-maintenance-Z4MNv6Vn.js");
2
+ const require_wal_maintenance = require("./wal-maintenance-wfVwXxO4.js");
3
3
  let node_worker_threads = require("node:worker_threads");
4
4
  //#region src/builtins/sqlite-storage/file-host-worker.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-bvjbNKbx.mjs";
1
+ import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-C7dJSaPS.mjs";
2
2
  import { parentPort, threadId, workerData } from "node:worker_threads";
3
3
  //#region src/builtins/sqlite-storage/file-host-worker.ts
4
4
  /**
@@ -1,7 +1,7 @@
1
1
  import { o as __toESM } from "./chunk-CNf5ZN-e.mjs";
2
- import { dc as userError } from "./dist-W0Eyg7Fm.mjs";
2
+ import { dc as userError } from "./dist-CRWinpyX.mjs";
3
3
  import { f as X509Certificate$1 } from "./x509.es-BRiJgOvu.mjs";
4
- import { D as reasonRequiresNewCa, E as evaluateExistingCert, F as readNameConstraints, N as permitsIdentity, _ as issueLeaf, b as collectCertIdentity, g as generateCa, j as isConstrainedCa, v as loadCa, y as localCaCommonName } from "./agent-https-Ds3-zbz-.mjs";
4
+ import { D as reasonRequiresNewCa, E as evaluateExistingCert, F as readNameConstraints, N as permitsIdentity, _ as issueLeaf, b as collectCertIdentity, g as generateCa, j as isConstrainedCa, v as loadCa, y as localCaCommonName } from "./agent-https-CACfLh65.mjs";
5
5
  import { X509Certificate, createPrivateKey } from "node:crypto";
6
6
  import { writeOwnerOnlyFileSync } from "@camstack/types/node";
7
7
  import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-CA672buZ.js");
2
+ const require_dist = require("./dist-1X5ccoX2.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
- const require_agent_https = require("./agent-https-BobAhSU6.js");
4
+ const require_agent_https = require("./agent-https-B7lqIrF1.js");
5
5
  let node_crypto = require("node:crypto");
6
6
  let _camstack_types_node = require("@camstack/types/node");
7
7
  let node_fs = require("node:fs");
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-Cek0wNdY.js");
3
- const require_dist = require("./dist-CA672buZ.js");
4
- const require_device_ca = require("./device-ca-D9nNDHW_.js");
3
+ const require_dist = require("./dist-1X5ccoX2.js");
4
+ const require_device_ca = require("./device-ca-v8lGdWVk.js");
5
5
  const require_read_all_rows$1 = require("./read-all-rows-CVoO1ONM.js");
6
6
  const require_builtins_alerts_alerts_addon = require("./builtins/alerts/alerts.addon.js");
7
7
  require("./builtins/alerts/index.js");
@@ -26,22 +26,22 @@ const require_builtins_loki_logging_index = require("./builtins/loki-logging/ind
26
26
  const require_builtins_native_metrics_native_metrics_addon = require("./builtins/native-metrics/native-metrics.addon.js");
27
27
  const require_builtins_device_history_device_history_addon = require("./builtins/device-history/device-history.addon.js");
28
28
  const require_builtins_sqlite_storage_filesystem_storage_addon = require("./builtins/sqlite-storage/filesystem-storage.addon.js");
29
- const require_wal_maintenance = require("./wal-maintenance-Z4MNv6Vn.js");
30
- const require_legacy_integration_rows_door = require("./legacy-integration-rows-door-BzVepX_e.js");
29
+ const require_wal_maintenance = require("./wal-maintenance-wfVwXxO4.js");
30
+ const require_legacy_integration_rows_door = require("./legacy-integration-rows-door-BUjw8YoW.js");
31
31
  const require_builtins_sqlite_storage_sqlite_settings_addon = require("./builtins/sqlite-storage/sqlite-settings.addon.js");
32
32
  const require_builtins_sqlite_storage_index = require("./builtins/sqlite-storage/index.js");
33
33
  const require_builtins_storage_orchestrator_storage_orchestrator_addon = require("./builtins/storage-orchestrator/storage-orchestrator.addon.js");
34
34
  require("./builtins/storage-orchestrator/index.js");
35
- const require_agent_https = require("./agent-https-BobAhSU6.js");
36
- const require_constants = require("./constants-_Zq5aGIs.js");
35
+ const require_agent_https = require("./agent-https-B7lqIrF1.js");
36
+ const require_constants = require("./constants-Dmc-T4Zw.js");
37
37
  const require_builtins_system_config_system_config_addon = require("./builtins/system-config/system-config.addon.js");
38
38
  require("./builtins/system-config/index.js");
39
39
  const require_builtins_winston_logging_index = require("./builtins/winston-logging/index.js");
40
40
  const require_custom_action_registry = require("./custom-action-registry-CmWpSeMS.js");
41
- const require_hub_mdns_ciao = require("./hub-mdns-ciao-DYD3STlf.js");
41
+ const require_hub_mdns_ciao = require("./hub-mdns-ciao-hBZgojNT.js");
42
42
  const require_platform_key_source = require("./platform-key-source-Di7HrlGR.js");
43
43
  const require_resource_monitor = require("./resource-monitor-mio9dSCT.js");
44
- const require_restore_archive = require("./restore-archive-BCXQaw89.js");
44
+ const require_restore_archive = require("./restore-archive-D9vM-Kzb.js");
45
45
  const require_coral_accelerators = require("./coral-accelerators-BSVsBVzt.js");
46
46
  let zod = require("zod");
47
47
  let node_crypto = require("node:crypto");