mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 23:31:07 +00:00
refactor: lazy load cli gateway helper runtimes
This commit is contained in:
committed by
Peter Steinberger
parent
58f1044ec0
commit
36c8282795
29
src/cli/nodes-cli/rpc.runtime.ts
Normal file
29
src/cli/nodes-cli/rpc.runtime.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { callGateway } from "../../gateway/call.js";
|
||||
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../../utils/message-channel.js";
|
||||
import { withProgress } from "../progress.js";
|
||||
import type { NodesRpcOpts } from "./types.js";
|
||||
|
||||
export async function callGatewayCliRuntime(
|
||||
method: string,
|
||||
opts: NodesRpcOpts,
|
||||
params?: unknown,
|
||||
callOpts?: { transportTimeoutMs?: number },
|
||||
) {
|
||||
return await withProgress(
|
||||
{
|
||||
label: `Nodes ${method}`,
|
||||
indeterminate: true,
|
||||
enabled: opts.json !== true,
|
||||
},
|
||||
async () =>
|
||||
await callGateway({
|
||||
url: opts.url,
|
||||
token: opts.token,
|
||||
method,
|
||||
params,
|
||||
timeoutMs: callOpts?.transportTimeoutMs ?? Number(opts.timeout ?? 10_000),
|
||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||
mode: GATEWAY_CLIENT_MODES.CLI,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { Command } from "commander";
|
||||
import { callGateway, randomIdempotencyKey } from "../../gateway/call.js";
|
||||
import { resolveNodeFromNodeList } from "../../shared/node-resolve.js";
|
||||
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../../utils/message-channel.js";
|
||||
import { withProgress } from "../progress.js";
|
||||
import { parseNodeList, parsePairingList } from "./format.js";
|
||||
import type { NodeListNode, NodesRpcOpts } from "./types.js";
|
||||
|
||||
type NodesCliRpcRuntimeModule = typeof import("./rpc.runtime.js");
|
||||
|
||||
let nodesCliRpcRuntimePromise: Promise<NodesCliRpcRuntimeModule> | undefined;
|
||||
|
||||
async function loadNodesCliRpcRuntime(): Promise<NodesCliRpcRuntimeModule> {
|
||||
nodesCliRpcRuntimePromise ??= import("./rpc.runtime.js");
|
||||
return nodesCliRpcRuntimePromise;
|
||||
}
|
||||
|
||||
export const nodesCallOpts = (cmd: Command, defaults?: { timeoutMs?: number }) =>
|
||||
cmd
|
||||
.option("--url <url>", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)")
|
||||
@@ -18,24 +25,10 @@ export const callGatewayCli = async (
|
||||
opts: NodesRpcOpts,
|
||||
params?: unknown,
|
||||
callOpts?: { transportTimeoutMs?: number },
|
||||
) =>
|
||||
withProgress(
|
||||
{
|
||||
label: `Nodes ${method}`,
|
||||
indeterminate: true,
|
||||
enabled: opts.json !== true,
|
||||
},
|
||||
async () =>
|
||||
await callGateway({
|
||||
url: opts.url,
|
||||
token: opts.token,
|
||||
method,
|
||||
params,
|
||||
timeoutMs: callOpts?.transportTimeoutMs ?? Number(opts.timeout ?? 10_000),
|
||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||
mode: GATEWAY_CLIENT_MODES.CLI,
|
||||
}),
|
||||
);
|
||||
) => {
|
||||
const runtime = await loadNodesCliRpcRuntime();
|
||||
return await runtime.callGatewayCliRuntime(method, opts, params, callOpts);
|
||||
};
|
||||
|
||||
export function buildNodeInvokeParams(params: {
|
||||
nodeId: string;
|
||||
@@ -48,7 +41,7 @@ export function buildNodeInvokeParams(params: {
|
||||
nodeId: params.nodeId,
|
||||
command: params.command,
|
||||
params: params.params,
|
||||
idempotencyKey: params.idempotencyKey ?? randomIdempotencyKey(),
|
||||
idempotencyKey: params.idempotencyKey ?? randomUUID(),
|
||||
};
|
||||
if (typeof params.timeoutMs === "number" && Number.isFinite(params.timeoutMs)) {
|
||||
invokeParams.timeoutMs = params.timeoutMs;
|
||||
|
||||
Reference in New Issue
Block a user