Skip to content

Commit a5aa72b

Browse files
authored
fix: update provider store after loading providers in bootstrap (#25236)
1 parent 563177c commit a5aa72b

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

packages/app/src/context/global-sync.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ function createGlobalSync() {
204204
},
205205
translate: language.t,
206206
getSdk: sdkFor,
207+
global: {
208+
provider: globalStore.provider,
209+
},
207210
})
208211

209212
async function loadSessions(directory: string) {

packages/app/src/context/global-sync/bootstrap.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ export async function bootstrapDirectory(input: {
260260
const seededPath = input.global.path.directory === input.directory ? input.global.path : undefined
261261
if (seededProject) input.setStore("project", seededProject)
262262
if (seededPath) input.setStore("path", seededPath)
263-
if (input.store.provider.all.length === 0 && input.global.provider.all.length > 0) {
264-
input.setStore("provider", input.global.provider)
265-
}
266263
if (Object.keys(input.store.config).length === 0 && Object.keys(input.global.config).length > 0) {
267264
input.setStore("config", reconcile(input.global.config, { merge: false }))
268265
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe("createChildStoreManager", () => {
2323
onDispose() {},
2424
translate: (key) => key,
2525
getSdk: () => null!,
26+
global: { provider: null! },
2627
})
2728

2829
Array.from({ length: 30 }, (_, index) => `/pinned-${index}`).forEach((directory) => {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createRoot, getOwner, onCleanup, runWithOwner, type Owner } from "solid-js"
22
import { createStore, type SetStoreFunction, type Store } from "solid-js/store"
33
import { Persist, persisted } from "@/utils/persist"
4-
import type { OpencodeClient, VcsInfo } from "@opencode-ai/sdk/v2/client"
4+
import type { OpencodeClient, ProviderListResponse, VcsInfo } from "@opencode-ai/sdk/v2/client"
55
import {
66
DIR_IDLE_TTL_MS,
77
MAX_DIR_STORES,
@@ -27,6 +27,9 @@ export function createChildStoreManager(input: {
2727
onDispose: (directory: string) => void
2828
translate: (key: string, vars?: Record<string, string | number>) => string
2929
getSdk: (directory: string) => OpencodeClient
30+
global: {
31+
provider: ProviderListResponse
32+
}
3033
}) {
3134
const children: Record<string, [Store<State>, SetStoreFunction<State>]> = {}
3235
const vcsCache = new Map<string, VcsCache>()
@@ -189,7 +192,13 @@ export function createChildStoreManager(input: {
189192
get provider_ready() {
190193
return !providerQuery.isLoading
191194
},
192-
provider: { all: [], connected: [], default: {} },
195+
get provider() {
196+
const EMPTY = { all: [], connected: [], default: {} }
197+
if (providerQuery.isLoading) return EMPTY
198+
if (providerQuery.data?.all.length === 0 && input.global.provider.all.length > 0)
199+
return input.global.provider
200+
return providerQuery.data ?? EMPTY
201+
},
193202
config: {},
194203
get path() {
195204
if (pathQuery.isLoading || !pathQuery.data)

0 commit comments

Comments
 (0)