Route request origin through ai pipeline facade

This commit is contained in:
fawney19
2026-04-30 12:15:51 +08:00
parent 7fcb9e6292
commit 558abfcfa3
9 changed files with 19 additions and 10 deletions

View File

@@ -49,6 +49,7 @@ pub(crate) use self::planner::{
pub(crate) use self::pure::*; pub(crate) use self::pure::*;
pub(crate) use crate::control::GatewayControlDecision; pub(crate) use crate::control::GatewayControlDecision;
pub(crate) use crate::execution_runtime::{ConversionMode, ExecutionStrategy}; pub(crate) use crate::execution_runtime::{ConversionMode, ExecutionStrategy};
pub(crate) use crate::headers::RequestOrigin;
pub(crate) fn build_provider_transport_request_url( pub(crate) fn build_provider_transport_request_url(
transport: &GatewayProviderTransportSnapshot, transport: &GatewayProviderTransportSnapshot,
@@ -87,6 +88,14 @@ pub(crate) fn collect_control_headers(
crate::headers::collect_control_headers(headers) crate::headers::collect_control_headers(headers)
} }
pub(crate) fn request_origin_from_headers(headers: &http::HeaderMap) -> RequestOrigin {
crate::headers::request_origin_from_headers(headers)
}
pub(crate) fn request_origin_from_parts(parts: &http::request::Parts) -> RequestOrigin {
crate::headers::request_origin_from_parts(parts)
}
pub(crate) fn build_report_context_original_request_echo( pub(crate) fn build_report_context_original_request_echo(
body_json: Option<&Value>, body_json: Option<&Value>,
body_bytes_b64: Option<&str>, body_bytes_b64: Option<&str>,

View File

@@ -109,7 +109,7 @@ pub(crate) async fn maybe_build_local_same_format_provider_decision_payload_for_
provider_request_method: Some(serde_json::Value::Null), provider_request_method: Some(serde_json::Value::Null),
provider_request_headers: Some(&resolved.provider_request_headers), provider_request_headers: Some(&resolved.provider_request_headers),
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: None, original_request_body_base64: None,
client_requested_stream: body_json client_requested_stream: body_json

View File

@@ -5,7 +5,7 @@ use serde_json::{Map, Value};
use crate::ai_pipeline::contracts::ExecutionRuntimeAuthContext; use crate::ai_pipeline::contracts::ExecutionRuntimeAuthContext;
use crate::ai_pipeline::planner::candidate_metadata::append_ranking_metadata_to_object; use crate::ai_pipeline::planner::candidate_metadata::append_ranking_metadata_to_object;
use crate::headers::RequestOrigin; use crate::ai_pipeline::{request_origin_from_headers, RequestOrigin};
use crate::orchestration::ExecutionAttemptIdentity; use crate::orchestration::ExecutionAttemptIdentity;
pub(crate) struct LocalExecutionReportContextParts<'a> { pub(crate) struct LocalExecutionReportContextParts<'a> {
@@ -138,7 +138,7 @@ pub(crate) fn build_local_execution_report_context(
user_agent, user_agent,
} = parts } = parts
.request_origin .request_origin
.unwrap_or_else(|| crate::headers::request_origin_from_headers(parts.original_headers)); .unwrap_or_else(|| request_origin_from_headers(parts.original_headers));
if let Some(client_ip) = client_ip { if let Some(client_ip) = client_ip {
object.insert("client_ip".to_string(), Value::String(client_ip)); object.insert("client_ip".to_string(), Value::String(client_ip));
} }
@@ -260,7 +260,7 @@ mod tests {
LocalExecutionReportContextParts, LocalExecutionReportContextParts,
}; };
use crate::ai_pipeline::contracts::ExecutionRuntimeAuthContext; use crate::ai_pipeline::contracts::ExecutionRuntimeAuthContext;
use crate::headers::RequestOrigin; use crate::ai_pipeline::RequestOrigin;
use crate::orchestration::ExecutionAttemptIdentity; use crate::orchestration::ExecutionAttemptIdentity;
#[test] #[test]

View File

@@ -90,7 +90,7 @@ pub(super) async fn maybe_build_local_gemini_files_decision_payload_for_candidat
provider_request_method: None, provider_request_method: None,
provider_request_headers: None, provider_request_headers: None,
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: resolved.provider_request_body_base64.as_deref(), original_request_body_base64: resolved.provider_request_body_base64.as_deref(),
client_requested_stream: spec_metadata.require_streaming, client_requested_stream: spec_metadata.require_streaming,

View File

@@ -87,7 +87,7 @@ pub(super) async fn maybe_build_local_openai_image_decision_payload_for_candidat
provider_request_method: Some(serde_json::Value::String(parts.method.to_string())), provider_request_method: Some(serde_json::Value::String(parts.method.to_string())),
provider_request_headers: Some(&resolved.provider_request_headers), provider_request_headers: Some(&resolved.provider_request_headers),
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: body_base64, original_request_body_base64: body_base64,
client_requested_stream: spec_metadata.require_streaming, client_requested_stream: spec_metadata.require_streaming,

View File

@@ -73,7 +73,7 @@ pub(super) async fn maybe_build_local_video_create_decision_payload_for_candidat
provider_request_method: None, provider_request_method: None,
provider_request_headers: None, provider_request_headers: None,
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: None, original_request_body_base64: None,
client_requested_stream: false, client_requested_stream: false,

View File

@@ -89,7 +89,7 @@ pub(super) async fn maybe_build_local_standard_decision_payload_for_candidate(
provider_request_method: Some(serde_json::Value::Null), provider_request_method: Some(serde_json::Value::Null),
provider_request_headers: Some(&resolved.provider_request_headers), provider_request_headers: Some(&resolved.provider_request_headers),
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: None, original_request_body_base64: None,
client_requested_stream: body_json client_requested_stream: body_json

View File

@@ -107,7 +107,7 @@ pub(crate) async fn maybe_build_local_openai_chat_decision_payload_for_candidate
provider_request_method: Some(serde_json::Value::Null), provider_request_method: Some(serde_json::Value::Null),
provider_request_headers: Some(&resolved.provider_request_headers), provider_request_headers: Some(&resolved.provider_request_headers),
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: None, original_request_body_base64: None,
client_requested_stream: body_json client_requested_stream: body_json

View File

@@ -105,7 +105,7 @@ pub(crate) async fn maybe_build_local_openai_responses_decision_payload_for_cand
provider_request_method: Some(serde_json::Value::Null), provider_request_method: Some(serde_json::Value::Null),
provider_request_headers: Some(&resolved.provider_request_headers), provider_request_headers: Some(&resolved.provider_request_headers),
original_headers: &parts.headers, original_headers: &parts.headers,
request_origin: Some(crate::headers::request_origin_from_parts(parts)), request_origin: Some(crate::ai_pipeline::request_origin_from_parts(parts)),
original_request_body_json: Some(body_json), original_request_body_json: Some(body_json),
original_request_body_base64: None, original_request_body_base64: None,
client_requested_stream: body_json client_requested_stream: body_json