pub struct AgentPool { /* private fields */ }Expand description
Manages a pool of long-lived agent processes keyed by auth token
Implementations§
Source§impl AgentPool
impl AgentPool
pub fn new(config: PoolConfig) -> Self
Sourcepub fn with_working_dir(self, dir: PathBuf) -> Self
pub fn with_working_dir(self, dir: PathBuf) -> Self
Set the working directory for spawned agent processes.
Sourcepub fn with_push_relay(self, push_relay: Arc<PushRelayClient>) -> Self
pub fn with_push_relay(self, push_relay: Arc<PushRelayClient>) -> Self
Set the push relay client for sending notifications
Sourcepub async fn get_or_spawn(
&mut self,
token: &str,
agent_command: &str,
) -> Result<(Sender<String>, Receiver<String>, Vec<String>, bool, Option<String>, Option<String>, Sender<String>)>
pub async fn get_or_spawn( &mut self, token: &str, agent_command: &str, ) -> Result<(Sender<String>, Receiver<String>, Vec<String>, bool, Option<String>, Option<String>, Sender<String>)>
Get an existing agent or spawn a new one for the given token. Returns (ws_to_agent_tx, agent_to_ws_rx, buffered_messages, was_reused, cached_init_response, cached_session_response, broadcast_tx)
Sourcepub fn mark_disconnected(&mut self, token: &str)
pub fn mark_disconnected(&mut self, token: &str)
Mark a client as disconnected. The agent stays alive for idle_timeout.
Sourcepub fn cache_init_response(&mut self, token: &str, response: String)
pub fn cache_init_response(&mut self, token: &str, response: String)
Cache the agent’s initialize response so reconnections can skip re-initialization
Sourcepub fn cache_session_response(&mut self, token: &str, response: String)
pub fn cache_session_response(&mut self, token: &str, response: String)
Cache the agent’s createSession response so reconnections reuse the same session ID
Sourcepub fn clear_session_response(&mut self, token: &str)
pub fn clear_session_response(&mut self, token: &str)
Clear the cached session response (e.g., when agent reports “Session not found”)
Sourcepub async fn remove_agent(&mut self, token: &str)
pub async fn remove_agent(&mut self, token: &str)
Remove and kill an agent
Sourcepub async fn reap_idle_agents(&mut self)
pub async fn reap_idle_agents(&mut self)
Check for idle agents that have exceeded the timeout and kill them
Sourcepub fn contains(&self, token: &str) -> bool
pub fn contains(&self, token: &str) -> bool
Check if the pool contains an agent for the given token
Sourcepub async fn kill_agent(&mut self, token: &str) -> bool
pub async fn kill_agent(&mut self, token: &str) -> bool
Kill a specific agent’s process (for testing). Returns true if the agent existed.
Sourcepub fn buffer_message(&mut self, token: &str, message: String)
pub fn buffer_message(&mut self, token: &str, message: String)
Buffer a message for a disconnected agent
Sourcepub async fn shutdown_all(&mut self)
pub async fn shutdown_all(&mut self)
Shut down all agents in the pool
Auto Trait Implementations§
impl Freeze for AgentPool
impl !RefUnwindSafe for AgentPool
impl Send for AgentPool
impl Sync for AgentPool
impl Unpin for AgentPool
impl UnsafeUnpin for AgentPool
impl !UnwindSafe for AgentPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more