1#![deny(missing_docs)]
29#![deny(unsafe_op_in_unsafe_fn)]
30#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
31#![allow(clippy::module_name_repetitions)]
32
33pub const A2A_VERSION: &str = "1.0.0";
37
38pub const A2A_CONTENT_TYPE: &str = "application/a2a+json";
40
41pub const A2A_VERSION_HEADER: &str = "A2A-Version";
43
44pub mod agent_card;
45pub mod artifact;
46pub mod error;
47pub mod events;
48pub mod extensions;
49pub mod jsonrpc;
50pub mod message;
51pub mod params;
52pub mod push;
53pub mod responses;
54pub mod security;
55#[cfg(feature = "signing")]
56pub mod signing;
57pub mod task;
58
59pub use agent_card::{AgentCapabilities, AgentCard, AgentInterface, AgentProvider, AgentSkill};
62pub use artifact::{Artifact, ArtifactId};
63pub use error::{A2aError, A2aResult, ErrorCode};
64pub use events::{StreamResponse, TaskArtifactUpdateEvent, TaskStatusUpdateEvent};
65pub use extensions::{AgentCardSignature, AgentExtension};
66pub use jsonrpc::{
67 JsonRpcError, JsonRpcErrorResponse, JsonRpcId, JsonRpcRequest, JsonRpcResponse,
68 JsonRpcSuccessResponse, JsonRpcVersion,
69};
70pub use message::{FileContent, Message, MessageId, MessageRole, Part, PartContent};
71pub use params::{
72 CancelTaskParams, DeletePushConfigParams, GetExtendedAgentCardParams, GetPushConfigParams,
73 ListPushConfigsParams, ListTasksParams, MessageSendParams, SendMessageConfiguration,
74 TaskIdParams, TaskQueryParams,
75};
76pub use push::{AuthenticationInfo, TaskPushNotificationConfig};
77pub use responses::{
78 AuthenticatedExtendedCardResponse, ListPushConfigsResponse, SendMessageResponse,
79 TaskListResponse,
80};
81pub use security::{
82 ApiKeyLocation, ApiKeySecurityScheme, AuthorizationCodeFlow, ClientCredentialsFlow,
83 DeviceCodeFlow, HttpAuthSecurityScheme, ImplicitFlow, MutualTlsSecurityScheme,
84 NamedSecuritySchemes, OAuth2SecurityScheme, OAuthFlows, OpenIdConnectSecurityScheme,
85 PasswordOAuthFlow, SecurityRequirement, SecurityScheme, StringList,
86};
87pub use task::{ContextId, Task, TaskId, TaskState, TaskStatus, TaskVersion};
88
89#[must_use]
95pub fn utc_now_iso8601() -> String {
96 use std::time::{SystemTime, UNIX_EPOCH};
97 let secs = SystemTime::now()
98 .duration_since(UNIX_EPOCH)
99 .unwrap_or_default()
100 .as_secs();
101 let (y, m, d, hh, mm, ss) = secs_to_ymd_hms(secs);
103 format!("{y:04}-{m:02}-{d:02}T{hh:02}:{mm:02}:{ss:02}Z")
104}
105
106const fn secs_to_ymd_hms(epoch: u64) -> (u64, u64, u64, u64, u64, u64) {
108 let secs_per_day = 86400_u64;
109 let mut days = epoch / secs_per_day;
110 let time_of_day = epoch % secs_per_day;
111 let hh = time_of_day / 3600;
112 let mm = (time_of_day % 3600) / 60;
113 let ss = time_of_day % 60;
114
115 days += 719_468;
118 let era = days / 146_097;
119 let doe = days - era * 146_097;
120 let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146_096) / 365;
121 let y = yoe + era * 400;
122 let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
123 let mp = (5 * doy + 2) / 153;
124 let d = doy - (153 * mp + 2) / 5 + 1;
125 let m = if mp < 10 { mp + 3 } else { mp - 9 };
126 let y = if m <= 2 { y + 1 } else { y };
127 (y, m, d, hh, mm, ss)
128}
129
130#[cfg(test)]
131mod tests {
132 use super::secs_to_ymd_hms;
133
134 #[test]
139 fn epoch_zero() {
140 assert_eq!(secs_to_ymd_hms(0), (1970, 1, 1, 0, 0, 0));
141 }
142
143 #[test]
145 fn time_of_day_decomposition() {
146 assert_eq!(secs_to_ymd_hms(3723), (1970, 1, 1, 1, 2, 3));
148 assert_eq!(secs_to_ymd_hms(86399), (1970, 1, 1, 23, 59, 59));
150 }
151
152 #[test]
154 fn day_boundary() {
155 assert_eq!(secs_to_ymd_hms(86400), (1970, 1, 2, 0, 0, 0));
157 }
158
159 #[test]
161 fn known_date_2000_01_01() {
162 assert_eq!(secs_to_ymd_hms(946_684_800), (2000, 1, 1, 0, 0, 0));
164 }
165
166 #[test]
167 fn known_date_leap_day_2000() {
168 assert_eq!(secs_to_ymd_hms(951_782_400), (2000, 2, 29, 0, 0, 0));
170 }
171
172 #[test]
173 fn known_date_2024_02_29() {
174 assert_eq!(secs_to_ymd_hms(1_709_164_800), (2024, 2, 29, 0, 0, 0));
176 }
177
178 #[test]
179 fn known_date_2024_03_01() {
180 assert_eq!(secs_to_ymd_hms(1_709_251_200), (2024, 3, 1, 0, 0, 0));
182 }
183
184 #[test]
186 fn january_february_year_adjustment() {
187 assert_eq!(secs_to_ymd_hms(1_767_225_600), (2026, 1, 1, 0, 0, 0));
189 assert_eq!(secs_to_ymd_hms(1_772_236_800), (2026, 2, 28, 0, 0, 0));
191 }
192
193 #[test]
195 fn march_mp_boundary() {
196 assert_eq!(secs_to_ymd_hms(1_772_323_200), (2026, 3, 1, 0, 0, 0));
198 assert_eq!(secs_to_ymd_hms(1_767_225_599), (2025, 12, 31, 23, 59, 59));
200 }
201
202 #[test]
204 fn era_boundary_1600() {
205 assert_eq!(secs_to_ymd_hms(978_307_200), (2001, 1, 1, 0, 0, 0));
208 }
209
210 #[test]
212 fn non_leap_century() {
213 assert_eq!(secs_to_ymd_hms(5_097_600), (1970, 3, 1, 0, 0, 0));
215 }
216
217 #[test]
219 fn full_timestamp_2026_03_15() {
220 assert_eq!(secs_to_ymd_hms(1_773_585_045), (2026, 3, 15, 14, 30, 45));
222 }
223
224 #[test]
226 fn end_of_year() {
227 assert_eq!(secs_to_ymd_hms(1_767_139_200), (2025, 12, 31, 0, 0, 0));
229 }
230
231 #[test]
233 fn mid_year_date() {
234 assert_eq!(secs_to_ymd_hms(1_686_830_400), (2023, 6, 15, 12, 0, 0));
236 }
237}