use super::*;
use std::env;
use std::ffi::OsString;
use std::fs;
pub fn selection_identity(path: &Path, id: &str) -> crate::config::ProviderIdentity {
crate::config::parse_config_base(&fs::read_to_string(path).unwrap())
.unwrap()
.resolve_provider_pin_identity(id)
.unwrap()
}
pub struct ModelEnvGuard {
saved: Vec<(&'static str, Option<OsString>)>,
}
impl ModelEnvGuard {
const VARS: &'static [&'static str] = &[
"CODEWHALE_MODEL",
"DEEPSEEK_MODEL",
"DEEPSEEK_DEFAULT_TEXT_MODEL",
"GLM_MODEL",
"BIGMODEL_MODEL",
"ZAI_MODEL",
"XAI_MODEL",
"GROK_MODEL",
"OPENROUTER_MODEL",
"OLLAMA_MODEL",
];
pub fn new() -> Self {
let saved = Self::VARS
.iter()
.map(|name| (*name, env::var_os(name)))
.collect();
unsafe {
for name in Self::VARS {
env::remove_var(name);
}
}
Self { saved }
}
}
impl Default for ModelEnvGuard {
fn default() -> Self {
Self::new()
}
}
impl Drop for ModelEnvGuard {
fn drop(&mut self) {
unsafe {
for (name, value) in &self.saved {
match value {
Some(value) => env::set_var(name, value),
None => env::remove_var(name),
}
}
}
}
}