@mailmodo/a2a 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +272 -138
- package/dist/a2a_request_handler-DPkhsCMt.d.mts +37 -0
- package/dist/a2a_request_handler-DQfg1Q-R.d.ts +37 -0
- package/dist/auth-handler-DVLcl8yj.d.mts +209 -0
- package/dist/auth-handler-Gzpf3xHC.d.ts +209 -0
- package/dist/chunk-HZFUOBJQ.mjs +198 -0
- package/dist/chunk-LIEYEFQG.mjs +879 -0
- package/dist/chunk-LVD4GF26.mjs +262 -0
- package/dist/chunk-PHP7LM4Y.mjs +8 -0
- package/dist/chunk-UBRSFN2J.mjs +776 -0
- package/dist/client/index.d.mts +312 -0
- package/dist/client/index.d.ts +312 -0
- package/dist/client/index.js +1158 -0
- package/dist/client/index.mjs +367 -0
- package/dist/error-DExKs0Q3.d.mts +233 -0
- package/dist/error-j1vYKII2.d.ts +233 -0
- package/dist/index.d.mts +14 -2739
- package/dist/index.d.ts +14 -2739
- package/dist/index.js +1605 -1158
- package/dist/index.mjs +29 -1612
- package/dist/server/express/index.d.mts +25 -0
- package/dist/server/express/index.d.ts +25 -0
- package/dist/server/express/index.js +468 -0
- package/dist/server/express/index.mjs +10 -0
- package/dist/server/index.d.mts +26 -0
- package/dist/server/index.d.ts +26 -0
- package/dist/server/index.js +1173 -0
- package/dist/server/index.mjs +32 -0
- package/dist/types-Due_Cv6t.d.mts +2550 -0
- package/dist/types-Due_Cv6t.d.ts +2550 -0
- package/package.json +18 -11
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { A as AgentCard, M as MessageSendParams, a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, i as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, a8 as GetTaskPushNotificationConfigParams, L as ListTaskPushNotificationConfigParams, D as DeleteTaskPushNotificationConfigParams } from './types-Due_Cv6t.mjs';
|
|
2
|
+
|
|
3
|
+
interface User {
|
|
4
|
+
get isAuthenticated(): boolean;
|
|
5
|
+
get userName(): string;
|
|
6
|
+
}
|
|
7
|
+
declare class UnauthenticatedUser implements User {
|
|
8
|
+
get isAuthenticated(): boolean;
|
|
9
|
+
get userName(): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class ServerCallContext {
|
|
13
|
+
private readonly _requestedExtensions?;
|
|
14
|
+
private readonly _user?;
|
|
15
|
+
private _activatedExtensions?;
|
|
16
|
+
constructor(requestedExtensions?: Set<string>, user?: User);
|
|
17
|
+
get user(): User | undefined;
|
|
18
|
+
get activatedExtensions(): ReadonlySet<string> | undefined;
|
|
19
|
+
get requestedExtensions(): ReadonlySet<string> | undefined;
|
|
20
|
+
addActivatedExtension(uri: string): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface A2ARequestHandler {
|
|
24
|
+
getAgentCard(): Promise<AgentCard>;
|
|
25
|
+
getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
|
|
26
|
+
sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
|
|
27
|
+
sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
28
|
+
getTask(params: TaskQueryParams, context?: ServerCallContext): Promise<Task>;
|
|
29
|
+
cancelTask(params: TaskIdParams, context?: ServerCallContext): Promise<Task>;
|
|
30
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
|
|
31
|
+
getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
|
|
32
|
+
listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
|
|
33
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<void>;
|
|
34
|
+
resubscribe(params: TaskIdParams, context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type A2ARequestHandler as A, ServerCallContext as S, type User as U, UnauthenticatedUser as a };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { A as AgentCard, M as MessageSendParams, a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, i as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, a8 as GetTaskPushNotificationConfigParams, L as ListTaskPushNotificationConfigParams, D as DeleteTaskPushNotificationConfigParams } from './types-Due_Cv6t.js';
|
|
2
|
+
|
|
3
|
+
interface User {
|
|
4
|
+
get isAuthenticated(): boolean;
|
|
5
|
+
get userName(): string;
|
|
6
|
+
}
|
|
7
|
+
declare class UnauthenticatedUser implements User {
|
|
8
|
+
get isAuthenticated(): boolean;
|
|
9
|
+
get userName(): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class ServerCallContext {
|
|
13
|
+
private readonly _requestedExtensions?;
|
|
14
|
+
private readonly _user?;
|
|
15
|
+
private _activatedExtensions?;
|
|
16
|
+
constructor(requestedExtensions?: Set<string>, user?: User);
|
|
17
|
+
get user(): User | undefined;
|
|
18
|
+
get activatedExtensions(): ReadonlySet<string> | undefined;
|
|
19
|
+
get requestedExtensions(): ReadonlySet<string> | undefined;
|
|
20
|
+
addActivatedExtension(uri: string): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface A2ARequestHandler {
|
|
24
|
+
getAgentCard(): Promise<AgentCard>;
|
|
25
|
+
getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
|
|
26
|
+
sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
|
|
27
|
+
sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
28
|
+
getTask(params: TaskQueryParams, context?: ServerCallContext): Promise<Task>;
|
|
29
|
+
cancelTask(params: TaskIdParams, context?: ServerCallContext): Promise<Task>;
|
|
30
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
|
|
31
|
+
getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
|
|
32
|
+
listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
|
|
33
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<void>;
|
|
34
|
+
resubscribe(params: TaskIdParams, context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type A2ARequestHandler as A, ServerCallContext as S, type User as U, UnauthenticatedUser as a };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { A as AgentCard, M as MessageSendParams, S as SendMessageResponse, a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, d as TaskPushNotificationConfig, e as SetTaskPushNotificationConfigResponse, f as TaskIdParams, G as GetTaskPushNotificationConfigResponse, L as ListTaskPushNotificationConfigParams, g as ListTaskPushNotificationConfigResponse, D as DeleteTaskPushNotificationConfigParams, h as DeleteTaskPushNotificationConfigResponse, i as TaskQueryParams, j as GetTaskResponse, C as CancelTaskResponse, J as JSONRPCResponse } from './types-Due_Cv6t.mjs';
|
|
2
|
+
|
|
3
|
+
type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
4
|
+
type SendMessageResult = Message | Task;
|
|
5
|
+
interface A2AClientOptions {
|
|
6
|
+
agentCardPath?: string;
|
|
7
|
+
fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A2AClient is a TypeScript HTTP client for interacting with A2A-compliant agents.
|
|
11
|
+
* Only JSON-RPC transport is supported.
|
|
12
|
+
*/
|
|
13
|
+
declare class A2AClient {
|
|
14
|
+
private static emptyOptions?;
|
|
15
|
+
private readonly agentCardPromise;
|
|
16
|
+
private readonly customFetchImpl?;
|
|
17
|
+
private serviceEndpointUrl?;
|
|
18
|
+
private transport?;
|
|
19
|
+
private requestIdCounter;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
22
|
+
* @param agentCard The AgentCard object.
|
|
23
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
24
|
+
*/
|
|
25
|
+
constructor(agentCard: AgentCard | string, options?: A2AClientOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
28
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
29
|
+
* @returns The fetch implementation.
|
|
30
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
31
|
+
* @throws If no fetch implementation is available.
|
|
32
|
+
*/
|
|
33
|
+
private _fetch;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
36
|
+
* @param agentCardUrl The URL of the agent card.
|
|
37
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
38
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
39
|
+
*/
|
|
40
|
+
static fromCardUrl(agentCardUrl: string, options?: A2AClientOptions): Promise<A2AClient>;
|
|
41
|
+
/**
|
|
42
|
+
* Sends a message to the agent.
|
|
43
|
+
* The behavior (blocking/non-blocking) and push notification configuration
|
|
44
|
+
* are specified within the `params.configuration` object.
|
|
45
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
46
|
+
* @param params The parameters for sending the message, including the message content and configuration.
|
|
47
|
+
* @returns A Promise resolving to SendMessageResponse, which can be a Message, Task, or an error.
|
|
48
|
+
*/
|
|
49
|
+
sendMessage(params: MessageSendParams): Promise<SendMessageResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a message to the agent and streams back responses using Server-Sent Events (SSE).
|
|
52
|
+
* Push notification configuration can be specified in `params.configuration`.
|
|
53
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
54
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
55
|
+
* @param params The parameters for sending the message.
|
|
56
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
57
|
+
* The generator throws an error if streaming is not supported or if an HTTP/SSE error occurs.
|
|
58
|
+
*/
|
|
59
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Sets or updates the push notification configuration for a given task.
|
|
62
|
+
* Requires the agent to support push notifications (`capabilities.pushNotifications: true` in AgentCard).
|
|
63
|
+
* @param params Parameters containing the taskId and the TaskPushNotificationConfig.
|
|
64
|
+
* @returns A Promise resolving to SetTaskPushNotificationConfigResponse.
|
|
65
|
+
*/
|
|
66
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<SetTaskPushNotificationConfigResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the push notification configuration for a given task.
|
|
69
|
+
* @param params Parameters containing the taskId.
|
|
70
|
+
* @returns A Promise resolving to GetTaskPushNotificationConfigResponse.
|
|
71
|
+
*/
|
|
72
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<GetTaskPushNotificationConfigResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Lists the push notification configurations for a given task.
|
|
75
|
+
* @param params Parameters containing the taskId.
|
|
76
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
77
|
+
*/
|
|
78
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams): Promise<ListTaskPushNotificationConfigResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Deletes the push notification configuration for a given task.
|
|
81
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
82
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
83
|
+
*/
|
|
84
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<DeleteTaskPushNotificationConfigResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a task by its ID.
|
|
87
|
+
* @param params Parameters containing the taskId and optional historyLength.
|
|
88
|
+
* @returns A Promise resolving to GetTaskResponse, which contains the Task object or an error.
|
|
89
|
+
*/
|
|
90
|
+
getTask(params: TaskQueryParams): Promise<GetTaskResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Cancels a task by its ID.
|
|
93
|
+
* @param params Parameters containing the taskId.
|
|
94
|
+
* @returns A Promise resolving to CancelTaskResponse, which contains the updated Task object or an error.
|
|
95
|
+
*/
|
|
96
|
+
cancelTask(params: TaskIdParams): Promise<CancelTaskResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
99
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
100
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
101
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
102
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
103
|
+
* @returns A Promise that resolves to the RPC response.
|
|
104
|
+
*/
|
|
105
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams): Promise<TExtensionResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
108
|
+
* This is used if a previous SSE connection for an active task was broken.
|
|
109
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
110
|
+
* @param params Parameters containing the taskId.
|
|
111
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
112
|
+
*/
|
|
113
|
+
resubscribeTask(params: TaskIdParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
114
|
+
private _getOrCreateTransport;
|
|
115
|
+
/**
|
|
116
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
117
|
+
* This method is called by the constructor.
|
|
118
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
119
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
120
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
121
|
+
*/
|
|
122
|
+
private _fetchAndCacheAgentCard;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves the Agent Card.
|
|
125
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
126
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
127
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
128
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
129
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
130
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
131
|
+
*/
|
|
132
|
+
getAgentCard(agentBaseUrl?: string, agentCardPath?: string): Promise<AgentCard>;
|
|
133
|
+
/**
|
|
134
|
+
* Determines the agent card URL based on the agent URL.
|
|
135
|
+
* @param agentBaseUrl The agent URL.
|
|
136
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
137
|
+
*/
|
|
138
|
+
private resolveAgentCardUrl;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
141
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
142
|
+
*/
|
|
143
|
+
private _getServiceEndpoint;
|
|
144
|
+
private invokeJsonRpc;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface HttpHeaders {
|
|
148
|
+
[key: string]: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generic interface for handling authentication for HTTP requests.
|
|
152
|
+
*
|
|
153
|
+
* - For each HTTP request, this handler is called to provide additional headers to the request through
|
|
154
|
+
* the headers() function.
|
|
155
|
+
* - After the server returns a response, the shouldRetryWithHeaders() function is called. Usually this
|
|
156
|
+
* function responds to a 401 or 403 response or JSON-RPC codes, but can respond to any other signal -
|
|
157
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
158
|
+
* - If the shouldRetryWithHeaders() function returns new headers, then the request should retried with the provided
|
|
159
|
+
* revised headers. These provisional headers may, or may not, be optimistically stored for subsequent requests -
|
|
160
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
161
|
+
* - If the request is successful and the onSuccessfulRetry() is defined, then the onSuccessfulRetry() function is
|
|
162
|
+
* called with the headers that were used to successfully complete the request. This callback provides an
|
|
163
|
+
* opportunity to save the headers for subsequent requests if they were not already saved.
|
|
164
|
+
*
|
|
165
|
+
*/
|
|
166
|
+
interface AuthenticationHandler {
|
|
167
|
+
/**
|
|
168
|
+
* Provides additional HTTP request headers.
|
|
169
|
+
* @returns HTTP headers which may include Authorization if available.
|
|
170
|
+
*/
|
|
171
|
+
headers: () => Promise<HttpHeaders>;
|
|
172
|
+
/**
|
|
173
|
+
* For every HTTP response (even 200s) the shouldRetryWithHeaders() method is called.
|
|
174
|
+
* This method is supposed to check if the request needs to be retried and if, yes,
|
|
175
|
+
* return a set of headers. An A2A server might indicate auth failures in its response
|
|
176
|
+
* by JSON-rpc codes, HTTP codes like 401, 403 or headers like WWW-Authenticate.
|
|
177
|
+
*
|
|
178
|
+
* @param req The RequestInit object used to invoke fetch()
|
|
179
|
+
* @param res The fetch Response object
|
|
180
|
+
* @returns If the HTTP request should be retried then returns the HTTP headers to use,
|
|
181
|
+
* or returns undefined if no retry should be made.
|
|
182
|
+
*/
|
|
183
|
+
shouldRetryWithHeaders: (req: RequestInit, res: Response) => Promise<HttpHeaders | undefined>;
|
|
184
|
+
/**
|
|
185
|
+
* If the last HTTP request using the headers from shouldRetryWithHeaders() was successful, and
|
|
186
|
+
* this function is implemented, then it will be called with the headers provided from
|
|
187
|
+
* shouldRetryWithHeaders().
|
|
188
|
+
*
|
|
189
|
+
* This callback allows transient headers to be saved for subsequent requests only when they
|
|
190
|
+
* are validated by the server.
|
|
191
|
+
*/
|
|
192
|
+
onSuccessfulRetry?: (headers: HttpHeaders) => Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Higher-order function that wraps fetch with authentication handling logic.
|
|
196
|
+
* Returns a new fetch function that automatically handles authentication retries for 401/403 responses.
|
|
197
|
+
*
|
|
198
|
+
* @param fetchImpl The underlying fetch implementation to wrap
|
|
199
|
+
* @param authHandler Authentication handler for managing auth headers and retries
|
|
200
|
+
* @returns A new fetch function with authentication handling capabilities
|
|
201
|
+
*
|
|
202
|
+
* Usage examples:
|
|
203
|
+
* - const authFetch = createAuthHandlingFetch(fetch, authHandler);
|
|
204
|
+
* - const response = await authFetch(url, options);
|
|
205
|
+
* - const response = await authFetch(url); // Direct function call
|
|
206
|
+
*/
|
|
207
|
+
declare function createAuthenticatingFetchWithRetry(fetchImpl: typeof fetch, authHandler: AuthenticationHandler): typeof fetch;
|
|
208
|
+
|
|
209
|
+
export { A2AClient as A, type HttpHeaders as H, type SendMessageResult as S, type A2AClientOptions as a, type AuthenticationHandler as b, createAuthenticatingFetchWithRetry as c, type A2AStreamEventData as d };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { A as AgentCard, M as MessageSendParams, S as SendMessageResponse, a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, d as TaskPushNotificationConfig, e as SetTaskPushNotificationConfigResponse, f as TaskIdParams, G as GetTaskPushNotificationConfigResponse, L as ListTaskPushNotificationConfigParams, g as ListTaskPushNotificationConfigResponse, D as DeleteTaskPushNotificationConfigParams, h as DeleteTaskPushNotificationConfigResponse, i as TaskQueryParams, j as GetTaskResponse, C as CancelTaskResponse, J as JSONRPCResponse } from './types-Due_Cv6t.js';
|
|
2
|
+
|
|
3
|
+
type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
4
|
+
type SendMessageResult = Message | Task;
|
|
5
|
+
interface A2AClientOptions {
|
|
6
|
+
agentCardPath?: string;
|
|
7
|
+
fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A2AClient is a TypeScript HTTP client for interacting with A2A-compliant agents.
|
|
11
|
+
* Only JSON-RPC transport is supported.
|
|
12
|
+
*/
|
|
13
|
+
declare class A2AClient {
|
|
14
|
+
private static emptyOptions?;
|
|
15
|
+
private readonly agentCardPromise;
|
|
16
|
+
private readonly customFetchImpl?;
|
|
17
|
+
private serviceEndpointUrl?;
|
|
18
|
+
private transport?;
|
|
19
|
+
private requestIdCounter;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
22
|
+
* @param agentCard The AgentCard object.
|
|
23
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
24
|
+
*/
|
|
25
|
+
constructor(agentCard: AgentCard | string, options?: A2AClientOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
28
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
29
|
+
* @returns The fetch implementation.
|
|
30
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
31
|
+
* @throws If no fetch implementation is available.
|
|
32
|
+
*/
|
|
33
|
+
private _fetch;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
36
|
+
* @param agentCardUrl The URL of the agent card.
|
|
37
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
38
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
39
|
+
*/
|
|
40
|
+
static fromCardUrl(agentCardUrl: string, options?: A2AClientOptions): Promise<A2AClient>;
|
|
41
|
+
/**
|
|
42
|
+
* Sends a message to the agent.
|
|
43
|
+
* The behavior (blocking/non-blocking) and push notification configuration
|
|
44
|
+
* are specified within the `params.configuration` object.
|
|
45
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
46
|
+
* @param params The parameters for sending the message, including the message content and configuration.
|
|
47
|
+
* @returns A Promise resolving to SendMessageResponse, which can be a Message, Task, or an error.
|
|
48
|
+
*/
|
|
49
|
+
sendMessage(params: MessageSendParams): Promise<SendMessageResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a message to the agent and streams back responses using Server-Sent Events (SSE).
|
|
52
|
+
* Push notification configuration can be specified in `params.configuration`.
|
|
53
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
54
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
55
|
+
* @param params The parameters for sending the message.
|
|
56
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
57
|
+
* The generator throws an error if streaming is not supported or if an HTTP/SSE error occurs.
|
|
58
|
+
*/
|
|
59
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Sets or updates the push notification configuration for a given task.
|
|
62
|
+
* Requires the agent to support push notifications (`capabilities.pushNotifications: true` in AgentCard).
|
|
63
|
+
* @param params Parameters containing the taskId and the TaskPushNotificationConfig.
|
|
64
|
+
* @returns A Promise resolving to SetTaskPushNotificationConfigResponse.
|
|
65
|
+
*/
|
|
66
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<SetTaskPushNotificationConfigResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the push notification configuration for a given task.
|
|
69
|
+
* @param params Parameters containing the taskId.
|
|
70
|
+
* @returns A Promise resolving to GetTaskPushNotificationConfigResponse.
|
|
71
|
+
*/
|
|
72
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<GetTaskPushNotificationConfigResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Lists the push notification configurations for a given task.
|
|
75
|
+
* @param params Parameters containing the taskId.
|
|
76
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
77
|
+
*/
|
|
78
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams): Promise<ListTaskPushNotificationConfigResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Deletes the push notification configuration for a given task.
|
|
81
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
82
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
83
|
+
*/
|
|
84
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<DeleteTaskPushNotificationConfigResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a task by its ID.
|
|
87
|
+
* @param params Parameters containing the taskId and optional historyLength.
|
|
88
|
+
* @returns A Promise resolving to GetTaskResponse, which contains the Task object or an error.
|
|
89
|
+
*/
|
|
90
|
+
getTask(params: TaskQueryParams): Promise<GetTaskResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Cancels a task by its ID.
|
|
93
|
+
* @param params Parameters containing the taskId.
|
|
94
|
+
* @returns A Promise resolving to CancelTaskResponse, which contains the updated Task object or an error.
|
|
95
|
+
*/
|
|
96
|
+
cancelTask(params: TaskIdParams): Promise<CancelTaskResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
99
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
100
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
101
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
102
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
103
|
+
* @returns A Promise that resolves to the RPC response.
|
|
104
|
+
*/
|
|
105
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams): Promise<TExtensionResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
108
|
+
* This is used if a previous SSE connection for an active task was broken.
|
|
109
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
110
|
+
* @param params Parameters containing the taskId.
|
|
111
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
112
|
+
*/
|
|
113
|
+
resubscribeTask(params: TaskIdParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
114
|
+
private _getOrCreateTransport;
|
|
115
|
+
/**
|
|
116
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
117
|
+
* This method is called by the constructor.
|
|
118
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
119
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
120
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
121
|
+
*/
|
|
122
|
+
private _fetchAndCacheAgentCard;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves the Agent Card.
|
|
125
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
126
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
127
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
128
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
129
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
130
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
131
|
+
*/
|
|
132
|
+
getAgentCard(agentBaseUrl?: string, agentCardPath?: string): Promise<AgentCard>;
|
|
133
|
+
/**
|
|
134
|
+
* Determines the agent card URL based on the agent URL.
|
|
135
|
+
* @param agentBaseUrl The agent URL.
|
|
136
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
137
|
+
*/
|
|
138
|
+
private resolveAgentCardUrl;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
141
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
142
|
+
*/
|
|
143
|
+
private _getServiceEndpoint;
|
|
144
|
+
private invokeJsonRpc;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface HttpHeaders {
|
|
148
|
+
[key: string]: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generic interface for handling authentication for HTTP requests.
|
|
152
|
+
*
|
|
153
|
+
* - For each HTTP request, this handler is called to provide additional headers to the request through
|
|
154
|
+
* the headers() function.
|
|
155
|
+
* - After the server returns a response, the shouldRetryWithHeaders() function is called. Usually this
|
|
156
|
+
* function responds to a 401 or 403 response or JSON-RPC codes, but can respond to any other signal -
|
|
157
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
158
|
+
* - If the shouldRetryWithHeaders() function returns new headers, then the request should retried with the provided
|
|
159
|
+
* revised headers. These provisional headers may, or may not, be optimistically stored for subsequent requests -
|
|
160
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
161
|
+
* - If the request is successful and the onSuccessfulRetry() is defined, then the onSuccessfulRetry() function is
|
|
162
|
+
* called with the headers that were used to successfully complete the request. This callback provides an
|
|
163
|
+
* opportunity to save the headers for subsequent requests if they were not already saved.
|
|
164
|
+
*
|
|
165
|
+
*/
|
|
166
|
+
interface AuthenticationHandler {
|
|
167
|
+
/**
|
|
168
|
+
* Provides additional HTTP request headers.
|
|
169
|
+
* @returns HTTP headers which may include Authorization if available.
|
|
170
|
+
*/
|
|
171
|
+
headers: () => Promise<HttpHeaders>;
|
|
172
|
+
/**
|
|
173
|
+
* For every HTTP response (even 200s) the shouldRetryWithHeaders() method is called.
|
|
174
|
+
* This method is supposed to check if the request needs to be retried and if, yes,
|
|
175
|
+
* return a set of headers. An A2A server might indicate auth failures in its response
|
|
176
|
+
* by JSON-rpc codes, HTTP codes like 401, 403 or headers like WWW-Authenticate.
|
|
177
|
+
*
|
|
178
|
+
* @param req The RequestInit object used to invoke fetch()
|
|
179
|
+
* @param res The fetch Response object
|
|
180
|
+
* @returns If the HTTP request should be retried then returns the HTTP headers to use,
|
|
181
|
+
* or returns undefined if no retry should be made.
|
|
182
|
+
*/
|
|
183
|
+
shouldRetryWithHeaders: (req: RequestInit, res: Response) => Promise<HttpHeaders | undefined>;
|
|
184
|
+
/**
|
|
185
|
+
* If the last HTTP request using the headers from shouldRetryWithHeaders() was successful, and
|
|
186
|
+
* this function is implemented, then it will be called with the headers provided from
|
|
187
|
+
* shouldRetryWithHeaders().
|
|
188
|
+
*
|
|
189
|
+
* This callback allows transient headers to be saved for subsequent requests only when they
|
|
190
|
+
* are validated by the server.
|
|
191
|
+
*/
|
|
192
|
+
onSuccessfulRetry?: (headers: HttpHeaders) => Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Higher-order function that wraps fetch with authentication handling logic.
|
|
196
|
+
* Returns a new fetch function that automatically handles authentication retries for 401/403 responses.
|
|
197
|
+
*
|
|
198
|
+
* @param fetchImpl The underlying fetch implementation to wrap
|
|
199
|
+
* @param authHandler Authentication handler for managing auth headers and retries
|
|
200
|
+
* @returns A new fetch function with authentication handling capabilities
|
|
201
|
+
*
|
|
202
|
+
* Usage examples:
|
|
203
|
+
* - const authFetch = createAuthHandlingFetch(fetch, authHandler);
|
|
204
|
+
* - const response = await authFetch(url, options);
|
|
205
|
+
* - const response = await authFetch(url); // Direct function call
|
|
206
|
+
*/
|
|
207
|
+
declare function createAuthenticatingFetchWithRetry(fetchImpl: typeof fetch, authHandler: AuthenticationHandler): typeof fetch;
|
|
208
|
+
|
|
209
|
+
export { A2AClient as A, type HttpHeaders as H, type SendMessageResult as S, type A2AClientOptions as a, type AuthenticationHandler as b, createAuthenticatingFetchWithRetry as c, type A2AStreamEventData as d };
|