mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-05 00:47:48 +08:00
fix(providers): refresh Antigravity grouped quotas
This commit is contained in:
@@ -12,6 +12,8 @@ use crate::quota::provider_pool_model_quota_exhausted;
|
||||
use crate::quota_refresh::ProviderPoolQuotaRequestSpec;
|
||||
|
||||
pub const ANTIGRAVITY_FETCH_AVAILABLE_MODELS_PATH: &str = "/v1internal:fetchAvailableModels";
|
||||
pub const ANTIGRAVITY_RETRIEVE_USER_QUOTA_SUMMARY_PATH: &str =
|
||||
"/v1internal:retrieveUserQuotaSummary";
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct AntigravityProviderPoolAdapter;
|
||||
@@ -92,3 +94,85 @@ pub fn build_antigravity_pool_quota_request(
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_antigravity_pool_quota_summary_request(
|
||||
key_id: &str,
|
||||
endpoint_base_url: &str,
|
||||
authorization: (String, String),
|
||||
project_id: Option<&str>,
|
||||
mut identity_headers: BTreeMap<String, String>,
|
||||
) -> ProviderPoolQuotaRequestSpec {
|
||||
let mut headers = std::mem::take(&mut identity_headers);
|
||||
headers.insert("authorization".to_string(), authorization.1);
|
||||
headers.insert("content-type".to_string(), "application/json".to_string());
|
||||
headers.insert("accept".to_string(), "application/json".to_string());
|
||||
headers
|
||||
.entry("user-agent".to_string())
|
||||
.or_insert_with(|| "antigravity".to_string());
|
||||
|
||||
let json_body = project_id
|
||||
.map(str::trim)
|
||||
.filter(|project_id| !project_id.is_empty())
|
||||
.map_or_else(|| json!({}), |project_id| json!({ "project": project_id }));
|
||||
|
||||
ProviderPoolQuotaRequestSpec {
|
||||
request_id: format!("antigravity-quota-summary:{key_id}"),
|
||||
provider_name: "antigravity".to_string(),
|
||||
quota_kind: "antigravity".to_string(),
|
||||
method: "POST".to_string(),
|
||||
url: format!(
|
||||
"{}{}",
|
||||
endpoint_base_url.trim_end_matches('/'),
|
||||
ANTIGRAVITY_RETRIEVE_USER_QUOTA_SUMMARY_PATH
|
||||
),
|
||||
headers,
|
||||
content_type: Some("application/json".to_string()),
|
||||
json_body: Some(json_body),
|
||||
client_api_format: "gemini:generate_content".to_string(),
|
||||
provider_api_format: "antigravity:retrieve_user_quota_summary".to_string(),
|
||||
model_name: Some("retrieveUserQuotaSummary".to_string()),
|
||||
accept_invalid_certs: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::{
|
||||
build_antigravity_pool_quota_summary_request, ANTIGRAVITY_RETRIEVE_USER_QUOTA_SUMMARY_PATH,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn grouped_quota_request_can_retry_without_project_on_the_same_endpoint() {
|
||||
let with_project = build_antigravity_pool_quota_summary_request(
|
||||
"key-1",
|
||||
"https://daily-cloudcode-pa.googleapis.com/",
|
||||
("authorization".to_string(), "Bearer token".to_string()),
|
||||
Some("project-1"),
|
||||
BTreeMap::new(),
|
||||
);
|
||||
let without_project = build_antigravity_pool_quota_summary_request(
|
||||
"key-1",
|
||||
"https://daily-cloudcode-pa.googleapis.com/",
|
||||
("authorization".to_string(), "Bearer token".to_string()),
|
||||
None,
|
||||
BTreeMap::new(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
with_project.url,
|
||||
format!(
|
||||
"https://daily-cloudcode-pa.googleapis.com{ANTIGRAVITY_RETRIEVE_USER_QUOTA_SUMMARY_PATH}"
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
with_project.json_body,
|
||||
Some(json!({"project": "project-1"}))
|
||||
);
|
||||
assert_eq!(without_project.url, with_project.url);
|
||||
assert_eq!(without_project.json_body, Some(json!({})));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ pub mod windsurf;
|
||||
|
||||
pub use antigravity::AntigravityProviderPoolAdapter;
|
||||
pub use antigravity::{
|
||||
build_antigravity_pool_quota_request, ANTIGRAVITY_FETCH_AVAILABLE_MODELS_PATH,
|
||||
build_antigravity_pool_quota_request, build_antigravity_pool_quota_summary_request,
|
||||
ANTIGRAVITY_FETCH_AVAILABLE_MODELS_PATH, ANTIGRAVITY_RETRIEVE_USER_QUOTA_SUMMARY_PATH,
|
||||
};
|
||||
pub use chatgpt_web::ChatGptWebProviderPoolAdapter;
|
||||
pub use chatgpt_web::{
|
||||
|
||||
Reference in New Issue
Block a user