Skip to main content

context69_contracts/
settings.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use utoipa::ToSchema;
4
5use crate::search::SearchMode;
6
7#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
8pub struct SearchSettingsResponse {
9    pub mode: SearchMode,
10    pub rerank_enabled: bool,
11    pub rerank_base_url: String,
12    pub rerank_model: String,
13    pub candidate_limit: usize,
14    pub timeout_secs: u64,
15    pub has_api_key: bool,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
19pub struct UpdateSearchSettingsRequest {
20    pub mode: SearchMode,
21    pub rerank_enabled: bool,
22    pub rerank_base_url: String,
23    pub rerank_model: String,
24    pub candidate_limit: usize,
25    pub timeout_secs: u64,
26    #[serde(default)]
27    pub api_key: Option<String>,
28    #[serde(default)]
29    pub clear_api_key: bool,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
33pub struct RuntimeSettingsResponse {
34    pub qdrant: RuntimeQdrantSettings,
35    pub embedding: RuntimeEmbeddingSettings,
36    pub scheduler: RuntimeSchedulerSettings,
37    pub chunking: RuntimeChunkingSettings,
38    pub file_library: RuntimeFileLibrarySettings,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
42pub struct UpdateRuntimeSettingsRequest {
43    pub qdrant: RuntimeQdrantSettings,
44    pub embedding: UpdateRuntimeEmbeddingSettings,
45    pub scheduler: RuntimeSchedulerSettings,
46    pub chunking: RuntimeChunkingSettings,
47    pub file_library: UpdateRuntimeFileLibrarySettings,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
51pub struct RuntimeQdrantSettings {
52    pub url: String,
53    pub collection_name: String,
54    pub recreate_on_dimension_mismatch: bool,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
58pub struct RuntimeEmbeddingSettings {
59    pub base_url: String,
60    pub model: String,
61    pub dimensions: usize,
62    pub timeout_secs: u64,
63    pub has_api_key: bool,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
67pub struct UpdateRuntimeEmbeddingSettings {
68    pub base_url: String,
69    pub model: String,
70    pub dimensions: usize,
71    pub timeout_secs: u64,
72    #[serde(default, skip_serializing_if = "Option::is_none")]
73    pub api_key: Option<String>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
77pub struct RuntimeSchedulerSettings {
78    pub interval_secs: u64,
79    pub run_on_start: bool,
80    pub max_concurrency: usize,
81    pub job_id: String,
82    #[serde(default, skip_serializing_if = "Option::is_none")]
83    pub valkey_url: Option<String>,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
87pub struct TestRuntimeValkeyRequest {
88    pub valkey_url: String,
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
92#[serde(rename_all = "snake_case")]
93pub enum VectorIndexRebuildState {
94    Idle,
95    Running,
96    Succeeded,
97    Failed,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
101pub struct VectorIndexRebuildStatus {
102    pub state: VectorIndexRebuildState,
103    pub processed_chunks: usize,
104    pub total_chunks: usize,
105    #[serde(default, skip_serializing_if = "Option::is_none")]
106    pub error_message: Option<String>,
107    #[serde(default, skip_serializing_if = "Option::is_none")]
108    pub started_at: Option<DateTime<Utc>>,
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    pub finished_at: Option<DateTime<Utc>>,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
114pub struct RuntimeChunkingSettings {
115    pub max_chars: usize,
116    pub overlap_chars: usize,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
120pub struct RuntimeFileLibrarySettings {
121    pub storage_root: String,
122    pub max_upload_size_mb: usize,
123    pub max_upload_request_size_mb: usize,
124    pub ingest_concurrency: usize,
125    pub pdf_pages_per_task: u32,
126    pub url_import_concurrency: usize,
127    pub url_import_min_interval_ms: u64,
128    pub trusted_proxy_enabled: bool,
129    #[serde(default, skip_serializing_if = "Option::is_none")]
130    pub s3: Option<RuntimeS3SettingsResponse>,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
134pub struct UpdateRuntimeFileLibrarySettings {
135    pub storage_root: String,
136    pub max_upload_size_mb: usize,
137    pub max_upload_request_size_mb: usize,
138    pub ingest_concurrency: usize,
139    pub pdf_pages_per_task: u32,
140    pub url_import_concurrency: usize,
141    pub url_import_min_interval_ms: u64,
142    #[serde(default)]
143    pub trusted_proxy_enabled: bool,
144    #[serde(default, skip_serializing_if = "Option::is_none")]
145    pub s3: Option<UpdateRuntimeS3Settings>,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
149pub struct RuntimeS3SettingsResponse {
150    pub endpoint: String,
151    pub region: String,
152    pub bucket: String,
153    pub prefix: String,
154    pub path_style: bool,
155    pub access_key: String,
156    pub has_secret_key: bool,
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
160pub struct UpdateRuntimeS3Settings {
161    pub endpoint: String,
162    pub region: String,
163    pub bucket: String,
164    #[serde(default)]
165    pub prefix: String,
166    #[serde(default)]
167    pub path_style: bool,
168    pub access_key: String,
169    #[serde(default, skip_serializing_if = "Option::is_none")]
170    pub secret_key: Option<String>,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
174#[serde(rename_all = "snake_case")]
175pub enum DoclingSettingsSource {
176    Config,
177    Database,
178    Unconfigured,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
182pub struct DoclingSettingsResponse {
183    pub configured: bool,
184    pub source: DoclingSettingsSource,
185    pub connection: DoclingConnectionSettingsResponse,
186    pub vlm: DoclingVlmSettingsResponse,
187}
188
189#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
190pub struct UpdateDoclingSettingsRequest {
191    pub connection: UpdateDoclingConnectionSettings,
192    #[serde(default)]
193    pub vlm: UpdateDoclingVlmSettings,
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
197pub struct DoclingConnectionSettingsResponse {
198    #[serde(default, skip_serializing_if = "Option::is_none")]
199    pub base_url: Option<String>,
200    pub timeout_secs: u64,
201    pub poll_interval_secs: u64,
202    pub task_timeout_secs: u64,
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
206pub struct UpdateDoclingConnectionSettings {
207    pub base_url: String,
208    pub timeout_secs: u64,
209    pub poll_interval_secs: u64,
210    pub task_timeout_secs: u64,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
214pub struct DoclingVlmSettingsResponse {
215    #[serde(default, skip_serializing_if = "Option::is_none")]
216    pub openai_base_url: Option<String>,
217    pub has_api_key: bool,
218    #[serde(default, skip_serializing_if = "Option::is_none")]
219    pub vlm_pipeline_model: Option<String>,
220    #[serde(default, skip_serializing_if = "Option::is_none")]
221    pub picture_description_model: Option<String>,
222    #[serde(default, skip_serializing_if = "Option::is_none")]
223    pub code_formula_model: Option<String>,
224}
225
226#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Default)]
227pub struct UpdateDoclingVlmSettings {
228    #[serde(default, skip_serializing_if = "Option::is_none")]
229    pub openai_base_url: Option<String>,
230    #[serde(default, skip_serializing_if = "Option::is_none")]
231    pub api_key: Option<String>,
232    #[serde(default, skip_serializing_if = "Option::is_none")]
233    pub vlm_pipeline_model: Option<String>,
234    #[serde(default, skip_serializing_if = "Option::is_none")]
235    pub picture_description_model: Option<String>,
236    #[serde(default, skip_serializing_if = "Option::is_none")]
237    pub code_formula_model: Option<String>,
238}