UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

60 lines (59 loc) • 2.01 kB
import { t as isPromiseLike } from "./promise-like-aMoWEh5w.mjs"; import { t as AsyncContext } from "./async-context-BYDAvG9A.mjs"; //#region 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); } }; } /** * Bind host-owned tools to one selected harness run. The SDK reads this scope * during tool construction, so plugins never receive private authority objects. */ 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; } } /** Read the host-owned tools bound to the current harness run. */ 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))]; } /** * Read a host-owned tool fact for the current run. This does not activate or * grant a tool; only the host can bind executable authority to the run scope. */ function isHostScopedAgentToolActive(e) { const t = e.trim().toLowerCase(); return t.length > 0 && getActiveAgentRingZeroTools().some((e) => e.name.trim().toLowerCase() === t); } //#endregion export { runWithAgentRingZeroTools as i, isHostScopedAgentToolActive as n, mergeAgentRingZeroTools as r, getActiveAgentRingZeroTools as t };