Merge upstream/main into feat/356-usage-record-columns

This commit is contained in:
RWDai
2026-05-18 20:33:05 +08:00
95 changed files with 14199 additions and 2756 deletions
@@ -516,7 +516,9 @@ pub(super) async fn maybe_build_local_admin_usage_summary_response(
.summarize_usage_audits(&UsageAuditSummaryQuery {
created_from_unix_secs,
created_until_unix_secs,
..Default::default()
user_id: query_param_value(query, "user_id"),
provider_name: query_param_value(query, "provider"),
model: query_param_value(query, "model"),
})
.await?;
return Ok(Some(build_admin_usage_summary_stats_response_from_summary(
@@ -13,12 +13,18 @@ pub(super) fn key_api_formats_without_entry(
}
pub(super) fn endpoint_key_counts_by_format(
provider_type: &str,
endpoints: &[StoredProviderCatalogEndpoint],
keys: &[StoredProviderCatalogKey],
) -> (
std::collections::BTreeMap<String, usize>,
std::collections::BTreeMap<String, usize>,
) {
admin_provider_endpoints_pure::endpoint_key_counts_by_format(keys)
admin_provider_endpoints_pure::endpoint_key_counts_by_format(provider_type, endpoints, keys)
}
pub(super) fn normalize_endpoint_api_format(api_format: &str) -> String {
admin_provider_endpoints_pure::normalize_endpoint_api_format(api_format)
}
pub(super) fn build_admin_provider_endpoint_response(
@@ -4,7 +4,10 @@ use aether_data_contracts::repository::provider_catalog::{
};
use std::time::{SystemTime, UNIX_EPOCH};
use super::payloads::{build_admin_provider_endpoint_response, endpoint_key_counts_by_format};
use super::payloads::{
build_admin_provider_endpoint_response, endpoint_key_counts_by_format,
normalize_endpoint_api_format,
};
pub(crate) async fn build_admin_provider_endpoints_payload(
state: &AdminAppState<'_>,
@@ -38,7 +41,8 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
.await
.ok()
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) =
endpoint_key_counts_by_format(&provider.provider_type, &endpoints, &keys);
let now_unix_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.ok()
@@ -51,15 +55,16 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
.skip(skip)
.take(limit)
.map(|endpoint| {
let endpoint_api_format = normalize_endpoint_api_format(&endpoint.api_format);
build_admin_provider_endpoint_response(
&endpoint,
&provider.name,
total_keys_by_format
.get(endpoint.api_format.as_str())
.get(endpoint_api_format.as_str())
.copied()
.unwrap_or(0),
active_keys_by_format
.get(endpoint.api_format.as_str())
.get(endpoint_api_format.as_str())
.copied()
.unwrap_or(0),
now_unix_secs,
@@ -92,22 +97,27 @@ pub(crate) async fn build_admin_endpoint_payload(
.await
.ok()
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(
&provider.provider_type,
std::slice::from_ref(&endpoint),
&keys,
);
let now_unix_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.ok()
.map(|duration| duration.as_secs())
.unwrap_or(0);
let endpoint_api_format = normalize_endpoint_api_format(&endpoint.api_format);
Some(build_admin_provider_endpoint_response(
&endpoint,
&provider.name,
total_keys_by_format
.get(endpoint.api_format.as_str())
.get(endpoint_api_format.as_str())
.copied()
.unwrap_or(0),
active_keys_by_format
.get(endpoint.api_format.as_str())
.get(endpoint_api_format.as_str())
.copied()
.unwrap_or(0),
now_unix_secs,
@@ -1,7 +1,7 @@
use super::extractors::admin_endpoint_id;
use super::payloads::{
build_admin_provider_endpoint_response, endpoint_key_counts_by_format,
AdminProviderEndpointUpdatePatch,
normalize_endpoint_api_format, AdminProviderEndpointUpdatePatch,
};
use super::support::build_admin_endpoints_data_unavailable_response;
use crate::handlers::admin::request::{AdminAppState, AdminRequestContext};
@@ -147,18 +147,23 @@ pub(super) async fn maybe_handle(
.list_provider_catalog_keys_by_provider_ids(std::slice::from_ref(&provider.id))
.await
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(
&provider.provider_type,
std::slice::from_ref(&updated),
&keys,
);
let updated_api_format = normalize_endpoint_api_format(&updated.api_format);
Ok(Some(
Json(build_admin_provider_endpoint_response(
&updated,
&provider.name,
total_keys_by_format
.get(updated.api_format.as_str())
.get(updated_api_format.as_str())
.copied()
.unwrap_or(0),
active_keys_by_format
.get(updated.api_format.as_str())
.get(updated_api_format.as_str())
.copied()
.unwrap_or(0),
now_unix_secs,