refactor(core,server): 简化配置加载,移除 workdir 参数

Provider 和 Agent 配置统一从全局目录加载,无需传递 workdir:
- ProviderRegistry.init() 不再需要 workdir 参数
- AgentRegistry.init() 不再需要 workdir 参数
- 配置文件路径统一使用 ~/.ai-terminal-assistant/
This commit is contained in:
2025-12-16 10:23:28 +08:00
parent 6a28c98789
commit a6c1e792fa
7 changed files with 32 additions and 55 deletions
+7 -12
View File
@@ -46,9 +46,6 @@ export class ProviderRegistry {
/** 是否已完全初始化(包括用户配置) */
private fullyInitialized = false;
/** 工作目录 */
private workdir?: string;
constructor() {
// 同步初始化内置提供商(不需要异步加载)
this.initBuiltinProviders();
@@ -70,13 +67,11 @@ export class ProviderRegistry {
* 完整初始化 Registry
* 加载用户配置(自定义提供商和配置)
*/
async init(workdir?: string): Promise<void> {
async init(): Promise<void> {
if (this.fullyInitialized) return;
this.workdir = workdir;
// 加载用户配置
const config = await loadProvidersConfig(workdir);
// 加载用户配置(从 ~/.ai-terminal-assistant/providers.json
const config = await loadProvidersConfig();
// 加载自定义提供商
if (config.providers) {
@@ -414,7 +409,7 @@ export class ProviderRegistry {
/**
* 保存配置到文件
*/
async saveConfig(workdir?: string): Promise<void> {
async saveConfig(): Promise<void> {
this.ensureInitialized();
const config = {
@@ -422,13 +417,13 @@ export class ProviderRegistry {
configs: Object.fromEntries(this.configs),
};
await saveProvidersConfig(config, workdir ?? this.workdir);
await saveProvidersConfig(config);
}
/**
* 重新加载配置
*/
async reloadConfig(workdir?: string): Promise<void> {
async reloadConfig(): Promise<void> {
this.fullyInitialized = false;
this.configs.clear();
this.customDefinitions.clear();
@@ -440,7 +435,7 @@ export class ProviderRegistry {
}
}
await this.init(workdir ?? this.workdir);
await this.init();
}
}