Skip to main content

Turn

Struct Turn 

Source
pub struct Turn {
    pub conversation_id: String,
    pub role: Role,
    pub content: String,
    pub tool_calls: Vec<ToolCall>,
    pub tool_use_id: Option<String>,
    pub provenance: Provenance,
    pub timestamp: u64,
    pub hlc: Hlc,
    pub op_id: String,
}
Expand description

One folded, ordered transcript turn — the typed projection of a crate::oplog::Surface::Conversation op.

hlc/op_id are provenance/ordering only (not part of the replayed Message): they record where the turn sits in the causal order and which op produced it (op identity IS turn identity — see the module docs).

Fields§

§conversation_id: String

Which conversation this turn threads into (DEFAULT_CONVERSATION when the payload names none).

§role: Role

user / assistant / tool.

§content: String

The turn text (content, falling back to the legacy text field).

§tool_calls: Vec<ToolCall>

Assistant tool calls — the REAL car_inference_types::ToolCall type, parsed from the payload. Empty for non-assistant turns or an assistant turn that called no tool.

§tool_use_id: Option<String>

For a Tool turn: the id of the tool call this result answers (Message::ToolResult.tool_use_id).

§provenance: Provenance

For a Tool turn: whether the result came from outside the trust boundary (car#723).

Carried through the oplog on purpose. A marking that survives the live turn but not a resume is worse than none — the same fetched bytes would come back as trusted after a restart, and the one path where nobody is watching is exactly where that matters. #[serde(default)] reads turns recorded before this field as Internal, which is how they were treated.

§timestamp: u64

Turn timestamp (ms) — the recency key B4’s LastN conversation retention orders on.

§hlc: Hlc

The causal-order stamp this turn folded with (ordering/provenance).

§op_id: String

The op that produced this turn (provenance; the fold identity).

Implementations§

Source§

impl Turn

Source

pub fn user_payload( conversation_id: &str, content: &str, timestamp: u64, ) -> Value

Build the Conversation op payload for a user turn — append it via DeviceLog::append(scope, Surface::Conversation, payload).

Source

pub fn assistant_payload( conversation_id: &str, content: &str, tool_calls: Vec<Value>, timestamp: u64, ) -> Value

Build the Conversation op payload for an assistant turn. tool_calls are raw ToolCall JSON values ({id?, name, arguments} — how a model or the daemon already holds them); Turn::from_record parses them into the typed ToolCall. Empty for a plain text reply.

Source

pub fn tool_payload( conversation_id: &str, tool_use_id: &str, content: &str, timestamp: u64, ) -> Value

Build the Conversation op payload for a tool-result turn.

Source

pub fn tool_payload_with_provenance( conversation_id: &str, tool_use_id: &str, content: &str, timestamp: u64, provenance: Provenance, ) -> Value

Turn::tool_payload for a result whose bytes came from outside the trust boundary. Separate constructor rather than a defaulted argument so the caller has to say which it is; tool_payload keeps the common case short and every existing call site correct.

Source

pub fn from_record(record: &FoldedRecord) -> Option<Turn>

Project a folded conversation record into a typed Turn. Returns None for a tombstone stub (a retention-dropped entity’s referential placeholder — never a real turn).

Tolerant of both the rich B2 payload (role/content/tool_calls) and the legacy (speaker, text, timestamp) shape the B4 tests use, so one transcript view serves every conversation op ever written.

Source

pub fn to_message(&self) -> Message

Build the REAL car_inference_types::Message for this turn (typed — a shape change to Message is a compile error here). The mapping:

Trait Implementations§

Source§

impl Clone for Turn

Source§

fn clone(&self) -> Turn

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Turn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Turn

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Turn

Source§

fn eq(&self, other: &Turn) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Turn

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Turn

Auto Trait Implementations§

§

impl Freeze for Turn

§

impl RefUnwindSafe for Turn

§

impl Send for Turn

§

impl Sync for Turn

§

impl Unpin for Turn

§

impl UnsafeUnpin for Turn

§

impl UnwindSafe for Turn

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more