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: SubscriberMapPer-thread subscriber lists for broadcasting display events.
rap_manager: SessionRapManagerPer-session RAP servers and toolsets (lazily booted).
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub async fn new(
state_dir: PathBuf,
callback_url: String,
) -> Result<Self, Box<dyn Error + Send + Sync>>
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.
Sourcepub async fn with_providers(
config: SessionManagerConfig,
providers: Vec<(String, Arc<dyn ModelProvider>)>,
provider_processes: Vec<Child>,
) -> Result<Self, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn init_remotes(&mut self, configs: Vec<RemoteConfig>)
pub fn init_remotes(&mut self, configs: Vec<RemoteConfig>)
Initialize remote daemon connections from config.
pub fn conversation_store(&self) -> &PersistentConversationStore
pub fn state_store(&self) -> &PersistentStateStore
Sourcepub fn broadcast(&self, msg: DaemonMessage)
pub fn broadcast(&self, msg: DaemonMessage)
Broadcast a message to all connected clients.
Sourcepub fn handle_view_update(
&self,
group_id: &ThreadId<str>,
view_type: &str,
content: Value,
)
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.
Sourcepub async fn create_session(
&self,
cwd: &Path,
model: ModelRef,
emit: &mut impl AsyncFnMut(DaemonMessage),
) -> Result<ThreadId, Box<dyn Error + Send + Sync>>
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.
Sourcepub async fn resume_session(
&self,
session_id: &ThreadId<str>,
thread_id: &ThreadId<str>,
emit: &mut impl AsyncFnMut(DaemonMessage),
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub async fn attach_client(
&self,
thread_id: &ThreadId<str>,
tx: UnboundedSender<DaemonMessage>,
wants_replay: bool,
keeps_session_alive: bool,
)
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).
Sourcepub async fn send_input(&self, msg: (InputMessage, Option<String>)) -> bool
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.
Sourcepub fn input_sender(&self) -> ChannelSender
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.
Sourcepub fn switch_model(
&self,
thread_id: &ThreadId<str>,
model: ModelRef,
requester: Option<&UnboundedSender<DaemonMessage>>,
) -> Result<(), String>
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.
Sourcepub async fn list_sessions(
&self,
subscribe: Option<UnboundedSender<DaemonMessage>>,
) -> HashMap<ThreadRef, SessionInfo>
pub async fn list_sessions( &self, subscribe: Option<UnboundedSender<DaemonMessage>>, ) -> HashMap<ThreadRef, SessionInfo>
List all sessions — active ones plus persisted ones from the cache.
Sourcepub async fn cleanup_session(&self, session_id: &ThreadId<str>)
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.
Sourcepub fn is_session_idle(&self, session_id: &ThreadId<str>) -> bool
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.
Sourcepub fn send_idle_ping(&self, session_id: &ThreadId<str>)
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.