支持 Gemini Interactions 与 Antigravity 配额精细化

This commit is contained in:
MMEXA
2026-07-08 22:34:29 +08:00
parent 1ca83ca3fb
commit 80a6579766
41 changed files with 1072 additions and 225 deletions
+26 -1
View File
@@ -142,6 +142,17 @@ pub fn extract_ai_standard_requested_model(body_json: &Value) -> Option<String>
.map(ToOwned::to_owned)
}
pub fn extract_ai_gemini_body_requested_target(body_json: &Value) -> Option<String> {
extract_ai_standard_requested_model(body_json).or_else(|| {
body_json
.get("agent")
.and_then(Value::as_str)
.map(str::trim)
.filter(|value| !value.is_empty())
.map(ToOwned::to_owned)
})
}
pub fn extract_ai_requested_model_from_request_path(
request_path: &str,
body_json: &Value,
@@ -150,7 +161,7 @@ pub fn extract_ai_requested_model_from_request_path(
match family {
AiRequestedModelFamily::Standard => extract_ai_standard_requested_model(body_json),
AiRequestedModelFamily::Gemini => extract_ai_gemini_model_from_path(request_path)
.or_else(|| extract_ai_standard_requested_model(body_json)),
.or_else(|| extract_ai_gemini_body_requested_target(body_json)),
}
}
@@ -245,4 +256,18 @@ mod tests {
assert_eq!(requested_model.as_deref(), Some("gemini-cli"));
}
#[test]
fn gemini_requested_model_parser_uses_body_agent_when_path_has_no_model() {
let requested_model = extract_ai_requested_model_from_request_path(
"/v1/interactions",
&serde_json::json!({ "agent": " antigravity-preview-05-2026 " }),
AiRequestedModelFamily::Gemini,
);
assert_eq!(
requested_model.as_deref(),
Some("antigravity-preview-05-2026")
);
}
}