Skip to main content

systemprompt_models/paths/
mod.rs

1//! Well-known directory layout helpers.
2//!
3//! [`AppPaths`] resolves the system, web, build, and storage path trees
4//! from a profile's [`crate::profile::PathsConfig`]. Submodules expose
5//! each tree plus shared directory/file-name constants.
6//! Resolution returns [`PathError`].
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11pub(crate) mod build;
12pub mod constants;
13mod error;
14mod storage;
15mod system;
16mod web;
17
18pub use build::BuildPaths;
19pub use constants::{cloud_container, dir_names, file_names};
20pub use error::PathError;
21pub use storage::StoragePaths;
22pub use system::SystemPaths;
23pub use web::WebPaths;
24
25use std::path::Path;
26
27use crate::profile::PathsConfig;
28use systemprompt_extension::AssetPaths;
29
30/// How profile paths are resolved against the local filesystem. Derive the
31/// right mode for a profile with [`crate::profile::Profile::path_resolution`].
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum PathResolution {
34    Canonicalize,
35    Lexical,
36}
37
38#[derive(Debug, Clone)]
39pub struct AppPaths {
40    system: SystemPaths,
41    web: WebPaths,
42    build: BuildPaths,
43    storage: StoragePaths,
44}
45
46impl AppPaths {
47    pub fn from_profile(
48        paths: &PathsConfig,
49        resolution: PathResolution,
50    ) -> Result<Self, PathError> {
51        Ok(Self {
52            system: SystemPaths::from_profile(paths, resolution)?,
53            web: WebPaths::from_profile(paths),
54            build: BuildPaths::from_profile(paths),
55            storage: StoragePaths::from_profile(paths)?,
56        })
57    }
58
59    pub const fn system(&self) -> &SystemPaths {
60        &self.system
61    }
62
63    pub const fn web(&self) -> &WebPaths {
64        &self.web
65    }
66
67    pub const fn build(&self) -> &BuildPaths {
68        &self.build
69    }
70
71    pub const fn storage(&self) -> &StoragePaths {
72        &self.storage
73    }
74}
75
76impl AssetPaths for AppPaths {
77    fn storage_files(&self) -> &Path {
78        self.storage.files()
79    }
80
81    fn web_dist(&self) -> &Path {
82        self.web.dist()
83    }
84}