Skip to main content

PersistentConversationStore

Struct PersistentConversationStore 

Source
pub struct PersistentConversationStore { /* private fields */ }

Implementations§

Source§

impl PersistentConversationStore

Source

pub fn new_with_dir( dir: impl AsRef<Path>, default_model: ModelRef, id_source: Arc<dyn IdSource>, ) -> PersistentConversationStore

Create a store that persists each thread to its own JSON file under dir. default_model is assigned to new threads and backfilled into metadata that predates per-thread model tracking. id_source generates ids for newly spawned threads (deterministic in tests).

Source

pub fn set_change_tx(&mut self, tx: UnboundedSender<ThreadId>)

Set the change notification sender. Called after construction.

Source

pub fn has_thread(&self, thread_id: &ThreadId<str>) -> bool

Whether metadata exists for this thread (in memory or on disk).

Source

pub fn get_root_thread_id(&self, thread_id: &ThreadId<str>) -> ThreadId

Resolve a thread ID to its root thread ID (i.e. the session ID).

Source

pub fn get_thread_parent_id( &self, thread_id: &ThreadId<str>, ) -> Option<ThreadId>

Get the parent thread ID, if any.

Source

pub fn set_thread_title(&self, thread_id: &ThreadId<str>, title: &str)

Set the title for a thread.

Source

pub fn get_thread_model(&self, thread_id: &ThreadId<str>) -> ModelRef

Get the model selected for this specific thread. Does NOT fall back to the parent thread — every thread is assigned a model at creation time.

Source

pub fn set_thread_model(&self, thread_id: &ThreadId<str>, model: ModelRef)

Set the model selected for a thread.

Source

pub fn get_session_thread_ids(&self, root_id: &ThreadId<str>) -> Vec<ThreadId>

List every thread in a session, including the root and descendants that are closed or used for compaction. Session-level state must still account for those threads even though they are omitted from the visible thread list.

Source

pub fn get_open_subthreads( &self, parent_id: &ThreadId<str>, ) -> Vec<SubthreadInfo>

List open (non-closed) subthreads that are descendants of parent_id within the given session. Walks the children tree via metadata.

Source

pub fn get_total_tokens_used(&self, thread_id: &ThreadId<str>) -> usize

Source

pub fn set_total_tokens_used(&self, thread_id: &ThreadId<str>, tokens: usize)

Source

pub fn get_last_updated(&self, thread_id: &ThreadId<str>) -> String

Source

pub fn set_last_updated(&self, thread_id: &ThreadId<str>, ts: &str)

Source

pub fn set_view( &self, thread_id: &ThreadId<str>, view_type: &str, content: Value, )

Update a view for a thread and persist.

Source

pub fn get_views(&self, thread_id: &ThreadId<str>) -> HashMap<String, Value>

Get all views for a thread.

Source

pub fn get_thread_title(&self, thread_id: &ThreadId<str>) -> Option<String>

Source

pub fn serialize_session(&self, root_thread_id: &ThreadId<str>) -> String

Serialize all threads in a session tree to a JSON string.

Source

pub fn import_session(&self, data: &str) -> Result<(), MemoryError>

Import a serialized session into the store.

Trait Implementations§

Source§

impl Clone for PersistentConversationStore

Source§

fn clone(&self) -> PersistentConversationStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConversationStore for PersistentConversationStore

Source§

type Error = MemoryError

Source§

fn ensure_root_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn thread_exists<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Return whether an exact root or child thread record exists without creating it.
Source§

fn load_history_up_to<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 ThreadId<str>, start_from: Option<i64>, up_to: Option<i64>, ) -> Pin<Box<dyn Future<Output = Result<Vec<InfinityMessage>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Load history for a session. Both bounds are counted in messages from the start of the thread: start_from skips that many leading messages, up_to truncates to that many leading messages (so start_from: Some(a), up_to: Some(b) yields the a-th through b-1-th messages, zero-based). None means unbounded. Read more
Source§

fn append_messages<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 ThreadId<str>, messages: Vec<(InfinityMessage, String)>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn spawn_thread<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, parent_thread_id: &'life1 ThreadId<str>, spawn_tool_call_id: &'life2 ToolCallId<str>, is_for_subscription_event: bool, context: SpawnContext, ) -> Pin<Box<dyn Future<Output = Result<ThreadId, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn is_thread_closed<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn close_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn is_subscription_event_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn is_fresh_context_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Whether thread_id was spawned with SpawnContext::Fresh (no inherited history). Fresh threads act as a boundary in load_history_with_ancestors: neither they nor their descendants see any context from before the fresh spawn.
Source§

fn get_thread_parent_info<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<Option<(ThreadId, ToolCallId)>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn get_ancestor_chain<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(ThreadId, i64)>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn save_compaction_summary<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, summary: &'life2 str, up_to_order: i64, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn load_latest_compaction_summary_up_to<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, up_to_order: Option<i64>, ) -> Pin<Box<dyn Future<Output = Result<Option<(String, i64)>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Load the latest compaction summary. When up_to_order is Some(n), only return summaries whose up_to_order is <= n.
Source§

fn is_compaction_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn mark_thread_as_compaction<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn get_thread_spawn_order<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<Option<i64>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, PersistentConversationStore: 'async_trait,

Source§

fn load_history_with_ancestors<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId<str>, ) -> Pin<Box<dyn Future<Output = Result<(Vec<InfinityMessage>, Option<i64>, usize), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Load full history for a thread including ancestor context and compaction. Walks backwards through ancestors to find the most recent compaction summary, skipping all earlier ancestors (their content is in the summary). Returns (history, leaf_compacted_up_to, ancestor_prefix_len) where the second element is the absolute store index the leaf thread’s compaction covers (if any), and the third is how many messages at the front of the history come from ancestors (not this thread’s own store).

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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