
























@@ -3,53 +3,32 @@
33 * runtime-compatible tools plus warnings for tools quarantined by schema
44 * policy, with plugin/channel ownership preserved.
55 */
6-import {
7-normalizeLowercaseStringOrEmpty,
8-normalizeOptionalString,
9-} from "@openclaw/normalization-core/string-coerce";
6+import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
107import type { OpenClawConfig } from "../config/types.openclaw.js";
118import type { ProviderRuntimeModel } from "../plugins/provider-runtime-model.types.js";
129import { getActivePluginRegistry } from "../plugins/runtime.js";
1310import { buildPluginToolMetadataKey, getPluginToolMeta } from "../plugins/tools.js";
1411import { getChannelAgentToolMeta } from "./channel-tools.js";
1512import { normalizeAgentRuntimeTools } from "./runtime-plan/tools.js";
16-import { summarizeToolDescriptionText } from "./tool-description-summary.js";
17-import { resolveToolDisplay } from "./tool-display.js";
1813import {
1914filterProviderNormalizableTools,
2015filterRuntimeCompatibleTools,
2116type RuntimeToolSchemaDiagnostic,
2217} from "./tool-schema-projection.js";
2318import { buildEffectiveToolInventoryGroups } from "./tools-effective-inventory-groups.js";
19+import {
20+disambiguateEffectiveToolLabels,
21+resolveEffectiveToolLabel,
22+resolveEffectiveToolRawDescription,
23+summarizeEffectiveToolDescription,
24+} from "./tools-effective-inventory-shared.js";
2425import type {
2526EffectiveToolInventoryEntry,
2627EffectiveToolInventoryNotice,
2728EffectiveToolSource,
2829} from "./tools-effective-inventory.types.js";
2930import type { AnyAgentTool } from "./tools/common.js";
303131-function resolveEffectiveToolLabel(tool: AnyAgentTool): string {
32-const rawLabel = normalizeOptionalString(tool.label) ?? "";
33-if (
34-rawLabel &&
35-normalizeLowercaseStringOrEmpty(rawLabel) !== normalizeLowercaseStringOrEmpty(tool.name)
36-) {
37-return rawLabel;
38-}
39-return resolveToolDisplay({ name: tool.name }).title;
40-}
41-42-function resolveRawToolDescription(tool: AnyAgentTool): string {
43-return normalizeOptionalString(tool.description) ?? "";
44-}
45-46-function summarizeToolDescription(tool: AnyAgentTool): string {
47-return summarizeToolDescriptionText({
48-rawDescription: resolveRawToolDescription(tool),
49-displaySummary: tool.displaySummary,
50-});
51-}
52-5332// Tool metadata may be attached to the normalized tool or the raw fallback
5433// before schema projection. Check both so owner attribution survives cloning.
5534function resolveEffectiveToolSource(
@@ -150,22 +129,6 @@ function buildReadableRawToolsByName(
150129return toolsByName;
151130}
152131153-// Duplicate labels are ambiguous in inventory UIs; add the owner/id only where
154-// needed so unique entries keep their concise display names.
155-function disambiguateLabels(entries: EffectiveToolInventoryEntry[]): EffectiveToolInventoryEntry[] {
156-const counts = new Map<string, number>();
157-for (const entry of entries) {
158-counts.set(entry.label, (counts.get(entry.label) ?? 0) + 1);
159-}
160-return entries.map((entry) => {
161-if ((counts.get(entry.label) ?? 0) < 2) {
162-return entry;
163-}
164-const suffix = entry.pluginId ?? entry.channelId ?? entry.id;
165-return { ...entry, label: `${entry.label} (${suffix})` };
166-});
167-}
168-169132/** Builds effective inventory entries from already runtime-compatible tools. */
170133export function buildEffectiveToolInventoryEntries(
171134tools: readonly AnyAgentTool[],
@@ -180,7 +143,7 @@ export function buildEffectiveToolInventoryEntries(
180143]),
181144);
182145183-return disambiguateLabels(
146+return disambiguateEffectiveToolLabels(
184147tools
185148.map((tool) => {
186149const source = resolveEffectiveToolSource(tool, rawToolsByName.get(tool.name));
@@ -193,18 +156,20 @@ export function buildEffectiveToolInventoryEntries(
193156label:
194157normalizeOptionalString(metadata?.displayName) ?? resolveEffectiveToolLabel(tool),
195158description:
196-normalizeOptionalString(metadata?.description) ?? summarizeToolDescription(tool),
159+normalizeOptionalString(metadata?.description) ??
160+summarizeEffectiveToolDescription(tool),
197161rawDescription:
198162normalizeOptionalString(metadata?.description) ??
199-resolveRawToolDescription(tool) ??
200-summarizeToolDescription(tool),
163+resolveEffectiveToolRawDescription(tool) ??
164+summarizeEffectiveToolDescription(tool),
201165 ...(metadata?.risk ? { risk: metadata.risk } : {}),
202166 ...(metadata?.tags ? { tags: metadata.tags } : {}),
203167},
204168source,
205169) satisfies EffectiveToolInventoryEntry;
206170})
207171.toSorted((a, b) => a.label.localeCompare(b.label)),
172+(entry) => entry.pluginId ?? entry.channelId ?? entry.id,
208173);
209174}
210175此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。