feat(api): add OAuth token fields and new provider types support

Add support for OAuth-based authentication with access/refresh tokens
and expiration tracking for API keys. Extend provider groups with
static headers configuration and headers profile options.

Changes include:
- Add AccessToken, RefreshToken, ExpiresAt, AccountID, ProjectID to APIKey model
- Add StaticHeaders and HeadersProfile to ProviderGroup model
- Add TokenRefresh configuration for background token management
- Support new provider types: ClaudeCode, Codex, GeminiCLI, Antigravity
- Update sync service to include new fields in provider snapshots
This commit is contained in:
zenfun
2025-12-28 02:49:54 +08:00
parent cca0802620
commit f0fe9f0dad
8 changed files with 132 additions and 22 deletions

View File

@@ -14,6 +14,8 @@ type ProviderGroup struct {
BaseURL string `gorm:"size:512;not null" json:"base_url"`
GoogleProject string `gorm:"size:128" json:"google_project,omitempty"`
GoogleLocation string `gorm:"size:64" json:"google_location,omitempty"`
StaticHeaders string `gorm:"type:text" json:"static_headers,omitempty"`
HeadersProfile string `gorm:"size:64" json:"headers_profile,omitempty"`
Models string `json:"models"` // comma-separated list of supported models
Status string `gorm:"size:50;default:'active'" json:"status"`
}
@@ -21,11 +23,16 @@ type ProviderGroup struct {
// APIKey represents a credential within a provider group.
type APIKey struct {
gorm.Model
GroupID uint `gorm:"not null;index" json:"group_id"`
APIKey string `gorm:"not null" json:"api_key"`
Weight int `gorm:"default:1" json:"weight"`
Status string `gorm:"size:50;default:'active'" json:"status"`
AutoBan bool `gorm:"default:true" json:"auto_ban"`
BanReason string `gorm:"size:255" json:"ban_reason"`
BanUntil *time.Time `json:"ban_until"`
GroupID uint `gorm:"not null;index" json:"group_id"`
APIKey string `gorm:"not null" json:"api_key"`
AccessToken string `gorm:"type:text" json:"access_token,omitempty"`
RefreshToken string `gorm:"type:text" json:"-"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
AccountID string `gorm:"size:255" json:"account_id,omitempty"`
ProjectID string `gorm:"size:255" json:"project_id,omitempty"`
Weight int `gorm:"default:1" json:"weight"`
Status string `gorm:"size:50;default:'active'" json:"status"`
AutoBan bool `gorm:"default:true" json:"auto_ban"`
BanReason string `gorm:"size:255" json:"ban_reason"`
BanUntil *time.Time `json:"ban_until"`
}