| 404 | const exit = useExit() |
| 405 | |
| 406 | async function bootstrap() { |
| 407 | // blocking |
| 408 | await Promise.all([ |
| 409 | sdk.client.config.providers({}, { throwOnError: true }).then((x) => { |
| 410 | batch(() => { |
| 411 | setStore("provider", x.data!.providers) |
| 412 | setStore("provider_default", x.data!.default) |
| 413 | }) |
| 414 | }), |
| 415 | sdk.client.provider.list({}, { throwOnError: true }).then((x) => { |
| 416 | batch(() => { |
| 417 | setStore("provider_next", x.data!) |
| 418 | }) |
| 419 | }), |
| 420 | sdk.client.app.agents({}, { throwOnError: true }).then((x) => setStore("agent", x.data ?? [])), |
| 421 | sdk.client.config.get({}, { throwOnError: true }).then((x) => setStore("config", x.data!)), |
| 422 | ]) |
| 423 | .then(() => { |
| 424 | if (store.status !== "complete") setStore("status", "partial") |
| 425 | // non-blocking |
| 426 | Promise.all([ |
| 427 | sdk.client.session.list().then((x) => |
| 428 | setStore( |
| 429 | "session", |
| 430 | (x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)), |
| 431 | ), |
| 432 | ), |
| 433 | sdk.client.command.list().then((x) => setStore("command", x.data ?? [])), |
| 434 | sdk.client.lsp.status().then((x) => setStore("lsp", x.data!)), |
| 435 | sdk.client.mcp.status().then((x) => setStore("mcp", x.data!)), |
| 436 | sdk.client.formatter.status().then((x) => setStore("formatter", x.data!)), |
| 437 | sdk.client.session.status().then((x) => setStore("session_status", x.data!)), |
| 438 | sdk.client.provider.auth().then((x) => setStore("provider_auth", x.data ?? {})), |
| 439 | sdk.client.vcs.get().then((x) => setStore("vcs", x.data)), |
| 440 | sdk.client.path.get().then((x) => setStore("path", x.data!)), |
| 441 | sdk.client.pty.list().then((x) => setStore("pty", x.data ?? [])), |
| 442 | // fetch permission bypass status |
| 443 | sdk.client.permission.bypass |
| 444 | .get() |
| 445 | .then((x) => setStore("permission_bypass_enabled", x.data?.enabled ?? false)) |
| 446 | .catch(() => {}), |
| 447 | // Initialize OpenRouter pricing cache in background (with timeout to avoid hanging) |
| 448 | // TODO: Temporarily disabled due to Bun crash |
| 449 | // Promise.race([ |
| 450 | // Pricing.initOpenRouterPricing(), |
| 451 | // new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), 10000)), |
| 452 | // ]).catch((e) => { |
| 453 | // Log.Default.warn("Failed to initialize OpenRouter pricing", { error: e instanceof Error ? e.message : String(e) }) |
| 454 | // }), |
| 455 | ]).then(() => { |
| 456 | setStore("status", "complete") |
| 457 | }) |
| 458 | }) |
| 459 | .catch(async (e) => { |
| 460 | Log.Default.error("tui bootstrap failed", { |
| 461 | error: e instanceof Error ? e.message : String(e), |
| 462 | name: e instanceof Error ? e.name : undefined, |
| 463 | stack: e instanceof Error ? e.stack : undefined, |