@a2a-js/sdk 0.3.6 → 0.3.8
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 +17 -7
- package/dist/chunk-DHC2REQH.js +2145 -0
- package/dist/{chunk-LTPINR5K.js → chunk-NUQQPJNY.js} +3 -60
- package/dist/chunk-UHZEIZLS.js +62 -0
- package/dist/client/index.cjs +2537 -168
- package/dist/client/index.d.cts +60 -2
- package/dist/client/index.d.ts +60 -2
- package/dist/client/index.js +321 -99
- package/dist/server/express/index.cjs +2171 -115
- package/dist/server/express/index.js +79 -54
- package/dist/server/index.cjs +184 -6
- package/dist/server/index.d.cts +68 -8
- package/dist/server/index.d.ts +68 -8
- package/dist/server/index.js +188 -8
- package/package.json +22 -15
package/dist/client/index.d.cts
CHANGED
|
@@ -566,6 +566,28 @@ declare class ClientFactory {
|
|
|
566
566
|
createFromUrl(baseUrl: string, path?: string): Promise<Client>;
|
|
567
567
|
}
|
|
568
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
|
+
|
|
569
591
|
interface JsonRpcTransportOptions {
|
|
570
592
|
endpoint: string;
|
|
571
593
|
fetchImpl?: typeof fetch;
|
|
@@ -590,7 +612,6 @@ declare class JsonRpcTransport implements Transport {
|
|
|
590
612
|
private _sendRpcRequest;
|
|
591
613
|
private _fetchRpc;
|
|
592
614
|
private _sendStreamingRequest;
|
|
593
|
-
private _parseA2ASseStream;
|
|
594
615
|
private _processSseEventData;
|
|
595
616
|
private static mapToError;
|
|
596
617
|
}
|
|
@@ -605,4 +626,41 @@ declare class JsonRpcTransportFactory implements TransportFactory {
|
|
|
605
626
|
create(url: string, _agentCard: AgentCard): Promise<Transport>;
|
|
606
627
|
}
|
|
607
628
|
|
|
608
|
-
|
|
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 };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -566,6 +566,28 @@ declare class ClientFactory {
|
|
|
566
566
|
createFromUrl(baseUrl: string, path?: string): Promise<Client>;
|
|
567
567
|
}
|
|
568
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
|
+
|
|
569
591
|
interface JsonRpcTransportOptions {
|
|
570
592
|
endpoint: string;
|
|
571
593
|
fetchImpl?: typeof fetch;
|
|
@@ -590,7 +612,6 @@ declare class JsonRpcTransport implements Transport {
|
|
|
590
612
|
private _sendRpcRequest;
|
|
591
613
|
private _fetchRpc;
|
|
592
614
|
private _sendStreamingRequest;
|
|
593
|
-
private _parseA2ASseStream;
|
|
594
615
|
private _processSseEventData;
|
|
595
616
|
private static mapToError;
|
|
596
617
|
}
|
|
@@ -605,4 +626,41 @@ declare class JsonRpcTransportFactory implements TransportFactory {
|
|
|
605
626
|
create(url: string, _agentCard: AgentCard): Promise<Transport>;
|
|
606
627
|
}
|
|
607
628
|
|
|
608
|
-
|
|
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 };
|
package/dist/client/index.js
CHANGED
|
@@ -1,55 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A2A_ERROR_CODE,
|
|
3
|
+
AgentCard,
|
|
4
|
+
AuthenticatedExtendedCardNotConfiguredError,
|
|
5
|
+
ContentTypeNotSupportedError,
|
|
6
|
+
FromProto,
|
|
7
|
+
InvalidAgentResponseError,
|
|
8
|
+
ListTaskPushNotificationConfigResponse,
|
|
9
|
+
PushNotificationNotSupportedError,
|
|
10
|
+
SendMessageRequest,
|
|
11
|
+
SendMessageResponse,
|
|
12
|
+
StreamResponse,
|
|
13
|
+
Task,
|
|
14
|
+
TaskNotCancelableError,
|
|
15
|
+
TaskNotFoundError,
|
|
16
|
+
TaskPushNotificationConfig,
|
|
17
|
+
ToProto,
|
|
18
|
+
UnsupportedOperationError,
|
|
19
|
+
parseSseStream
|
|
20
|
+
} from "../chunk-DHC2REQH.js";
|
|
1
21
|
import {
|
|
2
22
|
AGENT_CARD_PATH,
|
|
3
23
|
HTTP_EXTENSION_HEADER
|
|
4
24
|
} from "../chunk-3QDLXHKS.js";
|
|
25
|
+
import "../chunk-UHZEIZLS.js";
|
|
5
26
|
import {
|
|
6
27
|
Extensions
|
|
7
28
|
} from "../chunk-ZX6KNMCP.js";
|
|
8
29
|
|
|
9
|
-
// src/errors.ts
|
|
10
|
-
var TaskNotFoundError = class extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message ?? "Task not found");
|
|
13
|
-
this.name = "TaskNotFoundError";
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var TaskNotCancelableError = class extends Error {
|
|
17
|
-
constructor(message) {
|
|
18
|
-
super(message ?? "Task cannot be canceled");
|
|
19
|
-
this.name = "TaskNotCancelableError";
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var PushNotificationNotSupportedError = class extends Error {
|
|
23
|
-
constructor(message) {
|
|
24
|
-
super(message ?? "Push Notification is not supported");
|
|
25
|
-
this.name = "PushNotificationNotSupportedError";
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var UnsupportedOperationError = class extends Error {
|
|
29
|
-
constructor(message) {
|
|
30
|
-
super(message ?? "This operation is not supported");
|
|
31
|
-
this.name = "UnsupportedOperationError";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var ContentTypeNotSupportedError = class extends Error {
|
|
35
|
-
constructor(message) {
|
|
36
|
-
super(message ?? "Incompatible content types");
|
|
37
|
-
this.name = "ContentTypeNotSupportedError";
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var InvalidAgentResponseError = class extends Error {
|
|
41
|
-
constructor(message) {
|
|
42
|
-
super(message ?? "Invalid agent response type");
|
|
43
|
-
this.name = "InvalidAgentResponseError";
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var AuthenticatedExtendedCardNotConfiguredError = class extends Error {
|
|
47
|
-
constructor(message) {
|
|
48
|
-
super(message ?? "Authenticated Extended Card not configured");
|
|
49
|
-
this.name = "AuthenticatedExtendedCardNotConfiguredError";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
30
|
// src/client/transports/json_rpc_transport.ts
|
|
54
31
|
var JsonRpcTransport = class _JsonRpcTransport {
|
|
55
32
|
customFetchImpl;
|
|
@@ -218,55 +195,8 @@ var JsonRpcTransport = class _JsonRpcTransport {
|
|
|
218
195
|
`Invalid response Content-Type for SSE stream for ${method}. Expected 'text/event-stream'.`
|
|
219
196
|
);
|
|
220
197
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
async *_parseA2ASseStream(response, originalRequestId) {
|
|
224
|
-
if (!response.body) {
|
|
225
|
-
throw new Error("SSE response body is undefined. Cannot read stream.");
|
|
226
|
-
}
|
|
227
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
228
|
-
let buffer = "";
|
|
229
|
-
let eventDataBuffer = "";
|
|
230
|
-
try {
|
|
231
|
-
while (true) {
|
|
232
|
-
const { done, value } = await reader.read();
|
|
233
|
-
if (done) {
|
|
234
|
-
if (eventDataBuffer.trim()) {
|
|
235
|
-
const result = this._processSseEventData(
|
|
236
|
-
eventDataBuffer,
|
|
237
|
-
originalRequestId
|
|
238
|
-
);
|
|
239
|
-
yield result;
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
buffer += value;
|
|
244
|
-
let lineEndIndex;
|
|
245
|
-
while ((lineEndIndex = buffer.indexOf("\n")) >= 0) {
|
|
246
|
-
const line = buffer.substring(0, lineEndIndex).trim();
|
|
247
|
-
buffer = buffer.substring(lineEndIndex + 1);
|
|
248
|
-
if (line === "") {
|
|
249
|
-
if (eventDataBuffer) {
|
|
250
|
-
const result = this._processSseEventData(
|
|
251
|
-
eventDataBuffer,
|
|
252
|
-
originalRequestId
|
|
253
|
-
);
|
|
254
|
-
yield result;
|
|
255
|
-
eventDataBuffer = "";
|
|
256
|
-
}
|
|
257
|
-
} else if (line.startsWith("data:")) {
|
|
258
|
-
eventDataBuffer += line.substring(5).trimStart() + "\n";
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
} catch (error) {
|
|
263
|
-
console.error(
|
|
264
|
-
"Error reading or parsing SSE stream:",
|
|
265
|
-
error instanceof Error && error.message || "Error unknown"
|
|
266
|
-
);
|
|
267
|
-
throw error;
|
|
268
|
-
} finally {
|
|
269
|
-
reader.releaseLock();
|
|
198
|
+
for await (const event of parseSseStream(response)) {
|
|
199
|
+
yield this._processSseEventData(event.data, clientRequestId);
|
|
270
200
|
}
|
|
271
201
|
}
|
|
272
202
|
_processSseEventData(jsonData, originalRequestId) {
|
|
@@ -274,7 +204,7 @@ var JsonRpcTransport = class _JsonRpcTransport {
|
|
|
274
204
|
throw new Error("Attempted to process empty SSE event data.");
|
|
275
205
|
}
|
|
276
206
|
try {
|
|
277
|
-
const sseJsonRpcResponse = JSON.parse(jsonData
|
|
207
|
+
const sseJsonRpcResponse = JSON.parse(jsonData);
|
|
278
208
|
const a2aStreamResponse = sseJsonRpcResponse;
|
|
279
209
|
if (a2aStreamResponse.id !== originalRequestId) {
|
|
280
210
|
console.warn(
|
|
@@ -1074,13 +1004,280 @@ var Client = class {
|
|
|
1074
1004
|
}
|
|
1075
1005
|
};
|
|
1076
1006
|
|
|
1007
|
+
// src/client/transports/rest_transport.ts
|
|
1008
|
+
var RestTransport = class _RestTransport {
|
|
1009
|
+
customFetchImpl;
|
|
1010
|
+
endpoint;
|
|
1011
|
+
constructor(options) {
|
|
1012
|
+
this.endpoint = options.endpoint.replace(/\/+$/, "");
|
|
1013
|
+
this.customFetchImpl = options.fetchImpl;
|
|
1014
|
+
}
|
|
1015
|
+
async getExtendedAgentCard(options) {
|
|
1016
|
+
const response = await this._sendRequest(
|
|
1017
|
+
"GET",
|
|
1018
|
+
"/v1/card",
|
|
1019
|
+
void 0,
|
|
1020
|
+
options,
|
|
1021
|
+
void 0,
|
|
1022
|
+
AgentCard
|
|
1023
|
+
);
|
|
1024
|
+
return FromProto.agentCard(response);
|
|
1025
|
+
}
|
|
1026
|
+
async sendMessage(params, options) {
|
|
1027
|
+
const requestBody = ToProto.messageSendParams(params);
|
|
1028
|
+
const response = await this._sendRequest(
|
|
1029
|
+
"POST",
|
|
1030
|
+
"/v1/message:send",
|
|
1031
|
+
requestBody,
|
|
1032
|
+
options,
|
|
1033
|
+
SendMessageRequest,
|
|
1034
|
+
SendMessageResponse
|
|
1035
|
+
);
|
|
1036
|
+
return FromProto.sendMessageResult(response);
|
|
1037
|
+
}
|
|
1038
|
+
async *sendMessageStream(params, options) {
|
|
1039
|
+
const protoParams = ToProto.messageSendParams(params);
|
|
1040
|
+
const requestBody = SendMessageRequest.toJSON(protoParams);
|
|
1041
|
+
yield* this._sendStreamingRequest("/v1/message:stream", requestBody, options);
|
|
1042
|
+
}
|
|
1043
|
+
async setTaskPushNotificationConfig(params, options) {
|
|
1044
|
+
const requestBody = ToProto.taskPushNotificationConfig(params);
|
|
1045
|
+
const response = await this._sendRequest(
|
|
1046
|
+
"POST",
|
|
1047
|
+
`/v1/tasks/${encodeURIComponent(params.taskId)}/pushNotificationConfigs`,
|
|
1048
|
+
requestBody,
|
|
1049
|
+
options,
|
|
1050
|
+
TaskPushNotificationConfig,
|
|
1051
|
+
TaskPushNotificationConfig
|
|
1052
|
+
);
|
|
1053
|
+
return FromProto.taskPushNotificationConfig(response);
|
|
1054
|
+
}
|
|
1055
|
+
async getTaskPushNotificationConfig(params, options) {
|
|
1056
|
+
const { pushNotificationConfigId } = params;
|
|
1057
|
+
if (!pushNotificationConfigId) {
|
|
1058
|
+
throw new Error(
|
|
1059
|
+
"pushNotificationConfigId is required for getTaskPushNotificationConfig with REST transport."
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
const response = await this._sendRequest(
|
|
1063
|
+
"GET",
|
|
1064
|
+
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(pushNotificationConfigId)}`,
|
|
1065
|
+
void 0,
|
|
1066
|
+
options,
|
|
1067
|
+
void 0,
|
|
1068
|
+
TaskPushNotificationConfig
|
|
1069
|
+
);
|
|
1070
|
+
return FromProto.taskPushNotificationConfig(response);
|
|
1071
|
+
}
|
|
1072
|
+
async listTaskPushNotificationConfig(params, options) {
|
|
1073
|
+
const response = await this._sendRequest(
|
|
1074
|
+
"GET",
|
|
1075
|
+
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs`,
|
|
1076
|
+
void 0,
|
|
1077
|
+
options,
|
|
1078
|
+
void 0,
|
|
1079
|
+
ListTaskPushNotificationConfigResponse
|
|
1080
|
+
);
|
|
1081
|
+
return FromProto.listTaskPushNotificationConfig(response);
|
|
1082
|
+
}
|
|
1083
|
+
async deleteTaskPushNotificationConfig(params, options) {
|
|
1084
|
+
await this._sendRequest(
|
|
1085
|
+
"DELETE",
|
|
1086
|
+
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(params.pushNotificationConfigId)}`,
|
|
1087
|
+
void 0,
|
|
1088
|
+
options,
|
|
1089
|
+
void 0,
|
|
1090
|
+
void 0
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
async getTask(params, options) {
|
|
1094
|
+
const queryParams = new URLSearchParams();
|
|
1095
|
+
if (params.historyLength !== void 0) {
|
|
1096
|
+
queryParams.set("historyLength", String(params.historyLength));
|
|
1097
|
+
}
|
|
1098
|
+
const queryString = queryParams.toString();
|
|
1099
|
+
const path = `/v1/tasks/${encodeURIComponent(params.id)}${queryString ? `?${queryString}` : ""}`;
|
|
1100
|
+
const response = await this._sendRequest(
|
|
1101
|
+
"GET",
|
|
1102
|
+
path,
|
|
1103
|
+
void 0,
|
|
1104
|
+
options,
|
|
1105
|
+
void 0,
|
|
1106
|
+
Task
|
|
1107
|
+
);
|
|
1108
|
+
return FromProto.task(response);
|
|
1109
|
+
}
|
|
1110
|
+
async cancelTask(params, options) {
|
|
1111
|
+
const response = await this._sendRequest(
|
|
1112
|
+
"POST",
|
|
1113
|
+
`/v1/tasks/${encodeURIComponent(params.id)}:cancel`,
|
|
1114
|
+
void 0,
|
|
1115
|
+
options,
|
|
1116
|
+
void 0,
|
|
1117
|
+
Task
|
|
1118
|
+
);
|
|
1119
|
+
return FromProto.task(response);
|
|
1120
|
+
}
|
|
1121
|
+
async *resubscribeTask(params, options) {
|
|
1122
|
+
yield* this._sendStreamingRequest(
|
|
1123
|
+
`/v1/tasks/${encodeURIComponent(params.id)}:subscribe`,
|
|
1124
|
+
void 0,
|
|
1125
|
+
options
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
_fetch(...args) {
|
|
1129
|
+
if (this.customFetchImpl) {
|
|
1130
|
+
return this.customFetchImpl(...args);
|
|
1131
|
+
}
|
|
1132
|
+
if (typeof fetch === "function") {
|
|
1133
|
+
return fetch(...args);
|
|
1134
|
+
}
|
|
1135
|
+
throw new Error(
|
|
1136
|
+
"A `fetch` implementation was not provided and is not available in the global scope. Please provide a `fetchImpl` in the RestTransportOptions."
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1139
|
+
_buildHeaders(options, acceptHeader = "application/json") {
|
|
1140
|
+
return {
|
|
1141
|
+
...options?.serviceParameters,
|
|
1142
|
+
"Content-Type": "application/json",
|
|
1143
|
+
Accept: acceptHeader
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
async _sendRequest(method, path, body, options, requestType, responseType) {
|
|
1147
|
+
const url = `${this.endpoint}${path}`;
|
|
1148
|
+
const requestInit = {
|
|
1149
|
+
method,
|
|
1150
|
+
headers: this._buildHeaders(options),
|
|
1151
|
+
signal: options?.signal
|
|
1152
|
+
};
|
|
1153
|
+
if (body !== void 0 && method !== "GET") {
|
|
1154
|
+
if (!requestType) {
|
|
1155
|
+
throw new Error(
|
|
1156
|
+
`Bug: Request body provided for ${method} ${path} but no toJson serializer provided.`
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
requestInit.body = JSON.stringify(requestType.toJSON(body));
|
|
1160
|
+
}
|
|
1161
|
+
const response = await this._fetch(url, requestInit);
|
|
1162
|
+
if (!response.ok) {
|
|
1163
|
+
await this._handleErrorResponse(response, path);
|
|
1164
|
+
}
|
|
1165
|
+
if (response.status === 204 || !responseType) {
|
|
1166
|
+
return void 0;
|
|
1167
|
+
}
|
|
1168
|
+
const result = await response.json();
|
|
1169
|
+
return responseType.fromJSON(result);
|
|
1170
|
+
}
|
|
1171
|
+
async _handleErrorResponse(response, path) {
|
|
1172
|
+
let errorBodyText = "(empty or non-JSON response)";
|
|
1173
|
+
let errorBody;
|
|
1174
|
+
try {
|
|
1175
|
+
errorBodyText = await response.text();
|
|
1176
|
+
if (errorBodyText) {
|
|
1177
|
+
errorBody = JSON.parse(errorBodyText);
|
|
1178
|
+
}
|
|
1179
|
+
} catch (e) {
|
|
1180
|
+
throw new Error(
|
|
1181
|
+
`HTTP error for ${path}! Status: ${response.status} ${response.statusText}. Response: ${errorBodyText}`,
|
|
1182
|
+
{ cause: e }
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
if (errorBody && typeof errorBody.code === "number") {
|
|
1186
|
+
throw _RestTransport.mapToError(errorBody);
|
|
1187
|
+
}
|
|
1188
|
+
throw new Error(
|
|
1189
|
+
`HTTP error for ${path}! Status: ${response.status} ${response.statusText}. Response: ${errorBodyText}`
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
async *_sendStreamingRequest(path, body, options) {
|
|
1193
|
+
const url = `${this.endpoint}${path}`;
|
|
1194
|
+
const requestInit = {
|
|
1195
|
+
method: "POST",
|
|
1196
|
+
headers: this._buildHeaders(options, "text/event-stream"),
|
|
1197
|
+
signal: options?.signal
|
|
1198
|
+
};
|
|
1199
|
+
if (body !== void 0) {
|
|
1200
|
+
requestInit.body = JSON.stringify(body);
|
|
1201
|
+
}
|
|
1202
|
+
const response = await this._fetch(url, requestInit);
|
|
1203
|
+
if (!response.ok) {
|
|
1204
|
+
await this._handleErrorResponse(response, path);
|
|
1205
|
+
}
|
|
1206
|
+
const contentType = response.headers.get("Content-Type");
|
|
1207
|
+
if (!contentType?.startsWith("text/event-stream")) {
|
|
1208
|
+
throw new Error(
|
|
1209
|
+
`Invalid response Content-Type for SSE stream. Expected 'text/event-stream', got '${contentType}'.`
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
for await (const event of parseSseStream(response)) {
|
|
1213
|
+
if (event.type === "error") {
|
|
1214
|
+
const errorData = JSON.parse(event.data);
|
|
1215
|
+
throw _RestTransport.mapToError(errorData);
|
|
1216
|
+
}
|
|
1217
|
+
yield this._processSseEventData(event.data);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
_processSseEventData(jsonData) {
|
|
1221
|
+
if (!jsonData.trim()) {
|
|
1222
|
+
throw new Error("Attempted to process empty SSE event data.");
|
|
1223
|
+
}
|
|
1224
|
+
try {
|
|
1225
|
+
const response = JSON.parse(jsonData);
|
|
1226
|
+
const protoResponse = StreamResponse.fromJSON(response);
|
|
1227
|
+
return FromProto.messageStreamResult(protoResponse);
|
|
1228
|
+
} catch (e) {
|
|
1229
|
+
console.error("Failed to parse SSE event data:", jsonData, e);
|
|
1230
|
+
throw new Error(
|
|
1231
|
+
`Failed to parse SSE event data: "${jsonData.substring(0, 100)}...". Original error: ${e instanceof Error && e.message || "Unknown error"}`
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
static mapToError(error) {
|
|
1236
|
+
switch (error.code) {
|
|
1237
|
+
case A2A_ERROR_CODE.TASK_NOT_FOUND:
|
|
1238
|
+
return new TaskNotFoundError(error.message);
|
|
1239
|
+
case A2A_ERROR_CODE.TASK_NOT_CANCELABLE:
|
|
1240
|
+
return new TaskNotCancelableError(error.message);
|
|
1241
|
+
case A2A_ERROR_CODE.PUSH_NOTIFICATION_NOT_SUPPORTED:
|
|
1242
|
+
return new PushNotificationNotSupportedError(error.message);
|
|
1243
|
+
case A2A_ERROR_CODE.UNSUPPORTED_OPERATION:
|
|
1244
|
+
return new UnsupportedOperationError(error.message);
|
|
1245
|
+
case A2A_ERROR_CODE.CONTENT_TYPE_NOT_SUPPORTED:
|
|
1246
|
+
return new ContentTypeNotSupportedError(error.message);
|
|
1247
|
+
case A2A_ERROR_CODE.INVALID_AGENT_RESPONSE:
|
|
1248
|
+
return new InvalidAgentResponseError(error.message);
|
|
1249
|
+
case A2A_ERROR_CODE.AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED:
|
|
1250
|
+
return new AuthenticatedExtendedCardNotConfiguredError(error.message);
|
|
1251
|
+
default:
|
|
1252
|
+
return new Error(
|
|
1253
|
+
`REST error: ${error.message} (Code: ${error.code})${error.data ? ` Data: ${JSON.stringify(error.data)}` : ""}`
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
var RestTransportFactory = class _RestTransportFactory {
|
|
1259
|
+
constructor(options) {
|
|
1260
|
+
this.options = options;
|
|
1261
|
+
}
|
|
1262
|
+
static name = "HTTP+JSON";
|
|
1263
|
+
get protocolName() {
|
|
1264
|
+
return _RestTransportFactory.name;
|
|
1265
|
+
}
|
|
1266
|
+
async create(url, _agentCard) {
|
|
1267
|
+
return new RestTransport({
|
|
1268
|
+
endpoint: url,
|
|
1269
|
+
fetchImpl: this.options?.fetchImpl
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1077
1274
|
// src/client/factory.ts
|
|
1078
1275
|
var ClientFactoryOptions = {
|
|
1079
1276
|
/**
|
|
1080
1277
|
* SDK default options for {@link ClientFactory}.
|
|
1081
1278
|
*/
|
|
1082
1279
|
default: {
|
|
1083
|
-
transports: [new JsonRpcTransportFactory()]
|
|
1280
|
+
transports: [new JsonRpcTransportFactory(), new RestTransportFactory()]
|
|
1084
1281
|
},
|
|
1085
1282
|
/**
|
|
1086
1283
|
* Creates new options by merging an original and an override object.
|
|
@@ -1121,8 +1318,7 @@ var ClientFactory = class {
|
|
|
1121
1318
|
}
|
|
1122
1319
|
this.transportsByName = transportsByName(options.transports);
|
|
1123
1320
|
for (const transport of options.preferredTransports ?? []) {
|
|
1124
|
-
|
|
1125
|
-
if (!factory) {
|
|
1321
|
+
if (!this.transportsByName.has(transport)) {
|
|
1126
1322
|
throw new Error(
|
|
1127
1323
|
`Unknown preferred transport: ${transport}, available transports: ${[...this.transportsByName.keys()].join()}`
|
|
1128
1324
|
);
|
|
@@ -1138,7 +1334,7 @@ var ClientFactory = class {
|
|
|
1138
1334
|
async createFromAgentCard(agentCard) {
|
|
1139
1335
|
const agentCardPreferred = agentCard.preferredTransport ?? JsonRpcTransportFactory.name;
|
|
1140
1336
|
const additionalInterfaces = agentCard.additionalInterfaces ?? [];
|
|
1141
|
-
const urlsPerAgentTransports = new
|
|
1337
|
+
const urlsPerAgentTransports = new CaseInsensitiveMap([
|
|
1142
1338
|
[agentCardPreferred, agentCard.url],
|
|
1143
1339
|
...additionalInterfaces.map((i) => [i.transport, i.url])
|
|
1144
1340
|
]);
|
|
@@ -1194,7 +1390,7 @@ function mergeTransports(original, overrides) {
|
|
|
1194
1390
|
return Array.from(result.values());
|
|
1195
1391
|
}
|
|
1196
1392
|
function transportsByName(transports) {
|
|
1197
|
-
const result =
|
|
1393
|
+
const result = new CaseInsensitiveMap();
|
|
1198
1394
|
if (!transports) {
|
|
1199
1395
|
return result;
|
|
1200
1396
|
}
|
|
@@ -1212,6 +1408,23 @@ function mergeArrays(a1, a2) {
|
|
|
1212
1408
|
}
|
|
1213
1409
|
return [...a1 ?? [], ...a2 ?? []];
|
|
1214
1410
|
}
|
|
1411
|
+
var CaseInsensitiveMap = class extends Map {
|
|
1412
|
+
normalizeKey(key) {
|
|
1413
|
+
return key.toUpperCase();
|
|
1414
|
+
}
|
|
1415
|
+
set(key, value) {
|
|
1416
|
+
return super.set(this.normalizeKey(key), value);
|
|
1417
|
+
}
|
|
1418
|
+
get(key) {
|
|
1419
|
+
return super.get(this.normalizeKey(key));
|
|
1420
|
+
}
|
|
1421
|
+
has(key) {
|
|
1422
|
+
return super.has(this.normalizeKey(key));
|
|
1423
|
+
}
|
|
1424
|
+
delete(key) {
|
|
1425
|
+
return super.delete(this.normalizeKey(key));
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1215
1428
|
|
|
1216
1429
|
// src/client/service-parameters.ts
|
|
1217
1430
|
var ServiceParameters = {
|
|
@@ -1268,15 +1481,24 @@ var ClientCallContextKey = class {
|
|
|
1268
1481
|
export {
|
|
1269
1482
|
A2AClient,
|
|
1270
1483
|
AgentCardResolver,
|
|
1484
|
+
AuthenticatedExtendedCardNotConfiguredError,
|
|
1271
1485
|
Client,
|
|
1272
1486
|
ClientCallContext,
|
|
1273
1487
|
ClientCallContextKey,
|
|
1274
1488
|
ClientFactory,
|
|
1275
1489
|
ClientFactoryOptions,
|
|
1490
|
+
ContentTypeNotSupportedError,
|
|
1276
1491
|
DefaultAgentCardResolver,
|
|
1492
|
+
InvalidAgentResponseError,
|
|
1277
1493
|
JsonRpcTransport,
|
|
1278
1494
|
JsonRpcTransportFactory,
|
|
1495
|
+
PushNotificationNotSupportedError,
|
|
1496
|
+
RestTransport,
|
|
1497
|
+
RestTransportFactory,
|
|
1279
1498
|
ServiceParameters,
|
|
1499
|
+
TaskNotCancelableError,
|
|
1500
|
+
TaskNotFoundError,
|
|
1501
|
+
UnsupportedOperationError,
|
|
1280
1502
|
createAuthenticatingFetchWithRetry,
|
|
1281
1503
|
withA2AExtensions
|
|
1282
1504
|
};
|