pub struct TurnContext { /* private fields */ }Expand description
Current turn’s ordered fact state. All mutation goes through the three
controlled doors (append_input / append_model_output /
append_tool_results) plus seal; there is no second &mut seam —
fields are private by design. The only projection the fact machine offers
is the lossless frame(); policy-shaped materialization lives in
causa_runtime::budget::FramePolicy::materialize, so context never
depends on harness policy and never awaits behavior.
Implementations§
Source§impl TurnContext
impl TurnContext
Sourcepub fn blocks(&self) -> &[ContextBlock]
pub fn blocks(&self) -> &[ContextBlock]
Borrows the committed fact blocks in commit order.
Sourcepub fn version(&self) -> ContextVersion
pub fn version(&self) -> ContextVersion
Returns the current ContextVersion (count of canonical fact commits).
Sourcepub fn lifecycle(&self) -> TurnLifecycle
pub fn lifecycle(&self) -> TurnLifecycle
Returns the current lifecycle state.
Sourcepub fn snapshot_blocks(&self) -> Vec<ContextBlock>
pub fn snapshot_blocks(&self) -> Vec<ContextBlock>
Returns an owned copy of the committed blocks in commit order.
Sourcepub fn append_input(
&mut self,
text: TextPayload,
source: impl Into<String>,
) -> Result<BlockId, ContextError>
pub fn append_input( &mut self, text: TextPayload, source: impl Into<String>, ) -> Result<BlockId, ContextError>
Host door: admit one single-text message — the one-part sugar over
TurnContext::append_parts. The kernel does not interpret the
source label; role assignment is the renderer’s job.
Sourcepub fn append_parts(
&mut self,
parts: Vec<ContentPart>,
source: impl Into<String>,
) -> Result<BlockId, ContextError>
pub fn append_parts( &mut self, parts: Vec<ContentPart>, source: impl Into<String>, ) -> Result<BlockId, ContextError>
Host door for one logical message’s mixed content (caption + media,
multi-image, text runs): the ordered parts commit as ONE fact block.
Atomic — all-or-nothing validation, exactly one version bump,
contiguous sequences. Stamps source verbatim on the envelope.
Empty parts are rejected; media parts carry references only.
Sourcepub fn append_model_output(
&mut self,
invocation: InvocationId,
response: &ModelResponse,
stop_reason: ModelStopReason,
) -> Result<AppliedModelOutput, ContextError>
pub fn append_model_output( &mut self, invocation: InvocationId, response: &ModelResponse, stop_reason: ModelStopReason, ) -> Result<AppliedModelOutput, ContextError>
Model door: record the model’s response as facts. Borrows the response so the caller keeps the envelope for its own traces; usage and reasoning are deliberately caller-retained and never enter the fact state. Tool call ids are generated exactly once and returned in the receipt as the execution handoff.
Sourcepub fn append_tool_results(
&mut self,
results: Vec<ToolResultPayload>,
) -> Result<Vec<BlockId>, ContextError>
pub fn append_tool_results( &mut self, results: Vec<ToolResultPayload>, ) -> Result<Vec<BlockId>, ContextError>
Tool door: commit tool results. Canonical commit order is the paired call’s block order (the model’s original draft order), so two drivers submitting the same logical results in different completion orders produce identical snapshots. Batch completeness is runner policy; the kernel enforces pairing only.
Sourcepub fn frame(&self, round_id: RoundId) -> ContextFrame
pub fn frame(&self, round_id: RoundId) -> ContextFrame
Lossless canonical projection: the committed facts, ordered, with the
deterministic frame identity. Frame-materialization policy (budget,
compaction) is NOT applied here — the fact machine never awaits
behavior; the execution stack materializes policy-shaped frames
through causa_runtime::budget::FramePolicy::materialize, which
replaces only this frame’s block list.
Sourcepub fn seal(&mut self)
pub fn seal(&mut self)
Terminal lifecycle transition, owned by the driver: seal when the turn is over. Sealed turns reject every append operation; the kernel guarantees no post-terminal mutation. Conversation-level history eligibility is a driver stamp, not this marker.
Sourcepub fn from_validated_blocks(
turn_id: TurnId,
blocks: Vec<ContextBlock>,
version: ContextVersion,
) -> Result<Self, ContextError>
pub fn from_validated_blocks( turn_id: TurnId, blocks: Vec<ContextBlock>, version: ContextVersion, ) -> Result<Self, ContextError>
Rebuilds an open turn from a validated block log — the reload path behind the serde bridge. Sequence monotonicity, id agreement, and tool pairing are validated before construction; the next sequence continues densely after the given blocks.
Sourcepub fn validate_blocks(
turn_id: &TurnId,
blocks: &[ContextBlock],
) -> Result<(), ContextError>
pub fn validate_blocks( turn_id: &TurnId, blocks: &[ContextBlock], ) -> Result<(), ContextError>
The structural validation behind from_validated_blocks, callable
without constructing a throwaway machine — replay paths validate
snapshots in place. The runtime’s session replay
(ConversationState::from_history) also validates committed snapshots
through this entry, so every reload path shares one validator.
Sourcepub fn snapshot(&self) -> TurnSnapshot
pub fn snapshot(&self) -> TurnSnapshot
Projects the current state into an immutable TurnSnapshot — the
canonical wire shape for persistence. Session ordering is NOT part of
the snapshot: the runtime’s session aggregate assigns the
HistoryEntry sequence at commit.
Trait Implementations§
Source§impl Clone for TurnContext
impl Clone for TurnContext
Source§fn clone(&self) -> TurnContext
fn clone(&self) -> TurnContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more