Sfoglia il codice sorgente

fix: update provider store after loading providers in bootstrap (#25236)

Brendan Allan 3 mesi fa
parent
commit
a5aa72bd7d

+ 3 - 0
packages/app/src/context/global-sync.tsx

@@ -204,6 +204,9 @@ function createGlobalSync() {
     },
     translate: language.t,
     getSdk: sdkFor,
+    global: {
+      provider: globalStore.provider,
+    },
   })
 
   async function loadSessions(directory: string) {

+ 0 - 3
packages/app/src/context/global-sync/bootstrap.ts

@@ -260,9 +260,6 @@ export async function bootstrapDirectory(input: {
   const seededPath = input.global.path.directory === input.directory ? input.global.path : undefined
   if (seededProject) input.setStore("project", seededProject)
   if (seededPath) input.setStore("path", seededPath)
-  if (input.store.provider.all.length === 0 && input.global.provider.all.length > 0) {
-    input.setStore("provider", input.global.provider)
-  }
   if (Object.keys(input.store.config).length === 0 && Object.keys(input.global.config).length > 0) {
     input.setStore("config", reconcile(input.global.config, { merge: false }))
   }

+ 1 - 0
packages/app/src/context/global-sync/child-store.test.ts

@@ -23,6 +23,7 @@ describe("createChildStoreManager", () => {
       onDispose() {},
       translate: (key) => key,
       getSdk: () => null!,
+      global: { provider: null! },
     })
 
     Array.from({ length: 30 }, (_, index) => `/pinned-${index}`).forEach((directory) => {

+ 11 - 2
packages/app/src/context/global-sync/child-store.ts

@@ -1,7 +1,7 @@
 import { createRoot, getOwner, onCleanup, runWithOwner, type Owner } from "solid-js"
 import { createStore, type SetStoreFunction, type Store } from "solid-js/store"
 import { Persist, persisted } from "@/utils/persist"
-import type { OpencodeClient, VcsInfo } from "@opencode-ai/sdk/v2/client"
+import type { OpencodeClient, ProviderListResponse, VcsInfo } from "@opencode-ai/sdk/v2/client"
 import {
   DIR_IDLE_TTL_MS,
   MAX_DIR_STORES,
@@ -27,6 +27,9 @@ export function createChildStoreManager(input: {
   onDispose: (directory: string) => void
   translate: (key: string, vars?: Record<string, string | number>) => string
   getSdk: (directory: string) => OpencodeClient
+  global: {
+    provider: ProviderListResponse
+  }
 }) {
   const children: Record<string, [Store<State>, SetStoreFunction<State>]> = {}
   const vcsCache = new Map<string, VcsCache>()
@@ -189,7 +192,13 @@ export function createChildStoreManager(input: {
             get provider_ready() {
               return !providerQuery.isLoading
             },
-            provider: { all: [], connected: [], default: {} },
+            get provider() {
+              const EMPTY = { all: [], connected: [], default: {} }
+              if (providerQuery.isLoading) return EMPTY
+              if (providerQuery.data?.all.length === 0 && input.global.provider.all.length > 0)
+                return input.global.provider
+              return providerQuery.data ?? EMPTY
+            },
             config: {},
             get path() {
               if (pathQuery.isLoading || !pathQuery.data)