UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

74 lines (73 loc) • 2.62 kB
import { u as readPositiveIntegerParam } from "./common-njQNtpnW.mjs"; import { a as wrapExternalContent } from "./external-content-CGL7l-3s.mjs"; import "./security-runtime-C-zE_Zy_.mjs"; import { d as saveMediaBuffer } from "./store-zsTAVy24.mjs"; import "./media-store-2NPKQiFG.mjs"; import "./param-readers-CVZN1591.mjs"; import { a as FILE_TRANSFER_SUBDIR, i as FILE_FETCH_TOOL_DESCRIPTOR } from "./descriptors-CZtmxLD2.mjs"; import { n as TEXT_INLINE_MAX_BYTES, t as IMAGE_MIME_INLINE_SET } from "./mime-Bqs6nBQk.mjs"; import { n as FILE_FETCH_DEFAULT_MAX_BYTES, r as FILE_FETCH_HARD_MAX_BYTES } from "./file-fetch-protocol-BkzCnMYL.mjs"; import { n as readRequiredNodePath, r as humanSize, t as invokeNodeToolPayload } from "./node-tool-invoke-DIC-uNGI.mjs"; import { t as decodeFetchPayload } from "./fetch-payload-tpAVxkGH.mjs"; //#region extensions/file-transfer/src/tools/file-fetch-tool.ts function createFileFetchTool() { return { ...FILE_FETCH_TOOL_DESCRIPTOR, execute: async (e, t) => { const n = t; const { node: r, requestedPath: i } = readRequiredNodePath(n); const a = readPositiveIntegerParam(n, "maxBytes") ?? 8388608; const { audit: o, payload: s } = await invokeNodeToolPayload({ node: r, params: n, command: "file.fetch", commandParams: { path: i, maxBytes: Math.max(1, Math.min(a, FILE_FETCH_HARD_MAX_BYTES)) }, requestedPath: i }); const { canonicalPath: c, size: l, mimeType: u, base64: d, sha256: f, buffer: p } = decodeFetchPayload("file.fetch", s); const m = await saveMediaBuffer(p, u, FILE_TRANSFER_SUBDIR, FILE_FETCH_HARD_MAX_BYTES, c); const h = m.path; const g = f.slice(0, 12); const _ = IMAGE_MIME_INLINE_SET.has(u) && d.length > 0; const v = l <= 8192 && (u.startsWith("text/") || u === "application/json" || u === "application/xml" || u === "application/yaml"); let y = `Fetched ${c} (${humanSize(l)}, ${u}, sha256:${g}) saved at ${h}\nmediaId: ${m.id}`; if (v) { const e = p.toString("utf-8"); const t = e.startsWith("") ? e.slice(1) : e; y += `\n\n--- contents ---\n${t}`; } const b = [{ type: "text", text: wrapExternalContent(y, { source: "unknown" }) }]; if (_) b.push({ type: "image", data: d, mimeType: u }); await o({ canonicalPath: c, decision: "allowed", sizeBytes: l, sha256: f }); return { content: b, details: { path: c, size: l, mimeType: u, sha256: f, localPath: h, mediaId: m.id, media: { mediaUrls: [h] } } }; } }; } //#endregion export { createFileFetchTool };