@@ -18,7 +18,7 @@ import { reconcile, type SetStoreFunction, type Store } from "solid-js/store"
1818import type { State , VcsCache } from "./types"
1919import { cmp , normalizeAgentList , normalizeProviderList } from "./utils"
2020import { formatServerError } from "@/utils/server-errors"
21- import { QueryClient , queryOptions , skipToken } from "@tanstack/solid-query"
21+ import { QueryClient , queryOptions } from "@tanstack/solid-query"
2222import { loadMcpQuery } from "../global-sync"
2323
2424type GlobalStore = {
@@ -83,44 +83,25 @@ function showErrors(input: {
8383 } )
8484}
8585
86- export const loadGlobalConfigQuery = (
87- sdk ?: OpencodeClient ,
88- transform ?: ( x : Awaited < ReturnType < OpencodeClient [ "global" ] [ "config" ] [ "get" ] > > ) => void ,
89- ) =>
86+ export const loadGlobalConfigQuery = ( sdk : OpencodeClient ) =>
9087 queryOptions ( {
9188 queryKey : [ "config" ] ,
92- queryFn : sdk
93- ? ( ) =>
94- retry ( ( ) =>
95- sdk . global . config . get ( ) . then ( ( x ) => {
96- transform ?.( x )
97- return x . data !
98- } ) ,
99- )
100- : skipToken ,
89+ queryFn : ( ) => retry ( ( ) => sdk . global . config . get ( ) . then ( ( x ) => x . data ! ) ) ,
10190 } )
10291
103- export const loadProjectsQuery = (
104- sdk ?: OpencodeClient ,
105- transform ?: ( x : Awaited < ReturnType < OpencodeClient [ "project" ] [ "list" ] > > [ "data" ] ) => void ,
106- ) =>
92+ export const loadProjectsQuery = ( sdk : OpencodeClient ) =>
10793 queryOptions ( {
10894 queryKey : [ "project" ] ,
109- queryFn : sdk
110- ? ( ) =>
111- retry ( ( ) =>
112- sdk . project
113- . list ( )
114- . then ( ( x ) => {
115- return ( x . data ?? [ ] )
116- . filter ( ( p ) => ! ! p ?. id )
117- . filter ( ( p ) => ! ! p . worktree && ! p . worktree . includes ( "opencode-test" ) )
118- . slice ( )
119- . sort ( ( a , b ) => cmp ( a . id , b . id ) )
120- } )
121- . then ( transform ) ,
122- )
123- : skipToken ,
95+ queryFn : ( ) =>
96+ retry ( ( ) =>
97+ sdk . project . list ( ) . then ( ( x ) => {
98+ return ( x . data ?? [ ] )
99+ . filter ( ( p ) => ! ! p ?. id )
100+ . filter ( ( p ) => ! ! p . worktree && ! p . worktree . includes ( "opencode-test" ) )
101+ . slice ( )
102+ . sort ( ( a , b ) => cmp ( a . id , b . id ) )
103+ } ) ,
104+ ) ,
124105 } )
125106
126107export async function bootstrapGlobal ( input : {
@@ -136,9 +117,9 @@ export async function bootstrapGlobal(input: {
136117 ( ) => input . queryClient . fetchQuery ( loadProvidersQuery ( null , input . globalSDK ) ) ,
137118 ( ) => input . queryClient . fetchQuery ( loadPathQuery ( null , input . globalSDK ) ) ,
138119 ( ) =>
139- input . queryClient . fetchQuery (
140- loadProjectsQuery ( input . globalSDK , ( data ) => input . setGlobalStore ( "project" , data ?? [ ] ) ) ,
141- ) ,
120+ input . queryClient
121+ . fetchQuery ( loadProjectsQuery ( input . globalSDK ) )
122+ . then ( ( data ) => input . setGlobalStore ( "project" , data ) ) ,
142123 ]
143124 await runAll ( slow )
144125 // showErrors({
@@ -197,46 +178,22 @@ function warmSessions(input: {
197178 ) . then ( ( ) => undefined )
198179}
199180
200- export const loadProvidersQuery = ( directory : string | null , sdk ? : OpencodeClient ) =>
181+ export const loadProvidersQuery = ( directory : string | null , sdk : OpencodeClient ) =>
201182 queryOptions ( {
202183 queryKey : [ directory , "providers" ] ,
203- queryFn : sdk ? ( ) => retry ( ( ) => sdk . provider . list ( ) . then ( ( x ) => normalizeProviderList ( x . data ! ) ) ) : skipToken ,
184+ queryFn : ( ) => retry ( ( ) => sdk . provider . list ( ) . then ( ( x ) => normalizeProviderList ( x . data ! ) ) ) ,
204185 } )
205186
206- export const loadAgentsQuery = (
207- directory : string | null ,
208- sdk ?: OpencodeClient ,
209- transform ?: ( x : Awaited < ReturnType < OpencodeClient [ "app" ] [ "agents" ] > > ) => void ,
210- ) =>
187+ export const loadAgentsQuery = ( directory : string | null , sdk : OpencodeClient ) =>
211188 queryOptions ( {
212189 queryKey : [ directory , "agents" ] ,
213- queryFn : sdk
214- ? ( ) =>
215- retry ( ( ) =>
216- sdk . app . agents ( ) . then ( ( x ) => {
217- transform ?.( x )
218- return x . data !
219- } ) ,
220- )
221- : skipToken ,
190+ queryFn : ( ) => retry ( ( ) => sdk . app . agents ( ) . then ( ( x ) => normalizeAgentList ( x . data ) ) ) ,
222191 } )
223192
224- export const loadPathQuery = (
225- directory : string | null ,
226- sdk ?: OpencodeClient ,
227- transform ?: ( x : Awaited < ReturnType < OpencodeClient [ "path" ] [ "get" ] > > ) => void ,
228- ) =>
193+ export const loadPathQuery = ( directory : string | null , sdk : OpencodeClient ) =>
229194 queryOptions < Path > ( {
230195 queryKey : [ directory , "path" ] ,
231- queryFn : sdk
232- ? ( ) =>
233- retry ( ( ) =>
234- sdk . path . get ( ) . then ( async ( x ) => {
235- transform ?.( x )
236- return x . data !
237- } ) ,
238- )
239- : skipToken ,
196+ queryFn : ( ) => retry ( ( ) => sdk . path . get ( ) . then ( ( x ) => x . data ! ) ) ,
240197 } )
241198
242199export async function bootstrapDirectory ( input : {
@@ -271,22 +228,20 @@ export async function bootstrapDirectory(input: {
271228 const slow = [
272229 ( ) => Promise . resolve ( input . loadSessions ( input . directory ) ) ,
273230 ( ) =>
274- input . queryClient . ensureQueryData (
275- loadAgentsQuery ( input . directory , input . sdk , ( x ) => input . setStore ( "agent" , normalizeAgentList ( x . data ) ) ) ,
276- ) ,
231+ input . queryClient
232+ . ensureQueryData ( loadAgentsQuery ( input . directory , input . sdk ) )
233+ . then ( ( data ) => input . setStore ( "agent" , data ) ) ,
277234 ( ) =>
278235 retry ( ( ) => input . sdk . config . get ( ) . then ( ( x ) => input . setStore ( "config" , reconcile ( x . data ! , { merge : false } ) ) ) ) ,
279236 ( ) => retry ( ( ) => input . sdk . session . status ( ) . then ( ( x ) => input . setStore ( "session_status" , x . data ! ) ) ) ,
280237 ! seededProject &&
281238 ( ( ) => retry ( ( ) => input . sdk . project . current ( ) ) . then ( ( x ) => input . setStore ( "project" , x . data ! . id ) ) ) ,
282239 ! seededPath &&
283240 ( ( ) =>
284- input . queryClient . ensureQueryData (
285- loadPathQuery ( input . directory , input . sdk , ( x ) => {
286- const next = projectID ( x . data ?. directory ?? input . directory , input . global . project )
287- if ( next ) input . setStore ( "project" , next )
288- } ) ,
289- ) ) ,
241+ input . queryClient . ensureQueryData ( loadPathQuery ( input . directory , input . sdk ) ) . then ( ( data ) => {
242+ const next = projectID ( data . directory ?? input . directory , input . global . project )
243+ if ( next ) input . setStore ( "project" , next )
244+ } ) ) ,
290245 ( ) =>
291246 retry ( ( ) =>
292247 input . sdk . vcs . get ( ) . then ( ( x ) => {
0 commit comments