Skip to main content

ai_usagebar/custom/
types.rs

1//! The projected shape of a custom provider's response.
2//!
3//! Every built-in vendor has a `types.rs` that mirrors an upstream schema. A
4//! custom provider has no upstream schema to mirror — the schema is whatever
5//! the user pointed at — so what the rest of the program sees is this
6//! already-projected snapshot. It is also what the cache stores: the raw body
7//! is never persisted, so a cached payload cannot carry fields the user never
8//! asked to display, and the fallback parse is a plain `serde_json` round
9//! trip of this type.
10
11use chrono::{DateTime, Utc};
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct CustomSnapshot {
16    pub plan: Option<String>,
17    pub metrics: Vec<CustomMetric>,
18    pub texts: Vec<CustomText>,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22pub struct CustomMetric {
23    pub label: String,
24    /// `0..=100`, already rounded and clamped.
25    pub pct: u16,
26    /// `"12 of 100"` when the metric came from `used`/`limit`; `""` when the
27    /// provider only reported a percentage.
28    pub footnote: String,
29    pub resets_at: Option<DateTime<Utc>>,
30    pub window_secs: Option<u64>,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34pub struct CustomText {
35    pub label: String,
36    pub value: String,
37}