refactor(config): 移除环境变量依赖,统一使用 Provider 配置系统

- 移除 .env.example 文件
- 简化 resolveApiKey 函数,只从配置文件读取 API Key
- 重构 loadConfig/loadVisionConfig/loadSummaryConfig 使用 ProviderRegistry
- 更新测试以 mock Provider 系统
This commit is contained in:
2025-12-14 21:29:36 +08:00
parent c9d0cbce5b
commit 9e011476c8
6 changed files with 143 additions and 451 deletions
+4 -4
View File
@@ -126,7 +126,7 @@ export class ProviderRegistry {
this.ensureInitialized();
return Array.from(this.providers.entries()).map(([id, provider]) => {
const config = this.configs.get(id);
const apiKey = resolveApiKey(config, provider.info.apiKeyEnvVar);
const apiKey = resolveApiKey(config);
const customModels = config?.customModels ?? [];
return {
@@ -165,7 +165,7 @@ export class ProviderRegistry {
if (!provider) return undefined;
const config = this.configs.get(id);
const apiKey = resolveApiKey(config, provider.info.apiKeyEnvVar);
const apiKey = resolveApiKey(config);
return {
id,
@@ -355,7 +355,7 @@ export class ProviderRegistry {
}
const config = this.configs.get(providerId);
const resolvedApiKey = apiKey ?? resolveApiKey(config, provider.info.apiKeyEnvVar);
const resolvedApiKey = apiKey ?? resolveApiKey(config);
if (!resolvedApiKey && !provider.info.baseUrl?.includes('localhost')) {
return { success: false, error: 'API key not configured' };
@@ -390,7 +390,7 @@ export class ProviderRegistry {
}
const config = this.configs.get(providerId);
const apiKey = options?.apiKey ?? resolveApiKey(config, provider.info.apiKeyEnvVar);
const apiKey = options?.apiKey ?? resolveApiKey(config);
const baseUrl = options?.baseUrl ?? config?.baseUrl ?? provider.info.baseUrl;
if (!apiKey) {