mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-04 05:42:02 +00:00
* Status: handle node-only hosts * Status: address follow-up review nits * Changelog: note node-only status fix * Status: lazy-load node-only helper
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { DEFAULT_GATEWAY_PORT } from "../config/paths.js";
|
|
import { loadNodeHostConfig } from "../node-host/config.js";
|
|
|
|
type NodeOnlyServiceLike = {
|
|
installed: boolean | null;
|
|
loaded?: boolean | null;
|
|
externallyManaged?: boolean;
|
|
runtime?:
|
|
| {
|
|
status?: string;
|
|
pid?: number;
|
|
}
|
|
| undefined;
|
|
runtimeShort?: string | null;
|
|
};
|
|
|
|
export type NodeOnlyGatewayInfo = {
|
|
gatewayTarget: string;
|
|
gatewayValue: string;
|
|
connectionDetails: string;
|
|
};
|
|
|
|
function resolveNodeGatewayTarget(gateway?: { host?: string; port?: number }): string {
|
|
return gateway?.host
|
|
? `${gateway.host}:${gateway.port ?? DEFAULT_GATEWAY_PORT}`
|
|
: "(gateway address unknown)";
|
|
}
|
|
|
|
function hasRunningRuntime(
|
|
runtime:
|
|
| {
|
|
status?: string;
|
|
pid?: number;
|
|
}
|
|
| undefined,
|
|
): boolean {
|
|
return runtime?.status === "running" || typeof runtime?.pid === "number";
|
|
}
|
|
|
|
function isNodeServiceActive(node: NodeOnlyServiceLike): boolean {
|
|
if (node.installed !== true) {
|
|
return false;
|
|
}
|
|
if (node.externallyManaged === true) {
|
|
return true;
|
|
}
|
|
if (node.loaded === true) {
|
|
return true;
|
|
}
|
|
if (hasRunningRuntime(node.runtime)) {
|
|
return true;
|
|
}
|
|
return typeof node.runtimeShort === "string" && node.runtimeShort.startsWith("running");
|
|
}
|
|
|
|
export async function resolveNodeOnlyGatewayInfo(params: {
|
|
daemon: Pick<NodeOnlyServiceLike, "installed">;
|
|
node: NodeOnlyServiceLike;
|
|
}): Promise<NodeOnlyGatewayInfo | null> {
|
|
if (params.daemon.installed !== false || !isNodeServiceActive(params.node)) {
|
|
return null;
|
|
}
|
|
|
|
const gatewayTarget = resolveNodeGatewayTarget((await loadNodeHostConfig())?.gateway);
|
|
return {
|
|
gatewayTarget,
|
|
gatewayValue: `node → ${gatewayTarget} · no local gateway`,
|
|
connectionDetails: [
|
|
"Node-only mode detected",
|
|
"Local gateway: not expected on this machine",
|
|
`Remote gateway target: ${gatewayTarget}`,
|
|
"Inspect the remote gateway host for live channel and health details.",
|
|
].join("\n"),
|
|
};
|
|
}
|