@@ -18,8 +18,10 @@ import {
1818 bootstrapDirectory ,
1919 bootstrapGlobal ,
2020 clearProviderRev ,
21+ loadAgentsQuery ,
2122 loadGlobalConfigQuery ,
2223 loadPathQuery ,
24+ loadProjectsQuery ,
2325 loadProvidersQuery ,
2426} from "./global-sync/bootstrap"
2527import { createChildStoreManager } from "./global-sync/child-store"
@@ -77,12 +79,37 @@ function createGlobalSync() {
7779 const sessionLoads = new Map < string , Promise < void > > ( )
7880 const sessionMeta = new Map < string , { limit : number } > ( )
7981
82+ const sdkFor = ( directory : string ) => {
83+ const key = directoryKey ( directory )
84+ const cached = sdkCache . get ( key )
85+ if ( cached ) return cached
86+ const sdk = globalSDK . createClient ( {
87+ directory,
88+ throwOnError : true ,
89+ } )
90+ sdkCache . set ( key , sdk )
91+ return sdk
92+ }
93+
94+ const queryOptionsApi = {
95+ globalConfig : ( ) => loadGlobalConfigQuery ( globalSDK . client ) ,
96+ projects : ( ) => loadProjectsQuery ( globalSDK . client ) ,
97+ providers : ( directory : string | null ) =>
98+ loadProvidersQuery ( directory , directory === null ? globalSDK . client : sdkFor ( directory ) ) ,
99+ path : ( directory : string | null ) =>
100+ loadPathQuery ( directory , directory === null ? globalSDK . client : sdkFor ( directory ) ) ,
101+ agents : ( directory : string ) => loadAgentsQuery ( directory , sdkFor ( directory ) ) ,
102+ mcp : ( directory : string ) => loadMcpQuery ( directory , sdkFor ( directory ) ) ,
103+ lsp : ( directory : string ) => loadLspQuery ( directory , sdkFor ( directory ) ) ,
104+ keys : {
105+ lsp : lspQueryKey ,
106+ mcp : mcpQueryKey ,
107+ sessions : loadSessionsQueryKey ,
108+ } ,
109+ }
110+
80111 const [ configQuery , providerQuery , pathQuery ] = useQueries ( ( ) => ( {
81- queries : [
82- loadGlobalConfigQuery ( globalSDK . client ) ,
83- loadProvidersQuery ( null , globalSDK . client ) ,
84- loadPathQuery ( null , globalSDK . client ) ,
85- ] ,
112+ queries : [ queryOptionsApi . globalConfig ( ) , queryOptionsApi . providers ( null ) , queryOptionsApi . path ( null ) ] ,
86113 } ) )
87114
88115 const [ globalStore , setGlobalStore ] = createStore < GlobalStore > ( {
@@ -181,18 +208,6 @@ function createGlobalSync() {
181208 bootstrapInstance,
182209 } )
183210
184- const sdkFor = ( directory : string ) => {
185- const key = directoryKey ( directory )
186- const cached = sdkCache . get ( key )
187- if ( cached ) return cached
188- const sdk = globalSDK . createClient ( {
189- directory,
190- throwOnError : true ,
191- } )
192- sdkCache . set ( key , sdk )
193- return sdk
194- }
195-
196211 const children = createChildStoreManager ( {
197212 owner,
198213 isBooting : ( directory ) => booting . has ( directory ) ,
@@ -209,7 +224,7 @@ function createGlobalSync() {
209224 clearSessionPrefetchDirectory ( key )
210225 } ,
211226 translate : language . t ,
212- getSdk : sdkFor ,
227+ queryOptions : queryOptionsApi ,
213228 global : {
214229 provider : globalStore . provider ,
215230 } ,
@@ -368,7 +383,7 @@ function createGlobalSync() {
368383 setSessionTodo,
369384 vcsCache : children . vcsCache . get ( key ) ,
370385 loadLsp : ( ) => {
371- void queryClient . fetchQuery ( loadLspQuery ( key , sdkFor ( directory ) ) )
386+ void queryClient . fetchQuery ( queryOptionsApi . lsp ( key ) )
372387 } ,
373388 } )
374389 } )
@@ -426,6 +441,7 @@ function createGlobalSync() {
426441 } ,
427442 child : children . child ,
428443 peek : children . peek ,
444+ queryOptions : queryOptionsApi ,
429445 // bootstrap,
430446 updateConfig : updateConfigMutation . mutateAsync ,
431447 project : projectApi ,
@@ -447,3 +463,7 @@ export function useGlobalSync() {
447463 if ( ! context ) throw new Error ( "useGlobalSync must be used within GlobalSyncProvider" )
448464 return context
449465}
466+
467+ export function useQueryOptions ( ) {
468+ return useGlobalSync ( ) . queryOptions
469+ }
0 commit comments