/** * A2A Server — expose Network-AI as a Google A2A (Agent2Agent) agent. * * The `A2AAdapter` (adapters/a2a-adapter.ts) lets this orchestrator *call* * remote A2A agents. This module is the other direction: `A2AServer` serves * an Agent Card at `/.well-known/agent.json` and accepts `tasks/send` * JSON-RPC envelopes, so any A2A-speaking framework (Google ADK, Gemini * agents, LangGraph A2A clients, …) can discover this orchestrator and hand * it tasks. * * Incoming task text is delegated to a pluggable executor — typically a * closure over `AdapterRegistry.executeAgent()` or * `SwarmOrchestrator.delegateTask()`. * * Security posture mirrors `ApprovalInbox`: * - binds to 127.0.0.1 by default; * - optional Bearer `secret` gates the task routes (the Agent Card remains * public — it is the A2A discovery document); * - request bodies are size-capped; unknown methods are rejected. * * @example * ```ts * const server = new A2AServer({ * name: 'Network-AI Orchestrator', * description: 'Multi-agent swarm coordinator', * secret: process.env.A2A_SECRET, * executor: async (text) => { * const result = await registry.executeAgent('custom:solver', { * action: 'solve', params: { text }, * }, { agentId: 'a2a-server', taskId: 'a2a' }); * return { text: JSON.stringify(result.data) }; * }, * }); * server.startServer(4310); * ``` * * @module A2AServer * @version 1.0.0 */ import { type IncomingMessage, type Server, type ServerResponse } from 'http'; /** Task lifecycle states (A2A spec §4) */ export type A2AServerTaskState = 'submitted' | 'working' | 'completed' | 'canceled' | 'failed'; /** Executor invoked for every incoming `tasks/send` */ export type A2ATaskExecutor = (text: string, metadata: Record | undefined) => Promise<{ text?: string; data?: unknown; }>; /** A stored task record */ export interface A2AServerTask { /** Task id (client-supplied or generated) */ id: string; /** Current lifecycle state */ state: A2AServerTaskState; /** The incoming message text */ input: string; /** Output artifact text (present when completed) */ output?: string; /** Failure/cancel message */ message?: string; /** Creation timestamp (epoch ms) */ createdAt: number; /** Resolution timestamp (epoch ms) */ resolvedAt?: number; } /** Options for the A2AServer */ export interface A2AServerOptions { /** Agent name shown on the Agent Card */ name: string; /** Agent description shown on the Agent Card */ description?: string; /** Agent version shown on the Agent Card (default: '1.0.0') */ version?: string; /** Public URL of this agent (advertised on the card) */ url?: string; /** * Bearer token required on the task routes when set. The Agent Card at * /.well-known/agent.json stays public — it is the discovery document. */ secret?: string; /** Executor that fulfils incoming tasks (required) */ executor: A2ATaskExecutor; /** Maximum stored task records (default: 1000, oldest evicted first) */ maxHistory?: number; /** Maximum request body size in bytes (default: 1 MiB) */ maxBodyBytes?: number; } /** * Minimal, dependency-free A2A protocol server: Agent Card discovery plus * `tasks/send`, `tasks/get`, and `tasks/cancel` over JSON-RPC 2.0. */ export declare class A2AServer { private readonly options; private readonly tasks; constructor(options: A2AServerOptions); /** Build the Agent Card served at /.well-known/agent.json */ agentCard(): Record; /** Get a stored task by id */ getTask(id: string): A2AServerTask | undefined; /** Number of stored task records */ get taskCount(): number; /** * HTTP handler — mount on any node http server. * Routes: GET /.well-known/agent.json, POST /tasks. */ httpHandler(): (req: IncomingMessage, res: ServerResponse) => void; /** * Convenience: create and start an http.Server with the handler mounted. * Binds to 127.0.0.1 by default — expose deliberately, not accidentally. */ startServer(port: number, hostname?: string): Server; private route; private handleSend; private handleGet; private handleCancel; private store; private readBody; private json; private rpcError; } //# sourceMappingURL=a2a-server.d.ts.map