openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.94 kB
JavaScript
import{l as normalizeOptionalString,m as readNonBlankString}from"./string-coerce-CpTFcSwY.mjs";import{n as formatByteSize}from"./format-66SdinIu.mjs";import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{s as readPositiveIntegerParam}from"./common-DIgvX97L.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import{t as callGatewayTool}from"./gateway-Bf9f0Pcc.mjs";import"./number-runtime-G0nhUVZu.mjs";import"./agent-harness-runtime-BNh6LFIo.mjs";import{n as listNodes,o as resolveNodeIdFromList}from"./nodes-utils-Bgm8PZ2e.mjs";import"./param-readers-BpVB3RWF.mjs";import{t as bindFileTransferAudit}from"./audit-context-YrxeUP51.mjs";import{t as throwFromNodePayload}from"./errors-Dgj_hH87.mjs";import crypto from"node:crypto";
//!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})}
//!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}}export{readClampedInt as i,readRequiredNodePath as n,humanSize as r,invokeNodeToolPayload as t};