Skip to main content

AppState

Struct AppState 

Source
pub struct AppState {
Show 17 fields pub config: Arc<Config>, pub sessions: SessionStore, pub agents: Arc<HashMap<AgentKind, Arc<dyn Agent>>>, pub bot_token: SlackApiToken, pub slack_client: Arc<SlackHyperClient>, pub repo_channels: Arc<RwLock<HashMap<String, String>>>, pub bot_user_id: Arc<String>, pub in_progress: Arc<Mutex<HashSet<String>>>, pub pending_repos: Arc<Mutex<HashMap<String, Instant>>>, pub pending_session_ids: Arc<Mutex<HashSet<String>>>, pub agent_handles: Arc<Mutex<HashMap<String, AgentHandle>>>, pub kill_senders: Arc<Mutex<HashMap<String, Sender<()>>>>, pub last_plan: Arc<Mutex<HashMap<String, String>>>, pub pending_answers: Arc<Mutex<HashMap<String, Sender<String>>>>, pub pending_tool_approvals: Arc<Mutex<HashMap<String, Sender<bool>>>>, pub rate_limiter: Arc<Mutex<HashMap<String, Instant>>>, pub thread_models: Arc<Mutex<HashMap<String, String>>>,
}
Expand description

Shared application state passed to all handlers.

Fields§

§config: Arc<Config>§sessions: SessionStore§agents: Arc<HashMap<AgentKind, Arc<dyn Agent>>>§bot_token: SlackApiToken§slack_client: Arc<SlackHyperClient>§repo_channels: Arc<RwLock<HashMap<String, String>>>

Repo name → channel ID mapping (populated on startup).

§bot_user_id: Arc<String>

Bot’s own user ID (to filter self-messages).

§in_progress: Arc<Mutex<HashSet<String>>>

Concurrency guard: set of thread_ts currently being processed.

§pending_repos: Arc<Mutex<HashMap<String, Instant>>>

Repos with in-flight new message processing (prevents sync from duplicating threads). Tracks repo name → timestamp when marked pending for cleanup.

§pending_session_ids: Arc<Mutex<HashSet<String>>>

Session IDs currently being claimed (not yet persisted to SessionStore). Prevents race between sync and handle_new_message where both try to claim the same session.

§agent_handles: Arc<Mutex<HashMap<String, AgentHandle>>>

Running agent processes: thread_ts → AgentHandle.

§kill_senders: Arc<Mutex<HashMap<String, Sender<()>>>>

Kill senders: thread_ts → oneshot kill signal. Stored separately so !stop can always reach the kill signal even when the handle is borrowed by a running task.

§last_plan: Arc<Mutex<HashMap<String, String>>>

Last detected plan content per thread: thread_ts → plan text.

§pending_answers: Arc<Mutex<HashMap<String, Sender<String>>>>

Pending question answers: thread_ts → oneshot sender for the user’s reply.

§pending_tool_approvals: Arc<Mutex<HashMap<String, Sender<bool>>>>

Pending tool approvals: thread_ts → oneshot sender for the user’s allow/deny.

§rate_limiter: Arc<Mutex<HashMap<String, Instant>>>

Per-channel rate limiter: channel_id → last write time.

§thread_models: Arc<Mutex<HashMap<String, String>>>

Per-thread model overrides from /model command: thread_ts → model ID.

Implementations§

Source§

impl AppState

Source

pub fn is_allowed_user(&self, user_id: &str) -> bool

Source

pub async fn repo_for_channel(&self, channel_id: &str) -> Option<String>

Look up which repo a channel belongs to.

Source

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

Atomically claim a new session for sync if:

  1. The session_id is not already owned by Hermes (in SessionStore or pending)
  2. The repo doesn’t have an in-flight new message

Returns true if the claim succeeded, false if already claimed. On success, the session_id is added to pending_session_ids (caller must remove it later).

Source

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

Release a claimed session ID (called after session is persisted to SessionStore).

Source

pub async fn cleanup_stale_pending_repos(&self)

Clean up repos that have been pending for too long (>5 minutes). This handles cases where PendingRepoGuard drop fails silently.

Source

pub fn is_live_mode(&self) -> bool

Whether we’re in “live” streaming mode (edit messages in real-time).

Source

pub async fn resolved_model( &self, repo_name: &str, thread_ts: Option<&str>, ) -> String

Resolve the model for a thread: thread override > repo config > global default.

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