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