fix(desktop): 模型自动路由 — 首次登录自动选择可用模型
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
- saasStore: fetchAvailableModels 处理 currentModel 为空的情况,自动选择第一个可用模型 - connectionStore: SaaS relay 连接成功后同步 currentModel 到 conversationStore - 同时覆盖 Tauri 和浏览器两条 SaaS relay 路径 - 修复首次登录用户需手动选模型的问题
This commit is contained in:
@@ -546,6 +546,17 @@ export const useConnectionStore = create<ConnectionStore>((set, get) => {
|
||||
await kernelClient.connect();
|
||||
|
||||
set({ gatewayVersion: 'saas-relay', connectionState: 'connected' });
|
||||
|
||||
// 同步 modelToUse 到 conversationStore(首次登录时 currentModel 可能为空)
|
||||
try {
|
||||
const cs = await loadConversationStore();
|
||||
const currentInStore = cs?.useConversationStore.getState().currentModel;
|
||||
if (!currentInStore && modelToUse) {
|
||||
cs?.useConversationStore.getState().setCurrentModel(modelToUse);
|
||||
log.info(`Synced currentModel after SaaS relay connect: ${modelToUse}`);
|
||||
}
|
||||
} catch { /* non-critical */ }
|
||||
|
||||
log.debug('Connected via SaaS relay (kernel backend):', {
|
||||
model: modelToUse,
|
||||
baseUrl: `${session.saasUrl}/api/v1/relay`,
|
||||
@@ -578,6 +589,16 @@ export const useConnectionStore = create<ConnectionStore>((set, get) => {
|
||||
initializeStores();
|
||||
|
||||
log.debug('Connected to SaaS relay (browser mode)', { relayModel: fallbackModelId });
|
||||
|
||||
// 同步 currentModel 到 conversationStore(浏览器路径)
|
||||
try {
|
||||
const cs = await loadConversationStore();
|
||||
const currentInStore = cs?.useConversationStore.getState().currentModel;
|
||||
if (!currentInStore && fallbackModelId) {
|
||||
cs?.useConversationStore.getState().setCurrentModel(fallbackModelId);
|
||||
log.info(`Synced currentModel after browser SaaS relay connect: ${fallbackModelId}`);
|
||||
}
|
||||
} catch { /* non-critical */ }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -488,11 +488,15 @@ export const useSaaSStore = create<SaaSStore>((set, get) => {
|
||||
const { useConversationStore } = await import('./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;
|
||||
const firstModel = models[0];
|
||||
const fallbackId = firstModel.alias || firstModel.id;
|
||||
if (!current || !modelIds.includes(current)) {
|
||||
useConversationStore.getState().setCurrentModel(fallbackId);
|
||||
log.info(`Synced currentModel: ${current} not available, switched to ${fallbackId}`);
|
||||
if (current) {
|
||||
log.info(`Synced currentModel: ${current} not available, switched to ${fallbackId}`);
|
||||
} else {
|
||||
log.info(`Auto-selected first available model: ${fallbackId}`);
|
||||
}
|
||||
}
|
||||
} catch (syncErr) {
|
||||
log.warn('Failed to sync currentModel after fetching models:', syncErr);
|
||||
|
||||
Reference in New Issue
Block a user