UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

54 lines • 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cachedMcpToolKeysByServer = exports.cachedMcpTools = void 0; exports.beginServerToolsCacheListing = beginServerToolsCacheListing; exports.invalidateServerToolsCache = invalidateServerToolsCache; exports.cachedMcpTools = {}; exports.cachedMcpToolKeysByServer = {}; const activeServerToolsCacheListings = new Map(); function beginServerToolsCacheListing(serverName) { const listing = { invalidated: false }; let activeListings = activeServerToolsCacheListings.get(serverName); if (!activeListings) { activeListings = new Set(); activeServerToolsCacheListings.set(serverName, activeListings); } activeListings.add(listing); let released = false; return { isCurrent: () => !listing.invalidated, release: () => { if (released) { return; } released = true; activeListings.delete(listing); if (activeListings.size === 0) { activeServerToolsCacheListings.delete(serverName); } }, }; } /** * Remove cached tools for the given server so the next lookup fetches fresh data. * * @param serverName - Name of the MCP server whose cache should be cleared. */ async function invalidateServerToolsCache(serverName) { const activeListings = activeServerToolsCacheListings.get(serverName); if (activeListings) { for (const listing of activeListings) { listing.invalidated = true; } } const cachedKeys = exports.cachedMcpToolKeysByServer[serverName]; if (cachedKeys) { for (const cacheKey of cachedKeys) { delete exports.cachedMcpTools[cacheKey]; } delete exports.cachedMcpToolKeysByServer[serverName]; return; } delete exports.cachedMcpTools[serverName]; } //# sourceMappingURL=mcpToolCache.js.map