pub struct ConversationState {
pub session: Session,
pub context_head: ContextHeadPersistence,
pub api_messages: Vec<SharedMessage>,
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§context_head: ContextHeadPersistence§api_messages: Vec<SharedMessage>§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 from_resumed(session: Session) -> Self
pub fn from_resumed(session: Session) -> Self
Create from a resumed session.
Sourcepub async fn persist_context_head(
&mut self,
session_id: &str,
messages: Vec<SharedMessage>,
) -> Result<()>
pub async fn persist_context_head( &mut self, session_id: &str, messages: Vec<SharedMessage>, ) -> Result<()>
Persist a runtime-requested head using host metadata and latest usage. The caller completes the receipt with this exact result and continues consuming the runtime’s typed terminal error on failure.
Sourcepub fn snapshot(&self, consecutive_auto_turns: u32) -> ConversationSnapshot
pub fn snapshot(&self, consecutive_auto_turns: u32) -> ConversationSnapshot
Serializable mirror for clients (SessionEventWire::Conversation).
consecutive_auto_turns is actor/App-side state, not conversation
state, so the caller supplies it.
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).
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
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.