@@ -333,32 +333,57 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
333333 const start = Date . now ( ) - 30 * 24 * 60 * 60 * 1000
334334 const sessionListPromise = sdk . client . session
335335 . list ( { start : start } )
336- . then ( ( x ) => setStore ( "session" , reconcile ( ( x . data ?? [ ] ) . toSorted ( ( a , b ) => a . id . localeCompare ( b . id ) ) ) ) )
336+ . then ( ( x ) => ( x . data ?? [ ] ) . toSorted ( ( a , b ) => a . id . localeCompare ( b . id ) ) )
337337
338338 // blocking - include session.list when continuing a session
339+ const providersPromise = sdk . client . config . providers ( { } , { throwOnError : true } )
340+ const providerListPromise = sdk . client . provider . list ( { } , { throwOnError : true } )
341+ const agentsPromise = sdk . client . app . agents ( { } , { throwOnError : true } )
342+ const configPromise = sdk . client . config . get ( { } , { throwOnError : true } )
339343 const blockingRequests : Promise < unknown > [ ] = [
340- sdk . client . config . providers ( { } , { throwOnError : true } ) . then ( ( x ) => {
341- batch ( ( ) => {
342- setStore ( "provider" , reconcile ( x . data ! . providers ) )
343- setStore ( "provider_default" , reconcile ( x . data ! . default ) )
344- } )
345- } ) ,
346- sdk . client . provider . list ( { } , { throwOnError : true } ) . then ( ( x ) => {
347- batch ( ( ) => {
348- setStore ( "provider_next" , reconcile ( x . data ! ) )
349- } )
350- } ) ,
351- sdk . client . app . agents ( { } , { throwOnError : true } ) . then ( ( x ) => setStore ( "agent" , reconcile ( x . data ?? [ ] ) ) ) ,
352- sdk . client . config . get ( { } , { throwOnError : true } ) . then ( ( x ) => setStore ( "config" , reconcile ( x . data ! ) ) ) ,
344+ providersPromise ,
345+ providerListPromise ,
346+ agentsPromise ,
347+ configPromise ,
353348 ...( args . continue ? [ sessionListPromise ] : [ ] ) ,
354349 ]
355350
356351 await Promise . all ( blockingRequests )
352+ . then ( ( ) => {
353+ const providersResponse = providersPromise . then ( ( x ) => x . data ! )
354+ const providerListResponse = providerListPromise . then ( ( x ) => x . data ! )
355+ const agentsResponse = agentsPromise . then ( ( x ) => x . data ?? [ ] )
356+ const configResponse = configPromise . then ( ( x ) => x . data ! )
357+ const sessionListResponse = args . continue ? sessionListPromise : undefined
358+
359+ return Promise . all ( [
360+ providersResponse ,
361+ providerListResponse ,
362+ agentsResponse ,
363+ configResponse ,
364+ ...( sessionListResponse ? [ sessionListResponse ] : [ ] ) ,
365+ ] ) . then ( ( responses ) => {
366+ const providers = responses [ 0 ]
367+ const providerList = responses [ 1 ]
368+ const agents = responses [ 2 ]
369+ const config = responses [ 3 ]
370+ const sessions = responses [ 4 ]
371+
372+ batch ( ( ) => {
373+ setStore ( "provider" , reconcile ( providers . providers ) )
374+ setStore ( "provider_default" , reconcile ( providers . default ) )
375+ setStore ( "provider_next" , reconcile ( providerList ) )
376+ setStore ( "agent" , reconcile ( agents ) )
377+ setStore ( "config" , reconcile ( config ) )
378+ if ( sessions !== undefined ) setStore ( "session" , reconcile ( sessions ) )
379+ } )
380+ } )
381+ } )
357382 . then ( ( ) => {
358383 if ( store . status !== "complete" ) setStore ( "status" , "partial" )
359384 // non-blocking
360385 Promise . all ( [
361- ...( args . continue ? [ ] : [ sessionListPromise ] ) ,
386+ ...( args . continue ? [ ] : [ sessionListPromise . then ( ( sessions ) => setStore ( "session" , reconcile ( sessions ) ) ) ] ) ,
362387 sdk . client . command . list ( ) . then ( ( x ) => setStore ( "command" , reconcile ( x . data ?? [ ] ) ) ) ,
363388 sdk . client . lsp . status ( ) . then ( ( x ) => setStore ( "lsp" , reconcile ( x . data ! ) ) ) ,
364389 sdk . client . mcp . status ( ) . then ( ( x ) => setStore ( "mcp" , reconcile ( x . data ! ) ) ) ,
0 commit comments