feat: extend client affinity support to Antigravity and Anthropic APIKey accounts

Made-with: Cursor
This commit is contained in:
erio
2026-03-06 17:31:18 +08:00
parent af5d5dbcbc
commit 6b31b34672
4 changed files with 24 additions and 14 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ func AccountFromServiceShallow(a *service.Account) *Account {
}
}
// 客户端亲和调度(仅 Anthropic OAuth/SetupToken 账号)
// 客户端亲和调度(Anthropic 和 Antigravity 账号)
if a.IsClientAffinityEnabled() {
enabled := true
out.ClientAffinityEnabled = &enabled
+1 -1
View File
@@ -188,7 +188,7 @@ type Account struct {
CacheTTLOverrideEnabled *bool `json:"cache_ttl_override_enabled,omitempty"`
CacheTTLOverrideTarget *string `json:"cache_ttl_override_target,omitempty"`
// 客户端亲和调度(仅 Anthropic OAuth/SetupToken 账号有效)
// 客户端亲和调度(Anthropic 和 Antigravity 账号有效)
// 启用后新会话会优先调度到客户端之前使用过的账号
ClientAffinityEnabled *bool `json:"client_affinity_enabled,omitempty"`
+2 -2
View File
@@ -1100,10 +1100,10 @@ func (a *Account) IsSessionIDMaskingEnabled() bool {
}
// IsClientAffinityEnabled 检查是否启用客户端亲和调度
// 仅适用于 Anthropic OAuth/SetupToken 账号(Claude Code)
// 适用于 Anthropic 和 Antigravity 账号
// 启用后,新会话会优先调度到之前使用过的账号
func (a *Account) IsClientAffinityEnabled() bool {
if !a.IsAnthropicOAuthOrSetupToken() {
if a.Platform != PlatformAnthropic && a.Platform != PlatformAntigravity {
return false
}
if a.Extra == nil {
@@ -645,9 +645,9 @@
</div>
</div>
<!-- Client Affinity (Anthropic OAuth/SetupToken only) -->
<!-- Client Affinity (Anthropic & Antigravity accounts) -->
<div
v-if="account?.platform === 'anthropic' && (account?.type === 'oauth' || account?.type === 'setup-token')"
v-if="account?.platform === 'anthropic' || account?.platform === 'antigravity'"
class="border-t border-gray-200 pt-4 dark:border-dark-600"
>
<div class="flex items-center justify-between">
@@ -1905,16 +1905,16 @@ function loadQuotaControlSettings(account: Account) {
cacheTTLOverrideTarget.value = '5m'
clientAffinityEnabled.value = false
// Only applies to Anthropic OAuth/SetupToken accounts
if (account.platform !== 'anthropic' || (account.type !== 'oauth' && account.type !== 'setup-token')) {
return
}
// Client affinity (Anthropic OAuth/SetupToken only)
// Client affinity (Anthropic & Antigravity accounts)
if (account.client_affinity_enabled === true) {
clientAffinityEnabled.value = true
}
// Remaining quota control settings only apply to Anthropic OAuth/SetupToken accounts
if (account.platform !== 'anthropic' || (account.type !== 'oauth' && account.type !== 'setup-token')) {
return
}
// Load from extra field (via backend DTO fields)
if (account.window_cost_limit != null && account.window_cost_limit > 0) {
windowCostEnabled.value = true
@@ -2224,7 +2224,7 @@ const handleSubmit = async () => {
updatePayload.credentials = newCredentials
}
// For antigravity accounts, handle mixed_scheduling in extra
// For antigravity accounts, handle mixed_scheduling and client_affinity in extra
if (props.account.platform === 'antigravity') {
const currentExtra = (props.account.extra as Record<string, unknown>) || {}
const newExtra: Record<string, unknown> = { ...currentExtra }
@@ -2233,6 +2233,11 @@ const handleSubmit = async () => {
} else {
delete newExtra.mixed_scheduling
}
if (clientAffinityEnabled.value) {
newExtra.client_affinity_enabled = true
} else {
delete newExtra.client_affinity_enabled
}
updatePayload.extra = newExtra
}
@@ -2318,7 +2323,7 @@ const handleSubmit = async () => {
updatePayload.extra = newExtra
}
// For Anthropic API Key accounts, handle passthrough mode in extra
// For Anthropic API Key accounts, handle passthrough mode and client affinity in extra
if (props.account.platform === 'anthropic' && props.account.type === 'apikey') {
const currentExtra = (props.account.extra as Record<string, unknown>) || {}
const newExtra: Record<string, unknown> = { ...currentExtra }
@@ -2327,6 +2332,11 @@ const handleSubmit = async () => {
} else {
delete newExtra.anthropic_passthrough
}
if (clientAffinityEnabled.value) {
newExtra.client_affinity_enabled = true
} else {
delete newExtra.client_affinity_enabled
}
updatePayload.extra = newExtra
}