fix(ai): preserve last-used model during app session
This commit is contained in:
1 parent
c88fad6bd8
commit
c417e54698
3 files changed
+142
-14
No files matched your search
@@ -944,7 +944,8 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
await migrateToMultiConfig();
|
||||
}
|
||||
|
||||
// 同步活跃状态到默认配置
|
||||
// 重置 activeModel 到默认配置是有意行为——activeModel 是本次运行 (run-scoped) 的末次使用选择,
|
||||
// 应用启动和配置同步下载 (reloadAiConfigs) 两条路径均需丢弃会话内手动切换的模型、回到默认。
|
||||
const defaultConfig = aiConfigs.value.find((c) => c.isDefault) || aiConfigs.value[0];
|
||||
if (defaultConfig) {
|
||||
activeModel.value = { configId: defaultConfig.id, modelId: defaultConfig.model };
|
||||
@@ -956,14 +957,7 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
async function reloadAiConfigs(): Promise<void> {
|
||||
isAiConfigLoaded.value = false;
|
||||
await initAiConfigs();
|
||||
// If the active config was deleted, fall back to the default
|
||||
if (activeModel.value && !aiConfigs.value.find((c) => c.id === activeModel.value!.configId)) {
|
||||
if (aiConfigs.value.length > 0) {
|
||||
activeModel.value = { configId: aiConfigs.value[0].id, modelId: aiConfigs.value[0].model };
|
||||
} else {
|
||||
activeModel.value = null;
|
||||
}
|
||||
}
|
||||
if (aiConfigs.value.length === 0) activeModel.value = null;
|
||||
}
|
||||
|
||||
async function migrateToMultiConfig(): Promise<void> {
|
||||
@@ -1029,6 +1023,11 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
aiConfigs.value.forEach((c) => {
|
||||
c.isDefault = c.id === id;
|
||||
});
|
||||
const config = aiConfigs.value.find((c) => c.id === id);
|
||||
if (config) {
|
||||
// 修改默认配置时丢弃用户手动选择的模型,回到新默认——放在 await 之后确保后端持久化成功才执行
|
||||
activeModel.value = { configId: config.id, modelId: config.model };
|
||||
}
|
||||
}
|
||||
|
||||
function updateActiveModel(model: { configId: string; modelId: string }) {
|
||||
|
||||
Reference in new issue
Block a user