@camstack/server 1.2.754 → 1.2.756

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 (89) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/trpc/generated-cap-routers.js +5 -3
  3. package/package.json +4 -4
  4. package/system/dist/addon-utils.mjs +1 -1
  5. package/system/dist/{agent-https-cxghRfum.mjs → agent-https-B7O4d-KF.mjs} +1 -1
  6. package/system/dist/{agent-https-B0bjQVfy.js → agent-https-BazIdamh.js} +1 -1
  7. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  8. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  9. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  10. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  11. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  12. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  13. package/system/dist/builtins/autotrack/index.js +1 -1
  14. package/system/dist/builtins/autotrack/index.mjs +1 -1
  15. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  16. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  17. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  18. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  19. package/system/dist/builtins/camera-grid/index.js +1 -1
  20. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  21. package/system/dist/builtins/composer/composer.addon.js +3 -3
  22. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  23. package/system/dist/builtins/console-logging/index.js +1 -1
  24. package/system/dist/builtins/console-logging/index.mjs +1 -1
  25. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  26. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  27. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  28. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  29. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  30. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  31. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  32. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  33. package/system/dist/builtins/keychain/index.js +3 -3
  34. package/system/dist/builtins/keychain/index.mjs +3 -3
  35. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  36. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  37. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  38. package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  39. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  40. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  41. package/system/dist/builtins/loki-logging/index.js +135 -25
  42. package/system/dist/builtins/loki-logging/index.mjs +135 -25
  43. package/system/dist/builtins/loki-logging/loki-destination-set.d.ts +47 -0
  44. package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +10 -5
  45. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  46. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  47. package/system/dist/builtins/platform-probe/index.js +1 -1
  48. package/system/dist/builtins/platform-probe/index.mjs +10 -10
  49. package/system/dist/builtins/record-entries/index.js +1 -1
  50. package/system/dist/builtins/record-entries/index.mjs +1 -1
  51. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  52. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  53. package/system/dist/builtins/snapshot/index.js +1 -1
  54. package/system/dist/builtins/snapshot/index.mjs +1 -1
  55. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  56. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  57. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  58. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  59. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
  60. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
  61. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  62. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  63. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  64. package/system/dist/builtins/system-config/system-config.addon.mjs +115 -115
  65. package/system/dist/builtins/winston-logging/index.js +1 -1
  66. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  67. package/system/dist/{capture-engine-CfJdhMTH.mjs → capture-engine-BpVgVOt3.mjs} +1 -1
  68. package/system/dist/{capture-engine-eRAebXP1.js → capture-engine-DCSZ_pp4.js} +1 -1
  69. package/system/dist/{composition-sources-BvDYLpw_.js → composition-sources-Bqb0YCmj.js} +1 -1
  70. package/system/dist/{composition-sources-ChtkMq1Q.mjs → composition-sources-DT8QgEYB.mjs} +1 -1
  71. package/system/dist/{constants-DkC9-VOa.js → constants-BCZV9xqw.js} +1 -1
  72. package/system/dist/{constants-CYNsr0lM.mjs → constants-BRkCme4G.mjs} +1 -1
  73. package/system/dist/{coral-accelerators-BW3OcrLD.mjs → coral-accelerators-DBlgWB8k.mjs} +6 -6
  74. package/system/dist/{custom-action-registry-BIJZBObd.mjs → custom-action-registry-oHl1xltx.mjs} +37 -37
  75. package/system/dist/{device-ca-BxInMpK2.js → device-ca-4IH_uwz8.js} +1 -1
  76. package/system/dist/{device-ca-CQg3PTnE.mjs → device-ca-BmHs8CPi.mjs} +1 -1
  77. package/system/dist/{dist-DFWnAzAY.js → dist-C5CE_y4W.js} +27 -1
  78. package/system/dist/{dist-C5eIFTMo.mjs → dist-DAGBHQ1A.mjs} +27 -1
  79. package/system/dist/file-host-worker.js +1 -1
  80. package/system/dist/file-host-worker.mjs +1 -1
  81. package/system/dist/{hub-mdns-ciao-BQDdPkPO.js → hub-mdns-ciao-BIKk9QxJ.js} +2 -2
  82. package/system/dist/{hub-mdns-ciao-DW_g42El.mjs → hub-mdns-ciao-DrylQbdc.mjs} +2 -2
  83. package/system/dist/index.js +7 -7
  84. package/system/dist/index.mjs +218 -218
  85. package/system/dist/{restore-archive-D8ZIN10X.mjs → restore-archive-CHyWPskV.mjs} +94 -94
  86. package/system/dist/{restore-archive-DRjYgh6D.js → restore-archive-pBtJEDAE.js} +1 -1
  87. package/system/dist/{wal-maintenance-xYk-FpJW.mjs → wal-maintenance-DIz-F-sd.mjs} +0 -0
  88. package/system/dist/{wal-maintenance-D0zSmIwJ.js → wal-maintenance-DpfPdp-A.js} +0 -0
  89. package/system/package.json +1 -1
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-DFWnAzAY.js");
6
+ const require_dist = require("../../dist-C5CE_y4W.js");
7
7
  const require_log_read_filter = require("../../log-read-filter-Bi066jwU.js");
8
8
  let zod = require("zod");
9
9
  //#region src/builtins/loki-logging/loki-payload.ts
@@ -609,6 +609,110 @@ var LokiDestination = class {
609
609
  }
610
610
  };
611
611
  //#endregion
612
+ //#region src/builtins/loki-logging/loki-destination-set.ts
613
+ var INERT_STATUS = {
614
+ enabled: false,
615
+ configured: false,
616
+ queued: 0,
617
+ pushed: 0,
618
+ dropped: 0,
619
+ failures: 0,
620
+ lastError: null,
621
+ lastPushAtMs: null
622
+ };
623
+ var LokiDestinationSet = class {
624
+ deps;
625
+ members = /* @__PURE__ */ new Map();
626
+ constructor(deps) {
627
+ this.deps = deps;
628
+ }
629
+ async initialize() {}
630
+ /** The ids this set currently holds, in record-id order. */
631
+ ids() {
632
+ return [...this.members.keys()].sort();
633
+ }
634
+ /**
635
+ * Reconcile the set with `configs` (record id to config): add the new, reconfigure the
636
+ * existing, close the ones no longer there. An id in `keep` is left exactly as it is —
637
+ * its config could not be read this time (a locked keychain), so the previous one stands.
638
+ */
639
+ async apply(configs, keep = /* @__PURE__ */ new Set()) {
640
+ for (const [id, member] of [...this.members]) {
641
+ if (configs.has(id) || keep.has(id)) continue;
642
+ this.members.delete(id);
643
+ await member.shutdown();
644
+ }
645
+ for (const [id, config] of configs) {
646
+ const existing = this.members.get(id);
647
+ if (existing !== void 0) {
648
+ await existing.reconfigure(config);
649
+ continue;
650
+ }
651
+ const member = new LokiDestination(this.deps);
652
+ await member.initialize(config);
653
+ this.members.set(id, member);
654
+ }
655
+ }
656
+ write(entry) {
657
+ for (const member of this.members.values()) member.write(entry);
658
+ }
659
+ async flush() {
660
+ await Promise.all([...this.members.values()].map((m) => m.flush()));
661
+ }
662
+ /** The status of one instance; without an id, the first one (an inert status when none). */
663
+ getStatus(instanceId) {
664
+ const id = instanceId ?? this.ids()[0];
665
+ return (id === void 0 ? void 0 : this.members.get(id))?.getStatus() ?? INERT_STATUS;
666
+ }
667
+ getStatuses() {
668
+ return this.ids().map((instanceId) => ({
669
+ instanceId,
670
+ ...this.members.get(instanceId)?.getStatus() ?? INERT_STATUS
671
+ }));
672
+ }
673
+ /** The named instance, or the first one that can be read; null when none can. */
674
+ async readable(selector) {
675
+ if (selector?.instanceId !== void 0) return this.members.get(selector.instanceId) ?? null;
676
+ for (const id of this.ids()) {
677
+ const member = this.members.get(id);
678
+ if (member !== void 0 && (await member.describeRead()).readable) return member;
679
+ }
680
+ return null;
681
+ }
682
+ async describeRead(selector) {
683
+ const member = await this.readable(selector);
684
+ if (member !== null) return member.describeRead();
685
+ return {
686
+ readable: false,
687
+ reason: selector?.instanceId !== void 0 ? `No Loki destination ${selector.instanceId}` : "Loki is not enabled or has no URL",
688
+ filters: {
689
+ deviceId: true,
690
+ addonId: true,
691
+ nodeId: true,
692
+ tags: true,
693
+ level: true,
694
+ text: true,
695
+ timeRange: true
696
+ },
697
+ retentionDays: null
698
+ };
699
+ }
700
+ async read(query) {
701
+ const member = await this.readable(query);
702
+ if (member === null) throw new Error("Loki is not enabled or has no URL");
703
+ return member.read(query);
704
+ }
705
+ async cancelRead(input) {
706
+ for (const member of this.members.values()) if ((await member.cancelRead(input)).cancelled) return { cancelled: true };
707
+ return { cancelled: false };
708
+ }
709
+ async shutdown() {
710
+ const all = [...this.members.values()];
711
+ this.members.clear();
712
+ await Promise.all(all.map((m) => m.shutdown()));
713
+ }
714
+ };
715
+ //#endregion
612
716
  //#region src/builtins/loki-logging/loki-record-kinds.ts
613
717
  /**
614
718
  * The Loki connection as a record (D985): one `destinations` row per Loki instance, owned by
@@ -951,12 +1055,12 @@ var READY_PATH = "/ready";
951
1055
  var LokiLoggingAddon = class extends require_dist.BaseAddon {
952
1056
  destination = null;
953
1057
  instances = null;
954
- current = null;
955
1058
  refreshTimer = null;
956
1059
  retirementTimer = null;
957
1060
  shuttingDown = false;
958
1061
  declared = false;
959
- secretsWarned = false;
1062
+ /** Instances whose keychain lock was already warned about — once per lock, per instance. */
1063
+ secretsWarned = /* @__PURE__ */ new Set();
960
1064
  constructor() {
961
1065
  super({});
962
1066
  }
@@ -964,7 +1068,7 @@ var LokiLoggingAddon = class extends require_dist.BaseAddon {
964
1068
  return (this.ctx.kernel.localNodeId ?? "hub") === "hub";
965
1069
  }
966
1070
  async onInitialize() {
967
- this.destination = new LokiDestination();
1071
+ this.destination = new LokiDestinationSet();
968
1072
  this.shuttingDown = false;
969
1073
  const registrations = [{
970
1074
  capability: require_dist.logDestinationCapability,
@@ -977,7 +1081,7 @@ var LokiLoggingAddon = class extends require_dist.BaseAddon {
977
1081
  else await this.ensureDeclaredQuietly();
978
1082
  this.instances = new require_dist.RecordIntegrationInstances(records, lokiDestinationsKind, {
979
1083
  description: {
980
- instanceMode: "single",
1084
+ instanceMode: "multiple",
981
1085
  kind: "destination",
982
1086
  canTest: true
983
1087
  },
@@ -1004,9 +1108,9 @@ var LokiLoggingAddon = class extends require_dist.BaseAddon {
1004
1108
  }
1005
1109
  await this.refreshFromRecord();
1006
1110
  }
1007
- await this.destination.initialize(this.destinationConfig());
1008
- const url = this.current?.url ?? "";
1009
- this.ctx.logger.info(url.length > 0 ? `Loki logging initialized → ${url}` : "Loki logging registered but inactive (no URL set)");
1111
+ await this.destination.initialize();
1112
+ const urls = this.destination.getStatuses().filter((status) => status.configured).map((status) => status.instanceId);
1113
+ this.ctx.logger.info(urls.length > 0 ? `Loki logging initialized with ${String(urls.length)} destination(s): ${urls.join(", ")}` : "Loki logging registered but inactive (no destination configured)");
1010
1114
  this.attemptEnabledFlagRetirement(0);
1011
1115
  return registrations;
1012
1116
  }
@@ -1023,27 +1127,37 @@ var LokiLoggingAddon = class extends require_dist.BaseAddon {
1023
1127
  this.ctx.logger.warn("Loki logging: the connection kind could not be declared yet", { meta: { error: err instanceof Error ? err.message : String(err) } });
1024
1128
  }
1025
1129
  }
1026
- /** Re-read the connection record and apply it to the live destination. */
1130
+ /**
1131
+ * Re-read every connection record and reconcile the live destinations with them: a new record
1132
+ * starts one, an edit reconfigures it, a deleted record closes its client. A record whose
1133
+ * secret cannot be read (locked keychain) keeps the configuration it had (D49) and is skipped
1134
+ * if it never had one; the others are unaffected.
1135
+ */
1027
1136
  async refreshFromRecord() {
1028
1137
  if (this.instances === null || this.shuttingDown) return;
1029
- let first;
1138
+ let resolved;
1030
1139
  try {
1031
1140
  if (!this.declared) await this.ensureDeclared();
1032
- [first] = await this.instances.listResolved();
1141
+ resolved = await this.instances.listResolved();
1033
1142
  } catch (err) {
1034
- this.ctx.logger.warn("Loki logging: the connection record could not be read", { meta: { error: err instanceof Error ? err.message : String(err) } });
1143
+ this.ctx.logger.warn("Loki logging: the connection records could not be read", { meta: { error: err instanceof Error ? err.message : String(err) } });
1035
1144
  return;
1036
1145
  }
1037
- if (first?.secrets === "unavailable") {
1038
- if (!this.secretsWarned) {
1039
- this.secretsWarned = true;
1040
- this.ctx.logger.warn("Loki logging: the keychain is locked; the destination keeps its previous configuration");
1146
+ const configs = /* @__PURE__ */ new Map();
1147
+ const keep = /* @__PURE__ */ new Set();
1148
+ for (const instance of resolved) {
1149
+ if (instance.secrets === "unavailable") {
1150
+ keep.add(instance.id);
1151
+ if (!this.secretsWarned.has(instance.id)) {
1152
+ this.secretsWarned.add(instance.id);
1153
+ this.ctx.logger.warn(`Loki logging: the keychain is locked; destination ${instance.id} keeps its previous configuration`);
1154
+ }
1155
+ continue;
1041
1156
  }
1042
- return;
1157
+ this.secretsWarned.delete(instance.id);
1158
+ configs.set(instance.id, this.destinationConfig(instance.body));
1043
1159
  }
1044
- this.secretsWarned = false;
1045
- this.current = first?.body ?? null;
1046
- await this.destination?.reconfigure(this.destinationConfig());
1160
+ await this.destination?.apply(configs, keep);
1047
1161
  }
1048
1162
  /**
1049
1163
  * The catalogue to offer while initialising. Seq 3 cannot decide before registration, so it is
@@ -1270,11 +1384,7 @@ var LokiLoggingAddon = class extends require_dist.BaseAddon {
1270
1384
  * different signature is a type error — usefully, since silently overriding it
1271
1385
  * would have broken this addon's settings reload.
1272
1386
  */
1273
- destinationConfig() {
1274
- const body = this.current ?? {
1275
- ...LOKI_DEFAULT_BODY,
1276
- name: ""
1277
- };
1387
+ destinationConfig(body) {
1278
1388
  return {
1279
1389
  enabled: body.enabled !== false,
1280
1390
  url: body.url,
@@ -1,4 +1,4 @@
1
- import { Fs as isSecretMarker, Lt as RecordIntegrationInstances, Pi as preconditionOf, Ps as isSecretFieldView, Wr as isSameAddonId, Zo as RevConflictError, gs as defineAddonMigrations, jr as integrationInstancesCapability, ri as logDestinationCapability, vn as bareAddonId, vs as defineEntryKind, wo as BaseAddon } from "../../dist-C5eIFTMo.mjs";
1
+ import { Fs as isSecretMarker, Lt as RecordIntegrationInstances, Pi as preconditionOf, Ps as isSecretFieldView, Wr as isSameAddonId, Zo as RevConflictError, gs as defineAddonMigrations, jr as integrationInstancesCapability, ri as logDestinationCapability, vn as bareAddonId, vs as defineEntryKind, wo as BaseAddon } from "../../dist-DAGBHQ1A.mjs";
2
2
  import { n as compileLogFilter, o as lineMatches } from "../../log-read-filter-D7Ev3zm-.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/builtins/loki-logging/loki-payload.ts
@@ -604,6 +604,110 @@ var LokiDestination = class {
604
604
  }
605
605
  };
606
606
  //#endregion
607
+ //#region src/builtins/loki-logging/loki-destination-set.ts
608
+ var INERT_STATUS = {
609
+ enabled: false,
610
+ configured: false,
611
+ queued: 0,
612
+ pushed: 0,
613
+ dropped: 0,
614
+ failures: 0,
615
+ lastError: null,
616
+ lastPushAtMs: null
617
+ };
618
+ var LokiDestinationSet = class {
619
+ deps;
620
+ members = /* @__PURE__ */ new Map();
621
+ constructor(deps) {
622
+ this.deps = deps;
623
+ }
624
+ async initialize() {}
625
+ /** The ids this set currently holds, in record-id order. */
626
+ ids() {
627
+ return [...this.members.keys()].sort();
628
+ }
629
+ /**
630
+ * Reconcile the set with `configs` (record id to config): add the new, reconfigure the
631
+ * existing, close the ones no longer there. An id in `keep` is left exactly as it is —
632
+ * its config could not be read this time (a locked keychain), so the previous one stands.
633
+ */
634
+ async apply(configs, keep = /* @__PURE__ */ new Set()) {
635
+ for (const [id, member] of [...this.members]) {
636
+ if (configs.has(id) || keep.has(id)) continue;
637
+ this.members.delete(id);
638
+ await member.shutdown();
639
+ }
640
+ for (const [id, config] of configs) {
641
+ const existing = this.members.get(id);
642
+ if (existing !== void 0) {
643
+ await existing.reconfigure(config);
644
+ continue;
645
+ }
646
+ const member = new LokiDestination(this.deps);
647
+ await member.initialize(config);
648
+ this.members.set(id, member);
649
+ }
650
+ }
651
+ write(entry) {
652
+ for (const member of this.members.values()) member.write(entry);
653
+ }
654
+ async flush() {
655
+ await Promise.all([...this.members.values()].map((m) => m.flush()));
656
+ }
657
+ /** The status of one instance; without an id, the first one (an inert status when none). */
658
+ getStatus(instanceId) {
659
+ const id = instanceId ?? this.ids()[0];
660
+ return (id === void 0 ? void 0 : this.members.get(id))?.getStatus() ?? INERT_STATUS;
661
+ }
662
+ getStatuses() {
663
+ return this.ids().map((instanceId) => ({
664
+ instanceId,
665
+ ...this.members.get(instanceId)?.getStatus() ?? INERT_STATUS
666
+ }));
667
+ }
668
+ /** The named instance, or the first one that can be read; null when none can. */
669
+ async readable(selector) {
670
+ if (selector?.instanceId !== void 0) return this.members.get(selector.instanceId) ?? null;
671
+ for (const id of this.ids()) {
672
+ const member = this.members.get(id);
673
+ if (member !== void 0 && (await member.describeRead()).readable) return member;
674
+ }
675
+ return null;
676
+ }
677
+ async describeRead(selector) {
678
+ const member = await this.readable(selector);
679
+ if (member !== null) return member.describeRead();
680
+ return {
681
+ readable: false,
682
+ reason: selector?.instanceId !== void 0 ? `No Loki destination ${selector.instanceId}` : "Loki is not enabled or has no URL",
683
+ filters: {
684
+ deviceId: true,
685
+ addonId: true,
686
+ nodeId: true,
687
+ tags: true,
688
+ level: true,
689
+ text: true,
690
+ timeRange: true
691
+ },
692
+ retentionDays: null
693
+ };
694
+ }
695
+ async read(query) {
696
+ const member = await this.readable(query);
697
+ if (member === null) throw new Error("Loki is not enabled or has no URL");
698
+ return member.read(query);
699
+ }
700
+ async cancelRead(input) {
701
+ for (const member of this.members.values()) if ((await member.cancelRead(input)).cancelled) return { cancelled: true };
702
+ return { cancelled: false };
703
+ }
704
+ async shutdown() {
705
+ const all = [...this.members.values()];
706
+ this.members.clear();
707
+ await Promise.all(all.map((m) => m.shutdown()));
708
+ }
709
+ };
710
+ //#endregion
607
711
  //#region src/builtins/loki-logging/loki-record-kinds.ts
608
712
  /**
609
713
  * The Loki connection as a record (D985): one `destinations` row per Loki instance, owned by
@@ -944,12 +1048,12 @@ var READY_PATH = "/ready";
944
1048
  var LokiLoggingAddon = class extends BaseAddon {
945
1049
  destination = null;
946
1050
  instances = null;
947
- current = null;
948
1051
  refreshTimer = null;
949
1052
  retirementTimer = null;
950
1053
  shuttingDown = false;
951
1054
  declared = false;
952
- secretsWarned = false;
1055
+ /** Instances whose keychain lock was already warned about — once per lock, per instance. */
1056
+ secretsWarned = /* @__PURE__ */ new Set();
953
1057
  constructor() {
954
1058
  super({});
955
1059
  }
@@ -957,7 +1061,7 @@ var LokiLoggingAddon = class extends BaseAddon {
957
1061
  return (this.ctx.kernel.localNodeId ?? "hub") === "hub";
958
1062
  }
959
1063
  async onInitialize() {
960
- this.destination = new LokiDestination();
1064
+ this.destination = new LokiDestinationSet();
961
1065
  this.shuttingDown = false;
962
1066
  const registrations = [{
963
1067
  capability: logDestinationCapability,
@@ -970,7 +1074,7 @@ var LokiLoggingAddon = class extends BaseAddon {
970
1074
  else await this.ensureDeclaredQuietly();
971
1075
  this.instances = new RecordIntegrationInstances(records, lokiDestinationsKind, {
972
1076
  description: {
973
- instanceMode: "single",
1077
+ instanceMode: "multiple",
974
1078
  kind: "destination",
975
1079
  canTest: true
976
1080
  },
@@ -997,9 +1101,9 @@ var LokiLoggingAddon = class extends BaseAddon {
997
1101
  }
998
1102
  await this.refreshFromRecord();
999
1103
  }
1000
- await this.destination.initialize(this.destinationConfig());
1001
- const url = this.current?.url ?? "";
1002
- this.ctx.logger.info(url.length > 0 ? `Loki logging initialized → ${url}` : "Loki logging registered but inactive (no URL set)");
1104
+ await this.destination.initialize();
1105
+ const urls = this.destination.getStatuses().filter((status) => status.configured).map((status) => status.instanceId);
1106
+ this.ctx.logger.info(urls.length > 0 ? `Loki logging initialized with ${String(urls.length)} destination(s): ${urls.join(", ")}` : "Loki logging registered but inactive (no destination configured)");
1003
1107
  this.attemptEnabledFlagRetirement(0);
1004
1108
  return registrations;
1005
1109
  }
@@ -1016,27 +1120,37 @@ var LokiLoggingAddon = class extends BaseAddon {
1016
1120
  this.ctx.logger.warn("Loki logging: the connection kind could not be declared yet", { meta: { error: err instanceof Error ? err.message : String(err) } });
1017
1121
  }
1018
1122
  }
1019
- /** Re-read the connection record and apply it to the live destination. */
1123
+ /**
1124
+ * Re-read every connection record and reconcile the live destinations with them: a new record
1125
+ * starts one, an edit reconfigures it, a deleted record closes its client. A record whose
1126
+ * secret cannot be read (locked keychain) keeps the configuration it had (D49) and is skipped
1127
+ * if it never had one; the others are unaffected.
1128
+ */
1020
1129
  async refreshFromRecord() {
1021
1130
  if (this.instances === null || this.shuttingDown) return;
1022
- let first;
1131
+ let resolved;
1023
1132
  try {
1024
1133
  if (!this.declared) await this.ensureDeclared();
1025
- [first] = await this.instances.listResolved();
1134
+ resolved = await this.instances.listResolved();
1026
1135
  } catch (err) {
1027
- this.ctx.logger.warn("Loki logging: the connection record could not be read", { meta: { error: err instanceof Error ? err.message : String(err) } });
1136
+ this.ctx.logger.warn("Loki logging: the connection records could not be read", { meta: { error: err instanceof Error ? err.message : String(err) } });
1028
1137
  return;
1029
1138
  }
1030
- if (first?.secrets === "unavailable") {
1031
- if (!this.secretsWarned) {
1032
- this.secretsWarned = true;
1033
- this.ctx.logger.warn("Loki logging: the keychain is locked; the destination keeps its previous configuration");
1139
+ const configs = /* @__PURE__ */ new Map();
1140
+ const keep = /* @__PURE__ */ new Set();
1141
+ for (const instance of resolved) {
1142
+ if (instance.secrets === "unavailable") {
1143
+ keep.add(instance.id);
1144
+ if (!this.secretsWarned.has(instance.id)) {
1145
+ this.secretsWarned.add(instance.id);
1146
+ this.ctx.logger.warn(`Loki logging: the keychain is locked; destination ${instance.id} keeps its previous configuration`);
1147
+ }
1148
+ continue;
1034
1149
  }
1035
- return;
1150
+ this.secretsWarned.delete(instance.id);
1151
+ configs.set(instance.id, this.destinationConfig(instance.body));
1036
1152
  }
1037
- this.secretsWarned = false;
1038
- this.current = first?.body ?? null;
1039
- await this.destination?.reconfigure(this.destinationConfig());
1153
+ await this.destination?.apply(configs, keep);
1040
1154
  }
1041
1155
  /**
1042
1156
  * The catalogue to offer while initialising. Seq 3 cannot decide before registration, so it is
@@ -1263,11 +1377,7 @@ var LokiLoggingAddon = class extends BaseAddon {
1263
1377
  * different signature is a type error — usefully, since silently overriding it
1264
1378
  * would have broken this addon's settings reload.
1265
1379
  */
1266
- destinationConfig() {
1267
- const body = this.current ?? {
1268
- ...LOKI_DEFAULT_BODY,
1269
- name: ""
1270
- };
1380
+ destinationConfig(body) {
1271
1381
  return {
1272
1382
  enabled: body.enabled !== false,
1273
1383
  url: body.url,
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The Loki destinations of one node: one `LokiDestination` per `destinations` record (planning#408).
3
+ *
4
+ * `write` fans out to every one of them; each keeps its own queue, flush timer, counters and
5
+ * client, so one unreachable Loki never delays another. `read` / `describeRead` take an optional
6
+ * `instanceId`; without it the first READABLE instance answers (ordered by record id, so the
7
+ * answer is stable). The set never logs: it is registered as a log destination, and a line it
8
+ * wrote would feed itself. The addon logs around it.
9
+ */
10
+ import type { ILogDestination, LogEntry, LogReadCapabilities, LogReadQuery, LogReadResult } from "@camstack/types";
11
+ import { type LokiConfig, type LokiDestinationDeps, type LokiStatus } from "./loki-destination.js";
12
+ export interface LokiInstanceStatus extends LokiStatus {
13
+ readonly instanceId: string;
14
+ }
15
+ /** What a read or a capability probe may name. */
16
+ export interface LokiInstanceSelector {
17
+ readonly instanceId?: string | undefined;
18
+ }
19
+ export declare class LokiDestinationSet implements ILogDestination {
20
+ private readonly deps?;
21
+ private readonly members;
22
+ constructor(deps?: LokiDestinationDeps);
23
+ initialize(): Promise<void>;
24
+ /** The ids this set currently holds, in record-id order. */
25
+ ids(): readonly string[];
26
+ /**
27
+ * Reconcile the set with `configs` (record id to config): add the new, reconfigure the
28
+ * existing, close the ones no longer there. An id in `keep` is left exactly as it is —
29
+ * its config could not be read this time (a locked keychain), so the previous one stands.
30
+ */
31
+ apply(configs: ReadonlyMap<string, LokiConfig>, keep?: ReadonlySet<string>): Promise<void>;
32
+ write(entry: LogEntry): void;
33
+ flush(): Promise<void>;
34
+ /** The status of one instance; without an id, the first one (an inert status when none). */
35
+ getStatus(instanceId?: string): LokiStatus;
36
+ getStatuses(): readonly LokiInstanceStatus[];
37
+ /** The named instance, or the first one that can be read; null when none can. */
38
+ private readable;
39
+ describeRead(selector?: LokiInstanceSelector): Promise<LogReadCapabilities>;
40
+ read(query: LogReadQuery): Promise<LogReadResult>;
41
+ cancelRead(input: {
42
+ readonly requestId: string;
43
+ }): Promise<{
44
+ readonly cancelled: boolean;
45
+ }>;
46
+ shutdown(): Promise<void>;
47
+ }
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import type { ProviderRegistration } from "@camstack/types";
20
20
  import { BaseAddon } from "@camstack/types";
21
- import { LokiDestination } from "./loki-destination.js";
21
+ import { LokiDestinationSet } from "./loki-destination-set.js";
22
22
  /**
23
23
  * The addon keeps NO connection setting of its own (D985): the connection is a `destinations`
24
24
  * record. What remains in the settings store is the D777 retirement marker only.
@@ -29,18 +29,23 @@ export declare function stripUserinfo(message: string, typedUrl: string): string
29
29
  export declare class LokiLoggingAddon extends BaseAddon<LokiAddonConfig> {
30
30
  private destination;
31
31
  private instances;
32
- private current;
33
32
  private refreshTimer;
34
33
  private retirementTimer;
35
34
  private shuttingDown;
36
35
  private declared;
37
- private secretsWarned;
36
+ /** Instances whose keychain lock was already warned about — once per lock, per instance. */
37
+ private readonly secretsWarned;
38
38
  constructor();
39
39
  private isHub;
40
40
  protected onInitialize(): Promise<ProviderRegistration[]>;
41
41
  private ensureDeclared;
42
42
  private ensureDeclaredQuietly;
43
- /** Re-read the connection record and apply it to the live destination. */
43
+ /**
44
+ * Re-read every connection record and reconcile the live destinations with them: a new record
45
+ * starts one, an edit reconfigures it, a deleted record closes its client. A record whose
46
+ * secret cannot be read (locked keychain) keeps the configuration it had (D49) and is skipped
47
+ * if it never had one; the others are unaffected.
48
+ */
44
49
  private refreshFromRecord;
45
50
  /**
46
51
  * The catalogue to offer while initialising. Seq 3 cannot decide before registration, so it is
@@ -84,7 +89,7 @@ export declare class LokiLoggingAddon extends BaseAddon<LokiAddonConfig> {
84
89
  * would have broken this addon's settings reload.
85
90
  */
86
91
  private destinationConfig;
87
- getDestination(): LokiDestination;
92
+ getDestination(): LokiDestinationSet;
88
93
  private connectionForm;
89
94
  }
90
95
  export {};
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-DFWnAzAY.js");
6
+ const require_dist = require("../../dist-C5CE_y4W.js");
7
7
  let node_fs_promises = require("node:fs/promises");
8
8
  let node_util = require("node:util");
9
9
  let node_os = require("node:os");
@@ -1,9 +1,9 @@
1
- import { It as ROOT_BUCKET_KEY, Tr as foldSnapshotByFunction, Vi as reducePoints, dc as EventCategory, fi as metricsProviderCapability, ms as createEvent, nn as UNATTRIBUTED_BUCKET_KEY, qi as resolveBucketMs, uc as errMsg, wo as BaseAddon } from "../../dist-C5eIFTMo.mjs";
1
+ import { It as ROOT_BUCKET_KEY, Tr as foldSnapshotByFunction, Vi as reducePoints, dc as EventCategory, fi as metricsProviderCapability, ms as createEvent, nn as UNATTRIBUTED_BUCKET_KEY, qi as resolveBucketMs, uc as errMsg, wo as BaseAddon } from "../../dist-DAGBHQ1A.mjs";
2
2
  import { access, readFile, readdir } from "node:fs/promises";
3
3
  import { promisify } from "node:util";
4
4
  import * as os$1 from "node:os";
5
5
  import { platform } from "node:os";
6
- import * as fs from "node:fs";
6
+ import * as fs$1 from "node:fs";
7
7
  import { constants, readFileSync } from "node:fs";
8
8
  import { execFile } from "node:child_process";
9
9
  //#region src/builtins/native-metrics/cgroup-memory.ts
@@ -1686,7 +1686,7 @@ var NativeMetricsProvider = class {
1686
1686
  let swapUsedBytes = 0;
1687
1687
  let swapTotalBytes = 0;
1688
1688
  if (IS_LINUX) try {
1689
- const meminfo = fs.readFileSync("/proc/meminfo", "utf-8");
1689
+ const meminfo = fs$1.readFileSync("/proc/meminfo", "utf-8");
1690
1690
  const availKb = meminfo.match(/MemAvailable:\s+(\d+)/)?.[1];
1691
1691
  if (availKb !== void 0) available = parseInt(availKb, 10) * 1024;
1692
1692
  const swapTotal = parseInt(meminfo.match(/SwapTotal:\s+(\d+)/)?.[1] ?? "0", 10) * 1024;
@@ -1779,7 +1779,7 @@ async function sampleMacMemory(provider) {
1779
1779
  }
1780
1780
  function getDiskSpaceInternal(dirPath) {
1781
1781
  return new Promise((resolve, reject) => {
1782
- fs.statfs(dirPath, (err, stats) => {
1782
+ fs$1.statfs(dirPath, (err, stats) => {
1783
1783
  if (err) return reject(err);
1784
1784
  const totalBytes = stats.blocks * stats.bsize;
1785
1785
  const availableBytes = stats.bavail * stats.bsize;
@@ -1797,7 +1797,7 @@ function getDiskSpaceInternal(dirPath) {
1797
1797
  async function takeDiskIoSnapshot() {
1798
1798
  const now = Date.now();
1799
1799
  if (IS_LINUX) try {
1800
- const data = fs.readFileSync("/proc/diskstats", "utf-8");
1800
+ const data = fs$1.readFileSync("/proc/diskstats", "utf-8");
1801
1801
  let readOps = 0, readBytes = 0, writeOps = 0, writeBytes = 0;
1802
1802
  for (const line of data.split("\n")) {
1803
1803
  const parts = line.trim().split(/\s+/);
@@ -1828,7 +1828,7 @@ async function takeDiskIoSnapshot() {
1828
1828
  async function takeNetworkIoSnapshot() {
1829
1829
  const now = Date.now();
1830
1830
  if (IS_LINUX) try {
1831
- const data = fs.readFileSync("/proc/net/dev", "utf-8");
1831
+ const data = fs$1.readFileSync("/proc/net/dev", "utf-8");
1832
1832
  let rxBytes = 0, txBytes = 0, rxPackets = 0, txPackets = 0, rxErrors = 0, txErrors = 0;
1833
1833
  for (const line of data.split("\n")) {
1834
1834
  const match = line.match(/^\s*(\w+):\s+(.+)$/);
@@ -1889,7 +1889,7 @@ async function takeNetworkIoSnapshot() {
1889
1889
  }
1890
1890
  async function getCpuTemperatureInternal() {
1891
1891
  if (IS_LINUX) for (const p of ["/sys/class/thermal/thermal_zone0/temp", "/sys/class/hwmon/hwmon0/temp1_input"]) try {
1892
- const raw = fs.readFileSync(p, "utf-8").trim();
1892
+ const raw = fs$1.readFileSync(p, "utf-8").trim();
1893
1893
  const millideg = parseInt(raw, 10);
1894
1894
  if (!isNaN(millideg)) return Math.round(millideg / 100) / 10;
1895
1895
  } catch {
@@ -1940,10 +1940,10 @@ function getProcessResources() {
1940
1940
  let threadCount = 0;
1941
1941
  if (IS_LINUX) {
1942
1942
  try {
1943
- openFds = fs.readdirSync(`/proc/${process.pid}/fd`).length;
1943
+ openFds = fs$1.readdirSync(`/proc/${process.pid}/fd`).length;
1944
1944
  } catch {}
1945
1945
  try {
1946
- const match = fs.readFileSync(`/proc/${process.pid}/status`, "utf-8").match(/Threads:\s+(\d+)/);
1946
+ const match = fs$1.readFileSync(`/proc/${process.pid}/status`, "utf-8").match(/Threads:\s+(\d+)/);
1947
1947
  if (match) threadCount = parseInt(match[1], 10);
1948
1948
  } catch {}
1949
1949
  }
@@ -1958,7 +1958,7 @@ function getProcessResources() {
1958
1958
  function getPressure(resource) {
1959
1959
  if (!IS_LINUX) return null;
1960
1960
  try {
1961
- const data = fs.readFileSync(`/proc/pressure/${resource}`, "utf-8");
1961
+ const data = fs$1.readFileSync(`/proc/pressure/${resource}`, "utf-8");
1962
1962
  const parseLine = (prefix) => {
1963
1963
  const match = data.match(new RegExp(`${prefix} avg10=(\\d+\\.\\d+) avg60=(\\d+\\.\\d+) avg300=(\\d+\\.\\d+)`));
1964
1964
  if (!match) return null;
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-DFWnAzAY.js");
6
+ const require_dist = require("../../dist-C5CE_y4W.js");
7
7
  const require_coral_accelerators = require("../../coral-accelerators-BSVsBVzt.js");
8
8
  let node_path = require("node:path");
9
9
  node_path = require_chunk.__toESM(node_path);