1use serde::{Deserialize, Serialize};
15use std::collections::HashMap;
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct JSONRPCMessage {
24 pub jsonrpc: String,
26 #[serde(skip_serializing_if = "Option::is_none")]
29 pub id: Option<JSONRPCId>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
34#[serde(untagged)]
35pub enum JSONRPCId {
36 String(String),
37 Integer(i64),
38 Null,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct JSONRPCRequest {
44 pub jsonrpc: String,
46 pub method: String,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 pub params: Option<serde_json::Value>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct JSONRPCSuccessResponse {
56 pub jsonrpc: String,
58 pub result: serde_json::Value,
60 pub id: Option<JSONRPCId>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct JSONRPCErrorResponse {
67 pub jsonrpc: String,
69 pub error: JSONRPCError,
71 pub id: Option<JSONRPCId>,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct JSONRPCError {
78 pub code: i32,
80 pub message: String,
82 #[serde(skip_serializing_if = "Option::is_none")]
85 pub data: Option<serde_json::Value>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum JSONRPCResponse {
93 SendMessage(SendMessageResponse),
94 SendStreamingMessage(SendStreamingMessageResponse),
95 GetTask(GetTaskResponse),
96 CancelTask(CancelTaskResponse),
97 SetTaskPushNotificationConfig(SetTaskPushNotificationConfigResponse),
98 GetTaskPushNotificationConfig(GetTaskPushNotificationConfigResponse),
99 ListTaskPushNotificationConfig(ListTaskPushNotificationConfigResponse),
100 DeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigResponse),
101 GetAuthenticatedExtendedCard(GetAuthenticatedExtendedCardResponse),
102 Error(JSONRPCErrorResponse),
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(default)]
112pub struct JSONParseError {
113 pub code: i32, pub message: String,
117 #[serde(skip_serializing_if = "Option::is_none")]
119 pub data: Option<serde_json::Value>,
120}
121
122impl Default for JSONParseError {
123 fn default() -> Self {
124 Self {
125 code: JSON_PARSE_ERROR_CODE,
126 message: JSON_PARSE_ERROR_MESSAGE.to_string(),
127 data: None,
128 }
129 }
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(default)]
135pub struct InvalidRequestError {
136 pub code: i32, pub message: String,
140 #[serde(skip_serializing_if = "Option::is_none")]
142 pub data: Option<serde_json::Value>,
143}
144
145impl Default for InvalidRequestError {
146 fn default() -> Self {
147 Self {
148 code: INVALID_REQUEST_ERROR_CODE,
149 message: INVALID_REQUEST_ERROR_MESSAGE.to_string(),
150 data: None,
151 }
152 }
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
157#[serde(default)]
158pub struct MethodNotFoundError {
159 pub code: i32, pub message: String,
163 #[serde(skip_serializing_if = "Option::is_none")]
165 pub data: Option<serde_json::Value>,
166}
167
168impl Default for MethodNotFoundError {
169 fn default() -> Self {
170 Self {
171 code: METHOD_NOT_FOUND_ERROR_CODE,
172 message: METHOD_NOT_FOUND_ERROR_MESSAGE.to_string(),
173 data: None,
174 }
175 }
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize)]
180#[serde(default)]
181pub struct InvalidParamsError {
182 pub code: i32, pub message: String,
186 #[serde(skip_serializing_if = "Option::is_none")]
188 pub data: Option<serde_json::Value>,
189}
190
191impl Default for InvalidParamsError {
192 fn default() -> Self {
193 Self {
194 code: INVALID_PARAMS_ERROR_CODE,
195 message: INVALID_PARAMS_ERROR_MESSAGE.to_string(),
196 data: None,
197 }
198 }
199}
200
201#[derive(Debug, Clone, Serialize, Deserialize)]
203#[serde(default)]
204pub struct InternalError {
205 pub code: i32, pub message: String,
209 #[serde(skip_serializing_if = "Option::is_none")]
211 pub data: Option<serde_json::Value>,
212}
213
214impl Default for InternalError {
215 fn default() -> Self {
216 Self {
217 code: INTERNAL_ERROR_CODE,
218 message: INTERNAL_ERROR_MESSAGE.to_string(),
219 data: None,
220 }
221 }
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(default)]
227pub struct TaskNotFoundError {
228 pub code: i32, pub message: String,
232 #[serde(skip_serializing_if = "Option::is_none")]
234 pub data: Option<serde_json::Value>,
235}
236
237impl Default for TaskNotFoundError {
238 fn default() -> Self {
239 Self {
240 code: TASK_NOT_FOUND_ERROR_CODE,
241 message: TASK_NOT_FOUND_ERROR_MESSAGE.to_string(),
242 data: None,
243 }
244 }
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249#[serde(default)]
250pub struct TaskNotCancelableError {
251 pub code: i32, pub message: String,
255 #[serde(skip_serializing_if = "Option::is_none")]
257 pub data: Option<serde_json::Value>,
258}
259
260impl Default for TaskNotCancelableError {
261 fn default() -> Self {
262 Self {
263 code: TASK_NOT_CANCELABLE_ERROR_CODE,
264 message: TASK_NOT_CANCELABLE_ERROR_MESSAGE.to_string(),
265 data: None,
266 }
267 }
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
272#[serde(default)]
273pub struct PushNotificationNotSupportedError {
274 pub code: i32, pub message: String,
278 #[serde(skip_serializing_if = "Option::is_none")]
280 pub data: Option<serde_json::Value>,
281}
282
283impl Default for PushNotificationNotSupportedError {
284 fn default() -> Self {
285 Self {
286 code: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE,
287 message: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
288 data: None,
289 }
290 }
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize)]
295#[serde(default)]
296pub struct UnsupportedOperationError {
297 pub code: i32, pub message: String,
301 #[serde(skip_serializing_if = "Option::is_none")]
303 pub data: Option<serde_json::Value>,
304}
305
306impl Default for UnsupportedOperationError {
307 fn default() -> Self {
308 Self {
309 code: UNSUPPORTED_OPERATION_ERROR_CODE,
310 message: UNSUPPORTED_OPERATION_ERROR_MESSAGE.to_string(),
311 data: None,
312 }
313 }
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize)]
319#[serde(default)]
320pub struct ContentTypeNotSupportedError {
321 pub code: i32, pub message: String,
325 #[serde(skip_serializing_if = "Option::is_none")]
327 pub data: Option<serde_json::Value>,
328}
329
330impl Default for ContentTypeNotSupportedError {
331 fn default() -> Self {
332 Self {
333 code: CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE,
334 message: CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
335 data: None,
336 }
337 }
338}
339
340#[derive(Debug, Clone, Serialize, Deserialize)]
343#[serde(default)]
344pub struct InvalidAgentResponseError {
345 pub code: i32, pub message: String,
349 #[serde(skip_serializing_if = "Option::is_none")]
351 pub data: Option<serde_json::Value>,
352}
353
354impl Default for InvalidAgentResponseError {
355 fn default() -> Self {
356 Self {
357 code: INVALID_AGENT_RESPONSE_ERROR_CODE,
358 message: INVALID_AGENT_RESPONSE_ERROR_MESSAGE.to_string(),
359 data: None,
360 }
361 }
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize)]
366#[serde(default)]
367pub struct AuthenticatedExtendedCardNotConfiguredError {
368 pub code: i32, pub message: String,
372 #[serde(skip_serializing_if = "Option::is_none")]
374 pub data: Option<serde_json::Value>,
375}
376
377impl Default for AuthenticatedExtendedCardNotConfiguredError {
378 fn default() -> Self {
379 Self {
380 code: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE,
381 message: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE.to_string(),
382 data: None,
383 }
384 }
385}
386
387#[derive(Debug, Clone, Serialize, Deserialize)]
389#[serde(untagged)]
390pub enum A2AError {
391 JSONParse(JSONParseError),
392 InvalidRequest(InvalidRequestError),
393 MethodNotFound(MethodNotFoundError),
394 InvalidParams(InvalidParamsError),
395 Internal(InternalError),
396 TaskNotFound(TaskNotFoundError),
397 TaskNotCancelable(TaskNotCancelableError),
398 PushNotificationNotSupported(PushNotificationNotSupportedError),
399 UnsupportedOperation(UnsupportedOperationError),
400 ContentTypeNotSupported(ContentTypeNotSupportedError),
401 InvalidAgentResponse(InvalidAgentResponseError),
402 AuthenticatedExtendedCardNotConfigured(AuthenticatedExtendedCardNotConfiguredError),
403}
404
405const JSON_PARSE_ERROR_CODE: i32 = -32700;
407const JSON_PARSE_ERROR_MESSAGE: &str = "Invalid JSON payload";
408const INVALID_REQUEST_ERROR_CODE: i32 = -32600;
409const INVALID_REQUEST_ERROR_MESSAGE: &str = "Request payload validation error";
410const METHOD_NOT_FOUND_ERROR_CODE: i32 = -32601;
411const METHOD_NOT_FOUND_ERROR_MESSAGE: &str = "Method not found";
412const INVALID_PARAMS_ERROR_CODE: i32 = -32602;
413const INVALID_PARAMS_ERROR_MESSAGE: &str = "Invalid parameters";
414const INTERNAL_ERROR_CODE: i32 = -32603;
415const INTERNAL_ERROR_MESSAGE: &str = "Internal error";
416const TASK_NOT_FOUND_ERROR_CODE: i32 = -32001;
417const TASK_NOT_FOUND_ERROR_MESSAGE: &str = "Task not found";
418const TASK_NOT_CANCELABLE_ERROR_CODE: i32 = -32002;
419const TASK_NOT_CANCELABLE_ERROR_MESSAGE: &str = "Task cannot be canceled";
420const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE: i32 = -32003;
421const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Push Notification is not supported";
422const UNSUPPORTED_OPERATION_ERROR_CODE: i32 = -32004;
423const UNSUPPORTED_OPERATION_ERROR_MESSAGE: &str = "This operation is not supported";
424const CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE: i32 = -32005;
425const CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Incompatible content types";
426const INVALID_AGENT_RESPONSE_ERROR_CODE: i32 = -32006;
427const INVALID_AGENT_RESPONSE_ERROR_MESSAGE: &str = "Invalid agent response";
428const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE: i32 = -32007;
429const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE: &str =
430 "Authenticated Extended Card is not configured";
431
432#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
438#[serde(rename_all = "kebab-case")]
439pub enum TaskState {
440 Submitted,
442 Working,
444 InputRequired,
446 Completed,
448 Canceled,
450 Failed,
452 Rejected,
454 AuthRequired,
456 Unknown,
458}
459
460#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
462pub struct TaskStatus {
463 pub state: TaskState,
465 #[serde(skip_serializing_if = "Option::is_none")]
467 pub timestamp: Option<String>,
468 #[serde(skip_serializing_if = "Option::is_none")]
470 pub message: Option<Message>,
471}
472
473#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
475pub struct Task {
476 #[serde(default = "default_task_kind")]
478 pub kind: String,
479 pub id: String,
481 #[serde(rename = "contextId")]
483 pub context_id: String,
484 pub status: TaskStatus,
486 #[serde(skip_serializing_if = "Vec::is_empty", default)]
488 pub history: Vec<Message>,
489 #[serde(skip_serializing_if = "Vec::is_empty", default)]
491 pub artifacts: Vec<Artifact>,
492 #[serde(skip_serializing_if = "Option::is_none")]
494 pub metadata: Option<HashMap<String, serde_json::Value>>,
495}
496
497fn default_task_kind() -> String {
498 TASK_KIND.to_string()
499}
500
501#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
503#[serde(rename_all = "lowercase")]
504pub enum MessageRole {
505 User,
507 Agent,
509}
510
511impl PartialEq<&str> for MessageRole {
512 fn eq(&self, other: &&str) -> bool {
513 matches!(
514 (self, *other),
515 (MessageRole::User, "user")
516 | (MessageRole::Agent, "agent")
517 | (MessageRole::Agent, "assistant")
518 )
519 }
520}
521
522#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
524pub struct Message {
525 #[serde(default = "default_message_kind")]
527 pub kind: String,
528 #[serde(rename = "messageId")]
530 pub message_id: String,
531 pub role: MessageRole,
533 pub parts: Vec<Part>,
535 #[serde(skip_serializing_if = "Option::is_none", rename = "contextId")]
537 pub context_id: Option<String>,
538 #[serde(skip_serializing_if = "Option::is_none", rename = "taskId")]
540 pub task_id: Option<String>,
541 #[serde(
543 skip_serializing_if = "Vec::is_empty",
544 rename = "referenceTaskIds",
545 default
546 )]
547 pub reference_task_ids: Vec<String>,
548 #[serde(skip_serializing_if = "Vec::is_empty", default)]
550 pub extensions: Vec<String>,
551 #[serde(skip_serializing_if = "Option::is_none")]
553 pub metadata: Option<HashMap<String, serde_json::Value>>,
554}
555
556fn default_message_kind() -> String {
557 MESSAGE_KIND.to_string()
558}
559
560#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
562#[serde(tag = "kind", rename_all = "lowercase")]
563pub enum Part {
564 Text {
566 text: String,
568 #[serde(skip_serializing_if = "Option::is_none")]
570 metadata: Option<HashMap<String, serde_json::Value>>,
571 },
572 File {
574 file: FileContent,
576 #[serde(skip_serializing_if = "Option::is_none")]
578 metadata: Option<HashMap<String, serde_json::Value>>,
579 },
580 Data {
582 data: serde_json::Value,
584 #[serde(skip_serializing_if = "Option::is_none")]
586 metadata: Option<HashMap<String, serde_json::Value>>,
587 },
588}
589
590impl Part {
591 pub fn as_data(&self) -> Option<&serde_json::Value> {
592 match self {
593 Part::Data { data, .. } => Some(data),
594 _ => None,
595 }
596 }
597}
598
599#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
601#[serde(untagged)]
602pub enum FileContent {
603 WithBytes(FileWithBytes),
604 WithUri(FileWithUri),
605}
606
607#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
609pub struct FileWithBytes {
610 pub bytes: String,
612 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
614 pub mime_type: Option<String>,
615 #[serde(skip_serializing_if = "Option::is_none")]
617 pub name: Option<String>,
618}
619
620#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
622pub struct FileWithUri {
623 pub uri: String,
625 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
627 pub mime_type: Option<String>,
628 #[serde(skip_serializing_if = "Option::is_none")]
630 pub name: Option<String>,
631}
632
633#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
635pub struct Artifact {
636 #[serde(rename = "artifactId")]
638 pub artifact_id: String,
639 pub parts: Vec<Part>,
641 #[serde(skip_serializing_if = "Option::is_none")]
643 pub name: Option<String>,
644 #[serde(skip_serializing_if = "Option::is_none")]
646 pub description: Option<String>,
647 #[serde(skip_serializing_if = "Vec::is_empty", default)]
649 pub extensions: Vec<String>,
650 #[serde(skip_serializing_if = "Option::is_none")]
652 pub metadata: Option<HashMap<String, serde_json::Value>>,
653}
654
655#[derive(Debug, Clone, Serialize, Deserialize)]
661pub struct MessageSendParams {
662 pub message: Message,
664 #[serde(skip_serializing_if = "Option::is_none")]
666 pub configuration: Option<MessageSendConfiguration>,
667 #[serde(skip_serializing_if = "Option::is_none")]
669 pub metadata: Option<HashMap<String, serde_json::Value>>,
670}
671
672#[derive(Debug, Clone, Serialize, Deserialize, Default)]
674pub struct MessageSendConfiguration {
675 #[serde(skip_serializing_if = "Option::is_none")]
677 pub blocking: Option<bool>,
678 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
680 pub history_length: Option<i32>,
681 #[serde(
683 skip_serializing_if = "Vec::is_empty",
684 rename = "acceptedOutputModes",
685 default
686 )]
687 pub accepted_output_modes: Vec<String>,
688 #[serde(
690 skip_serializing_if = "Option::is_none",
691 rename = "pushNotificationConfig"
692 )]
693 pub push_notification_config: Option<PushNotificationConfig>,
694}
695
696#[derive(Debug, Clone, Serialize, Deserialize)]
698pub struct PushNotificationConfig {
699 pub url: String,
701 #[serde(skip_serializing_if = "Option::is_none")]
703 pub id: Option<String>,
704 #[serde(skip_serializing_if = "Option::is_none")]
706 pub token: Option<String>,
707 #[serde(skip_serializing_if = "Option::is_none")]
709 pub authentication: Option<PushNotificationAuthenticationInfo>,
710}
711
712#[derive(Debug, Clone, Serialize, Deserialize)]
714pub struct PushNotificationAuthenticationInfo {
715 pub schemes: Vec<String>,
717 #[serde(skip_serializing_if = "Option::is_none")]
719 pub credentials: Option<String>,
720}
721
722#[derive(Debug, Clone, Serialize, Deserialize)]
724pub struct TaskIdParams {
725 pub id: String,
727 #[serde(skip_serializing_if = "Option::is_none")]
729 pub metadata: Option<HashMap<String, serde_json::Value>>,
730}
731
732#[derive(Debug, Clone, Serialize, Deserialize)]
734pub struct TaskQueryParams {
735 pub id: String,
737 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
739 pub history_length: Option<i32>,
740 #[serde(skip_serializing_if = "Option::is_none")]
742 pub metadata: Option<HashMap<String, serde_json::Value>>,
743}
744
745#[derive(Debug, Clone, Serialize, Deserialize)]
747pub struct TaskPushNotificationConfig {
748 #[serde(rename = "taskId")]
750 pub task_id: String,
751 #[serde(rename = "pushNotificationConfig")]
753 pub push_notification_config: PushNotificationConfig,
754}
755
756#[derive(Debug, Clone, Serialize, Deserialize)]
758#[serde(untagged)]
759pub enum GetTaskPushNotificationConfigParams {
760 TaskIdOnly(TaskIdParams),
761 WithConfigId(GetTaskPushNotificationConfigParamsWithId),
762}
763
764#[derive(Debug, Clone, Serialize, Deserialize)]
766pub struct GetTaskPushNotificationConfigParamsWithId {
767 pub id: String,
769 #[serde(rename = "pushNotificationConfigId")]
771 pub push_notification_config_id: String,
772 #[serde(skip_serializing_if = "Option::is_none")]
774 pub metadata: Option<HashMap<String, serde_json::Value>>,
775}
776
777#[derive(Debug, Clone, Serialize, Deserialize)]
779pub struct ListTaskPushNotificationConfigParams {
780 pub id: String,
782 #[serde(skip_serializing_if = "Option::is_none")]
784 pub metadata: Option<HashMap<String, serde_json::Value>>,
785}
786
787#[derive(Debug, Clone, Serialize, Deserialize)]
789pub struct DeleteTaskPushNotificationConfigParams {
790 pub id: String,
792 #[serde(rename = "pushNotificationConfigId")]
794 pub push_notification_config_id: String,
795 #[serde(skip_serializing_if = "Option::is_none")]
797 pub metadata: Option<HashMap<String, serde_json::Value>>,
798}
799
800fn default_jsonrpc_version() -> String {
805 "2.0".to_string()
806}
807
808#[derive(Debug, Clone, Serialize, Deserialize)]
810pub struct A2ARequest {
811 #[serde(default = "default_jsonrpc_version")]
813 pub jsonrpc: String,
814 #[serde(skip_serializing_if = "Option::is_none")]
816 pub id: Option<JSONRPCId>,
817 #[serde(flatten)]
819 pub payload: A2ARequestPayload,
820}
821
822#[derive(Debug, Clone, Serialize, Deserialize)]
824#[serde(tag = "method")]
825pub enum A2ARequestPayload {
826 #[serde(rename = "message/send")]
828 SendMessage { params: MessageSendParams },
829 #[serde(rename = "message/stream")]
831 SendStreamingMessage { params: MessageSendParams },
832 #[serde(rename = "tasks/get")]
834 GetTask { params: TaskQueryParams },
835 #[serde(rename = "tasks/cancel")]
837 CancelTask { params: TaskIdParams },
838 #[serde(rename = "tasks/pushNotificationConfig/set")]
840 SetTaskPushNotificationConfig { params: TaskPushNotificationConfig },
841 #[serde(rename = "tasks/pushNotificationConfig/get")]
843 GetTaskPushNotificationConfig {
844 params: GetTaskPushNotificationConfigParams,
845 },
846 #[serde(rename = "tasks/resubscribe")]
848 TaskResubscription { params: TaskIdParams },
849 #[serde(rename = "tasks/pushNotificationConfig/list")]
851 ListTaskPushNotificationConfig {
852 params: ListTaskPushNotificationConfigParams,
853 },
854 #[serde(rename = "tasks/pushNotificationConfig/delete")]
856 DeleteTaskPushNotificationConfig {
857 params: DeleteTaskPushNotificationConfigParams,
858 },
859 #[serde(rename = "agent/getAuthenticatedExtendedCard")]
861 GetAuthenticatedExtendedCard,
862}
863
864#[derive(Debug, Clone, Serialize, Deserialize)]
870#[serde(untagged)]
871pub enum SendMessageResult {
872 Task(Task),
873 Message(Message),
874}
875
876#[derive(Debug, Clone, Serialize, Deserialize)]
878pub struct SendMessageSuccessResponse {
879 pub jsonrpc: String, pub result: SendMessageResult,
881 pub id: Option<JSONRPCId>,
882}
883
884#[derive(Debug, Clone, Serialize, Deserialize)]
886#[serde(untagged)]
887pub enum SendMessageResponse {
888 Success(Box<SendMessageSuccessResponse>),
889 Error(JSONRPCErrorResponse),
890}
891
892#[derive(Debug, Clone, Serialize, Deserialize)]
894#[serde(untagged)]
895pub enum SendStreamingMessageResult {
896 Task(Task),
897 Message(Message),
898 TaskStatusUpdate(TaskStatusUpdateEvent),
899 TaskArtifactUpdate(TaskArtifactUpdateEvent),
900}
901
902#[derive(Debug, Clone, Serialize, Deserialize)]
904pub struct SendStreamingMessageSuccessResponse {
905 pub jsonrpc: String, pub result: SendStreamingMessageResult,
907 pub id: Option<JSONRPCId>,
908}
909
910#[derive(Debug, Clone, Serialize, Deserialize)]
912#[serde(untagged)]
913pub enum SendStreamingMessageResponse {
914 Success(Box<SendStreamingMessageSuccessResponse>),
915 Error(JSONRPCErrorResponse),
916}
917
918#[derive(Debug, Clone, Serialize, Deserialize)]
920pub struct GetTaskSuccessResponse {
921 pub jsonrpc: String, pub result: Task,
923 pub id: Option<JSONRPCId>,
924}
925
926#[derive(Debug, Clone, Serialize, Deserialize)]
928#[serde(untagged)]
929pub enum GetTaskResponse {
930 Success(Box<GetTaskSuccessResponse>),
931 Error(JSONRPCErrorResponse),
932}
933
934#[derive(Debug, Clone, Serialize, Deserialize)]
936pub struct CancelTaskSuccessResponse {
937 pub jsonrpc: String, pub result: Task,
939 pub id: Option<JSONRPCId>,
940}
941
942#[derive(Debug, Clone, Serialize, Deserialize)]
944#[serde(untagged)]
945pub enum CancelTaskResponse {
946 Success(Box<CancelTaskSuccessResponse>),
947 Error(JSONRPCErrorResponse),
948}
949
950#[derive(Debug, Clone, Serialize, Deserialize)]
952pub struct SetTaskPushNotificationConfigSuccessResponse {
953 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
955 pub id: Option<JSONRPCId>,
956}
957
958#[derive(Debug, Clone, Serialize, Deserialize)]
960#[serde(untagged)]
961pub enum SetTaskPushNotificationConfigResponse {
962 Success(Box<SetTaskPushNotificationConfigSuccessResponse>),
963 Error(JSONRPCErrorResponse),
964}
965
966#[derive(Debug, Clone, Serialize, Deserialize)]
968pub struct GetTaskPushNotificationConfigSuccessResponse {
969 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
971 pub id: Option<JSONRPCId>,
972}
973
974#[derive(Debug, Clone, Serialize, Deserialize)]
976#[serde(untagged)]
977pub enum GetTaskPushNotificationConfigResponse {
978 Success(Box<GetTaskPushNotificationConfigSuccessResponse>),
979 Error(JSONRPCErrorResponse),
980}
981
982#[derive(Debug, Clone, Serialize, Deserialize)]
984pub struct ListTaskPushNotificationConfigSuccessResponse {
985 pub jsonrpc: String, pub result: Vec<TaskPushNotificationConfig>,
987 pub id: Option<JSONRPCId>,
988}
989
990#[derive(Debug, Clone, Serialize, Deserialize)]
992#[serde(untagged)]
993pub enum ListTaskPushNotificationConfigResponse {
994 Success(Box<ListTaskPushNotificationConfigSuccessResponse>),
995 Error(JSONRPCErrorResponse),
996}
997
998#[derive(Debug, Clone, Serialize, Deserialize)]
1000pub struct DeleteTaskPushNotificationConfigSuccessResponse {
1001 pub jsonrpc: String, pub result: (),
1004 pub id: Option<JSONRPCId>,
1005}
1006
1007#[derive(Debug, Clone, Serialize, Deserialize)]
1009#[serde(untagged)]
1010pub enum DeleteTaskPushNotificationConfigResponse {
1011 Success(Box<DeleteTaskPushNotificationConfigSuccessResponse>),
1012 Error(JSONRPCErrorResponse),
1013}
1014
1015#[derive(Debug, Clone, Serialize, Deserialize)]
1017pub struct GetAuthenticatedExtendedCardSuccessResponse {
1018 pub jsonrpc: String, pub result: AgentCard,
1020 pub id: Option<JSONRPCId>,
1021}
1022
1023#[derive(Debug, Clone, Serialize, Deserialize)]
1025#[serde(untagged)]
1026pub enum GetAuthenticatedExtendedCardResponse {
1027 Success(Box<GetAuthenticatedExtendedCardSuccessResponse>),
1028 Error(JSONRPCErrorResponse),
1029}
1030
1031#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1037pub enum TransportProtocol {
1038 #[serde(rename = "JSONRPC")]
1040 JsonRpc,
1041 #[serde(rename = "GRPC")]
1043 Grpc,
1044 #[serde(rename = "HTTP+JSON")]
1046 HttpJson,
1047}
1048
1049impl Default for TransportProtocol {
1050 fn default() -> Self {
1051 TransportProtocol::JsonRpc
1052 }
1053}
1054
1055#[derive(Debug, Clone, Serialize, Deserialize)]
1057pub struct AgentInterface {
1058 pub transport: TransportProtocol,
1060 pub url: String,
1062}
1063
1064#[derive(Debug, Clone, Serialize, Deserialize)]
1066pub struct AgentExtension {
1067 pub uri: String,
1069 #[serde(skip_serializing_if = "Option::is_none")]
1071 pub description: Option<String>,
1072 #[serde(skip_serializing_if = "Option::is_none")]
1074 pub required: Option<bool>,
1075 #[serde(skip_serializing_if = "Option::is_none")]
1077 pub params: Option<HashMap<String, serde_json::Value>>,
1078}
1079
1080#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1082pub struct AgentCapabilities {
1083 #[serde(skip_serializing_if = "Option::is_none")]
1085 pub streaming: Option<bool>,
1086 #[serde(skip_serializing_if = "Option::is_none", rename = "pushNotifications")]
1088 pub push_notifications: Option<bool>,
1089 #[serde(
1091 skip_serializing_if = "Option::is_none",
1092 rename = "stateTransitionHistory"
1093 )]
1094 pub state_transition_history: Option<bool>,
1095 #[serde(skip_serializing_if = "Vec::is_empty", default)]
1097 pub extensions: Vec<AgentExtension>,
1098}
1099
1100#[derive(Debug, Clone, Serialize, Deserialize)]
1102pub struct AgentProvider {
1103 pub organization: String,
1105 pub url: String,
1107}
1108
1109#[derive(Debug, Clone, Serialize, Deserialize)]
1111pub struct AgentSkill {
1112 pub id: String,
1114 pub name: String,
1116 pub description: String,
1118 pub tags: Vec<String>,
1120 #[serde(skip_serializing_if = "Vec::is_empty", default)]
1122 pub examples: Vec<String>,
1123 #[serde(skip_serializing_if = "Vec::is_empty", rename = "inputModes", default)]
1125 pub input_modes: Vec<String>,
1126 #[serde(skip_serializing_if = "Vec::is_empty", rename = "outputModes", default)]
1128 pub output_modes: Vec<String>,
1129 #[serde(skip_serializing_if = "Vec::is_empty", default)]
1131 pub security: Vec<HashMap<String, Vec<String>>>,
1132}
1133
1134#[derive(Debug, Clone, Serialize, Deserialize)]
1136pub struct AgentCardSignature {
1137 #[serde(rename = "protected")]
1139 pub protected_header: String,
1140 pub signature: String,
1142 #[serde(skip_serializing_if = "Option::is_none")]
1144 pub header: Option<HashMap<String, serde_json::Value>>,
1145}
1146
1147#[derive(Debug, Clone, Serialize, Deserialize)]
1149pub struct AgentCard {
1150 pub name: String,
1152 pub description: String,
1154 pub version: String,
1156 #[serde(rename = "protocolVersion", default = "default_protocol_version")]
1158 pub protocol_version: String,
1159 pub url: String,
1161 #[serde(rename = "preferredTransport", default)]
1163 pub preferred_transport: TransportProtocol,
1164 pub capabilities: AgentCapabilities,
1166 #[serde(rename = "defaultInputModes")]
1168 pub default_input_modes: Vec<String>,
1169 #[serde(rename = "defaultOutputModes")]
1171 pub default_output_modes: Vec<String>,
1172 pub skills: Vec<AgentSkill>,
1174 #[serde(skip_serializing_if = "Option::is_none")]
1176 pub provider: Option<AgentProvider>,
1177 #[serde(
1179 skip_serializing_if = "Vec::is_empty",
1180 rename = "additionalInterfaces",
1181 default
1182 )]
1183 pub additional_interfaces: Vec<AgentInterface>,
1184 #[serde(skip_serializing_if = "Option::is_none", rename = "documentationUrl")]
1186 pub documentation_url: Option<String>,
1187 #[serde(skip_serializing_if = "Option::is_none", rename = "iconUrl")]
1189 pub icon_url: Option<String>,
1190 #[serde(skip_serializing_if = "Vec::is_empty", default)]
1192 pub security: Vec<HashMap<String, Vec<String>>>,
1193 #[serde(skip_serializing_if = "Option::is_none", rename = "securitySchemes")]
1195 pub security_schemes: Option<HashMap<String, SecurityScheme>>,
1196 #[serde(skip_serializing_if = "Vec::is_empty", default)]
1198 pub signatures: Vec<AgentCardSignature>,
1199 #[serde(
1201 skip_serializing_if = "Option::is_none",
1202 rename = "supportsAuthenticatedExtendedCard"
1203 )]
1204 pub supports_authenticated_extended_card: Option<bool>,
1205}
1206
1207pub const PROTOCOL_VERSION: &str = "0.3.0";
1209pub const API_KEY_TYPE: &str = "apiKey";
1210pub const HTTP_TYPE: &str = "http";
1211pub const OAUTH2_TYPE: &str = "oauth2";
1212pub const OPENID_TYPE: &str = "openIdConnect";
1213pub const MUTUAL_TLS_TYPE: &str = "mutualTLS";
1214pub const TASK_KIND: &str = "task";
1215pub const MESSAGE_KIND: &str = "message";
1216pub const STATUS_UPDATE_KIND: &str = "status-update";
1217pub const ARTIFACT_UPDATE_KIND: &str = "artifact-update";
1218
1219fn default_protocol_version() -> String {
1220 PROTOCOL_VERSION.to_string()
1221}
1222
1223#[derive(Debug, Clone, Serialize, Deserialize)]
1229#[serde(untagged)]
1230pub enum SecurityScheme {
1231 ApiKey(APIKeySecurityScheme),
1232 Http(HTTPAuthSecurityScheme),
1233 OAuth2(Box<OAuth2SecurityScheme>),
1234 OpenIdConnect(OpenIdConnectSecurityScheme),
1235 MutualTLS(MutualTLSSecurityScheme),
1236}
1237
1238#[derive(Debug, Clone, Serialize, Deserialize)]
1240pub struct APIKeySecurityScheme {
1241 #[serde(rename = "type", default = "default_api_key_type")]
1243 pub scheme_type: String,
1244 pub name: String,
1246 #[serde(rename = "in")]
1248 pub location: APIKeyLocation,
1249 #[serde(skip_serializing_if = "Option::is_none")]
1251 pub description: Option<String>,
1252}
1253
1254fn default_api_key_type() -> String {
1255 API_KEY_TYPE.to_string()
1256}
1257
1258#[derive(Debug, Clone, Serialize, Deserialize)]
1260#[serde(rename_all = "lowercase")]
1261pub enum APIKeyLocation {
1262 Query,
1263 Header,
1264 Cookie,
1265}
1266
1267#[derive(Debug, Clone, Serialize, Deserialize)]
1269pub struct HTTPAuthSecurityScheme {
1270 #[serde(rename = "type", default = "default_http_type")]
1272 pub scheme_type: String,
1273 pub scheme: String,
1275 #[serde(skip_serializing_if = "Option::is_none")]
1277 pub description: Option<String>,
1278 #[serde(skip_serializing_if = "Option::is_none", rename = "bearerFormat")]
1280 pub bearer_format: Option<String>,
1281}
1282
1283fn default_http_type() -> String {
1284 HTTP_TYPE.to_string()
1285}
1286
1287#[derive(Debug, Clone, Serialize, Deserialize)]
1289pub struct OAuth2SecurityScheme {
1290 #[serde(rename = "type", default = "default_oauth2_type")]
1292 pub scheme_type: String,
1293 pub flows: OAuthFlows,
1295 #[serde(skip_serializing_if = "Option::is_none")]
1297 pub description: Option<String>,
1298 #[serde(skip_serializing_if = "Option::is_none", rename = "oauth2MetadataUrl")]
1300 pub oauth2_metadata_url: Option<String>,
1301}
1302
1303fn default_oauth2_type() -> String {
1304 OAUTH2_TYPE.to_string()
1305}
1306
1307#[derive(Debug, Clone, Serialize, Deserialize)]
1309pub struct OpenIdConnectSecurityScheme {
1310 #[serde(rename = "type", default = "default_openid_type")]
1312 pub scheme_type: String,
1313 #[serde(rename = "openIdConnectUrl")]
1315 pub open_id_connect_url: String,
1316 #[serde(skip_serializing_if = "Option::is_none")]
1318 pub description: Option<String>,
1319}
1320
1321fn default_openid_type() -> String {
1322 OPENID_TYPE.to_string()
1323}
1324
1325#[derive(Debug, Clone, Serialize, Deserialize)]
1327pub struct MutualTLSSecurityScheme {
1328 #[serde(rename = "type", default = "default_mutual_tls_type")]
1330 pub scheme_type: String,
1331 #[serde(skip_serializing_if = "Option::is_none")]
1333 pub description: Option<String>,
1334}
1335
1336fn default_mutual_tls_type() -> String {
1337 MUTUAL_TLS_TYPE.to_string()
1338}
1339
1340#[derive(Debug, Clone, Serialize, Deserialize)]
1342pub struct OAuthFlows {
1343 #[serde(skip_serializing_if = "Option::is_none", rename = "authorizationCode")]
1345 pub authorization_code: Option<AuthorizationCodeOAuthFlow>,
1346 #[serde(skip_serializing_if = "Option::is_none")]
1348 pub implicit: Option<ImplicitOAuthFlow>,
1349 #[serde(skip_serializing_if = "Option::is_none")]
1351 pub password: Option<PasswordOAuthFlow>,
1352 #[serde(skip_serializing_if = "Option::is_none", rename = "clientCredentials")]
1354 pub client_credentials: Option<ClientCredentialsOAuthFlow>,
1355}
1356
1357#[derive(Debug, Clone, Serialize, Deserialize)]
1359pub struct AuthorizationCodeOAuthFlow {
1360 #[serde(rename = "authorizationUrl")]
1362 pub authorization_url: String,
1363 #[serde(rename = "tokenUrl")]
1365 pub token_url: String,
1366 pub scopes: HashMap<String, String>,
1368 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1370 pub refresh_url: Option<String>,
1371}
1372
1373#[derive(Debug, Clone, Serialize, Deserialize)]
1375pub struct ImplicitOAuthFlow {
1376 #[serde(rename = "authorizationUrl")]
1378 pub authorization_url: String,
1379 pub scopes: HashMap<String, String>,
1381 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1383 pub refresh_url: Option<String>,
1384}
1385
1386#[derive(Debug, Clone, Serialize, Deserialize)]
1388pub struct PasswordOAuthFlow {
1389 #[serde(rename = "tokenUrl")]
1391 pub token_url: String,
1392 pub scopes: HashMap<String, String>,
1394 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1396 pub refresh_url: Option<String>,
1397}
1398
1399#[derive(Debug, Clone, Serialize, Deserialize)]
1401pub struct ClientCredentialsOAuthFlow {
1402 #[serde(rename = "tokenUrl")]
1404 pub token_url: String,
1405 pub scopes: HashMap<String, String>,
1407 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1409 pub refresh_url: Option<String>,
1410}
1411
1412#[derive(Debug, Clone, Serialize, Deserialize)]
1418#[serde(untagged)]
1419pub enum AgentResponse {
1420 Task(Task),
1421 Message(Message),
1422}
1423
1424#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1430pub struct TaskStatusUpdateEvent {
1431 #[serde(default = "default_status_update_kind")]
1433 pub kind: String,
1434 #[serde(rename = "taskId")]
1436 pub task_id: String,
1437 #[serde(rename = "contextId")]
1439 pub context_id: String,
1440 pub status: TaskStatus,
1442 #[serde(rename = "final")]
1444 pub is_final: bool,
1445 #[serde(skip_serializing_if = "Option::is_none")]
1447 pub metadata: Option<HashMap<String, serde_json::Value>>,
1448}
1449
1450fn default_status_update_kind() -> String {
1451 STATUS_UPDATE_KIND.to_string()
1452}
1453
1454#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1456pub struct TaskArtifactUpdateEvent {
1457 #[serde(default = "default_artifact_update_kind")]
1459 pub kind: String,
1460 #[serde(rename = "taskId")]
1462 pub task_id: String,
1463 #[serde(rename = "contextId")]
1465 pub context_id: String,
1466 pub artifact: Artifact,
1468 #[serde(skip_serializing_if = "Option::is_none")]
1470 pub append: Option<bool>,
1471 #[serde(skip_serializing_if = "Option::is_none", rename = "lastChunk")]
1473 pub last_chunk: Option<bool>,
1474 #[serde(skip_serializing_if = "Option::is_none")]
1476 pub metadata: Option<HashMap<String, serde_json::Value>>,
1477}
1478
1479fn default_artifact_update_kind() -> String {
1480 ARTIFACT_UPDATE_KIND.to_string()
1481}