pub struct PersistentConversationStore { /* private fields */ }Implementations§
Source§impl PersistentConversationStore
impl PersistentConversationStore
Sourcepub fn new_with_dir(
dir: impl AsRef<Path>,
default_model: ModelRef,
id_source: Arc<dyn IdSource>,
) -> Self
pub fn new_with_dir( dir: impl AsRef<Path>, default_model: ModelRef, id_source: Arc<dyn IdSource>, ) -> Self
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).
Sourcepub fn set_change_tx(&mut self, tx: UnboundedSender<ThreadId>)
pub fn set_change_tx(&mut self, tx: UnboundedSender<ThreadId>)
Set the change notification sender. Called after construction.
Sourcepub fn has_thread(&self, thread_id: &ThreadId<str>) -> bool
pub fn has_thread(&self, thread_id: &ThreadId<str>) -> bool
Whether metadata exists for this thread (in memory or on disk).
Sourcepub fn get_root_thread_id(&self, thread_id: &ThreadId<str>) -> ThreadId
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).
Sourcepub fn get_thread_parent_id(
&self,
thread_id: &ThreadId<str>,
) -> Option<ThreadId>
pub fn get_thread_parent_id( &self, thread_id: &ThreadId<str>, ) -> Option<ThreadId>
Get the parent thread ID, if any.
Sourcepub fn set_thread_title(&self, thread_id: &ThreadId<str>, title: &str)
pub fn set_thread_title(&self, thread_id: &ThreadId<str>, title: &str)
Set the title for a thread.
Sourcepub fn get_thread_model(&self, thread_id: &ThreadId<str>) -> ModelRef
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.
Sourcepub fn set_thread_model(&self, thread_id: &ThreadId<str>, model: ModelRef)
pub fn set_thread_model(&self, thread_id: &ThreadId<str>, model: ModelRef)
Set the model selected for a thread.
Sourcepub fn get_session_thread_ids(&self, root_id: &ThreadId<str>) -> Vec<ThreadId>
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.
Sourcepub fn get_open_subthreads(
&self,
parent_id: &ThreadId<str>,
) -> Vec<SubthreadInfo>
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.
pub fn get_total_tokens_used(&self, thread_id: &ThreadId<str>) -> usize
pub fn set_total_tokens_used(&self, thread_id: &ThreadId<str>, tokens: usize)
pub fn get_last_updated(&self, thread_id: &ThreadId<str>) -> String
pub fn set_last_updated(&self, thread_id: &ThreadId<str>, ts: &str)
Sourcepub fn set_view(
&self,
thread_id: &ThreadId<str>,
view_type: &str,
content: Value,
)
pub fn set_view( &self, thread_id: &ThreadId<str>, view_type: &str, content: Value, )
Update a view for a thread and persist.
Sourcepub fn get_views(&self, thread_id: &ThreadId<str>) -> HashMap<String, Value>
pub fn get_views(&self, thread_id: &ThreadId<str>) -> HashMap<String, Value>
Get all views for a thread.
pub fn get_thread_title(&self, thread_id: &ThreadId<str>) -> Option<String>
Sourcepub fn serialize_session(&self, root_thread_id: &ThreadId<str>) -> String
pub fn serialize_session(&self, root_thread_id: &ThreadId<str>) -> String
Serialize all threads in a session tree to a JSON string.
Sourcepub fn import_session(&self, data: &str) -> Result<(), MemoryError>
pub fn import_session(&self, data: &str) -> Result<(), MemoryError>
Import a serialized session into the store.
Trait Implementations§
Source§impl Clone for PersistentConversationStore
impl Clone for PersistentConversationStore
Source§impl ConversationStore for PersistentConversationStore
impl ConversationStore for PersistentConversationStore
type Error = MemoryError
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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 morefn 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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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.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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
up_to_order is Some(n),
only return summaries whose up_to_order is <= n.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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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,
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,
(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).