Skip to main content

a2a_ap2/
lib.rs

1//! # a2a-ap2 — Agent Payments Protocol extension for A2A
2//!
3//! This crate implements the [AP2 (Agent Payments Protocol) v0.1](https://ap2-protocol.org/)
4//! as a companion library to [`a2a-rs`]. It provides:
5//!
6//! - Strongly-typed Rust models for all AP2 types (mandates, payment requests,
7//!   receipts, roles)
8//! - Helpers for embedding AP2 data into A2A `Message` and `Artifact` parts
9//! - Helpers for extracting AP2 data from A2A parts
10//! - `AgentExtension` builders for declaring AP2 support in `AgentCard`s
11//! - Validation for all AP2 types
12//!
13//! ## Quick Start
14//!
15//! ```rust
16//! use a2a_ap2::{
17//!     IntentMandate, intent_mandate_message,
18//!     ap2_extension, Ap2Role,
19//! };
20//!
21//! // Declare AP2 support in an agent card
22//! let ext = ap2_extension(vec![Ap2Role::Shopper], false);
23//!
24//! // Create an intent mandate and wrap it in an A2A message
25//! let intent = IntentMandate {
26//!     user_cart_confirmation_required: true,
27//!     natural_language_description: "Buy red shoes under $100".into(),
28//!     merchants: None,
29//!     skus: None,
30//!     requires_refundability: Some(true),
31//!     intent_expiry: "2026-12-31T23:59:59Z".into(),
32//! };
33//! let message = intent_mandate_message(&intent, "msg-1".into()).unwrap();
34//! ```
35
36pub mod error;
37pub mod extension;
38pub mod helpers;
39pub mod types;
40pub mod validation;
41
42// Re-export types at crate root for convenience.
43pub use error::{Ap2Error, Result};
44
45pub use types::{
46    // Constants
47    AP2_EXTENSION_URI,
48    Ap2Role,
49    CART_MANDATE_DATA_KEY,
50    CartContents,
51    CartMandate,
52    ContactAddress,
53    // Receipt variant structs
54    Error,
55    Failure,
56    INTENT_MANDATE_DATA_KEY,
57    IntentMandate,
58    PAYMENT_MANDATE_DATA_KEY,
59    PAYMENT_RECEIPT_DATA_KEY,
60    PaymentCurrencyAmount,
61    PaymentDetailsInit,
62    PaymentDetailsModifier,
63    PaymentItem,
64    PaymentMandate,
65    PaymentMandateContents,
66    PaymentMethodData,
67    PaymentOptions,
68    PaymentReceipt,
69    PaymentRequest,
70    PaymentResponse,
71    PaymentShippingOption,
72    PaymentStatus,
73    RISK_DATA_KEY,
74    Success,
75};
76
77pub use helpers::{
78    cart_mandate_artifact, cart_mandate_to_part, extract_cart_mandate, extract_intent_mandate,
79    extract_payment_mandate, extract_payment_receipt, find_cart_mandate, find_intent_mandate,
80    find_payment_mandate, find_payment_receipt_in_parts, intent_mandate_message,
81    intent_mandate_to_part, payment_mandate_message, payment_mandate_to_part,
82    payment_receipt_to_part, risk_data_to_part,
83};
84
85pub use extension::{ap2_extension, get_ap2_roles, has_ap2_role, supports_ap2, with_ap2};
86
87pub use validation::Validate;