@camstack/server 1.2.876 → 1.2.878

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 (105) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/trpc/generated-cap-mounts.js +2 -1
  3. package/dist/api/trpc/generated-cap-routers.js +308 -256
  4. package/package.json +10 -9
  5. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/system/dist/builtins/autotrack/index.js +1 -1
  12. package/system/dist/builtins/autotrack/index.mjs +1 -1
  13. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  15. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  16. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  17. package/system/dist/builtins/camera-grid/index.js +1 -1
  18. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  19. package/system/dist/builtins/composer/composer.addon.js +4 -4
  20. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  21. package/system/dist/builtins/console-logging/index.js +1 -1
  22. package/system/dist/builtins/console-logging/index.mjs +1 -1
  23. package/system/dist/builtins/core-blocks/actions-store.d.ts +2 -0
  24. package/system/dist/builtins/core-blocks/core-block-store.d.ts +6 -0
  25. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +3 -0
  26. package/system/dist/builtins/core-blocks/core-blocks.addon.js +410 -9
  27. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +410 -9
  28. package/system/dist/builtins/core-blocks/record-kinds.d.ts +11 -1
  29. package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +6 -0
  30. package/system/dist/builtins/core-blocks/tags-service.d.ts +50 -0
  31. package/system/dist/builtins/core-blocks/tags-wiring.d.ts +16 -0
  32. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  33. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  34. package/system/dist/builtins/device-manager/device-manager.addon.js +59 -5
  35. package/system/dist/builtins/device-manager/device-manager.addon.mjs +59 -5
  36. package/system/dist/builtins/device-manager/device-meta-actions.d.ts +6 -0
  37. package/system/dist/builtins/device-manager/device-meta-types.d.ts +2 -0
  38. package/system/dist/builtins/device-manager/device-row-store.d.ts +1 -0
  39. package/system/dist/builtins/device-manager/device-template/template-grammar.d.ts +15 -1
  40. package/system/dist/builtins/device-manager/device-template/template-protocol.d.ts +8 -0
  41. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  42. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  43. package/system/dist/builtins/keychain/index.js +4 -4
  44. package/system/dist/builtins/keychain/index.mjs +4 -4
  45. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  46. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  47. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  48. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  49. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  50. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  51. package/system/dist/builtins/loki-logging/index.js +1 -1
  52. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  53. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  54. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  55. package/system/dist/builtins/platform-probe/index.js +1 -1
  56. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  57. package/system/dist/builtins/record-entries/index.js +1 -1
  58. package/system/dist/builtins/record-entries/index.mjs +1 -1
  59. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  60. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  61. package/system/dist/builtins/snapshot/index.js +1 -1
  62. package/system/dist/builtins/snapshot/index.mjs +1 -1
  63. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  64. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  65. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  66. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  67. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  68. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  69. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  70. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  71. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  72. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  73. package/system/dist/builtins/winston-logging/index.js +1 -1
  74. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  75. package/system/dist/{capture-engine-DtuMWHR3.js → capture-engine-DAGmlBmJ.js} +1 -1
  76. package/system/dist/{capture-engine-Bao8AioF.mjs → capture-engine-vlouhBCY.mjs} +1 -1
  77. package/system/dist/{composition-sources-DPSSQaGb.js → composition-sources-Rm8xDXjA.js} +1 -1
  78. package/system/dist/{composition-sources-CCoQYZna.mjs → composition-sources-TeHa4THk.mjs} +1 -1
  79. package/system/dist/{constants-BQNuuICz.mjs → constants-Bq1Xl_Ku.mjs} +1 -1
  80. package/system/dist/{constants-wcqPhWGp.js → constants-DnUpXvIY.js} +1 -1
  81. package/system/dist/{device-ca-CDsYbRF8.js → device-ca-DMudhY-2.js} +1 -1
  82. package/system/dist/{device-ca-DvK5zoNx.mjs → device-ca-yHLgyutP.mjs} +1 -1
  83. package/system/dist/device-template-worker.js +26 -3
  84. package/system/dist/device-template-worker.mjs +26 -3
  85. package/system/dist/{dist-CdW0TjIj.js → dist-Bh5JIimH.js} +1704 -1178
  86. package/system/dist/{dist-DcH8pKL-.mjs → dist-DemZNuSJ.mjs} +1651 -1179
  87. package/system/dist/file-host-worker.js +1 -1
  88. package/system/dist/file-host-worker.mjs +1 -1
  89. package/system/dist/{hub-identity-DOyLUW_7.mjs → hub-identity-BxaJKDQk.mjs} +1 -1
  90. package/system/dist/{hub-identity-BRxxw7hh.js → hub-identity-YfGdAaBm.js} +1 -1
  91. package/system/dist/{hub-mdns-ciao-lO2BAONK.js → hub-mdns-ciao-BkWOmG6H.js} +2 -2
  92. package/system/dist/{hub-mdns-ciao-9IzOmoit.mjs → hub-mdns-ciao-aIsTpo0F.mjs} +2 -2
  93. package/system/dist/index.js +8 -8
  94. package/system/dist/index.mjs +8 -8
  95. package/system/dist/{legacy-integration-rows-door-DBL83TzQ.js → legacy-integration-rows-door-C9PZZiKH.js} +1 -1
  96. package/system/dist/{legacy-integration-rows-door-CTxk0fz7.mjs → legacy-integration-rows-door-DrfZZHWq.mjs} +1 -1
  97. package/system/dist/{rename-composition-block-DK9CVk1U.mjs → rename-composition-block-C2KFIOMP.mjs} +1 -1
  98. package/system/dist/{rename-composition-block-CKZqCPQF.js → rename-composition-block-Qp1dW4FP.js} +1 -1
  99. package/system/dist/{restore-archive-2OReGcRK.js → restore-archive-DGgj7aqA.js} +1 -1
  100. package/system/dist/{restore-archive-CruwV_-u.mjs → restore-archive-D_K6PqRk.mjs} +1 -1
  101. package/system/dist/{template-protocol-DRZ4cm95.js → template-protocol-D5ogm1rj.js} +8 -44
  102. package/system/dist/{template-protocol-D_6uVHKs.mjs → template-protocol-SgPDx3Hw.mjs} +8 -44
  103. package/system/dist/{wal-maintenance-DgFSFQH0.mjs → wal-maintenance-BuiSFfF2.mjs} +0 -0
  104. package/system/dist/{wal-maintenance-CN7sdJj-.js → wal-maintenance-DD8mfRDn.js} +0 -0
  105. package/system/package.json +4 -1
@@ -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-CdW0TjIj.js");
3
+ const require_dist = require("../../dist-Bh5JIimH.js");
4
4
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
5
- const require_composition_sources = require("../../composition-sources-DPSSQaGb.js");
6
- const require_capture_engine = require("../../capture-engine-DtuMWHR3.js");
5
+ const require_composition_sources = require("../../composition-sources-Rm8xDXjA.js");
6
+ const require_capture_engine = require("../../capture-engine-DAGmlBmJ.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");
@@ -596,6 +596,7 @@ var ActionRowBodySchema = zod.z.object({
596
596
  steps: zod.z.array(require_dist.ActionStepSchema).min(1).max(50),
597
597
  variables: zod.z.array(require_dist.ActionVariableSchema).max(20).optional(),
598
598
  minDelaySec: require_dist.ActionMinDelaySecSchema.optional(),
599
+ tags: require_dist.TagsFieldSchema.optional(),
599
600
  createdAt: zod.z.number(),
600
601
  updatedAt: zod.z.number()
601
602
  });
@@ -606,9 +607,11 @@ var TemplateRowBodySchema = zod.z.object({
606
607
  kind: require_dist.TemplateKindSchema,
607
608
  name: zod.z.string().min(1).max(120),
608
609
  payload: zod.z.unknown(),
610
+ tags: require_dist.TagsFieldSchema.optional(),
609
611
  createdAt: zod.z.number(),
610
612
  updatedAt: zod.z.number()
611
613
  });
614
+ var TagStyleRowBodySchema = require_dist.TagStyleSchema;
612
615
  var TimedRunRowBodySchema = zod.z.object({
613
616
  activeUntil: zod.z.number(),
614
617
  requestedBy: zod.z.string().nullable(),
@@ -695,6 +698,14 @@ var _coreBlocksRecordKinds = require_dist.defineRecordKinds({
695
698
  retention: { none: "operator delete only; a template a device still uses is refused" },
696
699
  maxDataBytes: 256 * 1024
697
700
  },
701
+ "tag-styles": {
702
+ schema: TagStyleRowBodySchema,
703
+ class: "config",
704
+ writeTrigger: "the operator styles a tag (setStyle); a rename moves it; a remove deletes it",
705
+ device: "none",
706
+ at: "none",
707
+ retention: { none: "operator action only: removing or renaming the tag" }
708
+ },
698
709
  settings: {
699
710
  schema: CoreBlockSettingsBodySchema,
700
711
  class: "config",
@@ -1712,6 +1723,7 @@ var CoreBlockStore = class CoreBlockStore {
1712
1723
  const block = require_dist.CoreBlockSchema.parse({
1713
1724
  ...input,
1714
1725
  ...normalized,
1726
+ ...input.tags === void 0 ? {} : { tags: require_dist.normalizeTags(input.tags) },
1715
1727
  id: this.newId(),
1716
1728
  createdBy,
1717
1729
  createdAt: now,
@@ -1744,6 +1756,7 @@ var CoreBlockStore = class CoreBlockStore {
1744
1756
  files: nextFiles,
1745
1757
  entry: nextEntry
1746
1758
  } : {},
1759
+ ...patch.tags === void 0 ? {} : { tags: require_dist.normalizeTags(patch.tags) },
1747
1760
  id: existing.id,
1748
1761
  createdBy: existing.createdBy,
1749
1762
  createdAt: existing.createdAt,
@@ -1754,6 +1767,23 @@ var CoreBlockStore = class CoreBlockStore {
1754
1767
  return updated;
1755
1768
  }
1756
1769
  /**
1770
+ * Replace the tags of a block. Unlike {@link update} this does NOT move
1771
+ * `updatedAt`: that stamp is the version an open composition editor holds as
1772
+ * `expectedUpdatedAt`, and a tag rename must not make its next save stale.
1773
+ */
1774
+ async setTags(blockId, tags) {
1775
+ const existing = this.byId.get(blockId);
1776
+ if (!existing) throw new Error(`core block not found: ${blockId}`);
1777
+ const { tags: _previous, ...rest } = existing;
1778
+ const normalized = require_dist.normalizeTags(tags);
1779
+ const next = require_dist.CoreBlockSchema.parse(normalized.length === 0 ? rest : {
1780
+ ...rest,
1781
+ tags: normalized
1782
+ });
1783
+ await this.persist(next);
1784
+ this.byId.set(next.id, next);
1785
+ }
1786
+ /**
1757
1787
  * Store a composition block (D659): hub-placed, no code, never `running` on
1758
1788
  * creation — the composer's verdict, mirrored by the supervisor, says that.
1759
1789
  */
@@ -3543,7 +3573,8 @@ var ActionsService = class {
3543
3573
  name: patch.name ?? existing.name,
3544
3574
  steps,
3545
3575
  ...(patch.variables ?? existing.variables) === void 0 ? {} : { variables: patch.variables ?? existing.variables },
3546
- ...(patch.minDelaySec ?? existing.minDelaySec) === void 0 ? {} : { minDelaySec: patch.minDelaySec ?? existing.minDelaySec }
3576
+ ...(patch.minDelaySec ?? existing.minDelaySec) === void 0 ? {} : { minDelaySec: patch.minDelaySec ?? existing.minDelaySec },
3577
+ ...(patch.tags ?? existing.tags) === void 0 ? {} : { tags: patch.tags ?? existing.tags }
3547
3578
  });
3548
3579
  this.logger.info("internal action updated", { meta: { actionId: action.id } });
3549
3580
  return {
@@ -3696,6 +3727,11 @@ var ActionsService = class {
3696
3727
  * write="the operator creates / edits / deletes an internal action, or picks a camera's links"
3697
3728
  * retention="operator delete only; a camera's links go with the camera (deviceRemoval 'delete')"
3698
3729
  */
3730
+ /** The stored `tags` of a write: normalised, and absent when there are none. */
3731
+ function tagsBody$1(tags) {
3732
+ const normalized = require_dist.normalizeTags(tags ?? []);
3733
+ return normalized.length === 0 ? {} : { tags: normalized };
3734
+ }
3699
3735
  function uuidOf(actionId) {
3700
3736
  return actionId.slice(require_dist.INTERNAL_ACTION_PREFIX.length);
3701
3737
  }
@@ -3722,6 +3758,7 @@ var ActionsStore = class ActionsStore {
3722
3758
  steps: body.steps,
3723
3759
  ...body.variables === void 0 ? {} : { variables: body.variables },
3724
3760
  ...body.minDelaySec === void 0 || body.minDelaySec === 0 ? {} : { minDelaySec: body.minDelaySec },
3761
+ ...body.tags === void 0 || body.tags.length === 0 ? {} : { tags: body.tags },
3725
3762
  status: require_dist.IDLE_ACTION_STATUS
3726
3763
  };
3727
3764
  }
@@ -3772,6 +3809,7 @@ var ActionsStore = class ActionsStore {
3772
3809
  steps: input.steps,
3773
3810
  ...input.variables === void 0 ? {} : { variables: input.variables },
3774
3811
  ...input.minDelaySec === void 0 || input.minDelaySec === 0 ? {} : { minDelaySec: input.minDelaySec },
3812
+ ...tagsBody$1(input.tags),
3775
3813
  createdAt: at,
3776
3814
  updatedAt: at
3777
3815
  };
@@ -3789,6 +3827,7 @@ var ActionsStore = class ActionsStore {
3789
3827
  steps: input.steps,
3790
3828
  ...input.variables === void 0 ? {} : { variables: input.variables },
3791
3829
  ...input.minDelaySec === void 0 || input.minDelaySec === 0 ? {} : { minDelaySec: input.minDelaySec },
3830
+ ...tagsBody$1(input.tags),
3792
3831
  createdAt: existing.data.createdAt,
3793
3832
  updatedAt: this.now()
3794
3833
  };
@@ -3798,6 +3837,19 @@ var ActionsStore = class ActionsStore {
3798
3837
  });
3799
3838
  return ActionsStore.entryOf(existing.id, body);
3800
3839
  }
3840
+ /** Replace the tags of an internal action; its steps and `updatedAt` are left as they are. */
3841
+ async setTags(actionId, tags) {
3842
+ const existing = require_dist.isInternalActionId(actionId) ? await this.actions.get(uuidOf(actionId)) : null;
3843
+ if (existing === null) throw new require_dist.ActionError("not-found", `no internal action "${actionId}"`);
3844
+ const { tags: _previous, ...rest } = existing.data;
3845
+ await this.actions.put({
3846
+ id: existing.id,
3847
+ data: {
3848
+ ...rest,
3849
+ ...tagsBody$1(tags)
3850
+ }
3851
+ });
3852
+ }
3801
3853
  async delete(actionId) {
3802
3854
  if (!require_dist.isInternalActionId(actionId)) return false;
3803
3855
  return this.actions.delete(uuidOf(actionId));
@@ -5741,7 +5793,12 @@ var SchedulersService = class {
5741
5793
  }
5742
5794
  async update(input) {
5743
5795
  const prepared = await this.prepare(input.scheduler);
5744
- const scheduler = await this.deps.store.update(input.schedulerId, prepared);
5796
+ const existing = await this.deps.store.get(input.schedulerId);
5797
+ const tags = prepared.tags ?? existing?.tags;
5798
+ const scheduler = await this.deps.store.update(input.schedulerId, tags === void 0 ? prepared : {
5799
+ ...prepared,
5800
+ tags
5801
+ });
5745
5802
  this.deps.logger.info("scheduler updated", { meta: { schedulerId: scheduler.id } });
5746
5803
  await this.deps.engine.reload();
5747
5804
  return { scheduler };
@@ -5927,6 +5984,15 @@ var SchedulersService = class {
5927
5984
  * write="the operator creates / edits / deletes / switches a scheduler; the engine advances its processed-until stamp"
5928
5985
  * retention="operator delete only; the stamp goes with its scheduler"
5929
5986
  */
5987
+ /** The input with its tags normalised; an empty list is stored as absent (D1054). */
5988
+ function withNormalizedTags(input) {
5989
+ const { tags, ...rest } = input;
5990
+ const normalized = require_dist.normalizeTags(tags ?? []);
5991
+ return normalized.length === 0 ? rest : {
5992
+ ...rest,
5993
+ tags: normalized
5994
+ };
5995
+ }
5930
5996
  var SchedulersStore = class SchedulersStore {
5931
5997
  schedulers;
5932
5998
  state;
@@ -5962,7 +6028,7 @@ var SchedulersStore = class SchedulersStore {
5962
6028
  const id = this.newId();
5963
6029
  const at = this.now();
5964
6030
  const body = {
5965
- ...input,
6031
+ ...withNormalizedTags(input),
5966
6032
  createdAt: at,
5967
6033
  updatedAt: at
5968
6034
  };
@@ -5978,7 +6044,7 @@ var SchedulersStore = class SchedulersStore {
5978
6044
  if (existing === null) throw new require_dist.SchedulerError("not-found", `no scheduler "${schedulerId}"`);
5979
6045
  const at = this.now();
5980
6046
  const body = {
5981
- ...input,
6047
+ ...withNormalizedTags(input),
5982
6048
  createdAt: existing.data.createdAt,
5983
6049
  updatedAt: at
5984
6050
  };
@@ -5989,6 +6055,25 @@ var SchedulersStore = class SchedulersStore {
5989
6055
  await this.setProcessedUntil(existing.id, at);
5990
6056
  return SchedulersStore.of(existing.id, body);
5991
6057
  }
6058
+ /**
6059
+ * Replace the tags of a scheduler without touching its timeline: no
6060
+ * processed-until reset (a tag is not an edit of the timeline) and the same
6061
+ * `updatedAt`.
6062
+ */
6063
+ async setTags(schedulerId, tags) {
6064
+ const existing = await this.schedulers.get(schedulerId);
6065
+ if (existing === null) throw new require_dist.SchedulerError("not-found", `no scheduler "${schedulerId}"`);
6066
+ const { tags: _previous, ...rest } = existing.data;
6067
+ const normalized = require_dist.normalizeTags(tags);
6068
+ const body = normalized.length === 0 ? rest : {
6069
+ ...rest,
6070
+ tags: normalized
6071
+ };
6072
+ await this.schedulers.put({
6073
+ id: existing.id,
6074
+ data: body
6075
+ });
6076
+ }
5992
6077
  async delete(schedulerId) {
5993
6078
  const removed = await this.schedulers.delete(schedulerId);
5994
6079
  if (removed) await this.state.delete(schedulerId);
@@ -7323,10 +7408,16 @@ function recordOf(id, body) {
7323
7408
  kind: body.kind,
7324
7409
  name: body.name,
7325
7410
  payload: body.payload,
7411
+ ...body.tags === void 0 || body.tags.length === 0 ? {} : { tags: body.tags },
7326
7412
  createdAt: body.createdAt,
7327
7413
  updatedAt: body.updatedAt
7328
7414
  };
7329
7415
  }
7416
+ /** The stored `tags` of a write: normalised, absent when there are none. */
7417
+ function tagsBody(tags) {
7418
+ const normalized = require_dist.normalizeTags(tags ?? []);
7419
+ return normalized.length === 0 ? {} : { tags: normalized };
7420
+ }
7330
7421
  /** A shipped template as a record: read-only, timeless. */
7331
7422
  function builtinRecordOf(template) {
7332
7423
  return {
@@ -7368,7 +7459,7 @@ var TemplatesService = class {
7368
7459
  const row = await this.deps.templates.get(id);
7369
7460
  return row === null ? null : recordOf(row.id, row.data);
7370
7461
  };
7371
- create = async ({ kind, name, payload }) => {
7462
+ create = async ({ kind, name, payload, tags }) => {
7372
7463
  const checked = require_dist.checkTemplatePayload(kind, payload);
7373
7464
  if (!checked.ok) {
7374
7465
  this.deps.logger.warn("template: a payload its kind does not accept was refused", { meta: {
@@ -7386,6 +7477,7 @@ var TemplatesService = class {
7386
7477
  kind,
7387
7478
  name,
7388
7479
  payload: checked.payload,
7480
+ ...tagsBody(tags),
7389
7481
  createdAt: at,
7390
7482
  updatedAt: at
7391
7483
  };
@@ -7399,7 +7491,7 @@ var TemplatesService = class {
7399
7491
  template: recordOf(id, body)
7400
7492
  };
7401
7493
  };
7402
- update = async ({ id, name, payload }) => {
7494
+ update = async ({ id, name, payload, tags }) => {
7403
7495
  if (require_dist.isBuiltinTemplateId(id)) return {
7404
7496
  status: "refused",
7405
7497
  reason: "read-only",
@@ -7432,6 +7524,7 @@ var TemplatesService = class {
7432
7524
  kind: existing.data.kind,
7433
7525
  name: name ?? existing.data.name,
7434
7526
  payload: nextPayload,
7527
+ ...tagsBody(tags === void 0 ? existing.data.tags : tags),
7435
7528
  createdAt: existing.data.createdAt,
7436
7529
  updatedAt: this.now()
7437
7530
  };
@@ -9161,6 +9254,293 @@ async function writeComposedDeviceName(port, logger, blockId, name) {
9161
9254
  }
9162
9255
  }
9163
9256
  //#endregion
9257
+ //#region src/builtins/core-blocks/tags-service.ts
9258
+ /**
9259
+ * 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
9262
+ * kind, so `rename` and `remove` are ONE server operation that rewrites all of
9263
+ * them; the browser never drives that sequence (a closed tab would split the
9264
+ * fleet across two spellings).
9265
+ *
9266
+ * 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.
9268
+ * Tags compare trimmed and case-insensitively (`sameTag`).
9269
+ */
9270
+ /** The order owners are read and rewritten in; also the order a first spelling is picked. */
9271
+ var OWNER_KINDS = [
9272
+ "coreBlocks",
9273
+ "schedulers",
9274
+ "templates",
9275
+ "actions",
9276
+ "devices"
9277
+ ];
9278
+ var NO_UPDATES = {
9279
+ coreBlocks: 0,
9280
+ schedulers: 0,
9281
+ templates: 0,
9282
+ actions: 0,
9283
+ devices: 0
9284
+ };
9285
+ function requireName(value, what) {
9286
+ const parsed = require_dist.TagNameSchema.safeParse(value);
9287
+ if (!parsed.success) throw new Error(`[tags] ${what} is not a valid tag name: ${parsed.error.issues[0]?.message ?? "invalid"}`);
9288
+ return parsed.data;
9289
+ }
9290
+ var TagsService = class {
9291
+ deps;
9292
+ constructor(deps) {
9293
+ this.deps = deps;
9294
+ }
9295
+ async readStyles() {
9296
+ const out = [];
9297
+ let cursor;
9298
+ do {
9299
+ const page = await this.deps.styles.query(cursor === void 0 ? {} : { cursor });
9300
+ for (const row of page.records) out.push(row.data);
9301
+ cursor = page.nextCursor ?? void 0;
9302
+ } while (cursor !== void 0);
9303
+ return out;
9304
+ }
9305
+ list = async () => {
9306
+ const styles = new Map((await this.readStyles()).map((s) => [require_dist.tagKey(s.name), s]));
9307
+ const entries = /* @__PURE__ */ new Map();
9308
+ for (const style of styles.values()) entries.set(require_dist.tagKey(style.name), {
9309
+ name: style.name,
9310
+ counts: { ...NO_UPDATES }
9311
+ });
9312
+ for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
9313
+ const seen = /* @__PURE__ */ new Set();
9314
+ for (const tag of record.tags) {
9315
+ const key = require_dist.tagKey(tag);
9316
+ if (key.length === 0 || seen.has(key)) continue;
9317
+ seen.add(key);
9318
+ const entry = entries.get(key) ?? {
9319
+ name: tag.trim(),
9320
+ counts: { ...NO_UPDATES }
9321
+ };
9322
+ entry.counts[kind] += 1;
9323
+ entries.set(key, entry);
9324
+ }
9325
+ }
9326
+ const out = [];
9327
+ for (const [key, entry] of entries) {
9328
+ const style = styles.get(key);
9329
+ out.push({
9330
+ name: entry.name,
9331
+ color: style?.color ?? require_dist.defaultTagColorId(entry.name),
9332
+ icon: style?.icon ?? "tag",
9333
+ styled: style !== void 0,
9334
+ counts: entry.counts
9335
+ });
9336
+ }
9337
+ return out.toSorted((a, b) => a.name.localeCompare(b.name));
9338
+ };
9339
+ setStyle = async ({ name, color, icon }) => {
9340
+ const trimmed = requireName(name, "a tag name");
9341
+ await this.deps.styles.put({
9342
+ id: require_dist.tagKey(trimmed),
9343
+ data: {
9344
+ name: trimmed,
9345
+ color,
9346
+ icon
9347
+ }
9348
+ });
9349
+ };
9350
+ rename = async ({ from, to }) => {
9351
+ const source = requireName(from, "the tag to rename");
9352
+ const target = requireName(to, "the new tag name");
9353
+ const updated = await this.rewrite(source, (tags) => require_dist.renameInTags(tags, source, target));
9354
+ await this.moveStyle(source, target);
9355
+ this.deps.logger.info("tag renamed", { meta: {
9356
+ from: source,
9357
+ to: target,
9358
+ updated
9359
+ } });
9360
+ return { updated };
9361
+ };
9362
+ remove = async ({ name }) => {
9363
+ const target = requireName(name, "the tag to remove");
9364
+ const updated = await this.rewrite(target, (tags) => require_dist.removeFromTags(tags, target));
9365
+ await this.deps.styles.delete(require_dist.tagKey(target));
9366
+ this.deps.logger.info("tag removed", { meta: {
9367
+ name: target,
9368
+ updated
9369
+ } });
9370
+ return { updated };
9371
+ };
9372
+ /**
9373
+ * Apply `change` to every record carrying `tag`, on every owner kind. A record
9374
+ * that fails is logged and the rest are still attempted; the call then throws,
9375
+ * and the style is NOT touched — the tag still names the failed records, so the
9376
+ * operator repeats the same call (every step is idempotent).
9377
+ */
9378
+ async rewrite(tag, change) {
9379
+ const updated = { ...NO_UPDATES };
9380
+ const failed = [];
9381
+ const plan = [];
9382
+ for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
9383
+ const next = change(record.tags);
9384
+ if (next === null) continue;
9385
+ 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`);
9386
+ plan.push({
9387
+ kind,
9388
+ id: record.id,
9389
+ next
9390
+ });
9391
+ }
9392
+ for (const { kind, id, next } of plan) try {
9393
+ await this.deps.owners[kind].setTags(id, next);
9394
+ updated[kind] += 1;
9395
+ } catch (err) {
9396
+ failed.push(`${kind}:${id}`);
9397
+ const deviceId = kind === "devices" ? Number(id) : void 0;
9398
+ this.deps.logger.error("tag rewrite failed for one record — the rest were still attempted", {
9399
+ ...deviceId === void 0 || !Number.isFinite(deviceId) ? {} : { tags: { deviceId } },
9400
+ meta: {
9401
+ tag,
9402
+ kind,
9403
+ recordId: id,
9404
+ error: err instanceof Error ? err.message : String(err)
9405
+ }
9406
+ });
9407
+ }
9408
+ 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
+ return updated;
9410
+ }
9411
+ /** The style follows the tag; a merge onto a styled target keeps the TARGET's style. */
9412
+ async moveStyle(from, to) {
9413
+ const fromKey = require_dist.tagKey(from);
9414
+ const toKey = require_dist.tagKey(to);
9415
+ const fromStyle = await this.deps.styles.get(fromKey);
9416
+ if (fromKey === toKey) {
9417
+ if (fromStyle !== null) await this.deps.styles.put({
9418
+ id: toKey,
9419
+ data: {
9420
+ ...fromStyle.data,
9421
+ name: to
9422
+ }
9423
+ });
9424
+ return;
9425
+ }
9426
+ if (fromStyle === null) return;
9427
+ if (await this.deps.styles.get(toKey) === null) await this.deps.styles.put({
9428
+ id: toKey,
9429
+ data: {
9430
+ ...fromStyle.data,
9431
+ name: to
9432
+ }
9433
+ });
9434
+ await this.deps.styles.delete(fromKey);
9435
+ }
9436
+ };
9437
+ //#endregion
9438
+ //#region src/builtins/core-blocks/tags-wiring.ts
9439
+ /**
9440
+ * 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).
9442
+ */
9443
+ function coreBlocksPort(blocks) {
9444
+ return {
9445
+ list: async () => blocks().list().map((b) => ({
9446
+ id: b.id,
9447
+ tags: b.tags ?? []
9448
+ })),
9449
+ setTags: async (id, tags) => {
9450
+ await blocks().setTags(id, tags);
9451
+ }
9452
+ };
9453
+ }
9454
+ function schedulersPort(store) {
9455
+ return {
9456
+ list: async () => (await store.list()).map((s) => ({
9457
+ id: s.id,
9458
+ tags: s.tags ?? []
9459
+ })),
9460
+ setTags: (id, tags) => store.setTags(id, tags)
9461
+ };
9462
+ }
9463
+ function actionsPort(store) {
9464
+ return {
9465
+ list: async () => (await store.list()).map((a) => ({
9466
+ id: a.id,
9467
+ tags: a.tags ?? []
9468
+ })),
9469
+ setTags: (id, tags) => store.setTags(id, tags)
9470
+ };
9471
+ }
9472
+ function templatesPort(templates) {
9473
+ return {
9474
+ list: async () => {
9475
+ const out = [];
9476
+ let cursor;
9477
+ do {
9478
+ const page = await templates.query(cursor === void 0 ? {} : { cursor });
9479
+ for (const row of page.records) out.push({
9480
+ id: row.id,
9481
+ tags: row.data.tags ?? []
9482
+ });
9483
+ cursor = page.nextCursor ?? void 0;
9484
+ } while (cursor !== void 0);
9485
+ return out;
9486
+ },
9487
+ setTags: async (id, tags) => {
9488
+ const row = await templates.get(id);
9489
+ if (row === null) throw new Error(`no template "${id}"`);
9490
+ const { tags: _previous, ...rest } = row.data;
9491
+ const normalized = require_dist.normalizeTags(tags);
9492
+ await templates.put({
9493
+ id,
9494
+ data: normalized.length === 0 ? rest : {
9495
+ ...rest,
9496
+ tags: normalized
9497
+ }
9498
+ });
9499
+ }
9500
+ };
9501
+ }
9502
+ function devicesPort(api) {
9503
+ const need = () => {
9504
+ const current = api();
9505
+ if (current === void 0) throw new Error("[tags] the cluster API is not available yet");
9506
+ return current;
9507
+ };
9508
+ return {
9509
+ list: async () => {
9510
+ return (await need().deviceManager.listAll.query({ projection: "slim" })).map((d) => ({
9511
+ id: String(d.id),
9512
+ tags: d.tags ?? []
9513
+ }));
9514
+ },
9515
+ setTags: async (id, tags) => {
9516
+ await need().deviceManager.setTags.mutate({
9517
+ deviceId: Number(id),
9518
+ tags
9519
+ });
9520
+ }
9521
+ };
9522
+ }
9523
+ function buildTagsService(deps) {
9524
+ const { records } = deps;
9525
+ return new TagsService({
9526
+ owners: {
9527
+ coreBlocks: coreBlocksPort(deps.blocks),
9528
+ schedulers: schedulersPort(new SchedulersStore({
9529
+ schedulers: records.kind(coreBlocksRecordKinds.schedulers),
9530
+ state: records.kind(coreBlocksRecordKinds["scheduler-state"])
9531
+ })),
9532
+ templates: templatesPort(records.kind(coreBlocksRecordKinds.templates)),
9533
+ actions: actionsPort(new ActionsStore({
9534
+ actions: records.kind(coreBlocksRecordKinds.actions),
9535
+ links: records.kind(coreBlocksRecordKinds["action-links"])
9536
+ })),
9537
+ devices: deps.devices ?? devicesPort(deps.api)
9538
+ },
9539
+ styles: records.kind(coreBlocksRecordKinds["tag-styles"]),
9540
+ logger: deps.logger
9541
+ });
9542
+ }
9543
+ //#endregion
9164
9544
  //#region src/builtins/core-blocks/extract-settings-schema.ts
9165
9545
  /**
9166
9546
  * Read an optional `settingsSchema` named export from a compiled block bundle.
@@ -9360,6 +9740,7 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
9360
9740
  capability: require_dist.schedulersCapability,
9361
9741
  provider: schedulers.service
9362
9742
  },
9743
+ ...this.tagsRegistrations(),
9363
9744
  {
9364
9745
  capability: require_dist.powerSourceCapability,
9365
9746
  provider: this.buildPowerSource()
@@ -9380,6 +9761,26 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
9380
9761
  ...this.fanPresetRegistrations()
9381
9762
  ];
9382
9763
  }
9764
+ /** The tag styles and the one rename / remove that rewrites every owner (D1054). */
9765
+ tagsRegistrations() {
9766
+ const records = this.ctx.records;
9767
+ if (records === void 0) {
9768
+ this.ctx.logger.warn("tags: no ctx.records on this node — the tags cap is not registered");
9769
+ return [];
9770
+ }
9771
+ return [{
9772
+ capability: require_dist.tagsCapability,
9773
+ provider: this.buildTags(records)
9774
+ }];
9775
+ }
9776
+ buildTags(records) {
9777
+ return buildTagsService({
9778
+ records,
9779
+ blocks: () => this.requireStore(),
9780
+ api: () => this.ctx.api,
9781
+ logger: this.ctx.logger.child("tags")
9782
+ });
9783
+ }
9383
9784
  /** Read-only: the fixed layouts and the model built from the device's bindings and slices. */
9384
9785
  buildHeroLayout() {
9385
9786
  const requireApi = () => {