mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix: clean up stale models from recentModels and validate current selection
- Add modelExists helper to check if a model exists in providers - Filter recentModels to remove entries that no longer exist - Validate current model selection against available providers - Force sync from config if current model is invalid - Only update state when cleanup actually changes something
This commit is contained in:
1 parent
9d94c333b4
commit
0cf4c978de
1 file changed
+14
-5
@@ -81,16 +81,25 @@ export const useModelStore = create<ModelStore>()(
|
||||
|
||||
const state = get()
|
||||
|
||||
if (!providers || !state.model) {
|
||||
if (!providers) {
|
||||
get().syncFromConfig(configModel)
|
||||
return
|
||||
}
|
||||
|
||||
const modelExists = providers.some(
|
||||
(p) => p.id === state.model!.providerID && p.models && state.model!.modelID in p.models
|
||||
)
|
||||
const modelExists = (model: ModelSelection) =>
|
||||
providers.some(
|
||||
(p) => p.id === model.providerID && p.models && model.modelID in p.models
|
||||
)
|
||||
|
||||
if (!modelExists) {
|
||||
const currentModelExists = state.model ? modelExists(state.model) : false
|
||||
|
||||
const cleanedRecentModels = state.recentModels.filter(modelExists)
|
||||
|
||||
if (cleanedRecentModels.length !== state.recentModels.length) {
|
||||
set({ recentModels: cleanedRecentModels })
|
||||
}
|
||||
|
||||
if (!currentModelExists) {
|
||||
get().syncFromConfig(configModel, true)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user