@camstack/server 1.2.926 → 1.2.928

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 (96) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +10 -17
  3. package/system/dist/addon-utils.mjs +1 -1
  4. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  5. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  6. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  7. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  8. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  9. package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
  10. package/system/dist/builtins/autotrack/index.js +1 -1
  11. package/system/dist/builtins/autotrack/index.mjs +1 -1
  12. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  13. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  14. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  15. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  16. package/system/dist/builtins/camera-grid/index.js +1 -1
  17. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  18. package/system/dist/builtins/composer/composer.addon.js +4 -4
  19. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  20. package/system/dist/builtins/console-logging/index.js +1 -1
  21. package/system/dist/builtins/console-logging/index.mjs +1 -1
  22. package/system/dist/builtins/core-blocks/core-blocks.addon.js +4 -4
  23. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +4 -4
  24. package/system/dist/builtins/core-notifier/core-notifier.addon.js +1 -1
  25. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +1 -1
  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 +103 -55
  29. package/system/dist/builtins/device-manager/device-manager.addon.mjs +103 -55
  30. package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +24 -11
  31. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  32. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  33. package/system/dist/builtins/keychain/index.js +4 -4
  34. package/system/dist/builtins/keychain/index.mjs +4 -4
  35. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  36. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  37. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  38. package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  39. package/system/dist/builtins/local-network/local-network.addon.d.ts +13 -0
  40. package/system/dist/builtins/local-network/local-network.addon.js +47 -10
  41. package/system/dist/builtins/local-network/local-network.addon.mjs +47 -10
  42. package/system/dist/builtins/loki-logging/index.js +1 -1
  43. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  44. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  45. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  46. package/system/dist/builtins/platform-probe/index.js +1 -1
  47. package/system/dist/builtins/platform-probe/index.mjs +10 -10
  48. package/system/dist/builtins/record-entries/index.js +1 -1
  49. package/system/dist/builtins/record-entries/index.mjs +1 -1
  50. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  51. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  52. package/system/dist/builtins/snapshot/index.js +1 -1
  53. package/system/dist/builtins/snapshot/index.mjs +1 -1
  54. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  55. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  56. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  57. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  58. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  59. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  60. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  61. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  62. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  63. package/system/dist/builtins/system-config/system-config.addon.mjs +115 -115
  64. package/system/dist/builtins/winston-logging/index.js +1 -1
  65. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  66. package/system/dist/{capture-engine-BEXh051r.js → capture-engine-BcuwOSXv.js} +1 -1
  67. package/system/dist/{capture-engine-CWfylyT8.mjs → capture-engine-Bz7eXFjT.mjs} +1 -1
  68. package/system/dist/{composition-sources-CcpMUxus.mjs → composition-sources-BI614LJx.mjs} +1 -1
  69. package/system/dist/{composition-sources-B3_FuKde.js → composition-sources-v_kkb8A9.js} +1 -1
  70. package/system/dist/{constants-fPesBGmF.mjs → constants-BcUTQd1M.mjs} +1 -1
  71. package/system/dist/{constants-B0tqNa2l.js → constants-D2etJ02O.js} +1 -1
  72. package/system/dist/{coral-accelerators-DBlgWB8k.mjs → coral-accelerators-BW3OcrLD.mjs} +6 -6
  73. package/system/dist/{custom-action-registry-B9zFBNVa.mjs → custom-action-registry-N7flBDwT.mjs} +37 -37
  74. package/system/dist/{device-ca-Bh0GEstW.js → device-ca-CU8zh9Pi.js} +1 -1
  75. package/system/dist/{device-ca-B98SR8Xf.mjs → device-ca-ExMN3xW3.mjs} +1 -1
  76. package/system/dist/{device-row-store-CfWN8mLZ.js → device-row-store-BMIR-n3m.js} +1 -1
  77. package/system/dist/{device-row-store-BBByy029.mjs → device-row-store-CeW_GWh9.mjs} +1 -1
  78. package/system/dist/{dist-CH-iCceM.mjs → dist-BCHMSqzc.mjs} +325 -2
  79. package/system/dist/{dist-CVjsCA7D.js → dist-BZfvhfS1.js} +325 -2
  80. package/system/dist/file-host-worker.js +1 -1
  81. package/system/dist/file-host-worker.mjs +1 -1
  82. package/system/dist/{hub-identity-DCqJbSVn.mjs → hub-identity-CYC1820R.mjs} +10 -10
  83. package/system/dist/{hub-identity-BU4XzogT.js → hub-identity-Csxx2Q8k.js} +1 -1
  84. package/system/dist/{hub-mdns-ciao-BNzmwsIH.js → hub-mdns-ciao-By5577HM.js} +2 -2
  85. package/system/dist/{hub-mdns-ciao-IOM82NRd.mjs → hub-mdns-ciao-CCDxM5qz.mjs} +2 -2
  86. package/system/dist/index.js +8 -8
  87. package/system/dist/index.mjs +217 -217
  88. package/system/dist/{legacy-integration-rows-door-CRcvhOWb.js → legacy-integration-rows-door-CVwOo5aq.js} +1 -1
  89. package/system/dist/{legacy-integration-rows-door-nQzjUyPU.mjs → legacy-integration-rows-door-D9tQOUzh.mjs} +1 -1
  90. package/system/dist/{rename-composition-block-oOfXrUWs.js → rename-composition-block-C9HuBrKS.js} +1 -1
  91. package/system/dist/{rename-composition-block-CJ-C9HoY.mjs → rename-composition-block-DtaYmYAR.mjs} +1 -1
  92. package/system/dist/{restore-archive-DaYf1tQb.mjs → restore-archive-BJfyu0sG.mjs} +94 -94
  93. package/system/dist/{restore-archive-BSdudYif.js → restore-archive-CIFvqOze.js} +1 -1
  94. package/system/dist/{wal-maintenance-CyOVe3E1.mjs → wal-maintenance-CTrCPzds.mjs} +0 -0
  95. package/system/dist/{wal-maintenance-BRc_MNtZ.js → wal-maintenance-dq7T3quB.js} +0 -0
  96. package/system/package.json +1 -1
@@ -52196,6 +52196,53 @@ function anySubjectMatches(subjects, observed) {
52196
52196
  reason: subjects.length === 1 ? lastReason : `none of [${subjects.map(describeSubject).join(", ")}] matches (${observed.className || "unknown"})`
52197
52197
  };
52198
52198
  }
52199
+ var FaultCodesSchema = z.array(z.string().min(1)).max(64);
52200
+ function codeOf(entry) {
52201
+ if (entry === null || typeof entry !== "object") return void 0;
52202
+ const code = Reflect.get(entry, "code");
52203
+ return typeof code === "string" && code.length > 0 ? code : void 0;
52204
+ }
52205
+ /**
52206
+ * The fault reading off the three `error` fields. `undefined` is UNKNOWN:
52207
+ * `active` is `null`/absent (nothing read yet), which must never look like "no
52208
+ * fault".
52209
+ */
52210
+ function readFault(active, code, faults) {
52211
+ if (typeof active !== "boolean") return void 0;
52212
+ if (!active) return {
52213
+ active: false,
52214
+ codes: []
52215
+ };
52216
+ if (Array.isArray(faults)) {
52217
+ const codes = [];
52218
+ for (const entry of faults) {
52219
+ const c = codeOf(entry);
52220
+ if (c !== void 0) codes.push(c);
52221
+ }
52222
+ return {
52223
+ active: true,
52224
+ codes
52225
+ };
52226
+ }
52227
+ return {
52228
+ active: true,
52229
+ codes: typeof code === "string" && code.length > 0 ? [code] : []
52230
+ };
52231
+ }
52232
+ /** The active codes the leaf wants (all of them when it wants any). */
52233
+ function matchedFaultCodes(reading, wanted) {
52234
+ if (!reading.active) return [];
52235
+ return wanted.length === 0 ? reading.codes : reading.codes.filter((c) => wanted.includes(c));
52236
+ }
52237
+ /** Is a fault the leaf wants active? "Any fault" is satisfied by an active fault that names no code too. */
52238
+ function faultMatches(reading, wanted) {
52239
+ if (!reading.active) return false;
52240
+ return wanted.length === 0 || matchedFaultCodes(reading, wanted).length > 0;
52241
+ }
52242
+ /** "any fault" / `fault "a" or "b"`, for traces and logs. */
52243
+ function describeWantedFaults(wanted) {
52244
+ return wanted.length === 0 ? "any fault" : `fault ${wanted.map((c) => `"${c}"`).join(" or ")}`;
52245
+ }
52199
52246
  /**
52200
52247
  * Hold semantics — "for N seconds" on a leaf of the `when` tree (#498).
52201
52248
  *
@@ -52371,6 +52418,17 @@ var DeviceBecomesLeafSchema = z.object({
52371
52418
  path: ["value"]
52372
52419
  });
52373
52420
  });
52421
+ /**
52422
+ * A matching fault BECOMES active on a device (`device-fault.ts`): the device's
52423
+ * whole fault list is read, not only its principal code. `codes` empty = any
52424
+ * fault. Fires once per appearance; a fault already raised at start only seeds.
52425
+ */
52426
+ var DeviceFaultRaisedLeafSchema = z.object({
52427
+ kind: z.literal("device-fault-raised"),
52428
+ ...eventLeafId,
52429
+ deviceId: z.number().int().nonnegative(),
52430
+ codes: FaultCodesSchema
52431
+ });
52374
52432
  var DeviceEventLeafSchema = z.object({
52375
52433
  kind: z.literal("device-event"),
52376
52434
  ...eventLeafId,
@@ -52448,6 +52506,12 @@ var StationaryLeafSchema = z.object({
52448
52506
  /** `appeared`: it became parked. `departed`: the registry retired it. */
52449
52507
  phase: z.enum(["appeared", "departed"])
52450
52508
  });
52509
+ /** "has a fault": a matching fault is active on the device NOW (its whole fault list). `codes` empty = any. */
52510
+ var DeviceFaultIsLeafSchema = z.object({
52511
+ kind: z.literal("device-fault-is"),
52512
+ deviceId: z.number().int().nonnegative(),
52513
+ codes: FaultCodesSchema
52514
+ });
52451
52515
  /** "is": one device field compared to one value, NOW. */
52452
52516
  var DeviceIsLeafSchema = z.object({
52453
52517
  kind: z.literal("device-is"),
@@ -52570,12 +52634,14 @@ var AutomationWhenSchema = z.lazy(() => z.discriminatedUnion("kind", [
52570
52634
  DeviceBecomesLeafSchema,
52571
52635
  DeviceEventLeafSchema,
52572
52636
  DeviceFiredLeafSchema,
52637
+ DeviceFaultRaisedLeafSchema,
52573
52638
  ScheduleLeafSchema,
52574
52639
  ManualLeafSchema,
52575
52640
  IntervalLeafSchema,
52576
52641
  DetectionLeafSchema,
52577
52642
  StationaryLeafSchema,
52578
52643
  DeviceIsLeafSchema,
52644
+ DeviceFaultIsLeafSchema,
52579
52645
  StationaryPresentLeafSchema,
52580
52646
  ExpressionLeafSchema,
52581
52647
  TimeIsLeafSchema,
@@ -52585,6 +52651,7 @@ var EVENT_KINDS = new Set([
52585
52651
  "device-becomes",
52586
52652
  "device-event",
52587
52653
  "device-fired",
52654
+ "device-fault-raised",
52588
52655
  "schedule",
52589
52656
  "manual",
52590
52657
  "interval",
@@ -52684,6 +52751,7 @@ var LEAF_WORDS = {
52684
52751
  "device-becomes": "a device value that becomes",
52685
52752
  "device-event": "a device event",
52686
52753
  "device-fired": "a device firing an event",
52754
+ "device-fault-raised": "a device fault being raised",
52687
52755
  schedule: "a schedule",
52688
52756
  manual: "a manual run",
52689
52757
  interval: "an interval",
@@ -53177,6 +53245,86 @@ var AutomationNotifyStepSchema = z.object({
53177
53245
  body: z.string().min(1, "a notification needs a message").max(NOTIFY_BODY_MAX),
53178
53246
  ...continueOnErrorShape
53179
53247
  });
53248
+ var HTTP_URL_MAX = 2e3;
53249
+ var HTTP_BODY_MAX = 16384;
53250
+ var HTTP_HEADER_VALUE_MAX = 1e3;
53251
+ var saveAsSchema = z.string().regex(SET_VAR_NAME_RE, "a variable name is letters, digits and _, not starting with a digit (max 40)").refine((name) => !RESERVED_RUN_VARS.includes(name), { message: `the names ${RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be used` });
53252
+ var retryUntilSecondsSchema = z.number().int().min(1).max(600, `a retry window is at most 600 s`);
53253
+ /**
53254
+ * Whether a TCP port on a host answers. TCP only: an ICMP echo needs a raw
53255
+ * socket or a `ping` binary with extra privileges, and the hub image ships
53256
+ * neither for its non-root user, so it is not offered.
53257
+ *
53258
+ * Without `expect` the step wants the host REACHABLE. The result
53259
+ * (`{ reachable, rttMs, error }`) goes to the run variable `saveAs`.
53260
+ */
53261
+ var AutomationProbeStepSchema = z.object({
53262
+ kind: z.literal("probe"),
53263
+ ...stepEnabledShape,
53264
+ /** A host name or an address; may carry `{{vars.x}}` slots. */
53265
+ host: z.string().min(1, "a probe needs a host").max(253).regex(/^[^\s/]+$/, "a host has no spaces or slashes"),
53266
+ port: z.number().int().min(1, "a port is 1 to 65535").max(65535, "a port is 1 to 65535"),
53267
+ timeoutSeconds: z.number().int().min(1).max(30),
53268
+ expect: z.enum(["reachable", "unreachable"]).optional(),
53269
+ /** Keep probing every {@link REACH_RETRY_INTERVAL_S} s until the expectation holds, for this long. */
53270
+ retryUntilSeconds: retryUntilSecondsSchema.optional(),
53271
+ saveAs: saveAsSchema.optional(),
53272
+ ...continueOnErrorShape
53273
+ }).strict();
53274
+ var HTTP_METHODS = [
53275
+ "GET",
53276
+ "POST",
53277
+ "PUT",
53278
+ "PATCH",
53279
+ "DELETE"
53280
+ ];
53281
+ /**
53282
+ * What an HTTP request must answer for the step to pass: its status, or a field
53283
+ * of the parsed JSON body, compared the way a device field is.
53284
+ */
53285
+ var AutomationHttpExpectSchema = z.object({
53286
+ on: z.enum(["status", "json"]),
53287
+ /** A dotted path into the JSON body (`sysInfo.rawUartRemoteAddress`); needed for `json`. */
53288
+ fieldPath: z.string().min(1).max(200).optional(),
53289
+ operator: AutomationConditionOperatorSchema,
53290
+ value: z.union([
53291
+ z.string(),
53292
+ z.number(),
53293
+ z.boolean()
53294
+ ])
53295
+ }).strict().refine((expect) => expect.on !== "json" || expect.fieldPath !== void 0, {
53296
+ message: "a JSON expectation names the field it reads",
53297
+ path: ["fieldPath"]
53298
+ });
53299
+ function isHttpUrl(url) {
53300
+ if (url.includes("{{")) return /^https?:\/\/\S+$/i.test(url);
53301
+ try {
53302
+ const parsed = new URL(url);
53303
+ return parsed.protocol === "http:" || parsed.protocol === "https:";
53304
+ } catch {
53305
+ return false;
53306
+ }
53307
+ }
53308
+ /**
53309
+ * One HTTP request. Without `expect` the step wants a 2xx answer. The result
53310
+ * (`{ status, ok, json, text, error }`) goes to the run variable `saveAs`.
53311
+ * Header values are stored as typed, in plain text: they are in the recipe and
53312
+ * in the generated source, so anyone who can open the automation can read a
53313
+ * token put in one. Header values and bodies are never logged or traced.
53314
+ */
53315
+ var AutomationHttpRequestStepSchema = z.object({
53316
+ kind: z.literal("http-request"),
53317
+ ...stepEnabledShape,
53318
+ method: z.enum(HTTP_METHODS),
53319
+ url: z.string().max(HTTP_URL_MAX).refine(isHttpUrl, "the address is an http:// or https:// URL"),
53320
+ headers: z.record(z.string().regex(/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/, "not a valid header name"), z.string().max(HTTP_HEADER_VALUE_MAX)).refine((headers) => Object.keys(headers).length <= 20, { message: `at most 20 headers` }).optional(),
53321
+ body: z.string().max(HTTP_BODY_MAX).optional(),
53322
+ timeoutSeconds: z.number().int().min(1).max(60),
53323
+ expect: AutomationHttpExpectSchema.optional(),
53324
+ retryUntilSeconds: retryUntilSecondsSchema.optional(),
53325
+ saveAs: saveAsSchema.optional(),
53326
+ ...continueOnErrorShape
53327
+ }).strict();
53180
53328
  var AutomationRunActionStepSchema = z.object({
53181
53329
  kind: z.literal("action"),
53182
53330
  ...stepEnabledShape,
@@ -53232,7 +53380,9 @@ var plainStepSchemas = [
53232
53380
  AutomationStopStepSchema.omit({ if: true }).strict(),
53233
53381
  AutomationSetStepSchema.omit({ if: true }).strict(),
53234
53382
  AutomationRunActionStepSchema.strict(),
53235
- AutomationNotifyStepSchema.strict()
53383
+ AutomationNotifyStepSchema.strict(),
53384
+ AutomationProbeStepSchema,
53385
+ AutomationHttpRequestStepSchema
53236
53386
  ];
53237
53387
  /**
53238
53388
  * A plain step: a flow step with no condition of its own and no step inside
@@ -53335,6 +53485,8 @@ var AutomationActionSchema = z.discriminatedUnion("kind", [
53335
53485
  AutomationRepeatStepSchema,
53336
53486
  AutomationRunActionStepSchema,
53337
53487
  AutomationNotifyStepSchema,
53488
+ AutomationProbeStepSchema,
53489
+ AutomationHttpRequestStepSchema,
53338
53490
  z.object({
53339
53491
  kind: z.literal("code"),
53340
53492
  ...stepEnabledShape,
@@ -53410,6 +53562,8 @@ function stepGuardOf(action) {
53410
53562
  switch (action.kind) {
53411
53563
  case "action":
53412
53564
  case "notify":
53565
+ case "probe":
53566
+ case "http-request":
53413
53567
  case "code":
53414
53568
  case "choose":
53415
53569
  case "wait-until":
@@ -53849,6 +54003,7 @@ var AutomationConditionTraceNodeSchema = z.object({
53849
54003
  "not",
53850
54004
  "condition",
53851
54005
  "device-is",
54006
+ "device-fault-is",
53852
54007
  "expression",
53853
54008
  "stationary-present",
53854
54009
  "time-is",
@@ -53856,6 +54011,7 @@ var AutomationConditionTraceNodeSchema = z.object({
53856
54011
  "device-becomes",
53857
54012
  "device-event",
53858
54013
  "device-fired",
54014
+ "device-fault-raised",
53859
54015
  "schedule",
53860
54016
  "interval",
53861
54017
  "manual",
@@ -53914,6 +54070,9 @@ var StepTraceBaseSchema = z.object({
53914
54070
  * (D1021): why a sentence says "—" where a number was expected. Bounded.
53915
54071
  */
53916
54072
  templates: z.array(z.string()).max(20).optional(),
54073
+ /** A probe or an HTTP request: how many tries it made, and what the last one saw (no header, no body). */
54074
+ attempts: z.number().int().optional(),
54075
+ lastAttempt: z.string().optional(),
53917
54076
  /**
53918
54077
  * What the step's own `if` read when the step was reached (#472): `true` the
53919
54078
  * step ran, `false` its `else` ran (or nothing did), `unknown` a state leaf
@@ -54435,6 +54594,7 @@ async function runSteps(steps, options) {
54435
54594
  let emptyReason;
54436
54595
  let timedOutReason;
54437
54596
  let templateNotes = [];
54597
+ let attemptsSeen;
54438
54598
  const scope = {
54439
54599
  setDeviceId: (id) => {
54440
54600
  deviceId = id;
@@ -54460,8 +54620,18 @@ async function runSteps(steps, options) {
54460
54620
  },
54461
54621
  markTimedOut: (reason) => {
54462
54622
  timedOutReason = reason;
54623
+ },
54624
+ setAttempts: (count, last) => {
54625
+ attemptsSeen = {
54626
+ count,
54627
+ last
54628
+ };
54463
54629
  }
54464
54630
  };
54631
+ const attemptsTrace = () => attemptsSeen === void 0 ? {} : {
54632
+ attempts: attemptsSeen.count,
54633
+ lastAttempt: attemptsSeen.last.slice(0, 300)
54634
+ };
54465
54635
  const templatesTrace = () => templateNotes.length === 0 ? {} : { templates: [...templateNotes] };
54466
54636
  const argsTrace = () => sent === void 0 ? {} : { args: buildStepArgsTrace(sent) };
54467
54637
  const devicesTrace = () => perDevice.length === 0 ? {} : { devices: perDevice.slice(0, 200) };
@@ -54495,6 +54665,7 @@ async function runSteps(steps, options) {
54495
54665
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
54496
54666
  ...argsTrace(),
54497
54667
  ...templatesTrace(),
54668
+ ...attemptsTrace(),
54498
54669
  ...devicesTrace(),
54499
54670
  ...guardTrace,
54500
54671
  path,
@@ -54526,6 +54697,7 @@ async function runSteps(steps, options) {
54526
54697
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
54527
54698
  ...argsTrace(),
54528
54699
  ...templatesTrace(),
54700
+ ...attemptsTrace(),
54529
54701
  ...devicesTrace(),
54530
54702
  ...guardTrace,
54531
54703
  path,
@@ -54951,6 +55123,8 @@ function stableIdMapOf(devices) {
54951
55123
  }
54952
55124
  /** The cap whose runtime-state slice IS the occupancy snapshot, parked objects included. */
54953
55125
  var ZONE_ANALYTICS_CAP = "zone-analytics";
55126
+ /** The cap whose slice holds a device's faults. */
55127
+ var ERROR_CAP = "error";
54954
55128
  function collectInto(cond, out) {
54955
55129
  switch (cond.kind) {
54956
55130
  case "all":
@@ -54967,6 +55141,13 @@ function collectInto(cond, out) {
54967
55141
  cap: cond.cap
54968
55142
  });
54969
55143
  return;
55144
+ case "device-fault-is":
55145
+ out.push({
55146
+ kind: "device",
55147
+ deviceId: cond.deviceId,
55148
+ cap: ERROR_CAP
55149
+ });
55150
+ return;
54970
55151
  case "stationary-present":
54971
55152
  out.push({
54972
55153
  kind: "device",
@@ -55298,6 +55479,35 @@ function evalNode(cond, path, reader, now, out, state) {
55298
55479
  });
55299
55480
  return ok;
55300
55481
  }
55482
+ case "device-fault-is": {
55483
+ const reading = readFault(reader.read(cond.deviceId, ERROR_CAP, "active"), reader.read(cond.deviceId, ERROR_CAP, "code"), reader.read(cond.deviceId, ERROR_CAP, "faults"));
55484
+ const base = {
55485
+ path,
55486
+ kind: cond.kind,
55487
+ deviceId: cond.deviceId,
55488
+ cap: ERROR_CAP,
55489
+ fieldPath: "faults",
55490
+ expected: cond.codes.join(", ")
55491
+ };
55492
+ if (reading === void 0) {
55493
+ state.unknown = true;
55494
+ out.push({
55495
+ ...base,
55496
+ outcome: "fail",
55497
+ reason: "whether the device has a fault is unknown → fail"
55498
+ });
55499
+ return false;
55500
+ }
55501
+ const ok = faultMatches(reading, cond.codes);
55502
+ const shown = reading.active ? reading.codes.join(", ") || "a fault" : "none";
55503
+ out.push({
55504
+ ...base,
55505
+ outcome: ok ? "pass" : "fail",
55506
+ observed: shown,
55507
+ reason: `faults: ${shown}, expected ${describeWantedFaults(cond.codes)} → ${ok ? "pass" : "fail"}`
55508
+ });
55509
+ return ok;
55510
+ }
55301
55511
  case "stationary-present": {
55302
55512
  const verdict = judgeStationaryPresent(cond, reader);
55303
55513
  if (verdict.unknown === true) state.unknown = true;
@@ -55625,12 +55835,22 @@ var BECOMES_VARIABLES = describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "
55625
55835
  ...v,
55626
55836
  hintKey: "becomesDeviceId"
55627
55837
  } : v);
55838
+ /** What a fault row puts in the bag: the occurrence carries both (`codegen.ts`). */
55839
+ var FAULT_VARIABLES = [{
55840
+ name: "deviceId",
55841
+ description: "the device that raised the fault",
55842
+ hintKey: "faultDeviceId"
55843
+ }, {
55844
+ name: "faultCode",
55845
+ description: "the code of the fault that was raised, empty when it names none"
55846
+ }];
55628
55847
  /** What one event row kind provides; kinds that provide none are absent. */
55629
55848
  function triggerLeafVariables(kind) {
55630
55849
  if (kind === "detection") return DETECTION_VARIABLES;
55631
55850
  if (kind === "stationary") return STATIONARY_VARIABLES;
55632
55851
  if (kind === "device-becomes") return BECOMES_VARIABLES;
55633
55852
  if (kind === "device-fired") return FIRED_VARIABLES;
55853
+ if (kind === "device-fault-raised") return FAULT_VARIABLES;
55634
55854
  return [];
55635
55855
  }
55636
55856
  /** How often the state mirror is re-read as the backstop for a dropped event
@@ -55643,6 +55863,8 @@ function stepMetaOf(action) {
55643
55863
  case "code": return { kind: "code" };
55644
55864
  case "action": return { kind: "action" };
55645
55865
  case "notify": return { kind: "notify" };
55866
+ case "probe": return { kind: "probe" };
55867
+ case "http-request": return { kind: "http-request" };
55646
55868
  case "stop": return { kind: "stop" };
55647
55869
  case "wait-until": return { kind: "wait-until" };
55648
55870
  case "parallel": return { kind: "parallel" };
@@ -55769,6 +55991,41 @@ function emitLeaf(trigger, path) {
55769
55991
  void check()
55770
55992
  const reconcile = setInterval(() => { void check() }, RECONCILE_MS)
55771
55993
  disposers.push(() => clearInterval(reconcile))
55994
+ }`;
55995
+ case "device-fault-raised": return ` // event leaf ${path}: device fault raised — reads the device's WHOLE fault list
55996
+ // (the principal code when it publishes no list). Fires ONCE when a wanted fault
55997
+ // appears; the first good read only seeds, and a failed or unknown read changes
55998
+ // nothing (D49).
55999
+ {
56000
+ const watch = new FaultRaisedWatch(${j(trigger.codes)})
56001
+ const check = async (): Promise<void> => {
56002
+ const read = await readCapSlice(${j(trigger.deviceId)}, 'error')
56003
+ if (!read.ok) return
56004
+ const field = (name: string): unknown =>
56005
+ read.slice !== null && typeof read.slice === 'object' ? Reflect.get(read.slice, name) : undefined
56006
+ const raised = watch.observe(readFault(field('active'), field('code'), field('faults')))
56007
+ if (raised === undefined) return
56008
+ ctx.logger.info(
56009
+ 'device fault raised — ' + (raised.code === '' ? 'a fault' : 'fault ' + raised.code),
56010
+ { tags: { deviceId: ${j(trigger.deviceId)} }, leaf: ${at} },
56011
+ )
56012
+ void run(
56013
+ {
56014
+ kind: 'device-fault-raised',
56015
+ leaf: ${at},
56016
+ at: Date.now(),
56017
+ deviceId: ${j(trigger.deviceId)},
56018
+ faultCode: raised.code,
56019
+ },
56020
+ 'fault ' + (raised.code === '' ? 'raised' : raised.code + ' raised'),
56021
+ )
56022
+ }
56023
+ disposers.push(
56024
+ ctx.eventBus.subscribe({ category: 'device.state-changed', deviceId: ${j(trigger.deviceId)} }, () => { void check() }),
56025
+ )
56026
+ void check()
56027
+ const reconcile = setInterval(() => { void check() }, RECONCILE_MS)
56028
+ disposers.push(() => clearInterval(reconcile))
55772
56029
  }`;
55773
56030
  case "device-becomes": {
55774
56031
  const hold = holdOf(trigger);
@@ -55932,6 +56189,42 @@ function emitStepBody(action) {
55932
56189
  })
55933
56190
  if (sent.status === 'refused') throw new Error('notification target ' + sent.reason)
55934
56191
  if (sent.status === 'failed') throw new Error('notification failed: ' + sent.message)`;
56192
+ case "probe": return ` // a TCP reachability probe: one measurement, an expectation, an optional retry window
56193
+ const probed = await runProbeStep(
56194
+ { connect: tcpConnect, now: () => Date.now(), sleep, isAborted: () => token.aborted },
56195
+ {
56196
+ host: String(substitute(${j(action.host)}, vars)),
56197
+ port: ${j(action.port)},
56198
+ timeoutSeconds: ${j(action.timeoutSeconds)},
56199
+ ${action.expect === void 0 ? "" : `expect: ${j(action.expect)},`}
56200
+ ${action.retryUntilSeconds === void 0 ? "" : `retryUntilSeconds: ${j(action.retryUntilSeconds)},`}
56201
+ },
56202
+ )
56203
+ ${action.saveAs === void 0 ? "" : `Object.assign(vars, reachVars(${j(action.saveAs)}, probed.result))`}
56204
+ scope.setAttempts(probed.attempts, probed.message)
56205
+ ctx.logger.info('probe finished', { host: String(substitute(${j(action.host)}, vars)), port: ${j(action.port)}, met: probed.met, attempts: probed.attempts, rttMs: probed.result.rttMs })
56206
+ if (!probed.met) throw new Error('probe: ' + probed.message)`;
56207
+ case "http-request": return ` // an HTTP request: one measurement, an expectation, an optional retry window.
56208
+ // Header values and the body are never logged or traced.
56209
+ const httpUrl = String(substitute(${j(action.url)}, vars))
56210
+ scope.setArgs({ method: ${j(action.method)}, url: redactUrl(httpUrl) })
56211
+ const startedHttp = Date.now()
56212
+ const requested = await runHttpStep(
56213
+ { fetch: globalThis.fetch, now: () => Date.now(), sleep, isAborted: () => token.aborted },
56214
+ {
56215
+ method: ${j(action.method)},
56216
+ url: httpUrl,
56217
+ timeoutSeconds: ${j(action.timeoutSeconds)},
56218
+ ${action.headers === void 0 ? "" : `headers: substituteStrings(${j(action.headers)}, vars),`}
56219
+ ${action.body === void 0 ? "" : `body: String(substitute(${j(action.body)}, vars)),`}
56220
+ ${action.expect === void 0 ? "" : `expect: ${j(action.expect)},`}
56221
+ ${action.retryUntilSeconds === void 0 ? "" : `retryUntilSeconds: ${j(action.retryUntilSeconds)},`}
56222
+ },
56223
+ )
56224
+ ${action.saveAs === void 0 ? "" : `Object.assign(vars, reachVars(${j(action.saveAs)}, requested.result))`}
56225
+ scope.setAttempts(requested.attempts, requested.message)
56226
+ ctx.logger.info('http request finished', { method: ${j(action.method)}, url: redactUrl(httpUrl), status: requested.result.status, met: requested.met, attempts: requested.attempts, durationMs: Date.now() - startedHttp })
56227
+ if (!requested.met) throw new Error('http request: ' + requested.message)`;
55935
56228
  case "stop": return ` // end the run here, on purpose: the steps after it are not-run with this reason
55936
56229
  scope.stop(String(substitute(${j(action.reason)}, vars)), ${j(action.outcome)})`;
55937
56230
  case "set": return ` // write the run's own bag, for the steps after this one — substitution only
@@ -55943,7 +56236,7 @@ ${action.code.split("\n").map((line) => ` ${line}`).join("\n")}
55943
56236
  }
55944
56237
  }
55945
56238
  function continues(action) {
55946
- return (action.kind === "command" || action.kind === "action" || action.kind === "notify") && action.continueOnError === true;
56239
+ return (action.kind === "command" || action.kind === "action" || action.kind === "notify" || action.kind === "probe" || action.kind === "http-request") && action.continueOnError === true;
55947
56240
  }
55948
56241
  /** Whether the site is inside a block step: the automation's own steps sit at `actions.<n>`. */
55949
56242
  function isNestedSite(site) {
@@ -56173,6 +56466,8 @@ import {
56173
56466
  DetectionTriggerFilter,
56174
56467
  DeviceFiredWatch,
56175
56468
  EventCategory,
56469
+ FaultRaisedWatch,
56470
+ readFault,
56176
56471
  RunGate,
56177
56472
  buildTriggerTrace,
56178
56473
  collectWhenMirrorSources,
@@ -56194,6 +56489,10 @@ import {
56194
56489
  vocabCall,
56195
56490
  evaluateStepCondition,
56196
56491
  runSteps,
56492
+ runProbeStep,
56493
+ runHttpStep,
56494
+ redactUrl,
56495
+ reachVars,
56197
56496
  repeatCheck,
56198
56497
  waitUntil,
56199
56498
  waitTimedOutMessage,
@@ -56620,6 +56919,30 @@ ${hasTime ? ` // a time-is leaf changes sides at a boundary with no device ev
56620
56919
  return resolveStepArgs(value, vars, warnMissingVar)
56621
56920
  }
56622
56921
 
56922
+ /** Header values, substituted: the values are text, and are never logged. */
56923
+ function substituteStrings(
56924
+ raw: Record<string, string>,
56925
+ vars: Record<string, unknown>,
56926
+ ): Record<string, string> {
56927
+ return Object.fromEntries(Object.entries(raw).map(([key, value]) => [key, String(substitute(value, vars))]))
56928
+ }
56929
+
56930
+ /** Open a TCP connection and close it again: resolves when the port answered. */
56931
+ async function tcpConnect(host: string, port: number, timeoutMs: number): Promise<void> {
56932
+ const net = await import('node:net')
56933
+ await new Promise<void>((resolve, reject) => {
56934
+ const socket = net.connect({ host, port })
56935
+ const done = (err?: Error): void => {
56936
+ socket.destroy()
56937
+ if (err === undefined) resolve()
56938
+ else reject(err)
56939
+ }
56940
+ socket.setTimeout(timeoutMs, () => done(new Error('timed out after ' + String(timeoutMs / 1000) + ' s')))
56941
+ socket.once('connect', () => done())
56942
+ socket.once('error', (err) => done(err))
56943
+ })
56944
+ }
56945
+
56623
56946
  /** The variables handed to an Action step, substituted and kept to primitives. */
56624
56947
  function substituteVariables(
56625
56948
  raw: Record<string, string | number | boolean>,