Files
openclaw/src/cli/gateway-rpc.runtime.ts
Peter Steinberger b1117d9862 refactor: extract gateway client package (#87797)
* refactor: extract gateway client package

* chore: drop generated gateway package artifacts

* refactor: move gateway protocol package

* refactor: remove old gateway protocol tree

* test: keep auth compat split in run mode

* test: expose gateway wrapper options for internals

* fix: watch moved gateway package sources

* test: normalize slash command import guard

* chore: teach knip gateway package entries

* ci: route gateway client package checks

* fix: reuse ipaddr for gateway client hosts

* fix: sync gateway protocol usage schema
2026-05-29 02:23:42 +01:00

49 lines
1.5 KiB
TypeScript

import {
GATEWAY_CLIENT_MODES,
GATEWAY_CLIENT_NAMES,
} from "../../packages/gateway-protocol/src/client-info.js";
import { callGateway } from "../gateway/call.js";
import type { GatewayRpcOpts } from "./gateway-rpc.types.js";
import { parseTimeoutMsWithFallback } from "./parse-timeout.js";
import { withProgress } from "./progress.js";
type CallGatewayFromCliRuntimeExtra = {
clientName?: Parameters<typeof callGateway>[0]["clientName"];
mode?: Parameters<typeof callGateway>[0]["mode"];
deviceIdentity?: Parameters<typeof callGateway>[0]["deviceIdentity"];
expectFinal?: boolean;
progress?: boolean;
scopes?: Parameters<typeof callGateway>[0]["scopes"];
};
const DEFAULT_GATEWAY_RPC_TIMEOUT_MS = 10_000;
export async function callGatewayFromCliRuntime(
method: string,
opts: GatewayRpcOpts,
params?: unknown,
extra?: CallGatewayFromCliRuntimeExtra,
) {
const showProgress = extra?.progress ?? opts.json !== true;
return await withProgress(
{
label: `Gateway ${method}`,
indeterminate: true,
enabled: showProgress,
},
async () =>
await callGateway({
url: opts.url,
token: opts.token,
method,
params,
deviceIdentity: extra?.deviceIdentity,
expectFinal: extra?.expectFinal ?? Boolean(opts.expectFinal),
scopes: extra?.scopes,
timeoutMs: parseTimeoutMsWithFallback(opts.timeout, DEFAULT_GATEWAY_RPC_TIMEOUT_MS),
clientName: extra?.clientName ?? GATEWAY_CLIENT_NAMES.CLI,
mode: extra?.mode ?? GATEWAY_CLIENT_MODES.CLI,
}),
);
}