refactor(core): 统一配置系统,移除 config.json

- 移除 config.json,所有配置统一从 agents.json 和 providers.json 读取
- config-loader.ts 从全局目录 ~/.ai-terminal-assistant/ 加载配置
- loadConfig() 从 agentRegistry.getGlobalConfig() 获取 defaults.model
- 添加 loadVisionConfig() 支持 Vision 模型配置
- Tavily API Key 仅从环境变量读取
- UI AgentDefaultsEditor 添加 Vision 模型配置界面
- 更新相关测试
This commit is contained in:
2025-12-16 00:33:29 +08:00
parent 76b1ae1573
commit 9376887995
14 changed files with 414 additions and 643 deletions
+9 -4
View File
@@ -12,6 +12,7 @@ import { getSessionManager } from '../session/manager.js';
import { broadcastToSession } from '../ws.js';
import { emitStatusEvent, emitLogEvent } from '../sse.js';
import { createServerPermissionCallback, setSessionAutoApprove } from '../permission/handler.js';
import { getConfig } from '../routes/config.js';
// ============================================================================
// Core 模块接口定义(避免直接依赖 @ai-assistant/core 类型)
@@ -220,18 +221,22 @@ export async function initCore(): Promise<boolean> {
return false;
}
// 获取服务器配置的工作目录
const config = getConfig();
const workdir = config.workdir;
// 初始化 ProviderRegistry(加载用户配置)
const providerRegistry = core.getProviderRegistry();
if (!providerRegistry.isInitialized()) {
await providerRegistry.init();
console.log('[Agent] ProviderRegistry initialized');
await providerRegistry.init(workdir);
console.log('[Agent] ProviderRegistry initialized with workdir:', workdir);
}
// 初始化 AgentRegistry(加载用户自定义 Agent 配置)
const agentRegistry = core.agentRegistry;
if (!agentRegistry.isInitialized()) {
await agentRegistry.init(process.cwd());
console.log('[Agent] AgentRegistry initialized');
await agentRegistry.init(workdir);
console.log('[Agent] AgentRegistry initialized with workdir:', workdir);
}
coreModule = core;
+6 -5
View File
@@ -5,6 +5,7 @@
*/
import { Hono } from 'hono';
import { getConfig } from './config.js';
// Types from core - dynamically import to avoid build dependency
interface ProviderListItem {
@@ -246,7 +247,7 @@ providersRouter.post('/', async (c) => {
const registry = core.getProviderRegistry();
registry.registerCustom(body);
await registry.saveConfig();
await registry.saveConfig(getConfig().workdir);
return c.json({
success: true,
@@ -284,7 +285,7 @@ providersRouter.put('/:id', async (c) => {
}
registry.setConfig(id, { ...body, id });
await registry.saveConfig();
await registry.saveConfig(getConfig().workdir);
return c.json({
success: true,
@@ -320,7 +321,7 @@ providersRouter.delete('/:id', async (c) => {
return c.json({ success: false, error: `Provider not found: ${id}` }, 404);
}
await registry.saveConfig();
await registry.saveConfig(getConfig().workdir);
return c.json({
success: true,
@@ -364,7 +365,7 @@ providersRouter.post('/:id/models', async (c) => {
const registry = core.getProviderRegistry();
registry.addCustomModel(providerId, body);
await registry.saveConfig();
await registry.saveConfig(getConfig().workdir);
return c.json({
success: true,
@@ -407,7 +408,7 @@ providersRouter.delete('/:id/models/:modelId', async (c) => {
);
}
await registry.saveConfig();
await registry.saveConfig(getConfig().workdir);
return c.json({
success: true,