From f07d1361c89deb2750fa50ff56bca1fc5b179e9c Mon Sep 17 00:00:00 2001 From: hex2077 Date: Mon, 24 Nov 2025 18:08:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(ProviderPoolManager):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E8=B7=B3=E8=BF=87=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=92=8C=E9=87=8D=E7=BD=AE=E5=81=A5=E5=BA=B7=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加markProviderZero方法用于重置提供商的错误计数和使用计数 当健康检查未实现时跳过检查并自动标记为零状态 优化健康检查返回null时的处理逻辑 --- src/provider-pool-manager.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/provider-pool-manager.js b/src/provider-pool-manager.js index 4ed6058..6282f10 100644 --- a/src/provider-pool-manager.js +++ b/src/provider-pool-manager.js @@ -139,6 +139,26 @@ export class ProviderPoolManager { } } + /** + * Marks a provider as healthy. + * @param {string} providerType - The type of the provider. + * @param {object} providerConfig - The configuration of the provider to mark. + */ + markProviderZero(providerType, providerConfig) { + const pool = this.providerStatus[providerType]; + if (pool) { + const provider = pool.find(p => p.uuid === providerConfig.uuid); + if (provider) { + provider.config.errorCount = 0; // Reset error count on health recovery + provider.config.usageCount = 0; // Reset usage count on health recovery + console.log(`[ProviderPoolManager] Marked provider as zero: ${provider.config.uuid} for type ${providerType}`); + + // 优化1: 使用防抖保存 + this._debouncedSave(providerType); + } + } + } + /** * 禁用指定提供商 * @param {string} providerType - 提供商类型 @@ -198,6 +218,11 @@ export class ProviderPoolManager { try { // Perform actual health check based on provider type const isHealthy = await this._checkProviderHealth(providerType, providerConfig); + if(isHealthy === null){ + console.log(`[ProviderPoolManager] Health check for ${providerConfig.uuid} (${providerType}) skipped: Check not implemented.`); + this.markProviderZero(providerType, providerConfig); + continue; + } if (isHealthy) { if (!providerStatus.config.isHealthy) { @@ -246,7 +271,7 @@ export class ProviderPoolManager { }; const serviceAdapter = getServiceAdapter(tempConfig); if(!providerConfig.checkHealth){ - return true; + return null; } // Determine a suitable model name for health check