import { A as A2ARequestHandler, S as ServerCallContext } from './a2a_request_handler-BuP9LgXH.js'; import { c as WebHandlerOptions, A as AgentCardProvider, W as WebRequest, a as WebResponse } from './types-Br-FXCQW.js'; import { L as Logger } from './logger-B5whDJNa.js'; /** * A2A Route Definitions * * This module exports the canonical route definitions for the A2A protocol. * These can be used by any adapter to set up routing consistently. */ /** * HTTP methods supported by A2A routes. */ type HttpMethod = 'GET' | 'POST' | 'DELETE'; /** * HTTP status codes used by A2A. */ declare const HTTP_STATUS: { readonly OK: 200; readonly CREATED: 201; readonly ACCEPTED: 202; readonly NO_CONTENT: 204; readonly BAD_REQUEST: 400; readonly UNAUTHORIZED: 401; readonly FORBIDDEN: 403; readonly NOT_FOUND: 404; readonly CONFLICT: 409; readonly INTERNAL_SERVER_ERROR: 500; readonly NOT_IMPLEMENTED: 501; }; /** * Type for HTTP status code values. */ type HttpStatusCode = (typeof HTTP_STATUS)[keyof typeof HTTP_STATUS]; /** * Route pattern string type. * Patterns use :param for path parameters (e.g., '/v1/tasks/:taskId'). */ type RoutePattern = string; /** * A2A route definition. * Framework-agnostic description of an A2A endpoint. */ interface A2ARouteDefinition { /** HTTP method */ readonly method: HttpMethod; /** Route pattern with :param placeholders (e.g., '/v1/tasks/:taskId') */ readonly pattern: RoutePattern; /** Human-readable description */ readonly description: string; /** Expected HTTP status code on success */ readonly successStatus: HttpStatusCode; /** Whether this route returns an SSE stream */ readonly isStreaming: TStreaming; } /** * Streaming route definition (isStreaming: true). */ type StreamingRoute = A2ARouteDefinition; /** * Non-streaming route definition (isStreaming: false). */ type NonStreamingRoute = A2ARouteDefinition; /** * REST API route definitions. * These define the canonical A2A REST endpoints. */ declare const REST_ROUTES: readonly [{ readonly method: "GET"; readonly pattern: "/v1/card"; readonly description: "Get authenticated extended agent card"; readonly successStatus: 200; readonly isStreaming: false; }, { readonly method: "POST"; readonly pattern: "/v1/message:send"; readonly description: "Send a message synchronously"; readonly successStatus: 201; readonly isStreaming: false; }, { readonly method: "POST"; readonly pattern: "/v1/message:stream"; readonly description: "Send a message with streaming response"; readonly successStatus: 200; readonly isStreaming: true; }, { readonly method: "GET"; readonly pattern: "/v1/tasks/:taskId"; readonly description: "Get task status and details"; readonly successStatus: 200; readonly isStreaming: false; }, { readonly method: "POST"; readonly pattern: "/v1/tasks/:taskId:cancel"; readonly description: "Cancel a task"; readonly successStatus: 202; readonly isStreaming: false; }, { readonly method: "POST"; readonly pattern: "/v1/tasks/:taskId:subscribe"; readonly description: "Subscribe to task updates via SSE"; readonly successStatus: 200; readonly isStreaming: true; }, { readonly method: "POST"; readonly pattern: "/v1/tasks/:taskId/pushNotificationConfigs"; readonly description: "Create push notification config"; readonly successStatus: 201; readonly isStreaming: false; }, { readonly method: "GET"; readonly pattern: "/v1/tasks/:taskId/pushNotificationConfigs"; readonly description: "List push notification configs"; readonly successStatus: 200; readonly isStreaming: false; }, { readonly method: "GET"; readonly pattern: "/v1/tasks/:taskId/pushNotificationConfigs/:configId"; readonly description: "Get push notification config"; readonly successStatus: 200; readonly isStreaming: false; }, { readonly method: "DELETE"; readonly pattern: "/v1/tasks/:taskId/pushNotificationConfigs/:configId"; readonly description: "Delete push notification config"; readonly successStatus: 204; readonly isStreaming: false; }]; /** * Agent card route definition. */ declare const AGENT_CARD_ROUTE: A2ARouteDefinition; /** * JSON-RPC route definition. */ declare const JSON_RPC_ROUTE: A2ARouteDefinition; /** * Converts an A2A route pattern to Express format. * Express uses backslash to escape colons in route patterns. * * @example * toExpressPattern('/v1/message:send') // '/v1/message\\:send' * toExpressPattern('/v1/tasks/:taskId') // '/v1/tasks/:taskId' */ declare function toExpressPattern(pattern: string): string; /** * Converts an A2A route pattern to a regex for matching. * Captures named parameters. * * @example * toRegex('/v1/tasks/:taskId').exec('/v1/tasks/abc123') * // { groups: { taskId: 'abc123' } } */ declare function toRegex(pattern: string): RegExp; /** * Extracts path parameters from a URL using a route pattern. * * @example * extractParams('/v1/tasks/:taskId', '/v1/tasks/abc123') * // { taskId: 'abc123' } */ declare function extractParams(pattern: string, path: string): Record | null; /** * Checks if a path matches a route pattern. */ declare function matchesPattern(pattern: string, path: string): boolean; /** * Prepends a base path to a route pattern. * * @example * withBasePath('/api', '/v1/tasks/:taskId') // '/api/v1/tasks/:taskId' */ declare function withBasePath(basePath: string, pattern: string): string; /** * Web-Standard Base Handlers for A2A Server * * These handlers implement the A2A protocol using only web-standard APIs. * They can be used directly or wrapped by framework-specific adapters. * * This module uses the shared logic from: * - transports/jsonrpc/json_rpc_logic.ts - JSON-RPC processing * - request_handler/agent_card_utils.ts - Agent card handling * - error.ts - Error formatting * - sse_utils.ts - SSE event formatting */ /** * Options for the agent card handler. */ interface AgentCardHandlerOptions extends WebHandlerOptions { /** * Provider for agent card data. * Can be an A2ARequestHandler, an object with getAgentCard(), or a function. */ agentCardProvider?: AgentCardProvider; } /** * Creates a web-standard handler for the agent card endpoint. * * Uses shared fetchAgentCard() logic from request_handler/agent_card_utils.ts. */ declare function createAgentCardHandler(requestHandler: A2ARequestHandler, options?: AgentCardHandlerOptions): (request: WebRequest) => Promise; /** * Creates a web-standard handler for JSON-RPC requests. * * Uses shared processJsonRpc() logic from transports/jsonrpc/json_rpc_logic.ts. */ declare function createJsonRpcHandler(requestHandler: A2ARequestHandler, options?: WebHandlerOptions): (request: WebRequest) => Promise; /** * REST route definition. */ interface RestRoute { method: 'GET' | 'POST' | 'DELETE'; pattern: string; handler: (request: WebRequest, params: Record, context: ServerCallContext, logger: Logger) => Promise; } /** * Creates web-standard handlers for REST API endpoints. * * Uses shared error formatting from error.ts. */ declare function createRestHandlers(requestHandler: A2ARequestHandler, options?: WebHandlerOptions): { routes: RestRoute[]; handleRequest: (request: WebRequest, pathname: string) => Promise; }; /** * Configuration for the combined A2A handler. */ interface A2AHandlerConfig extends WebHandlerOptions { /** Path for agent card endpoint (default: '/.well-known/agent-card.json') */ agentCardPath?: string; /** Path for JSON-RPC endpoint (default: '/') */ jsonRpcPath?: string; /** Path prefix for REST endpoints (default: '') */ restBasePath?: string; } /** * Creates a combined handler that routes to agent card, JSON-RPC, or REST handlers. * This is the main entry point for framework adapters. */ declare function createA2AHandler(requestHandler: A2ARequestHandler, config?: A2AHandlerConfig): (request: WebRequest) => Promise; export { type A2ARouteDefinition as A, type HttpMethod as H, JSON_RPC_ROUTE as J, type NonStreamingRoute as N, type RoutePattern as R, type StreamingRoute as S, type HttpStatusCode as a, REST_ROUTES as b, AGENT_CARD_ROUTE as c, HTTP_STATUS as d, toRegex as e, extractParams as f, createAgentCardHandler as g, createJsonRpcHandler as h, createRestHandlers as i, createA2AHandler as j, type AgentCardHandlerOptions as k, type A2AHandlerConfig as l, matchesPattern as m, toExpressPattern as t, withBasePath as w };