openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.51 kB
JavaScript
import{B as listCoreToolFactoryDescriptors,H as resolveCoreToolFactoryFamily}from"./tool-catalog-Du-FMXr3.mjs";import{c as normalizeToolPolicyName,i as expandToolGroups,l as readToolAllowlistIntersection,s as normalizeToolList,t as attachToolAllowlistIntersection}from"./tool-policy-shared-KKJW93v9.mjs";import{r as mayMatchGlobWithPrefix}from"./glob-pattern-BJcX7VXN.mjs";import{o as expandPolicyWithPluginGroups,r as buildPluginToolGroups,s as expandShippedCoreToolPolicyNames}from"./tool-policy-Bsc3kFBH.mjs";import{n as createRuntimeToolMatcher}from"./tool-policy-match-D9XrfLbh.mjs";
//!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)===`*`)}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)}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}}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))))}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_`)))}export{shouldCreateBundleMcpRuntimeForAttempt as a,shouldCreateBundleLspRuntimeForAttempt as i,mergeForcedEmbeddedAttemptToolsAllow as n,resolveEmbeddedAttemptToolConstructionPlan as r,applyEmbeddedAttemptToolsAllow as t};