UNPKG

eve

Version:

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

1 lines 1.18 kB
import{buildBaseToolContext}from"#context/build-base-tool-context.js";import{createAuthorizationContext}from"#runtime/authorization-context.js";import{handleAuthorizationError}from"#runtime/connections/scoped-authorization.js";function createToolExecuteWithAuth(e){return(t,n,r)=>{let i=createAuthorizationContext({scope:e.scope}),a={...buildBaseToolContext({options:n,toolName:e.scope}),getToken:i.getToken,requireAuth:i.requireAuth};return i.run(()=>{if(e.execution===`background`){if(r===void 0)throw Error(`Background tool execution requires a task runtime.`);return e.execute(t,a,r)}return e.execute(t,a,r)})}}function buildApprovalResponseAuth(e){let t=createAuthorizationContext({scope:e.scope,boundResponder:e.responder});return{getToken:(n,r)=>t.getToken(n,namespaceApprovalAuthOptions(e.scope,r)),requireAuth:(n,r)=>t.requireAuth(n,namespaceApprovalAuthOptions(e.scope,r))}}function namespaceApprovalAuthOptions(e,t){return t?.authKey===void 0?t:{...t,authKey:`${e}:${t.authKey}`}}async function handleApprovalResponsePolicyError(e){return await handleAuthorizationError(e)}export{buildApprovalResponseAuth,createToolExecuteWithAuth,handleApprovalResponsePolicyError};