/** * PaymentsA2AServer sets up and starts the A2A server for payments agents. * Handles A2A protocol endpoints and allows optional custom endpoints. * * The server provides a complete A2A protocol implementation with: * - JSON-RPC endpoint for A2A messages * - Agent Card endpoint (.well-known/agent-card.json, with .well-known/agent.json legacy alias) * - Bearer token extraction and validation * - Credit validation and burning * - Task execution and streaming * - Customizable routes and handlers */ import express from 'express'; import http from 'http'; import { AgentExecutor } from '@a2a-js/sdk/server'; import type { AgentCard } from './types.js'; import { PaymentsRequestHandler } from './paymentsRequestHandler.js'; /** * Options for starting the PaymentsA2AServer. * Provides comprehensive configuration for A2A server setup. */ export interface PaymentsA2AServerOptions { /** The agent card defining the agent's capabilities and metadata */ agentCard: AgentCard; /** User-implemented executor for handling A2A tasks */ executor: AgentExecutor; /** Payments service instance for credit validation and burning */ paymentsService: any; /** Port number to bind the server to */ /** Port number to listen on. Use 0 for automatic port assignment. */ port: number; /** Custom task store implementation (defaults to InMemoryTaskStore) */ taskStore?: any; /** Base path for all A2A routes (defaults to '/') */ basePath?: string; /** Whether to expose the agent card at .well-known/agent-card.json (+ legacy .well-known/agent.json alias) */ exposeAgentCard?: boolean; /** Whether to expose default A2A JSON-RPC routes */ exposeDefaultRoutes?: boolean; /** Custom Express app instance (defaults to new express()) */ expressApp?: express.Express; /** Custom request handler to override JSON-RPC method handling */ customRequestHandler?: any; /** Options for configuring the PaymentsRequestHandler behavior */ handlerOptions?: { asyncExecution?: boolean; defaultBatch?: boolean; defaultMarginPercent?: number; }; /** Hooks for intercepting requests before/after processing */ hooks?: { /** Called before processing any JSON-RPC request */ beforeRequest?: (method: string, params: any, req: express.Request) => Promise; /** Called after processing any JSON-RPC request */ afterRequest?: (method: string, result: any, req: express.Request) => Promise; /** Called when a JSON-RPC request fails */ onError?: (method: string, error: Error, req: express.Request) => Promise; }; } /** * Result returned by the server start method. * Contains the Express app and HTTP server instances for further customization. */ export interface PaymentsA2AServerResult { /** The configured Express application */ app: express.Express; /** The HTTP server instance */ server: http.Server; /** The request handler instance for direct access if needed */ handler: PaymentsRequestHandler; /** The actual port the server is listening on */ port: number; /** * Closes the server and all active connections. * @returns Promise that resolves when the server is fully closed */ close: () => Promise; } /** * PaymentsA2AServer sets up the A2A endpoints and starts the server. * * This class provides a complete A2A protocol implementation with payment integration. * It handles: * - JSON-RPC message routing * - Agent card exposure * - Bearer token extraction * - Credit validation and burning * - Task execution and streaming * - Customizable routes and handlers * * @example * ```typescript * const server = PaymentsA2AServer.start({ * agentCard: myAgentCard, * executor: new MyExecutor(), * paymentsService: payments, * port: 41242, * basePath: '/a2a/', * hooks: { * beforeRequest: async (method, params, req) => { * console.log(`Processing ${method} request`) * } * } * }) * ``` */ export declare class PaymentsA2AServer { /** * Starts the A2A server with the given options. * * This method sets up the complete A2A server infrastructure including: * - Express app configuration * - A2A route setup * - Middleware for bearer token extraction * - Agent card endpoint * - HTTP server creation and binding * * @param options - Server configuration options * @returns Server result containing app, server, adapter, and handler instances * * @example * ```typescript * const result = PaymentsA2AServer.start({ * agentCard: buildPaymentAgentCard(baseCard, paymentMetadata), * executor: new MyPaymentsExecutor(), * paymentsService: payments, * port: 41242, * basePath: '/a2a/', * exposeAgentCard: true, * exposeDefaultRoutes: true * }) * * // Access the Express app for additional routes * result.app.get('/health', (req, res) => res.json({ status: 'ok' })) * ``` */ static start(options: PaymentsA2AServerOptions): PaymentsA2AServerResult; } //# sourceMappingURL=server.d.ts.map