UNPKG

eve

Version:

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

1 lines 1.71 kB
import{authJson}from"./vercel.js";import{DEVELOPMENT_MODEL_CREDENTIAL_ROUTE,DEVELOPMENT_MODEL_REJECTED_HEADER}from"./development-broker-protocol.js";import{createHash}from"node:crypto";import{isLoopbackHostname}from"#shared/network-address.js";import{isEveDevEnvironment}from"#internal/application/dev-environment.js";import{DEVELOPMENT_WORKFLOW_SECRET_ENV,DEVELOPMENT_WORKFLOW_TRANSPORT_HEADER}from"#internal/workflow/development-world-protocol.js";function developmentModelBrokerAvailable(){return isEveDevEnvironment()&&!!(process.env.EVE_DEV_CONTROL_URL&&process.env[DEVELOPMENT_WORKFLOW_SECRET_ENV])}async function readDevelopmentModelCredential(e,t,n){if(!developmentModelBrokerAvailable())return;let r=new URL(DEVELOPMENT_MODEL_CREDENTIAL_ROUTE,process.env.EVE_DEV_CONTROL_URL);if(!isLoopbackHostname(r.hostname)||r.protocol!==`http:`||r.username||r.password)throw Error(`The local model connection is unavailable. Restart eve dev.`);r.searchParams.set(`provider`,e);let i={[DEVELOPMENT_WORKFLOW_TRANSPORT_HEADER]:process.env[DEVELOPMENT_WORKFLOW_SECRET_ENV]};t&&(i[DEVELOPMENT_MODEL_REJECTED_HEADER]=createHash(`sha256`).update(t).digest(`hex`));let a=await authJson(r.href,{headers:i,signal:n},256e3,75e3);if(typeof a.token!=`string`||!a.token||![`api-key`,`oauth`,`oidc`].includes(String(a.kind)))throw Error(`The model connection is unavailable. Run /login to reconnect.`);return{kind:a.kind,token:a.token,...typeof a.teamId==`string`&&{teamId:a.teamId},...typeof a.teamName==`string`&&{teamName:a.teamName},...typeof a.accountId==`string`&&{accountId:a.accountId},...typeof a.accountLabel==`string`&&{accountLabel:a.accountLabel}}}export{developmentModelBrokerAvailable,readDevelopmentModelCredential};