1use serde::{Deserialize, Serialize};
15use std::collections::HashMap;
16
17pub mod agent_card;
23pub use agent_card::{
24 AgentCapabilities, AgentCard, AgentCardSignature, AgentExtension, AgentInterface,
25 AgentProvider, AgentSkill, TransportProtocol,
26};
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct JSONRPCMessage {
31 pub jsonrpc: String,
33 #[serde(skip_serializing_if = "Option::is_none")]
36 pub id: Option<JSONRPCId>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
41#[serde(untagged)]
42pub enum JSONRPCId {
43 String(String),
44 Integer(i64),
45 Null,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct JSONRPCRequest {
51 pub jsonrpc: String,
53 pub method: String,
55 #[serde(skip_serializing_if = "Option::is_none")]
57 pub params: Option<serde_json::Value>,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 pub id: Option<JSONRPCId>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct JSONRPCSuccessResponse {
66 pub jsonrpc: String,
68 pub result: serde_json::Value,
70 pub id: Option<JSONRPCId>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct JSONRPCErrorResponse {
77 pub jsonrpc: String,
79 pub error: JSONRPCError,
81 pub id: Option<JSONRPCId>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct JSONRPCError {
88 pub code: i32,
90 pub message: String,
92 #[serde(skip_serializing_if = "Option::is_none")]
95 pub data: Option<serde_json::Value>,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum JSONRPCResponse {
103 SendMessage(SendMessageResponse),
104 SendStreamingMessage(SendStreamingMessageResponse),
105 GetTask(GetTaskResponse),
106 CancelTask(CancelTaskResponse),
107 SetTaskPushNotificationConfig(SetTaskPushNotificationConfigResponse),
108 GetTaskPushNotificationConfig(GetTaskPushNotificationConfigResponse),
109 ListTaskPushNotificationConfig(ListTaskPushNotificationConfigResponse),
110 DeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigResponse),
111 GetAuthenticatedExtendedCard(GetAuthenticatedExtendedCardResponse),
112 Error(JSONRPCErrorResponse),
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(default)]
122pub struct JSONParseError {
123 pub code: i32, pub message: String,
127 #[serde(skip_serializing_if = "Option::is_none")]
129 pub data: Option<serde_json::Value>,
130}
131
132impl Default for JSONParseError {
133 fn default() -> Self {
134 Self {
135 code: JSON_PARSE_ERROR_CODE,
136 message: JSON_PARSE_ERROR_MESSAGE.to_string(),
137 data: None,
138 }
139 }
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(default)]
145pub struct InvalidRequestError {
146 pub code: i32, pub message: String,
150 #[serde(skip_serializing_if = "Option::is_none")]
152 pub data: Option<serde_json::Value>,
153}
154
155impl Default for InvalidRequestError {
156 fn default() -> Self {
157 Self {
158 code: INVALID_REQUEST_ERROR_CODE,
159 message: INVALID_REQUEST_ERROR_MESSAGE.to_string(),
160 data: None,
161 }
162 }
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(default)]
168pub struct MethodNotFoundError {
169 pub code: i32, pub message: String,
173 #[serde(skip_serializing_if = "Option::is_none")]
175 pub data: Option<serde_json::Value>,
176}
177
178impl Default for MethodNotFoundError {
179 fn default() -> Self {
180 Self {
181 code: METHOD_NOT_FOUND_ERROR_CODE,
182 message: METHOD_NOT_FOUND_ERROR_MESSAGE.to_string(),
183 data: None,
184 }
185 }
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(default)]
191pub struct InvalidParamsError {
192 pub code: i32, pub message: String,
196 #[serde(skip_serializing_if = "Option::is_none")]
198 pub data: Option<serde_json::Value>,
199}
200
201impl Default for InvalidParamsError {
202 fn default() -> Self {
203 Self {
204 code: INVALID_PARAMS_ERROR_CODE,
205 message: INVALID_PARAMS_ERROR_MESSAGE.to_string(),
206 data: None,
207 }
208 }
209}
210
211#[derive(Debug, Clone, Serialize, Deserialize)]
213#[serde(default)]
214pub struct InternalError {
215 pub code: i32, pub message: String,
219 #[serde(skip_serializing_if = "Option::is_none")]
221 pub data: Option<serde_json::Value>,
222}
223
224impl Default for InternalError {
225 fn default() -> Self {
226 Self {
227 code: INTERNAL_ERROR_CODE,
228 message: INTERNAL_ERROR_MESSAGE.to_string(),
229 data: None,
230 }
231 }
232}
233
234#[derive(Debug, Clone, Serialize, Deserialize)]
236#[serde(default)]
237pub struct TaskNotFoundError {
238 pub code: i32, pub message: String,
242 #[serde(skip_serializing_if = "Option::is_none")]
244 pub data: Option<serde_json::Value>,
245}
246
247impl Default for TaskNotFoundError {
248 fn default() -> Self {
249 Self {
250 code: TASK_NOT_FOUND_ERROR_CODE,
251 message: TASK_NOT_FOUND_ERROR_MESSAGE.to_string(),
252 data: None,
253 }
254 }
255}
256
257#[derive(Debug, Clone, Serialize, Deserialize)]
259#[serde(default)]
260pub struct TaskNotCancelableError {
261 pub code: i32, pub message: String,
265 #[serde(skip_serializing_if = "Option::is_none")]
267 pub data: Option<serde_json::Value>,
268}
269
270impl Default for TaskNotCancelableError {
271 fn default() -> Self {
272 Self {
273 code: TASK_NOT_CANCELABLE_ERROR_CODE,
274 message: TASK_NOT_CANCELABLE_ERROR_MESSAGE.to_string(),
275 data: None,
276 }
277 }
278}
279
280#[derive(Debug, Clone, Serialize, Deserialize)]
282#[serde(default)]
283pub struct PushNotificationNotSupportedError {
284 pub code: i32, pub message: String,
288 #[serde(skip_serializing_if = "Option::is_none")]
290 pub data: Option<serde_json::Value>,
291}
292
293impl Default for PushNotificationNotSupportedError {
294 fn default() -> Self {
295 Self {
296 code: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE,
297 message: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
298 data: None,
299 }
300 }
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
305#[serde(default)]
306pub struct UnsupportedOperationError {
307 pub code: i32, pub message: String,
311 #[serde(skip_serializing_if = "Option::is_none")]
313 pub data: Option<serde_json::Value>,
314}
315
316impl Default for UnsupportedOperationError {
317 fn default() -> Self {
318 Self {
319 code: UNSUPPORTED_OPERATION_ERROR_CODE,
320 message: UNSUPPORTED_OPERATION_ERROR_MESSAGE.to_string(),
321 data: None,
322 }
323 }
324}
325
326#[derive(Debug, Clone, Serialize, Deserialize)]
329#[serde(default)]
330pub struct ContentTypeNotSupportedError {
331 pub code: i32, pub message: String,
335 #[serde(skip_serializing_if = "Option::is_none")]
337 pub data: Option<serde_json::Value>,
338}
339
340impl Default for ContentTypeNotSupportedError {
341 fn default() -> Self {
342 Self {
343 code: CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE,
344 message: CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
345 data: None,
346 }
347 }
348}
349
350#[derive(Debug, Clone, Serialize, Deserialize)]
353#[serde(default)]
354pub struct InvalidAgentResponseError {
355 pub code: i32, pub message: String,
359 #[serde(skip_serializing_if = "Option::is_none")]
361 pub data: Option<serde_json::Value>,
362}
363
364impl Default for InvalidAgentResponseError {
365 fn default() -> Self {
366 Self {
367 code: INVALID_AGENT_RESPONSE_ERROR_CODE,
368 message: INVALID_AGENT_RESPONSE_ERROR_MESSAGE.to_string(),
369 data: None,
370 }
371 }
372}
373
374#[derive(Debug, Clone, Serialize, Deserialize)]
376#[serde(default)]
377pub struct AuthenticatedExtendedCardNotConfiguredError {
378 pub code: i32, pub message: String,
382 #[serde(skip_serializing_if = "Option::is_none")]
384 pub data: Option<serde_json::Value>,
385}
386
387impl Default for AuthenticatedExtendedCardNotConfiguredError {
388 fn default() -> Self {
389 Self {
390 code: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE,
391 message: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE.to_string(),
392 data: None,
393 }
394 }
395}
396
397#[derive(Debug, Clone, Serialize, Deserialize)]
399#[serde(untagged)]
400pub enum A2AError {
401 JSONParse(JSONParseError),
402 InvalidRequest(InvalidRequestError),
403 MethodNotFound(MethodNotFoundError),
404 InvalidParams(InvalidParamsError),
405 Internal(InternalError),
406 TaskNotFound(TaskNotFoundError),
407 TaskNotCancelable(TaskNotCancelableError),
408 PushNotificationNotSupported(PushNotificationNotSupportedError),
409 UnsupportedOperation(UnsupportedOperationError),
410 ContentTypeNotSupported(ContentTypeNotSupportedError),
411 InvalidAgentResponse(InvalidAgentResponseError),
412 AuthenticatedExtendedCardNotConfigured(AuthenticatedExtendedCardNotConfiguredError),
413}
414
415const JSON_PARSE_ERROR_CODE: i32 = -32700;
417const JSON_PARSE_ERROR_MESSAGE: &str = "Invalid JSON payload";
418const INVALID_REQUEST_ERROR_CODE: i32 = -32600;
419const INVALID_REQUEST_ERROR_MESSAGE: &str = "Request payload validation error";
420const METHOD_NOT_FOUND_ERROR_CODE: i32 = -32601;
421const METHOD_NOT_FOUND_ERROR_MESSAGE: &str = "Method not found";
422const INVALID_PARAMS_ERROR_CODE: i32 = -32602;
423const INVALID_PARAMS_ERROR_MESSAGE: &str = "Invalid parameters";
424const INTERNAL_ERROR_CODE: i32 = -32603;
425const INTERNAL_ERROR_MESSAGE: &str = "Internal error";
426const TASK_NOT_FOUND_ERROR_CODE: i32 = -32001;
427const TASK_NOT_FOUND_ERROR_MESSAGE: &str = "Task not found";
428const TASK_NOT_CANCELABLE_ERROR_CODE: i32 = -32002;
429const TASK_NOT_CANCELABLE_ERROR_MESSAGE: &str = "Task cannot be canceled";
430const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE: i32 = -32003;
431const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Push Notification is not supported";
432const UNSUPPORTED_OPERATION_ERROR_CODE: i32 = -32004;
433const UNSUPPORTED_OPERATION_ERROR_MESSAGE: &str = "This operation is not supported";
434const CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE: i32 = -32005;
435const CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Incompatible content types";
436const INVALID_AGENT_RESPONSE_ERROR_CODE: i32 = -32006;
437const INVALID_AGENT_RESPONSE_ERROR_MESSAGE: &str = "Invalid agent response";
438const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE: i32 = -32007;
439const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE: &str =
440 "Authenticated Extended Card is not configured";
441
442#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
448#[serde(rename_all = "kebab-case")]
449pub enum TaskState {
450 Submitted,
452 Working,
454 InputRequired,
456 Completed,
458 Canceled,
460 Failed,
462 Rejected,
464 AuthRequired,
466 Unknown,
468}
469
470#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
472pub struct TaskStatus {
473 pub state: TaskState,
475 #[serde(skip_serializing_if = "Option::is_none")]
477 pub timestamp: Option<String>,
478 #[serde(skip_serializing_if = "Option::is_none")]
480 pub message: Option<Message>,
481}
482
483#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
485pub struct Task {
486 #[serde(default = "default_task_kind")]
488 pub kind: String,
489 pub id: String,
491 #[serde(rename = "contextId")]
493 pub context_id: String,
494 pub status: TaskStatus,
496 #[serde(skip_serializing_if = "Vec::is_empty", default)]
498 pub history: Vec<Message>,
499 #[serde(skip_serializing_if = "Vec::is_empty", default)]
501 pub artifacts: Vec<Artifact>,
502 #[serde(skip_serializing_if = "Option::is_none")]
504 pub metadata: Option<HashMap<String, serde_json::Value>>,
505}
506
507fn default_task_kind() -> String {
508 TASK_KIND.to_string()
509}
510
511#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
513#[serde(rename_all = "lowercase")]
514pub enum MessageRole {
515 User,
517 Agent,
519}
520
521impl PartialEq<&str> for MessageRole {
522 fn eq(&self, other: &&str) -> bool {
523 matches!(
524 (self, *other),
525 (MessageRole::User, "user")
526 | (MessageRole::Agent, "agent")
527 | (MessageRole::Agent, "assistant")
528 )
529 }
530}
531
532#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
534pub struct Message {
535 #[serde(default = "default_message_kind")]
537 pub kind: String,
538 #[serde(rename = "messageId")]
540 pub message_id: String,
541 pub role: MessageRole,
543 pub parts: Vec<Part>,
545 #[serde(skip_serializing_if = "Option::is_none", rename = "contextId")]
547 pub context_id: Option<String>,
548 #[serde(skip_serializing_if = "Option::is_none", rename = "taskId")]
550 pub task_id: Option<String>,
551 #[serde(
553 skip_serializing_if = "Vec::is_empty",
554 rename = "referenceTaskIds",
555 default
556 )]
557 pub reference_task_ids: Vec<String>,
558 #[serde(skip_serializing_if = "Vec::is_empty", default)]
560 pub extensions: Vec<String>,
561 #[serde(skip_serializing_if = "Option::is_none")]
563 pub metadata: Option<HashMap<String, serde_json::Value>>,
564}
565
566fn default_message_kind() -> String {
567 MESSAGE_KIND.to_string()
568}
569
570#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
572#[serde(tag = "kind", rename_all = "lowercase")]
573pub enum Part {
574 Text {
576 text: String,
578 #[serde(skip_serializing_if = "Option::is_none")]
580 metadata: Option<HashMap<String, serde_json::Value>>,
581 },
582 File {
584 file: FileContent,
586 #[serde(skip_serializing_if = "Option::is_none")]
588 metadata: Option<HashMap<String, serde_json::Value>>,
589 },
590 Data {
592 data: serde_json::Value,
594 #[serde(skip_serializing_if = "Option::is_none")]
596 metadata: Option<HashMap<String, serde_json::Value>>,
597 },
598}
599
600impl Part {
601 pub fn as_data(&self) -> Option<&serde_json::Value> {
602 match self {
603 Part::Data { data, .. } => Some(data),
604 _ => None,
605 }
606 }
607}
608
609#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
611#[serde(untagged)]
612pub enum FileContent {
613 WithBytes(FileWithBytes),
614 WithUri(FileWithUri),
615}
616
617#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
619pub struct FileWithBytes {
620 pub bytes: String,
622 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
624 pub mime_type: Option<String>,
625 #[serde(skip_serializing_if = "Option::is_none")]
627 pub name: Option<String>,
628}
629
630#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
632pub struct FileWithUri {
633 pub uri: String,
635 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
637 pub mime_type: Option<String>,
638 #[serde(skip_serializing_if = "Option::is_none")]
640 pub name: Option<String>,
641}
642
643#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
645pub struct Artifact {
646 #[serde(rename = "artifactId")]
648 pub artifact_id: String,
649 pub parts: Vec<Part>,
651 #[serde(skip_serializing_if = "Option::is_none")]
653 pub name: Option<String>,
654 #[serde(skip_serializing_if = "Option::is_none")]
656 pub description: Option<String>,
657 #[serde(skip_serializing_if = "Vec::is_empty", default)]
659 pub extensions: Vec<String>,
660 #[serde(skip_serializing_if = "Option::is_none")]
662 pub metadata: Option<HashMap<String, serde_json::Value>>,
663}
664
665#[derive(Debug, Clone, Serialize, Deserialize)]
671pub struct MessageSendParams {
672 pub message: Message,
674 #[serde(skip_serializing_if = "Option::is_none")]
676 pub configuration: Option<MessageSendConfiguration>,
677 #[serde(skip_serializing_if = "Option::is_none")]
679 pub metadata: Option<HashMap<String, serde_json::Value>>,
680}
681
682#[derive(Debug, Clone, Serialize, Deserialize, Default)]
684pub struct MessageSendConfiguration {
685 #[serde(skip_serializing_if = "Option::is_none")]
687 pub blocking: Option<bool>,
688 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
690 pub history_length: Option<i32>,
691 #[serde(
693 skip_serializing_if = "Vec::is_empty",
694 rename = "acceptedOutputModes",
695 default
696 )]
697 pub accepted_output_modes: Vec<String>,
698 #[serde(
700 skip_serializing_if = "Option::is_none",
701 rename = "pushNotificationConfig"
702 )]
703 pub push_notification_config: Option<PushNotificationConfig>,
704}
705
706#[derive(Debug, Clone, Serialize, Deserialize)]
708pub struct PushNotificationConfig {
709 pub url: String,
711 #[serde(skip_serializing_if = "Option::is_none")]
713 pub id: Option<String>,
714 #[serde(skip_serializing_if = "Option::is_none")]
716 pub token: Option<String>,
717 #[serde(skip_serializing_if = "Option::is_none")]
719 pub authentication: Option<PushNotificationAuthenticationInfo>,
720}
721
722#[derive(Debug, Clone, Serialize, Deserialize)]
724pub struct PushNotificationAuthenticationInfo {
725 pub schemes: Vec<String>,
727 #[serde(skip_serializing_if = "Option::is_none")]
729 pub credentials: Option<String>,
730}
731
732#[derive(Debug, Clone, Serialize, Deserialize)]
734pub struct TaskIdParams {
735 pub id: String,
737 #[serde(skip_serializing_if = "Option::is_none")]
739 pub metadata: Option<HashMap<String, serde_json::Value>>,
740}
741
742#[derive(Debug, Clone, Serialize, Deserialize)]
744pub struct TaskQueryParams {
745 pub id: String,
747 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
749 pub history_length: Option<i32>,
750 #[serde(skip_serializing_if = "Option::is_none")]
752 pub metadata: Option<HashMap<String, serde_json::Value>>,
753}
754
755#[derive(Debug, Clone, Serialize, Deserialize)]
757pub struct TaskPushNotificationConfig {
758 #[serde(rename = "taskId")]
760 pub task_id: String,
761 #[serde(rename = "pushNotificationConfig")]
763 pub push_notification_config: PushNotificationConfig,
764}
765
766#[derive(Debug, Clone, Serialize, Deserialize)]
768#[serde(untagged)]
769pub enum GetTaskPushNotificationConfigParams {
770 TaskIdOnly(TaskIdParams),
771 WithConfigId(GetTaskPushNotificationConfigParamsWithId),
772}
773
774#[derive(Debug, Clone, Serialize, Deserialize)]
776pub struct GetTaskPushNotificationConfigParamsWithId {
777 pub id: String,
779 #[serde(rename = "pushNotificationConfigId")]
781 pub push_notification_config_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 ListTaskPushNotificationConfigParams {
790 pub id: String,
792 #[serde(skip_serializing_if = "Option::is_none")]
794 pub metadata: Option<HashMap<String, serde_json::Value>>,
795}
796
797#[derive(Debug, Clone, Serialize, Deserialize)]
799pub struct DeleteTaskPushNotificationConfigParams {
800 pub id: String,
802 #[serde(rename = "pushNotificationConfigId")]
804 pub push_notification_config_id: String,
805 #[serde(skip_serializing_if = "Option::is_none")]
807 pub metadata: Option<HashMap<String, serde_json::Value>>,
808}
809
810fn default_jsonrpc_version() -> String {
815 "2.0".to_string()
816}
817
818#[derive(Debug, Clone, Serialize, Deserialize)]
820pub struct A2ARequest {
821 #[serde(default = "default_jsonrpc_version")]
823 pub jsonrpc: String,
824 #[serde(skip_serializing_if = "Option::is_none")]
826 pub id: Option<JSONRPCId>,
827 #[serde(flatten)]
829 pub payload: A2ARequestPayload,
830}
831
832#[derive(Debug, Clone, Serialize, Deserialize)]
834#[serde(tag = "method")]
835pub enum A2ARequestPayload {
836 #[serde(rename = "message/send")]
838 SendMessage { params: MessageSendParams },
839 #[serde(rename = "message/stream")]
841 SendStreamingMessage { params: MessageSendParams },
842 #[serde(rename = "tasks/get")]
844 GetTask { params: TaskQueryParams },
845 #[serde(rename = "tasks/cancel")]
847 CancelTask { params: TaskIdParams },
848 #[serde(rename = "tasks/pushNotificationConfig/set")]
850 SetTaskPushNotificationConfig { params: TaskPushNotificationConfig },
851 #[serde(rename = "tasks/pushNotificationConfig/get")]
853 GetTaskPushNotificationConfig {
854 params: GetTaskPushNotificationConfigParams,
855 },
856 #[serde(rename = "tasks/resubscribe")]
858 TaskResubscription { params: TaskIdParams },
859 #[serde(rename = "tasks/pushNotificationConfig/list")]
861 ListTaskPushNotificationConfig {
862 params: ListTaskPushNotificationConfigParams,
863 },
864 #[serde(rename = "tasks/pushNotificationConfig/delete")]
866 DeleteTaskPushNotificationConfig {
867 params: DeleteTaskPushNotificationConfigParams,
868 },
869 #[serde(rename = "agent/getAuthenticatedExtendedCard")]
871 GetAuthenticatedExtendedCard,
872}
873
874#[derive(Debug, Clone, Serialize, Deserialize)]
880#[serde(untagged)]
881pub enum SendMessageResult {
882 Task(Task),
883 Message(Message),
884}
885
886#[derive(Debug, Clone, Serialize, Deserialize)]
888pub struct SendMessageSuccessResponse {
889 pub jsonrpc: String, pub result: SendMessageResult,
891 pub id: Option<JSONRPCId>,
892}
893
894#[derive(Debug, Clone, Serialize, Deserialize)]
896#[serde(untagged)]
897pub enum SendMessageResponse {
898 Success(Box<SendMessageSuccessResponse>),
899 Error(JSONRPCErrorResponse),
900}
901
902#[derive(Debug, Clone, Serialize, Deserialize)]
904#[serde(untagged)]
905pub enum SendStreamingMessageResult {
906 Task(Task),
907 Message(Message),
908 TaskStatusUpdate(TaskStatusUpdateEvent),
909 TaskArtifactUpdate(TaskArtifactUpdateEvent),
910}
911
912#[derive(Debug, Clone, Serialize, Deserialize)]
914pub struct SendStreamingMessageSuccessResponse {
915 pub jsonrpc: String, pub result: SendStreamingMessageResult,
917 pub id: Option<JSONRPCId>,
918}
919
920#[derive(Debug, Clone, Serialize, Deserialize)]
922#[serde(untagged)]
923pub enum SendStreamingMessageResponse {
924 Success(Box<SendStreamingMessageSuccessResponse>),
925 Error(JSONRPCErrorResponse),
926}
927
928#[derive(Debug, Clone, Serialize, Deserialize)]
930pub struct GetTaskSuccessResponse {
931 pub jsonrpc: String, pub result: Task,
933 pub id: Option<JSONRPCId>,
934}
935
936#[derive(Debug, Clone, Serialize, Deserialize)]
938#[serde(untagged)]
939pub enum GetTaskResponse {
940 Success(Box<GetTaskSuccessResponse>),
941 Error(JSONRPCErrorResponse),
942}
943
944#[derive(Debug, Clone, Serialize, Deserialize)]
946pub struct CancelTaskSuccessResponse {
947 pub jsonrpc: String, pub result: Task,
949 pub id: Option<JSONRPCId>,
950}
951
952#[derive(Debug, Clone, Serialize, Deserialize)]
954#[serde(untagged)]
955pub enum CancelTaskResponse {
956 Success(Box<CancelTaskSuccessResponse>),
957 Error(JSONRPCErrorResponse),
958}
959
960#[derive(Debug, Clone, Serialize, Deserialize)]
962pub struct SetTaskPushNotificationConfigSuccessResponse {
963 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
965 pub id: Option<JSONRPCId>,
966}
967
968#[derive(Debug, Clone, Serialize, Deserialize)]
970#[serde(untagged)]
971pub enum SetTaskPushNotificationConfigResponse {
972 Success(Box<SetTaskPushNotificationConfigSuccessResponse>),
973 Error(JSONRPCErrorResponse),
974}
975
976#[derive(Debug, Clone, Serialize, Deserialize)]
978pub struct GetTaskPushNotificationConfigSuccessResponse {
979 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
981 pub id: Option<JSONRPCId>,
982}
983
984#[derive(Debug, Clone, Serialize, Deserialize)]
986#[serde(untagged)]
987pub enum GetTaskPushNotificationConfigResponse {
988 Success(Box<GetTaskPushNotificationConfigSuccessResponse>),
989 Error(JSONRPCErrorResponse),
990}
991
992#[derive(Debug, Clone, Serialize, Deserialize)]
994pub struct ListTaskPushNotificationConfigSuccessResponse {
995 pub jsonrpc: String, pub result: Vec<TaskPushNotificationConfig>,
997 pub id: Option<JSONRPCId>,
998}
999
1000#[derive(Debug, Clone, Serialize, Deserialize)]
1002#[serde(untagged)]
1003pub enum ListTaskPushNotificationConfigResponse {
1004 Success(Box<ListTaskPushNotificationConfigSuccessResponse>),
1005 Error(JSONRPCErrorResponse),
1006}
1007
1008#[derive(Debug, Clone, Serialize, Deserialize)]
1010pub struct DeleteTaskPushNotificationConfigSuccessResponse {
1011 pub jsonrpc: String, pub result: (),
1014 pub id: Option<JSONRPCId>,
1015}
1016
1017#[derive(Debug, Clone, Serialize, Deserialize)]
1019#[serde(untagged)]
1020pub enum DeleteTaskPushNotificationConfigResponse {
1021 Success(Box<DeleteTaskPushNotificationConfigSuccessResponse>),
1022 Error(JSONRPCErrorResponse),
1023}
1024
1025#[derive(Debug, Clone, Serialize, Deserialize)]
1027pub struct GetAuthenticatedExtendedCardSuccessResponse {
1028 pub jsonrpc: String, pub result: AgentCard,
1030 pub id: Option<JSONRPCId>,
1031}
1032
1033#[derive(Debug, Clone, Serialize, Deserialize)]
1035#[serde(untagged)]
1036pub enum GetAuthenticatedExtendedCardResponse {
1037 Success(Box<GetAuthenticatedExtendedCardSuccessResponse>),
1038 Error(JSONRPCErrorResponse),
1039}
1040
1041pub const PROTOCOL_VERSION: &str = "0.3.0";
1043pub const API_KEY_TYPE: &str = "apiKey";
1044pub const HTTP_TYPE: &str = "http";
1045pub const OAUTH2_TYPE: &str = "oauth2";
1046pub const OPENID_TYPE: &str = "openIdConnect";
1047pub const MUTUAL_TLS_TYPE: &str = "mutualTLS";
1048pub const TASK_KIND: &str = "task";
1049pub const MESSAGE_KIND: &str = "message";
1050pub const STATUS_UPDATE_KIND: &str = "status-update";
1051pub const ARTIFACT_UPDATE_KIND: &str = "artifact-update";
1052
1053#[derive(Debug, Clone, Serialize, Deserialize)]
1059#[serde(untagged)]
1060pub enum SecurityScheme {
1061 ApiKey(APIKeySecurityScheme),
1062 Http(HTTPAuthSecurityScheme),
1063 OAuth2(Box<OAuth2SecurityScheme>),
1064 OpenIdConnect(OpenIdConnectSecurityScheme),
1065 MutualTLS(MutualTLSSecurityScheme),
1066}
1067
1068#[derive(Debug, Clone, Serialize, Deserialize)]
1070pub struct APIKeySecurityScheme {
1071 #[serde(rename = "type", default = "default_api_key_type")]
1073 pub scheme_type: String,
1074 pub name: String,
1076 #[serde(rename = "in")]
1078 pub location: APIKeyLocation,
1079 #[serde(skip_serializing_if = "Option::is_none")]
1081 pub description: Option<String>,
1082}
1083
1084fn default_api_key_type() -> String {
1085 API_KEY_TYPE.to_string()
1086}
1087
1088#[derive(Debug, Clone, Serialize, Deserialize)]
1090#[serde(rename_all = "lowercase")]
1091pub enum APIKeyLocation {
1092 Query,
1093 Header,
1094 Cookie,
1095}
1096
1097#[derive(Debug, Clone, Serialize, Deserialize)]
1099pub struct HTTPAuthSecurityScheme {
1100 #[serde(rename = "type", default = "default_http_type")]
1102 pub scheme_type: String,
1103 pub scheme: String,
1105 #[serde(skip_serializing_if = "Option::is_none")]
1107 pub description: Option<String>,
1108 #[serde(skip_serializing_if = "Option::is_none", rename = "bearerFormat")]
1110 pub bearer_format: Option<String>,
1111}
1112
1113fn default_http_type() -> String {
1114 HTTP_TYPE.to_string()
1115}
1116
1117#[derive(Debug, Clone, Serialize, Deserialize)]
1119pub struct OAuth2SecurityScheme {
1120 #[serde(rename = "type", default = "default_oauth2_type")]
1122 pub scheme_type: String,
1123 pub flows: OAuthFlows,
1125 #[serde(skip_serializing_if = "Option::is_none")]
1127 pub description: Option<String>,
1128 #[serde(skip_serializing_if = "Option::is_none", rename = "oauth2MetadataUrl")]
1130 pub oauth2_metadata_url: Option<String>,
1131}
1132
1133fn default_oauth2_type() -> String {
1134 OAUTH2_TYPE.to_string()
1135}
1136
1137#[derive(Debug, Clone, Serialize, Deserialize)]
1139pub struct OpenIdConnectSecurityScheme {
1140 #[serde(rename = "type", default = "default_openid_type")]
1142 pub scheme_type: String,
1143 #[serde(rename = "openIdConnectUrl")]
1145 pub open_id_connect_url: String,
1146 #[serde(skip_serializing_if = "Option::is_none")]
1148 pub description: Option<String>,
1149}
1150
1151fn default_openid_type() -> String {
1152 OPENID_TYPE.to_string()
1153}
1154
1155#[derive(Debug, Clone, Serialize, Deserialize)]
1157pub struct MutualTLSSecurityScheme {
1158 #[serde(rename = "type", default = "default_mutual_tls_type")]
1160 pub scheme_type: String,
1161 #[serde(skip_serializing_if = "Option::is_none")]
1163 pub description: Option<String>,
1164}
1165
1166fn default_mutual_tls_type() -> String {
1167 MUTUAL_TLS_TYPE.to_string()
1168}
1169
1170#[derive(Debug, Clone, Serialize, Deserialize)]
1172pub struct OAuthFlows {
1173 #[serde(skip_serializing_if = "Option::is_none", rename = "authorizationCode")]
1175 pub authorization_code: Option<AuthorizationCodeOAuthFlow>,
1176 #[serde(skip_serializing_if = "Option::is_none")]
1178 pub implicit: Option<ImplicitOAuthFlow>,
1179 #[serde(skip_serializing_if = "Option::is_none")]
1181 pub password: Option<PasswordOAuthFlow>,
1182 #[serde(skip_serializing_if = "Option::is_none", rename = "clientCredentials")]
1184 pub client_credentials: Option<ClientCredentialsOAuthFlow>,
1185}
1186
1187#[derive(Debug, Clone, Serialize, Deserialize)]
1189pub struct AuthorizationCodeOAuthFlow {
1190 #[serde(rename = "authorizationUrl")]
1192 pub authorization_url: String,
1193 #[serde(rename = "tokenUrl")]
1195 pub token_url: String,
1196 pub scopes: HashMap<String, String>,
1198 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1200 pub refresh_url: Option<String>,
1201}
1202
1203#[derive(Debug, Clone, Serialize, Deserialize)]
1205pub struct ImplicitOAuthFlow {
1206 #[serde(rename = "authorizationUrl")]
1208 pub authorization_url: String,
1209 pub scopes: HashMap<String, String>,
1211 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1213 pub refresh_url: Option<String>,
1214}
1215
1216#[derive(Debug, Clone, Serialize, Deserialize)]
1218pub struct PasswordOAuthFlow {
1219 #[serde(rename = "tokenUrl")]
1221 pub token_url: String,
1222 pub scopes: HashMap<String, String>,
1224 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1226 pub refresh_url: Option<String>,
1227}
1228
1229#[derive(Debug, Clone, Serialize, Deserialize)]
1231pub struct ClientCredentialsOAuthFlow {
1232 #[serde(rename = "tokenUrl")]
1234 pub token_url: String,
1235 pub scopes: HashMap<String, String>,
1237 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1239 pub refresh_url: Option<String>,
1240}
1241
1242#[derive(Debug, Clone, Serialize, Deserialize)]
1248#[serde(untagged)]
1249pub enum AgentResponse {
1250 Task(Task),
1251 Message(Message),
1252}
1253
1254#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1260pub struct TaskStatusUpdateEvent {
1261 #[serde(default = "default_status_update_kind")]
1263 pub kind: String,
1264 #[serde(rename = "taskId")]
1266 pub task_id: String,
1267 #[serde(rename = "contextId")]
1269 pub context_id: String,
1270 pub status: TaskStatus,
1272 #[serde(rename = "final")]
1274 pub is_final: bool,
1275 #[serde(skip_serializing_if = "Option::is_none")]
1277 pub metadata: Option<HashMap<String, serde_json::Value>>,
1278}
1279
1280fn default_status_update_kind() -> String {
1281 STATUS_UPDATE_KIND.to_string()
1282}
1283
1284#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1286pub struct TaskArtifactUpdateEvent {
1287 #[serde(default = "default_artifact_update_kind")]
1289 pub kind: String,
1290 #[serde(rename = "taskId")]
1292 pub task_id: String,
1293 #[serde(rename = "contextId")]
1295 pub context_id: String,
1296 pub artifact: Artifact,
1298 #[serde(skip_serializing_if = "Option::is_none")]
1300 pub append: Option<bool>,
1301 #[serde(skip_serializing_if = "Option::is_none", rename = "lastChunk")]
1303 pub last_chunk: Option<bool>,
1304 #[serde(skip_serializing_if = "Option::is_none")]
1306 pub metadata: Option<HashMap<String, serde_json::Value>>,
1307}
1308
1309fn default_artifact_update_kind() -> String {
1310 ARTIFACT_UPDATE_KIND.to_string()
1311}