Skip to main content

a2a_rust/types/
mod.rs

1//! Core A2A protocol types.
2
3use base64::Engine as _;
4use serde::{Deserialize, Deserializer, Serializer};
5
6/// Agent discovery and capability types.
7pub mod agent_card;
8/// Validated helper type for application-level agent identifiers.
9pub mod agent_id;
10/// Auth-required metadata helpers and conventions.
11pub mod auth;
12/// Messages, parts, and artifacts exchanged by agents.
13pub mod message;
14/// Push-notification configuration types.
15pub mod push;
16/// Operation request payloads.
17pub mod requests;
18/// Operation response payloads and stream events.
19pub mod responses;
20/// Security scheme and requirement types.
21pub mod security;
22/// Task state and status models.
23pub mod task;
24
25pub use self::agent_card::*;
26pub use self::agent_id::*;
27pub use self::auth::*;
28pub use self::message::*;
29pub use self::push::*;
30pub use self::requests::*;
31pub use self::responses::*;
32pub use self::security::*;
33pub use self::task::*;
34
35/// Shared JSON object alias used across metadata-bearing protocol types.
36pub type JsonObject = serde_json::Map<String, serde_json::Value>;
37
38pub(crate) fn is_false(value: &bool) -> bool {
39    !*value
40}
41
42pub(crate) mod base64_bytes {
43    use super::*;
44
45    const ENGINE: base64::engine::GeneralPurpose = base64::engine::general_purpose::STANDARD;
46
47    pub(crate) mod option {
48        use super::*;
49
50        pub fn serialize<S>(value: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
51        where
52            S: Serializer,
53        {
54            match value {
55                Some(bytes) => serializer.serialize_some(&ENGINE.encode(bytes)),
56                None => serializer.serialize_none(),
57            }
58        }
59
60        pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
61        where
62            D: Deserializer<'de>,
63        {
64            let encoded = Option::<String>::deserialize(deserializer)?;
65            encoded
66                .map(|encoded| ENGINE.decode(encoded).map_err(serde::de::Error::custom))
67                .transpose()
68        }
69    }
70}