Elffuss BraidHub

kikocis/continue public

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