2026-07-11 13:16:10 +07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
pub enum InternetMode {
|
|
|
|
|
#[default]
|
|
|
|
|
Off,
|
|
|
|
|
ReadOnly,
|
|
|
|
|
Full,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl InternetMode {
|
|
|
|
|
pub fn can_fetch(&self) -> bool {
|
|
|
|
|
matches!(self, InternetMode::Full)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn can_download(&self) -> bool {
|
|
|
|
|
matches!(self, InternetMode::Full)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn can_search(&self) -> bool {
|
|
|
|
|
matches!(self, InternetMode::Full)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Settings {
|
|
|
|
|
pub internet_mode: InternetMode,
|
|
|
|
|
pub provider: String,
|
|
|
|
|
pub model: String,
|
|
|
|
|
pub api_key: Option<String>,
|
|
|
|
|
pub max_tokens: u32,
|
|
|
|
|
pub temperature: f32,
|
|
|
|
|
pub review_enabled: bool,
|
|
|
|
|
pub review_max_lessons_per_run: usize,
|
|
|
|
|
pub adaptive_review_max_skip: u32,
|
2026-07-11 21:06:22 +07:00
|
|
|
pub verify_command: Option<String>,
|
|
|
|
|
pub verify_timeout_ms: u64,
|
2026-07-11 13:16:10 +07:00
|
|
|
pub workflow_max_concurrency: usize,
|
|
|
|
|
pub session_archive_enabled: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Settings {
|
|
|
|
|
internet_mode: InternetMode::Off,
|
2026-07-11 22:10:17 +07:00
|
|
|
provider: "zen".to_string(),
|
|
|
|
|
model: "deepseek-v4-flash-free".to_string(),
|
2026-07-11 13:16:10 +07:00
|
|
|
api_key: None,
|
|
|
|
|
max_tokens: 8192,
|
|
|
|
|
temperature: 0.7,
|
|
|
|
|
review_enabled: true,
|
|
|
|
|
review_max_lessons_per_run: 5,
|
|
|
|
|
adaptive_review_max_skip: 3,
|
2026-07-11 21:06:22 +07:00
|
|
|
verify_command: None,
|
|
|
|
|
verify_timeout_ms: 30000,
|
2026-07-11 13:16:10 +07:00
|
|
|
workflow_max_concurrency: 5,
|
|
|
|
|
session_archive_enabled: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Settings {
|
|
|
|
|
pub fn load() -> Self {
|
|
|
|
|
let store = super::store::Store::new();
|
|
|
|
|
let path = store.base_dir.join("settings.json");
|
|
|
|
|
std::fs::read_to_string(path)
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| serde_json::from_str(&s).ok())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn save(&self) -> std::io::Result<()> {
|
|
|
|
|
let store = super::store::Store::new();
|
|
|
|
|
std::fs::create_dir_all(&store.base_dir)?;
|
|
|
|
|
let path = store.base_dir.join("settings.json");
|
|
|
|
|
let s = serde_json::to_string_pretty(self)?;
|
|
|
|
|
std::fs::write(path, s)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|