refactor ai serving modules and crates

This commit is contained in:
fawney19
2026-05-02 13:23:54 +08:00
parent 4fc7cecf30
commit c130d0e2c9
309 changed files with 21549 additions and 14265 deletions

View File

@@ -937,7 +937,7 @@ fn build_web_search_sse_body(
input_tokens: u64,
) -> Result<Vec<u8>, serde_json::Error> {
let events = build_web_search_events(model, query, tool_use_id, search_results, input_tokens);
crate::ai_pipeline_api::encode_kiro_sse_events(events)
crate::ai_serving::api::encode_kiro_sse_events(events)
}
fn build_web_search_events(

View File

@@ -33,6 +33,7 @@ pub(crate) use self::fallback::{
pub(crate) use crate::orchestration::{
append_local_failover_policy_to_value, LocalFailoverAnalysis, LocalFailoverDecision,
};
pub(crate) use aether_ai_serving::{ConversionMode, ExecutionStrategy};
pub use server::{
build_execution_runtime_router, build_execution_runtime_router_with_request_concurrency_limit,
build_execution_runtime_router_with_request_gates, serve_execution_runtime_tcp,
@@ -52,46 +53,6 @@ pub(crate) use transport::{
DirectUpstreamStreamExecution, ExecutionRuntimeTransportError,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ExecutionStrategy {
GatewayAffinityForward,
RawPublicProxy,
LocalSameFormat,
LocalCrossFormat,
}
impl ExecutionStrategy {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::GatewayAffinityForward => "gateway_affinity_forward",
Self::RawPublicProxy => "raw_public_proxy",
Self::LocalSameFormat => "local_same_format",
Self::LocalCrossFormat => "local_cross_format",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ConversionMode {
None,
RequestOnly,
ResponseOnly,
Bidirectional,
}
impl ConversionMode {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::None => "none",
Self::RequestOnly => "request_only",
Self::ResponseOnly => "response_only",
Self::Bidirectional => "bidirectional",
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct ClientIntent {
pub(crate) client_contract: String,

View File

@@ -39,7 +39,7 @@ use self::execution_failures::{
build_stream_failure_from_execution_error, build_stream_failure_report,
handle_prefetch_stream_failure, submit_midstream_stream_failure, StreamFailureReport,
};
use crate::ai_pipeline_api::{
use crate::ai_serving::api::{
maybe_bridge_standard_sync_json_to_stream, maybe_build_provider_private_stream_normalizer,
maybe_build_stream_response_rewriter, normalize_provider_private_report_context,
StreamingStandardTerminalObserver,

View File

@@ -13,7 +13,7 @@ use futures_util::{Stream, StreamExt};
use serde_json::Value;
use tracing::warn;
use crate::ai_pipeline_api::{
use crate::ai_serving::api::{
maybe_bridge_standard_sync_json_to_stream, maybe_build_provider_private_stream_normalizer,
normalize_provider_private_report_context, StreamingStandardTerminalObserver,
};
@@ -399,7 +399,7 @@ fn should_treat_upstream_response_as_stream(
report_context
.get("envelope_name")
.and_then(Value::as_str)
.is_some_and(|value| value.eq_ignore_ascii_case(crate::ai_pipeline::KIRO_ENVELOPE_NAME))
.is_some_and(|value| value.eq_ignore_ascii_case(crate::ai_serving::KIRO_ENVELOPE_NAME))
}
fn should_buffer_non_stream_response(
@@ -495,7 +495,7 @@ fn maybe_bridge_non_sse_sync_json_to_stream(
body_bytes: &[u8],
provider_api_format: &str,
report_context: &Value,
) -> Result<Option<crate::ai_pipeline::SyncToStreamBridgeOutcome>, GatewayError> {
) -> Result<Option<crate::ai_serving::SyncToStreamBridgeOutcome>, GatewayError> {
if !(200..300).contains(&status_code) || body_bytes.is_empty() {
return Ok(None);
}
@@ -584,7 +584,7 @@ fn format_error_chain(err: &(dyn std::error::Error + 'static)) -> String {
fn observe_stream_chunk(
observer: &mut StreamingStandardTerminalObserver,
report_context: &Value,
private_stream_normalizer: Option<&mut crate::ai_pipeline::ProviderPrivateStreamNormalizer<'_>>,
private_stream_normalizer: Option<&mut crate::ai_serving::ProviderPrivateStreamNormalizer<'_>>,
observer_buffered: &mut Vec<u8>,
chunk: &[u8],
) {
@@ -608,7 +608,7 @@ fn observe_stream_chunk(
fn finalize_stream_terminal_summary(
observer: &mut StreamingStandardTerminalObserver,
report_context: &Value,
private_stream_normalizer: Option<&mut crate::ai_pipeline::ProviderPrivateStreamNormalizer<'_>>,
private_stream_normalizer: Option<&mut crate::ai_serving::ProviderPrivateStreamNormalizer<'_>>,
observer_buffered: &mut Vec<u8>,
) -> Option<ExecutionStreamTerminalSummary> {
if let Some(normalizer) = private_stream_normalizer {

View File

@@ -1,6 +1,6 @@
#[cfg(test)]
use crate::ai_pipeline_api::core_success_background_report_kind;
use crate::ai_pipeline_api::{
use crate::ai_serving::api::core_success_background_report_kind;
use crate::ai_serving::api::{
build_core_error_body_for_client_format, core_error_background_report_kind,
core_error_default_client_api_format, is_core_error_finalize_kind,
maybe_compile_sync_finalize_response,

View File

@@ -15,7 +15,7 @@ use axum::http::Response;
use base64::Engine as _;
use tracing::warn;
use crate::ai_pipeline_api::{
use crate::ai_serving::api::{
implicit_sync_finalize_report_kind, maybe_build_sync_finalize_outcome,
LocalCoreSyncFinalizeOutcome,
};

View File

@@ -3,12 +3,12 @@ use axum::http::Request;
use base64::Engine as _;
use serde_json::json;
use crate::ai_pipeline_api::{
use crate::ai_serving::api::{
build_gemini_stream_plan_from_decision, build_gemini_sync_plan_from_decision,
build_openai_responses_stream_plan_from_decision,
build_openai_responses_sync_plan_from_decision, build_passthrough_sync_plan_from_decision,
build_standard_stream_plan_from_decision, build_standard_sync_plan_from_decision,
GatewayControlSyncDecisionResponse,
AiExecutionDecision,
};
use crate::execution_runtime::submission::{
build_best_effort_local_core_error_body, has_nested_error,
@@ -34,10 +34,8 @@ fn test_parts() -> http::request::Parts {
parts
}
fn missing_exact_provider_request_payload(
decision_kind: &str,
) -> GatewayControlSyncDecisionResponse {
GatewayControlSyncDecisionResponse {
fn missing_exact_provider_request_payload(decision_kind: &str) -> AiExecutionDecision {
AiExecutionDecision {
action: "execution_runtime".to_string(),
decision_kind: Some(decision_kind.to_string()),
execution_strategy: Some("local_same_format".to_string()),