Skip to main content

SessionManager

Struct SessionManager 

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

SessionManager: entries form a tree through id/parentId; the leaf is the current position. Appends add a child of the leaf; branching moves the leaf. Persisted sessions are written only once the first assistant message exists, then appended line by line.

Implementations§

Source§

impl SessionManager

Source

pub fn create( env: Box<dyn Env>, cwd: &str, session_dir: Option<&str>, options: Option<NewSessionOptions>, ) -> Result<Self, Error>

create: a new persisted session in session_dir (default: the cwd’s dir under the agent dir).

Source

pub fn open( env: Box<dyn Env>, path: &str, session_dir: Option<&str>, cwd_override: Option<&str>, ) -> Result<Self, Error>

open: a specific session file. The cwd comes from cwd_override, else the header, else the process cwd; session_dir defaults to the file’s directory.

Source

pub fn in_memory( env: Box<dyn Env>, cwd: &str, options: Option<NewSessionOptions>, entries: Option<Vec<Value>>, ) -> Result<Self, Error>

inMemory: a session that is never written, optionally adopting stored entries.

Source

pub fn fork_from( env: Box<dyn Env>, source_path: &str, target_cwd: &str, session_dir: Option<&str>, options: Option<NewSessionOptions>, ) -> Result<Self, Error>

forkFrom: copies another session’s entries into a new session for target_cwd.

Source

pub fn new_session( &mut self, options: Option<NewSessionOptions>, ) -> Result<Option<String>, Error>

newSession: a fresh header and no entries. Returns the new session file path (persisted only).

Source

pub fn append_message(&mut self, message: Value) -> Result<String, Error>

appendMessage: a message entry as child of the leaf. Returns its id.

Source

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

getSessionName: the latest session_info name; empty clears it.

Source

pub fn branch(&mut self, branch_from_id: &str) -> Result<(), Error>

branch: moves the leaf to an earlier entry; the next append starts a new branch there.

Source

pub fn reset_leaf(&mut self)

resetLeaf: the next append creates a new root.

Source

pub fn cwd(&self) -> &str

Source

pub fn session_dir(&self) -> &str

Source

pub fn session_id(&self) -> &str

Source

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

Source

pub fn leaf_id(&self) -> Option<&Value>

The leaf id; None before the first entry (or after reset_leaf).

Source

pub fn entry(&self, id: &str) -> Option<&Value>

Source

pub fn children(&self, parent_id: &str) -> Vec<&Value>

getChildren: direct children in index order.

Source

pub fn label(&self, id: &str) -> Option<&Value>

Source

pub fn branch_entries(&self, from_id: Option<&str>) -> Vec<&Value>

getBranch: root-first path to from_id (default: the leaf).

Source

pub fn build_context_entries(&self) -> Vec<&Value>

buildContextEntries from the leaf.

Source

pub fn build_session_projection(&self) -> SessionProjection<'_>

buildSessionProjection from the leaf.

Source

pub fn build_session_context(&self) -> SessionContext

buildSessionContext from the leaf.

Source

pub fn header(&self) -> Option<&Value>

Source

pub fn entries(&self) -> Vec<&Value>

getEntries: every entry except headers.

Source

pub fn tree(&self) -> SessionTree<'_>

Trait Implementations§

Source§

impl Debug for SessionManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.