pub struct Session {
pub id: String,
pub title: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub messages: Vec<Message>,
pub tool_uses: Vec<ToolUse>,
pub usage: Usage,
pub agent: String,
pub metadata: SessionMetadata,
}Expand description
A conversation session
Fields§
§id: String§title: Option<String>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>§messages: Vec<Message>§tool_uses: Vec<ToolUse>§usage: Usage§agent: String§metadata: SessionMetadataImplementations§
Source§impl Session
impl Session
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Add a message to the session
Sourcepub async fn prompt(&mut self, message: &str) -> Result<SessionResult>
pub async fn prompt(&mut self, message: &str) -> Result<SessionResult>
Execute a prompt and get the result
Sourcepub async fn prompt_with_events(
&mut self,
message: &str,
event_tx: Sender<SessionEvent>,
) -> Result<SessionResult>
pub async fn prompt_with_events( &mut self, message: &str, event_tx: Sender<SessionEvent>, ) -> Result<SessionResult>
Process a user message with real-time event streaming for UI updates. Events are sent through the provided channel as tool calls execute.
Sourcepub async fn generate_title(&mut self) -> Result<()>
pub async fn generate_title(&mut self) -> Result<()>
Generate a title for the session based on the first message Only sets title if not already set (for initial title generation)
Sourcepub async fn regenerate_title(&mut self) -> Result<()>
pub async fn regenerate_title(&mut self) -> Result<()>
Regenerate the title based on the first message, even if already set Use this for on-demand title updates or after context changes
Sourcepub fn clear_title(&mut self)
pub fn clear_title(&mut self)
Clear the title, allowing it to be regenerated
Sourcepub async fn on_context_change(&mut self, regenerate_title: bool) -> Result<()>
pub async fn on_context_change(&mut self, regenerate_title: bool) -> Result<()>
Handle context change - updates metadata and optionally regenerates title Call this when the session context changes (e.g., directory change, model change)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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