UNPKG

eve

Version:

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

1 lines 2.81 kB
import{interactiveAsker,withAnswers}from"../ask.js";import{detectDeployment,isProjectResolved,projectResolutionFromDeployment}from"../project-resolution.js";import{withSpinner}from"../with-spinner.js";import{snapshotSetupState}from"../state.js";import{deployProject}from"../boxes/deploy-project.js";import{linkVercelProject}from"../boxes/link-project.js";import{resolveProvisioning}from"../boxes/resolve-provisioning.js";import{runHeadless,runInteractive}from"../runner.js";import{inProjectSetupState,prompterSink}from"./in-project.js";import{runInstallVercelCliFlow}from"./install-vercel-cli.js";import{runLoginFlow}from"./login.js";import{inspectApplication}from"#services/inspect-application.js";import{isChatGptModelRouting}from"#shared/chatgpt-model.js";function productionUrlOf(e){return e.kind===`deployed`?e.productionUrl:void 0}async function runDeployFlow(e){let{appRoot:t,prompter:n,interactive:r,signal:i}=e,a={detectDeployment,inspectApplication,runLoginFlow,runInstallVercelCliFlow,...e.deps};try{let e=(await a.inspectApplication(t)).compiledState?.manifest.config.model?.routing;if(isChatGptModelRouting(e))return{kind:`local-model`}}catch{}let o=await withSpinner(n,`Checking the current Vercel link...`,async()=>{let e=await a.detectDeployment(t,{signal:i});return i?.throwIfAborted(),projectResolutionFromDeployment(e)}),s=isProjectResolved(o);if(!s&&!r)return{kind:`needs-link`};if(r){let e=await a.runLoginFlow({appRoot:t,prompter:n,signal:i});if(e.kind===`cli-missing`){let r=await a.runInstallVercelCliFlow({appRoot:t,prompter:n,signal:i});if(r.kind===`cancelled`)return{kind:`cancelled`};if(r.kind===`failed`)throw Error("Could not install the Vercel CLI. Install it with `npm i -g vercel@latest`, then retry deployment.");e=await a.runLoginFlow({appRoot:t,prompter:n,signal:i})}if(e.kind===`cancelled`)return{kind:`cancelled`};if(e.kind!==`already`&&e.kind!==`logged-in`)throw Error(e.kind===`unavailable`?`Could not reach Vercel. Check your connection and retry deployment.`:`Vercel login did not complete. Retry deployment to sign in.`)}let c=inProjectSetupState(t,o,{deploymentPending:!0}),l=s?[deployProject({prompter:n,headless:!r,deps:a.deployProject})]:[resolveProvisioning({asker:withAnswers({deploy:`vercel`})(interactiveAsker(n)),prompter:n,targetDirectory:t,mode:{headless:!1},deps:a.resolveProvisioning}),linkVercelProject({prompter:n,deps:a.linkProject}),deployProject({prompter:n,headless:!r,deps:a.deployProject})],u=prompterSink(n);if(!r)return{kind:`deployed`,productionUrl:productionUrlOf((await runHeadless(l,c,u,{snapshot:snapshotSetupState,signal:i})).project)};let d=await runInteractive(l,c,u,{snapshot:snapshotSetupState,signal:i});return d.kind===`cancelled`?{kind:`cancelled`}:{kind:`deployed`,productionUrl:productionUrlOf(d.state.project)}}export{runDeployFlow};