refactor(nodes-cli): share node.invoke param builder
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { Command } from "commander";
|
||||
import type { NodesRpcOpts } from "./types.js";
|
||||
import { randomIdempotencyKey } from "../../gateway/call.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { renderTable } from "../../terminal/table.js";
|
||||
import { shortenHomePath } from "../../utils.js";
|
||||
@@ -14,7 +13,7 @@ import {
|
||||
} from "../nodes-camera.js";
|
||||
import { parseDurationMs } from "../parse-duration.js";
|
||||
import { getNodesTheme, runNodesCommand } from "./cli-utils.js";
|
||||
import { callGatewayCli, nodesCallOpts, resolveNodeId } from "./rpc.js";
|
||||
import { buildNodeInvokeParams, callGatewayCli, nodesCallOpts, resolveNodeId } from "./rpc.js";
|
||||
|
||||
const parseFacing = (value: string): CameraFacing => {
|
||||
const v = String(value ?? "")
|
||||
@@ -37,12 +36,15 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
.action(async (opts: NodesRpcOpts) => {
|
||||
await runNodesCommand("camera list", async () => {
|
||||
const nodeId = await resolveNodeId(opts, String(opts.node ?? ""));
|
||||
const raw = await callGatewayCli("node.invoke", opts, {
|
||||
nodeId,
|
||||
command: "camera.list",
|
||||
params: {},
|
||||
idempotencyKey: randomIdempotencyKey(),
|
||||
});
|
||||
const raw = await callGatewayCli(
|
||||
"node.invoke",
|
||||
opts,
|
||||
buildNodeInvokeParams({
|
||||
nodeId,
|
||||
command: "camera.list",
|
||||
params: {},
|
||||
}),
|
||||
);
|
||||
|
||||
const res = typeof raw === "object" && raw !== null ? (raw as { payload?: unknown }) : {};
|
||||
const payload =
|
||||
@@ -130,7 +132,7 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
}> = [];
|
||||
|
||||
for (const facing of facings) {
|
||||
const invokeParams: Record<string, unknown> = {
|
||||
const invokeParams = buildNodeInvokeParams({
|
||||
nodeId,
|
||||
command: "camera.snap",
|
||||
params: {
|
||||
@@ -141,11 +143,8 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
delayMs: Number.isFinite(delayMs) ? delayMs : undefined,
|
||||
deviceId: deviceId || undefined,
|
||||
},
|
||||
idempotencyKey: randomIdempotencyKey(),
|
||||
};
|
||||
if (typeof timeoutMs === "number" && Number.isFinite(timeoutMs)) {
|
||||
invokeParams.timeoutMs = timeoutMs;
|
||||
}
|
||||
timeoutMs,
|
||||
});
|
||||
|
||||
const raw = await callGatewayCli("node.invoke", opts, invokeParams);
|
||||
const res =
|
||||
@@ -204,7 +203,7 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
: undefined;
|
||||
const deviceId = opts.deviceId ? String(opts.deviceId).trim() : undefined;
|
||||
|
||||
const invokeParams: Record<string, unknown> = {
|
||||
const invokeParams = buildNodeInvokeParams({
|
||||
nodeId,
|
||||
command: "camera.clip",
|
||||
params: {
|
||||
@@ -214,11 +213,8 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
format: "mp4",
|
||||
deviceId: deviceId || undefined,
|
||||
},
|
||||
idempotencyKey: randomIdempotencyKey(),
|
||||
};
|
||||
if (typeof timeoutMs === "number" && Number.isFinite(timeoutMs)) {
|
||||
invokeParams.timeoutMs = timeoutMs;
|
||||
}
|
||||
timeoutMs,
|
||||
});
|
||||
|
||||
const raw = await callGatewayCli("node.invoke", opts, invokeParams);
|
||||
const res = typeof raw === "object" && raw !== null ? (raw as { payload?: unknown }) : {};
|
||||
|
||||
Reference in New Issue
Block a user