diff --git a/desktop/src/store/chat/conversationStore.ts b/desktop/src/store/chat/conversationStore.ts index ff86e2a..5c15967 100644 --- a/desktop/src/store/chat/conversationStore.ts +++ b/desktop/src/store/chat/conversationStore.ts @@ -192,7 +192,7 @@ export const useConversationStore = create()( agents: [DEFAULT_AGENT], currentAgent: DEFAULT_AGENT, sessionKey: null, - currentModel: 'glm-4-flash-250414', + currentModel: '', // Set dynamically: SaaS models or config.toml default newConversation: (currentMessages: ChatMessage[]) => { const state = get(); diff --git a/desktop/src/store/saasStore.ts b/desktop/src/store/saasStore.ts index 4d1212c..6bc0a11 100644 --- a/desktop/src/store/saasStore.ts +++ b/desktop/src/store/saasStore.ts @@ -467,6 +467,24 @@ export const useSaaSStore = create((set, get) => { saasClient.setBaseUrl(saasUrl); const models = await saasClient.listModels(); set({ availableModels: models }); + + // Sync currentModel: if the stored model is not in the available list, + // switch to the first available model to prevent 404 errors + if (models.length > 0) { + try { + const { useConversationStore } = require('./chat/conversationStore'); + const current = useConversationStore.getState().currentModel; + const modelIds = models.map(m => m.alias || m.id); + if (current && !modelIds.includes(current)) { + const firstModel = models[0]; + const fallbackId = firstModel.alias || firstModel.id; + useConversationStore.getState().setCurrentModel(fallbackId); + log.info(`Synced currentModel: ${current} not available, switched to ${fallbackId}`); + } + } catch (syncErr) { + log.warn('Failed to sync currentModel after fetching models:', syncErr); + } + } } catch (err: unknown) { log.warn('Failed to fetch available models:', err); // Do not set error state - model fetch failure is non-critical