@camstack/core 0.1.36 → 0.1.38

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 (41) hide show
  1. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.d.ts +7 -1
  2. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.d.ts.map +1 -1
  3. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +46 -56
  4. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js.map +1 -1
  5. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +47 -57
  6. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs.map +1 -1
  7. package/dist/index.js +89 -143
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +89 -143
  10. package/dist/index.mjs.map +1 -1
  11. package/package.json +2 -37
  12. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.d.ts +0 -8
  13. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.d.ts.map +0 -1
  14. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.js +0 -75
  15. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.js.map +0 -1
  16. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.mjs +0 -69
  17. package/dist/builtins/auth-orchestrator/auth-orchestrator.addon.mjs.map +0 -1
  18. package/dist/builtins/auth-orchestrator/index.d.ts +0 -2
  19. package/dist/builtins/auth-orchestrator/index.d.ts.map +0 -1
  20. package/dist/builtins/auth-orchestrator/index.js +0 -7
  21. package/dist/builtins/auth-orchestrator/index.mjs +0 -2
  22. package/dist/builtins/mesh-orchestrator/index.d.ts +0 -2
  23. package/dist/builtins/mesh-orchestrator/index.d.ts.map +0 -1
  24. package/dist/builtins/mesh-orchestrator/index.js +0 -7
  25. package/dist/builtins/mesh-orchestrator/index.mjs +0 -2
  26. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.d.ts +0 -9
  27. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.d.ts.map +0 -1
  28. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.js +0 -113
  29. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.js.map +0 -1
  30. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.mjs +0 -107
  31. package/dist/builtins/mesh-orchestrator/mesh-orchestrator.addon.mjs.map +0 -1
  32. package/dist/builtins/turn-orchestrator/index.d.ts +0 -2
  33. package/dist/builtins/turn-orchestrator/index.d.ts.map +0 -1
  34. package/dist/builtins/turn-orchestrator/index.js +0 -7
  35. package/dist/builtins/turn-orchestrator/index.mjs +0 -2
  36. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.d.ts +0 -34
  37. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.d.ts.map +0 -1
  38. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.js +0 -126
  39. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.js.map +0 -1
  40. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.mjs +0 -120
  41. package/dist/builtins/turn-orchestrator/turn-orchestrator.addon.mjs.map +0 -1
@@ -9,10 +9,16 @@ interface RemoteAccessOrchestratorConfig {
9
9
  export declare class RemoteAccessOrchestratorAddon extends BaseAddon<RemoteAccessOrchestratorConfig> {
10
10
  constructor();
11
11
  protected onInitialize(): Promise<ProviderRegistration[]>;
12
+ /**
13
+ * Maintain the persisted `enabledProviders` set from a tunnel
14
+ * lifecycle event. `source.id` is `string | number`; `network-access`
15
+ * providers emit with `type: 'addon'` so it is always the addonId
16
+ * string. Non-string / non-addon sources are ignored defensively.
17
+ */
18
+ private onTunnelLifecycle;
12
19
  private autoStartEnabledProviders;
13
20
  private markEnabled;
14
21
  private resolveImpl;
15
- private listProviders;
16
22
  }
17
23
  export default RemoteAccessOrchestratorAddon;
18
24
  //# sourceMappingURL=remote-access-orchestrator.addon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-access-orchestrator.addon.d.ts","sourceRoot":"","sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,SAAS,EAIT,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAA;AAgBxB,UAAU,8BAA8B;IACtC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAA;CAC7C;AAED,qBAAa,6BAA8B,SAAQ,SAAS,CAAC,8BAA8B,CAAC;;cAK1E,YAAY,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;YAyDjD,yBAAyB;YA8CzB,WAAW;IAQzB,OAAO,CAAC,WAAW;YAQL,aAAa;CAkC5B;AAED,eAAe,6BAA6B,CAAA"}
1
+ {"version":3,"file":"remote-access-orchestrator.addon.d.ts","sourceRoot":"","sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EACL,SAAS,EAET,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAA;AAWxB,UAAU,8BAA8B;IACtC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAA;CAC7C;AAED,qBAAa,6BAA8B,SAAQ,SAAS,CAAC,8BAA8B,CAAC;;cAK1E,YAAY,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAsD/D;;;;;OAKG;YACW,iBAAiB;YAajB,yBAAyB;YA8CzB,WAAW;IAWzB,OAAO,CAAC,WAAW;CAOpB;AAED,eAAe,6BAA6B,CAAA"}
@@ -6,40 +6,39 @@ require("../../chunk-C13QxCFV.js");
6
6
  let _camstack_types = require("@camstack/types");
7
7
  //#region src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts
8
8
  /**
9
- * Remote-access orchestrator — singleton facade over the
10
- * `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).
11
- * Mirrors the auth-orchestrator and backup-orchestrator patterns.
9
+ * Remote-access orchestrator — backend-only boot-autostart service for
10
+ * the `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).
12
11
  *
13
- * Persistence + autostart contract:
12
+ * Retired its `remote-access` facade cap (2026-05-15): the admin UI now
13
+ * talks to the `network-access` collection cap directly via generic
14
+ * per-`addonId` routing, so this addon registers NO capability.
15
+ *
16
+ * What it still owns — the load-bearing logic:
14
17
  * The orchestrator owns the "operator wants this provider running"
15
- * intent — a `enabledProviders: string[]` slice in its addon-store
18
+ * intent — an `enabledProviders: string[]` slice in its addon-store
16
19
  * blob (BaseAddon.config). On boot we iterate the list and call
17
- * `provider.start()` for each enabled entry. `startProvider` /
18
- * `stopProvider` mutate this list so a Start press persists across
19
- * restarts. Same shape as turn-orchestrator's setProviderEnabled.
20
+ * `provider.start()` for each enabled entry, so a tunnel set up once
21
+ * stays up across hub restarts.
22
+ *
23
+ * Since start/stop no longer flow through this addon, the enabled-set
24
+ * is maintained purely from the event bus: every `network-access`
25
+ * provider emits `NetworkTunnelStarted` / `NetworkTunnelStopped` when
26
+ * it starts/stops. We add the emitting addonId on Started, remove it
27
+ * on Stopped, and persist — keeping the operator intent in sync no
28
+ * matter who triggered the lifecycle change.
20
29
  */
21
30
  var RemoteAccessOrchestratorAddon = class extends _camstack_types.BaseAddon {
22
31
  constructor() {
23
32
  super({ enabledProviders: [] });
24
33
  }
25
34
  async onInitialize() {
26
- const provider = {
27
- listProviders: async () => this.listProviders(),
28
- startProvider: async ({ addonId }) => {
29
- const impl = this.resolveImpl(addonId);
30
- if (!impl?.start) throw new Error(`Remote-access provider "${addonId}" does not support start`);
31
- const endpoint = await impl.start();
32
- await this.markEnabled(addonId, true);
33
- return endpoint;
34
- },
35
- stopProvider: async ({ addonId }) => {
36
- const impl = this.resolveImpl(addonId);
37
- if (impl?.stop) await impl.stop();
38
- await this.markEnabled(addonId, false);
39
- return { success: true };
40
- }
41
- };
42
- this.ctx.logger.info("Remote-access orchestrator initialized", { meta: { enabledCount: this.config.enabledProviders.length } });
35
+ this.ctx.logger.info("Remote-access orchestrator initialized (backend-only)", { meta: { enabledCount: this.config.enabledProviders.length } });
36
+ this.ctx.eventBus?.subscribe({ category: _camstack_types.EventCategory.NetworkTunnelStarted }, (event) => {
37
+ this.onTunnelLifecycle(event.source, true);
38
+ });
39
+ this.ctx.eventBus?.subscribe({ category: _camstack_types.EventCategory.NetworkTunnelStopped }, (event) => {
40
+ this.onTunnelLifecycle(event.source, false);
41
+ });
43
42
  setImmediate(() => {
44
43
  this.autoStartEnabledProviders();
45
44
  });
@@ -49,10 +48,24 @@ var RemoteAccessOrchestratorAddon = class extends _camstack_types.BaseAddon {
49
48
  this.watchCapability("mesh-network", { onReady: () => {
50
49
  this.autoStartEnabledProviders();
51
50
  } });
52
- return [{
53
- capability: _camstack_types.remoteAccessCapability,
54
- provider
55
- }];
51
+ return [];
52
+ }
53
+ /**
54
+ * Maintain the persisted `enabledProviders` set from a tunnel
55
+ * lifecycle event. `source.id` is `string | number`; `network-access`
56
+ * providers emit with `type: 'addon'` so it is always the addonId
57
+ * string. Non-string / non-addon sources are ignored defensively.
58
+ */
59
+ async onTunnelLifecycle(source, started) {
60
+ if (source.type !== "addon" || typeof source.id !== "string") {
61
+ this.ctx.logger.warn("tunnel lifecycle event with non-addon source — ignoring", { meta: {
62
+ sourceType: source.type,
63
+ sourceId: source.id,
64
+ started
65
+ } });
66
+ return;
67
+ }
68
+ await this.markEnabled(source.id, started);
56
69
  }
57
70
  async autoStartEnabledProviders() {
58
71
  const ids = this.config.enabledProviders;
@@ -96,38 +109,15 @@ var RemoteAccessOrchestratorAddon = class extends _camstack_types.BaseAddon {
96
109
  if (enabled) current.add(addonId);
97
110
  else current.delete(addonId);
98
111
  if (wasEnabled === enabled) return;
112
+ this.ctx.logger.info("remote-access intent updated", { meta: {
113
+ addonId,
114
+ enabled
115
+ } });
99
116
  await this.updateGlobalSettings({ enabledProviders: [...current] });
100
117
  }
101
118
  resolveImpl(addonId) {
102
119
  return (this.capabilities?.getCollectionEntries("network-access") ?? []).find(([id]) => id === addonId)?.[1] ?? null;
103
120
  }
104
- async listProviders() {
105
- const entries = this.capabilities?.getCollectionEntries("network-access") ?? [];
106
- const enabled = new Set(this.config.enabledProviders);
107
- const out = [];
108
- for (const [addonId, impl] of entries) {
109
- let connected = false;
110
- let endpoint = null;
111
- let error;
112
- if (impl.getStatus) try {
113
- const s = await impl.getStatus();
114
- connected = s.connected;
115
- endpoint = s.endpoint;
116
- error = s.error;
117
- } catch (err) {
118
- error = err instanceof Error ? err.message : String(err);
119
- }
120
- out.push({
121
- addonId,
122
- displayName: impl.displayName ?? addonId,
123
- enabled: enabled.has(addonId),
124
- connected,
125
- endpoint,
126
- ...error !== void 0 ? { error } : {}
127
- });
128
- }
129
- return out;
130
- }
131
121
  };
132
122
  //#endregion
133
123
  exports.RemoteAccessOrchestratorAddon = RemoteAccessOrchestratorAddon;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-access-orchestrator.addon.js","names":[],"sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"sourcesContent":["/**\n * Remote-access orchestrator — singleton facade over the\n * `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).\n * Mirrors the auth-orchestrator and backup-orchestrator patterns.\n *\n * Persistence + autostart contract:\n * The orchestrator owns the \"operator wants this provider running\"\n * intent — a `enabledProviders: string[]` slice in its addon-store\n * blob (BaseAddon.config). On boot we iterate the list and call\n * `provider.start()` for each enabled entry. `startProvider` /\n * `stopProvider` mutate this list so a Start press persists across\n * restarts. Same shape as turn-orchestrator's setProviderEnabled.\n */\nimport {\n BaseAddon,\n remoteAccessCapability,\n type IRemoteAccessOrchestrator,\n type RemoteAccessProviderInfo,\n type ProviderRegistration,\n} from '@camstack/types'\n\ninterface NetworkAccessLike {\n start?: () => Promise<{ url: string; hostname: string; port: number; protocol: 'http' | 'https' }>\n stop?: () => Promise<void>\n getStatus?: () => Promise<{\n connected: boolean\n endpoint: { url: string; hostname: string; port: number; protocol: 'http' | 'https' } | null\n error?: string\n }>\n}\n\ninterface NetworkAccessRegistrationMeta {\n readonly displayName?: string\n}\n\ninterface RemoteAccessOrchestratorConfig {\n /**\n * addonIds the operator has explicitly Started. Auto-respawned on\n * boot so a tunnel set up once stays up across hub restarts.\n */\n readonly enabledProviders: readonly string[]\n}\n\nexport class RemoteAccessOrchestratorAddon extends BaseAddon<RemoteAccessOrchestratorConfig> {\n constructor() {\n super({ enabledProviders: [] })\n }\n\n protected async onInitialize(): Promise<ProviderRegistration[]> {\n const provider: IRemoteAccessOrchestrator = {\n listProviders: async () => this.listProviders(),\n startProvider: async ({ addonId }) => {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) throw new Error(`Remote-access provider \"${addonId}\" does not support start`)\n const endpoint = await impl.start()\n // Persist intent — next boot will auto-respawn this provider.\n await this.markEnabled(addonId, true)\n return endpoint\n },\n stopProvider: async ({ addonId }) => {\n const impl = this.resolveImpl(addonId)\n if (impl?.stop) await impl.stop()\n // Clear intent — boot must NOT respawn this on next start.\n await this.markEnabled(addonId, false)\n return { success: true as const }\n },\n } satisfies IRemoteAccessOrchestrator\n this.ctx.logger.info('Remote-access orchestrator initialized', {\n meta: { enabledCount: this.config.enabledProviders.length },\n })\n // Defer autostart to next tick so the orchestrator's own provider\n // registration completes first. `resolveImpl` reads from the\n // capabilities registry which only sees in-process / cluster-mirrored\n // providers once they've ALSO registered — small delay gives the\n // cluster bridge time to discover them on cold boot. Errors are\n // logged but never block init.\n setImmediate(() => { this.autoStartEnabledProviders() })\n\n // Lazy retry — forked providers (cloudflare-tunnel etc) typically\n // register 15-20 s after this orchestrator boots, well past the\n // `setImmediate` above. Hook BaseAddon's `system.ready-state`\n // subscription so we re-run autoStart every time the\n // `network-access` cap transitions to ready (whichever node holds\n // it). The inner logic is idempotent + skips already-connected\n // providers.\n this.watchCapability('network-access', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Same watch for `mesh-network`. The tailscale-ingress provider\n // registers `network-access` synchronously at boot, but `start()`\n // throws when the tailnet isn't joined yet — so the boot-time\n // autoStart call fails for tailscale ingresses if the tailscale\n // daemon hadn't logged in by then. Watching `mesh-network` here\n // re-triggers autoStart the moment the client transitions to\n // joined (manual operator login or auto-rejoin), without needing\n // a server restart. Same idempotency rules: providers already\n // connected are skipped.\n this.watchCapability('mesh-network', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n return [{ capability: remoteAccessCapability, provider }]\n }\n\n private async autoStartEnabledProviders(): Promise<void> {\n const ids = this.config.enabledProviders\n if (ids.length === 0) return\n this.ctx.logger.info('Auto-starting enabled remote-access providers', {\n meta: { addonIds: [...ids] },\n })\n for (const addonId of ids) {\n try {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) {\n // Provider isn't loaded yet (worker bridge still hydrating)\n // OR it doesn't implement start. Log at debug level — the\n // provider-registered subscription below will retry as soon\n // as the addon appears.\n this.ctx.logger.warn('autostart: provider not ready or unsupported', {\n meta: { addonId, hasImpl: !!impl, hasStart: !!impl?.start },\n })\n continue\n }\n // Idempotent: skip when the provider is already connected.\n // Avoids spamming start() on every provider-registered event\n // and prevents respawning a child process that's already alive.\n if (impl.getStatus) {\n const status = await impl.getStatus().catch(() => null)\n if (status?.connected) {\n this.ctx.logger.info('autostart: provider already connected — skipping', {\n meta: { addonId, url: status.endpoint?.url },\n })\n continue\n }\n }\n const endpoint = await impl.start()\n this.ctx.logger.info('autostart: provider started', {\n meta: { addonId, url: endpoint.url },\n })\n } catch (err) {\n this.ctx.logger.error('autostart: provider start failed', {\n meta: {\n addonId,\n error: err instanceof Error ? err.message : String(err),\n },\n })\n }\n }\n }\n\n private async markEnabled(addonId: string, enabled: boolean): Promise<void> {\n const current = new Set(this.config.enabledProviders)\n const wasEnabled = current.has(addonId)\n if (enabled) current.add(addonId); else current.delete(addonId)\n if (wasEnabled === enabled) return\n await this.updateGlobalSettings({ enabledProviders: [...current] })\n }\n\n private resolveImpl(addonId: string): (NetworkAccessLike & NetworkAccessRegistrationMeta) | null {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike & NetworkAccessRegistrationMeta>(\n 'network-access',\n ) ?? []\n const found = entries.find(([id]) => id === addonId)\n return found?.[1] ?? null\n }\n\n private async listProviders(): Promise<readonly RemoteAccessProviderInfo[]> {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike & NetworkAccessRegistrationMeta>(\n 'network-access',\n ) ?? []\n const enabled = new Set(this.config.enabledProviders)\n const out: RemoteAccessProviderInfo[] = []\n for (const [addonId, impl] of entries) {\n let connected = false\n let endpoint: RemoteAccessProviderInfo['endpoint'] = null\n let error: string | undefined\n if (impl.getStatus) {\n try {\n const s = await impl.getStatus()\n connected = s.connected\n endpoint = s.endpoint\n error = s.error\n } catch (err) {\n error = err instanceof Error ? err.message : String(err)\n }\n }\n out.push({\n addonId,\n displayName: impl.displayName ?? addonId,\n // `enabled` is now the operator's persisted intent — orthogonal\n // to `connected` (which reflects the live tunnel state). Boot\n // tries to bring enabled→connected automatically.\n enabled: enabled.has(addonId),\n connected,\n endpoint,\n ...(error !== undefined ? { error } : {}),\n })\n }\n return out\n }\n}\n\nexport default RemoteAccessOrchestratorAddon\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,gCAAb,cAAmD,gBAAA,UAA0C;CAC3F,cAAc;EACZ,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC;;CAGjC,MAAgB,eAAgD;EAC9D,MAAM,WAAsC;GAC1C,eAAe,YAAY,KAAK,eAAe;GAC/C,eAAe,OAAO,EAAE,cAAc;IACpC,MAAM,OAAO,KAAK,YAAY,QAAQ;IACtC,IAAI,CAAC,MAAM,OAAO,MAAM,IAAI,MAAM,2BAA2B,QAAQ,0BAA0B;IAC/F,MAAM,WAAW,MAAM,KAAK,OAAO;IAEnC,MAA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AEJ,OAAO"}
1
+ {"version":3,"file":"remote-access-orchestrator.addon.js","names":[],"sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"sourcesContent":["/**\n * Remote-access orchestrator — backend-only boot-autostart service for\n * the `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).\n *\n * Retired its `remote-access` facade cap (2026-05-15): the admin UI now\n * talks to the `network-access` collection cap directly via generic\n * per-`addonId` routing, so this addon registers NO capability.\n *\n * What it still owns — the load-bearing logic:\n * The orchestrator owns the \"operator wants this provider running\"\n * intent — an `enabledProviders: string[]` slice in its addon-store\n * blob (BaseAddon.config). On boot we iterate the list and call\n * `provider.start()` for each enabled entry, so a tunnel set up once\n * stays up across hub restarts.\n *\n * Since start/stop no longer flow through this addon, the enabled-set\n * is maintained purely from the event bus: every `network-access`\n * provider emits `NetworkTunnelStarted` / `NetworkTunnelStopped` when\n * it starts/stops. We add the emitting addonId on Started, remove it\n * on Stopped, and persist — keeping the operator intent in sync no\n * matter who triggered the lifecycle change.\n */\nimport {\n BaseAddon,\n EventCategory,\n type ProviderRegistration,\n} from '@camstack/types'\n\ninterface NetworkAccessLike {\n start?: () => Promise<{ url: string; hostname: string; port: number; protocol: 'http' | 'https' }>\n getStatus?: () => Promise<{\n connected: boolean\n endpoint: { url: string; hostname: string; port: number; protocol: 'http' | 'https' } | null\n error?: string\n }>\n}\n\ninterface RemoteAccessOrchestratorConfig {\n /**\n * addonIds the operator has explicitly Started. Auto-respawned on\n * boot so a tunnel set up once stays up across hub restarts.\n */\n readonly enabledProviders: readonly string[]\n}\n\nexport class RemoteAccessOrchestratorAddon extends BaseAddon<RemoteAccessOrchestratorConfig> {\n constructor() {\n super({ enabledProviders: [] })\n }\n\n protected async onInitialize(): Promise<ProviderRegistration[]> {\n this.ctx.logger.info('Remote-access orchestrator initialized (backend-only)', {\n meta: { enabledCount: this.config.enabledProviders.length },\n })\n\n // Track operator intent from the lifecycle events every\n // `network-access` provider emits. The emitting addonId is carried\n // on `event.source.id` (events are emitted with\n // `source: { type: 'addon', id: ctx.id }`).\n this.ctx.eventBus?.subscribe(\n { category: EventCategory.NetworkTunnelStarted },\n (event) => { void this.onTunnelLifecycle(event.source, true) },\n )\n this.ctx.eventBus?.subscribe(\n { category: EventCategory.NetworkTunnelStopped },\n (event) => { void this.onTunnelLifecycle(event.source, false) },\n )\n\n // Defer autostart to next tick so provider registrations from\n // co-located addons settle first. `resolveImpl` reads from the\n // capabilities registry which only sees in-process / cluster-mirrored\n // providers once they've ALSO registered — small delay gives the\n // cluster bridge time to discover them on cold boot. Errors are\n // logged but never block init.\n setImmediate(() => { void this.autoStartEnabledProviders() })\n\n // Lazy retry — forked providers (cloudflare-tunnel etc) typically\n // register 15-20 s after this orchestrator boots, well past the\n // `setImmediate` above. Hook BaseAddon's `system.ready-state`\n // subscription so we re-run autoStart every time the\n // `network-access` cap transitions to ready (whichever node holds\n // it). The inner logic is idempotent + skips already-connected\n // providers.\n this.watchCapability('network-access', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Same watch for `mesh-network`. The tailscale-ingress provider\n // registers `network-access` synchronously at boot, but `start()`\n // throws when the tailnet isn't joined yet — so the boot-time\n // autoStart call fails for tailscale ingresses if the tailscale\n // daemon hadn't logged in by then. Watching `mesh-network` here\n // re-triggers autoStart the moment the client transitions to\n // joined (manual operator login or auto-rejoin), without needing\n // a server restart. Same idempotency rules: providers already\n // connected are skipped.\n this.watchCapability('mesh-network', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Backend-only addon — registers no capability.\n return []\n }\n\n /**\n * Maintain the persisted `enabledProviders` set from a tunnel\n * lifecycle event. `source.id` is `string | number`; `network-access`\n * providers emit with `type: 'addon'` so it is always the addonId\n * string. Non-string / non-addon sources are ignored defensively.\n */\n private async onTunnelLifecycle(\n source: { readonly type: string; readonly id: string | number },\n started: boolean,\n ): Promise<void> {\n if (source.type !== 'addon' || typeof source.id !== 'string') {\n this.ctx.logger.warn('tunnel lifecycle event with non-addon source — ignoring', {\n meta: { sourceType: source.type, sourceId: source.id, started },\n })\n return\n }\n await this.markEnabled(source.id, started)\n }\n\n private async autoStartEnabledProviders(): Promise<void> {\n const ids = this.config.enabledProviders\n if (ids.length === 0) return\n this.ctx.logger.info('Auto-starting enabled remote-access providers', {\n meta: { addonIds: [...ids] },\n })\n for (const addonId of ids) {\n try {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) {\n // Provider isn't loaded yet (worker bridge still hydrating)\n // OR it doesn't implement start. Log at warn level — the\n // `watchCapability` subscriptions above retry as soon as the\n // provider appears.\n this.ctx.logger.warn('autostart: provider not ready or unsupported', {\n meta: { addonId, hasImpl: !!impl, hasStart: !!impl?.start },\n })\n continue\n }\n // Idempotent: skip when the provider is already connected.\n // Avoids spamming start() on every ready-state event and\n // prevents respawning a child process that's already alive.\n if (impl.getStatus) {\n const status = await impl.getStatus().catch(() => null)\n if (status?.connected) {\n this.ctx.logger.info('autostart: provider already connected — skipping', {\n meta: { addonId, url: status.endpoint?.url },\n })\n continue\n }\n }\n const endpoint = await impl.start()\n this.ctx.logger.info('autostart: provider started', {\n meta: { addonId, url: endpoint.url },\n })\n } catch (err) {\n this.ctx.logger.error('autostart: provider start failed', {\n meta: {\n addonId,\n error: err instanceof Error ? err.message : String(err),\n },\n })\n }\n }\n }\n\n private async markEnabled(addonId: string, enabled: boolean): Promise<void> {\n const current = new Set(this.config.enabledProviders)\n const wasEnabled = current.has(addonId)\n if (enabled) current.add(addonId); else current.delete(addonId)\n if (wasEnabled === enabled) return\n this.ctx.logger.info('remote-access intent updated', {\n meta: { addonId, enabled },\n })\n await this.updateGlobalSettings({ enabledProviders: [...current] })\n }\n\n private resolveImpl(addonId: string): NetworkAccessLike | null {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike>(\n 'network-access',\n ) ?? []\n const found = entries.find(([id]) => id === addonId)\n return found?.[1] ?? null\n }\n}\n\nexport default RemoteAccessOrchestratorAddon\n"],"mappings":";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ins/remote-access-orchestrator/remote-access-orchestrator.addon.ts
3
3
  /**
4
- * Remote-access orchestrator — singleton facade over the
5
- * `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).
6
- * Mirrors the auth-orchestrator and backup-orchestrator patterns.
4
+ * Remote-access orchestrator — backend-only boot-autostart service for
5
+ * the `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).
7
6
  *
8
- * Persistence + autostart contract:
7
+ * Retired its `remote-access` facade cap (2026-05-15): the admin UI now
8
+ * talks to the `network-access` collection cap directly via generic
9
+ * per-`addonId` routing, so this addon registers NO capability.
10
+ *
11
+ * What it still owns — the load-bearing logic:
9
12
  * The orchestrator owns the "operator wants this provider running"
10
- * intent — a `enabledProviders: string[]` slice in its addon-store
13
+ * intent — an `enabledProviders: string[]` slice in its addon-store
11
14
  * blob (BaseAddon.config). On boot we iterate the list and call
12
- * `provider.start()` for each enabled entry. `startProvider` /
13
- * `stopProvider` mutate this list so a Start press persists across
14
- * restarts. Same shape as turn-orchestrator's setProviderEnabled.
15
+ * `provider.start()` for each enabled entry, so a tunnel set up once
16
+ * stays up across hub restarts.
17
+ *
18
+ * Since start/stop no longer flow through this addon, the enabled-set
19
+ * is maintained purely from the event bus: every `network-access`
20
+ * provider emits `NetworkTunnelStarted` / `NetworkTunnelStopped` when
21
+ * it starts/stops. We add the emitting addonId on Started, remove it
22
+ * on Stopped, and persist — keeping the operator intent in sync no
23
+ * matter who triggered the lifecycle change.
15
24
  */
16
25
  var RemoteAccessOrchestratorAddon = class extends BaseAddon {
17
26
  constructor() {
18
27
  super({ enabledProviders: [] });
19
28
  }
20
29
  async onInitialize() {
21
- const provider = {
22
- listProviders: async () => this.listProviders(),
23
- startProvider: async ({ addonId }) => {
24
- const impl = this.resolveImpl(addonId);
25
- if (!impl?.start) throw new Error(`Remote-access provider "${addonId}" does not support start`);
26
- const endpoint = await impl.start();
27
- await this.markEnabled(addonId, true);
28
- return endpoint;
29
- },
30
- stopProvider: async ({ addonId }) => {
31
- const impl = this.resolveImpl(addonId);
32
- if (impl?.stop) await impl.stop();
33
- await this.markEnabled(addonId, false);
34
- return { success: true };
35
- }
36
- };
37
- this.ctx.logger.info("Remote-access orchestrator initialized", { meta: { enabledCount: this.config.enabledProviders.length } });
30
+ this.ctx.logger.info("Remote-access orchestrator initialized (backend-only)", { meta: { enabledCount: this.config.enabledProviders.length } });
31
+ this.ctx.eventBus?.subscribe({ category: EventCategory.NetworkTunnelStarted }, (event) => {
32
+ this.onTunnelLifecycle(event.source, true);
33
+ });
34
+ this.ctx.eventBus?.subscribe({ category: EventCategory.NetworkTunnelStopped }, (event) => {
35
+ this.onTunnelLifecycle(event.source, false);
36
+ });
38
37
  setImmediate(() => {
39
38
  this.autoStartEnabledProviders();
40
39
  });
@@ -44,10 +43,24 @@ var RemoteAccessOrchestratorAddon = class extends BaseAddon {
44
43
  this.watchCapability("mesh-network", { onReady: () => {
45
44
  this.autoStartEnabledProviders();
46
45
  } });
47
- return [{
48
- capability: remoteAccessCapability,
49
- provider
50
- }];
46
+ return [];
47
+ }
48
+ /**
49
+ * Maintain the persisted `enabledProviders` set from a tunnel
50
+ * lifecycle event. `source.id` is `string | number`; `network-access`
51
+ * providers emit with `type: 'addon'` so it is always the addonId
52
+ * string. Non-string / non-addon sources are ignored defensively.
53
+ */
54
+ async onTunnelLifecycle(source, started) {
55
+ if (source.type !== "addon" || typeof source.id !== "string") {
56
+ this.ctx.logger.warn("tunnel lifecycle event with non-addon source — ignoring", { meta: {
57
+ sourceType: source.type,
58
+ sourceId: source.id,
59
+ started
60
+ } });
61
+ return;
62
+ }
63
+ await this.markEnabled(source.id, started);
51
64
  }
52
65
  async autoStartEnabledProviders() {
53
66
  const ids = this.config.enabledProviders;
@@ -91,38 +104,15 @@ var RemoteAccessOrchestratorAddon = class extends BaseAddon {
91
104
  if (enabled) current.add(addonId);
92
105
  else current.delete(addonId);
93
106
  if (wasEnabled === enabled) return;
107
+ this.ctx.logger.info("remote-access intent updated", { meta: {
108
+ addonId,
109
+ enabled
110
+ } });
94
111
  await this.updateGlobalSettings({ enabledProviders: [...current] });
95
112
  }
96
113
  resolveImpl(addonId) {
97
114
  return (this.capabilities?.getCollectionEntries("network-access") ?? []).find(([id]) => id === addonId)?.[1] ?? null;
98
115
  }
99
- async listProviders() {
100
- const entries = this.capabilities?.getCollectionEntries("network-access") ?? [];
101
- const enabled = new Set(this.config.enabledProviders);
102
- const out = [];
103
- for (const [addonId, impl] of entries) {
104
- let connected = false;
105
- let endpoint = null;
106
- let error;
107
- if (impl.getStatus) try {
108
- const s = await impl.getStatus();
109
- connected = s.connected;
110
- endpoint = s.endpoint;
111
- error = s.error;
112
- } catch (err) {
113
- error = err instanceof Error ? err.message : String(err);
114
- }
115
- out.push({
116
- addonId,
117
- displayName: impl.displayName ?? addonId,
118
- enabled: enabled.has(addonId),
119
- connected,
120
- endpoint,
121
- ...error !== void 0 ? { error } : {}
122
- });
123
- }
124
- return out;
125
- }
126
116
  };
127
117
  //#endregion
128
118
  export { RemoteAccessOrchestratorAddon, RemoteAccessOrchestratorAddon as default };
@@ -1 +1 @@
1
- {"version":3,"file":"remote-access-orchestrator.addon.mjs","names":[],"sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"sourcesContent":["/**\n * Remote-access orchestrator — singleton facade over the\n * `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).\n * Mirrors the auth-orchestrator and backup-orchestrator patterns.\n *\n * Persistence + autostart contract:\n * The orchestrator owns the \"operator wants this provider running\"\n * intent — a `enabledProviders: string[]` slice in its addon-store\n * blob (BaseAddon.config). On boot we iterate the list and call\n * `provider.start()` for each enabled entry. `startProvider` /\n * `stopProvider` mutate this list so a Start press persists across\n * restarts. Same shape as turn-orchestrator's setProviderEnabled.\n */\nimport {\n BaseAddon,\n remoteAccessCapability,\n type IRemoteAccessOrchestrator,\n type RemoteAccessProviderInfo,\n type ProviderRegistration,\n} from '@camstack/types'\n\ninterface NetworkAccessLike {\n start?: () => Promise<{ url: string; hostname: string; port: number; protocol: 'http' | 'https' }>\n stop?: () => Promise<void>\n getStatus?: () => Promise<{\n connected: boolean\n endpoint: { url: string; hostname: string; port: number; protocol: 'http' | 'https' } | null\n error?: string\n }>\n}\n\ninterface NetworkAccessRegistrationMeta {\n readonly displayName?: string\n}\n\ninterface RemoteAccessOrchestratorConfig {\n /**\n * addonIds the operator has explicitly Started. Auto-respawned on\n * boot so a tunnel set up once stays up across hub restarts.\n */\n readonly enabledProviders: readonly string[]\n}\n\nexport class RemoteAccessOrchestratorAddon extends BaseAddon<RemoteAccessOrchestratorConfig> {\n constructor() {\n super({ enabledProviders: [] })\n }\n\n protected async onInitialize(): Promise<ProviderRegistration[]> {\n const provider: IRemoteAccessOrchestrator = {\n listProviders: async () => this.listProviders(),\n startProvider: async ({ addonId }) => {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) throw new Error(`Remote-access provider \"${addonId}\" does not support start`)\n const endpoint = await impl.start()\n // Persist intent — next boot will auto-respawn this provider.\n await this.markEnabled(addonId, true)\n return endpoint\n },\n stopProvider: async ({ addonId }) => {\n const impl = this.resolveImpl(addonId)\n if (impl?.stop) await impl.stop()\n // Clear intent — boot must NOT respawn this on next start.\n await this.markEnabled(addonId, false)\n return { success: true as const }\n },\n } satisfies IRemoteAccessOrchestrator\n this.ctx.logger.info('Remote-access orchestrator initialized', {\n meta: { enabledCount: this.config.enabledProviders.length },\n })\n // Defer autostart to next tick so the orchestrator's own provider\n // registration completes first. `resolveImpl` reads from the\n // capabilities registry which only sees in-process / cluster-mirrored\n // providers once they've ALSO registered — small delay gives the\n // cluster bridge time to discover them on cold boot. Errors are\n // logged but never block init.\n setImmediate(() => { this.autoStartEnabledProviders() })\n\n // Lazy retry — forked providers (cloudflare-tunnel etc) typically\n // register 15-20 s after this orchestrator boots, well past the\n // `setImmediate` above. Hook BaseAddon's `system.ready-state`\n // subscription so we re-run autoStart every time the\n // `network-access` cap transitions to ready (whichever node holds\n // it). The inner logic is idempotent + skips already-connected\n // providers.\n this.watchCapability('network-access', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Same watch for `mesh-network`. The tailscale-ingress provider\n // registers `network-access` synchronously at boot, but `start()`\n // throws when the tailnet isn't joined yet — so the boot-time\n // autoStart call fails for tailscale ingresses if the tailscale\n // daemon hadn't logged in by then. Watching `mesh-network` here\n // re-triggers autoStart the moment the client transitions to\n // joined (manual operator login or auto-rejoin), without needing\n // a server restart. Same idempotency rules: providers already\n // connected are skipped.\n this.watchCapability('mesh-network', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n return [{ capability: remoteAccessCapability, provider }]\n }\n\n private async autoStartEnabledProviders(): Promise<void> {\n const ids = this.config.enabledProviders\n if (ids.length === 0) return\n this.ctx.logger.info('Auto-starting enabled remote-access providers', {\n meta: { addonIds: [...ids] },\n })\n for (const addonId of ids) {\n try {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) {\n // Provider isn't loaded yet (worker bridge still hydrating)\n // OR it doesn't implement start. Log at debug level — the\n // provider-registered subscription below will retry as soon\n // as the addon appears.\n this.ctx.logger.warn('autostart: provider not ready or unsupported', {\n meta: { addonId, hasImpl: !!impl, hasStart: !!impl?.start },\n })\n continue\n }\n // Idempotent: skip when the provider is already connected.\n // Avoids spamming start() on every provider-registered event\n // and prevents respawning a child process that's already alive.\n if (impl.getStatus) {\n const status = await impl.getStatus().catch(() => null)\n if (status?.connected) {\n this.ctx.logger.info('autostart: provider already connected — skipping', {\n meta: { addonId, url: status.endpoint?.url },\n })\n continue\n }\n }\n const endpoint = await impl.start()\n this.ctx.logger.info('autostart: provider started', {\n meta: { addonId, url: endpoint.url },\n })\n } catch (err) {\n this.ctx.logger.error('autostart: provider start failed', {\n meta: {\n addonId,\n error: err instanceof Error ? err.message : String(err),\n },\n })\n }\n }\n }\n\n private async markEnabled(addonId: string, enabled: boolean): Promise<void> {\n const current = new Set(this.config.enabledProviders)\n const wasEnabled = current.has(addonId)\n if (enabled) current.add(addonId); else current.delete(addonId)\n if (wasEnabled === enabled) return\n await this.updateGlobalSettings({ enabledProviders: [...current] })\n }\n\n private resolveImpl(addonId: string): (NetworkAccessLike & NetworkAccessRegistrationMeta) | null {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike & NetworkAccessRegistrationMeta>(\n 'network-access',\n ) ?? []\n const found = entries.find(([id]) => id === addonId)\n return found?.[1] ?? null\n }\n\n private async listProviders(): Promise<readonly RemoteAccessProviderInfo[]> {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike & NetworkAccessRegistrationMeta>(\n 'network-access',\n ) ?? []\n const enabled = new Set(this.config.enabledProviders)\n const out: RemoteAccessProviderInfo[] = []\n for (const [addonId, impl] of entries) {\n let connected = false\n let endpoint: RemoteAccessProviderInfo['endpoint'] = null\n let error: string | undefined\n if (impl.getStatus) {\n try {\n const s = await impl.getStatus()\n connected = s.connected\n endpoint = s.endpoint\n error = s.error\n } catch (err) {\n error = err instanceof Error ? err.message : String(err)\n }\n }\n out.push({\n addonId,\n displayName: impl.displayName ?? addonId,\n // `enabled` is now the operator's persisted intent — orthogonal\n // to `connected` (which reflects the live tunnel state). Boot\n // tries to bring enabled→connected automatically.\n enabled: enabled.has(addonId),\n connected,\n endpoint,\n ...(error !== undefined ? { error } : {}),\n })\n }\n return out\n }\n}\n\nexport default RemoteAccessOrchestratorAddon\n"],"mappings":";;;;;;;;;;;;;;;AA2CA,IAAa,gCAAb,cAAmD,UAA0C;CAC3F,cAAc;EACZ,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC;;CAGjC,MAAgB,eAAgD;EAC9D,MAAM,WAAsC;GAC1C,eAAe,YAAY,KAAK,eAAe;GAC/C,eAAe,OAAO,EAAE,cAAc;IACpC,MAAM,OAAO,KAAK,YAAY,QAAQ;IACtC,IAAI,CAAC,MAAM,OAAO,MAAM,IAAI,MAAM,2BAA2B,QAAQ,0BAA0B;IAC/F,MAAM,WAAW,MAAM,KAAK,OAAO;IA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EAEJ,OAAO"}
1
+ {"version":3,"file":"remote-access-orchestrator.addon.mjs","names":[],"sources":["../../../src/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.ts"],"sourcesContent":["/**\n * Remote-access orchestrator — backend-only boot-autostart service for\n * the `network-access` collection (Cloudflare Tunnel, ngrok, Tailscale, …).\n *\n * Retired its `remote-access` facade cap (2026-05-15): the admin UI now\n * talks to the `network-access` collection cap directly via generic\n * per-`addonId` routing, so this addon registers NO capability.\n *\n * What it still owns — the load-bearing logic:\n * The orchestrator owns the \"operator wants this provider running\"\n * intent — an `enabledProviders: string[]` slice in its addon-store\n * blob (BaseAddon.config). On boot we iterate the list and call\n * `provider.start()` for each enabled entry, so a tunnel set up once\n * stays up across hub restarts.\n *\n * Since start/stop no longer flow through this addon, the enabled-set\n * is maintained purely from the event bus: every `network-access`\n * provider emits `NetworkTunnelStarted` / `NetworkTunnelStopped` when\n * it starts/stops. We add the emitting addonId on Started, remove it\n * on Stopped, and persist — keeping the operator intent in sync no\n * matter who triggered the lifecycle change.\n */\nimport {\n BaseAddon,\n EventCategory,\n type ProviderRegistration,\n} from '@camstack/types'\n\ninterface NetworkAccessLike {\n start?: () => Promise<{ url: string; hostname: string; port: number; protocol: 'http' | 'https' }>\n getStatus?: () => Promise<{\n connected: boolean\n endpoint: { url: string; hostname: string; port: number; protocol: 'http' | 'https' } | null\n error?: string\n }>\n}\n\ninterface RemoteAccessOrchestratorConfig {\n /**\n * addonIds the operator has explicitly Started. Auto-respawned on\n * boot so a tunnel set up once stays up across hub restarts.\n */\n readonly enabledProviders: readonly string[]\n}\n\nexport class RemoteAccessOrchestratorAddon extends BaseAddon<RemoteAccessOrchestratorConfig> {\n constructor() {\n super({ enabledProviders: [] })\n }\n\n protected async onInitialize(): Promise<ProviderRegistration[]> {\n this.ctx.logger.info('Remote-access orchestrator initialized (backend-only)', {\n meta: { enabledCount: this.config.enabledProviders.length },\n })\n\n // Track operator intent from the lifecycle events every\n // `network-access` provider emits. The emitting addonId is carried\n // on `event.source.id` (events are emitted with\n // `source: { type: 'addon', id: ctx.id }`).\n this.ctx.eventBus?.subscribe(\n { category: EventCategory.NetworkTunnelStarted },\n (event) => { void this.onTunnelLifecycle(event.source, true) },\n )\n this.ctx.eventBus?.subscribe(\n { category: EventCategory.NetworkTunnelStopped },\n (event) => { void this.onTunnelLifecycle(event.source, false) },\n )\n\n // Defer autostart to next tick so provider registrations from\n // co-located addons settle first. `resolveImpl` reads from the\n // capabilities registry which only sees in-process / cluster-mirrored\n // providers once they've ALSO registered — small delay gives the\n // cluster bridge time to discover them on cold boot. Errors are\n // logged but never block init.\n setImmediate(() => { void this.autoStartEnabledProviders() })\n\n // Lazy retry — forked providers (cloudflare-tunnel etc) typically\n // register 15-20 s after this orchestrator boots, well past the\n // `setImmediate` above. Hook BaseAddon's `system.ready-state`\n // subscription so we re-run autoStart every time the\n // `network-access` cap transitions to ready (whichever node holds\n // it). The inner logic is idempotent + skips already-connected\n // providers.\n this.watchCapability('network-access', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Same watch for `mesh-network`. The tailscale-ingress provider\n // registers `network-access` synchronously at boot, but `start()`\n // throws when the tailnet isn't joined yet — so the boot-time\n // autoStart call fails for tailscale ingresses if the tailscale\n // daemon hadn't logged in by then. Watching `mesh-network` here\n // re-triggers autoStart the moment the client transitions to\n // joined (manual operator login or auto-rejoin), without needing\n // a server restart. Same idempotency rules: providers already\n // connected are skipped.\n this.watchCapability('mesh-network', {\n onReady: () => { void this.autoStartEnabledProviders() },\n })\n\n // Backend-only addon — registers no capability.\n return []\n }\n\n /**\n * Maintain the persisted `enabledProviders` set from a tunnel\n * lifecycle event. `source.id` is `string | number`; `network-access`\n * providers emit with `type: 'addon'` so it is always the addonId\n * string. Non-string / non-addon sources are ignored defensively.\n */\n private async onTunnelLifecycle(\n source: { readonly type: string; readonly id: string | number },\n started: boolean,\n ): Promise<void> {\n if (source.type !== 'addon' || typeof source.id !== 'string') {\n this.ctx.logger.warn('tunnel lifecycle event with non-addon source — ignoring', {\n meta: { sourceType: source.type, sourceId: source.id, started },\n })\n return\n }\n await this.markEnabled(source.id, started)\n }\n\n private async autoStartEnabledProviders(): Promise<void> {\n const ids = this.config.enabledProviders\n if (ids.length === 0) return\n this.ctx.logger.info('Auto-starting enabled remote-access providers', {\n meta: { addonIds: [...ids] },\n })\n for (const addonId of ids) {\n try {\n const impl = this.resolveImpl(addonId)\n if (!impl?.start) {\n // Provider isn't loaded yet (worker bridge still hydrating)\n // OR it doesn't implement start. Log at warn level — the\n // `watchCapability` subscriptions above retry as soon as the\n // provider appears.\n this.ctx.logger.warn('autostart: provider not ready or unsupported', {\n meta: { addonId, hasImpl: !!impl, hasStart: !!impl?.start },\n })\n continue\n }\n // Idempotent: skip when the provider is already connected.\n // Avoids spamming start() on every ready-state event and\n // prevents respawning a child process that's already alive.\n if (impl.getStatus) {\n const status = await impl.getStatus().catch(() => null)\n if (status?.connected) {\n this.ctx.logger.info('autostart: provider already connected — skipping', {\n meta: { addonId, url: status.endpoint?.url },\n })\n continue\n }\n }\n const endpoint = await impl.start()\n this.ctx.logger.info('autostart: provider started', {\n meta: { addonId, url: endpoint.url },\n })\n } catch (err) {\n this.ctx.logger.error('autostart: provider start failed', {\n meta: {\n addonId,\n error: err instanceof Error ? err.message : String(err),\n },\n })\n }\n }\n }\n\n private async markEnabled(addonId: string, enabled: boolean): Promise<void> {\n const current = new Set(this.config.enabledProviders)\n const wasEnabled = current.has(addonId)\n if (enabled) current.add(addonId); else current.delete(addonId)\n if (wasEnabled === enabled) return\n this.ctx.logger.info('remote-access intent updated', {\n meta: { addonId, enabled },\n })\n await this.updateGlobalSettings({ enabledProviders: [...current] })\n }\n\n private resolveImpl(addonId: string): NetworkAccessLike | null {\n const entries = this.capabilities?.getCollectionEntries<NetworkAccessLike>(\n 'network-access',\n ) ?? []\n const found = entries.find(([id]) => id === addonId)\n return found?.[1] ?? null\n }\n}\n\nexport default RemoteAccessOrchestratorAddon\n"],"mapp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