UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.37 kB
import{t as isPromiseLike}from"./promise-like-OKzBwzLG.mjs";import{t as AsyncContext}from"./async-context-D4i8WbBE.mjs"; //!src/agents/agent-tools.ring-zero-context.ts const activeRingZeroTools=new AsyncContext(Symbol(`agentRingZeroTools`));function bindToolToScope(e,t){const n=e.execute;return{...e,execute:async(r,i,a,o)=>{if(!t.active)throw Object.assign(/* @__PURE__ */ new Error(`host-scoped tool "${e.name}" is no longer authorized for this run`),{name:`HostScopedAgentToolAuthorizationError`,status:403});return await n(r,i,a,o)}}}function runWithAgentRingZeroTools(e,t){const n={active:true,tools:[]};n.tools=e.map(e=>bindToolToScope(e,n));try{const e=activeRingZeroTools.run(n,t);if(isPromiseLike(e))return Promise.resolve(e).finally(()=>{n.active=false});n.active=false;return e}catch(e){n.active=false;throw e}}function getActiveAgentRingZeroTools(){const e=activeRingZeroTools.getStore();return e?.active===true?e.tools:[]}function mergeAgentRingZeroTools(e,t){if(e.length===0)return t;const n=new Set(e.map(e=>e.name));return[...e,...t.filter(e=>!n.has(e.name))]}function isHostScopedAgentToolActive(e){const t=e.trim().toLowerCase();return t.length>0&&getActiveAgentRingZeroTools().some(e=>e.name.trim().toLowerCase()===t)}export{runWithAgentRingZeroTools as i,isHostScopedAgentToolActive as n,mergeAgentRingZeroTools as r,getActiveAgentRingZeroTools as t};