@camstack/server 1.2.909 → 1.2.911
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 +14 -0
- package/dist/agent/main.js +21 -8
- package/dist/api/core/cap-providers.js +81 -78
- package/dist/api/trpc/device-config-secret-redaction.js +42 -2
- package/dist/api/trpc/generated-cap-routers.js +20 -0
- package/dist/api/trpc/trpc.middleware.js +10 -2
- package/dist/core/addon/addon-registry.service.js +25 -1
- package/dist/core/addon/instance-lifecycle.js +106 -33
- package/package.json +29 -12
- package/system/dist/addon-runner.js +229 -21
- package/system/dist/addon-runner.mjs +230 -22
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +4 -4
- package/system/dist/builtins/composer/composer.addon.mjs +4 -4
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +6 -5
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +6 -5
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +15 -9
- package/system/dist/builtins/loki-logging/index.mjs +15 -9
- package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +6 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-C6IjgNU4.js → capture-engine-CRXUcNzg.js} +1 -1
- package/system/dist/{capture-engine-CE9QyWYX.mjs → capture-engine-erwNulcY.mjs} +1 -1
- package/system/dist/{composition-sources-YIJB6QG7.js → composition-sources-CmJRQLAB.js} +1 -1
- package/system/dist/{composition-sources-CsPiXLpf.mjs → composition-sources-DrQFzsQU.mjs} +1 -1
- package/system/dist/{constants-D6sXdBUu.js → constants-BuRweEmb.js} +1 -1
- package/system/dist/{constants-D1n14R3Y.mjs → constants-D9ZICjoN.mjs} +1 -1
- package/system/dist/{device-ca-BTbsR2J2.js → device-ca-DGwzbKB7.js} +1 -1
- package/system/dist/{device-ca-DahOgcXb.mjs → device-ca-XXMVM6Lu.mjs} +1 -1
- package/system/dist/{dist-_gUzcZPn.js → dist-CZx3IYRz.js} +523 -42
- package/system/dist/{dist-DxW5ebV-.mjs → dist-DUYpvNfO.mjs} +522 -41
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-DpzA5fuQ.mjs → hub-identity-Dc-SOwBk.mjs} +1 -1
- package/system/dist/{hub-identity-CDhT1yT0.js → hub-identity-vVRXZi0z.js} +1 -1
- package/system/dist/{hub-mdns-ciao-C6nswov4.mjs → hub-mdns-ciao-DpRGDUEE.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-BWDuSepO.js → hub-mdns-ciao-uCdDDwE4.js} +2 -2
- package/system/dist/index.d.ts +1 -0
- package/system/dist/index.js +218 -26
- package/system/dist/index.mjs +219 -28
- package/system/dist/kernel/moleculer/accessory-spawn-retry.d.ts +67 -0
- package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +2 -0
- package/system/dist/kernel/moleculer/hub-connect-switches.d.ts +23 -0
- package/system/dist/{legacy-integration-rows-door-vKSv01GH.js → legacy-integration-rows-door-CtObsXaU.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-lCNawQ-w.mjs → legacy-integration-rows-door-DvbF3IY8.mjs} +1 -1
- package/system/dist/{rename-composition-block-ONfuFbfd.mjs → rename-composition-block-CowZDV1m.mjs} +1 -1
- package/system/dist/{rename-composition-block-ozGMTnI_.js → rename-composition-block-rKmnICiK.js} +1 -1
- package/system/dist/{restore-archive-CUVoxsCu.js → restore-archive-BvvAR6Ww.js} +1 -1
- package/system/dist/{restore-archive-DWTsdq1K.mjs → restore-archive-DH-lFUT0.mjs} +1 -1
- package/system/dist/{wal-maintenance-B6pvtESa.mjs → wal-maintenance-B0uiPZUs.mjs} +0 -0
- package/system/dist/{wal-maintenance-Cgpar8TL.js → wal-maintenance-CB9zUxb-.js} +0 -0
- package/system/package.json +1 -1
|
@@ -4,10 +4,11 @@ exports.ADDON_NOT_RUNNING_CODE = void 0;
|
|
|
4
4
|
exports.testBeforeCreate = testBeforeCreate;
|
|
5
5
|
exports.createRegisteredInstance = createRegisteredInstance;
|
|
6
6
|
exports.deleteRegisteredInstance = deleteRegisteredInstance;
|
|
7
|
-
exports.isFixedBuiltin = isFixedBuiltin;
|
|
8
7
|
exports.rawInstancesProvider = rawInstancesProvider;
|
|
9
|
-
exports.
|
|
8
|
+
exports.switchRegisteredInstance = switchRegisteredInstance;
|
|
9
|
+
exports.cachedDescription = cachedDescription;
|
|
10
10
|
exports.withInstanceLifecycle = withInstanceLifecycle;
|
|
11
|
+
exports.rememberDescription = rememberDescription;
|
|
11
12
|
exports.addonNotRunningError = addonNotRunningError;
|
|
12
13
|
exports.deferInstanceLifecycle = deferInstanceLifecycle;
|
|
13
14
|
/**
|
|
@@ -363,10 +364,6 @@ async function bringsDevicesOf(deps, addonId, provider, kind) {
|
|
|
363
364
|
return (0, integration_role_1.bringsDevices)(described.role);
|
|
364
365
|
return (0, integration_role_1.bringsDevices)((0, integration_role_1.describedRoleOf)(described) ?? described.role);
|
|
365
366
|
}
|
|
366
|
-
/** A builtin the hub itself declared (`DeclaredDevices` marks it `fixed`); its switch is the registry flag. */
|
|
367
|
-
function isFixedBuiltin(integration) {
|
|
368
|
-
return integration.info['fixed'] === true;
|
|
369
|
-
}
|
|
370
367
|
/** Who the transport stamped as the caller of an `integration-instances` call; null when nobody. */
|
|
371
368
|
function callerAddonIdOf(input) {
|
|
372
369
|
const stamp = Reflect.get(input, 'callerAddonId');
|
|
@@ -379,15 +376,35 @@ function rawInstancesProvider(provider) {
|
|
|
379
376
|
return RAW_PROVIDERS.get(provider) ?? provider;
|
|
380
377
|
}
|
|
381
378
|
/**
|
|
382
|
-
* The
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
379
|
+
* The ONE door of an instance's switch (D1066): the hub registry row's `enabled`, for every role
|
|
380
|
+
* and every row, fixed builtins included. The row is written first, so the switch holds whether or
|
|
381
|
+
* not the addon is up; the addon is then told (`setInstanceEnabled` of its RAW provider, which only
|
|
382
|
+
* re-applies its runtime and fires `onSwitched`). An addon that is down or refuses learns the state
|
|
383
|
+
* from the registry at its next boot, so a failed notice is logged and never undoes the switch.
|
|
387
384
|
*/
|
|
388
|
-
async function
|
|
385
|
+
async function switchRegisteredInstance(deps, integration, enabled, addon) {
|
|
389
386
|
await deps.integrations().updateIntegration(integration.id, { enabled });
|
|
390
387
|
await emitSwitchEvent(deps, integration, enabled);
|
|
388
|
+
if (addon === null)
|
|
389
|
+
return;
|
|
390
|
+
try {
|
|
391
|
+
await addon.setInstanceEnabled({ id: integration.id, enabled });
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
deps.logger.warn('switched in the registry; the addon was not told (it reads it at its next boot)', {
|
|
395
|
+
tags: { integrationId: integration.id, addonId: integration.addonId },
|
|
396
|
+
meta: { phase: 'set-enabled', enabled, error: (0, types_1.errMsg)(err) },
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** What each wrapped provider described last (at registration, or on a call that asked): a registry read answers from it. */
|
|
401
|
+
const DESCRIPTIONS = new WeakMap();
|
|
402
|
+
/**
|
|
403
|
+
* The description the hub holds for a registered provider, or null before it answered once. A
|
|
404
|
+
* registry read (`integrations.list`, `getAvailableTypes`) uses it instead of calling the addon (D1066).
|
|
405
|
+
*/
|
|
406
|
+
function cachedDescription(provider) {
|
|
407
|
+
return DESCRIPTIONS.get(provider) ?? null;
|
|
391
408
|
}
|
|
392
409
|
/** `integration.enabled` / `integration.disabled`, only when the switch actually moved. */
|
|
393
410
|
async function emitSwitchEvent(deps, integration, enabled) {
|
|
@@ -439,7 +456,7 @@ function withInstanceLifecycle(addonId, provider, deps) {
|
|
|
439
456
|
return { id: created.id };
|
|
440
457
|
}
|
|
441
458
|
if (!(await bringsDevicesOf(deps, bare, provider, input.kind))) {
|
|
442
|
-
return provider
|
|
459
|
+
return createServiceInstance(deps, bare, provider, input);
|
|
443
460
|
}
|
|
444
461
|
const reg = deps.integrations();
|
|
445
462
|
if (input.id !== undefined) {
|
|
@@ -471,15 +488,10 @@ function withInstanceLifecycle(addonId, provider, deps) {
|
|
|
471
488
|
await deleteRegisteredInstance(deps, provider, integration);
|
|
472
489
|
return { ok: true };
|
|
473
490
|
};
|
|
474
|
-
//
|
|
475
|
-
// is the registry flag, the one store, so the listing reads it and the switch writes it.
|
|
476
|
-
const fixedRow = async (id) => {
|
|
477
|
-
const row = await deps.integrations().getIntegration(id);
|
|
478
|
-
return row !== null && row.addonId === bare && isFixedBuiltin(row) ? row : null;
|
|
479
|
-
};
|
|
491
|
+
// The switch is the registry row's, for every row: what the addon lists is overlaid with it.
|
|
480
492
|
const withRegistryFlag = async (instance) => {
|
|
481
|
-
const row = await
|
|
482
|
-
return row === null ? instance : { ...instance, enabled: row.enabled };
|
|
493
|
+
const row = await deps.integrations().getIntegration(instance.id);
|
|
494
|
+
return row === null || row.addonId !== bare ? instance : { ...instance, enabled: row.enabled };
|
|
483
495
|
};
|
|
484
496
|
const listInstances = async () => Promise.all((await provider.listInstances()).map(withRegistryFlag));
|
|
485
497
|
const getInstance = async (input) => {
|
|
@@ -487,20 +499,20 @@ function withInstanceLifecycle(addonId, provider, deps) {
|
|
|
487
499
|
return instance === null ? null : withRegistryFlag(instance);
|
|
488
500
|
};
|
|
489
501
|
const setInstanceEnabled = async (input) => {
|
|
490
|
-
const fixed = await fixedRow(input.id);
|
|
491
|
-
if (fixed !== null) {
|
|
492
|
-
await setFixedBuiltinEnabled(deps, fixed, input.enabled);
|
|
493
|
-
return { ok: true };
|
|
494
|
-
}
|
|
495
|
-
// The switch of an instance lives in its record body: the baseline is what the body said
|
|
496
|
-
// BEFORE the write, never the registry flag (this path does not write it).
|
|
497
502
|
const row = await deps.integrations().getIntegration(input.id);
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
503
|
+
if (row === null || row.addonId !== bare) {
|
|
504
|
+
throw new server_1.TRPCError({
|
|
505
|
+
code: 'NOT_FOUND',
|
|
506
|
+
message: `Addon "${bare}" has no integration "${input.id}" to switch`,
|
|
507
|
+
});
|
|
502
508
|
}
|
|
503
|
-
|
|
509
|
+
await switchRegisteredInstance(deps, row, input.enabled, provider);
|
|
510
|
+
return { ok: true };
|
|
511
|
+
};
|
|
512
|
+
const describe = async () => {
|
|
513
|
+
const described = await provider.describe();
|
|
514
|
+
DESCRIPTIONS.set(wrapped, described);
|
|
515
|
+
return described;
|
|
504
516
|
};
|
|
505
517
|
const wrapped = new Proxy(provider, {
|
|
506
518
|
get(target, prop) {
|
|
@@ -514,6 +526,8 @@ function withInstanceLifecycle(addonId, provider, deps) {
|
|
|
514
526
|
return getInstance;
|
|
515
527
|
if (prop === 'setInstanceEnabled')
|
|
516
528
|
return setInstanceEnabled;
|
|
529
|
+
if (prop === 'describe')
|
|
530
|
+
return describe;
|
|
517
531
|
const value = Reflect.get(target, prop);
|
|
518
532
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
519
533
|
},
|
|
@@ -521,6 +535,57 @@ function withInstanceLifecycle(addonId, provider, deps) {
|
|
|
521
535
|
RAW_PROVIDERS.set(wrapped, provider);
|
|
522
536
|
return wrapped;
|
|
523
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Ask a just-registered provider to describe itself ONCE and keep the answer ({@link cachedDescription}),
|
|
540
|
+
* off every request path: a registry read never asks the addon (D1066). One call at registration, no
|
|
541
|
+
* retry: a failure is logged and the reads fall back to the manifest until a later `describe()` lands.
|
|
542
|
+
*/
|
|
543
|
+
function rememberDescription(provider, addonId, logger) {
|
|
544
|
+
Promise.resolve()
|
|
545
|
+
.then(() => provider.describe())
|
|
546
|
+
.catch((err) => {
|
|
547
|
+
logger.warn('provider description not cached at registration', {
|
|
548
|
+
tags: { addonId },
|
|
549
|
+
meta: { phase: 'register', error: (0, types_1.errMsg)(err) },
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Create an instance that brings no devices (a broker account, a relay, a destination): the addon
|
|
555
|
+
* makes its record under the id it mints, and the hub gives it its registry row, the one stored
|
|
556
|
+
* switch (D1066). Hidden from the Integrations list by its `info`. A refused row removes the record.
|
|
557
|
+
*/
|
|
558
|
+
async function createServiceInstance(deps, addonId, provider, input) {
|
|
559
|
+
const created = await provider.createInstance(input);
|
|
560
|
+
const reg = deps.integrations();
|
|
561
|
+
try {
|
|
562
|
+
const existing = await reg.getIntegration(created.id);
|
|
563
|
+
if (existing !== null) {
|
|
564
|
+
if (existing.addonId === addonId)
|
|
565
|
+
return created;
|
|
566
|
+
throw new server_1.TRPCError({
|
|
567
|
+
code: 'CONFLICT',
|
|
568
|
+
message: `Integration "${created.id}" already belongs to "${existing.addonId}"`,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
await reg.createIntegration({
|
|
572
|
+
id: created.id,
|
|
573
|
+
addonId,
|
|
574
|
+
name: input.name,
|
|
575
|
+
info: { [types_1.SERVICE_INSTANCE_INFO_KEY]: true },
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
catch (err) {
|
|
579
|
+
await provider.deleteInstance({ id: created.id }).catch((cleanupErr) => {
|
|
580
|
+
deps.logger.warn('instance record not removed after its registry row was refused', {
|
|
581
|
+
tags: { addonId },
|
|
582
|
+
meta: { phase: 'create-rollback', id: created.id, error: (0, types_1.errMsg)(cleanupErr) },
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
throw err;
|
|
586
|
+
}
|
|
587
|
+
return created;
|
|
588
|
+
}
|
|
524
589
|
/** The stable code (D863) of {@link addonNotRunningError}: a client reads it from `data.i18n`. */
|
|
525
590
|
exports.ADDON_NOT_RUNNING_CODE = 'integration-instances.addon-not-running';
|
|
526
591
|
/**
|
|
@@ -566,6 +631,11 @@ function deferInstanceLifecycle(resolve, logger) {
|
|
|
566
631
|
const listInstances = async () => readNow().listInstances();
|
|
567
632
|
const getInstance = async (input) => readNow().getInstance(input);
|
|
568
633
|
const setInstanceEnabled = async (input) => wrapNow('switch').setInstanceEnabled(input);
|
|
634
|
+
const describe = async () => {
|
|
635
|
+
const described = await provider.describe();
|
|
636
|
+
DESCRIPTIONS.set(deferred, described);
|
|
637
|
+
return described;
|
|
638
|
+
};
|
|
569
639
|
const deferred = new Proxy(provider, {
|
|
570
640
|
get(target, prop) {
|
|
571
641
|
if (prop === 'createInstance')
|
|
@@ -578,10 +648,13 @@ function deferInstanceLifecycle(resolve, logger) {
|
|
|
578
648
|
return getInstance;
|
|
579
649
|
if (prop === 'setInstanceEnabled')
|
|
580
650
|
return setInstanceEnabled;
|
|
651
|
+
if (prop === 'describe')
|
|
652
|
+
return describe;
|
|
581
653
|
const value = Reflect.get(target, prop);
|
|
582
654
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
583
655
|
},
|
|
584
656
|
});
|
|
657
|
+
rememberDescription(deferred, bare, logger);
|
|
585
658
|
RAW_PROVIDERS.set(deferred, rawInstancesProvider(provider));
|
|
586
659
|
return deferred;
|
|
587
660
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.911",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,9 +66,26 @@
|
|
|
66
66
|
],
|
|
67
67
|
"requires": {
|
|
68
68
|
"addons": {
|
|
69
|
-
"@camstack/addon-admin-ui": ">=1.2.
|
|
70
|
-
"@camstack/addon-agent-ui": ">=1.2.
|
|
71
|
-
"@camstack/addon-
|
|
69
|
+
"@camstack/addon-admin-ui": ">=1.2.709",
|
|
70
|
+
"@camstack/addon-agent-ui": ">=1.2.415",
|
|
71
|
+
"@camstack/addon-ai": ">=0.4.183",
|
|
72
|
+
"@camstack/addon-cloudflare": ">=1.2.162",
|
|
73
|
+
"@camstack/addon-export-alexa": ">=1.2.203",
|
|
74
|
+
"@camstack/addon-export-google": ">=0.1.138",
|
|
75
|
+
"@camstack/addon-import-alexa": ">=0.2.208",
|
|
76
|
+
"@camstack/addon-matter-broker": ">=0.2.172",
|
|
77
|
+
"@camstack/addon-mqtt-broker": ">=1.2.160",
|
|
78
|
+
"@camstack/addon-notifiers": ">=1.2.640",
|
|
79
|
+
"@camstack/addon-pipeline": ">=1.2.671",
|
|
80
|
+
"@camstack/addon-pipeline-orchestrator": ">=1.2.709",
|
|
81
|
+
"@camstack/addon-provider-enpal": ">=0.1.28",
|
|
82
|
+
"@camstack/addon-provider-homeassistant": ">=1.2.696",
|
|
83
|
+
"@camstack/addon-smtp-nodemailer": ">=1.2.157",
|
|
84
|
+
"@camstack/addon-static-turn": ">=1.2.148",
|
|
85
|
+
"@camstack/addon-tailscale": ">=1.2.155",
|
|
86
|
+
"@camstack/addon-terminal": ">=0.1.168",
|
|
87
|
+
"@camstack/addon-training": ">=0.1.139",
|
|
88
|
+
"@camstack/addon-waste-collections": ">=0.1.44"
|
|
72
89
|
},
|
|
73
90
|
"wrapper": {
|
|
74
91
|
"desktop": ">=0.0.1",
|
|
@@ -77,19 +94,19 @@
|
|
|
77
94
|
}
|
|
78
95
|
},
|
|
79
96
|
"dependencies": {
|
|
80
|
-
"@camstack/addon-admin-ui": "1.2.
|
|
81
|
-
"@camstack/addon-agent-ui": "1.2.
|
|
97
|
+
"@camstack/addon-admin-ui": "1.2.709",
|
|
98
|
+
"@camstack/addon-agent-ui": "1.2.415",
|
|
82
99
|
"@camstack/addon-auth": "1.2.182",
|
|
83
100
|
"@camstack/addon-benchmark": "1.2.313",
|
|
84
101
|
"@camstack/addon-decoder-nodeav": "1.2.149",
|
|
85
|
-
"@camstack/addon-notifiers": "1.2.
|
|
86
|
-
"@camstack/addon-pipeline": "1.2.
|
|
87
|
-
"@camstack/addon-pipeline-orchestrator": "1.2.
|
|
102
|
+
"@camstack/addon-notifiers": "1.2.640",
|
|
103
|
+
"@camstack/addon-pipeline": "1.2.671",
|
|
104
|
+
"@camstack/addon-pipeline-orchestrator": "1.2.709",
|
|
88
105
|
"@camstack/addon-post-analysis": "1.2.718",
|
|
89
|
-
"@camstack/develop": "0.1.
|
|
106
|
+
"@camstack/develop": "0.1.55",
|
|
90
107
|
"@camstack/sdk": "1.2.159",
|
|
91
|
-
"@camstack/types": "1.2.
|
|
92
|
-
"@camstack/ui-library": "1.2.
|
|
108
|
+
"@camstack/types": "1.2.602",
|
|
109
|
+
"@camstack/ui-library": "1.2.476",
|
|
93
110
|
"@fastify/compress": "^9.0.0",
|
|
94
111
|
"@fastify/cookie": "^11.0.2",
|
|
95
112
|
"@fastify/cors": "^11.2.0",
|
|
@@ -149,6 +149,25 @@ function refusalReportOf(addonId, err) {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
|
+
//#region src/kernel/moleculer/hub-connect-switches.ts
|
|
153
|
+
/**
|
|
154
|
+
* On a hub connect, every addon with instance kinds reads its switches from the registry again
|
|
155
|
+
* (D1066). Event-driven, no timer (D3): the next connect retries. A forked runner's FIRST connect
|
|
156
|
+
* is its boot, so a registry that still does not answer ends the process and the supervisor
|
|
157
|
+
* respawns it, bounded and marked terminally failed (D6), instead of leaving instances off.
|
|
158
|
+
*/
|
|
159
|
+
async function rehydrateSwitchesOnHubConnect(entries, deps) {
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
if (entry.addon.rehydrateSwitches === void 0) continue;
|
|
162
|
+
try {
|
|
163
|
+
await entry.addon.rehydrateSwitches();
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (deps.fatalOnUnread && (0, _camstack_types_addon.isInstanceSwitchesUnreadError)(err)) deps.exit(entry.addonId, err);
|
|
166
|
+
else deps.onUnread(entry.addonId, err);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
152
171
|
//#region src/kernel/addon-class-resolver.ts
|
|
153
172
|
function isRecord$4(value) {
|
|
154
173
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -6109,6 +6128,156 @@ var AccessoryShrinkGate = class {
|
|
|
6109
6128
|
}
|
|
6110
6129
|
};
|
|
6111
6130
|
//#endregion
|
|
6131
|
+
//#region src/kernel/moleculer/accessory-spawn-retry.ts
|
|
6132
|
+
/** A spawn failure that knows which step threw. */
|
|
6133
|
+
var AccessorySpawnStepError = class extends Error {
|
|
6134
|
+
step;
|
|
6135
|
+
/** The child's numeric id once allocated; null when allocation itself failed. */
|
|
6136
|
+
deviceId;
|
|
6137
|
+
constructor(step, deviceId, cause) {
|
|
6138
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
6139
|
+
super(`${step}: ${reason}`, { cause });
|
|
6140
|
+
this.name = "AccessorySpawnStepError";
|
|
6141
|
+
this.step = step;
|
|
6142
|
+
this.deviceId = deviceId;
|
|
6143
|
+
}
|
|
6144
|
+
};
|
|
6145
|
+
function describeError(error) {
|
|
6146
|
+
if (error instanceof AccessorySpawnStepError) return {
|
|
6147
|
+
step: error.step,
|
|
6148
|
+
reason: error.message.slice(error.step.length + 2)
|
|
6149
|
+
};
|
|
6150
|
+
return {
|
|
6151
|
+
step: "unknown",
|
|
6152
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
6153
|
+
};
|
|
6154
|
+
}
|
|
6155
|
+
var AccessorySpawnRetry = class AccessorySpawnRetry {
|
|
6156
|
+
#logger;
|
|
6157
|
+
#delaysMs;
|
|
6158
|
+
/** Pending spawns, by `<parent>:<child stableId>`. */
|
|
6159
|
+
#pending = /* @__PURE__ */ new Map();
|
|
6160
|
+
/** Gave up — sticks until the parent is registered again. */
|
|
6161
|
+
#gaveUp = /* @__PURE__ */ new Set();
|
|
6162
|
+
constructor(options) {
|
|
6163
|
+
this.#logger = options.logger;
|
|
6164
|
+
this.#delaysMs = options.delaysMs ?? _camstack_types_addon.DEVICE_RESTORE_RETRY_DELAYS_MS;
|
|
6165
|
+
}
|
|
6166
|
+
static #key(parentDeviceId, stableId) {
|
|
6167
|
+
return `${parentDeviceId}:${stableId}`;
|
|
6168
|
+
}
|
|
6169
|
+
/** The parent went away (teardown / shutdown): drop its pending rounds and its give-ups. */
|
|
6170
|
+
cancelParent(parentDeviceId) {
|
|
6171
|
+
for (const [key, entry] of this.#pending) {
|
|
6172
|
+
if (entry.parentDeviceId !== parentDeviceId) continue;
|
|
6173
|
+
entry.cancelled = true;
|
|
6174
|
+
if (entry.timer !== null) clearTimeout(entry.timer);
|
|
6175
|
+
this.#pending.delete(key);
|
|
6176
|
+
}
|
|
6177
|
+
this.#forgetGiveUps(parentDeviceId);
|
|
6178
|
+
}
|
|
6179
|
+
/** The parent registered again: a fresh chance for children that gave up. */
|
|
6180
|
+
resetParent(parentDeviceId) {
|
|
6181
|
+
this.#forgetGiveUps(parentDeviceId);
|
|
6182
|
+
}
|
|
6183
|
+
#forgetGiveUps(parentDeviceId) {
|
|
6184
|
+
const prefix = `${parentDeviceId}:`;
|
|
6185
|
+
for (const key of this.#gaveUp) if (key.startsWith(prefix)) this.#gaveUp.delete(key);
|
|
6186
|
+
}
|
|
6187
|
+
/** Record the initial failure and run the bounded rounds in the background. */
|
|
6188
|
+
schedule(request) {
|
|
6189
|
+
const key = AccessorySpawnRetry.#key(request.parentDeviceId, request.stableId);
|
|
6190
|
+
if (this.#pending.has(key)) return;
|
|
6191
|
+
if (this.#gaveUp.has(key)) {
|
|
6192
|
+
this.#logger.debug("Accessory child spawn skipped — gave up earlier, parent not re-registered", {
|
|
6193
|
+
tags: { parentDeviceId: request.parentDeviceId },
|
|
6194
|
+
meta: { stableId: request.stableId }
|
|
6195
|
+
});
|
|
6196
|
+
return;
|
|
6197
|
+
}
|
|
6198
|
+
const entry = {
|
|
6199
|
+
parentDeviceId: request.parentDeviceId,
|
|
6200
|
+
cancelled: false,
|
|
6201
|
+
timer: null
|
|
6202
|
+
};
|
|
6203
|
+
this.#pending.set(key, entry);
|
|
6204
|
+
this.#record(request, request.deviceId, request.error, 0, false);
|
|
6205
|
+
this.#run(key, entry, request);
|
|
6206
|
+
}
|
|
6207
|
+
#record(request, deviceId, error, retry, terminal) {
|
|
6208
|
+
const { step, reason } = describeError(error);
|
|
6209
|
+
this.#logger.error(terminal ? "Accessory child spawn gave up after the bounded retries" : "Accessory child spawn failed", {
|
|
6210
|
+
tags: {
|
|
6211
|
+
...deviceId === null ? {} : { deviceId },
|
|
6212
|
+
parentDeviceId: request.parentDeviceId
|
|
6213
|
+
},
|
|
6214
|
+
meta: {
|
|
6215
|
+
stableId: request.stableId,
|
|
6216
|
+
step,
|
|
6217
|
+
error: reason,
|
|
6218
|
+
retry,
|
|
6219
|
+
max: this.#delaysMs.length
|
|
6220
|
+
}
|
|
6221
|
+
});
|
|
6222
|
+
}
|
|
6223
|
+
async #run(key, entry, request) {
|
|
6224
|
+
let lastError = request.error;
|
|
6225
|
+
let deviceId = request.deviceId;
|
|
6226
|
+
for (let round = 1; round <= this.#delaysMs.length; round += 1) {
|
|
6227
|
+
await this.#sleep(entry, this.#delaysMs[round - 1] ?? 0);
|
|
6228
|
+
if (entry.cancelled) return;
|
|
6229
|
+
if (!request.isParentRegistered()) {
|
|
6230
|
+
this.#pending.delete(key);
|
|
6231
|
+
this.#logger.info("Accessory child spawn retry skipped — parent no longer registered", {
|
|
6232
|
+
tags: {
|
|
6233
|
+
...deviceId === null ? {} : { deviceId },
|
|
6234
|
+
parentDeviceId: request.parentDeviceId
|
|
6235
|
+
},
|
|
6236
|
+
meta: {
|
|
6237
|
+
stableId: request.stableId,
|
|
6238
|
+
retry: round
|
|
6239
|
+
}
|
|
6240
|
+
});
|
|
6241
|
+
return;
|
|
6242
|
+
}
|
|
6243
|
+
try {
|
|
6244
|
+
await request.attempt({ final: round === this.#delaysMs.length });
|
|
6245
|
+
if (entry.cancelled) return;
|
|
6246
|
+
this.#pending.delete(key);
|
|
6247
|
+
this.#logger.info("Accessory child spawned on retry", {
|
|
6248
|
+
tags: {
|
|
6249
|
+
...deviceId === null ? {} : { deviceId },
|
|
6250
|
+
parentDeviceId: request.parentDeviceId
|
|
6251
|
+
},
|
|
6252
|
+
meta: {
|
|
6253
|
+
stableId: request.stableId,
|
|
6254
|
+
retry: round
|
|
6255
|
+
}
|
|
6256
|
+
});
|
|
6257
|
+
return;
|
|
6258
|
+
} catch (err) {
|
|
6259
|
+
if (entry.cancelled) return;
|
|
6260
|
+
lastError = err;
|
|
6261
|
+
if (err instanceof AccessorySpawnStepError && err.deviceId !== null) deviceId = err.deviceId;
|
|
6262
|
+
if (round < this.#delaysMs.length) this.#record(request, deviceId, err, round, false);
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
this.#record(request, deviceId, lastError, this.#delaysMs.length, true);
|
|
6266
|
+
this.#pending.delete(key);
|
|
6267
|
+
this.#gaveUp.add(key);
|
|
6268
|
+
}
|
|
6269
|
+
#sleep(entry, ms) {
|
|
6270
|
+
return new Promise((resolve) => {
|
|
6271
|
+
const timer = setTimeout(() => {
|
|
6272
|
+
entry.timer = null;
|
|
6273
|
+
resolve();
|
|
6274
|
+
}, ms);
|
|
6275
|
+
timer.unref?.();
|
|
6276
|
+
entry.timer = timer;
|
|
6277
|
+
});
|
|
6278
|
+
}
|
|
6279
|
+
};
|
|
6280
|
+
//#endregion
|
|
6112
6281
|
//#region src/kernel/moleculer/runtime-state-load.ts
|
|
6113
6282
|
/** A device build refused because its runtime state could not be loaded. */
|
|
6114
6283
|
var RuntimeStateLoadError = class extends Error {
|
|
@@ -6689,6 +6858,10 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6689
6858
|
const resolveParentIntegrationId = async (parentId) => {
|
|
6690
6859
|
return (await callDeviceManager(api, "loadMeta", { deviceId: parentId }).catch(() => null))?.integrationId ?? void 0;
|
|
6691
6860
|
};
|
|
6861
|
+
const accessorySpawnRetry = new AccessorySpawnRetry({
|
|
6862
|
+
logger: opts.logger,
|
|
6863
|
+
...opts.accessorySpawnRetryDelaysMs !== void 0 ? { delaysMs: opts.accessorySpawnRetryDelaysMs } : {}
|
|
6864
|
+
});
|
|
6692
6865
|
/**
|
|
6693
6866
|
* Spawn one accessory child device declared by a parent's
|
|
6694
6867
|
* `getAccessoryChildren()`. Mirrors the standard `create()` flow
|
|
@@ -6698,9 +6871,20 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6698
6871
|
* row already exists, `persistInitialConfig` is skipped (config
|
|
6699
6872
|
* arg empty) and the child self-hydrates from `loadConfig`.
|
|
6700
6873
|
*/
|
|
6701
|
-
const spawnAccessoryChild = async (parent, spec) => {
|
|
6874
|
+
const spawnAccessoryChild = async (parent, spec, spawnOptions = { final: false }) => {
|
|
6702
6875
|
const childStableId = `${parent.stableId}-${spec.stableIdSuffix}`;
|
|
6703
|
-
|
|
6876
|
+
let allocatedId = null;
|
|
6877
|
+
try {
|
|
6878
|
+
return await spawnAccessoryChildSteps(parent, spec, childStableId, (id) => {
|
|
6879
|
+
allocatedId = id;
|
|
6880
|
+
}, spawnOptions);
|
|
6881
|
+
} catch (err) {
|
|
6882
|
+
throw err instanceof AccessorySpawnStepError ? err : new AccessorySpawnStepError("register", allocatedId, err);
|
|
6883
|
+
}
|
|
6884
|
+
};
|
|
6885
|
+
const spawnAccessoryChildSteps = async (parent, spec, childStableId, onAllocated, spawnOptions) => {
|
|
6886
|
+
const id = await deviceApi.allocateDeviceId(childStableId).catch((err) => Promise.reject(new AccessorySpawnStepError("allocateDeviceId", null, err)));
|
|
6887
|
+
onAllocated(id);
|
|
6704
6888
|
const existing = registry.getById(id);
|
|
6705
6889
|
if (existing && existing.stableId === childStableId) return existing;
|
|
6706
6890
|
const empty = {};
|
|
@@ -6717,12 +6901,17 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6717
6901
|
...spec.meta.type !== void 0 ? { type: spec.meta.type } : {},
|
|
6718
6902
|
...integrationId !== void 0 ? { integrationId } : {}
|
|
6719
6903
|
}).catch((err) => {
|
|
6720
|
-
|
|
6904
|
+
if (!spawnOptions.final) return Promise.reject(new AccessorySpawnStepError("applyInitialMeta", id, err));
|
|
6905
|
+
opts.logger.error("Accessory child spawned WITHOUT its meta pre-seed after the last retry", {
|
|
6721
6906
|
tags: {
|
|
6722
|
-
|
|
6723
|
-
|
|
6907
|
+
deviceId: id,
|
|
6908
|
+
parentDeviceId: parent.id
|
|
6724
6909
|
},
|
|
6725
|
-
meta: {
|
|
6910
|
+
meta: {
|
|
6911
|
+
step: "applyInitialMeta",
|
|
6912
|
+
stableId: childStableId,
|
|
6913
|
+
error: err instanceof Error ? err.message : String(err)
|
|
6914
|
+
}
|
|
6726
6915
|
});
|
|
6727
6916
|
});
|
|
6728
6917
|
if (isFirstSpawn && Object.keys(spec.config).length > 0) await callDeviceManager(api, "persistConfig", {
|
|
@@ -6730,7 +6919,7 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6730
6919
|
data: spec.config
|
|
6731
6920
|
}).catch(() => {});
|
|
6732
6921
|
const [initialRuntimeState, loadedConfig, deviceMeta] = await Promise.all([
|
|
6733
|
-
loadRuntimeStateFor(id, childStableId, "accessory-child"),
|
|
6922
|
+
loadRuntimeStateFor(id, childStableId, "accessory-child").catch((err) => Promise.reject(new AccessorySpawnStepError("loadRuntimeState", id, err))),
|
|
6734
6923
|
callDeviceManager(api, "loadConfig", { deviceId: id }).catch(() => empty),
|
|
6735
6924
|
callDeviceManager(api, "loadMeta", { deviceId: id }).catch(() => null)
|
|
6736
6925
|
]);
|
|
@@ -6769,6 +6958,7 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
6769
6958
|
*/
|
|
6770
6959
|
const teardownLocal = async (deviceId, runLifecycle) => {
|
|
6771
6960
|
const device = registry.getById(deviceId);
|
|
6961
|
+
accessorySpawnRetry.cancelParent(deviceId);
|
|
6772
6962
|
cancelProbeRetry(deviceId);
|
|
6773
6963
|
if (!device) return;
|
|
6774
6964
|
const children = registry.getChildren(deviceId);
|
|
@@ -7013,6 +7203,7 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
7013
7203
|
if (!opts.capabilityRegistry) workerNativeCaps.get("device-ops")?.delete(device.id);
|
|
7014
7204
|
throw err;
|
|
7015
7205
|
}
|
|
7206
|
+
accessorySpawnRetry.resetParent(device.id);
|
|
7016
7207
|
const lifecycleHost = device;
|
|
7017
7208
|
const shrinkGate = new AccessoryShrinkGate();
|
|
7018
7209
|
const runReconcileNow = async () => {
|
|
@@ -7050,14 +7241,14 @@ function createBrokerDeviceManagerApi(opts) {
|
|
|
7050
7241
|
try {
|
|
7051
7242
|
await spawnAccessoryChild(device, spec);
|
|
7052
7243
|
} catch (err) {
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7244
|
+
accessorySpawnRetry.schedule({
|
|
7245
|
+
deviceId: err instanceof AccessorySpawnStepError ? err.deviceId : null,
|
|
7246
|
+
stableId: `${device.stableId}-${spec.stableIdSuffix}`,
|
|
7247
|
+
parentDeviceId: device.id,
|
|
7248
|
+
error: err,
|
|
7249
|
+
isParentRegistered: () => registry.getById(device.id) !== null,
|
|
7250
|
+
attempt: async (attemptOptions) => {
|
|
7251
|
+
await spawnAccessoryChild(device, spec, attemptOptions);
|
|
7061
7252
|
}
|
|
7062
7253
|
});
|
|
7063
7254
|
}
|
|
@@ -12559,18 +12750,35 @@ async function main() {
|
|
|
12559
12750
|
if (deviceRestorePromises.length > 0 && !shuttingDown) await Promise.allSettled(deviceRestorePromises);
|
|
12560
12751
|
refreshChildCaps("post-init", customActionRegistry.describeAll(specs.map((spec) => spec.addonId)));
|
|
12561
12752
|
let hubReachableFired = false;
|
|
12562
|
-
const
|
|
12753
|
+
const rehydrateSwitches = (first) => rehydrateSwitchesOnHubConnect(loaded, {
|
|
12754
|
+
fatalOnUnread: first,
|
|
12755
|
+
onUnread: (addonId, err) => {
|
|
12756
|
+
runnerLog.error(`"${addonId}" instance switches not read from the registry`, { meta: { error: (0, _camstack_types_addon.errMsg)(err) } });
|
|
12757
|
+
},
|
|
12758
|
+
exit: (addonId, err) => {
|
|
12759
|
+
console.error(`[addon-runner] "${addonId}" cannot read its instance switches: ${(0, _camstack_types_addon.errMsg)(err)}`);
|
|
12760
|
+
process.exit(1);
|
|
12761
|
+
}
|
|
12762
|
+
});
|
|
12763
|
+
const fireHubReachableOnce = async () => {
|
|
12563
12764
|
if (hubReachableFired) return;
|
|
12564
12765
|
hubReachableFired = true;
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
|
|
12766
|
+
await rehydrateSwitches(true);
|
|
12767
|
+
for (const entry of loaded) {
|
|
12768
|
+
if (typeof entry.addon.onHubReachable !== "function") continue;
|
|
12769
|
+
Promise.resolve(entry.addon.onHubReachable()).catch((err) => {
|
|
12770
|
+
runnerLog.error(`"${entry.addonId}" onHubReachable() threw`, { meta: { error: (0, _camstack_types_addon.errMsg)(err) } });
|
|
12771
|
+
});
|
|
12772
|
+
}
|
|
12568
12773
|
};
|
|
12569
12774
|
udsChildClient.onConnected(() => {
|
|
12570
|
-
if (hubReachableFired)
|
|
12775
|
+
if (hubReachableFired) {
|
|
12776
|
+
refreshChildCaps("on reconnect");
|
|
12777
|
+
rehydrateSwitches(false);
|
|
12778
|
+
}
|
|
12571
12779
|
fireHubReachableOnce();
|
|
12572
12780
|
});
|
|
12573
|
-
fireHubReachableOnce();
|
|
12781
|
+
await fireHubReachableOnce();
|
|
12574
12782
|
runnerLog.info(`"${nodeId}" started — ${loaded.length} addon(s) ready (UDS connected)`);
|
|
12575
12783
|
process.stdout.write(`READY:${nodeId}\n`);
|
|
12576
12784
|
const stopHeapWatch = startRunnerHeapWatch({
|