Elffuss BraidHub

kikocis/continue public

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