a2a_protocol_types/
wire_builders.rs1use crate::agent_card::{AgentCapabilities, AgentInterface, AgentProvider};
19use crate::artifact::{Artifact, ArtifactId};
20use crate::events::{TaskArtifactUpdateEvent, TaskStatusUpdateEvent};
21use crate::extensions::AgentExtension;
22use crate::message::Message;
23use crate::push::{AuthenticationInfo, TaskPushNotificationConfig};
24use crate::task::{ContextId, Task, TaskId, TaskStatus};
25
26impl TaskStatus {
27 #[must_use]
30 pub fn with_message(mut self, message: Message) -> Self {
31 self.message = Some(message);
32 self
33 }
34
35 #[must_use]
39 pub fn at(mut self, timestamp: impl Into<String>) -> Self {
40 self.timestamp = Some(timestamp.into());
41 self
42 }
43}
44
45impl Task {
46 #[must_use]
48 pub fn with_history(mut self, history: Vec<Message>) -> Self {
49 self.history = Some(history);
50 self
51 }
52
53 #[must_use]
55 pub fn with_artifacts(mut self, artifacts: Vec<Artifact>) -> Self {
56 self.artifacts = Some(artifacts);
57 self
58 }
59
60 #[must_use]
62 pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
63 self.metadata = Some(metadata);
64 self
65 }
66}
67
68impl Artifact {
69 #[must_use]
71 pub fn with_name(mut self, name: impl Into<String>) -> Self {
72 self.name = Some(name.into());
73 self
74 }
75
76 #[must_use]
78 pub fn with_description(mut self, description: impl Into<String>) -> Self {
79 self.description = Some(description.into());
80 self
81 }
82
83 #[must_use]
85 pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
86 self.metadata = Some(metadata);
87 self
88 }
89
90 #[must_use]
92 pub fn with_extensions<I, S>(mut self, extensions: I) -> Self
93 where
94 I: IntoIterator<Item = S>,
95 S: Into<String>,
96 {
97 self.extensions = Some(extensions.into_iter().map(Into::into).collect());
98 self
99 }
100
101 #[must_use]
106 pub fn unchecked(id: impl Into<ArtifactId>, parts: Vec<crate::message::Part>) -> Self {
107 let mut artifact = Self::new(id, vec![crate::message::Part::text(String::new())]);
108 artifact.parts = parts;
109 artifact
110 }
111}
112
113impl TaskStatusUpdateEvent {
114 #[must_use]
117 pub fn new(
118 task_id: impl Into<TaskId>,
119 context_id: impl Into<ContextId>,
120 status: TaskStatus,
121 ) -> Self {
122 Self {
123 task_id: task_id.into(),
124 context_id: context_id.into(),
125 status,
126 metadata: None,
127 }
128 }
129
130 #[must_use]
132 pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
133 self.metadata = Some(metadata);
134 self
135 }
136}
137
138impl TaskArtifactUpdateEvent {
139 #[must_use]
142 pub fn new(
143 task_id: impl Into<TaskId>,
144 context_id: impl Into<ContextId>,
145 artifact: Artifact,
146 ) -> Self {
147 Self {
148 task_id: task_id.into(),
149 context_id: context_id.into(),
150 artifact,
151 append: None,
152 last_chunk: None,
153 metadata: None,
154 }
155 }
156
157 #[must_use]
160 pub const fn with_append(mut self, append: bool) -> Self {
161 self.append = Some(append);
162 self
163 }
164
165 #[must_use]
167 pub const fn with_last_chunk(mut self, last_chunk: bool) -> Self {
168 self.last_chunk = Some(last_chunk);
169 self
170 }
171
172 #[must_use]
174 pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
175 self.metadata = Some(metadata);
176 self
177 }
178}
179
180impl TaskPushNotificationConfig {
181 #[must_use]
184 pub fn for_url(url: impl Into<String>) -> Self {
185 Self {
186 tenant: None,
187 id: None,
188 task_id: None,
189 url: url.into(),
190 token: None,
191 authentication: None,
192 }
193 }
194
195 #[must_use]
197 pub fn with_id(mut self, id: impl Into<String>) -> Self {
198 self.id = Some(id.into());
199 self
200 }
201
202 #[must_use]
205 pub fn with_token(mut self, token: impl Into<String>) -> Self {
206 self.token = Some(token.into());
207 self
208 }
209
210 #[must_use]
212 pub fn with_authentication(mut self, authentication: AuthenticationInfo) -> Self {
213 self.authentication = Some(authentication);
214 self
215 }
216
217 #[must_use]
219 pub fn with_tenant(mut self, tenant: impl Into<String>) -> Self {
220 self.tenant = Some(tenant.into());
221 self
222 }
223}
224
225impl AgentExtension {
226 #[must_use]
228 pub fn with_description(mut self, description: impl Into<String>) -> Self {
229 self.description = Some(description.into());
230 self
231 }
232
233 #[must_use]
235 pub const fn with_required(mut self, required: bool) -> Self {
236 self.required = Some(required);
237 self
238 }
239
240 #[must_use]
242 pub fn with_params(mut self, params: serde_json::Value) -> Self {
243 self.params = Some(params);
244 self
245 }
246}
247
248impl AgentProvider {
249 #[must_use]
251 pub fn new(organization: impl Into<String>, url: impl Into<String>) -> Self {
252 Self {
253 url: url.into(),
254 organization: organization.into(),
255 }
256 }
257}
258
259impl AgentCapabilities {
260 #[must_use]
262 pub fn with_extensions(mut self, extensions: Vec<AgentExtension>) -> Self {
263 self.extensions = Some(extensions);
264 self
265 }
266}
267
268impl AgentInterface {
269 #[must_use]
272 pub fn with_protocol_version(mut self, version: impl Into<String>) -> Self {
273 self.protocol_version = version.into();
274 self
275 }
276}
277
278#[cfg(test)]
279#[path = "wire_builders_tests.rs"]
280mod tests;