mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
Refactor provider transport modules
This commit is contained in:
@@ -12,6 +12,7 @@ use aether_scheduler_core::{
|
||||
ClientSessionAffinity, SchedulerMinimalCandidateSelectionCandidate, SchedulerRankingOutcome,
|
||||
};
|
||||
|
||||
use crate::ai_serving::transport::provider_types::provider_runtime_policy;
|
||||
use crate::ai_serving::{
|
||||
candidate_common_transport_skip_reason, candidate_transport_pair_skip_reason,
|
||||
CandidateTransportPolicyFacts, GatewayAuthApiKeySnapshot, GatewayProviderTransportSnapshot,
|
||||
@@ -398,6 +399,8 @@ pub(crate) fn candidate_auth_channel_skip_reason(
|
||||
let request_auth_channel = normalize_request_auth_channel(request_auth_channel?)?;
|
||||
let upstream_auth_channel = resolve_transport_request_auth_channel(transport)?;
|
||||
if request_auth_channel == upstream_auth_channel
|
||||
|| provider_runtime_policy(&transport.provider.provider_type)
|
||||
.allow_auth_channel_mismatch_by_default
|
||||
|| allow_auth_channel_mismatch_for_format(transport)
|
||||
{
|
||||
None
|
||||
@@ -418,12 +421,11 @@ fn resolve_transport_request_auth_channel(
|
||||
transport: &GatewayProviderTransportSnapshot,
|
||||
) -> Option<&'static str> {
|
||||
let auth_type = resolve_transport_auth_type_for_endpoint_format(transport);
|
||||
let provider_policy = provider_runtime_policy(&transport.provider.provider_type);
|
||||
match auth_type.as_str() {
|
||||
"api_key" => Some("api_key"),
|
||||
"bearer" => Some("bearer_like"),
|
||||
"oauth" if provider_uses_bearer_like_oauth(&transport.provider.provider_type) => {
|
||||
Some("bearer_like")
|
||||
}
|
||||
"oauth" if provider_policy.oauth_is_bearer_like => Some("bearer_like"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -450,13 +452,6 @@ fn resolve_transport_auth_type_for_endpoint_format(
|
||||
.unwrap_or(default_auth_type)
|
||||
}
|
||||
|
||||
fn provider_uses_bearer_like_oauth(provider_type: &str) -> bool {
|
||||
matches!(
|
||||
provider_type.trim().to_ascii_lowercase().as_str(),
|
||||
"claude_code" | "chatgpt_web" | "gemini_cli" | "antigravity" | "kiro"
|
||||
)
|
||||
}
|
||||
|
||||
fn allow_auth_channel_mismatch_for_format(transport: &GatewayProviderTransportSnapshot) -> bool {
|
||||
let api_format = crate::ai_serving::normalize_api_format_alias(&transport.endpoint.api_format);
|
||||
transport
|
||||
@@ -622,6 +617,16 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_channel_gate_allows_kiro_provider_mismatch_by_default() {
|
||||
let mut transport = sample_transport("oauth");
|
||||
transport.provider.provider_type = "kiro".to_string();
|
||||
assert_eq!(
|
||||
candidate_auth_channel_skip_reason(&transport, Some("api_key")),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pool_group_common_gate_ignores_representative_key_model_policy() {
|
||||
let candidate = sample_candidate();
|
||||
|
||||
@@ -2008,7 +2008,7 @@ fn ai_serving_video_routes_request_preparation_through_request_payload_seams() {
|
||||
}
|
||||
|
||||
let provider_transport_video =
|
||||
read_workspace_file("crates/aether-provider-transport/src/video.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/video/mod.rs");
|
||||
for pattern in [
|
||||
"pub enum ProviderVideoCreateFamily",
|
||||
"pub fn video_create_transport_unsupported_reason(",
|
||||
@@ -2083,7 +2083,7 @@ fn ai_serving_files_routes_request_preparation_through_request_payload_seams() {
|
||||
}
|
||||
|
||||
let provider_transport_files =
|
||||
read_workspace_file("crates/aether-provider-transport/src/gemini_files.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/gemini_files/mod.rs");
|
||||
for pattern in [
|
||||
"pub fn gemini_files_transport_unsupported_reason(",
|
||||
"pub fn resolve_gemini_files_auth(",
|
||||
@@ -2169,7 +2169,7 @@ fn ai_serving_image_routes_split_surface_normalization_and_transport_policy() {
|
||||
}
|
||||
|
||||
let provider_transport_image =
|
||||
read_workspace_file("crates/aether-provider-transport/src/openai_image.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/openai_image/mod.rs");
|
||||
for pattern in [
|
||||
"pub fn openai_image_transport_unsupported_reason(",
|
||||
"pub fn resolve_openai_image_auth(",
|
||||
@@ -2622,7 +2622,7 @@ fn ai_serving_standard_attempts_consume_eligible_local_candidates_without_transp
|
||||
}
|
||||
|
||||
let provider_transport_standard =
|
||||
read_workspace_file("crates/aether-provider-transport/src/standard.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/standard/mod.rs");
|
||||
for pattern in [
|
||||
"pub struct StandardProviderRequestHeadersInput",
|
||||
"pub struct StandardProviderRequestHeaders",
|
||||
@@ -2642,7 +2642,7 @@ fn ai_serving_standard_attempts_consume_eligible_local_candidates_without_transp
|
||||
}
|
||||
|
||||
let provider_transport_request_url =
|
||||
read_workspace_file("crates/aether-provider-transport/src/request_url.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/request_url/mod.rs");
|
||||
assert!(
|
||||
provider_transport_request_url.contains("pub fn build_kiro_cross_format_upstream_url("),
|
||||
"provider-transport request_url.rs should own Kiro cross-format URL hook"
|
||||
@@ -2704,7 +2704,7 @@ fn ai_serving_standard_plan_builders_delegate_fallback_transport_policy() {
|
||||
}
|
||||
|
||||
let provider_transport_standard =
|
||||
read_workspace_file("crates/aether-provider-transport/src/standard.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/standard/mod.rs");
|
||||
for pattern in [
|
||||
"pub enum StandardPlanFallbackAcceptPolicy",
|
||||
"pub struct StandardPlanFallbackHeadersInput",
|
||||
@@ -2972,7 +2972,7 @@ fn ai_serving_same_format_provider_request_policy_owns_provider_type_behavior()
|
||||
"apps/aether-gateway/src/ai_serving/planner/passthrough/provider/family/request/policy.rs",
|
||||
);
|
||||
let provider_transport_policy =
|
||||
read_workspace_file("crates/aether-provider-transport/src/same_format_provider.rs");
|
||||
read_workspace_file("crates/aether-provider-transport/src/same_format_provider/mod.rs");
|
||||
for pattern in [
|
||||
"pub struct SameFormatProviderRequestBehavior {",
|
||||
"pub struct SameFormatProviderRequestBodyInput",
|
||||
|
||||
Reference in New Issue
Block a user