@@ -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" ;
@@ -263,60 +267,63 @@ function AppInner() {
263267 close : closeCommandPalette ,
264268 } = useCommandRegistry ( ) ;
265269
266- const getThinkingLevelForWorkspace = useCallback ( ( workspaceId : string ) : ThinkingLevel => {
267- if ( ! workspaceId ) {
268- return "off" ;
269- }
270-
271- if ( typeof window === "undefined" || ! window . localStorage ) {
272- return "off" ;
273- }
274-
275- try {
276- // First get the model for this workspace, then get thinking level for that model
277- const modelKey = getModelKey ( workspaceId ) ;
278- const modelStored = window . localStorage . getItem ( modelKey ) ;
279- const model = modelStored ? ( JSON . parse ( modelStored ) as string ) : getDefaultModel ( ) ;
270+ const getCurrentModelForWorkspace = useCallback (
271+ ( workspaceId : string ) : string => {
272+ if ( ! workspaceId ) return getDefaultModel ( ) ;
273+ // Prefer live workspace state; fall back to persisted preference
274+ const modelFromStore = workspaceStore . getWorkspaceState ( workspaceId ) ?. currentModel ;
275+ return (
276+ modelFromStore ??
277+ readPersistedState < string | null > ( getModelKey ( workspaceId ) , null ) ??
278+ getDefaultModel ( )
279+ ) ;
280+ } ,
281+ [ workspaceStore ]
282+ ) ;
280283
281- const key = getThinkingLevelKey ( model ) ;
282- const stored = window . localStorage . getItem ( key ) ;
283- if ( ! stored || stored === "undefined" ) {
284+ const getThinkingLevelForWorkspace = useCallback (
285+ ( workspaceId : string ) : ThinkingLevel => {
286+ if ( ! workspaceId ) {
284287 return "off" ;
285288 }
286- const parsed = JSON . parse ( stored ) as ThinkingLevel ;
287- return THINKING_LEVELS . includes ( parsed ) ? parsed : "off" ;
288- } catch ( error ) {
289- console . warn ( "Failed to read thinking level" , error ) ;
290- return "off" ;
291- }
292- } , [ ] ) ;
293289
294- const setThinkingLevelFromPalette = useCallback ( ( workspaceId : string , level : ThinkingLevel ) => {
295- if ( ! workspaceId ) {
296- return ;
297- }
290+ try {
291+ const model = getCurrentModelForWorkspace ( workspaceId ) ;
292+ const storedLevel = readPersistedState < ThinkingLevel > ( getThinkingLevelKey ( model ) , "off" ) ;
293+ return THINKING_LEVELS . includes ( storedLevel ) ? storedLevel : "off" ;
294+ } catch ( error ) {
295+ console . warn ( "Failed to read thinking level" , error ) ;
296+ return "off" ;
297+ }
298+ } ,
299+ [ getCurrentModelForWorkspace ]
300+ ) ;
298301
299- // Get the model for this workspace to set thinking level for it
300- const modelKey = getModelKey ( workspaceId ) ;
301- const modelStored = window . localStorage ?. getItem ( modelKey ) ;
302- const model = modelStored ? ( JSON . parse ( modelStored ) as string ) : getDefaultModel ( ) ;
302+ const setThinkingLevelFromPalette = useCallback (
303+ ( workspaceId : string , level : ThinkingLevel ) => {
304+ if ( ! workspaceId ) {
305+ return ;
306+ }
303307
304- const normalized = THINKING_LEVELS . includes ( level ) ? level : "off" ;
305- const key = getThinkingLevelKey ( model ) ;
308+ const model = getCurrentModelForWorkspace ( workspaceId ) ;
309+ const normalized = THINKING_LEVELS . includes ( level ) ? level : "off" ;
310+ const key = getThinkingLevelKey ( model ) ;
306311
307- // Use the utility function which handles localStorage and event dispatch
308- // ThinkingProvider will pick this up via its listener
309- updatePersistedState ( key , normalized ) ;
312+ // Use the utility function which handles localStorage and event dispatch
313+ // ThinkingProvider will pick this up via its listener
314+ updatePersistedState ( key , normalized ) ;
310315
311- // Dispatch toast notification event for UI feedback
312- if ( typeof window !== "undefined" ) {
313- window . dispatchEvent (
314- new CustomEvent ( CUSTOM_EVENTS . THINKING_LEVEL_TOAST , {
315- detail : { workspaceId, level : normalized } ,
316- } )
317- ) ;
318- }
319- } , [ ] ) ;
316+ // Dispatch toast notification event for UI feedback
317+ if ( typeof window !== "undefined" ) {
318+ window . dispatchEvent (
319+ new CustomEvent ( CUSTOM_EVENTS . THINKING_LEVEL_TOAST , {
320+ detail : { workspaceId, level : normalized } ,
321+ } )
322+ ) ;
323+ }
324+ } ,
325+ [ getCurrentModelForWorkspace ]
326+ ) ;
320327
321328 const registerParamsRef = useRef < BuildSourcesParams | null > ( null ) ;
322329
0 commit comments