Elffuss BraidHub

kikocis/continue public

87f75892af56 · 2.9 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 onClick={(e) => {
62 e.stopPropagation();
63 dispatch(toggleToolGroupSetting(groupName));
64 }}
65 >
66 <ToggleSwitch
67 isToggled={isGroupEnabled}
68 onToggle={() => dispatch(toggleToolGroupSetting(groupName))}
69 text=""
70 size={10}
71 disabled={allToolsOff}
72 />
73 </div>
74 </ToolTip>
75 </div>
76
77 {isExpanded && (
78 <div className="mt-3 space-y-1">
79 {tools.map((tool) => (
80 <ToolPolicyItem
81 key={tool.uri + tool.function.name}
82 tool={tool}
83 duplicatesDetected={duplicateDetection[tool.function.name]}
84 isGroupEnabled={isGroupEnabled}
85 />
86 ))}
87 </div>
88 )}
89 </div>
90 </Card>
91 );
92}