pub struct ServerState {
pub sessions: Arc<DashMap<String, UserSession>>,
pub ws_tx: Sender<String>,
pub auth: Option<Arc<AuthState>>,
pub config_toml: Option<String>,
}Expand description
Shared state accessible by all axum handlers.
Fields§
§sessions: Arc<DashMap<String, UserSession>>Per-user session registry (TMU Phase 2).
ws_tx: Sender<String>Broadcast sender for backward compat — delegates to the default user’s channel.
New code should use user_ws_tx(user_key) instead.
auth: Option<Arc<AuthState>>Auth state (None = auth disabled, all endpoints open).
config_toml: Option<String>Shared config TOML (all users share the same agent config).
Implementations§
Source§impl ServerState
impl ServerState
Sourcepub fn new(
session: Session,
ws_tx: Sender<String>,
auth: Option<Arc<AuthState>>,
) -> Self
pub fn new( session: Session, ws_tx: Sender<String>, auth: Option<Arc<AuthState>>, ) -> Self
Create new shared state from a default session, broadcast sender, and optional auth.
The provided session becomes the "default" user’s session. When auth is
enabled, authenticated users get their own sessions created on demand.
Sourcepub fn with_config_toml(self, config_toml: String) -> Self
pub fn with_config_toml(self, config_toml: String) -> Self
Set the shared config TOML.
Sourcepub async fn ensure_user_session(
&self,
user_key: &str,
) -> (Arc<Mutex<Session>>, Sender<String>, Arc<MemoryTokenStore>)
pub async fn ensure_user_session( &self, user_key: &str, ) -> (Arc<Mutex<Session>>, Sender<String>, Arc<MemoryTokenStore>)
Get or create a session for the given user key, returning the session + ws_tx.
This is the main entry point for route handlers. It ensures the user has a session, spawns a drain task if newly created, and returns references to the session mutex, broadcast sender, and token store.
Sourcepub fn spawn_drain_task(self, workflow_rx: UnboundedReceiver<TuiMessage>)
pub fn spawn_drain_task(self, workflow_rx: UnboundedReceiver<TuiMessage>)
Spawn the default user’s drain task (backward compatibility).
Called during server startup for the initial session.
Sourcepub async fn resolve_user_key(&self, headers: &HeaderMap) -> String
pub async fn resolve_user_key(&self, headers: &HeaderMap) -> String
Resolve the user key from request headers.
Returns "default" when auth is disabled.
Returns the JWT sub claim (or dev:email for dev mode) when auth is enabled.
Trait Implementations§
Source§impl Clone for ServerState
impl Clone for ServerState
Source§fn clone(&self) -> ServerState
fn clone(&self) -> ServerState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more