Skip to main content

AppState

Struct AppState 

Source
pub struct AppState { /* private fields */ }
Expand description

Shared application state wrapped in Arc for use with Axum.

Implementations§

Source§

impl AppState

Source

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).

Source

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.

Source

pub async fn get_pending_approval(&self, id: &str) -> Option<PendingApproval>

Get metadata for a pending approval (without resolving it).

Source

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.

Source

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.

Source

pub async fn resolve_ask_user( &self, id: &str, answers: Option<Value>, cancelled: bool, ) -> Option<PendingAskUser>

Resolve a pending ask-user request.

Source

pub async fn get_pending_ask_user(&self, id: &str) -> Option<PendingAskUser>

Get metadata for a pending ask-user request.

Source

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.

Source

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.

Source

pub async fn get_pending_plan_approval( &self, id: &str, ) -> Option<PendingPlanApproval>

Get metadata for a pending plan approval.

Source

pub async fn clear_session_plan_approvals(&self, session_id: &str)

Clear all pending plan approvals for a session.

Source§

impl AppState

Source

pub async fn is_bridge_mode(&self) -> bool

Check if bridge mode is active (TUI owns execution, Web UI mirrors).

Source

pub async fn bridge_session_id(&self) -> Option<String>

Get the bridge session ID, if bridge mode is active.

Source

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.

Source

pub async fn clear_bridge_session(&self)

Deactivate bridge mode.

Source

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.

Source

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.

Source

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.

Source

pub async fn clear_injection_queue(&self, session_id: &str)

Remove the injection queue for a session.

Source

pub async fn set_agent_executor(&self, executor: Arc<dyn AgentExecutor>)

Set the agent executor implementation.

Source

pub async fn agent_executor(&self) -> Option<Arc<dyn AgentExecutor>>

Get the agent executor (if set).

Source§

impl AppState

Source

pub fn new( session_manager: SessionManager, config: AppConfig, working_dir: String, user_store: UserStore, model_registry: ModelRegistry, ) -> Self

Create a new AppState.

Source

pub async fn session_manager(&self) -> RwLockReadGuard<'_, SessionManager>

Get a read guard for the session manager.

Source

pub async fn session_manager_mut(&self) -> RwLockWriteGuard<'_, SessionManager>

Get a write guard for the session manager.

Source

pub async fn current_session_id(&self) -> Option<String>

Get the current session ID (if a session is loaded).

Source

pub async fn config(&self) -> RwLockReadGuard<'_, AppConfig>

Get a read guard for the app config.

Source

pub async fn config_mut(&self) -> RwLockWriteGuard<'_, AppConfig>

Get a write guard for the app config.

Source

pub fn working_dir(&self) -> &str

Get the working directory.

Source

pub fn user_store(&self) -> &UserStore

Get a reference to the user store.

Source

pub async fn model_registry(&self) -> RwLockReadGuard<'_, ModelRegistry>

Get a read guard for the model registry.

Source

pub async fn model_registry_mut(&self) -> RwLockWriteGuard<'_, ModelRegistry>

Get a write guard for the model registry.

Source

pub fn ws_sender(&self) -> Sender<WsBroadcast>

Get a clone of the broadcast sender.

Source

pub fn ws_subscribe(&self) -> Receiver<WsBroadcast>

Subscribe to WebSocket broadcasts.

Source

pub fn broadcast(&self, msg: WsBroadcast)

Broadcast a message to all WebSocket subscribers.

Source

pub async fn mode(&self) -> OperationMode

Get the current operation mode.

Source

pub async fn set_mode(&self, mode: OperationMode)

Set the operation mode.

Source

pub async fn autonomy_level(&self) -> String

Get the current autonomy level.

Source

pub async fn set_autonomy_level(&self, level: String)

Set the autonomy level.

Source

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.

Source

pub async fn clear_interrupt(&self)

Clear the interrupt flag.

Source

pub async fn is_interrupt_requested(&self) -> bool

Check if interrupt has been requested.

Source

pub async fn set_session_running(&self, session_id: String)

Mark a session as running.

Source

pub async fn set_session_idle(&self, session_id: &str)

Mark a session as idle.

Source

pub async fn is_session_running(&self, session_id: &str) -> bool

Check if a session is running.

Source

pub fn git_branch(&self) -> Option<String>

Get the git branch for the working directory.

Trait Implementations§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> AppState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more