@a2a-js/sdk 0.3.7 → 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 +10 -0
- 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 +2157 -26
- package/dist/client/index.js +99 -27
- package/dist/server/express/index.cjs +2067 -14
- package/dist/server/express/index.js +71 -17
- package/dist/server/index.js +4 -2
- package/package.json +14 -1
- package/dist/chunk-SJNAG4AL.js +0 -122
package/dist/client/index.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A2A_ERROR_CODE,
|
|
3
|
+
AgentCard,
|
|
3
4
|
AuthenticatedExtendedCardNotConfiguredError,
|
|
4
5
|
ContentTypeNotSupportedError,
|
|
6
|
+
FromProto,
|
|
5
7
|
InvalidAgentResponseError,
|
|
8
|
+
ListTaskPushNotificationConfigResponse,
|
|
6
9
|
PushNotificationNotSupportedError,
|
|
10
|
+
SendMessageRequest,
|
|
11
|
+
SendMessageResponse,
|
|
12
|
+
StreamResponse,
|
|
13
|
+
Task,
|
|
7
14
|
TaskNotCancelableError,
|
|
8
15
|
TaskNotFoundError,
|
|
16
|
+
TaskPushNotificationConfig,
|
|
17
|
+
ToProto,
|
|
9
18
|
UnsupportedOperationError,
|
|
10
19
|
parseSseStream
|
|
11
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-DHC2REQH.js";
|
|
12
21
|
import {
|
|
13
22
|
AGENT_CARD_PATH,
|
|
14
23
|
HTTP_EXTENSION_HEADER
|
|
15
24
|
} from "../chunk-3QDLXHKS.js";
|
|
25
|
+
import "../chunk-UHZEIZLS.js";
|
|
16
26
|
import {
|
|
17
27
|
Extensions
|
|
18
28
|
} from "../chunk-ZX6KNMCP.js";
|
|
@@ -1003,23 +1013,44 @@ var RestTransport = class _RestTransport {
|
|
|
1003
1013
|
this.customFetchImpl = options.fetchImpl;
|
|
1004
1014
|
}
|
|
1005
1015
|
async getExtendedAgentCard(options) {
|
|
1006
|
-
|
|
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);
|
|
1007
1025
|
}
|
|
1008
1026
|
async sendMessage(params, options) {
|
|
1009
|
-
|
|
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);
|
|
1010
1037
|
}
|
|
1011
1038
|
async *sendMessageStream(params, options) {
|
|
1012
|
-
|
|
1039
|
+
const protoParams = ToProto.messageSendParams(params);
|
|
1040
|
+
const requestBody = SendMessageRequest.toJSON(protoParams);
|
|
1041
|
+
yield* this._sendStreamingRequest("/v1/message:stream", requestBody, options);
|
|
1013
1042
|
}
|
|
1014
1043
|
async setTaskPushNotificationConfig(params, options) {
|
|
1015
|
-
|
|
1044
|
+
const requestBody = ToProto.taskPushNotificationConfig(params);
|
|
1045
|
+
const response = await this._sendRequest(
|
|
1016
1046
|
"POST",
|
|
1017
1047
|
`/v1/tasks/${encodeURIComponent(params.taskId)}/pushNotificationConfigs`,
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1048
|
+
requestBody,
|
|
1049
|
+
options,
|
|
1050
|
+
TaskPushNotificationConfig,
|
|
1051
|
+
TaskPushNotificationConfig
|
|
1022
1052
|
);
|
|
1053
|
+
return FromProto.taskPushNotificationConfig(response);
|
|
1023
1054
|
}
|
|
1024
1055
|
async getTaskPushNotificationConfig(params, options) {
|
|
1025
1056
|
const { pushNotificationConfigId } = params;
|
|
@@ -1028,27 +1059,35 @@ var RestTransport = class _RestTransport {
|
|
|
1028
1059
|
"pushNotificationConfigId is required for getTaskPushNotificationConfig with REST transport."
|
|
1029
1060
|
);
|
|
1030
1061
|
}
|
|
1031
|
-
|
|
1062
|
+
const response = await this._sendRequest(
|
|
1032
1063
|
"GET",
|
|
1033
1064
|
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(pushNotificationConfigId)}`,
|
|
1034
1065
|
void 0,
|
|
1035
|
-
options
|
|
1066
|
+
options,
|
|
1067
|
+
void 0,
|
|
1068
|
+
TaskPushNotificationConfig
|
|
1036
1069
|
);
|
|
1070
|
+
return FromProto.taskPushNotificationConfig(response);
|
|
1037
1071
|
}
|
|
1038
1072
|
async listTaskPushNotificationConfig(params, options) {
|
|
1039
|
-
|
|
1073
|
+
const response = await this._sendRequest(
|
|
1040
1074
|
"GET",
|
|
1041
1075
|
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs`,
|
|
1042
1076
|
void 0,
|
|
1043
|
-
options
|
|
1077
|
+
options,
|
|
1078
|
+
void 0,
|
|
1079
|
+
ListTaskPushNotificationConfigResponse
|
|
1044
1080
|
);
|
|
1081
|
+
return FromProto.listTaskPushNotificationConfig(response);
|
|
1045
1082
|
}
|
|
1046
1083
|
async deleteTaskPushNotificationConfig(params, options) {
|
|
1047
1084
|
await this._sendRequest(
|
|
1048
1085
|
"DELETE",
|
|
1049
1086
|
`/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(params.pushNotificationConfigId)}`,
|
|
1050
1087
|
void 0,
|
|
1051
|
-
options
|
|
1088
|
+
options,
|
|
1089
|
+
void 0,
|
|
1090
|
+
void 0
|
|
1052
1091
|
);
|
|
1053
1092
|
}
|
|
1054
1093
|
async getTask(params, options) {
|
|
@@ -1058,15 +1097,26 @@ var RestTransport = class _RestTransport {
|
|
|
1058
1097
|
}
|
|
1059
1098
|
const queryString = queryParams.toString();
|
|
1060
1099
|
const path = `/v1/tasks/${encodeURIComponent(params.id)}${queryString ? `?${queryString}` : ""}`;
|
|
1061
|
-
|
|
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);
|
|
1062
1109
|
}
|
|
1063
1110
|
async cancelTask(params, options) {
|
|
1064
|
-
|
|
1111
|
+
const response = await this._sendRequest(
|
|
1065
1112
|
"POST",
|
|
1066
1113
|
`/v1/tasks/${encodeURIComponent(params.id)}:cancel`,
|
|
1067
1114
|
void 0,
|
|
1068
|
-
options
|
|
1115
|
+
options,
|
|
1116
|
+
void 0,
|
|
1117
|
+
Task
|
|
1069
1118
|
);
|
|
1119
|
+
return FromProto.task(response);
|
|
1070
1120
|
}
|
|
1071
1121
|
async *resubscribeTask(params, options) {
|
|
1072
1122
|
yield* this._sendStreamingRequest(
|
|
@@ -1093,7 +1143,7 @@ var RestTransport = class _RestTransport {
|
|
|
1093
1143
|
Accept: acceptHeader
|
|
1094
1144
|
};
|
|
1095
1145
|
}
|
|
1096
|
-
async _sendRequest(method, path, body, options) {
|
|
1146
|
+
async _sendRequest(method, path, body, options, requestType, responseType) {
|
|
1097
1147
|
const url = `${this.endpoint}${path}`;
|
|
1098
1148
|
const requestInit = {
|
|
1099
1149
|
method,
|
|
@@ -1101,17 +1151,22 @@ var RestTransport = class _RestTransport {
|
|
|
1101
1151
|
signal: options?.signal
|
|
1102
1152
|
};
|
|
1103
1153
|
if (body !== void 0 && method !== "GET") {
|
|
1104
|
-
|
|
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));
|
|
1105
1160
|
}
|
|
1106
1161
|
const response = await this._fetch(url, requestInit);
|
|
1107
1162
|
if (!response.ok) {
|
|
1108
1163
|
await this._handleErrorResponse(response, path);
|
|
1109
1164
|
}
|
|
1110
|
-
if (response.status === 204) {
|
|
1165
|
+
if (response.status === 204 || !responseType) {
|
|
1111
1166
|
return void 0;
|
|
1112
1167
|
}
|
|
1113
1168
|
const result = await response.json();
|
|
1114
|
-
return result;
|
|
1169
|
+
return responseType.fromJSON(result);
|
|
1115
1170
|
}
|
|
1116
1171
|
async _handleErrorResponse(response, path) {
|
|
1117
1172
|
let errorBodyText = "(empty or non-JSON response)";
|
|
@@ -1167,8 +1222,9 @@ var RestTransport = class _RestTransport {
|
|
|
1167
1222
|
throw new Error("Attempted to process empty SSE event data.");
|
|
1168
1223
|
}
|
|
1169
1224
|
try {
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1225
|
+
const response = JSON.parse(jsonData);
|
|
1226
|
+
const protoResponse = StreamResponse.fromJSON(response);
|
|
1227
|
+
return FromProto.messageStreamResult(protoResponse);
|
|
1172
1228
|
} catch (e) {
|
|
1173
1229
|
console.error("Failed to parse SSE event data:", jsonData, e);
|
|
1174
1230
|
throw new Error(
|
|
@@ -1262,8 +1318,7 @@ var ClientFactory = class {
|
|
|
1262
1318
|
}
|
|
1263
1319
|
this.transportsByName = transportsByName(options.transports);
|
|
1264
1320
|
for (const transport of options.preferredTransports ?? []) {
|
|
1265
|
-
|
|
1266
|
-
if (!factory) {
|
|
1321
|
+
if (!this.transportsByName.has(transport)) {
|
|
1267
1322
|
throw new Error(
|
|
1268
1323
|
`Unknown preferred transport: ${transport}, available transports: ${[...this.transportsByName.keys()].join()}`
|
|
1269
1324
|
);
|
|
@@ -1279,7 +1334,7 @@ var ClientFactory = class {
|
|
|
1279
1334
|
async createFromAgentCard(agentCard) {
|
|
1280
1335
|
const agentCardPreferred = agentCard.preferredTransport ?? JsonRpcTransportFactory.name;
|
|
1281
1336
|
const additionalInterfaces = agentCard.additionalInterfaces ?? [];
|
|
1282
|
-
const urlsPerAgentTransports = new
|
|
1337
|
+
const urlsPerAgentTransports = new CaseInsensitiveMap([
|
|
1283
1338
|
[agentCardPreferred, agentCard.url],
|
|
1284
1339
|
...additionalInterfaces.map((i) => [i.transport, i.url])
|
|
1285
1340
|
]);
|
|
@@ -1335,7 +1390,7 @@ function mergeTransports(original, overrides) {
|
|
|
1335
1390
|
return Array.from(result.values());
|
|
1336
1391
|
}
|
|
1337
1392
|
function transportsByName(transports) {
|
|
1338
|
-
const result =
|
|
1393
|
+
const result = new CaseInsensitiveMap();
|
|
1339
1394
|
if (!transports) {
|
|
1340
1395
|
return result;
|
|
1341
1396
|
}
|
|
@@ -1353,6 +1408,23 @@ function mergeArrays(a1, a2) {
|
|
|
1353
1408
|
}
|
|
1354
1409
|
return [...a1 ?? [], ...a2 ?? []];
|
|
1355
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
|
+
};
|
|
1356
1428
|
|
|
1357
1429
|
// src/client/service-parameters.ts
|
|
1358
1430
|
var ServiceParameters = {
|