#![deny(missing_docs)]
#![deny(unsafe_op_in_unsafe_fn)]
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(clippy::module_name_repetitions)]
pub const A2A_VERSION: &str = "1.0.0";
pub const A2A_CONTENT_TYPE: &str = "application/a2a+json";
pub const A2A_VERSION_HEADER: &str = "A2A-Version";
pub mod agent_card;
pub mod artifact;
pub mod error;
pub mod events;
pub mod extensions;
pub mod jsonrpc;
pub mod message;
pub mod params;
pub mod push;
pub mod responses;
pub mod security;
pub mod serde_helpers;
#[cfg(feature = "signing")]
pub mod signing;
pub mod task;
pub use agent_card::{AgentCapabilities, AgentCard, AgentInterface, AgentProvider, AgentSkill};
pub use artifact::{Artifact, ArtifactId};
pub use error::{A2aError, A2aResult, ErrorCode};
pub use events::{StreamResponse, TaskArtifactUpdateEvent, TaskStatusUpdateEvent};
pub use extensions::{AgentCardSignature, AgentExtension};
pub use jsonrpc::{
JsonRpcError, JsonRpcErrorResponse, JsonRpcId, JsonRpcRequest, JsonRpcResponse,
JsonRpcSuccessResponse, JsonRpcVersion,
};
pub use message::{FileContent, Message, MessageId, MessageRole, Part, PartContent};
pub use params::{
CancelTaskParams, DeletePushConfigParams, GetExtendedAgentCardParams, GetPushConfigParams,
ListPushConfigsParams, ListTasksParams, MessageSendParams, SendMessageConfiguration,
TaskIdParams, TaskQueryParams,
};
pub use push::{AuthenticationInfo, TaskPushNotificationConfig};
pub use responses::{
AuthenticatedExtendedCardResponse, ListPushConfigsResponse, SendMessageResponse,
TaskListResponse,
};
pub use security::{
ApiKeyLocation, ApiKeySecurityScheme, AuthorizationCodeFlow, ClientCredentialsFlow,
DeviceCodeFlow, HttpAuthSecurityScheme, ImplicitFlow, MutualTlsSecurityScheme,
NamedSecuritySchemes, OAuth2SecurityScheme, OAuthFlows, OpenIdConnectSecurityScheme,
PasswordOAuthFlow, SecurityRequirement, SecurityScheme, StringList,
};
pub use serde_helpers::{deser_from_slice, deser_from_str, SerBuffer};
pub use task::{ContextId, Task, TaskId, TaskState, TaskStatus, TaskVersion};
#[must_use]
pub fn utc_now_iso8601() -> String {
use std::time::{SystemTime, UNIX_EPOCH};
let secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
let (y, m, d, hh, mm, ss) = secs_to_ymd_hms(secs);
format!("{y:04}-{m:02}-{d:02}T{hh:02}:{mm:02}:{ss:02}Z")
}
const fn secs_to_ymd_hms(epoch: u64) -> (u64, u64, u64, u64, u64, u64) {
let secs_per_day = 86400_u64;
let mut days = epoch / secs_per_day;
let time_of_day = epoch % secs_per_day;
let hh = time_of_day / 3600;
let mm = (time_of_day % 3600) / 60;
let ss = time_of_day % 60;
days += 719_468;
let era = days / 146_097;
let doe = days - era * 146_097;
let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146_096) / 365;
let y = yoe + era * 400;
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
let mp = (5 * doy + 2) / 153;
let d = doy - (153 * mp + 2) / 5 + 1;
let m = if mp < 10 { mp + 3 } else { mp - 9 };
let y = if m <= 2 { y + 1 } else { y };
(y, m, d, hh, mm, ss)
}
#[cfg(test)]
mod tests {
use super::secs_to_ymd_hms;
#[test]
fn epoch_zero() {
assert_eq!(secs_to_ymd_hms(0), (1970, 1, 1, 0, 0, 0));
}
#[test]
fn time_of_day_decomposition() {
assert_eq!(secs_to_ymd_hms(3723), (1970, 1, 1, 1, 2, 3));
assert_eq!(secs_to_ymd_hms(86399), (1970, 1, 1, 23, 59, 59));
}
#[test]
fn day_boundary() {
assert_eq!(secs_to_ymd_hms(86400), (1970, 1, 2, 0, 0, 0));
}
#[test]
fn known_date_2000_01_01() {
assert_eq!(secs_to_ymd_hms(946_684_800), (2000, 1, 1, 0, 0, 0));
}
#[test]
fn known_date_leap_day_2000() {
assert_eq!(secs_to_ymd_hms(951_782_400), (2000, 2, 29, 0, 0, 0));
}
#[test]
fn known_date_2024_02_29() {
assert_eq!(secs_to_ymd_hms(1_709_164_800), (2024, 2, 29, 0, 0, 0));
}
#[test]
fn known_date_2024_03_01() {
assert_eq!(secs_to_ymd_hms(1_709_251_200), (2024, 3, 1, 0, 0, 0));
}
#[test]
fn january_february_year_adjustment() {
assert_eq!(secs_to_ymd_hms(1_767_225_600), (2026, 1, 1, 0, 0, 0));
assert_eq!(secs_to_ymd_hms(1_772_236_800), (2026, 2, 28, 0, 0, 0));
}
#[test]
fn march_mp_boundary() {
assert_eq!(secs_to_ymd_hms(1_772_323_200), (2026, 3, 1, 0, 0, 0));
assert_eq!(secs_to_ymd_hms(1_767_225_599), (2025, 12, 31, 23, 59, 59));
}
#[test]
fn era_boundary_1600() {
assert_eq!(secs_to_ymd_hms(978_307_200), (2001, 1, 1, 0, 0, 0));
}
#[test]
fn non_leap_century() {
assert_eq!(secs_to_ymd_hms(5_097_600), (1970, 3, 1, 0, 0, 0));
}
#[test]
fn full_timestamp_2026_03_15() {
assert_eq!(secs_to_ymd_hms(1_773_585_045), (2026, 3, 15, 14, 30, 45));
}
#[test]
fn end_of_year() {
assert_eq!(secs_to_ymd_hms(1_767_139_200), (2025, 12, 31, 0, 0, 0));
}
#[test]
fn mid_year_date() {
assert_eq!(secs_to_ymd_hms(1_686_830_400), (2023, 6, 15, 12, 0, 0));
}
}