mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 10:57:03 +08:00
feat: add selectable routing groups and composite billing
Support per-model provider enablement and compact model editing. Capture request-time billing factors, charge customer costs separately, and preserve historical statistics without backfills.
This commit is contained in:
@@ -159,6 +159,12 @@ async fn perform_stats_aggregation_for_day(
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
sqlx::query(UPDATE_STATS_DAILY_BILLING_COST_SQL)
|
||||
.bind(day_start_utc)
|
||||
.bind(day_end_utc)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
let model_rows =
|
||||
upsert_stats_daily_model_rows(&mut tx, day_start_utc, day_end_utc, now_utc).await?;
|
||||
let provider_rows =
|
||||
|
||||
@@ -2404,6 +2404,18 @@ WHERE created_at >= $1
|
||||
AND provider_name NOT IN ('unknown', 'pending')
|
||||
"#;
|
||||
|
||||
// Keep customer consumption separate from the upstream procurement-cost rollup.
|
||||
pub(super) const UPDATE_STATS_DAILY_BILLING_COST_SQL: &str = r#"
|
||||
UPDATE stats_daily SET billing_cost=(
|
||||
SELECT round(COALESCE(sum(billable_amount),0),8)
|
||||
FROM usage_analytics_facts_v1
|
||||
WHERE created_at >= $1 AND created_at < $2
|
||||
AND status NOT IN ('pending','streaming')
|
||||
AND provider_name NOT IN ('unknown','pending')
|
||||
)
|
||||
WHERE date=$1
|
||||
"#;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
|
||||
Reference in New Issue
Block a user