#[non_exhaustive]pub struct SessionGraph {
pub thread_id: String,
pub events: Vec<GraphEvent>,
/* private fields */
}Expand description
Append-only event log for a single conversation thread.
events is the only first-class data — every higher-level view
(current branch messages, checkpoint markers, warning summaries) is
derived. Entries before archival_watermark may have been moved to
cold storage; consumers should treat indices < archival_watermark
as opaque.
#[non_exhaustive] so internal bookkeeping fields (e.g.
schema_version, archival metadata) can be added without
breaking downstream SessionLog impls. Construct via
SessionGraph::new(thread_id).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.thread_id: StringConversation identifier this log belongs to.
events: Vec<GraphEvent>All events in append order.
Implementations§
Source§impl SessionGraph
impl SessionGraph
Sourcepub fn append(&mut self, event: GraphEvent) -> usize
pub fn append(&mut self, event: GraphEvent) -> usize
Append one event to the log. Returns the index assigned to it.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Number of events currently in memory (excludes archived ranges).
Sourcepub fn events_since(&self, cursor: usize) -> &[GraphEvent]
pub fn events_since(&self, cursor: usize) -> &[GraphEvent]
Borrow the slice of events at indices >= cursor.
Sourcepub fn replay_into<S, R>(&self, initial: S, reducer: R) -> S
pub fn replay_into<S, R>(&self, initial: S, reducer: R) -> S
Derive a value of arbitrary type S by folding every event in
the log through reducer, oldest-first. The closure is called
once per event with (&mut state, &GraphEvent) so it can both
inspect and mutate the accumulator.
This is the closure form of “the audit log is the source of truth”: every domain that needs a derived view (message transcript, error count per turn, custom analytics) walks the log directly through this method rather than maintaining a parallel projection that could diverge.
Sourcepub fn current_branch_messages(&self) -> Vec<Message>
pub fn current_branch_messages(&self) -> Vec<Message>
Render the conversation as a Vec<Message> suitable for
ChatModel::complete. Only UserMessage and AssistantMessage
events contribute; tool events live inside the assistant’s content
blocks, which the codec handles separately.
Sourcepub fn fork(
&mut self,
branch_at: usize,
new_thread_id: impl Into<String>,
) -> Option<Self>
pub fn fork( &mut self, branch_at: usize, new_thread_id: impl Into<String>, ) -> Option<Self>
Fork: produce a fresh session whose events are a copy of this
session’s events at indices 0..=branch_at, bound to new_thread_id.
A BranchCreated event is appended to the parent to record the
fork point.
Returns None if branch_at is out of range.
Sourcepub const fn archive_before(&mut self, watermark: usize)
pub const fn archive_before(&mut self, watermark: usize)
Mark events at indices < watermark as archived. Does not actually
drop them from events — a persistence backend may purge them
during cold-storage migration. Watermarks are monotonic and
silently ignore non-advancing values: a watermark ≤ the
current archival point or beyond events.len() is a no-op
without error, mirroring crate::SessionLog::archive_before.
Sourcepub const fn archival_watermark(&self) -> usize
pub const fn archival_watermark(&self) -> usize
Effective archival cut-off.
Sourcepub fn branch_events(&self) -> impl Iterator<Item = (&str, usize)>
pub fn branch_events(&self) -> impl Iterator<Item = (&str, usize)>
Convenience iterator over BranchCreated events for tooling that
renders branch trees.
Trait Implementations§
Source§impl Clone for SessionGraph
impl Clone for SessionGraph
Source§fn clone(&self) -> SessionGraph
fn clone(&self) -> SessionGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more