Elffuss BraidHub

kikocis/continue public

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