UNPKG

eve

Version:

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

1 lines 7.51 kB
import{resolveModelEndpointStatus}from"#internal/resolve-model-endpoint-status.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{WORKFLOW_TOOL_NAME}from"#shared/workflow-sandbox.js";function toChatGptEndpoint(e){if(e===void 0)return;let t={state:e.kind};return e.kind===`ready`&&e.accountLabel!==void 0?{...t,accountLabel:e.accountLabel}:t}function buildAgentInfoResponse(e,t){let{manifest:n}=e,r=toModuleSource(n,n.config.source);if(r.binding===void 0)throw Error(`Compiled config source "${n.config.source.sourceId}" has no binding.`);let i=collectCompositionDiagnostics(n),a=collectRemoteAgents(n);return{agent:{agentRoot:n.agentRoot,appRoot:n.appRoot,config:{...r,binding:r.binding},description:n.config.description,model:n.config.dynamicModel===void 0?{contextWindowTokens:n.config.model.contextWindowTokens,endpoint:resolveModelEndpointStatus(n.config.model.routing,t.gatewayCredentials,toChatGptEndpoint(t.chatgptAuth)),id:n.config.model.id,providerOptions:sanitizeProviderOptionsForInfo(n.config.model.providerOptions),reasoning:n.config.reasoning,routing:n.config.model.routing,source:n.config.model.source===void 0?void 0:toModuleSource(n,n.config.model.source)}:{reasoning:n.config.reasoning,routing:{kind:`dynamic`,resolver:renderDynamicResolver(n,{...n.config.dynamicModel,slug:`model`})}},name:n.config.name,nodeId:ROOT_COMPILED_AGENT_NODE_ID,outputSchema:n.config.outputSchema},capabilities:{devRoutes:t.mode===`development`},channels:{routes:n.channelRoutes.effective.map(e=>({...toModuleSource(n,e),adapterKind:e.adapterKind,method:e.method,name:e.name,urlPath:e.urlPath})),shadowed:[...n.channelRoutes.shadowed]},composition:i,connections:n.connections.map(e=>({...toModuleSource(n,e),connectionName:e.connectionName,description:e.description,hasApproval:!1,hasAuthorization:e.vercelConnect!==void 0,hasHeaders:!1,protocol:e.protocol,url:e.url})),diagnostics:{discoveryErrors:n.diagnosticsSummary.errors,discoveryWarnings:n.diagnosticsSummary.warnings},hooks:n.hooks.map(e=>({...toModuleSource(n,e),eventNames:[...e.eventNames],slug:e.slug})),instructions:{dynamic:n.dynamicInstructions.map(e=>renderDynamicResolver(n,e)),static:n.instructions.map(e=>({...toOwnedSource(n,e),content:e.content,name:e.name,role:e.role}))},instrumentation:n.instrumentation===void 0?void 0:toModuleSource(n,n.instrumentation),kernelEffects:projectPreparedKernelEffects(n),kind:`eve-agent-info`,memories:n.memories.map(e=>({...toModuleSource(n,e),description:e.description,slot:e.slot,visibility:e.visibility})),mode:t.mode,remoteAgents:{entries:a,total:a.length},sandbox:{...toModuleSource(n,n.sandbox),backendKind:n.sandbox.backendName,description:n.sandbox.description,hasBootstrap:!1,hasOnSession:!1,revalidationKey:n.sandbox.revalidationKey,sourceHash:n.sandbox.sourceHash},schedules:n.schedules.map(e=>({...toOwnedSource(n,e),cron:e.cron,hasRun:e.hasRun,markdown:e.markdown,name:e.name})),skills:{dynamic:n.dynamicSkills.map(e=>renderDynamicResolver(n,e)),static:n.skills.map(e=>({...toOwnedSource(n,e),description:e.description,license:e.license,markdown:e.markdown,metadata:e.metadata,name:e.name}))},subagents:{local:n.subagents.map(e=>{let t={...toOwnedSource(n,e),description:e.description,entryPath:e.entryPath,name:e.name,nodeId:e.nodeId,parentNodeId:e.parentNodeId,rootPath:e.rootPath,summary:summarizeNode(e.agent)};return e.configResolver===void 0?t:{...t,configResolver:renderDynamicResolver(e.agent,{...e.configResolver,slug:`config`})}}),total:n.subagents.length},tools:{dynamic:n.dynamicTools.map(e=>renderDynamicResolver(n,e)),static:n.tools.map(e=>({...toModuleSource(n,e),description:e.description,hasAuth:!1,hasExecute:e.hasExecute,hasModelOutputProjection:e.hasModelOutputProjection,hasOutputSchema:e.outputSchema!==void 0,inputSchema:e.inputSchema,name:e.name,outputSchema:e.outputSchema,requiresApproval:e.requiresApproval}))},version:4,workflow:n.workflowTool===void 0?{enabled:!1,toolName:WORKFLOW_TOOL_NAME}:{enabled:!0,source:toModuleSource(n,n.workflowTool),toolName:WORKFLOW_TOOL_NAME},workspace:{resourceRoot:n.workspaceResourceRoot,rootEntries:[...n.workspaceResourceRoot.rootEntries]}}}const CREDENTIAL_OPTION_KEY=/^(api[-_]?key|access[-_]?token|auth|authorization|bearer|client[-_]?secret|credentials?|headers|password|private[-_]?key|secret|token)$/i;function sanitizeProviderOptionsForInfo(e){if(e===void 0)return;let t={};for(let[n,r]of Object.entries(e))t[n]=redactCredentialOptions(r);return t}function redactCredentialOptions(e){if(typeof e!=`object`||!e||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))if(n!==`byok`){if(CREDENTIAL_OPTION_KEY.test(n)){t[n]=`[redacted]`;continue}if(typeof r==`object`&&r){t[n]=Array.isArray(r)?r.map(e=>typeof e==`object`&&e&&!Array.isArray(e)?redactCredentialOptions(e):e):redactCredentialOptions(r);continue}t[n]=r}return t}function toModuleSource(e,t){let n=e.bindings[t.sourceId];if(n===void 0)throw Error(`Compiled source "${t.sourceId}" has no binding.`);return sourceProjection(t,n.owner,n)}function toOwnedSource(e,t){let n=e.bindings[t.sourceId],r=n?.owner??t.owner;if(r===void 0)throw Error(`Compiled source "${t.sourceId}" has no owner.`);return sourceProjection(t,r,n)}function sourceProjection(e,t,n){let r={logicalPath:e.logicalPath,owner:t,sourceId:e.sourceId,sourceKind:toAgentInfoSourceKind(e.sourceKind)},i=n===void 0?void 0:{backing:n.backing,logicalPath:n.logicalPath,owner:n.owner};return n!==void 0&&e.exportName!==void 0?{...r,binding:i,exportName:e.exportName}:n===void 0?e.exportName===void 0?r:{...r,exportName:e.exportName}:{...r,binding:i}}function toAgentInfoSourceKind(e){switch(e){case`markdown`:case`module`:case`skill-package`:return e;default:throw Error(`Unsupported compiled source kind "${e}".`)}}function renderDynamicResolver(e,t){return{...toModuleSource(e,t),eventNames:[...t.eventNames],slug:t.slug}}function summarizeNode(e){return{channels:e.channelRoutes.effective.length,connections:e.connections.length,hooks:e.hooks.length,instructions:e.instructions.length,memories:e.memories.length,schedules:e.schedules.length,skills:e.skills.length,tools:e.tools.length}}function collectRemoteAgents(e){return[e,...e.subagents.map(e=>e.agent)].flatMap(e=>e.remoteAgents.map(e=>({...sourceProjection(e,e.owner,e.binding),description:e.description,name:e.name,nodeId:e.nodeId,parentNodeId:e.parentNodeId,url:e.url})))}function collectCompositionDiagnostics(e){let t=[e,...e.subagents.map(e=>e.agent)].flatMap(e=>e.sourceComposition.entries).map(e=>{let t={kind:e.kind,logicalPath:e.source.logicalPath,owner:e.source.owner,sourceId:e.source.sourceId};return e.kind===`shadowed`?{...t,winnerSourceId:e.winnerSourceId}:t});return{disabled:t.filter(e=>e.kind===`disabled`),shadowed:t.filter(e=>e.kind===`shadowed`)}}function projectPreparedKernelEffects(e){let t=[];for(let n of e.tools){let e=n.behavior,r=e?.handling;if(e!==void 0&&r!==void 0)switch(r.kind){case`dispatch`:t.push({action:r.action===`self-agent`?`subagent-call`:r.action,audience:[...e.availability],kind:`dispatch`,sourceId:n.sourceId});break;case`provider-tool`:t.push({audience:[...e.availability],kind:`provider-tool`,sourceId:n.sourceId});break;case`request-input`:t.push({audience:[...e.availability],kind:`request-input`,sourceId:n.sourceId});break;case`workflow-tool`:t.push({action:`workflow-tool-call`,audience:[...e.availability],kind:`dispatch`,sourceId:n.sourceId});break;default:throw Error(`Unsupported compiled tool handling: ${String(r)}`)}}return t}export{buildAgentInfoResponse};