Skip to main content

Message

Struct Message 

Source
#[non_exhaustive]
pub struct Message { /* private fields */ }
Expand description

Ergonomic wrapper over proto Message.

Implementations§

Source§

impl Message

Source

pub fn new(message_id: impl Into<String>, role: Role, parts: Vec<Part>) -> Self

Source

pub fn with_context_id(self, context_id: impl Into<String>) -> Self

Source

pub fn with_task_id(self, task_id: impl Into<String>) -> Self

Source

pub fn message_id(&self) -> &str

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn data_parts(&self) -> Vec<Value>

Raw JSON data parts (no number normalization).

Source

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.

Source

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.

Source

pub fn as_proto(&self) -> &Message

Source

pub fn into_proto(self) -> Message

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Message> for Message

Source§

fn from(msg: Message) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Message

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Message> for Message

Source§

type Error = A2aTypeError

The type returned in the event of a conversion error.
Source§

fn try_from(inner: Message) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,