pub struct ConversationState { /* private fields */ }Expand description
Session-level controlled operations over the kernel’s facts:
begin_turnadmits a fresh active turn (rejects concurrent active and turn-id collisions with committed history);seal_turnis the only stamping path — forCompleted/Interruptedit seals the activeTurnContextand records the outcome in one step (invariantsealed_result ∈ {Completed, Interrupted} ⇒ active.is_sealed()); forPausedit records the stamp while the activeTurnContextstays open, so a laterresume_turncan continue it (invariantsealed_result == Paused ⇒ activeis open);commitis the exactly-once transition into history: it alone assigns theTurnSequence(as aHistoryEntry), rejects anything not sealed-and-Completed(Pausedgets the dedicatedTurnPausedrejection), and clears the active slot — a repeated commit therefore lands onUnknownTurn(rejection, not idempotence);abort_turndiscards the active turn in any state (open, paused, sealed); history is untouched either way, and an aborted turn’s id may be reused.
The single active slot, completed-only admission, and commit-time ordering are this component’s defaults — a custom host composes the kernel facts differently without touching them.
Implementations§
Source§impl ConversationState
impl ConversationState
Sourcepub fn new(conversation_id: ConversationId) -> Self
pub fn new(conversation_id: ConversationId) -> Self
A fresh, empty session: no history, no active turn, version zero.
Sourcepub fn next_turn_sequence(&self) -> TurnSequence
pub fn next_turn_sequence(&self) -> TurnSequence
The next TurnSequence the session will assign on commit. Derived
from history.last() + 1 so the source of truth is history; there
is no in-memory field to drift. TurnSequence(0) if empty.
Sourcepub fn begin_turn(
&mut self,
turn_id: TurnId,
) -> Result<&mut TurnContext, ConversationError>
pub fn begin_turn( &mut self, turn_id: TurnId, ) -> Result<&mut TurnContext, ConversationError>
Admit a fresh active turn. Rejects while any active exists (sealed ones must be committed or aborted first) and when the id collides with committed history — an aborted turn’s id is reusable.
Sourcepub fn seal_turn(
&mut self,
turn_id: TurnId,
result: SealedResult,
) -> Result<(), ConversationError>
pub fn seal_turn( &mut self, turn_id: TurnId, result: SealedResult, ) -> Result<(), ConversationError>
The only stamping path. Completed/Interrupted seal the active
TurnContext and record the outcome atomically; Paused records
the stamp while the turn stays open — the driver-owned counterpart
of TurnContext::seal, deliberately withheld for resumable pauses.
Sourcepub fn active_turn(&self) -> Option<&TurnContext>
pub fn active_turn(&self) -> Option<&TurnContext>
Read-only view of the active turn.
Sourcepub fn sealed_result(&self) -> Option<SealedResult>
pub fn sealed_result(&self) -> Option<SealedResult>
The eligibility stamp, if any (Some(Paused) marks a resumable
turn).
Sourcepub fn active_turn_mut(&mut self) -> Option<&mut TurnContext>
pub fn active_turn_mut(&mut self) -> Option<&mut TurnContext>
Mutable view of the active turn — the host’s door access for
append_input before running.
Sourcepub fn commit(
&mut self,
turn_id: TurnId,
) -> Result<HistoryEntry, ConversationError>
pub fn commit( &mut self, turn_id: TurnId, ) -> Result<HistoryEntry, ConversationError>
Exactly-once commit: requires the turn id to match the active slot,
the turn to be sealed, and the stamp to read Completed. Assigns
the next TurnSequence, appends the HistoryEntry to history,
and clears the active slot. Rejection (not idempotence): after the
first commit the slot is empty, so a repeated commit returns
UnknownTurn.
Sourcepub fn abort_turn(
&mut self,
turn_id: TurnId,
) -> Result<TurnContext, ConversationError>
pub fn abort_turn( &mut self, turn_id: TurnId, ) -> Result<TurnContext, ConversationError>
Discard the active turn in any state (open, paused, sealed-completed,
sealed-interrupted). History is untouched; the returned
TurnContext is for caller inspection only (no reopen/unseal). An
aborted turn’s id may be reused by a later begin_turn.
Sourcepub fn frame(
&self,
round_id: RoundId,
) -> Result<ContextFrame, ConversationError>
pub fn frame( &self, round_id: RoundId, ) -> Result<ContextFrame, ConversationError>
Lossless merged view: committed history (sequence ascending, blocks in BlockSequence order) followed by the active turn’s blocks, under the Conversation scope identity. Sync and policy-free by design — budget, selection and compaction over the merged view orchestrate through the policy layer and never mutate facts. The only failure source is a missing active turn.
Sourcepub fn runner_parts(
&mut self,
) -> (&ConversationId, Vec<TurnSnapshot>, Option<&mut TurnContext>)
pub fn runner_parts( &mut self, ) -> (&ConversationId, Vec<TurnSnapshot>, Option<&mut TurnContext>)
Borrow-split for a conversation driver’s consume/return flow: the
conversation id and committed history are read while the active
turn is driven mutably. Stamping still goes through the public
seal_turn afterwards, so no second &mut seam exists.
Sourcepub fn from_history(
conversation_id: ConversationId,
entries: Vec<HistoryEntry>,
) -> Result<Self, ConversationError>
pub fn from_history( conversation_id: ConversationId, entries: Vec<HistoryEntry>, ) -> Result<Self, ConversationError>
Validated replay path: rebuild a session from committed history
entries. The active slot starts empty (live paths never enter
here); ConversationVersion resets to zero (replay is a fresh load).
Validation runs the shared validate_history closed set — any
violation maps to ConversationError::InvalidSequence so callers
never touch ContextError.
Sourcepub fn history(&self) -> &[HistoryEntry]
pub fn history(&self) -> &[HistoryEntry]
Committed history in ascending TurnSequence order.
Sourcepub fn history_len(&self) -> usize
pub fn history_len(&self) -> usize
Number of committed entries in history.
Sourcepub fn version(&self) -> ConversationVersion
pub fn version(&self) -> ConversationVersion
The ConversationVersion, ticked at every controlled transition
(begin_turn / commit / abort_turn); zero for a fresh or
replayed session.
Sourcepub fn conversation_id(&self) -> &ConversationId
pub fn conversation_id(&self) -> &ConversationId
The session’s identity.
Trait Implementations§
Source§impl Clone for ConversationState
impl Clone for ConversationState
Source§fn clone(&self) -> ConversationState
fn clone(&self) -> ConversationState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more