openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.73 kB
JavaScript
import{lt as e,xt as t}from"./git-operation.worker.js";import{a as n,i as r,n as i,r as a}from"./git-operation.worker-workspace-hash-memo-B4uJ3zCg.mjs";import{a as o,d as s,o as c}from"./git-operation.worker-workspace-manifest-Zk1wvpHZ.mjs";import{a as l,i as u,n as d,r as f,t as p}from"./git-operation.worker-workspace-manifest-comparison-B0otBJpG.mjs";import{createHash as m}from"node:crypto";import{deserialize as h}from"node:v8";import{zstdDecompressSync as g}from"node:zlib";function applyWorkspaceSourceOverlay(e,t,n){let r=f(e),i=f(n),a=f(t),o=p(r,i),c=new Set([...o].filter(e=>i.get(e)?.type!==`directory`&&(i.has(e)||r.get(e)?.type!==`directory`)));for(let e of a.keys())(o.has(e)||d(c,e))&&a.delete(e);for(let e of o){let t=i.get(e);t&&a.set(e,t)}for(let e of a.keys())for(let t of[...s(e)].toReversed())a.set(t,{path:t,type:`directory`});return{version:1,baseCommit:n.baseCommit,entries:[...a.values()].filter(e=>e.type===`file`||e.type===`symlink`),directories:[...a.values()].flatMap(e=>e.type===`directory`?[e.path]:[])}}function decodeUtf8(e){return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`utf8`)}function decodeManifestValue(e){return JSON.parse(decodeUtf8(e.input.payload))}async function withHashes(e,t){let o={contentHashCount:0,memoHitCount:0};if(!e)return{value:await n(t),hashes:[],metrics:o};let s=new Map(e.entries),c=new Map(s),l=await(e.owner===`worker`?a(c,t,o):r(c,t,o));return i(c),{value:l,hashes:[...c].filter(([e,t])=>s.get(e)!==t),metrics:o}}async function executeWorkspaceManifestComputation(n,r){switch(n.type){case`workspace.manifest.local`:{let{executeLocalWorkspaceManifestRead:e}=await import(`./git-operation.worker-local-workspace-manifest-scan-B9tzLfSl.mjs`),t=n.input.snapshot;return await e(...h(g(t)))}case`workspace.manifest.base-refresh`:{let{readActualWorkspaceManifestImpl:e}=await import(`./git-operation.worker-workspace-actual-manifest-CCtoh4gL.mjs`).then(e=>e.i),t=n.input;return await withHashes(t.hashes,async()=>{let{manifest:n}=await e({root:t.beforeRoot,baseCommit:t.baseCommit}),{manifest:r}=await e({root:t.afterRoot,baseCommit:t.baseCommit}),i=o(decodeUtf8(t.baseRaw),t.baseRef,t.buildCacheInputs),a=applyWorkspaceSourceOverlay(n,i,r);a.buildCacheInputs=[.../* @__PURE__ */ new Set([...t.buildCacheInputs,...r.entries.map(e=>e.path)])];let s=f(n),u=f(a);for(let[e,n]of f(i))if(!s.has(e)&&!l(n,u.get(e)))throw Error(`The selected base conflicts with saved workspace data at ${e}; move that saved file before retrying ${t.action}.`);let d=c(a);return{rawManifest:d,manifestRef:`sha256:${m(`sha256`).update(d).digest(`hex`)}`,buildCacheInputs:a.buildCacheInputs}})}case`workspace.manifest.equal`:{let e=n.input,t=f(o(decodeUtf8(e.baseRaw),e.baseRef,e.buildCacheInputs)),r=f(o(decodeUtf8(e.currentRaw),e.currentRef,e.buildCacheInputs));return t.size===r.size&&[...t].every(([e,t])=>l(t,r.get(e)))}case`workspace.manifest.remote-capture`:{let{captureNodeWorkspaceManifestImpl:e}=await import(`./git-operation.worker-workspace-manifest-script.runtime-rfHrwlVv.mjs`);return await e(n.input,r)}case`workspace.manifest.nodes`:{let{localWorkspaceNode:e}=await import(`./git-operation.worker-workspace-reconcile-fs-BmK2VKZq.mjs`),r=decodeManifestValue(n);return await withHashes(r.hashes,async()=>{let n=await t({tasks:r.paths.map(t=>async()=>[t,await e(r.root,t)]),limit:4,errorMode:`stop`});if(n.hasError)throw n.firstError;return n.results})}case`workspace.manifest.staged`:{let{loadStagedWorkerWorkspace:e}=await import(`./git-operation.worker-workspace-result-inventory.runtime-CEwb8ZsP.mjs`);return await e(n.input.root,n.input.ref,n.input.buildCacheInputs)}case`workspace.manifest.stage-input`:{let{buildWorkspaceStageInput:e}=await import(`./git-operation.worker-workspace-result-preparation.runtime-C5wzKgmZ.mjs`);return await e(n.input,r)}case`workspace.manifest.tree-input`:{let{buildWorkspaceTreeInput:e}=await import(`./git-operation.worker-workspace-result-preparation.runtime-C5wzKgmZ.mjs`);return await e(decodeManifestValue(n),r)}case`workspace.manifest.entries`:{let{readStagedWorkerWorkspaceEntries:t}=await import(`./git-operation.worker-workspace-result-inventory.runtime-CEwb8ZsP.mjs`);return e(await t(n.input))}case`workspace.manifest.capture`:case`workspace.manifest.snapshot`:case`workspace.manifest.document`:case`workspace.manifest.reference`:{let{readActualWorkspaceManifestImpl:e}=await import(`./git-operation.worker-workspace-actual-manifest-CCtoh4gL.mjs`).then(e=>e.i),t=decodeManifestValue(n),r=await withHashes(t.hashes,()=>e({...t,includePaths:t.includePaths&&new Set(t.includePaths),gitIgnore:t.gitIgnore&&{paths:new Set(t.gitIgnore.paths),retainedPaths:new Set(t.gitIgnore.retainedPaths)},buildCacheInputs:t.buildCacheInputs&&new Set(t.buildCacheInputs),preserveDirectories:t.preserveDirectories&&new Set(t.preserveDirectories)}));if(n.type===`workspace.manifest.document`){let{manifestRef:e,rawManifest:t}=r.value;return{...r,value:{manifestRef:e,rawManifest:t}}}return n.type===`workspace.manifest.reference`?{...r,value:r.value.manifestRef}:n.type===`workspace.manifest.snapshot`?r:{...r,value:{manifest:r.value.manifest,manifestRef:r.value.manifestRef}}}case`workspace.manifest.file`:{let{readWorkspaceFileSnapshotWithLimit:e}=await import(`./git-operation.worker-workspace-actual-manifest-CCtoh4gL.mjs`).then(e=>e.i),t=decodeManifestValue(n);return await withHashes(t.hashes,()=>e(t.path,t.maxBytes,t.root))}case`workspace.reconcile.preflight`:{let{preflightWorkspaceApplyImpl:e}=await import(`./git-operation.worker-workspace-reconcile-preflight-4_MI0Oww.mjs`),t=decodeManifestValue(n);return await withHashes(t.hashes,()=>e(t))}case`workspace.manifest.paths`:{let e=n.input,t=o(decodeUtf8(e.raw),e.expectedRef,e.buildCacheInputs);return/* @__PURE__ */ new Set([...t.directories??[],...t.entries.map(e=>e.path)])}case`workspace.manifest.parse`:{let e=decodeUtf8(n.input.raw),t=n.input.expectedRef??`sha256:${m(`sha256`).update(e).digest(`hex`)}`;return{manifest:o(e,t),manifestRef:t}}case`workspace.manifest.overlay`:{let e=decodeManifestValue(n),t=c(applyWorkspaceSourceOverlay(e.source,e.prepared,e.incoming)),r=`sha256:${m(`sha256`).update(t).digest(`hex`)}`;return{manifest:o(t,r),manifestRef:r}}case`workspace.manifest.serialize`:{let e=decodeManifestValue(n),t=c(e.manifest);return{raw:t,manifestRef:`sha256:${m(`sha256`).update(t).digest(`hex`)}`}}case`workspace.manifest.pair`:{let e=decodeUtf8(n.input.baseRaw),t=decodeUtf8(n.input.currentRaw),r=o(e,n.input.baseRef,n.input.buildCacheInputs),i=o(t,n.input.currentRef,n.input.buildCacheInputs),a=u(r,i);return{base:r,current:i,...a,paths:a.entries.map(e=>e.path)}}}throw Error(`Unsupported workspace computation`)}export{executeWorkspaceManifestComputation};