openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
43 lines (42 loc) • 2.14 kB
JavaScript
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs";
import { n as getLoadedRuntimePluginRegistry } from "./active-runtime-registry-Y-wDXpG6.mjs";
import { i as listAgentToolResultMiddlewareRegistrations } from "./agent-tool-result-middleware-C6qDSxiL.mjs";
import { n as loadPluginRegistryHandle } from "./loader--j41eir2.mjs";
//#region src/plugins/agent-tool-result-middleware-loader.ts
const log = createSubsystemLogger("plugins/agent-tool-result-middleware");
function listRuntimeMiddlewareOwnerPluginIds(e, t) {
const n = /* @__PURE__ */ new Set();
for (const r of e?.agentToolResultMiddlewares ?? []) if (r.runtimes.includes(t)) n.add(r.pluginId);
return n;
}
async function loadAgentToolResultMiddlewareRegistrationsForRuntime(e) {
const t = listAgentToolResultMiddlewareRegistrations(e.runtime);
try {
const n = getActivePluginRegistry();
const r = listRuntimeMiddlewareOwnerPluginIds(n, e.runtime);
const i = [];
for (const t of n?.agentToolResultMiddlewareOwners ?? []) if (t.runtimes.includes(e.runtime) && !r.has(t.pluginId) && !i.some((e) => e.pluginId === t.pluginId)) i.push(t);
if (i.length === 0) return t;
const a = i.map((e) => e.pluginId);
const o = new Set(a);
const s = getLoadedRuntimePluginRegistry({ requiredPluginIds: a });
const c = listRuntimeMiddlewareOwnerPluginIds(s, e.runtime);
const l = (s && a.every((e) => c.has(e)) ? s : loadPluginRegistryHandle({
config: (await import("./config/config.js")).getRuntimeConfig(),
onlyPluginIds: a,
manifestRegistry: {
plugins: i.map((e) => e.manifest),
diagnostics: []
},
channelPluginLoadIntent: "full"
})).agentToolResultMiddlewares.filter((t) => o.has(t.pluginId) && t.runtimes.includes(e.runtime));
return [...t, ...l];
} catch (t) {
const n = t instanceof Error ? t.message : String(t);
log.warn(`[${e.runtime}] failed to load tool result middleware plugins: ${n}`);
return listAgentToolResultMiddlewareRegistrations(e.runtime);
}
}
//#endregion
export { loadAgentToolResultMiddlewareRegistrationsForRuntime };