mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-20 00:31:37 +00:00
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
// Lazy gateway RPC facade and shared Commander options for CLI subcommands.
|
|
import type { Command } from "commander";
|
|
import type {
|
|
GatewayClientMode,
|
|
GatewayClientName,
|
|
} from "../../packages/gateway-protocol/src/client-info.js";
|
|
import type { OperatorScope } from "../gateway/operator-scopes.js";
|
|
import type { DeviceIdentity } from "../infra/device-identity.js";
|
|
import { createLazyImportLoader } from "../shared/lazy-promise.js";
|
|
import type { GatewayRpcOpts } from "./gateway-rpc.types.js";
|
|
export type { GatewayRpcOpts } from "./gateway-rpc.types.js";
|
|
|
|
type GatewayRpcRuntimeModule = typeof import("./gateway-rpc.runtime.js");
|
|
|
|
const gatewayRpcRuntimeLoader = createLazyImportLoader<GatewayRpcRuntimeModule>(
|
|
() => import("./gateway-rpc.runtime.js"),
|
|
);
|
|
|
|
async function loadGatewayRpcRuntime(): Promise<GatewayRpcRuntimeModule> {
|
|
// Keep gateway transport/runtime imports out of help and shell completion startup.
|
|
return gatewayRpcRuntimeLoader.load();
|
|
}
|
|
|
|
export function addGatewayClientOptions(cmd: Command, defaults?: { timeoutMs?: number }) {
|
|
return cmd
|
|
.option("--url <url>", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)")
|
|
.option("--token <token>", "Gateway token (if required)")
|
|
.option("--timeout <ms>", "Timeout in ms", String(defaults?.timeoutMs ?? 30_000))
|
|
.option("--expect-final", "Wait for final response (agent)", false);
|
|
}
|
|
|
|
export async function callGatewayFromCli(
|
|
method: string,
|
|
opts: GatewayRpcOpts,
|
|
params?: unknown,
|
|
extra?: {
|
|
clientName?: GatewayClientName;
|
|
mode?: GatewayClientMode;
|
|
deviceIdentity?: DeviceIdentity | null;
|
|
signal?: AbortSignal;
|
|
expectFinal?: boolean;
|
|
progress?: boolean;
|
|
scopes?: OperatorScope[];
|
|
},
|
|
) {
|
|
const runtime = await loadGatewayRpcRuntime();
|
|
return await runtime.callGatewayFromCliRuntime(method, opts, params, extra);
|
|
}
|