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}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct JSONRPCSuccessResponse {
63 pub jsonrpc: String,
65 pub result: serde_json::Value,
67 pub id: Option<JSONRPCId>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct JSONRPCErrorResponse {
74 pub jsonrpc: String,
76 pub error: JSONRPCError,
78 pub id: Option<JSONRPCId>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct JSONRPCError {
85 pub code: i32,
87 pub message: String,
89 #[serde(skip_serializing_if = "Option::is_none")]
92 pub data: Option<serde_json::Value>,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum JSONRPCResponse {
100 SendMessage(SendMessageResponse),
101 SendStreamingMessage(SendStreamingMessageResponse),
102 GetTask(GetTaskResponse),
103 CancelTask(CancelTaskResponse),
104 SetTaskPushNotificationConfig(SetTaskPushNotificationConfigResponse),
105 GetTaskPushNotificationConfig(GetTaskPushNotificationConfigResponse),
106 ListTaskPushNotificationConfig(ListTaskPushNotificationConfigResponse),
107 DeleteTaskPushNotificationConfig(DeleteTaskPushNotificationConfigResponse),
108 GetAuthenticatedExtendedCard(GetAuthenticatedExtendedCardResponse),
109 Error(JSONRPCErrorResponse),
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(default)]
119pub struct JSONParseError {
120 pub code: i32, pub message: String,
124 #[serde(skip_serializing_if = "Option::is_none")]
126 pub data: Option<serde_json::Value>,
127}
128
129impl Default for JSONParseError {
130 fn default() -> Self {
131 Self {
132 code: JSON_PARSE_ERROR_CODE,
133 message: JSON_PARSE_ERROR_MESSAGE.to_string(),
134 data: None,
135 }
136 }
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(default)]
142pub struct InvalidRequestError {
143 pub code: i32, pub message: String,
147 #[serde(skip_serializing_if = "Option::is_none")]
149 pub data: Option<serde_json::Value>,
150}
151
152impl Default for InvalidRequestError {
153 fn default() -> Self {
154 Self {
155 code: INVALID_REQUEST_ERROR_CODE,
156 message: INVALID_REQUEST_ERROR_MESSAGE.to_string(),
157 data: None,
158 }
159 }
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
164#[serde(default)]
165pub struct MethodNotFoundError {
166 pub code: i32, pub message: String,
170 #[serde(skip_serializing_if = "Option::is_none")]
172 pub data: Option<serde_json::Value>,
173}
174
175impl Default for MethodNotFoundError {
176 fn default() -> Self {
177 Self {
178 code: METHOD_NOT_FOUND_ERROR_CODE,
179 message: METHOD_NOT_FOUND_ERROR_MESSAGE.to_string(),
180 data: None,
181 }
182 }
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize)]
187#[serde(default)]
188pub struct InvalidParamsError {
189 pub code: i32, pub message: String,
193 #[serde(skip_serializing_if = "Option::is_none")]
195 pub data: Option<serde_json::Value>,
196}
197
198impl Default for InvalidParamsError {
199 fn default() -> Self {
200 Self {
201 code: INVALID_PARAMS_ERROR_CODE,
202 message: INVALID_PARAMS_ERROR_MESSAGE.to_string(),
203 data: None,
204 }
205 }
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(default)]
211pub struct InternalError {
212 pub code: i32, pub message: String,
216 #[serde(skip_serializing_if = "Option::is_none")]
218 pub data: Option<serde_json::Value>,
219}
220
221impl Default for InternalError {
222 fn default() -> Self {
223 Self {
224 code: INTERNAL_ERROR_CODE,
225 message: INTERNAL_ERROR_MESSAGE.to_string(),
226 data: None,
227 }
228 }
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize)]
233#[serde(default)]
234pub struct TaskNotFoundError {
235 pub code: i32, pub message: String,
239 #[serde(skip_serializing_if = "Option::is_none")]
241 pub data: Option<serde_json::Value>,
242}
243
244impl Default for TaskNotFoundError {
245 fn default() -> Self {
246 Self {
247 code: TASK_NOT_FOUND_ERROR_CODE,
248 message: TASK_NOT_FOUND_ERROR_MESSAGE.to_string(),
249 data: None,
250 }
251 }
252}
253
254#[derive(Debug, Clone, Serialize, Deserialize)]
256#[serde(default)]
257pub struct TaskNotCancelableError {
258 pub code: i32, pub message: String,
262 #[serde(skip_serializing_if = "Option::is_none")]
264 pub data: Option<serde_json::Value>,
265}
266
267impl Default for TaskNotCancelableError {
268 fn default() -> Self {
269 Self {
270 code: TASK_NOT_CANCELABLE_ERROR_CODE,
271 message: TASK_NOT_CANCELABLE_ERROR_MESSAGE.to_string(),
272 data: None,
273 }
274 }
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize)]
279#[serde(default)]
280pub struct PushNotificationNotSupportedError {
281 pub code: i32, pub message: String,
285 #[serde(skip_serializing_if = "Option::is_none")]
287 pub data: Option<serde_json::Value>,
288}
289
290impl Default for PushNotificationNotSupportedError {
291 fn default() -> Self {
292 Self {
293 code: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE,
294 message: PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
295 data: None,
296 }
297 }
298}
299
300#[derive(Debug, Clone, Serialize, Deserialize)]
302#[serde(default)]
303pub struct UnsupportedOperationError {
304 pub code: i32, pub message: String,
308 #[serde(skip_serializing_if = "Option::is_none")]
310 pub data: Option<serde_json::Value>,
311}
312
313impl Default for UnsupportedOperationError {
314 fn default() -> Self {
315 Self {
316 code: UNSUPPORTED_OPERATION_ERROR_CODE,
317 message: UNSUPPORTED_OPERATION_ERROR_MESSAGE.to_string(),
318 data: None,
319 }
320 }
321}
322
323#[derive(Debug, Clone, Serialize, Deserialize)]
326#[serde(default)]
327pub struct ContentTypeNotSupportedError {
328 pub code: i32, pub message: String,
332 #[serde(skip_serializing_if = "Option::is_none")]
334 pub data: Option<serde_json::Value>,
335}
336
337impl Default for ContentTypeNotSupportedError {
338 fn default() -> Self {
339 Self {
340 code: CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE,
341 message: CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE.to_string(),
342 data: None,
343 }
344 }
345}
346
347#[derive(Debug, Clone, Serialize, Deserialize)]
350#[serde(default)]
351pub struct InvalidAgentResponseError {
352 pub code: i32, pub message: String,
356 #[serde(skip_serializing_if = "Option::is_none")]
358 pub data: Option<serde_json::Value>,
359}
360
361impl Default for InvalidAgentResponseError {
362 fn default() -> Self {
363 Self {
364 code: INVALID_AGENT_RESPONSE_ERROR_CODE,
365 message: INVALID_AGENT_RESPONSE_ERROR_MESSAGE.to_string(),
366 data: None,
367 }
368 }
369}
370
371#[derive(Debug, Clone, Serialize, Deserialize)]
373#[serde(default)]
374pub struct AuthenticatedExtendedCardNotConfiguredError {
375 pub code: i32, pub message: String,
379 #[serde(skip_serializing_if = "Option::is_none")]
381 pub data: Option<serde_json::Value>,
382}
383
384impl Default for AuthenticatedExtendedCardNotConfiguredError {
385 fn default() -> Self {
386 Self {
387 code: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE,
388 message: AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE.to_string(),
389 data: None,
390 }
391 }
392}
393
394#[derive(Debug, Clone, Serialize, Deserialize)]
396#[serde(untagged)]
397pub enum A2AError {
398 JSONParse(JSONParseError),
399 InvalidRequest(InvalidRequestError),
400 MethodNotFound(MethodNotFoundError),
401 InvalidParams(InvalidParamsError),
402 Internal(InternalError),
403 TaskNotFound(TaskNotFoundError),
404 TaskNotCancelable(TaskNotCancelableError),
405 PushNotificationNotSupported(PushNotificationNotSupportedError),
406 UnsupportedOperation(UnsupportedOperationError),
407 ContentTypeNotSupported(ContentTypeNotSupportedError),
408 InvalidAgentResponse(InvalidAgentResponseError),
409 AuthenticatedExtendedCardNotConfigured(AuthenticatedExtendedCardNotConfiguredError),
410}
411
412const JSON_PARSE_ERROR_CODE: i32 = -32700;
414const JSON_PARSE_ERROR_MESSAGE: &str = "Invalid JSON payload";
415const INVALID_REQUEST_ERROR_CODE: i32 = -32600;
416const INVALID_REQUEST_ERROR_MESSAGE: &str = "Request payload validation error";
417const METHOD_NOT_FOUND_ERROR_CODE: i32 = -32601;
418const METHOD_NOT_FOUND_ERROR_MESSAGE: &str = "Method not found";
419const INVALID_PARAMS_ERROR_CODE: i32 = -32602;
420const INVALID_PARAMS_ERROR_MESSAGE: &str = "Invalid parameters";
421const INTERNAL_ERROR_CODE: i32 = -32603;
422const INTERNAL_ERROR_MESSAGE: &str = "Internal error";
423const TASK_NOT_FOUND_ERROR_CODE: i32 = -32001;
424const TASK_NOT_FOUND_ERROR_MESSAGE: &str = "Task not found";
425const TASK_NOT_CANCELABLE_ERROR_CODE: i32 = -32002;
426const TASK_NOT_CANCELABLE_ERROR_MESSAGE: &str = "Task cannot be canceled";
427const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_CODE: i32 = -32003;
428const PUSH_NOTIFICATION_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Push Notification is not supported";
429const UNSUPPORTED_OPERATION_ERROR_CODE: i32 = -32004;
430const UNSUPPORTED_OPERATION_ERROR_MESSAGE: &str = "This operation is not supported";
431const CONTENT_TYPE_NOT_SUPPORTED_ERROR_CODE: i32 = -32005;
432const CONTENT_TYPE_NOT_SUPPORTED_ERROR_MESSAGE: &str = "Incompatible content types";
433const INVALID_AGENT_RESPONSE_ERROR_CODE: i32 = -32006;
434const INVALID_AGENT_RESPONSE_ERROR_MESSAGE: &str = "Invalid agent response";
435const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_CODE: i32 = -32007;
436const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED_ERROR_MESSAGE: &str =
437 "Authenticated Extended Card is not configured";
438
439#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
445#[serde(rename_all = "kebab-case")]
446pub enum TaskState {
447 Submitted,
449 Working,
451 InputRequired,
453 Completed,
455 Canceled,
457 Failed,
459 Rejected,
461 AuthRequired,
463 Unknown,
465}
466
467#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
469pub struct TaskStatus {
470 pub state: TaskState,
472 #[serde(skip_serializing_if = "Option::is_none")]
474 pub timestamp: Option<String>,
475 #[serde(skip_serializing_if = "Option::is_none")]
477 pub message: Option<Message>,
478}
479
480#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
482pub struct Task {
483 #[serde(default = "default_task_kind")]
485 pub kind: String,
486 pub id: String,
488 #[serde(rename = "contextId")]
490 pub context_id: String,
491 pub status: TaskStatus,
493 #[serde(skip_serializing_if = "Vec::is_empty", default)]
495 pub history: Vec<Message>,
496 #[serde(skip_serializing_if = "Vec::is_empty", default)]
498 pub artifacts: Vec<Artifact>,
499 #[serde(skip_serializing_if = "Option::is_none")]
501 pub metadata: Option<HashMap<String, serde_json::Value>>,
502}
503
504fn default_task_kind() -> String {
505 TASK_KIND.to_string()
506}
507
508#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
510#[serde(rename_all = "lowercase")]
511pub enum MessageRole {
512 User,
514 Agent,
516}
517
518impl PartialEq<&str> for MessageRole {
519 fn eq(&self, other: &&str) -> bool {
520 matches!(
521 (self, *other),
522 (MessageRole::User, "user")
523 | (MessageRole::Agent, "agent")
524 | (MessageRole::Agent, "assistant")
525 )
526 }
527}
528
529#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
531pub struct Message {
532 #[serde(default = "default_message_kind")]
534 pub kind: String,
535 #[serde(rename = "messageId")]
537 pub message_id: String,
538 pub role: MessageRole,
540 pub parts: Vec<Part>,
542 #[serde(skip_serializing_if = "Option::is_none", rename = "contextId")]
544 pub context_id: Option<String>,
545 #[serde(skip_serializing_if = "Option::is_none", rename = "taskId")]
547 pub task_id: Option<String>,
548 #[serde(
550 skip_serializing_if = "Vec::is_empty",
551 rename = "referenceTaskIds",
552 default
553 )]
554 pub reference_task_ids: Vec<String>,
555 #[serde(skip_serializing_if = "Vec::is_empty", default)]
557 pub extensions: Vec<String>,
558 #[serde(skip_serializing_if = "Option::is_none")]
560 pub metadata: Option<HashMap<String, serde_json::Value>>,
561}
562
563fn default_message_kind() -> String {
564 MESSAGE_KIND.to_string()
565}
566
567#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
569#[serde(tag = "kind", rename_all = "lowercase")]
570pub enum Part {
571 Text {
573 text: String,
575 #[serde(skip_serializing_if = "Option::is_none")]
577 metadata: Option<HashMap<String, serde_json::Value>>,
578 },
579 File {
581 file: FileContent,
583 #[serde(skip_serializing_if = "Option::is_none")]
585 metadata: Option<HashMap<String, serde_json::Value>>,
586 },
587 Data {
589 data: serde_json::Value,
591 #[serde(skip_serializing_if = "Option::is_none")]
593 metadata: Option<HashMap<String, serde_json::Value>>,
594 },
595}
596
597impl Part {
598 pub fn as_data(&self) -> Option<&serde_json::Value> {
599 match self {
600 Part::Data { data, .. } => Some(data),
601 _ => None,
602 }
603 }
604}
605
606#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
608#[serde(untagged)]
609pub enum FileContent {
610 WithBytes(FileWithBytes),
611 WithUri(FileWithUri),
612}
613
614#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
616pub struct FileWithBytes {
617 pub bytes: String,
619 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
621 pub mime_type: Option<String>,
622 #[serde(skip_serializing_if = "Option::is_none")]
624 pub name: Option<String>,
625}
626
627#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
629pub struct FileWithUri {
630 pub uri: String,
632 #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
634 pub mime_type: Option<String>,
635 #[serde(skip_serializing_if = "Option::is_none")]
637 pub name: Option<String>,
638}
639
640#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
642pub struct Artifact {
643 #[serde(rename = "artifactId")]
645 pub artifact_id: String,
646 pub parts: Vec<Part>,
648 #[serde(skip_serializing_if = "Option::is_none")]
650 pub name: Option<String>,
651 #[serde(skip_serializing_if = "Option::is_none")]
653 pub description: Option<String>,
654 #[serde(skip_serializing_if = "Vec::is_empty", default)]
656 pub extensions: Vec<String>,
657 #[serde(skip_serializing_if = "Option::is_none")]
659 pub metadata: Option<HashMap<String, serde_json::Value>>,
660}
661
662#[derive(Debug, Clone, Serialize, Deserialize)]
668pub struct MessageSendParams {
669 pub message: Message,
671 #[serde(skip_serializing_if = "Option::is_none")]
673 pub configuration: Option<MessageSendConfiguration>,
674 #[serde(skip_serializing_if = "Option::is_none")]
676 pub metadata: Option<HashMap<String, serde_json::Value>>,
677}
678
679#[derive(Debug, Clone, Serialize, Deserialize, Default)]
681pub struct MessageSendConfiguration {
682 #[serde(skip_serializing_if = "Option::is_none")]
684 pub blocking: Option<bool>,
685 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
687 pub history_length: Option<i32>,
688 #[serde(
690 skip_serializing_if = "Vec::is_empty",
691 rename = "acceptedOutputModes",
692 default
693 )]
694 pub accepted_output_modes: Vec<String>,
695 #[serde(
697 skip_serializing_if = "Option::is_none",
698 rename = "pushNotificationConfig"
699 )]
700 pub push_notification_config: Option<PushNotificationConfig>,
701}
702
703#[derive(Debug, Clone, Serialize, Deserialize)]
705pub struct PushNotificationConfig {
706 pub url: String,
708 #[serde(skip_serializing_if = "Option::is_none")]
710 pub id: Option<String>,
711 #[serde(skip_serializing_if = "Option::is_none")]
713 pub token: Option<String>,
714 #[serde(skip_serializing_if = "Option::is_none")]
716 pub authentication: Option<PushNotificationAuthenticationInfo>,
717}
718
719#[derive(Debug, Clone, Serialize, Deserialize)]
721pub struct PushNotificationAuthenticationInfo {
722 pub schemes: Vec<String>,
724 #[serde(skip_serializing_if = "Option::is_none")]
726 pub credentials: Option<String>,
727}
728
729#[derive(Debug, Clone, Serialize, Deserialize)]
731pub struct TaskIdParams {
732 pub id: String,
734 #[serde(skip_serializing_if = "Option::is_none")]
736 pub metadata: Option<HashMap<String, serde_json::Value>>,
737}
738
739#[derive(Debug, Clone, Serialize, Deserialize)]
741pub struct TaskQueryParams {
742 pub id: String,
744 #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
746 pub history_length: Option<i32>,
747 #[serde(skip_serializing_if = "Option::is_none")]
749 pub metadata: Option<HashMap<String, serde_json::Value>>,
750}
751
752#[derive(Debug, Clone, Serialize, Deserialize)]
754pub struct TaskPushNotificationConfig {
755 #[serde(rename = "taskId")]
757 pub task_id: String,
758 #[serde(rename = "pushNotificationConfig")]
760 pub push_notification_config: PushNotificationConfig,
761}
762
763#[derive(Debug, Clone, Serialize, Deserialize)]
765#[serde(untagged)]
766pub enum GetTaskPushNotificationConfigParams {
767 TaskIdOnly(TaskIdParams),
768 WithConfigId(GetTaskPushNotificationConfigParamsWithId),
769}
770
771#[derive(Debug, Clone, Serialize, Deserialize)]
773pub struct GetTaskPushNotificationConfigParamsWithId {
774 pub id: String,
776 #[serde(rename = "pushNotificationConfigId")]
778 pub push_notification_config_id: String,
779 #[serde(skip_serializing_if = "Option::is_none")]
781 pub metadata: Option<HashMap<String, serde_json::Value>>,
782}
783
784#[derive(Debug, Clone, Serialize, Deserialize)]
786pub struct ListTaskPushNotificationConfigParams {
787 pub id: String,
789 #[serde(skip_serializing_if = "Option::is_none")]
791 pub metadata: Option<HashMap<String, serde_json::Value>>,
792}
793
794#[derive(Debug, Clone, Serialize, Deserialize)]
796pub struct DeleteTaskPushNotificationConfigParams {
797 pub id: String,
799 #[serde(rename = "pushNotificationConfigId")]
801 pub push_notification_config_id: String,
802 #[serde(skip_serializing_if = "Option::is_none")]
804 pub metadata: Option<HashMap<String, serde_json::Value>>,
805}
806
807fn default_jsonrpc_version() -> String {
812 "2.0".to_string()
813}
814
815#[derive(Debug, Clone, Serialize, Deserialize)]
817pub struct A2ARequest {
818 #[serde(default = "default_jsonrpc_version")]
820 pub jsonrpc: String,
821 #[serde(skip_serializing_if = "Option::is_none")]
823 pub id: Option<JSONRPCId>,
824 #[serde(flatten)]
826 pub payload: A2ARequestPayload,
827}
828
829#[derive(Debug, Clone, Serialize, Deserialize)]
831#[serde(tag = "method")]
832pub enum A2ARequestPayload {
833 #[serde(rename = "message/send")]
835 SendMessage { params: MessageSendParams },
836 #[serde(rename = "message/stream")]
838 SendStreamingMessage { params: MessageSendParams },
839 #[serde(rename = "tasks/get")]
841 GetTask { params: TaskQueryParams },
842 #[serde(rename = "tasks/cancel")]
844 CancelTask { params: TaskIdParams },
845 #[serde(rename = "tasks/pushNotificationConfig/set")]
847 SetTaskPushNotificationConfig { params: TaskPushNotificationConfig },
848 #[serde(rename = "tasks/pushNotificationConfig/get")]
850 GetTaskPushNotificationConfig {
851 params: GetTaskPushNotificationConfigParams,
852 },
853 #[serde(rename = "tasks/resubscribe")]
855 TaskResubscription { params: TaskIdParams },
856 #[serde(rename = "tasks/pushNotificationConfig/list")]
858 ListTaskPushNotificationConfig {
859 params: ListTaskPushNotificationConfigParams,
860 },
861 #[serde(rename = "tasks/pushNotificationConfig/delete")]
863 DeleteTaskPushNotificationConfig {
864 params: DeleteTaskPushNotificationConfigParams,
865 },
866 #[serde(rename = "agent/getAuthenticatedExtendedCard")]
868 GetAuthenticatedExtendedCard,
869}
870
871#[derive(Debug, Clone, Serialize, Deserialize)]
877#[serde(untagged)]
878pub enum SendMessageResult {
879 Task(Task),
880 Message(Message),
881}
882
883#[derive(Debug, Clone, Serialize, Deserialize)]
885pub struct SendMessageSuccessResponse {
886 pub jsonrpc: String, pub result: SendMessageResult,
888 pub id: Option<JSONRPCId>,
889}
890
891#[derive(Debug, Clone, Serialize, Deserialize)]
893#[serde(untagged)]
894pub enum SendMessageResponse {
895 Success(Box<SendMessageSuccessResponse>),
896 Error(JSONRPCErrorResponse),
897}
898
899#[derive(Debug, Clone, Serialize, Deserialize)]
901#[serde(untagged)]
902pub enum SendStreamingMessageResult {
903 Task(Task),
904 Message(Message),
905 TaskStatusUpdate(TaskStatusUpdateEvent),
906 TaskArtifactUpdate(TaskArtifactUpdateEvent),
907}
908
909#[derive(Debug, Clone, Serialize, Deserialize)]
911pub struct SendStreamingMessageSuccessResponse {
912 pub jsonrpc: String, pub result: SendStreamingMessageResult,
914 pub id: Option<JSONRPCId>,
915}
916
917#[derive(Debug, Clone, Serialize, Deserialize)]
919#[serde(untagged)]
920pub enum SendStreamingMessageResponse {
921 Success(Box<SendStreamingMessageSuccessResponse>),
922 Error(JSONRPCErrorResponse),
923}
924
925#[derive(Debug, Clone, Serialize, Deserialize)]
927pub struct GetTaskSuccessResponse {
928 pub jsonrpc: String, pub result: Task,
930 pub id: Option<JSONRPCId>,
931}
932
933#[derive(Debug, Clone, Serialize, Deserialize)]
935#[serde(untagged)]
936pub enum GetTaskResponse {
937 Success(Box<GetTaskSuccessResponse>),
938 Error(JSONRPCErrorResponse),
939}
940
941#[derive(Debug, Clone, Serialize, Deserialize)]
943pub struct CancelTaskSuccessResponse {
944 pub jsonrpc: String, pub result: Task,
946 pub id: Option<JSONRPCId>,
947}
948
949#[derive(Debug, Clone, Serialize, Deserialize)]
951#[serde(untagged)]
952pub enum CancelTaskResponse {
953 Success(Box<CancelTaskSuccessResponse>),
954 Error(JSONRPCErrorResponse),
955}
956
957#[derive(Debug, Clone, Serialize, Deserialize)]
959pub struct SetTaskPushNotificationConfigSuccessResponse {
960 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
962 pub id: Option<JSONRPCId>,
963}
964
965#[derive(Debug, Clone, Serialize, Deserialize)]
967#[serde(untagged)]
968pub enum SetTaskPushNotificationConfigResponse {
969 Success(Box<SetTaskPushNotificationConfigSuccessResponse>),
970 Error(JSONRPCErrorResponse),
971}
972
973#[derive(Debug, Clone, Serialize, Deserialize)]
975pub struct GetTaskPushNotificationConfigSuccessResponse {
976 pub jsonrpc: String, pub result: TaskPushNotificationConfig,
978 pub id: Option<JSONRPCId>,
979}
980
981#[derive(Debug, Clone, Serialize, Deserialize)]
983#[serde(untagged)]
984pub enum GetTaskPushNotificationConfigResponse {
985 Success(Box<GetTaskPushNotificationConfigSuccessResponse>),
986 Error(JSONRPCErrorResponse),
987}
988
989#[derive(Debug, Clone, Serialize, Deserialize)]
991pub struct ListTaskPushNotificationConfigSuccessResponse {
992 pub jsonrpc: String, pub result: Vec<TaskPushNotificationConfig>,
994 pub id: Option<JSONRPCId>,
995}
996
997#[derive(Debug, Clone, Serialize, Deserialize)]
999#[serde(untagged)]
1000pub enum ListTaskPushNotificationConfigResponse {
1001 Success(Box<ListTaskPushNotificationConfigSuccessResponse>),
1002 Error(JSONRPCErrorResponse),
1003}
1004
1005#[derive(Debug, Clone, Serialize, Deserialize)]
1007pub struct DeleteTaskPushNotificationConfigSuccessResponse {
1008 pub jsonrpc: String, pub result: (),
1011 pub id: Option<JSONRPCId>,
1012}
1013
1014#[derive(Debug, Clone, Serialize, Deserialize)]
1016#[serde(untagged)]
1017pub enum DeleteTaskPushNotificationConfigResponse {
1018 Success(Box<DeleteTaskPushNotificationConfigSuccessResponse>),
1019 Error(JSONRPCErrorResponse),
1020}
1021
1022#[derive(Debug, Clone, Serialize, Deserialize)]
1024pub struct GetAuthenticatedExtendedCardSuccessResponse {
1025 pub jsonrpc: String, pub result: AgentCard,
1027 pub id: Option<JSONRPCId>,
1028}
1029
1030#[derive(Debug, Clone, Serialize, Deserialize)]
1032#[serde(untagged)]
1033pub enum GetAuthenticatedExtendedCardResponse {
1034 Success(Box<GetAuthenticatedExtendedCardSuccessResponse>),
1035 Error(JSONRPCErrorResponse),
1036}
1037
1038pub const PROTOCOL_VERSION: &str = "0.3.0";
1040pub const API_KEY_TYPE: &str = "apiKey";
1041pub const HTTP_TYPE: &str = "http";
1042pub const OAUTH2_TYPE: &str = "oauth2";
1043pub const OPENID_TYPE: &str = "openIdConnect";
1044pub const MUTUAL_TLS_TYPE: &str = "mutualTLS";
1045pub const TASK_KIND: &str = "task";
1046pub const MESSAGE_KIND: &str = "message";
1047pub const STATUS_UPDATE_KIND: &str = "status-update";
1048pub const ARTIFACT_UPDATE_KIND: &str = "artifact-update";
1049
1050#[derive(Debug, Clone, Serialize, Deserialize)]
1056#[serde(untagged)]
1057pub enum SecurityScheme {
1058 ApiKey(APIKeySecurityScheme),
1059 Http(HTTPAuthSecurityScheme),
1060 OAuth2(Box<OAuth2SecurityScheme>),
1061 OpenIdConnect(OpenIdConnectSecurityScheme),
1062 MutualTLS(MutualTLSSecurityScheme),
1063}
1064
1065#[derive(Debug, Clone, Serialize, Deserialize)]
1067pub struct APIKeySecurityScheme {
1068 #[serde(rename = "type", default = "default_api_key_type")]
1070 pub scheme_type: String,
1071 pub name: String,
1073 #[serde(rename = "in")]
1075 pub location: APIKeyLocation,
1076 #[serde(skip_serializing_if = "Option::is_none")]
1078 pub description: Option<String>,
1079}
1080
1081fn default_api_key_type() -> String {
1082 API_KEY_TYPE.to_string()
1083}
1084
1085#[derive(Debug, Clone, Serialize, Deserialize)]
1087#[serde(rename_all = "lowercase")]
1088pub enum APIKeyLocation {
1089 Query,
1090 Header,
1091 Cookie,
1092}
1093
1094#[derive(Debug, Clone, Serialize, Deserialize)]
1096pub struct HTTPAuthSecurityScheme {
1097 #[serde(rename = "type", default = "default_http_type")]
1099 pub scheme_type: String,
1100 pub scheme: String,
1102 #[serde(skip_serializing_if = "Option::is_none")]
1104 pub description: Option<String>,
1105 #[serde(skip_serializing_if = "Option::is_none", rename = "bearerFormat")]
1107 pub bearer_format: Option<String>,
1108}
1109
1110fn default_http_type() -> String {
1111 HTTP_TYPE.to_string()
1112}
1113
1114#[derive(Debug, Clone, Serialize, Deserialize)]
1116pub struct OAuth2SecurityScheme {
1117 #[serde(rename = "type", default = "default_oauth2_type")]
1119 pub scheme_type: String,
1120 pub flows: OAuthFlows,
1122 #[serde(skip_serializing_if = "Option::is_none")]
1124 pub description: Option<String>,
1125 #[serde(skip_serializing_if = "Option::is_none", rename = "oauth2MetadataUrl")]
1127 pub oauth2_metadata_url: Option<String>,
1128}
1129
1130fn default_oauth2_type() -> String {
1131 OAUTH2_TYPE.to_string()
1132}
1133
1134#[derive(Debug, Clone, Serialize, Deserialize)]
1136pub struct OpenIdConnectSecurityScheme {
1137 #[serde(rename = "type", default = "default_openid_type")]
1139 pub scheme_type: String,
1140 #[serde(rename = "openIdConnectUrl")]
1142 pub open_id_connect_url: String,
1143 #[serde(skip_serializing_if = "Option::is_none")]
1145 pub description: Option<String>,
1146}
1147
1148fn default_openid_type() -> String {
1149 OPENID_TYPE.to_string()
1150}
1151
1152#[derive(Debug, Clone, Serialize, Deserialize)]
1154pub struct MutualTLSSecurityScheme {
1155 #[serde(rename = "type", default = "default_mutual_tls_type")]
1157 pub scheme_type: String,
1158 #[serde(skip_serializing_if = "Option::is_none")]
1160 pub description: Option<String>,
1161}
1162
1163fn default_mutual_tls_type() -> String {
1164 MUTUAL_TLS_TYPE.to_string()
1165}
1166
1167#[derive(Debug, Clone, Serialize, Deserialize)]
1169pub struct OAuthFlows {
1170 #[serde(skip_serializing_if = "Option::is_none", rename = "authorizationCode")]
1172 pub authorization_code: Option<AuthorizationCodeOAuthFlow>,
1173 #[serde(skip_serializing_if = "Option::is_none")]
1175 pub implicit: Option<ImplicitOAuthFlow>,
1176 #[serde(skip_serializing_if = "Option::is_none")]
1178 pub password: Option<PasswordOAuthFlow>,
1179 #[serde(skip_serializing_if = "Option::is_none", rename = "clientCredentials")]
1181 pub client_credentials: Option<ClientCredentialsOAuthFlow>,
1182}
1183
1184#[derive(Debug, Clone, Serialize, Deserialize)]
1186pub struct AuthorizationCodeOAuthFlow {
1187 #[serde(rename = "authorizationUrl")]
1189 pub authorization_url: String,
1190 #[serde(rename = "tokenUrl")]
1192 pub token_url: String,
1193 pub scopes: HashMap<String, String>,
1195 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1197 pub refresh_url: Option<String>,
1198}
1199
1200#[derive(Debug, Clone, Serialize, Deserialize)]
1202pub struct ImplicitOAuthFlow {
1203 #[serde(rename = "authorizationUrl")]
1205 pub authorization_url: String,
1206 pub scopes: HashMap<String, String>,
1208 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1210 pub refresh_url: Option<String>,
1211}
1212
1213#[derive(Debug, Clone, Serialize, Deserialize)]
1215pub struct PasswordOAuthFlow {
1216 #[serde(rename = "tokenUrl")]
1218 pub token_url: String,
1219 pub scopes: HashMap<String, String>,
1221 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1223 pub refresh_url: Option<String>,
1224}
1225
1226#[derive(Debug, Clone, Serialize, Deserialize)]
1228pub struct ClientCredentialsOAuthFlow {
1229 #[serde(rename = "tokenUrl")]
1231 pub token_url: String,
1232 pub scopes: HashMap<String, String>,
1234 #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1236 pub refresh_url: Option<String>,
1237}
1238
1239#[derive(Debug, Clone, Serialize, Deserialize)]
1245#[serde(untagged)]
1246pub enum AgentResponse {
1247 Task(Task),
1248 Message(Message),
1249}
1250
1251#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1257pub struct TaskStatusUpdateEvent {
1258 #[serde(default = "default_status_update_kind")]
1260 pub kind: String,
1261 #[serde(rename = "taskId")]
1263 pub task_id: String,
1264 #[serde(rename = "contextId")]
1266 pub context_id: String,
1267 pub status: TaskStatus,
1269 #[serde(rename = "final")]
1271 pub is_final: bool,
1272 #[serde(skip_serializing_if = "Option::is_none")]
1274 pub metadata: Option<HashMap<String, serde_json::Value>>,
1275}
1276
1277fn default_status_update_kind() -> String {
1278 STATUS_UPDATE_KIND.to_string()
1279}
1280
1281#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1283pub struct TaskArtifactUpdateEvent {
1284 #[serde(default = "default_artifact_update_kind")]
1286 pub kind: String,
1287 #[serde(rename = "taskId")]
1289 pub task_id: String,
1290 #[serde(rename = "contextId")]
1292 pub context_id: String,
1293 pub artifact: Artifact,
1295 #[serde(skip_serializing_if = "Option::is_none")]
1297 pub append: Option<bool>,
1298 #[serde(skip_serializing_if = "Option::is_none", rename = "lastChunk")]
1300 pub last_chunk: Option<bool>,
1301 #[serde(skip_serializing_if = "Option::is_none")]
1303 pub metadata: Option<HashMap<String, serde_json::Value>>,
1304}
1305
1306fn default_artifact_update_kind() -> String {
1307 ARTIFACT_UPDATE_KIND.to_string()
1308}