| 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 | const disableIndexingToggle = |
| 145 | currentOrg?.policy?.allowCodebaseIndexing === false; |
| 146 | |
| 147 | return ( |
| 148 | <div className="flex flex-col"> |
| 149 | {/* {selectedProfile && isLocalProfile(selectedProfile) ? ( |
| 150 | <div className="flex items-center justify-center"> |
| 151 | <SecondaryButton |
| 152 | className="flex flex-row items-center gap-1" |
| 153 | onClick={() => { |
| 154 | ideMessenger.post("config/openProfile", { |
| 155 | profileId: selectedProfile.id, |
| 156 | }); |
| 157 | }} |
| 158 | > |
| 159 | <span>Open</span> |
| 160 | <span>Config</span> |
| 161 | <span className="xs:flex hidden">File</span> |
| 162 | </SecondaryButton> |
| 163 | </div> |
| 164 | ) : null} */} |
| 165 | {hubEnabled ? ( |
| 166 | <div className="flex flex-col gap-4 py-4"> |
| 167 | <div> |
| 168 | <h2 className="mb-2 mt-0 p-0">User settings</h2> |
| 169 | </div> |
| 170 | |
| 171 | <div className="flex flex-col gap-4"> |
| 172 | <ToggleSwitch |
| 173 | isToggled={showSessionTabs} |
| 174 | onToggle={() => |
| 175 | handleUpdate({ |
| 176 | showSessionTabs: !showSessionTabs, |
| 177 | }) |
| 178 | } |
| 179 | text="Show Session Tabs" |
| 180 | /> |
| 181 | <ToggleSwitch |
| 182 | isToggled={codeWrap} |
| 183 | onToggle={() => |
| 184 | handleUpdate({ |
| 185 | codeWrap: !codeWrap, |
| 186 | }) |
| 187 | } |
| 188 | text="Wrap Codeblocks" |
| 189 | /> |
| 190 | |
| 191 | <ToggleSwitch |
| 192 | isToggled={showChatScrollbar} |
| 193 | onToggle={() => |
| 194 | handleUpdate({ |
| 195 | showChatScrollbar: !showChatScrollbar, |
| 196 | }) |
| 197 | } |
| 198 | text="Show Chat Scrollbar" |
| 199 | /> |
| 200 | <ToggleSwitch |
| 201 | isToggled={readResponseTTS} |
| 202 | onToggle={() => |
| 203 | handleUpdate({ |
| 204 | readResponseTTS: !readResponseTTS, |
| 205 | }) |
| 206 | } |
| 207 | text="Text-to-Speech Output" |
| 208 | /> |
| 209 | {/* <ToggleSwitch |
| 210 | isToggled={useChromiumForDocsCrawling} |
| 211 | onToggle={() => |
| 212 | handleUpdate({ |
| 213 | useChromiumForDocsCrawling: !useChromiumForDocsCrawling, |
| 214 | }) |
| 215 | } |
| 216 | text="Use Chromium for Docs Crawling" |
| 217 | /> */} |
| 218 | <ToggleSwitch |
| 219 | isToggled={!disableSessionTitles} |
| 220 | onToggle={() => |
| 221 | handleUpdate({ |
| 222 | disableSessionTitles: !disableSessionTitles, |
| 223 | }) |
| 224 | } |
| 225 | text="Enable Session Titles" |
| 226 | /> |
| 227 | <ToggleSwitch |
| 228 | isToggled={!displayRawMarkdown} |
| 229 | onToggle={() => |
| 230 | handleUpdate({ |
| 231 | displayRawMarkdown: !displayRawMarkdown, |
| 232 | }) |
| 233 | } |
| 234 | text="Format Markdown" |
| 235 | /> |
| 236 | |
| 237 | <ToggleSwitch |
| 238 | isToggled={allowAnonymousTelemetry} |
| 239 | disabled={disableTelemetryToggle} |
| 240 | onToggle={() => |
| 241 | handleUpdate({ |
| 242 | allowAnonymousTelemetry: !allowAnonymousTelemetry, |
| 243 | }) |
| 244 | } |
| 245 | text="Allow Anonymous Telemetry" |
| 246 | /> |
| 247 | |
| 248 | <ToggleSwitch |
| 249 | isToggled={!disableIndexing} |
| 250 | disabled={disableIndexingToggle} |
| 251 | onToggle={() => |
| 252 | handleUpdate({ |
| 253 | disableIndexing: !disableIndexing, |
| 254 | }) |
| 255 | } |
| 256 | text="Enable Indexing" |
| 257 | /> |
| 258 | |
| 259 | {/* <ToggleSwitch |
| 260 | isToggled={useAutocompleteCache} |
| 261 | onToggle={() => |
| 262 | handleUpdate({ |
| 263 | useAutocompleteCache: !useAutocompleteCache, |
| 264 | }) |
| 265 | } |
| 266 | text="Use Autocomplete Cache" |
| 267 | /> */} |
| 268 | |
| 269 | <label className="flex items-center justify-between gap-3"> |
| 270 | <span className="text-left">Font Size</span> |
| 271 | <NumberInput |
| 272 | value={fontSize} |
| 273 | onChange={(val) => { |
| 274 | setLocalStorage("fontSize", val); |
| 275 | handleUpdate({ |
| 276 | fontSize: val, |
| 277 | }); |
| 278 | }} |
| 279 | min={7} |
| 280 | max={50} |
| 281 | /> |
| 282 | </label> |
| 283 | <label className="flex items-center justify-between gap-3"> |
| 284 | <span className="lines lines-1 text-left"> |
| 285 | Multiline Autocompletions |
| 286 | </span> |
| 287 | <Select |
| 288 | value={useAutocompleteMultilineCompletions} |
| 289 | onChange={(e) => |
| 290 | handleUpdate({ |
| 291 | useAutocompleteMultilineCompletions: e.target.value as |
| 292 | | "auto" |
| 293 | | "always" |
| 294 | | "never", |
| 295 | }) |
| 296 | } |
| 297 | > |
| 298 | <option value="auto">Auto</option> |
| 299 | <option value="always">Always</option> |
| 300 | <option value="never">Never</option> |
| 301 | </Select> |
| 302 | </label> |
| 303 | <label className="flex items-center justify-between gap-3"> |
| 304 | <span className="text-left">Autocomplete Timeout (ms)</span> |
| 305 | <NumberInput |
| 306 | value={modelTimeout} |
| 307 | onChange={(val) => |
| 308 | handleUpdate({ |
| 309 | modelTimeout: val, |
| 310 | }) |
| 311 | } |
| 312 | min={100} |
| 313 | max={5000} |
| 314 | /> |
| 315 | </label> |
| 316 | <label className="flex items-center justify-between gap-3"> |
| 317 | <span className="text-left">Autocomplete Debounce (ms)</span> |
| 318 | <NumberInput |
| 319 | value={debounceDelay} |
| 320 | onChange={(val) => |
| 321 | handleUpdate({ |
| 322 | debounceDelay: val, |
| 323 | }) |
| 324 | } |
| 325 | min={0} |
| 326 | max={2500} |
| 327 | /> |
| 328 | </label> |
| 329 | <form |
| 330 | className="flex flex-col gap-1" |
| 331 | onSubmit={(e) => { |
| 332 | e.preventDefault(); |
| 333 | handleDisableAutocompleteSubmit(); |
| 334 | }} |
| 335 | > |
| 336 | <div className="flex items-center justify-between"> |
| 337 | <span>Disable autocomplete in files</span> |
| 338 | <div className="flex items-center gap-2"> |
| 339 | <Input |
| 340 | value={formDisableAutocomplete} |
| 341 | className="max-w-[100px]" |
| 342 | onChange={(e) => { |
| 343 | setFormDisableAutocomplete(e.target.value); |
| 344 | }} |
| 345 | /> |
| 346 | <div className="flex h-full flex-col"> |
| 347 | {formDisableAutocomplete !== disableAutocompleteInFiles ? ( |
| 348 | <> |
| 349 | <div |
| 350 | onClick={handleDisableAutocompleteSubmit} |
| 351 | className="cursor-pointer" |
| 352 | > |
| 353 | <CheckIcon className="h-4 w-4 text-green-500 hover:opacity-80" /> |
| 354 | </div> |
| 355 | <div |
| 356 | onClick={cancelChangeDisableAutocomplete} |
| 357 | className="cursor-pointer" |
| 358 | > |
| 359 | <XMarkIcon className="h-4 w-4 text-red-500 hover:opacity-80" /> |
| 360 | </div> |
| 361 | </> |
| 362 | ) : ( |
| 363 | <div> |
| 364 | <CheckIcon className="text-vsc-foreground-muted h-4 w-4" /> |
| 365 | </div> |
| 366 | )} |
| 367 | </div> |
| 368 | </div> |
| 369 | </div> |
| 370 | <span className="text-vsc-foreground-muted text-lightgray self-end text-xs"> |
| 371 | Comma-separated list of path matchers |
| 372 | </span> |
| 373 | </form> |
| 374 | </div> |
| 375 | |
| 376 | <div className="flex flex-col gap-x-2 gap-y-4"> |
| 377 | <div |
| 378 | className="flex cursor-pointer items-center gap-2 text-left text-sm font-semibold" |
| 379 | onClick={() => setShowExperimental(!showExperimental)} |
| 380 | > |
| 381 | <ChevronRightIcon |
| 382 | className={`h-4 w-4 transition-transform ${ |
| 383 | showExperimental ? "rotate-90" : "" |
| 384 | }`} |
| 385 | /> |
| 386 | <span>Experimental Settings</span> |
| 387 | </div> |
| 388 | <div |
| 389 | className={`duration-400 overflow-hidden transition-all ease-in-out ${ |
| 390 | showExperimental |
| 391 | ? "max-h-96" /* Increased from max-h-40 to max-h-96 to accommodate ContinueFeaturesMenu */ |
| 392 | : "max-h-0" |
| 393 | }`} |
| 394 | > |
| 395 | <div className="flex flex-col gap-x-1 gap-y-4 pl-6"> |
| 396 | <ToggleSwitch |
| 397 | isToggled={autoAcceptEditToolDiffs} |
| 398 | onToggle={() => |
| 399 | handleUpdate({ |
| 400 | autoAcceptEditToolDiffs: !autoAcceptEditToolDiffs, |
| 401 | }) |
| 402 | } |
| 403 | text="Auto-Accept Agent Edits" |
| 404 | showIfToggled={ |
| 405 | <> |
| 406 | <ToolTip |
| 407 | content={`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`} |
| 408 | > |
| 409 | <ExclamationTriangleIcon className="h-3 w-3 text-yellow-500" /> |
| 410 | </ToolTip> |
| 411 | </> |
| 412 | } |
| 413 | /> |
| 414 | |
| 415 | <ToggleSwitch |
| 416 | isToggled={useCurrentFileAsContext} |
| 417 | onToggle={() => |
| 418 | handleUpdate({ |
| 419 | useCurrentFileAsContext: !useCurrentFileAsContext, |
| 420 | }) |
| 421 | } |
| 422 | text="Add Current File by Default" |
| 423 | /> |
| 424 | |
| 425 | <ToggleSwitch |
| 426 | isToggled={enableExperimentalTools} |
| 427 | onToggle={() => |
| 428 | handleUpdate({ |
| 429 | enableExperimentalTools: !enableExperimentalTools, |
| 430 | }) |
| 431 | } |
| 432 | text="Enable experimental tools" |
| 433 | /> |
| 434 | |
| 435 | <ToggleSwitch |
| 436 | isToggled={onlyUseSystemMessageTools} |
| 437 | onToggle={() => |
| 438 | handleUpdate({ |
| 439 | onlyUseSystemMessageTools: !onlyUseSystemMessageTools, |
| 440 | }) |
| 441 | } |
| 442 | text="Only use system message tools" |
| 443 | /> |
| 444 | |
| 445 | <ToggleSwitch |
| 446 | isToggled={codebaseToolCallingOnly} |
| 447 | onToggle={() => |
| 448 | handleUpdate({ |
| 449 | codebaseToolCallingOnly: !codebaseToolCallingOnly, |
| 450 | }) |
| 451 | } |
| 452 | text="@Codebase: use tool calling only" |
| 453 | /> |
| 454 | |
| 455 | <ToggleSwitch |
| 456 | isToggled={continueAfterToolRejection} |
| 457 | onToggle={() => |
| 458 | handleUpdate({ |
| 459 | continueAfterToolRejection: !continueAfterToolRejection, |
| 460 | }) |
| 461 | } |
| 462 | text="Stream after tool rejection" |
| 463 | /> |
| 464 | |
| 465 | {hasContinueEmail && ( |
| 466 | <ContinueFeaturesMenu |
| 467 | enableStaticContextualization={ |
| 468 | enableStaticContextualization |
| 469 | } |
| 470 | handleEnableStaticContextualizationToggle={ |
| 471 | handleEnableStaticContextualizationToggle |
| 472 | } |
| 473 | /> |
| 474 | )} |
| 475 | </div> |
| 476 | </div> |
| 477 | </div> |
| 478 | </div> |
| 479 | ) : null} |
| 480 | </div> |
| 481 | ); |
| 482 | } |