@@ -10,7 +10,7 @@ import NewWorkspaceModal from "./components/NewWorkspaceModal";
1010import { AIView } from "./components/AIView" ;
1111import { ErrorBoundary } from "./components/ErrorBoundary" ;
1212import { TipsCarousel } from "./components/TipsCarousel" ;
13- import { usePersistedState } from "./hooks/usePersistedState" ;
13+ import { usePersistedState , updatePersistedState } from "./hooks/usePersistedState" ;
1414import { matchesKeybind , KEYBINDS } from "./utils/ui/keybinds" ;
1515import { useProjectManagement } from "./hooks/useProjectManagement" ;
1616import { useWorkspaceManagement } from "./hooks/useWorkspaceManagement" ;
@@ -21,6 +21,12 @@ import { CommandPalette } from "./components/CommandPalette";
2121import { buildCoreSources , type BuildSourcesParams } from "./utils/commands/sources" ;
2222import { useGitStatus } from "./hooks/useGitStatus" ;
2323
24+ import type { ThinkingLevel } from "./types/thinking" ;
25+ import { CUSTOM_EVENTS } from "./constants/events" ;
26+ import { getThinkingLevelKey } from "./constants/storage" ;
27+
28+ const THINKING_LEVELS : ThinkingLevel [ ] = [ "off" , "low" , "medium" , "high" ] ;
29+
2430// Global Styles with nice fonts
2531const globalStyles = css `
2632 * {
@@ -277,6 +283,51 @@ function AppInner() {
277283 close : closeCommandPalette ,
278284 } = useCommandRegistry ( ) ;
279285
286+ const getThinkingLevelForWorkspace = useCallback ( ( workspaceId : string ) : ThinkingLevel => {
287+ if ( ! workspaceId ) {
288+ return "off" ;
289+ }
290+
291+ if ( typeof window === "undefined" || ! window . localStorage ) {
292+ return "off" ;
293+ }
294+
295+ try {
296+ const key = getThinkingLevelKey ( workspaceId ) ;
297+ const stored = window . localStorage . getItem ( key ) ;
298+ if ( ! stored || stored === "undefined" ) {
299+ return "off" ;
300+ }
301+ const parsed = JSON . parse ( stored ) as ThinkingLevel ;
302+ return THINKING_LEVELS . includes ( parsed ) ? parsed : "off" ;
303+ } catch ( error ) {
304+ console . warn ( "Failed to read thinking level" , error ) ;
305+ return "off" ;
306+ }
307+ } , [ ] ) ;
308+
309+ const setThinkingLevelFromPalette = useCallback ( ( workspaceId : string , level : ThinkingLevel ) => {
310+ if ( ! workspaceId ) {
311+ return ;
312+ }
313+
314+ const normalized = THINKING_LEVELS . includes ( level ) ? level : "off" ;
315+ const key = getThinkingLevelKey ( workspaceId ) ;
316+
317+ // Use the utility function which handles localStorage and event dispatch
318+ // ThinkingProvider will pick this up via its listener
319+ updatePersistedState ( key , normalized ) ;
320+
321+ // Dispatch toast notification event for UI feedback
322+ if ( typeof window !== "undefined" ) {
323+ window . dispatchEvent (
324+ new CustomEvent ( CUSTOM_EVENTS . THINKING_LEVEL_TOAST , {
325+ detail : { workspaceId, level : normalized } ,
326+ } )
327+ ) ;
328+ }
329+ } , [ ] ) ;
330+
280331 const registerParamsRef = useRef < BuildSourcesParams | null > ( null ) ;
281332
282333 const openNewWorkspaceFromPalette = useCallback (
@@ -343,6 +394,8 @@ function AppInner() {
343394 workspaceMetadata,
344395 selectedWorkspace,
345396 streamingModels,
397+ getThinkingLevel : getThinkingLevelForWorkspace ,
398+ onSetThinkingLevel : setThinkingLevelFromPalette ,
346399 onOpenNewWorkspaceModal : openNewWorkspaceFromPalette ,
347400 onCreateWorkspace : createWorkspaceFromPalette ,
348401 onSelectWorkspace : selectWorkspaceFromPalette ,
0 commit comments