perf: streamline provider and agent startup loading #185
Avoids loading the full provider catalog on startup Prewarms project config in the background Prevents duplicate worktree-scoped config requests
This commit is contained in:
@@ -80,7 +80,6 @@ export async function bootstrapGlobal(
|
||||
set({ projects })
|
||||
}),
|
||||
),
|
||||
retry(() => sdk.provider.list().then((x) => set({ providers: unwrap(x, "provider.list") }))),
|
||||
])
|
||||
|
||||
const errors = results
|
||||
@@ -125,7 +124,6 @@ export async function bootstrapDirectory(input: {
|
||||
global: {
|
||||
config: Record<string, unknown>
|
||||
projects: Project[]
|
||||
providers: { all: unknown[]; connected: unknown[]; default: Record<string, unknown> }
|
||||
}
|
||||
loadSessions: (directory: string) => Promise<void> | void
|
||||
}) {
|
||||
@@ -136,9 +134,6 @@ export async function bootstrapDirectory(input: {
|
||||
// Seed from global state while we fetch directory-specific data
|
||||
const seededProject = projectID(directory, g.projects)
|
||||
if (seededProject) set({ project: seededProject })
|
||||
if (state.provider.all.length === 0 && g.providers.all.length > 0) {
|
||||
set({ provider: g.providers as State["provider"] })
|
||||
}
|
||||
if (Object.keys(state.config ?? {}).length === 0 && Object.keys(g.config ?? {}).length > 0) {
|
||||
set({ config: g.config as State["config"] })
|
||||
}
|
||||
@@ -152,7 +147,6 @@ export async function bootstrapDirectory(input: {
|
||||
seededProject
|
||||
? Promise.resolve()
|
||||
: retry(() => sdk.project.current().then((x) => set({ project: unwrap(x, "project.current").id }))),
|
||||
retry(() => sdk.provider.list().then((x) => set({ provider: unwrap(x, "provider.list") }))),
|
||||
retry(() => sdk.config.get().then((x) => set({ config: unwrap(x, "config.get") }))),
|
||||
retry(() =>
|
||||
sdk.path.get().then((x) => {
|
||||
@@ -177,7 +171,7 @@ export async function bootstrapDirectory(input: {
|
||||
// - path.get feeds project resolution, but if we already resolved a project
|
||||
// (from global projects) its failure is tolerable; the worktree path is
|
||||
// refreshed by later events.
|
||||
const [, , , pathResult] = phase1Results
|
||||
const [, , pathResult] = phase1Results
|
||||
const pathFailedWithoutProject =
|
||||
pathResult.status === "rejected" && !getState().project
|
||||
|
||||
@@ -194,7 +188,6 @@ export async function bootstrapDirectory(input: {
|
||||
// These enrich the UI but aren't required for basic functionality.
|
||||
// ---------------------------------------------------------------------------
|
||||
void Promise.allSettled([
|
||||
retry(() => sdk.app.agents().then((x) => set({ agent: unwrap(x, "app.agents") }))),
|
||||
retry(() => sdk.command.list().then((x) => set({ command: unwrap(x, "command.list") }))),
|
||||
retry(() => sdk.mcp.status().then((x) => set({ mcp: unwrap(x, "mcp.status") }))),
|
||||
retry(() => sdk.lsp.status().then((x) => set({ lsp: unwrap(x, "lsp.status") }))),
|
||||
|
||||
@@ -1657,11 +1657,10 @@ export function SyncProvider(props: {
|
||||
ingestDirectoryStateIntoRoutingIndex(routingIndex, directory, store.getState())
|
||||
}
|
||||
},
|
||||
global: {
|
||||
config: globalState.config,
|
||||
projects: globalState.projects,
|
||||
providers: globalState.providers,
|
||||
},
|
||||
global: {
|
||||
config: globalState.config,
|
||||
projects: globalState.projects,
|
||||
},
|
||||
loadSessions: (dir) => retry(async () => {
|
||||
const rootSessions = (await listGlobalSessionPages(props.sdk, {
|
||||
directory: dir,
|
||||
@@ -1752,11 +1751,11 @@ export function SyncProvider(props: {
|
||||
const generation = ++globalBootstrapGeneration
|
||||
bootingRoot = true
|
||||
const globalActions = useGlobalSyncStore.getState().actions
|
||||
bootstrapGlobal(props.sdk, (patch) => {
|
||||
if (globalBootstrapGeneration === generation) {
|
||||
globalActions.set(patch)
|
||||
}
|
||||
})
|
||||
bootstrapGlobal(props.sdk, (patch) => {
|
||||
if (globalBootstrapGeneration === generation) {
|
||||
globalActions.set(patch)
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
if (globalBootstrapGeneration === generation) {
|
||||
bootedAt = Date.now()
|
||||
@@ -1772,7 +1771,7 @@ export function SyncProvider(props: {
|
||||
bootingRoot = false
|
||||
}
|
||||
}
|
||||
}, [props.sdk])
|
||||
}, [props.sdk])
|
||||
|
||||
// Event pipeline — created once per mount. No class, no start/stop.
|
||||
// Abort controller owned by the pipeline closure. Cleanup aborts + flushes.
|
||||
|
||||
Reference in New Issue
Block a user