@@ -7,7 +7,11 @@ import { LeftSidebar } from "./components/LeftSidebar";
77import { ProjectCreateModal } from "./components/ProjectCreateModal" ;
88import { AIView } from "./components/AIView" ;
99import { ErrorBoundary } from "./components/ErrorBoundary" ;
10- import { usePersistedState , updatePersistedState } from "./hooks/usePersistedState" ;
10+ import {
11+ usePersistedState ,
12+ updatePersistedState ,
13+ readPersistedState ,
14+ } from "./hooks/usePersistedState" ;
1115import { matchesKeybind , KEYBINDS } from "./utils/ui/keybinds" ;
1216import { buildSortedWorkspacesByProject } from "./utils/ui/workspaceFiltering" ;
1317import { useResumeManager } from "./hooks/useResumeManager" ;
@@ -271,60 +275,63 @@ function AppInner() {
271275 close : closeCommandPalette ,
272276 } = useCommandRegistry ( ) ;
273277
274- const getThinkingLevelForWorkspace = useCallback ( ( workspaceId : string ) : ThinkingLevel => {
275- if ( ! workspaceId ) {
276- return "off" ;
277- }
278-
279- if ( typeof window === "undefined" || ! window . localStorage ) {
280- return "off" ;
281- }
282-
283- try {
284- // First get the model for this workspace, then get thinking level for that model
285- const modelKey = getModelKey ( workspaceId ) ;
286- const modelStored = window . localStorage . getItem ( modelKey ) ;
287- const model = modelStored ? ( JSON . parse ( modelStored ) as string ) : getDefaultModel ( ) ;
278+ const getCurrentModelForWorkspace = useCallback (
279+ ( workspaceId : string ) : string => {
280+ if ( ! workspaceId ) return getDefaultModel ( ) ;
281+ // Prefer live workspace state; fall back to persisted preference
282+ const modelFromStore = workspaceStore . getWorkspaceState ( workspaceId ) ?. currentModel ;
283+ return (
284+ modelFromStore ??
285+ readPersistedState < string | null > ( getModelKey ( workspaceId ) , null ) ??
286+ getDefaultModel ( )
287+ ) ;
288+ } ,
289+ [ workspaceStore ]
290+ ) ;
288291
289- const key = getThinkingLevelKey ( model ) ;
290- const stored = window . localStorage . getItem ( key ) ;
291- if ( ! stored || stored === "undefined" ) {
292+ const getThinkingLevelForWorkspace = useCallback (
293+ ( workspaceId : string ) : ThinkingLevel => {
294+ if ( ! workspaceId ) {
292295 return "off" ;
293296 }
294- const parsed = JSON . parse ( stored ) as ThinkingLevel ;
295- return THINKING_LEVELS . includes ( parsed ) ? parsed : "off" ;
296- } catch ( error ) {
297- console . warn ( "Failed to read thinking level" , error ) ;
298- return "off" ;
299- }
300- } , [ ] ) ;
301297
302- const setThinkingLevelFromPalette = useCallback ( ( workspaceId : string , level : ThinkingLevel ) => {
303- if ( ! workspaceId ) {
304- return ;
305- }
298+ try {
299+ const model = getCurrentModelForWorkspace ( workspaceId ) ;
300+ const storedLevel = readPersistedState < ThinkingLevel > ( getThinkingLevelKey ( model ) , "off" ) ;
301+ return THINKING_LEVELS . includes ( storedLevel ) ? storedLevel : "off" ;
302+ } catch ( error ) {
303+ console . warn ( "Failed to read thinking level" , error ) ;
304+ return "off" ;
305+ }
306+ } ,
307+ [ getCurrentModelForWorkspace ]
308+ ) ;
306309
307- // Get the model for this workspace to set thinking level for it
308- const modelKey = getModelKey ( workspaceId ) ;
309- const modelStored = window . localStorage ?. getItem ( modelKey ) ;
310- const model = modelStored ? ( JSON . parse ( modelStored ) as string ) : getDefaultModel ( ) ;
310+ const setThinkingLevelFromPalette = useCallback (
311+ ( workspaceId : string , level : ThinkingLevel ) => {
312+ if ( ! workspaceId ) {
313+ return ;
314+ }
311315
312- const normalized = THINKING_LEVELS . includes ( level ) ? level : "off" ;
313- const key = getThinkingLevelKey ( model ) ;
316+ const model = getCurrentModelForWorkspace ( workspaceId ) ;
317+ const normalized = THINKING_LEVELS . includes ( level ) ? level : "off" ;
318+ const key = getThinkingLevelKey ( model ) ;
314319
315- // Use the utility function which handles localStorage and event dispatch
316- // ThinkingProvider will pick this up via its listener
317- updatePersistedState ( key , normalized ) ;
320+ // Use the utility function which handles localStorage and event dispatch
321+ // ThinkingProvider will pick this up via its listener
322+ updatePersistedState ( key , normalized ) ;
318323
319- // Dispatch toast notification event for UI feedback
320- if ( typeof window !== "undefined" ) {
321- window . dispatchEvent (
322- new CustomEvent ( CUSTOM_EVENTS . THINKING_LEVEL_TOAST , {
323- detail : { workspaceId, level : normalized } ,
324- } )
325- ) ;
326- }
327- } , [ ] ) ;
324+ // Dispatch toast notification event for UI feedback
325+ if ( typeof window !== "undefined" ) {
326+ window . dispatchEvent (
327+ new CustomEvent ( CUSTOM_EVENTS . THINKING_LEVEL_TOAST , {
328+ detail : { workspaceId, level : normalized } ,
329+ } )
330+ ) ;
331+ }
332+ } ,
333+ [ getCurrentModelForWorkspace ]
334+ ) ;
328335
329336 const registerParamsRef = useRef < BuildSourcesParams | null > ( null ) ;
330337
0 commit comments