@camstack/server 1.2.775 → 1.2.776
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.
- package/CHANGELOG.md +6 -0
- package/package.json +5 -13
- package/system/dist/addon-runner.js +17 -4
- package/system/dist/addon-runner.mjs +17 -4
- package/system/dist/addon-utils.mjs +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +3 -3
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +4 -4
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +4 -4
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +3 -3
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +9 -9
- package/system/dist/builtins/platform-probe/index.mjs +9 -9
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +19 -19
- package/system/dist/builtins/system-config/system-config.addon.mjs +282 -282
- package/system/dist/{coral-accelerators-DBlgWB8k.mjs → coral-accelerators-BW3OcrLD.mjs} +6 -6
- package/system/dist/{custom-action-registry-oHl1xltx.mjs → custom-action-registry-BIJZBObd.mjs} +37 -37
- package/system/dist/index.js +17 -4
- package/system/dist/index.mjs +229 -216
- package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +7 -1
- package/system/dist/{restore-archive-DYn0lsQl.mjs → restore-archive-BT_VMwFC.mjs} +149 -149
- package/system/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EDGETPU_LIB_ENV, chooseEdgetpuDelegate, nodeDataRootFromEnv } from "@camstack/types/node";
|
|
2
|
-
import
|
|
2
|
+
import Kt from "node:fs";
|
|
3
3
|
//#region src/builtins/platform-probe/coral-accelerators.ts
|
|
4
4
|
/**
|
|
5
5
|
* Coral USB Edge TPU USB identifiers.
|
|
@@ -185,21 +185,21 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
|
|
|
185
185
|
}
|
|
186
186
|
function safeListOrNull(dir) {
|
|
187
187
|
try {
|
|
188
|
-
return
|
|
188
|
+
return Kt.readdirSync(dir);
|
|
189
189
|
} catch {
|
|
190
190
|
return null;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
function safeList(dir) {
|
|
194
194
|
try {
|
|
195
|
-
return
|
|
195
|
+
return Kt.readdirSync(dir);
|
|
196
196
|
} catch {
|
|
197
197
|
return [];
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
function safeRead(path) {
|
|
201
201
|
try {
|
|
202
|
-
return
|
|
202
|
+
return Kt.readFileSync(path, "utf8").trim();
|
|
203
203
|
} catch {
|
|
204
204
|
return "";
|
|
205
205
|
}
|
|
@@ -213,7 +213,7 @@ var nodeCoralFs = {
|
|
|
213
213
|
listApexClass: () => safeList("/sys/class/apex"),
|
|
214
214
|
canOpen: (path) => {
|
|
215
215
|
try {
|
|
216
|
-
|
|
216
|
+
Kt.accessSync(path, Kt.constants.R_OK | Kt.constants.W_OK);
|
|
217
217
|
return true;
|
|
218
218
|
} catch {
|
|
219
219
|
return false;
|
|
@@ -221,7 +221,7 @@ var nodeCoralFs = {
|
|
|
221
221
|
},
|
|
222
222
|
exists: (path) => {
|
|
223
223
|
try {
|
|
224
|
-
return
|
|
224
|
+
return Kt.existsSync(path);
|
|
225
225
|
} catch {
|
|
226
226
|
return false;
|
|
227
227
|
}
|
package/system/dist/{custom-action-registry-oHl1xltx.mjs → custom-action-registry-BIJZBObd.mjs}
RENAMED
|
@@ -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
|
|
6
|
+
import * as fs 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
|
|
162
|
+
return fs.existsSync(filePath) && fs.statSync(filePath).size > 0;
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Sibling files of a single-file (non-directory) format — extra files the
|
|
@@ -269,11 +269,11 @@ function resolveRedirectUrl(current, location) {
|
|
|
269
269
|
return new URL(location, current);
|
|
270
270
|
}
|
|
271
271
|
async function downloadFile(url, destPath, onProgressOrOptions) {
|
|
272
|
-
if (fs
|
|
272
|
+
if (fs.existsSync(destPath)) return destPath;
|
|
273
273
|
const opts = normalizeDownloadOptions(onProgressOrOptions);
|
|
274
274
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
275
275
|
const maxRedirects = opts.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
276
|
-
fs
|
|
276
|
+
fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
|
|
277
277
|
const tmpPath = destPath + ".downloading";
|
|
278
278
|
try {
|
|
279
279
|
let current = url;
|
|
@@ -315,7 +315,7 @@ async function downloadFile(url, destPath, onProgressOrOptions) {
|
|
|
315
315
|
if (!response.body) throw new Error(`No response body from ${url}`);
|
|
316
316
|
const total = parseInt(response.headers.get("content-length") ?? "0", 10);
|
|
317
317
|
let downloaded = 0;
|
|
318
|
-
const fileStream = fs
|
|
318
|
+
const fileStream = fs.createWriteStream(tmpPath);
|
|
319
319
|
const reader = response.body.getReader();
|
|
320
320
|
try {
|
|
321
321
|
for (;;) {
|
|
@@ -333,11 +333,11 @@ async function downloadFile(url, destPath, onProgressOrOptions) {
|
|
|
333
333
|
fileStream.on("error", reject);
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
fs
|
|
336
|
+
fs.renameSync(tmpPath, destPath);
|
|
337
337
|
return destPath;
|
|
338
338
|
} catch (err) {
|
|
339
339
|
try {
|
|
340
|
-
fs
|
|
340
|
+
fs.unlinkSync(tmpPath);
|
|
341
341
|
} catch {}
|
|
342
342
|
throw err;
|
|
343
343
|
}
|
|
@@ -368,12 +368,12 @@ async function downloadModel(options) {
|
|
|
368
368
|
const { url, fallbackUrls = [], destDir, filename, expectedSha256, onProgress } = options;
|
|
369
369
|
const fname = filename ?? url.split("/").pop() ?? "model.bin";
|
|
370
370
|
const destPath = path$1.join(destDir, fname);
|
|
371
|
-
if (fs
|
|
371
|
+
if (fs.existsSync(destPath)) return {
|
|
372
372
|
filePath: destPath,
|
|
373
373
|
downloadedBytes: 0,
|
|
374
374
|
fromCache: true
|
|
375
375
|
};
|
|
376
|
-
fs
|
|
376
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
377
377
|
const urls = [url, ...fallbackUrls];
|
|
378
378
|
let lastError = null;
|
|
379
379
|
for (const tryUrl of urls) try {
|
|
@@ -381,25 +381,25 @@ async function downloadModel(options) {
|
|
|
381
381
|
if (expectedSha256) {
|
|
382
382
|
const hash = await computeSha256(destPath);
|
|
383
383
|
if (hash !== expectedSha256) {
|
|
384
|
-
fs
|
|
384
|
+
fs.unlinkSync(destPath);
|
|
385
385
|
throw new Error(`SHA256 mismatch: expected ${expectedSha256}, got ${hash}`);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
return {
|
|
389
389
|
filePath: destPath,
|
|
390
|
-
downloadedBytes: fs
|
|
390
|
+
downloadedBytes: fs.statSync(destPath).size,
|
|
391
391
|
fromCache: false
|
|
392
392
|
};
|
|
393
393
|
} catch (e) {
|
|
394
394
|
lastError = e;
|
|
395
|
-
if (fs
|
|
395
|
+
if (fs.existsSync(destPath)) fs.unlinkSync(destPath);
|
|
396
396
|
}
|
|
397
397
|
throw lastError ?? /* @__PURE__ */ new Error(`Failed to download model from ${url}`);
|
|
398
398
|
}
|
|
399
399
|
async function computeSha256(filePath) {
|
|
400
400
|
return new Promise((resolve, reject) => {
|
|
401
401
|
const hash = createHash("sha256");
|
|
402
|
-
const stream = fs
|
|
402
|
+
const stream = fs.createReadStream(filePath);
|
|
403
403
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
404
404
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
405
405
|
stream.on("error", reject);
|
|
@@ -424,28 +424,28 @@ async function downloadDirectory(url, destDir, knownFiles, onProgress) {
|
|
|
424
424
|
fileUrl: `https://huggingface.co/${repo}/resolve/main/${dirPath}/${f}`
|
|
425
425
|
}));
|
|
426
426
|
const tmpDir = destDir + ".downloading";
|
|
427
|
-
fs
|
|
427
|
+
fs.rmSync(tmpDir, {
|
|
428
428
|
recursive: true,
|
|
429
429
|
force: true
|
|
430
430
|
});
|
|
431
|
-
fs
|
|
431
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
432
432
|
let totalDownloaded = 0;
|
|
433
433
|
try {
|
|
434
434
|
for (const file of files) {
|
|
435
435
|
const destPath = path$1.join(tmpDir, file.relativePath);
|
|
436
|
-
fs
|
|
436
|
+
fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
|
|
437
437
|
await downloadFile(file.fileUrl, destPath, (downloaded, _total) => {
|
|
438
438
|
onProgress?.(totalDownloaded + downloaded, void 0);
|
|
439
439
|
});
|
|
440
|
-
totalDownloaded += fs
|
|
440
|
+
totalDownloaded += fs.statSync(destPath).size;
|
|
441
441
|
}
|
|
442
|
-
fs
|
|
442
|
+
fs.rmSync(destDir, {
|
|
443
443
|
recursive: true,
|
|
444
444
|
force: true
|
|
445
445
|
});
|
|
446
|
-
fs
|
|
446
|
+
fs.renameSync(tmpDir, destDir);
|
|
447
447
|
} catch (err) {
|
|
448
|
-
fs
|
|
448
|
+
fs.rmSync(tmpDir, {
|
|
449
449
|
recursive: true,
|
|
450
450
|
force: true
|
|
451
451
|
});
|
|
@@ -477,7 +477,7 @@ function revisionRecordPath(modelPath) {
|
|
|
477
477
|
}
|
|
478
478
|
function readRevisionRecord(modelPath) {
|
|
479
479
|
try {
|
|
480
|
-
return fs
|
|
480
|
+
return fs.readFileSync(revisionRecordPath(modelPath), "utf8").trim();
|
|
481
481
|
} catch {
|
|
482
482
|
return null;
|
|
483
483
|
}
|
|
@@ -541,8 +541,8 @@ function writeRevisionRecord(modelPath, revision) {
|
|
|
541
541
|
if (revision === void 0) return;
|
|
542
542
|
const record = revisionRecordPath(modelPath);
|
|
543
543
|
const tmp = `${record}.tmp`;
|
|
544
|
-
fs
|
|
545
|
-
fs
|
|
544
|
+
fs.writeFileSync(tmp, `${revision}\n`);
|
|
545
|
+
fs.renameSync(tmp, record);
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
548
548
|
* Prove an unrecorded (or differently recorded) copy current by hashing its
|
|
@@ -562,9 +562,9 @@ async function adoptByHash(modelsDir, modelPath, formatEntry) {
|
|
|
562
562
|
}
|
|
563
563
|
/** True when every file of the format is on disk, whatever revision it holds. */
|
|
564
564
|
function isCompleteCopy(modelsDir, modelPath, formatEntry) {
|
|
565
|
-
if (!fs
|
|
566
|
-
if (formatEntry.isDirectory) return fs
|
|
567
|
-
if (fs
|
|
565
|
+
if (!fs.existsSync(modelPath)) return false;
|
|
566
|
+
if (formatEntry.isDirectory) return fs.existsSync(path$1.join(modelPath, "Manifest.json"));
|
|
567
|
+
if (fs.statSync(modelPath).size <= 0) return false;
|
|
568
568
|
return siblingFilesFor(formatEntry).every((f) => isNonEmptyFile(path$1.join(modelsDir, f)));
|
|
569
569
|
}
|
|
570
570
|
/**
|
|
@@ -586,14 +586,14 @@ async function replaceSingleFileFormat(url, modelPath, modelsDir, siblings, onPr
|
|
|
586
586
|
}));
|
|
587
587
|
try {
|
|
588
588
|
for (const [i, part] of parts.entries()) {
|
|
589
|
-
fs
|
|
589
|
+
fs.rmSync(part.staged, { force: true });
|
|
590
590
|
await downloadFile(part.url, part.staged, i === 0 ? (downloaded, total) => onProgress?.(downloaded, total === 0 ? void 0 : total) : void 0);
|
|
591
591
|
}
|
|
592
592
|
} catch (err) {
|
|
593
|
-
for (const part of parts) fs
|
|
593
|
+
for (const part of parts) fs.rmSync(part.staged, { force: true });
|
|
594
594
|
throw err;
|
|
595
595
|
}
|
|
596
|
-
for (const part of parts) fs
|
|
596
|
+
for (const part of parts) fs.renameSync(part.staged, part.dest);
|
|
597
597
|
}
|
|
598
598
|
/**
|
|
599
599
|
* Resolve a `ModelCatalogEntry` against `modelsDir`: download model file
|
|
@@ -608,14 +608,14 @@ async function ensureModel(modelsDir, entry, format, onProgress) {
|
|
|
608
608
|
const modelPath = path$1.join(modelsDir, filename);
|
|
609
609
|
const siblings = siblingFilesFor(formatEntry);
|
|
610
610
|
let outdated = false;
|
|
611
|
-
if (fs
|
|
611
|
+
if (fs.existsSync(modelPath)) if (formatEntry.isDirectory && !fs.existsSync(path$1.join(modelPath, "Manifest.json"))) fs.rmSync(modelPath, {
|
|
612
612
|
recursive: true,
|
|
613
613
|
force: true
|
|
614
614
|
});
|
|
615
615
|
else if (siblings.some((f) => !isNonEmptyFile(path$1.join(modelsDir, f)))) outdated = !isCurrentRevision(modelPath, formatEntry) && !await adoptByHash(modelsDir, modelPath, formatEntry);
|
|
616
616
|
else if (isCurrentRevision(modelPath, formatEntry) || await adoptByHash(modelsDir, modelPath, formatEntry)) return modelPath;
|
|
617
617
|
else outdated = true;
|
|
618
|
-
fs
|
|
618
|
+
fs.mkdirSync(modelsDir, { recursive: true });
|
|
619
619
|
if (formatEntry.isDirectory) await downloadDirectory(formatEntry.url, modelPath, formatEntry.files, onProgress);
|
|
620
620
|
else if (outdated) await replaceSingleFileFormat(formatEntry.url, modelPath, modelsDir, siblings, onProgress);
|
|
621
621
|
else {
|
|
@@ -673,25 +673,25 @@ function isModelDownloaded(modelsDir, entry, format) {
|
|
|
673
673
|
const formatEntry = entry.formats[format];
|
|
674
674
|
if (!formatEntry) return false;
|
|
675
675
|
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
676
|
-
if (!modelPath || !fs
|
|
676
|
+
if (!modelPath || !fs.existsSync(modelPath)) return false;
|
|
677
677
|
if (!isCurrentRevision(modelPath, formatEntry)) return false;
|
|
678
678
|
return isCompleteCopy(modelsDir, modelPath, formatEntry);
|
|
679
679
|
}
|
|
680
680
|
/** Remove the on-disk model file/directory. Returns true if something was deleted. */
|
|
681
681
|
function deleteModelFromDisk(modelsDir, entry, format) {
|
|
682
682
|
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
683
|
-
if (!modelPath || !fs
|
|
684
|
-
fs
|
|
683
|
+
if (!modelPath || !fs.existsSync(modelPath)) return false;
|
|
684
|
+
fs.rmSync(revisionRecordPath(modelPath), { force: true });
|
|
685
685
|
const formatEntry = entry.formats[format];
|
|
686
|
-
if (formatEntry?.isDirectory) fs
|
|
686
|
+
if (formatEntry?.isDirectory) fs.rmSync(modelPath, {
|
|
687
687
|
recursive: true,
|
|
688
688
|
force: true
|
|
689
689
|
});
|
|
690
690
|
else {
|
|
691
|
-
fs
|
|
691
|
+
fs.unlinkSync(modelPath);
|
|
692
692
|
if (formatEntry) for (const sibling of siblingFilesFor(formatEntry)) {
|
|
693
693
|
const sibPath = path$1.join(modelsDir, sibling);
|
|
694
|
-
if (fs
|
|
694
|
+
if (fs.existsSync(sibPath)) fs.unlinkSync(sibPath);
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
return true;
|
package/system/dist/index.js
CHANGED
|
@@ -16272,7 +16272,13 @@ function buildNativeCapProxy(broker, addonId, capName, deviceId) {
|
|
|
16272
16272
|
function deviceHasStreamSources(device) {
|
|
16273
16273
|
return typeof Reflect.get(device, "getStreamSources") === "function";
|
|
16274
16274
|
}
|
|
16275
|
-
|
|
16275
|
+
/**
|
|
16276
|
+
* `afterRemove` is the worker's local teardown (registry entry, native caps,
|
|
16277
|
+
* children). The hub's `remove` reaches a forked worker ONLY through this
|
|
16278
|
+
* provider, so the lifecycle call alone would leave a zombie instance in the
|
|
16279
|
+
* worker (timers running, still listed as adopted). It is idempotent.
|
|
16280
|
+
*/
|
|
16281
|
+
function buildDeviceOpsProvider(device, afterRemove) {
|
|
16276
16282
|
const assertMatch = (incoming) => {
|
|
16277
16283
|
if (incoming !== device.id) throw new Error(`device-ops: deviceId mismatch — expected '${device.id}', got '${incoming}'`);
|
|
16278
16284
|
};
|
|
@@ -16300,6 +16306,7 @@ function buildDeviceOpsProvider(device) {
|
|
|
16300
16306
|
removeDevice: async (input) => {
|
|
16301
16307
|
assertMatch(input.deviceId);
|
|
16302
16308
|
await device.removeDevice();
|
|
16309
|
+
await afterRemove?.(device.id);
|
|
16303
16310
|
},
|
|
16304
16311
|
getSettingsSchema: async (input) => {
|
|
16305
16312
|
assertMatch(input.deviceId);
|
|
@@ -16530,6 +16537,10 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
16530
16537
|
}
|
|
16531
16538
|
};
|
|
16532
16539
|
};
|
|
16540
|
+
/** The integration a spawned child inherits: its parent's persisted one, if any. */
|
|
16541
|
+
const resolveParentIntegrationId = async (parentId) => {
|
|
16542
|
+
return (await callDeviceManager(api, "loadMeta", { deviceId: parentId }).catch(() => null))?.integrationId ?? void 0;
|
|
16543
|
+
};
|
|
16533
16544
|
/**
|
|
16534
16545
|
* Spawn one accessory child device declared by a parent's
|
|
16535
16546
|
* `getAccessoryChildren()`. Mirrors the standard `create()` flow
|
|
@@ -16547,13 +16558,15 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
16547
16558
|
const empty = {};
|
|
16548
16559
|
const existingMeta = await callDeviceManager(api, "loadMeta", { deviceId: id }).catch(() => null);
|
|
16549
16560
|
const isFirstSpawn = !existingMeta || existingMeta.name === childStableId;
|
|
16561
|
+
const linkDeviceId = spec.meta.linkDeviceId ?? parent.id;
|
|
16562
|
+
const integrationId = spec.meta.integrationId ?? await resolveParentIntegrationId(parent.id);
|
|
16550
16563
|
await callDeviceManager(api, "applyInitialMeta", {
|
|
16551
16564
|
deviceId: id,
|
|
16552
|
-
linkDeviceId
|
|
16565
|
+
linkDeviceId,
|
|
16553
16566
|
...isFirstSpawn && spec.meta.name !== void 0 ? { name: spec.meta.name } : {},
|
|
16554
16567
|
...isFirstSpawn && spec.meta.location !== void 0 ? { location: spec.meta.location } : {},
|
|
16555
16568
|
...spec.meta.type !== void 0 ? { type: spec.meta.type } : {},
|
|
16556
|
-
...
|
|
16569
|
+
...integrationId !== void 0 ? { integrationId } : {},
|
|
16557
16570
|
...spec.meta.role !== void 0 ? { role: spec.meta.role } : {}
|
|
16558
16571
|
}).catch((err) => {
|
|
16559
16572
|
opts.logger.warn("spawnAccessoryChild: applyInitialMeta pre-seed failed", {
|
|
@@ -16814,7 +16827,7 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
16814
16827
|
},
|
|
16815
16828
|
register: async (device) => {
|
|
16816
16829
|
registry.register(addonId, device);
|
|
16817
|
-
buildContext(device.stableId, device.id, device.parentDeviceId).registerNativeCap(_camstack_types_addon.deviceOpsCapability, buildDeviceOpsProvider(device));
|
|
16830
|
+
buildContext(device.stableId, device.id, device.parentDeviceId).registerNativeCap(_camstack_types_addon.deviceOpsCapability, buildDeviceOpsProvider(device, (id) => teardownLocal(id, false)));
|
|
16818
16831
|
try {
|
|
16819
16832
|
await callDeviceManager(api, "registerDevice", {
|
|
16820
16833
|
addonId,
|