@@ -20,6 +20,7 @@ import type { z } from 'zod';
2020
2121export  interface  AIAnalystState  { 
2222  showAIAnalyst : boolean ; 
23+   activeSchemaConnectionUuid : string  |  undefined ; 
2324  showChatHistory : boolean ; 
2425  abortController ?: AbortController ; 
2526  loading : boolean ; 
@@ -46,6 +47,7 @@ export interface AIAnalystState {
4647
4748export  const  defaultAIAnalystState : AIAnalystState  =  { 
4849  showAIAnalyst : false , 
50+   activeSchemaConnectionUuid : undefined , 
4951  showChatHistory : false , 
5052  abortController : undefined , 
5153  loading : false , 
@@ -150,9 +152,26 @@ const createSelector = <T extends keyof AIAnalystState>(key: T) =>
150152      } ) ) ; 
151153    } , 
152154  } ) ; 
153- export  const  showAIAnalystAtom  =  createSelector ( 'showAIAnalyst' ) ; 
154155export  const  aiAnalystShowChatHistoryAtom  =  createSelector ( 'showChatHistory' ) ; 
155156export  const  aiAnalystAbortControllerAtom  =  createSelector ( 'abortController' ) ; 
157+ export  const  aiAnalystActiveSchemaConnectionUuidAtom  =  createSelector ( 'activeSchemaConnectionUuid' ) ; 
158+ 
159+ export  const  showAIAnalystAtom  =  selector < boolean > ( { 
160+   key : 'showAIAnalystAtom' , 
161+   get : ( {  get } )  =>  get ( aiAnalystAtom ) . showAIAnalyst , 
162+   set : ( {  set,  get } ,  newValue )  =>  { 
163+     const  currentState  =  get ( aiAnalystAtom ) ; 
164+     const  isShowing  =  currentState . showAIAnalyst ; 
165+     const  willShow  =  newValue  instanceof  DefaultValue  ? currentState . showAIAnalyst  : newValue ; 
166+ 
167+     set ( aiAnalystAtom ,  ( prev )  =>  ( { 
168+       ...prev , 
169+       showAIAnalyst : newValue  instanceof  DefaultValue  ? prev . showAIAnalyst  : newValue , 
170+       // Reset when hiding the AI Analyst 
171+       activeSchemaConnectionUuid : isShowing  &&  ! willShow  ? undefined  : prev . activeSchemaConnectionUuid , 
172+     } ) ) ; 
173+   } , 
174+ } ) ; 
156175
157176export  const  aiAnalystLoadingAtom  =  selector < boolean > ( { 
158177  key : 'aiAnalystLoadingAtom' , 
0 commit comments