Files
ForgeLM/tauri-app/src-tauri/src/model_library/paths.rs
T
Evandro Fonseca Junior 9a093dca15 feat: Tier-1 Model Manager with Hot-Swapping, HF Download Engine, bug fixes, and test repairs
- Phase 4: Hugging Face Download Engine — streaming GGUF downloads with progress, cancellation, and managed-model storage
- Phase 5: Model Source Validation — source-mode compatibility, path/file validation, inline error UI with recovery guidance
- Hot-swap: stop runtime → update model_path → restart atomic command
- Model library: folder open, delete model file, local model management
- SettingsPage unified hub: local models list + HF search with 3-state action buttons
- Bug fixes: send button text restored (4 failing tests), reasoning-toggle aria-label, Rust warnings
- All 89 tests passing, cargo check clean
2026-03-31 02:03:55 -03:00

53 lines
1.8 KiB
Rust

use std::path::{Path, PathBuf};
const MODEL_LIBRARY_DIR: &str = "model-library";
const INDEX_FILE: &str = "index.json";
const MANAGED_MODELS_DIR: &str = "managed-models";
const DEFAULT_MODELS_DIR: &str = "models";
/// Resolves the models directory from the user-configured `models_dir`.
/// - `None` → `./models` (relative to the app's working directory)
/// - `Some("")` → `./models`
/// - `Some(path)` → that exact path
pub fn resolve_models_dir(models_dir: Option<&str>) -> PathBuf {
match models_dir {
None | Some("") => PathBuf::from(DEFAULT_MODELS_DIR),
Some(path) => PathBuf::from(path),
}
}
pub fn model_library_dir(app_data_dir: &Path) -> PathBuf {
app_data_dir.join(MODEL_LIBRARY_DIR)
}
pub fn model_library_index_path(app_data_dir: &Path) -> PathBuf {
model_library_dir(app_data_dir).join(INDEX_FILE)
}
/// Legacy path for the managed-models location inside AppData.
/// Used only for index persistence — downloads now go to the user-configured
/// `models_dir` (defaults to `./models` in the project root).
pub fn managed_models_dir(app_data_dir: &Path) -> PathBuf {
model_library_dir(app_data_dir).join(MANAGED_MODELS_DIR)
}
#[cfg(test)]
mod tests {
use super::{managed_models_dir, model_library_dir, model_library_index_path};
#[test]
fn model_library_paths_live_under_app_data_dir() {
let root = std::path::Path::new("C:/Users/demo/AppData/Roaming/ForgeLM");
assert_eq!(model_library_dir(root), root.join("model-library"));
assert_eq!(
model_library_index_path(root),
root.join("model-library").join("index.json")
);
assert_eq!(
managed_models_dir(root),
root.join("model-library").join("managed-models")
);
}
}