ap2-protocol-js

Independent TypeScript implementation of the Agent Payments Protocol (AP2): SD-JWT mandate delegation chains, receipts, and constraint evaluation. Community project; not affiliated with or endorsed by Google.


Keywords
ap2, agent-payments-protocol, sd-jwt, mandate, payments, agent, authorization, verification, commerce, a2a, adk, agents, typescript
License
Apache-2.0
Install
npm install ap2-protocol-js@0.1.0

Documentation

ap2-js

JavaScript/TypeScript samples for the Agent Payments Protocol (AP2), built on the Agent Development Kit (ADK) and the A2A SDK.

Available Scenarios

See the scenario README for detailed setup and usage instructions.

Why TypeScript for AP2 Agents?

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/sdk and @google/adk packages.
  • Portability: Run on any Node.js 20+ runtime, including serverless and container platforms.

Project Structure

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

Development

# 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 test

See the scenario README for a full walkthrough.