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