@dexwox-labs/a2a-server
Version:
TypeScript server implementation for Google's Agent-to-Agent (A2A) protocol - includes Express/WebSocket handlers, request validation and queue management
94 lines • 3.07 kB
TypeScript
/**
* @module A2AServer
* @description Server implementation for hosting A2A protocol agents
*/
import type { Request, Response, NextFunction } from 'express';
import { AgentCard } from '@dexwox-labs/a2a-core';
import { RequestHandler } from './request-handler';
/**
* Server implementation for hosting A2A protocol agents
*
* The A2AServer class provides a complete HTTP and WebSocket server implementation
* for hosting agents that implement the A2A protocol. It handles request routing,
* error handling, and WebSocket connections for streaming.
*
* @example
* ```typescript
* import { A2AServer, DefaultRequestHandler } from '@dexwox-labs/a2a-node';
*
* // Define an agent
* const agent = {
* id: 'weather-agent',
* name: 'Weather Agent',
* description: 'Provides weather information',
* capabilities: ['weather-forecasting'],
* endpoint: 'http://localhost:3000'
* };
*
* // Create a request handler
* const requestHandler = new DefaultRequestHandler([agent]);
*
* // Create and start the server
* const server = new A2AServer(agent, requestHandler);
* server.start(3000);
* ```
*/
export declare class A2AServer {
private readonly contextMiddleware?;
/** Express application instance */
private readonly app;
/** WebSocket server instance */
private wss;
/** Agent card for this server */
private readonly agentCard;
/** Handler for processing incoming requests */
private readonly requestHandler;
/**
* Creates a new A2AServer instance
*
* @param agentCard - The agent card describing this server's capabilities
* @param requestHandler - Handler for processing incoming requests
* @param contextMiddleware - Optional custom middleware for request context
*/
constructor(agentCard: AgentCard, requestHandler: RequestHandler, contextMiddleware?: ((req: Request, res: Response, next: NextFunction) => void) | undefined);
/**
* Configures Express middleware for the server
*
* Sets up JSON parsing, CORS, and request context middleware.
* @private
*/
private configureMiddleware;
/**
* Configures HTTP routes for the server
*
* Sets up the agent card endpoint and API routes.
* @private
*/
private configureRoutes;
/**
* Configures global error handling for the server
*
* Sets up middleware to catch and format errors according to the A2A protocol.
* @private
*/
private configureErrorHandling;
/**
* Starts the A2A server on the specified port
*
* This method starts both the HTTP server and WebSocket server for handling
* A2A protocol requests. The WebSocket server is used for streaming messages.
*
* @param port - The port to listen on (default: 3000)
*
* @example
* ```typescript
* // Start on the default port (3000)
* server.start();
*
* // Start on a specific port
* server.start(8080);
* ```
*/
start(port?: number): void;
}
//# sourceMappingURL=app.d.ts.map