mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 08:27:46 +08:00
feat(providers): add xAI provider with device code OAuth
Add a separate `xai` provider type for xAI Grok CLI subscription accounts. It is independent of the existing `grok` provider, which reverse-proxies grok.com with browser cookies; behavior of `grok` is unchanged. Account binding uses the xAI device code flow, so no local callback listener is needed and headless deployments can bind accounts. Refresh tokens can also be imported individually or in batches, and are rotated on refresh. OAuth requests default to the cli-chat-proxy Responses API; API keys and compact stay on api.x.ai. Explicit custom gateways are preserved. Only `openai:responses` and `openai:responses:compact` are exposed; Chat, Claude and Gemini clients reach the provider through Aether's existing cross-format conversion rather than new native endpoints. Upstream Responses payloads are sanitized for what xAI actually rejects: `previous_response_id` and `metadata.user_id` are dropped, hosted `tool_choice` is rewritten, `web_search` is restored for converted clients, `image_generation` is stripped on older Grok conversation models, unsupported reasoning effort is removed, and requested `reasoning.encrypted_content` is preserved with a replay policy keyed on the configured provider type rather than the model name. Quota refresh reads /user and /billing?format=credits and stores a structured usage snapshot; a prepaid balance keeps an account selectable after the weekly allowance is exhausted. API-key accounts skip the subscription billing surface. The admin UI shows remaining weekly quota as a labeled bar in the provider drawer and the pool list. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -546,7 +546,7 @@ pub fn endpoint_supports_rust_models_fetch(api_format: &str) -> bool {
|
||||
pub fn provider_type_uses_preset_models(provider_type: &str) -> bool {
|
||||
matches!(
|
||||
provider_type.trim().to_ascii_lowercase().as_str(),
|
||||
"claude_code" | "gemini_cli" | "grok"
|
||||
"claude_code" | "gemini_cli" | "grok" | "xai"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -604,6 +604,18 @@ pub fn preset_models_for_provider(provider_type: &str) -> Option<Vec<Value>> {
|
||||
preset_model("grok-imagine-image-pro", "xai", "Grok Imagine Image Pro", "openai:image"),
|
||||
preset_model("grok-imagine-image-edit", "xai", "Grok Imagine Image Edit", "openai:image"),
|
||||
],
|
||||
"xai" => vec![
|
||||
preset_model("grok-4.6", "xai", "Grok 4.6", "openai:responses"),
|
||||
preset_model("grok-build-0.1", "xai", "Grok Build 0.1", "openai:responses"),
|
||||
preset_model("grok-4.5", "xai", "Grok 4.5", "openai:responses"),
|
||||
preset_model("grok-4.3", "xai", "Grok 4.3", "openai:responses"),
|
||||
preset_model("grok-4.20-0309-reasoning", "xai", "Grok 4.20 0309 Reasoning", "openai:responses"),
|
||||
preset_model("grok-4.20-0309-non-reasoning", "xai", "Grok 4.20 0309 Non-Reasoning", "openai:responses"),
|
||||
preset_model("grok-4.20-multi-agent-0309", "xai", "Grok 4.20 Multi-Agent 0309", "openai:responses"),
|
||||
preset_model("grok-3-mini", "xai", "Grok 3 Mini", "openai:responses"),
|
||||
preset_model("grok-3-mini-fast", "xai", "Grok 3 Mini Fast", "openai:responses"),
|
||||
preset_model("grok-composer-2.5-fast", "xai", "Grok Composer 2.5 Fast", "openai:responses"),
|
||||
],
|
||||
_ => return None,
|
||||
};
|
||||
Some(models)
|
||||
@@ -1977,4 +1989,32 @@ mod tests {
|
||||
assert_eq!(models[15]["api_formats"], json!(["openai:image"]));
|
||||
assert_eq!(models[18]["api_formats"], json!(["openai:image"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preset_models_cover_xai_cli_catalog() {
|
||||
let models = preset_models_for_provider("xai").expect("preset models should exist");
|
||||
let model_ids = models
|
||||
.iter()
|
||||
.map(|model| model["id"].as_str().expect("model id"))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
model_ids,
|
||||
vec![
|
||||
"grok-4.6",
|
||||
"grok-build-0.1",
|
||||
"grok-4.5",
|
||||
"grok-4.3",
|
||||
"grok-4.20-0309-reasoning",
|
||||
"grok-4.20-0309-non-reasoning",
|
||||
"grok-4.20-multi-agent-0309",
|
||||
"grok-3-mini",
|
||||
"grok-3-mini-fast",
|
||||
"grok-composer-2.5-fast",
|
||||
]
|
||||
);
|
||||
assert!(models.iter().all(|model| model["owned_by"] == json!("xai")));
|
||||
assert!(models
|
||||
.iter()
|
||||
.all(|model| model["api_formats"] == json!(["openai:responses"])));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user