@nextclaw/service 0.1.1

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 (242) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
  3. package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
  4. package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
  5. package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
  6. package/dist/cli/commands/agent/index.d.ts +3 -0
  7. package/dist/cli/commands/agent/index.js +3 -0
  8. package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
  9. package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
  10. package/dist/cli/commands/companion/index.d.ts +15 -0
  11. package/dist/cli/commands/companion/index.js +24 -0
  12. package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
  13. package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
  14. package/dist/cli/commands/config/index.d.ts +2 -0
  15. package/dist/cli/commands/config/index.js +2 -0
  16. package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
  17. package/dist/cli/commands/config/services/config-commands.service.js +133 -0
  18. package/dist/cli/commands/cron/index.d.ts +2 -0
  19. package/dist/cli/commands/cron/index.js +2 -0
  20. package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
  21. package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
  22. package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
  23. package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
  24. package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
  25. package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
  26. package/dist/cli/commands/diagnostics/index.d.ts +2 -0
  27. package/dist/cli/commands/diagnostics/index.js +2 -0
  28. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
  29. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
  30. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
  31. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
  32. package/dist/cli/commands/gateway/index.d.ts +14 -0
  33. package/dist/cli/commands/gateway/index.js +15 -0
  34. package/dist/cli/commands/logs/index.d.ts +12 -0
  35. package/dist/cli/commands/logs/index.js +29 -0
  36. package/dist/cli/commands/mcp/index.d.ts +14 -0
  37. package/dist/cli/commands/mcp/index.js +193 -0
  38. package/dist/cli/commands/restart/index.d.ts +20 -0
  39. package/dist/cli/commands/restart/index.js +88 -0
  40. package/dist/cli/commands/secrets/index.d.ts +22 -0
  41. package/dist/cli/commands/secrets/index.js +280 -0
  42. package/dist/cli/commands/serve/index.d.ts +14 -0
  43. package/dist/cli/commands/serve/index.js +19 -0
  44. package/dist/cli/commands/skills/index.d.ts +26 -0
  45. package/dist/cli/commands/skills/index.js +147 -0
  46. package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
  47. package/dist/cli/commands/skills/marketplace-client.js +84 -0
  48. package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
  49. package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
  50. package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
  51. package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
  52. package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
  53. package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
  54. package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
  55. package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
  56. package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
  57. package/dist/cli/commands/skills/marketplace.service.js +238 -0
  58. package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
  59. package/dist/cli/commands/skills/skills-query.service.js +212 -0
  60. package/dist/cli/commands/start/index.d.ts +18 -0
  61. package/dist/cli/commands/start/index.js +25 -0
  62. package/dist/cli/commands/stop/index.d.ts +12 -0
  63. package/dist/cli/commands/stop/index.js +11 -0
  64. package/dist/cli/commands/ui/index.d.ts +14 -0
  65. package/dist/cli/commands/ui/index.js +17 -0
  66. package/dist/cli/commands/usage/index.d.ts +2 -0
  67. package/dist/cli/commands/usage/index.js +2 -0
  68. package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
  69. package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
  70. package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
  71. package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
  72. package/dist/commands/channel/channel-config-view.d.ts +7 -0
  73. package/dist/commands/channel/channel-config-view.js +7 -0
  74. package/dist/commands/channel/index.d.ts +28 -0
  75. package/dist/commands/channel/index.js +224 -0
  76. package/dist/commands/platform-auth/index.d.ts +2 -0
  77. package/dist/commands/platform-auth/index.js +2 -0
  78. package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
  79. package/dist/commands/platform-auth/services/account-status.service.js +34 -0
  80. package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
  81. package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
  82. package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
  83. package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
  84. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
  85. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
  86. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
  87. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
  88. package/dist/commands/plugin/index.d.ts +30 -0
  89. package/dist/commands/plugin/index.js +266 -0
  90. package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
  91. package/dist/commands/plugin/plugin-command-utils.js +37 -0
  92. package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
  93. package/dist/commands/plugin/plugin-extension-registry.js +35 -0
  94. package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
  95. package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
  96. package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
  97. package/dist/commands/plugin/plugin-registry-loader.js +43 -0
  98. package/dist/commands/plugin/plugin-reload.d.ts +13 -0
  99. package/dist/commands/plugin/plugin-reload.js +42 -0
  100. package/dist/commands/remote/index.d.ts +47 -0
  101. package/dist/commands/remote/index.js +174 -0
  102. package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
  103. package/dist/commands/remote/services/remote-access-host.service.js +126 -0
  104. package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
  105. package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
  106. package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
  107. package/dist/commands/remote/services/remote-service-control.service.js +188 -0
  108. package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
  109. package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
  110. package/dist/commands/service/index.d.ts +16 -0
  111. package/dist/commands/service/index.js +31 -0
  112. package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
  113. package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
  114. package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
  115. package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
  116. package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
  117. package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
  118. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
  119. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
  120. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
  121. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
  122. package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
  123. package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
  124. package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
  125. package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
  126. package/dist/index.d.ts +4 -0
  127. package/dist/index.js +3 -0
  128. package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
  129. package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
  130. package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
  131. package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
  132. package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
  133. package/dist/launcher/npm-runtime-bundle.service.js +150 -0
  134. package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
  135. package/dist/launcher/npm-runtime-bundle.types.js +1 -0
  136. package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
  137. package/dist/launcher/npm-runtime-launcher.service.js +57 -0
  138. package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
  139. package/dist/launcher/npm-runtime-update-command.service.js +87 -0
  140. package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
  141. package/dist/launcher/npm-runtime-update-source.service.js +57 -0
  142. package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
  143. package/dist/launcher/npm-runtime-update-state.store.js +92 -0
  144. package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
  145. package/dist/launcher/npm-runtime-update.manager.js +179 -0
  146. package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
  147. package/dist/launcher/npm-runtime-update.service.js +183 -0
  148. package/dist/service-runtime.service.d.ts +91 -0
  149. package/dist/service-runtime.service.js +392 -0
  150. package/dist/shared/controllers/gateway.controller.d.ts +61 -0
  151. package/dist/shared/controllers/gateway.controller.js +318 -0
  152. package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
  153. package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
  154. package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
  155. package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
  156. package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
  157. package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
  158. package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
  159. package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
  160. package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
  161. package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
  162. package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
  163. package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
  164. package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
  165. package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
  166. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
  167. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
  168. package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
  169. package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
  170. package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
  171. package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
  172. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
  173. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
  174. package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
  175. package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
  176. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
  177. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
  178. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
  179. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
  180. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
  181. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
  182. package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
  183. package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
  184. package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
  185. package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
  186. package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
  187. package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
  188. package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
  189. package/dist/shared/services/runtime/runtime-command.service.js +163 -0
  190. package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
  191. package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
  192. package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
  193. package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
  194. package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
  195. package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
  196. package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
  197. package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
  198. package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
  199. package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
  200. package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
  201. package/dist/shared/services/ui/companion-runtime.service.js +145 -0
  202. package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
  203. package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
  204. package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
  205. package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
  206. package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
  207. package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
  208. package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
  209. package/dist/shared/services/ui/service-remote-access.service.js +38 -0
  210. package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
  211. package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
  212. package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
  213. package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
  214. package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
  215. package/dist/shared/stores/companion-runtime.store.js +27 -0
  216. package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
  217. package/dist/shared/stores/local-ui-runtime.store.js +54 -0
  218. package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
  219. package/dist/shared/stores/managed-service-state.store.js +38 -0
  220. package/dist/shared/stores/pending-restart.store.d.ts +21 -0
  221. package/dist/shared/stores/pending-restart.store.js +35 -0
  222. package/dist/shared/types/cli.types.d.ts +295 -0
  223. package/dist/shared/types/cli.types.js +1 -0
  224. package/dist/shared/utils/cli.utils.d.ts +34 -0
  225. package/dist/shared/utils/cli.utils.js +262 -0
  226. package/dist/shared/utils/config-path.d.ts +15 -0
  227. package/dist/shared/utils/config-path.js +167 -0
  228. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
  229. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
  230. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
  231. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
  232. package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
  233. package/dist/shared/utils/package/package-manifest.utils.js +48 -0
  234. package/dist/shared/utils/runtime-helpers.d.ts +14 -0
  235. package/dist/shared/utils/runtime-helpers.js +26 -0
  236. package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
  237. package/dist/shared/utils/service-port-probe.utils.js +164 -0
  238. package/dist/shared/utils/startup-trace.d.ts +7 -0
  239. package/dist/shared/utils/startup-trace.js +37 -0
  240. package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
  241. package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
  242. package/package.json +68 -0
@@ -0,0 +1,218 @@
1
+ import { toExtensionRegistry } from "../../../../commands/plugin/plugin-extension-registry.js";
2
+ import { createEmptyPluginRegistry, discoverPluginRegistryStatus, loadPluginRegistryProgressively } from "../../../../commands/plugin/plugin-registry-loader.js";
3
+ import { logPluginDiagnostics } from "../../../../commands/plugin/index.js";
4
+ import { shouldRestartChannelsForPluginReload } from "../../../../commands/plugin/plugin-reload.js";
5
+ import { logPluginGatewayDiagnostics, pluginGatewayLogger } from "../service-startup-support.service.js";
6
+ import { getWorkspacePath } from "@nextclaw/core";
7
+ import { eventKeys } from "@nextclaw/shared";
8
+ import { getPluginChannelBindings, getPluginUiMetadataFromRegistry, toPluginConfigView } from "@nextclaw/openclaw-compat";
9
+ //#region src/shared/services/gateway/managers/gateway-plugin.manager.ts
10
+ function buildSnapshot(registry, extensionContributions) {
11
+ const extensionChannelIds = new Set(extensionContributions.channelBindings.map((binding) => binding.channelId));
12
+ const extensionPluginIds = new Set(extensionContributions.uiMetadata.map((metadata) => metadata.id));
13
+ return {
14
+ registry,
15
+ extensionRegistry: toExtensionRegistry(registry),
16
+ channelBindings: [...getPluginChannelBindings(registry).filter((binding) => !extensionChannelIds.has(binding.channelId)), ...extensionContributions.channelBindings],
17
+ uiMetadata: [...getPluginUiMetadataFromRegistry(registry).filter((metadata) => !extensionPluginIds.has(metadata.id)), ...extensionContributions.uiMetadata]
18
+ };
19
+ }
20
+ function countEnabledPlugins(config, workspaceDir) {
21
+ return discoverPluginRegistryStatus(config, workspaceDir).plugins.filter((plugin) => plugin.enabled).length;
22
+ }
23
+ var GatewayPluginManager = class {
24
+ extensionContributions = {
25
+ channelBindings: [],
26
+ uiMetadata: []
27
+ };
28
+ snapshot = buildSnapshot(createEmptyPluginRegistry(), this.extensionContributions);
29
+ gatewayHandles = [];
30
+ constructor(gateway) {
31
+ this.gateway = gateway;
32
+ }
33
+ getRegistry = () => this.snapshot.registry;
34
+ getExtensionRegistry = () => this.snapshot.extensionRegistry;
35
+ getChannelBindings = () => this.snapshot.channelBindings;
36
+ getUiMetadata = () => this.snapshot.uiMetadata;
37
+ load = async () => {
38
+ const config = this.gateway.configManager.loadConfig();
39
+ const workspace = getWorkspacePath(config.agents.defaults.workspace);
40
+ const totalPluginCount = countEnabledPlugins(config, workspace);
41
+ let loadedPluginCount = 0;
42
+ this.gateway.bootstrapStatus.markPluginHydrationRunning({ totalPluginCount });
43
+ this.gateway.bootstrapStatus.markChannelsPending();
44
+ try {
45
+ const registry = await loadPluginRegistryProgressively(config, workspace, { onPluginProcessed: ({ loadedPluginCount: nextCount }) => {
46
+ loadedPluginCount = nextCount;
47
+ this.gateway.bootstrapStatus.markPluginHydrationProgress({
48
+ loadedPluginCount: nextCount,
49
+ totalPluginCount
50
+ });
51
+ } });
52
+ this.extensionContributions = await this.gateway.extensions.loadContributions();
53
+ const shouldRebuildChannels = this.replaceSnapshot(registry, []);
54
+ this.loadKernelExtensionContributions(registry);
55
+ logPluginDiagnostics(registry);
56
+ if (shouldRebuildChannels) await this.gateway.configManager.rebuildChannels(config, { start: false });
57
+ this.publishConfigChanges();
58
+ this.gateway.bootstrapStatus.markPluginHydrationReady({
59
+ loadedPluginCount: loadedPluginCount || totalPluginCount,
60
+ totalPluginCount
61
+ });
62
+ } catch (error) {
63
+ this.gateway.bootstrapStatus.markPluginHydrationError(error instanceof Error ? error.message : String(error));
64
+ throw error;
65
+ }
66
+ };
67
+ reloadForConfigChange = async (params) => {
68
+ const workspace = getWorkspacePath(params.config.agents.defaults.workspace);
69
+ const registry = await loadPluginRegistryProgressively(params.config, workspace);
70
+ this.extensionContributions = await this.gateway.extensions.loadContributions();
71
+ const restartChannels = this.replaceSnapshot(registry, params.changedPaths);
72
+ this.loadKernelExtensionContributions(registry);
73
+ logPluginDiagnostics(registry);
74
+ if (restartChannels) await this.restartGateways();
75
+ this.publishConfigChanges();
76
+ return { restartChannels };
77
+ };
78
+ reloadForDevHotReload = async (changedPaths) => {
79
+ const config = this.gateway.configManager.loadConfig();
80
+ if ((await this.reloadForConfigChange({
81
+ config,
82
+ changedPaths
83
+ })).restartChannels) await this.gateway.configManager.rebuildChannels(config, { start: true });
84
+ };
85
+ startGateways = async () => {
86
+ const config = this.gateway.configManager.loadConfig();
87
+ const diagnostics = [];
88
+ const handles = [];
89
+ const configView = toPluginConfigView(config, this.snapshot.channelBindings);
90
+ for (const binding of this.snapshot.channelBindings) {
91
+ if (!this.isChannelEnabled(binding.channelId, configView)) continue;
92
+ await this.startChannelGateways({
93
+ binding,
94
+ configView,
95
+ diagnostics,
96
+ handles
97
+ });
98
+ }
99
+ this.gatewayHandles = handles;
100
+ logPluginGatewayDiagnostics(diagnostics);
101
+ };
102
+ publishConfigChanges = () => {
103
+ this.gateway.appEventBus.emit(eventKeys.configUpdated, { path: "channels" }, {
104
+ emittedAt: (/* @__PURE__ */ new Date()).toISOString(),
105
+ source: "backend"
106
+ });
107
+ this.gateway.appEventBus.emit(eventKeys.configUpdated, { path: "plugins" }, {
108
+ emittedAt: (/* @__PURE__ */ new Date()).toISOString(),
109
+ source: "backend"
110
+ });
111
+ };
112
+ restartGateways = async () => {
113
+ await this.stopGateways();
114
+ await this.startGateways();
115
+ };
116
+ stopGateways = async () => {
117
+ for (const handle of this.gatewayHandles) try {
118
+ handle.abort?.();
119
+ await handle.stop?.();
120
+ } catch {}
121
+ this.gatewayHandles = [];
122
+ };
123
+ startChannelGateways = async (params) => {
124
+ const { binding, configView, diagnostics, handles } = params;
125
+ const gateway = binding.channel.gateway;
126
+ if (!gateway?.startAccount) return;
127
+ const accountIds = this.resolveGatewayAccountIds(binding, configView);
128
+ for (const accountId of accountIds) {
129
+ const abortController = new AbortController();
130
+ let stopGateway;
131
+ const startTask = Promise.resolve().then(async () => await gateway.startAccount?.({
132
+ accountId,
133
+ channelId: binding.channelId,
134
+ cfg: configView,
135
+ abortSignal: abortController.signal,
136
+ runtime: {
137
+ log: pluginGatewayLogger.info,
138
+ info: pluginGatewayLogger.info,
139
+ warn: pluginGatewayLogger.warn,
140
+ error: pluginGatewayLogger.error,
141
+ debug: pluginGatewayLogger.debug
142
+ },
143
+ setStatus: () => void 0,
144
+ log: pluginGatewayLogger
145
+ })).then((started) => {
146
+ if (started && typeof started === "object" && "stop" in started && typeof started.stop === "function") stopGateway = started.stop.bind(started);
147
+ }).catch((error) => {
148
+ if (abortController.signal.aborted) return;
149
+ this.reportGatewayStartFailure({
150
+ accountId,
151
+ binding,
152
+ diagnostics,
153
+ error
154
+ });
155
+ });
156
+ handles.push({
157
+ pluginId: binding.pluginId,
158
+ channelId: binding.channelId,
159
+ accountId,
160
+ abort: () => abortController.abort(),
161
+ stop: async () => {
162
+ abortController.abort();
163
+ await startTask;
164
+ await stopGateway?.();
165
+ }
166
+ });
167
+ }
168
+ };
169
+ resolveGatewayAccountIds = (binding, configView) => {
170
+ const accountIdsRaw = binding.channel.config?.listAccountIds?.(configView) ?? [binding.channel.config?.defaultAccountId?.(configView) ?? "default"];
171
+ const accountIds = Array.from(new Set(accountIdsRaw.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean)));
172
+ return accountIds.length > 0 ? accountIds : ["default"];
173
+ };
174
+ reportGatewayStartFailure = (params) => {
175
+ const { accountId, binding, diagnostics, error } = params;
176
+ const raw = String(error);
177
+ const lower = raw.toLowerCase();
178
+ const level = lower.includes("required") || lower.includes("not configured") || lower.includes("missing") ? "warn" : "error";
179
+ const message = `failed to start channel gateway for ${binding.channelId}/${accountId}: ${raw}`;
180
+ diagnostics.push({
181
+ level,
182
+ pluginId: binding.pluginId,
183
+ message
184
+ });
185
+ if (level === "error") {
186
+ pluginGatewayLogger.error(message);
187
+ return;
188
+ }
189
+ pluginGatewayLogger.warn(message);
190
+ };
191
+ isChannelEnabled = (channelId, configView) => {
192
+ const channelConfig = (configView.channels && typeof configView.channels === "object" && !Array.isArray(configView.channels) ? configView.channels : {})[channelId];
193
+ if (!channelConfig || typeof channelConfig !== "object" || Array.isArray(channelConfig)) return false;
194
+ return channelConfig.enabled === true;
195
+ };
196
+ replaceSnapshot = (registry, changedPaths) => {
197
+ const nextSnapshot = buildSnapshot(registry, this.extensionContributions);
198
+ const shouldRestartChannels = shouldRestartChannelsForPluginReload({
199
+ changedPaths,
200
+ currentPluginChannelBindings: this.snapshot.channelBindings,
201
+ nextPluginChannelBindings: nextSnapshot.channelBindings,
202
+ currentExtensionChannels: this.snapshot.extensionRegistry.channels,
203
+ nextExtensionChannels: nextSnapshot.extensionRegistry.channels
204
+ });
205
+ this.snapshot = nextSnapshot;
206
+ return shouldRestartChannels;
207
+ };
208
+ loadKernelExtensionContributions = (registry) => {
209
+ this.gateway.kernel.extensions.loadContributions({
210
+ registry,
211
+ extensionRegistry: this.snapshot.extensionRegistry,
212
+ channelBindings: this.snapshot.channelBindings,
213
+ uiMetadata: this.snapshot.uiMetadata
214
+ });
215
+ };
216
+ };
217
+ //#endregion
218
+ export { GatewayPluginManager };
@@ -0,0 +1,20 @@
1
+ import { createManagedRemoteModuleForUi } from "../../runtime/service-remote-runtime.service.js";
2
+ import { GatewayRuntimeDeps } from "../nextclaw-gateway-runtime.service.js";
3
+ import { Config } from "@nextclaw/core";
4
+ import { UiRemoteAccessHost } from "@nextclaw/server";
5
+ import { ConfigManager } from "@nextclaw/kernel";
6
+
7
+ //#region src/shared/services/gateway/managers/gateway-remote.manager.d.ts
8
+ type RemoteServiceModule = ReturnType<typeof createManagedRemoteModuleForUi>;
9
+ declare class GatewayRemoteManager {
10
+ readonly remoteModule: RemoteServiceModule;
11
+ readonly remoteAccess: UiRemoteAccessHost;
12
+ constructor(params: {
13
+ deps: GatewayRuntimeDeps;
14
+ configManager: ConfigManager;
15
+ uiConfig: Config["ui"];
16
+ });
17
+ stop: () => Promise<void>;
18
+ }
19
+ //#endregion
20
+ export { GatewayRemoteManager };
@@ -0,0 +1,25 @@
1
+ import { createRemoteAccessHost } from "../../ui/service-remote-access.service.js";
2
+ import { createManagedRemoteModuleForUi } from "../../runtime/service-remote-runtime.service.js";
3
+ //#region src/shared/services/gateway/managers/gateway-remote.manager.ts
4
+ var GatewayRemoteManager = class {
5
+ remoteModule;
6
+ remoteAccess;
7
+ constructor(params) {
8
+ const { configManager, deps, uiConfig } = params;
9
+ this.remoteModule = createManagedRemoteModuleForUi({
10
+ loadConfig: configManager.loadConfig,
11
+ uiConfig
12
+ });
13
+ this.remoteAccess = createRemoteAccessHost({
14
+ serviceCommands: deps,
15
+ requestRestart: deps.requestRestart,
16
+ uiConfig,
17
+ remoteModule: this.remoteModule
18
+ });
19
+ }
20
+ stop = async () => {
21
+ await this.remoteModule?.stop();
22
+ };
23
+ };
24
+ //#endregion
25
+ export { GatewayRemoteManager };
@@ -0,0 +1,22 @@
1
+ import { DeferredUiNcpAgentController } from "../session/service-deferred-ncp-agent.service.js";
2
+ import { NextclawGatewayRuntime } from "./nextclaw-gateway-runtime.service.js";
3
+ import { NextclawKernel } from "@nextclaw/kernel";
4
+
5
+ //#region src/shared/services/gateway/nextclaw-app.service.d.ts
6
+ type UiStartupHandle = {
7
+ deferredNcpAgent: DeferredUiNcpAgentController;
8
+ endpoint: string;
9
+ };
10
+ type NextclawAppKernel = Pick<NextclawKernel, "agentRuntimeManager" | "start">;
11
+ declare class NextclawApp {
12
+ private readonly gateway;
13
+ private readonly kernel;
14
+ private kernelReady;
15
+ constructor(gateway: NextclawGatewayRuntime, kernel?: NextclawAppKernel);
16
+ start: () => Promise<void>;
17
+ bootstrapKernel: () => Promise<void>;
18
+ warmDerivedCapabilities: () => Promise<void>;
19
+ private readonly handleKernelStartupError;
20
+ }
21
+ //#endregion
22
+ export { NextclawApp, UiStartupHandle };
@@ -0,0 +1,53 @@
1
+ import { logStartupTrace, measureStartupAsync } from "../../utils/startup-trace.js";
2
+ //#region src/shared/services/gateway/nextclaw-app.service.ts
3
+ var NextclawApp = class {
4
+ kernel;
5
+ kernelReady = false;
6
+ constructor(gateway, kernel) {
7
+ this.gateway = gateway;
8
+ this.kernel = kernel ?? gateway.kernel;
9
+ }
10
+ start = async () => {
11
+ logStartupTrace("service.deferred_startup.begin");
12
+ try {
13
+ await this.bootstrapKernel();
14
+ } catch (error) {
15
+ this.handleKernelStartupError(error);
16
+ }
17
+ await this.warmDerivedCapabilities();
18
+ console.log("✓ Deferred startup: plugin gateways and channels settled");
19
+ logStartupTrace("service.deferred_startup.end");
20
+ };
21
+ bootstrapKernel = async () => {
22
+ this.gateway.bootstrapStatus.markNcpAgentRunning();
23
+ await measureStartupAsync("service.deferred_startup.bootstrap_kernel", async () => await this.kernel.start());
24
+ const ncpAgent = this.kernel.agentRuntimeManager.currentHandle;
25
+ if (!ncpAgent) throw new Error("Kernel start completed without an agent runtime handle.");
26
+ this.gateway.activateAgentRuntime(ncpAgent);
27
+ this.kernelReady = true;
28
+ if (this.gateway.uiConfig.enabled) {
29
+ console.log("✓ UI NCP agent: ready");
30
+ return;
31
+ }
32
+ console.log("✓ Service NCP agent: ready");
33
+ };
34
+ warmDerivedCapabilities = async () => {
35
+ await measureStartupAsync("service.deferred_startup.load_plugins", this.gateway.plugins.load);
36
+ await measureStartupAsync("service.deferred_startup.start_plugin_gateways", this.gateway.plugins.startGateways);
37
+ await measureStartupAsync("service.deferred_startup.start_extensions", this.gateway.extensions.start);
38
+ await measureStartupAsync("service.deferred_startup.start_channels", this.gateway.startDeferredChannels);
39
+ await measureStartupAsync("service.deferred_startup.wake_restart_sentinel", this.gateway.restartWake.wakeFromRestartSentinel);
40
+ if (!this.kernelReady) return;
41
+ setTimeout(() => {
42
+ measureStartupAsync("service.deferred_startup.warm_ncp_capabilities", async () => await this.kernel.agentRuntimeManager.warmDerivedCapabilities()).catch((error) => {
43
+ console.warn(`UI NCP derived capability warmup failed: ${error instanceof Error ? error.message : String(error)}`);
44
+ });
45
+ }, 0).unref?.();
46
+ };
47
+ handleKernelStartupError = (error) => {
48
+ this.gateway.bootstrapStatus.markNcpAgentError(error instanceof Error ? error.message : String(error));
49
+ console.error(`UI NCP agent startup failed: ${error instanceof Error ? error.message : String(error)}`);
50
+ };
51
+ };
52
+ //#endregion
53
+ export { NextclawApp };
@@ -0,0 +1,89 @@
1
+ import { RequestRestartParams } from "../../types/cli.types.js";
2
+ import { GatewayControllerImpl } from "../../controllers/gateway.controller.js";
3
+ import { GatewayPluginManager } from "./managers/gateway-plugin.manager.js";
4
+ import { GatewayRemoteManager } from "./managers/gateway-remote.manager.js";
5
+ import { GatewayRestartWakeService } from "./gateway-restart-wake.service.js";
6
+ import { UiStartupHandle } from "./nextclaw-app.service.js";
7
+ import { ServiceBootstrapStatusStore } from "./service-bootstrap-status.js";
8
+ import { ServiceFileWatcherRegistry } from "./service-startup-support.service.js";
9
+ import { ServiceExtensionRuntime } from "../extensions/service-extension-runtime.service.js";
10
+ import * as NextclawCore from "@nextclaw/core";
11
+ import { MarketplaceApiConfig, UiNcpAgent, UiRuntimeControlHost, UiRuntimeUpdateHost } from "@nextclaw/server";
12
+ import { EventBus, Ingress } from "@nextclaw/shared";
13
+ import { AgentRuntimeHandle, AutomationManager, ConfigManager, LlmProviderManager, NextclawKernel } from "@nextclaw/kernel";
14
+
15
+ //#region src/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts
16
+ type Config$1 = NextclawCore.Config;
17
+ type MessageBus$1 = NextclawCore.MessageBus;
18
+ type SessionManager$1 = NextclawCore.SessionManager;
19
+ type GatewayRuntimeOptions = {
20
+ uiOverrides?: Partial<Config$1["ui"]>;
21
+ uiStaticDir?: string | null;
22
+ };
23
+ type GatewayRuntimeDeps = {
24
+ requestRestart: (params: RequestRestartParams) => Promise<void>;
25
+ initializeAgentHomeDirectory: (homeDirectory: string) => void;
26
+ startService: (options: {
27
+ uiOverrides: Record<string, unknown>;
28
+ open: boolean;
29
+ }) => Promise<void>;
30
+ stopService: () => Promise<void>;
31
+ runCliSubcommand: (args: string[]) => Promise<string>;
32
+ installBuiltinMarketplaceSkill: (slug: string, force: boolean | undefined) => {
33
+ message: string;
34
+ output?: string;
35
+ } | null;
36
+ };
37
+ declare class NextclawGatewayRuntime {
38
+ private readonly deps;
39
+ private readonly options;
40
+ readonly kernel: NextclawKernel;
41
+ readonly appEventBus: EventBus;
42
+ readonly messageBus: MessageBus$1;
43
+ readonly sessionManager: SessionManager$1;
44
+ readonly automation: AutomationManager;
45
+ readonly runtimeControl: UiRuntimeControlHost;
46
+ readonly runtimeUpdate: UiRuntimeUpdateHost | null;
47
+ readonly ingress: Ingress;
48
+ readonly productVersion: string;
49
+ readonly providerManager: LlmProviderManager;
50
+ readonly gatewayController: GatewayControllerImpl;
51
+ readonly configManager: ConfigManager;
52
+ readonly uiConfig: Config$1["ui"];
53
+ readonly uiStaticDir: string | null;
54
+ readonly workspace: string;
55
+ readonly remoteManager: GatewayRemoteManager;
56
+ readonly marketplace: MarketplaceApiConfig;
57
+ readonly plugins: GatewayPluginManager;
58
+ readonly restartWake: GatewayRestartWakeService;
59
+ bootstrapStatus: ServiceBootstrapStatusStore;
60
+ uiStartup: UiStartupHandle;
61
+ readonly extensions: ServiceExtensionRuntime;
62
+ liveAgentRuntime: AgentRuntimeHandle | null;
63
+ readonly fileWatchers: ServiceFileWatcherRegistry;
64
+ private deferredChannelStarter;
65
+ constructor(deps: GatewayRuntimeDeps, options?: GatewayRuntimeOptions);
66
+ start: () => Promise<void>;
67
+ private reset;
68
+ get ncpAgent(): UiNcpAgent;
69
+ activateAgentRuntime: (ncpAgent: AgentRuntimeHandle) => void;
70
+ private createBootstrapStatus;
71
+ private createDisabledUiStartup;
72
+ private startUiRuntime;
73
+ private createUiRouterOptions;
74
+ private runRuntimeLoop;
75
+ private startDeferredRuntime;
76
+ readonly startDeferredChannels: () => Promise<void>;
77
+ private installChannelDevHotReload;
78
+ private readonly startChannels;
79
+ private createMarketplace;
80
+ private cleanup;
81
+ private markUiRuntimeReady;
82
+ private createGatewayController;
83
+ private startSupportServices;
84
+ private configurePluginRuntime;
85
+ private installConfigRuntimeHooks;
86
+ private configureIngressHandlers;
87
+ }
88
+ //#endregion
89
+ export { GatewayRuntimeDeps, NextclawGatewayRuntime };