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 async fn last_for_directory(workspace: Option<&Path>) -> Result<Self>
pub async fn last_for_directory(workspace: Option<&Path>) -> Result<Self>
Load the last session, optionally scoped to a workspace directory
When workspace is Some, only considers sessions created in that directory.
When None, returns the most recent session globally (legacy behavior).
Sourcepub async fn last() -> Result<Self>
pub async fn last() -> Result<Self>
Load the last session (global, unscoped — legacy compatibility)
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>,
registry: Arc<ProviderRegistry>,
) -> Result<SessionResult>
pub async fn prompt_with_events( &mut self, message: &str, event_tx: Sender<SessionEvent>, registry: Arc<ProviderRegistry>, ) -> 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.
Accepts a pre-loaded ProviderRegistry to avoid re-fetching secrets
from Vault on every message (which was the primary TUI performance
bottleneck).
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)
Sourcepub async fn from_opencode(
session_id: &str,
storage: &OpenCodeStorage,
) -> Result<Self>
pub async fn from_opencode( session_id: &str, storage: &OpenCodeStorage, ) -> Result<Self>
Import an OpenCode session into CodeTether
Loads messages and parts from OpenCode storage and converts them into a CodeTether session that can be resumed.
Sourcepub async fn last_opencode_for_directory(dir: &Path) -> Result<Self>
pub async fn last_opencode_for_directory(dir: &Path) -> Result<Self>
Try to load the last OpenCode session for a directory as a fallback
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>,
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
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request