UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

48 lines (47 loc) • 2.52 kB
import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs"; import { i as pluginToolMatcherCoversTool, t as createPluginToolMatcherScope } from "./tool-hook-matcher-DlUmH-ng.mjs"; //#region src/plugins/agent-tool-result-middleware.ts const AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIME_SET = /* @__PURE__ */ new Set([ "openclaw", "codex", "agentsapi" ]); function normalizeAgentToolResultMiddlewareRuntime(e) { const t = e.trim().toLowerCase(); return AGENT_TOOL_RESULT_MIDDLEWARE_RUNTIME_SET.has(t) ? t : void 0; } function normalizeAgentToolResultMiddlewareRuntimes(e, t) { return normalizeAgentToolResultMiddlewareRuntimeIds(e?.runtimes ?? t); } function normalizeAgentToolResultMiddlewareRuntimeIds(e) { const t = []; for (const n of e ?? []) { const e = normalizeAgentToolResultMiddlewareRuntime(n); if (e && !t.includes(e)) t.push(e); } return t; } function sameMiddlewareScope(e, t) { return e.runtimes.length === t.runtimes.length && e.runtimes.every((e) => t.runtimes.includes(e)) && (e.matcher ?? []).length === (t.matcher ?? []).length && (e.matcher ?? []).every((e) => t.matcher?.includes(e)); } function readAgentToolResultMiddlewareScopes(e) { return e.scopes?.length ? e.scopes : [{ runtimes: e.runtimes }]; } function appendAgentToolResultMiddlewareScope(e, t) { const n = readAgentToolResultMiddlewareScopes(e); if (!n.some((e) => sameMiddlewareScope(e, t))) e.scopes = [...n, t]; else if (!e.scopes) e.scopes = n; e.runtimes = [...new Set(readAgentToolResultMiddlewareScopes(e).flatMap((e) => e.runtimes))]; } function agentToolResultMiddlewareRegistrationCoversTool(e, t, n) { return readAgentToolResultMiddlewareScopes(e).some((e) => e.runtimes.includes(t) && pluginToolMatcherCoversTool(e.matcher, n)); } function getAgentToolResultMiddlewareMatcherScope(e) { const t = (getActivePluginRegistry()?.agentToolResultMiddlewares ?? []).flatMap((t) => readAgentToolResultMiddlewareScopes(t).filter((t) => t.runtimes.includes(e)).map((e) => e.matcher)); return createPluginToolMatcherScope(t); } function listAgentToolResultMiddlewareRegistrations(e) { return getActivePluginRegistry()?.agentToolResultMiddlewares?.filter((t) => t.runtimes.includes(e)) ?? []; } //#endregion export { normalizeAgentToolResultMiddlewareRuntimeIds as a, listAgentToolResultMiddlewareRegistrations as i, appendAgentToolResultMiddlewareScope as n, normalizeAgentToolResultMiddlewareRuntimes as o, getAgentToolResultMiddlewareMatcherScope as r, agentToolResultMiddlewareRegistrationCoversTool as t };