fix: 完成调度优先级逻辑的处理

This commit is contained in:
KevinLiao
2025-07-30 08:56:42 +08:00
parent 27efca3afb
commit 89f9f48576
4 changed files with 96 additions and 77 deletions

View File

@@ -9,7 +9,7 @@ class UnifiedClaudeScheduler {
}
// 🎯 统一调度Claude账号官方和Console
async selectAccountForApiKey(apiKeyData, sessionHash = null) {
async selectAccountForApiKey(apiKeyData, sessionHash = null, requestedModel = null) {
try {
// 如果API Key绑定了专属账户优先使用
if (apiKeyData.claudeAccountId) {
@@ -41,11 +41,16 @@ class UnifiedClaudeScheduler {
}
}
// 获取所有可用账户
const availableAccounts = await this._getAllAvailableAccounts(apiKeyData);
// 获取所有可用账户(传递请求的模型进行过滤)
const availableAccounts = await this._getAllAvailableAccounts(apiKeyData, requestedModel);
if (availableAccounts.length === 0) {
throw new Error('No available Claude accounts (neither official nor console)');
// 提供更详细的错误信息
if (requestedModel) {
throw new Error(`No available Claude accounts support the requested model: ${requestedModel}`);
} else {
throw new Error('No available Claude accounts (neither official nor console)');
}
}
// 按优先级和最后使用时间排序
@@ -73,7 +78,7 @@ class UnifiedClaudeScheduler {
}
// 📋 获取所有可用账户合并官方和Console
async _getAllAvailableAccounts(apiKeyData) {
async _getAllAvailableAccounts(apiKeyData, requestedModel = null) {
const availableAccounts = [];
// 如果API Key绑定了专属Claude账户优先返回
@@ -130,6 +135,14 @@ class UnifiedClaudeScheduler {
account.status === 'active' &&
account.accountType === 'shared') {
// 检查模型支持(如果有请求的模型)
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
if (!account.supportedModels.includes(requestedModel)) {
logger.info(`🚫 Claude Console account ${account.name} does not support model ${requestedModel}`);
continue;
}
}
// 检查是否被限流
const isRateLimited = await claudeConsoleAccountService.isAccountRateLimited(account.id);
if (!isRateLimited) {