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 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: StringWhich conversation this turn threads into (DEFAULT_CONVERSATION when
the payload names none).
role: Roleuser / assistant / tool.
content: StringThe 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).
timestamp: u64Turn timestamp (ms) — the recency key B4’s LastN conversation
retention orders on.
hlc: HlcThe causal-order stamp this turn folded with (ordering/provenance).
op_id: StringThe op that produced this turn (provenance; the fold identity).
Implementations§
Source§impl Turn
impl Turn
Sourcepub fn user_payload(
conversation_id: &str,
content: &str,
timestamp: u64,
) -> Value
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).
Sourcepub fn assistant_payload(
conversation_id: &str,
content: &str,
tool_calls: Vec<Value>,
timestamp: u64,
) -> Value
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.
Sourcepub fn tool_payload(
conversation_id: &str,
tool_use_id: &str,
content: &str,
timestamp: u64,
) -> Value
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.
Sourcepub fn from_record(record: &FoldedRecord) -> Option<Turn>
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.
Sourcepub fn to_message(&self) -> Message
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:
Role::User→Message::UserRole::Assistant→Message::Assistant { content, tool_calls }Role::Tool→Message::ToolResult { tool_use_id, content }