#[non_exhaustive]pub struct Message { /* private fields */ }Expand description
Ergonomic wrapper over proto Message.
Implementations§
Source§impl Message
impl Message
pub fn new(message_id: impl Into<String>, role: Role, parts: Vec<Part>) -> Self
pub fn with_context_id(self, context_id: impl Into<String>) -> Self
pub fn with_task_id(self, task_id: impl Into<String>) -> Self
pub fn message_id(&self) -> &str
Sourcepub fn context_id(&self) -> &str
pub fn context_id(&self) -> &str
Context id, or empty string if unset. Proto default for the
context_id field is the empty string, not null.
Sourcepub fn task_id(&self) -> &str
pub fn task_id(&self) -> &str
Task id the message is bound to, or empty string if unset. Callers making a fresh request leave this empty; continuations set it to the existing task’s id.
Sourcepub fn metadata(&self) -> Option<&Struct>
pub fn metadata(&self) -> Option<&Struct>
Borrow the raw Message.metadata proto struct. Prefer
Self::metadata_keys for the common “which correlation fields
arrived” check; drop to this accessor when you need to read
specific values.
Sourcepub fn metadata_keys(&self) -> Vec<String>
pub fn metadata_keys(&self) -> Vec<String>
Sorted list of keys present on Message.metadata. Returns an
empty vec if metadata is unset. Convenient for log lines and
demo-level “which correlation fields did the caller supply”
inspection without exposing the values themselves.
Sourcepub fn text_parts(&self) -> Vec<&str>
pub fn text_parts(&self) -> Vec<&str>
Returns individual text parts, preserving part boundaries. This is the primary safe accessor for message text content. Callers decide how to combine parts.
Sourcepub fn joined_text(&self) -> String
pub fn joined_text(&self) -> String
Convenience: joins all text parts with a single space.
Use text_parts() when part boundaries matter (e.g., multi-part prompts).
Sourcepub fn data_parts(&self) -> Vec<Value>
pub fn data_parts(&self) -> Vec<Value>
Raw JSON data parts (no number normalization).
Sourcepub fn parse_first_data<T: DeserializeOwned>(
&self,
) -> Option<Result<T, A2aTypeError>>
pub fn parse_first_data<T: DeserializeOwned>( &self, ) -> Option<Result<T, A2aTypeError>>
Deserialize the first Data part into T, normalizing proto f64 integers.
Returns None if no Data part exists. Returns Err if deserialization fails.
Sourcepub fn parse_first_data_or_text<T: DeserializeOwned>(
&self,
) -> Option<Result<T, A2aTypeError>>
pub fn parse_first_data_or_text<T: DeserializeOwned>( &self, ) -> Option<Result<T, A2aTypeError>>
Deserialize from the first Data part, falling back to parsing the first Text part as JSON.
A2A protocol v0.3 clients (e.g., Strands A2AAgent via a2a-sdk) send
typed JSON as a text part ({"kind":"text","text":"{...}"}), while
Turul clients send it as a data part. This method handles both.
Preference order: Data part (proto struct) → Text part (JSON string).
Returns None if no Data or parseable Text part exists.