Elffuss BraidHub

kikocis/continue public

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