UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) • 1.87 kB
import { createHash } from "node:crypto"; import { serialize } from "node:v8"; import { deflateRawSync, zstdCompressSync, zstdDecompressSync } from "node:zlib"; //#region src/gateway/worker-environments/local-workspace-cas.ts const LOCAL_WORKSPACE_CONTENT_BATCH = 256; function localWorkspaceDigestBytes(e) { if (!/^sha256:[a-f0-9]{64}$/u.test(e)) throw new Error("Invalid local workspace tree digest"); return Uint8Array.from(Buffer.from(e.slice(7), "hex")); } function localWorkspaceDigestReference(e) { return `sha256:${Buffer.from(e).toString("hex")}`; } function encodeLocalWorkspaceTreePacks(e, t) { const n = /* @__PURE__ */ new Set([""]); if (t === void 0) { for (const t of e.values()) if (t.children !== null) n.add(t.children); } else for (const r of t) { if (r === "") continue; const t = r.slice(0, Math.max(0, r.lastIndexOf("/"))); const i = e.get(t)?.children; if (i != null) n.add(i); } return [...n].map((t) => { const n = e.get(t); const r = []; const i = []; const a = [n]; while (a.length) { const t = a.pop(); r.push(t); if (t.children !== null) i.push(e.get(t.children).treeRef); for (const n of [t.left, t.right]) if (n !== null) a.push(e.get(n)); } return { treeRef: n.treeRef, records: r, children: i }; }); } function prepareLocalWorkspaceTreePacks(e, t) { const n = encodeLocalWorkspaceTreePacks(e, t); const r = []; for (let e = 0; e < n.length; e += 256) r.push(deflateRawSync(serialize({ packs: n.slice(e, e + 256) }))); return r; } function prepareLocalWorkspaceSourcePathSet(e) { return { digest: `sha256:${createHash("sha256").update(e).digest("hex")}`, compressed: zstdCompressSync(Buffer.from(e)) }; } //#endregion export { prepareLocalWorkspaceTreePacks as i, localWorkspaceDigestReference as n, prepareLocalWorkspaceSourcePathSet as r, localWorkspaceDigestBytes as t };