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

- saasStore: fetchAvailableModels 处理 currentModel 为空的情况,自动选择第一个可用模型
- connectionStore: SaaS relay 连接成功后同步 currentModel 到 conversationStore
- 同时覆盖 Tauri 和浏览器两条 SaaS relay 路径
- 修复首次登录用户需手动选模型的问题
This commit is contained in:
iven
2026-04-15 01:45:36 +08:00
parent be2a136392
commit 76d36f62a6
2 changed files with 29 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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);