Elffuss BraidHub

kikocis/continue public

b68bd43d7a56 · 16.6 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 handleEnableStaticContextualizationToggle = (value: boolean) => {
71 handleUpdate({ enableStaticContextualization: value });
72 };
73
74 useEffect(() => {
75 // Necessary so that reformatted/trimmed values don't cause dirty state
76 setFormPromptPath(promptPath);
77 }, [promptPath]);
78
79 // TODO defaults are in multiple places, should be consolidated and probably not explicit here
80 const showSessionTabs = config.ui?.showSessionTabs ?? false;
81 const codeWrap = config.ui?.codeWrap ?? false;
82 const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
83 const readResponseTTS = config.experimental?.readResponseTTS ?? false;
84 const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false;
85 const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
86 const disableSessionTitles = config.disableSessionTitles ?? false;
87 const useCurrentFileAsContext =
88 config.experimental?.useCurrentFileAsContext ?? false;
89 const enableExperimentalTools =
90 config.experimental?.enableExperimentalTools ?? false;
91 const onlyUseSystemMessageTools =
92 config.experimental?.onlyUseSystemMessageTools ?? false;
93 const codebaseToolCallingOnly =
94 config.experimental?.codebaseToolCallingOnly ?? false;
95 const enableStaticContextualization =
96 config.experimental?.enableStaticContextualization ?? false;
97
98 const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
99 const disableIndexing = config.disableIndexing ?? false;
100
101 // const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? true;
102 // const useChromiumForDocsCrawling =
103 // config.experimental?.useChromiumForDocsCrawling ?? false;
104 // const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
105 const useAutocompleteMultilineCompletions =
106 config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
107 const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150;
108 const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250;
109 const fontSize = useFontSize();
110
111 const cancelChangeDisableAutocomplete = () => {
112 setFormDisableAutocomplete(disableAutocompleteInFiles);
113 };
114 const handleDisableAutocompleteSubmit = () => {
115 handleUpdate({
116 disableAutocompleteInFiles: formDisableAutocomplete
117 .split(",")
118 .map((val) => val.trim())
119 .filter((val) => !!val),
120 });
121 };
122
123 const [hubEnabled, setHubEnabled] = useState(false);
124 useEffect(() => {
125 void ideMessenger.ide
126 .getIdeSettings()
127 .then(({ continueTestEnvironment }) => {
128 setHubEnabled(continueTestEnvironment === "production");
129 });
130 }, [ideMessenger]);
131
132 const hasContinueEmail = (session as HubSessionInfo)?.account?.id.includes(
133 "@continue.dev",
134 );
135
136 return (
137 <div className="flex flex-col">
138 {/* {selectedProfile && isLocalProfile(selectedProfile) ? (
139 <div className="flex items-center justify-center">
140 <SecondaryButton
141 className="flex flex-row items-center gap-1"
142 onClick={() => {
143 ideMessenger.post("config/openProfile", {
144 profileId: selectedProfile.id,
145 });
146 }}
147 >
148 <span>Open</span>
149 <span>Config</span>
150 <span className="xs:flex hidden">File</span>
151 </SecondaryButton>
152 </div>
153 ) : null} */}
154 {hubEnabled ? (
155 <div className="flex flex-col gap-4 py-4">
156 <div>
157 <h2 className="mb-2 mt-0 p-0">User settings</h2>
158 </div>
159
160 <div className="flex flex-col gap-4">
161 <ToggleSwitch
162 isToggled={showSessionTabs}
163 onToggle={() =>
164 handleUpdate({
165 showSessionTabs: !showSessionTabs,
166 })
167 }
168 text="Show Session Tabs"
169 />
170 <ToggleSwitch
171 isToggled={codeWrap}
172 onToggle={() =>
173 handleUpdate({
174 codeWrap: !codeWrap,
175 })
176 }
177 text="Wrap Codeblocks"
178 />
179
180 <ToggleSwitch
181 isToggled={showChatScrollbar}
182 onToggle={() =>
183 handleUpdate({
184 showChatScrollbar: !showChatScrollbar,
185 })
186 }
187 text="Show Chat Scrollbar"
188 />
189 <ToggleSwitch
190 isToggled={readResponseTTS}
191 onToggle={() =>
192 handleUpdate({
193 readResponseTTS: !readResponseTTS,
194 })
195 }
196 text="Text-to-Speech Output"
197 />
198 {/* <ToggleSwitch
199 isToggled={useChromiumForDocsCrawling}
200 onToggle={() =>
201 handleUpdate({
202 useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
203 })
204 }
205 text="Use Chromium for Docs Crawling"
206 /> */}
207 <ToggleSwitch
208 isToggled={!disableSessionTitles}
209 onToggle={() =>
210 handleUpdate({
211 disableSessionTitles: !disableSessionTitles,
212 })
213 }
214 text="Enable Session Titles"
215 />
216 <ToggleSwitch
217 isToggled={!displayRawMarkdown}
218 onToggle={() =>
219 handleUpdate({
220 displayRawMarkdown: !displayRawMarkdown,
221 })
222 }
223 text="Format Markdown"
224 />
225
226 <ToggleSwitch
227 isToggled={allowAnonymousTelemetry}
228 onToggle={() =>
229 handleUpdate({
230 allowAnonymousTelemetry: !allowAnonymousTelemetry,
231 })
232 }
233 text="Allow Anonymous Telemetry"
234 />
235
236 <ToggleSwitch
237 isToggled={!disableIndexing}
238 onToggle={() =>
239 handleUpdate({
240 disableIndexing: !disableIndexing,
241 })
242 }
243 text="Enable Indexing"
244 />
245
246 {/* <ToggleSwitch
247 isToggled={useAutocompleteCache}
248 onToggle={() =>
249 handleUpdate({
250 useAutocompleteCache: !useAutocompleteCache,
251 })
252 }
253 text="Use Autocomplete Cache"
254 /> */}
255
256 <label className="flex items-center justify-between gap-3">
257 <span className="text-left">Font Size</span>
258 <NumberInput
259 value={fontSize}
260 onChange={(val) => {
261 setLocalStorage("fontSize", val);
262 handleUpdate({
263 fontSize: val,
264 });
265 }}
266 min={7}
267 max={50}
268 />
269 </label>
270 <label className="flex items-center justify-between gap-3">
271 <span className="lines lines-1 text-left">
272 Multiline Autocompletions
273 </span>
274 <Select
275 value={useAutocompleteMultilineCompletions}
276 onChange={(e) =>
277 handleUpdate({
278 useAutocompleteMultilineCompletions: e.target.value as
279 | "auto"
280 | "always"
281 | "never",
282 })
283 }
284 >
285 <option value="auto">Auto</option>
286 <option value="always">Always</option>
287 <option value="never">Never</option>
288 </Select>
289 </label>
290 <label className="flex items-center justify-between gap-3">
291 <span className="text-left">Autocomplete Timeout (ms)</span>
292 <NumberInput
293 value={modelTimeout}
294 onChange={(val) =>
295 handleUpdate({
296 modelTimeout: val,
297 })
298 }
299 min={100}
300 max={5000}
301 />
302 </label>
303 <label className="flex items-center justify-between gap-3">
304 <span className="text-left">Autocomplete Debounce (ms)</span>
305 <NumberInput
306 value={debounceDelay}
307 onChange={(val) =>
308 handleUpdate({
309 debounceDelay: val,
310 })
311 }
312 min={0}
313 max={2500}
314 />
315 </label>
316 <form
317 className="flex flex-col gap-1"
318 onSubmit={(e) => {
319 e.preventDefault();
320 handleDisableAutocompleteSubmit();
321 }}
322 >
323 <div className="flex items-center justify-between">
324 <span>Disable autocomplete in files</span>
325 <div className="flex items-center gap-2">
326 <Input
327 value={formDisableAutocomplete}
328 className="max-w-[100px]"
329 onChange={(e) => {
330 setFormDisableAutocomplete(e.target.value);
331 }}
332 />
333 <div className="flex h-full flex-col">
334 {formDisableAutocomplete !== disableAutocompleteInFiles ? (
335 <>
336 <div
337 onClick={handleDisableAutocompleteSubmit}
338 className="cursor-pointer"
339 >
340 <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
341 </div>
342 <div
343 onClick={cancelChangeDisableAutocomplete}
344 className="cursor-pointer"
345 >
346 <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
347 </div>
348 </>
349 ) : (
350 <div>
351 <CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
352 </div>
353 )}
354 </div>
355 </div>
356 </div>
357 <span className="text-vsc-foreground-muted text-lightgray self-end text-xs">
358 Comma-separated list of path matchers
359 </span>
360 </form>
361 </div>
362
363 <div className="flex flex-col gap-x-2 gap-y-4">
364 <div
365 className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold"
366 onClick={() => setShowExperimental(!showExperimental)}
367 >
368 <ChevronRightIcon
369 className={`h-4 w-4 transition-transform ${
370 showExperimental ? "rotate-90" : ""
371 }`}
372 />
373 <span>Experimental Settings</span>
374 </div>
375 <div
376 className={`duration-400 overflow-hidden transition-all ease-in-out ${
377 showExperimental
378 ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */
379 : "max-h-0"
380 }`}
381 >
382 <div className="flex flex-col gap-x-1 gap-y-4 pl-6">
383 <ToggleSwitch
384 isToggled={autoAcceptEditToolDiffs}
385 onToggle={() =>
386 handleUpdate({
387 autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs,
388 })
389 }
390 text="Auto-Accept Agent Edits"
391 showIfToggled={
392 <>
393 <ExclamationTriangleIcon
394 data-tooltip-id={`auto-accept-diffs-warning-tooltip`}
395 className="h-3 w-3 text-yellow-500"
396 />
397 <ToolTip id={`auto-accept-diffs-warning-tooltip`}>
398 {`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`}
399 </ToolTip>
400 </>
401 }
402 />
403
404 <ToggleSwitch
405 isToggled={useCurrentFileAsContext}
406 onToggle={() =>
407 handleUpdate({
408 useCurrentFileAsContext: !useCurrentFileAsContext,
409 })
410 }
411 text="Add Current File by Default"
412 />
413
414 <ToggleSwitch
415 isToggled={enableExperimentalTools}
416 onToggle={() =>
417 handleUpdate({
418 enableExperimentalTools: !enableExperimentalTools,
419 })
420 }
421 text="Enable experimental tools"
422 />
423
424 <ToggleSwitch
425 isToggled={onlyUseSystemMessageTools}
426 onToggle={() =>
427 handleUpdate({
428 onlyUseSystemMessageTools: !onlyUseSystemMessageTools,
429 })
430 }
431 text="Only use system message tools"
432 />
433
434 <ToggleSwitch
435 isToggled={codebaseToolCallingOnly}
436 onToggle={() =>
437 handleUpdate({
438 codebaseToolCallingOnly: !codebaseToolCallingOnly,
439 })
440 }
441 text="@Codebase: use tool calling only"
442 />
443
444 {hasContinueEmail && (
445 <ContinueFeaturesMenu
446 enableStaticContextualization={
447 enableStaticContextualization
448 }
449 handleEnableStaticContextualizationToggle={
450 handleEnableStaticContextualizationToggle
451 }
452 />
453 )}
454 </div>
455 </div>
456 </div>
457 </div>
458 ) : null}
459 </div>
460 );
461}