eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 3 kB
JavaScript
import{AI_GATEWAY_API_KEY_ENV_VAR}from"../ai-gateway-api-key.js";import{interactiveAsker,withAnswers}from"../ask.js";import{detectProjectIdentity}from"../project-resolution.js";import{withSpinner}from"../with-spinner.js";import{snapshotSetupState}from"../state.js";import{detectAiGateway,findEnvFileWithKey}from"../boxes/detect-ai-gateway.js";import{applyAiGatewayCredential}from"../boxes/apply-ai-gateway-credential.js";import{linkVercelProject}from"../boxes/link-project.js";import{resolveProvisioning}from"../boxes/resolve-provisioning.js";import{WizardCancelledError}from"../step.js";import{runInteractive}from"../runner.js";import{inProjectSetupState,prompterSink}from"./in-project.js";import pc from"#compiled/picocolors/index.js";import{hasEnvValue,resolveGatewayCredential}from"#internal/resolve-model-endpoint-status.js";async function runLinkFlow(e){let{appRoot:t,prompter:n,signal:r,projectSelection:i=`existing-only`}=e,a={detectProjectIdentity,findEnvFileWithKey,env:process.env,...e.deps},o=await withSpinner(n,`Checking the current Vercel link...`,async()=>{let e=await a.detectProjectIdentity(t,{signal:r});return r?.throwIfAborted(),e});if(o===void 0){let[r,i]=await Promise.all([a.findEnvFileWithKey(t,AI_GATEWAY_API_KEY_ENV_VAR),a.findEnvFileWithKey(t,`VERCEL_OIDC_TOKEN`)]),o=r??i;o!==void 0&&e.teamSelectMessage===void 0&&n.log.message(`This directory is not linked to a Vercel project yet — the model currently runs on credentials from ${o}.`)}else{let e=o.teamName===void 0?pc.bold(o.projectName):`${pc.bold(o.projectName)} in ${pc.bold(o.teamName)}`;try{if(await n.select({message:`This directory is already linked to\n${e}`,options:[{value:`relink`,label:`Link to another project`},{value:`dismiss`,label:`Dismiss`}]})===`dismiss`)return{kind:`cancelled`}}catch(e){if(e instanceof WizardCancelledError)return{kind:`cancelled`};throw e}}let s=inProjectSetupState(t,{kind:`unresolved`}),c=[resolveProvisioning({asker:withAnswers({deploy:`vercel`})(interactiveAsker(n)),prompter:n,targetDirectory:t,mode:{headless:!1},adoptExistingLink:!1,projectSelection:i,teamSelectMessage:e.teamSelectMessage,deps:a.resolveProvisioning}),linkVercelProject({prompter:n,deps:a.linkProject}),detectAiGateway(),applyAiGatewayCredential({prompter:n,deps:a.applyAiGatewayCredential})];if((await runInteractive(c,s,prompterSink(n),{snapshot:snapshotSetupState,signal:r})).kind===`cancelled`)return{kind:`cancelled`};let[l,u]=await Promise.all([a.findEnvFileWithKey(t,`VERCEL_OIDC_TOKEN`),a.findEnvFileWithKey(t,AI_GATEWAY_API_KEY_ENV_VAR)]);r?.throwIfAborted(),l===void 0&&u===void 0&&n.log.warning("Linked, but no model credential landed in an env file (VERCEL_OIDC_TOKEN or AI_GATEWAY_API_KEY). Run `vercel env pull` once the project has AI Gateway access.");let d={kind:`done`},f={apiKeyInEnv:hasEnvValue(a.env[AI_GATEWAY_API_KEY_ENV_VAR])};u!==void 0&&(f.apiKeyFile=u),l!==void 0&&(f.oidcFile=l);let p=resolveGatewayCredential(f);return p!==void 0&&(d.resolution=p),d}export{runLinkFlow};