merge: resolve conflicts with upstream/main (Gemini 3→3.1 mappings)

This commit is contained in:
erio
2026-02-25 00:38:39 +08:00
8 changed files with 172 additions and 34 deletions

View File

@@ -372,6 +372,9 @@ func (a *Account) GetModelMapping() map[string]string {
}
}
if len(result) > 0 {
if a.Platform == domain.PlatformAntigravity {
ensureAntigravityDefaultPassthrough(result, "gemini-3-flash")
}
return result
}
}
@@ -382,6 +385,21 @@ func (a *Account) GetModelMapping() map[string]string {
return nil
}
func ensureAntigravityDefaultPassthrough(mapping map[string]string, model string) {
if mapping == nil || model == "" {
return
}
if _, exists := mapping[model]; exists {
return
}
for pattern := range mapping {
if matchWildcard(pattern, model) {
return
}
}
mapping[model] = model
}
// IsModelSupported 检查模型是否在 model_mapping 中(支持通配符)
// 如果未配置 mapping返回 true允许所有模型
func (a *Account) IsModelSupported(requestedModel string) bool {

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"strings"
"sync"
"time"
@@ -217,12 +218,20 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
}
if account.Platform == PlatformGemini {
return s.getGeminiUsage(ctx, account)
usage, err := s.getGeminiUsage(ctx, account)
if err == nil {
s.tryClearRecoverableAccountError(ctx, account)
}
return usage, err
}
// Antigravity 平台:使用 AntigravityQuotaFetcher 获取额度
if account.Platform == PlatformAntigravity {
return s.getAntigravityUsage(ctx, account)
usage, err := s.getAntigravityUsage(ctx, account)
if err == nil {
s.tryClearRecoverableAccountError(ctx, account)
}
return usage, err
}
// 只有oauth类型账号可以通过API获取usage有profile scope
@@ -256,6 +265,7 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
// 4. 添加窗口统计有独立缓存1 分钟)
s.addWindowStats(ctx, account, usage)
s.tryClearRecoverableAccountError(ctx, account)
return usage, nil
}
@@ -486,6 +496,32 @@ func parseTime(s string) (time.Time, error) {
return time.Time{}, fmt.Errorf("unable to parse time: %s", s)
}
func (s *AccountUsageService) tryClearRecoverableAccountError(ctx context.Context, account *Account) {
if account == nil || account.Status != StatusError {
return
}
msg := strings.ToLower(strings.TrimSpace(account.ErrorMessage))
if msg == "" {
return
}
if !strings.Contains(msg, "token refresh failed") &&
!strings.Contains(msg, "invalid_client") &&
!strings.Contains(msg, "missing_project_id") &&
!strings.Contains(msg, "unauthenticated") {
return
}
if err := s.accountRepo.ClearError(ctx, account.ID); err != nil {
log.Printf("[usage] failed to clear recoverable account error for account %d: %v", account.ID, err)
return
}
account.Status = StatusActive
account.ErrorMessage = ""
}
// buildUsageInfo 构建UsageInfo
func (s *AccountUsageService) buildUsageInfo(resp *ClaudeUsageResponse, updatedAt *time.Time) *UsageInfo {
info := &UsageInfo{

View File

@@ -267,3 +267,38 @@ func TestAccountGetMappedModel(t *testing.T) {
})
}
}
func TestAccountGetModelMapping_AntigravityEnsuresGemini3FlashPassthrough(t *testing.T) {
account := &Account{
Platform: PlatformAntigravity,
Credentials: map[string]any{
"model_mapping": map[string]any{
"gemini-3-pro-high": "gemini-3.1-pro-high",
},
},
}
mapping := account.GetModelMapping()
if mapping["gemini-3-flash"] != "gemini-3-flash" {
t.Fatalf("expected gemini-3-flash passthrough to be auto-filled, got: %q", mapping["gemini-3-flash"])
}
}
func TestAccountGetModelMapping_AntigravityRespectsWildcardOverride(t *testing.T) {
account := &Account{
Platform: PlatformAntigravity,
Credentials: map[string]any{
"model_mapping": map[string]any{
"gemini-3*": "gemini-3.1-pro-high",
},
},
}
mapping := account.GetModelMapping()
if _, exists := mapping["gemini-3-flash"]; exists {
t.Fatalf("did not expect explicit gemini-3-flash passthrough when wildcard already exists")
}
if mapped := account.GetMappedModel("gemini-3-flash"); mapped != "gemini-3.1-pro-high" {
t.Fatalf("expected wildcard mapping to stay effective, got: %q", mapped)
}
}