mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix: sync model store with config changes for context usage updates (#75)
This commit is contained in:
1 parent
efd3b94372
commit
05af9d9ea3
2 files changed
+18
-13
No files matched your search
@@ -14,13 +14,11 @@ export function useModelSelection(
|
||||
directory?: string
|
||||
): UseModelSelectionResult {
|
||||
const { data: config } = useConfig(opcodeUrl, directory)
|
||||
const { model, recentModels, setModel, initializeFromConfig, getModelString } = useModelStore()
|
||||
const { model, recentModels, setModel, syncFromConfig, getModelString } = useModelStore()
|
||||
|
||||
useEffect(() => {
|
||||
if (config?.model) {
|
||||
initializeFromConfig(config.model)
|
||||
}
|
||||
}, [config?.model, initializeFromConfig])
|
||||
syncFromConfig(config?.model)
|
||||
}, [config?.model, syncFromConfig])
|
||||
|
||||
return {
|
||||
model,
|
||||
|
||||
@@ -10,10 +10,10 @@ interface ModelStore {
|
||||
model: ModelSelection | null
|
||||
recentModels: ModelSelection[]
|
||||
variants: Record<string, string | undefined>
|
||||
isInitialized: boolean
|
||||
lastConfigModel: string | undefined
|
||||
|
||||
setModel: (model: ModelSelection) => void
|
||||
initializeFromConfig: (configModel: string | undefined) => void
|
||||
syncFromConfig: (configModel: string | undefined) => void
|
||||
getModelString: () => string | null
|
||||
setVariant: (model: ModelSelection, variant: string | undefined) => void
|
||||
getVariant: (model: ModelSelection) => string | undefined
|
||||
@@ -35,7 +35,7 @@ export const useModelStore = create<ModelStore>()(
|
||||
model: null,
|
||||
recentModels: [],
|
||||
variants: {},
|
||||
isInitialized: false,
|
||||
lastConfigModel: undefined,
|
||||
|
||||
setModel: (model: ModelSelection) => {
|
||||
set((state) => {
|
||||
@@ -53,18 +53,25 @@ export const useModelStore = create<ModelStore>()(
|
||||
})
|
||||
},
|
||||
|
||||
initializeFromConfig: (configModel: string | undefined) => {
|
||||
syncFromConfig: (configModel: string | undefined) => {
|
||||
const state = get()
|
||||
if (state.isInitialized) return
|
||||
if (state.lastConfigModel === configModel) return
|
||||
|
||||
if (!state.model && configModel) {
|
||||
if (configModel) {
|
||||
const parsed = parseModelString(configModel)
|
||||
if (parsed) {
|
||||
set({ model: parsed, isInitialized: true })
|
||||
const newRecent = [
|
||||
parsed,
|
||||
...state.recentModels.filter(
|
||||
(m) => !(m.providerID === parsed.providerID && m.modelID === parsed.modelID)
|
||||
),
|
||||
].slice(0, MAX_RECENT_MODELS)
|
||||
|
||||
set({ model: parsed, lastConfigModel: configModel, recentModels: newRecent })
|
||||
return
|
||||
}
|
||||
}
|
||||
set({ isInitialized: true })
|
||||
set({ lastConfigModel: configModel })
|
||||
},
|
||||
|
||||
getModelString: () => {
|
||||
|
||||
Reference in new issue
Block a user