-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathtoolDisplayName.ts
More file actions
27 lines (23 loc) · 870 Bytes
/
toolDisplayName.ts
File metadata and controls
27 lines (23 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { ToolItem } from '@/components/extension/componentPanel/types';
type ToolDisplayNameSource = Pick<ToolItem, 'name' | 'display_name'>;
type ToolSearchSource = Pick<ToolItem, 'name' | 'display_name' | 'description' | 'origin' | 'origin_name'>;
export function resolveToolDisplayName(
toolName: string,
availableTools: ToolDisplayNameSource[] = []
): string {
const tool = availableTools.find(item => item.name === toolName);
return tool?.display_name || toolName;
}
export function matchesToolSearch(tool: ToolSearchSource, rawQuery: string): boolean {
const query = rawQuery.trim().toLowerCase();
if (!query) {
return true;
}
return [
tool.display_name,
tool.name,
tool.description,
tool.origin,
tool.origin_name,
].some(value => value?.toLowerCase().includes(query));
}