@mailmodo/a2a 0.3.3 → 0.3.7
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 +385 -173
- package/dist/a2a_request_handler-1Isk3l-0.d.mts +49 -0
- package/dist/a2a_request_handler-BuP9LgXH.d.ts +49 -0
- package/dist/chunk-7JFJW6P6.mjs +38 -0
- package/dist/chunk-AZGEDUZX.mjs +261 -0
- package/dist/chunk-BNBEZNW7.mjs +122 -0
- package/dist/chunk-PHP7LM4Y.mjs +8 -0
- package/dist/client/index.d.mts +666 -0
- package/dist/client/index.d.ts +666 -0
- package/dist/client/index.js +1605 -0
- package/dist/client/index.mjs +1448 -0
- package/dist/extensions-DvruCIzw.d.mts +2589 -0
- package/dist/extensions-DvruCIzw.d.ts +2589 -0
- package/dist/index.d.mts +5 -2758
- package/dist/index.d.ts +5 -2758
- package/dist/index.js +28 -1637
- package/dist/index.mjs +9 -1628
- package/dist/server/express/index.d.mts +97 -0
- package/dist/server/express/index.d.ts +97 -0
- package/dist/server/express/index.js +994 -0
- package/dist/server/express/index.mjs +646 -0
- package/dist/server/index.d.mts +316 -0
- package/dist/server/index.d.ts +316 -0
- package/dist/server/index.js +1386 -0
- package/dist/server/index.mjs +1070 -0
- package/package.json +51 -22
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { ae as AgentCard, x as MessageSendParams, S as SendMessageResponse, F as Message, ay as Task, aQ as TaskStatusUpdateEvent, aS as TaskArtifactUpdateEvent, $ as TaskPushNotificationConfig, b as SetTaskPushNotificationConfigResponse, Z as TaskIdParams, c as GetTaskPushNotificationConfigResponse, a7 as ListTaskPushNotificationConfigParams, k as ListTaskPushNotificationConfigResponse, a9 as DeleteTaskPushNotificationConfigParams, h as DeleteTaskPushNotificationConfigResponse, X as TaskQueryParams, G as GetTaskResponse, C as CancelTaskResponse, j as JSONRPCResponse, E as Extensions, a3 as GetTaskPushNotificationConfigParams, z as PushNotificationConfig } from '../extensions-DvruCIzw.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
|
+
* @deprecated Use {@link ClientFactory}
|
|
13
|
+
*/
|
|
14
|
+
declare class A2AClient {
|
|
15
|
+
private static emptyOptions?;
|
|
16
|
+
private readonly agentCardPromise;
|
|
17
|
+
private readonly customFetchImpl?;
|
|
18
|
+
private serviceEndpointUrl?;
|
|
19
|
+
private transport?;
|
|
20
|
+
private requestIdCounter;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
23
|
+
* @param agentCard The AgentCard object.
|
|
24
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
25
|
+
*/
|
|
26
|
+
constructor(agentCard: AgentCard | string, options?: A2AClientOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
29
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
30
|
+
* @returns The fetch implementation.
|
|
31
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
32
|
+
* @throws If no fetch implementation is available.
|
|
33
|
+
*/
|
|
34
|
+
private _fetch;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
37
|
+
* @param agentCardUrl The URL of the agent card.
|
|
38
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
39
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
40
|
+
*/
|
|
41
|
+
static fromCardUrl(agentCardUrl: string, options?: A2AClientOptions): Promise<A2AClient>;
|
|
42
|
+
/**
|
|
43
|
+
* Sends a message to the agent.
|
|
44
|
+
* The behavior (blocking/non-blocking) and push notification configuration
|
|
45
|
+
* are specified within the `params.configuration` object.
|
|
46
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
47
|
+
* @param params The parameters for sending the message, including the message content and configuration.
|
|
48
|
+
* @returns A Promise resolving to SendMessageResponse, which can be a Message, Task, or an error.
|
|
49
|
+
*/
|
|
50
|
+
sendMessage(params: MessageSendParams): Promise<SendMessageResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Sends a message to the agent and streams back responses using Server-Sent Events (SSE).
|
|
53
|
+
* Push notification configuration can be specified in `params.configuration`.
|
|
54
|
+
* Optionally, `params.message.contextId` or `params.message.taskId` can be provided.
|
|
55
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
56
|
+
* @param params The parameters for sending the message.
|
|
57
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
58
|
+
* The generator throws an error if streaming is not supported or if an HTTP/SSE error occurs.
|
|
59
|
+
*/
|
|
60
|
+
sendMessageStream(params: MessageSendParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Sets or updates the push notification configuration for a given task.
|
|
63
|
+
* Requires the agent to support push notifications (`capabilities.pushNotifications: true` in AgentCard).
|
|
64
|
+
* @param params Parameters containing the taskId and the TaskPushNotificationConfig.
|
|
65
|
+
* @returns A Promise resolving to SetTaskPushNotificationConfigResponse.
|
|
66
|
+
*/
|
|
67
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig): Promise<SetTaskPushNotificationConfigResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the push notification configuration for a given task.
|
|
70
|
+
* @param params Parameters containing the taskId.
|
|
71
|
+
* @returns A Promise resolving to GetTaskPushNotificationConfigResponse.
|
|
72
|
+
*/
|
|
73
|
+
getTaskPushNotificationConfig(params: TaskIdParams): Promise<GetTaskPushNotificationConfigResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Lists the push notification configurations for a given task.
|
|
76
|
+
* @param params Parameters containing the taskId.
|
|
77
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
78
|
+
*/
|
|
79
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams): Promise<ListTaskPushNotificationConfigResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Deletes the push notification configuration for a given task.
|
|
82
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
83
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
84
|
+
*/
|
|
85
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<DeleteTaskPushNotificationConfigResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves a task by its ID.
|
|
88
|
+
* @param params Parameters containing the taskId and optional historyLength.
|
|
89
|
+
* @returns A Promise resolving to GetTaskResponse, which contains the Task object or an error.
|
|
90
|
+
*/
|
|
91
|
+
getTask(params: TaskQueryParams): Promise<GetTaskResponse>;
|
|
92
|
+
/**
|
|
93
|
+
* Cancels a task by its ID.
|
|
94
|
+
* @param params Parameters containing the taskId.
|
|
95
|
+
* @returns A Promise resolving to CancelTaskResponse, which contains the updated Task object or an error.
|
|
96
|
+
*/
|
|
97
|
+
cancelTask(params: TaskIdParams): Promise<CancelTaskResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
100
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
101
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
102
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
103
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
104
|
+
* @returns A Promise that resolves to the RPC response.
|
|
105
|
+
*/
|
|
106
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams): Promise<TExtensionResponse>;
|
|
107
|
+
/**
|
|
108
|
+
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
109
|
+
* This is used if a previous SSE connection for an active task was broken.
|
|
110
|
+
* Requires the agent to support streaming (`capabilities.streaming: true` in AgentCard).
|
|
111
|
+
* @param params Parameters containing the taskId.
|
|
112
|
+
* @returns An AsyncGenerator yielding A2AStreamEventData (Message, Task, TaskStatusUpdateEvent, or TaskArtifactUpdateEvent).
|
|
113
|
+
*/
|
|
114
|
+
resubscribeTask(params: TaskIdParams): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
115
|
+
private _getOrCreateTransport;
|
|
116
|
+
/**
|
|
117
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
118
|
+
* This method is called by the constructor.
|
|
119
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
120
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
121
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
122
|
+
*/
|
|
123
|
+
private _fetchAndCacheAgentCard;
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves the Agent Card.
|
|
126
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
127
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
128
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
129
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
130
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
131
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
132
|
+
*/
|
|
133
|
+
getAgentCard(agentBaseUrl?: string, agentCardPath?: string): Promise<AgentCard>;
|
|
134
|
+
/**
|
|
135
|
+
* Determines the agent card URL based on the agent URL.
|
|
136
|
+
* @param agentBaseUrl The agent URL.
|
|
137
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
138
|
+
*/
|
|
139
|
+
private resolveAgentCardUrl;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
142
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
143
|
+
*/
|
|
144
|
+
private _getServiceEndpoint;
|
|
145
|
+
private invokeJsonRpc;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface HttpHeaders {
|
|
149
|
+
[key: string]: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Generic interface for handling authentication for HTTP requests.
|
|
153
|
+
*
|
|
154
|
+
* - For each HTTP request, this handler is called to provide additional headers to the request through
|
|
155
|
+
* the headers() function.
|
|
156
|
+
* - After the server returns a response, the shouldRetryWithHeaders() function is called. Usually this
|
|
157
|
+
* function responds to a 401 or 403 response or JSON-RPC codes, but can respond to any other signal -
|
|
158
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
159
|
+
* - If the shouldRetryWithHeaders() function returns new headers, then the request should retried with the provided
|
|
160
|
+
* revised headers. These provisional headers may, or may not, be optimistically stored for subsequent requests -
|
|
161
|
+
* that is an implementation detail of the AuthenticationHandler.
|
|
162
|
+
* - If the request is successful and the onSuccessfulRetry() is defined, then the onSuccessfulRetry() function is
|
|
163
|
+
* called with the headers that were used to successfully complete the request. This callback provides an
|
|
164
|
+
* opportunity to save the headers for subsequent requests if they were not already saved.
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
interface AuthenticationHandler {
|
|
168
|
+
/**
|
|
169
|
+
* Provides additional HTTP request headers.
|
|
170
|
+
* @returns HTTP headers which may include Authorization if available.
|
|
171
|
+
*/
|
|
172
|
+
headers: () => Promise<HttpHeaders>;
|
|
173
|
+
/**
|
|
174
|
+
* For every HTTP response (even 200s) the shouldRetryWithHeaders() method is called.
|
|
175
|
+
* This method is supposed to check if the request needs to be retried and if, yes,
|
|
176
|
+
* return a set of headers. An A2A server might indicate auth failures in its response
|
|
177
|
+
* by JSON-rpc codes, HTTP codes like 401, 403 or headers like WWW-Authenticate.
|
|
178
|
+
*
|
|
179
|
+
* @param req The RequestInit object used to invoke fetch()
|
|
180
|
+
* @param res The fetch Response object
|
|
181
|
+
* @returns If the HTTP request should be retried then returns the HTTP headers to use,
|
|
182
|
+
* or returns undefined if no retry should be made.
|
|
183
|
+
*/
|
|
184
|
+
shouldRetryWithHeaders: (req: RequestInit, res: Response) => Promise<HttpHeaders | undefined>;
|
|
185
|
+
/**
|
|
186
|
+
* If the last HTTP request using the headers from shouldRetryWithHeaders() was successful, and
|
|
187
|
+
* this function is implemented, then it will be called with the headers provided from
|
|
188
|
+
* shouldRetryWithHeaders().
|
|
189
|
+
*
|
|
190
|
+
* This callback allows transient headers to be saved for subsequent requests only when they
|
|
191
|
+
* are validated by the server.
|
|
192
|
+
*/
|
|
193
|
+
onSuccessfulRetry?: (headers: HttpHeaders) => Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Higher-order function that wraps fetch with authentication handling logic.
|
|
197
|
+
* Returns a new fetch function that automatically handles authentication retries for 401/403 responses.
|
|
198
|
+
*
|
|
199
|
+
* @param fetchImpl The underlying fetch implementation to wrap
|
|
200
|
+
* @param authHandler Authentication handler for managing auth headers and retries
|
|
201
|
+
* @returns A new fetch function with authentication handling capabilities
|
|
202
|
+
*
|
|
203
|
+
* Usage examples:
|
|
204
|
+
* - const authFetch = createAuthHandlingFetch(fetch, authHandler);
|
|
205
|
+
* - const response = await authFetch(url, options);
|
|
206
|
+
* - const response = await authFetch(url); // Direct function call
|
|
207
|
+
*/
|
|
208
|
+
declare function createAuthenticatingFetchWithRetry(fetchImpl: typeof fetch, authHandler: AuthenticationHandler): typeof fetch;
|
|
209
|
+
|
|
210
|
+
interface AgentCardResolverOptions {
|
|
211
|
+
path?: string;
|
|
212
|
+
fetchImpl?: typeof fetch;
|
|
213
|
+
}
|
|
214
|
+
declare class DefaultAgentCardResolver implements AgentCardResolver {
|
|
215
|
+
readonly options?: AgentCardResolverOptions;
|
|
216
|
+
constructor(options?: AgentCardResolverOptions);
|
|
217
|
+
/**
|
|
218
|
+
* Fetches the agent card based on provided base URL and path.
|
|
219
|
+
* Path is selected in the following order:
|
|
220
|
+
* 1) path parameter
|
|
221
|
+
* 2) path from options
|
|
222
|
+
* 3) .well-known/agent-card.json
|
|
223
|
+
*/
|
|
224
|
+
resolve(baseUrl: string, path?: string): Promise<AgentCard>;
|
|
225
|
+
private fetchImpl;
|
|
226
|
+
}
|
|
227
|
+
interface AgentCardResolver {
|
|
228
|
+
/**
|
|
229
|
+
* Fetches the agent card based on provided base URL and path,
|
|
230
|
+
*/
|
|
231
|
+
resolve(baseUrl: string, path?: string): Promise<AgentCard>;
|
|
232
|
+
}
|
|
233
|
+
declare const AgentCardResolver: {
|
|
234
|
+
default: DefaultAgentCardResolver;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Function that applies an update to a {@link ClientCallContext}.
|
|
239
|
+
*/
|
|
240
|
+
type ContextUpdate = (context: ClientCallContext) => void;
|
|
241
|
+
/**
|
|
242
|
+
* Opaque context object to carry per-call context data.
|
|
243
|
+
* Use {@link ClientCallContextKey} to create typed keys for storing and retrieving values.
|
|
244
|
+
*/
|
|
245
|
+
type ClientCallContext = Record<symbol, unknown>;
|
|
246
|
+
declare const ClientCallContext: {
|
|
247
|
+
/**
|
|
248
|
+
* Create a new {@link ClientCallContext} with optional updates applied.
|
|
249
|
+
*/
|
|
250
|
+
create: (...updates: ContextUpdate[]) => ClientCallContext;
|
|
251
|
+
/**
|
|
252
|
+
* Create a new {@link ClientCallContext} based on an existing one with updates applied.
|
|
253
|
+
*/
|
|
254
|
+
createFrom: (context: ClientCallContext | undefined, ...updates: ContextUpdate[]) => ClientCallContext;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Each instance represents a unique key for storing
|
|
258
|
+
* and retrieving typed values in a {@link ClientCallContext}.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* const key = new ClientCallContextKey<string>('My key');
|
|
263
|
+
* const context = ClientCallContext.create(key.set('example-value'));
|
|
264
|
+
* const value = key.get(context); // 'example-value'
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare class ClientCallContextKey<T> {
|
|
268
|
+
readonly symbol: symbol;
|
|
269
|
+
constructor(description: string);
|
|
270
|
+
set(value: T): ContextUpdate;
|
|
271
|
+
get(context: ClientCallContext): T | undefined;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
interface CallInterceptor {
|
|
275
|
+
/**
|
|
276
|
+
* Invoked before transport method.
|
|
277
|
+
*/
|
|
278
|
+
before(args: BeforeArgs): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Invoked after transport method.
|
|
281
|
+
*/
|
|
282
|
+
after(args: AfterArgs): Promise<void>;
|
|
283
|
+
}
|
|
284
|
+
interface BeforeArgs<K extends keyof Client = keyof Client> {
|
|
285
|
+
/**
|
|
286
|
+
* Identifies the client method invoked and its payload.
|
|
287
|
+
* Payload inside the input object can be modified.
|
|
288
|
+
*/
|
|
289
|
+
readonly input: ClientCallInput<K>;
|
|
290
|
+
/**
|
|
291
|
+
* Identifies the agent card cached on the client
|
|
292
|
+
*/
|
|
293
|
+
readonly agentCard: AgentCard;
|
|
294
|
+
/**
|
|
295
|
+
* If set by the interceptor, stops execution, invokes "after"
|
|
296
|
+
* for executed interceptors and returns the result. Transport is not called.
|
|
297
|
+
*/
|
|
298
|
+
earlyReturn?: ClientCallResult<K>;
|
|
299
|
+
/**
|
|
300
|
+
* Options passed to the client.
|
|
301
|
+
*/
|
|
302
|
+
options?: RequestOptions;
|
|
303
|
+
}
|
|
304
|
+
interface AfterArgs<K extends keyof Client = keyof Client> {
|
|
305
|
+
/**
|
|
306
|
+
* Identifies the client method invoked and its result.
|
|
307
|
+
* Payload inside the result object can be modified.
|
|
308
|
+
*/
|
|
309
|
+
readonly result: ClientCallResult<K>;
|
|
310
|
+
/**
|
|
311
|
+
* Identifies the agent card cached on the client
|
|
312
|
+
*/
|
|
313
|
+
readonly agentCard: AgentCard;
|
|
314
|
+
/**
|
|
315
|
+
* If set by the interceptor, stops execution and returns result value,
|
|
316
|
+
* remaining interceptors are not executed.
|
|
317
|
+
*/
|
|
318
|
+
earlyReturn?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Options passed to the client.
|
|
321
|
+
*/
|
|
322
|
+
options?: RequestOptions;
|
|
323
|
+
}
|
|
324
|
+
type ClientCallInput<K extends keyof Client = keyof Client> = MethodInput<Client, K>;
|
|
325
|
+
type ClientCallResult<K extends keyof Client = keyof Client> = MethodResult<Client, K, ResultsOverrides>;
|
|
326
|
+
/**
|
|
327
|
+
* For
|
|
328
|
+
*
|
|
329
|
+
* interface Foo {
|
|
330
|
+
* f1(arg: string): Promise<Result1>;
|
|
331
|
+
* f2(arg: number): Promise<Result2>;
|
|
332
|
+
* }
|
|
333
|
+
*
|
|
334
|
+
* MethodInputs<Foo> resolves to
|
|
335
|
+
*
|
|
336
|
+
* {
|
|
337
|
+
* readonly method: "f1";
|
|
338
|
+
* value: string;
|
|
339
|
+
* } | {
|
|
340
|
+
* readonly method: "f2";
|
|
341
|
+
* value: number;
|
|
342
|
+
* }
|
|
343
|
+
*/
|
|
344
|
+
type MethodInput<T, TMembers extends keyof T = keyof T> = {
|
|
345
|
+
[M in TMembers]: T[M] extends (options: RequestOptions | undefined) => unknown ? {
|
|
346
|
+
readonly method: M;
|
|
347
|
+
value?: never;
|
|
348
|
+
} : T[M] extends (payload: infer P) => unknown ? {
|
|
349
|
+
readonly method: M;
|
|
350
|
+
value: P;
|
|
351
|
+
} : never;
|
|
352
|
+
}[TMembers];
|
|
353
|
+
/**
|
|
354
|
+
* For
|
|
355
|
+
*
|
|
356
|
+
* interface Foo {
|
|
357
|
+
* f1(): Promise<Result1>;
|
|
358
|
+
* f2(): Promise<Result2>;
|
|
359
|
+
* }
|
|
360
|
+
*
|
|
361
|
+
* MethodsResults<Foo> resolves to
|
|
362
|
+
*
|
|
363
|
+
* {
|
|
364
|
+
* readonly method: "f1";
|
|
365
|
+
* value: Result1;
|
|
366
|
+
* } | {
|
|
367
|
+
* readonly method: "f2";
|
|
368
|
+
* value: Result2;
|
|
369
|
+
* }
|
|
370
|
+
*/
|
|
371
|
+
type MethodResult<T, TMembers extends keyof T = keyof T, TOverrides = object> = {
|
|
372
|
+
[M in TMembers]: M extends keyof TOverrides ? {
|
|
373
|
+
readonly method: M;
|
|
374
|
+
value: TOverrides[M];
|
|
375
|
+
} : T[M] extends (payload: unknown) => infer R ? {
|
|
376
|
+
readonly method: M;
|
|
377
|
+
value: Awaited<R>;
|
|
378
|
+
} : never;
|
|
379
|
+
}[TMembers];
|
|
380
|
+
interface ResultsOverrides {
|
|
381
|
+
sendMessageStream: A2AStreamEventData;
|
|
382
|
+
resubscribeTask: A2AStreamEventData;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
type ServiceParametersUpdate = (parameters: ServiceParameters) => void;
|
|
386
|
+
type ServiceParameters = Record<string, string>;
|
|
387
|
+
declare const ServiceParameters: {
|
|
388
|
+
create(...updates: ServiceParametersUpdate[]): ServiceParameters;
|
|
389
|
+
createFrom: (serviceParameters: ServiceParameters | undefined, ...updates: ServiceParametersUpdate[]) => ServiceParameters;
|
|
390
|
+
};
|
|
391
|
+
declare function withA2AExtensions(...extensions: Extensions): ServiceParametersUpdate;
|
|
392
|
+
|
|
393
|
+
interface Transport {
|
|
394
|
+
getExtendedAgentCard(options?: RequestOptions): Promise<AgentCard>;
|
|
395
|
+
sendMessage(params: MessageSendParams, options?: RequestOptions): Promise<SendMessageResult>;
|
|
396
|
+
sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
397
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
398
|
+
getTaskPushNotificationConfig(params: GetTaskPushNotificationConfigParams, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
399
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions): Promise<TaskPushNotificationConfig[]>;
|
|
400
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions): Promise<void>;
|
|
401
|
+
getTask(params: TaskQueryParams, options?: RequestOptions): Promise<Task>;
|
|
402
|
+
cancelTask(params: TaskIdParams, options?: RequestOptions): Promise<Task>;
|
|
403
|
+
resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
404
|
+
}
|
|
405
|
+
interface TransportFactory {
|
|
406
|
+
get protocolName(): string;
|
|
407
|
+
create(url: string, agentCard: AgentCard): Promise<Transport>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
interface ClientConfig {
|
|
411
|
+
/**
|
|
412
|
+
* Whether client prefers to poll for task updates instead of blocking until a terminal state is reached.
|
|
413
|
+
* If set to true, non-streaming send message result might be a Message or a Task in any (including non-terminal) state.
|
|
414
|
+
* Callers are responsible for running the polling loop. This configuration does not apply to streaming requests.
|
|
415
|
+
*/
|
|
416
|
+
polling?: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Specifies the default list of accepted media types to apply for all "send message" calls.
|
|
419
|
+
*/
|
|
420
|
+
acceptedOutputModes?: string[];
|
|
421
|
+
/**
|
|
422
|
+
* Specifies the default push notification configuration to apply for every Task.
|
|
423
|
+
*/
|
|
424
|
+
pushNotificationConfig?: PushNotificationConfig;
|
|
425
|
+
/**
|
|
426
|
+
* Interceptors invoked for each request.
|
|
427
|
+
*/
|
|
428
|
+
interceptors?: CallInterceptor[];
|
|
429
|
+
}
|
|
430
|
+
interface RequestOptions {
|
|
431
|
+
/**
|
|
432
|
+
* Signal to abort request execution.
|
|
433
|
+
*/
|
|
434
|
+
signal?: AbortSignal;
|
|
435
|
+
/**
|
|
436
|
+
* A key-value map for passing horizontally applicable context or parameters.
|
|
437
|
+
* All parameters are passed to the server via underlying transports (e.g. In JsonRPC via Headers).
|
|
438
|
+
*/
|
|
439
|
+
serviceParameters?: ServiceParameters;
|
|
440
|
+
/**
|
|
441
|
+
* Arbitrary data available to interceptors and transport implementation.
|
|
442
|
+
*/
|
|
443
|
+
context?: ClientCallContext;
|
|
444
|
+
}
|
|
445
|
+
declare class Client {
|
|
446
|
+
readonly transport: Transport;
|
|
447
|
+
private agentCard;
|
|
448
|
+
readonly config?: ClientConfig;
|
|
449
|
+
constructor(transport: Transport, agentCard: AgentCard, config?: ClientConfig);
|
|
450
|
+
/**
|
|
451
|
+
* If the current agent card supports the extended feature, it will try to fetch the extended agent card from the server,
|
|
452
|
+
* Otherwise it will return the current agent card value.
|
|
453
|
+
*/
|
|
454
|
+
getAgentCard(options?: RequestOptions): Promise<AgentCard>;
|
|
455
|
+
/**
|
|
456
|
+
* Sends a message to an agent to initiate a new interaction or to continue an existing one.
|
|
457
|
+
* Uses blocking mode by default.
|
|
458
|
+
*/
|
|
459
|
+
sendMessage(params: MessageSendParams, options?: RequestOptions): Promise<SendMessageResult>;
|
|
460
|
+
/**
|
|
461
|
+
* Sends a message to an agent to initiate/continue a task AND subscribes the client to real-time updates for that task.
|
|
462
|
+
* Performs fallback to non-streaming if not supported by the agent.
|
|
463
|
+
*/
|
|
464
|
+
sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
465
|
+
/**
|
|
466
|
+
* Sets or updates the push notification configuration for a specified task.
|
|
467
|
+
* Requires the server to have AgentCard.capabilities.pushNotifications: true.
|
|
468
|
+
*/
|
|
469
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
470
|
+
/**
|
|
471
|
+
* Retrieves the current push notification configuration for a specified task.
|
|
472
|
+
* Requires the server to have AgentCard.capabilities.pushNotifications: true.
|
|
473
|
+
*/
|
|
474
|
+
getTaskPushNotificationConfig(params: TaskIdParams, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
475
|
+
/**
|
|
476
|
+
* Retrieves the associated push notification configurations for a specified task.
|
|
477
|
+
* Requires the server to have AgentCard.capabilities.pushNotifications: true.
|
|
478
|
+
*/
|
|
479
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions): Promise<TaskPushNotificationConfig[]>;
|
|
480
|
+
/**
|
|
481
|
+
* Deletes an associated push notification configuration for a task.
|
|
482
|
+
*/
|
|
483
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions): Promise<void>;
|
|
484
|
+
/**
|
|
485
|
+
* Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task.
|
|
486
|
+
*/
|
|
487
|
+
getTask(params: TaskQueryParams, options?: RequestOptions): Promise<Task>;
|
|
488
|
+
/**
|
|
489
|
+
* Requests the cancellation of an ongoing task. The server will attempt to cancel the task,
|
|
490
|
+
* but success is not guaranteed (e.g., the task might have already completed or failed, or cancellation might not be supported at its current stage).
|
|
491
|
+
*/
|
|
492
|
+
cancelTask(params: TaskIdParams, options?: RequestOptions): Promise<Task>;
|
|
493
|
+
/**
|
|
494
|
+
* Allows a client to reconnect to an updates stream for an ongoing task after a previous connection was interrupted.
|
|
495
|
+
*/
|
|
496
|
+
resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
497
|
+
private applyClientConfig;
|
|
498
|
+
private executeWithInterceptors;
|
|
499
|
+
private interceptBefore;
|
|
500
|
+
private interceptAfter;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
type TransportProtocolName = 'JSONRPC' | 'HTTP+JSON' | 'GRPC' | (string & {});
|
|
504
|
+
|
|
505
|
+
interface ClientFactoryOptions {
|
|
506
|
+
/**
|
|
507
|
+
* Transport factories to use.
|
|
508
|
+
* Effectively defines transports supported by this client factory.
|
|
509
|
+
*/
|
|
510
|
+
transports: TransportFactory[];
|
|
511
|
+
/**
|
|
512
|
+
* Client config to be used for clients created by this factory.
|
|
513
|
+
*/
|
|
514
|
+
clientConfig?: ClientConfig;
|
|
515
|
+
/**
|
|
516
|
+
* Transport preferences to override ones defined by the agent card.
|
|
517
|
+
* If no matches are found among preferred transports, agent card values are used next.
|
|
518
|
+
*/
|
|
519
|
+
preferredTransports?: TransportProtocolName[];
|
|
520
|
+
/**
|
|
521
|
+
* Used for createFromAgentCardUrl to download agent card.
|
|
522
|
+
*/
|
|
523
|
+
cardResolver?: AgentCardResolver;
|
|
524
|
+
}
|
|
525
|
+
declare const ClientFactoryOptions: {
|
|
526
|
+
/**
|
|
527
|
+
* SDK default options for {@link ClientFactory}.
|
|
528
|
+
*/
|
|
529
|
+
default: Readonly<ClientFactoryOptions>;
|
|
530
|
+
/**
|
|
531
|
+
* Creates new options by merging an original and an override object.
|
|
532
|
+
* Transports are merged based on `TransportFactory.protocolName`,
|
|
533
|
+
* interceptors are concatenated, other fields are overriden.
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* ```ts
|
|
537
|
+
* const options = ClientFactoryOptions.createFrom(ClientFactoryOptions.default, {
|
|
538
|
+
* transports: [new MyCustomTransportFactory()], // adds a custom transport
|
|
539
|
+
* clientConfig: { interceptors: [new MyInterceptor()] }, // adds a custom interceptor
|
|
540
|
+
* });
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
createFrom(original: ClientFactoryOptions, overrides: Partial<ClientFactoryOptions>): ClientFactoryOptions;
|
|
544
|
+
};
|
|
545
|
+
declare class ClientFactory {
|
|
546
|
+
readonly options: ClientFactoryOptions;
|
|
547
|
+
private readonly transportsByName;
|
|
548
|
+
private readonly agentCardResolver;
|
|
549
|
+
constructor(options?: ClientFactoryOptions);
|
|
550
|
+
/**
|
|
551
|
+
* Creates a new client from the provided agent card.
|
|
552
|
+
*/
|
|
553
|
+
createFromAgentCard(agentCard: AgentCard): Promise<Client>;
|
|
554
|
+
/**
|
|
555
|
+
* Downloads agent card using AgentCardResolver from options
|
|
556
|
+
* and creates a new client from the downloaded card.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* const factory = new ClientFactory(); // use default options and default {@link AgentCardResolver}.
|
|
561
|
+
* const client1 = await factory.createFromUrl('https://example.com'); // /.well-known/agent-card.json is used by default
|
|
562
|
+
* const client2 = await factory.createFromUrl('https://example.com', '/my-agent-card.json'); // specify custom path
|
|
563
|
+
* const client3 = await factory.createFromUrl('https://example.com/my-agent-card.json', ''); // specify full URL and set path to empty
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
createFromUrl(baseUrl: string, path?: string): Promise<Client>;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
declare class TaskNotFoundError extends Error {
|
|
570
|
+
constructor(message?: string);
|
|
571
|
+
}
|
|
572
|
+
declare class TaskNotCancelableError extends Error {
|
|
573
|
+
constructor(message?: string);
|
|
574
|
+
}
|
|
575
|
+
declare class PushNotificationNotSupportedError extends Error {
|
|
576
|
+
constructor(message?: string);
|
|
577
|
+
}
|
|
578
|
+
declare class UnsupportedOperationError extends Error {
|
|
579
|
+
constructor(message?: string);
|
|
580
|
+
}
|
|
581
|
+
declare class ContentTypeNotSupportedError extends Error {
|
|
582
|
+
constructor(message?: string);
|
|
583
|
+
}
|
|
584
|
+
declare class InvalidAgentResponseError extends Error {
|
|
585
|
+
constructor(message?: string);
|
|
586
|
+
}
|
|
587
|
+
declare class AuthenticatedExtendedCardNotConfiguredError extends Error {
|
|
588
|
+
constructor(message?: string);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
interface JsonRpcTransportOptions {
|
|
592
|
+
endpoint: string;
|
|
593
|
+
fetchImpl?: typeof fetch;
|
|
594
|
+
}
|
|
595
|
+
declare class JsonRpcTransport implements Transport {
|
|
596
|
+
private readonly customFetchImpl?;
|
|
597
|
+
private readonly endpoint;
|
|
598
|
+
private requestIdCounter;
|
|
599
|
+
constructor(options: JsonRpcTransportOptions);
|
|
600
|
+
getExtendedAgentCard(options?: RequestOptions, idOverride?: number): Promise<AgentCard>;
|
|
601
|
+
sendMessage(params: MessageSendParams, options?: RequestOptions, idOverride?: number): Promise<SendMessageResult>;
|
|
602
|
+
sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
603
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions, idOverride?: number): Promise<TaskPushNotificationConfig>;
|
|
604
|
+
getTaskPushNotificationConfig(params: GetTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise<TaskPushNotificationConfig>;
|
|
605
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise<TaskPushNotificationConfig[]>;
|
|
606
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions, idOverride?: number): Promise<void>;
|
|
607
|
+
getTask(params: TaskQueryParams, options?: RequestOptions, idOverride?: number): Promise<Task>;
|
|
608
|
+
cancelTask(params: TaskIdParams, options?: RequestOptions, idOverride?: number): Promise<Task>;
|
|
609
|
+
resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
610
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams, idOverride: number, options?: RequestOptions): Promise<TExtensionResponse>;
|
|
611
|
+
private _fetch;
|
|
612
|
+
private _sendRpcRequest;
|
|
613
|
+
private _fetchRpc;
|
|
614
|
+
private _sendStreamingRequest;
|
|
615
|
+
private _processSseEventData;
|
|
616
|
+
private static mapToError;
|
|
617
|
+
}
|
|
618
|
+
declare class JsonRpcTransportFactoryOptions {
|
|
619
|
+
fetchImpl?: typeof fetch;
|
|
620
|
+
}
|
|
621
|
+
declare class JsonRpcTransportFactory implements TransportFactory {
|
|
622
|
+
private readonly options?;
|
|
623
|
+
static readonly name: TransportProtocolName;
|
|
624
|
+
constructor(options?: JsonRpcTransportFactoryOptions);
|
|
625
|
+
get protocolName(): string;
|
|
626
|
+
create(url: string, _agentCard: AgentCard): Promise<Transport>;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
interface RestTransportOptions {
|
|
630
|
+
endpoint: string;
|
|
631
|
+
fetchImpl?: typeof fetch;
|
|
632
|
+
}
|
|
633
|
+
declare class RestTransport implements Transport {
|
|
634
|
+
private readonly customFetchImpl?;
|
|
635
|
+
private readonly endpoint;
|
|
636
|
+
constructor(options: RestTransportOptions);
|
|
637
|
+
getExtendedAgentCard(options?: RequestOptions): Promise<AgentCard>;
|
|
638
|
+
sendMessage(params: MessageSendParams, options?: RequestOptions): Promise<SendMessageResult>;
|
|
639
|
+
sendMessageStream(params: MessageSendParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
640
|
+
setTaskPushNotificationConfig(params: TaskPushNotificationConfig, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
641
|
+
getTaskPushNotificationConfig(params: GetTaskPushNotificationConfigParams, options?: RequestOptions): Promise<TaskPushNotificationConfig>;
|
|
642
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams, options?: RequestOptions): Promise<TaskPushNotificationConfig[]>;
|
|
643
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, options?: RequestOptions): Promise<void>;
|
|
644
|
+
getTask(params: TaskQueryParams, options?: RequestOptions): Promise<Task>;
|
|
645
|
+
cancelTask(params: TaskIdParams, options?: RequestOptions): Promise<Task>;
|
|
646
|
+
resubscribeTask(params: TaskIdParams, options?: RequestOptions): AsyncGenerator<A2AStreamEventData, void, undefined>;
|
|
647
|
+
private _fetch;
|
|
648
|
+
private _buildHeaders;
|
|
649
|
+
private _sendRequest;
|
|
650
|
+
private _handleErrorResponse;
|
|
651
|
+
private _sendStreamingRequest;
|
|
652
|
+
private _processSseEventData;
|
|
653
|
+
private static mapToError;
|
|
654
|
+
}
|
|
655
|
+
interface RestTransportFactoryOptions {
|
|
656
|
+
fetchImpl?: typeof fetch;
|
|
657
|
+
}
|
|
658
|
+
declare class RestTransportFactory implements TransportFactory {
|
|
659
|
+
private readonly options?;
|
|
660
|
+
static readonly name: TransportProtocolName;
|
|
661
|
+
constructor(options?: RestTransportFactoryOptions);
|
|
662
|
+
get protocolName(): string;
|
|
663
|
+
create(url: string, _agentCard: AgentCard): Promise<Transport>;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export { A2AClient, type A2AClientOptions, type AfterArgs, AgentCardResolver, type AgentCardResolverOptions, AuthenticatedExtendedCardNotConfiguredError, type AuthenticationHandler, type BeforeArgs, type CallInterceptor, Client, ClientCallContext, ClientCallContextKey, type ClientCallInput, type ClientCallResult, type ClientConfig, ClientFactory, ClientFactoryOptions, ContentTypeNotSupportedError, type ContextUpdate, DefaultAgentCardResolver, type HttpHeaders, InvalidAgentResponseError, JsonRpcTransport, JsonRpcTransportFactory, type JsonRpcTransportOptions, PushNotificationNotSupportedError, type RequestOptions, RestTransport, RestTransportFactory, type RestTransportOptions, ServiceParameters, type ServiceParametersUpdate, TaskNotCancelableError, TaskNotFoundError, type Transport, type TransportFactory, UnsupportedOperationError, createAuthenticatingFetchWithRetry, withA2AExtensions };
|