UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

7 lines • 5.16 kB
import{n as runtimeProcessEntrypoints}from"./runtime-process-entrypoints-Dnd1WskT.mjs";import{a as resolveRuntimeWorkerUrl,o as runtimeNeedsTypeScriptLoader,t as resolveRuntimeArgs}from"./runtime-worker-url-Dqf-I1cs.mjs";import"./workspace-access-GnBgOJqh.mjs";import"./workspace-bootstrap-policy-B71K4ysN.mjs";import{fileURLToPath}from"node:url";import path from"node:path"; //!src/agents/workspace-attachment-preparer.ts function createWorkspaceAttachmentPreparer(e){if(!path.posix.isAbsolute(e.remoteRoot)&&!path.win32.isAbsolute(e.remoteRoot))throw new Error(`Attachment workspace root must be absolute`);return async(t,n)=>{const{prepareWorkspaceAttachments:r}=await import(`./workspace-attachments-DkXQcxb-.mjs`);n();return await r({...e,turn:t,assertCurrent:n})}} //!src/agents/workspace-memory-client.ts function createWorkspaceMemoryFileClient(e){const t=path.resolve(e.workspaceDir);const n=path.posix.resolve(e.remoteWorkspaceDir);const outside=(e,t)=>e===`..`||e.startsWith(`..${t.sep}`)||t.isAbsolute(e);const host=e=>{const r=path.relative(t,e);return outside(r,path)?e:path.posix.join(n,...r.split(path.sep))};const gateway=e=>{const r=path.posix.relative(n,e);return outside(r,path.posix)?e:path.join(t,...r.split(`/`))};const extra=(e=[])=>e.map(e=>{const mapped=e=>path.isAbsolute(e)?host(e):e;return typeof e===`string`?mapped(e):{...e,path:mapped(e.path)}});async function call(t,n){e.signal.throwIfAborted();n?.();let r;try{const i=await e.request(JSON.stringify(t),e.signal,n);e.signal.throwIfAborted();r=JSON.parse(i)}catch(e){if(t.operation===`maintenance`&&t.method===`commitContent`)throw Object.assign(new Error(`Memory write outcome is unknown`,{cause:e}),{publication:`uncertain`});throw e}if(r.error)throw Object.assign(new Error(r.error.message),{...r.error.code?{code:r.error.code}:{},...r.error.name?{name:r.error.name}:{},...[`uncertain`,`committed`].includes(r.error.publication??``)?{publication:r.error.publication}:{}});return r.result}const maintain=(e,...t)=>call({operation:`maintenance`,method:e,args:t});return{maintenance:{readFile:async e=>Buffer.from(await maintain(`readFile`,host(e)),`base64`),stat:(e,t)=>maintain(`stat`,host(e),t),listDirectory:e=>maintain(`listDirectory`,host(e)),mkdir:e=>maintain(`mkdir`,host(e)),rename:(e,t)=>maintain(`rename`,host(e),host(t)),resolveWritePath:async e=>gateway(await maintain(`resolveWritePath`,host(e))),commitContent:e=>maintain(`commitContent`,{...e,filePath:host(e.filePath)}),resolveDreamsPath:async()=>gateway(await maintain(`resolveDreamsPath`)),readDreams:e=>maintain(`readDreams`,host(e)),writeDreams:(e,t,n,r)=>call({operation:`maintenance`,method:`writeDreams`,args:[host(e),t,...r?[r]:[]]},n),replaceReport:(e,t,n)=>maintain(`replaceReport`,host(e),t,...n?[n]:[]),appendCorpus:(e,t,n)=>call({operation:`maintenance`,method:`appendCorpus`,args:[host(e),t]},n)},assertCurrent:()=>e.signal.throwIfAborted(),async listFiles(e,t,n,r){const i=await call({operation:`list`,extraPaths:extra(t),multimodal:n});for(const e of i.skipped)r?.(gateway(e));return i.files.map(gateway)},async inspectFile(e,t,n){const r=await call({operation:`inspect`,filePath:host(e),multimodal:n});return r?{...r,absPath:gateway(r.absPath)}:null},readFile({workspaceDir:e,extraPaths:t,relPath:n,...r}){return call({operation:`read`,params:{...r,extraPaths:extra(t),relPath:path.isAbsolute(n)?host(n):n}})},readForIndexing:e=>call({operation:`readForIndexing`,filePath:host(e)}),buildMultimodalChunk:e=>call({operation:`multimodal`,entry:{...e,absPath:host(e.absPath)}}),async watch(t,n,r){const i=AbortSignal.any([e.signal,r]);i.throwIfAborted();const a={agentId:t.agentId,settings:{extraPaths:extra(t.settings.extraPaths),multimodal:t.settings.multimodal,sync:{watchDebounceMs:t.settings.sync.watchDebounceMs}}};await e.subscribe(`${JSON.stringify(a)}\n`,e=>{i.throwIfAborted();const t=JSON.parse(e);if(t!==`change`&&t!==`unavailable`)throw new Error(`Invalid Memory change notification`);n(t)},i);if(!i.aborted)n(`unavailable`)}}} //!src/agents/workspace-worker.ts function resolveWorkspaceWorkerUrl(e){return resolveRuntimeWorkerUrl(e===`memory`?runtimeProcessEntrypoints.workspaceMemory:runtimeProcessEntrypoints.workspaceSkills)}function resolveWorkspaceWorkerExecArgv(e){if(!runtimeNeedsTypeScriptLoader(fileURLToPath(resolveWorkspaceWorkerUrl(e)))&&!runtimeNeedsTypeScriptLoader(fileURLToPath(import.meta.url)))return resolveRuntimeArgs();const t=`import { register } from `+JSON.stringify(import.meta.resolve(`tsx/esm/api`))+`; register({ tsconfig: `+JSON.stringify(fileURLToPath(new URL(`../../tsconfig.json`,import.meta.url)))+` });`;return[`--import`,`data:text/javascript,${encodeURIComponent(t)}`]}function resolveWorkspaceWorkerArgv(e){return[...resolveWorkspaceWorkerExecArgv(e),fileURLToPath(resolveWorkspaceWorkerUrl(e))]}async function readWorkspaceSkillResources(...e){const{readSkillResourceFiles:t}=await import(`./resources-BTknTEjw.mjs`);return t(...e)}export{createWorkspaceMemoryFileClient as a,resolveWorkspaceWorkerUrl as i,resolveWorkspaceWorkerArgv as n,createWorkspaceAttachmentPreparer as o,resolveWorkspaceWorkerExecArgv as r,readWorkspaceSkillResources as t};