import type { Command } from "commander"; import { callGateway } from "../gateway/call.js"; import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../utils/message-channel.js"; import { withProgress } from "./progress.js"; export type GatewayRpcOpts = { url?: string; token?: string; timeout?: string; expectFinal?: boolean; json?: boolean; }; export function addGatewayClientOptions(cmd: Command) { return cmd .option("--url ", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)") .option("--token ", "Gateway token (if required)") .option("--timeout ", "Timeout in ms", "10000") .option("--expect-final", "Wait for final response (agent)", false); } export async function callGatewayFromCli( method: string, opts: GatewayRpcOpts, params?: unknown, extra?: { expectFinal?: boolean }, ) { return await withProgress( { label: `Gateway ${method}`, indeterminate: true, enabled: opts.json !== true, }, async () => await callGateway({ url: opts.url, token: opts.token, method, params, expectFinal: extra?.expectFinal ?? Boolean(opts.expectFinal), timeoutMs: Number(opts.timeout ?? 10_000), clientName: GATEWAY_CLIENT_NAMES.CLI, mode: GATEWAY_CLIENT_MODES.CLI, }), ); }