import { T as TransportFactory, C as ClientConfig, a as TransportProtocolName, b as Client, c as Transport, R as RequestOptions, S as SendMessageResult, A as A2AStreamEventData } from '../core-NwQicv77.js'; export { d as A2AClient, e as A2AClientOptions, f as AfterArgs, B as BeforeArgs, g as CallInterceptor, h as ClientCallContext, i as ClientCallContextKey, j as ClientCallInput, k as ClientCallResult, l as ContextUpdate, m as ServiceParameters, n as ServiceParametersUpdate, w as withA2AExtensions } from '../core-NwQicv77.js'; import { i as AgentCard, aj as MessageSendParams, aU as TaskPushNotificationConfig, U as GetTaskPushNotificationConfigParams, aa as ListTaskPushNotificationConfigParams, E as DeleteTaskPushNotificationConfigParams, aY as TaskQueryParams, aL as Task, aP as TaskIdParams, a8 as JSONRPCResponse } from '../extensions-APfrw8gz.js'; interface HttpHeaders { [key: string]: string; } /** * Generic interface for handling authentication for HTTP requests. * * - For each HTTP request, this handler is called to provide additional headers to the request through * the headers() function. * - After the server returns a response, the shouldRetryWithHeaders() function is called. Usually this * function responds to a 401 or 403 response or JSON-RPC codes, but can respond to any other signal - * that is an implementation detail of the AuthenticationHandler. * - If the shouldRetryWithHeaders() function returns new headers, then the request should retried with the provided * revised headers. These provisional headers may, or may not, be optimistically stored for subsequent requests - * that is an implementation detail of the AuthenticationHandler. * - If the request is successful and the onSuccessfulRetry() is defined, then the onSuccessfulRetry() function is * called with the headers that were used to successfully complete the request. This callback provides an * opportunity to save the headers for subsequent requests if they were not already saved. * */ interface AuthenticationHandler { /** * Provides additional HTTP request headers. * @returns HTTP headers which may include Authorization if available. */ headers: () => Promise; /** * For every HTTP response (even 200s) the shouldRetryWithHeaders() method is called. * This method is supposed to check if the request needs to be retried and if, yes, * return a set of headers. An A2A server might indicate auth failures in its response * by JSON-rpc codes, HTTP codes like 401, 403 or headers like WWW-Authenticate. * * @param req The RequestInit object used to invoke fetch() * @param res The fetch Response object * @returns If the HTTP request should be retried then returns the HTTP headers to use, * or returns undefined if no retry should be made. */ shouldRetryWithHeaders: (req: RequestInit, res: Response) => Promise; /** * If the last HTTP request using the headers from shouldRetryWithHeaders() was successful, and * this function is implemented, then it will be called with the headers provided from * shouldRetryWithHeaders(). * * This callback allows transient headers to be saved for subsequent requests only when they * are validated by the server. */ onSuccessfulRetry?: (headers: HttpHeaders) => Promise; } /** * Higher-order function that wraps fetch with authentication handling logic. * Returns a new fetch function that automatically handles authentication retries for 401/403 responses. * * @param fetchImpl The underlying fetch implementation to wrap * @param authHandler Authentication handler for managing auth headers and retries * @returns A new fetch function with authentication handling capabilities * * Usage examples: * - const authFetch = createAuthHandlingFetch(fetch, authHandler); * - const response = await authFetch(url, options); * - const response = await authFetch(url); // Direct function call */ declare function createAuthenticatingFetchWithRetry(fetchImpl: typeof fetch, authHandler: AuthenticationHandler): typeof fetch; interface AgentCardResolverOptions { path?: string; fetchImpl?: typeof fetch; } declare class DefaultAgentCardResolver implements AgentCardResolver { readonly options?: AgentCardResolverOptions; constructor(options?: AgentCardResolverOptions); /** * Fetches the agent card based on provided base URL and path. * Path is selected in the following order: * 1) path parameter * 2) path from options * 3) .well-known/agent-card.json */ resolve(baseUrl: string, path?: string): Promise; private fetchImpl; private normalizeAgentCard; private isProtoAgentCard; private hasProtoSecurity; private hasProtoSecuritySchemes; } interface AgentCardResolver { /** * Fetches the agent card based on provided base URL and path, */ resolve(baseUrl: string, path?: string): Promise; } declare const AgentCardResolver: { default: DefaultAgentCardResolver; }; interface ClientFactoryOptions { /** * Transport factories to use. * Effectively defines transports supported by this client factory. */ transports: TransportFactory[]; /** * Client config to be used for clients created by this factory. */ clientConfig?: ClientConfig; /** * Transport preferences to override ones defined by the agent card. * If no matches are found among preferred transports, agent card values are used next. */ preferredTransports?: TransportProtocolName[]; /** * Used for createFromAgentCardUrl to download agent card. */ cardResolver?: AgentCardResolver; } declare const ClientFactoryOptions: { /** * SDK default options for {@link ClientFactory}. */ default: Readonly; /** * Creates new options by merging an original and an override object. * Transports are merged based on `TransportFactory.protocolName`, * interceptors are concatenated, other fields are overriden. * * @example * ```ts * const options = ClientFactoryOptions.createFrom(ClientFactoryOptions.default, { * transports: [new MyCustomTransportFactory()], // adds a custom transport * clientConfig: { interceptors: [new MyInterceptor()] }, // adds a custom interceptor * }); * ``` */ createFrom(original: ClientFactoryOptions, overrides: Partial): ClientFactoryOptions; }; declare class ClientFactory { readonly options: ClientFactoryOptions; private readonly transportsByName; private readonly agentCardResolver; constructor(options?: ClientFactoryOptions); /** * Creates a new client from the provided agent card. */ createFromAgentCard(agentCard: AgentCard): Promise; /** * Downloads agent card using AgentCardResolver from options * and creates a new client from the downloaded card. * * @example * ```ts * const factory = new ClientFactory(); // use default options and default {@link AgentCardResolver}. * const client1 = await factory.createFromUrl('https://example.com'); // /.well-known/agent-card.json is used by default * const client2 = await factory.createFromUrl('https://example.com', '/my-agent-card.json'); // specify custom path * const client3 = await factory.createFromUrl('https://example.com/my-agent-card.json', ''); // specify full URL and set path to empty * ``` */ createFromUrl(baseUrl: string, path?: string): Promise; } declare class TaskNotFoundError extends Error { constructor(message?: string); } declare class TaskNotCancelableError extends Error { constructor(message?: string); } declare class PushNotificationNotSupportedError extends Error { constructor(message?: string); } declare class UnsupportedOperationError extends Error { constructor(message?: string); } declare class ContentTypeNotSupportedError extends Error { constructor(message?: string); } declare class InvalidAgentResponseError extends Error { constructor(message?: string); } declare class AuthenticatedExtendedCardNotConfiguredError extends Error { constructor(message?: string); } interface JsonRpcTransportOptions { endpoint: string; fetchImpl?: typeof fetch; } declare class JsonRpcTransport implements Transport { private readonly customFetchImpl?; private readonly endpoint; private requestIdCounter; constructor(options: JsonRpcTransportOptions); getExtendedAgentCard(options?: RequestOptions, idOverride?: number): Promise; sendMessage(params: MessageSendParams, options?: RequestOptions, idOverride?: number): Promise; sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator; setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions, idOverride?: number): Promise; getTaskPushNotificationConfig(params: GetTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise; listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise; deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise; getTask(params: TaskQueryParams, options?: RequestOptions, idOverride?: number): Promise; cancelTask(params: TaskIdParams, options?: RequestOptions, idOverride?: number): Promise; resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator; callExtensionMethod(method: string, params: TExtensionParams, idOverride: number, options?: RequestOptions): Promise; private _fetch; private _sendRpcRequest; private _fetchRpc; private _sendStreamingRequest; private _processSseEventData; private static mapToError; } declare class JsonRpcTransportFactoryOptions { fetchImpl?: typeof fetch; } declare class JsonRpcTransportFactory implements TransportFactory { private readonly options?; static readonly name: TransportProtocolName; constructor(options?: JsonRpcTransportFactoryOptions); get protocolName(): string; create(url: string, _agentCard: AgentCard): Promise; } interface RestTransportOptions { endpoint: string; fetchImpl?: typeof fetch; } declare class RestTransport implements Transport { private readonly customFetchImpl?; private readonly endpoint; constructor(options: RestTransportOptions); getExtendedAgentCard(options?: RequestOptions): Promise; sendMessage(params: MessageSendParams, options?: RequestOptions): Promise; sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator; setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions): Promise; getTaskPushNotificationConfig(params: GetTaskPushNotificationConfigParams, options?: RequestOptions): Promise; listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions): Promise; deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions): Promise; getTask(params: TaskQueryParams, options?: RequestOptions): Promise; cancelTask(params: TaskIdParams, options?: RequestOptions): Promise; resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator; private _fetch; private _buildHeaders; private _sendRequest; private _handleErrorResponse; private _sendStreamingRequest; private _processSseEventData; private static mapToError; } interface RestTransportFactoryOptions { fetchImpl?: typeof fetch; } declare class RestTransportFactory implements TransportFactory { private readonly options?; static readonly name: TransportProtocolName; constructor(options?: RestTransportFactoryOptions); get protocolName(): string; create(url: string, _agentCard: AgentCard): Promise; } export { AgentCardResolver, type AgentCardResolverOptions, AuthenticatedExtendedCardNotConfiguredError, type AuthenticationHandler, Client, ClientConfig, ClientFactory, ClientFactoryOptions, ContentTypeNotSupportedError, DefaultAgentCardResolver, type HttpHeaders, InvalidAgentResponseError, JsonRpcTransport, JsonRpcTransportFactory, type JsonRpcTransportOptions, PushNotificationNotSupportedError, RequestOptions, RestTransport, RestTransportFactory, type RestTransportOptions, TaskNotCancelableError, TaskNotFoundError, Transport, TransportFactory, UnsupportedOperationError, createAuthenticatingFetchWithRetry };