UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.65 kB
import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs";import{t as AUTOMATIONS_TOOL_NAME}from"./automations-tool-name-CptnbJ9-.mjs";import{c as normalizeToolPolicyName}from"./tool-policy-shared-KKJW93v9.mjs";import{t as ToolAuthorizationError}from"./tool-input-error-BCfbFipG.mjs";import"./tool-policy-Bsc3kFBH.mjs";import{n as createRuntimeToolMatcher}from"./tool-policy-match-D9XrfLbh.mjs";import{d as isCompletionReportInputProvenance,v as normalizeInputProvenance}from"./input-provenance-TIcSrNt5.mjs";import{n as copyPluginToolMeta}from"./tool-metadata-Cb5nBZYD.mjs";import"./common-DIgvX97L.mjs";import{s as withPreparedSessionCapabilityRead}from"./subagent-session-store-ClkR5Yv6.mjs";import{t as hasVerifiedRequesterCompletionHandoff}from"./requester-tool-policy-QdoptA0_.mjs"; //!src/agents/delegation-capability.ts const log=createSubsystemLogger(`agents/delegation-capability`);const NEW_DELEGATION_TOOL_NAMES=/* @__PURE__ */ new Set([`codex_session_send`,`llm-task`,`openclaw`,`sessions_send`,`sessions_spawn`]);const REPORT_ONLY_TOOL_ACTIONS=/* @__PURE__ */ new Map([[AUTOMATIONS_TOOL_NAME,/* @__PURE__ */ new Set([`get`,`list`,`remove`,`runs`,`status`])],[`image_generate`,/* @__PURE__ */ new Set([`list`,`status`])],[`music_generate`,/* @__PURE__ */ new Set([`list`,`status`])],[`video_generate`,/* @__PURE__ */ new Set([`list`,`status`])]]);const REPORT_ONLY_ERROR=`New delegation is unavailable while reporting a completion through a fallback model.`;function isFallbackAttempt(e){return e.isFallbackRetry||e.modelRoutingProvenance.stage===`fallback`}function resolveDelegationCapability(e){if(!isCompletionReportInputProvenance(e.inputProvenance))return`full`;if(e.disableTools===true)return`report_only`;const t=e.fallbackActive?`host_only`:`full`;if(e.fallbackActive){const t=e.requesterContinuation;if(!t?.trustedInternalHandoff?.settleBatch||!hasVerifiedRequesterCompletionHandoff({...t,inputProvenance:normalizeInputProvenance(e.inputProvenance)}))return`report_only`}if(e.toolsAllow===void 0)return t;return[...NEW_DELEGATION_TOOL_NAMES].some(createRuntimeToolMatcher(e.toolsAllow))?t:`report_only`}function prepareDelegationCapability(e){const{run:t}=e;const n={fallbackActive:e.fallbackActive,inputProvenance:t.inputProvenance,disableTools:t.disableTools,toolsAllow:t.toolsAllow,requesterContinuation:{config:t.config,sessionKey:e.sessionKey,sessionId:e.sessionId,modelProvider:e.modelProvider,modelId:e.modelId,trustedInternalHandoff:t.trustedInternalHandoff}};return e.fallbackActive&&t.trustedInternalHandoff?.settleBatch?withPreparedSessionCapabilityRead(()=>resolveDelegationCapability(n)):resolveDelegationCapability(n)}function readToolAction(e){if(!e||typeof e!==`object`||Array.isArray(e))return``;const t=e.action;return typeof t===`string`?t.trim().toLowerCase():``}function wrapReportOnlyTool(e,t){const n=new Proxy(e,{get(e,n,r){if(n!==`execute`)return Reflect.get(e,n,r);return async(n,r,i,a)=>{if(!t.has(readToolAction(r)))throw new ToolAuthorizationError(REPORT_ONLY_ERROR);return await e.execute(n,r,i,a)}}});copyPluginToolMeta(e,n);return n}function applyDelegationCapability(e,t){if(t!==`report_only`)return e;const n=[];const r=[];const i=e.flatMap(e=>{const t=normalizeToolPolicyName(e.name);if(NEW_DELEGATION_TOOL_NAMES.has(t)){n.push(t);return[]}const i=REPORT_ONLY_TOOL_ACTIONS.get(t);if(!i)return[e];r.push(t);return[wrapReportOnlyTool(e,i)]});if(n.length>0||r.length>0)log.debug(`delegation capability restricted run tools`,{removed:n,narrowed:r});return i}export{resolveDelegationCapability as i,isFallbackAttempt as n,prepareDelegationCapability as r,applyDelegationCapability as t};