openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
91 lines (90 loc) • 3.38 kB
JavaScript
import { l as normalizeOptionalString, m as readNonBlankString } from "./string-coerce-CCIiB4H7.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as formatByteSize } from "./format-KwhqGIVR.mjs";
import { u as readPositiveIntegerParam } from "./common-njQNtpnW.mjs";
import { t as callGatewayTool } from "./gateway-DL_Nxi-v.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./number-runtime-W4chuk8B.mjs";
import "./agent-harness-runtime-BCklzcv7.mjs";
import { n as listNodes, o as resolveNodeIdFromList } from "./nodes-utils-B4u6gtyR.mjs";
import "./param-readers-CVZN1591.mjs";
import { t as bindFileTransferAudit } from "./audit-context-D4se-huO.mjs";
import { t as throwFromNodePayload } from "./errors-xXzCEVsC.mjs";
import crypto from "node:crypto";
//#region extensions/file-transfer/src/shared/params.ts
function readGatewayCallOptions(e) {
const t = {};
if (typeof e.gatewayUrl === "string" && e.gatewayUrl.trim()) t.gatewayUrl = e.gatewayUrl.trim();
if (typeof e.gatewayToken === "string" && e.gatewayToken.trim()) t.gatewayToken = e.gatewayToken.trim();
t.timeoutMs = readPositiveIntegerParam(e, "timeoutMs");
return t;
}
function readClampedInt(e) {
const t = readPositiveIntegerParam(e.input, e.key) ?? e.defaultValue;
return Math.max(1, Math.min(t, e.hardMax));
}
function humanSize(e) {
return formatByteSize(e, {
style: "legacy-binary",
maxUnit: "mega",
separator: " ",
fractionDigits: (e, t) => t === "byte" ? null : t === "kilo" ? 1 : 2
});
}
//#endregion
//#region extensions/file-transfer/src/tools/node-tool-invoke.ts
function readRequiredNodePath(e) {
const t = normalizeOptionalString(e.node);
const n = readNonBlankString(e.path);
if (!t) throw new Error("node required");
if (!n) throw new Error("path required");
return {
node: t,
requestedPath: n
};
}
async function invokeNodeToolPayload(e) {
const t = readGatewayCallOptions(e.params);
const n = await listNodes(t);
if (n.length === 0) throw new Error("no paired nodes available; file-transfer tools require a paired node from nodes status. Use local file/exec tools for local workspace paths.");
const r = resolveNodeIdFromList(n, e.node, false);
const i = n.find((e) => e.nodeId === r)?.displayName ?? e.node;
const a = Date.now();
const o = bindFileTransferAudit({
op: e.command,
nodeId: r,
nodeDisplayName: i,
requestedPath: e.requestedPath
}, a);
const s = await callGatewayTool("node.invoke", t, {
nodeId: r,
command: e.command,
params: e.commandParams,
idempotencyKey: crypto.randomUUID()
});
const c = asNullableRecord(s?.payload);
if (!c) {
await o({
decision: "error",
errorMessage: e.invalidPayloadMessage ?? "invalid payload",
...e.errorAuditExtra
});
throw new Error(e.invalidPayloadError ?? `invalid ${e.command} payload`);
}
if (c.ok === false || e.requireOk === true && c.ok !== true) {
await o({
canonicalPath: typeof c.canonicalPath === "string" ? c.canonicalPath : void 0,
decision: "error",
errorCode: typeof c.code === "string" ? c.code : void 0,
errorMessage: typeof c.message === "string" ? c.message : void 0,
...e.errorAuditExtra
});
throwFromNodePayload(e.command, c);
}
return {
audit: o,
payload: c
};
}
//#endregion
export { readClampedInt as i, readRequiredNodePath as n, humanSize as r, invokeNodeToolPayload as t };