Elffuss BraidHub

kikocis/continue public

dd84f7eaed6c · 15.8 KiBRawPermalink
1import {
2 CheckIcon,
3 ChevronRightIcon,
4 ExclamationTriangleIcon,
5 XMarkIcon,
6} from "@heroicons/react/24/outline";
7import {
8 SharedConfigSchema,
9 modifyAnyConfigWithSharedConfig,
10} from "core/config/sharedConfig";
11import { HubSessionInfo } from "core/control-plane/AuthTypes";
12import { useContext, useEffect, useState } from "react";
13import { Input } from "../../components";
14import NumberInput from "../../components/gui/NumberInput";
15import { Select } from "../../components/gui/Select";
16import ToggleSwitch from "../../components/gui/Switch";
17import { ToolTip } from "../../components/gui/Tooltip";
18import { useFontSize } from "../../components/ui/font";
19import { useAuth } from "../../context/Auth";
20import { IdeMessengerContext } from "../../context/IdeMessenger";
21import { useAppDispatch, useAppSelector } from "../../redux/hooks";
22import { updateConfig } from "../../redux/slices/configSlice";
23import { setLocalStorage } from "../../util/localStorage";
24import { ContinueFeaturesMenu } from "./ContinueFeaturesMenu";
25
26export function UserSettingsForm() {
27 /////// User settings section //////
28 const dispatch = useAppDispatch();
29 const ideMessenger = useContext(IdeMessengerContext);
30 const config = useAppSelector((state) => state.config.config);
31 const [showExperimental, setShowExperimental] = useState(false);
32 const { session } = useAuth();
33
34 function handleUpdate(sharedConfig: SharedConfigSchema) {
35 // Optimistic update
36 const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig);
37 dispatch(updateConfig(updatedConfig));
38 // IMPORTANT no need for model role updates (separate logic for selected model roles)
39 // simply because this function won't be used to update model roles
40
41 // Actual update to core which propagates back with config update event
42 ideMessenger.post("config/updateSharedConfig", sharedConfig);
43 }
44
45 // Disable autocomplete
46 const disableAutocompleteInFiles = (
47 config.tabAutocompleteOptions?.disableInFiles ?? []
48 ).join(", ");
49 const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
50 disableAutocompleteInFiles,
51 );
52
53 useEffect(() => {
54 // Necessary so that reformatted/trimmed values don't cause dirty state
55 setFormDisableAutocomplete(disableAutocompleteInFiles);
56 }, [disableAutocompleteInFiles]);
57
58 // Workspace prompts
59 const promptPath = config.experimental?.promptPath || "";
60 const [formPromptPath, setFormPromptPath] = useState(promptPath);
61 const cancelChangePromptPath = () => {
62 setFormPromptPath(promptPath);
63 };
64 const handleSubmitPromptPath = () => {
65 handleUpdate({
66 promptPath: formPromptPath || "",
67 });
68 };
69
70 const handleLogEditingDataToggle = (value: boolean) => {
71 handleUpdate({ logEditingData: value });
72 };
73
74 const handleOptInNextEditToggle = (value: boolean) => {
75 handleUpdate({ optInNextEditFeature: value });
76 };
77
78 useEffect(() => {
79 // Necessary so that reformatted/trimmed values don't cause dirty state
80 setFormPromptPath(promptPath);
81 }, [promptPath]);
82
83 // TODO defaults are in multiple places, should be consolidated and probably not explicit here
84 const showSessionTabs = config.ui?.showSessionTabs ?? false;
85 const codeWrap = config.ui?.codeWrap ?? false;
86 const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
87 const readResponseTTS = config.experimental?.readResponseTTS ?? false;
88 const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false;
89 const logEditingData = config.experimental?.logEditingData ?? false;
90 const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
91 const disableSessionTitles = config.disableSessionTitles ?? false;
92 const useCurrentFileAsContext =
93 config.experimental?.useCurrentFileAsContext ?? false;
94 const enableExperimentalTools =
95 config.experimental?.enableExperimentalTools ?? false;
96 const optInNextEditFeature =
97 config.experimental?.optInNextEditFeature ?? false;
98
99 const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
100 const disableIndexing = config.disableIndexing ?? false;
101
102 // const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? true;
103 // const useChromiumForDocsCrawling =
104 // config.experimental?.useChromiumForDocsCrawling ?? false;
105 // const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
106 const useAutocompleteMultilineCompletions =
107 config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
108 const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150;
109 const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250;
110 const fontSize = useFontSize();
111
112 const cancelChangeDisableAutocomplete = () => {
113 setFormDisableAutocomplete(disableAutocompleteInFiles);
114 };
115 const handleDisableAutocompleteSubmit = () => {
116 handleUpdate({
117 disableAutocompleteInFiles: formDisableAutocomplete
118 .split(",")
119 .map((val) => val.trim())
120 .filter((val) => !!val),
121 });
122 };
123
124 const [hubEnabled, setHubEnabled] = useState(false);
125 useEffect(() => {
126 void ideMessenger.ide
127 .getIdeSettings()
128 .then(({ continueTestEnvironment }) => {
129 setHubEnabled(continueTestEnvironment === "production");
130 });
131 }, [ideMessenger]);
132
133 const hasContinueEmail = (session as HubSessionInfo)?.account?.id.includes(
134 "@continue.dev",
135 );
136
137 return (
138 <div className="flex flex-col">
139 {/* {selectedProfile && isLocalProfile(selectedProfile) ? (
140 <div className="flex items-center justify-center">
141 <SecondaryButton
142 className="flex flex-row items-center gap-1"
143 onClick={() => {
144 ideMessenger.post("config/openProfile", {
145 profileId: selectedProfile.id,
146 });
147 }}
148 >
149 <span>Open</span>
150 <span>Config</span>
151 <span className="xs:flex hidden">File</span>
152 </SecondaryButton>
153 </div>
154 ) : null} */}
155 {hubEnabled ? (
156 <div className="flex flex-col gap-4 py-4">
157 <div>
158 <h2 className="mb-2 mt-0 p-0">User settings</h2>
159 </div>
160
161 <div className="flex flex-col gap-4">
162 <ToggleSwitch
163 isToggled={showSessionTabs}
164 onToggle={() =>
165 handleUpdate({
166 showSessionTabs: !showSessionTabs,
167 })
168 }
169 text="Show Session Tabs"
170 />
171 <ToggleSwitch
172 isToggled={codeWrap}
173 onToggle={() =>
174 handleUpdate({
175 codeWrap: !codeWrap,
176 })
177 }
178 text="Wrap Codeblocks"
179 />
180
181 <ToggleSwitch
182 isToggled={showChatScrollbar}
183 onToggle={() =>
184 handleUpdate({
185 showChatScrollbar: !showChatScrollbar,
186 })
187 }
188 text="Show Chat Scrollbar"
189 />
190 <ToggleSwitch
191 isToggled={readResponseTTS}
192 onToggle={() =>
193 handleUpdate({
194 readResponseTTS: !readResponseTTS,
195 })
196 }
197 text="Text-to-Speech Output"
198 />
199 {/* <ToggleSwitch
200 isToggled={useChromiumForDocsCrawling}
201 onToggle={() =>
202 handleUpdate({
203 useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
204 })
205 }
206 text="Use Chromium for Docs Crawling"
207 /> */}
208 <ToggleSwitch
209 isToggled={!disableSessionTitles}
210 onToggle={() =>
211 handleUpdate({
212 disableSessionTitles: !disableSessionTitles,
213 })
214 }
215 text="Enable Session Titles"
216 />
217 <ToggleSwitch
218 isToggled={!displayRawMarkdown}
219 onToggle={() =>
220 handleUpdate({
221 displayRawMarkdown: !displayRawMarkdown,
222 })
223 }
224 text="Format Markdown"
225 />
226
227 <ToggleSwitch
228 isToggled={allowAnonymousTelemetry}
229 onToggle={() =>
230 handleUpdate({
231 allowAnonymousTelemetry: !allowAnonymousTelemetry,
232 })
233 }
234 text="Allow Anonymous Telemetry"
235 />
236
237 <ToggleSwitch
238 isToggled={!disableIndexing}
239 onToggle={() =>
240 handleUpdate({
241 disableIndexing: !disableIndexing,
242 })
243 }
244 text="Enable Indexing"
245 />
246
247 {/* <ToggleSwitch
248 isToggled={useAutocompleteCache}
249 onToggle={() =>
250 handleUpdate({
251 useAutocompleteCache: !useAutocompleteCache,
252 })
253 }
254 text="Use Autocomplete Cache"
255 /> */}
256
257 <label className="flex items-center justify-between gap-3">
258 <span className="text-left">Font Size</span>
259 <NumberInput
260 value={fontSize}
261 onChange={(val) => {
262 setLocalStorage("fontSize", val);
263 handleUpdate({
264 fontSize: val,
265 });
266 }}
267 min={7}
268 max={50}
269 />
270 </label>
271 <label className="flex items-center justify-between gap-3">
272 <span className="lines lines-1 text-left">
273 Multiline Autocompletions
274 </span>
275 <Select
276 value={useAutocompleteMultilineCompletions}
277 onChange={(e) =>
278 handleUpdate({
279 useAutocompleteMultilineCompletions: e.target.value as
280 | "auto"
281 | "always"
282 | "never",
283 })
284 }
285 >
286 <option value="auto">Auto</option>
287 <option value="always">Always</option>
288 <option value="never">Never</option>
289 </Select>
290 </label>
291 <label className="flex items-center justify-between gap-3">
292 <span className="text-left">Autocomplete Timeout (ms)</span>
293 <NumberInput
294 value={modelTimeout}
295 onChange={(val) =>
296 handleUpdate({
297 modelTimeout: val,
298 })
299 }
300 min={100}
301 max={5000}
302 />
303 </label>
304 <label className="flex items-center justify-between gap-3">
305 <span className="text-left">Autocomplete Debounce (ms)</span>
306 <NumberInput
307 value={debounceDelay}
308 onChange={(val) =>
309 handleUpdate({
310 debounceDelay: val,
311 })
312 }
313 min={0}
314 max={2500}
315 />
316 </label>
317 <form
318 className="flex flex-col gap-1"
319 onSubmit={(e) => {
320 e.preventDefault();
321 handleDisableAutocompleteSubmit();
322 }}
323 >
324 <div className="flex items-center justify-between">
325 <span>Disable autocomplete in files</span>
326 <div className="flex items-center gap-2">
327 <Input
328 value={formDisableAutocomplete}
329 className="max-w-[100px]"
330 onChange={(e) => {
331 setFormDisableAutocomplete(e.target.value);
332 }}
333 />
334 <div className="flex h-full flex-col">
335 {formDisableAutocomplete !== disableAutocompleteInFiles ? (
336 <>
337 <div
338 onClick={handleDisableAutocompleteSubmit}
339 className="cursor-pointer"
340 >
341 <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
342 </div>
343 <div
344 onClick={cancelChangeDisableAutocomplete}
345 className="cursor-pointer"
346 >
347 <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
348 </div>
349 </>
350 ) : (
351 <div>
352 <CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
353 </div>
354 )}
355 </div>
356 </div>
357 </div>
358 <span className="text-vsc-foreground-muted text-lightgray self-end text-xs">
359 Comma-separated list of path matchers
360 </span>
361 </form>
362 </div>
363
364 <div className="flex flex-col gap-x-2 gap-y-4">
365 <div
366 className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold"
367 onClick={() => setShowExperimental(!showExperimental)}
368 >
369 <ChevronRightIcon
370 className={`h-4 w-4 transition-transform ${
371 showExperimental ? "rotate-90" : ""
372 }`}
373 />
374 <span>Experimental Settings</span>
375 </div>
376 <div
377 className={`duration-400 overflow-hidden transition-all ease-in-out ${
378 showExperimental
379 ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */
380 : "max-h-0"
381 }`}
382 >
383 <div className="flex flex-col gap-x-1 gap-y-4 pl-6">
384 <ToggleSwitch
385 isToggled={autoAcceptEditToolDiffs}
386 onToggle={() =>
387 handleUpdate({
388 autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs,
389 })
390 }
391 text="Auto-Accept Agent Edits"
392 showIfToggled={
393 <>
394 <ExclamationTriangleIcon
395 data-tooltip-id={`auto-accept-diffs-warning-tooltip`}
396 className="h-3 w-3 text-yellow-500"
397 />
398 <ToolTip id={`auto-accept-diffs-warning-tooltip`}>
399 {`Be very careful with this setting. When turned on, Agent mode's edit tool can make changes to files with no manual review or guaranteed stopping point`}
400 </ToolTip>
401 </>
402 }
403 />
404
405 <ToggleSwitch
406 isToggled={useCurrentFileAsContext}
407 onToggle={() =>
408 handleUpdate({
409 useCurrentFileAsContext: !useCurrentFileAsContext,
410 })
411 }
412 text="Add Current File by Default"
413 />
414
415 <ToggleSwitch
416 isToggled={enableExperimentalTools}
417 onToggle={() =>
418 handleUpdate({
419 enableExperimentalTools: !enableExperimentalTools,
420 })
421 }
422 text="Enable experimental tools"
423 />
424
425 {hasContinueEmail && (
426 <ContinueFeaturesMenu
427 logEditingData={logEditingData}
428 handleLogEditingDataToggle={handleLogEditingDataToggle}
429 optInNextEditFeature={optInNextEditFeature}
430 handleOptInNextEditToggle={handleOptInNextEditToggle}
431 />
432 )}
433 </div>
434 </div>
435 </div>
436 </div>
437 ) : null}
438 </div>
439 );
440}