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
impl Session
Sourcepub fn new(storage: Box<dyn SessionStorage>) -> Self
pub fn new(storage: Box<dyn SessionStorage>) -> Self
Wrap an existing storage backend.
Sourcepub fn get_storage(&self) -> &dyn SessionStorage
pub fn get_storage(&self) -> &dyn SessionStorage
Access the underlying storage.
Sourcepub fn get_storage_mut(&mut self) -> &mut dyn SessionStorage
pub fn get_storage_mut(&mut self) -> &mut dyn SessionStorage
Mutably access the underlying storage.
Sourcepub fn into_storage(self) -> Box<dyn SessionStorage>
pub fn into_storage(self) -> Box<dyn SessionStorage>
Consume and return the underlying storage.
pub fn metadata(&self) -> SessionMetadata
pub fn get_leaf_id(&self) -> Option<String>
pub fn get_entry(&self, id: &str) -> Option<SessionEntry>
pub fn get_entries(&self) -> Vec<SessionEntry>
pub fn find_entries(&self, type_name: &str) -> Vec<SessionEntry>
pub fn get_label(&self, id: &str) -> Option<String>
Sourcepub fn get_branch(
&self,
from_id: Option<&str>,
) -> Result<Vec<SessionEntry>, String>
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.
Sourcepub fn build_context(&self) -> SessionContext
pub fn build_context(&self) -> SessionContext
Build the session context (messages + metadata) for the LLM.
Pi-compatible: uses build_session_context() from this module.
Sourcepub fn build_session_context(&self) -> SessionContext
pub fn build_session_context(&self) -> SessionContext
Alias for build_context — pi-compatible naming.
Sourcepub fn session_id(&self) -> String
pub fn session_id(&self) -> String
Convenience: session ID from metadata.
Sourcepub fn session_file(&self) -> Option<PathBuf>
pub fn session_file(&self) -> Option<PathBuf>
Convenience: session file path from metadata.
Sourcepub fn session_name(&self) -> Option<String>
pub fn session_name(&self) -> Option<String>
Convenience: session display name.
Sourcepub fn get_session_name(&self) -> Option<String>
pub fn get_session_name(&self) -> Option<String>
Get the latest session name from session_info entries.
Sourcepub fn append_message(&mut self, message: &AgentMessage) -> String
pub fn append_message(&mut self, message: &AgentMessage) -> String
Append a conversation message. Returns the entry id.
Sourcepub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String
pub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String
Append a thinking level change. Returns the entry id.
Sourcepub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String
pub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String
Append a model change. Returns the entry id.
Sourcepub fn append_active_tools_change(
&mut self,
active_tool_names: &[String],
) -> String
pub fn append_active_tools_change( &mut self, active_tool_names: &[String], ) -> String
Append an active tools change. Returns the entry id.
Sourcepub fn append_compaction(
&mut self,
summary: &str,
first_kept_entry_id: &str,
tokens_before: u64,
details: Option<Value>,
from_hook: Option<bool>,
) -> String
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.
Sourcepub fn append_session_info(&mut self, name: &str) -> String
pub fn append_session_info(&mut self, name: &str) -> String
Append a session info entry (display name). Returns the entry id.
Sourcepub fn append_branch_summary(
&mut self,
from_id: &str,
summary: &str,
details: Option<Value>,
from_hook: Option<bool>,
) -> String
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.
Sourcepub fn append_label_change(
&mut self,
target_id: &str,
label: Option<&str>,
) -> String
pub fn append_label_change( &mut self, target_id: &str, label: Option<&str>, ) -> String
Append a label change (bookmark/unbookmark). Returns the entry id.
Sourcepub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String
pub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String
Append a custom entry (extension data). Returns the entry id.
Sourcepub fn append_custom_message_entry(
&mut self,
custom_type: &str,
content: Value,
display: bool,
details: Option<Value>,
) -> String
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.
Sourcepub fn move_to(
&mut self,
entry_id: Option<&str>,
summary: Option<(String, Option<Value>, Option<bool>)>,
) -> Result<Option<String>, String>
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.
Sourcepub fn set_leaf_id(&mut self, leaf_id: Option<&str>) -> Result<(), String>
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.
Sourcepub fn reset_leaf(&mut self) -> Result<(), String>
pub fn reset_leaf(&mut self) -> Result<(), String>
Reset leaf to null (before any entries).