@camstack/server 1.2.890 → 1.2.892

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 (119) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/trpc/generated-cap-mounts.js +2 -1
  3. package/dist/api/trpc/generated-cap-routers.js +212 -39
  4. package/dist/core/addon/addon-registry.service.js +47 -0
  5. package/dist/core/addon/retire-undeclared-fixed-integrations.js +57 -0
  6. package/package.json +31 -19
  7. package/system/dist/addon-runner.js +25 -9
  8. package/system/dist/addon-runner.mjs +25 -9
  9. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  10. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  11. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  12. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  13. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  14. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  15. package/system/dist/builtins/autotrack/index.js +1 -1
  16. package/system/dist/builtins/autotrack/index.mjs +1 -1
  17. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  18. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  19. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  20. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  21. package/system/dist/builtins/camera-grid/addon.d.ts +65 -41
  22. package/system/dist/builtins/camera-grid/grid-blocks.d.ts +51 -0
  23. package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +4 -3
  24. package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +3 -1
  25. package/system/dist/builtins/camera-grid/grid-plan.d.ts +3 -3
  26. package/system/dist/builtins/camera-grid/index.d.ts +2 -6
  27. package/system/dist/builtins/camera-grid/index.js +431 -727
  28. package/system/dist/builtins/camera-grid/index.mjs +428 -719
  29. package/system/dist/builtins/composer/composed-device.d.ts +12 -2
  30. package/system/dist/builtins/composer/composer.addon.js +28 -10
  31. package/system/dist/builtins/composer/composer.addon.mjs +28 -10
  32. package/system/dist/builtins/composer/composition-declarations.d.ts +3 -1
  33. package/system/dist/builtins/console-logging/index.js +1 -1
  34. package/system/dist/builtins/console-logging/index.mjs +1 -1
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.js +283 -51
  36. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +284 -52
  37. package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +19 -1
  38. package/system/dist/builtins/core-blocks/power-source-devices.d.ts +9 -0
  39. package/system/dist/builtins/core-blocks/power-source-service.d.ts +39 -2
  40. package/system/dist/builtins/core-blocks/tags-service.d.ts +20 -3
  41. package/system/dist/builtins/core-blocks/tags-wiring.d.ts +15 -2
  42. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  43. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  44. package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
  45. package/system/dist/builtins/device-manager/device-manager.addon.js +172 -5
  46. package/system/dist/builtins/device-manager/device-manager.addon.mjs +172 -5
  47. package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
  48. package/system/dist/builtins/device-manager/device-row-store.d.ts +3 -2
  49. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
  50. package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -0
  51. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  52. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  53. package/system/dist/builtins/keychain/index.js +4 -4
  54. package/system/dist/builtins/keychain/index.mjs +4 -4
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  56. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  57. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  58. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  60. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  61. package/system/dist/builtins/loki-logging/index.js +1 -1
  62. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  64. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  65. package/system/dist/builtins/platform-probe/index.js +1 -1
  66. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  67. package/system/dist/builtins/record-entries/index.js +1 -1
  68. package/system/dist/builtins/record-entries/index.mjs +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  70. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  71. package/system/dist/builtins/snapshot/index.js +1 -1
  72. package/system/dist/builtins/snapshot/index.mjs +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  74. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  76. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  80. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  81. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  82. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  83. package/system/dist/builtins/winston-logging/index.js +1 -1
  84. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  85. package/system/dist/{capture-engine-C1vdBL88.js → capture-engine-DHmlkW_d.js} +1 -1
  86. package/system/dist/{capture-engine-B1bMuzVX.mjs → capture-engine-sl6e9f9S.mjs} +1 -1
  87. package/system/dist/{composition-sources-Dj6qn5PP.mjs → composition-sources-CznD85Ri.mjs} +1 -1
  88. package/system/dist/{composition-sources-BfLlyKRe.js → composition-sources-PqcZfe3j.js} +1 -1
  89. package/system/dist/{constants-Ba51ywI4.mjs → constants-CHwj_mIM.mjs} +1 -1
  90. package/system/dist/{constants-DuB_xXYx.js → constants-_2SOk0By.js} +1 -1
  91. package/system/dist/{device-ca-CkXjf3ms.mjs → device-ca-D2H1EMUY.mjs} +1 -1
  92. package/system/dist/{device-ca-CVjaotgX.js → device-ca-WIEO5ZcE.js} +1 -1
  93. package/system/dist/{dist-BKojK6Wf.mjs → dist-DbAhCrHy.mjs} +2468 -454
  94. package/system/dist/{dist-BjhII4Uq.js → dist-yx2KHo3b.js} +2575 -453
  95. package/system/dist/file-host-worker.js +1 -1
  96. package/system/dist/file-host-worker.mjs +1 -1
  97. package/system/dist/{hub-identity-C0qf888i.mjs → hub-identity-BcvZqT0L.mjs} +1 -1
  98. package/system/dist/{hub-identity-C0ehkt78.js → hub-identity-Buegac-w.js} +1 -1
  99. package/system/dist/{hub-mdns-ciao-BYe34S2Q.mjs → hub-mdns-ciao-B6K_dO2s.mjs} +2 -2
  100. package/system/dist/{hub-mdns-ciao-DJHjyjvT.js → hub-mdns-ciao-DcNPj7WJ.js} +2 -2
  101. package/system/dist/index.js +33 -19
  102. package/system/dist/index.mjs +33 -19
  103. package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
  104. package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
  105. package/system/dist/{legacy-integration-rows-door-G6EceE_J.js → legacy-integration-rows-door-BsZyVNiR.js} +1 -1
  106. package/system/dist/{legacy-integration-rows-door-BEYgXSXr.mjs → legacy-integration-rows-door-DHOJeDPG.mjs} +1 -1
  107. package/system/dist/{rename-composition-block-D1mO51F9.js → rename-composition-block-BXMor7MR.js} +1 -1
  108. package/system/dist/{rename-composition-block-D6bq3Twf.mjs → rename-composition-block-DcVS1LuC.mjs} +1 -1
  109. package/system/dist/{restore-archive-FXsCWq_f.mjs → restore-archive-BG8VJ8Ar.mjs} +82 -82
  110. package/system/dist/{restore-archive-CJvMq13C.js → restore-archive-BURufVQd.js} +1 -1
  111. package/system/dist/{wal-maintenance-Ci9Dl-lB.mjs → wal-maintenance-B4wGD6QR.mjs} +0 -0
  112. package/system/dist/{wal-maintenance-COJ_JxrD.js → wal-maintenance-CeaJyKNT.js} +0 -0
  113. package/system/package.json +2 -5
  114. package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
  115. package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
  116. package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
  117. package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
  118. package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
  119. package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("../../chunk-Cek0wNdY.js");
3
- const require_dist = require("../../dist-BjhII4Uq.js");
3
+ const require_dist = require("../../dist-yx2KHo3b.js");
4
4
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
5
- const require_composition_sources = require("../../composition-sources-BfLlyKRe.js");
6
- const require_capture_engine = require("../../capture-engine-C1vdBL88.js");
5
+ const require_composition_sources = require("../../composition-sources-PqcZfe3j.js");
6
+ const require_capture_engine = require("../../capture-engine-DHmlkW_d.js");
7
7
  const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
8
8
  const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
9
9
  const require_cap_call_scope = require("../../cap-call-scope-8eiugfLl.js");
@@ -4111,10 +4111,23 @@ function buildActionsRuntime(deps) {
4111
4111
  * The link and the off time are read from the STORED composition on each call
4112
4112
  * (D676), never cached as a second copy. A forced restart is switch off now,
4113
4113
  * switch on after `offSeconds`, through an injected scheduler so a spec drives
4114
- * the clock; the pending switch-on is cancelled on `stop()`.
4114
+ * the clock; the pending switch-on is cancelled on `stop()`. A switch that declares
4115
+ * a native power cycle (a PoE port) is cycled in one call instead, and never
4116
+ * switched off or on. A switch that ANSWERED it only reports (D1058) is never
4117
+ * switched on or off: power on / off are refused as `not-settable`, and `getStatus`
4118
+ * says so (`switchSettable`) for the surfaces that withdraw them.
4115
4119
  *
4116
4120
  * Every refusal is a typed result with its reason, logged with the device tag.
4117
4121
  */
4122
+ /** `switch.getOptions` FAILED (not absent): what the switch can do is unknown. */
4123
+ var SwitchOptionsUnreadableError = class extends Error {
4124
+ switchDeviceId;
4125
+ constructor(switchDeviceId, cause) {
4126
+ super(`switch ${switchDeviceId}: its options could not be read (${cause instanceof Error ? cause.message : String(cause)}); not power-cycling and not switching it off blind`);
4127
+ this.name = "SwitchOptionsUnreadableError";
4128
+ this.switchDeviceId = switchDeviceId;
4129
+ }
4130
+ };
4118
4131
  var timeoutScheduler = { schedule: (delayMs, fire) => {
4119
4132
  const handle = setTimeout(fire, delayMs);
4120
4133
  return { cancel: () => clearTimeout(handle) };
@@ -4124,28 +4137,40 @@ var PowerSourceService = class {
4124
4137
  deps;
4125
4138
  /** Restarts whose switch-on has not run yet, by device id. */
4126
4139
  restarting = /* @__PURE__ */ new Map();
4140
+ /**
4141
+ * Devices whose switch-options read is failing now: warned once per streak, cleared by a
4142
+ * success or when the device is no longer linked. A removed device leaves at most one bare id
4143
+ * behind (this service has no removal hook); the set dies with the process.
4144
+ */
4145
+ optionsReadFailing = /* @__PURE__ */ new Set();
4127
4146
  constructor(deps) {
4128
4147
  this.deps = deps;
4129
4148
  }
4130
4149
  getStatus = async ({ deviceId }) => {
4131
4150
  const link = await this.linkOf(deviceId);
4132
- if (link === null) return {
4133
- linked: false,
4134
- switchDeviceId: null,
4135
- switchName: null,
4136
- switchOn: null,
4137
- switchOnline: null,
4138
- restartInProgress: false,
4139
- offSeconds: 0
4140
- };
4151
+ if (link === null) {
4152
+ this.optionsReadFailing.delete(deviceId);
4153
+ return {
4154
+ linked: false,
4155
+ switchDeviceId: null,
4156
+ switchName: null,
4157
+ switchOn: null,
4158
+ switchOnline: null,
4159
+ switchSettable: null,
4160
+ restartInProgress: false,
4161
+ offSeconds: 0
4162
+ };
4163
+ }
4141
4164
  const switchDevice = await this.deps.devices.find(link.switch).catch(() => null);
4142
4165
  const switchOn = switchDevice === null ? null : await this.deps.devices.readOn(switchDevice.id).catch(() => null);
4166
+ const switchSettable = switchDevice === null ? null : await this.settableOf(deviceId, switchDevice.id);
4143
4167
  return {
4144
4168
  linked: true,
4145
4169
  switchDeviceId: switchDevice?.id ?? null,
4146
4170
  switchName: switchDevice?.name ?? link.switch.stableId,
4147
4171
  switchOn,
4148
4172
  switchOnline: switchDevice?.online ?? null,
4173
+ switchSettable,
4149
4174
  restartInProgress: this.restarting.has(deviceId),
4150
4175
  offSeconds: link.offSeconds
4151
4176
  };
@@ -4167,6 +4192,28 @@ var PowerSourceService = class {
4167
4192
  const { link, switchDevice } = lookup.resolved;
4168
4193
  const switchId = switchDevice.id;
4169
4194
  pending.switchId = switchId;
4195
+ const cycle = this.deps.devices.cycle;
4196
+ if (cycle !== void 0) {
4197
+ let cycled;
4198
+ try {
4199
+ cycled = await cycle(switchId);
4200
+ } catch (err) {
4201
+ this.restarting.delete(deviceId);
4202
+ const reason = err instanceof SwitchOptionsUnreadableError ? "switch-options-unreadable" : "switch-call-failed";
4203
+ return this.refuse(deviceId, reason, errorText$3(err), switchId);
4204
+ }
4205
+ if (cycled) {
4206
+ this.restarting.delete(deviceId);
4207
+ this.deps.logger.info("power-source: forced restart through the switch’s native power cycle", {
4208
+ tags: { deviceId },
4209
+ meta: {
4210
+ switchId,
4211
+ switchName: switchDevice.name
4212
+ }
4213
+ });
4214
+ return ACCEPTED;
4215
+ }
4216
+ }
4170
4217
  try {
4171
4218
  await this.deps.devices.setOn(switchId, false);
4172
4219
  } catch (err) {
@@ -4221,6 +4268,7 @@ var PowerSourceService = class {
4221
4268
  const lookup = await this.lookup(deviceId);
4222
4269
  if (lookup.kind === "refused") return this.refuse(deviceId, lookup.reason, lookup.message, null);
4223
4270
  const { switchDevice } = lookup.resolved;
4271
+ if (await this.settableOf(deviceId, switchDevice.id) === false) return this.refuse(deviceId, "not-settable", `the switch ${switchDevice.name} only reports its state; it cannot be switched ${on ? "on" : "off"}`, switchDevice.id);
4224
4272
  try {
4225
4273
  await this.deps.devices.setOn(switchDevice.id, on);
4226
4274
  } catch (err) {
@@ -4235,6 +4283,32 @@ var PowerSourceService = class {
4235
4283
  });
4236
4284
  return ACCEPTED;
4237
4285
  }
4286
+ /**
4287
+ * Whether the switch can be set: `true` for a plain switch (no options reader, or a provider
4288
+ * without `getOptions`), `null` when the read FAILED — never `false` for unknown. Every hero
4289
+ * build reads `getStatus`, so a failing read warns once per device per failure streak (tagged);
4290
+ * a successful read ends the streak.
4291
+ */
4292
+ async settableOf(deviceId, switchId) {
4293
+ const options = this.deps.devices.options;
4294
+ if (options === void 0) return true;
4295
+ try {
4296
+ const settable = (await options(switchId)).supportsSetState;
4297
+ this.optionsReadFailing.delete(deviceId);
4298
+ return settable;
4299
+ } catch (err) {
4300
+ if (this.optionsReadFailing.has(deviceId)) return null;
4301
+ this.optionsReadFailing.add(deviceId);
4302
+ this.deps.logger.warn("power-source: the switch options could not be read; settable unknown", {
4303
+ tags: { deviceId },
4304
+ meta: {
4305
+ switchId,
4306
+ error: errorText$3(err)
4307
+ }
4308
+ });
4309
+ return null;
4310
+ }
4311
+ }
4238
4312
  /** The link and the switch, or the reason there is nothing to act on. Reads the switch state: unknown is refused. */
4239
4313
  async lookup(deviceId) {
4240
4314
  const stored = await this.storedLinkOf(deviceId);
@@ -6207,6 +6281,8 @@ var RemoteComponentsService = class {
6207
6281
  * count comes from the remote cap and is `null` when it cannot be asked.
6208
6282
  */
6209
6283
  var REMOTE_CAP = "remote";
6284
+ var SWITCH_CAP = "switch";
6285
+ var POWER_SOURCE_CAP = "power-source";
6210
6286
  /** Models built at once for a list; the cap bounds the list, this bounds the fan-out on the registry. */
6211
6287
  var ROW_MODELS_CONCURRENCY = 16;
6212
6288
  var HeroLayoutService = class {
@@ -6241,6 +6317,8 @@ var HeroLayoutService = class {
6241
6317
  }
6242
6318
  }));
6243
6319
  const remoteCommands = await this.remoteCommands(deviceId);
6320
+ const switchOptions = bound.includes(SWITCH_CAP) ? await this.switchOptions(deviceId) : void 0;
6321
+ const powerSupplySettable = bound.includes(POWER_SOURCE_CAP) ? await this.powerSupplySettable(deviceId) : null;
6244
6322
  return require_dist.buildHeroModel({
6245
6323
  device: {
6246
6324
  id: deviceId,
@@ -6256,7 +6334,9 @@ var HeroLayoutService = class {
6256
6334
  slices,
6257
6335
  now: this.deps.now(),
6258
6336
  remoteCommands,
6259
- access: { canActuate: canActuate ?? true }
6337
+ access: { canActuate: canActuate ?? true },
6338
+ ...switchOptions !== void 0 ? { switchOptions } : {},
6339
+ powerSupplySettable
6260
6340
  });
6261
6341
  };
6262
6342
  /**
@@ -6289,6 +6369,34 @@ var HeroLayoutService = class {
6289
6369
  return null;
6290
6370
  }
6291
6371
  }
6372
+ /**
6373
+ * What the switch can do. A provider without `getOptions` answers the defaults through the
6374
+ * reader; a read that FAILED is unknown — the hero draws on/off, as before (D315) — and is
6375
+ * logged with the device.
6376
+ */
6377
+ async switchOptions(deviceId) {
6378
+ try {
6379
+ return await this.deps.reader.switchOptions(deviceId);
6380
+ } catch (error) {
6381
+ this.deps.logger.warn("hero model: the switch options could not be read; on/off drawn", {
6382
+ tags: { deviceId },
6383
+ meta: { error: error instanceof Error ? error.message : String(error) }
6384
+ });
6385
+ return;
6386
+ }
6387
+ }
6388
+ /** Whether the supply's switch can be set; a failed read is unknown (on/off drawn), logged. */
6389
+ async powerSupplySettable(deviceId) {
6390
+ try {
6391
+ return await this.deps.reader.powerSupplySettable(deviceId);
6392
+ } catch (error) {
6393
+ this.deps.logger.warn("hero model: the power supply status could not be read; power on/off drawn", {
6394
+ tags: { deviceId },
6395
+ meta: { error: error instanceof Error ? error.message : String(error) }
6396
+ });
6397
+ return null;
6398
+ }
6399
+ }
6292
6400
  async remoteCommands(deviceId) {
6293
6401
  try {
6294
6402
  return await this.deps.reader.remoteCommands(deviceId);
@@ -6413,6 +6521,54 @@ async function seedLockDoors(deps) {
6413
6521
  }
6414
6522
  }
6415
6523
  //#endregion
6524
+ //#region src/builtins/core-blocks/power-source-devices.ts
6525
+ /**
6526
+ * The devices `power-source` acts on, reached over `ctx.api`: the linked switch is read,
6527
+ * set, and — when its provider declares a native power cycle — cycled in one call.
6528
+ */
6529
+ /** The switch's options; the defaults when its provider has no `getOptions`; throws typed when the read failed. */
6530
+ async function switchOptionsOf(api, deviceId) {
6531
+ try {
6532
+ return await api.switch.getOptions.query({ deviceId });
6533
+ } catch (err) {
6534
+ if ((0, _camstack_types_addon.isCapMethodAbsent)(err)) return require_dist.SWITCH_DEFAULT_OPTIONS;
6535
+ throw new SwitchOptionsUnreadableError(deviceId, err);
6536
+ }
6537
+ }
6538
+ function powerSourceDevicesOver(requireApi) {
6539
+ return {
6540
+ find: async (ref) => {
6541
+ const row = (await requireApi().deviceManager.listAll.query({
6542
+ addonId: ref.addonId,
6543
+ projection: "slim"
6544
+ })).find((r) => r.stableId === ref.stableId);
6545
+ return row === void 0 ? null : {
6546
+ id: row.id,
6547
+ name: row.name,
6548
+ online: row.online
6549
+ };
6550
+ },
6551
+ readOn: async (deviceId) => {
6552
+ const status = await requireApi().switch.getStatus.query({ deviceId });
6553
+ const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
6554
+ return typeof on === "boolean" ? on : null;
6555
+ },
6556
+ setOn: async (deviceId, on) => {
6557
+ await requireApi().switch.setState.mutate({
6558
+ deviceId,
6559
+ on
6560
+ });
6561
+ },
6562
+ options: (deviceId) => switchOptionsOf(requireApi(), deviceId),
6563
+ cycle: async (deviceId) => {
6564
+ const api = requireApi();
6565
+ if (!(await switchOptionsOf(api, deviceId)).supportsPowerCycle) return false;
6566
+ await api.switch.powerCycle.mutate({ deviceId });
6567
+ return true;
6568
+ }
6569
+ };
6570
+ }
6571
+ //#endregion
6416
6572
  //#region src/builtins/core-blocks/fan-link-forward.ts
6417
6573
  /**
6418
6574
  * A write to a fan-control field the operator linked in Customize goes to the
@@ -9257,14 +9413,16 @@ async function writeComposedDeviceName(port, logger, blockId, name) {
9257
9413
  //#region src/builtins/core-blocks/tags-service.ts
9258
9414
  /**
9259
9415
  * The `tags` cap (D1054). A tag lives on the record it labels — a core block, a
9260
- * scheduler, a template, an action, a device — and only its STYLE (colour token,
9261
- * icon) is registered here. This service is the one place that knows every owner
9416
+ * scheduler, a template, an action, a device, a notification rule — and only
9417
+ * its STYLE (colour token, icon) is registered here. This service is the one place that knows every owner
9262
9418
  * kind, so `rename` and `remove` are ONE server operation that rewrites all of
9263
9419
  * them; the browser never drives that sequence (a closed tab would split the
9264
9420
  * fleet across two spellings).
9265
9421
  *
9266
9422
  * Owners are reached through {@link TagOwnerPort}s: the local stores directly,
9267
- * the devices through the device manager over `ctx.api` — never a second copy.
9423
+ * the devices and notification rules through their caps over `ctx.api` — never
9424
+ * a second copy. An owner that cannot be read degrades `list` (its count is
9425
+ * `null`) and refuses `rename` / `remove` before any write.
9268
9426
  * Tags compare trimmed and case-insensitively (`sameTag`).
9269
9427
  */
9270
9428
  /** The order owners are read and rewritten in; also the order a first spelling is picked. */
@@ -9273,14 +9431,39 @@ var OWNER_KINDS = [
9273
9431
  "schedulers",
9274
9432
  "templates",
9275
9433
  "actions",
9276
- "devices"
9434
+ "devices",
9435
+ "notificationRules"
9277
9436
  ];
9437
+ /** The list counts: an owner that could not be read is `null`, never `0` (D393). */
9438
+ function withUnknown(counts, unreachable) {
9439
+ return {
9440
+ coreBlocks: unreachable.has("coreBlocks") ? null : counts.coreBlocks,
9441
+ schedulers: unreachable.has("schedulers") ? null : counts.schedulers,
9442
+ templates: unreachable.has("templates") ? null : counts.templates,
9443
+ actions: unreachable.has("actions") ? null : counts.actions,
9444
+ devices: unreachable.has("devices") ? null : counts.devices,
9445
+ notificationRules: unreachable.has("notificationRules") ? null : counts.notificationRules
9446
+ };
9447
+ }
9448
+ /**
9449
+ * A rename or remove refused because one owner kind could not be read. Nothing
9450
+ * was written; `owner` names which one, so the operator knows what to bring back.
9451
+ */
9452
+ var TagOwnerUnreachableError = class extends Error {
9453
+ owner;
9454
+ name = "TagOwnerUnreachableError";
9455
+ constructor(owner, tag, cause) {
9456
+ super(`[tags] "${tag}" was not changed anywhere: the ${owner} owner could not be read (${cause instanceof Error ? cause.message : String(cause)}); nothing was written — retry once it is back`, { cause });
9457
+ this.owner = owner;
9458
+ }
9459
+ };
9278
9460
  var NO_UPDATES = {
9279
9461
  coreBlocks: 0,
9280
9462
  schedulers: 0,
9281
9463
  templates: 0,
9282
9464
  actions: 0,
9283
- devices: 0
9465
+ devices: 0,
9466
+ notificationRules: 0
9284
9467
  };
9285
9468
  function requireName(value, what) {
9286
9469
  const parsed = require_dist.TagNameSchema.safeParse(value);
@@ -9304,12 +9487,27 @@ var TagsService = class {
9304
9487
  }
9305
9488
  list = async () => {
9306
9489
  const styles = new Map((await this.readStyles()).map((s) => [require_dist.tagKey(s.name), s]));
9490
+ const unreachable = /* @__PURE__ */ new Set();
9491
+ const read = [];
9492
+ for (const kind of OWNER_KINDS) try {
9493
+ read.push({
9494
+ kind,
9495
+ records: await this.deps.owners[kind].list()
9496
+ });
9497
+ } catch (err) {
9498
+ unreachable.add(kind);
9499
+ this.deps.logger.warn("tag owner could not be read — its count is unknown on this list", { meta: {
9500
+ owner: kind,
9501
+ error: err instanceof Error ? err.message : String(err)
9502
+ } });
9503
+ }
9504
+ const zero = () => ({ ...NO_UPDATES });
9307
9505
  const entries = /* @__PURE__ */ new Map();
9308
9506
  for (const style of styles.values()) entries.set(require_dist.tagKey(style.name), {
9309
9507
  name: style.name,
9310
- counts: { ...NO_UPDATES }
9508
+ counts: zero()
9311
9509
  });
9312
- for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
9510
+ for (const { kind, records } of read) for (const record of records) {
9313
9511
  const seen = /* @__PURE__ */ new Set();
9314
9512
  for (const tag of record.tags) {
9315
9513
  const key = require_dist.tagKey(tag);
@@ -9317,7 +9515,7 @@ var TagsService = class {
9317
9515
  seen.add(key);
9318
9516
  const entry = entries.get(key) ?? {
9319
9517
  name: tag.trim(),
9320
- counts: { ...NO_UPDATES }
9518
+ counts: zero()
9321
9519
  };
9322
9520
  entry.counts[kind] += 1;
9323
9521
  entries.set(key, entry);
@@ -9331,7 +9529,7 @@ var TagsService = class {
9331
9529
  color: style?.color ?? require_dist.defaultTagColorId(entry.name),
9332
9530
  icon: style?.icon ?? "tag",
9333
9531
  styled: style !== void 0,
9334
- counts: entry.counts
9532
+ counts: withUnknown(entry.counts, unreachable)
9335
9533
  });
9336
9534
  }
9337
9535
  return out.toSorted((a, b) => a.name.localeCompare(b.name));
@@ -9379,7 +9577,7 @@ var TagsService = class {
9379
9577
  const updated = { ...NO_UPDATES };
9380
9578
  const failed = [];
9381
9579
  const plan = [];
9382
- for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
9580
+ for (const kind of OWNER_KINDS) for (const record of await this.readOwnerOrRefuse(kind, tag)) {
9383
9581
  const next = change(record.tags);
9384
9582
  if (next === null) continue;
9385
9583
  if (next.length > 20) throw new Error(`[tags] "${tag}" cannot be applied: ${kind}:${record.id} would carry ${next.length} tags (max 20); nothing was written`);
@@ -9408,6 +9606,18 @@ var TagsService = class {
9408
9606
  if (failed.length > 0) throw new Error(`[tags] "${tag}" was not rewritten on ${failed.length} record(s) (${failed.slice(0, 5).join(", ")}); the style was left alone — repeat the call`);
9409
9607
  return updated;
9410
9608
  }
9609
+ /**
9610
+ * An owner's records for a rewrite. One that cannot be read refuses the whole
9611
+ * call BEFORE anything is written: a rename applied to only some owners would
9612
+ * leave the fleet split across two spellings.
9613
+ */
9614
+ async readOwnerOrRefuse(kind, tag) {
9615
+ try {
9616
+ return await this.deps.owners[kind].list();
9617
+ } catch (err) {
9618
+ throw new TagOwnerUnreachableError(kind, tag, err);
9619
+ }
9620
+ }
9411
9621
  /** The style follows the tag; a merge onto a styled target keeps the TARGET's style. */
9412
9622
  async moveStyle(from, to) {
9413
9623
  const fromKey = require_dist.tagKey(from);
@@ -9438,7 +9648,8 @@ var TagsService = class {
9438
9648
  //#region src/builtins/core-blocks/tags-wiring.ts
9439
9649
  /**
9440
9650
  * Builds the `tags` cap provider (D1054) over the stores core-blocks owns and the
9441
- * device manager (over `ctx.api`, never a copy of its data).
9651
+ * device manager and the notification rules (over `ctx.api`, never a copy of
9652
+ * their data).
9442
9653
  */
9443
9654
  function coreBlocksPort(blocks) {
9444
9655
  return {
@@ -9520,6 +9731,47 @@ function devicesPort(api) {
9520
9731
  }
9521
9732
  };
9522
9733
  }
9734
+ function needApi(api) {
9735
+ const current = api();
9736
+ if (current === void 0) throw new Error("[tags] the cluster API is not available yet");
9737
+ return current;
9738
+ }
9739
+ /**
9740
+ * A notification rule's owner-port id is `<kind>:<ruleId>`: event rules,
9741
+ * summaries, timelapses and calendar-events rules live in separate stores, so
9742
+ * the write must name which one.
9743
+ */
9744
+ function ruleTagOwnerId(kind, ruleId) {
9745
+ return `${kind}:${ruleId}`;
9746
+ }
9747
+ function parseRuleTagOwnerId(id) {
9748
+ const sep = id.indexOf(":");
9749
+ const kind = require_dist.NcTaggedRuleKindSchema.safeParse(sep < 0 ? "" : id.slice(0, sep));
9750
+ if (!kind.success) throw new Error(`[tags] not a notification-rule owner id: ${id}`);
9751
+ return {
9752
+ kind: kind.data,
9753
+ ruleId: id.slice(sep + 1)
9754
+ };
9755
+ }
9756
+ function notificationRulesPort(api) {
9757
+ return {
9758
+ list: async () => {
9759
+ const { rules } = await needApi(api).notificationRules.listRuleTags.query({});
9760
+ return rules.map((r) => ({
9761
+ id: ruleTagOwnerId(r.kind, r.ruleId),
9762
+ tags: r.tags
9763
+ }));
9764
+ },
9765
+ setTags: async (id, tags) => {
9766
+ const { kind, ruleId } = parseRuleTagOwnerId(id);
9767
+ await needApi(api).notificationRules.setRuleTags.mutate({
9768
+ kind,
9769
+ ruleId,
9770
+ tags
9771
+ });
9772
+ }
9773
+ };
9774
+ }
9523
9775
  function buildTagsService(deps) {
9524
9776
  const { records } = deps;
9525
9777
  return new TagsService({
@@ -9534,7 +9786,8 @@ function buildTagsService(deps) {
9534
9786
  actions: records.kind(coreBlocksRecordKinds.actions),
9535
9787
  links: records.kind(coreBlocksRecordKinds["action-links"])
9536
9788
  })),
9537
- devices: deps.devices ?? devicesPort(deps.api)
9789
+ devices: deps.devices ?? devicesPort(deps.api),
9790
+ notificationRules: deps.notificationRules ?? notificationRulesPort(deps.api)
9538
9791
  },
9539
9792
  styles: records.kind(coreBlocksRecordKinds["tag-styles"]),
9540
9793
  logger: deps.logger
@@ -9809,7 +10062,9 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
9809
10062
  deviceId,
9810
10063
  capName
9811
10064
  }),
9812
- remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length
10065
+ remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length,
10066
+ switchOptions: (deviceId) => switchOptionsOf(requireApi(), deviceId),
10067
+ powerSupplySettable: async (deviceId) => (await requireApi().powerSource.getStatus.query({ deviceId })).switchSettable ?? null
9813
10068
  }
9814
10069
  });
9815
10070
  }
@@ -9829,30 +10084,7 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
9829
10084
  if (!api) throw new Error("core-blocks: no ctx.api on this node — power-source cannot reach devices");
9830
10085
  return api;
9831
10086
  };
9832
- return {
9833
- find: async (ref) => {
9834
- const row = (await requireApi().deviceManager.listAll.query({
9835
- addonId: ref.addonId,
9836
- projection: "slim"
9837
- })).find((r) => r.stableId === ref.stableId);
9838
- return row === void 0 ? null : {
9839
- id: row.id,
9840
- name: row.name,
9841
- online: row.online
9842
- };
9843
- },
9844
- readOn: async (deviceId) => {
9845
- const status = await requireApi().switch.getStatus.query({ deviceId });
9846
- const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
9847
- return typeof on === "boolean" ? on : null;
9848
- },
9849
- setOn: async (deviceId, on) => {
9850
- await requireApi().switch.setState.mutate({
9851
- deviceId,
9852
- on
9853
- });
9854
- }
9855
- };
10087
+ return powerSourceDevicesOver(requireApi);
9856
10088
  }
9857
10089
  buildRemote(records) {
9858
10090
  const settings = this.ctx.settings;