惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
A
About on SuperTechFans
J
Java Code Geeks
量子位
博客园 - 三生石上(FineUI控件)
博客园 - Franky
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(tools): consolidate provider policy resolution ·...
vincentkoc · 2026-06-23 · via Recent Commits to openclaw:main

@@ -3,11 +3,7 @@

33

* sessions. Keeps runtime tool filtering tied to canonical config, session

44

* provenance, and inherited sub-agent capabilities.

55

*/

6-

import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";

7-

import {

8-

normalizeLowercaseStringOrEmpty,

9-

normalizeOptionalLowercaseString,

10-

} from "@openclaw/normalization-core/string-coerce";

6+

import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";

117

import {

128

normalizeUniqueSingleOrTrimmedStringList,

139

uniqueStrings,

@@ -26,6 +22,7 @@ import {

2622

import { normalizeMessageChannel } from "../utils/message-channel.js";

2723

import { resolveAgentConfig, resolveAgentIdFromSessionKey } from "./agent-scope.js";

2824

import type { AnyAgentTool } from "./agent-tools.types.js";

25+

import { resolveProviderToolPolicy } from "./provider-tool-policy.js";

2926

import { pickSandboxToolPolicy } from "./sandbox-tool-policy.js";

3027

import type { SandboxToolPolicy } from "./sandbox.js";

3128

import {

@@ -43,6 +40,8 @@ import {

4340

resolveToolProfilePolicy,

4441

} from "./tool-policy.js";

454243+

export { resolveProviderToolPolicy };

44+4645

/**

4746

* Tools always denied for sub-agents regardless of depth.

4847

* These are system-level or interactive tools that sub-agents should never use.

@@ -145,59 +144,6 @@ export function filterToolsByPolicy(tools: AnyAgentTool[], policy?: SandboxToolP

145144

return tools.filter((tool) => isToolAllowedByPolicyName(tool.name, policy));

146145

}

147146148-

type ToolPolicyConfig = {

149-

allow?: string[];

150-

alsoAllow?: string[];

151-

deny?: string[];

152-

profile?: string;

153-

};

154-155-

function normalizeProviderKey(value: string): string {

156-

const normalized = normalizeLowercaseStringOrEmpty(value);

157-

const slashIndex = normalized.indexOf("/");

158-

if (slashIndex <= 0) {

159-

return normalizeProviderId(normalized);

160-

}

161-

const provider = normalizeProviderId(normalized.slice(0, slashIndex));

162-

const modelId = normalized.slice(slashIndex + 1);

163-

return modelId ? `${provider}/${modelId}` : provider;

164-

}

165-166-

function isCanonicalProviderKey(value: string): boolean {

167-

return normalizeLowercaseStringOrEmpty(value) === normalizeProviderKey(value);

168-

}

169-170-

function buildProviderToolPolicyLookup(

171-

entries: Array<[string, ToolPolicyConfig]>,

172-

): Map<string, ToolPolicyConfig> {

173-

const lookup = new Map<

174-

string,

175-

{

176-

canonical: boolean;

177-

value: ToolPolicyConfig;

178-

}

179-

>();

180-

for (const [key, value] of entries) {

181-

const normalized = normalizeProviderKey(key);

182-

if (!normalized) {

183-

continue;

184-

}

185-

const canonical = isCanonicalProviderKey(key);

186-

const existing = lookup.get(normalized);

187-

// Alias and canonical keys can normalize to the same provider. Prefer the

188-

// canonical entry so mixed legacy/canonical configs do not depend on

189-

// Object.entries insertion order.

190-

if (!existing || (canonical && !existing.canonical)) {

191-

lookup.set(normalized, { canonical, value });

192-

}

193-

}

194-

const resolved = new Map<string, ToolPolicyConfig>();

195-

for (const [key, entry] of lookup) {

196-

resolved.set(key, entry.value);

197-

}

198-

return resolved;

199-

}

200-201147

function collectUniqueStrings(values: Array<string | null | undefined>): string[] {

202148

return normalizeUniqueSingleOrTrimmedStringList(values);

203149

}

@@ -322,42 +268,6 @@ export function resolveTrustedGroupId(params: {

322268

});

323269

}

324270325-

/** Resolve model/provider-scoped tool policy from canonical provider keys. */

326-

export function resolveProviderToolPolicy(params: {

327-

byProvider?: Record<string, ToolPolicyConfig>;

328-

modelProvider?: string;

329-

modelId?: string;

330-

}): ToolPolicyConfig | undefined {

331-

const provider = params.modelProvider?.trim();

332-

if (!provider || !params.byProvider) {

333-

return undefined;

334-

}

335-336-

const entries = Object.entries(params.byProvider);

337-

if (entries.length === 0) {

338-

return undefined;

339-

}

340-341-

const lookup = buildProviderToolPolicyLookup(entries);

342-343-

const normalizedProvider = normalizeProviderKey(provider);

344-

const rawModelId = normalizeOptionalLowercaseString(params.modelId);

345-

// Model IDs can contain provider-like prefixes (for example OpenRouter refs);

346-

// keep them inside the selected provider scope instead of treating them as a

347-

// byProvider override.

348-

const fullModelId = rawModelId ? `${normalizedProvider}/${rawModelId}` : undefined;

349-350-

const candidates = [...(fullModelId ? [fullModelId] : []), normalizedProvider];

351-352-

for (const key of candidates) {

353-

const match = lookup.get(key);

354-

if (match) {

355-

return match;

356-

}

357-

}

358-

return undefined;

359-

}

360-361271

function resolveExplicitProfileAlsoAllow(tools?: OpenClawConfig["tools"]): string[] | undefined {

362272

return Array.isArray(tools?.alsoAllow) ? tools.alsoAllow : undefined;

363273

}