pub struct ConversationState {
pub session: Session,
pub context_head: ContextHeadPersistence,
pub api_messages: Vec<Arc<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 keepwarm_cost: f64,
pub keepwarm_tokens: ConversationTokens,
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<Arc<Value>>§total_input_tokens: u64§total_output_tokens: u64§total_cache_read_tokens: u64§total_cache_creation_tokens: u64§session_cost: f64§keepwarm_cost: f64Prompt-cache keep-warm spend (task #444), already INCLUDED in
session_cost and shown separately; persisted with it
(Session::keepwarm_cost).
keepwarm_tokens: ConversationTokensKeep-warm ping tokens, already INCLUDED in the total_* counters
above and shown separately so /stats adds up.
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. A session saved before interruption
markers existed (legacy abort_context recap) is migrated here too —
/resume loads sessions without going through engine::setup —
idempotently: an already-migrated session is untouched.
Sourcepub async fn save(&mut self) -> bool
pub async fn save(&mut self) -> bool
Save the current conversation state to disk. Returns whether it was
written: false when there is nothing to save (empty history), the
context head is unverified (context_head), or the write failed
(logged).
Sourcepub fn prepare_save(&mut self) -> Option<Session>
pub fn prepare_save(&mut self) -> Option<Session>
Fold the live state into self.session and return the snapshot to
write — or None when there is nothing to save (empty history) or
the context head is unverified. The session actor hands the snapshot
to its background writer (session::persister) instead of awaiting
the I/O. The clone is cheap: messages are Arc-shared.
Sourcepub async fn persist_context_head(
&mut self,
session_id: &str,
messages: Vec<Arc<Value>>,
) -> Result<(), Error>
pub async fn persist_context_head( &mut self, session_id: &str, messages: Vec<Arc<Value>>, ) -> Result<(), Error>
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 more