fix: sync currentModel from SaaS available models on login
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Root cause: conversationStore hardcoded 'glm-4-flash' as default model, which may not exist in SaaS admin config, causing 404 on all chat requests. - conversationStore: default currentModel to empty string (runtime-resolved) - saasStore: after fetching available models, auto-switch currentModel to first available if the stored model is not in the list - SaaS relay getModel() already had fallback to first available model
This commit is contained in:
@@ -192,7 +192,7 @@ export const useConversationStore = create<ConversationState>()(
|
|||||||
agents: [DEFAULT_AGENT],
|
agents: [DEFAULT_AGENT],
|
||||||
currentAgent: DEFAULT_AGENT,
|
currentAgent: DEFAULT_AGENT,
|
||||||
sessionKey: null,
|
sessionKey: null,
|
||||||
currentModel: 'glm-4-flash-250414',
|
currentModel: '', // Set dynamically: SaaS models or config.toml default
|
||||||
|
|
||||||
newConversation: (currentMessages: ChatMessage[]) => {
|
newConversation: (currentMessages: ChatMessage[]) => {
|
||||||
const state = get();
|
const state = get();
|
||||||
|
|||||||
@@ -467,6 +467,24 @@ export const useSaaSStore = create<SaaSStore>((set, get) => {
|
|||||||
saasClient.setBaseUrl(saasUrl);
|
saasClient.setBaseUrl(saasUrl);
|
||||||
const models = await saasClient.listModels();
|
const models = await saasClient.listModels();
|
||||||
set({ availableModels: models });
|
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) {
|
} catch (err: unknown) {
|
||||||
log.warn('Failed to fetch available models:', err);
|
log.warn('Failed to fetch available models:', err);
|
||||||
// Do not set error state - model fetch failure is non-critical
|
// Do not set error state - model fetch failure is non-critical
|
||||||
|
|||||||
Reference in New Issue
Block a user