use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CureCache {
pub updated_at: i64,
pub source: CureSource,
pub tools: HashMap<String, Vec<CuredModel>>,
}
impl CureCache {
pub fn is_stale(&self, max_age_secs: i64) -> bool {
let now = chrono::Utc::now().timestamp();
now - self.updated_at > max_age_secs
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CureSource {
OpenCodeCache,
OpenRouter,
Hardcoded,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CuredModel {
pub id: String,
pub display_name: String,
pub context_window: Option<u64>,
pub max_output: Option<u64>,
}
#[derive(Debug, thiserror::Error)]
pub enum CureError {
#[error("OpenCode cache not found at {path}")]
OpenCodeCacheNotFound { path: PathBuf },
#[error("failed to parse OpenCode cache: {0}")]
OpenCodeCacheParse(#[from] serde_json::Error),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("home directory could not be determined")]
NoHomeDir,
#[cfg(feature = "cure-network")]
#[error("OpenRouter request failed: {0}")]
OpenRouter(#[from] reqwest::Error),
#[cfg(feature = "cure-network")]
#[error("OpenRouter response malformed: {0}")]
OpenRouterParse(String),
}