pub enum CanonicalMessage {
User {
id: MessageId,
content: Vec<ContentBlock>,
timestamp: ProtocolTimestamp,
},
Assistant {
id: MessageId,
content: Vec<ContentBlock>,
stop_reason: StopReason,
timestamp: ProtocolTimestamp,
},
ToolResult {
id: MessageId,
tool_call_id: ToolCallId,
tool_name: String,
content: Vec<ContentBlock>,
is_error: bool,
error: Option<ToolFailure>,
timestamp: ProtocolTimestamp,
},
}Expand description
A provider-neutral conversation message.
Variants§
User
User-authored input.
Fields
content: Vec<ContentBlock>User-visible text or images.
timestamp: ProtocolTimestampMessage creation time.
Assistant
Model-authored output.
Fields
content: Vec<ContentBlock>Text, thinking, and tool calls.
stop_reason: StopReasonNormalized completion reason.
timestamp: ProtocolTimestampMessage completion time.
ToolResult
Result returned for a tool call.
Fields
tool_call_id: ToolCallIdTool call receiving this result.
content: Vec<ContentBlock>Text or image result content.
error: Option<ToolFailure>Machine-readable failure details, present only on failure.
timestamp: ProtocolTimestampResult completion time.
Implementations§
Source§impl CanonicalMessage
impl CanonicalMessage
Sourcepub fn user(
id: MessageId,
content: Vec<ContentBlock>,
timestamp: ProtocolTimestamp,
) -> Result<Self, MessageValidationError>
pub fn user( id: MessageId, content: Vec<ContentBlock>, timestamp: ProtocolTimestamp, ) -> Result<Self, MessageValidationError>
Creates a validated user message.
§Errors
Returns an error when content is empty, too numerous, or contains a block that is invalid for the user role.
Sourcepub fn assistant(
id: MessageId,
content: Vec<ContentBlock>,
stop_reason: StopReason,
timestamp: ProtocolTimestamp,
) -> Result<Self, MessageValidationError>
pub fn assistant( id: MessageId, content: Vec<ContentBlock>, stop_reason: StopReason, timestamp: ProtocolTimestamp, ) -> Result<Self, MessageValidationError>
Creates a validated assistant message.
§Errors
Returns an error when content is empty, too numerous, or contains a block that is invalid for the assistant role.
Sourcepub fn tool_result_success(
id: MessageId,
tool_call_id: ToolCallId,
tool_name: impl Into<String>,
content: Vec<ContentBlock>,
timestamp: ProtocolTimestamp,
) -> Result<Self, MessageValidationError>
pub fn tool_result_success( id: MessageId, tool_call_id: ToolCallId, tool_name: impl Into<String>, content: Vec<ContentBlock>, timestamp: ProtocolTimestamp, ) -> Result<Self, MessageValidationError>
Creates a successful tool-result message.
§Errors
Returns an error when the tool name or result content is invalid.
Sourcepub fn tool_result_failure(
id: MessageId,
tool_call_id: ToolCallId,
tool_name: impl Into<String>,
content: Vec<ContentBlock>,
error: ToolFailure,
timestamp: ProtocolTimestamp,
) -> Result<Self, MessageValidationError>
pub fn tool_result_failure( id: MessageId, tool_call_id: ToolCallId, tool_name: impl Into<String>, content: Vec<ContentBlock>, error: ToolFailure, timestamp: ProtocolTimestamp, ) -> Result<Self, MessageValidationError>
Creates a failed tool-result message.
§Errors
Returns an error when the tool name or result content is invalid.
Sourcepub const fn role(&self) -> MessageRole
pub const fn role(&self) -> MessageRole
Returns the message role.
Trait Implementations§
Source§impl Clone for CanonicalMessage
impl Clone for CanonicalMessage
Source§fn clone(&self) -> CanonicalMessage
fn clone(&self) -> CanonicalMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more