mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-26 01:49:30 +00:00
Reject malformed or explicit empty Gateway RPC timeout values before opening Gateway calls, align the shared Gateway RPC omitted-timeout fallback with the 30000 ms CLI default, and validate explicit `cron add --timeout-seconds` values at the CLI boundary. Carries forward the useful source work from #54646 and the earlier timeout-validation context from #40953. #60661 remains separate accepted-run timeout semantics work and is intentionally not folded into this change. Validation: - `npm run review-results -- /tmp/clownfish-check-27341769444` - `git diff --check` - OpenClaw PR checks on `ce7bd8b9388a5689b14ddc2b3a984f7b4647e5ca`: 132 pass, 0 pending, 0 failing - ClawSweeper re-review: https://github.com/openclaw/clawsweeper/actions/runs/27344244608 Co-authored-by: RayRuan <43744645+ruanrrn@users.noreply.github.com> Co-authored-by: Homeran <11574611+comeran@users.noreply.github.com>
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
// Runtime gateway RPC helper shared by CLI commands that call the Gateway.
|
|
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 = 30_000;
|
|
|
|
export async function callGatewayFromCliRuntime(
|
|
method: string,
|
|
opts: GatewayRpcOpts,
|
|
params?: unknown,
|
|
extra?: CallGatewayFromCliRuntimeExtra,
|
|
) {
|
|
// Progress is disabled for JSON output so stdout stays parseable.
|
|
const showProgress = extra?.progress ?? opts.json !== true;
|
|
const timeoutMs = parseTimeoutMsWithFallback(opts.timeout, DEFAULT_GATEWAY_RPC_TIMEOUT_MS, {
|
|
invalidType: "error",
|
|
});
|
|
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,
|
|
clientName: extra?.clientName ?? GATEWAY_CLIENT_NAMES.CLI,
|
|
mode: extra?.mode ?? GATEWAY_CLIENT_MODES.CLI,
|
|
}),
|
|
);
|
|
}
|