UNPKG

eve

Version:

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

1 lines 1.71 kB
import{probeAgentInfo}from"./agent-info-probe.js";import{isObject}from"#shared/guards.js";import{AgentInfoResponseError,ClientError}from"#client/index.js";import{toErrorMessage}from"#shared/errors.js";import{formatVercelTrustedSourcesFailure,isVercelAuthChallenge,vercelTrustedSourcesErrorCode}from"#services/dev-client/vercel-auth-error.js";function isEveOidcChallenge(e){if(!(e instanceof ClientError)||e.status!==401)return!1;try{let n=JSON.parse(e.body);return isObject(n)&&n.ok===!1&&n.code===`unauthorized`&&n.error===`Authorization is required for this route.`}catch{return!1}}function classifyRemoteError(e,t){if(isVercelAuthChallenge(e))return{state:`auth-required`,challenge:{kind:`vercel-deployment-protection`}};if(isEveOidcChallenge(e))return{state:`auth-required`,challenge:{kind:`eve-oidc`}};if(e instanceof ClientError){let n=vercelTrustedSourcesErrorCode(e.message);if(t===`connection-check`&&e.status===403&&n===`TRUSTED_SOURCES_ENVIRONMENT_MISMATCH`)return{state:`auth-required`,challenge:{kind:`vercel-deployment-protection`}};let r={message:formatVercelTrustedSourcesFailure(e.message)};return{state:`unavailable`,failure:n===void 0?r:{...r,code:n}}}return{state:`unavailable`,failure:{message:toErrorMessage(e)}}}async function probeDeploymentHealth(e){try{let n=await e.health();return isObject(n)&&n.ok===!0}catch{return!1}}async function probeRemoteInfo(t){let i=await probeAgentInfo({client:t.client});if(i.kind===`ready`)return{state:`ready`,info:i.info};let{error:a}=i;return(a instanceof AgentInfoResponseError||a instanceof ClientError&&a.status===404)&&await probeDeploymentHealth(t.client)?{state:`ready`}:classifyRemoteError(a,t.phase)}export{classifyRemoteError,probeRemoteInfo};