UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

90 lines (89 loc) • 4.18 kB
import { l as mergeAlsoAllowPolicy } from "./tool-policy-BR4v75RA.mjs"; import { t as isFrozenTemplateToolAllowPolicy } from "./tool-policy-runtime-CvSLQvPo.mjs"; import { n as buildDefaultToolPolicyPipelineSteps, t as applyToolPolicyPipeline } from "./tool-policy-pipeline-D-pE_49H.mjs"; //#region src/agents/conversation-tool-policy-pipeline.ts function mergePolicyAllowlist(e, t) { if (isFrozenTemplateToolAllowPolicy(e)) return e; return mergeAlsoAllowPolicy(e, t ? [...t] : void 0); } /** * Resolves the shared policy layers once so local and remote fixed tool surfaces cannot * diverge on profile `alsoAllow`, sender, sandbox, delegation, or runtime-cap semantics. */ function resolveConversationToolPolicies(e) { const t = e.capabilityProfile.policy; const n = [...t.profileAlsoAllow ?? [], ...e.additionalProfileAllow ?? []]; const r = [...t.providerProfileAlsoAllow ?? [], ...e.additionalProfileAllow ?? []]; return { profilePolicy: mergePolicyAllowlist(t.profilePolicy, n), providerProfilePolicy: mergePolicyAllowlist(t.providerProfilePolicy, r), globalPolicy: mergePolicyAllowlist(t.globalPolicy, e.additionalPolicyAllow), globalProviderPolicy: mergePolicyAllowlist(t.globalProviderPolicy, e.additionalPolicyAllow), agentPolicy: mergePolicyAllowlist(t.agentPolicy, e.additionalPolicyAllow), agentProviderPolicy: mergePolicyAllowlist(t.agentProviderPolicy, e.additionalPolicyAllow), groupPolicy: mergePolicyAllowlist(t.groupPolicy, e.additionalPolicyAllow), senderPolicy: mergePolicyAllowlist(t.senderPolicy, e.additionalPolicyAllow), sandboxPolicy: mergePolicyAllowlist(t.sandboxPolicy, e.additionalPolicyAllow), subagentPolicy: mergePolicyAllowlist(t.subagentPolicy, e.additionalPolicyAllow), runtimeToolPolicy: t.runtimeToolPolicyForInheritance, inheritedToolPolicy: mergePolicyAllowlist(t.inheritedToolPolicy, e.additionalInheritedAllow) }; } /** Builds the canonical ordered policy pipeline for a resolved conversation. */ function buildConversationToolPolicyPipelineSteps(e) { const t = e.capabilityProfile.policy; const step = (t, n, r = "session") => ({ policy: t, source: { kind: r }, label: n, unavailableCoreToolReason: e.unavailableCoreToolReason }); return [ ...buildDefaultToolPolicyPipelineSteps({ profilePolicy: e.policies.profilePolicy, profile: t.profile, profileUnavailableCoreWarningAllowlist: t.profilePolicy?.allow, providerProfilePolicy: e.policies.providerProfilePolicy, providerProfile: t.providerProfile, providerProfileUnavailableCoreWarningAllowlist: t.providerProfilePolicy?.allow, globalPolicy: e.policies.globalPolicy, globalProviderPolicy: e.policies.globalProviderPolicy, agentPolicy: e.policies.agentPolicy, agentProviderPolicy: e.policies.agentProviderPolicy, groupPolicy: e.policies.groupPolicy, senderPolicy: e.policies.senderPolicy, agentId: t.agentId, sources: t.sources, unavailableCoreToolReason: e.unavailableCoreToolReason }), step(e.policies.sandboxPolicy, "sandbox tools.allow"), step(e.policies.subagentPolicy, "subagent tools.allow"), ...e.includeRuntimeToolPolicy ? [step(e.policies.runtimeToolPolicy, "runtime tools.allow", "runtime")] : [], step(e.policies.inheritedToolPolicy, "inherited tools") ]; } /** Projects a fixed runtime catalog through the exact conversation policy pipeline. */ function projectConversationToolNames(e) { const t = resolveConversationToolPolicies({ capabilityProfile: e.capabilityProfile }); const n = e.toolNames.map((e) => ({ name: e })); return applyToolPolicyPipeline({ tools: n, toolMeta: e.toolMeta ?? (() => void 0), warn: e.warn, steps: buildConversationToolPolicyPipelineSteps({ capabilityProfile: e.capabilityProfile, policies: t, includeRuntimeToolPolicy: true }) }).map((e) => e.name); } function isConversationToolAllowed(e, t, n) { return projectConversationToolNames({ capabilityProfile: e, toolNames: [t], toolMeta: () => n, warn: () => void 0 }).length === 1; } //#endregion export { resolveConversationToolPolicies as i, isConversationToolAllowed as n, projectConversationToolNames as r, buildConversationToolPolicyPipelineSteps as t };