Skip to main content

Session

Struct Session 

Source
pub struct Session<M>
where M: AgentMessage,
{ /* private fields */ }
Expand description

Session manager: JSONL persistence, history access, context trimming.

Uses Claude Code compatible JSONL format with UUID v7 (time-sortable).

Implementations§

Source§

impl<M> Session<M>
where M: AgentMessage,

Source

pub fn new(session_dir: &str, max_history: usize) -> Result<Session<M>, Error>

Create a new session with a fresh JSONL file.

Creates the session directory if it doesn’t exist. Returns an error if the directory cannot be created.

Source

pub fn resume(path: &Path, _session_dir: &str, max_history: usize) -> Session<M>

Resume from a specific session file.

Source

pub fn resume_last(session_dir: &str, max_history: usize) -> Option<Session<M>>

Resume the most recent session in the session directory.

Source

pub fn push(&mut self, role: <M as AgentMessage>::Role, content: String) -> &M

Push a message, persist to JSONL, return ref.

Source

pub fn push_msg(&mut self, msg: M)

Push a pre-built message.

Source

pub fn messages(&self) -> &[M]

Access messages.

Source

pub fn messages_mut(&mut self) -> &mut Vec<M>

Mutable access to messages (for external trimming).

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn session_file(&self) -> &Path

Source

pub fn session_id(&self) -> &str

Source

pub fn trim(&mut self) -> usize

Trim history to fit context window.

Preserves system messages and the most recent non-system messages. Inserts a “[N earlier messages trimmed]” system notice. Returns the number of trimmed messages (0 if no trimming needed).

Auto Trait Implementations§

§

impl<M> Freeze for Session<M>

§

impl<M> RefUnwindSafe for Session<M>
where M: RefUnwindSafe,

§

impl<M> Send for Session<M>
where M: Send,

§

impl<M> Sync for Session<M>
where M: Sync,

§

impl<M> Unpin for Session<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for Session<M>

§

impl<M> UnwindSafe for Session<M>
where M: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.