UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.75 kB
import{resolveSelfModificationConfig}from"./config.js";import{createGitHubCredentialProvider}from"./credentials.js";import{resolveSelfModificationMode}from"./mode.js";import{SELF_MODIFICATION_BASELINE_NETWORK_POLICY}from"./network-policy.js";import{REPOSITORY_PATH,prepareSelfModificationWorkspace}from"./git-workspace.js";import{createSelfModificationFilesystem}from"./filesystem.js";import{shellQuote}from"#shared/shell-quote.js";import{SANDBOX_BACKEND_PROBES}from"#sandbox/backends/default.js";import{defaultBackend,defineSandbox}from"#public/sandbox/index.js";import{justbash}from"#public/sandbox/just-bash.js";import{microsandbox}from"#public/sandbox/microsandbox.js";import{vercel}from"#public/sandbox/vercel.js";function defineSelfModificationSandbox(e={}){let t=resolveSelfModificationConfig(e.config);return defineSandbox({backend:()=>{let n=resolveSelfModificationMode(t);return n===`local`?justbash({filesystem:createSelfModificationFilesystem}):n===`disabled`?e.backend??defaultBackend():selectDeployedSelfModificationBackend(e.backend,SANDBOX_BACKEND_PROBES)},async onSession({ctx:e,use:n}){if(resolveSelfModificationMode(t)!==`deployed`||t.deployed===void 0)return;if(e.session.parent===void 0)throw Error(`Production self-modification workspaces require a delegated child session.`);let r=t.deployed,i=await n();await i.setNetworkPolicy(SELF_MODIFICATION_BASELINE_NETWORK_POLICY);let a=await createGitHubCredentialProvider(r.credentials).resolve({capability:`checkout`,repository:r.repository});await prepareSelfModificationWorkspace({directory:r.directory,repository:r.repository,sandbox:i,targetBranch:r.targetBranch,token:a});let o=r.directory===`.`?REPOSITORY_PATH:`${REPOSITORY_PATH}/${r.directory}`;if((await i.run({command:`rm -rf /source && ln -s ${shellQuote(`${o}/agent`)} /source`})).exitCode!==0)throw Error(`Self-modification could not mount the production agent source.`)}})}function selectDeployedSelfModificationBackend(e,t){if(e!==void 0){if(e.name===`vercel`||e.name===`microsandbox`)return e;throw unsupportedBackend(e.name)}if(t.isDeployedOnVercel())return vercel({networkPolicy:SELF_MODIFICATION_BASELINE_NETWORK_POLICY});if(t.isMicrosandboxSupported())return microsandbox({networkPolicy:SELF_MODIFICATION_BASELINE_NETWORK_POLICY});throw unsupportedBackend()}function unsupportedBackend(e){let t=e===void 0?`No supported backend is available.`:`The configured ${e} backend does not support them.`;return Error(`Deployed self-modification requires runtime credential transforms. ${t} Use vercel() on Vercel or microsandbox() on a supported self-hosted system.`)}var sandbox_default=defineSelfModificationSandbox();export{sandbox_default as default,defineSelfModificationSandbox,selectDeployedSelfModificationBackend};