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,
}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: StringImplementations§
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.