UNPKG

@a2alite/sdk

Version:

A Modular SDK (Server & Client) for Agent to Agent (A2A) protocol, with easy task lifecycle management

33 lines (32 loc) 1.88 kB
import { JSONRPCRequest, JSONRPCResponse, RequestsByMethod } from "../../types/types.ts"; type HandlerResponse = { response?: JSONRPCResponse; stream?: AsyncGenerator<JSONRPCResponse>; }; /** * Interface for the JSON-RPC Server, outlining its core functionalities. */ interface IJSONRPCServer { /** * Registers a handler for a specific JSON-RPC method. * @param requestSchema The Zod schema defining the specific request, including a literal method name. * @param handler The function to execute when a request matching the schema is received. */ setRequestHandler<M extends keyof RequestsByMethod>(methodName: M, handler: (request: RequestsByMethod[M], requestAbortSignal?: AbortSignal, extension?: Record<string, any>) => Promise<HandlerResponse>): void; /** * Handles an incoming raw JSON-RPC request string. * This is the primary entry point for the server to receive requests. * @param rawRequest The raw JSON string of the request. * @param requestAbortSignal An optional AbortSignal to cancel the specific request. * @returns A promise that resolves to the JSON string of the response, or undefined for notifications. */ handleRequest(request: JSONRPCRequest, requestAbortSignal?: AbortSignal, extension?: Record<string, any>): Promise<HandlerResponse>; } declare class JSONRPCServer implements IJSONRPCServer { private _handlers; private serverAbortSignal?; setRequestHandler<M extends keyof RequestsByMethod>(methodName: M, handler: (request: RequestsByMethod[M], requestAbortSignal?: AbortSignal, extension?: Record<string, any>) => Promise<HandlerResponse>): void; handleRequest(request: JSONRPCRequest, requestAbortSignal?: AbortSignal, extension?: Record<string, any>): Promise<HandlerResponse>; } export type { HandlerResponse, IJSONRPCServer }; export { JSONRPCServer };