import { Payments } from '../index.js'; import type { DelegationConfig } from '../common/types.js'; import { MessageSendParams, SendMessageResponse, TaskQueryParams, GetTaskResponse, TaskPushNotificationConfig, SetTaskPushNotificationConfigResponse, TaskIdParams, GetTaskPushNotificationConfigResponse, JSONRPCResponse, JSONRPCErrorResponse } from '@a2a-js/sdk'; import { A2AClient } from '@a2a-js/sdk/client'; /** * PaymentsClient is a high-level client for A2A agents with payments integration. * Each instance is bound to a specific agentId and planId. */ export declare class PaymentsClient extends A2AClient { payments: Payments; private readonly agentId; private readonly planId; private readonly delegationConfig?; private accessToken; /** * Creates a new PaymentsClient instance. * @param agentBaseUrl - The base URL of the agent (e.g. http://localhost:3005/a2a/). * @param payments - The Payments object. * @param agentId - The ID of the agent. * @param planId - The ID of the plan. * @param agentCardPath - Optional path to the agent card relative to base URL (defaults to '.well-known/agent-card.json'). */ private constructor(); /** * Creates a PaymentsClient by fetching the AgentCard first and then * constructing the underlying A2AClient with the AgentCard object. */ static create(agentBaseUrl: string, payments: Payments, agentId: string, planId: string, agentCardPath?: string, delegationConfig?: DelegationConfig): Promise; /** * Fetches a remote agent card, trying the requested (canonical) path first and * falling back to the legacy '.well-known/agent.json' so updated clients keep * working against agents that have not adopted the canonical path yet. * TODO(a2a): drop the fallback one release after agents are updated. */ private static _fetchAgentCard; /** * Gets and caches the access token for this client instance. * @returns The access token string. */ private _getX402AccessToken; /** * Clears the cached access token for this client instance. */ clearToken(): void; /** * Build the in-band x402 message metadata (x402 v2 A2A transport). * * The server consumes the same base64 access token whether it arrives in the * deprecated `payment-signature` header or in band, so the in-band * `x402.payment.payload` is just the decoded PaymentPayload object. Falls back * to wrapping the raw token if it is not decodable (never expected for real * Nevermined tokens, which are base64 JSON). * * @param accessToken - The x402 access token string * @returns The message-metadata fragment carrying status + payload */ private _buildInBandPaymentMetadata; /** * Return a copy of the message params with the in-band x402 payment metadata * merged into `message.metadata`, optionally correlating to a taskId returned * by a prior `input-required` (payment-required) response. Immutable: the * caller's params object is never mutated. * * @param params - The original message send params * @param accessToken - The x402 access token to embed in band * @param taskId - Optional taskId to correlate a payment-required follow-up */ private _withInBandPayment; /** * Detect a payment-required response (x402 v2 A2A transport): an * `input-required` task whose status message carries * `x402.payment.status: payment-required`. Returns the task id to correlate a * follow-up payment, or `undefined` when the response is not payment-required. * * @param response - The JSON-RPC send-message response */ private _paymentRequiredTaskId; /** * Type guard to check if a JSON-RPC response is an error response. * @param response - The JSON-RPC response to check * @returns true if the response contains an error, false otherwise */ isErrorResponse(response: JSONRPCResponse): response is JSONRPCErrorResponse; /** * Sends a message to the agent, managing authentication automatically. * @param params - The parameters for sending the message. * @returns The response from the agent. */ sendA2AMessage(params: MessageSendParams): Promise; /** * Sends a message to the agent and streams back responses using Server-Sent Events (SSE). * Push notification configuration can be specified in `params.configuration`. * Optionally, `params.message.contextId` or `params.message.taskId` can be provided. * Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard). * @param params - The parameters for sending the message. * @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent). * The generator throws an error if streaming is not supported or if an HTTP/SSE error occurs. */ sendA2AMessageStream(params: MessageSendParams): AsyncGenerator; /** * Parses an HTTP response body as an A2A Server-Sent Event stream. * Each 'data' field of an SSE event is expected to be a JSON-RPC 2.0 Response object, * specifically a SendStreamingMessageResponse (or similar structure for resubscribe). * @param response -The HTTP Response object whose body is the SSE stream. * @param originalRequestId - The ID of the client's JSON-RPC request that initiated this stream. * Used to validate the `id` in the streamed JSON-RPC responses. * @returns An AsyncGenerator yielding the `result` field of each valid JSON-RPC success response from the stream. */ private _parseA2AStream; /** * Processes a single SSE event's data string, expecting it to be a JSON-RPC response. * @param jsonData - The string content from one or more 'data:' lines of an SSE event. * @param originalRequestId - The ID of the client's request that initiated the stream. * @returns The `result` field of the parsed JSON-RPC success response. * @throws Error if data is not valid JSON, not a valid JSON-RPC response, an error response, or ID mismatch. */ private _processEventData; /** * Resubscribes to a task's event stream using Server-Sent Events (SSE). * This is used if a previous SSE connection for an active task was broken. * Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard). * @param params - Parameters containing the taskId. * @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent). */ resubscribeA2ATask(params: TaskIdParams): AsyncGenerator; /** * Retrieves a task by its ID, managing authentication automatically. * @param params - The parameters for the task query. * @returns The task response. */ getA2ATask(params: TaskQueryParams): Promise; /** * Sets or updates the push notification configuration for a given task, managing authentication automatically. * @param params - The parameters for the task push notification configuration. * @returns The response from the agent. */ setA2ATaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise; /** * Gets the push notification configuration for a given task, managing authentication automatically. * @param params - The parameters for the task push notification configuration. * @returns The response from the agent. */ getA2ATaskPushNotificationConfig(params: TaskIdParams): Promise; /** * Internal helper to make a JSON-RPC POST request with custom headers. * @param method - The RPC method name. * @param params - The parameters for the RPC method. * @param headers - Optional custom headers. * @returns The response from the agent. */ protected _postRpcRequestWithHeaders(method: string, params: TParams, headers?: Record): Promise; } export type { MessageSendParams, SendMessageResponse, TaskQueryParams, GetTaskResponse, TaskPushNotificationConfig, SetTaskPushNotificationConfigResponse, TaskIdParams, GetTaskPushNotificationConfigResponse, } from '@a2a-js/sdk'; //# sourceMappingURL=paymentsClient.d.ts.map