a2a_types/
lib.rs

1//! # A2A (Agent2Agent) Protocol Types
2//!
3//! This crate provides the Rust data structures for the Agent2Agent (A2A) protocol,
4//! a standard for interoperability between AI agents. The types are derived from the
5//! official A2A JSON Schema for that specific release
6//! and are designed for serialization and deserialization with `serde`.
7//!
8//! The primary goal of A2A is to enable agents to:
9//! - Discover each other's capabilities via the `AgentCard`.
10//! - Negotiate interaction modalities (text, files, structured data).
11//! - Manage collaborative `Task`s.
12//! - Securely exchange information as `Message`s.
13
14use serde::{Deserialize, Serialize};
15use std::collections::HashMap;
16
17// ============================================================================
18// JSON-RPC 2.0 Base Types (from schema)
19// ============================================================================
20
21// Re-export agent card types
22pub mod agent_card;
23pub use agent_card::{
24    AgentCapabilities, AgentCard, AgentCardSignature, AgentExtension, AgentInterface,
25    AgentProvider, AgentSkill, TransportProtocol,
26};
27
28/// Defines the base structure for any JSON-RPC 2.0 request, response, or notification.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct JSONRPCMessage {
31    /// The version of the JSON-RPC protocol. MUST be exactly "2.0".
32    pub jsonrpc: String,
33    /// A unique identifier established by the client. It must be a String, a Number, or null.
34    /// The server must reply with the same value in the response. This property is omitted for notifications.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub id: Option<JSONRPCId>,
37}
38
39/// Represents a JSON-RPC 2.0 identifier, which can be a string, number, or null.
40#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
41#[serde(untagged)]
42pub enum JSONRPCId {
43    String(String),
44    Integer(i64),
45    Null,
46}
47
48/// Represents a JSON-RPC 2.0 Request object.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct JSONRPCRequest {
51    /// The version of the JSON-RPC protocol. MUST be exactly "2.0".
52    pub jsonrpc: String,
53    /// A string containing the name of the method to be invoked.
54    pub method: String,
55    /// A structured value holding the parameter values to be used during the method invocation.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub params: Option<serde_json::Value>,
58}
59
60/// Represents a successful JSON-RPC 2.0 Response object.
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct JSONRPCSuccessResponse {
63    /// The version of the JSON-RPC protocol. MUST be exactly "2.0".
64    pub jsonrpc: String,
65    /// The value of this member is determined by the method invoked on the Server.
66    pub result: serde_json::Value,
67    /// The identifier established by the client.
68    pub id: Option<JSONRPCId>,
69}
70
71/// Represents a JSON-RPC 2.0 Error Response object.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct JSONRPCErrorResponse {
74    /// The version of the JSON-RPC protocol. MUST be exactly "2.0".
75    pub jsonrpc: String,
76    /// An object describing the error that occurred.
77    pub error: JSONRPCError,
78    /// The identifier established by the client.
79    pub id: Option<JSONRPCId>,
80}
81
82/// Represents a JSON-RPC 2.0 Error object, included in an error response.
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct JSONRPCError {
85    /// A number that indicates the error type that occurred.
86    pub code: i32,
87    /// A string providing a short description of the error.
88    pub message: String,
89    /// A primitive or structured value containing additional information about the error.
90    /// This may be omitted.
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub data: Option<serde_json::Value>,
93}
94
95/// A discriminated union representing all possible JSON-RPC 2.0 responses
96/// for the A2A specification methods.
97#[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// ============================================================================
113// A2A Error Types (from schema definitions)
114// ============================================================================
115
116/// An error indicating that the server received invalid JSON.
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(default)]
119pub struct JSONParseError {
120    /// The error code for a JSON parse error.
121    pub code: i32, // -32700
122    /// The error message.
123    pub message: String,
124    /// A primitive or structured value containing additional information about the error.
125    #[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/// An error indicating that the JSON sent is not a valid Request object.
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(default)]
142pub struct InvalidRequestError {
143    /// The error code for an invalid request.
144    pub code: i32, // -32600
145    /// The error message.
146    pub message: String,
147    /// A primitive or structured value containing additional information about the error.
148    #[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/// An error indicating that the requested method does not exist or is not available.
163#[derive(Debug, Clone, Serialize, Deserialize)]
164#[serde(default)]
165pub struct MethodNotFoundError {
166    /// The error code for a method not found error.
167    pub code: i32, // -32601
168    /// The error message.
169    pub message: String,
170    /// A primitive or structured value containing additional information about the error.
171    #[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/// An error indicating that the method parameters are invalid.
186#[derive(Debug, Clone, Serialize, Deserialize)]
187#[serde(default)]
188pub struct InvalidParamsError {
189    /// The error code for an invalid parameters error.
190    pub code: i32, // -32602
191    /// The error message.
192    pub message: String,
193    /// A primitive or structured value containing additional information about the error.
194    #[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/// An error indicating an internal error on the server.
209#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(default)]
211pub struct InternalError {
212    /// The error code for an internal server error.
213    pub code: i32, // -32603
214    /// The error message.
215    pub message: String,
216    /// A primitive or structured value containing additional information about the error.
217    #[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/// An A2A-specific error indicating that the requested task ID was not found.
232#[derive(Debug, Clone, Serialize, Deserialize)]
233#[serde(default)]
234pub struct TaskNotFoundError {
235    /// The error code for a task not found error.
236    pub code: i32, // -32001
237    /// The error message.
238    pub message: String,
239    /// A primitive or structured value containing additional information about the error.
240    #[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/// An A2A-specific error indicating that the task is in a state where it cannot be canceled.
255#[derive(Debug, Clone, Serialize, Deserialize)]
256#[serde(default)]
257pub struct TaskNotCancelableError {
258    /// The error code for a task that cannot be canceled.
259    pub code: i32, // -32002
260    /// The error message.
261    pub message: String,
262    /// A primitive or structured value containing additional information about the error.
263    #[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/// An A2A-specific error indicating that the agent does not support push notifications.
278#[derive(Debug, Clone, Serialize, Deserialize)]
279#[serde(default)]
280pub struct PushNotificationNotSupportedError {
281    /// The error code for when push notifications are not supported.
282    pub code: i32, // -32003
283    /// The error message.
284    pub message: String,
285    /// A primitive or structured value containing additional information about the error.
286    #[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/// An A2A-specific error indicating that the requested operation is not supported by the agent.
301#[derive(Debug, Clone, Serialize, Deserialize)]
302#[serde(default)]
303pub struct UnsupportedOperationError {
304    /// The error code for an unsupported operation.
305    pub code: i32, // -32004
306    /// The error message.
307    pub message: String,
308    /// A primitive or structured value containing additional information about the error.
309    #[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/// An A2A-specific error indicating an incompatibility between the requested
324/// content types and the agent's capabilities.
325#[derive(Debug, Clone, Serialize, Deserialize)]
326#[serde(default)]
327pub struct ContentTypeNotSupportedError {
328    /// The error code for an unsupported content type.
329    pub code: i32, // -32005
330    /// The error message.
331    pub message: String,
332    /// A primitive or structured value containing additional information about the error.
333    #[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/// An A2A-specific error indicating that the agent returned a response that
348/// does not conform to the specification for the current method.
349#[derive(Debug, Clone, Serialize, Deserialize)]
350#[serde(default)]
351pub struct InvalidAgentResponseError {
352    /// The error code for an invalid agent response.
353    pub code: i32, // -32006
354    /// The error message.
355    pub message: String,
356    /// A primitive or structured value containing additional information about the error.
357    #[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/// An A2A-specific error indicating that the agent does not have an Authenticated Extended Card configured.
372#[derive(Debug, Clone, Serialize, Deserialize)]
373#[serde(default)]
374pub struct AuthenticatedExtendedCardNotConfiguredError {
375    /// The error code for when an authenticated extended card is not configured.
376    pub code: i32, // -32007
377    /// The error message.
378    pub message: String,
379    /// A primitive or structured value containing additional information about the error.
380    #[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/// A discriminated union of all standard JSON-RPC and A2A-specific error types.
395#[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
412// Error code and message constants
413const 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// ============================================================================
440// A2A Core Protocol Types (from schema)
441// ============================================================================
442
443/// Defines the lifecycle states of a Task.
444#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
445#[serde(rename_all = "kebab-case")]
446pub enum TaskState {
447    /// The task has been submitted and is awaiting execution.
448    Submitted,
449    /// The agent is actively working on the task.
450    Working,
451    /// The task is paused and waiting for input from the user.
452    InputRequired,
453    /// The task has been successfully completed.
454    Completed,
455    /// The task has been canceled by the user.
456    Canceled,
457    /// The task failed due to an error during execution.
458    Failed,
459    /// The task was rejected by the agent and was not started.
460    Rejected,
461    /// The task requires authentication to proceed.
462    AuthRequired,
463    /// The task is in an unknown or indeterminate state.
464    Unknown,
465}
466
467/// Represents the status of a task at a specific point in time.
468#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
469pub struct TaskStatus {
470    /// The current state of the task's lifecycle.
471    pub state: TaskState,
472    /// An ISO 8601 datetime string indicating when this status was recorded.
473    #[serde(skip_serializing_if = "Option::is_none")]
474    pub timestamp: Option<String>,
475    /// An optional, human-readable message providing more details about the current status.
476    #[serde(skip_serializing_if = "Option::is_none")]
477    pub message: Option<Message>,
478}
479
480/// Represents a single, stateful operation or conversation between a client and an agent.
481#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
482pub struct Task {
483    /// The type of this object, used as a discriminator. Always 'task'.
484    #[serde(default = "default_task_kind")]
485    pub kind: String,
486    /// A unique identifier for the task, generated by the server for a new task.
487    pub id: String,
488    /// A server-generated identifier for maintaining context across multiple related tasks or interactions.
489    #[serde(rename = "contextId")]
490    pub context_id: String,
491    /// The current status of the task, including its state and a descriptive message.
492    pub status: TaskStatus,
493    /// An array of messages exchanged during the task, representing the conversation history.
494    #[serde(skip_serializing_if = "Vec::is_empty", default)]
495    pub history: Vec<Message>,
496    /// A collection of artifacts generated by the agent during the execution of the task.
497    #[serde(skip_serializing_if = "Vec::is_empty", default)]
498    pub artifacts: Vec<Artifact>,
499    /// Optional metadata for extensions. The key is an extension-specific identifier.
500    #[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/// Identifies the sender of a message.
509#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
510#[serde(rename_all = "lowercase")]
511pub enum MessageRole {
512    /// For messages sent by the client/user.
513    User,
514    /// For messages sent by the agent/service.
515    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/// Represents a single message in the conversation between a user and an agent.
530#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
531pub struct Message {
532    /// The type of this object, used as a discriminator. Always 'message'.
533    #[serde(default = "default_message_kind")]
534    pub kind: String,
535    /// A unique identifier for the message, typically a UUID, generated by the sender.
536    #[serde(rename = "messageId")]
537    pub message_id: String,
538    /// Identifies the sender of the message. `user` for the client, `agent` for the service.
539    pub role: MessageRole,
540    /// An array of content parts that form the message body.
541    pub parts: Vec<Part>,
542    /// The context identifier for this message, used to group related interactions.
543    #[serde(skip_serializing_if = "Option::is_none", rename = "contextId")]
544    pub context_id: Option<String>,
545    /// The identifier of the task this message is part of. Can be omitted for the first message of a new task.
546    #[serde(skip_serializing_if = "Option::is_none", rename = "taskId")]
547    pub task_id: Option<String>,
548    /// A list of other task IDs that this message references for additional context.
549    #[serde(
550        skip_serializing_if = "Vec::is_empty",
551        rename = "referenceTaskIds",
552        default
553    )]
554    pub reference_task_ids: Vec<String>,
555    /// The URIs of extensions that are relevant to this message.
556    #[serde(skip_serializing_if = "Vec::is_empty", default)]
557    pub extensions: Vec<String>,
558    /// Optional metadata for extensions. The key is an extension-specific identifier.
559    #[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/// A discriminated union representing a part of a message or artifact.
568#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
569#[serde(tag = "kind", rename_all = "lowercase")]
570pub enum Part {
571    /// Represents a text segment.
572    Text {
573        /// The string content of the text part.
574        text: String,
575        /// Optional metadata associated with this part.
576        #[serde(skip_serializing_if = "Option::is_none")]
577        metadata: Option<HashMap<String, serde_json::Value>>,
578    },
579    /// Represents a file segment.
580    File {
581        /// The file content, represented as either a URI or as base64-encoded bytes.
582        file: FileContent,
583        /// Optional metadata associated with this part.
584        #[serde(skip_serializing_if = "Option::is_none")]
585        metadata: Option<HashMap<String, serde_json::Value>>,
586    },
587    /// Represents a structured data segment (e.g., JSON).
588    Data {
589        /// The structured data content.
590        data: serde_json::Value,
591        /// Optional metadata associated with this part.
592        #[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/// Represents file content, which can be provided either directly as bytes or as a URI.
607#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
608#[serde(untagged)]
609pub enum FileContent {
610    WithBytes(FileWithBytes),
611    WithUri(FileWithUri),
612}
613
614/// Represents a file with its content provided directly as a base64-encoded string.
615#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
616pub struct FileWithBytes {
617    /// The base64-encoded content of the file.
618    pub bytes: String,
619    /// The MIME type of the file (e.g., "application/pdf").
620    #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
621    pub mime_type: Option<String>,
622    /// An optional name for the file (e.g., "document.pdf").
623    #[serde(skip_serializing_if = "Option::is_none")]
624    pub name: Option<String>,
625}
626
627/// Represents a file with its content located at a specific URI.
628#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
629pub struct FileWithUri {
630    /// A URL pointing to the file's content.
631    pub uri: String,
632    /// The MIME type of the file (e.g., "application/pdf").
633    #[serde(skip_serializing_if = "Option::is_none", rename = "mimeType")]
634    pub mime_type: Option<String>,
635    /// An optional name for the file (e.g., "document.pdf").
636    #[serde(skip_serializing_if = "Option::is_none")]
637    pub name: Option<String>,
638}
639
640/// Represents a file, data structure, or other resource generated by an agent during a task.
641#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
642pub struct Artifact {
643    /// A unique identifier for the artifact within the scope of the task.
644    #[serde(rename = "artifactId")]
645    pub artifact_id: String,
646    /// An array of content parts that make up the artifact.
647    pub parts: Vec<Part>,
648    /// An optional, human-readable name for the artifact.
649    #[serde(skip_serializing_if = "Option::is_none")]
650    pub name: Option<String>,
651    /// An optional, human-readable description of the artifact.
652    #[serde(skip_serializing_if = "Option::is_none")]
653    pub description: Option<String>,
654    /// The URIs of extensions that are relevant to this artifact.
655    #[serde(skip_serializing_if = "Vec::is_empty", default)]
656    pub extensions: Vec<String>,
657    /// Optional metadata for extensions. The key is an extension-specific identifier.
658    #[serde(skip_serializing_if = "Option::is_none")]
659    pub metadata: Option<HashMap<String, serde_json::Value>>,
660}
661
662// ============================================================================
663// A2A Method Parameter Types (from schema)
664// ============================================================================
665
666/// Defines the parameters for a request to send a message to an agent.
667#[derive(Debug, Clone, Serialize, Deserialize)]
668pub struct MessageSendParams {
669    /// The message object being sent to the agent.
670    pub message: Message,
671    /// Optional configuration for the send request.
672    #[serde(skip_serializing_if = "Option::is_none")]
673    pub configuration: Option<MessageSendConfiguration>,
674    /// Optional metadata for extensions.
675    #[serde(skip_serializing_if = "Option::is_none")]
676    pub metadata: Option<HashMap<String, serde_json::Value>>,
677}
678
679/// Defines configuration options for a `message/send` or `message/stream` request.
680#[derive(Debug, Clone, Serialize, Deserialize, Default)]
681pub struct MessageSendConfiguration {
682    /// If true, the client will wait for the task to complete. The server may reject this if the task is long-running.
683    #[serde(skip_serializing_if = "Option::is_none")]
684    pub blocking: Option<bool>,
685    /// The number of most recent messages from the task's history to retrieve in the response.
686    #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
687    pub history_length: Option<i32>,
688    /// A list of output MIME types the client is prepared to accept in the response.
689    #[serde(
690        skip_serializing_if = "Vec::is_empty",
691        rename = "acceptedOutputModes",
692        default
693    )]
694    pub accepted_output_modes: Vec<String>,
695    /// Configuration for the agent to send push notifications for updates after the initial response.
696    #[serde(
697        skip_serializing_if = "Option::is_none",
698        rename = "pushNotificationConfig"
699    )]
700    pub push_notification_config: Option<PushNotificationConfig>,
701}
702
703/// Defines the configuration for setting up push notifications for task updates.
704#[derive(Debug, Clone, Serialize, Deserialize)]
705pub struct PushNotificationConfig {
706    /// The callback URL where the agent should send push notifications.
707    pub url: String,
708    /// A unique ID for the push notification configuration, set by the client.
709    #[serde(skip_serializing_if = "Option::is_none")]
710    pub id: Option<String>,
711    /// A unique token for this task or session to validate incoming push notifications.
712    #[serde(skip_serializing_if = "Option::is_none")]
713    pub token: Option<String>,
714    /// Optional authentication details for the agent to use when calling the notification URL.
715    #[serde(skip_serializing_if = "Option::is_none")]
716    pub authentication: Option<PushNotificationAuthenticationInfo>,
717}
718
719/// Defines authentication details for a push notification endpoint.
720#[derive(Debug, Clone, Serialize, Deserialize)]
721pub struct PushNotificationAuthenticationInfo {
722    /// A list of supported authentication schemes (e.g., 'Basic', 'Bearer').
723    pub schemes: Vec<String>,
724    /// Optional credentials required by the push notification endpoint.
725    #[serde(skip_serializing_if = "Option::is_none")]
726    pub credentials: Option<String>,
727}
728
729/// Defines parameters containing a task ID, used for simple task operations.
730#[derive(Debug, Clone, Serialize, Deserialize)]
731pub struct TaskIdParams {
732    /// The unique identifier of the task.
733    pub id: String,
734    /// Optional metadata associated with the request.
735    #[serde(skip_serializing_if = "Option::is_none")]
736    pub metadata: Option<HashMap<String, serde_json::Value>>,
737}
738
739/// Defines parameters for querying a task, with an option to limit history length.
740#[derive(Debug, Clone, Serialize, Deserialize)]
741pub struct TaskQueryParams {
742    /// The unique identifier of the task.
743    pub id: String,
744    /// The number of most recent messages from the task's history to retrieve.
745    #[serde(skip_serializing_if = "Option::is_none", rename = "historyLength")]
746    pub history_length: Option<i32>,
747    /// Optional metadata associated with the request.
748    #[serde(skip_serializing_if = "Option::is_none")]
749    pub metadata: Option<HashMap<String, serde_json::Value>>,
750}
751
752/// A container associating a push notification configuration with a specific task.
753#[derive(Debug, Clone, Serialize, Deserialize)]
754pub struct TaskPushNotificationConfig {
755    /// The ID of the task.
756    #[serde(rename = "taskId")]
757    pub task_id: String,
758    /// The push notification configuration for this task.
759    #[serde(rename = "pushNotificationConfig")]
760    pub push_notification_config: PushNotificationConfig,
761}
762
763/// Defines parameters for fetching a specific push notification configuration for a task.
764#[derive(Debug, Clone, Serialize, Deserialize)]
765#[serde(untagged)]
766pub enum GetTaskPushNotificationConfigParams {
767    TaskIdOnly(TaskIdParams),
768    WithConfigId(GetTaskPushNotificationConfigParamsWithId),
769}
770
771/// Parameters for fetching a push notification configuration with a specific config ID.
772#[derive(Debug, Clone, Serialize, Deserialize)]
773pub struct GetTaskPushNotificationConfigParamsWithId {
774    /// The unique identifier of the task.
775    pub id: String,
776    /// The ID of the push notification configuration to retrieve.
777    #[serde(rename = "pushNotificationConfigId")]
778    pub push_notification_config_id: String,
779    /// Optional metadata associated with the request.
780    #[serde(skip_serializing_if = "Option::is_none")]
781    pub metadata: Option<HashMap<String, serde_json::Value>>,
782}
783
784/// Defines parameters for listing all push notification configurations associated with a task.
785#[derive(Debug, Clone, Serialize, Deserialize)]
786pub struct ListTaskPushNotificationConfigParams {
787    /// The unique identifier of the task.
788    pub id: String,
789    /// Optional metadata associated with the request.
790    #[serde(skip_serializing_if = "Option::is_none")]
791    pub metadata: Option<HashMap<String, serde_json::Value>>,
792}
793
794/// Defines parameters for deleting a specific push notification configuration for a task.
795#[derive(Debug, Clone, Serialize, Deserialize)]
796pub struct DeleteTaskPushNotificationConfigParams {
797    /// The unique identifier of the task.
798    pub id: String,
799    /// The ID of the push notification configuration to delete.
800    #[serde(rename = "pushNotificationConfigId")]
801    pub push_notification_config_id: String,
802    /// Optional metadata associated with the request.
803    #[serde(skip_serializing_if = "Option::is_none")]
804    pub metadata: Option<HashMap<String, serde_json::Value>>,
805}
806
807// ============================================================================
808// A2A Request Types (from schema)
809// ============================================================================
810
811fn default_jsonrpc_version() -> String {
812    "2.0".to_string()
813}
814
815/// Represents a complete A2A JSON-RPC request, wrapping the payload with common fields.
816#[derive(Debug, Clone, Serialize, Deserialize)]
817pub struct A2ARequest {
818    /// The JSON-RPC version. Always "2.0".
819    #[serde(default = "default_jsonrpc_version")]
820    pub jsonrpc: String,
821    /// The request identifier.
822    #[serde(skip_serializing_if = "Option::is_none")]
823    pub id: Option<JSONRPCId>,
824    /// The specific A2A method and its parameters.
825    #[serde(flatten)]
826    pub payload: A2ARequestPayload,
827}
828
829/// A discriminated union of all possible A2A request payloads, tagged by the `method` field.
830#[derive(Debug, Clone, Serialize, Deserialize)]
831#[serde(tag = "method")]
832pub enum A2ARequestPayload {
833    /// Payload for the `message/send` method.
834    #[serde(rename = "message/send")]
835    SendMessage { params: MessageSendParams },
836    /// Payload for the `message/stream` method.
837    #[serde(rename = "message/stream")]
838    SendStreamingMessage { params: MessageSendParams },
839    /// Payload for the `tasks/get` method.
840    #[serde(rename = "tasks/get")]
841    GetTask { params: TaskQueryParams },
842    /// Payload for the `tasks/cancel` method.
843    #[serde(rename = "tasks/cancel")]
844    CancelTask { params: TaskIdParams },
845    /// Payload for the `tasks/pushNotificationConfig/set` method.
846    #[serde(rename = "tasks/pushNotificationConfig/set")]
847    SetTaskPushNotificationConfig { params: TaskPushNotificationConfig },
848    /// Payload for the `tasks/pushNotificationConfig/get` method.
849    #[serde(rename = "tasks/pushNotificationConfig/get")]
850    GetTaskPushNotificationConfig {
851        params: GetTaskPushNotificationConfigParams,
852    },
853    /// Payload for the `tasks/resubscribe` method.
854    #[serde(rename = "tasks/resubscribe")]
855    TaskResubscription { params: TaskIdParams },
856    /// Payload for the `tasks/pushNotificationConfig/list` method.
857    #[serde(rename = "tasks/pushNotificationConfig/list")]
858    ListTaskPushNotificationConfig {
859        params: ListTaskPushNotificationConfigParams,
860    },
861    /// Payload for the `tasks/pushNotificationConfig/delete` method.
862    #[serde(rename = "tasks/pushNotificationConfig/delete")]
863    DeleteTaskPushNotificationConfig {
864        params: DeleteTaskPushNotificationConfigParams,
865    },
866    /// Payload for the `agent/getAuthenticatedExtendedCard` method.
867    #[serde(rename = "agent/getAuthenticatedExtendedCard")]
868    GetAuthenticatedExtendedCard,
869}
870
871// ============================================================================
872// A2A Response Types (from schema)
873// ============================================================================
874
875/// The result of a `message/send` call, which can be a direct reply or a task object.
876#[derive(Debug, Clone, Serialize, Deserialize)]
877#[serde(untagged)]
878pub enum SendMessageResult {
879    Task(Task),
880    Message(Message),
881}
882
883/// Represents a successful JSON-RPC response for the `message/send` method.
884#[derive(Debug, Clone, Serialize, Deserialize)]
885pub struct SendMessageSuccessResponse {
886    pub jsonrpc: String, // Always "2.0"
887    pub result: SendMessageResult,
888    pub id: Option<JSONRPCId>,
889}
890
891/// Represents a JSON-RPC response for the `message/send` method.
892#[derive(Debug, Clone, Serialize, Deserialize)]
893#[serde(untagged)]
894pub enum SendMessageResponse {
895    Success(Box<SendMessageSuccessResponse>),
896    Error(JSONRPCErrorResponse),
897}
898
899/// The result of a `message/stream` call, which can be an initial object or a streaming event.
900#[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/// Represents a successful JSON-RPC response for the `message/stream` method.
910#[derive(Debug, Clone, Serialize, Deserialize)]
911pub struct SendStreamingMessageSuccessResponse {
912    pub jsonrpc: String, // Always "2.0"
913    pub result: SendStreamingMessageResult,
914    pub id: Option<JSONRPCId>,
915}
916
917/// Represents a JSON-RPC response for the `message/stream` method.
918#[derive(Debug, Clone, Serialize, Deserialize)]
919#[serde(untagged)]
920pub enum SendStreamingMessageResponse {
921    Success(Box<SendStreamingMessageSuccessResponse>),
922    Error(JSONRPCErrorResponse),
923}
924
925/// Represents a successful JSON-RPC response for the `tasks/get` method.
926#[derive(Debug, Clone, Serialize, Deserialize)]
927pub struct GetTaskSuccessResponse {
928    pub jsonrpc: String, // Always "2.0"
929    pub result: Task,
930    pub id: Option<JSONRPCId>,
931}
932
933/// Represents a JSON-RPC response for the `tasks/get` method.
934#[derive(Debug, Clone, Serialize, Deserialize)]
935#[serde(untagged)]
936pub enum GetTaskResponse {
937    Success(Box<GetTaskSuccessResponse>),
938    Error(JSONRPCErrorResponse),
939}
940
941/// Represents a successful JSON-RPC response for the `tasks/cancel` method.
942#[derive(Debug, Clone, Serialize, Deserialize)]
943pub struct CancelTaskSuccessResponse {
944    pub jsonrpc: String, // Always "2.0"
945    pub result: Task,
946    pub id: Option<JSONRPCId>,
947}
948
949/// Represents a JSON-RPC response for the `tasks/cancel` method.
950#[derive(Debug, Clone, Serialize, Deserialize)]
951#[serde(untagged)]
952pub enum CancelTaskResponse {
953    Success(Box<CancelTaskSuccessResponse>),
954    Error(JSONRPCErrorResponse),
955}
956
957/// Represents a successful JSON-RPC response for the `tasks/pushNotificationConfig/set` method.
958#[derive(Debug, Clone, Serialize, Deserialize)]
959pub struct SetTaskPushNotificationConfigSuccessResponse {
960    pub jsonrpc: String, // Always "2.0"
961    pub result: TaskPushNotificationConfig,
962    pub id: Option<JSONRPCId>,
963}
964
965/// Represents a JSON-RPC response for the `tasks/pushNotificationConfig/set` method.
966#[derive(Debug, Clone, Serialize, Deserialize)]
967#[serde(untagged)]
968pub enum SetTaskPushNotificationConfigResponse {
969    Success(Box<SetTaskPushNotificationConfigSuccessResponse>),
970    Error(JSONRPCErrorResponse),
971}
972
973/// Represents a successful JSON-RPC response for the `tasks/pushNotificationConfig/get` method.
974#[derive(Debug, Clone, Serialize, Deserialize)]
975pub struct GetTaskPushNotificationConfigSuccessResponse {
976    pub jsonrpc: String, // Always "2.0"
977    pub result: TaskPushNotificationConfig,
978    pub id: Option<JSONRPCId>,
979}
980
981/// Represents a JSON-RPC response for the `tasks/pushNotificationConfig/get` method.
982#[derive(Debug, Clone, Serialize, Deserialize)]
983#[serde(untagged)]
984pub enum GetTaskPushNotificationConfigResponse {
985    Success(Box<GetTaskPushNotificationConfigSuccessResponse>),
986    Error(JSONRPCErrorResponse),
987}
988
989/// Represents a successful JSON-RPC response for the `tasks/pushNotificationConfig/list` method.
990#[derive(Debug, Clone, Serialize, Deserialize)]
991pub struct ListTaskPushNotificationConfigSuccessResponse {
992    pub jsonrpc: String, // Always "2.0"
993    pub result: Vec<TaskPushNotificationConfig>,
994    pub id: Option<JSONRPCId>,
995}
996
997/// Represents a JSON-RPC response for the `tasks/pushNotificationConfig/list` method.
998#[derive(Debug, Clone, Serialize, Deserialize)]
999#[serde(untagged)]
1000pub enum ListTaskPushNotificationConfigResponse {
1001    Success(Box<ListTaskPushNotificationConfigSuccessResponse>),
1002    Error(JSONRPCErrorResponse),
1003}
1004
1005/// Represents a successful JSON-RPC response for the `tasks/pushNotificationConfig/delete` method.
1006#[derive(Debug, Clone, Serialize, Deserialize)]
1007pub struct DeleteTaskPushNotificationConfigSuccessResponse {
1008    pub jsonrpc: String, // Always "2.0"
1009    /// The result is null on successful deletion.
1010    pub result: (),
1011    pub id: Option<JSONRPCId>,
1012}
1013
1014/// Represents a JSON-RPC response for the `tasks/pushNotificationConfig/delete` method.
1015#[derive(Debug, Clone, Serialize, Deserialize)]
1016#[serde(untagged)]
1017pub enum DeleteTaskPushNotificationConfigResponse {
1018    Success(Box<DeleteTaskPushNotificationConfigSuccessResponse>),
1019    Error(JSONRPCErrorResponse),
1020}
1021
1022/// Represents a successful JSON-RPC response for the `agent/getAuthenticatedExtendedCard` method.
1023#[derive(Debug, Clone, Serialize, Deserialize)]
1024pub struct GetAuthenticatedExtendedCardSuccessResponse {
1025    pub jsonrpc: String, // Always "2.0"
1026    pub result: AgentCard,
1027    pub id: Option<JSONRPCId>,
1028}
1029
1030/// Represents a JSON-RPC response for the `agent/getAuthenticatedExtendedCard` method.
1031#[derive(Debug, Clone, Serialize, Deserialize)]
1032#[serde(untagged)]
1033pub enum GetAuthenticatedExtendedCardResponse {
1034    Success(Box<GetAuthenticatedExtendedCardSuccessResponse>),
1035    Error(JSONRPCErrorResponse),
1036}
1037
1038// Constants for type values
1039pub 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// ============================================================================
1051// Security and Authentication Types (from schema)
1052// ============================================================================
1053
1054/// Defines a security scheme that can be used to secure an agent's endpoints.
1055#[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/// Defines a security scheme using an API key.
1066#[derive(Debug, Clone, Serialize, Deserialize)]
1067pub struct APIKeySecurityScheme {
1068    /// The type of the security scheme. Must be 'apiKey'.
1069    #[serde(rename = "type", default = "default_api_key_type")]
1070    pub scheme_type: String,
1071    /// The name of the header, query, or cookie parameter to be used.
1072    pub name: String,
1073    /// The location of the API key.
1074    #[serde(rename = "in")]
1075    pub location: APIKeyLocation,
1076    /// An optional description for the security scheme.
1077    #[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/// The location of an API key.
1086#[derive(Debug, Clone, Serialize, Deserialize)]
1087#[serde(rename_all = "lowercase")]
1088pub enum APIKeyLocation {
1089    Query,
1090    Header,
1091    Cookie,
1092}
1093
1094/// Defines a security scheme using HTTP authentication.
1095#[derive(Debug, Clone, Serialize, Deserialize)]
1096pub struct HTTPAuthSecurityScheme {
1097    /// The type of the security scheme. Must be 'http'.
1098    #[serde(rename = "type", default = "default_http_type")]
1099    pub scheme_type: String,
1100    /// The name of the HTTP Authentication scheme to be used.
1101    pub scheme: String,
1102    /// An optional description for the security scheme.
1103    #[serde(skip_serializing_if = "Option::is_none")]
1104    pub description: Option<String>,
1105    /// A hint to the client to identify how the bearer token is formatted.
1106    #[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/// Defines a security scheme using OAuth 2.0.
1115#[derive(Debug, Clone, Serialize, Deserialize)]
1116pub struct OAuth2SecurityScheme {
1117    /// The type of the security scheme. Must be 'oauth2'.
1118    #[serde(rename = "type", default = "default_oauth2_type")]
1119    pub scheme_type: String,
1120    /// Configuration information for the supported OAuth 2.0 flows.
1121    pub flows: OAuthFlows,
1122    /// An optional description for the security scheme.
1123    #[serde(skip_serializing_if = "Option::is_none")]
1124    pub description: Option<String>,
1125    /// URL to the oauth2 authorization server metadata.
1126    #[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/// Defines a security scheme using OpenID Connect.
1135#[derive(Debug, Clone, Serialize, Deserialize)]
1136pub struct OpenIdConnectSecurityScheme {
1137    /// The type of the security scheme. Must be 'openIdConnect'.
1138    #[serde(rename = "type", default = "default_openid_type")]
1139    pub scheme_type: String,
1140    /// The OpenID Connect Discovery URL.
1141    #[serde(rename = "openIdConnectUrl")]
1142    pub open_id_connect_url: String,
1143    /// An optional description for the security scheme.
1144    #[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/// Defines a security scheme using mTLS authentication.
1153#[derive(Debug, Clone, Serialize, Deserialize)]
1154pub struct MutualTLSSecurityScheme {
1155    /// The type of the security scheme. Must be 'mutualTLS'.
1156    #[serde(rename = "type", default = "default_mutual_tls_type")]
1157    pub scheme_type: String,
1158    /// An optional description for the security scheme.
1159    #[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/// Defines the configuration for the supported OAuth 2.0 flows.
1168#[derive(Debug, Clone, Serialize, Deserialize)]
1169pub struct OAuthFlows {
1170    /// Configuration for the OAuth Authorization Code flow.
1171    #[serde(skip_serializing_if = "Option::is_none", rename = "authorizationCode")]
1172    pub authorization_code: Option<AuthorizationCodeOAuthFlow>,
1173    /// Configuration for the OAuth Implicit flow.
1174    #[serde(skip_serializing_if = "Option::is_none")]
1175    pub implicit: Option<ImplicitOAuthFlow>,
1176    /// Configuration for the OAuth Resource Owner Password flow.
1177    #[serde(skip_serializing_if = "Option::is_none")]
1178    pub password: Option<PasswordOAuthFlow>,
1179    /// Configuration for the OAuth Client Credentials flow.
1180    #[serde(skip_serializing_if = "Option::is_none", rename = "clientCredentials")]
1181    pub client_credentials: Option<ClientCredentialsOAuthFlow>,
1182}
1183
1184/// Defines configuration details for the OAuth 2.0 Authorization Code flow.
1185#[derive(Debug, Clone, Serialize, Deserialize)]
1186pub struct AuthorizationCodeOAuthFlow {
1187    /// The authorization URL to be used for this flow.
1188    #[serde(rename = "authorizationUrl")]
1189    pub authorization_url: String,
1190    /// The token URL to be used for this flow.
1191    #[serde(rename = "tokenUrl")]
1192    pub token_url: String,
1193    /// The available scopes for the OAuth2 security scheme.
1194    pub scopes: HashMap<String, String>,
1195    /// The URL to be used for obtaining refresh tokens.
1196    #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1197    pub refresh_url: Option<String>,
1198}
1199
1200/// Defines configuration details for the OAuth 2.0 Implicit flow.
1201#[derive(Debug, Clone, Serialize, Deserialize)]
1202pub struct ImplicitOAuthFlow {
1203    /// The authorization URL to be used for this flow.
1204    #[serde(rename = "authorizationUrl")]
1205    pub authorization_url: String,
1206    /// The available scopes for the OAuth2 security scheme.
1207    pub scopes: HashMap<String, String>,
1208    /// The URL to be used for obtaining refresh tokens.
1209    #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1210    pub refresh_url: Option<String>,
1211}
1212
1213/// Defines configuration details for the OAuth 2.0 Resource Owner Password flow.
1214#[derive(Debug, Clone, Serialize, Deserialize)]
1215pub struct PasswordOAuthFlow {
1216    /// The token URL to be used for this flow.
1217    #[serde(rename = "tokenUrl")]
1218    pub token_url: String,
1219    /// The available scopes for the OAuth2 security scheme.
1220    pub scopes: HashMap<String, String>,
1221    /// The URL to be used for obtaining refresh tokens.
1222    #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1223    pub refresh_url: Option<String>,
1224}
1225
1226/// Defines configuration details for the OAuth 2.0 Client Credentials flow.
1227#[derive(Debug, Clone, Serialize, Deserialize)]
1228pub struct ClientCredentialsOAuthFlow {
1229    /// The token URL to be used for this flow.
1230    #[serde(rename = "tokenUrl")]
1231    pub token_url: String,
1232    /// The available scopes for the OAuth2 security scheme.
1233    pub scopes: HashMap<String, String>,
1234    /// The URL to be used for obtaining refresh tokens.
1235    #[serde(skip_serializing_if = "Option::is_none", rename = "refreshUrl")]
1236    pub refresh_url: Option<String>,
1237}
1238
1239// ============================================================================
1240// Convenience Types
1241// ============================================================================
1242
1243/// Main agent response type that can be either a Task or Message.
1244#[derive(Debug, Clone, Serialize, Deserialize)]
1245#[serde(untagged)]
1246pub enum AgentResponse {
1247    Task(Task),
1248    Message(Message),
1249}
1250
1251// ============================================================================
1252// Streaming Event Types (from schema)
1253// ============================================================================
1254
1255/// An event sent by the agent to notify the client of a change in a task's status.
1256#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1257pub struct TaskStatusUpdateEvent {
1258    /// The type of this event. Always "status-update".
1259    #[serde(default = "default_status_update_kind")]
1260    pub kind: String,
1261    /// The ID of the task that was updated.
1262    #[serde(rename = "taskId")]
1263    pub task_id: String,
1264    /// The context ID associated with the task.
1265    #[serde(rename = "contextId")]
1266    pub context_id: String,
1267    /// The new status of the task.
1268    pub status: TaskStatus,
1269    /// If true, this is the final event in the stream for this interaction.
1270    #[serde(rename = "final")]
1271    pub is_final: bool,
1272    /// Optional metadata for extensions.
1273    #[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/// An event sent by the agent to notify the client that an artifact has been generated or updated.
1282#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1283pub struct TaskArtifactUpdateEvent {
1284    /// The type of this event. Always "artifact-update".
1285    #[serde(default = "default_artifact_update_kind")]
1286    pub kind: String,
1287    /// The ID of the task this artifact belongs to.
1288    #[serde(rename = "taskId")]
1289    pub task_id: String,
1290    /// The context ID associated with the task.
1291    #[serde(rename = "contextId")]
1292    pub context_id: String,
1293    /// The artifact that was generated or updated.
1294    pub artifact: Artifact,
1295    /// If true, the content of this artifact should be appended to a previously sent artifact with the same ID.
1296    #[serde(skip_serializing_if = "Option::is_none")]
1297    pub append: Option<bool>,
1298    /// If true, this is the final chunk of the artifact.
1299    #[serde(skip_serializing_if = "Option::is_none", rename = "lastChunk")]
1300    pub last_chunk: Option<bool>,
1301    /// Optional metadata for extensions.
1302    #[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}