use crate::product::protocol::openai_models::ModelInfo;
use crate::product::protocol::openai_models::ModelVisibility;
use crate::product::protocol::openai_models::ModelsResponse;
use chrono::DateTime;
use chrono::Utc;
use serde_json::json;
use std::path::Path;
pub fn write_models_cache(lha_home: &Path) -> std::io::Result<()> {
let response: ModelsResponse =
serde_json::from_str(include_str!("../../agent_runtime/models.json"))
.map_err(std::io::Error::other)?;
let models: Vec<ModelInfo> = response
.models
.into_iter()
.filter(|model| model.visibility == ModelVisibility::List)
.collect();
write_models_cache_with_models(lha_home, models)
}
pub fn write_models_cache_with_models(
lha_home: &Path,
models: Vec<ModelInfo>,
) -> std::io::Result<()> {
let cache_path = lha_home.join("models_cache.json");
let fetched_at: DateTime<Utc> = Utc::now();
let cache = json!({
"fetched_at": fetched_at,
"etag": null,
"models": models
});
std::fs::write(cache_path, serde_json::to_string_pretty(&cache)?)
}