UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

37 lines (36 loc) • 1.72 kB
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs"; import { o as getAsyncWorkSignal } from "./async-work-scope-BXagjUap.mjs"; import { i as withGuardedFetchRequestAuthority } from "./fetch-request-authority-nK0cxa_-.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/agents/agent-bundle-mcp-request-context.ts const requestSignals = resolveGlobalSingleton(Symbol.for("openclaw.sessionMcpRequestSignal"), () => new AsyncLocalStorage()); function getSessionMcpRequestSignal() { const e = requestSignals.getStore(); const t = getAsyncWorkSignal(); return e && t ? AbortSignal.any([e, t]) : e ?? t; } function runWithSessionMcpRequestSignal(e, t) { return e ? requestSignals.run(e, t) : t(); } const callAuthorities = resolveGlobalSingleton(Symbol.for("openclaw.sessionMcpToolCallAuthority"), () => new AsyncLocalStorage()); /** Caller-owned liveness check that MCP tools/call re-runs immediately before server I/O. */ function getSessionMcpToolCallAuthority() { return callAuthorities.getStore(); } function runWithSessionMcpToolCallAuthority(e, t) { return e ? callAuthorities.run(e, t) : t(); } /** * Binds a configured-server request to the loopback caller's grant: it is * rechecked at the request boundary, including after reconnection or catalog * refresh waits, and carried into guarded fetches. */ function withSessionMcpCallerAuthority(e) { const t = getSessionMcpToolCallAuthority(); return t ? (...n) => { t(); return withGuardedFetchRequestAuthority(t, () => e(...n)); } : e; } //#endregion export { withSessionMcpCallerAuthority as i, runWithSessionMcpRequestSignal as n, runWithSessionMcpToolCallAuthority as r, getSessionMcpRequestSignal as t };