@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.
- package/LICENSE +21 -0
- package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
- package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
- package/dist/cli/commands/agent/index.d.ts +3 -0
- package/dist/cli/commands/agent/index.js +3 -0
- package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
- package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
- package/dist/cli/commands/companion/index.d.ts +15 -0
- package/dist/cli/commands/companion/index.js +24 -0
- package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
- package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
- package/dist/cli/commands/config/index.d.ts +2 -0
- package/dist/cli/commands/config/index.js +2 -0
- package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
- package/dist/cli/commands/config/services/config-commands.service.js +133 -0
- package/dist/cli/commands/cron/index.d.ts +2 -0
- package/dist/cli/commands/cron/index.js +2 -0
- package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
- package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
- package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
- package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
- package/dist/cli/commands/diagnostics/index.d.ts +2 -0
- package/dist/cli/commands/diagnostics/index.js +2 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
- package/dist/cli/commands/gateway/index.d.ts +14 -0
- package/dist/cli/commands/gateway/index.js +15 -0
- package/dist/cli/commands/logs/index.d.ts +12 -0
- package/dist/cli/commands/logs/index.js +29 -0
- package/dist/cli/commands/mcp/index.d.ts +14 -0
- package/dist/cli/commands/mcp/index.js +193 -0
- package/dist/cli/commands/restart/index.d.ts +20 -0
- package/dist/cli/commands/restart/index.js +88 -0
- package/dist/cli/commands/secrets/index.d.ts +22 -0
- package/dist/cli/commands/secrets/index.js +280 -0
- package/dist/cli/commands/serve/index.d.ts +14 -0
- package/dist/cli/commands/serve/index.js +19 -0
- package/dist/cli/commands/skills/index.d.ts +26 -0
- package/dist/cli/commands/skills/index.js +147 -0
- package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
- package/dist/cli/commands/skills/marketplace-client.js +84 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
- package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
- package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
- package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
- package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
- package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
- package/dist/cli/commands/skills/marketplace.service.js +238 -0
- package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
- package/dist/cli/commands/skills/skills-query.service.js +212 -0
- package/dist/cli/commands/start/index.d.ts +18 -0
- package/dist/cli/commands/start/index.js +25 -0
- package/dist/cli/commands/stop/index.d.ts +12 -0
- package/dist/cli/commands/stop/index.js +11 -0
- package/dist/cli/commands/ui/index.d.ts +14 -0
- package/dist/cli/commands/ui/index.js +17 -0
- package/dist/cli/commands/usage/index.d.ts +2 -0
- package/dist/cli/commands/usage/index.js +2 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
- package/dist/commands/channel/channel-config-view.d.ts +7 -0
- package/dist/commands/channel/channel-config-view.js +7 -0
- package/dist/commands/channel/index.d.ts +28 -0
- package/dist/commands/channel/index.js +224 -0
- package/dist/commands/platform-auth/index.d.ts +2 -0
- package/dist/commands/platform-auth/index.js +2 -0
- package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
- package/dist/commands/platform-auth/services/account-status.service.js +34 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
- package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
- package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
- package/dist/commands/plugin/index.d.ts +30 -0
- package/dist/commands/plugin/index.js +266 -0
- package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
- package/dist/commands/plugin/plugin-command-utils.js +37 -0
- package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
- package/dist/commands/plugin/plugin-extension-registry.js +35 -0
- package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
- package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
- package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
- package/dist/commands/plugin/plugin-registry-loader.js +43 -0
- package/dist/commands/plugin/plugin-reload.d.ts +13 -0
- package/dist/commands/plugin/plugin-reload.js +42 -0
- package/dist/commands/remote/index.d.ts +47 -0
- package/dist/commands/remote/index.js +174 -0
- package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
- package/dist/commands/remote/services/remote-access-host.service.js +126 -0
- package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
- package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
- package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
- package/dist/commands/remote/services/remote-service-control.service.js +188 -0
- package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
- package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
- package/dist/commands/service/index.d.ts +16 -0
- package/dist/commands/service/index.js +31 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
- package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
- package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
- package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
- package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
- package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
- package/dist/launcher/npm-runtime-bundle.service.js +150 -0
- package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
- package/dist/launcher/npm-runtime-bundle.types.js +1 -0
- package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-launcher.service.js +57 -0
- package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
- package/dist/launcher/npm-runtime-update-command.service.js +87 -0
- package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-update-source.service.js +57 -0
- package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
- package/dist/launcher/npm-runtime-update-state.store.js +92 -0
- package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
- package/dist/launcher/npm-runtime-update.manager.js +179 -0
- package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
- package/dist/launcher/npm-runtime-update.service.js +183 -0
- package/dist/service-runtime.service.d.ts +91 -0
- package/dist/service-runtime.service.js +392 -0
- package/dist/shared/controllers/gateway.controller.d.ts +61 -0
- package/dist/shared/controllers/gateway.controller.js +318 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
- package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
- package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
- package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
- package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
- package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
- package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
- package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
- package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
- package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
- package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
- package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
- package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
- package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
- package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
- package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
- package/dist/shared/services/runtime/runtime-command.service.js +163 -0
- package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
- package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
- package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
- package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
- package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
- package/dist/shared/services/ui/companion-runtime.service.js +145 -0
- package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
- package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
- package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
- package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
- package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
- package/dist/shared/services/ui/service-remote-access.service.js +38 -0
- package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
- package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
- package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
- package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
- package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
- package/dist/shared/stores/companion-runtime.store.js +27 -0
- package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
- package/dist/shared/stores/local-ui-runtime.store.js +54 -0
- package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
- package/dist/shared/stores/managed-service-state.store.js +38 -0
- package/dist/shared/stores/pending-restart.store.d.ts +21 -0
- package/dist/shared/stores/pending-restart.store.js +35 -0
- package/dist/shared/types/cli.types.d.ts +295 -0
- package/dist/shared/types/cli.types.js +1 -0
- package/dist/shared/utils/cli.utils.d.ts +34 -0
- package/dist/shared/utils/cli.utils.js +262 -0
- package/dist/shared/utils/config-path.d.ts +15 -0
- package/dist/shared/utils/config-path.js +167 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
- package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
- package/dist/shared/utils/package/package-manifest.utils.js +48 -0
- package/dist/shared/utils/runtime-helpers.d.ts +14 -0
- package/dist/shared/utils/runtime-helpers.js +26 -0
- package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
- package/dist/shared/utils/service-port-probe.utils.js +164 -0
- package/dist/shared/utils/startup-trace.d.ts +7 -0
- package/dist/shared/utils/startup-trace.js +37 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
- package/package.json +68 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { getPackageVersion as getPackageVersion$1 } from "../../utils/package/package-manifest.utils.js";
|
|
2
|
+
import { openBrowser, resolveUiConfig, resolveUiStaticDir } from "../../utils/cli.utils.js";
|
|
3
|
+
import { localUiRuntimeStore } from "../../stores/local-ui-runtime.store.js";
|
|
4
|
+
import { managedServiceStateStore } from "../../stores/managed-service-state.store.js";
|
|
5
|
+
import { logStartupTrace, measureStartupAsync, measureStartupSync } from "../../utils/startup-trace.js";
|
|
6
|
+
import { GatewayControllerImpl } from "../../controllers/gateway.controller.js";
|
|
7
|
+
import { companionRuntimeService } from "../ui/companion-runtime.service.js";
|
|
8
|
+
import { createRuntimeControlHost } from "../ui/runtime-control-host.service.js";
|
|
9
|
+
import { NpmRuntimeUpdateHost } from "../ui/npm-runtime-update-host.service.js";
|
|
10
|
+
import { ServiceMarketplaceInstaller } from "../marketplace/service-marketplace-installer.service.js";
|
|
11
|
+
import { resolveChannelConfigView } from "../../../commands/channel/channel-config-view.js";
|
|
12
|
+
import { ServiceExtensionRuntime } from "../extensions/service-extension-runtime.service.js";
|
|
13
|
+
import { ServiceFileWatcherRegistry, markLocalUiRuntimeIfStarted, startGatewayRuntimeSupport, watchServiceConfigFile } from "./service-startup-support.service.js";
|
|
14
|
+
import { GatewayPluginManager } from "./managers/gateway-plugin.manager.js";
|
|
15
|
+
import { GatewayRemoteManager } from "./managers/gateway-remote.manager.js";
|
|
16
|
+
import { GatewayRestartWakeService } from "./gateway-restart-wake.service.js";
|
|
17
|
+
import { createCronJobHandler } from "./cron-job-handler.service.js";
|
|
18
|
+
import { handleGatewayDeferredStartupError } from "./utils/gateway-runtime-lifecycle.utils.js";
|
|
19
|
+
import { NextclawApp } from "./nextclaw-app.service.js";
|
|
20
|
+
import { ServiceBootstrapStatusStore } from "./service-bootstrap-status.js";
|
|
21
|
+
import { createDeferredUiNcpAgent } from "../session/service-deferred-ncp-agent.service.js";
|
|
22
|
+
import { installPluginRuntimeBridge } from "../plugin/utils/plugin-runtime-bridge.utils.js";
|
|
23
|
+
import { wrapStartChannelsWithDevPluginHotReload } from "../plugin/utils/plugin-dev-hot-reload.utils.js";
|
|
24
|
+
import { resolve } from "node:path";
|
|
25
|
+
import * as NextclawCore from "@nextclaw/core";
|
|
26
|
+
import { startUiServer } from "@nextclaw/server";
|
|
27
|
+
import { setPluginRuntimeBridge } from "@nextclaw/openclaw-compat";
|
|
28
|
+
import { NextclawKernel, runGatewayInboundLoop } from "@nextclaw/kernel";
|
|
29
|
+
import { setImmediate } from "node:timers/promises";
|
|
30
|
+
//#region src/shared/services/gateway/nextclaw-gateway-runtime.service.ts
|
|
31
|
+
const { getConfigPath: getConfigPath$1, getDataDir: getDataDir$1, getWorkspacePath: getWorkspacePath$1, saveConfig: saveConfig$1 } = NextclawCore;
|
|
32
|
+
const DEV_PLUGIN_HOT_RELOAD_STARTUP_SETTLE_MS = 5e3;
|
|
33
|
+
function resolveApplyRestartMode(uiPort) {
|
|
34
|
+
const serviceState = managedServiceStateStore.read();
|
|
35
|
+
if (serviceState?.pid === process.pid) return "managed-service-restart";
|
|
36
|
+
if (process.env.NEXTCLAW_RUNTIME_BUNDLE_CHILD === "1" && typeof serviceState?.uiPort === "number" && serviceState.uiPort === uiPort) return "managed-service-restart";
|
|
37
|
+
return "manual-process-restart";
|
|
38
|
+
}
|
|
39
|
+
var NextclawGatewayRuntime = class {
|
|
40
|
+
kernel;
|
|
41
|
+
appEventBus;
|
|
42
|
+
messageBus;
|
|
43
|
+
sessionManager;
|
|
44
|
+
automation;
|
|
45
|
+
runtimeControl;
|
|
46
|
+
runtimeUpdate;
|
|
47
|
+
ingress;
|
|
48
|
+
productVersion;
|
|
49
|
+
providerManager;
|
|
50
|
+
gatewayController;
|
|
51
|
+
configManager;
|
|
52
|
+
uiConfig;
|
|
53
|
+
uiStaticDir;
|
|
54
|
+
workspace;
|
|
55
|
+
remoteManager;
|
|
56
|
+
marketplace;
|
|
57
|
+
plugins;
|
|
58
|
+
restartWake;
|
|
59
|
+
bootstrapStatus;
|
|
60
|
+
uiStartup;
|
|
61
|
+
extensions;
|
|
62
|
+
liveAgentRuntime = null;
|
|
63
|
+
fileWatchers = new ServiceFileWatcherRegistry();
|
|
64
|
+
deferredChannelStarter;
|
|
65
|
+
constructor(deps, options = {}) {
|
|
66
|
+
this.deps = deps;
|
|
67
|
+
this.options = options;
|
|
68
|
+
const configPath = getConfigPath$1();
|
|
69
|
+
this.kernel = measureStartupSync("service.gateway.kernel", () => new NextclawKernel({
|
|
70
|
+
homeDir: getDataDir$1(),
|
|
71
|
+
configPath
|
|
72
|
+
}));
|
|
73
|
+
this.configManager = this.kernel.configManager;
|
|
74
|
+
const config = this.configManager.config;
|
|
75
|
+
this.uiConfig = resolveUiConfig(config, options.uiOverrides);
|
|
76
|
+
this.uiStaticDir = options.uiStaticDir === void 0 ? resolveUiStaticDir() : options.uiStaticDir;
|
|
77
|
+
this.workspace = getWorkspacePath$1(config.agents.defaults.workspace);
|
|
78
|
+
this.appEventBus = this.kernel.eventBus;
|
|
79
|
+
this.ingress = this.kernel.ingress;
|
|
80
|
+
this.messageBus = this.kernel.messageBus;
|
|
81
|
+
this.sessionManager = this.kernel.sessions;
|
|
82
|
+
this.automation = this.kernel.automation;
|
|
83
|
+
this.productVersion = getPackageVersion$1();
|
|
84
|
+
this.plugins = new GatewayPluginManager(this);
|
|
85
|
+
this.providerManager = this.kernel.llmProviders;
|
|
86
|
+
this.installConfigRuntimeHooks();
|
|
87
|
+
this.restartWake = new GatewayRestartWakeService(this);
|
|
88
|
+
this.bootstrapStatus = this.createBootstrapStatus();
|
|
89
|
+
this.uiStartup = this.createDisabledUiStartup();
|
|
90
|
+
this.extensions = new ServiceExtensionRuntime(this);
|
|
91
|
+
this.remoteManager = new GatewayRemoteManager({
|
|
92
|
+
deps: this.deps,
|
|
93
|
+
configManager: this.configManager,
|
|
94
|
+
uiConfig: this.uiConfig
|
|
95
|
+
});
|
|
96
|
+
this.marketplace = this.createMarketplace();
|
|
97
|
+
this.runtimeControl = createRuntimeControlHost({
|
|
98
|
+
serviceCommands: this.deps,
|
|
99
|
+
requestRestart: this.deps.requestRestart,
|
|
100
|
+
uiConfig: this.uiConfig
|
|
101
|
+
});
|
|
102
|
+
this.runtimeUpdate = process.env.NEXTCLAW_DISABLE_RUNTIME_UPDATE_HOST === "1" ? null : new NpmRuntimeUpdateHost({
|
|
103
|
+
eventBus: this.appEventBus,
|
|
104
|
+
applyRestartMode: resolveApplyRestartMode(this.uiConfig.port),
|
|
105
|
+
requestRestart: this.deps.requestRestart,
|
|
106
|
+
uiConfig: this.uiConfig
|
|
107
|
+
});
|
|
108
|
+
this.gatewayController = this.createGatewayController();
|
|
109
|
+
this.kernel.agentRuntimeManager.connectGatewayController(this.gatewayController);
|
|
110
|
+
this.deferredChannelStarter = this.startChannels;
|
|
111
|
+
this.automation.onJob = createCronJobHandler({
|
|
112
|
+
resolveNcpAgent: () => this.liveAgentRuntime,
|
|
113
|
+
bus: this.messageBus
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
start = async () => {
|
|
117
|
+
logStartupTrace("service.start_gateway.begin");
|
|
118
|
+
await this.reset();
|
|
119
|
+
this.configureIngressHandlers();
|
|
120
|
+
this.uiStartup = await this.startUiRuntime();
|
|
121
|
+
await companionRuntimeService.applyConfig(this.configManager.config);
|
|
122
|
+
await this.markUiRuntimeReady();
|
|
123
|
+
await this.startSupportServices();
|
|
124
|
+
this.installChannelDevHotReload();
|
|
125
|
+
await this.runRuntimeLoop();
|
|
126
|
+
await companionRuntimeService.ensureStopped();
|
|
127
|
+
logStartupTrace("service.start_gateway.end");
|
|
128
|
+
};
|
|
129
|
+
reset = async () => {
|
|
130
|
+
await this.fileWatchers.clear();
|
|
131
|
+
this.bootstrapStatus = this.createBootstrapStatus();
|
|
132
|
+
this.uiStartup = this.createDisabledUiStartup();
|
|
133
|
+
this.deferredChannelStarter = this.startChannels;
|
|
134
|
+
this.liveAgentRuntime = null;
|
|
135
|
+
};
|
|
136
|
+
get ncpAgent() {
|
|
137
|
+
return this.uiStartup.deferredNcpAgent.agent;
|
|
138
|
+
}
|
|
139
|
+
activateAgentRuntime = (ncpAgent) => {
|
|
140
|
+
this.liveAgentRuntime = ncpAgent;
|
|
141
|
+
if (this.uiConfig.enabled) this.uiStartup.deferredNcpAgent.activate(ncpAgent);
|
|
142
|
+
this.bootstrapStatus.markNcpAgentReady();
|
|
143
|
+
};
|
|
144
|
+
createBootstrapStatus = () => {
|
|
145
|
+
const bootstrapStatus = new ServiceBootstrapStatusStore();
|
|
146
|
+
bootstrapStatus.markNcpAgentPending();
|
|
147
|
+
bootstrapStatus.markPluginHydrationPending();
|
|
148
|
+
bootstrapStatus.markChannelsPending();
|
|
149
|
+
bootstrapStatus.setRemoteState(this.configManager.config.remote.enabled ? "pending" : "disabled");
|
|
150
|
+
return bootstrapStatus;
|
|
151
|
+
};
|
|
152
|
+
createDisabledUiStartup = () => ({
|
|
153
|
+
deferredNcpAgent: createDeferredUiNcpAgent(),
|
|
154
|
+
endpoint: ""
|
|
155
|
+
});
|
|
156
|
+
startUiRuntime = async () => {
|
|
157
|
+
const uiStartup = await measureStartupAsync("service.start_ui_runtime", async () => {
|
|
158
|
+
logStartupTrace("service.start_ui_runtime.begin");
|
|
159
|
+
if (!this.uiConfig.enabled) return this.createDisabledUiStartup();
|
|
160
|
+
const deferredNcpAgent = this.uiStartup.deferredNcpAgent;
|
|
161
|
+
const uiServer = await startUiServer(this.createUiRouterOptions());
|
|
162
|
+
const uiUrl = NextclawCore.resolveLocalUiBaseUrl({
|
|
163
|
+
host: uiServer.host,
|
|
164
|
+
port: uiServer.port
|
|
165
|
+
});
|
|
166
|
+
console.log(`✓ UI API: ${uiUrl}/api`);
|
|
167
|
+
if (this.uiStaticDir) console.log(`✓ UI frontend: ${uiUrl}`);
|
|
168
|
+
if (this.uiConfig.open) openBrowser(uiUrl);
|
|
169
|
+
logStartupTrace("service.start_ui_runtime.ready", {
|
|
170
|
+
host: uiServer.host,
|
|
171
|
+
port: uiServer.port
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
deferredNcpAgent,
|
|
175
|
+
endpoint: uiUrl
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
markLocalUiRuntimeIfStarted({
|
|
179
|
+
uiStartup: this.uiConfig.enabled ? uiStartup : null,
|
|
180
|
+
uiConfig: this.uiConfig
|
|
181
|
+
});
|
|
182
|
+
return uiStartup;
|
|
183
|
+
};
|
|
184
|
+
createUiRouterOptions = () => ({
|
|
185
|
+
configPath: this.configManager.configPath,
|
|
186
|
+
appEventBus: this.appEventBus,
|
|
187
|
+
ingress: this.ingress,
|
|
188
|
+
uiConfig: this.uiConfig,
|
|
189
|
+
uiStaticDir: this.uiStaticDir,
|
|
190
|
+
productVersion: this.productVersion,
|
|
191
|
+
applyLiveConfigReload: this.configManager.applyLiveConfigReload,
|
|
192
|
+
initializeAgentHomeDirectory: this.deps.initializeAgentHomeDirectory,
|
|
193
|
+
marketplace: this.marketplace,
|
|
194
|
+
cron: this.automation,
|
|
195
|
+
ncpAgent: this.ncpAgent,
|
|
196
|
+
sessions: this.kernel.ncpSessionApi,
|
|
197
|
+
remoteAccess: this.remoteManager.remoteAccess,
|
|
198
|
+
runtimeControl: this.runtimeControl,
|
|
199
|
+
...this.runtimeUpdate ? { runtimeUpdate: this.runtimeUpdate } : {},
|
|
200
|
+
bootstrapStatus: this.bootstrapStatus,
|
|
201
|
+
plugins: this.plugins,
|
|
202
|
+
providers: this.providerManager
|
|
203
|
+
});
|
|
204
|
+
runRuntimeLoop = async () => {
|
|
205
|
+
logStartupTrace("service.start_gateway.runtime_loop_begin");
|
|
206
|
+
let startupTask = null;
|
|
207
|
+
try {
|
|
208
|
+
const runtimeLoopTask = runGatewayInboundLoop(this);
|
|
209
|
+
startupTask = this.startDeferredRuntime();
|
|
210
|
+
startupTask.catch((error) => handleGatewayDeferredStartupError({
|
|
211
|
+
bootstrapStatus: this.bootstrapStatus,
|
|
212
|
+
error
|
|
213
|
+
}));
|
|
214
|
+
await runtimeLoopTask;
|
|
215
|
+
} finally {
|
|
216
|
+
if (startupTask) await startupTask.catch(() => void 0);
|
|
217
|
+
await this.cleanup();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
startDeferredRuntime = async () => {
|
|
221
|
+
await new NextclawApp(this).start();
|
|
222
|
+
};
|
|
223
|
+
startDeferredChannels = async () => {
|
|
224
|
+
await this.deferredChannelStarter();
|
|
225
|
+
};
|
|
226
|
+
installChannelDevHotReload = () => {
|
|
227
|
+
this.deferredChannelStarter = wrapStartChannelsWithDevPluginHotReload({
|
|
228
|
+
startChannels: this.startChannels,
|
|
229
|
+
watcherRegistry: this.fileWatchers,
|
|
230
|
+
isRuntimeActive: () => true,
|
|
231
|
+
reloadPlugins: async (pluginIds) => {
|
|
232
|
+
await this.plugins.reloadForDevHotReload(pluginIds.map((pluginId) => `plugins.entries.${pluginId}.source`));
|
|
233
|
+
},
|
|
234
|
+
startupSettleMs: DEV_PLUGIN_HOT_RELOAD_STARTUP_SETTLE_MS
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
startChannels = async () => {
|
|
238
|
+
await this.kernel.channels.start();
|
|
239
|
+
const enabledChannels = this.kernel.channels.enabledChannels;
|
|
240
|
+
if (enabledChannels.length > 0) console.log(`✓ Channels enabled: ${enabledChannels.join(", ")}`);
|
|
241
|
+
else console.log("Warning: No channels enabled");
|
|
242
|
+
this.bootstrapStatus.markChannelsReady(enabledChannels);
|
|
243
|
+
this.bootstrapStatus.markReady();
|
|
244
|
+
};
|
|
245
|
+
createMarketplace = () => ({
|
|
246
|
+
apiBaseUrl: process.env.NEXTCLAW_MARKETPLACE_API_BASE,
|
|
247
|
+
installer: new ServiceMarketplaceInstaller({
|
|
248
|
+
applyLiveConfigReload: this.configManager.applyLiveConfigReload,
|
|
249
|
+
runCliSubcommand: this.deps.runCliSubcommand,
|
|
250
|
+
installBuiltinSkill: this.deps.installBuiltinMarketplaceSkill
|
|
251
|
+
}).createInstaller()
|
|
252
|
+
});
|
|
253
|
+
cleanup = async () => {
|
|
254
|
+
localUiRuntimeStore.clearIfOwnedByProcess();
|
|
255
|
+
await this.fileWatchers.clear();
|
|
256
|
+
this.liveAgentRuntime = null;
|
|
257
|
+
await this.uiStartup.deferredNcpAgent.close();
|
|
258
|
+
await this.extensions.stop();
|
|
259
|
+
await this.remoteManager.stop();
|
|
260
|
+
await this.plugins.stopGateways();
|
|
261
|
+
setPluginRuntimeBridge(null);
|
|
262
|
+
};
|
|
263
|
+
markUiRuntimeReady = async () => {
|
|
264
|
+
this.bootstrapStatus.markShellReady();
|
|
265
|
+
await setImmediate();
|
|
266
|
+
};
|
|
267
|
+
createGatewayController = () => {
|
|
268
|
+
return measureStartupSync("service.gateway.gateway_controller", () => new GatewayControllerImpl({
|
|
269
|
+
configManager: this.configManager,
|
|
270
|
+
channels: this.kernel.channels,
|
|
271
|
+
cron: this.automation,
|
|
272
|
+
sessionManager: this.sessionManager,
|
|
273
|
+
getConfigPath: getConfigPath$1,
|
|
274
|
+
saveConfig: saveConfig$1,
|
|
275
|
+
requestRestart: async (options) => {
|
|
276
|
+
await this.deps.requestRestart({
|
|
277
|
+
reason: options?.reason ?? "gateway tool restart",
|
|
278
|
+
manualMessage: "Restart the gateway to apply changes.",
|
|
279
|
+
strategy: "background-service-or-exit",
|
|
280
|
+
delayMs: options?.delayMs,
|
|
281
|
+
silentOnServiceRestart: true
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
285
|
+
};
|
|
286
|
+
startSupportServices = async () => {
|
|
287
|
+
this.plugins.publishConfigChanges();
|
|
288
|
+
this.configurePluginRuntime();
|
|
289
|
+
await measureStartupAsync("service.start_gateway_support_services", async () => await startGatewayRuntimeSupport({
|
|
290
|
+
automation: this.automation,
|
|
291
|
+
remoteModule: this.remoteManager.remoteModule,
|
|
292
|
+
watchConfigFile: () => watchServiceConfigFile({
|
|
293
|
+
configPath: resolve(getConfigPath$1()),
|
|
294
|
+
watcherRegistry: this.fileWatchers,
|
|
295
|
+
scheduleReload: (reason) => this.configManager.scheduleReload(reason)
|
|
296
|
+
}),
|
|
297
|
+
watcherRegistry: this.fileWatchers
|
|
298
|
+
}));
|
|
299
|
+
};
|
|
300
|
+
configurePluginRuntime = () => {
|
|
301
|
+
installPluginRuntimeBridge(this);
|
|
302
|
+
};
|
|
303
|
+
installConfigRuntimeHooks = () => {
|
|
304
|
+
this.configManager.installRuntimeHooks({
|
|
305
|
+
resolveChannelConfig: (nextConfig) => resolveChannelConfigView(nextConfig, this.kernel.extensions.getChannelBindings()),
|
|
306
|
+
getExtensionChannels: () => this.kernel.extensions.getExtensionRegistry().channels,
|
|
307
|
+
reloadCompanion: async ({ config: nextConfig }) => {
|
|
308
|
+
await companionRuntimeService.applyConfig(nextConfig);
|
|
309
|
+
},
|
|
310
|
+
reloadPlugins: async ({ config: nextConfig, changedPaths }) => {
|
|
311
|
+
const result = await this.plugins.reloadForConfigChange({
|
|
312
|
+
config: nextConfig,
|
|
313
|
+
changedPaths
|
|
314
|
+
});
|
|
315
|
+
if (result.restartChannels) console.log("Config reload: plugin channel gateways restarted.");
|
|
316
|
+
return { restartChannels: result.restartChannels };
|
|
317
|
+
},
|
|
318
|
+
reloadMcp: async ({ config: nextConfig }) => {
|
|
319
|
+
await this.liveAgentRuntime?.applyMcpConfig?.(nextConfig);
|
|
320
|
+
},
|
|
321
|
+
onRestartRequired: (paths) => {
|
|
322
|
+
this.deps.requestRestart({
|
|
323
|
+
changedPaths: paths,
|
|
324
|
+
manualMessage: `已保存以下改动,等待你手动重启后生效:${paths.join(", ")}`,
|
|
325
|
+
mode: "notify",
|
|
326
|
+
reason: `config reload requires restart: ${paths.join(", ")}`,
|
|
327
|
+
strategy: "background-service-or-manual"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
configureIngressHandlers = () => {
|
|
333
|
+
this.extensions.registerIngressHandlers(this.ingress);
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
export { NextclawGatewayRuntime };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BootstrapRemoteState, BootstrapStatusView } from "@nextclaw/server";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/services/gateway/service-bootstrap-status.d.ts
|
|
4
|
+
declare class ServiceBootstrapStatusStore {
|
|
5
|
+
private state;
|
|
6
|
+
getStatus(): BootstrapStatusView;
|
|
7
|
+
markShellReady(): void;
|
|
8
|
+
markNcpAgentPending(): void;
|
|
9
|
+
markNcpAgentRunning(): void;
|
|
10
|
+
markNcpAgentReady(): void;
|
|
11
|
+
markNcpAgentError(error: string): void;
|
|
12
|
+
markPluginHydrationPending(): void;
|
|
13
|
+
markPluginHydrationRunning(params: {
|
|
14
|
+
totalPluginCount: number;
|
|
15
|
+
}): void;
|
|
16
|
+
markPluginHydrationProgress(params: {
|
|
17
|
+
loadedPluginCount: number;
|
|
18
|
+
totalPluginCount?: number;
|
|
19
|
+
}): void;
|
|
20
|
+
markPluginHydrationReady(params: {
|
|
21
|
+
loadedPluginCount: number;
|
|
22
|
+
totalPluginCount: number;
|
|
23
|
+
}): void;
|
|
24
|
+
markPluginHydrationError(error: string): void;
|
|
25
|
+
markChannelsPending(): void;
|
|
26
|
+
markChannelsReady(enabled: string[]): void;
|
|
27
|
+
markChannelsError(error: string): void;
|
|
28
|
+
setRemoteState(state: BootstrapRemoteState, message?: string): void;
|
|
29
|
+
markReady(): void;
|
|
30
|
+
markError(error: string): void;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ServiceBootstrapStatusStore };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
//#region src/shared/services/gateway/service-bootstrap-status.ts
|
|
2
|
+
function now() {
|
|
3
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
4
|
+
}
|
|
5
|
+
var ServiceBootstrapStatusStore = class {
|
|
6
|
+
state = {
|
|
7
|
+
phase: "kernel-starting",
|
|
8
|
+
ncpAgent: { state: "pending" },
|
|
9
|
+
pluginHydration: {
|
|
10
|
+
state: "pending",
|
|
11
|
+
loadedPluginCount: 0,
|
|
12
|
+
totalPluginCount: 0
|
|
13
|
+
},
|
|
14
|
+
channels: {
|
|
15
|
+
state: "pending",
|
|
16
|
+
enabled: []
|
|
17
|
+
},
|
|
18
|
+
remote: { state: "pending" }
|
|
19
|
+
};
|
|
20
|
+
getStatus() {
|
|
21
|
+
return {
|
|
22
|
+
...this.state,
|
|
23
|
+
ncpAgent: { ...this.state.ncpAgent },
|
|
24
|
+
pluginHydration: { ...this.state.pluginHydration },
|
|
25
|
+
channels: {
|
|
26
|
+
...this.state.channels,
|
|
27
|
+
enabled: [...this.state.channels.enabled]
|
|
28
|
+
},
|
|
29
|
+
remote: { ...this.state.remote }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
markShellReady() {
|
|
33
|
+
this.state.phase = "shell-ready";
|
|
34
|
+
this.state.shellReadyAt = this.state.shellReadyAt ?? now();
|
|
35
|
+
}
|
|
36
|
+
markNcpAgentPending() {
|
|
37
|
+
this.state.ncpAgent = { state: "pending" };
|
|
38
|
+
}
|
|
39
|
+
markNcpAgentRunning() {
|
|
40
|
+
this.state.ncpAgent = {
|
|
41
|
+
state: "running",
|
|
42
|
+
startedAt: this.state.ncpAgent.startedAt ?? now(),
|
|
43
|
+
completedAt: void 0,
|
|
44
|
+
error: void 0
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
markNcpAgentReady() {
|
|
48
|
+
this.state.ncpAgent = {
|
|
49
|
+
state: "ready",
|
|
50
|
+
startedAt: this.state.ncpAgent.startedAt ?? now(),
|
|
51
|
+
completedAt: now(),
|
|
52
|
+
error: void 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
markNcpAgentError(error) {
|
|
56
|
+
this.state.ncpAgent = {
|
|
57
|
+
state: "error",
|
|
58
|
+
startedAt: this.state.ncpAgent.startedAt ?? now(),
|
|
59
|
+
completedAt: now(),
|
|
60
|
+
error
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
markPluginHydrationPending() {
|
|
64
|
+
this.state.pluginHydration = {
|
|
65
|
+
...this.state.pluginHydration,
|
|
66
|
+
state: "pending",
|
|
67
|
+
loadedPluginCount: 0,
|
|
68
|
+
totalPluginCount: 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
markPluginHydrationRunning(params) {
|
|
72
|
+
this.state.phase = "hydrating-capabilities";
|
|
73
|
+
this.state.pluginHydration = {
|
|
74
|
+
...this.state.pluginHydration,
|
|
75
|
+
state: "running",
|
|
76
|
+
loadedPluginCount: 0,
|
|
77
|
+
totalPluginCount: params.totalPluginCount,
|
|
78
|
+
startedAt: this.state.pluginHydration.startedAt ?? now(),
|
|
79
|
+
completedAt: void 0,
|
|
80
|
+
error: void 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
markPluginHydrationProgress(params) {
|
|
84
|
+
this.state.pluginHydration = {
|
|
85
|
+
...this.state.pluginHydration,
|
|
86
|
+
state: "running",
|
|
87
|
+
loadedPluginCount: params.loadedPluginCount,
|
|
88
|
+
totalPluginCount: params.totalPluginCount ?? this.state.pluginHydration.totalPluginCount
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
markPluginHydrationReady(params) {
|
|
92
|
+
this.state.pluginHydration = {
|
|
93
|
+
...this.state.pluginHydration,
|
|
94
|
+
state: "ready",
|
|
95
|
+
loadedPluginCount: params.loadedPluginCount,
|
|
96
|
+
totalPluginCount: params.totalPluginCount,
|
|
97
|
+
completedAt: now(),
|
|
98
|
+
error: void 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
markPluginHydrationError(error) {
|
|
102
|
+
this.state.phase = "error";
|
|
103
|
+
this.state.lastError = error;
|
|
104
|
+
this.state.pluginHydration = {
|
|
105
|
+
...this.state.pluginHydration,
|
|
106
|
+
state: "error",
|
|
107
|
+
completedAt: now(),
|
|
108
|
+
error
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
markChannelsPending() {
|
|
112
|
+
this.state.channels = {
|
|
113
|
+
state: "pending",
|
|
114
|
+
enabled: []
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
markChannelsReady(enabled) {
|
|
118
|
+
this.state.channels = {
|
|
119
|
+
state: "ready",
|
|
120
|
+
enabled: [...enabled]
|
|
121
|
+
};
|
|
122
|
+
if (this.state.pluginHydration.state === "ready") {
|
|
123
|
+
this.state.phase = "ready";
|
|
124
|
+
this.state.lastError = void 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
markChannelsError(error) {
|
|
128
|
+
this.state.phase = "error";
|
|
129
|
+
this.state.lastError = error;
|
|
130
|
+
this.state.channels = {
|
|
131
|
+
state: "error",
|
|
132
|
+
enabled: [...this.state.channels.enabled],
|
|
133
|
+
error
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
setRemoteState(state, message) {
|
|
137
|
+
this.state.remote = {
|
|
138
|
+
state,
|
|
139
|
+
...message ? { message } : {}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
markReady() {
|
|
143
|
+
this.state.phase = "ready";
|
|
144
|
+
this.state.lastError = void 0;
|
|
145
|
+
}
|
|
146
|
+
markError(error) {
|
|
147
|
+
this.state.phase = "error";
|
|
148
|
+
this.state.lastError = error;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
152
|
+
export { ServiceBootstrapStatusStore };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Config } from "@nextclaw/core";
|
|
2
|
+
import { RemoteServiceModule } from "@nextclaw/remote";
|
|
3
|
+
import { PluginDiagnostic } from "@nextclaw/openclaw-compat";
|
|
4
|
+
import { AutomationManager } from "@nextclaw/kernel";
|
|
5
|
+
import { FSWatcher } from "chokidar";
|
|
6
|
+
|
|
7
|
+
//#region src/shared/services/gateway/service-startup-support.service.d.ts
|
|
8
|
+
declare const pluginGatewayLogger: {
|
|
9
|
+
info: (message: string) => void;
|
|
10
|
+
warn: (message: string) => void;
|
|
11
|
+
error: (message: string) => void;
|
|
12
|
+
debug: (message: string) => void;
|
|
13
|
+
};
|
|
14
|
+
declare function logPluginGatewayDiagnostics(diagnostics: PluginDiagnostic[]): void;
|
|
15
|
+
declare function startGatewaySupportServices(params: {
|
|
16
|
+
automation: AutomationManager;
|
|
17
|
+
remoteModule: RemoteServiceModule | null;
|
|
18
|
+
watchConfigFile: () => void;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
declare function watchCronStoreFile(automation: AutomationManager): FSWatcher;
|
|
21
|
+
declare function watchServiceConfigFile(params: {
|
|
22
|
+
configPath: string;
|
|
23
|
+
watcherRegistry: ServiceFileWatcherRegistry;
|
|
24
|
+
scheduleReload: (reason: string) => void;
|
|
25
|
+
}): void;
|
|
26
|
+
declare class ServiceFileWatcherRegistry {
|
|
27
|
+
private readonly watchers;
|
|
28
|
+
readonly remember: (watcher: FSWatcher) => void;
|
|
29
|
+
readonly clear: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
declare function markLocalUiRuntimeIfStarted(params: {
|
|
32
|
+
uiStartup: unknown | null | undefined;
|
|
33
|
+
uiConfig: Pick<Config["ui"], "host" | "port">;
|
|
34
|
+
}): void;
|
|
35
|
+
declare function startGatewayRuntimeSupport(params: {
|
|
36
|
+
automation: AutomationManager;
|
|
37
|
+
remoteModule: RemoteServiceModule | null;
|
|
38
|
+
watchConfigFile: () => void;
|
|
39
|
+
watcherRegistry: ServiceFileWatcherRegistry;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { ServiceFileWatcherRegistry, logPluginGatewayDiagnostics, markLocalUiRuntimeIfStarted, pluginGatewayLogger, startGatewayRuntimeSupport, startGatewaySupportServices, watchCronStoreFile, watchServiceConfigFile };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { localUiRuntimeStore } from "../../stores/local-ui-runtime.store.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import chokidar from "chokidar";
|
|
4
|
+
//#region src/shared/services/gateway/service-startup-support.service.ts
|
|
5
|
+
const pluginGatewayLogger = {
|
|
6
|
+
info: (message) => console.log(`[plugins] ${message}`),
|
|
7
|
+
warn: (message) => console.warn(`[plugins] ${message}`),
|
|
8
|
+
error: (message) => console.error(`[plugins] ${message}`),
|
|
9
|
+
debug: (message) => console.debug(`[plugins] ${message}`)
|
|
10
|
+
};
|
|
11
|
+
function logPluginGatewayDiagnostics(diagnostics) {
|
|
12
|
+
for (const diag of diagnostics) {
|
|
13
|
+
const text = `${diag.pluginId ? `${diag.pluginId}: ` : ""}${diag.message}`;
|
|
14
|
+
if (diag.level === "error") console.error(`[plugins] ${text}`);
|
|
15
|
+
else console.warn(`[plugins] ${text}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function startGatewaySupportServices(params) {
|
|
19
|
+
const { automation, remoteModule, watchConfigFile } = params;
|
|
20
|
+
const cronJobs = automation.status().jobs;
|
|
21
|
+
if (cronJobs > 0) console.log(`✓ Cron: ${cronJobs} scheduled jobs`);
|
|
22
|
+
remoteModule?.start();
|
|
23
|
+
watchConfigFile();
|
|
24
|
+
await automation.start();
|
|
25
|
+
}
|
|
26
|
+
function watchCronStoreFile(automation) {
|
|
27
|
+
const cronStorePath = resolve(automation.storePath);
|
|
28
|
+
const watcher = chokidar.watch(cronStorePath, {
|
|
29
|
+
ignoreInitial: true,
|
|
30
|
+
awaitWriteFinish: {
|
|
31
|
+
stabilityThreshold: 200,
|
|
32
|
+
pollInterval: 50
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
watcher.on("all", (event, changedPath) => {
|
|
36
|
+
if (resolve(changedPath) !== cronStorePath) return;
|
|
37
|
+
if (event === "add" || event === "change" || event === "unlink") try {
|
|
38
|
+
automation.reloadFromStore();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error(`Cron store reload failed (${event}): ${String(error)}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return watcher;
|
|
44
|
+
}
|
|
45
|
+
function watchServiceConfigFile(params) {
|
|
46
|
+
const configPath = resolve(params.configPath);
|
|
47
|
+
const watcher = chokidar.watch(configPath, {
|
|
48
|
+
ignoreInitial: true,
|
|
49
|
+
awaitWriteFinish: {
|
|
50
|
+
stabilityThreshold: 200,
|
|
51
|
+
pollInterval: 50
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
params.watcherRegistry.remember(watcher);
|
|
55
|
+
watcher.on("all", (event, changedPath) => {
|
|
56
|
+
if (resolve(changedPath) !== configPath) return;
|
|
57
|
+
if (event === "add") {
|
|
58
|
+
params.scheduleReload("config add");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (event === "change") {
|
|
62
|
+
params.scheduleReload("config change");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (event === "unlink") params.scheduleReload("config unlink");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var ServiceFileWatcherRegistry = class {
|
|
69
|
+
watchers = [];
|
|
70
|
+
remember = (watcher) => {
|
|
71
|
+
this.watchers.push(watcher);
|
|
72
|
+
};
|
|
73
|
+
clear = async () => {
|
|
74
|
+
const watchers = this.watchers.splice(0);
|
|
75
|
+
await Promise.allSettled(watchers.map(async (watcher) => {
|
|
76
|
+
try {
|
|
77
|
+
await watcher.close();
|
|
78
|
+
} catch {}
|
|
79
|
+
}));
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
function markLocalUiRuntimeIfStarted(params) {
|
|
83
|
+
const { uiConfig, uiStartup } = params;
|
|
84
|
+
if (uiStartup) localUiRuntimeStore.writeCurrentProcess(uiConfig);
|
|
85
|
+
}
|
|
86
|
+
async function startGatewayRuntimeSupport(params) {
|
|
87
|
+
const { automation, remoteModule, watchConfigFile, watcherRegistry } = params;
|
|
88
|
+
await startGatewaySupportServices({
|
|
89
|
+
automation,
|
|
90
|
+
remoteModule,
|
|
91
|
+
watchConfigFile
|
|
92
|
+
});
|
|
93
|
+
watcherRegistry.remember(watchCronStoreFile(automation));
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { ServiceFileWatcherRegistry, logPluginGatewayDiagnostics, markLocalUiRuntimeIfStarted, pluginGatewayLogger, startGatewayRuntimeSupport, startGatewaySupportServices, watchCronStoreFile, watchServiceConfigFile };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ServiceBootstrapStatusStore } from "../service-bootstrap-status.js";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts
|
|
4
|
+
declare function handleGatewayDeferredStartupError(params: {
|
|
5
|
+
bootstrapStatus: ServiceBootstrapStatusStore;
|
|
6
|
+
error: unknown;
|
|
7
|
+
}): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { handleGatewayDeferredStartupError };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.ts
|
|
2
|
+
function handleGatewayDeferredStartupError(params) {
|
|
3
|
+
const { bootstrapStatus, error } = params;
|
|
4
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5
|
+
bootstrapStatus.markError(message);
|
|
6
|
+
if (bootstrapStatus.getStatus().pluginHydration.state === "running") bootstrapStatus.markPluginHydrationError(message);
|
|
7
|
+
console.error(`Deferred startup failed: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { handleGatewayDeferredStartupError };
|