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
+9 -21
View File
@@ -7,34 +7,25 @@
import { existsSync } from 'node:fs';
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { homedir } from 'node:os';
import type { ProvidersConfigFile, CustomProviderDefinition, ProviderConfig } from './types.js';
/** 配置目录名 */
const CONFIG_DIR = '.ai-terminal-assistant';
import { getConfigDir as getGlobalConfigDir } from '../constants/paths.js';
/** 配置文件名 */
const CONFIG_FILE = 'providers.json';
/**
* 获取配置目录路径
*/
export function getConfigDir(workdir?: string): string {
return workdir ? join(workdir, CONFIG_DIR) : join(homedir(), CONFIG_DIR);
}
/**
* 获取配置文件路径
* 始终使用全局配置目录 ~/.ai-terminal-assistant/
*/
export function getConfigPath(workdir?: string): string {
return join(getConfigDir(workdir), CONFIG_FILE);
export function getConfigPath(): string {
return join(getGlobalConfigDir(), CONFIG_FILE);
}
/**
* 加载提供商配置
*/
export async function loadProvidersConfig(workdir?: string): Promise<ProvidersConfigFile> {
const configPath = getConfigPath(workdir);
export async function loadProvidersConfig(): Promise<ProvidersConfigFile> {
const configPath = getConfigPath();
if (!existsSync(configPath)) {
return { providers: {}, configs: {} };
@@ -56,12 +47,9 @@ export async function loadProvidersConfig(workdir?: string): Promise<ProvidersCo
/**
* 保存提供商配置
*/
export async function saveProvidersConfig(
config: ProvidersConfigFile,
workdir?: string
): Promise<void> {
const configDir = getConfigDir(workdir);
const configPath = getConfigPath(workdir);
export async function saveProvidersConfig(config: ProvidersConfigFile): Promise<void> {
const configDir = getGlobalConfigDir();
const configPath = getConfigPath();
// 确保目录存在
if (!existsSync(configDir)) {