UNPKG

eve

Version:

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

1 lines • 1.73 kB
import{AgentInfoResponseError,ClientError}from"#client/index.js";import{isObject}from"#shared/guards.js";import{toErrorMessage}from"#shared/errors.js";import{formatVercelTrustedSourcesFailure,isVercelAuthChallenge,vercelTrustedSourcesErrorCode}from"#services/dev-client/vercel-auth-error.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";function isEveOidcChallenge(e){if(!(e instanceof ClientError)||e.status!==401)return!1;try{let t=JSON.parse(e.body);return isObject(t)&&t.ok===!1&&t.code===`unauthorized`&&t.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 t=await e.health();return isObject(t)&&t.ok===!0}catch{return!1}}async function probeRemoteInfo(e){let t=await probeAgentInfo({client:e.client});if(t.kind===`ready`)return{state:`ready`,info:t.info};let{error:n}=t;return(n instanceof AgentInfoResponseError||n instanceof ClientError&&n.status===404)&&await probeDeploymentHealth(e.client)?{state:`ready`}:classifyRemoteError(n,e.phase)}export{classifyRemoteError,probeRemoteInfo};