llm_manager/config/
profiles.rs1use std::path::PathBuf;
2
3use crate::config::Profile;
4use crate::config::builtin_profiles;
5use crate::config::config_base_dir;
6use crate::config::store::NamedStore;
7
8pub fn profiles_config_dir() -> PathBuf {
10 config_base_dir().join("llm-manager").join("profiles")
11}
12
13pub fn unused_profiles_dir() -> PathBuf {
15 config_base_dir()
16 .join("llm-manager")
17 .join("unused_profiles")
18}
19
20#[derive(Debug, Clone)]
22pub struct ProfileStore {
23 inner: NamedStore<Profile>,
24}
25
26impl ProfileStore {
27 pub fn new() -> Self {
28 let profiles_dir = profiles_config_dir();
29 let unused_dir = unused_profiles_dir();
30 Self {
31 inner: NamedStore::new(profiles_dir, unused_dir),
32 }
33 }
34
35 pub fn save(&mut self, profile: &Profile) {
37 self.inner.save(&profile.name, profile)
38 }
39
40 pub fn insert_builtin(&mut self, profile: Profile) {
42 self.inner.insert_builtin(profile.name.clone(), profile)
43 }
44
45 pub fn delete(&mut self, name: &str) -> bool {
47 let builtin = builtin_profiles();
48 let names: Vec<String> = builtin.iter().map(|b| b.name.clone()).collect();
49 self.inner.delete(name, &names)
50 }
51
52 pub fn get(&self, name: &str) -> Option<&Profile> {
54 self.inner.get(name)
55 }
56
57 pub fn user_profiles(&self) -> Vec<Profile> {
59 let builtin = builtin_profiles();
60 let names: Vec<String> = builtin.iter().map(|b| b.name.clone()).collect();
61 self.inner.user_items(&names)
62 }
63
64 pub fn all(&self) -> Vec<Profile> {
66 let builtin = builtin_profiles();
67 let names: Vec<String> = builtin.iter().map(|b| b.name.clone()).collect();
68 self.inner.all(builtin, &names)
69 }
70}
71
72impl Default for ProfileStore {
73 fn default() -> Self {
74 Self::new()
75 }
76}