Elffuss BraidHub

kikocis/continue public

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