Skip to main content

systemprompt_files/config/
types.rs

1use serde::{Deserialize, Serialize};
2
3const DEFAULT_URL_PREFIX: &str = "/files";
4pub(super) const DEFAULT_MAX_FILE_SIZE_BYTES: u64 = 50 * 1024 * 1024;
5
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum FilePersistenceMode {
9    #[default]
10    ContextScoped,
11    UserLibrary,
12    Disabled,
13}
14
15#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
16#[allow(clippy::struct_excessive_bools)]
17pub struct AllowedFileTypes {
18    pub images: bool,
19    pub documents: bool,
20    pub audio: bool,
21    pub video: bool,
22}
23
24impl Default for AllowedFileTypes {
25    fn default() -> Self {
26        Self {
27            images: true,
28            documents: true,
29            audio: true,
30            video: false,
31        }
32    }
33}
34
35#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
36pub struct FileUploadConfig {
37    #[serde(default = "default_enabled")]
38    pub enabled: bool,
39    #[serde(default = "default_max_file_size")]
40    pub max_file_size_bytes: u64,
41    #[serde(default)]
42    pub persistence_mode: FilePersistenceMode,
43    #[serde(default)]
44    pub allowed_types: AllowedFileTypes,
45}
46
47const fn default_enabled() -> bool {
48    true
49}
50
51const fn default_max_file_size() -> u64 {
52    DEFAULT_MAX_FILE_SIZE_BYTES
53}
54
55impl Default for FileUploadConfig {
56    fn default() -> Self {
57        Self {
58            enabled: true,
59            max_file_size_bytes: DEFAULT_MAX_FILE_SIZE_BYTES,
60            persistence_mode: FilePersistenceMode::default(),
61            allowed_types: AllowedFileTypes::default(),
62        }
63    }
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct FilesConfigYaml {
69    #[serde(default = "default_url_prefix")]
70    pub url_prefix: String,
71    #[serde(default)]
72    pub upload: FileUploadConfig,
73}
74
75fn default_url_prefix() -> String {
76    DEFAULT_URL_PREFIX.to_string()
77}
78
79impl Default for FilesConfigYaml {
80    fn default() -> Self {
81        Self {
82            url_prefix: default_url_prefix(),
83            upload: FileUploadConfig::default(),
84        }
85    }
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub(super) struct FilesConfigWrapper {
90    #[serde(default)]
91    pub files: FilesConfigYaml,
92}