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:
Chris Scott committed 2026-04-15 17:44:02 +00:00
1 parent 9d94c333b4
commit 0cf4c978de
1 file changed
+14 -5
+14 -5
View File
@@ -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)
}
},