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 trusted_proxy_enabled: bool,
127    #[serde(default, skip_serializing_if = "Option::is_none")]
128    pub s3: Option<RuntimeS3SettingsResponse>,
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
132pub struct UpdateRuntimeFileLibrarySettings {
133    pub storage_root: String,
134    pub max_upload_size_mb: usize,
135    pub max_upload_request_size_mb: usize,
136    pub ingest_concurrency: usize,
137    pub pdf_pages_per_task: u32,
138    #[serde(default)]
139    pub trusted_proxy_enabled: bool,
140    #[serde(default, skip_serializing_if = "Option::is_none")]
141    pub s3: Option<UpdateRuntimeS3Settings>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
145pub struct RuntimeS3SettingsResponse {
146    pub endpoint: String,
147    pub region: String,
148    pub bucket: String,
149    pub prefix: String,
150    pub path_style: bool,
151    pub access_key: String,
152    pub has_secret_key: bool,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
156pub struct UpdateRuntimeS3Settings {
157    pub endpoint: String,
158    pub region: String,
159    pub bucket: String,
160    #[serde(default)]
161    pub prefix: String,
162    #[serde(default)]
163    pub path_style: bool,
164    pub access_key: String,
165    #[serde(default, skip_serializing_if = "Option::is_none")]
166    pub secret_key: Option<String>,
167}
168
169#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
170#[serde(rename_all = "snake_case")]
171pub enum DoclingSettingsSource {
172    Config,
173    Database,
174    Unconfigured,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
178pub struct DoclingSettingsResponse {
179    pub configured: bool,
180    pub source: DoclingSettingsSource,
181    pub connection: DoclingConnectionSettingsResponse,
182    pub vlm: DoclingVlmSettingsResponse,
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
186pub struct UpdateDoclingSettingsRequest {
187    pub connection: UpdateDoclingConnectionSettings,
188    #[serde(default)]
189    pub vlm: UpdateDoclingVlmSettings,
190}
191
192#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
193pub struct DoclingConnectionSettingsResponse {
194    #[serde(default, skip_serializing_if = "Option::is_none")]
195    pub base_url: Option<String>,
196    pub timeout_secs: u64,
197    pub poll_interval_secs: u64,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
201pub struct UpdateDoclingConnectionSettings {
202    pub base_url: String,
203    pub timeout_secs: u64,
204    pub poll_interval_secs: u64,
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
208pub struct DoclingVlmSettingsResponse {
209    #[serde(default, skip_serializing_if = "Option::is_none")]
210    pub openai_base_url: Option<String>,
211    pub has_api_key: bool,
212    #[serde(default, skip_serializing_if = "Option::is_none")]
213    pub vlm_pipeline_model: Option<String>,
214    #[serde(default, skip_serializing_if = "Option::is_none")]
215    pub picture_description_model: Option<String>,
216    #[serde(default, skip_serializing_if = "Option::is_none")]
217    pub code_formula_model: Option<String>,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Default)]
221pub struct UpdateDoclingVlmSettings {
222    #[serde(default, skip_serializing_if = "Option::is_none")]
223    pub openai_base_url: Option<String>,
224    #[serde(default, skip_serializing_if = "Option::is_none")]
225    pub api_key: Option<String>,
226    #[serde(default, skip_serializing_if = "Option::is_none")]
227    pub vlm_pipeline_model: Option<String>,
228    #[serde(default, skip_serializing_if = "Option::is_none")]
229    pub picture_description_model: Option<String>,
230    #[serde(default, skip_serializing_if = "Option::is_none")]
231    pub code_formula_model: Option<String>,
232}