pub struct ChatMessage {
pub role: MessageRole,
pub content: String,
pub tool_calls: Option<Vec<ToolCallItem>>,
pub tool_call_id: Option<String>,
pub images: Option<Vec<ImageData>>,
pub reasoning_content: Option<String>,
pub sender_name: Option<String>,
pub recipient_name: Option<String>,
pub display_hint: DisplayHint,
}Expand description
对话消息
Fields§
§role: MessageRole§content: String消息内容(tool_call 类消息可为空)
tool_calls: Option<Vec<ToolCallItem>>LLM 发起的工具调用列表(仅 assistant 角色且有 tool_calls 时非 None)
tool_call_id: Option<String>工具执行结果对应的 tool_call_id(仅 tool 角色时非 None)
images: Option<Vec<ImageData>>图片数据(用于多模态 user message,不持久化到 session 文件)
reasoning_content: Option<String>LLM 思考内容(thinking mode 返回的 reasoning_content,需传回下一轮请求)
sender_name: Option<String>消息发送者名称(如 Teammate@Frontend、SubAgent@search)。
仅由 teammate/subagent 消息设置;主 agent 消息为 None。
不持久化到 session 文件,仅用于运行时 UI 渲染。
recipient_name: Option<String>消息目标接收者名称(如 Counter2、Main)。
仅当消息有明确 @目标时设置;广播给所有人时为 None。
不持久化到 session 文件,仅用于运行时 UI 渲染。
display_hint: DisplayHint显示提示(运行时 UI 渲染层专用,不持久化)。 Draft 表示 teammate 内部思考,用户可见但其他 agent 不可见。
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn text(role: MessageRole, content: impl Into<String>) -> Self
pub fn text(role: MessageRole, content: impl Into<String>) -> Self
创建普通文本消息
Sourcepub fn with_sender(self, name: impl Into<String>) -> Self
pub fn with_sender(self, name: impl Into<String>) -> Self
设置消息发送者名称(Builder 模式)。
用于 teammate/subagent 消息标记发送者,UI 渲染层据此显示气泡标签。
Sourcepub fn with_recipient(self, name: impl Into<String>) -> Self
pub fn with_recipient(self, name: impl Into<String>) -> Self
设置消息目标接收者名称(Builder 模式)。
仅当消息有明确 @目标时设置,UI 渲染层据此显示 → Target 标识。
Sourcepub fn with_display_hint(self, hint: DisplayHint) -> Self
pub fn with_display_hint(self, hint: DisplayHint) -> Self
设置显示提示(Builder 模式)。
Sourcepub fn display_type(&self) -> DisplayType
pub fn display_type(&self) -> DisplayType
推断显示类型(渲染层入口)
将 role + tool_calls 组合映射为精确的 DisplayType,
渲染层无需再做 role == "assistant" && tool_calls.is_some() 的判断。
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.