Elffuss BraidHub

kikocis/continue public

ea05c35331da · 19.7 KiBRawPermalink
1import {
2 CheckIcon,
3 ChevronRightIcon,
4 ExclamationTriangleIcon,
5 InformationCircleIcon,
6 XMarkIcon,
7} from "@heroicons/react/24/outline";
8import {
9 SharedConfigSchema,
10 modifyAnyConfigWithSharedConfig,
11} from "core/config/sharedConfig";
12import { HubSessionInfo } from "core/control-plane/AuthTypes";
13import { useContext, useEffect, useState } from "react";
14import { Input } from "../../components";
15import NumberInput from "../../components/gui/NumberInput";
16import { Select } from "../../components/gui/Select";
17import ToggleSwitch from "../../components/gui/Switch";
18import { ToolTip } from "../../components/gui/Tooltip";
19import { useFontSize } from "../../components/ui/font";
20import { useAuth } from "../../context/Auth";
21import { IdeMessengerContext } from "../../context/IdeMessenger";
22import { useAppDispatch, useAppSelector } from "../../redux/hooks";
23import { updateConfig } from "../../redux/slices/configSlice";
24import { selectCurrentOrg } from "../../redux/slices/profilesSlice";
25import { isContinueTeamMember } from "../../util/isContinueTeamMember";
26import { setLocalStorage } from "../../util/localStorage";
27import { ContinueFeaturesMenu } from "./ContinueFeaturesMenu";
28
29export function UserSettingsForm() {
30 /////// User settings section //////
31 const dispatch = useAppDispatch();
32 const ideMessenger = useContext(IdeMessengerContext);
33 const config = useAppSelector((state) => state.config.config);
34 const currentOrg = useAppSelector(selectCurrentOrg);
35
36 const [showExperimental, setShowExperimental] = useState(false);
37 const { session } = useAuth();
38
39 function handleUpdate(sharedConfig: SharedConfigSchema) {
40 // Optimistic update
41 const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig);
42 dispatch(updateConfig(updatedConfig));
43 // IMPORTANT no need for model role updates (separate logic for selected model roles)
44 // simply because this function won't be used to update model roles
45
46 // Actual update to core which propagates back with config update event
47 ideMessenger.post("config/updateSharedConfig", sharedConfig);
48 }
49
50 // Disable autocomplete
51 const disableAutocompleteInFiles = (
52 config.tabAutocompleteOptions?.disableInFiles ?? []
53 ).join(", ");
54 const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
55 disableAutocompleteInFiles,
56 );
57
58 useEffect(() => {
59 // Necessary so that reformatted/trimmed values don't cause dirty state
60 setFormDisableAutocomplete(disableAutocompleteInFiles);
61 }, [disableAutocompleteInFiles]);
62
63 // Workspace prompts
64 const promptPath = config.experimental?.promptPath || "";
65 const [formPromptPath, setFormPromptPath] = useState(promptPath);
66 const cancelChangePromptPath = () => {
67 setFormPromptPath(promptPath);
68 };
69 const handleSubmitPromptPath = () => {
70 handleUpdate({
71 promptPath: formPromptPath || "",
72 });
73 };
74
75 const handleEnableStaticContextualizationToggle = (value: boolean) => {
76 handleUpdate({ enableStaticContextualization: value });
77 };
78
79 useEffect(() => {
80 // Necessary so that reformatted/trimmed values don't cause dirty state
81 setFormPromptPath(promptPath);
82 }, [promptPath]);
83
84 // TODO defaults are in multiple places, should be consolidated and probably not explicit here
85 const showSessionTabs = config.ui?.showSessionTabs ?? false;
86 const continueAfterToolRejection =
87 config.ui?.continueAfterToolRejection ?? false;
88 const codeWrap = config.ui?.codeWrap ?? false;
89 const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
90 const readResponseTTS = config.experimental?.readResponseTTS ?? false;
91 const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false;
92 const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
93 const disableSessionTitles = config.disableSessionTitles ?? false;
94 const useCurrentFileAsContext =
95 config.experimental?.useCurrentFileAsContext ?? false;
96 const enableExperimentalTools =
97 config.experimental?.enableExperimentalTools ?? false;
98 const onlyUseSystemMessageTools =
99 config.experimental?.onlyUseSystemMessageTools ?? false;
100 const codebaseToolCallingOnly =
101 config.experimental?.codebaseToolCallingOnly ?? false;
102 const enableStaticContextualization =
103 config.experimental?.enableStaticContextualization ?? false;
104
105 const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
106 const disableIndexing = config.disableIndexing ?? false;
107
108 // const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? true;
109 // const useChromiumForDocsCrawling =
110 // config.experimental?.useChromiumForDocsCrawling ?? false;
111 // const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
112 const useAutocompleteMultilineCompletions =
113 config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
114 const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150;
115 const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250;
116 const fontSize = useFontSize();
117
118 const cancelChangeDisableAutocomplete = () => {
119 setFormDisableAutocomplete(disableAutocompleteInFiles);
120 };
121 const handleDisableAutocompleteSubmit = () => {
122 handleUpdate({
123 disableAutocompleteInFiles: formDisableAutocomplete
124 .split(",")
125 .map((val) => val.trim())
126 .filter((val) => !!val),
127 });
128 };
129
130 const [hubEnabled, setHubEnabled] = useState(false);
131 useEffect(() => {
132 void ideMessenger.ide
133 .getIdeSettings()
134 .then(({ continueTestEnvironment }) => {
135 setHubEnabled(continueTestEnvironment === "production");
136 });
137 }, [ideMessenger]);
138
139 const hasContinueEmail = isContinueTeamMember(
140 (session as HubSessionInfo)?.account?.id,
141 );
142
143 const disableTelemetryToggle =
144 currentOrg?.policy?.allowAnonymousTelemetry === false;
145 const disableIndexingToggle =
146 currentOrg?.policy?.allowCodebaseIndexing === false;
147
148 return (
149 <div className="flex flex-col">
150 {/* {selectedProfile && isLocalProfile(selectedProfile) ? (
151 <div className="flex items-center justify-center">
152 <SecondaryButton
153 className="flex flex-row items-center gap-1"
154 onClick={() => {
155 ideMessenger.post("config/openProfile", {
156 profileId: selectedProfile.id,
157 });
158 }}
159 >
160 <span>Open</span>
161 <span>Config</span>
162 <span className="xs:flex hidden">File</span>
163 </SecondaryButton>
164 </div>
165 ) : null} */}
166 {hubEnabled ? (
167 <div className="flex flex-col gap-4 py-4">
168 <div>
169 <h2 className="mb-2 mt-0 p-0">User settings</h2>
170 </div>
171
172 <div className="flex flex-col gap-4">
173 <ToggleSwitch
174 isToggled={showSessionTabs}
175 onToggle={() =>
176 handleUpdate({
177 showSessionTabs: !showSessionTabs,
178 })
179 }
180 text="Show Session Tabs"
181 tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions."
182 />
183 <ToggleSwitch
184 isToggled={codeWrap}
185 onToggle={() =>
186 handleUpdate({
187 codeWrap: !codeWrap,
188 })
189 }
190 text="Wrap Codeblocks"
191 tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions."
192 />
193
194 <ToggleSwitch
195 isToggled={showChatScrollbar}
196 onToggle={() =>
197 handleUpdate({
198 showChatScrollbar: !showChatScrollbar,
199 })
200 }
201 text="Show Chat Scrollbar"
202 tooltip="If on, enables a scrollbar in the chat window."
203 />
204 <ToggleSwitch
205 isToggled={readResponseTTS}
206 onToggle={() =>
207 handleUpdate({
208 readResponseTTS: !readResponseTTS,
209 })
210 }
211 text="Text-to-Speech Output"
212 tooltip="If on, reads LLM responses aloud with TTS."
213 />
214 {/* <ToggleSwitch
215 isToggled={useChromiumForDocsCrawling}
216 onToggle={() =>
217 handleUpdate({
218 useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
219 })
220 }
221 text="Use Chromium for Docs Crawling"
222 /> */}
223 <ToggleSwitch
224 isToggled={!disableSessionTitles}
225 onToggle={() =>
226 handleUpdate({
227 disableSessionTitles: !disableSessionTitles,
228 })
229 }
230 text="Enable Session Titles"
231 tooltip="If on, generates summary titles for each chat session after the first message, using the current Chat model."
232 />
233 <ToggleSwitch
234 isToggled={!displayRawMarkdown}
235 onToggle={() =>
236 handleUpdate({
237 displayRawMarkdown: !displayRawMarkdown,
238 })
239 }
240 text="Format Markdown"
241 tooltip="If off, shows responses as raw text."
242 />
243
244 <ToggleSwitch
245 isToggled={allowAnonymousTelemetry}
246 disabled={disableTelemetryToggle}
247 onToggle={() =>
248 handleUpdate({
249 allowAnonymousTelemetry: !allowAnonymousTelemetry,
250 })
251 }
252 text="Allow Anonymous Telemetry"
253 tooltip="If on, allows Continue to send anonymous telemetry."
254 />
255
256 <ToggleSwitch
257 isToggled={!disableIndexing}
258 disabled={disableIndexingToggle}
259 onToggle={() =>
260 handleUpdate({
261 disableIndexing: !disableIndexing,
262 })
263 }
264 text="Enable Indexing"
265 />
266
267 {/* <ToggleSwitch
268 isToggled={useAutocompleteCache}
269 onToggle={() =>
270 handleUpdate({
271 useAutocompleteCache: !useAutocompleteCache,
272 })
273 }
274 text="Use Autocomplete Cache"
275 /> */}
276
277 <label className="flex items-center justify-between gap-3">
278 <span className="flex items-center gap-x-1 text-left">
279 Font Size{" "}
280 <ToolTip content="Specifies base font size for UI elements">
281 <InformationCircleIcon className="h-3 w-3" />
282 </ToolTip>
283 </span>
284 <NumberInput
285 value={fontSize}
286 onChange={(val) => {
287 setLocalStorage("fontSize", val);
288 handleUpdate({
289 fontSize: val,
290 });
291 }}
292 min={7}
293 max={50}
294 />
295 </label>
296 <label className="flex items-center justify-between gap-3">
297 <span className="lines lines-1 flex items-center gap-x-1 text-left">
298 Multiline Autocompletions
299 <ToolTip content="Controls multiline completions for autocomplete.">
300 <InformationCircleIcon className="h-3 w-3" />
301 </ToolTip>
302 </span>
303 <Select
304 value={useAutocompleteMultilineCompletions}
305 onChange={(e) =>
306 handleUpdate({
307 useAutocompleteMultilineCompletions: e.target.value as
308 | "auto"
309 | "always"
310 | "never",
311 })
312 }
313 >
314 <option value="auto">Auto</option>
315 <option value="always">Always</option>
316 <option value="never">Never</option>
317 </Select>
318 </label>
319 <label className="flex items-center justify-between gap-3">
320 <span className="flex items-center gap-x-1 text-left">
321 Autocomplete Timeout (ms)
322 <ToolTip content="Maximum time in milliseconds for autocomplete request/retrieval.">
323 <InformationCircleIcon className="h-3 w-3" />
324 </ToolTip>
325 </span>
326 <NumberInput
327 value={modelTimeout}
328 onChange={(val) =>
329 handleUpdate({
330 modelTimeout: val,
331 })
332 }
333 min={100}
334 max={5000}
335 />
336 </label>
337 <label className="flex items-center justify-between gap-3">
338 <span className="flex items-center gap-x-1 text-left">
339 Autocomplete Debounce (ms)
340 <ToolTip content="Minimum time in milliseconds to trigger an autocomplete request after a change.">
341 <InformationCircleIcon className="h-3 w-3" />
342 </ToolTip>
343 </span>
344 <NumberInput
345 value={debounceDelay}
346 onChange={(val) =>
347 handleUpdate({
348 debounceDelay: val,
349 })
350 }
351 min={0}
352 max={2500}
353 />
354 </label>
355 <form
356 className="flex flex-col gap-1"
357 onSubmit={(e) => {
358 e.preventDefault();
359 handleDisableAutocompleteSubmit();
360 }}
361 >
362 <div className="flex items-center justify-between">
363 <span className="flex items-center gap-x-1">
364 Disable autocomplete in files
365 <ToolTip content="List of comma-separated glob pattern to disable autocomplete in matching files. E.g., **/*.{txt,md}">
366 <InformationCircleIcon className="h-3 w-3" />
367 </ToolTip>
368 </span>
369 <div className="flex items-center gap-2">
370 <Input
371 value={formDisableAutocomplete}
372 className="max-w-[100px]"
373 onChange={(e) => {
374 setFormDisableAutocomplete(e.target.value);
375 }}
376 />
377 <div className="flex h-full flex-col">
378 {formDisableAutocomplete !== disableAutocompleteInFiles ? (
379 <>
380 <div
381 onClick={handleDisableAutocompleteSubmit}
382 className="cursor-pointer"
383 >
384 <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
385 </div>
386 <div
387 onClick={cancelChangeDisableAutocomplete}
388 className="cursor-pointer"
389 >
390 <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
391 </div>
392 </>
393 ) : (
394 <div>
395 <CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
396 </div>
397 )}
398 </div>
399 </div>
400 </div>
401 <span className="text-vsc-foreground-muted text-lightgray self-end text-xs">
402 Comma-separated list of path matchers
403 </span>
404 </form>
405 </div>
406
407 <div className="flex flex-col gap-x-2 gap-y-4">
408 <div
409 className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold"
410 onClick={() => setShowExperimental(!showExperimental)}
411 >
412 <ChevronRightIcon
413 className={`h-4 w-4 transition-transform ${
414 showExperimental ? "rotate-90" : ""
415 }`}
416 />
417 <span>Experimental Settings</span>
418 </div>
419 <div
420 className={`duration-400 overflow-hidden transition-all ease-in-out ${
421 showExperimental
422 ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */
423 : "max-h-0"
424 }`}
425 >
426 <div className="flex flex-col gap-x-1 gap-y-4 pl-6">
427 <ToggleSwitch
428 isToggled={autoAcceptEditToolDiffs}
429 onToggle={() =>
430 handleUpdate({
431 autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs,
432 })
433 }
434 text="Auto-Accept Agent Edits"
435 tooltip="If on, diffs generated by the edit tool are
436 automatically accepted and Agent proceeds with the next conversational turn."
437 showIfToggled={
438 <>
439 <ToolTip
440 content={`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`}
441 >
442 <ExclamationTriangleIcon className="h-3 w-3 text-yellow-500" />
443 </ToolTip>
444 </>
445 }
446 />
447
448 <ToggleSwitch
449 isToggled={useCurrentFileAsContext}
450 onToggle={() =>
451 handleUpdate({
452 useCurrentFileAsContext: !useCurrentFileAsContext,
453 })
454 }
455 text="Add Current File by Default"
456 tooltip="If on, the currently open file is added as context in every new conversation."
457 />
458
459 <ToggleSwitch
460 isToggled={enableExperimentalTools}
461 onToggle={() =>
462 handleUpdate({
463 enableExperimentalTools: !enableExperimentalTools,
464 })
465 }
466 text="Enable experimental tools"
467 />
468
469 <ToggleSwitch
470 isToggled={onlyUseSystemMessageTools}
471 onToggle={() =>
472 handleUpdate({
473 onlyUseSystemMessageTools: !onlyUseSystemMessageTools,
474 })
475 }
476 tooltip="If on, Continue will not attempt to use native tool calling and will only use system message tools."
477 text="Only use system message tools"
478 />
479
480 <ToggleSwitch
481 isToggled={codebaseToolCallingOnly}
482 onToggle={() =>
483 handleUpdate({
484 codebaseToolCallingOnly: !codebaseToolCallingOnly,
485 })
486 }
487 text="@Codebase: use tool calling only"
488 />
489
490 <ToggleSwitch
491 isToggled={continueAfterToolRejection}
492 onToggle={() =>
493 handleUpdate({
494 continueAfterToolRejection: !continueAfterToolRejection,
495 })
496 }
497 text="Stream after tool rejection"
498 tooltip="If on, streaming will continue after the tool call is rejected."
499 />
500
501 {hasContinueEmail && (
502 <ContinueFeaturesMenu
503 enableStaticContextualization={
504 enableStaticContextualization
505 }
506 handleEnableStaticContextualizationToggle={
507 handleEnableStaticContextualizationToggle
508 }
509 />
510 )}
511 </div>
512 </div>
513 </div>
514 </div>
515 ) : null}
516 </div>
517 );
518}