UNPKG

@dexwox-labs/a2a-client

Version:

TypeScript client implementation for Google's Agent-to-Agent (A2A) protocol - includes HTTP/WebSocket communication, circuit breakers and error handling

91 lines 2.75 kB
/** * @module HttpUtils * @description Utility functions for HTTP communication with A2A protocol servers */ import { JsonRpcRequest, JsonRpcResponse } from '@dexwox-labs/a2a-core'; import { MessageClientOptions } from '../types'; /** * Authentication options for HTTP requests * * This interface defines how authentication should be handled for HTTP requests, * supporting various authentication methods including basic auth, bearer tokens, * API keys, and custom headers. * * @example * ```typescript * // Basic authentication * const basicAuth: AuthOptions = { * type: 'basic', * credentials: { * username: 'user', * password: 'pass' * } * }; * * // Bearer token authentication * const tokenAuth: AuthOptions = { * type: 'bearer', * credentials: { * token: 'your-jwt-token' * } * }; * ``` */ export interface AuthOptions { /** Authentication type to use */ type: 'basic' | 'bearer' | 'apiKey' | 'custom'; /** Credentials for the selected authentication type */ credentials: { /** Username for basic authentication */ username?: string; /** Password for basic authentication */ password?: string; /** Token for bearer authentication */ token?: string; /** API key for apiKey authentication */ apiKey?: string; /** Custom header name for custom authentication */ headerName?: string; /** Custom header value for custom authentication */ headerValue?: string; }; } /** * Sends a JSON-RPC request to an A2A protocol server * * This function handles the details of making authenticated HTTP requests * to A2A protocol servers, including setting up the proper headers, * handling authentication, and processing the response. * * @param options - Client options including base URL, headers, timeout, and authentication * @param request - JSON-RPC request object to send * @returns Promise resolving to the JSON-RPC response * @throws Error if the HTTP request fails or times out * * @example * ```typescript * // Send a simple JSON-RPC request * const response = await sendRequest<AgentCard[]>( * { * baseUrl: 'https://a2a-server.example.com', * timeout: 5000, * auth: { * type: 'bearer', * credentials: { token: 'your-token' } * } * }, * { * jsonrpc: '2.0', * method: 'discover', * params: { capability: 'chat' }, * id: '1' * } * ); * * console.log('Response:', response.result); * ``` */ export declare function sendRequest<T = unknown>(options: MessageClientOptions & { auth?: AuthOptions; }, request: JsonRpcRequest): Promise<JsonRpcResponse<T>>; //# sourceMappingURL=http-utils.d.ts.map