JavaScript/TypeScript samples for the Agent Payments Protocol (AP2), built on the Agent Development Kit (ADK) and the A2A SDK.
-
Human-Present Card Payment
- Complete card payment flow with all four agents implemented in TypeScript.
See the scenario README for detailed setup and usage instructions.
TypeScript is a natural fit for AP2 agents that are deployed alongside web, Node.js, or edge runtimes:
- Type Safety: Compile-time validation of protocol structures via Zod schemas mirrored from the AP2 reference types.
-
Ecosystem: Direct access to the npm ecosystem and the
@a2a-js/sdkand@google/adkpackages. - Portability: Run on any Node.js 20+ runtime, including serverless and container platforms.
ap2-js/
└── src/
├── roles/ # Agent role implementations and entry points
│ ├── shopping/ # Shopping Agent (root orchestrator)
│ │ └── subagents/ # shopper, shipping-collector, payment-collector
│ ├── merchant/ # Merchant Agent
│ ├── credentials-provider/
│ └── payment-processor/
├── common/ # Shared modules used across roles
│ ├── server/ # A2A server bootstrap, executor, middleware
│ ├── utils/ # Message and artifact helpers
│ ├── types/ # AP2 protocol object types
│ ├── schemas/ # Zod schemas mirroring the protocol
│ ├── vc/ # W3C Verifiable Credential helpers
│ ├── config/ # Session and runtime configuration
│ └── constants/ # Shared constants
├── test/
│ └── e2e/ # End-to-end smoke tests
└── scenarios/
└── a2a/
└── human-present/
└── cards/ # Card payment scenario
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# fill in the required values in .env
# Type-check and build
npm run build
# Start all four agents plus the ADK web UI
npm run dev
# Run the e2e smoke tests against running agents
npm testSee the scenario README for a full walkthrough.