openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.74 kB
JavaScript
import{M as e,N as t,c as n,n as r,r as i,s as a}from"./openclaw-state-read-workspace-path-exclusions-Cjo9Lmns.mjs";import{i as o,m as s,p as c}from"./openclaw-state-read-workspace-manifest-B5vKGqPY.mjs";function sameEntry(e,t){if(e===t)return!0;if(!e||!t||e.path!==t.path||e.type!==t.type)return!1;switch(e.type){case`file`:return t.type===`file`&&e.mode===t.mode&&e.size===t.size&&e.sha256===t.sha256;case`symlink`:return t.type===`symlink`&&e.mode===t.mode&&e.target===t.target;default:return!0}}function manifestNodes(n){let a=t(n.entries),o=r(n.buildCacheInputs),s=/* @__PURE__ */ new Map;for(let t of n.directories??[])i(t,o.has(t)||e(t,a),n.buildCacheInputs!==void 0)||s.set(t,{path:t,type:`directory`});for(let t of n.entries)i(t.path,o.has(t.path)||e(t.path,a),n.buildCacheInputs!==void 0)||s.set(t.path,t);return s}function hasPathAncestor(e,t){for(let r of n(t))if(e.has(r))return!0;return!1}function diffNodePaths(e,t){let n=/* @__PURE__ */ new Set;for(let r of e.values())sameEntry(r,t.get(r.path))||n.add(r.path);for(let r of t.keys())e.has(r)||n.add(r);return n}function prepareWorkspaceReconciliation(e,t,{baseNodes:i,currentNodes:a}={baseNodes:manifestNodes(e),currentNodes:manifestNodes(t)}){let o=diffNodePaths(i,a),s=new Set(o);for(let e of o)for(let t of n(e))s.add(t);let c={baseNodes:[],currentNodes:[],changedPaths:[...o],buildCacheInputs:e.buildCacheInputs===void 0&&t.buildCacheInputs===void 0?void 0:[...r([...e.buildCacheInputs??[],...t.buildCacheInputs??[]])]};for(let e of s){let t=i.get(e),n=a.get(e);t&&c.baseNodes.push([e,t]),n&&c.currentNodes.push([e,n])}return{preflight:c,includePaths:t.baseCommit?/* @__PURE__ */ new Set([...i.keys(),...a.keys()]):void 0}}function parseChangedWorkspaceResult(e,t,n=!0,{baseNodes:r,currentNodes:i}={baseNodes:manifestNodes(e),currentNodes:manifestNodes(t)}){let l=0,u=[],d=[];for(let e of i.values()){let t=r.get(e.path);sameEntry(t,e)||(l++,e.type!==`directory`&&(u.push(e),!t&&e.type===`file`&&e.size>0&&d.push(e)))}for(let e of r.keys())i.has(e)||l++;if(n&&l>5e4)throw new s(`Workspace result changes ${l} files/directories (limit ${c}).`);let f=0;for(let e of u){if(e.type===`file`&&e.size>67108864)throw Error(`Cloud workspace result is too large: `+e.path+a(e.path));f+=e.type===`file`?e.size:Buffer.byteLength(e.target)}if(f>805306368){let e=d.toSorted((e,t)=>t.size-e.size).slice(0,5);throw new s(`Cloud workspace staged result exceeds its byte limit: `+f+` bytes across `+u.length+` changed files/symlinks; `+o+` byte limit.
Largest new files: `+JSON.stringify(e.map(e=>e.path))+`
`)}return{changed:l>0,entries:u}}export{prepareWorkspaceReconciliation as a,parseChangedWorkspaceResult as i,hasPathAncestor as n,sameEntry as o,manifestNodes as r,diffNodePaths as t};