feat(auth): add OAuth2 support for xAI with PKCE and token persistence
- Implemented xAI OAuth2 integration with PKCE (Proof Key for Code Exchange) support. - Added logic for token exchange, refresh, and persistent storage in JSON format. - Created `xai` package with helpers for OAuth discovery, API token handling, and URL building. - Introduced `XAIExecutor` for integrating xAI credentials into runtime HTTP requests. - Added unit tests to validate OAuth flow, token persistence, and endpoint validation.
This commit is contained in:
@@ -21,6 +21,7 @@ type staticModelsJSON struct {
|
||||
CodexPro []*ModelInfo `json:"codex-pro"`
|
||||
Kimi []*ModelInfo `json:"kimi"`
|
||||
Antigravity []*ModelInfo `json:"antigravity"`
|
||||
XAI []*ModelInfo `json:"xai"`
|
||||
}
|
||||
|
||||
// GetClaudeModels returns the standard Claude model definitions.
|
||||
@@ -78,6 +79,11 @@ func GetAntigravityModels() []*ModelInfo {
|
||||
return cloneModelInfos(getModels().Antigravity)
|
||||
}
|
||||
|
||||
// GetXAIModels returns the standard xAI Grok model definitions.
|
||||
func GetXAIModels() []*ModelInfo {
|
||||
return cloneModelInfos(getModels().XAI)
|
||||
}
|
||||
|
||||
// WithCodexBuiltins injects hard-coded Codex-only model definitions that should
|
||||
// not depend on remote models.json updates. Built-ins replace any matching IDs
|
||||
// already present in the provided slice.
|
||||
@@ -167,6 +173,7 @@ func cloneModelInfos(models []*ModelInfo) []*ModelInfo {
|
||||
// - codex
|
||||
// - kimi
|
||||
// - antigravity
|
||||
// - xai
|
||||
func GetStaticModelDefinitionsByChannel(channel string) []*ModelInfo {
|
||||
key := strings.ToLower(strings.TrimSpace(channel))
|
||||
switch key {
|
||||
@@ -186,6 +193,8 @@ func GetStaticModelDefinitionsByChannel(channel string) []*ModelInfo {
|
||||
return GetKimiModels()
|
||||
case "antigravity":
|
||||
return GetAntigravityModels()
|
||||
case "xai", "x-ai", "grok":
|
||||
return GetXAIModels()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -208,6 +217,7 @@ func LookupStaticModelInfo(modelID string) *ModelInfo {
|
||||
data.CodexPro,
|
||||
data.Kimi,
|
||||
data.Antigravity,
|
||||
data.XAI,
|
||||
}
|
||||
for _, models := range allModels {
|
||||
for _, m := range models {
|
||||
|
||||
Reference in New Issue
Block a user