use crate::models::Usage;
use crate::tui::app::App;
pub(super) fn cache_warmup_result(usage: &Usage) -> String {
let cache = match (
usage.prompt_cache_hit_tokens,
usage.prompt_cache_miss_tokens,
) {
(Some(hit), Some(miss)) => format!("Cache warmup complete: hit {hit} | miss {miss}"),
(Some(hit), None) => format!("Cache warmup complete: hit {hit} | miss unavailable"),
(None, Some(miss)) => format!("Cache warmup complete: hit unavailable | miss {miss}"),
(None, None) => "Cache warmup complete: cache telemetry unavailable".to_string(),
};
format!(
"{cache}\nNote: the first warmup is usually a miss. Later requests that reuse the same stable prefix may hit the provider cache; a hit is not guaranteed."
)
}
pub(super) fn prefix_stability_chip(app: &App) -> Option<(String, ratatui::style::Color)> {
let pct = app.prefix_stability_pct?;
let changes = app.prefix_change_count;
let color = if changes == 0 {
ratatui::style::Color::Green
} else if pct >= 95 {
ratatui::style::Color::Green
} else if pct >= 80 {
ratatui::style::Color::Yellow
} else {
ratatui::style::Color::Red
};
let label = if changes == 0 {
format!("P {pct}%")
} else {
format!(
"P {pct}% ({changes} change{})",
if changes == 1 { "" } else { "s" }
)
};
Some((label, color))
}
pub(super) fn available_models_message(current_model: &str, models: &[String]) -> String {
let mut lines = vec![format!("Available models ({})", models.len())];
for model in models {
if model == current_model {
lines.push(format!("* {model} (current)"));
} else {
lines.push(format!(" {model}"));
}
}
lines.join("\n")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn available_models_message_marks_current_model() {
let models = vec![
"deepseek-v4-pro".to_string(),
"deepseek-v4-flash".to_string(),
];
let msg = available_models_message("deepseek-v4-pro", &models);
assert!(msg.contains("* deepseek-v4-pro (current)"), "got: {msg}");
assert!(msg.contains(" deepseek-v4-flash"), "got: {msg}");
assert!(msg.starts_with("Available models (2)"), "got: {msg}");
}
#[test]
fn cache_warmup_result_handles_missing_telemetry() {
let usage = Usage {
prompt_cache_hit_tokens: None,
prompt_cache_miss_tokens: None,
..Default::default()
};
let msg = cache_warmup_result(&usage);
assert!(msg.contains("cache telemetry unavailable"), "got: {msg}");
}
}