@camstack/server 1.2.821 → 1.2.822

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 (98) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/trpc/generated-cap-routers.js +20 -0
  3. package/package.json +10 -10
  4. package/system/dist/{agent-https-N6Or6UAu.mjs → agent-https-C4yxMErF.mjs} +1 -1
  5. package/system/dist/{agent-https-Bp5yzi8b.js → agent-https-SGBI0xP8.js} +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  7. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  9. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  11. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  12. package/system/dist/builtins/autotrack/index.js +1 -1
  13. package/system/dist/builtins/autotrack/index.mjs +1 -1
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  15. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  16. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  17. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  18. package/system/dist/builtins/camera-grid/index.js +1 -1
  19. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  20. package/system/dist/builtins/composer/composer.addon.js +3 -3
  21. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  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/actions-service.d.ts +16 -0
  25. package/system/dist/builtins/core-blocks/core-blocks.addon.js +149 -7
  26. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +149 -7
  27. package/system/dist/builtins/core-blocks/device-template-door.d.ts +25 -0
  28. package/system/dist/builtins/core-blocks/fan-presets-service.d.ts +5 -0
  29. package/system/dist/builtins/core-blocks/scheduler/scheduler-engine.d.ts +5 -0
  30. package/system/dist/builtins/core-blocks/step-condition-door.d.ts +19 -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-manager.addon.d.ts +7 -0
  34. package/system/dist/builtins/device-manager/device-manager.addon.js +655 -2
  35. package/system/dist/builtins/device-manager/device-manager.addon.mjs +653 -1
  36. package/system/dist/builtins/device-manager/device-template/template-host.d.ts +60 -0
  37. package/system/dist/builtins/device-manager/device-template-actions.d.ts +33 -0
  38. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  39. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  40. package/system/dist/builtins/keychain/index.js +4 -4
  41. package/system/dist/builtins/keychain/index.mjs +4 -4
  42. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  43. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  44. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  45. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  46. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  47. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  48. package/system/dist/builtins/loki-logging/index.js +1 -1
  49. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  50. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  51. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  52. package/system/dist/builtins/platform-probe/index.js +1 -1
  53. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  54. package/system/dist/builtins/record-entries/index.js +1 -1
  55. package/system/dist/builtins/record-entries/index.mjs +1 -1
  56. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  57. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  58. package/system/dist/builtins/snapshot/index.js +1 -1
  59. package/system/dist/builtins/snapshot/index.mjs +1 -1
  60. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  61. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  62. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  63. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  64. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  65. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  66. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  67. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  68. package/system/dist/builtins/system-config/system-config.addon.js +9 -9
  69. package/system/dist/builtins/system-config/system-config.addon.mjs +286 -286
  70. package/system/dist/builtins/winston-logging/index.js +1 -1
  71. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  72. package/system/dist/{capture-engine-4lB0sLCf.js → capture-engine-6MVUyUry.js} +1 -1
  73. package/system/dist/{capture-engine-Cz7z5d36.mjs → capture-engine-BSjE-CQA.mjs} +1 -1
  74. package/system/dist/{composition-sources-C9gEj25e.js → composition-sources-BBAOXZdC.js} +1 -1
  75. package/system/dist/{composition-sources-C0e2g_VP.mjs → composition-sources-C8T9DRbZ.mjs} +1 -1
  76. package/system/dist/{constants-CZMy7dor.mjs → constants-CReG6K4k.mjs} +1 -1
  77. package/system/dist/{constants-Cq3B9yzj.js → constants-v0g9--wN.js} +1 -1
  78. package/system/dist/{device-ca-BenyQXJV.js → device-ca-BFcBTfff.js} +1 -1
  79. package/system/dist/{device-ca-BmQ6N-A-.mjs → device-ca-cX8qUs2s.mjs} +1 -1
  80. package/system/dist/device-template-worker.js +5 -7032
  81. package/system/dist/device-template-worker.mjs +1 -7026
  82. package/system/dist/{dist-M5VX8Hqf.js → dist-C2czR9xK.js} +633 -24
  83. package/system/dist/{dist-DuKMbGBM.mjs → dist-DjBZ1HhF.mjs} +592 -25
  84. package/system/dist/file-host-worker.js +1 -1
  85. package/system/dist/file-host-worker.mjs +1 -1
  86. package/system/dist/{hub-mdns-ciao-CXBfBwAy.mjs → hub-mdns-ciao-Cnr8xiSd.mjs} +2 -2
  87. package/system/dist/{hub-mdns-ciao-k3pOKWyZ.js → hub-mdns-ciao-CpCleue0.js} +2 -2
  88. package/system/dist/index.js +8 -8
  89. package/system/dist/index.mjs +8 -8
  90. package/system/dist/{legacy-integration-rows-door-C13OeuW9.mjs → legacy-integration-rows-door-CGajkVPh.mjs} +1 -1
  91. package/system/dist/{legacy-integration-rows-door-mIpR3e6X.js → legacy-integration-rows-door-DhW6mPZj.js} +1 -1
  92. package/system/dist/{restore-archive-CCgt7SZ8.js → restore-archive-BLab80kx.js} +7 -7
  93. package/system/dist/{restore-archive-DDeQFJN5.mjs → restore-archive-eA7L58KT.mjs} +86 -86
  94. package/system/dist/template-protocol-BmMM5VBf.mjs +7033 -0
  95. package/system/dist/template-protocol-CTP4eAo_.js +7059 -0
  96. package/system/dist/{wal-maintenance-Cj7xe4wN.mjs → wal-maintenance-DeBxoOFh.mjs} +0 -0
  97. package/system/dist/{wal-maintenance-D5M6hl53.js → wal-maintenance-DhnSF7K-.js} +0 -0
  98. package/system/package.json +1 -1
@@ -3342,7 +3342,7 @@ var SecretOverwriteRefusedError = class extends Error {
3342
3342
  this.name = "SecretOverwriteRefusedError";
3343
3343
  }
3344
3344
  };
3345
- function isRecord$3(value) {
3345
+ function isRecord$3$1(value) {
3346
3346
  return typeof value === "object" && value !== null && !Array.isArray(value);
3347
3347
  }
3348
3348
  function resolvedValue(pass, marker) {
@@ -3371,7 +3371,7 @@ function inArray(pass, incoming, stored) {
3371
3371
  return incoming.map((item, index) => {
3372
3372
  const twin = stored[index];
3373
3373
  if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
3374
- if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
3374
+ if (isRecord$3$1(item) && isRecord$3$1(twin)) return inArrayRow(pass, item, twin);
3375
3375
  if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
3376
3376
  return item;
3377
3377
  });
@@ -3382,7 +3382,7 @@ function inArrayRow(pass, incoming, stored) {
3382
3382
  const twin = stored[key];
3383
3383
  if (isSecretMarker(twin)) {
3384
3384
  if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
3385
- } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
3385
+ } else if (isRecord$3$1(value) && isRecord$3$1(twin)) out[key] = inArrayRow(pass, value, twin);
3386
3386
  else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
3387
3387
  }
3388
3388
  return out;
@@ -3390,7 +3390,7 @@ function inArrayRow(pass, incoming, stored) {
3390
3390
  async function walk(pass, incoming, stored) {
3391
3391
  if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
3392
3392
  if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
3393
- if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
3393
+ if (!isRecord$3$1(incoming) || !isRecord$3$1(stored)) return incoming;
3394
3394
  const out = { ...incoming };
3395
3395
  for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
3396
3396
  return out;
@@ -3421,7 +3421,7 @@ async function restoreUnchangedSecrets(input) {
3421
3421
  function isJsonEqual(a, b) {
3422
3422
  if (Object.is(a, b)) return true;
3423
3423
  if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
3424
- if (isRecord$3(a) && isRecord$3(b)) {
3424
+ if (isRecord$3$1(a) && isRecord$3$1(b)) {
3425
3425
  const keys = Object.keys(a);
3426
3426
  if (keys.length !== Object.keys(b).length) return false;
3427
3427
  return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
@@ -3445,7 +3445,7 @@ function markerKeysOf(blob, owner) {
3445
3445
  }
3446
3446
  function nodeFromStored(value, owner) {
3447
3447
  if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
3448
- if (!isRecord$3(value)) return null;
3448
+ if (!isRecord$3$1(value)) return null;
3449
3449
  const children = /* @__PURE__ */ new Map();
3450
3450
  for (const [key, child] of Object.entries(value)) {
3451
3451
  const node = nodeFromStored(child, owner);
@@ -43881,11 +43881,35 @@ function normalizeStepTargets(steps) {
43881
43881
  /**
43882
43882
  * The steps an internal Action may contain: cap and wait, and nothing that can
43883
43883
  * call back into an Action — so an Action can never reach itself (no cycles).
43884
+ * This is the LEAF shape: no condition of its own.
43885
+ */
43886
+ var LeafActionStepSchema = zod.z.discriminatedUnion("kind", [AutomationWaitStepSchema, AutomationCapStepSchema]);
43887
+ /**
43888
+ * The optional guard of a step (#472): `if` is the ONE `when` tree (D980), read
43889
+ * on the state mirror when the step is reached; `else` runs when it is false.
43890
+ * An `else` holds leaf steps only — the nesting is bounded at ONE level, so a
43891
+ * branch can never grow a tree the trace has to draw.
43884
43892
  */
43885
- var ActionStepSchema = zod.z.discriminatedUnion("kind", [AutomationWaitStepSchema, AutomationCapStepSchema]);
43893
+ var stepGuardShape = {
43894
+ if: AutomationWhenSchema.optional(),
43895
+ else: zod.z.array(LeafActionStepSchema).max(10).optional()
43896
+ };
43897
+ var elseNeedsIf = {
43898
+ message: "an else list needs the condition it is the other side of (if)",
43899
+ path: ["else"]
43900
+ };
43901
+ var GuardedWaitStepSchema = AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
43902
+ var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
43903
+ message: "a cap step needs a target",
43904
+ path: ["target"]
43905
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
43906
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
43907
+ path: ["actionId"]
43908
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
43909
+ var ActionStepSchema = zod.z.discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]);
43886
43910
  var AutomationActionSchema = zod.z.discriminatedUnion("kind", [
43887
- AutomationWaitStepSchema,
43888
- AutomationCapStepSchema,
43911
+ GuardedWaitStepSchema,
43912
+ GuardedCapStepSchema,
43889
43913
  zod.z.object({
43890
43914
  kind: zod.z.literal("action"),
43891
43915
  /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
@@ -44804,7 +44828,7 @@ var StepDeviceTraceSchema = zod.z.object({
44804
44828
  outcome: zod.z.enum(["ok", "error"]),
44805
44829
  message: zod.z.string().optional()
44806
44830
  });
44807
- var AutomationStepTraceSchema = zod.z.object({
44831
+ var StepTraceBaseSchema = zod.z.object({
44808
44832
  /** `actions.<i>` */
44809
44833
  path: zod.z.string().min(1),
44810
44834
  kind: zod.z.string().min(1),
@@ -44823,15 +44847,35 @@ var AutomationStepTraceSchema = zod.z.object({
44823
44847
  * is shown as {@link REDACTED_ARG}. Absent on traces written before it existed.
44824
44848
  */
44825
44849
  args: zod.z.record(zod.z.string(), TraceValueSchema).optional(),
44826
- /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. */
44850
+ /**
44851
+ * The device values a templated arg printed as `—`, one `ref: reason` each
44852
+ * (D1021): why a sentence says "—" where a number was expected. Bounded.
44853
+ */
44854
+ templates: zod.z.array(zod.z.string()).max(20).optional(),
44855
+ /**
44856
+ * What the step's own `if` read when the step was reached (#472): `true` the
44857
+ * step ran, `false` its `else` ran (or nothing did), `unknown` a state leaf
44858
+ * could not be read, so NEITHER side ran. Absent on an unguarded step.
44859
+ */
44860
+ condition: zod.z.enum([
44861
+ "true",
44862
+ "false",
44863
+ "unknown"
44864
+ ]).optional(),
44865
+ /** Why the condition read what it read, in the evaluator's own words. */
44866
+ conditionReason: zod.z.string().optional(),
44867
+ /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. */
44827
44868
  outcome: zod.z.enum([
44828
44869
  "ok",
44829
44870
  "error",
44830
44871
  "not-run",
44831
- "empty"
44872
+ "empty",
44873
+ "skipped"
44832
44874
  ]),
44833
44875
  message: zod.z.string().optional()
44834
44876
  });
44877
+ /** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
44878
+ var AutomationStepTraceSchema = StepTraceBaseSchema.extend({ else: zod.z.array(StepTraceBaseSchema).optional() });
44835
44879
  var AutomationRunTraceSchema = zod.z.object({
44836
44880
  runId: zod.z.string().min(1),
44837
44881
  startedAt: zod.z.number(),
@@ -45139,6 +45183,7 @@ zod.z.enum([
45139
45183
  "invalid-variables",
45140
45184
  "invalid-steps",
45141
45185
  "not-linked",
45186
+ "template-scope",
45142
45187
  "busy"
45143
45188
  ]);
45144
45189
  /**
@@ -45163,9 +45208,50 @@ var ActionRunChangedSchema = zod.z.object({
45163
45208
  lastRunAt: zod.z.number().nullable(),
45164
45209
  lastError: zod.z.string().nullable()
45165
45210
  });
45211
+ /**
45212
+ * The guard of a conditional step (#472): the step's `if` is the ONE `when`
45213
+ * tree (D980), read on a {@link ConditionMirror} filled for exactly the leaves
45214
+ * the tree names, at the moment the step is reached. A state that cannot be
45215
+ * read is UNKNOWN, and unknown runs neither side (D49: a failed read changes
45216
+ * nothing, and never decides a branch).
45217
+ */
45218
+ /** Fill a mirror for the tree's leaves from `fetchers` and judge it NOW. */
45219
+ async function evaluateStepCondition(when, fetchers, now = Date.now) {
45220
+ const mirror = new ConditionMirror(collectWhenMirrorSources(when));
45221
+ await mirror.refresh(fetchers);
45222
+ const evaluation = evaluateWhenTree(when, mirror, now());
45223
+ const first = evaluation.nodes.filter((n) => n.outcome !== "pass").map((n) => n.reason)[0];
45224
+ if (evaluation.unknown) return {
45225
+ result: "unknown",
45226
+ reason: `a state the condition reads is not known${first === void 0 ? "" : ` (${first})`}`
45227
+ };
45228
+ return evaluation.pass ? {
45229
+ result: "true",
45230
+ reason: "the condition holds"
45231
+ } : {
45232
+ result: "false",
45233
+ reason: first ?? "the condition does not hold"
45234
+ };
45235
+ }
45166
45236
  function errorMessage(err) {
45167
45237
  return err instanceof Error ? err.message : String(err);
45168
45238
  }
45239
+ /** A guard that throws is an unknown, never a crash of the run. */
45240
+ async function readGuard(guard) {
45241
+ try {
45242
+ return await guard();
45243
+ } catch (err) {
45244
+ return {
45245
+ result: "unknown",
45246
+ reason: `the condition could not be read: ${errorMessage(err)}`
45247
+ };
45248
+ }
45249
+ }
45250
+ /** The else level of a trace is one level deep: a nested trace carries no `else` of its own. */
45251
+ function withoutElse(trace) {
45252
+ const { else: _else, ...rest } = trace;
45253
+ return rest;
45254
+ }
45169
45255
  async function runSteps(steps, options) {
45170
45256
  const traces = [];
45171
45257
  let failed = false;
@@ -45183,10 +45269,57 @@ async function runSteps(steps, options) {
45183
45269
  continue;
45184
45270
  }
45185
45271
  const startedAt = options.now();
45272
+ let guardTrace = {};
45273
+ if (step.guard !== void 0) {
45274
+ const verdict = await readGuard(step.guard);
45275
+ guardTrace = {
45276
+ condition: verdict.result,
45277
+ conditionReason: verdict.reason
45278
+ };
45279
+ if (verdict.result === "unknown") options.onGuardUnknown?.({
45280
+ index,
45281
+ path,
45282
+ reason: verdict.reason,
45283
+ deviceId: step.meta.deviceId
45284
+ });
45285
+ if (verdict.result !== "true") {
45286
+ const branch = verdict.result === "false" ? step.otherwise ?? [] : [];
45287
+ if (branch.length === 0) {
45288
+ traces.push({
45289
+ ...step.meta,
45290
+ ...guardTrace,
45291
+ path,
45292
+ startedAt,
45293
+ endedAt: options.now(),
45294
+ outcome: "skipped",
45295
+ message: verdict.result === "unknown" ? `not run: ${verdict.reason}` : `not run: the condition is false (${verdict.reason})`
45296
+ });
45297
+ continue;
45298
+ }
45299
+ const sub = await runSteps(branch, {
45300
+ ...options,
45301
+ pathPrefix: `${path}.else`
45302
+ });
45303
+ if (sub.failed) failed = true;
45304
+ else if (sub.aborted) aborted = true;
45305
+ traces.push({
45306
+ ...step.meta,
45307
+ ...guardTrace,
45308
+ path,
45309
+ startedAt,
45310
+ endedAt: options.now(),
45311
+ outcome: sub.failed ? "error" : "ok",
45312
+ ...sub.failed ? { message: "an else step failed" } : {},
45313
+ else: sub.steps.map(withoutElse)
45314
+ });
45315
+ continue;
45316
+ }
45317
+ }
45186
45318
  let deviceId = step.meta.deviceId;
45187
45319
  let sent;
45188
45320
  const perDevice = [];
45189
45321
  let emptyReason;
45322
+ let templateNotes = [];
45190
45323
  const scope = {
45191
45324
  setDeviceId: (id) => {
45192
45325
  deviceId = id;
@@ -45199,8 +45332,12 @@ async function runSteps(steps, options) {
45199
45332
  },
45200
45333
  setArgs: (args) => {
45201
45334
  sent = args;
45335
+ },
45336
+ setTemplateNotes: (notes) => {
45337
+ templateNotes = notes.slice(0, 20);
45202
45338
  }
45203
45339
  };
45340
+ const templatesTrace = () => templateNotes.length === 0 ? {} : { templates: [...templateNotes] };
45204
45341
  const argsTrace = () => sent === void 0 ? {} : { args: buildStepArgsTrace(sent) };
45205
45342
  const devicesTrace = () => perDevice.length === 0 ? {} : { devices: perDevice.slice(0, 200) };
45206
45343
  try {
@@ -45209,7 +45346,9 @@ async function runSteps(steps, options) {
45209
45346
  ...step.meta,
45210
45347
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
45211
45348
  ...argsTrace(),
45349
+ ...templatesTrace(),
45212
45350
  ...devicesTrace(),
45351
+ ...guardTrace,
45213
45352
  path,
45214
45353
  startedAt,
45215
45354
  endedAt: options.now(),
@@ -45229,7 +45368,9 @@ async function runSteps(steps, options) {
45229
45368
  ...step.meta,
45230
45369
  ...deviceId === void 0 || perDevice.length > 1 ? {} : { deviceId },
45231
45370
  ...argsTrace(),
45371
+ ...templatesTrace(),
45232
45372
  ...devicesTrace(),
45373
+ ...guardTrace,
45233
45374
  path,
45234
45375
  startedAt,
45235
45376
  endedAt: options.now(),
@@ -45278,6 +45419,125 @@ function resolveStepArgs(value, vars, onMissing) {
45278
45419
  if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, resolveStepArgs(v, vars, onMissing)]));
45279
45420
  return value;
45280
45421
  }
45422
+ /** A device template that did not render: the step fails with this, never throws past `runSteps`. */
45423
+ var StepTemplateError = class extends Error {
45424
+ reason;
45425
+ constructor(reason, message) {
45426
+ super(`device template [${reason}]: ${message}`);
45427
+ this.reason = reason;
45428
+ this.name = "StepTemplateError";
45429
+ }
45430
+ };
45431
+ /**
45432
+ * A `{{vars.x}}` slot, set aside while a template renders. The slot carries a
45433
+ * nonce drawn per call, so a device value that happens to contain the sentinel
45434
+ * characters can never name a held variable.
45435
+ */
45436
+ var VAR_SLOT_OPEN = "";
45437
+ var VAR_SLOT_CLOSE = "";
45438
+ var TEMPLATE_MARKUP_RE = /\{\{|\{%/;
45439
+ function newSlotNonce() {
45440
+ return Math.random().toString(36).slice(2, 12);
45441
+ }
45442
+ function slotPattern(nonce) {
45443
+ return new RegExp(`${VAR_SLOT_OPEN}${nonce}:([A-Za-z_][A-Za-z0-9_]*)${VAR_SLOT_CLOSE}`, "g");
45444
+ }
45445
+ /** True when a string, once its `{{vars.x}}` slots are set aside, still carries template markup. */
45446
+ function carriesDeviceTemplate(text) {
45447
+ return TEMPLATE_MARKUP_RE.test(text.replace(TEMPLATE_RE, ""));
45448
+ }
45449
+ /** Every string in `value` that is a device template (D1021), de-duplicated, in walk order. */
45450
+ function collectDeviceTemplates(value) {
45451
+ const found = /* @__PURE__ */ new Set();
45452
+ const walk = (node) => {
45453
+ if (typeof node === "string") {
45454
+ if (carriesDeviceTemplate(node)) found.add(node);
45455
+ } else if (Array.isArray(node)) for (const item of node) walk(item);
45456
+ else if (node !== null && typeof node === "object") for (const item of Object.values(node)) walk(item);
45457
+ };
45458
+ walk(value);
45459
+ return [...found];
45460
+ }
45461
+ function protectVarSlots(text, nonce) {
45462
+ return text.replace(TEMPLATE_RE, (_m, key) => `${VAR_SLOT_OPEN}${nonce}:${key}${VAR_SLOT_CLOSE}`);
45463
+ }
45464
+ function restoreVarSlots(text, nonce, vars, onMissing) {
45465
+ return text.replace(slotPattern(nonce), (_m, key) => {
45466
+ const v = vars[key];
45467
+ if (v === void 0) {
45468
+ onMissing(key);
45469
+ return "";
45470
+ }
45471
+ return String(v);
45472
+ });
45473
+ }
45474
+ /**
45475
+ * {@link resolveStepArgs} plus the device templates of a step (D1021). A string
45476
+ * that carries `{{ … }}` / `{% … %}` beyond a `{{vars.x}}` slot is rendered by
45477
+ * `render` BEFORE the variables are put in, so a variable's value is data and
45478
+ * never template source (an action variable can come from a non-admin caller).
45479
+ * A refused render, or no renderer, throws {@link StepTemplateError}: the step
45480
+ * fails with the typed reason and nothing is dispatched.
45481
+ */
45482
+ async function resolveStepArgsWithTemplates(value, vars, onMissing, render) {
45483
+ const nonce = newSlotNonce();
45484
+ const sources = [];
45485
+ const indexOf = /* @__PURE__ */ new Map();
45486
+ const hold = (text) => {
45487
+ const known = indexOf.get(text);
45488
+ if (known !== void 0) return known;
45489
+ sources.push(text);
45490
+ indexOf.set(text, sources.length - 1);
45491
+ return sources.length - 1;
45492
+ };
45493
+ class Pending {
45494
+ index;
45495
+ constructor(index) {
45496
+ this.index = index;
45497
+ }
45498
+ }
45499
+ const collect = (node) => {
45500
+ if (isVarRef(node)) return resolveStepArgs(node, vars, onMissing);
45501
+ if (typeof node === "string") return carriesDeviceTemplate(node) ? new Pending(hold(protectVarSlots(node, nonce))) : resolveStepArgs(node, vars, onMissing);
45502
+ if (Array.isArray(node)) return node.map(collect);
45503
+ if (node !== null && typeof node === "object") return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, collect(v)]));
45504
+ return node;
45505
+ };
45506
+ const skeleton = collect(value);
45507
+ if (sources.length === 0) return {
45508
+ value: skeleton,
45509
+ notes: []
45510
+ };
45511
+ if (render === void 0) throw new StepTemplateError("unavailable", "this node has no device template renderer");
45512
+ let answers;
45513
+ try {
45514
+ answers = await render(sources);
45515
+ } catch (err) {
45516
+ throw new StepTemplateError("unavailable", errorMessage(err));
45517
+ }
45518
+ const texts = [];
45519
+ const notes = [];
45520
+ for (const index of sources.keys()) {
45521
+ const answer = answers[index];
45522
+ if (answer === void 0) throw new StepTemplateError("unavailable", `no answer for template ${index + 1}`);
45523
+ if (!answer.ok) throw new StepTemplateError(answer.refusal.reason, answer.refusal.message);
45524
+ texts.push(restoreVarSlots(answer.text, nonce, vars, onMissing));
45525
+ for (const entry of answer.trace) {
45526
+ const note = `${entry.ref}: ${entry.reason}`;
45527
+ if (!notes.includes(note)) notes.push(note);
45528
+ }
45529
+ }
45530
+ const fill = (node) => {
45531
+ if (node instanceof Pending) return texts[node.index] ?? "";
45532
+ if (Array.isArray(node)) return node.map(fill);
45533
+ if (node !== null && typeof node === "object") return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, fill(v)]));
45534
+ return node;
45535
+ };
45536
+ return {
45537
+ value: fill(skeleton),
45538
+ notes
45539
+ };
45540
+ }
45281
45541
  function stepMetaOfAction(step) {
45282
45542
  if (step.kind === "wait") return { kind: "wait" };
45283
45543
  const { target, actionId } = normalizeCapStep(step);
@@ -45331,19 +45591,36 @@ async function runForDevices(deviceIds, scope, work, concurrency = 4) {
45331
45591
  * variables. Variables are substituted per step, at the moment it runs, so a
45332
45592
  * missing one fails THAT step (traced) and leaves the later ones not-run.
45333
45593
  */
45594
+ /** The guard and the else list of a step, bound to the run (#472); `{}` for an unguarded step. */
45595
+ function guardOf(step, vars, deps) {
45596
+ const when = step.if;
45597
+ if (when === void 0) return {};
45598
+ const evaluate = deps.evaluateCondition;
45599
+ return {
45600
+ guard: async () => evaluate === void 0 ? {
45601
+ result: "unknown",
45602
+ reason: "this consumer has no condition evaluator"
45603
+ } : evaluate(when),
45604
+ ...step.else === void 0 ? {} : { otherwise: buildActionSteps(step.else, vars, deps) }
45605
+ };
45606
+ }
45334
45607
  function buildActionSteps(steps, vars, deps) {
45335
45608
  return steps.map((step) => {
45609
+ const guarded = guardOf(step, vars, deps);
45336
45610
  const meta = stepMetaOfAction(step);
45337
45611
  if (step.kind === "wait") return {
45338
45612
  meta,
45613
+ ...guarded,
45339
45614
  run: () => deps.sleep(step.seconds * 1e3)
45340
45615
  };
45341
45616
  const normalized = normalizeCapStep(step);
45342
45617
  return {
45343
45618
  meta,
45619
+ ...guarded,
45344
45620
  run: async (scope) => {
45345
- const resolved = resolveStepArgs(step.args ?? {}, vars, deps.onMissingVar);
45346
- const args = isPlainRecord(resolved) ? resolved : {};
45621
+ const templated = await resolveStepArgsWithTemplates(step.args ?? {}, vars, deps.onMissingVar, deps.renderTemplates);
45622
+ if (templated.notes.length > 0) scope.setTemplateNotes(templated.notes);
45623
+ const args = isPlainRecord(templated.value) ? templated.value : {};
45347
45624
  const target = await deps.resolveTarget(normalized.target, normalized.actionId, vars, {
45348
45625
  actionId: normalized.actionId,
45349
45626
  owner: deps.owner
@@ -53106,6 +53383,25 @@ var CAP_CUSTOMIZE_CATALOG = {
53106
53383
  }]
53107
53384
  }
53108
53385
  };
53386
+ /**
53387
+ * Unit meta on runtime-state fields. The composed-device row reads this;
53388
+ * it is not an override list (D944).
53389
+ */
53390
+ var CAP_RUNTIME_FIELD_UNITS = {
53391
+ "ambient-light-sensor": { illuminance: "lx" },
53392
+ "battery": {
53393
+ level: "%",
53394
+ voltage: "V"
53395
+ },
53396
+ "humidity-sensor": { humidity: "%" },
53397
+ "power-meter": {
53398
+ power: "W",
53399
+ energy: "kWh",
53400
+ voltage: "V",
53401
+ current: "A"
53402
+ },
53403
+ "temperature-sensor": { temperature: "°C" }
53404
+ };
53109
53405
  function problem(code, path, message) {
53110
53406
  return {
53111
53407
  code,
@@ -57947,6 +58243,161 @@ function checkDeviceAlias(alias, isTaken) {
57947
58243
  };
57948
58244
  }
57949
58245
  /**
58246
+ * Device value templates, the parts that need no template engine (D1021).
58247
+ *
58248
+ * A template is plain text with Jinja-style `{{ … }}` / `{% … %}` blocks:
58249
+ * `{{ stufa_veranda.temperature | unit('°F') | round(1) }}`. Devices are named
58250
+ * by their alias (`device-alias.ts`); a field is `alias.field` when the field
58251
+ * name is unique across the device's capabilities, else `alias.<cap>.field`,
58252
+ * and an ambiguous `alias.field` is refused by name.
58253
+ *
58254
+ * The engine itself (nunjucks) lives ONLY in the hub's renderer
58255
+ * (`packages/system/src/builtins/device-manager/device-template/`, guard
58256
+ * `check-device-template-grammar`): it does not sandbox, so it renders only in
58257
+ * a worker thread under a wall-time budget, over frozen plain data. This file
58258
+ * is the shared vocabulary — limits, refusal reasons, the trace, and how a
58259
+ * `(alias, path)` reference resolves against a device's slices.
58260
+ */
58261
+ var DEVICE_TEMPLATE_MAX_LENGTH = 4096;
58262
+ var DEVICE_TEMPLATE_MAX_OUTPUT = 4096;
58263
+ var DeviceTemplateSchema = zod.z.string().min(1).max(DEVICE_TEMPLATE_MAX_LENGTH);
58264
+ /** The filters a template may use. Anything else is refused at parse time. */
58265
+ var DEVICE_TEMPLATE_FILTERS = [
58266
+ "unit",
58267
+ "round",
58268
+ "default",
58269
+ "since",
58270
+ "ago",
58271
+ "format",
58272
+ "upper",
58273
+ "lower",
58274
+ "title",
58275
+ "capitalize",
58276
+ "trim",
58277
+ "abs",
58278
+ "int",
58279
+ "float",
58280
+ "length",
58281
+ "d",
58282
+ "join",
58283
+ "replace",
58284
+ "first",
58285
+ "last",
58286
+ "sort",
58287
+ "reverse",
58288
+ "sum",
58289
+ "string",
58290
+ "list",
58291
+ "truncate"
58292
+ ];
58293
+ var DeviceTemplateRefusalSchema = zod.z.object({
58294
+ reason: zod.z.enum([
58295
+ "too-long",
58296
+ "syntax",
58297
+ "forbidden-syntax",
58298
+ "forbidden-member",
58299
+ "unknown-filter",
58300
+ "ambiguous-field",
58301
+ "busy",
58302
+ "budget-exceeded",
58303
+ "timeout",
58304
+ "output-too-large",
58305
+ "render-failed",
58306
+ "out-of-scope",
58307
+ "unavailable"
58308
+ ]),
58309
+ message: zod.z.string()
58310
+ });
58311
+ var DeviceTemplateTraceEntrySchema = zod.z.object({
58312
+ ref: zod.z.string(),
58313
+ reason: zod.z.enum([
58314
+ "unknown-alias",
58315
+ "unknown-field",
58316
+ "no-field",
58317
+ "unavailable"
58318
+ ])
58319
+ });
58320
+ var DeviceTemplateRenderSchema = zod.z.discriminatedUnion("ok", [zod.z.object({
58321
+ ok: zod.z.literal(true),
58322
+ text: zod.z.string(),
58323
+ trace: zod.z.array(DeviceTemplateTraceEntrySchema)
58324
+ }), zod.z.object({
58325
+ ok: zod.z.literal(false),
58326
+ refusal: DeviceTemplateRefusalSchema,
58327
+ trace: zod.z.array(DeviceTemplateTraceEntrySchema)
58328
+ })]);
58329
+ /** A capability name as a template spells it: `temperature-sensor` → `temperature_sensor`. */
58330
+ function templateCapKey(cap) {
58331
+ return cap.replace(/-/g, "_");
58332
+ }
58333
+ function isRecord$3(value) {
58334
+ return typeof value === "object" && value !== null && !Array.isArray(value);
58335
+ }
58336
+ function pickPath(root, path) {
58337
+ let cursor = root;
58338
+ for (const part of path) if (Array.isArray(cursor) && typeof part === "number") cursor = cursor[part];
58339
+ else if (isRecord$3(cursor) && Object.hasOwn(cursor, String(part))) cursor = cursor[String(part)];
58340
+ else return;
58341
+ return cursor;
58342
+ }
58343
+ /**
58344
+ * Resolve the path after an alias. `<cap>.field…` when the first segment names
58345
+ * one of the device's caps; otherwise `field…` when exactly one cap carries a
58346
+ * field of that name; several caps carrying it is `ambiguous`, naming them.
58347
+ */
58348
+ function resolveTemplateRef(view, path) {
58349
+ const head = path[0];
58350
+ if (head === void 0) return {
58351
+ kind: "missing",
58352
+ reason: "no-field"
58353
+ };
58354
+ const caps = Object.keys(view.slices);
58355
+ const named = caps.find((cap) => cap === head || templateCapKey(cap) === head);
58356
+ if (named !== void 0) {
58357
+ const rest = path.slice(1);
58358
+ if (rest.length === 0) return {
58359
+ kind: "missing",
58360
+ reason: "no-field"
58361
+ };
58362
+ const value = pickPath(view.slices[named], rest);
58363
+ if (value === void 0) return {
58364
+ kind: "missing",
58365
+ reason: "unknown-field"
58366
+ };
58367
+ return {
58368
+ kind: "value",
58369
+ cap: named,
58370
+ fieldPath: rest,
58371
+ value
58372
+ };
58373
+ }
58374
+ const owners = caps.filter((cap) => {
58375
+ const slice = view.slices[cap];
58376
+ return isRecord$3(slice) && Object.hasOwn(slice, String(head));
58377
+ });
58378
+ if (owners.length === 0) return {
58379
+ kind: "missing",
58380
+ reason: "unknown-field"
58381
+ };
58382
+ const [only] = owners;
58383
+ if (owners.length > 1 || only === void 0) return {
58384
+ kind: "ambiguous",
58385
+ field: String(head),
58386
+ caps: owners
58387
+ };
58388
+ const value = pickPath(view.slices[only], path);
58389
+ if (value === void 0) return {
58390
+ kind: "missing",
58391
+ reason: "unknown-field"
58392
+ };
58393
+ return {
58394
+ kind: "value",
58395
+ cap: only,
58396
+ fieldPath: path,
58397
+ value
58398
+ };
58399
+ }
58400
+ /**
57950
58401
  * A SITE ZONE — a named part of the property that several locations belong to.
57951
58402
  *
57952
58403
  * "Night zone" holds every bedroom; "Zona giorno" the living room and the
@@ -58868,6 +59319,38 @@ var deviceManagerCapability = {
58868
59319
  kind: "mutation",
58869
59320
  auth: "admin"
58870
59321
  }),
59322
+ /**
59323
+ * Render device value templates (D1021). The ONE door every consumer uses:
59324
+ * an action step, a scheduler point, a notification rule, a generated
59325
+ * automation block. Admin-only (an in-process block carries the mesh
59326
+ * principal): it reads device state by alias, so a non-admin never calls it
59327
+ * directly. `allowedDeviceIds` is the set the END caller was proven to see;
59328
+ * a template naming another device answers `out-of-scope`. Answers are
59329
+ * index-aligned with `templates`.
59330
+ */
59331
+ renderDeviceTemplates: method(zod.z.object({
59332
+ templates: zod.z.array(DeviceTemplateSchema).max(64),
59333
+ allowedDeviceIds: zod.z.array(zod.z.number().int()).optional()
59334
+ }), zod.z.object({ results: zod.z.array(DeviceTemplateRenderSchema) }), { auth: "admin" }),
59335
+ /**
59336
+ * Vet templates without rendering them: the syntax refusal, or the devices
59337
+ * each names and whether `allowedDeviceIds` covers them. The save door and
59338
+ * the run-time scope check both ask this.
59339
+ */
59340
+ checkDeviceTemplates: method(zod.z.object({
59341
+ templates: zod.z.array(zod.z.string()).max(64),
59342
+ allowedDeviceIds: zod.z.array(zod.z.number().int()).optional()
59343
+ }), zod.z.object({ results: zod.z.array(zod.z.discriminatedUnion("ok", [zod.z.object({
59344
+ ok: zod.z.literal(true),
59345
+ aliases: zod.z.array(zod.z.object({
59346
+ alias: zod.z.string(),
59347
+ deviceId: zod.z.number().int().nullable(),
59348
+ allowed: zod.z.boolean()
59349
+ }))
59350
+ }), zod.z.object({
59351
+ ok: zod.z.literal(false),
59352
+ refusal: DeviceTemplateRefusalSchema
59353
+ })])) }), { auth: "admin" }),
58871
59354
  /** Update the operator-organisational location label. `null`
58872
59355
  * clears it. */
58873
59356
  setLocation: method(zod.z.object({
@@ -63479,6 +63962,17 @@ var TIMED_RUN_DEVICE_TYPES = [DeviceType.Heater, DeviceType.PetFountain];
63479
63962
  function timedRunLimitOf(deviceType) {
63480
63963
  return TIMED_RUN_LIMITS[deviceType] ?? null;
63481
63964
  }
63965
+ var MS_PER_SECOND = 1e3;
63966
+ var MS_PER_MINUTE = 6e4;
63967
+ /**
63968
+ * Whole units left on an armed run. Minutes and seconds both ceil, and a run
63969
+ * that has not expired yet never reads as zero.
63970
+ */
63971
+ function timedRunRemaining(activeUntil, now, unit) {
63972
+ const left = activeUntil - now;
63973
+ if (left <= 0) return 0;
63974
+ return Math.max(1, Math.ceil(left / (unit === "min" ? MS_PER_MINUTE : MS_PER_SECOND)));
63975
+ }
63482
63976
  /** Seconds in a duration of `duration` `unit`. */
63483
63977
  function timedRunSeconds(duration, unit) {
63484
63978
  return unit === "min" ? duration * 60 : duration;
@@ -64018,7 +64512,13 @@ var HeroTimedRunSlotSchema = zod.z.object({
64018
64512
  activeUntil: zod.z.number().nullable(),
64019
64513
  quickRun: TimedRunQuickRunSchema,
64020
64514
  run: HeroActionSchema,
64021
- cancel: HeroActionSchema
64515
+ cancel: HeroActionSchema,
64516
+ /**
64517
+ * Whole units left (the limit's unit, ceil). `null` while nothing is armed.
64518
+ * A number, not words: the row formats it, and a text here would not fit the
64519
+ * hero-layout declaration.
64520
+ */
64521
+ remaining: zod.z.number().nullable()
64022
64522
  });
64023
64523
  var HeroPowerSupplySlotSchema = zod.z.object({
64024
64524
  /** The plug's state; `null` = unknown, never off. */
@@ -64137,18 +64637,31 @@ var HeroModelSchema = zod.z.object({
64137
64637
  * 4. a trailing fact (power, else battery, else consumables).
64138
64638
  *
64139
64639
  * Selection rules, all taken from the model:
64140
- * - ONE control is ever shown: the device's own power; else the FIRST control of
64640
+ * - the primary control is the device's own power; else the FIRST control of
64141
64641
  * the FIRST row that has any (a later row's control is never promoted). When
64142
64642
  * the model lists that part in `gated`, the row has no inline control: the
64143
64643
  * projection never falls through to another control the caller could use.
64644
+ * - a timed run, when the model carries the slot, sits beside that primary:
64645
+ * Run while idle, Stop while armed. Gating the slot hides the control.
64144
64646
  * - the status line is the head (what plays, else the state) plus at most
64145
- * {@link ROW_STATUS_FACTS_MAX} facts, the trailing fact excluded;
64647
+ * {@link ROW_STATUS_FACTS_MAX} facts, the trailing fact excluded, then the
64648
+ * time left on an armed timed run;
64146
64649
  * - the trailing fact is the first of power, battery, consumables.
64147
64650
  *
64148
64651
  * `projectDeviceRow` is pure and computes nothing: it selects from a
64149
64652
  * {@link HeroModel}. A row that needed a value the hero lacks would mean the
64150
64653
  * model is missing it, so the fix goes in the model.
64151
64654
  */
64655
+ /**
64656
+ * The row's timed-run control. `id` is `timed-run.run` while idle and
64657
+ * `timed-run.cancel` while armed; `duration` and `unit` are the one-tap run
64658
+ * a Run press starts.
64659
+ */
64660
+ var HeroRowTimedRunSchema = zod.z.object({
64661
+ id: zod.z.enum(["timed-run.run", "timed-run.cancel"]),
64662
+ duration: zod.z.number(),
64663
+ unit: zod.z.enum(["min", "s"])
64664
+ });
64152
64665
  var HeroRowModelSchema = zod.z.object({
64153
64666
  deviceId: zod.z.number().int(),
64154
64667
  name: zod.z.string(),
@@ -64161,6 +64674,11 @@ var HeroRowModelSchema = zod.z.object({
64161
64674
  statusLine: zod.z.array(HeroTextSchema),
64162
64675
  /** `null` = the type has no inline control, or the caller may not act on it. */
64163
64676
  primary: HeroControlSchema.nullable(),
64677
+ /**
64678
+ * Beside `primary` when the device offers a timed run: Run while idle, Stop
64679
+ * while armed. `null` when there is no slot, or the caller may not act.
64680
+ */
64681
+ timedRun: HeroRowTimedRunSchema.nullable(),
64164
64682
  trailing: HeroFactSchema.nullable()
64165
64683
  });
64166
64684
  /** The trailing fact, in order of preference. */
@@ -64197,7 +64715,30 @@ function primaryOf(model) {
64197
64715
  return null;
64198
64716
  }
64199
64717
  function statusLineOf(model, trailing) {
64200
- return [model.rows.find((r) => r.id === "now-playing")?.status ?? null ?? model.title, ...model.facts.filter((f) => f !== trailing).map((f) => f.text).slice(0, 3)];
64718
+ const head = model.rows.find((r) => r.id === "now-playing")?.status ?? null ?? model.title;
64719
+ const rest = model.facts.filter((f) => f !== trailing).map((f) => f.text).slice(0, 3);
64720
+ const slot = model.timedRun;
64721
+ if (slot === null || slot.remaining === null) return [head, ...rest];
64722
+ const word = slot.quickRun.unit === "min" ? "min" : "s";
64723
+ const left = {
64724
+ en: `${slot.remaining} ${word}`,
64725
+ it: `${slot.remaining} ${word}`
64726
+ };
64727
+ return [
64728
+ head,
64729
+ ...rest,
64730
+ left
64731
+ ];
64732
+ }
64733
+ /** Run while the slot is idle, Stop while it is armed. Hidden when the caller may not act. */
64734
+ function timedRunOf(model) {
64735
+ const slot = model.timedRun;
64736
+ if (slot === null || model.gated.includes("timed-run")) return null;
64737
+ return {
64738
+ id: slot.activeUntil === null ? "timed-run.run" : "timed-run.cancel",
64739
+ duration: slot.quickRun.duration,
64740
+ unit: slot.quickRun.unit
64741
+ };
64201
64742
  }
64202
64743
  function projectDeviceRow(model) {
64203
64744
  const trailing = trailingOf(model.facts);
@@ -64211,6 +64752,7 @@ function projectDeviceRow(model) {
64211
64752
  scene: model.scene,
64212
64753
  statusLine: statusLineOf(model, trailing),
64213
64754
  primary: primaryOf(model),
64755
+ timedRun: timedRunOf(model),
64214
64756
  trailing
64215
64757
  };
64216
64758
  }
@@ -100524,10 +101066,14 @@ function timerTile(quickRun) {
100524
101066
  value: t(text, text)
100525
101067
  };
100526
101068
  }
101069
+ function remainingWords(amount, unit) {
101070
+ const word = unit === "min" ? "min" : "s";
101071
+ return t(`${amount} ${word}`, `${amount} ${word}`);
101072
+ }
100527
101073
  var timedRunContribution = contribution("timed-run", TimedRunStatusSchema, (slice, ctx) => {
100528
101074
  const type = deviceTypeOf(ctx.type);
100529
- const limit = type === void 0 ? void 0 : TIMED_RUN_LIMITS[type];
100530
- if (limit === void 0) return {};
101075
+ const limit = type === void 0 ? null : timedRunLimitOf(type);
101076
+ if (limit === null) return {};
100531
101077
  const quickRun = slice?.quickRun ?? timedRunQuickRun(limit, null);
100532
101078
  const activeUntil = slice?.activeUntil != null && slice.activeUntil > ctx.now ? slice.activeUntil : null;
100533
101079
  const runArgs = {
@@ -100537,11 +101083,12 @@ var timedRunContribution = contribution("timed-run", TimedRunStatusSchema, (slic
100537
101083
  const run = action("timed-run.run", t(`Run ${quickRun.duration} ${quickRun.unit}`, `Avvia ${quickRun.duration} ${quickRun.unit}`), "timer", "timed-run", "runFor", runArgs, "primary");
100538
101084
  const cancel = action("timed-run.cancel", t("Stop", "Ferma"), "timer-off", "timed-run", "cancel");
100539
101085
  const restart = action("timed-run.restart", t("Restart", "Riavvia"), "rotate-cw", "timed-run", "runFor", runArgs);
100540
- const left = activeUntil === null ? 0 : Math.max(1, Math.ceil((activeUntil - ctx.now) / 6e4));
101086
+ const remaining = activeUntil === null ? null : timedRunRemaining(activeUntil, ctx.now, quickRun.unit);
101087
+ const words = remaining === null ? null : remainingWords(remaining, quickRun.unit);
100541
101088
  const row = {
100542
101089
  id: "run-for",
100543
101090
  icon: "timer",
100544
- status: activeUntil === null ? t(`Run for ${quickRun.duration} ${quickRun.unit}`, `Avvia per ${quickRun.duration} ${quickRun.unit}`) : t(`Stops in ${left} min`, `Si ferma tra ${left} min`),
101091
+ status: words === null ? t(`Run for ${quickRun.duration} ${quickRun.unit}`, `Avvia per ${quickRun.duration} ${quickRun.unit}`) : t(`Stops in ${words.en}`, `Si ferma tra ${words.it}`),
100545
101092
  controls: activeUntil === null ? [asAction(run)] : [asAction(cancel), asAction(restart)]
100546
101093
  };
100547
101094
  const armed = activeUntil === null ? {} : { right: [timerTile(quickRun)] };
@@ -100550,7 +101097,8 @@ var timedRunContribution = contribution("timed-run", TimedRunStatusSchema, (slic
100550
101097
  activeUntil,
100551
101098
  quickRun,
100552
101099
  run,
100553
- cancel
101100
+ cancel,
101101
+ remaining
100554
101102
  },
100555
101103
  rows: [row],
100556
101104
  tilesFallback: true,
@@ -104214,6 +104762,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
104214
104762
  access: "create",
104215
104763
  role: "admin"
104216
104764
  },
104765
+ "deviceManager.checkDeviceTemplates": {
104766
+ capName: "device-manager",
104767
+ capScope: "system",
104768
+ addonId: null,
104769
+ access: "view",
104770
+ role: "admin"
104771
+ },
104217
104772
  "deviceManager.cleanupDeletedDevicesData": {
104218
104773
  capName: "device-manager",
104219
104774
  capScope: "system",
@@ -104613,6 +105168,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
104613
105168
  access: "create",
104614
105169
  role: "admin"
104615
105170
  },
105171
+ "deviceManager.renderDeviceTemplates": {
105172
+ capName: "device-manager",
105173
+ capScope: "system",
105174
+ addonId: null,
105175
+ access: "view",
105176
+ role: "admin"
105177
+ },
104616
105178
  "deviceManager.reportDiscoveryObservations": {
104617
105179
  capName: "device-manager",
104618
105180
  capScope: "system",
@@ -112529,7 +113091,6 @@ function offered(received) {
112529
113091
  };
112530
113092
  }
112531
113093
  offered(HA_AS), withheld(HOMEKIT_REASON), withheld(ALEXA_REASON), withheld(GOOGLE_REASON), withheld(MATTER_REASON);
112532
- zod.z.string().min(1).max(4096);
112533
113094
  /**
112534
113095
  * Runtime list of cap names with status. Used by the settings
112535
113096
  * aggregator to enumerate caps whose `status` should be polled +
@@ -116099,6 +116660,12 @@ var SESSION_ONLY_POLICY = {
116099
116660
  durability: "session",
116100
116661
  volatileFields: []
116101
116662
  };
116663
+ /**
116664
+ * The unit a composed-device field row offers convert-unit from (D941, D944).
116665
+ */
116666
+ function runtimeFieldUnit(cap, path) {
116667
+ return CAP_RUNTIME_FIELD_UNITS[cap]?.[path];
116668
+ }
116102
116669
  var G711_SCALE_CORRECTION_DB = {
116103
116670
  PCMU: 20 * Math.log10(4),
116104
116671
  PCMA: 20 * Math.log10(8)
@@ -118232,6 +118799,24 @@ Object.defineProperty(exports, "DEVICE_STATUS_METHOD", {
118232
118799
  return DEVICE_STATUS_METHOD;
118233
118800
  }
118234
118801
  });
118802
+ Object.defineProperty(exports, "DEVICE_TEMPLATE_FILTERS", {
118803
+ enumerable: true,
118804
+ get: function() {
118805
+ return DEVICE_TEMPLATE_FILTERS;
118806
+ }
118807
+ });
118808
+ Object.defineProperty(exports, "DEVICE_TEMPLATE_MAX_LENGTH", {
118809
+ enumerable: true,
118810
+ get: function() {
118811
+ return DEVICE_TEMPLATE_MAX_LENGTH;
118812
+ }
118813
+ });
118814
+ Object.defineProperty(exports, "DEVICE_TEMPLATE_MAX_OUTPUT", {
118815
+ enumerable: true,
118816
+ get: function() {
118817
+ return DEVICE_TEMPLATE_MAX_OUTPUT;
118818
+ }
118819
+ });
118235
118820
  Object.defineProperty(exports, "DEVICE_TOMBSTONE_RETENTION_MS", {
118236
118821
  enumerable: true,
118237
118822
  get: function() {
@@ -119144,6 +119729,12 @@ Object.defineProperty(exports, "cloneStatefulExpressionMemory", {
119144
119729
  return cloneStatefulExpressionMemory;
119145
119730
  }
119146
119731
  });
119732
+ Object.defineProperty(exports, "collectDeviceTemplates", {
119733
+ enumerable: true,
119734
+ get: function() {
119735
+ return collectDeviceTemplates;
119736
+ }
119737
+ });
119147
119738
  Object.defineProperty(exports, "collectSecretConfigKeys", {
119148
119739
  enumerable: true,
119149
119740
  get: function() {
@@ -119528,6 +120119,12 @@ Object.defineProperty(exports, "evaluateStatistic", {
119528
120119
  return evaluateStatistic;
119529
120120
  }
119530
120121
  });
120122
+ Object.defineProperty(exports, "evaluateStepCondition", {
120123
+ enumerable: true,
120124
+ get: function() {
120125
+ return evaluateStepCondition;
120126
+ }
120127
+ });
119531
120128
  Object.defineProperty(exports, "evaluateWhenTree", {
119532
120129
  enumerable: true,
119533
120130
  get: function() {
@@ -120428,6 +121025,12 @@ Object.defineProperty(exports, "resolveStepArgs", {
120428
121025
  return resolveStepArgs;
120429
121026
  }
120430
121027
  });
121028
+ Object.defineProperty(exports, "resolveTemplateRef", {
121029
+ enumerable: true,
121030
+ get: function() {
121031
+ return resolveTemplateRef;
121032
+ }
121033
+ });
120431
121034
  Object.defineProperty(exports, "runFanOut", {
120432
121035
  enumerable: true,
120433
121036
  get: function() {
@@ -120440,6 +121043,12 @@ Object.defineProperty(exports, "runSteps", {
120440
121043
  return runSteps;
120441
121044
  }
120442
121045
  });
121046
+ Object.defineProperty(exports, "runtimeFieldUnit", {
121047
+ enumerable: true,
121048
+ get: function() {
121049
+ return runtimeFieldUnit;
121050
+ }
121051
+ });
120443
121052
  Object.defineProperty(exports, "runtimeStatePolicyFor", {
120444
121053
  enumerable: true,
120445
121054
  get: function() {