fix(config): 优化配置错误提示信息
- 未选择 provider 时提示"选择并配置模型提供商" - 已选择 provider 但未配置 API Key 时提示配置该 provider
This commit is contained in:
@@ -99,7 +99,8 @@ export function loadConfig(): AgentConfig {
|
||||
// 从配置文件读取
|
||||
const storedConfig = getConfig();
|
||||
|
||||
// 确定最终的 provider
|
||||
// 检查是否配置了 provider
|
||||
const hasProviderConfig = !!storedConfig.provider;
|
||||
const finalProvider = storedConfig.provider || 'anthropic';
|
||||
|
||||
// 通过 ProviderRegistry 获取 API Key
|
||||
@@ -107,11 +108,11 @@ export function loadConfig(): AgentConfig {
|
||||
const finalApiKey = resolveApiKey(providerConfig);
|
||||
|
||||
if (!finalApiKey) {
|
||||
throw new ConfigurationError(
|
||||
`未配置 ${finalProvider} 的 API Key,请在 Provider 设置中配置`,
|
||||
finalProvider,
|
||||
'apiKey'
|
||||
);
|
||||
// 根据是否已选择 provider 给出不同的提示
|
||||
const message = hasProviderConfig
|
||||
? `请在 Providers 面板配置 ${finalProvider} 的 API Key`
|
||||
: '请先在 Providers 面板选择并配置一个模型提供商';
|
||||
throw new ConfigurationError(message, finalProvider, 'apiKey');
|
||||
}
|
||||
|
||||
// 确定模型
|
||||
|
||||
Reference in New Issue
Block a user