tweak: adjust tui syncing logic to help prevent case where agents would be undefined / missing
This commit is contained in:
@@ -333,32 +333,57 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||||||
const start = Date.now() - 30 * 24 * 60 * 60 * 1000
|
const start = Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||||
const sessionListPromise = sdk.client.session
|
const sessionListPromise = sdk.client.session
|
||||||
.list({ start: start })
|
.list({ start: start })
|
||||||
.then((x) => setStore("session", reconcile((x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)))))
|
.then((x) => (x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)))
|
||||||
|
|
||||||
// blocking - include session.list when continuing a session
|
// blocking - include session.list when continuing a session
|
||||||
|
const providersPromise = sdk.client.config.providers({}, { throwOnError: true })
|
||||||
|
const providerListPromise = sdk.client.provider.list({}, { throwOnError: true })
|
||||||
|
const agentsPromise = sdk.client.app.agents({}, { throwOnError: true })
|
||||||
|
const configPromise = sdk.client.config.get({}, { throwOnError: true })
|
||||||
const blockingRequests: Promise<unknown>[] = [
|
const blockingRequests: Promise<unknown>[] = [
|
||||||
sdk.client.config.providers({}, { throwOnError: true }).then((x) => {
|
providersPromise,
|
||||||
batch(() => {
|
providerListPromise,
|
||||||
setStore("provider", reconcile(x.data!.providers))
|
agentsPromise,
|
||||||
setStore("provider_default", reconcile(x.data!.default))
|
configPromise,
|
||||||
})
|
|
||||||
}),
|
|
||||||
sdk.client.provider.list({}, { throwOnError: true }).then((x) => {
|
|
||||||
batch(() => {
|
|
||||||
setStore("provider_next", reconcile(x.data!))
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
sdk.client.app.agents({}, { throwOnError: true }).then((x) => setStore("agent", reconcile(x.data ?? []))),
|
|
||||||
sdk.client.config.get({}, { throwOnError: true }).then((x) => setStore("config", reconcile(x.data!))),
|
|
||||||
...(args.continue ? [sessionListPromise] : []),
|
...(args.continue ? [sessionListPromise] : []),
|
||||||
]
|
]
|
||||||
|
|
||||||
await Promise.all(blockingRequests)
|
await Promise.all(blockingRequests)
|
||||||
|
.then(() => {
|
||||||
|
const providersResponse = providersPromise.then((x) => x.data!)
|
||||||
|
const providerListResponse = providerListPromise.then((x) => x.data!)
|
||||||
|
const agentsResponse = agentsPromise.then((x) => x.data ?? [])
|
||||||
|
const configResponse = configPromise.then((x) => x.data!)
|
||||||
|
const sessionListResponse = args.continue ? sessionListPromise : undefined
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
providersResponse,
|
||||||
|
providerListResponse,
|
||||||
|
agentsResponse,
|
||||||
|
configResponse,
|
||||||
|
...(sessionListResponse ? [sessionListResponse] : []),
|
||||||
|
]).then((responses) => {
|
||||||
|
const providers = responses[0]
|
||||||
|
const providerList = responses[1]
|
||||||
|
const agents = responses[2]
|
||||||
|
const config = responses[3]
|
||||||
|
const sessions = responses[4]
|
||||||
|
|
||||||
|
batch(() => {
|
||||||
|
setStore("provider", reconcile(providers.providers))
|
||||||
|
setStore("provider_default", reconcile(providers.default))
|
||||||
|
setStore("provider_next", reconcile(providerList))
|
||||||
|
setStore("agent", reconcile(agents))
|
||||||
|
setStore("config", reconcile(config))
|
||||||
|
if (sessions !== undefined) setStore("session", reconcile(sessions))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (store.status !== "complete") setStore("status", "partial")
|
if (store.status !== "complete") setStore("status", "partial")
|
||||||
// non-blocking
|
// non-blocking
|
||||||
Promise.all([
|
Promise.all([
|
||||||
...(args.continue ? [] : [sessionListPromise]),
|
...(args.continue ? [] : [sessionListPromise.then((sessions) => setStore("session", reconcile(sessions)))]),
|
||||||
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
|
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
|
||||||
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
|
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
|
||||||
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
|
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
|
||||||
|
|||||||
Reference in New Issue
Block a user