fix(antigravity): fetch default mapping from API and sync Redis on rate limit
1. Frontend: replace hardcoded antigravityDefaultMappings with async fetch from GET /admin/accounts/antigravity/default-model-mapping, eliminating the duplicate data source that caused frontend/backend mapping inconsistency. 2. Backend: convert handleSmartRetry and antigravityRetryLoop from standalone functions to AntigravityGatewayService methods, enabling Redis cache sync (updateAccountModelRateLimitInCache) after both rate-limit write paths — long-delay branch and retry-exhausted branch.
This commit is contained in:
@@ -273,39 +273,25 @@ const antigravityPresetMappings = [
|
||||
{ label: 'Opus 4.5', from: 'claude-opus-4-5-thinking', to: 'claude-opus-4-5-thinking', color: 'bg-pink-100 text-pink-700 hover:bg-pink-200 dark:bg-pink-900/30 dark:text-pink-400' }
|
||||
]
|
||||
|
||||
// Antigravity 默认映射(与迁移脚本 049 保持一致)
|
||||
// 基于官方 API 返回的模型列表,只支持 Claude 4.5+ 和 Gemini 2.5+
|
||||
// 精确匹配,无通配符
|
||||
export const antigravityDefaultMappings: { from: string; to: string }[] = [
|
||||
// Claude 白名单
|
||||
{ from: 'claude-opus-4-6', to: 'claude-opus-4-6' },
|
||||
{ from: 'claude-opus-4-5-thinking', to: 'claude-opus-4-5-thinking' },
|
||||
{ from: 'claude-sonnet-4-5', to: 'claude-sonnet-4-5' },
|
||||
{ from: 'claude-sonnet-4-5-thinking', to: 'claude-sonnet-4-5-thinking' },
|
||||
// Claude 详细版本 ID 映射
|
||||
{ from: 'claude-opus-4-5-20251101', to: 'claude-opus-4-5-thinking' },
|
||||
{ from: 'claude-sonnet-4-5-20250929', to: 'claude-sonnet-4-5' },
|
||||
// Claude Haiku → Sonnet(无 Haiku 支持)
|
||||
{ from: 'claude-haiku-4-5', to: 'claude-sonnet-4-5' },
|
||||
{ from: 'claude-haiku-4-5-20251001', to: 'claude-sonnet-4-5' },
|
||||
// Gemini 2.5 白名单
|
||||
{ from: 'gemini-2.5-flash', to: 'gemini-2.5-flash' },
|
||||
{ from: 'gemini-2.5-flash-lite', to: 'gemini-2.5-flash-lite' },
|
||||
{ from: 'gemini-2.5-flash-thinking', to: 'gemini-2.5-flash-thinking' },
|
||||
{ from: 'gemini-2.5-pro', to: 'gemini-2.5-pro' },
|
||||
// Gemini 3 白名单
|
||||
{ from: 'gemini-3-flash', to: 'gemini-3-flash' },
|
||||
{ from: 'gemini-3-pro-high', to: 'gemini-3-pro-high' },
|
||||
{ from: 'gemini-3-pro-low', to: 'gemini-3-pro-low' },
|
||||
{ from: 'gemini-3-pro-image', to: 'gemini-3-pro-image' },
|
||||
// Gemini 3 preview 映射
|
||||
{ from: 'gemini-3-flash-preview', to: 'gemini-3-flash' },
|
||||
{ from: 'gemini-3-pro-preview', to: 'gemini-3-pro-high' },
|
||||
{ from: 'gemini-3-pro-image-preview', to: 'gemini-3-pro-image' },
|
||||
// 其他官方模型
|
||||
{ from: 'gpt-oss-120b-medium', to: 'gpt-oss-120b-medium' },
|
||||
{ from: 'tab_flash_lite_preview', to: 'tab_flash_lite_preview' }
|
||||
]
|
||||
// Antigravity 默认映射(从后端 API 获取,与 constants.go 保持一致)
|
||||
// 使用 fetchAntigravityDefaultMappings() 异步获取
|
||||
import { getAntigravityDefaultModelMapping } from '@/api/admin/accounts'
|
||||
|
||||
let _antigravityDefaultMappingsCache: { from: string; to: string }[] | null = null
|
||||
|
||||
export async function fetchAntigravityDefaultMappings(): Promise<{ from: string; to: string }[]> {
|
||||
if (_antigravityDefaultMappingsCache !== null) {
|
||||
return _antigravityDefaultMappingsCache
|
||||
}
|
||||
try {
|
||||
const mapping = await getAntigravityDefaultModelMapping()
|
||||
_antigravityDefaultMappingsCache = Object.entries(mapping).map(([from, to]) => ({ from, to }))
|
||||
} catch (e) {
|
||||
console.warn('[fetchAntigravityDefaultMappings] API failed, using empty fallback', e)
|
||||
_antigravityDefaultMappingsCache = []
|
||||
}
|
||||
return _antigravityDefaultMappingsCache
|
||||
}
|
||||
|
||||
// =====================
|
||||
// 常用错误码
|
||||
|
||||
Reference in New Issue
Block a user