2026-05-02 13:23:54 +08:00
|
|
|
use crate::ai_serving::{AiExecutionDecision, AiExecutionPlanPayload, GatewayControlDecision};
|
2026-04-05 20:23:16 +08:00
|
|
|
use crate::{AppState, GatewayError};
|
2026-04-03 14:59:58 +08:00
|
|
|
|
2026-04-27 13:39:50 +08:00
|
|
|
mod candidate_affinity_cache;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod candidate_materialization;
|
|
|
|
|
mod candidate_metadata;
|
|
|
|
|
mod candidate_preparation;
|
2026-04-27 13:39:50 +08:00
|
|
|
mod candidate_ranking;
|
2026-04-27 12:34:03 +08:00
|
|
|
mod candidate_resolution;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod candidate_source;
|
2026-04-27 16:21:57 +08:00
|
|
|
mod candidate_transport_ranking_facts;
|
2026-04-09 00:10:38 +08:00
|
|
|
mod common;
|
2026-04-03 14:59:58 +08:00
|
|
|
mod decision;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod decision_input;
|
2026-05-22 18:40:11 +08:00
|
|
|
mod gemini_cli;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod materialization_policy;
|
2026-04-09 00:10:38 +08:00
|
|
|
mod passthrough;
|
|
|
|
|
mod plan_builders;
|
2026-04-17 23:05:49 +08:00
|
|
|
mod pool_scheduler;
|
2026-05-12 01:46:22 +08:00
|
|
|
pub(crate) mod pool_scores;
|
2026-05-26 22:29:45 +08:00
|
|
|
mod redaction;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod report_context;
|
2026-06-10 18:16:55 +08:00
|
|
|
mod request_gzip;
|
2026-04-07 02:50:19 +08:00
|
|
|
mod route;
|
2026-04-14 01:27:04 +08:00
|
|
|
mod runtime_miss;
|
|
|
|
|
mod spec_metadata;
|
2026-04-09 00:10:38 +08:00
|
|
|
mod specialized;
|
|
|
|
|
mod standard;
|
|
|
|
|
mod state;
|
2026-04-07 02:50:19 +08:00
|
|
|
|
2026-05-03 20:14:29 +08:00
|
|
|
pub(crate) use self::candidate_materialization::LocalExecutionAttemptSource;
|
2026-05-12 13:15:41 +08:00
|
|
|
pub(crate) use self::candidate_resolution::{
|
|
|
|
|
candidate_auth_channel_skip_reason, read_candidate_transport_snapshot,
|
|
|
|
|
EligibleLocalExecutionCandidate, LocalExecutionCandidateKind, SkippedLocalExecutionCandidate,
|
|
|
|
|
};
|
2026-04-09 00:10:38 +08:00
|
|
|
pub(crate) use self::passthrough::{
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_same_format_stream_attempt_source, build_local_same_format_stream_plan_and_reports,
|
|
|
|
|
build_local_same_format_sync_attempt_source, build_local_same_format_sync_plan_and_reports,
|
2026-04-09 00:10:38 +08:00
|
|
|
};
|
|
|
|
|
pub(crate) use self::plan_builders::{
|
|
|
|
|
build_gemini_stream_plan_from_decision, build_gemini_sync_plan_from_decision,
|
2026-04-26 20:32:55 +08:00
|
|
|
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,
|
2026-05-02 13:23:54 +08:00
|
|
|
AiStreamAttempt, AiSyncAttempt,
|
2026-04-09 00:10:38 +08:00
|
|
|
};
|
2026-05-12 15:27:21 +08:00
|
|
|
pub(crate) use self::pool_scores::{
|
|
|
|
|
build_provider_key_pool_score_upsert, provider_key_pool_score_id, provider_key_pool_score_scope,
|
|
|
|
|
};
|
2026-06-10 18:16:55 +08:00
|
|
|
pub(crate) use self::request_gzip::resolve_transport_request_gzip_policy;
|
2026-04-23 14:42:51 +08:00
|
|
|
pub(crate) use self::route::is_matching_stream_request as planner_is_matching_stream_request;
|
2026-05-12 13:15:41 +08:00
|
|
|
pub(crate) use self::runtime_miss::{
|
|
|
|
|
apply_local_runtime_candidate_terminal_reason, record_local_runtime_candidate_skip_reason,
|
|
|
|
|
};
|
2026-04-09 00:10:38 +08:00
|
|
|
pub(crate) use self::specialized::{
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_gemini_files_stream_attempt_source_for_kind,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_gemini_files_stream_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_gemini_files_sync_attempt_source_for_kind,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_gemini_files_sync_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_image_stream_attempt_source_for_kind,
|
2026-04-23 14:42:51 +08:00
|
|
|
build_local_image_stream_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_image_sync_attempt_source_for_kind,
|
2026-04-22 21:09:29 +08:00
|
|
|
build_local_image_sync_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_video_sync_attempt_source_for_kind,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_video_sync_plan_and_reports_for_kind,
|
2026-05-09 01:21:26 +08:00
|
|
|
set_local_openai_image_execution_exhausted_diagnostic,
|
2026-04-09 00:10:38 +08:00
|
|
|
};
|
|
|
|
|
pub(crate) use self::standard::{
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_openai_chat_stream_attempt_source_for_kind,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_openai_chat_stream_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_openai_chat_sync_attempt_source_for_kind,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_openai_chat_sync_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_openai_responses_stream_attempt_source_for_kind,
|
2026-04-26 20:32:55 +08:00
|
|
|
build_local_openai_responses_stream_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_openai_responses_sync_attempt_source_for_kind,
|
2026-04-26 20:32:55 +08:00
|
|
|
build_local_openai_responses_sync_plan_and_reports_for_kind,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_stream_attempt_source as build_standard_family_stream_attempt_source,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_stream_plan_and_reports as build_standard_family_stream_plan_and_reports,
|
2026-05-03 20:14:29 +08:00
|
|
|
build_local_sync_attempt_source as build_standard_family_sync_attempt_source,
|
2026-04-09 00:10:38 +08:00
|
|
|
build_local_sync_plan_and_reports as build_standard_family_sync_plan_and_reports,
|
|
|
|
|
set_local_openai_chat_execution_exhausted_diagnostic,
|
|
|
|
|
};
|
|
|
|
|
pub(crate) use self::state::{
|
|
|
|
|
GatewayAuthApiKeySnapshot, GatewayProviderTransportSnapshot, LocalResolvedOAuthRequestAuth,
|
|
|
|
|
PlannerAppState,
|
2026-04-07 02:50:19 +08:00
|
|
|
};
|
2026-05-02 13:23:54 +08:00
|
|
|
pub(crate) use aether_ai_serving::extract_ai_pool_sticky_session_token as extract_pool_sticky_session_token;
|
|
|
|
|
pub(crate) use aether_ai_serving::{
|
|
|
|
|
build_ai_execution_decision_response, AiExecutionDecisionResponseParts,
|
|
|
|
|
CandidateFailureDiagnostic, CandidateFailureDiagnosticKind,
|
|
|
|
|
};
|
2026-04-03 14:59:58 +08:00
|
|
|
|
|
|
|
|
pub(crate) async fn maybe_build_sync_decision_payload(
|
|
|
|
|
state: &AppState,
|
|
|
|
|
parts: &http::request::Parts,
|
|
|
|
|
trace_id: &str,
|
|
|
|
|
decision: &GatewayControlDecision,
|
|
|
|
|
body_json: &serde_json::Value,
|
|
|
|
|
body_base64: Option<&str>,
|
|
|
|
|
body_is_empty: bool,
|
2026-05-02 13:23:54 +08:00
|
|
|
) -> Result<Option<AiExecutionDecision>, GatewayError> {
|
2026-04-03 14:59:58 +08:00
|
|
|
decision::maybe_build_sync_decision_payload(
|
|
|
|
|
state,
|
|
|
|
|
parts,
|
|
|
|
|
trace_id,
|
|
|
|
|
decision,
|
|
|
|
|
body_json,
|
|
|
|
|
body_base64,
|
|
|
|
|
body_is_empty,
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn maybe_build_stream_decision_payload(
|
|
|
|
|
state: &AppState,
|
|
|
|
|
parts: &http::request::Parts,
|
|
|
|
|
trace_id: &str,
|
|
|
|
|
decision: &GatewayControlDecision,
|
|
|
|
|
body_json: &serde_json::Value,
|
2026-04-23 14:42:51 +08:00
|
|
|
body_base64: Option<&str>,
|
2026-05-02 13:23:54 +08:00
|
|
|
) -> Result<Option<AiExecutionDecision>, GatewayError> {
|
2026-04-23 14:42:51 +08:00
|
|
|
decision::maybe_build_stream_decision_payload(
|
|
|
|
|
state,
|
|
|
|
|
parts,
|
|
|
|
|
trace_id,
|
|
|
|
|
decision,
|
|
|
|
|
body_json,
|
|
|
|
|
body_base64,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2026-04-03 14:59:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn maybe_build_sync_plan_payload(
|
|
|
|
|
state: &AppState,
|
|
|
|
|
parts: &http::request::Parts,
|
|
|
|
|
trace_id: &str,
|
|
|
|
|
decision: &GatewayControlDecision,
|
|
|
|
|
body_json: &serde_json::Value,
|
|
|
|
|
body_base64: Option<&str>,
|
|
|
|
|
body_is_empty: bool,
|
2026-05-02 13:23:54 +08:00
|
|
|
) -> Result<Option<AiExecutionPlanPayload>, GatewayError> {
|
2026-04-03 14:59:58 +08:00
|
|
|
decision::maybe_build_sync_plan_payload_impl(
|
|
|
|
|
state,
|
|
|
|
|
parts,
|
|
|
|
|
trace_id,
|
|
|
|
|
decision,
|
|
|
|
|
body_json,
|
|
|
|
|
body_base64,
|
|
|
|
|
body_is_empty,
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn maybe_build_stream_plan_payload(
|
|
|
|
|
state: &AppState,
|
|
|
|
|
parts: &http::request::Parts,
|
|
|
|
|
trace_id: &str,
|
|
|
|
|
decision: &GatewayControlDecision,
|
|
|
|
|
body_json: &serde_json::Value,
|
2026-04-23 14:42:51 +08:00
|
|
|
body_base64: Option<&str>,
|
2026-05-02 13:23:54 +08:00
|
|
|
) -> Result<Option<AiExecutionPlanPayload>, GatewayError> {
|
2026-04-23 14:42:51 +08:00
|
|
|
decision::maybe_build_stream_plan_payload_impl(
|
|
|
|
|
state,
|
|
|
|
|
parts,
|
|
|
|
|
trace_id,
|
|
|
|
|
decision,
|
|
|
|
|
body_json,
|
|
|
|
|
body_base64,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2026-04-03 14:59:58 +08:00
|
|
|
}
|