Elffuss BraidHub

kikocis/continue public

9d8db5fc402e · 5.8 KiBRawPermalink
1import {
2 BookOpenIcon,
3 ChatBubbleLeftIcon,
4 ChevronLeftIcon,
5 CubeIcon,
6 EllipsisHorizontalIcon,
7 ExclamationTriangleIcon,
8 PencilIcon,
9 Squares2X2Icon,
10 WrenchScrewdriverIcon,
11} from "@heroicons/react/24/outline";
12import { ReactNode } from "react";
13import { vscBadgeForeground } from "../..";
14import { useAppSelector } from "../../../redux/hooks";
15import { ToolTip } from "../../gui/Tooltip";
16import AssistantSelect from "../../modelSelection/platform/AssistantSelect";
17import { useFontSize } from "../../ui/font";
18import HoverItem from "../InputToolbar/HoverItem";
19import { useLump } from "./LumpContext";
20import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip";
21import { McpSectionTooltip } from "./sections/mcp/MCPTooltip";
22import { ToolsSectionTooltip } from "./sections/tool-policies/ToolPoliciesSectionTooltip";
23
24interface BlockSettingsToolbarIcon {
25 title: string;
26 tooltip: ReactNode;
27 icon: React.ComponentType<any>;
28 itemCount?: number;
29 onClick: () => void;
30 isSelected?: boolean;
31 className?: string;
32}
33
34interface Section {
35 id: string;
36 title: string;
37 tooltip: ReactNode;
38 icon: React.ComponentType<any>;
39}
40
41const sections: Section[] = [
42 { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon },
43 { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon },
44 { id: "docs", title: "Docs", tooltip: "Docs", icon: BookOpenIcon },
45 {
46 id: "prompts",
47 title: "Prompts",
48 tooltip: "Prompts",
49 icon: ChatBubbleLeftIcon,
50 },
51 {
52 id: "tools",
53 title: "Tools",
54 tooltip: <ToolsSectionTooltip />,
55 icon: WrenchScrewdriverIcon,
56 },
57 {
58 id: "mcp",
59 title: "MCP",
60 tooltip: <McpSectionTooltip />,
61 icon: Squares2X2Icon,
62 },
63 {
64 id: "error",
65 title: "Errors",
66 tooltip: <ErrorsSectionTooltip />,
67 icon: ExclamationTriangleIcon,
68 },
69];
70
71function BlockSettingsToolbarIcon(
72 props: BlockSettingsToolbarIcon & { sectionId?: string },
73) {
74 const isErrorSection = props.sectionId === "error";
75
76 const id = `block-settings-toolbar-icon-${props.sectionId}`;
77
78 const fontSize = useFontSize(-3);
79 return (
80 <>
81 <HoverItem
82 px={0}
83 onClick={props.onClick}
84 data-testid={id}
85 data-tooltip-id={id}
86 >
87 <div
88 role="button"
89 tabIndex={0}
90 onKeyDown={(e) => {
91 if (e.key === "Enter" || e.key === " ") {
92 e.preventDefault();
93 props.onClick();
94 }
95 }}
96 className={`${
97 props.isSelected
98 ? isErrorSection
99 ? "bg-red-600"
100 : "bg-badge"
101 : undefined
102 } relative flex select-none items-center rounded-full px-[3px] transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 sm:px-1 ${props.className || ""}`}
103 >
104 <props.icon
105 className={`h-[13px] w-[13px] flex-shrink-0 hover:brightness-125 ${
106 isErrorSection ? "text-red-600" : ""
107 }`}
108 style={{
109 color: props.isSelected ? vscBadgeForeground : undefined,
110 }}
111 aria-hidden="true"
112 />
113 <div
114 style={{ fontSize }}
115 className={`overflow-hidden transition-all duration-200 ${
116 props.isSelected ? "ml-1 w-auto opacity-100" : "w-0 opacity-0"
117 }`}
118 >
119 <span
120 className="whitespace-nowrap"
121 style={{ color: vscBadgeForeground }}
122 >
123 {props.title}
124 </span>
125 </div>
126 </div>
127 </HoverItem>
128 <ToolTip delayShow={700} id={id}>
129 {props.tooltip}
130 </ToolTip>
131 </>
132 );
133}
134
135export function BlockSettingsTopToolbar() {
136 const {
137 isToolbarExpanded,
138 toggleToolbar,
139 selectedSection,
140 setSelectedSection,
141 } = useLump();
142
143 const configError = useAppSelector((store) => store.config.configError);
144
145 const handleEllipsisClick = () => {
146 if (isToolbarExpanded) {
147 setSelectedSection(null);
148 }
149 toggleToolbar();
150 };
151
152 const visibleSections = sections.filter(
153 (section) =>
154 section.id !== "error" ||
155 (section.id === "error" && configError && configError?.length > 0),
156 );
157
158 return (
159 <div className="flex flex-1 items-center justify-between gap-2">
160 <div className="flex flex-row">
161 <div className="xs:flex hidden items-center justify-center text-gray-400">
162 <BlockSettingsToolbarIcon
163 className="-ml-1.5"
164 icon={isToolbarExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon}
165 tooltip={isToolbarExpanded ? "Collapse Toolbar" : "Expand Toolbar"}
166 title=""
167 isSelected={false}
168 onClick={handleEllipsisClick}
169 />
170 <div
171 className={`${isToolbarExpanded ? "w-min" : "w-0"} flex overflow-hidden transition-all duration-200`}
172 >
173 <div className="flex">
174 {visibleSections.map((section) => (
175 <BlockSettingsToolbarIcon
176 key={section.id}
177 sectionId={section.id}
178 icon={section.icon}
179 tooltip={section.tooltip}
180 title={section.title}
181 isSelected={selectedSection === section.id}
182 onClick={() =>
183 setSelectedSection(
184 selectedSection === section.id ? null : section.id,
185 )
186 }
187 />
188 ))}
189 </div>
190 </div>
191 </div>
192 </div>
193 <div className="flex gap-0.5">
194 <HoverItem
195 data-tooltip-id="assistant-select-tooltip"
196 className="!m-0 !p-0"
197 >
198 <AssistantSelect />
199 <ToolTip id="assistant-select-tooltip" place="top">
200 Select Assistant
201 </ToolTip>
202 </HoverItem>
203 </div>
204 </div>
205 );
206}