UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

78 lines (77 loc) • 2.95 kB
import { E as parseStrictNonNegativeInteger } from "./number-coercion-D6u-4YD8.mjs"; import { r as textResult } from "./tool-results-CcV0sxnb.mjs"; import "./number-runtime-W4chuk8B.mjs"; import { n as DIR_LIST_HARD_MAX_ENTRIES, r as DIR_LIST_TOOL_DESCRIPTOR } from "./descriptors-CZtmxLD2.mjs"; import { i as readClampedInt, n as readRequiredNodePath, t as invokeNodeToolPayload } from "./node-tool-invoke-DIC-uNGI.mjs"; import { t as renderDirectoryText } from "./directory-text-BSWL301l.mjs"; //#region extensions/file-transfer/src/tools/dir-list-tool.ts function createDirListTool() { return { ...DIR_LIST_TOOL_DESCRIPTOR, execute: async (e, t) => { const n = t; const { node: r, requestedPath: i } = readRequiredNodePath(n); const a = readClampedInt({ input: n, key: "maxEntries", defaultValue: 200, hardMax: DIR_LIST_HARD_MAX_ENTRIES }); const o = typeof n.pageToken === "string" && n.pageToken.trim() ? n.pageToken.trim() : void 0; const { audit: s, payload: c } = await invokeNodeToolPayload({ node: r, params: n, command: "dir.list", commandParams: { path: i, pageToken: o, maxEntries: a }, requestedPath: i }); const l = typeof c.path === "string" ? c.path : i; const u = Array.isArray(c.entries) ? c.entries : []; const d = c.truncated === true; const f = typeof c.nextPageToken === "string" ? c.nextPageToken : void 0; await s({ canonicalPath: l, decision: "allowed" }); const p = parseStrictNonNegativeInteger(o) ?? 0; const m = JSON.stringify({ path: l, returnedCount: u.length }).slice(0, -1); const h = renderDirectoryText({ entries: u, project: ({ name: e, isDir: t, size: n }) => ({ name: e, isDir: t, size: n }), render: (e) => { const t = e.length < u.length; const n = t ? e.length > 0 ? String(p + e.length) : void 0 : f; const r = JSON.stringify({ truncated: t || d, nextPageToken: n }); const i = `${m},"displayedCount":${e.length},"entries":[${e.join(",")}],${r.slice(1)}`; return { manifest: i, text: `${i}\n${t && e.length === 0 ? "No entries displayed: the next complete entry or directory metadata exceeds the text budget or contains reserved markers. Pagination cannot advance; use available node-local directory capabilities." : (t || d) && !n ? "More entries available; the node supplied no continuation token." : "If present, pass nextPageToken as pageToken; keep node and path."}` }; }, fallback: "Directory listing omitted: the resolved path or continuation metadata cannot be represented safely within the 8192-byte text limit. No usable paths or continuation token are shown; use available node-local directory capabilities." }); return textResult(h, { path: l, entries: u, nextPageToken: f, truncated: d }); } }; } //#endregion export { createDirListTool };