pub struct AppState { /* private fields */ }Expand description
Shared application state wrapped in Arc for use with Axum.
Implementations§
Source§impl AppState
impl AppState
Sourcepub async fn add_pending_approval(
&self,
id: String,
approval: PendingApproval,
) -> Receiver<ApprovalResult>
pub async fn add_pending_approval( &self, id: String, approval: PendingApproval, ) -> Receiver<ApprovalResult>
Add a pending approval request.
Returns a oneshot::Receiver that the caller can .await to block
until the approval is resolved (or the state is torn down / interrupted).
Sourcepub async fn resolve_approval(
&self,
id: &str,
approved: bool,
auto_approve: bool,
) -> Option<PendingApproval>
pub async fn resolve_approval( &self, id: &str, approved: bool, auto_approve: bool, ) -> Option<PendingApproval>
Resolve a pending approval by sending through the oneshot channel.
Returns the approval metadata if found, None if not found or already resolved.
Sourcepub async fn get_pending_approval(&self, id: &str) -> Option<PendingApproval>
pub async fn get_pending_approval(&self, id: &str) -> Option<PendingApproval>
Get metadata for a pending approval (without resolving it).
Sourcepub async fn clear_session_approvals(&self, session_id: &str)
pub async fn clear_session_approvals(&self, session_id: &str)
Clear all pending approvals for a session (e.g. when session ends).
Sends rejection through the oneshot channels so any blocked agent tasks wake up rather than hanging forever.
Sourcepub async fn add_pending_ask_user(
&self,
id: String,
ask_user: PendingAskUser,
) -> Receiver<AskUserResult>
pub async fn add_pending_ask_user( &self, id: String, ask_user: PendingAskUser, ) -> Receiver<AskUserResult>
Add a pending ask-user request.
Returns a oneshot::Receiver that the agent can .await.
Sourcepub async fn resolve_ask_user(
&self,
id: &str,
answers: Option<Value>,
cancelled: bool,
) -> Option<PendingAskUser>
pub async fn resolve_ask_user( &self, id: &str, answers: Option<Value>, cancelled: bool, ) -> Option<PendingAskUser>
Resolve a pending ask-user request.
Sourcepub async fn get_pending_ask_user(&self, id: &str) -> Option<PendingAskUser>
pub async fn get_pending_ask_user(&self, id: &str) -> Option<PendingAskUser>
Get metadata for a pending ask-user request.
Sourcepub async fn add_pending_plan_approval(
&self,
id: String,
plan_approval: PendingPlanApproval,
) -> Receiver<PlanApprovalResult>
pub async fn add_pending_plan_approval( &self, id: String, plan_approval: PendingPlanApproval, ) -> Receiver<PlanApprovalResult>
Add a pending plan approval request.
Returns a oneshot::Receiver that the agent can .await to block
until the plan is approved, rejected, or revised.
Sourcepub async fn resolve_plan_approval(
&self,
id: &str,
action: String,
feedback: String,
) -> Option<PendingPlanApproval>
pub async fn resolve_plan_approval( &self, id: &str, action: String, feedback: String, ) -> Option<PendingPlanApproval>
Resolve a pending plan approval.
action is typically “approve”, “reject”, or “revise”.
feedback is optional textual feedback from the user.
Returns the plan-approval metadata if found, None if already resolved.
Sourcepub async fn get_pending_plan_approval(
&self,
id: &str,
) -> Option<PendingPlanApproval>
pub async fn get_pending_plan_approval( &self, id: &str, ) -> Option<PendingPlanApproval>
Get metadata for a pending plan approval.
Sourcepub async fn clear_session_plan_approvals(&self, session_id: &str)
pub async fn clear_session_plan_approvals(&self, session_id: &str)
Clear all pending plan approvals for a session.
Source§impl AppState
impl AppState
Sourcepub async fn is_bridge_mode(&self) -> bool
pub async fn is_bridge_mode(&self) -> bool
Check if bridge mode is active (TUI owns execution, Web UI mirrors).
Sourcepub async fn bridge_session_id(&self) -> Option<String>
pub async fn bridge_session_id(&self) -> Option<String>
Get the bridge session ID, if bridge mode is active.
Sourcepub async fn set_bridge_session(&self, session_id: String)
pub async fn set_bridge_session(&self, session_id: String)
Activate bridge mode for a given session.
While active, the Web UI should not start its own agent execution for this session; instead it should route messages to the TUI injector.
Sourcepub async fn clear_bridge_session(&self)
pub async fn clear_bridge_session(&self)
Deactivate bridge mode.
Sourcepub async fn is_bridge_guarded(&self, session_id: &str) -> bool
pub async fn is_bridge_guarded(&self, session_id: &str) -> bool
Check whether a mutation on a session should be blocked because the TUI owns it in bridge mode.
Returns true if the session is bridge-owned and should not be
mutated by the web server’s own agent executor.
Sourcepub async fn get_or_create_injection_queue(
&self,
session_id: &str,
) -> (Sender<String>, Option<Receiver<String>>)
pub async fn get_or_create_injection_queue( &self, session_id: &str, ) -> (Sender<String>, Option<Receiver<String>>)
Get or create the injection queue sender for a session.
Returns (sender, Option<receiver>). The receiver is Some only when the
queue was first created – the caller that creates the session’s agent loop
should take the receiver. Subsequent callers get None for the receiver.
Sourcepub async fn try_inject_message(
&self,
session_id: &str,
message: String,
) -> Result<(), String>
pub async fn try_inject_message( &self, session_id: &str, message: String, ) -> Result<(), String>
Try to inject a message into a running session’s queue.
Returns Ok(()) on success, Err(message) if queue is full or not found.
Sourcepub async fn clear_injection_queue(&self, session_id: &str)
pub async fn clear_injection_queue(&self, session_id: &str)
Remove the injection queue for a session.
Sourcepub async fn set_agent_executor(&self, executor: Arc<dyn AgentExecutor>)
pub async fn set_agent_executor(&self, executor: Arc<dyn AgentExecutor>)
Set the agent executor implementation.
Sourcepub async fn agent_executor(&self) -> Option<Arc<dyn AgentExecutor>>
pub async fn agent_executor(&self) -> Option<Arc<dyn AgentExecutor>>
Get the agent executor (if set).
Source§impl AppState
impl AppState
Sourcepub fn new(
session_manager: SessionManager,
config: AppConfig,
working_dir: String,
user_store: UserStore,
model_registry: ModelRegistry,
) -> Self
pub fn new( session_manager: SessionManager, config: AppConfig, working_dir: String, user_store: UserStore, model_registry: ModelRegistry, ) -> Self
Create a new AppState.
Sourcepub async fn session_manager(&self) -> RwLockReadGuard<'_, SessionManager>
pub async fn session_manager(&self) -> RwLockReadGuard<'_, SessionManager>
Get a read guard for the session manager.
Sourcepub async fn session_manager_mut(&self) -> RwLockWriteGuard<'_, SessionManager>
pub async fn session_manager_mut(&self) -> RwLockWriteGuard<'_, SessionManager>
Get a write guard for the session manager.
Sourcepub async fn current_session_id(&self) -> Option<String>
pub async fn current_session_id(&self) -> Option<String>
Get the current session ID (if a session is loaded).
Sourcepub async fn config(&self) -> RwLockReadGuard<'_, AppConfig>
pub async fn config(&self) -> RwLockReadGuard<'_, AppConfig>
Get a read guard for the app config.
Sourcepub async fn config_mut(&self) -> RwLockWriteGuard<'_, AppConfig>
pub async fn config_mut(&self) -> RwLockWriteGuard<'_, AppConfig>
Get a write guard for the app config.
Sourcepub fn working_dir(&self) -> &str
pub fn working_dir(&self) -> &str
Get the working directory.
Sourcepub fn user_store(&self) -> &UserStore
pub fn user_store(&self) -> &UserStore
Get a reference to the user store.
Sourcepub async fn model_registry(&self) -> RwLockReadGuard<'_, ModelRegistry>
pub async fn model_registry(&self) -> RwLockReadGuard<'_, ModelRegistry>
Get a read guard for the model registry.
Sourcepub async fn model_registry_mut(&self) -> RwLockWriteGuard<'_, ModelRegistry>
pub async fn model_registry_mut(&self) -> RwLockWriteGuard<'_, ModelRegistry>
Get a write guard for the model registry.
Sourcepub fn ws_sender(&self) -> Sender<WsBroadcast>
pub fn ws_sender(&self) -> Sender<WsBroadcast>
Get a clone of the broadcast sender.
Sourcepub fn ws_subscribe(&self) -> Receiver<WsBroadcast>
pub fn ws_subscribe(&self) -> Receiver<WsBroadcast>
Subscribe to WebSocket broadcasts.
Sourcepub fn broadcast(&self, msg: WsBroadcast)
pub fn broadcast(&self, msg: WsBroadcast)
Broadcast a message to all WebSocket subscribers.
Sourcepub async fn mode(&self) -> OperationMode
pub async fn mode(&self) -> OperationMode
Get the current operation mode.
Sourcepub async fn set_mode(&self, mode: OperationMode)
pub async fn set_mode(&self, mode: OperationMode)
Set the operation mode.
Sourcepub async fn autonomy_level(&self) -> String
pub async fn autonomy_level(&self) -> String
Get the current autonomy level.
Sourcepub async fn set_autonomy_level(&self, level: String)
pub async fn set_autonomy_level(&self, level: String)
Set the autonomy level.
Sourcepub async fn request_interrupt(&self)
pub async fn request_interrupt(&self)
Request an interrupt.
Also denies all pending approvals, ask-user, and plan-approval requests by sending rejection through their oneshot channels so blocked tasks wake up.
Sourcepub async fn clear_interrupt(&self)
pub async fn clear_interrupt(&self)
Clear the interrupt flag.
Sourcepub async fn is_interrupt_requested(&self) -> bool
pub async fn is_interrupt_requested(&self) -> bool
Check if interrupt has been requested.
Sourcepub async fn set_session_running(&self, session_id: String)
pub async fn set_session_running(&self, session_id: String)
Mark a session as running.
Sourcepub async fn set_session_idle(&self, session_id: &str)
pub async fn set_session_idle(&self, session_id: &str)
Mark a session as idle.
Sourcepub async fn is_session_running(&self, session_id: &str) -> bool
pub async fn is_session_running(&self, session_id: &str) -> bool
Check if a session is running.
Sourcepub fn git_branch(&self) -> Option<String>
pub fn git_branch(&self) -> Option<String>
Get the git branch for the working directory.