1use std::fmt;
21
22use serde::Deserialize;
23
24use crate::db::Database;
25use crate::error::Error;
26
27#[derive(Debug)]
31pub enum TypedError {
32 Ffi(Error),
33 Json(serde_json::Error),
34}
35
36impl From<Error> for TypedError {
37 fn from(err: Error) -> Self {
38 TypedError::Ffi(err)
39 }
40}
41
42impl From<serde_json::Error> for TypedError {
43 fn from(err: serde_json::Error) -> Self {
44 TypedError::Json(err)
45 }
46}
47
48impl fmt::Display for TypedError {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 TypedError::Ffi(err) => fmt::Display::fmt(err, f),
52 TypedError::Json(err) => write!(f, "invalid Lite JSON response: {err}"),
53 }
54 }
55}
56
57impl std::error::Error for TypedError {
58 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
59 match self {
60 TypedError::Ffi(err) => Some(err),
61 TypedError::Json(err) => Some(err),
62 }
63 }
64}
65
66pub type TypedResult<T> = std::result::Result<T, TypedError>;
70
71#[derive(Debug, Clone, Deserialize)]
73pub struct StorageStatus {
74 pub format: String,
75 pub engine: String,
76 pub primary_layout: String,
77 pub replay_layout: String,
78 pub index_layout: String,
79 #[serde(default)]
80 pub index_namespace: Option<String>,
81 #[serde(default)]
82 pub format_version: Option<u32>,
83 #[serde(default)]
84 pub page_size: Option<u32>,
85 #[serde(default)]
86 pub active_checkpoint: Option<u8>,
87 #[serde(default)]
88 pub checkpoint_sequence: Option<u64>,
89 #[serde(default)]
90 pub page_count: Option<u64>,
91}
92
93#[derive(Debug, Clone, Deserialize)]
95pub struct MemoryAdmissionStats {
96 pub pressure: String,
97 pub denied_count: u64,
98 pub last_denied_ns: u64,
99 pub request_count: u64,
100 pub requested_host_bytes: u64,
101 pub requested_backend_bytes: u64,
102 pub requested_kv_bytes: u64,
103 pub requested_scratch_bytes: u64,
104 pub admitted_host_bytes: u64,
105 pub admitted_backend_bytes: u64,
106 pub host_limit_bytes: u64,
107 pub backend_limit_bytes: u64,
108 pub combined_limit_bytes: u64,
109 pub available_memory_bytes: u64,
110}
111
112#[derive(Debug, Clone, Deserialize)]
116pub struct InferenceStatus {
117 pub mode: String,
118 pub available_modes: Vec<String>,
119 pub configured: bool,
120 pub remote_provider_configured: bool,
121 pub local_runtime_configured: bool,
122 pub local_runtime_available: bool,
123 pub caller_supplied_artifacts: bool,
124 pub no_inference_configured_ok: bool,
125 pub host_budget_mb: u32,
126 pub backend_budget_mb: u32,
127 pub combined_budget_mb: u32,
128 pub kv_budget_mb: u32,
129 pub scratch_budget_mb: u32,
130 pub process_memory_budget_mb: u32,
131 pub process_memory_limit_bytes: u64,
132 pub process_memory_limit_source: String,
133 #[serde(default)]
134 pub memory_admission: Option<MemoryAdmissionStats>,
135}
136
137#[derive(Debug, Clone, Deserialize)]
139pub struct Capabilities {
140 pub freestanding_build: bool,
141 pub threading: String,
142 pub hosted_profile: bool,
143 pub manual_maintenance: bool,
144 pub background_enrichment_runtime: bool,
145 pub ttl_cleanup_runtime: bool,
146 pub transaction_recovery_runtime: bool,
147 pub local_template_rendering: bool,
148 pub remote_template_rendering: bool,
149 pub remote_template_host_callbacks: bool,
150 pub inference_mode: String,
151 pub supported_inference_modes: Vec<String>,
152 pub available_inference_modes: Vec<String>,
153 pub inference_required: bool,
154 pub no_inference_configured_ok: bool,
155 pub caller_supplied_artifacts: bool,
156 pub caller_supplied_embeddings: bool,
157 pub remote_inference_providers: bool,
158 pub local_inference_runtime: bool,
159 pub generated_enrichment_planning: bool,
160 pub text_search: bool,
161 pub dense_vector_search: bool,
162 pub sparse_vector_search: bool,
163 pub hybrid_search: bool,
164 pub graph_search: bool,
165 pub distributed_shard_ownership: bool,
166 pub raft_replication: bool,
167 pub cluster_placement: bool,
168 pub cross_node_joins: bool,
169 pub remote_shard_fanout: bool,
170 pub distributed_transaction_coordination: bool,
171 pub cluster_heartbeat_status_aggregation: bool,
172 pub server_side_autoscaling: bool,
173 pub kubernetes_operator: bool,
174 pub object_storage_primary: bool,
175}
176
177#[derive(Debug, Clone, Deserialize)]
182pub struct PendingWorkStatus {
183 #[serde(default)]
184 pub background_publications: serde_json::Value,
185 pub derived_target_sequence: u64,
186 pub has_async_indexes: bool,
187 pub portable_import_publication_in_progress: bool,
188 pub portable_import_recovery_required: bool,
189 pub portable_runtime_activation_pending: bool,
190 #[serde(default)]
191 pub enrichment: serde_json::Value,
192 #[serde(default)]
193 pub resolution: serde_json::Value,
194 #[serde(default)]
195 pub promotion: serde_json::Value,
196 #[serde(default)]
197 pub text_merge: serde_json::Value,
198 #[serde(default)]
199 pub replacements: Vec<serde_json::Value>,
200}
201
202#[derive(Debug, Clone, Deserialize)]
206pub struct Status {
207 pub storage: StorageStatus,
208 #[serde(default)]
209 pub stats: serde_json::Value,
210 pub pending_work: PendingWorkStatus,
211 pub inference: InferenceStatus,
212 pub capabilities: Capabilities,
213}
214
215#[derive(Debug, Clone, Deserialize)]
218pub struct ReplayGeneratedEnrichmentsResult {
219 pub replayed: u64,
220}
221
222impl Database {
223 pub fn status(&self) -> TypedResult<Status> {
225 let body = self.status_json()?;
226 Ok(serde_json::from_slice(&body)?)
227 }
228
229 pub fn pending_work_stats(&self) -> TypedResult<PendingWorkStatus> {
231 let body = self.pending_work_stats_json()?;
232 Ok(serde_json::from_slice(&body)?)
233 }
234
235 pub fn run_until_idle_status(&self) -> TypedResult<PendingWorkStatus> {
238 let body = self.run_until_idle_json()?;
239 Ok(serde_json::from_slice(&body)?)
240 }
241
242 pub fn replay_generated_enrichments(&self) -> TypedResult<ReplayGeneratedEnrichmentsResult> {
245 let body = self.replay_generated_enrichments_json()?;
246 Ok(serde_json::from_slice(&body)?)
247 }
248
249 pub fn capabilities(&self) -> TypedResult<Capabilities> {
251 let body = self.capabilities_json()?;
252 Ok(serde_json::from_slice(&body)?)
253 }
254}