pub struct ChainManager { /* private fields */ }Expand description
Manager for multiple conversation chains.
Provides operations for creating, accessing, and managing multiple conversation state machines. Ported from DLM’s ChainManager.
§Example
let mut manager = ChainManager::new();
// Create a chain with auto-generated ID
let chain_id = manager.create_chain(None);
// Create a chain with specific ID
let chain_id = manager.create_chain(Some("my-chain".to_string()));
// Get chain for operations
if let Some(chain) = manager.get_chain_mut(&chain_id) {
chain.split(some_node)?;
}
// Merge two chains
manager.merge_chains(&chain1, &chain2)?;Implementations§
Source§impl ChainManager
impl ChainManager
Sourcepub fn with_config(config: ChainManagerConfig) -> Self
pub fn with_config(config: ChainManagerConfig) -> Self
Create a new chain manager with specific config.
Sourcepub fn create_chain(
&mut self,
chain_id: Option<ChainId>,
) -> Result<ChainId, ChainManagerError>
pub fn create_chain( &mut self, chain_id: Option<ChainId>, ) -> Result<ChainId, ChainManagerError>
Create a new conversation chain.
If chain_id is None, a unique ID is generated.
Returns the chain ID.
Sourcepub fn create_chain_from_graph(
&mut self,
chain_id: Option<ChainId>,
graph: TrajectoryGraph,
) -> Result<ChainId, ChainManagerError>
pub fn create_chain_from_graph( &mut self, chain_id: Option<ChainId>, graph: TrajectoryGraph, ) -> Result<ChainId, ChainManagerError>
Create a chain from an existing graph.
Sourcepub fn get_chain(&self, chain_id: &ChainId) -> Option<&BranchStateMachine>
pub fn get_chain(&self, chain_id: &ChainId) -> Option<&BranchStateMachine>
Get a chain by ID (immutable).
Sourcepub fn get_chain_mut(
&mut self,
chain_id: &ChainId,
) -> Option<&mut BranchStateMachine>
pub fn get_chain_mut( &mut self, chain_id: &ChainId, ) -> Option<&mut BranchStateMachine>
Get a chain by ID (mutable).
Sourcepub fn get_metadata(&self, chain_id: &ChainId) -> Option<&ChainMetadata>
pub fn get_metadata(&self, chain_id: &ChainId) -> Option<&ChainMetadata>
Get chain metadata.
Sourcepub fn get_metadata_mut(
&mut self,
chain_id: &ChainId,
) -> Option<&mut ChainMetadata>
pub fn get_metadata_mut( &mut self, chain_id: &ChainId, ) -> Option<&mut ChainMetadata>
Get mutable chain metadata.
Sourcepub fn chain_count(&self) -> usize
pub fn chain_count(&self) -> usize
Get number of chains.
Sourcepub fn active_chain(&self) -> Option<&ChainId>
pub fn active_chain(&self) -> Option<&ChainId>
Get the currently active chain ID.
Sourcepub fn set_active_chain(
&mut self,
chain_id: ChainId,
) -> Result<(), ChainManagerError>
pub fn set_active_chain( &mut self, chain_id: ChainId, ) -> Result<(), ChainManagerError>
Set the active chain.
Sourcepub fn get_active_chain(&self) -> Option<&BranchStateMachine>
pub fn get_active_chain(&self) -> Option<&BranchStateMachine>
Get the active chain (immutable).
Sourcepub fn get_active_chain_mut(&mut self) -> Option<&mut BranchStateMachine>
pub fn get_active_chain_mut(&mut self) -> Option<&mut BranchStateMachine>
Get the active chain (mutable).
Sourcepub fn delete_chain(&mut self, chain_id: &ChainId) -> bool
pub fn delete_chain(&mut self, chain_id: &ChainId) -> bool
Delete a chain.
Sourcepub fn merge_chains(
&mut self,
from: &ChainId,
into: &ChainId,
) -> Result<(), ChainManagerError>
pub fn merge_chains( &mut self, from: &ChainId, into: &ChainId, ) -> Result<(), ChainManagerError>
Merge two chains.
The from chain is merged into into, and then deleted.
Sourcepub fn split_chain(
&mut self,
chain_id: &ChainId,
node_id: NodeId,
) -> Result<ChainId, ChainManagerError>
pub fn split_chain( &mut self, chain_id: &ChainId, node_id: NodeId, ) -> Result<ChainId, ChainManagerError>
Split a chain at a node, creating a new chain.
Returns the ID of the new chain.
Sourcepub fn cleanup_inactive(&mut self, threshold: Duration)
pub fn cleanup_inactive(&mut self, threshold: Duration)
Cleanup inactive chains.
Removes chains that haven’t been accessed within the threshold.
Sourcepub fn deactivate_chain(
&mut self,
chain_id: &ChainId,
) -> Result<(), ChainManagerError>
pub fn deactivate_chain( &mut self, chain_id: &ChainId, ) -> Result<(), ChainManagerError>
Mark a chain as inactive.
Sourcepub fn reactivate_chain(
&mut self,
chain_id: &ChainId,
) -> Result<(), ChainManagerError>
pub fn reactivate_chain( &mut self, chain_id: &ChainId, ) -> Result<(), ChainManagerError>
Reactivate a chain.
Sourcepub fn stats(&self) -> ChainManagerStats
pub fn stats(&self) -> ChainManagerStats
Get statistics about all managed chains.
Sourcepub fn all_metadata(&self) -> impl Iterator<Item = &ChainMetadata>
pub fn all_metadata(&self) -> impl Iterator<Item = &ChainMetadata>
Get all metadata.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChainManager
impl RefUnwindSafe for ChainManager
impl Send for ChainManager
impl Sync for ChainManager
impl Unpin for ChainManager
impl UnwindSafe for ChainManager
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
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