use turul_a2a_proto as pb;
use turul_a2a_types::Part;
pub struct MessageBuilder {
message_id: String,
role: i32,
parts: Vec<pb::Part>,
context_id: String,
task_id: String,
}
impl MessageBuilder {
pub fn new() -> Self {
Self {
message_id: uuid::Uuid::now_v7().to_string(),
role: pb::Role::User.into(),
parts: vec![],
context_id: String::new(),
task_id: String::new(),
}
}
pub fn text(mut self, text: impl Into<String>) -> Self {
self.parts.push(pb::Part {
content: Some(pb::part::Content::Text(text.into())),
metadata: None,
filename: String::new(),
media_type: String::new(),
});
self
}
pub fn data(mut self, value: serde_json::Value) -> Self {
self.parts.push(Part::data(value).into_proto());
self
}
pub fn part(mut self, part: Part) -> Self {
self.parts.push(part.into_proto());
self
}
pub fn parts<I>(mut self, parts: I) -> Self
where
I: IntoIterator<Item = Part>,
{
self.parts.extend(parts.into_iter().map(|p| p.into_proto()));
self
}
pub fn role(mut self, role: turul_a2a_types::Role) -> Self {
self.role = pb::Role::from(role).into();
self
}
pub fn message_id(mut self, id: impl Into<String>) -> Self {
self.message_id = id.into();
self
}
pub fn context_id(mut self, id: impl Into<String>) -> Self {
self.context_id = id.into();
self
}
pub fn task_id(mut self, id: impl Into<String>) -> Self {
self.task_id = id.into();
self
}
pub fn build(self) -> pb::SendMessageRequest {
pb::SendMessageRequest {
message: Some(pb::Message {
message_id: self.message_id,
role: self.role,
parts: self.parts,
context_id: self.context_id,
task_id: self.task_id,
metadata: None,
extensions: vec![],
reference_task_ids: vec![],
}),
configuration: None,
metadata: None,
tenant: String::new(),
}
}
}
impl From<MessageBuilder> for pb::SendMessageRequest {
fn from(builder: MessageBuilder) -> Self {
builder.build()
}
}
impl Default for MessageBuilder {
fn default() -> Self {
Self::new()
}
}