openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.73 kB
JavaScript
import{i as e,r as t}from"./git-operation.worker-staged-inputs-DZiTgX91.mjs";import{C as n,S as r,d as i,g as a,h as o,i as s,u as c}from"./git-operation.worker-workspace-manifest-DsRMcvMP.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 r=e(n.entries),a=c(n.buildCacheInputs),o=/* @__PURE__ */ new Map;for(let e of n.directories??[])i(e,a.has(e)||t(e,r),n.buildCacheInputs!==void 0)||o.set(e,{path:e,type:`directory`});for(let e of n.entries)i(e.path,a.has(e.path)||t(e.path,r),n.buildCacheInputs!==void 0)||o.set(e.path,e);return o}function hasPathAncestor(e,t){for(let n of a(t))if(e.has(n))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:n,currentNodes:r}={baseNodes:manifestNodes(e),currentNodes:manifestNodes(t)}){let i=diffNodePaths(n,r),o=new Set(i);for(let e of i)for(let t of a(e))o.add(t);let s={baseNodes:[],currentNodes:[],changedPaths:[...i],buildCacheInputs:e.buildCacheInputs===void 0&&t.buildCacheInputs===void 0?void 0:[...c([...e.buildCacheInputs??[],...t.buildCacheInputs??[]])]};for(let e of o){let t=n.get(e),i=r.get(e);t&&s.baseNodes.push([e,t]),i&&s.currentNodes.push([e,i])}return{preflight:s,includePaths:t.baseCommit?/* @__PURE__ */ new Set([...n.keys(),...r.keys()]):void 0}}function parseChangedWorkspaceResult(e,t,i=!0,{baseNodes:a,currentNodes:c}={baseNodes:manifestNodes(e),currentNodes:manifestNodes(t)}){let l=0,u=[],d=[];for(let e of c.values()){let t=a.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 a.keys())c.has(e)||l++;if(i&&l>5e4)throw new n(`Workspace result changes ${l} files/directories (limit ${r}).`);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+o(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 n(`Cloud workspace staged result exceeds its byte limit: `+f+` bytes across `+u.length+` changed files/symlinks; `+s+` 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};