refactor(nodes-cli): share node.invoke param builder

This commit is contained in:
Peter Steinberger
2026-02-16 02:03:15 +00:00
parent 966957fc66
commit d4bdcda324
4 changed files with 56 additions and 61 deletions

View File

@@ -1,6 +1,6 @@
import type { Command } from "commander";
import type { NodeListNode, NodesRpcOpts } from "./types.js";
import { callGateway } from "../../gateway/call.js";
import { callGateway, randomIdempotencyKey } from "../../gateway/call.js";
import { resolveNodeIdFromCandidates } from "../../shared/node-match.js";
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../../utils/message-channel.js";
import { withProgress } from "../progress.js";
@@ -37,6 +37,25 @@ export const callGatewayCli = async (
}),
);
export function buildNodeInvokeParams(params: {
nodeId: string;
command: string;
params?: Record<string, unknown>;
timeoutMs?: number;
idempotencyKey?: string;
}): Record<string, unknown> {
const invokeParams: Record<string, unknown> = {
nodeId: params.nodeId,
command: params.command,
params: params.params,
idempotencyKey: params.idempotencyKey ?? randomIdempotencyKey(),
};
if (typeof params.timeoutMs === "number" && Number.isFinite(params.timeoutMs)) {
invokeParams.timeoutMs = params.timeoutMs;
}
return invokeParams;
}
export function unauthorizedHintForMessage(message: string): string | null {
const haystack = message.toLowerCase();
if (