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