fix: 切换 Provider 后不生效 + Ollama 模式 API Key 输入框仍显示
1. reloadAdapter 加 try-catch: 配置中间状态 createAdapter 抛异常时不阻断 IPC, 记录日志即可 2. sendMessage 时兜底调用 reloadAdapter: 确保每次发消息用最新 adapter, 不依赖 config:set 的逐字段 reload 3. Ollama 模式隐藏 API Key 输入框, 切换到 Ollama 时自动清空旧 key 4. 切换 Provider 时自动填充默认 URL(仅旧 URL 为默认值或空时)
This commit is contained in:
+14
-9
@@ -230,15 +230,20 @@ async function initialize(): Promise<void> {
|
||||
|
||||
// ===== 热重载 Adapter 回调(设置变更时触发)=====
|
||||
const reloadAdapter = () => {
|
||||
const newAdapter = createAdapter();
|
||||
agentLoop.setAdapter(newAdapter);
|
||||
// Provider 切换时同步 contextLength:仅 Ollama 使用 numCtx 作为有效上下文窗口
|
||||
const provider = configService.get<string>('llm.provider') ?? '';
|
||||
if (provider === 'ollama') {
|
||||
const numCtx = configService.get<number>('ollama.numCtx');
|
||||
agentLoop.updateConfig({ contextLength: numCtx ?? undefined });
|
||||
} else {
|
||||
agentLoop.updateConfig({ contextLength: undefined });
|
||||
try {
|
||||
const newAdapter = createAdapter();
|
||||
agentLoop.setAdapter(newAdapter);
|
||||
// Provider 切换时同步 contextLength:仅 Ollama 使用 numCtx 作为有效上下文窗口
|
||||
const provider = configService.get<string>('llm.provider') ?? '';
|
||||
if (provider === 'ollama') {
|
||||
const numCtx = configService.get<number>('ollama.numCtx');
|
||||
agentLoop.updateConfig({ contextLength: numCtx ?? undefined });
|
||||
} else {
|
||||
agentLoop.updateConfig({ contextLength: undefined });
|
||||
}
|
||||
log.info(`[CONFIG] Adapter reloaded: provider=${provider}`);
|
||||
} catch (err) {
|
||||
log.error(`[CONFIG] Failed to reload adapter: ${(err as Error).message}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user