

























@@ -2,30 +2,18 @@ import { spawn } from "node:child_process";
22import crypto from "node:crypto";
33import fs from "node:fs/promises";
44import path from "node:path";
5-import {
6-callGatewayTool,
7-listNodes,
8-resolveNodeIdFromList,
9-type AnyAgentTool,
10-type NodeListNode,
11-} from "openclaw/plugin-sdk/agent-harness-runtime";
5+import { type AnyAgentTool } from "openclaw/plugin-sdk/agent-harness-runtime";
126import { saveMediaBuffer } from "openclaw/plugin-sdk/media-store";
137import { appendFileTransferAudit } from "../shared/audit.js";
14-import { throwFromNodePayload } from "../shared/errors.js";
158import { IMAGE_MIME_INLINE_SET, mimeFromExtension } from "../shared/mime.js";
16-import {
17-humanSize,
18-readBoolean,
19-readClampedInt,
20-readGatewayCallOptions,
21-readTrimmedString,
22-} from "../shared/params.js";
9+import { humanSize, readBoolean, readClampedInt } from "../shared/params.js";
2310import {
2411DIR_FETCH_DEFAULT_MAX_BYTES,
2512DIR_FETCH_HARD_MAX_BYTES,
2613DIR_FETCH_TOOL_DESCRIPTOR,
2714FILE_TRANSFER_SUBDIR,
2815} from "./descriptors.js";
16+import { invokeNodeToolPayload, readRequiredNodePath } from "./node-tool-invoke.js";
29173018// Cap how many local file paths we surface in details.media.mediaUrls.
3119// Larger trees still land on disk but we don't spam the channel adapter
@@ -478,14 +466,7 @@ export function createDirFetchTool(): AnyAgentTool {
478466 ...DIR_FETCH_TOOL_DESCRIPTOR,
479467execute: async (_toolCallId, args) => {
480468const params = args as Record<string, unknown>;
481-const node = readTrimmedString(params, "node");
482-const dirPath = readTrimmedString(params, "path");
483-if (!node) {
484-throw new Error("node required");
485-}
486-if (!dirPath) {
487-throw new Error("path required");
488-}
469+const { node, requestedPath: dirPath } = readRequiredNodePath(params);
489470490471const maxBytes = readClampedInt({
491472input: params,
@@ -496,56 +477,18 @@ export function createDirFetchTool(): AnyAgentTool {
496477});
497478const includeDotfiles = readBoolean(params, "includeDotfiles", false);
498479499-const gatewayOpts = readGatewayCallOptions(params);
500-const nodes: NodeListNode[] = await listNodes(gatewayOpts);
501-const nodeId = resolveNodeIdFromList(nodes, node, false);
502-const nodeMeta = nodes.find((n) => n.nodeId === nodeId);
503-const nodeDisplayName = nodeMeta?.displayName ?? node;
504-const startedAt = Date.now();
505-506-const raw = await callGatewayTool<{ payload: unknown }>("node.invoke", gatewayOpts, {
507- nodeId,
480+const { nodeId, nodeDisplayName, payload, startedAt } = await invokeNodeToolPayload({
481+ node,
482+ params,
508483command: "dir.fetch",
509-params: {
484+commandParams: {
510485path: dirPath,
511486 maxBytes,
512487 includeDotfiles,
513488},
514-idempotencyKey: crypto.randomUUID(),
489+requestedPath: dirPath,
515490});
516491517-const payload =
518-raw?.payload && typeof raw.payload === "object" && !Array.isArray(raw.payload)
519- ? (raw.payload as Record<string, unknown>)
520- : null;
521-if (!payload) {
522-await appendFileTransferAudit({
523-op: "dir.fetch",
524- nodeId,
525- nodeDisplayName,
526-requestedPath: dirPath,
527-decision: "error",
528-errorMessage: "invalid payload",
529-durationMs: Date.now() - startedAt,
530-});
531-throw new Error("invalid dir.fetch payload");
532-}
533-if (payload.ok === false) {
534-await appendFileTransferAudit({
535-op: "dir.fetch",
536- nodeId,
537- nodeDisplayName,
538-requestedPath: dirPath,
539-canonicalPath:
540-typeof payload.canonicalPath === "string" ? payload.canonicalPath : undefined,
541-decision: "error",
542-errorCode: typeof payload.code === "string" ? payload.code : undefined,
543-errorMessage: typeof payload.message === "string" ? payload.message : undefined,
544-durationMs: Date.now() - startedAt,
545-});
546-throwFromNodePayload("dir.fetch", payload);
547-}
548-549492const canonicalPath = typeof payload.path === "string" ? payload.path : "";
550493const tarBase64 = typeof payload.tarBase64 === "string" ? payload.tarBase64 : "";
551494const tarBytes = typeof payload.tarBytes === "number" ? payload.tarBytes : -1;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。