mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 12:14:54 +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.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import {
|
|
GATEWAY_CLIENT_MODES,
|
|
GATEWAY_CLIENT_NAMES,
|
|
} from "../../packages/gateway-protocol/src/client-info.js";
|
|
import { callGateway } from "../gateway/call.js";
|
|
import type { PluginRuntime } from "./runtime/types.js";
|
|
|
|
export function createPluginCliGatewayNodesRuntime(): PluginRuntime["nodes"] {
|
|
return {
|
|
async list(params) {
|
|
const payload = await callGateway({
|
|
method: "node.list",
|
|
params: {},
|
|
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
|
mode: GATEWAY_CLIENT_MODES.CLI,
|
|
});
|
|
const nodes = Array.isArray(payload?.nodes) ? payload.nodes : [];
|
|
const filteredNodes =
|
|
params?.connected === true
|
|
? nodes.filter(
|
|
(node) =>
|
|
node !== null &&
|
|
typeof node === "object" &&
|
|
(node as { connected?: unknown }).connected === true,
|
|
)
|
|
: nodes;
|
|
return {
|
|
nodes: filteredNodes as Awaited<ReturnType<PluginRuntime["nodes"]["list"]>>["nodes"],
|
|
};
|
|
},
|
|
async invoke(params) {
|
|
return await callGateway({
|
|
method: "node.invoke",
|
|
params: {
|
|
nodeId: params.nodeId,
|
|
command: params.command,
|
|
...(params.params !== undefined && { params: params.params }),
|
|
timeoutMs: params.timeoutMs,
|
|
idempotencyKey: params.idempotencyKey || randomUUID(),
|
|
},
|
|
timeoutMs: params.timeoutMs ? params.timeoutMs + 5_000 : undefined,
|
|
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
|
mode: GATEWAY_CLIENT_MODES.CLI,
|
|
});
|
|
},
|
|
};
|
|
}
|