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