| 1 | import { |
| 2 | SharedConfigSchema, |
| 3 | modifyAnyConfigWithSharedConfig, |
| 4 | } from "core/config/sharedConfig"; |
| 5 | import { HubSessionInfo } from "core/control-plane/AuthTypes"; |
| 6 | import { isContinueTeamMember } from "core/util/isContinueTeamMember"; |
| 7 | import { useContext, useEffect, useState } from "react"; |
| 8 | import { Card, Toggle, useFontSize } from "../../../components/ui"; |
| 9 | import { useAuth } from "../../../context/Auth"; |
| 10 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 11 | import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; |
| 12 | import { updateConfig } from "../../../redux/slices/configSlice"; |
| 13 | import { selectCurrentOrg } from "../../../redux/slices/profilesSlice"; |
| 14 | import { setLocalStorage } from "../../../util/localStorage"; |
| 15 | import { ConfigHeader } from "../components/ConfigHeader"; |
| 16 | import { ContinueFeaturesMenu } from "../components/ContinueFeaturesMenu"; |
| 17 | import { UserSetting } from "../components/UserSetting"; |
| 18 | |
| 19 | export function UserSettingsSection() { |
| 20 | /////// User settings section ////// |
| 21 | const dispatch = useAppDispatch(); |
| 22 | const ideMessenger = useContext(IdeMessengerContext); |
| 23 | const config = useAppSelector((state) => state.config.config); |
| 24 | const currentOrg = useAppSelector(selectCurrentOrg); |
| 25 | |
| 26 | const [showExperimental, setShowExperimental] = useState(false); |
| 27 | const { session } = useAuth(); |
| 28 | |
| 29 | function handleUpdate(sharedConfig: SharedConfigSchema) { |
| 30 | // Optimistic update |
| 31 | const updatedConfig = modifyAnyConfigWithSharedConfig(config, sharedConfig); |
| 32 | dispatch(updateConfig(updatedConfig)); |
| 33 | // IMPORTANT no need for model role updates (separate logic for selected model roles) |
| 34 | // simply because this function won't be used to update model roles |
| 35 | |
| 36 | // Actual update to core which propagates back with config update event |
| 37 | ideMessenger.post("config/updateSharedConfig", sharedConfig); |
| 38 | } |
| 39 | |
| 40 | // Disable autocomplete |
| 41 | const disableAutocompleteInFiles = ( |
| 42 | config.tabAutocompleteOptions?.disableInFiles ?? [] |
| 43 | ).join(", "); |
| 44 | const [formDisableAutocomplete, setFormDisableAutocomplete] = useState( |
| 45 | disableAutocompleteInFiles, |
| 46 | ); |
| 47 | |
| 48 | useEffect(() => { |
| 49 | // Necessary so that reformatted/trimmed values don't cause dirty state |
| 50 | setFormDisableAutocomplete(disableAutocompleteInFiles); |
| 51 | }, [disableAutocompleteInFiles]); |
| 52 | |
| 53 | // Workspace prompts |
| 54 | const promptPath = config.experimental?.promptPath || ""; |
| 55 | |
| 56 | const handleEnableStaticContextualizationToggle = (value: boolean) => { |
| 57 | handleUpdate({ enableStaticContextualization: value }); |
| 58 | }; |
| 59 | |
| 60 | // TODO defaults are in multiple places, should be consolidated and probably not explicit here |
| 61 | const showSessionTabs = config.ui?.showSessionTabs ?? false; |
| 62 | const continueAfterToolRejection = |
| 63 | config.ui?.continueAfterToolRejection ?? false; |
| 64 | const codeWrap = config.ui?.codeWrap ?? false; |
| 65 | const showChatScrollbar = config.ui?.showChatScrollbar ?? false; |
| 66 | const readResponseTTS = config.experimental?.readResponseTTS ?? false; |
| 67 | const autoAcceptEditToolDiffs = config.ui?.autoAcceptEditToolDiffs ?? false; |
| 68 | const displayRawMarkdown = config.ui?.displayRawMarkdown ?? false; |
| 69 | const disableSessionTitles = config.disableSessionTitles ?? false; |
| 70 | const useCurrentFileAsContext = |
| 71 | config.experimental?.useCurrentFileAsContext ?? false; |
| 72 | const enableExperimentalTools = |
| 73 | config.experimental?.enableExperimentalTools ?? false; |
| 74 | const onlyUseSystemMessageTools = |
| 75 | config.experimental?.onlyUseSystemMessageTools ?? false; |
| 76 | const codebaseToolCallingOnly = |
| 77 | config.experimental?.codebaseToolCallingOnly ?? false; |
| 78 | const enableStaticContextualization = |
| 79 | config.experimental?.enableStaticContextualization ?? false; |
| 80 | |
| 81 | const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; |
| 82 | |
| 83 | const useAutocompleteMultilineCompletions = |
| 84 | config.tabAutocompleteOptions?.multilineCompletions ?? "auto"; |
| 85 | const modelTimeout = config.tabAutocompleteOptions?.modelTimeout ?? 150; |
| 86 | const debounceDelay = config.tabAutocompleteOptions?.debounceDelay ?? 250; |
| 87 | const fontSize = useFontSize(); |
| 88 | |
| 89 | const cancelChangeDisableAutocomplete = () => { |
| 90 | setFormDisableAutocomplete(disableAutocompleteInFiles); |
| 91 | }; |
| 92 | const handleDisableAutocompleteSubmit = () => { |
| 93 | handleUpdate({ |
| 94 | disableAutocompleteInFiles: formDisableAutocomplete |
| 95 | .split(",") |
| 96 | .map((val) => val.trim()) |
| 97 | .filter((val) => !!val), |
| 98 | }); |
| 99 | }; |
| 100 | |
| 101 | const hasContinueEmail = isContinueTeamMember( |
| 102 | (session as HubSessionInfo)?.account?.id, |
| 103 | ); |
| 104 | |
| 105 | const disableTelemetryToggle = |
| 106 | currentOrg?.policy?.allowAnonymousTelemetry === false; |
| 107 | |
| 108 | return ( |
| 109 | <div> |
| 110 | <div className="flex flex-col"> |
| 111 | <ConfigHeader title="User Settings" /> |
| 112 | <div className="space-y-6"> |
| 113 | {/* Chat Interface Settings */} |
| 114 | <div> |
| 115 | <ConfigHeader title="Chat" variant="sm" /> |
| 116 | <Card> |
| 117 | <div className="flex flex-col gap-4"> |
| 118 | <UserSetting |
| 119 | type="toggle" |
| 120 | title="Show Session Tabs" |
| 121 | description="Displays tabs above the chat as an alternative way to organize and access your sessions." |
| 122 | value={showSessionTabs} |
| 123 | onChange={(value) => handleUpdate({ showSessionTabs: value })} |
| 124 | /> |
| 125 | <UserSetting |
| 126 | type="toggle" |
| 127 | title="Wrap Codeblocks" |
| 128 | description="Wraps long lines in code blocks instead of showing horizontal scroll." |
| 129 | value={codeWrap} |
| 130 | onChange={(value) => handleUpdate({ codeWrap: value })} |
| 131 | /> |
| 132 | <UserSetting |
| 133 | type="toggle" |
| 134 | title="Show Chat Scrollbar" |
| 135 | description="Enables a scrollbar in the chat window." |
| 136 | value={showChatScrollbar} |
| 137 | onChange={(value) => |
| 138 | handleUpdate({ showChatScrollbar: value }) |
| 139 | } |
| 140 | /> |
| 141 | <UserSetting |
| 142 | type="toggle" |
| 143 | title="Text-to-Speech Output" |
| 144 | description="Reads LLM responses aloud with TTS." |
| 145 | value={readResponseTTS} |
| 146 | onChange={(value) => handleUpdate({ readResponseTTS: value })} |
| 147 | /> |
| 148 | <UserSetting |
| 149 | type="toggle" |
| 150 | title="Enable Session Titles" |
| 151 | description="Generates summary titles for each chat session after the first message, using the current Chat model." |
| 152 | value={!disableSessionTitles} |
| 153 | onChange={(value) => |
| 154 | handleUpdate({ disableSessionTitles: !value }) |
| 155 | } |
| 156 | /> |
| 157 | <UserSetting |
| 158 | type="toggle" |
| 159 | title="Format Markdown" |
| 160 | description="If off, shows responses as raw text." |
| 161 | value={!displayRawMarkdown} |
| 162 | onChange={(value) => |
| 163 | handleUpdate({ displayRawMarkdown: !value }) |
| 164 | } |
| 165 | /> |
| 166 | <UserSetting |
| 167 | type="toggle" |
| 168 | title="Auto-Accept Agent Edits" |
| 169 | description="Diffs generated by the edit tool are automatically accepted and Agent proceeds with the next conversational turn." |
| 170 | value={autoAcceptEditToolDiffs} |
| 171 | onChange={(value) => |
| 172 | handleUpdate({ autoAcceptEditToolDiffs: value }) |
| 173 | } |
| 174 | /> |
| 175 | </div> |
| 176 | </Card> |
| 177 | </div> |
| 178 | |
| 179 | {/* Telemetry Settings */} |
| 180 | <div> |
| 181 | <ConfigHeader title="Telemetry" variant="sm" /> |
| 182 | <Card> |
| 183 | <div className="flex flex-col gap-4"> |
| 184 | <UserSetting |
| 185 | type="toggle" |
| 186 | title="Allow Anonymous Telemetry" |
| 187 | description="Allows Continue to send anonymous telemetry." |
| 188 | value={allowAnonymousTelemetry} |
| 189 | disabled={disableTelemetryToggle} |
| 190 | onChange={(value) => |
| 191 | handleUpdate({ allowAnonymousTelemetry: value }) |
| 192 | } |
| 193 | /> |
| 194 | </div> |
| 195 | </Card> |
| 196 | </div> |
| 197 | |
| 198 | {/* Appearance Settings */} |
| 199 | <div> |
| 200 | <ConfigHeader title="Appearance" variant="sm" /> |
| 201 | <Card> |
| 202 | <div className="flex flex-col gap-4"> |
| 203 | <UserSetting |
| 204 | type="number" |
| 205 | title="Font Size" |
| 206 | description="Specifies base font size for UI elements." |
| 207 | value={fontSize} |
| 208 | onChange={(val) => { |
| 209 | setLocalStorage("fontSize", val); |
| 210 | handleUpdate({ fontSize: val }); |
| 211 | }} |
| 212 | min={7} |
| 213 | max={50} |
| 214 | /> |
| 215 | </div> |
| 216 | </Card> |
| 217 | </div> |
| 218 | |
| 219 | {/* Autocomplete Settings */} |
| 220 | <div> |
| 221 | <ConfigHeader title="Autocomplete" variant="sm" /> |
| 222 | <Card> |
| 223 | <div className="flex flex-col gap-4"> |
| 224 | <UserSetting |
| 225 | type="select" |
| 226 | title="Multiline Autocompletions" |
| 227 | description="Controls multiline completions for autocomplete." |
| 228 | value={useAutocompleteMultilineCompletions} |
| 229 | onChange={(value) => |
| 230 | handleUpdate({ |
| 231 | useAutocompleteMultilineCompletions: value as |
| 232 | | "auto" |
| 233 | | "always" |
| 234 | | "never", |
| 235 | }) |
| 236 | } |
| 237 | options={[ |
| 238 | { label: "Auto", value: "auto" }, |
| 239 | { label: "Always", value: "always" }, |
| 240 | { label: "Never", value: "never" }, |
| 241 | ]} |
| 242 | /> |
| 243 | <UserSetting |
| 244 | type="number" |
| 245 | title="Autocomplete Timeout (ms)" |
| 246 | description="Maximum time in milliseconds for autocomplete request/retrieval." |
| 247 | value={modelTimeout} |
| 248 | onChange={(val) => handleUpdate({ modelTimeout: val })} |
| 249 | min={100} |
| 250 | max={5000} |
| 251 | /> |
| 252 | <UserSetting |
| 253 | type="number" |
| 254 | title="Autocomplete Debounce (ms)" |
| 255 | description="Minimum time in milliseconds to trigger an autocomplete request after a change." |
| 256 | value={debounceDelay} |
| 257 | onChange={(val) => handleUpdate({ debounceDelay: val })} |
| 258 | min={0} |
| 259 | max={2500} |
| 260 | /> |
| 261 | <UserSetting |
| 262 | type="input" |
| 263 | title="Disable autocomplete in files" |
| 264 | description="List of comma-separated glob pattern to disable autocomplete in matching files." |
| 265 | placeholder="**/*.(txt,md)" |
| 266 | value={formDisableAutocomplete} |
| 267 | onChange={setFormDisableAutocomplete} |
| 268 | onSubmit={handleDisableAutocompleteSubmit} |
| 269 | onCancel={cancelChangeDisableAutocomplete} |
| 270 | isDirty={ |
| 271 | formDisableAutocomplete !== disableAutocompleteInFiles |
| 272 | } |
| 273 | isValid={formDisableAutocomplete.trim() !== ""} |
| 274 | /> |
| 275 | </div> |
| 276 | </Card> |
| 277 | </div> |
| 278 | |
| 279 | {/* Experimental Settings */} |
| 280 | <div> |
| 281 | <ConfigHeader title="Experimental" variant="sm" /> |
| 282 | <Card> |
| 283 | <Toggle |
| 284 | isOpen={showExperimental} |
| 285 | onToggle={() => setShowExperimental(!showExperimental)} |
| 286 | title="Show Experimental Settings" |
| 287 | > |
| 288 | <div className="flex flex-col gap-x-1 gap-y-4"> |
| 289 | <UserSetting |
| 290 | type="toggle" |
| 291 | title="Add Current File by Default" |
| 292 | description=" the currently open file is added as context in every new conversation." |
| 293 | value={useCurrentFileAsContext} |
| 294 | onChange={(value) => |
| 295 | handleUpdate({ useCurrentFileAsContext: value }) |
| 296 | } |
| 297 | /> |
| 298 | <UserSetting |
| 299 | type="toggle" |
| 300 | title="Enable experimental tools" |
| 301 | description=" enables access to experimental tools that are still in development." |
| 302 | value={enableExperimentalTools} |
| 303 | onChange={(value) => |
| 304 | handleUpdate({ enableExperimentalTools: value }) |
| 305 | } |
| 306 | /> |
| 307 | <UserSetting |
| 308 | type="toggle" |
| 309 | title="Only use system message tools" |
| 310 | description=" Continue will not attempt to use native tool calling and will only use system message tools." |
| 311 | value={onlyUseSystemMessageTools} |
| 312 | onChange={(value) => |
| 313 | handleUpdate({ onlyUseSystemMessageTools: value }) |
| 314 | } |
| 315 | /> |
| 316 | <UserSetting |
| 317 | type="toggle" |
| 318 | title="@Codebase: use tool calling only" |
| 319 | description=" @codebase context provider will only use tool calling for code retrieval." |
| 320 | value={codebaseToolCallingOnly} |
| 321 | onChange={(value) => |
| 322 | handleUpdate({ codebaseToolCallingOnly: value }) |
| 323 | } |
| 324 | /> |
| 325 | <UserSetting |
| 326 | type="toggle" |
| 327 | title="Stream after tool rejection" |
| 328 | description=" streaming will continue after the tool call is rejected." |
| 329 | value={continueAfterToolRejection} |
| 330 | onChange={(value) => |
| 331 | handleUpdate({ continueAfterToolRejection: value }) |
| 332 | } |
| 333 | /> |
| 334 | |
| 335 | {hasContinueEmail && ( |
| 336 | <ContinueFeaturesMenu |
| 337 | enableStaticContextualization={ |
| 338 | enableStaticContextualization |
| 339 | } |
| 340 | handleEnableStaticContextualizationToggle={ |
| 341 | handleEnableStaticContextualizationToggle |
| 342 | } |
| 343 | /> |
| 344 | )} |
| 345 | </div> |
| 346 | </Toggle> |
| 347 | </Card> |
| 348 | </div> |
| 349 | </div> |
| 350 | </div> |
| 351 | </div> |
| 352 | ); |
| 353 | } |