fix(grok): route generic account refresh correctly

This commit is contained in:
Heatherm Huang
2026-07-14 15:00:52 +08:00
parent 41cec0db05
commit a13a6113dd
14 changed files with 137 additions and 18 deletions
@@ -52,6 +52,7 @@ type AccountHandler struct {
openaiOAuthService *service.OpenAIOAuthService
geminiOAuthService *service.GeminiOAuthService
antigravityOAuthService *service.AntigravityOAuthService
grokOAuthService service.GrokOAuthTokenService
rateLimitService *service.RateLimitService
accountUsageService *service.AccountUsageService
accountTestService *service.AccountTestService
@@ -70,6 +71,7 @@ func NewAccountHandler(
openaiOAuthService *service.OpenAIOAuthService,
geminiOAuthService *service.GeminiOAuthService,
antigravityOAuthService *service.AntigravityOAuthService,
grokOAuthService service.GrokOAuthTokenService,
rateLimitService *service.RateLimitService,
accountUsageService *service.AccountUsageService,
accountTestService *service.AccountTestService,
@@ -85,6 +87,7 @@ func NewAccountHandler(
openaiOAuthService: openaiOAuthService,
geminiOAuthService: geminiOAuthService,
antigravityOAuthService: antigravityOAuthService,
grokOAuthService: grokOAuthService,
rateLimitService: rateLimitService,
accountUsageService: accountUsageService,
accountTestService: accountTestService,
@@ -1179,6 +1182,19 @@ func (h *AccountHandler) refreshSingleAccount(ctx context.Context, account *serv
return nil, "", fmt.Errorf("failed to clear account error: %w", clearErr)
}
}
} else if account.Platform == service.PlatformGrok {
if h.grokOAuthService == nil {
return nil, "", fmt.Errorf("grok oauth service is not configured")
}
tokenInfo, err := h.grokOAuthService.RefreshAccountToken(ctx, account)
if err != nil {
return nil, "", fmt.Errorf("failed to refresh Grok credentials: %w", err)
}
newCredentials = service.MergeCredentials(account.Credentials, h.grokOAuthService.BuildAccountCredentials(tokenInfo))
if baseURL := strings.TrimSpace(account.GetCredential("base_url")); baseURL != "" {
newCredentials["base_url"] = baseURL
}
} else {
// Use Anthropic/Claude OAuth service to refresh token
tokenInfo, err := h.oauthService.RefreshAccountToken(ctx, account)