pub struct ConversationState {
pub session: Session,
pub api_messages: Vec<Value>,
pub total_input_tokens: u64,
pub total_output_tokens: u64,
pub total_cache_read_tokens: u64,
pub total_cache_creation_tokens: u64,
pub session_cost: f64,
pub abort_context: Option<String>,
pub queued_message: Option<String>,
pub pending_events: Vec<String>,
}Expand description
Conversation state tracked by the engine.
Fields§
§session: Session§api_messages: Vec<Value>§total_input_tokens: u64§total_output_tokens: u64§total_cache_read_tokens: u64§total_cache_creation_tokens: u64§session_cost: f64§abort_context: Option<String>§queued_message: Option<String>Message queued to send after current stream completes.
pending_events: Vec<String>Events buffered during streaming — drained on stream completion.
Implementations§
Source§impl ConversationState
impl ConversationState
Sourcepub fn new(session: Session) -> ConversationState
pub fn new(session: Session) -> ConversationState
Create a new conversation with a fresh session.
Sourcepub fn from_resumed(session: Session) -> ConversationState
pub fn from_resumed(session: Session) -> ConversationState
Create from a resumed session.
Sourcepub fn add_usage(
&mut self,
input_tokens: u64,
output_tokens: u64,
cache_read: u64,
cache_creation: u64,
cache_creation_5m: Option<u64>,
cache_creation_1h: Option<u64>,
model: &str,
)
pub fn add_usage( &mut self, input_tokens: u64, output_tokens: u64, cache_read: u64, cache_creation: u64, cache_creation_5m: Option<u64>, cache_creation_1h: Option<u64>, model: &str, )
Add usage from a model turn.
cache_creation_5m / cache_creation_1h are the cache-write TTL
split. When either is present the cost uses the split rates
(5m: 1.25×, 1h: 2.0×); when both are None the aggregate
cache_creation is billed at the 5m rate (fail-cheap fallback).
Sourcepub fn estimate_tokens(&self) -> usize
pub fn estimate_tokens(&self) -> usize
Estimate current token count (for compaction decisions).
Auto Trait Implementations§
impl Freeze for ConversationState
impl RefUnwindSafe for ConversationState
impl Send for ConversationState
impl Sync for ConversationState
impl Unpin for ConversationState
impl UnsafeUnpin for ConversationState
impl UnwindSafe for ConversationState
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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