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