UNPKG

eve

Version:

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

1 lines 1.77 kB
import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString,getOptionalStringRecordProperty}from"#internal/authored-module.js";import{serializeOutputSchema}from"#tools/schema.js";async function normalizeDynamicRemoteAgentConfig(e){let t=`Dynamic subagent "${e.name}" must return defineAgent(...), defineRemoteAgent(...), or null.`,n=expectObjectRecord(e.value,t);if(expectOnlyKnownKeys(n,[`auth`,`description`,`forwardPrincipal`,`headers`,`kind`,`outputSchema`,`path`,`url`],t),n.kind!==`remote`)throw Error(t);let r=await resolveUrl(n.url,t),i=readCredentialsStepId(n);if(validateCredentials(n,t),(n.auth!==void 0||n.headers!==void 0)&&i===void 0)throw Error(`${t} Dynamic remote auth and headers must be compiled by eve so credentials stay out of durable workflow state.`);let a={description:expectString(n.description,t),path:n.path===void 0?EVE_SESSION_ROUTE_PATH:expectString(n.path,t),url:r};return i!==void 0&&(a.credentialsStepId=i),n.forwardPrincipal!==void 0&&(a.forwardPrincipal=expectBoolean(n.forwardPrincipal,t)),n.outputSchema!==void 0&&(a.outputSchema=serializeOutputSchema(n.outputSchema)),a}async function resolveUrl(e,t){let n=typeof e==`function`?await expectFunction(e,t)():expectString(e,t);if(n.length===0)throw Error(`${t} The "url" field must resolve to a non-empty string.`);return n}function validateCredentials(e,t){e.auth!==void 0&&expectFunction(e.auth,t),e.headers!==void 0&&typeof e.headers!=`function`&&getOptionalStringRecordProperty(e,`headers`,t)}function readCredentialsStepId(e){let t=e.__eveResolveRemoteAgentCredentials;if(typeof t!=`function`)return;let n=t.stepId;return typeof n==`string`?n:void 0}export{normalizeDynamicRemoteAgentConfig};