mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 01:47:47 +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:
@@ -1,5 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static POSTGRES_WORKDIR_SEQ: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
use aether_data::driver::postgres::PostgresPoolConfig;
|
||||
use aether_data::{DataBackends, DataLayerConfig};
|
||||
@@ -21,10 +24,20 @@ pub struct ManagedPostgresServer {
|
||||
impl ManagedPostgresServer {
|
||||
pub async fn start() -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let port = reserve_local_port()?;
|
||||
// pid+port is not unique: cargo test shares one PID, and ephemeral ports
|
||||
// are reused after the listener is dropped. Parallel e2e tests then hit
|
||||
// create_dir AlreadyExists.
|
||||
let seq = POSTGRES_WORKDIR_SEQ.fetch_add(1, Ordering::Relaxed);
|
||||
let nanos = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|duration| duration.as_nanos())
|
||||
.unwrap_or(0);
|
||||
let workdir = std::env::temp_dir().join(format!(
|
||||
"aether-postgres-baseline-{}-{}",
|
||||
"aether-postgres-baseline-{}-{}-{}-{}",
|
||||
std::process::id(),
|
||||
port
|
||||
port,
|
||||
seq,
|
||||
nanos
|
||||
));
|
||||
let data_dir = workdir.join("data");
|
||||
std::fs::create_dir(&workdir)?;
|
||||
|
||||
Reference in New Issue
Block a user