|
| 1 | +use baml_ids::ProjectId; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | +use ts_rs::TS; |
| 4 | + |
| 5 | +use crate::{base::EpochMsTimestamp, rpc::ApiEndpoint}; |
| 6 | + |
| 7 | +#[derive(Debug, Serialize, Deserialize, TS)] |
| 8 | +#[ts(export)] |
| 9 | +pub struct GetCostStatsRequest { |
| 10 | + #[ts(type = "string")] |
| 11 | + pub project_id: ProjectId, |
| 12 | + #[ts(type = "FilterExpression<number>", optional)] |
| 13 | + pub start_time: |
| 14 | + Option<super::ui_function_calls::FilterExpression<crate::base::EpochMsTimestamp>>, |
| 15 | + #[ts(type = "FilterExpression<number>", optional)] |
| 16 | + pub end_time: Option<super::ui_function_calls::FilterExpression<crate::base::EpochMsTimestamp>>, |
| 17 | + #[ts(optional)] |
| 18 | + pub relative_time: Option<super::ui_function_calls::RelativeTime>, |
| 19 | + #[ts(optional)] |
| 20 | + pub function_name: Option<super::ui_function_calls::FilterExpression<String>>, |
| 21 | + #[ts(optional)] |
| 22 | + pub status: Option< |
| 23 | + super::ui_function_calls::FilterExpression<super::ui_function_calls::FunctionCallStatus>, |
| 24 | + >, |
| 25 | + #[ts(optional)] |
| 26 | + pub tags: Option<Vec<super::ui_function_calls::TagFilter>>, |
| 27 | +} |
| 28 | + |
| 29 | +#[derive(Debug, Serialize, Deserialize, TS)] |
| 30 | +#[ts(export)] |
| 31 | +pub struct TimeSeriesFloatPoint { |
| 32 | + #[ts(type = "number")] |
| 33 | + pub interval_start: EpochMsTimestamp, |
| 34 | + pub value: f64, |
| 35 | +} |
| 36 | + |
| 37 | +#[derive(Debug, Serialize, Deserialize, TS)] |
| 38 | +#[ts(export)] |
| 39 | +pub struct MetricSeriesFloat { |
| 40 | + pub total: f64, |
| 41 | + pub series: Vec<TimeSeriesFloatPoint>, |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Debug, Serialize, Deserialize, TS)] |
| 45 | +#[ts(export)] |
| 46 | +pub struct CostByClientBreakdownItem { |
| 47 | + pub client_name: String, |
| 48 | + pub total_cost: f64, |
| 49 | +} |
| 50 | + |
| 51 | +#[derive(Debug, Serialize, Deserialize, TS)] |
| 52 | +#[ts(export)] |
| 53 | +pub struct GetCostStatsResponse { |
| 54 | + pub total_cost: MetricSeriesFloat, |
| 55 | + pub cost_by_client: Vec<CostByClientBreakdownItem>, |
| 56 | +} |
| 57 | + |
| 58 | +pub struct GetCostStats; |
| 59 | + |
| 60 | +impl ApiEndpoint for GetCostStats { |
| 61 | + type Request<'a> = GetCostStatsRequest; |
| 62 | + type Response<'a> = GetCostStatsResponse; |
| 63 | + |
| 64 | + const PATH: &'static str = "/v1/dashboard/cost"; |
| 65 | +} |
0 commit comments