mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
feat: 新增 Claude Console 账户限流机制开关
This commit is contained in:
@@ -307,6 +307,14 @@ class ClaudeConsoleAccountService {
|
|||||||
throw new Error('Account not found')
|
throw new Error('Account not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果限流时间设置为 0,表示不启用限流机制,直接返回
|
||||||
|
if (account.rateLimitDuration === 0) {
|
||||||
|
logger.info(
|
||||||
|
`ℹ️ Claude Console account ${account.name} (${accountId}) has rate limiting disabled, skipping rate limit`
|
||||||
|
)
|
||||||
|
return { success: true, skipped: true }
|
||||||
|
}
|
||||||
|
|
||||||
const updates = {
|
const updates = {
|
||||||
rateLimitedAt: new Date().toISOString(),
|
rateLimitedAt: new Date().toISOString(),
|
||||||
rateLimitStatus: 'limited'
|
rateLimitStatus: 'limited'
|
||||||
@@ -351,6 +359,11 @@ class ClaudeConsoleAccountService {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果限流时间设置为 0,表示不启用限流机制
|
||||||
|
if (account.rateLimitDuration === 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (account.rateLimitStatus === 'limited' && account.rateLimitedAt) {
|
if (account.rateLimitStatus === 'limited' && account.rateLimitedAt) {
|
||||||
const rateLimitedAt = new Date(account.rateLimitedAt)
|
const rateLimitedAt = new Date(account.rateLimitedAt)
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|||||||
@@ -350,19 +350,34 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
<label class="mb-3 block text-sm font-semibold text-gray-700">限流机制</label>
|
||||||
>限流时间 (分钟)</label
|
<div class="mb-3">
|
||||||
>
|
<label class="inline-flex cursor-pointer items-center">
|
||||||
<input
|
<input
|
||||||
v-model.number="form.rateLimitDuration"
|
v-model="form.enableRateLimit"
|
||||||
class="form-input w-full"
|
type="checkbox"
|
||||||
min="1"
|
class="mr-2 rounded border-gray-300 text-blue-600 focus:border-blue-500 focus:ring focus:ring-blue-200"
|
||||||
placeholder="默认60分钟"
|
/>
|
||||||
type="number"
|
<span class="text-sm text-gray-700">启用限流机制</span>
|
||||||
/>
|
</label>
|
||||||
<p class="mt-1 text-xs text-gray-500">
|
<p class="mt-1 text-xs text-gray-500">
|
||||||
当账号返回429错误时,暂停调度的时间(分钟)
|
启用后,当账号返回429错误时将暂停调度一段时间
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="form.enableRateLimit">
|
||||||
|
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
||||||
|
>限流时间 (分钟)</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model.number="form.rateLimitDuration"
|
||||||
|
class="form-input w-full"
|
||||||
|
min="1"
|
||||||
|
placeholder="默认60分钟"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">账号被限流后暂停调度的时间(分钟)</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -509,19 +524,34 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
<label class="mb-3 block text-sm font-semibold text-gray-700">限流机制</label>
|
||||||
>限流时间 (分钟)</label
|
<div class="mb-3">
|
||||||
>
|
<label class="inline-flex cursor-pointer items-center">
|
||||||
<input
|
<input
|
||||||
v-model.number="form.rateLimitDuration"
|
v-model="form.enableRateLimit"
|
||||||
class="form-input w-full"
|
type="checkbox"
|
||||||
min="1"
|
class="mr-2 rounded border-gray-300 text-blue-600 focus:border-blue-500 focus:ring focus:ring-blue-200"
|
||||||
placeholder="默认60分钟"
|
/>
|
||||||
type="number"
|
<span class="text-sm text-gray-700">启用限流机制</span>
|
||||||
/>
|
</label>
|
||||||
<p class="mt-1 text-xs text-gray-500">
|
<p class="mt-1 text-xs text-gray-500">
|
||||||
当账号返回429错误时,暂停调度的时间(分钟)
|
启用后,当账号返回429错误时将暂停调度一段时间
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="form.enableRateLimit">
|
||||||
|
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
||||||
|
>限流时间 (分钟)</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model.number="form.rateLimitDuration"
|
||||||
|
class="form-input w-full"
|
||||||
|
min="1"
|
||||||
|
placeholder="默认60分钟"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">账号被限流后暂停调度的时间(分钟)</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1080,13 +1110,33 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="mb-3 block text-sm font-semibold text-gray-700">限流时间 (分钟)</label>
|
<label class="mb-3 block text-sm font-semibold text-gray-700">限流机制</label>
|
||||||
<input
|
<div class="mb-3">
|
||||||
v-model.number="form.rateLimitDuration"
|
<label class="inline-flex cursor-pointer items-center">
|
||||||
class="form-input w-full"
|
<input
|
||||||
min="1"
|
v-model="form.enableRateLimit"
|
||||||
type="number"
|
type="checkbox"
|
||||||
/>
|
class="mr-2 rounded border-gray-300 text-blue-600 focus:border-blue-500 focus:ring focus:ring-blue-200"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-700">启用限流机制</span>
|
||||||
|
</label>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">
|
||||||
|
启用后,当账号返回429错误时将暂停调度一段时间
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="form.enableRateLimit">
|
||||||
|
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
||||||
|
>限流时间 (分钟)</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model.number="form.rateLimitDuration"
|
||||||
|
class="form-input w-full"
|
||||||
|
min="1"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">账号被限流后暂停调度的时间(分钟)</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1179,13 +1229,33 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="mb-3 block text-sm font-semibold text-gray-700">限流时间 (分钟)</label>
|
<label class="mb-3 block text-sm font-semibold text-gray-700">限流机制</label>
|
||||||
<input
|
<div class="mb-3">
|
||||||
v-model.number="form.rateLimitDuration"
|
<label class="inline-flex cursor-pointer items-center">
|
||||||
class="form-input w-full"
|
<input
|
||||||
min="1"
|
v-model="form.enableRateLimit"
|
||||||
type="number"
|
type="checkbox"
|
||||||
/>
|
class="mr-2 rounded border-gray-300 text-blue-600 focus:border-blue-500 focus:ring focus:ring-blue-200"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-gray-700">启用限流机制</span>
|
||||||
|
</label>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">
|
||||||
|
启用后,当账号返回429错误时将暂停调度一段时间
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="form.enableRateLimit">
|
||||||
|
<label class="mb-3 block text-sm font-semibold text-gray-700"
|
||||||
|
>限流时间 (分钟)</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model.number="form.rateLimitDuration"
|
||||||
|
class="form-input w-full"
|
||||||
|
min="1"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">账号被限流后暂停调度的时间(分钟)</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1373,6 +1443,8 @@ const form = ref({
|
|||||||
return ''
|
return ''
|
||||||
})(),
|
})(),
|
||||||
userAgent: props.account?.userAgent || '',
|
userAgent: props.account?.userAgent || '',
|
||||||
|
enableRateLimit:
|
||||||
|
props.account?.rateLimitDuration && props.account?.rateLimitDuration > 0 ? true : false,
|
||||||
rateLimitDuration: props.account?.rateLimitDuration || 60,
|
rateLimitDuration: props.account?.rateLimitDuration || 60,
|
||||||
// Bedrock 特定字段
|
// Bedrock 特定字段
|
||||||
accessKeyId: props.account?.accessKeyId || '',
|
accessKeyId: props.account?.accessKeyId || '',
|
||||||
@@ -1809,7 +1881,8 @@ const createAccount = async () => {
|
|||||||
data.priority = form.value.priority || 50
|
data.priority = form.value.priority || 50
|
||||||
data.supportedModels = convertMappingsToObject() || {}
|
data.supportedModels = convertMappingsToObject() || {}
|
||||||
data.userAgent = form.value.userAgent || null
|
data.userAgent = form.value.userAgent || null
|
||||||
data.rateLimitDuration = form.value.rateLimitDuration || 60
|
// 如果不启用限流,传递 0 表示不限流
|
||||||
|
data.rateLimitDuration = form.value.enableRateLimit ? form.value.rateLimitDuration || 60 : 0
|
||||||
} else if (form.value.platform === 'bedrock') {
|
} else if (form.value.platform === 'bedrock') {
|
||||||
// Bedrock 账户特定数据 - 构造 awsCredentials 对象
|
// Bedrock 账户特定数据 - 构造 awsCredentials 对象
|
||||||
data.awsCredentials = {
|
data.awsCredentials = {
|
||||||
@@ -1821,7 +1894,8 @@ const createAccount = async () => {
|
|||||||
data.defaultModel = form.value.defaultModel || null
|
data.defaultModel = form.value.defaultModel || null
|
||||||
data.smallFastModel = form.value.smallFastModel || null
|
data.smallFastModel = form.value.smallFastModel || null
|
||||||
data.priority = form.value.priority || 50
|
data.priority = form.value.priority || 50
|
||||||
data.rateLimitDuration = form.value.rateLimitDuration || 60
|
// 如果不启用限流,传递 0 表示不限流
|
||||||
|
data.rateLimitDuration = form.value.enableRateLimit ? form.value.rateLimitDuration || 60 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
let result
|
let result
|
||||||
@@ -1964,7 +2038,8 @@ const updateAccount = async () => {
|
|||||||
data.priority = form.value.priority || 50
|
data.priority = form.value.priority || 50
|
||||||
data.supportedModels = convertMappingsToObject() || {}
|
data.supportedModels = convertMappingsToObject() || {}
|
||||||
data.userAgent = form.value.userAgent || null
|
data.userAgent = form.value.userAgent || null
|
||||||
data.rateLimitDuration = form.value.rateLimitDuration || 60
|
// 如果不启用限流,传递 0 表示不限流
|
||||||
|
data.rateLimitDuration = form.value.enableRateLimit ? form.value.rateLimitDuration || 60 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bedrock 特定更新
|
// Bedrock 特定更新
|
||||||
@@ -1989,7 +2064,8 @@ const updateAccount = async () => {
|
|||||||
data.defaultModel = form.value.defaultModel || null
|
data.defaultModel = form.value.defaultModel || null
|
||||||
data.smallFastModel = form.value.smallFastModel || null
|
data.smallFastModel = form.value.smallFastModel || null
|
||||||
data.priority = form.value.priority || 50
|
data.priority = form.value.priority || 50
|
||||||
data.rateLimitDuration = form.value.rateLimitDuration || 60
|
// 如果不启用限流,传递 0 表示不限流
|
||||||
|
data.rateLimitDuration = form.value.enableRateLimit ? form.value.rateLimitDuration || 60 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.account.platform === 'claude') {
|
if (props.account.platform === 'claude') {
|
||||||
@@ -2272,6 +2348,8 @@ watch(
|
|||||||
return ''
|
return ''
|
||||||
})(),
|
})(),
|
||||||
userAgent: newAccount.userAgent || '',
|
userAgent: newAccount.userAgent || '',
|
||||||
|
enableRateLimit:
|
||||||
|
newAccount.rateLimitDuration && newAccount.rateLimitDuration > 0 ? true : false,
|
||||||
rateLimitDuration: newAccount.rateLimitDuration || 60,
|
rateLimitDuration: newAccount.rateLimitDuration || 60,
|
||||||
// Bedrock 特定字段
|
// Bedrock 特定字段
|
||||||
accessKeyId: '', // 编辑模式不显示现有的访问密钥
|
accessKeyId: '', // 编辑模式不显示现有的访问密钥
|
||||||
|
|||||||
Reference in New Issue
Block a user