fix: only throw NoAvailableProviderError for Kiro providers
This commit is contained in:
parent
369aa59286
commit
7d9f505a15
1 changed files with 12 additions and 4 deletions
|
|
@ -72,12 +72,15 @@ export class NoAvailableProviderError extends Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Provider types that should throw error when no available provider (instead of falling back to main config)
|
||||||
|
const STRICT_POOL_PROVIDERS = ['claude-kiro-oauth'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get API service adapter, considering provider pools
|
* Get API service adapter, considering provider pools
|
||||||
* @param {Object} config - The current request configuration
|
* @param {Object} config - The current request configuration
|
||||||
* @param {string} [requestedModel] - Optional. The model name to filter providers by.
|
* @param {string} [requestedModel] - Optional. The model name to filter providers by.
|
||||||
* @returns {Promise<Object>} The API service adapter
|
* @returns {Promise<Object>} The API service adapter
|
||||||
* @throws {NoAvailableProviderError} If no healthy provider is available in the pool
|
* @throws {NoAvailableProviderError} If no healthy provider is available in the pool (only for strict pool providers)
|
||||||
*/
|
*/
|
||||||
export async function getApiService(config, requestedModel = null) {
|
export async function getApiService(config, requestedModel = null) {
|
||||||
let serviceConfig = config;
|
let serviceConfig = config;
|
||||||
|
|
@ -91,9 +94,14 @@ export async function getApiService(config, requestedModel = null) {
|
||||||
config.uuid = serviceConfig.uuid;
|
config.uuid = serviceConfig.uuid;
|
||||||
console.log(`[API Service] Using pooled configuration for ${config.MODEL_PROVIDER}: ${serviceConfig.uuid}${requestedModel ? ` (model: ${requestedModel})` : ''}`);
|
console.log(`[API Service] Using pooled configuration for ${config.MODEL_PROVIDER}: ${serviceConfig.uuid}${requestedModel ? ` (model: ${requestedModel})` : ''}`);
|
||||||
} else {
|
} else {
|
||||||
// 号池没有可用账号,抛出错误
|
// 号池没有可用账号
|
||||||
console.error(`[API Service] 号池无可用账号: ${config.MODEL_PROVIDER}${requestedModel ? ` (model: ${requestedModel})` : ''}`);
|
// 只有 Kiro 类型的 provider 抛出错误,其他 provider 回退到主配置
|
||||||
throw new NoAvailableProviderError(config.MODEL_PROVIDER, requestedModel);
|
if (STRICT_POOL_PROVIDERS.includes(config.MODEL_PROVIDER)) {
|
||||||
|
console.error(`[API Service] 号池无可用账号: ${config.MODEL_PROVIDER}${requestedModel ? ` (model: ${requestedModel})` : ''}`);
|
||||||
|
throw new NoAvailableProviderError(config.MODEL_PROVIDER, requestedModel);
|
||||||
|
} else {
|
||||||
|
console.warn(`[API Service] No healthy provider found in pool for ${config.MODEL_PROVIDER}${requestedModel ? ` supporting model: ${requestedModel}` : ''}. Falling back to main config.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getServiceAdapter(serviceConfig);
|
return getServiceAdapter(serviceConfig);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue