ChainManager

Struct ChainManager 

Source
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

Source

pub fn new() -> Self

Create a new chain manager with default config.

Source

pub fn with_config(config: ChainManagerConfig) -> Self

Create a new chain manager with specific config.

Source

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.

Source

pub fn create_chain_from_graph( &mut self, chain_id: Option<ChainId>, graph: TrajectoryGraph, ) -> Result<ChainId, ChainManagerError>

Create a chain from an existing graph.

Source

pub fn get_chain(&self, chain_id: &ChainId) -> Option<&BranchStateMachine>

Get a chain by ID (immutable).

Source

pub fn get_chain_mut( &mut self, chain_id: &ChainId, ) -> Option<&mut BranchStateMachine>

Get a chain by ID (mutable).

Source

pub fn get_metadata(&self, chain_id: &ChainId) -> Option<&ChainMetadata>

Get chain metadata.

Source

pub fn get_metadata_mut( &mut self, chain_id: &ChainId, ) -> Option<&mut ChainMetadata>

Get mutable chain metadata.

Source

pub fn contains(&self, chain_id: &ChainId) -> bool

Check if a chain exists.

Source

pub fn chain_ids(&self) -> impl Iterator<Item = &ChainId>

Get all chain IDs.

Source

pub fn chain_count(&self) -> usize

Get number of chains.

Source

pub fn active_chain(&self) -> Option<&ChainId>

Get the currently active chain ID.

Source

pub fn set_active_chain( &mut self, chain_id: ChainId, ) -> Result<(), ChainManagerError>

Set the active chain.

Source

pub fn get_active_chain(&self) -> Option<&BranchStateMachine>

Get the active chain (immutable).

Source

pub fn get_active_chain_mut(&mut self) -> Option<&mut BranchStateMachine>

Get the active chain (mutable).

Source

pub fn delete_chain(&mut self, chain_id: &ChainId) -> bool

Delete a chain.

Source

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.

Source

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.

Source

pub fn cleanup_inactive(&mut self, threshold: Duration)

Cleanup inactive chains.

Removes chains that haven’t been accessed within the threshold.

Source

pub fn deactivate_chain( &mut self, chain_id: &ChainId, ) -> Result<(), ChainManagerError>

Mark a chain as inactive.

Source

pub fn reactivate_chain( &mut self, chain_id: &ChainId, ) -> Result<(), ChainManagerError>

Reactivate a chain.

Source

pub fn stats(&self) -> ChainManagerStats

Get statistics about all managed chains.

Source

pub fn all_metadata(&self) -> impl Iterator<Item = &ChainMetadata>

Get all metadata.

Source

pub fn find_by_tag(&self, tag: &str) -> Vec<&ChainId>

Find chains by tag.

Source

pub fn find_by_title(&self, query: &str) -> Vec<&ChainId>

Find chains by title (partial match).

Trait Implementations§

Source§

impl Default for ChainManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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