UNPKG

eve

Version:

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

1 lines 1.81 kB
import{VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER}from"#client/types.js";import{LOCAL_DEV_INTERACTIVE_CLIENT_HEADER}from"#runtime/local-dev-capability.js";function hasDevelopmentAuthorizationHeader(e){return e!==void 0&&Object.keys(e).some(e=>e.toLowerCase()===`authorization`)}async function resolveRemoteHeaders(e){if(!e.includeTrustedOidcHeader)return{...await e.credentials.resolveBypassHeaders(),...e.headers};let[t,n]=await Promise.all([e.credentials.resolveBypassHeaders(),e.credentials.resolveToken()]),r={...t,...e.headers},i=n.trim();return i.length>0&&(r[VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]=i),r}function resolveDevelopmentClientOptions(e){return{host:e}}function resolveLocalDevelopmentClientOptions(e){let t=e.interactiveClient===!0?{...e.headers,[LOCAL_DEV_INTERACTIVE_CLIENT_HEADER]:`1`}:e.headers,n={host:e.serverUrl,redirect:`manual`};if(hasDevelopmentAuthorizationHeader(t))return{...n,headers:t};let r={...n,auth:{bearer:e.token}};return t===void 0?r:{...r,headers:t}}function resolveRemoteDevelopmentClientOptions(e){let t=new URL(e.serverUrl).origin;if(e.credentials.serverOrigin!==t)throw Error(`Credential gate origin ${e.credentials.serverOrigin} does not match client origin ${t}.`);return hasDevelopmentAuthorizationHeader(e.headers)?{headers:()=>resolveRemoteHeaders({credentials:e.credentials,headers:e.headers,includeTrustedOidcHeader:!0}),host:e.serverUrl,redirect:`manual`}:{auth:{vercelOidc:{token:()=>e.credentials.resolveToken()}},headers:e.headers===void 0?e.credentials.resolveBypassHeaders:()=>resolveRemoteHeaders({credentials:e.credentials,headers:e.headers,includeTrustedOidcHeader:!1}),host:e.serverUrl,redirect:`manual`}}export{hasDevelopmentAuthorizationHeader,resolveDevelopmentClientOptions,resolveLocalDevelopmentClientOptions,resolveRemoteDevelopmentClientOptions};