mentedb_server/state.rs
1//! Shared application state for the MenteDB server.
2use mentedb::MenteDb;
3use mentedb_extraction::ExtractionConfig;
4use std::sync::Arc;
5use std::time::Instant;
6
7use crate::extraction_queue::ExtractionSender;
8
9#[derive(Clone)]
10pub struct AppState {
11 /// The default database (data directory root). Same handle as
12 /// `databases.default_db()`; kept for the gRPC, WebSocket and metrics
13 /// paths, which serve the default database only.
14 pub db: Arc<MenteDb>,
15 /// The default database plus the named per-tenant ones.
16 pub databases: Arc<crate::databases::Databases>,
17 /// Checks bearer tokens. `None` disables auth (development mode).
18 pub verifier: Option<Arc<crate::auth::TokenVerifier>>,
19 pub spaces: Arc<tokio::sync::RwLock<mentedb_core::SpaceManager>>,
20 /// HS256 secret for issuing tokens at /v1/auth/token. Unset when tokens
21 /// are verified with a public key only.
22 pub jwt_secret: Option<String>,
23 pub admin_key: Option<String>,
24 pub start_time: Instant,
25 /// Extraction pipeline configuration. `None` means no LLM provider configured.
26 pub extraction_config: Option<ExtractionConfig>,
27 /// When true, storing a conversation-type memory auto-runs extraction.
28 pub auto_extract: bool,
29 /// Bounded channel sender for the background extraction worker.
30 pub extraction_tx: Option<ExtractionSender>,
31 /// Self-organizing sharding handle. `None` unless `MENTEDB_SHARDING` is set.
32 pub cluster: Option<crate::cluster::Cluster>,
33 /// Per-agent delta trackers for `/v1/process_turn`, so delta-aware context
34 /// serving (only what changed since the agent's last turn) works across
35 /// requests instead of resetting every call.
36 pub turn_trackers:
37 Arc<tokio::sync::Mutex<std::collections::HashMap<String, mentedb::context::DeltaTracker>>>,
38}