@camstack/system 1.2.470 → 1.2.472

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 (93) hide show
  1. package/dist/addon-runner.js +248 -19
  2. package/dist/addon-runner.mjs +249 -20
  3. package/dist/addon-utils.mjs +1 -1
  4. package/dist/{agent-https-DmNQyAl7.mjs → agent-https-JhvY1axF.mjs} +1 -1
  5. package/dist/{agent-https-D_oo3PNv.js → agent-https-bnyFRK7Y.js} +1 -1
  6. package/dist/auth/user-manager.d.ts +2 -2
  7. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  8. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  9. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  10. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  11. package/dist/builtins/alerts/alerts.addon.js +1 -1
  12. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  13. package/dist/builtins/autotrack/index.js +1 -1
  14. package/dist/builtins/autotrack/index.mjs +1 -1
  15. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  16. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  17. package/dist/builtins/calendars/calendars.addon.js +1 -1
  18. package/dist/builtins/calendars/calendars.addon.mjs +1 -1
  19. package/dist/builtins/camera-grid/index.js +1 -1
  20. package/dist/builtins/camera-grid/index.mjs +1 -1
  21. package/dist/builtins/composer/composer.addon.js +2 -2
  22. package/dist/builtins/composer/composer.addon.mjs +2 -2
  23. package/dist/builtins/console-logging/index.js +1 -1
  24. package/dist/builtins/console-logging/index.mjs +1 -1
  25. package/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
  26. package/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
  27. package/dist/builtins/device-history/device-history.addon.js +1 -1
  28. package/dist/builtins/device-history/device-history.addon.mjs +1 -1
  29. package/dist/builtins/device-manager/device-manager.addon.js +1 -1
  30. package/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  31. package/dist/builtins/hub-forwarder/index.js +1 -1
  32. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  33. package/dist/builtins/keychain/index.js +3 -3
  34. package/dist/builtins/keychain/index.mjs +3 -3
  35. package/dist/builtins/liveness-monitor/liveness-monitor.addon.d.ts +9 -25
  36. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +240 -39
  37. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +237 -38
  38. package/dist/builtins/liveness-monitor/liveness-reporter.d.ts +28 -0
  39. package/dist/builtins/liveness-monitor/storage-root-access.d.ts +53 -0
  40. package/dist/builtins/local-auth/local-auth.addon.js +2 -2
  41. package/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  42. package/dist/builtins/local-network/local-network.addon.js +2 -2
  43. package/dist/builtins/local-network/local-network.addon.mjs +2 -2
  44. package/dist/builtins/loki-logging/index.js +1 -1
  45. package/dist/builtins/loki-logging/index.mjs +1 -1
  46. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  47. package/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  48. package/dist/builtins/platform-probe/coral-accelerators.d.ts +14 -4
  49. package/dist/builtins/platform-probe/index.js +9 -6
  50. package/dist/builtins/platform-probe/index.mjs +15 -12
  51. package/dist/builtins/record-entries/index.js +1 -1
  52. package/dist/builtins/record-entries/index.mjs +1 -1
  53. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  54. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  55. package/dist/builtins/snapshot/index.js +1 -1
  56. package/dist/builtins/snapshot/index.mjs +1 -1
  57. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  58. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  59. package/dist/builtins/sqlite-storage/index.js +1 -1
  60. package/dist/builtins/sqlite-storage/index.mjs +1 -1
  61. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
  62. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
  63. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  64. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  65. package/dist/builtins/system-config/system-config.addon.js +3 -3
  66. package/dist/builtins/system-config/system-config.addon.mjs +115 -115
  67. package/dist/builtins/winston-logging/index.js +1 -1
  68. package/dist/builtins/winston-logging/index.mjs +1 -1
  69. package/dist/{composition-sources-B0tqvf0t.mjs → composition-sources-BY6rFuAE.mjs} +1 -1
  70. package/dist/{composition-sources-CRJffEiB.js → composition-sources-D3h-tNoJ.js} +1 -1
  71. package/dist/{constants-WF1AqoKF.js → constants-CqbO6e9i.js} +1 -1
  72. package/dist/{constants--A505iuO.mjs → constants-zBiEodEM.mjs} +1 -1
  73. package/dist/{coral-accelerators-Cri32b7q.js → coral-accelerators-BSVsBVzt.js} +46 -11
  74. package/dist/{coral-accelerators-Dl-GnMHn.mjs → coral-accelerators-DBlgWB8k.mjs} +52 -17
  75. package/dist/{custom-action-registry-BGYDjTqY.mjs → custom-action-registry-DZSCLBuT.mjs} +37 -37
  76. package/dist/{device-ca-DYmToMp8.mjs → device-ca-BWTWWBcc.mjs} +1 -1
  77. package/dist/{device-ca-R4MZZtc0.js → device-ca-CfiIg3a9.js} +1 -1
  78. package/dist/{dist-X1r44BdF.mjs → dist-CdFkkmXW.mjs} +6845 -1651
  79. package/dist/{dist-DRL3rEfN.js → dist-DX5Fu3mV.js} +6845 -1651
  80. package/dist/file-host-worker.js +1 -1
  81. package/dist/file-host-worker.mjs +1 -1
  82. package/dist/{hub-mdns-ciao-DUoTS6jN.js → hub-mdns-ciao-C174UDzO.js} +2 -2
  83. package/dist/{hub-mdns-ciao-CZV5Hion.mjs → hub-mdns-ciao-CYp1Gipm.mjs} +2 -2
  84. package/dist/index.js +235 -17
  85. package/dist/index.mjs +453 -235
  86. package/dist/kernel/hwaccel/hwaccel-resolver.d.ts +24 -4
  87. package/dist/kernel/hwaccel/vaapi-init-probe.d.ts +29 -0
  88. package/dist/kernel/moleculer/runner-process-group.d.ts +4 -0
  89. package/dist/{restore-archive-Df6PsOHP.js → restore-archive-B2jIFfu_.js} +1 -1
  90. package/dist/{restore-archive-X0ciGMmO.mjs → restore-archive-BX0gaKtG.mjs} +94 -94
  91. package/dist/{wal-maintenance-DYvzJiuK.js → wal-maintenance-Dxqd5igw.js} +0 -0
  92. package/dist/{wal-maintenance-D6J_MmZ8.mjs → wal-maintenance-KHzJXlF2.mjs} +0 -0
  93. package/package.json +1 -1
@@ -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-DRL3rEfN.js");
6
+ const require_dist = require("../../dist-DX5Fu3mV.js");
7
7
  const require_formatter = require("../../formatter-DqAKDlvN.js");
8
8
  const require_log_file_read_protocol = require("../../log-file-read-protocol-D0WcLbIV.js");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { Ln as logDestinationCapability, ei as BaseAddon } from "../../dist-X1r44BdF.mjs";
1
+ import { Ln as logDestinationCapability, ei as BaseAddon } from "../../dist-CdFkkmXW.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-B7qW8bPJ.mjs";
3
3
  import { a as LogFileIndexStore, i as serveRead, n as isFromReader, t as CancelBook } from "../../log-file-read-protocol-B7M3X3bT.mjs";
4
4
  import { createRequire } from "node:module";
@@ -1,4 +1,4 @@
1
- import { $r as errMsg, Kr as compositionSourceKey } from "./dist-X1r44BdF.mjs";
1
+ import { $r as errMsg, Kr as compositionSourceKey } from "./dist-CdFkkmXW.mjs";
2
2
  //#region src/builtins/core-blocks/composition-sources.ts
3
3
  /**
4
4
  * Describe what a composition reads and writes for SAVE-time validation
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-DRL3rEfN.js");
1
+ const require_dist = require("./dist-DX5Fu3mV.js");
2
2
  //#region src/builtins/core-blocks/composition-sources.ts
3
3
  /**
4
4
  * Describe what a composition reads and writes for SAVE-time validation
@@ -1,5 +1,5 @@
1
1
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
2
- var MESH_CA_KEY_REF = require("./dist-DRL3rEfN.js").buildSecretRef({
2
+ var MESH_CA_KEY_REF = require("./dist-DX5Fu3mV.js").buildSecretRef({
3
3
  owner: "system",
4
4
  scope: { kind: "global" },
5
5
  fieldPath: "meshCaKey"
@@ -1,4 +1,4 @@
1
- import { Ri as buildSecretRef } from "./dist-X1r44BdF.mjs";
1
+ import { Ri as buildSecretRef } from "./dist-CdFkkmXW.mjs";
2
2
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
3
3
  var MESH_CA_KEY_REF = buildSecretRef({
4
4
  owner: "system",
@@ -29,14 +29,34 @@ function currentDelegateHost() {
29
29
  override: process.env[_camstack_types_node.EDGETPU_LIB_ENV]
30
30
  };
31
31
  }
32
- function countUsbCorals(devices, fsx) {
33
- let count = 0;
32
+ /** usbfs names a device `/dev/bus/usb/<busnum>/<devnum>`, each zero-padded to three digits. */
33
+ function usbDeviceNode(device, fsx) {
34
+ const bus = Number.parseInt(fsx.readUsbAttr(device, "busnum"), 10);
35
+ const dev = Number.parseInt(fsx.readUsbAttr(device, "devnum"), 10);
36
+ if (!Number.isInteger(bus) || !Number.isInteger(dev) || bus <= 0 || dev <= 0) return null;
37
+ return `/dev/bus/usb/${String(bus).padStart(3, "0")}/${String(dev).padStart(3, "0")}`;
38
+ }
39
+ /**
40
+ * USB units: sysfs is the HOST's view — a container whose `/dev/bus/usb`
41
+ * mapping was removed still lists the stick under `/sys/bus/usb/devices`. A
42
+ * listed Coral is usable only when its usbfs device node is in this process's
43
+ * view AND opens read/write; otherwise it is present but not accessible.
44
+ */
45
+ function classifyUsb(devices, fsx) {
46
+ let usable = 0;
47
+ const inaccessibleNodes = [];
34
48
  for (const device of devices) {
35
49
  const vendor = fsx.readUsbAttr(device, "idVendor").toLowerCase();
36
50
  const product = fsx.readUsbAttr(device, "idProduct").toLowerCase();
37
- if (CORAL_USB_IDS.some((id) => id.vendor === vendor && id.product === product)) count++;
51
+ if (!CORAL_USB_IDS.some((id) => id.vendor === vendor && id.product === product)) continue;
52
+ const node = usbDeviceNode(device, fsx);
53
+ if (node !== null && fsx.exists(node) && fsx.canOpen(node)) usable++;
54
+ else inaccessibleNodes.push(node ?? `/sys/bus/usb/devices/${device}`);
38
55
  }
39
- return count;
56
+ return {
57
+ usable,
58
+ inaccessibleNodes
59
+ };
40
60
  }
41
61
  function countPciCorals(fsx) {
42
62
  let count = 0;
@@ -79,7 +99,9 @@ function classifyCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
79
99
  /**
80
100
  * Detect Coral Edge TPUs on USB and PCIe/M.2, with the evidence that decided.
81
101
  *
82
- * - USB: every matching USB device counts (multiple Corals run concurrently).
102
+ * - USB: every matching USB device counts (multiple Corals run concurrently),
103
+ * usable only if its `/dev/bus/usb/<BBB>/<DDD>` node opens read/write — a
104
+ * listed stick whose node is missing or refused is `device-not-accessible`.
83
105
  * - PCIe: the apex driver's units, each usable only if its device node opens;
84
106
  * a Coral PCI function the driver did not bind is `driver-missing`.
85
107
  * - Fallback: when the USB bus is NOT OBSERVABLE (`/sys/bus/usb/devices`
@@ -96,18 +118,28 @@ function classifyCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
96
118
  function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
97
119
  const usbDevices = fsx.listUsbDevices();
98
120
  const usbBus = usbDevices !== null && usbDevices.length > 0 ? "observed" : "unobservable";
99
- const usb = usbDevices === null ? 0 : countUsbCorals(usbDevices, fsx);
121
+ const usb = usbDevices === null ? {
122
+ usable: 0,
123
+ inaccessibleNodes: []
124
+ } : classifyUsb(usbDevices, fsx);
125
+ const usbSeen = usb.usable + usb.inaccessibleNodes.length;
126
+ const inaccessibleUsbNodes = usb.inaccessibleNodes;
100
127
  const pci = classifyPci(fsx);
101
128
  const units = [];
102
- if (usb > 0) units.push({
129
+ if (usb.usable > 0) units.push({
103
130
  bus: "usb",
104
- count: usb
131
+ count: usb.usable
105
132
  });
106
133
  if (pci.usable > 0) units.push({
107
134
  bus: "pci",
108
135
  count: pci.usable
109
136
  });
110
137
  const unavailable = [];
138
+ if (usb.inaccessibleNodes.length > 0) unavailable.push({
139
+ bus: "usb",
140
+ count: usb.inaccessibleNodes.length,
141
+ reason: "device-not-accessible"
142
+ });
111
143
  if (pci.driverMissing > 0) unavailable.push({
112
144
  bus: "pci",
113
145
  count: pci.driverMissing,
@@ -128,7 +160,8 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
128
160
  units
129
161
  },
130
162
  usbBus,
131
- decidedBy: usb > 0 ? "usb-ids" : "pci"
163
+ decidedBy: usbSeen > 0 ? "usb-ids" : "pci",
164
+ inaccessibleUsbNodes
132
165
  };
133
166
  if (usbBus === "unobservable" && (0, _camstack_types_node.chooseEdgetpuDelegate)({
134
167
  ...delegateHost,
@@ -142,12 +175,14 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
142
175
  }]
143
176
  },
144
177
  usbBus,
145
- decidedBy: "delegate-fallback"
178
+ decidedBy: "delegate-fallback",
179
+ inaccessibleUsbNodes
146
180
  };
147
181
  return {
148
182
  info: null,
149
183
  usbBus,
150
- decidedBy: "none"
184
+ decidedBy: "none",
185
+ inaccessibleUsbNodes
151
186
  };
152
187
  }
153
188
  function safeListOrNull(dir) {
@@ -1,5 +1,5 @@
1
1
  import { EDGETPU_LIB_ENV, chooseEdgetpuDelegate, nodeDataRootFromEnv } from "@camstack/types/node";
2
- import Kt from "node:fs";
2
+ import fs from "node:fs";
3
3
  //#region src/builtins/platform-probe/coral-accelerators.ts
4
4
  /**
5
5
  * Coral USB Edge TPU USB identifiers.
@@ -27,14 +27,34 @@ function currentDelegateHost() {
27
27
  override: process.env[EDGETPU_LIB_ENV]
28
28
  };
29
29
  }
30
- function countUsbCorals(devices, fsx) {
31
- let count = 0;
30
+ /** usbfs names a device `/dev/bus/usb/<busnum>/<devnum>`, each zero-padded to three digits. */
31
+ function usbDeviceNode(device, fsx) {
32
+ const bus = Number.parseInt(fsx.readUsbAttr(device, "busnum"), 10);
33
+ const dev = Number.parseInt(fsx.readUsbAttr(device, "devnum"), 10);
34
+ if (!Number.isInteger(bus) || !Number.isInteger(dev) || bus <= 0 || dev <= 0) return null;
35
+ return `/dev/bus/usb/${String(bus).padStart(3, "0")}/${String(dev).padStart(3, "0")}`;
36
+ }
37
+ /**
38
+ * USB units: sysfs is the HOST's view — a container whose `/dev/bus/usb`
39
+ * mapping was removed still lists the stick under `/sys/bus/usb/devices`. A
40
+ * listed Coral is usable only when its usbfs device node is in this process's
41
+ * view AND opens read/write; otherwise it is present but not accessible.
42
+ */
43
+ function classifyUsb(devices, fsx) {
44
+ let usable = 0;
45
+ const inaccessibleNodes = [];
32
46
  for (const device of devices) {
33
47
  const vendor = fsx.readUsbAttr(device, "idVendor").toLowerCase();
34
48
  const product = fsx.readUsbAttr(device, "idProduct").toLowerCase();
35
- if (CORAL_USB_IDS.some((id) => id.vendor === vendor && id.product === product)) count++;
49
+ if (!CORAL_USB_IDS.some((id) => id.vendor === vendor && id.product === product)) continue;
50
+ const node = usbDeviceNode(device, fsx);
51
+ if (node !== null && fsx.exists(node) && fsx.canOpen(node)) usable++;
52
+ else inaccessibleNodes.push(node ?? `/sys/bus/usb/devices/${device}`);
36
53
  }
37
- return count;
54
+ return {
55
+ usable,
56
+ inaccessibleNodes
57
+ };
38
58
  }
39
59
  function countPciCorals(fsx) {
40
60
  let count = 0;
@@ -77,7 +97,9 @@ function classifyCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
77
97
  /**
78
98
  * Detect Coral Edge TPUs on USB and PCIe/M.2, with the evidence that decided.
79
99
  *
80
- * - USB: every matching USB device counts (multiple Corals run concurrently).
100
+ * - USB: every matching USB device counts (multiple Corals run concurrently),
101
+ * usable only if its `/dev/bus/usb/<BBB>/<DDD>` node opens read/write — a
102
+ * listed stick whose node is missing or refused is `device-not-accessible`.
81
103
  * - PCIe: the apex driver's units, each usable only if its device node opens;
82
104
  * a Coral PCI function the driver did not bind is `driver-missing`.
83
105
  * - Fallback: when the USB bus is NOT OBSERVABLE (`/sys/bus/usb/devices`
@@ -94,18 +116,28 @@ function classifyCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
94
116
  function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
95
117
  const usbDevices = fsx.listUsbDevices();
96
118
  const usbBus = usbDevices !== null && usbDevices.length > 0 ? "observed" : "unobservable";
97
- const usb = usbDevices === null ? 0 : countUsbCorals(usbDevices, fsx);
119
+ const usb = usbDevices === null ? {
120
+ usable: 0,
121
+ inaccessibleNodes: []
122
+ } : classifyUsb(usbDevices, fsx);
123
+ const usbSeen = usb.usable + usb.inaccessibleNodes.length;
124
+ const inaccessibleUsbNodes = usb.inaccessibleNodes;
98
125
  const pci = classifyPci(fsx);
99
126
  const units = [];
100
- if (usb > 0) units.push({
127
+ if (usb.usable > 0) units.push({
101
128
  bus: "usb",
102
- count: usb
129
+ count: usb.usable
103
130
  });
104
131
  if (pci.usable > 0) units.push({
105
132
  bus: "pci",
106
133
  count: pci.usable
107
134
  });
108
135
  const unavailable = [];
136
+ if (usb.inaccessibleNodes.length > 0) unavailable.push({
137
+ bus: "usb",
138
+ count: usb.inaccessibleNodes.length,
139
+ reason: "device-not-accessible"
140
+ });
109
141
  if (pci.driverMissing > 0) unavailable.push({
110
142
  bus: "pci",
111
143
  count: pci.driverMissing,
@@ -126,7 +158,8 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
126
158
  units
127
159
  },
128
160
  usbBus,
129
- decidedBy: usb > 0 ? "usb-ids" : "pci"
161
+ decidedBy: usbSeen > 0 ? "usb-ids" : "pci",
162
+ inaccessibleUsbNodes
130
163
  };
131
164
  if (usbBus === "unobservable" && chooseEdgetpuDelegate({
132
165
  ...delegateHost,
@@ -140,31 +173,33 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
140
173
  }]
141
174
  },
142
175
  usbBus,
143
- decidedBy: "delegate-fallback"
176
+ decidedBy: "delegate-fallback",
177
+ inaccessibleUsbNodes
144
178
  };
145
179
  return {
146
180
  info: null,
147
181
  usbBus,
148
- decidedBy: "none"
182
+ decidedBy: "none",
183
+ inaccessibleUsbNodes
149
184
  };
150
185
  }
151
186
  function safeListOrNull(dir) {
152
187
  try {
153
- return Kt.readdirSync(dir);
188
+ return fs.readdirSync(dir);
154
189
  } catch {
155
190
  return null;
156
191
  }
157
192
  }
158
193
  function safeList(dir) {
159
194
  try {
160
- return Kt.readdirSync(dir);
195
+ return fs.readdirSync(dir);
161
196
  } catch {
162
197
  return [];
163
198
  }
164
199
  }
165
200
  function safeRead(path) {
166
201
  try {
167
- return Kt.readFileSync(path, "utf8").trim();
202
+ return fs.readFileSync(path, "utf8").trim();
168
203
  } catch {
169
204
  return "";
170
205
  }
@@ -178,7 +213,7 @@ var nodeCoralFs = {
178
213
  listApexClass: () => safeList("/sys/class/apex"),
179
214
  canOpen: (path) => {
180
215
  try {
181
- Kt.accessSync(path, Kt.constants.R_OK | Kt.constants.W_OK);
216
+ fs.accessSync(path, fs.constants.R_OK | fs.constants.W_OK);
182
217
  return true;
183
218
  } catch {
184
219
  return false;
@@ -186,7 +221,7 @@ var nodeCoralFs = {
186
221
  },
187
222
  exists: (path) => {
188
223
  try {
189
- return Kt.existsSync(path);
224
+ return fs.existsSync(path);
190
225
  } catch {
191
226
  return false;
192
227
  }
@@ -3,7 +3,7 @@ import * as path$1 from "node:path";
3
3
  import path from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { HF_REPO, MODEL_FORMATS, describeCustomActions, hfModelUrl } from "@camstack/types/addon";
6
- import * as fs from "node:fs";
6
+ import * as fs$1 from "node:fs";
7
7
  import { createReadStream, promises } from "node:fs";
8
8
  import { createServer } from "node:http";
9
9
  import { brotliCompress, constants as constants$1, gzip } from "node:zlib";
@@ -159,7 +159,7 @@ var HOSTED_MODEL_REVISIONS = {
159
159
  //#endregion
160
160
  //#region src/download/model-downloader.ts
161
161
  function isNonEmptyFile(filePath) {
162
- return fs.existsSync(filePath) && fs.statSync(filePath).size > 0;
162
+ return fs$1.existsSync(filePath) && fs$1.statSync(filePath).size > 0;
163
163
  }
164
164
  /**
165
165
  * Sibling files of a single-file (non-directory) format — extra files the
@@ -236,11 +236,11 @@ function resolveRedirectUrl(current, location) {
236
236
  return new URL(location, current);
237
237
  }
238
238
  async function downloadFile(url, destPath, onProgressOrOptions) {
239
- if (fs.existsSync(destPath)) return destPath;
239
+ if (fs$1.existsSync(destPath)) return destPath;
240
240
  const opts = normalizeDownloadOptions(onProgressOrOptions);
241
241
  const fetchImpl = opts.fetchImpl ?? fetch;
242
242
  const maxRedirects = opts.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
243
- fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
243
+ fs$1.mkdirSync(path$1.dirname(destPath), { recursive: true });
244
244
  const tmpPath = destPath + ".downloading";
245
245
  try {
246
246
  let current = url;
@@ -278,7 +278,7 @@ async function downloadFile(url, destPath, onProgressOrOptions) {
278
278
  if (!response.body) throw new Error(`No response body from ${url}`);
279
279
  const total = parseInt(response.headers.get("content-length") ?? "0", 10);
280
280
  let downloaded = 0;
281
- const fileStream = fs.createWriteStream(tmpPath);
281
+ const fileStream = fs$1.createWriteStream(tmpPath);
282
282
  const reader = response.body.getReader();
283
283
  try {
284
284
  for (;;) {
@@ -296,11 +296,11 @@ async function downloadFile(url, destPath, onProgressOrOptions) {
296
296
  fileStream.on("error", reject);
297
297
  });
298
298
  }
299
- fs.renameSync(tmpPath, destPath);
299
+ fs$1.renameSync(tmpPath, destPath);
300
300
  return destPath;
301
301
  } catch (err) {
302
302
  try {
303
- fs.unlinkSync(tmpPath);
303
+ fs$1.unlinkSync(tmpPath);
304
304
  } catch {}
305
305
  throw err;
306
306
  }
@@ -324,12 +324,12 @@ async function downloadModel(options) {
324
324
  const { url, fallbackUrls = [], destDir, filename, expectedSha256, onProgress } = options;
325
325
  const fname = filename ?? url.split("/").pop() ?? "model.bin";
326
326
  const destPath = path$1.join(destDir, fname);
327
- if (fs.existsSync(destPath)) return {
327
+ if (fs$1.existsSync(destPath)) return {
328
328
  filePath: destPath,
329
329
  downloadedBytes: 0,
330
330
  fromCache: true
331
331
  };
332
- fs.mkdirSync(destDir, { recursive: true });
332
+ fs$1.mkdirSync(destDir, { recursive: true });
333
333
  const urls = [url, ...fallbackUrls];
334
334
  let lastError = null;
335
335
  for (const tryUrl of urls) try {
@@ -337,25 +337,25 @@ async function downloadModel(options) {
337
337
  if (expectedSha256) {
338
338
  const hash = await computeSha256(destPath);
339
339
  if (hash !== expectedSha256) {
340
- fs.unlinkSync(destPath);
340
+ fs$1.unlinkSync(destPath);
341
341
  throw new Error(`SHA256 mismatch: expected ${expectedSha256}, got ${hash}`);
342
342
  }
343
343
  }
344
344
  return {
345
345
  filePath: destPath,
346
- downloadedBytes: fs.statSync(destPath).size,
346
+ downloadedBytes: fs$1.statSync(destPath).size,
347
347
  fromCache: false
348
348
  };
349
349
  } catch (e) {
350
350
  lastError = e;
351
- if (fs.existsSync(destPath)) fs.unlinkSync(destPath);
351
+ if (fs$1.existsSync(destPath)) fs$1.unlinkSync(destPath);
352
352
  }
353
353
  throw lastError ?? /* @__PURE__ */ new Error(`Failed to download model from ${url}`);
354
354
  }
355
355
  async function computeSha256(filePath) {
356
356
  return new Promise((resolve, reject) => {
357
357
  const hash = createHash("sha256");
358
- const stream = fs.createReadStream(filePath);
358
+ const stream = fs$1.createReadStream(filePath);
359
359
  stream.on("data", (chunk) => hash.update(chunk));
360
360
  stream.on("end", () => resolve(hash.digest("hex")));
361
361
  stream.on("error", reject);
@@ -380,28 +380,28 @@ async function downloadDirectory(url, destDir, knownFiles, onProgress) {
380
380
  fileUrl: `https://huggingface.co/${repo}/resolve/main/${dirPath}/${f}`
381
381
  }));
382
382
  const tmpDir = destDir + ".downloading";
383
- fs.rmSync(tmpDir, {
383
+ fs$1.rmSync(tmpDir, {
384
384
  recursive: true,
385
385
  force: true
386
386
  });
387
- fs.mkdirSync(tmpDir, { recursive: true });
387
+ fs$1.mkdirSync(tmpDir, { recursive: true });
388
388
  let totalDownloaded = 0;
389
389
  try {
390
390
  for (const file of files) {
391
391
  const destPath = path$1.join(tmpDir, file.relativePath);
392
- fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
392
+ fs$1.mkdirSync(path$1.dirname(destPath), { recursive: true });
393
393
  await downloadFile(file.fileUrl, destPath, (downloaded, _total) => {
394
394
  onProgress?.(totalDownloaded + downloaded, void 0);
395
395
  });
396
- totalDownloaded += fs.statSync(destPath).size;
396
+ totalDownloaded += fs$1.statSync(destPath).size;
397
397
  }
398
- fs.rmSync(destDir, {
398
+ fs$1.rmSync(destDir, {
399
399
  recursive: true,
400
400
  force: true
401
401
  });
402
- fs.renameSync(tmpDir, destDir);
402
+ fs$1.renameSync(tmpDir, destDir);
403
403
  } catch (err) {
404
- fs.rmSync(tmpDir, {
404
+ fs$1.rmSync(tmpDir, {
405
405
  recursive: true,
406
406
  force: true
407
407
  });
@@ -433,7 +433,7 @@ function revisionRecordPath(modelPath) {
433
433
  }
434
434
  function readRevisionRecord(modelPath) {
435
435
  try {
436
- return fs.readFileSync(revisionRecordPath(modelPath), "utf8").trim();
436
+ return fs$1.readFileSync(revisionRecordPath(modelPath), "utf8").trim();
437
437
  } catch {
438
438
  return null;
439
439
  }
@@ -497,8 +497,8 @@ function writeRevisionRecord(modelPath, revision) {
497
497
  if (revision === void 0) return;
498
498
  const record = revisionRecordPath(modelPath);
499
499
  const tmp = `${record}.tmp`;
500
- fs.writeFileSync(tmp, `${revision}\n`);
501
- fs.renameSync(tmp, record);
500
+ fs$1.writeFileSync(tmp, `${revision}\n`);
501
+ fs$1.renameSync(tmp, record);
502
502
  }
503
503
  /**
504
504
  * Prove an unrecorded (or differently recorded) copy current by hashing its
@@ -518,9 +518,9 @@ async function adoptByHash(modelsDir, modelPath, formatEntry) {
518
518
  }
519
519
  /** True when every file of the format is on disk, whatever revision it holds. */
520
520
  function isCompleteCopy(modelsDir, modelPath, formatEntry) {
521
- if (!fs.existsSync(modelPath)) return false;
522
- if (formatEntry.isDirectory) return fs.existsSync(path$1.join(modelPath, "Manifest.json"));
523
- if (fs.statSync(modelPath).size <= 0) return false;
521
+ if (!fs$1.existsSync(modelPath)) return false;
522
+ if (formatEntry.isDirectory) return fs$1.existsSync(path$1.join(modelPath, "Manifest.json"));
523
+ if (fs$1.statSync(modelPath).size <= 0) return false;
524
524
  return siblingFilesFor(formatEntry).every((f) => isNonEmptyFile(path$1.join(modelsDir, f)));
525
525
  }
526
526
  /**
@@ -542,14 +542,14 @@ async function replaceSingleFileFormat(url, modelPath, modelsDir, siblings, onPr
542
542
  }));
543
543
  try {
544
544
  for (const [i, part] of parts.entries()) {
545
- fs.rmSync(part.staged, { force: true });
545
+ fs$1.rmSync(part.staged, { force: true });
546
546
  await downloadFile(part.url, part.staged, i === 0 ? (downloaded, total) => onProgress?.(downloaded, total === 0 ? void 0 : total) : void 0);
547
547
  }
548
548
  } catch (err) {
549
- for (const part of parts) fs.rmSync(part.staged, { force: true });
549
+ for (const part of parts) fs$1.rmSync(part.staged, { force: true });
550
550
  throw err;
551
551
  }
552
- for (const part of parts) fs.renameSync(part.staged, part.dest);
552
+ for (const part of parts) fs$1.renameSync(part.staged, part.dest);
553
553
  }
554
554
  /**
555
555
  * Resolve a `ModelCatalogEntry` against `modelsDir`: download model file
@@ -564,14 +564,14 @@ async function ensureModel(modelsDir, entry, format, onProgress) {
564
564
  const modelPath = path$1.join(modelsDir, filename);
565
565
  const siblings = siblingFilesFor(formatEntry);
566
566
  let outdated = false;
567
- if (fs.existsSync(modelPath)) if (formatEntry.isDirectory && !fs.existsSync(path$1.join(modelPath, "Manifest.json"))) fs.rmSync(modelPath, {
567
+ if (fs$1.existsSync(modelPath)) if (formatEntry.isDirectory && !fs$1.existsSync(path$1.join(modelPath, "Manifest.json"))) fs$1.rmSync(modelPath, {
568
568
  recursive: true,
569
569
  force: true
570
570
  });
571
571
  else if (siblings.some((f) => !isNonEmptyFile(path$1.join(modelsDir, f)))) outdated = !isCurrentRevision(modelPath, formatEntry) && !await adoptByHash(modelsDir, modelPath, formatEntry);
572
572
  else if (isCurrentRevision(modelPath, formatEntry) || await adoptByHash(modelsDir, modelPath, formatEntry)) return modelPath;
573
573
  else outdated = true;
574
- fs.mkdirSync(modelsDir, { recursive: true });
574
+ fs$1.mkdirSync(modelsDir, { recursive: true });
575
575
  if (formatEntry.isDirectory) await downloadDirectory(formatEntry.url, modelPath, formatEntry.files, onProgress);
576
576
  else if (outdated) await replaceSingleFileFormat(formatEntry.url, modelPath, modelsDir, siblings, onProgress);
577
577
  else {
@@ -629,25 +629,25 @@ function isModelDownloaded(modelsDir, entry, format) {
629
629
  const formatEntry = entry.formats[format];
630
630
  if (!formatEntry) return false;
631
631
  const modelPath = getModelFilePath(modelsDir, entry, format);
632
- if (!modelPath || !fs.existsSync(modelPath)) return false;
632
+ if (!modelPath || !fs$1.existsSync(modelPath)) return false;
633
633
  if (!isCurrentRevision(modelPath, formatEntry)) return false;
634
634
  return isCompleteCopy(modelsDir, modelPath, formatEntry);
635
635
  }
636
636
  /** Remove the on-disk model file/directory. Returns true if something was deleted. */
637
637
  function deleteModelFromDisk(modelsDir, entry, format) {
638
638
  const modelPath = getModelFilePath(modelsDir, entry, format);
639
- if (!modelPath || !fs.existsSync(modelPath)) return false;
640
- fs.rmSync(revisionRecordPath(modelPath), { force: true });
639
+ if (!modelPath || !fs$1.existsSync(modelPath)) return false;
640
+ fs$1.rmSync(revisionRecordPath(modelPath), { force: true });
641
641
  const formatEntry = entry.formats[format];
642
- if (formatEntry?.isDirectory) fs.rmSync(modelPath, {
642
+ if (formatEntry?.isDirectory) fs$1.rmSync(modelPath, {
643
643
  recursive: true,
644
644
  force: true
645
645
  });
646
646
  else {
647
- fs.unlinkSync(modelPath);
647
+ fs$1.unlinkSync(modelPath);
648
648
  if (formatEntry) for (const sibling of siblingFilesFor(formatEntry)) {
649
649
  const sibPath = path$1.join(modelsDir, sibling);
650
- if (fs.existsSync(sibPath)) fs.unlinkSync(sibPath);
650
+ if (fs$1.existsSync(sibPath)) fs$1.unlinkSync(sibPath);
651
651
  }
652
652
  }
653
653
  return true;
@@ -1,4 +1,4 @@
1
- import { A as DEVICE_SAN_USER_PREFIX, Ri as buildSecretRef, k as DEVICE_SAN_CREDENTIAL_PREFIX } from "./dist-X1r44BdF.mjs";
1
+ import { A as DEVICE_SAN_USER_PREFIX, Ri as buildSecretRef, k as DEVICE_SAN_CREDENTIAL_PREFIX } from "./dist-CdFkkmXW.mjs";
2
2
  import { S as backdatedNotBefore, a as KeyUsageFlags, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension } from "./x509.es-DK__ETIe.mjs";
3
3
  import { X509Certificate, createPublicKey, randomBytes, verify, webcrypto } from "node:crypto";
4
4
  //#region src/auth/jwt-signing-key.ts
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-DRL3rEfN.js");
1
+ const require_dist = require("./dist-DX5Fu3mV.js");
2
2
  const require_x509_es = require("./x509.es-C4cOo48M.js");
3
3
  let node_crypto = require("node:crypto");
4
4
  //#region src/auth/jwt-signing-key.ts