From 76d36f62a6f02361197f0c7a034470fd60c65e93 Mon Sep 17 00:00:00 2001 From: iven Date: Wed, 15 Apr 2026 01:45:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20=E6=A8=A1=E5=9E=8B=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B7=AF=E7=94=B1=20=E2=80=94=20=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=87=AA=E5=8A=A8=E9=80=89=E6=8B=A9=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - saasStore: fetchAvailableModels 处理 currentModel 为空的情况,自动选择第一个可用模型 - connectionStore: SaaS relay 连接成功后同步 currentModel 到 conversationStore - 同时覆盖 Tauri 和浏览器两条 SaaS relay 路径 - 修复首次登录用户需手动选模型的问题 --- desktop/src/store/connectionStore.ts | 21 +++++++++++++++++++++ desktop/src/store/saasStore.ts | 12 ++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/desktop/src/store/connectionStore.ts b/desktop/src/store/connectionStore.ts index e9fa984..b1e242e 100644 --- a/desktop/src/store/connectionStore.ts +++ b/desktop/src/store/connectionStore.ts @@ -546,6 +546,17 @@ export const useConnectionStore = create((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((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; } diff --git a/desktop/src/store/saasStore.ts b/desktop/src/store/saasStore.ts index 1929ea7..8055354 100644 --- a/desktop/src/store/saasStore.ts +++ b/desktop/src/store/saasStore.ts @@ -488,11 +488,15 @@ export const useSaaSStore = create((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);