@a2a-js/sdk 0.3.2 → 0.3.4
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 +506 -314
- package/dist/client/index.cjs +171 -71
- package/dist/client/index.d.cts +67 -34
- package/dist/client/index.d.ts +67 -34
- package/dist/client/index.js +171 -71
- package/dist/server/index.cjs +136 -19
- package/dist/server/index.d.cts +40 -4
- package/dist/server/index.d.ts +40 -4
- package/dist/server/index.js +134 -19
- package/package.json +4 -4
package/dist/client/index.cjs
CHANGED
|
@@ -28,94 +28,80 @@ module.exports = __toCommonJS(client_exports);
|
|
|
28
28
|
var AGENT_CARD_PATH = ".well-known/agent-card.json";
|
|
29
29
|
|
|
30
30
|
// src/client/client.ts
|
|
31
|
-
var A2AClient = class {
|
|
31
|
+
var A2AClient = class _A2AClient {
|
|
32
32
|
agentCardPromise;
|
|
33
33
|
requestIdCounter = 1;
|
|
34
34
|
serviceEndpointUrl;
|
|
35
35
|
// To be populated from AgentCard after fetching
|
|
36
|
-
|
|
36
|
+
customFetchImpl;
|
|
37
37
|
/**
|
|
38
|
-
* Constructs an A2AClient instance.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* The `url` field from the Agent Card will be used as the RPC service endpoint.
|
|
42
|
-
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
43
|
-
* @param options Optional. The options for the A2AClient including the fetch implementation, agent card path, and authentication handler.
|
|
44
|
-
*/
|
|
45
|
-
constructor(agentBaseUrl, options) {
|
|
46
|
-
this.fetchImpl = options?.fetchImpl ?? fetch;
|
|
47
|
-
this.agentCardPromise = this._fetchAndCacheAgentCard(agentBaseUrl, options?.agentCardPath);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
51
|
-
* This method is called by the constructor.
|
|
52
|
-
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
53
|
-
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
54
|
-
* @returns A Promise that resolves to the AgentCard.
|
|
38
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
39
|
+
* @param agentCard The AgentCard object.
|
|
40
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
55
41
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status} ${response.statusText}`);
|
|
64
|
-
}
|
|
65
|
-
const agentCard = await response.json();
|
|
42
|
+
constructor(agentCard, options) {
|
|
43
|
+
this.customFetchImpl = options?.fetchImpl;
|
|
44
|
+
if (typeof agentCard === "string") {
|
|
45
|
+
console.warn("Warning: Constructing A2AClient with a URL is deprecated. Please use A2AClient.fromCardUrl() instead.");
|
|
46
|
+
this.agentCardPromise = this._fetchAndCacheAgentCard(agentCard, options?.agentCardPath);
|
|
47
|
+
} else {
|
|
66
48
|
if (!agentCard.url) {
|
|
67
|
-
throw new Error("
|
|
49
|
+
throw new Error("Provided Agent Card does not contain a valid 'url' for the service endpoint.");
|
|
68
50
|
}
|
|
69
51
|
this.serviceEndpointUrl = agentCard.url;
|
|
70
|
-
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error("Error fetching or parsing Agent Card:", error);
|
|
73
|
-
throw error;
|
|
52
|
+
this.agentCardPromise = Promise.resolve(agentCard);
|
|
74
53
|
}
|
|
75
54
|
}
|
|
76
55
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param
|
|
81
|
-
* @
|
|
82
|
-
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
83
|
-
* @returns A Promise that resolves to the AgentCard.
|
|
56
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
57
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
58
|
+
* @returns The fetch implementation.
|
|
59
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
60
|
+
* @throws If no fetch implementation is available.
|
|
84
61
|
*/
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
const response = await this.fetchImpl(agentCardUrl, {
|
|
89
|
-
headers: { "Accept": "application/json" }
|
|
90
|
-
});
|
|
91
|
-
if (!response.ok) {
|
|
92
|
-
throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status} ${response.statusText}`);
|
|
93
|
-
}
|
|
94
|
-
return await response.json();
|
|
62
|
+
_fetch(...args) {
|
|
63
|
+
if (this.customFetchImpl) {
|
|
64
|
+
return this.customFetchImpl(...args);
|
|
95
65
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
*/
|
|
103
|
-
resolveAgentCardUrl(agentBaseUrl, agentCardPath = AGENT_CARD_PATH) {
|
|
104
|
-
return `${agentBaseUrl.replace(/\/$/, "")}/${agentCardPath.replace(/^\//, "")}`;
|
|
66
|
+
if (typeof fetch === "function") {
|
|
67
|
+
return fetch(...args);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(
|
|
70
|
+
"A `fetch` implementation was not provided and is not available in the global scope. Please provide a `fetchImpl` in the A2AClientOptions. For earlier Node.js versions (pre-v18), you can use a library like `node-fetch`."
|
|
71
|
+
);
|
|
105
72
|
}
|
|
106
73
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
74
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
75
|
+
* @param agentCardUrl The URL of the agent card.
|
|
76
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
77
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
109
78
|
*/
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
|
|
79
|
+
static async fromCardUrl(agentCardUrl, options) {
|
|
80
|
+
const fetchImpl = options?.fetchImpl;
|
|
81
|
+
const requestInit = {
|
|
82
|
+
headers: { "Accept": "application/json" }
|
|
83
|
+
};
|
|
84
|
+
let response;
|
|
85
|
+
if (fetchImpl) {
|
|
86
|
+
response = await fetchImpl(agentCardUrl, requestInit);
|
|
87
|
+
} else if (typeof fetch === "function") {
|
|
88
|
+
response = await fetch(agentCardUrl, requestInit);
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"A `fetch` implementation was not provided and is not available in the global scope. Please provide a `fetchImpl` in the A2AClientOptions. For earlier Node.js versions (pre-v18), you can use a library like `node-fetch`."
|
|
92
|
+
);
|
|
113
93
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
throw new Error("Agent Card URL for RPC endpoint is not available. Fetching might have failed.");
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status} ${response.statusText}`);
|
|
117
96
|
}
|
|
118
|
-
|
|
97
|
+
let agentCard;
|
|
98
|
+
try {
|
|
99
|
+
agentCard = await response.json();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error("Failed to parse Agent Card JSON:", error);
|
|
102
|
+
throw new Error(`Failed to parse Agent Card JSON from ${agentCardUrl}. Original error: ${error.message}`);
|
|
103
|
+
}
|
|
104
|
+
return new _A2AClient(agentCard, options);
|
|
119
105
|
}
|
|
120
106
|
/**
|
|
121
107
|
* Helper method to make a generic JSON-RPC POST request.
|
|
@@ -174,7 +160,7 @@ var A2AClient = class {
|
|
|
174
160
|
},
|
|
175
161
|
body: JSON.stringify(rpcRequest)
|
|
176
162
|
};
|
|
177
|
-
return this.
|
|
163
|
+
return this._fetch(url, requestInit);
|
|
178
164
|
}
|
|
179
165
|
/**
|
|
180
166
|
* Sends a message to the agent.
|
|
@@ -257,6 +243,28 @@ var A2AClient = class {
|
|
|
257
243
|
params
|
|
258
244
|
);
|
|
259
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Lists the push notification configurations for a given task.
|
|
248
|
+
* @param params Parameters containing the taskId.
|
|
249
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
250
|
+
*/
|
|
251
|
+
async listTaskPushNotificationConfig(params) {
|
|
252
|
+
return this._postRpcRequest(
|
|
253
|
+
"tasks/pushNotificationConfig/list",
|
|
254
|
+
params
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Deletes the push notification configuration for a given task.
|
|
259
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
260
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
261
|
+
*/
|
|
262
|
+
async deleteTaskPushNotificationConfig(params) {
|
|
263
|
+
return this._postRpcRequest(
|
|
264
|
+
"tasks/pushNotificationConfig/delete",
|
|
265
|
+
params
|
|
266
|
+
);
|
|
267
|
+
}
|
|
260
268
|
/**
|
|
261
269
|
* Retrieves a task by its ID.
|
|
262
270
|
* @param params Parameters containing the taskId and optional historyLength.
|
|
@@ -273,6 +281,17 @@ var A2AClient = class {
|
|
|
273
281
|
async cancelTask(params) {
|
|
274
282
|
return this._postRpcRequest("tasks/cancel", params);
|
|
275
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
286
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
287
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
288
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
289
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
290
|
+
* @returns A Promise that resolves to the RPC response.
|
|
291
|
+
*/
|
|
292
|
+
async callExtensionMethod(method, params) {
|
|
293
|
+
return this._postRpcRequest(method, params);
|
|
294
|
+
}
|
|
276
295
|
/**
|
|
277
296
|
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
278
297
|
* This is used if a previous SSE connection for an active task was broken.
|
|
@@ -294,7 +313,7 @@ var A2AClient = class {
|
|
|
294
313
|
params,
|
|
295
314
|
id: clientRequestId
|
|
296
315
|
};
|
|
297
|
-
const response = await this.
|
|
316
|
+
const response = await this._fetch(endpoint, {
|
|
298
317
|
method: "POST",
|
|
299
318
|
headers: {
|
|
300
319
|
"Content-Type": "application/json",
|
|
@@ -409,6 +428,87 @@ var A2AClient = class {
|
|
|
409
428
|
isErrorResponse(response) {
|
|
410
429
|
return "error" in response;
|
|
411
430
|
}
|
|
431
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
432
|
+
// Functions used to support old A2AClient Constructor to be deprecated soon
|
|
433
|
+
// TODOs:
|
|
434
|
+
// * remove `agentCardPromise`, and just use agentCard initialized
|
|
435
|
+
// * _getServiceEndpoint can be made synchronous or deleted and accessed via
|
|
436
|
+
// agentCard.url
|
|
437
|
+
// * getAgentCard changed to this.agentCard
|
|
438
|
+
// * delete resolveAgentCardUrl(), _fetchAndCacheAgentCard(),
|
|
439
|
+
// agentCardPath from A2AClientOptions
|
|
440
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
441
|
+
/**
|
|
442
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
443
|
+
* This method is called by the constructor.
|
|
444
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
445
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
446
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
447
|
+
*/
|
|
448
|
+
async _fetchAndCacheAgentCard(agentBaseUrl, agentCardPath) {
|
|
449
|
+
try {
|
|
450
|
+
const agentCardUrl = this.resolveAgentCardUrl(agentBaseUrl, agentCardPath);
|
|
451
|
+
const response = await this._fetch(agentCardUrl, {
|
|
452
|
+
headers: { "Accept": "application/json" }
|
|
453
|
+
});
|
|
454
|
+
if (!response.ok) {
|
|
455
|
+
throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status} ${response.statusText}`);
|
|
456
|
+
}
|
|
457
|
+
const agentCard = await response.json();
|
|
458
|
+
if (!agentCard.url) {
|
|
459
|
+
throw new Error("Fetched Agent Card does not contain a valid 'url' for the service endpoint.");
|
|
460
|
+
}
|
|
461
|
+
this.serviceEndpointUrl = agentCard.url;
|
|
462
|
+
return agentCard;
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.error("Error fetching or parsing Agent Card:", error);
|
|
465
|
+
throw error;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Retrieves the Agent Card.
|
|
470
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
471
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
472
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
473
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
474
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
475
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
476
|
+
*/
|
|
477
|
+
async getAgentCard(agentBaseUrl, agentCardPath) {
|
|
478
|
+
if (agentBaseUrl) {
|
|
479
|
+
const agentCardUrl = this.resolveAgentCardUrl(agentBaseUrl, agentCardPath);
|
|
480
|
+
const response = await this._fetch(agentCardUrl, {
|
|
481
|
+
headers: { "Accept": "application/json" }
|
|
482
|
+
});
|
|
483
|
+
if (!response.ok) {
|
|
484
|
+
throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status} ${response.statusText}`);
|
|
485
|
+
}
|
|
486
|
+
return await response.json();
|
|
487
|
+
}
|
|
488
|
+
return this.agentCardPromise;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Determines the agent card URL based on the agent URL.
|
|
492
|
+
* @param agentBaseUrl The agent URL.
|
|
493
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
494
|
+
*/
|
|
495
|
+
resolveAgentCardUrl(agentBaseUrl, agentCardPath = AGENT_CARD_PATH) {
|
|
496
|
+
return `${agentBaseUrl.replace(/\/$/, "")}/${agentCardPath.replace(/^\//, "")}`;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
500
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
501
|
+
*/
|
|
502
|
+
async _getServiceEndpoint() {
|
|
503
|
+
if (this.serviceEndpointUrl) {
|
|
504
|
+
return this.serviceEndpointUrl;
|
|
505
|
+
}
|
|
506
|
+
await this.agentCardPromise;
|
|
507
|
+
if (!this.serviceEndpointUrl) {
|
|
508
|
+
throw new Error("Agent Card URL for RPC endpoint is not available. Fetching might have failed.");
|
|
509
|
+
}
|
|
510
|
+
return this.serviceEndpointUrl;
|
|
511
|
+
}
|
|
412
512
|
};
|
|
413
513
|
|
|
414
514
|
// src/client/auth-handler.ts
|
package/dist/client/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ac as AgentCard, w as MessageSendParams, S as SendMessageResponse, B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, Z as TaskPushNotificationConfig, b as SetTaskPushNotificationConfigResponse, X as TaskIdParams, c as GetTaskPushNotificationConfigResponse, V as TaskQueryParams, G as GetTaskResponse, C as CancelTaskResponse, i as JSONRPCResponse, J as JSONRPCErrorResponse } from '../types-DNKcmF0f.cjs';
|
|
1
|
+
import { ac as AgentCard, w as MessageSendParams, S as SendMessageResponse, B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, Z as TaskPushNotificationConfig, b as SetTaskPushNotificationConfigResponse, X as TaskIdParams, c as GetTaskPushNotificationConfigResponse, a5 as ListTaskPushNotificationConfigParams, j as ListTaskPushNotificationConfigResponse, a7 as DeleteTaskPushNotificationConfigParams, g as DeleteTaskPushNotificationConfigResponse, V as TaskQueryParams, G as GetTaskResponse, C as CancelTaskResponse, i as JSONRPCResponse, J as JSONRPCErrorResponse } from '../types-DNKcmF0f.cjs';
|
|
2
2
|
|
|
3
3
|
type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
4
4
|
interface A2AClientOptions {
|
|
@@ -12,45 +12,28 @@ declare class A2AClient {
|
|
|
12
12
|
private agentCardPromise;
|
|
13
13
|
private requestIdCounter;
|
|
14
14
|
private serviceEndpointUrl?;
|
|
15
|
-
private
|
|
15
|
+
private customFetchImpl?;
|
|
16
16
|
/**
|
|
17
|
-
* Constructs an A2AClient instance.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* The `url` field from the Agent Card will be used as the RPC service endpoint.
|
|
21
|
-
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
22
|
-
* @param options Optional. The options for the A2AClient including the fetch implementation, agent card path, and authentication handler.
|
|
17
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
18
|
+
* @param agentCard The AgentCard object.
|
|
19
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
23
20
|
*/
|
|
24
|
-
constructor(
|
|
21
|
+
constructor(agentCard: AgentCard | string, options?: A2AClientOptions);
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
23
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
24
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
25
|
+
* @returns The fetch implementation.
|
|
26
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
27
|
+
* @throws If no fetch implementation is available.
|
|
31
28
|
*/
|
|
32
|
-
private
|
|
29
|
+
private _fetch;
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
39
|
-
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
40
|
-
* @returns A Promise that resolves to the AgentCard.
|
|
31
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
32
|
+
* @param agentCardUrl The URL of the agent card.
|
|
33
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
34
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
41
35
|
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Determines the agent card URL based on the agent URL.
|
|
45
|
-
* @param agentBaseUrl The agent URL.
|
|
46
|
-
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
47
|
-
*/
|
|
48
|
-
private resolveAgentCardUrl;
|
|
49
|
-
/**
|
|
50
|
-
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
51
|
-
* @returns A Promise that resolves to the service endpoint URL string.
|
|
52
|
-
*/
|
|
53
|
-
private _getServiceEndpoint;
|
|
36
|
+
static fromCardUrl(agentCardUrl: string, options?: A2AClientOptions): Promise<A2AClient>;
|
|
54
37
|
/**
|
|
55
38
|
* Helper method to make a generic JSON-RPC POST request.
|
|
56
39
|
* @param method The RPC method name.
|
|
@@ -98,6 +81,18 @@ declare class A2AClient {
|
|
|
98
81
|
* @returns A Promise resolving to GetTaskPushNotificationConfigResponse.
|
|
99
82
|
*/
|
|
100
83
|
getTaskPushNotificationConfig(params: TaskIdParams): Promise<GetTaskPushNotificationConfigResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Lists the push notification configurations for a given task.
|
|
86
|
+
* @param params Parameters containing the taskId.
|
|
87
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
88
|
+
*/
|
|
89
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams): Promise<ListTaskPushNotificationConfigResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Deletes the push notification configuration for a given task.
|
|
92
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
93
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
94
|
+
*/
|
|
95
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<DeleteTaskPushNotificationConfigResponse>;
|
|
101
96
|
/**
|
|
102
97
|
* Retrieves a task by its ID.
|
|
103
98
|
* @param params Parameters containing the taskId and optional historyLength.
|
|
@@ -110,6 +105,15 @@ declare class A2AClient {
|
|
|
110
105
|
* @returns A Promise resolving to CancelTaskResponse, which contains the updated Task object or an error.
|
|
111
106
|
*/
|
|
112
107
|
cancelTask(params: TaskIdParams): Promise<CancelTaskResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
110
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
111
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
112
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
113
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
114
|
+
* @returns A Promise that resolves to the RPC response.
|
|
115
|
+
*/
|
|
116
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams): Promise<TExtensionResponse>;
|
|
113
117
|
/**
|
|
114
118
|
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
115
119
|
* This is used if a previous SSE connection for an active task was broken.
|
|
@@ -137,6 +141,35 @@ declare class A2AClient {
|
|
|
137
141
|
*/
|
|
138
142
|
private _processSseEventData;
|
|
139
143
|
isErrorResponse(response: JSONRPCResponse): response is JSONRPCErrorResponse;
|
|
144
|
+
/**
|
|
145
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
146
|
+
* This method is called by the constructor.
|
|
147
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
148
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
149
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
150
|
+
*/
|
|
151
|
+
private _fetchAndCacheAgentCard;
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves the Agent Card.
|
|
154
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
155
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
156
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
157
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
158
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
159
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
160
|
+
*/
|
|
161
|
+
getAgentCard(agentBaseUrl?: string, agentCardPath?: string): Promise<AgentCard>;
|
|
162
|
+
/**
|
|
163
|
+
* Determines the agent card URL based on the agent URL.
|
|
164
|
+
* @param agentBaseUrl The agent URL.
|
|
165
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
166
|
+
*/
|
|
167
|
+
private resolveAgentCardUrl;
|
|
168
|
+
/**
|
|
169
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
170
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
171
|
+
*/
|
|
172
|
+
private _getServiceEndpoint;
|
|
140
173
|
}
|
|
141
174
|
|
|
142
175
|
interface HttpHeaders {
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ac as AgentCard, w as MessageSendParams, S as SendMessageResponse, B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, Z as TaskPushNotificationConfig, b as SetTaskPushNotificationConfigResponse, X as TaskIdParams, c as GetTaskPushNotificationConfigResponse, V as TaskQueryParams, G as GetTaskResponse, C as CancelTaskResponse, i as JSONRPCResponse, J as JSONRPCErrorResponse } from '../types-DNKcmF0f.js';
|
|
1
|
+
import { ac as AgentCard, w as MessageSendParams, S as SendMessageResponse, B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, Z as TaskPushNotificationConfig, b as SetTaskPushNotificationConfigResponse, X as TaskIdParams, c as GetTaskPushNotificationConfigResponse, a5 as ListTaskPushNotificationConfigParams, j as ListTaskPushNotificationConfigResponse, a7 as DeleteTaskPushNotificationConfigParams, g as DeleteTaskPushNotificationConfigResponse, V as TaskQueryParams, G as GetTaskResponse, C as CancelTaskResponse, i as JSONRPCResponse, J as JSONRPCErrorResponse } from '../types-DNKcmF0f.js';
|
|
2
2
|
|
|
3
3
|
type A2AStreamEventData = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
|
|
4
4
|
interface A2AClientOptions {
|
|
@@ -12,45 +12,28 @@ declare class A2AClient {
|
|
|
12
12
|
private agentCardPromise;
|
|
13
13
|
private requestIdCounter;
|
|
14
14
|
private serviceEndpointUrl?;
|
|
15
|
-
private
|
|
15
|
+
private customFetchImpl?;
|
|
16
16
|
/**
|
|
17
|
-
* Constructs an A2AClient instance.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* The `url` field from the Agent Card will be used as the RPC service endpoint.
|
|
21
|
-
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
22
|
-
* @param options Optional. The options for the A2AClient including the fetch implementation, agent card path, and authentication handler.
|
|
17
|
+
* Constructs an A2AClient instance from an AgentCard.
|
|
18
|
+
* @param agentCard The AgentCard object.
|
|
19
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
23
20
|
*/
|
|
24
|
-
constructor(
|
|
21
|
+
constructor(agentCard: AgentCard | string, options?: A2AClientOptions);
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
23
|
+
* Dynamically resolves the fetch implementation to use for requests.
|
|
24
|
+
* Prefers a custom implementation if provided, otherwise falls back to the global fetch.
|
|
25
|
+
* @returns The fetch implementation.
|
|
26
|
+
* @param args Arguments to pass to the fetch implementation.
|
|
27
|
+
* @throws If no fetch implementation is available.
|
|
31
28
|
*/
|
|
32
|
-
private
|
|
29
|
+
private _fetch;
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
39
|
-
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
40
|
-
* @returns A Promise that resolves to the AgentCard.
|
|
31
|
+
* Creates an A2AClient instance by fetching the AgentCard from a URL then constructing the A2AClient.
|
|
32
|
+
* @param agentCardUrl The URL of the agent card.
|
|
33
|
+
* @param options Optional. The options for the A2AClient including the fetch/auth implementation.
|
|
34
|
+
* @returns A Promise that resolves to a new A2AClient instance.
|
|
41
35
|
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Determines the agent card URL based on the agent URL.
|
|
45
|
-
* @param agentBaseUrl The agent URL.
|
|
46
|
-
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
47
|
-
*/
|
|
48
|
-
private resolveAgentCardUrl;
|
|
49
|
-
/**
|
|
50
|
-
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
51
|
-
* @returns A Promise that resolves to the service endpoint URL string.
|
|
52
|
-
*/
|
|
53
|
-
private _getServiceEndpoint;
|
|
36
|
+
static fromCardUrl(agentCardUrl: string, options?: A2AClientOptions): Promise<A2AClient>;
|
|
54
37
|
/**
|
|
55
38
|
* Helper method to make a generic JSON-RPC POST request.
|
|
56
39
|
* @param method The RPC method name.
|
|
@@ -98,6 +81,18 @@ declare class A2AClient {
|
|
|
98
81
|
* @returns A Promise resolving to GetTaskPushNotificationConfigResponse.
|
|
99
82
|
*/
|
|
100
83
|
getTaskPushNotificationConfig(params: TaskIdParams): Promise<GetTaskPushNotificationConfigResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Lists the push notification configurations for a given task.
|
|
86
|
+
* @param params Parameters containing the taskId.
|
|
87
|
+
* @returns A Promise resolving to ListTaskPushNotificationConfigResponse.
|
|
88
|
+
*/
|
|
89
|
+
listTaskPushNotificationConfig(params: ListTaskPushNotificationConfigParams): Promise<ListTaskPushNotificationConfigResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Deletes the push notification configuration for a given task.
|
|
92
|
+
* @param params Parameters containing the taskId and push notification configuration ID.
|
|
93
|
+
* @returns A Promise resolving to DeleteTaskPushNotificationConfigResponse.
|
|
94
|
+
*/
|
|
95
|
+
deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<DeleteTaskPushNotificationConfigResponse>;
|
|
101
96
|
/**
|
|
102
97
|
* Retrieves a task by its ID.
|
|
103
98
|
* @param params Parameters containing the taskId and optional historyLength.
|
|
@@ -110,6 +105,15 @@ declare class A2AClient {
|
|
|
110
105
|
* @returns A Promise resolving to CancelTaskResponse, which contains the updated Task object or an error.
|
|
111
106
|
*/
|
|
112
107
|
cancelTask(params: TaskIdParams): Promise<CancelTaskResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* @template TExtensionParams The type of parameters for the custom extension method.
|
|
110
|
+
* @template TExtensionResponse The type of response expected from the custom extension method.
|
|
111
|
+
* This should extend JSONRPCResponse. This ensures the extension response is still a valid A2A response.
|
|
112
|
+
* @param method Custom JSON-RPC method defined in the AgentCard's extensions.
|
|
113
|
+
* @param params Extension paramters defined in the AgentCard's extensions.
|
|
114
|
+
* @returns A Promise that resolves to the RPC response.
|
|
115
|
+
*/
|
|
116
|
+
callExtensionMethod<TExtensionParams, TExtensionResponse extends JSONRPCResponse>(method: string, params: TExtensionParams): Promise<TExtensionResponse>;
|
|
113
117
|
/**
|
|
114
118
|
* Resubscribes to a task's event stream using Server-Sent Events (SSE).
|
|
115
119
|
* This is used if a previous SSE connection for an active task was broken.
|
|
@@ -137,6 +141,35 @@ declare class A2AClient {
|
|
|
137
141
|
*/
|
|
138
142
|
private _processSseEventData;
|
|
139
143
|
isErrorResponse(response: JSONRPCResponse): response is JSONRPCErrorResponse;
|
|
144
|
+
/**
|
|
145
|
+
* Fetches the Agent Card from the agent's well-known URI and caches its service endpoint URL.
|
|
146
|
+
* This method is called by the constructor.
|
|
147
|
+
* @param agentBaseUrl The base URL of the A2A agent (e.g., https://agent.example.com)
|
|
148
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
149
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
150
|
+
*/
|
|
151
|
+
private _fetchAndCacheAgentCard;
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves the Agent Card.
|
|
154
|
+
* If an `agentBaseUrl` is provided, it fetches the card from that specific URL.
|
|
155
|
+
* Otherwise, it returns the card fetched and cached during client construction.
|
|
156
|
+
* @param agentBaseUrl Optional. The base URL of the agent to fetch the card from.
|
|
157
|
+
* @param agentCardPath path to the agent card, defaults to .well-known/agent-card.json
|
|
158
|
+
* If provided, this will fetch a new card, not use the cached one from the constructor's URL.
|
|
159
|
+
* @returns A Promise that resolves to the AgentCard.
|
|
160
|
+
*/
|
|
161
|
+
getAgentCard(agentBaseUrl?: string, agentCardPath?: string): Promise<AgentCard>;
|
|
162
|
+
/**
|
|
163
|
+
* Determines the agent card URL based on the agent URL.
|
|
164
|
+
* @param agentBaseUrl The agent URL.
|
|
165
|
+
* @param agentCardPath Optional relative path to the agent card, defaults to .well-known/agent-card.json
|
|
166
|
+
*/
|
|
167
|
+
private resolveAgentCardUrl;
|
|
168
|
+
/**
|
|
169
|
+
* Gets the RPC service endpoint URL. Ensures the agent card has been fetched first.
|
|
170
|
+
* @returns A Promise that resolves to the service endpoint URL string.
|
|
171
|
+
*/
|
|
172
|
+
private _getServiceEndpoint;
|
|
140
173
|
}
|
|
141
174
|
|
|
142
175
|
interface HttpHeaders {
|