fix(config): 优化配置错误提示信息

- 未选择 provider 时提示"选择并配置模型提供商"
- 已选择 provider 但未配置 API Key 时提示配置该 provider
This commit is contained in:
2025-12-14 22:44:13 +08:00
parent 07a039001d
commit cacd9914fd
+7 -6
View File
@@ -99,7 +99,8 @@ export function loadConfig(): AgentConfig {
// 从配置文件读取 // 从配置文件读取
const storedConfig = getConfig(); const storedConfig = getConfig();
// 确定最终的 provider // 检查是否配置了 provider
const hasProviderConfig = !!storedConfig.provider;
const finalProvider = storedConfig.provider || 'anthropic'; const finalProvider = storedConfig.provider || 'anthropic';
// 通过 ProviderRegistry 获取 API Key // 通过 ProviderRegistry 获取 API Key
@@ -107,11 +108,11 @@ export function loadConfig(): AgentConfig {
const finalApiKey = resolveApiKey(providerConfig); const finalApiKey = resolveApiKey(providerConfig);
if (!finalApiKey) { if (!finalApiKey) {
throw new ConfigurationError( // 根据是否已选择 provider 给出不同的提示
`未配置 ${finalProvider} 的 API Key,请在 Provider 设置中配置`, const message = hasProviderConfig
finalProvider, ? `请在 Providers 面板配置 ${finalProvider} 的 API Key`
'apiKey' : '请先在 Providers 面板选择并配置一个模型提供商';
); throw new ConfigurationError(message, finalProvider, 'apiKey');
} }
// 确定模型 // 确定模型