2026-03-31 19:19:04 +08:00
|
|
|
use super::{
|
|
|
|
|
classified, is_claude_cli_request, is_gemini_cli_request, is_gemini_models_route,
|
|
|
|
|
is_gemini_operation_route, ClassifiedRoute,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub(super) fn classify_ai_public_route(
|
|
|
|
|
method: &http::Method,
|
|
|
|
|
normalized_path: &str,
|
|
|
|
|
headers: &http::HeaderMap,
|
|
|
|
|
) -> Option<ClassifiedRoute> {
|
|
|
|
|
if method == http::Method::POST && normalized_path == "/v1/chat/completions" {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"openai",
|
|
|
|
|
"chat",
|
|
|
|
|
"openai:chat",
|
|
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else if method == http::Method::POST
|
|
|
|
|
&& matches!(normalized_path, "/v1/responses" | "/v1/responses/compact")
|
|
|
|
|
{
|
|
|
|
|
if normalized_path.ends_with("/compact") {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"openai",
|
2026-04-26 20:32:55 +08:00
|
|
|
"responses:compact",
|
|
|
|
|
"openai:responses:compact",
|
2026-03-31 19:19:04 +08:00
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else {
|
2026-04-26 20:32:55 +08:00
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"openai",
|
|
|
|
|
"responses",
|
|
|
|
|
"openai:responses",
|
|
|
|
|
true,
|
|
|
|
|
))
|
2026-03-31 19:19:04 +08:00
|
|
|
}
|
2026-04-22 21:09:29 +08:00
|
|
|
} else if method == http::Method::POST
|
|
|
|
|
&& matches!(
|
|
|
|
|
normalized_path,
|
2026-04-23 14:42:51 +08:00
|
|
|
"/v1/images/generations" | "/v1/images/edits" | "/v1/images/variations"
|
2026-04-22 21:09:29 +08:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"openai",
|
|
|
|
|
"image",
|
|
|
|
|
"openai:image",
|
|
|
|
|
true,
|
|
|
|
|
))
|
2026-03-31 19:19:04 +08:00
|
|
|
} else if method == http::Method::POST && normalized_path == "/v1/messages/count_tokens" {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"claude",
|
|
|
|
|
"count_tokens",
|
2026-04-29 09:25:19 +08:00
|
|
|
"claude:messages",
|
2026-03-31 19:19:04 +08:00
|
|
|
false,
|
|
|
|
|
))
|
|
|
|
|
} else if method == http::Method::POST && normalized_path == "/v1/messages" {
|
2026-04-29 09:25:19 +08:00
|
|
|
let route_kind = if is_claude_cli_request(headers) {
|
|
|
|
|
"cli"
|
2026-03-31 19:19:04 +08:00
|
|
|
} else {
|
2026-04-29 09:25:19 +08:00
|
|
|
"messages"
|
|
|
|
|
};
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"claude",
|
|
|
|
|
route_kind,
|
|
|
|
|
"claude:messages",
|
|
|
|
|
true,
|
|
|
|
|
))
|
2026-03-31 19:19:04 +08:00
|
|
|
} else if normalized_path.starts_with("/v1/videos") {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"openai",
|
|
|
|
|
"video",
|
|
|
|
|
"openai:video",
|
|
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else if is_gemini_models_route(normalized_path) {
|
|
|
|
|
if normalized_path.ends_with(":predictLongRunning") {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"gemini",
|
|
|
|
|
"video",
|
|
|
|
|
"gemini:video",
|
|
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else if is_gemini_cli_request(headers) {
|
2026-04-29 09:25:19 +08:00
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"gemini",
|
|
|
|
|
"cli",
|
|
|
|
|
"gemini:generate_content",
|
|
|
|
|
true,
|
|
|
|
|
))
|
2026-03-31 19:19:04 +08:00
|
|
|
} else {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"gemini",
|
2026-04-29 09:25:19 +08:00
|
|
|
"generate_content",
|
|
|
|
|
"gemini:generate_content",
|
2026-03-31 19:19:04 +08:00
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
} else if is_gemini_operation_route(normalized_path) {
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"gemini",
|
|
|
|
|
"video",
|
|
|
|
|
"gemini:video",
|
|
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else if (method == http::Method::POST && normalized_path == "/upload/v1beta/files")
|
|
|
|
|
|| normalized_path.starts_with("/v1beta/files")
|
|
|
|
|
{
|
|
|
|
|
Some(classified(
|
|
|
|
|
"ai_public",
|
|
|
|
|
"gemini",
|
|
|
|
|
"files",
|
2026-04-29 09:25:19 +08:00
|
|
|
"gemini:files",
|
2026-03-31 19:19:04 +08:00
|
|
|
true,
|
|
|
|
|
))
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|