/** * A2A's gRPC binding: the service `lf.a2a.v1.A2AService` of protocol 1.0, served over the same * `a2aHandler()` as its JSON-RPC and HTTP+JSON bindings, and so over the same tasks, and a client that * calls an agent over it. Over HTTP/2 from `node:http2`, with no dependency. * * ```ts * const handler = a2aHandler(agent, { card, interfaces: [{ url: 'agents.example.com:50051', protocolBinding: 'GRPC' }] }); * const grpc = a2aGrpcService(handler); * await grpc.listen(50051); * ``` */ import { type Http2Server, type IncomingHttpHeaders, type ServerHttp2Stream } from 'node:http2'; import { type A2aClient, type A2aClientOptions, type A2aHandler } from './a2a.js'; /** Options for `a2aGrpcService()`. */ export interface A2aGrpcServiceOptions { /** Largest request message taken, in bytes. Defaults to 4 MiB, gRPC's own default. */ maxMessageBytes?: number; } /** The gRPC binding of one A2A handler. */ export interface A2aGrpcService { /** * Answers one HTTP/2 stream: give it each stream of a server of your own, such as one over TLS, * as `server.on('stream', service.handle)`. */ handle(stream: ServerHttp2Stream, headers: IncomingHttpHeaders): void; /** * Starts a server over plain HTTP/2 on `port`, 0 for any, on `host`: for a server behind a proxy * that ends TLS, and for tests. Resolves with the address to list on the card, `host:port`. Its * `close()` stops taking calls, tells each connected client to go, and resolves once the calls in * flight finish. */ listen(port?: number, host?: string): Promise<{ url: string; port: number; server: Http2Server; close(): Promise; }>; } /** * The gRPC binding over an `a2aHandler()`: each method of `lf.a2a.v1.A2AService`, its message read as * the JSON the handler takes and its answer written back, a stream as a server-streaming call, and an * error as a gRPC status with A2A's `ErrorInfo` in `grpc-status-details-bin`. The caller is read by the * handler's own `principal`, from a `Request` with the call's metadata as its headers. */ export declare function a2aGrpcService(handler: A2aHandler, options?: A2aGrpcServiceOptions): A2aGrpcService; /** Options for `a2aGrpcClient()`. */ export interface A2aGrpcClientOptions extends Omit { /** Where the agent's gRPC service is: `host:port`, as its card lists it, or an `http://` or `https://` URL. */ url: string; /** Where its card is, for `card()`. Without it, `card()` reads the extended card. */ cardUrl?: string; } /** A client for an A2A agent over gRPC, with `close()` for its connection. */ export interface A2aGrpcClient extends A2aClient { /** Closes the HTTP/2 connection. */ close(): Promise; } /** * A client for one A2A agent over its gRPC binding: the same methods as `a2aClient()`, each a call of * `lf.a2a.v1.A2AService` over one HTTP/2 connection, a gRPC error raised as an `A2aError` with the * protocol's code. Plain HTTP/2 for `host:port` and `http://`; TLS for `https://`. */ export declare function a2aGrpcClient(options: A2aGrpcClientOptions): A2aGrpcClient;