openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
124 lines (123 loc) • 5.92 kB
JavaScript
import { o as expandPolicyWithPluginGroups, r as buildPluginToolGroups, s as expandShippedCoreToolPolicyNames } from "./tool-policy-BR4v75RA.mjs";
import { V as resolveCoreToolFactoryFamily, z as listCoreToolFactoryDescriptors } from "./tool-catalog-C1ALpCJD.mjs";
import { c as normalizeToolPolicyName, i as expandToolGroups, l as readToolAllowlistIntersection, s as normalizeToolList, t as attachToolAllowlistIntersection } from "./tool-policy-shared-BHvBopvF.mjs";
import { r as mayMatchGlobWithPrefix } from "./glob-pattern-BfbeUKrV.mjs";
import { n as createRuntimeToolMatcher } from "./tool-policy-match-DzwVnbV4.mjs";
//#region src/agents/embedded-agent-runner/run/attempt-tool-construction-plan.ts
function createUniformCodingToolConstructionPlan(e) {
return {
includeBaseCodingTools: e,
includeShellTools: e,
includeChannelTools: e,
includeOpenClawTools: e,
includePluginTools: e
};
}
function isBundleMcpAllowlistName(e) {
return e === "bundle-mcp" || e.includes("__");
}
function hasWildcardToolAllowlist(e) {
return e.some((e) => normalizeToolPolicyName(e) === "*");
}
/**
* Applies a runtime allowlist to a concrete tool list after expanding tool and
* plugin groups. Undefined allowlists keep all tools; an explicit empty list
* intentionally disables all runtime tools.
*/
function applyEmbeddedAttemptToolsAllow(e, t, n) {
if (!t) return e;
return (readToolAllowlistIntersection(t) ?? [t]).reduce((e, t) => {
if (t.length === 0) return [];
if (hasWildcardToolAllowlist(t)) return e;
if (e.length === 0) return [];
const r = n?.toolMeta ? buildPluginToolGroups({
tools: e,
toolMeta: n.toolMeta
}) : void 0;
const i = r ? expandPolicyWithPluginGroups({ allow: t }, r) : { allow: expandShippedCoreToolPolicyNames(t) };
const a = createRuntimeToolMatcher(i?.allow);
return e.filter((e) => a(e.name) || n?.toolAliases?.(e).some(a));
}, e);
}
/**
* Adds host-required tools to a narrowed runtime allowlist. Wildcard and
* undefined allowlists already cover every required tool.
*/
function mergeForcedEmbeddedAttemptToolsAllow(e, t) {
if (e === void 0) return;
const n = [...t.forceMessageTool ? ["message"] : [], ...t.forceToolNames ?? []];
const merge = (e) => {
const t = new Set(e.map(normalizeToolPolicyName));
return [...e, ...n.filter((e) => {
const n = normalizeToolPolicyName(e);
if (t.has("*") || t.has(n)) return false;
t.add(n);
return true;
})];
};
const r = readToolAllowlistIntersection(e);
const i = merge(e);
return r ? attachToolAllowlistIntersection(i, r.map(merge)) : i;
}
function resolveCodingToolConstructionPlanForAllowlist(e) {
if (!e) return createUniformCodingToolConstructionPlan(true);
const t = readToolAllowlistIntersection(e);
if (!t && e.length === 0) return createUniformCodingToolConstructionPlan(false);
if (!t && hasWildcardToolAllowlist(e)) return createUniformCodingToolConstructionPlan(true);
const n = t?.flat() ?? e;
const r = expandToolGroups(expandShippedCoreToolPolicyNames(n));
const i = normalizeToolList(r);
const a = (t ?? [e]).map((e) => createRuntimeToolMatcher(expandShippedCoreToolPolicyNames(e), false));
const o = new Set(listCoreToolFactoryDescriptors().filter(({ name: e }) => a.every((t) => t(e))).map(({ family: e }) => e));
const s = i.some((e) => !resolveCoreToolFactoryFamily(e) && e !== "bundle-mcp");
return {
includeBaseCodingTools: o.has("base-coding"),
includeShellTools: o.has("shell"),
includeChannelTools: s,
includeOpenClawTools: o.has("openclaw"),
includePluginTools: s
};
}
/**
* Decides which tool families need to be constructed for an embedded attempt.
* This keeps allowlisted plugin/channel tools available without forcing every
* local core tool factory to run for narrow plugin-only configurations.
*/
function resolveEmbeddedAttemptToolConstructionPlan(e) {
if (e.disableTools === true || e.isRawModelRun === true || e.toolsEnabled === false) return {
constructTools: false,
includeCoreTools: false,
codingToolConstructionPlan: createUniformCodingToolConstructionPlan(false)
};
const t = mergeForcedEmbeddedAttemptToolsAllow(e.toolsAllow, { forceMessageTool: e.forceMessageTool });
const n = resolveCodingToolConstructionPlanForAllowlist(t);
const r = n.includeBaseCodingTools || n.includeShellTools || n.includeOpenClawTools;
return {
constructTools: r || n.includeChannelTools || n.includePluginTools,
includeCoreTools: r,
...t ? { runtimeToolAllowlist: t } : {},
codingToolConstructionPlan: n
};
}
function shouldCreateBundleRuntimeForAttempt(e, t) {
if (!e.toolsEnabled || e.disableTools === true) return false;
if (!e.toolsAllow) return true;
return (readToolAllowlistIntersection(e.toolsAllow) ?? [e.toolsAllow]).every((e) => e.length > 0 && (hasWildcardToolAllowlist(e) || t(e.map(normalizeToolPolicyName))));
}
/**
* Decides whether the bundled MCP runtime is needed for this attempt. Bundle
* runtime creation follows explicit bundle/plugin names or globs that can reach
* a configured server namespace. Final tool policy remains authoritative.
*/
function shouldCreateBundleMcpRuntimeForAttempt(e) {
return shouldCreateBundleRuntimeForAttempt(e, (t) => {
if (t.some((e) => isBundleMcpAllowlistName(e) || e === "group:plugins")) return true;
const n = t.filter((e) => e.includes("*"));
return n.length > 0 && (e.resolveConfiguredMcpNamespaces?.() ?? []).some((e) => n.some((t) => mayMatchGlobWithPrefix(t, e.toLowerCase())));
});
}
function shouldCreateBundleLspRuntimeForAttempt(e) {
return shouldCreateBundleRuntimeForAttempt(e, (e) => e.some((e) => e === "bundle-lsp" || e === "group:plugins" || e.startsWith("lsp_") || mayMatchGlobWithPrefix(e, "lsp_")));
}
//#endregion
export { shouldCreateBundleMcpRuntimeForAttempt as a, shouldCreateBundleLspRuntimeForAttempt as i, mergeForcedEmbeddedAttemptToolsAllow as n, resolveEmbeddedAttemptToolConstructionPlan as r, applyEmbeddedAttemptToolsAllow as t };