mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 07:14:33 +00:00
refactor(tools): centralize default policy steps
This commit is contained in:
@@ -14,6 +14,54 @@ export type ToolPolicyPipelineStep = {
|
||||
stripPluginOnlyAllowlist?: boolean;
|
||||
};
|
||||
|
||||
export function buildDefaultToolPolicyPipelineSteps(params: {
|
||||
profilePolicy?: ToolPolicyLike;
|
||||
profile?: string;
|
||||
providerProfilePolicy?: ToolPolicyLike;
|
||||
providerProfile?: string;
|
||||
globalPolicy?: ToolPolicyLike;
|
||||
globalProviderPolicy?: ToolPolicyLike;
|
||||
agentPolicy?: ToolPolicyLike;
|
||||
agentProviderPolicy?: ToolPolicyLike;
|
||||
groupPolicy?: ToolPolicyLike;
|
||||
agentId?: string;
|
||||
}): ToolPolicyPipelineStep[] {
|
||||
const agentId = params.agentId?.trim();
|
||||
const profile = params.profile?.trim();
|
||||
const providerProfile = params.providerProfile?.trim();
|
||||
return [
|
||||
{
|
||||
policy: params.profilePolicy,
|
||||
label: profile ? `tools.profile (${profile})` : "tools.profile",
|
||||
stripPluginOnlyAllowlist: true,
|
||||
},
|
||||
{
|
||||
policy: params.providerProfilePolicy,
|
||||
label: providerProfile
|
||||
? `tools.byProvider.profile (${providerProfile})`
|
||||
: "tools.byProvider.profile",
|
||||
stripPluginOnlyAllowlist: true,
|
||||
},
|
||||
{ policy: params.globalPolicy, label: "tools.allow", stripPluginOnlyAllowlist: true },
|
||||
{
|
||||
policy: params.globalProviderPolicy,
|
||||
label: "tools.byProvider.allow",
|
||||
stripPluginOnlyAllowlist: true,
|
||||
},
|
||||
{
|
||||
policy: params.agentPolicy,
|
||||
label: agentId ? `agents.${agentId}.tools.allow` : "agent tools.allow",
|
||||
stripPluginOnlyAllowlist: true,
|
||||
},
|
||||
{
|
||||
policy: params.agentProviderPolicy,
|
||||
label: agentId ? `agents.${agentId}.tools.byProvider.allow` : "agent tools.byProvider.allow",
|
||||
stripPluginOnlyAllowlist: true,
|
||||
},
|
||||
{ policy: params.groupPolicy, label: "group tools.allow", stripPluginOnlyAllowlist: true },
|
||||
];
|
||||
}
|
||||
|
||||
export function applyToolPolicyPipeline(params: {
|
||||
tools: AnyAgentTool[];
|
||||
toolMeta: (tool: AnyAgentTool) => { pluginId: string } | undefined;
|
||||
|
||||
Reference in New Issue
Block a user