设置面板新增子代理默认模型选择器

- 向量记忆引擎下方新增「子代理默认模型」下拉框
- 留空则跟随当前模型,选择后所有 spawn_task 默认使用该模型
- spawn_task 工具仍支持单次指定 model 参数覆盖默认值
This commit is contained in:
thzxx
2026-06-05 10:56:08 +08:00
parent da71020003
commit f4a92fc40f
3 changed files with 50 additions and 1 deletions
+42
View File
@@ -257,6 +257,7 @@ export function openSettingsModal(): void {
updateConnectionInfo();
updateRunningModels();
populateMemoryEmbedModels();
populateSubAgentModels();
updateMemoryVectorStatus();
}
@@ -365,6 +366,47 @@ async function populateMemoryEmbedModels(): Promise<void> {
}
}
async function populateSubAgentModels(): Promise<void> {
const select = document.querySelector('#selectSubAgentModel') as HTMLSelectElement;
if (!select) return;
const api = state.get<OllamaAPI>(KEYS.API);
if (!api) return;
try {
const data = await api.listModels();
if (!data.models?.length) return;
// 保留第一个 "跟随当前模型" 选项,追加所有模型
while (select.options.length > 1) select.remove(1);
data.models
.sort((a, b) => (a.name < b.name ? -1 : 1))
.forEach(m => {
const opt = document.createElement('option');
opt.value = m.name;
opt.textContent = m.name;
select.appendChild(opt);
});
// 恢复已保存的选择
const db = state.get<ChatDB | null>(KEYS.DB);
if (db) {
const saved = await db.getSetting('subAgentModel', '');
if (saved) select.value = saved;
}
} catch (err) {
logWarn('加载子代理模型列表失败', (err as Error).message);
}
}
// 子代理模型设置保存
document.querySelector('#selectSubAgentModel')?.addEventListener('change', async () => {
const db = state.get<ChatDB | null>(KEYS.DB);
if (!db) return;
const val = (document.querySelector('#selectSubAgentModel') as HTMLSelectElement).value;
await db.saveSetting('subAgentModel', val);
logSetting('子代理默认模型', val || '跟随当前模型');
});
function updateMemoryVectorStatus(): void {
const statusEl = document.querySelector('#memoryVectorStatus');
if (!statusEl) return;