fix(desktop): P0-1 验证 SaaS 模型选择 — 防止残留模型 ID 导致请求失败
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
Tauri 桌面端通过 SaaS Token Pool 中转访问 LLM,模型列表由 SaaS 后端 动态提供。之前的实现直接使用 conversationStore 持久化的 currentModel, 可能在切换连接模式后使用过期的模型 ID,导致 relay 请求失败。 修复: - Tauri 路径:用 SaaS relayModels 的 id+alias 构建 validModelIds 集合, preferredModel 仅在集合内时才使用,否则回退到第一个可用模型 - 浏览器路径:同样验证 currentModel 在 SaaS 模型列表中才使用 后端 cache.resolve_model() 别名解析作为二道防线保留。
This commit is contained in:
@@ -501,7 +501,14 @@ export const useConnectionStore = create<ConnectionStore>((set, get) => {
|
||||
if (!fallbackId) {
|
||||
throw new Error('可用模型数据格式异常,请刷新页面重试');
|
||||
}
|
||||
const modelToUse = preferredModel || fallbackId;
|
||||
// 验证 preferredModel 是否在 SaaS 可用模型列表中
|
||||
// 避免使用上一次非 SaaS 会话残留的模型 ID
|
||||
const validModelIds = new Set(
|
||||
relayModels.flatMap(m => [m.id, ...(m.alias ? [m.alias] : [])])
|
||||
);
|
||||
const modelToUse = (preferredModel && validModelIds.has(preferredModel))
|
||||
? preferredModel
|
||||
: fallbackId;
|
||||
|
||||
kernelClient.setConfig({
|
||||
provider: 'custom',
|
||||
@@ -540,12 +547,16 @@ export const useConnectionStore = create<ConnectionStore>((set, get) => {
|
||||
if (!fallbackModelId) {
|
||||
throw new Error('可用模型数据格式异常,请刷新页面重试');
|
||||
}
|
||||
// 浏览器路径也验证模型是否在 SaaS 列表中
|
||||
const validBrowserModelIds = new Set(
|
||||
relayModels.flatMap(m => [m.id, ...(m.alias ? [m.alias] : [])])
|
||||
);
|
||||
const relayClient = createSaaSRelayGatewayClient(session.saasUrl, () => {
|
||||
// 每次调用时读取 conversationStore 的 currentModel,fallback 到第一个可用模型
|
||||
try {
|
||||
const { useConversationStore } = require('./chat/conversationStore');
|
||||
const current = useConversationStore.getState().currentModel;
|
||||
return current || fallbackModelId;
|
||||
return (current && validBrowserModelIds.has(current)) ? current : fallbackModelId;
|
||||
} catch {
|
||||
return fallbackModelId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user