pub struct ThreadManager { /* private fields */ }Expand description
Manages all agent threads with event emission.
Implementations§
Source§impl ThreadManager
impl ThreadManager
Sourcepub fn with_config(config: ThreadManagerConfig) -> Self
pub fn with_config(config: ThreadManagerConfig) -> Self
Create with custom config.
Sourcepub fn subscribe(&self) -> Receiver<ThreadEvent>
pub fn subscribe(&self) -> Receiver<ThreadEvent>
Subscribe to thread events.
Sourcepub fn create_chat(&mut self, label: impl Into<String>) -> ThreadId
pub fn create_chat(&mut self, label: impl Into<String>) -> ThreadId
Create a new chat thread and make it foreground.
Sourcepub fn create_subagent(
&mut self,
label: impl Into<String>,
agent_id: impl Into<String>,
task: impl Into<String>,
parent_id: Option<ThreadId>,
) -> ThreadId
pub fn create_subagent( &mut self, label: impl Into<String>, agent_id: impl Into<String>, task: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId
Create a sub-agent thread.
Sourcepub fn create_background(
&mut self,
label: impl Into<String>,
purpose: impl Into<String>,
parent_id: Option<ThreadId>,
) -> ThreadId
pub fn create_background( &mut self, label: impl Into<String>, purpose: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId
Create a background thread.
Sourcepub fn create_task(
&mut self,
label: impl Into<String>,
action: impl Into<String>,
parent_id: Option<ThreadId>,
) -> ThreadId
pub fn create_task( &mut self, label: impl Into<String>, action: impl Into<String>, parent_id: Option<ThreadId>, ) -> ThreadId
Create a task thread.
Sourcepub fn get(&self, id: ThreadId) -> Option<&AgentThread>
pub fn get(&self, id: ThreadId) -> Option<&AgentThread>
Get a thread by ID.
Sourcepub fn get_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>
pub fn get_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>
Get a mutable thread by ID.
Sourcepub fn foreground(&self) -> Option<&AgentThread>
pub fn foreground(&self) -> Option<&AgentThread>
Get the foreground thread.
Sourcepub fn foreground_mut(&mut self) -> Option<&mut AgentThread>
pub fn foreground_mut(&mut self) -> Option<&mut AgentThread>
Get the foreground thread mutably.
Sourcepub fn foreground_id(&self) -> Option<ThreadId>
pub fn foreground_id(&self) -> Option<ThreadId>
Get foreground thread ID.
Sourcepub fn list(&self) -> Vec<&AgentThread>
pub fn list(&self) -> Vec<&AgentThread>
List all threads.
Sourcepub fn list_info(&self) -> Vec<ThreadInfo>
pub fn list_info(&self) -> Vec<ThreadInfo>
List thread info for sidebar display.
Sourcepub fn set_description(&mut self, id: ThreadId, description: impl Into<String>)
pub fn set_description(&mut self, id: ThreadId, description: impl Into<String>)
Set description for a thread.
Sourcepub fn set_foreground_description(&mut self, description: impl Into<String>)
pub fn set_foreground_description(&mut self, description: impl Into<String>)
Set description for the foreground thread.
Sourcepub fn set_status(&mut self, id: ThreadId, status: ThreadStatus)
pub fn set_status(&mut self, id: ThreadId, status: ThreadStatus)
Update thread status.
Sourcepub fn switch_foreground(&mut self, id: ThreadId) -> bool
pub fn switch_foreground(&mut self, id: ThreadId) -> bool
Switch foreground to a different thread.
Sourcepub fn clear_foreground(&mut self)
pub fn clear_foreground(&mut self)
Clear the foreground — no thread is active (background all).
Sourcepub fn find_best_match(&self, content: &str) -> Option<ThreadId>
pub fn find_best_match(&self, content: &str) -> Option<ThreadId>
Find the best matching thread for a given message content. Returns the thread ID if a good match is found, None otherwise.
Sourcepub fn complete(
&mut self,
id: ThreadId,
summary: Option<String>,
result: Option<String>,
)
pub fn complete( &mut self, id: ThreadId, summary: Option<String>, result: Option<String>, )
Mark a thread as completed.
Sourcepub fn add_message(
&mut self,
id: ThreadId,
role: MessageRole,
content: impl Into<String>,
)
pub fn add_message( &mut self, id: ThreadId, role: MessageRole, content: impl Into<String>, )
Add a message to a thread.
Sourcepub fn add_foreground_message(
&mut self,
role: MessageRole,
content: impl Into<String>,
)
pub fn add_foreground_message( &mut self, role: MessageRole, content: impl Into<String>, )
Add a message to the foreground thread.
Sourcepub fn remove(&mut self, id: ThreadId) -> Option<AgentThread>
pub fn remove(&mut self, id: ThreadId) -> Option<AgentThread>
Remove a thread.
Sourcepub fn cleanup_ephemeral(&mut self)
pub fn cleanup_ephemeral(&mut self)
Clean up old ephemeral threads.
Sourcepub fn build_global_context(&self) -> String
pub fn build_global_context(&self) -> String
Build global context from all threads that share context.
Sourcepub fn save_to_file(&self, path: &Path) -> Result<()>
pub fn save_to_file(&self, path: &Path) -> Result<()>
Save threads to a file.
Sourcepub fn load_from_file(path: &Path) -> Result<Self>
pub fn load_from_file(path: &Path) -> Result<Self>
Load threads from a file.
Sourcepub fn load_or_default(path: &Path) -> Self
pub fn load_or_default(path: &Path) -> Self
Load from file or create with default chat thread.
Sourcepub fn create_thread(&mut self, label: impl Into<String>) -> ThreadId
pub fn create_thread(&mut self, label: impl Into<String>) -> ThreadId
Alias for create_chat (old API compatibility).
Sourcepub fn switch_to(&mut self, id: ThreadId) -> Option<ThreadId>
pub fn switch_to(&mut self, id: ThreadId) -> Option<ThreadId>
Alias for switch_foreground that returns old foreground ID (old API compatibility).
Sourcepub fn get_by_id(&self, id: ThreadId) -> Option<&AgentThread>
pub fn get_by_id(&self, id: ThreadId) -> Option<&AgentThread>
Get a thread by ID (compatibility - already exists as get()).
Sourcepub fn get_by_id_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>
pub fn get_by_id_mut(&mut self, id: ThreadId) -> Option<&mut AgentThread>
Get a mutable thread by ID (compatibility - already exists as get_mut()).