Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

High-level session wrapper, matching pi’s Session class.

Owns a SessionStorage and provides entry construction, context building, branch navigation, and metadata access. All append_* methods generate typed entries with auto-generated IDs, parent chains, and timestamps.

Implementations§

Source§

impl Session

Source

pub fn new(storage: Box<dyn SessionStorage>) -> Self

Wrap an existing storage backend.

Source

pub fn get_storage(&self) -> &dyn SessionStorage

Access the underlying storage.

Source

pub fn get_storage_mut(&mut self) -> &mut dyn SessionStorage

Mutably access the underlying storage.

Source

pub fn into_storage(self) -> Box<dyn SessionStorage>

Consume and return the underlying storage.

Source

pub fn metadata(&self) -> SessionMetadata

Source

pub fn get_leaf_id(&self) -> Option<String>

Source

pub fn get_entry(&self, id: &str) -> Option<SessionEntry>

Source

pub fn get_entries(&self) -> Vec<SessionEntry>

Source

pub fn find_entries(&self, type_name: &str) -> Vec<SessionEntry>

Source

pub fn get_label(&self, id: &str) -> Option<String>

Source

pub fn get_branch( &self, from_id: Option<&str>, ) -> Result<Vec<SessionEntry>, String>

Get the path from root to the given leaf (or current leaf if None). Pi-compatible: delegates to storage’s get_path_to_root.

Source

pub fn build_context(&self) -> SessionContext

Build the session context (messages + metadata) for the LLM. Pi-compatible: uses build_session_context() from this module.

Source

pub fn build_session_context(&self) -> SessionContext

Alias for build_context — pi-compatible naming.

Source

pub fn session_id(&self) -> String

Convenience: session ID from metadata.

Source

pub fn session_file(&self) -> Option<PathBuf>

Convenience: session file path from metadata.

Source

pub fn session_name(&self) -> Option<String>

Convenience: session display name.

Source

pub fn get_session_name(&self) -> Option<String>

Get the latest session name from session_info entries.

Source

pub fn append_message(&mut self, message: &AgentMessage) -> String

Append a conversation message. Returns the entry id.

Source

pub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String

Append a thinking level change. Returns the entry id.

Source

pub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String

Append a model change. Returns the entry id.

Source

pub fn append_active_tools_change( &mut self, active_tool_names: &[String], ) -> String

Append an active tools change. Returns the entry id.

Source

pub fn append_compaction( &mut self, summary: &str, first_kept_entry_id: &str, tokens_before: u64, details: Option<Value>, from_hook: Option<bool>, ) -> String

Append a compaction summary. Returns the entry id.

Source

pub fn append_session_info(&mut self, name: &str) -> String

Append a session info entry (display name). Returns the entry id.

Source

pub fn append_branch_summary( &mut self, from_id: &str, summary: &str, details: Option<Value>, from_hook: Option<bool>, ) -> String

Append a branch summary. Returns the entry id.

Source

pub fn append_label_change( &mut self, target_id: &str, label: Option<&str>, ) -> String

Append a label change (bookmark/unbookmark). Returns the entry id.

Source

pub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String

Append a custom entry (extension data). Returns the entry id.

Source

pub fn append_custom_message_entry( &mut self, custom_type: &str, content: Value, display: bool, details: Option<Value>, ) -> String

Append a custom message entry (pi-compatible extension message). Returns the entry id.

Source

pub fn move_to( &mut self, entry_id: Option<&str>, summary: Option<(String, Option<Value>, Option<bool>)>, ) -> Result<Option<String>, String>

Move the leaf pointer to an earlier entry, optionally with a summary. Pi-compatible: atomically moves leaf and appends a BranchSummaryEntry. Returns the entry id of the BranchSummaryEntry if a summary was provided.

Source

pub fn set_leaf_id(&mut self, leaf_id: Option<&str>) -> Result<(), String>

Reset the leaf to the given entry (in-memory + leaf entry persisted). Pi-compatible: delegates to set_leaf_id on storage.

Source

pub fn reset_leaf(&mut self) -> Result<(), String>

Reset leaf to null (before any entries).

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> 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> 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, 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<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