Elffuss BraidHub

kikocis/continue public

4e263ad457a7 · 16.9 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 { selectCurrentOrg } from "../../redux/slices/profilesSlice";
24import { isContinueTeamMember } from "../../util/isContinueTeamMember";
25import { setLocalStorage } from "../../util/localStorage";
26import { ContinueFeaturesMenu } from "./ContinueFeaturesMenu";
27
28export function UserSettingsForm() {
29 /////// User settings section //////
30 const dispatch = useAppDispatch();
31 const ideMessenger = useContext(IdeMessengerContext);
32 const config = useAppSelector((state) => state.config.config);
33 const currentOrg = useAppSelector(selectCurrentOrg);
34
35 const [showExperimental, setShowExperimental] = useState(false);
36 const { session } = useAuth();
37
38 function handleUpdate(sharedConfig: SharedConfigSchema) {
39 // Optimistic update
40 const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig);
41 dispatch(updateConfig(updatedConfig));
42 // IMPORTANT no need for model role updates (separate logic for selected model roles)
43 // simply because this function won't be used to update model roles
44
45 // Actual update to core which propagates back with config update event
46 ideMessenger.post("config/updateSharedConfig", sharedConfig);
47 }
48
49 // Disable autocomplete
50 const disableAutocompleteInFiles = (
51 config.tabAutocompleteOptions?.disableInFiles ?? []
52 ).join(", ");
53 const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
54 disableAutocompleteInFiles,
55 );
56
57 useEffect(() => {
58 // Necessary so that reformatted/trimmed values don't cause dirty state
59 setFormDisableAutocomplete(disableAutocompleteInFiles);
60 }, [disableAutocompleteInFiles]);
61
62 // Workspace prompts
63 const promptPath = config.experimental?.promptPath || "";
64 const [formPromptPath, setFormPromptPath] = useState(promptPath);
65 const cancelChangePromptPath = () => {
66 setFormPromptPath(promptPath);
67 };
68 const handleSubmitPromptPath = () => {
69 handleUpdate({
70 promptPath: formPromptPath || "",
71 });
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 onlyUseSystemMessageTools =
96 config.experimental?.onlyUseSystemMessageTools ?? 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 = isContinueTeamMember(
137 (session as HubSessionInfo)?.account?.id,
138 );
139
140 const disableTelemetryToggle =
141 currentOrg?.policy?.allowAnonymousTelemetry === false;
142
143 return (
144 <div className="flex flex-col">
145 {/* {selectedProfile && isLocalProfile(selectedProfile) ? (
146 <div className="flex items-center justify-center">
147 <SecondaryButton
148 className="flex flex-row items-center gap-1"
149 onClick={() => {
150 ideMessenger.post("config/openProfile", {
151 profileId: selectedProfile.id,
152 });
153 }}
154 >
155 <span>Open</span>
156 <span>Config</span>
157 <span className="xs:flex hidden">File</span>
158 </SecondaryButton>
159 </div>
160 ) : null} */}
161 {hubEnabled ? (
162 <div className="flex flex-col gap-4 py-4">
163 <div>
164 <h2 className="mb-2 mt-0 p-0">User settings</h2>
165 </div>
166
167 <div className="flex flex-col gap-4">
168 <ToggleSwitch
169 isToggled={showSessionTabs}
170 onToggle={() =>
171 handleUpdate({
172 showSessionTabs: !showSessionTabs,
173 })
174 }
175 text="Show Session Tabs"
176 />
177 <ToggleSwitch
178 isToggled={codeWrap}
179 onToggle={() =>
180 handleUpdate({
181 codeWrap: !codeWrap,
182 })
183 }
184 text="Wrap Codeblocks"
185 />
186
187 <ToggleSwitch
188 isToggled={showChatScrollbar}
189 onToggle={() =>
190 handleUpdate({
191 showChatScrollbar: !showChatScrollbar,
192 })
193 }
194 text="Show Chat Scrollbar"
195 />
196 <ToggleSwitch
197 isToggled={readResponseTTS}
198 onToggle={() =>
199 handleUpdate({
200 readResponseTTS: !readResponseTTS,
201 })
202 }
203 text="Text-to-Speech Output"
204 />
205 {/* <ToggleSwitch
206 isToggled={useChromiumForDocsCrawling}
207 onToggle={() =>
208 handleUpdate({
209 useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
210 })
211 }
212 text="Use Chromium for Docs Crawling"
213 /> */}
214 <ToggleSwitch
215 isToggled={!disableSessionTitles}
216 onToggle={() =>
217 handleUpdate({
218 disableSessionTitles: !disableSessionTitles,
219 })
220 }
221 text="Enable Session Titles"
222 />
223 <ToggleSwitch
224 isToggled={!displayRawMarkdown}
225 onToggle={() =>
226 handleUpdate({
227 displayRawMarkdown: !displayRawMarkdown,
228 })
229 }
230 text="Format Markdown"
231 />
232
233 <ToggleSwitch
234 isToggled={allowAnonymousTelemetry}
235 disabled={disableTelemetryToggle}
236 onToggle={() =>
237 handleUpdate({
238 allowAnonymousTelemetry: !allowAnonymousTelemetry,
239 })
240 }
241 text="Allow Anonymous Telemetry"
242 />
243
244 <ToggleSwitch
245 isToggled={!disableIndexing}
246 onToggle={() =>
247 handleUpdate({
248 disableIndexing: !disableIndexing,
249 })
250 }
251 text="Enable Indexing"
252 />
253
254 {/* <ToggleSwitch
255 isToggled={useAutocompleteCache}
256 onToggle={() =>
257 handleUpdate({
258 useAutocompleteCache: !useAutocompleteCache,
259 })
260 }
261 text="Use Autocomplete Cache"
262 /> */}
263
264 <label className="flex items-center justify-between gap-3">
265 <span className="text-left">Font Size</span>
266 <NumberInput
267 value={fontSize}
268 onChange={(val) => {
269 setLocalStorage("fontSize", val);
270 handleUpdate({
271 fontSize: val,
272 });
273 }}
274 min={7}
275 max={50}
276 />
277 </label>
278 <label className="flex items-center justify-between gap-3">
279 <span className="lines lines-1 text-left">
280 Multiline Autocompletions
281 </span>
282 <Select
283 value={useAutocompleteMultilineCompletions}
284 onChange={(e) =>
285 handleUpdate({
286 useAutocompleteMultilineCompletions: e.target.value as
287 | "auto"
288 | "always"
289 | "never",
290 })
291 }
292 >
293 <option value="auto">Auto</option>
294 <option value="always">Always</option>
295 <option value="never">Never</option>
296 </Select>
297 </label>
298 <label className="flex items-center justify-between gap-3">
299 <span className="text-left">Autocomplete Timeout (ms)</span>
300 <NumberInput
301 value={modelTimeout}
302 onChange={(val) =>
303 handleUpdate({
304 modelTimeout: val,
305 })
306 }
307 min={100}
308 max={5000}
309 />
310 </label>
311 <label className="flex items-center justify-between gap-3">
312 <span className="text-left">Autocomplete Debounce (ms)</span>
313 <NumberInput
314 value={debounceDelay}
315 onChange={(val) =>
316 handleUpdate({
317 debounceDelay: val,
318 })
319 }
320 min={0}
321 max={2500}
322 />
323 </label>
324 <form
325 className="flex flex-col gap-1"
326 onSubmit={(e) => {
327 e.preventDefault();
328 handleDisableAutocompleteSubmit();
329 }}
330 >
331 <div className="flex items-center justify-between">
332 <span>Disable autocomplete in files</span>
333 <div className="flex items-center gap-2">
334 <Input
335 value={formDisableAutocomplete}
336 className="max-w-[100px]"
337 onChange={(e) => {
338 setFormDisableAutocomplete(e.target.value);
339 }}
340 />
341 <div className="flex h-full flex-col">
342 {formDisableAutocomplete !== disableAutocompleteInFiles ? (
343 <>
344 <div
345 onClick={handleDisableAutocompleteSubmit}
346 className="cursor-pointer"
347 >
348 <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
349 </div>
350 <div
351 onClick={cancelChangeDisableAutocomplete}
352 className="cursor-pointer"
353 >
354 <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
355 </div>
356 </>
357 ) : (
358 <div>
359 <CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
360 </div>
361 )}
362 </div>
363 </div>
364 </div>
365 <span className="text-vsc-foreground-muted text-lightgray self-end text-xs">
366 Comma-separated list of path matchers
367 </span>
368 </form>
369 </div>
370
371 <div className="flex flex-col gap-x-2 gap-y-4">
372 <div
373 className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold"
374 onClick={() => setShowExperimental(!showExperimental)}
375 >
376 <ChevronRightIcon
377 className={`h-4 w-4 transition-transform ${
378 showExperimental ? "rotate-90" : ""
379 }`}
380 />
381 <span>Experimental Settings</span>
382 </div>
383 <div
384 className={`duration-400 overflow-hidden transition-all ease-in-out ${
385 showExperimental
386 ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */
387 : "max-h-0"
388 }`}
389 >
390 <div className="flex flex-col gap-x-1 gap-y-4 pl-6">
391 <ToggleSwitch
392 isToggled={autoAcceptEditToolDiffs}
393 onToggle={() =>
394 handleUpdate({
395 autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs,
396 })
397 }
398 text="Auto-Accept Agent Edits"
399 showIfToggled={
400 <>
401 <ExclamationTriangleIcon
402 data-tooltip-id={`auto-accept-diffs-warning-tooltip`}
403 className="h-3 w-3 text-yellow-500"
404 />
405 <ToolTip id={`auto-accept-diffs-warning-tooltip`}>
406 {`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`}
407 </ToolTip>
408 </>
409 }
410 />
411
412 <ToggleSwitch
413 isToggled={useCurrentFileAsContext}
414 onToggle={() =>
415 handleUpdate({
416 useCurrentFileAsContext: !useCurrentFileAsContext,
417 })
418 }
419 text="Add Current File by Default"
420 />
421
422 <ToggleSwitch
423 isToggled={enableExperimentalTools}
424 onToggle={() =>
425 handleUpdate({
426 enableExperimentalTools: !enableExperimentalTools,
427 })
428 }
429 text="Enable experimental tools"
430 />
431
432 <ToggleSwitch
433 isToggled={onlyUseSystemMessageTools}
434 onToggle={() =>
435 handleUpdate({
436 onlyUseSystemMessageTools: !onlyUseSystemMessageTools,
437 })
438 }
439 text="Only use system message tools"
440 />
441
442 <ToggleSwitch
443 isToggled={codebaseToolCallingOnly}
444 onToggle={() =>
445 handleUpdate({
446 codebaseToolCallingOnly: !codebaseToolCallingOnly,
447 })
448 }
449 text="@Codebase: use tool calling only"
450 />
451
452 {hasContinueEmail && (
453 <ContinueFeaturesMenu
454 enableStaticContextualization={
455 enableStaticContextualization
456 }
457 handleEnableStaticContextualizationToggle={
458 handleEnableStaticContextualizationToggle
459 }
460 />
461 )}
462 </div>
463 </div>
464 </div>
465 </div>
466 ) : null}
467 </div>
468 );
469}