UNPKG

eve

Version:

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

1 lines 1.75 kB
import{appendEnv}from"../append-env.js";import{AI_GATEWAY_API_KEY_ENV_FILE,AI_GATEWAY_API_KEY_ENV_VAR,writeAiGatewayApiKey}from"../ai-gateway-api-key.js";import{isProjectResolved}from"../project-resolution.js";import{runVercelEnvPull}from"../run-vercel-link.js";import{withSpinner}from"../with-spinner.js";import{requireProjectPath}from"../state.js";import{detectAiGatewayResolution}from"./detect-ai-gateway.js";import{createPromptCommandOutput}from"#setup/cli/index.js";function applyAiGatewayCredential(e){let t=e.deps??{appendEnv,runVercelEnvPull,detectAiGatewayResolution};return{id:`apply-ai-gateway-credential`,shouldRun(e){let{aiGateway:t,project:n}=e;return t.kind===`byok`||t.kind===`inherit`&&isProjectResolved(n)},async gather(){return null},async perform({state:n,signal:r}){let{prompter:i}=e,a=requireProjectPath(n),o=n.aiGateway,s=isProjectResolved(n.project);if(o.kind===`byop`)return{kind:`unresolved`};if(o.kind===`byok`){let n=await writeAiGatewayApiKey({projectRoot:a,apiKey:o.apiGatewayKey,appendEnv:t.appendEnv});return e.prompter.log.success(`Wrote ${n.envKey} to ${n.envPath}`),{kind:`api-key`,envFile:n.envFile}}if(!s)return i.log.warning(`No Vercel project linked and no API key provided. The agent will not reach a model until you set ${AI_GATEWAY_API_KEY_ENV_VAR} in ${AI_GATEWAY_API_KEY_ENV_FILE} or link a project.`),{kind:`unresolved`};let c=createPromptCommandOutput(i.log),l=await withSpinner(i,`Pulling Vercel environment variables into .env.local...`,()=>t.runVercelEnvPull(a,c,r));return r?.throwIfAborted(),l||i.log.warning(`Linked the project, but pulling environment variables did not complete.`),t.detectAiGatewayResolution(a)},apply(e,t){return{...e,aiGatewayCredentials:t}}}}export{applyAiGatewayCredential};