pub struct ChatMessage {Show 13 fields
pub role: MessageRole,
pub content: String,
pub timestamp: DateTime<Local>,
pub kind: ChatMessageKind,
pub metadata: Option<Value>,
pub actions: Vec<ActionDisplay>,
pub thinking: Option<String>,
pub images: Option<Vec<String>>,
pub image_numbers: Option<Vec<u64>>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub tool_name: Option<String>,
pub provider_continuation: Option<ProviderContinuation>,
}Expand description
Represents a chat message
Fields§
§role: MessageRole§content: String§timestamp: DateTime<Local>§kind: ChatMessageKindMermaid-owned message classification. Provider adapters ignore this; render/persistence use it to distinguish generated checkpoints from normal user/assistant turns.
metadata: Option<Value>Optional Mermaid-owned structured metadata for UI/replay.
actions: Vec<ActionDisplay>Actions performed during this message (for display purposes)
thinking: Option<String>Thinking/reasoning content (for models that expose their thought process)
images: Option<Vec<String>>Base64-encoded images/PDFs for multimodal models
image_numbers: Option<Vec<u64>>Global [Image #N] display numbers, parallel to images (same length,
same order). Kept separate from images so provider adapters and the
/context image count keep reading images: Vec<String> unchanged, and
so sessions saved before image numbering deserialize cleanly (None →
the transcript falls back to a positional index).
tool_calls: Option<Vec<ToolCall>>Tool calls from the model (Ollama native function calling)
tool_call_id: Option<String>Tool call ID for tool result messages (OpenAI-compatible format) This links the tool result back to the original tool_call from the assistant
tool_name: Option<String>Tool name for tool result messages (required by Ollama API) This tells the model which function’s result is being returned
provider_continuation: Option<ProviderContinuation>Provider-owned continuation state. Anthropic stores its signed thinking block; Meta stores ordered Responses output items for encrypted replay. Other providers leave this unset and ignore it on the wire.
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn run_summary(content: impl Into<String>) -> Self
pub fn run_summary(content: impl Into<String>) -> Self
Create a display-only run summary (e.g. “Worked for 5m 12s · used 12.3k
tokens”). Rendered dim/italic where the spinner was; excluded from the
model context by build_chat_request so it never bloats the conversation.
Sourcepub fn tool(
tool_call_id: impl Into<String>,
tool_name: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn tool( tool_call_id: impl Into<String>, tool_name: impl Into<String>, content: impl Into<String>, ) -> Self
Create a tool result message
Sourcepub fn with_images(self, images: Vec<String>) -> Self
pub fn with_images(self, images: Vec<String>) -> Self
Builder: attach images
Sourcepub fn with_image_numbers(self, numbers: Vec<u64>) -> Self
pub fn with_image_numbers(self, numbers: Vec<u64>) -> Self
Builder: attach the parallel global image numbers (same length/order as
with_images). Set together at submit time so the transcript can show
each image’s stable [Image #N].
Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Builder: attach tool calls
Sourcepub fn with_provider_continuation(
self,
continuation: ProviderContinuation,
) -> Self
pub fn with_provider_continuation( self, continuation: ProviderContinuation, ) -> Self
Builder: attach opaque provider continuation data.
Sourcepub fn extract_thinking(text: &str) -> (Option<String>, String)
pub fn extract_thinking(text: &str) -> (Option<String>, String)
Extract thinking blocks from message content.
Returns (thinking_content, answer_content).
Performs a single find for the start marker; the previous version
scanned twice (contains + find) and called find("Thinking...")
again inside the if-let-chain.
Safety: str::find() returns byte offsets. The markers "Thinking..."
and "...done thinking." are pure ASCII, so adding their .len()
always lands on a valid UTF-8 char boundary.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatMessage
impl Debug for ChatMessage
Source§impl<'de> Deserialize<'de> for ChatMessage
impl<'de> Deserialize<'de> for ChatMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ChatMessage
impl RefUnwindSafe for ChatMessage
impl Send for ChatMessage
impl Sync for ChatMessage
impl Unpin for ChatMessage
impl UnsafeUnpin for ChatMessage
impl UnwindSafe for ChatMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more