Skip to content

Commit a45a875

Browse files
authored
Refactor tool selection logic and enhance regex mapping (#10)
This pull request includes updates to the `ToolsToggle` component and the `toolIcons` configuration to enhance the tool selection functionality. The most important changes involve the introduction of regex-based tool matching and the addition of new tool icon mappings. Enhancements to tool selection functionality: * [`src/components/ChatInputButton/ToolsToggle.tsx`](diffhunk://#diff-5e81be1e28b3637aa2337dde6d10a306e31c56a504ee3c59747f301d1f3fc2e1L24-R40): Updated the `handleQuickToolToggle` function to use regex patterns from `toolIconMappings` for more accurate tool matching. Updates to tool icon mappings: * [`src/components/ChatInputButton/toolIcons.tsx`](diffhunk://#diff-f9c7082cb98bf0b9e486b971e75e43b385a100093e611408d2e6cb356ec3f655L3-L29): Added new tool icon mappings for Docker, GitHub, Git, and filesystem management tools, and made regex a required field for all tool mappings.Updated the tool selection logic to use regex for more precise matching, replacing the simple pattern-based approach. Introduced required regex fields in `toolIconMappings` for consistent behavior across tool integrations. Expanded `toolIcons.tsx` with additional tool mappings and refined titles.
1 parent fe25a7c commit a45a875

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

src/components/ChatInputButton/ToolsToggle.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@ export const ToolsToggle: React.FC<ToolsToggleButtonProps> = ({
2121
};
2222

2323
const handleQuickToolToggle = (pattern: string) => {
24-
const relatedTools = availableTools.filter(tool =>
25-
tool.toLowerCase().includes(pattern.toLowerCase())
26-
);
24+
// Find the tool mapping for the current pattern
25+
const toolMapping = toolIconMappings.find(mapping => mapping.pattern === pattern);
2726

28-
// If all related tools are selected, unselect them; otherwise, select them
29-
const allSelected = relatedTools.every(tool => selectedTools.includes(tool));
27+
const relatedTools = availableTools.filter(tool => {
28+
const toolLower = tool.toLowerCase();
29+
30+
// Use the regex pattern from toolMapping if it exists
31+
if (toolMapping?.regex) {
32+
return toolMapping.regex.test(toolLower);
33+
}
34+
35+
// Fallback to simple pattern matching if no regex is defined
36+
const regex = new RegExp(`^${pattern}`, 'i');
37+
return regex.test(toolLower);
38+
});
3039

40+
const allSelected = relatedTools.every(tool => selectedTools.includes(tool));
3141
if (allSelected) {
3242
onToolsChange(selectedTools.filter(tool => !relatedTools.includes(tool)));
3343
} else {
@@ -36,6 +46,7 @@ export const ToolsToggle: React.FC<ToolsToggleButtonProps> = ({
3646
}
3747
};
3848

49+
3950
return (
4051
<div className="flex items-center gap-2">
4152
{/* Main tools configuration button */}
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,56 @@
11
import { IconType } from 'react-icons';
22
import { SiGmail } from 'react-icons/si';
3-
import { TbApi } from 'react-icons/tb';
4-
import { FaDatabase } from 'react-icons/fa';
5-
// Import other icons as needed
3+
import {FaDatabase, FaDocker, FaGithub, FaGitSquare, FaRegFolderOpen} from 'react-icons/fa';
4+
import {MdOutlineHttp} from "react-icons/md";
65

76
interface ToolIconMapping {
87
pattern: string;
98
icon: IconType;
109
title: string;
10+
regex: RegExp; // Make regex required since we're using it for all
1111
}
1212

1313
export const toolIconMappings: ToolIconMapping[] = [
1414
{
1515
pattern: 'gmail',
1616
icon: SiGmail,
17-
title: 'Gmail Tools'
17+
title: 'Access Gmail',
18+
regex: /^gmail\w*/
1819
},
1920
{
2021
pattern: 'curl',
21-
icon: TbApi,
22-
title: 'API Tools'
22+
icon: MdOutlineHttp,
23+
title: 'HTTP Tools using cURL',
24+
regex: /^curl\w*/
2325
},
2426
{
2527
pattern: 'sql',
2628
icon: FaDatabase,
27-
title: 'Database Tools'
29+
title: 'Database Tools',
30+
regex: /^sql\w*/
31+
},
32+
{
33+
pattern: 'git',
34+
icon: FaGitSquare,
35+
title: 'Git Tools',
36+
regex: /^git(?!hub)\w*/
37+
},
38+
{
39+
pattern: 'github',
40+
icon: FaGithub,
41+
title: 'GitHub Tools',
42+
regex: /^github\w*/
43+
},
44+
{
45+
pattern: 'docker',
46+
icon: FaDocker,
47+
title: 'Docker Tools',
48+
regex: /^docker\w*/
49+
},
50+
{
51+
pattern: 'filesystem',
52+
icon: FaRegFolderOpen,
53+
title: 'Manage Filesystem',
54+
regex: /^filesystem\w*/
2855
}
29-
// Add more mappings as needed
3056
];

0 commit comments

Comments
 (0)