Skip to main content

codetether_agent/tui/app/smart_switch/
helpers.rs

1//! Small helper functions for smart switch.
2
3use crate::tui::constants::SMART_SWITCH_MAX_RETRIES;
4
5/// Returns the max number of smart switch retries (from env or default).
6pub fn smart_switch_max_retries() -> u8 {
7    std::env::var("CODETETHER_SMART_SWITCH_MAX_RETRIES")
8        .ok()
9        .and_then(|v| v.parse::<u8>().ok())
10        .map(|v| v.clamp(1, 10))
11        .unwrap_or(SMART_SWITCH_MAX_RETRIES)
12}
13
14/// Extracts provider name from a model reference (e.g. "minimax/MiniMax-M2" -> "minimax").
15pub fn extract_provider_from_model(model_ref: &str) -> Option<&str> {
16    model_ref.split('/').next().filter(|p| !p.is_empty())
17}
18
19/// Returns true when the model changed compared to the current session model.
20pub fn should_execute_smart_switch(
21    current_model: Option<&str>,
22    pending: Option<&super::retry::PendingSmartSwitchRetry>,
23) -> bool {
24    match (current_model, pending) {
25        (Some(current), Some(retry)) => current != retry.target_model,
26        (_, Some(_)) => true,
27        _ => false,
28    }
29}