@camstack/server 1.2.910 → 1.2.912

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 (100) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/agent/main.js +21 -8
  3. package/dist/api/core/cap-providers.js +81 -78
  4. package/dist/api/trpc/generated-cap-routers.js +20 -0
  5. package/dist/core/addon/addon-registry.service.js +25 -1
  6. package/dist/core/addon/instance-lifecycle.js +106 -33
  7. package/package.json +12 -12
  8. package/system/dist/addon-runner.js +229 -21
  9. package/system/dist/addon-runner.mjs +230 -22
  10. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  11. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  12. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  13. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  14. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  15. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  16. package/system/dist/builtins/autotrack/index.js +1 -1
  17. package/system/dist/builtins/autotrack/index.mjs +1 -1
  18. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  19. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  20. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  21. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  22. package/system/dist/builtins/camera-grid/index.js +1 -1
  23. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  24. package/system/dist/builtins/composer/composer.addon.js +4 -4
  25. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  26. package/system/dist/builtins/console-logging/index.js +1 -1
  27. package/system/dist/builtins/console-logging/index.mjs +1 -1
  28. package/system/dist/builtins/core-blocks/core-blocks.addon.js +4 -4
  29. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +4 -4
  30. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  31. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  32. package/system/dist/builtins/device-manager/device-manager.addon.js +2 -2
  33. package/system/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
  34. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  35. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  36. package/system/dist/builtins/keychain/index.js +4 -4
  37. package/system/dist/builtins/keychain/index.mjs +4 -4
  38. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  39. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  40. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  41. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  42. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  43. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  44. package/system/dist/builtins/loki-logging/index.js +15 -9
  45. package/system/dist/builtins/loki-logging/index.mjs +15 -9
  46. package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +6 -0
  47. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  48. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  49. package/system/dist/builtins/platform-probe/index.js +1 -1
  50. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  51. package/system/dist/builtins/record-entries/index.js +1 -1
  52. package/system/dist/builtins/record-entries/index.mjs +1 -1
  53. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  54. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  55. package/system/dist/builtins/snapshot/index.js +1 -1
  56. package/system/dist/builtins/snapshot/index.mjs +1 -1
  57. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  58. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  59. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  60. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  61. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  62. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  63. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  64. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  65. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  66. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  67. package/system/dist/builtins/winston-logging/index.js +1 -1
  68. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  69. package/system/dist/{capture-engine-B7DJgM95.js → capture-engine-CRXUcNzg.js} +1 -1
  70. package/system/dist/{capture-engine-DTx0c7kf.mjs → capture-engine-erwNulcY.mjs} +1 -1
  71. package/system/dist/{composition-sources-DRZuLQaM.js → composition-sources-CmJRQLAB.js} +1 -1
  72. package/system/dist/{composition-sources-CY6MmRpR.mjs → composition-sources-DrQFzsQU.mjs} +1 -1
  73. package/system/dist/{constants-BIYn2uH-.js → constants-BuRweEmb.js} +1 -1
  74. package/system/dist/{constants-DKNphWBk.mjs → constants-D9ZICjoN.mjs} +1 -1
  75. package/system/dist/{device-ca-N9oMCP1h.js → device-ca-DGwzbKB7.js} +1 -1
  76. package/system/dist/{device-ca-CoeuG8vp.mjs → device-ca-XXMVM6Lu.mjs} +1 -1
  77. package/system/dist/{dist-xH7EdlAg.js → dist-CZx3IYRz.js} +487 -39
  78. package/system/dist/{dist-CUt0SVMu.mjs → dist-DUYpvNfO.mjs} +486 -38
  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-identity-BPRu1Pr9.mjs → hub-identity-Dc-SOwBk.mjs} +1 -1
  82. package/system/dist/{hub-identity-As9K7AG1.js → hub-identity-vVRXZi0z.js} +1 -1
  83. package/system/dist/{hub-mdns-ciao-D4CeSt_C.mjs → hub-mdns-ciao-DpRGDUEE.mjs} +2 -2
  84. package/system/dist/{hub-mdns-ciao-jaGozuwj.js → hub-mdns-ciao-uCdDDwE4.js} +2 -2
  85. package/system/dist/index.d.ts +1 -0
  86. package/system/dist/index.js +228 -28
  87. package/system/dist/index.mjs +229 -30
  88. package/system/dist/kernel/moleculer/accessory-spawn-retry.d.ts +67 -0
  89. package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +2 -0
  90. package/system/dist/kernel/moleculer/hub-connect-switches.d.ts +23 -0
  91. package/system/dist/kernel/transport/acting-addon.d.ts +5 -1
  92. package/system/dist/{legacy-integration-rows-door-Gk42wKsu.js → legacy-integration-rows-door-CtObsXaU.js} +1 -1
  93. package/system/dist/{legacy-integration-rows-door-DAAF9Orf.mjs → legacy-integration-rows-door-DvbF3IY8.mjs} +1 -1
  94. package/system/dist/{rename-composition-block-CWJ_zyT_.mjs → rename-composition-block-CowZDV1m.mjs} +1 -1
  95. package/system/dist/{rename-composition-block-PFCvxuaj.js → rename-composition-block-rKmnICiK.js} +1 -1
  96. package/system/dist/{restore-archive-r_vUDU7Z.js → restore-archive-BvvAR6Ww.js} +1 -1
  97. package/system/dist/{restore-archive-BABm0OtJ.mjs → restore-archive-gLbz6iuS.mjs} +82 -82
  98. package/system/dist/{wal-maintenance-DugOl9LZ.mjs → wal-maintenance-B0uiPZUs.mjs} +0 -0
  99. package/system/dist/{wal-maintenance-hrjEiyFX.js → wal-maintenance-CB9zUxb-.js} +0 -0
  100. package/system/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.912] - 2026-11-19
11
+
12
+ ### Changed
13
+
14
+ - Rebuilt against updated dependencies.
15
+
16
+ ## [1.2.911] - 2026-11-19
17
+
18
+ ### Changed
19
+
20
+ - A device-provider accessory child that failed to spawn at boot is now retried a bounded number of times, then reported as failed in the log, instead of staying unroutable until the addon restarts.
21
+ - Integration list, get and getByAddonId are pure registry reads that never call an addon, ending the hub and addon call cycle behind hub stalls
22
+
10
23
  ## [1.2.910] - 2026-11-19
11
24
 
12
25
  ### Changed
@@ -1211,16 +1211,29 @@ async function startAgent(configPath) {
1211
1211
  // Hub connected — its view of this agent was reset, so the full manifest goes again.
1212
1212
  // (A stale `certificate-rejected` clears on the registration's ack.)
1213
1213
  registration.onHubConnected();
1214
- if (hubReachableFired)
1215
- return;
1214
+ // Every (re)connect reads the switches again for each addon that serves instance kinds: an
1215
+ // owner whose registry read failed earlier is retried by the next connect (event-driven, D3),
1216
+ // and a hub restart after a good read changes nothing the addon already knows.
1217
+ const first = !hubReachableFired;
1216
1218
  hubReachableFired = true;
1217
- for (const [, entry] of loadedAddons) {
1218
- if (!entry.addon || typeof entry.addon.onHubReachable !== 'function')
1219
- continue;
1220
- Promise.resolve(entry.addon.onHubReachable()).catch((err) => {
1221
- console.error(`[Agent] ${entry.id} onHubReachable() threw:`, err);
1219
+ void (async () => {
1220
+ await (0, system_1.rehydrateSwitchesOnHubConnect)([...loadedAddons.values()].flatMap((entry) => entry.addon ? [{ addonId: entry.id, addon: entry.addon }] : []), {
1221
+ fatalOnUnread: false,
1222
+ onUnread: (addonId, err) => {
1223
+ console.error(`[Agent] ${addonId} instance switches not read:`, err);
1224
+ },
1225
+ exit: () => undefined,
1222
1226
  });
1223
- }
1227
+ if (!first)
1228
+ return;
1229
+ for (const [, entry] of loadedAddons) {
1230
+ if (!entry.addon || typeof entry.addon.onHubReachable !== 'function')
1231
+ continue;
1232
+ Promise.resolve(entry.addon.onHubReachable()).catch((err) => {
1233
+ console.error(`[Agent] ${entry.id} onHubReachable() threw:`, err);
1234
+ });
1235
+ }
1236
+ })();
1224
1237
  });
1225
1238
  console.log(`[Agent] Node "${config.nodeId}" (name="${config.name}") ready — ${loadedAddons.size} addon(s) loaded`);
1226
1239
  }
@@ -790,12 +790,12 @@ exports.INTEGRATION_CAP_MARKERS = new Set(['device-provider', 'device-adoption']
790
790
  * `integration-instances` declares its role (`devices`) and is listed for its devices. Decided from the manifest, so a not-yet-registered provider does
791
791
  * not flash a row in. A row it already has stays in the registry and reachable by id.
792
792
  */
793
- async function hidesFromIntegrations(ar, addonId) {
793
+ function hidesFromIntegrations(ar, addonId) {
794
794
  const addon = ar.listAddons().find((a) => a.manifest.id === addonId);
795
795
  if (addon === undefined)
796
796
  return false;
797
797
  const declared = addon.declaration?.integrationRole ?? addon.manifest.integrationRole;
798
- const described = declared === undefined ? await describedInstancesOf(getInstancesProvider(ar, addonId)) : null;
798
+ const described = declared === undefined ? describedInstancesOf(ar, addonId) : null;
799
799
  return !(0, integration_role_js_1.bringsDevices)((0, integration_role_js_1.resolveIntegrationRole)({
800
800
  integrationRole: declared,
801
801
  describedRole: (0, integration_role_js_1.describedRoleOf)(described),
@@ -803,18 +803,13 @@ async function hidesFromIntegrations(ar, addonId) {
803
803
  }));
804
804
  }
805
805
  /**
806
- * The provider's own description, or null when it has none or cannot answer: an addon that
807
- * is mid-restart must not make the Integrations page throw, it falls back to the manifest.
806
+ * What the addon's provider described when it registered (the hub keeps it, `cachedDescription`), or
807
+ * null when it is not registered yet. NEVER a call to the addon: a registry read that awaits an addon
808
+ * makes every integration read depend on every addon (D1066), so it falls back to the manifest.
808
809
  */
809
- async function describedInstancesOf(provider) {
810
- if (provider === null)
811
- return null;
812
- try {
813
- return await provider.describe();
814
- }
815
- catch {
816
- return null;
817
- }
810
+ function describedInstancesOf(ar, addonId) {
811
+ const provider = getInstancesProvider(ar, addonId);
812
+ return provider === null ? null : (0, instance_lifecycle_1.cachedDescription)(provider);
818
813
  }
819
814
  /** The wizard's discovery word for what a provider describes (`none` and `account` find nothing before an instance exists). */
820
815
  function wizardDiscoveryMode(described) {
@@ -823,45 +818,6 @@ function wizardDiscoveryMode(described) {
823
818
  function getInstancesProvider(ar, addonId) {
824
819
  return (0, integration_instances_provider_js_1.findInstancesProvider)(ar.getCapabilityRegistry(), addonId);
825
820
  }
826
- /**
827
- * An integration's `enabled` is a projection of its instance body (epic #440, step 3): the one
828
- * switch is `setInstanceEnabled`, stored in the addon's record. One `listInstances` call per
829
- * addon answers every row of it. A row the addon cannot speak for (its provider is not up, it
830
- * keeps no instance for the row, it fails to answer) keeps the registry's stored flag but is
831
- * marked `switchUnknown`: that flag is stale, not the state, and a reader must not draw it as on or
832
- * off (D315). A failure is logged: a listing never fails because one addon did not answer.
833
- *
834
- * A FIXED builtin is the exception: its switch is the registry flag, the hub's own, written by
835
- * `setFixedBuiltinEnabled` (`instance-lifecycle.ts`) from `setInstanceEnabled` or from
836
- * `integrations.update({ enabled })`, and the name-only record it is seeded with carries no flag,
837
- * which a body reads as "on". Its row is never projected and the flag is the answer, whether or
838
- * not its addon is up.
839
- */
840
- async function projectSwitches(ar, logger, integrations) {
841
- const byAddon = new Map();
842
- for (const addonId of new Set(integrations.filter((i) => !(0, instance_lifecycle_1.isFixedBuiltin)(i)).map((i) => i.addonId))) {
843
- const provider = getInstancesProvider(ar, addonId);
844
- if (provider === null)
845
- continue;
846
- try {
847
- const instances = await provider.listInstances();
848
- byAddon.set(addonId, new Map(instances.map((i) => [i.id, i.enabled !== false])));
849
- }
850
- catch (err) {
851
- logger.warn('integration switch not projected: the addon did not answer', {
852
- tags: { addonId },
853
- meta: { error: (0, types_1.errMsg)(err) },
854
- });
855
- }
856
- }
857
- return integrations.map((i) => {
858
- // A fixed builtin's switch is the registry flag: the hub owns it, the addon does not answer for it.
859
- if ((0, instance_lifecycle_1.isFixedBuiltin)(i))
860
- return i;
861
- const enabled = byAddon.get(i.addonId)?.get(i.id);
862
- return enabled === undefined ? { ...i, switchUnknown: true } : { ...i, enabled };
863
- });
864
- }
865
821
  function buildIntegrationsProvider(ar, loggingService) {
866
822
  const logger = loggingService.createLogger('integrations');
867
823
  const withProcessState = (i) => ({
@@ -873,24 +829,81 @@ function buildIntegrationsProvider(ar, loggingService) {
873
829
  const integrations = await requireIntegrationRegistry(ar).listIntegrations();
874
830
  const hidden = new Map();
875
831
  for (const addonId of new Set(integrations.map((i) => i.addonId))) {
876
- hidden.set(addonId, await hidesFromIntegrations(ar, addonId));
832
+ hidden.set(addonId, hidesFromIntegrations(ar, addonId));
877
833
  }
878
- const visible = integrations.filter((i) => hidden.get(i.addonId) !== true);
879
- return (await projectSwitches(ar, logger, visible)).map(withProcessState);
834
+ return integrations
835
+ .filter((i) => hidden.get(i.addonId) !== true && i.info[types_1.SERVICE_INSTANCE_INFO_KEY] !== true)
836
+ .map(withProcessState);
880
837
  },
881
838
  get: async (input) => {
882
839
  const integration = await requireIntegrationRegistry(ar).getIntegration(input.id);
883
840
  if (!integration)
884
841
  throw new Error(`Integration "${input.id}" not found`);
885
- const [projected] = await projectSwitches(ar, logger, [integration]);
886
- return withProcessState(projected ?? integration);
842
+ return withProcessState(integration);
887
843
  },
888
844
  getByAddonId: async (input) => {
889
- const integration = await requireIntegrationRegistry(ar).getIntegrationByAddonId(input.addonId);
890
- if (!integration)
891
- return integration;
892
- const [projected] = await projectSwitches(ar, logger, [integration]);
893
- return projected ?? integration;
845
+ // The row of a devices-role addon only: a services instance row (`info.serviceInstance`)
846
+ // belongs to an instance, never to the addon, and would answer for it.
847
+ const bare = (0, types_1.bareAddonId)(input.addonId);
848
+ const rows = await requireIntegrationRegistry(ar).listIntegrations();
849
+ return (rows.find((i) => i.addonId === bare && i.info?.[types_1.SERVICE_INSTANCE_INFO_KEY] !== true) ?? null);
850
+ },
851
+ listByAddon: async (input) => {
852
+ const rows = await requireIntegrationRegistry(ar).listIntegrations();
853
+ const bare = (0, types_1.bareAddonId)(input.addonId);
854
+ return rows.filter((i) => i.addonId === bare);
855
+ },
856
+ adoptInstanceRows: async (input) => {
857
+ const reg = requireIntegrationRegistry(ar);
858
+ const addonId = (0, types_1.bareAddonId)(input.addonId);
859
+ // An addon states rows of its OWN instances only: the transport stamps who is calling.
860
+ const stamp = Reflect.get(input, 'callerAddonId');
861
+ if (typeof stamp === 'string' && stamp.length > 0 && (0, types_1.bareAddonId)(stamp) !== addonId) {
862
+ throw new server_1.TRPCError({
863
+ code: 'FORBIDDEN',
864
+ message: `addon "${(0, types_1.bareAddonId)(stamp)}" cannot adopt instance rows of addon "${addonId}"`,
865
+ });
866
+ }
867
+ let created = 0;
868
+ let updated = 0;
869
+ const conflicts = [];
870
+ for (const row of input.rows) {
871
+ const existing = await reg.getIntegration(row.id);
872
+ if (existing === null) {
873
+ // An absent row with a record is a services instance under its addon-minted id. The
874
+ // registry writes an explicit id with `ifRev: 0`, so it can never overwrite a row a
875
+ // concurrent writer (or the `int_NNNN` counter) placed first.
876
+ try {
877
+ await reg.createIntegration({
878
+ id: row.id,
879
+ addonId,
880
+ name: row.name,
881
+ enabled: row.enabled,
882
+ info: { [types_1.SERVICE_INSTANCE_INFO_KEY]: true },
883
+ });
884
+ created += 1;
885
+ }
886
+ catch (err) {
887
+ const raced = await reg.getIntegration(row.id);
888
+ if (raced === null)
889
+ throw err;
890
+ if (raced.addonId !== addonId)
891
+ conflicts.push({ id: row.id, ownerAddonId: raced.addonId });
892
+ }
893
+ }
894
+ else if (existing.addonId !== addonId) {
895
+ logger.warn('adopt skipped: the row belongs to another addon', {
896
+ tags: { integrationId: row.id, addonId },
897
+ meta: { owner: existing.addonId },
898
+ });
899
+ conflicts.push({ id: row.id, ownerAddonId: existing.addonId });
900
+ }
901
+ else if (row.stated && existing.enabled !== row.enabled) {
902
+ await reg.updateIntegration(row.id, { enabled: row.enabled });
903
+ updated += 1;
904
+ }
905
+ }
906
+ return { created, updated, conflicts };
894
907
  },
895
908
  update: async (input) => {
896
909
  const reg = requireIntegrationRegistry(ar);
@@ -902,19 +915,10 @@ function buildIntegrationsProvider(ar, loggingService) {
902
915
  });
903
916
  throw new Error(`Integration "${input.id}" not found`);
904
917
  }
905
- if (input.enabled !== undefined && (0, instance_lifecycle_1.isFixedBuiltin)(previous)) {
906
- // The hub owns a fixed builtin's switch (the registry flag): it works while the addon is down.
907
- await (0, instance_lifecycle_1.setFixedBuiltinEnabled)(ar.instanceLifecycleDeps(), previous, input.enabled);
908
- }
909
- else if (input.enabled !== undefined) {
910
- logger.warn('refused: integrations.update does not switch', {
911
- tags: { integrationId: input.id, addonId: previous.addonId },
912
- meta: { phase: 'update', reason: 'switch-through-set-instance-enabled' },
913
- });
914
- throw new server_1.TRPCError({
915
- code: 'BAD_REQUEST',
916
- message: `Integration "${input.id}" is switched through integration-instances.setInstanceEnabled, not integrations.update`,
917
- });
918
+ if (input.enabled !== undefined) {
919
+ // The one door of the switch (D1066): the registry row, then the addon is told. Works while the addon is down.
920
+ const raw = getInstancesProvider(ar, previous.addonId);
921
+ await (0, instance_lifecycle_1.switchRegisteredInstance)(ar.instanceLifecycleDeps(), previous, input.enabled, raw === null ? null : (0, instance_lifecycle_1.rawInstancesProvider)(raw));
918
922
  }
919
923
  const { id, enabled: _switched, ...updates } = input;
920
924
  const changedFields = Object.keys(updates).filter((k) => updates[k] !== undefined);
@@ -996,7 +1000,7 @@ function buildIntegrationsProvider(ar, loggingService) {
996
1000
  }));
997
1001
  const providerAddons = [];
998
1002
  for (const addon of markerAddons) {
999
- if (!(await hidesFromIntegrations(ar, addon.manifest.id)))
1003
+ if (!hidesFromIntegrations(ar, addon.manifest.id))
1000
1004
  providerAddons.push(addon);
1001
1005
  }
1002
1006
  const integrations = await reg.listIntegrations();
@@ -1005,8 +1009,7 @@ function buildIntegrationsProvider(ar, loggingService) {
1005
1009
  const d = addon.declaration;
1006
1010
  const icon = d?.icon ?? m.icon;
1007
1011
  const color = d?.color ?? m.color ?? '#78716c';
1008
- const instances = getInstancesProvider(ar, m.id);
1009
- const described = await describedInstancesOf(instances);
1012
+ const described = describedInstancesOf(ar, m.id);
1010
1013
  const instanceMode = described !== null
1011
1014
  ? described.instanceMode === 'single'
1012
1015
  ? 'unique'
@@ -6043,6 +6043,26 @@ function createCapRouter_integrations(getProvider, createRemoteProxy) {
6043
6043
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6044
6044
  return p.getByAddonId(methodInput);
6045
6045
  }),
6046
+ listByAddon: trpc_middleware_js_1.protectedProcedure
6047
+ .input(types_74.integrationsCapability.methods.listByAddon.input.loose())
6048
+ .output(types_74.integrationsCapability.methods.listByAddon.output)
6049
+ .query(async ({ input, ctx }) => {
6050
+ const parsedInput = ctx.req !== undefined ? (0, types_3.withoutCallerStamp)(input) : input;
6051
+ const { nodeId, ...methodInput } = parsedInput;
6052
+ const p = resolveProvider('integrations', nodeId, () => getProvider(ctx), createRemoteProxy);
6053
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6054
+ return p.listByAddon(methodInput);
6055
+ }),
6056
+ adoptInstanceRows: trpc_middleware_js_1.adminProcedure
6057
+ .input(types_74.integrationsCapability.methods.adoptInstanceRows.input.loose())
6058
+ .output(types_74.integrationsCapability.methods.adoptInstanceRows.output)
6059
+ .mutation(async ({ input, ctx }) => {
6060
+ const parsedInput = ctx.req !== undefined ? (0, types_3.withoutCallerStamp)(input) : input;
6061
+ const { nodeId, ...methodInput } = parsedInput;
6062
+ const p = resolveProvider('integrations', nodeId, () => getProvider(ctx), createRemoteProxy);
6063
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
6064
+ return p.adoptInstanceRows(methodInput);
6065
+ }),
6046
6066
  update: trpc_middleware_js_1.adminProcedure
6047
6067
  .input(types_74.integrationsCapability.methods.update.input.loose())
6048
6068
  .output(types_74.integrationsCapability.methods.update.output)
@@ -1485,6 +1485,23 @@ class AddonRegistryService {
1485
1485
  setCredentialTokenService(service) {
1486
1486
  this.credentialTokenService = service;
1487
1487
  }
1488
+ /** Every in-process addon with instance kinds reads its switches from the now-wired registry. */
1489
+ async rehydrateInProcessSwitches() {
1490
+ for (const [addonId, entry] of this.addonEntries) {
1491
+ const addon = entry.addon;
1492
+ if (addon?.rehydrateSwitches === undefined)
1493
+ continue;
1494
+ try {
1495
+ await addon.rehydrateSwitches();
1496
+ }
1497
+ catch (err) {
1498
+ this.logger.error('in-process addon instance switches not read: its instances stay off', {
1499
+ tags: { addonId },
1500
+ meta: { error: (0, types_2.errMsg)(err) },
1501
+ });
1502
+ }
1503
+ }
1504
+ }
1488
1505
  async wireHubMainOrphanRecords() {
1489
1506
  const recordsCap = this.capabilityRegistry.getSingleton('records');
1490
1507
  if (recordsCap === null || recordsCap === undefined) {
@@ -1499,6 +1516,9 @@ class AddonRegistryService {
1499
1516
  this.integrationRegistry = new system_1.IntegrationRegistry(system_1.IntegrationRegistry.recordStoresOf(integrationRecords));
1500
1517
  await this.integrationRegistry.initialize();
1501
1518
  this.logger.info('IntegrationRegistry initialized (records)', { meta: { phase: 'v2' } });
1519
+ // The registry wires asynchronously, so an in-process addon that booted first read nothing and
1520
+ // holds its instances off (D1066): every one reads its switches now, in this process, directly.
1521
+ await this.rehydrateInProcessSwitches();
1502
1522
  const clusterRecords = this.recordsForOwner('cluster-agent', this.secretsForOwner('cluster-agent'));
1503
1523
  await clusterRecords.declare(system_1.clusterAgentRecordKinds);
1504
1524
  this.clusterAgentRecords = clusterRecords;
@@ -3117,7 +3137,11 @@ class AddonRegistryService {
3117
3137
  // An `integration-instances` holder is registered with its delete guarded by the link index (D1013).
3118
3138
  this.capabilityRegistry.registerProvider(capabilityName, addonId, (0, instance_links_service_js_1.registeredProviderFor)(capabilityName, provider, this.capabilityRegistry, {
3119
3139
  addonId,
3120
- wrap: this.instanceLifecycleWrap,
3140
+ wrap: (wrapAddonId, held) => {
3141
+ const wrapped = this.instanceLifecycleWrap(wrapAddonId, held);
3142
+ (0, instance_lifecycle_js_1.rememberDescription)(wrapped, addonId, logger);
3143
+ return wrapped;
3144
+ },
3121
3145
  }));
3122
3146
  logger.info('Registered provider via context.registerProvider()', {
3123
3147
  meta: { capabilityName },
@@ -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.setFixedBuiltinEnabled = setFixedBuiltinEnabled;
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 switch of a FIXED builtin: the registry flag, the one store, written here and nowhere else.
383
- * It needs no addon provider, so a builtin whose addon is down or failed can still be turned back
384
- * on: `integrations.update({ enabled })` (the hub's own cap, no provider in the path) reaches it
385
- * directly, and `setInstanceEnabled` reaches it when the provider is up. The enabled / disabled
386
- * event follows a real change only.
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 setFixedBuiltinEnabled(deps, integration, enabled) {
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.createInstance(input);
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
- // A FIXED builtin keeps a name-only record with no flag, which a body reads as "on": its switch
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 fixedRow(instance.id);
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
- const previous = row !== null && row.addonId === bare ? await provider.getInstance({ id: input.id }) : null;
499
- const result = await provider.setInstanceEnabled(input);
500
- if (row !== null && previous !== null) {
501
- await emitSwitchEvent(deps, { ...row, enabled: previous.enabled !== false }, input.enabled);
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
- return result;
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.910",
3
+ "version": "1.2.912",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -66,9 +66,9 @@
66
66
  ],
67
67
  "requires": {
68
68
  "addons": {
69
- "@camstack/addon-admin-ui": ">=1.2.708",
70
- "@camstack/addon-pipeline": ">=1.2.670",
71
- "@camstack/addon-pipeline-orchestrator": ">=1.2.708"
69
+ "@camstack/addon-admin-ui": ">=1.2.710",
70
+ "@camstack/addon-agent-ui": ">=1.2.416",
71
+ "@camstack/addon-pipeline": ">=1.2.672"
72
72
  },
73
73
  "wrapper": {
74
74
  "desktop": ">=0.0.1",
@@ -77,19 +77,19 @@
77
77
  }
78
78
  },
79
79
  "dependencies": {
80
- "@camstack/addon-admin-ui": "1.2.708",
81
- "@camstack/addon-agent-ui": "1.2.414",
80
+ "@camstack/addon-admin-ui": "1.2.710",
81
+ "@camstack/addon-agent-ui": "1.2.415",
82
82
  "@camstack/addon-auth": "1.2.182",
83
83
  "@camstack/addon-benchmark": "1.2.313",
84
84
  "@camstack/addon-decoder-nodeav": "1.2.149",
85
- "@camstack/addon-notifiers": "1.2.639",
86
- "@camstack/addon-pipeline": "1.2.670",
87
- "@camstack/addon-pipeline-orchestrator": "1.2.708",
85
+ "@camstack/addon-notifiers": "1.2.640",
86
+ "@camstack/addon-pipeline": "1.2.672",
87
+ "@camstack/addon-pipeline-orchestrator": "1.2.709",
88
88
  "@camstack/addon-post-analysis": "1.2.718",
89
- "@camstack/develop": "0.1.54",
89
+ "@camstack/develop": "0.1.55",
90
90
  "@camstack/sdk": "1.2.159",
91
- "@camstack/types": "1.2.601",
92
- "@camstack/ui-library": "1.2.475",
91
+ "@camstack/types": "1.2.602",
92
+ "@camstack/ui-library": "1.2.477",
93
93
  "@fastify/compress": "^9.0.0",
94
94
  "@fastify/cookie": "^11.0.2",
95
95
  "@fastify/cors": "^11.2.0",