UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.19 kB
import{o as e}from"./openclaw-state-read-logger-Ix7jXPG1.mjs";import{v as t}from"./openclaw-state-read-read-open-flags-CtNL1rJs.mjs";import{n}from"./openclaw-state-read-fs-safe-CpAHBauR.mjs";import{a as r,c as i,j as a,r as o}from"./openclaw-state-read-workspace-path-exclusions-Cjo9Lmns.mjs";import"./openclaw-state-read-workspace-manifest-B5vKGqPY.mjs";import{i as s,n as c,r as l}from"./openclaw-state-read-workspace-reconcile-fs-D0L5ne7X.mjs";import{n as u,o as d}from"./openclaw-state-read-workspace-manifest-comparison-BsGOV5Ve.mjs";import{lstatSync as f}from"node:fs";import p from"node:fs/promises";async function localWorkspaceDescendantPaths(e,t,n,i,a){let s=[],c=[...t],d=0,f=0;for(;c.length>0;){let t=c.pop(),m=[];for await(let n of await p.opendir(l(e,t)))if(m.push(n.name),f+=1,f>25e4)throw Error(`Gateway workspace manifest has too many entries`);for(let f of m.toSorted()){let m=`${t}/${f}`;if(d+=Buffer.byteLength(m),d>67108864)throw Error(`Gateway workspace manifest paths exceed their byte limit`);if(r(m)){u(i,m)&&s.push(m);continue}if(o(m,await n(m),a))continue;s.push(m);let h=await p.lstat(l(e,m));h.isDirectory()&&!h.isSymbolicLink()&&c.push(m)}}return s}async function preflightWorkspaceApplyImpl(o){let m=o.buildCacheInputs!==void 0,h=a(await n(o.root)),g=new Set(o.buildCacheInputs),isRetainedInput=async e=>g.has(e)||await h(e),_=new Map(o.baseNodes),v=new Map(o.currentNodes),y=new Set(o.changedPaths),b=new Set([...y].filter(e=>_.get(e)?.type===`directory`&&v.get(e)?.type!==`directory`)),x=[...b].filter(e=>!u(b,e)),S=[];for(let e of x){let t=await p.lstat(l(o.root,e)).catch(()=>void 0);t?.isDirectory()&&!t.isSymbolicLink()&&S.push(e)}let C=await localWorkspaceDescendantPaths(o.root,S,isRetainedInput,new Set(x.filter(e=>v.has(e))),m),w=[.../* @__PURE__ */ new Set([...y,...C])].toSorted(),T=/* @__PURE__ */ new Set,E=/* @__PURE__ */ new Set,D=/* @__PURE__ */ new Set,O=/* @__PURE__ */ new Map,localNode=t=>e(O,t,()=>s(o.root,t));for(let e of w){if(u(D,e))continue;if(v.get(e)===void 0)try{if(!f(l(o.root,e),{throwIfNoEntry:!1}))continue}catch(e){if(t(e,`ENOENT`)||t(e,`ENOTDIR`))continue;throw e}let n=!1,a=!1;for(let t of i(e)){let e=_.get(t),r=v.get(t);if(!e&&!r){let e=await localNode(t);if(e&&e.type!==`directory`){E.add(t),D.add(t),n=!0;break}continue}let i=await localNode(t);if(!d(i,e)&&!d(i,r)){E.add(t),D.add(t),n=!0;break}e&&e.type!==`directory`&&!d(e,r)&&d(i,e)&&(a=!0)}if(n)continue;let s;if(a?s=void 0:(s=await localNode(e),s?.type!==`directory`||r(e)||_.has(e)&&v.has(e)||v.get(e)?.type===`directory`||!await c(o.root,e,isRetainedInput,void 0,m)||(s=void 0)),d(s,_.get(e)))y.has(e)&&T.add(e);else if(!d(s,v.get(e))){E.add(e);let t=v.get(e);(t?.type===`directory`&&s!==void 0&&s.type!==`directory`||t!==void 0&&t.type!==`directory`&&s?.type===`directory`)&&D.add(e)}}let k=[...E];for(let e of k)for(let t of i(e)){let e=v.get(t);if(y.has(t)&&e&&e.type!==`directory`){E.add(t),D.add(t);break}}let A=[...E].filter(e=>!u(D,e)).toSorted(),j=[...D].filter(e=>!u(D,e)).toSorted(),M=new Set(A),N=new Set(j);for(let e of T)(M.has(e)||u(N,e))&&T.delete(e);return{applyPaths:T,conflictPaths:A,blockingConflictPaths:j}}export{preflightWorkspaceApplyImpl};