Elffuss BraidHub

kikocis/continue public

main · 2.7 KiBRawPermalink
1import { ChevronDownIcon } from "@heroicons/react/24/outline";
2import { Tool } from "core";
3import ToggleSwitch from "../../../components/gui/Switch";
4import { ToolTip } from "../../../components/gui/Tooltip";
5import { Card } from "../../../components/ui";
6import { useAppDispatch } from "../../../redux/hooks";
7import { toggleToolGroupSetting } from "../../../redux/slices/uiSlice";
8import { ToolPolicyItem } from "./ToolPolicyItem";
9
10interface ToolPoliciesGroupProps {
11 groupName: string;
12 tools: Tool[];
13 isGroupEnabled: boolean;
14 isExpanded: boolean;
15 allToolsOff: boolean;
16 duplicateDetection: Record<string, boolean>;
17 onToggleGroup: (groupName: string) => void;
18}
19
20export function ToolPoliciesGroup({
21 groupName,
22 tools,
23 isGroupEnabled,
24 isExpanded,
25 allToolsOff,
26 duplicateDetection,
27 onToggleGroup,
28}: ToolPoliciesGroupProps) {
29 const dispatch = useAppDispatch();
30
31 return (
32 <Card>
33 <div className="flex flex-col">
34 <div
35 className="-mx-2 flex cursor-pointer items-center justify-between gap-3 rounded px-2 py-2 hover:bg-gray-50 hover:bg-opacity-5"
36 onClick={() => onToggleGroup(groupName)}
37 >
38 <div className="flex items-center gap-3">
39 <ChevronDownIcon
40 className={`text-description h-3 w-3 transition-transform ${
41 isExpanded ? "rotate-180" : ""
42 }`}
43 />
44 <div className="flex items-center gap-2">
45 <span className="text-sm font-semibold">{groupName}</span>
46 <div className="flex h-5 w-5 items-center justify-center rounded-full bg-gray-600 text-xs font-medium text-white">
47 {tools.length}
48 </div>
49 </div>
50 </div>
51 <ToolTip
52 content={
53 allToolsOff
54 ? "Tools disabled in current mode"
55 : isGroupEnabled
56 ? `Disable all tools in ${groupName} group`
57 : `Enable all tools in ${groupName} group`
58 }
59 >
60 <div>
61 <ToggleSwitch
62 isToggled={isGroupEnabled}
63 onToggle={() => dispatch(toggleToolGroupSetting(groupName))}
64 text=""
65 size={10}
66 disabled={allToolsOff}
67 />
68 </div>
69 </ToolTip>
70 </div>
71
72 {isExpanded && (
73 <div className="mt-3 space-y-1">
74 {tools.map((tool) => (
75 <ToolPolicyItem
76 key={tool.uri + tool.function.name}
77 tool={tool}
78 duplicatesDetected={duplicateDetection[tool.function.name]}
79 isGroupEnabled={isGroupEnabled}
80 />
81 ))}
82 </div>
83 )}
84 </div>
85 </Card>
86 );
87}