Skip to main content

Crate a2a_ap2

Crate a2a_ap2 

Source
Expand description

§a2a-ap2 — Agent Payments Protocol extension for A2A

This crate implements the AP2 (Agent Payments Protocol) v0.1 as a companion library to [a2a-rs]. It provides:

  • Strongly-typed Rust models for all AP2 types (mandates, payment requests, receipts, roles)
  • Helpers for embedding AP2 data into A2A Message and Artifact parts
  • Helpers for extracting AP2 data from A2A parts
  • AgentExtension builders for declaring AP2 support in AgentCards
  • Validation for all AP2 types

§Quick Start

use a2a_ap2::{
    IntentMandate, intent_mandate_message,
    ap2_extension, Ap2Role,
};

// Declare AP2 support in an agent card
let ext = ap2_extension(vec![Ap2Role::Shopper], false);

// Create an intent mandate and wrap it in an A2A message
let intent = IntentMandate {
    user_cart_confirmation_required: true,
    natural_language_description: "Buy red shoes under $100".into(),
    merchants: None,
    skus: None,
    requires_refundability: Some(true),
    intent_expiry: "2026-12-31T23:59:59Z".into(),
};
let message = intent_mandate_message(&intent, "msg-1".into()).unwrap();

Re-exports§

pub use error::Ap2Error;
pub use error::Result;
pub use types::AP2_EXTENSION_URI;
pub use types::Ap2Role;
pub use types::CART_MANDATE_DATA_KEY;
pub use types::CartContents;
pub use types::CartMandate;
pub use types::ContactAddress;
pub use types::Error;
pub use types::Failure;
pub use types::INTENT_MANDATE_DATA_KEY;
pub use types::IntentMandate;
pub use types::PAYMENT_MANDATE_DATA_KEY;
pub use types::PAYMENT_RECEIPT_DATA_KEY;
pub use types::PaymentCurrencyAmount;
pub use types::PaymentDetailsInit;
pub use types::PaymentDetailsModifier;
pub use types::PaymentItem;
pub use types::PaymentMandate;
pub use types::PaymentMandateContents;
pub use types::PaymentMethodData;
pub use types::PaymentOptions;
pub use types::PaymentReceipt;
pub use types::PaymentRequest;
pub use types::PaymentResponse;
pub use types::PaymentShippingOption;
pub use types::PaymentStatus;
pub use types::RISK_DATA_KEY;
pub use types::Success;
pub use helpers::cart_mandate_artifact;
pub use helpers::cart_mandate_to_part;
pub use helpers::extract_cart_mandate;
pub use helpers::extract_intent_mandate;
pub use helpers::extract_payment_mandate;
pub use helpers::extract_payment_receipt;
pub use helpers::find_cart_mandate;
pub use helpers::find_intent_mandate;
pub use helpers::find_payment_mandate;
pub use helpers::find_payment_receipt_in_parts;
pub use helpers::intent_mandate_message;
pub use helpers::intent_mandate_to_part;
pub use helpers::payment_mandate_message;
pub use helpers::payment_mandate_to_part;
pub use helpers::payment_receipt_to_part;
pub use helpers::risk_data_to_part;
pub use extension::ap2_extension;
pub use extension::get_ap2_roles;
pub use extension::has_ap2_role;
pub use extension::supports_ap2;
pub use extension::with_ap2;
pub use validation::Validate;

Modules§

error
extension
Helpers for declaring AP2 support in an A2A AgentCard.
helpers
Helpers for embedding and extracting AP2 types in A2A protocol messages.
types
validation
Validation for AP2 types.