pub struct Message {
pub msg_id: String,
pub role: Role,
pub content: String,
pub images: Vec<ImageRef>,
pub content_blocks: Vec<ContentBlock>,
pub alt_index: Option<u32>,
pub alt_count: Option<u32>,
pub alternatives: Vec<MessageAlternative>,
pub timestamp: String,
pub provider_key: Option<String>,
pub model: Option<String>,
pub origin: Option<MessageOrigin>,
}Expand description
A chat message. One shape everywhere — no polymorphism.
content_blocks is the canonical content representation.
content is a derived convenience field (human-readable text summary).
On disk, only content_blocks is stored; content is derived on load.
Fields§
§msg_id: String§role: Role§content: String§images: Vec<ImageRef>§content_blocks: Vec<ContentBlock>§alt_index: Option<u32>§alt_count: Option<u32>§alternatives: Vec<MessageAlternative>§timestamp: String§provider_key: Option<String>Provider key that minted this message’s content (e.g. "anthropic",
"openrouter-anthropic"). Opaque thinking data — thinking
signatures and redacted_thinking blobs — is bound to its minting
provider and is not portable across a provider switch; the replay path
uses this to drop blocks the active provider cannot interpret. None
for messages persisted before provenance tracking, or for messages
(user turns, system recaps) that carry no provider-bound data.
model: Option<String>Model id that minted this message’s content (e.g. "claude-opus-4-6",
"anthropic/claude-opus-4.6"), in the same vocabulary as the usage
ledger. Unlike Message::provider_key (which drives thinking-replay
portability), this is pure provenance: it lets history tooling
attribute a stored turn to the model that generated it. None for
messages persisted before model provenance tracking and for messages
no model minted (user turns, system recaps).
origin: Option<MessageOrigin>How this message entered the conversation. Currently only
Some(Autonomous) is persisted (heartbeat <sendMessage> output);
compaction’s deep-idle archive uses it to keep unanswered autonomous
messages visible across an archive boundary.
Implementations§
Source§impl Message
impl Message
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Ensure content and content_blocks are consistent after deserialization.
Handles both old format (content only) and new format (content_blocks only):
- Old: wraps
contentin aTextblock - New: derives
contentfrom blocks
Sourcepub fn is_tool_result_only(&self) -> bool
pub fn is_tool_result_only(&self) -> bool
True when this is a user-role message whose content consists
entirely of ToolResult blocks — i.e. a synthetic tool-loop
message rather than a real user turn.
Used by compaction, history rendering, and turn-counting logic.
Sourcepub fn serialize_for_storage(&self) -> Result<String, Error>
pub fn serialize_for_storage(&self) -> Result<String, Error>
Serialize for disk storage, omitting the redundant content field
and stripping inline data from image refs.
The wire protocol (History, log command) still includes content via
normal serde serialization. This method is only for JSONL persistence.