Elffuss BraidHub

kikocis/continue public

95c91a48de4e · 13.8 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 { useContext, useEffect, useState } from "react";
12import { Input } from "../../components";
13import NumberInput from "../../components/gui/NumberInput";
14import { Select } from "../../components/gui/Select";
15import ToggleSwitch from "../../components/gui/Switch";
16import { ToolTip } from "../../components/gui/Tooltip";
17import { useFontSize } from "../../components/ui/font";
18import { IdeMessengerContext } from "../../context/IdeMessenger";
19import { useAppDispatch, useAppSelector } from "../../redux/hooks";
20import { updateConfig } from "../../redux/slices/configSlice";
21import { setLocalStorage } from "../../util/localStorage";
22
23export function UserSettingsForm() {
24 /////// User settings section //////
25 const dispatch = useAppDispatch();
26 const ideMessenger = useContext(IdeMessengerContext);
27 const config = useAppSelector((state) => state.config.config);
28 const [showExperimental, setShowExperimental] = useState(false);
29
30 function handleUpdate(sharedConfig: SharedConfigSchema) {
31 // Optimistic update
32 const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig);
33 dispatch(updateConfig(updatedConfig));
34 // IMPORTANT no need for model role updates (separate logic for selected model roles)
35 // simply because this function won't be used to update model roles
36
37 // Actual update to core which propagates back with config update event
38 ideMessenger.post("config/updateSharedConfig", sharedConfig);
39 }
40
41 // Disable autocomplete
42 const disableAutocompleteInFiles = (
43 config.tabAutocompleteOptions?.disableInFiles ?? []
44 ).join(", ");
45 const [formDisableAutocomplete, setFormDisableAutocomplete] = useState(
46 disableAutocompleteInFiles,
47 );
48
49 useEffect(() => {
50 // Necessary so that reformatted/trimmed values don't cause dirty state
51 setFormDisableAutocomplete(disableAutocompleteInFiles);
52 }, [disableAutocompleteInFiles]);
53
54 // Workspace prompts
55 const promptPath = config.experimental?.promptPath || "";
56 const [formPromptPath, setFormPromptPath] = useState(promptPath);
57 const cancelChangePromptPath = () => {
58 setFormPromptPath(promptPath);
59 };
60 const handleSubmitPromptPath = () => {
61 handleUpdate({
62 promptPath: formPromptPath || "",
63 });
64 };
65
66 useEffect(() => {
67 // Necessary so that reformatted/trimmed values don't cause dirty state
68 setFormPromptPath(promptPath);
69 }, [promptPath]);
70
71 // TODO defaults are in multiple places, should be consolidated and probably not explicit here
72 const showSessionTabs = config.ui?.showSessionTabs ?? false;
73 const codeWrap = config.ui?.codeWrap ?? false;
74 const showChatScrollbar = config.ui?.showChatScrollbar ?? false;
75 const readResponseTTS = config.experimental?.readResponseTTS ?? false;
76 const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false;
77 const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false;
78 const disableSessionTitles = config.disableSessionTitles ?? false;
79
80 const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true;
81 const disableIndexing = config.disableIndexing ?? false;
82
83 // const useAutocompleteCache = config.tabAutocompleteOptions?.useCache ?? true;
84 // const useChromiumForDocsCrawling =
85 // config.experimental?.useChromiumForDocsCrawling ?? false;
86 // const codeBlockToolbarPosition = config.ui?.codeBlockToolbarPosition ?? "top";
87 const useAutocompleteMultilineCompletions =
88 config.tabAutocompleteOptions?.multilineCompletions ?? "auto";
89 const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150;
90 const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250;
91 const fontSize = useFontSize();
92
93 const cancelChangeDisableAutocomplete = () => {
94 setFormDisableAutocomplete(disableAutocompleteInFiles);
95 };
96 const handleDisableAutocompleteSubmit = () => {
97 handleUpdate({
98 disableAutocompleteInFiles: formDisableAutocomplete
99 .split(",")
100 .map((val) => val.trim())
101 .filter((val) => !!val),
102 });
103 };
104
105 const [hubEnabled, setHubEnabled] = useState(false);
106 useEffect(() => {
107 ideMessenger.ide.getIdeSettings().then(({ continueTestEnvironment }) => {
108 setHubEnabled(continueTestEnvironment === "production");
109 });
110 }, [ideMessenger]);
111
112 return (
113 <div className="flex flex-col">
114 {/* {selectedProfile && isLocalProfile(selectedProfile) ? (
115 <div className="flex items-center justify-center">
116 <SecondaryButton
117 className="flex flex-row items-center gap-1"
118 onClick={() => {
119 ideMessenger.post("config/openProfile", {
120 profileId: selectedProfile.id,
121 });
122 }}
123 >
124 <span>Open</span>
125 <span>Config</span>
126 <span className="xs:flex hidden">File</span>
127 </SecondaryButton>
128 </div>
129 ) : null} */}
130 {hubEnabled ? (
131 <div className="flex flex-col gap-4 py-4">
132 <div>
133 <h2 className="mb-2 mt-0 p-0">User settings</h2>
134 </div>
135
136 <div className="flex flex-col gap-4">
137 <ToggleSwitch
138 isToggled={showSessionTabs}
139 onToggle={() =>
140 handleUpdate({
141 showSessionTabs: !showSessionTabs,
142 })
143 }
144 text="Show Session Tabs"
145 />
146 <ToggleSwitch
147 isToggled={codeWrap}
148 onToggle={() =>
149 handleUpdate({
150 codeWrap: !codeWrap,
151 })
152 }
153 text="Wrap Codeblocks"
154 />
155
156 <ToggleSwitch
157 isToggled={showChatScrollbar}
158 onToggle={() =>
159 handleUpdate({
160 showChatScrollbar: !showChatScrollbar,
161 })
162 }
163 text="Show Chat Scrollbar"
164 />
165 <ToggleSwitch
166 isToggled={readResponseTTS}
167 onToggle={() =>
168 handleUpdate({
169 readResponseTTS: !readResponseTTS,
170 })
171 }
172 text="Text-to-Speech Output"
173 />
174 {/* <ToggleSwitch
175 isToggled={useChromiumForDocsCrawling}
176 onToggle={() =>
177 handleUpdate({
178 useChromiumForDocsCrawling: !useChromiumForDocsCrawling,
179 })
180 }
181 text="Use Chromium for Docs Crawling"
182 /> */}
183 <ToggleSwitch
184 isToggled={!disableSessionTitles}
185 onToggle={() =>
186 handleUpdate({
187 disableSessionTitles: !disableSessionTitles,
188 })
189 }
190 text="Enable Session Titles"
191 />
192 <ToggleSwitch
193 isToggled={!displayRawMarkdown}
194 onToggle={() =>
195 handleUpdate({
196 displayRawMarkdown: !displayRawMarkdown,
197 })
198 }
199 text="Format Markdown"
200 />
201
202 <ToggleSwitch
203 isToggled={allowAnonymousTelemetry}
204 onToggle={() =>
205 handleUpdate({
206 allowAnonymousTelemetry: !allowAnonymousTelemetry,
207 })
208 }
209 text="Allow Anonymous Telemetry"
210 />
211
212 <ToggleSwitch
213 isToggled={!disableIndexing}
214 onToggle={() =>
215 handleUpdate({
216 disableIndexing: !disableIndexing,
217 })
218 }
219 text="Enable Indexing"
220 />
221
222 {/* <ToggleSwitch
223 isToggled={useAutocompleteCache}
224 onToggle={() =>
225 handleUpdate({
226 useAutocompleteCache: !useAutocompleteCache,
227 })
228 }
229 text="Use Autocomplete Cache"
230 /> */}
231
232 <label className="flex items-center justify-between gap-3">
233 <span className="text-left">Font Size</span>
234 <NumberInput
235 value={fontSize}
236 onChange={(val) => {
237 setLocalStorage("fontSize", val);
238 handleUpdate({
239 fontSize: val,
240 });
241 }}
242 min={7}
243 max={50}
244 />
245 </label>
246 <label className="flex items-center justify-between gap-3">
247 <span className="lines lines-1 text-left">
248 Multiline Autocompletions
249 </span>
250 <Select
251 value={useAutocompleteMultilineCompletions}
252 onChange={(e) =>
253 handleUpdate({
254 useAutocompleteMultilineCompletions: e.target.value as
255 | "auto"
256 | "always"
257 | "never",
258 })
259 }
260 >
261 <option value="auto">Auto</option>
262 <option value="always">Always</option>
263 <option value="never">Never</option>
264 </Select>
265 </label>
266 <label className="flex items-center justify-between gap-3">
267 <span className="text-left">Autocomplete Timeout (ms)</span>
268 <NumberInput
269 value={modelTimeout}
270 onChange={(val) =>
271 handleUpdate({
272 modelTimeout: val,
273 })
274 }
275 min={100}
276 max={5000}
277 />
278 </label>
279 <label className="flex items-center justify-between gap-3">
280 <span className="text-left">Autocomplete Debounce (ms)</span>
281 <NumberInput
282 value={debounceDelay}
283 onChange={(val) =>
284 handleUpdate({
285 debounceDelay: val,
286 })
287 }
288 min={0}
289 max={2500}
290 />
291 </label>
292 <form
293 className="flex flex-col gap-1"
294 onSubmit={(e) => {
295 e.preventDefault();
296 handleDisableAutocompleteSubmit();
297 }}
298 >
299 <div className="flex items-center justify-between">
300 <span>Disable autocomplete in files</span>
301 <div className="flex items-center gap-2">
302 <Input
303 value={formDisableAutocomplete}
304 className="max-w-[100px]"
305 onChange={(e) => {
306 setFormDisableAutocomplete(e.target.value);
307 }}
308 />
309 <div className="flex h-full flex-col">
310 {formDisableAutocomplete !== disableAutocompleteInFiles ? (
311 <>
312 <div
313 onClick={handleDisableAutocompleteSubmit}
314 className="cursor-pointer"
315 >
316 <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" />
317 </div>
318 <div
319 onClick={cancelChangeDisableAutocomplete}
320 className="cursor-pointer"
321 >
322 <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" />
323 </div>
324 </>
325 ) : (
326 <div>
327 <CheckIcon className="text-vsc-foreground-muted h-4 w-4" />
328 </div>
329 )}
330 </div>
331 </div>
332 </div>
333 <span className="text-vsc-foreground-muted text-lightgray self-end text-xs">
334 Comma-separated list of path matchers
335 </span>
336 </form>
337 </div>
338
339 <div className="flex flex-col gap-2">
340 <div
341 className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold"
342 onClick={() => setShowExperimental(!showExperimental)}
343 >
344 <ChevronRightIcon
345 className={`h-4 w-4 transition-transform ${
346 showExperimental ? "rotate-90" : ""
347 }`}
348 />
349 <span>Experimental Settings</span>
350 </div>
351 <div
352 className={`duration-400 overflow-hidden transition-all ease-in-out ${
353 showExperimental ? "max-h-40" : "max-h-0"
354 }`}
355 >
356 <div className="flex flex-col gap-1 pl-6">
357 <ToggleSwitch
358 isToggled={autoAcceptEditToolDiffs}
359 onToggle={() =>
360 handleUpdate({
361 autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs,
362 })
363 }
364 text="Auto-Accept Agent Edits"
365 showIfToggled={
366 <>
367 <ExclamationTriangleIcon
368 data-tooltip-id={`auto-accept-diffs-warning-tooltip`}
369 className="h-3 w-3 text-yellow-500"
370 />
371 <ToolTip id={`auto-accept-diffs-warning-tooltip`}>
372 {`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`}
373 </ToolTip>
374 </>
375 }
376 />
377 </div>
378 </div>
379 </div>
380 </div>
381 ) : null}
382 </div>
383 );
384}