Browse Source

tui: fix model state persistence when model store is not ready

Aiden Cline 1 month ago
parent
commit
f3513bacff
1 changed files with 9 additions and 0 deletions
  1. 9 0
      packages/opencode/src/cli/cmd/tui/context/local.tsx

+ 9 - 0
packages/opencode/src/cli/cmd/tui/context/local.tsx

@@ -113,8 +113,16 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
       })
       })
 
 
       const file = Bun.file(path.join(Global.Path.state, "model.json"))
       const file = Bun.file(path.join(Global.Path.state, "model.json"))
+      const state = {
+        pending: false,
+      }
 
 
       function save() {
       function save() {
+        if (!modelStore.ready) {
+          state.pending = true
+          return
+        }
+        state.pending = false
         Bun.write(
         Bun.write(
           file,
           file,
           JSON.stringify({
           JSON.stringify({
@@ -135,6 +143,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
         .catch(() => {})
         .catch(() => {})
         .finally(() => {
         .finally(() => {
           setModelStore("ready", true)
           setModelStore("ready", true)
+          if (state.pending) save()
         })
         })
 
 
       const args = useArgs()
       const args = useArgs()