eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.6 kB
JavaScript
import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString}from"#internal/authored-module.js";import{serializeOutputSchema}from"#tools/schema.js";import{isDynamicSentinel}from"#dynamic/definition.js";const ALLOWED_DYNAMIC_SUBAGENT_EVENTS=new Set([`session.started`,`turn.started`]);function normalizeSubagentConfig(e,t){if(isDynamicSentinel(e)){let n=expectObjectRecord(e,t);expectOnlyKnownKeys(n,[`build`,`events`,`kind`],t);let r=expectObjectRecord(n.events,t),i=[];for(let[e,n]of Object.entries(r)){if(!ALLOWED_DYNAMIC_SUBAGENT_EVENTS.has(e))throw Error(`${t} Dynamic subagents support only "session.started" and "turn.started" handlers.`);expectFunction(n,t),i.push(e)}let a=n.build===void 0?void 0:normalizeDynamicSubagentBuild(n.build,t);return a===void 0?{eventNames:i,kind:`dynamic`}:{build:a,eventNames:i,kind:`dynamic`}}if(typeof e==`object`&&e&&e.kind===`remote`){let n=expectObjectRecord(e,t);expectOnlyKnownKeys(n,[`auth`,`description`,`forwardPrincipal`,`headers`,`kind`,`outputSchema`,`path`,`tool`,`url`],t),n.forwardPrincipal!==void 0&&expectBoolean(n.forwardPrincipal,`${t} Expected "forwardPrincipal" to be a boolean.`);let r=serializeOutputSchema(n.outputSchema);return{description:expectString(n.description,t),kind:`remote`,outputSchema:r,path:n.path===void 0?EVE_SESSION_ROUTE_PATH:expectString(n.path,t),tool:n.tool===void 0?void 0:expectBoolean(n.tool,t),url:typeof n.url==`function`?void 0:expectString(n.url,t)}}return{definition:e,kind:`local`}}function assertRemoteAgentDefinitionHasNoLocalPackageEntries(e){let t=e.manifest,n=[t.connections.length>0?`connections/`:void 0,t.hooks.length>0?`hooks/`:void 0,t.instructions.length>0?`instructions`:void 0,t.lib.length>0?`lib/`:void 0,t.sandbox===null?void 0:`sandbox/`,t.sandboxWorkspaces.length>0?`sandbox/workspace/`:void 0,t.schedules.length>0?`schedules/`:void 0,t.skills.length>0?`skills/`:void 0,t.subagents.length>0?`subagents/`:void 0,t.tools.length>0?`tools/`:void 0].filter(e=>e!==void 0);if(n.length>0)throw Error(`Remote subagent definition "${e.logicalPath}" cannot include local package entries. Remove unsupported entries: ${n.join(`, `)}.`)}function normalizeDynamicSubagentBuild(e,t){let n=expectObjectRecord(e,t);if(expectOnlyKnownKeys(n,[`externalDependencies`],t),n.externalDependencies===void 0)return{};if(!Array.isArray(n.externalDependencies))throw Error(t);return{externalDependencies:n.externalDependencies.map(e=>expectString(e,t))}}export{assertRemoteAgentDefinitionHasNoLocalPackageEntries,normalizeSubagentConfig};