Skip to content

Commit 5de49e3

Browse files
ly-wang19vincentkoc
authored andcommitted
perf(plugins): classify cached tool candidates once
1 parent 2968004 commit 5de49e3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/plugins/tools.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,17 @@ function createCachedDescriptorPluginTool(params: {
707707
throw new Error(`plugin tool runtime unavailable (${pluginId}): ${toolName}`);
708708
}
709709
const requestedToolName = normalizeToolName(toolName);
710+
const matchingNamedCandidates: PluginToolRegistration[] = [];
711+
const unnamedCandidates: PluginToolRegistration[] = [];
712+
for (const candidate of candidates) {
713+
if (candidate.names.length === 0) {
714+
unnamedCandidates.push(candidate);
715+
continue;
716+
}
717+
if (candidate.names.some((name) => normalizeToolName(name) === requestedToolName)) {
718+
matchingNamedCandidates.push(candidate);
719+
}
720+
}
710721
const resolveCandidateTool = (
711722
candidate: PluginToolRegistration,
712723
): AnyAgentTool | undefined => {
@@ -724,12 +735,6 @@ function createCachedDescriptorPluginTool(params: {
724735
}
725736
return undefined;
726737
};
727-
const matchingNamedCandidates = candidates.filter(
728-
(candidate) =>
729-
candidate.names.length > 0 &&
730-
candidate.names.some((name) => normalizeToolName(name) === requestedToolName),
731-
);
732-
const unnamedCandidates = candidates.filter((candidate) => candidate.names.length === 0);
733738
for (const candidate of [...matchingNamedCandidates, ...unnamedCandidates]) {
734739
let matchedTool: AnyAgentTool | undefined;
735740
try {

0 commit comments

Comments
 (0)