@a2a-js/sdk 0.3.6 → 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.
@@ -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
- export { A2AClient, type A2AClientOptions, type AfterArgs, AgentCardResolver, type AgentCardResolverOptions, type AuthenticationHandler, type BeforeArgs, type CallInterceptor, Client, ClientCallContext, ClientCallContextKey, type ClientCallInput, type ClientCallResult, type ClientConfig, ClientFactory, ClientFactoryOptions, type ContextUpdate, DefaultAgentCardResolver, type HttpHeaders, JsonRpcTransport, JsonRpcTransportFactory, type JsonRpcTransportOptions, type RequestOptions, ServiceParameters, type ServiceParametersUpdate, type Transport, type TransportFactory, createAuthenticatingFetchWithRetry, withA2AExtensions };
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 };
@@ -1,3 +1,14 @@
1
+ import {
2
+ A2A_ERROR_CODE,
3
+ AuthenticatedExtendedCardNotConfiguredError,
4
+ ContentTypeNotSupportedError,
5
+ InvalidAgentResponseError,
6
+ PushNotificationNotSupportedError,
7
+ TaskNotCancelableError,
8
+ TaskNotFoundError,
9
+ UnsupportedOperationError,
10
+ parseSseStream
11
+ } from "../chunk-SJNAG4AL.js";
1
12
  import {
2
13
  AGENT_CARD_PATH,
3
14
  HTTP_EXTENSION_HEADER
@@ -6,50 +17,6 @@ import {
6
17
  Extensions
7
18
  } from "../chunk-ZX6KNMCP.js";
8
19
 
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
20
  // src/client/transports/json_rpc_transport.ts
54
21
  var JsonRpcTransport = class _JsonRpcTransport {
55
22
  customFetchImpl;
@@ -218,55 +185,8 @@ var JsonRpcTransport = class _JsonRpcTransport {
218
185
  `Invalid response Content-Type for SSE stream for ${method}. Expected 'text/event-stream'.`
219
186
  );
220
187
  }
221
- yield* this._parseA2ASseStream(response, clientRequestId);
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();
188
+ for await (const event of parseSseStream(response)) {
189
+ yield this._processSseEventData(event.data, clientRequestId);
270
190
  }
271
191
  }
272
192
  _processSseEventData(jsonData, originalRequestId) {
@@ -274,7 +194,7 @@ var JsonRpcTransport = class _JsonRpcTransport {
274
194
  throw new Error("Attempted to process empty SSE event data.");
275
195
  }
276
196
  try {
277
- const sseJsonRpcResponse = JSON.parse(jsonData.replace(/\n$/, ""));
197
+ const sseJsonRpcResponse = JSON.parse(jsonData);
278
198
  const a2aStreamResponse = sseJsonRpcResponse;
279
199
  if (a2aStreamResponse.id !== originalRequestId) {
280
200
  console.warn(
@@ -1074,13 +994,234 @@ var Client = class {
1074
994
  }
1075
995
  };
1076
996
 
997
+ // src/client/transports/rest_transport.ts
998
+ var RestTransport = class _RestTransport {
999
+ customFetchImpl;
1000
+ endpoint;
1001
+ constructor(options) {
1002
+ this.endpoint = options.endpoint.replace(/\/+$/, "");
1003
+ this.customFetchImpl = options.fetchImpl;
1004
+ }
1005
+ async getExtendedAgentCard(options) {
1006
+ return this._sendRequest("GET", "/v1/card", void 0, options);
1007
+ }
1008
+ async sendMessage(params, options) {
1009
+ return this._sendRequest("POST", "/v1/message:send", params, options);
1010
+ }
1011
+ async *sendMessageStream(params, options) {
1012
+ yield* this._sendStreamingRequest("/v1/message:stream", params, options);
1013
+ }
1014
+ async setTaskPushNotificationConfig(params, options) {
1015
+ return this._sendRequest(
1016
+ "POST",
1017
+ `/v1/tasks/${encodeURIComponent(params.taskId)}/pushNotificationConfigs`,
1018
+ {
1019
+ pushNotificationConfig: params.pushNotificationConfig
1020
+ },
1021
+ options
1022
+ );
1023
+ }
1024
+ async getTaskPushNotificationConfig(params, options) {
1025
+ const { pushNotificationConfigId } = params;
1026
+ if (!pushNotificationConfigId) {
1027
+ throw new Error(
1028
+ "pushNotificationConfigId is required for getTaskPushNotificationConfig with REST transport."
1029
+ );
1030
+ }
1031
+ return this._sendRequest(
1032
+ "GET",
1033
+ `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(pushNotificationConfigId)}`,
1034
+ void 0,
1035
+ options
1036
+ );
1037
+ }
1038
+ async listTaskPushNotificationConfig(params, options) {
1039
+ return this._sendRequest(
1040
+ "GET",
1041
+ `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs`,
1042
+ void 0,
1043
+ options
1044
+ );
1045
+ }
1046
+ async deleteTaskPushNotificationConfig(params, options) {
1047
+ await this._sendRequest(
1048
+ "DELETE",
1049
+ `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(params.pushNotificationConfigId)}`,
1050
+ void 0,
1051
+ options
1052
+ );
1053
+ }
1054
+ async getTask(params, options) {
1055
+ const queryParams = new URLSearchParams();
1056
+ if (params.historyLength !== void 0) {
1057
+ queryParams.set("historyLength", String(params.historyLength));
1058
+ }
1059
+ const queryString = queryParams.toString();
1060
+ const path = `/v1/tasks/${encodeURIComponent(params.id)}${queryString ? `?${queryString}` : ""}`;
1061
+ return this._sendRequest("GET", path, void 0, options);
1062
+ }
1063
+ async cancelTask(params, options) {
1064
+ return this._sendRequest(
1065
+ "POST",
1066
+ `/v1/tasks/${encodeURIComponent(params.id)}:cancel`,
1067
+ void 0,
1068
+ options
1069
+ );
1070
+ }
1071
+ async *resubscribeTask(params, options) {
1072
+ yield* this._sendStreamingRequest(
1073
+ `/v1/tasks/${encodeURIComponent(params.id)}:subscribe`,
1074
+ void 0,
1075
+ options
1076
+ );
1077
+ }
1078
+ _fetch(...args) {
1079
+ if (this.customFetchImpl) {
1080
+ return this.customFetchImpl(...args);
1081
+ }
1082
+ if (typeof fetch === "function") {
1083
+ return fetch(...args);
1084
+ }
1085
+ throw new Error(
1086
+ "A `fetch` implementation was not provided and is not available in the global scope. Please provide a `fetchImpl` in the RestTransportOptions."
1087
+ );
1088
+ }
1089
+ _buildHeaders(options, acceptHeader = "application/json") {
1090
+ return {
1091
+ ...options?.serviceParameters,
1092
+ "Content-Type": "application/json",
1093
+ Accept: acceptHeader
1094
+ };
1095
+ }
1096
+ async _sendRequest(method, path, body, options) {
1097
+ const url = `${this.endpoint}${path}`;
1098
+ const requestInit = {
1099
+ method,
1100
+ headers: this._buildHeaders(options),
1101
+ signal: options?.signal
1102
+ };
1103
+ if (body !== void 0 && method !== "GET") {
1104
+ requestInit.body = JSON.stringify(body);
1105
+ }
1106
+ const response = await this._fetch(url, requestInit);
1107
+ if (!response.ok) {
1108
+ await this._handleErrorResponse(response, path);
1109
+ }
1110
+ if (response.status === 204) {
1111
+ return void 0;
1112
+ }
1113
+ const result = await response.json();
1114
+ return result;
1115
+ }
1116
+ async _handleErrorResponse(response, path) {
1117
+ let errorBodyText = "(empty or non-JSON response)";
1118
+ let errorBody;
1119
+ try {
1120
+ errorBodyText = await response.text();
1121
+ if (errorBodyText) {
1122
+ errorBody = JSON.parse(errorBodyText);
1123
+ }
1124
+ } catch (e) {
1125
+ throw new Error(
1126
+ `HTTP error for ${path}! Status: ${response.status} ${response.statusText}. Response: ${errorBodyText}`,
1127
+ { cause: e }
1128
+ );
1129
+ }
1130
+ if (errorBody && typeof errorBody.code === "number") {
1131
+ throw _RestTransport.mapToError(errorBody);
1132
+ }
1133
+ throw new Error(
1134
+ `HTTP error for ${path}! Status: ${response.status} ${response.statusText}. Response: ${errorBodyText}`
1135
+ );
1136
+ }
1137
+ async *_sendStreamingRequest(path, body, options) {
1138
+ const url = `${this.endpoint}${path}`;
1139
+ const requestInit = {
1140
+ method: "POST",
1141
+ headers: this._buildHeaders(options, "text/event-stream"),
1142
+ signal: options?.signal
1143
+ };
1144
+ if (body !== void 0) {
1145
+ requestInit.body = JSON.stringify(body);
1146
+ }
1147
+ const response = await this._fetch(url, requestInit);
1148
+ if (!response.ok) {
1149
+ await this._handleErrorResponse(response, path);
1150
+ }
1151
+ const contentType = response.headers.get("Content-Type");
1152
+ if (!contentType?.startsWith("text/event-stream")) {
1153
+ throw new Error(
1154
+ `Invalid response Content-Type for SSE stream. Expected 'text/event-stream', got '${contentType}'.`
1155
+ );
1156
+ }
1157
+ for await (const event of parseSseStream(response)) {
1158
+ if (event.type === "error") {
1159
+ const errorData = JSON.parse(event.data);
1160
+ throw _RestTransport.mapToError(errorData);
1161
+ }
1162
+ yield this._processSseEventData(event.data);
1163
+ }
1164
+ }
1165
+ _processSseEventData(jsonData) {
1166
+ if (!jsonData.trim()) {
1167
+ throw new Error("Attempted to process empty SSE event data.");
1168
+ }
1169
+ try {
1170
+ const data = JSON.parse(jsonData);
1171
+ return data;
1172
+ } catch (e) {
1173
+ console.error("Failed to parse SSE event data:", jsonData, e);
1174
+ throw new Error(
1175
+ `Failed to parse SSE event data: "${jsonData.substring(0, 100)}...". Original error: ${e instanceof Error && e.message || "Unknown error"}`
1176
+ );
1177
+ }
1178
+ }
1179
+ static mapToError(error) {
1180
+ switch (error.code) {
1181
+ case A2A_ERROR_CODE.TASK_NOT_FOUND:
1182
+ return new TaskNotFoundError(error.message);
1183
+ case A2A_ERROR_CODE.TASK_NOT_CANCELABLE:
1184
+ return new TaskNotCancelableError(error.message);
1185
+ case A2A_ERROR_CODE.PUSH_NOTIFICATION_NOT_SUPPORTED:
1186
+ return new PushNotificationNotSupportedError(error.message);
1187
+ case A2A_ERROR_CODE.UNSUPPORTED_OPERATION:
1188
+ return new UnsupportedOperationError(error.message);
1189
+ case A2A_ERROR_CODE.CONTENT_TYPE_NOT_SUPPORTED:
1190
+ return new ContentTypeNotSupportedError(error.message);
1191
+ case A2A_ERROR_CODE.INVALID_AGENT_RESPONSE:
1192
+ return new InvalidAgentResponseError(error.message);
1193
+ case A2A_ERROR_CODE.AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED:
1194
+ return new AuthenticatedExtendedCardNotConfiguredError(error.message);
1195
+ default:
1196
+ return new Error(
1197
+ `REST error: ${error.message} (Code: ${error.code})${error.data ? ` Data: ${JSON.stringify(error.data)}` : ""}`
1198
+ );
1199
+ }
1200
+ }
1201
+ };
1202
+ var RestTransportFactory = class _RestTransportFactory {
1203
+ constructor(options) {
1204
+ this.options = options;
1205
+ }
1206
+ static name = "HTTP+JSON";
1207
+ get protocolName() {
1208
+ return _RestTransportFactory.name;
1209
+ }
1210
+ async create(url, _agentCard) {
1211
+ return new RestTransport({
1212
+ endpoint: url,
1213
+ fetchImpl: this.options?.fetchImpl
1214
+ });
1215
+ }
1216
+ };
1217
+
1077
1218
  // src/client/factory.ts
1078
1219
  var ClientFactoryOptions = {
1079
1220
  /**
1080
1221
  * SDK default options for {@link ClientFactory}.
1081
1222
  */
1082
1223
  default: {
1083
- transports: [new JsonRpcTransportFactory()]
1224
+ transports: [new JsonRpcTransportFactory(), new RestTransportFactory()]
1084
1225
  },
1085
1226
  /**
1086
1227
  * Creates new options by merging an original and an override object.
@@ -1268,15 +1409,24 @@ var ClientCallContextKey = class {
1268
1409
  export {
1269
1410
  A2AClient,
1270
1411
  AgentCardResolver,
1412
+ AuthenticatedExtendedCardNotConfiguredError,
1271
1413
  Client,
1272
1414
  ClientCallContext,
1273
1415
  ClientCallContextKey,
1274
1416
  ClientFactory,
1275
1417
  ClientFactoryOptions,
1418
+ ContentTypeNotSupportedError,
1276
1419
  DefaultAgentCardResolver,
1420
+ InvalidAgentResponseError,
1277
1421
  JsonRpcTransport,
1278
1422
  JsonRpcTransportFactory,
1423
+ PushNotificationNotSupportedError,
1424
+ RestTransport,
1425
+ RestTransportFactory,
1279
1426
  ServiceParameters,
1427
+ TaskNotCancelableError,
1428
+ TaskNotFoundError,
1429
+ UnsupportedOperationError,
1280
1430
  createAuthenticatingFetchWithRetry,
1281
1431
  withA2AExtensions
1282
1432
  };
@@ -498,6 +498,22 @@ var A2AExpressApp = class {
498
498
  // src/server/express/rest_handler.ts
499
499
  var import_express4 = __toESM(require("express"), 1);
500
500
 
501
+ // src/errors.ts
502
+ var A2A_ERROR_CODE = {
503
+ PARSE_ERROR: -32700,
504
+ INVALID_REQUEST: -32600,
505
+ METHOD_NOT_FOUND: -32601,
506
+ INVALID_PARAMS: -32602,
507
+ INTERNAL_ERROR: -32603,
508
+ TASK_NOT_FOUND: -32001,
509
+ TASK_NOT_CANCELABLE: -32002,
510
+ PUSH_NOTIFICATION_NOT_SUPPORTED: -32003,
511
+ UNSUPPORTED_OPERATION: -32004,
512
+ CONTENT_TYPE_NOT_SUPPORTED: -32005,
513
+ INVALID_AGENT_RESPONSE: -32006,
514
+ AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: -32007
515
+ };
516
+
501
517
  // src/server/transports/rest/rest_transport_handler.ts
502
518
  var HTTP_STATUS = {
503
519
  OK: 200,
@@ -511,17 +527,6 @@ var HTTP_STATUS = {
511
527
  INTERNAL_SERVER_ERROR: 500,
512
528
  NOT_IMPLEMENTED: 501
513
529
  };
514
- var A2A_ERROR_CODE = {
515
- PARSE_ERROR: -32700,
516
- INVALID_REQUEST: -32600,
517
- METHOD_NOT_FOUND: -32601,
518
- INVALID_PARAMS: -32602,
519
- TASK_NOT_FOUND: -32001,
520
- TASK_NOT_CANCELABLE: -32002,
521
- PUSH_NOTIFICATION_NOT_SUPPORTED: -32003,
522
- UNSUPPORTED_OPERATION: -32004,
523
- UNAUTHORIZED: -32005
524
- };
525
530
  function mapErrorToStatus(errorCode) {
526
531
  switch (errorCode) {
527
532
  case A2A_ERROR_CODE.PARSE_ERROR:
@@ -536,8 +541,6 @@ function mapErrorToStatus(errorCode) {
536
541
  case A2A_ERROR_CODE.PUSH_NOTIFICATION_NOT_SUPPORTED:
537
542
  case A2A_ERROR_CODE.UNSUPPORTED_OPERATION:
538
543
  return HTTP_STATUS.BAD_REQUEST;
539
- case A2A_ERROR_CODE.UNAUTHORIZED:
540
- return HTTP_STATUS.UNAUTHORIZED;
541
544
  default:
542
545
  return HTTP_STATUS.INTERNAL_SERVER_ERROR;
543
546
  }
@@ -569,8 +572,8 @@ var RestTransportHandler = class _RestTransportHandler {
569
572
  /**
570
573
  * Gets the authenticated extended agent card.
571
574
  */
572
- async getAuthenticatedExtendedAgentCard() {
573
- return this.requestHandler.getAuthenticatedExtendedAgentCard();
575
+ async getAuthenticatedExtendedAgentCard(context) {
576
+ return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
574
577
  }
575
578
  /**
576
579
  * Sends a message to the agent.
@@ -883,7 +886,7 @@ function restHandler(options) {
883
886
  "/v1/card",
884
887
  asyncHandler(async (req, res) => {
885
888
  const context = await buildContext(req);
886
- const result = await restTransportHandler.getAuthenticatedExtendedAgentCard();
889
+ const result = await restTransportHandler.getAuthenticatedExtendedAgentCard(context);
887
890
  sendResponse(res, HTTP_STATUS.OK, context, result);
888
891
  })
889
892
  );
@@ -1,3 +1,9 @@
1
+ import {
2
+ A2A_ERROR_CODE,
3
+ SSE_HEADERS,
4
+ formatSSEErrorEvent,
5
+ formatSSEEvent
6
+ } from "../../chunk-SJNAG4AL.js";
1
7
  import {
2
8
  AGENT_CARD_PATH,
3
9
  HTTP_EXTENSION_HEADER
@@ -17,28 +23,6 @@ import express3 from "express";
17
23
 
18
24
  // src/server/express/json_rpc_handler.ts
19
25
  import express from "express";
20
-
21
- // src/sse_utils.ts
22
- var SSE_HEADERS = {
23
- "Content-Type": "text/event-stream",
24
- "Cache-Control": "no-cache",
25
- Connection: "keep-alive",
26
- "X-Accel-Buffering": "no"
27
- // Disable buffering in nginx
28
- };
29
- function formatSSEEvent(event) {
30
- return `data: ${JSON.stringify(event)}
31
-
32
- `;
33
- }
34
- function formatSSEErrorEvent(error) {
35
- return `event: error
36
- data: ${JSON.stringify(error)}
37
-
38
- `;
39
- }
40
-
41
- // src/server/express/json_rpc_handler.ts
42
26
  function jsonRpcHandler(options) {
43
27
  const jsonRpcTransportHandler = new JsonRpcTransportHandler(options.requestHandler);
44
28
  const router = express.Router();
@@ -196,17 +180,6 @@ var HTTP_STATUS = {
196
180
  INTERNAL_SERVER_ERROR: 500,
197
181
  NOT_IMPLEMENTED: 501
198
182
  };
199
- var A2A_ERROR_CODE = {
200
- PARSE_ERROR: -32700,
201
- INVALID_REQUEST: -32600,
202
- METHOD_NOT_FOUND: -32601,
203
- INVALID_PARAMS: -32602,
204
- TASK_NOT_FOUND: -32001,
205
- TASK_NOT_CANCELABLE: -32002,
206
- PUSH_NOTIFICATION_NOT_SUPPORTED: -32003,
207
- UNSUPPORTED_OPERATION: -32004,
208
- UNAUTHORIZED: -32005
209
- };
210
183
  function mapErrorToStatus(errorCode) {
211
184
  switch (errorCode) {
212
185
  case A2A_ERROR_CODE.PARSE_ERROR:
@@ -221,8 +194,6 @@ function mapErrorToStatus(errorCode) {
221
194
  case A2A_ERROR_CODE.PUSH_NOTIFICATION_NOT_SUPPORTED:
222
195
  case A2A_ERROR_CODE.UNSUPPORTED_OPERATION:
223
196
  return HTTP_STATUS.BAD_REQUEST;
224
- case A2A_ERROR_CODE.UNAUTHORIZED:
225
- return HTTP_STATUS.UNAUTHORIZED;
226
197
  default:
227
198
  return HTTP_STATUS.INTERNAL_SERVER_ERROR;
228
199
  }
@@ -254,8 +225,8 @@ var RestTransportHandler = class _RestTransportHandler {
254
225
  /**
255
226
  * Gets the authenticated extended agent card.
256
227
  */
257
- async getAuthenticatedExtendedAgentCard() {
258
- return this.requestHandler.getAuthenticatedExtendedAgentCard();
228
+ async getAuthenticatedExtendedAgentCard(context) {
229
+ return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
259
230
  }
260
231
  /**
261
232
  * Sends a message to the agent.
@@ -568,7 +539,7 @@ function restHandler(options) {
568
539
  "/v1/card",
569
540
  asyncHandler(async (req, res) => {
570
541
  const context = await buildContext(req);
571
- const result = await restTransportHandler.getAuthenticatedExtendedAgentCard();
542
+ const result = await restTransportHandler.getAuthenticatedExtendedAgentCard(context);
572
543
  sendResponse(res, HTTP_STATUS.OK, context, result);
573
544
  })
574
545
  );