Elffuss BraidHub

kikocis/continue public

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