UNPKG

eve

Version:

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

1 lines 1.24 kB
import{SELF_MODIFICATION_BASELINE_NETWORK_POLICY}from"./network-policy.js";import{gitHubGitBrokerNetworkPolicy}from"#shared/git.js";const MAX_ERROR_OUTPUT=2e3;async function withBrokeredGitHubCredential(e,t,n){let r;try{await e.setNetworkPolicy(gitHubGitBrokerNetworkPolicy(t)),r={ok:!0,value:await n()}}catch(e){r={error:e,ok:!1}}try{await e.setNetworkPolicy(SELF_MODIFICATION_BASELINE_NETWORK_POLICY)}catch(e){throw Error(`Could not revoke the brokered GitHub credential from the sandbox.`,{cause:r.ok?e:AggregateError([r.error,e])})}if(!r.ok)throw r.error;return r.value}async function gitOutput(e,t,n=!0){let r=await e.run({command:t});if(r.exitCode!==0)throw gitCommandError(t,r);let i=String(r.stdout??``);return n?i.trim():i}async function runGitCommand(e,t){let n=await e.run({command:t});if(n.exitCode!==0)throw gitCommandError(t,n)}function gitCommandError(e,t){let n=truncate(String(t.stderr??``).trim()),r=truncate(String(t.stdout??``).trim());return Error([`Git command failed with exit ${t.exitCode}: ${e}`,n&&`stderr: ${n}`,r&&`stdout: ${r}`].filter(Boolean).join(`; `))}function truncate(e){return e.length<=MAX_ERROR_OUTPUT?e:`${e.slice(0,MAX_ERROR_OUTPUT)}…`}export{gitOutput,runGitCommand,withBrokeredGitHubCredential};