Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager {
    pub session_store: SessionStoreHandle,
    pub catalog: Arc<ModelCatalog>,
    pub remote_daemons: Option<RemoteDaemons>,
    pub subscriber_map: SubscriberMap,
    pub rap_manager: SessionRapManager,
    /* private fields */
}
Expand description

Manages all sessions on top of a single, daemon-lifetime agent system.

The agent system itself never shuts down: threads idle out individually and respawn on demand, so message delivery never races a teardown. What starts and stops with session activity are the session’s RAP tool servers, managed lazily by SessionRapManager — “shutting down” a session just means stopping its servers (they reboot transparently on the next tool invocation) and flagging it in the session store.

Fields§

§session_store: SessionStoreHandle§catalog: Arc<ModelCatalog>

Registered model providers and their available models.

§remote_daemons: Option<RemoteDaemons>

Remote daemon connections.

§subscriber_map: SubscriberMap

Per-thread subscriber lists for broadcasting display events.

§rap_manager: SessionRapManager

Per-session RAP servers and toolsets (lazily booted).

Implementations§

Source§

impl SessionManager

Source

pub async fn new( state_dir: PathBuf, callback_url: String, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Build a manager with the production defaults: providers are spawned from ~/.infinity/providers.json and the user-level RAP config is ~/.infinity/rap.json.

Source

pub async fn with_providers( config: SessionManagerConfig, providers: Vec<(String, Arc<dyn ModelProvider>)>, provider_processes: Vec<Child>, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Build a manager from explicit (provider_id, provider) pairs instead of spawning provider processes from the on-disk config. This is the generic constructor used by tests (e.g. with an in-process mock provider); provider_processes are held for the manager’s lifetime and killed on drop.

Source

pub fn init_remotes(&mut self, configs: Vec<RemoteConfig>)

Initialize remote daemon connections from config.

Source

pub fn conversation_store(&self) -> &PersistentConversationStore

Source

pub fn state_store(&self) -> &PersistentStateStore

Source

pub fn broadcast(&self, msg: DaemonMessage)

Broadcast a message to all connected clients.

Source

pub fn handle_view_update( &self, group_id: &ThreadId<str>, view_type: &str, content: Value, )

Handle a view_update RAP callback: persist the view and broadcast to subscribers.

Source

pub async fn create_session( &self, cwd: &Path, model: ModelRef, emit: &mut impl AsyncFnMut(DaemonMessage), ) -> Result<ThreadId, Box<dyn Error + Send + Sync>>

Create a brand new session with the given working directory and model. The model is not validated here; if it is no longer available when the agent runs, the thread worker falls back to the default model.

Source

pub async fn resume_session( &self, session_id: &ThreadId<str>, thread_id: &ThreadId<str>, emit: &mut impl AsyncFnMut(DaemonMessage), ) -> Result<(), Box<dyn Error + Send + Sync>>

Resume a persisted session, recovering its cwd from the session store. Does NOT boot the agent loop — that happens lazily on first user input via send_input. This just emits Connected so the client can attach.

Source

pub async fn attach_client( &self, thread_id: &ThreadId<str>, tx: UnboundedSender<DaemonMessage>, wants_replay: bool, keeps_session_alive: bool, )

Attach a client’s message sender to a thread for receiving display events. The request is routed to the thread’s driver (spawning one if none is live) and resolves once the subscriber is installed — its replay sent and its registration completed — so input sent afterwards is guaranteed to be observed by the client.

keeps_session_alive: when false, this subscriber will not prevent the session from going idle (and its RAP servers being stopped).

Source

pub async fn send_input(&self, msg: (InputMessage, Option<String>)) -> bool

Send an input message to the agent system.

All input surfaces enqueue blindly. The router drops event-style input for unknown or stopped threads, while user text may create or resume a thread. A resulting Live lifecycle transition clears the root session’s idle and stopped flags, including when a child thread wakes.

Source

pub fn input_sender(&self) -> ChannelSender

The agent system’s input sender, used by the RAP callback bridge to forward converted callbacks directly into the input queue. The router owns thread-existence and stopped-thread admission.

Source

pub fn switch_model( &self, thread_id: &ThreadId<str>, model: ModelRef, requester: Option<&UnboundedSender<DaemonMessage>>, ) -> Result<(), String>

Switch the model used for future requests on a specific thread. The switch affects only thread_id — it does not propagate to child threads.

The selection is validated against the catalog and persisted in the conversation store; every completion round resolves the persisted selection when it starts (via CatalogModelSource), so the switch takes effect on the thread’s next round — an in-flight completion finishes on the model it started with.

The DaemonMessage::ModelSwitched confirmation is broadcast to the thread’s subscribers, and delivered to requester as well when the requester is not already among those subscribers — so the requesting client sees the confirmation exactly once whether or not it is attached.

Source

pub async fn list_sessions( &self, subscribe: Option<UnboundedSender<DaemonMessage>>, ) -> HashMap<ThreadRef, SessionInfo>

List all sessions — active ones plus persisted ones from the cache.

Source

pub async fn cleanup_session(&self, session_id: &ThreadId<str>)

Shut down a session: stop its RAP servers, drop its cached toolset (so a later restart re-reads the RAP config), clear pending choices, and mark it shut down in the store.

The agent system keeps running — a thread that is mid-completion finishes and flushes its turn, then parks. Sending new user input clears the flag and picks the session back up (its servers reboot lazily); RAP callbacks arriving while shut down are ignored.

Source

pub fn is_session_idle(&self, session_id: &ThreadId<str>) -> bool

Returns true if the session has no active threads: none with a live driver and none waiting on subscription events.

Source

pub fn send_idle_ping(&self, session_id: &ThreadId<str>)

Request an idle re-evaluation for a session (e.g. after a client disconnect): if none of its threads are live and no keep-alive client remains, its RAP servers are stopped.

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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