mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
feat(account): 支持 Pro 账号使用 Opus 4.5+ 模型
Opus 4.5 已对 Claude Pro 用户开放,调整账户模型限制逻辑: - Pro 账号:支持 Opus 4.5+,不支持历史版本 (3.x/4.0/4.1) - Free 账号:不支持任何 Opus 模型 - Max 账号:支持所有 Opus 版本 修改内容: - 新增 isOpus45OrNewer() 函数用于精确识别模型版本 - 更新 claudeAccountService.js 中的账户选择逻辑 - 更新 unifiedClaudeScheduler.js 中的模型支持检查 - 新增测试脚本验证官方模型名称识别 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ const {
|
||||
const tokenRefreshService = require('./tokenRefreshService')
|
||||
const LRUCache = require('../utils/lruCache')
|
||||
const { formatDateWithTimezone, getISOStringWithTimezone } = require('../utils/dateHelper')
|
||||
const { isOpus45OrNewer } = require('../utils/modelHelper')
|
||||
|
||||
class ClaudeAccountService {
|
||||
constructor() {
|
||||
@@ -852,22 +853,32 @@ class ClaudeAccountService {
|
||||
!this.isSubscriptionExpired(account)
|
||||
)
|
||||
|
||||
// 如果请求的是 Opus 模型,过滤掉 Pro 和 Free 账号
|
||||
// 如果请求的是 Opus 模型,根据账号类型和模型版本过滤
|
||||
if (modelName && modelName.toLowerCase().includes('opus')) {
|
||||
const isNewOpus = isOpus45OrNewer(modelName)
|
||||
|
||||
activeAccounts = activeAccounts.filter((account) => {
|
||||
// 检查账号的订阅信息
|
||||
if (account.subscriptionInfo) {
|
||||
try {
|
||||
const info = JSON.parse(account.subscriptionInfo)
|
||||
// Pro 和 Free 账号不支持 Opus
|
||||
|
||||
// Free 账号不支持任何 Opus 模型
|
||||
if (info.accountType === 'claude_free' || info.accountType === 'free') {
|
||||
return false
|
||||
}
|
||||
|
||||
// Pro 账号:仅支持 Opus 4.5+
|
||||
if (info.hasClaudePro === true && info.hasClaudeMax !== true) {
|
||||
return false // Claude Pro 不支持 Opus
|
||||
return isNewOpus // 仅新版 Opus 支持
|
||||
}
|
||||
if (info.accountType === 'claude_pro' || info.accountType === 'claude_free') {
|
||||
return false // 明确标记为 Pro 或 Free 的账号不支持
|
||||
if (info.accountType === 'claude_pro') {
|
||||
return isNewOpus // 仅新版 Opus 支持
|
||||
}
|
||||
|
||||
// Max 账号支持所有 Opus 版本
|
||||
return true
|
||||
} catch (e) {
|
||||
// 解析失败,假设为旧数据,默认支持(兼容旧数据为 Max)
|
||||
// 解析失败,假设为旧数据(Max),默认支持
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -876,7 +887,8 @@ class ClaudeAccountService {
|
||||
})
|
||||
|
||||
if (activeAccounts.length === 0) {
|
||||
throw new Error('No Claude accounts available that support Opus model')
|
||||
const modelDesc = isNewOpus ? 'Opus 4.5+' : 'legacy Opus (requires Max subscription)'
|
||||
throw new Error(`No Claude accounts available that support ${modelDesc} model`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -970,22 +982,32 @@ class ClaudeAccountService {
|
||||
!this.isSubscriptionExpired(account)
|
||||
)
|
||||
|
||||
// 如果请求的是 Opus 模型,过滤掉 Pro 和 Free 账号
|
||||
// 如果请求的是 Opus 模型,根据账号类型和模型版本过滤
|
||||
if (modelName && modelName.toLowerCase().includes('opus')) {
|
||||
const isNewOpus = isOpus45OrNewer(modelName)
|
||||
|
||||
sharedAccounts = sharedAccounts.filter((account) => {
|
||||
// 检查账号的订阅信息
|
||||
if (account.subscriptionInfo) {
|
||||
try {
|
||||
const info = JSON.parse(account.subscriptionInfo)
|
||||
// Pro 和 Free 账号不支持 Opus
|
||||
|
||||
// Free 账号不支持任何 Opus 模型
|
||||
if (info.accountType === 'claude_free' || info.accountType === 'free') {
|
||||
return false
|
||||
}
|
||||
|
||||
// Pro 账号:仅支持 Opus 4.5+
|
||||
if (info.hasClaudePro === true && info.hasClaudeMax !== true) {
|
||||
return false // Claude Pro 不支持 Opus
|
||||
return isNewOpus // 仅新版 Opus 支持
|
||||
}
|
||||
if (info.accountType === 'claude_pro' || info.accountType === 'claude_free') {
|
||||
return false // 明确标记为 Pro 或 Free 的账号不支持
|
||||
if (info.accountType === 'claude_pro') {
|
||||
return isNewOpus // 仅新版 Opus 支持
|
||||
}
|
||||
|
||||
// Max 账号支持所有 Opus 版本
|
||||
return true
|
||||
} catch (e) {
|
||||
// 解析失败,假设为旧数据,默认支持(兼容旧数据为 Max)
|
||||
// 解析失败,假设为旧数据(Max),默认支持
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -994,7 +1016,8 @@ class ClaudeAccountService {
|
||||
})
|
||||
|
||||
if (sharedAccounts.length === 0) {
|
||||
throw new Error('No shared Claude accounts available that support Opus model')
|
||||
const modelDesc = isNewOpus ? 'Opus 4.5+' : 'legacy Opus (requires Max subscription)'
|
||||
throw new Error(`No shared Claude accounts available that support ${modelDesc} model`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ const ccrAccountService = require('./ccrAccountService')
|
||||
const accountGroupService = require('./accountGroupService')
|
||||
const redis = require('../models/redis')
|
||||
const logger = require('../utils/logger')
|
||||
const { parseVendorPrefixedModel } = require('../utils/modelHelper')
|
||||
const { parseVendorPrefixedModel, isOpus45OrNewer } = require('../utils/modelHelper')
|
||||
|
||||
class UnifiedClaudeScheduler {
|
||||
constructor() {
|
||||
@@ -48,6 +48,8 @@ class UnifiedClaudeScheduler {
|
||||
|
||||
// 2. Opus 模型的订阅级别检查
|
||||
if (requestedModel.toLowerCase().includes('opus')) {
|
||||
const isNewOpus = isOpus45OrNewer(requestedModel)
|
||||
|
||||
if (account.subscriptionInfo) {
|
||||
try {
|
||||
const info =
|
||||
@@ -55,21 +57,39 @@ class UnifiedClaudeScheduler {
|
||||
? JSON.parse(account.subscriptionInfo)
|
||||
: account.subscriptionInfo
|
||||
|
||||
// Pro 和 Free 账号不支持 Opus
|
||||
// Free 账号不支持任何 Opus 模型
|
||||
if (info.accountType === 'claude_free' || info.accountType === 'free') {
|
||||
logger.info(
|
||||
`🚫 Claude account ${account.name} (Free) does not support Opus model${context ? ` ${context}` : ''}`
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
// Pro 账号:仅支持 Opus 4.5+
|
||||
if (info.hasClaudePro === true && info.hasClaudeMax !== true) {
|
||||
logger.info(
|
||||
`🚫 Claude account ${account.name} (Pro) does not support Opus model${context ? ` ${context}` : ''}`
|
||||
)
|
||||
return false
|
||||
if (!isNewOpus) {
|
||||
logger.info(
|
||||
`🚫 Claude account ${account.name} (Pro) does not support legacy Opus model${context ? ` ${context}` : ''}`
|
||||
)
|
||||
return false
|
||||
}
|
||||
// Opus 4.5+ 支持
|
||||
return true
|
||||
}
|
||||
if (info.accountType === 'claude_pro' || info.accountType === 'claude_free') {
|
||||
logger.info(
|
||||
`🚫 Claude account ${account.name} (${info.accountType}) does not support Opus model${context ? ` ${context}` : ''}`
|
||||
)
|
||||
return false
|
||||
if (info.accountType === 'claude_pro') {
|
||||
if (!isNewOpus) {
|
||||
logger.info(
|
||||
`🚫 Claude account ${account.name} (Pro) does not support legacy Opus model${context ? ` ${context}` : ''}`
|
||||
)
|
||||
return false
|
||||
}
|
||||
// Opus 4.5+ 支持
|
||||
return true
|
||||
}
|
||||
|
||||
// Max 账号支持所有 Opus 版本
|
||||
} catch (e) {
|
||||
// 解析失败,假设为旧数据,默认支持(兼容旧数据为 Max)
|
||||
// 解析失败,假设为旧数据(Max),默认支持
|
||||
logger.debug(
|
||||
`Account ${account.name} has invalid subscriptionInfo${context ? ` ${context}` : ''}, assuming Max`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user