mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 10:52:53 +00:00
* 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
49 lines
1.5 KiB
TypeScript
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,
|
|
}),
|
|
);
|
|
}
|