@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.
@@ -1,13 +1,30 @@
1
+ import {
2
+ A2A_ERROR_CODE,
3
+ AgentCard,
4
+ FromProto,
5
+ ListTaskPushNotificationConfigResponse,
6
+ SSE_HEADERS,
7
+ SendMessageRequest,
8
+ SendMessageResponse,
9
+ StreamResponse,
10
+ Task,
11
+ TaskPushNotificationConfig,
12
+ ToProto,
13
+ formatSSEErrorEvent,
14
+ formatSSEEvent
15
+ } from "../../chunk-DHC2REQH.js";
1
16
  import {
2
17
  AGENT_CARD_PATH,
3
18
  HTTP_EXTENSION_HEADER
4
19
  } from "../../chunk-3QDLXHKS.js";
5
20
  import {
6
- A2AError,
7
21
  JsonRpcTransportHandler,
8
22
  ServerCallContext,
9
23
  UnauthenticatedUser
10
- } from "../../chunk-LTPINR5K.js";
24
+ } from "../../chunk-NUQQPJNY.js";
25
+ import {
26
+ A2AError
27
+ } from "../../chunk-UHZEIZLS.js";
11
28
  import {
12
29
  Extensions
13
30
  } from "../../chunk-ZX6KNMCP.js";
@@ -17,28 +34,6 @@ import express3 from "express";
17
34
 
18
35
  // src/server/express/json_rpc_handler.ts
19
36
  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
37
  function jsonRpcHandler(options) {
43
38
  const jsonRpcTransportHandler = new JsonRpcTransportHandler(options.requestHandler);
44
39
  const router = express.Router();
@@ -196,17 +191,6 @@ var HTTP_STATUS = {
196
191
  INTERNAL_SERVER_ERROR: 500,
197
192
  NOT_IMPLEMENTED: 501
198
193
  };
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
194
  function mapErrorToStatus(errorCode) {
211
195
  switch (errorCode) {
212
196
  case A2A_ERROR_CODE.PARSE_ERROR:
@@ -221,8 +205,6 @@ function mapErrorToStatus(errorCode) {
221
205
  case A2A_ERROR_CODE.PUSH_NOTIFICATION_NOT_SUPPORTED:
222
206
  case A2A_ERROR_CODE.UNSUPPORTED_OPERATION:
223
207
  return HTTP_STATUS.BAD_REQUEST;
224
- case A2A_ERROR_CODE.UNAUTHORIZED:
225
- return HTTP_STATUS.UNAUTHORIZED;
226
208
  default:
227
209
  return HTTP_STATUS.INTERNAL_SERVER_ERROR;
228
210
  }
@@ -254,8 +236,8 @@ var RestTransportHandler = class _RestTransportHandler {
254
236
  /**
255
237
  * Gets the authenticated extended agent card.
256
238
  */
257
- async getAuthenticatedExtendedAgentCard() {
258
- return this.requestHandler.getAuthenticatedExtendedAgentCard();
239
+ async getAuthenticatedExtendedAgentCard(context) {
240
+ return this.requestHandler.getAuthenticatedExtendedAgentCard(context);
259
241
  }
260
242
  /**
261
243
  * Sends a message to the agent.
@@ -498,13 +480,16 @@ function restHandler(options) {
498
480
  res.setHeader(HTTP_EXTENSION_HEADER, Array.from(context.activatedExtensions));
499
481
  }
500
482
  };
501
- const sendResponse = (res, statusCode, context, body) => {
483
+ const sendResponse = (res, statusCode, context, body, responseType) => {
502
484
  setExtensionsHeader(res, context);
503
485
  res.status(statusCode);
504
486
  if (statusCode === HTTP_STATUS.NO_CONTENT) {
505
487
  res.end();
506
488
  } else {
507
- res.json(body);
489
+ if (!responseType) {
490
+ throw new Error("Bug: toJson serializer must be provided for non-204 responses.");
491
+ }
492
+ res.json(responseType.toJSON(body));
508
493
  }
509
494
  };
510
495
  const sendStreamResponse = async (res, stream, context) => {
@@ -525,10 +510,14 @@ function restHandler(options) {
525
510
  res.flushHeaders();
526
511
  try {
527
512
  if (!firstResult.done) {
528
- res.write(formatSSEEvent(firstResult.value));
513
+ const proto = ToProto.messageStreamResult(firstResult.value);
514
+ const result = StreamResponse.toJSON(proto);
515
+ res.write(formatSSEEvent(result));
529
516
  }
530
517
  for await (const event of { [Symbol.asyncIterator]: () => iterator }) {
531
- res.write(formatSSEEvent(event));
518
+ const proto = ToProto.messageStreamResult(event);
519
+ const result = StreamResponse.toJSON(proto);
520
+ res.write(formatSSEEvent(result));
532
521
  }
533
522
  } catch (streamError) {
534
523
  console.error("SSE streaming error:", streamError);
@@ -568,23 +557,35 @@ function restHandler(options) {
568
557
  "/v1/card",
569
558
  asyncHandler(async (req, res) => {
570
559
  const context = await buildContext(req);
571
- const result = await restTransportHandler.getAuthenticatedExtendedAgentCard();
572
- sendResponse(res, HTTP_STATUS.OK, context, result);
560
+ const result = await restTransportHandler.getAuthenticatedExtendedAgentCard(context);
561
+ const protoResult = ToProto.agentCard(result);
562
+ sendResponse(res, HTTP_STATUS.OK, context, protoResult, AgentCard);
573
563
  })
574
564
  );
575
565
  router.post(
576
566
  "/v1/message\\:send",
577
567
  asyncHandler(async (req, res) => {
578
568
  const context = await buildContext(req);
579
- const result = await restTransportHandler.sendMessage(req.body, context);
580
- sendResponse(res, HTTP_STATUS.CREATED, context, result);
569
+ const protoReq = SendMessageRequest.fromJSON(req.body);
570
+ const params = FromProto.messageSendParams(protoReq);
571
+ const result = await restTransportHandler.sendMessage(params, context);
572
+ const protoResult = ToProto.messageSendResult(result);
573
+ sendResponse(
574
+ res,
575
+ HTTP_STATUS.CREATED,
576
+ context,
577
+ protoResult,
578
+ SendMessageResponse
579
+ );
581
580
  })
582
581
  );
583
582
  router.post(
584
583
  "/v1/message\\:stream",
585
584
  asyncHandler(async (req, res) => {
586
585
  const context = await buildContext(req);
587
- const stream = await restTransportHandler.sendMessageStream(req.body, context);
586
+ const protoReq = SendMessageRequest.fromJSON(req.body);
587
+ const params = FromProto.messageSendParams(protoReq);
588
+ const stream = await restTransportHandler.sendMessageStream(params, context);
588
589
  await sendStreamResponse(res, stream, context);
589
590
  })
590
591
  );
@@ -595,9 +596,11 @@ function restHandler(options) {
595
596
  const result = await restTransportHandler.getTask(
596
597
  req.params.taskId,
597
598
  context,
598
- req.query.historyLength
599
+ //TODO: clarify for version 1.0.0 the format of the historyLength query parameter, and if history should always be added to the returned object
600
+ req.query.historyLength ?? req.query.history_length
599
601
  );
600
- sendResponse(res, HTTP_STATUS.OK, context, result);
602
+ const protoResult = ToProto.task(result);
603
+ sendResponse(res, HTTP_STATUS.OK, context, protoResult, Task);
601
604
  })
602
605
  );
603
606
  router.post(
@@ -605,7 +608,8 @@ function restHandler(options) {
605
608
  asyncHandler(async (req, res) => {
606
609
  const context = await buildContext(req);
607
610
  const result = await restTransportHandler.cancelTask(req.params.taskId, context);
608
- sendResponse(res, HTTP_STATUS.ACCEPTED, context, result);
611
+ const protoResult = ToProto.task(result);
612
+ sendResponse(res, HTTP_STATUS.ACCEPTED, context, protoResult, Task);
609
613
  })
610
614
  );
611
615
  router.post(
@@ -626,7 +630,14 @@ function restHandler(options) {
626
630
  task_id: req.params.taskId
627
631
  };
628
632
  const result = await restTransportHandler.setTaskPushNotificationConfig(config, context);
629
- sendResponse(res, HTTP_STATUS.CREATED, context, result);
633
+ const protoResult = ToProto.taskPushNotificationConfig(result);
634
+ sendResponse(
635
+ res,
636
+ HTTP_STATUS.CREATED,
637
+ context,
638
+ protoResult,
639
+ TaskPushNotificationConfig
640
+ );
630
641
  })
631
642
  );
632
643
  router.get(
@@ -637,7 +648,14 @@ function restHandler(options) {
637
648
  req.params.taskId,
638
649
  context
639
650
  );
640
- sendResponse(res, HTTP_STATUS.OK, context, result);
651
+ const protoResult = ToProto.listTaskPushNotificationConfig(result);
652
+ sendResponse(
653
+ res,
654
+ HTTP_STATUS.OK,
655
+ context,
656
+ protoResult,
657
+ ListTaskPushNotificationConfigResponse
658
+ );
641
659
  })
642
660
  );
643
661
  router.get(
@@ -649,7 +667,14 @@ function restHandler(options) {
649
667
  req.params.configId,
650
668
  context
651
669
  );
652
- sendResponse(res, HTTP_STATUS.OK, context, result);
670
+ const protoResult = ToProto.taskPushNotificationConfig(result);
671
+ sendResponse(
672
+ res,
673
+ HTTP_STATUS.OK,
674
+ context,
675
+ protoResult,
676
+ TaskPushNotificationConfig
677
+ );
653
678
  })
654
679
  );
655
680
  router.delete(
@@ -54,16 +54,194 @@ var RequestContext = class {
54
54
  };
55
55
 
56
56
  // src/server/events/execution_event_bus.ts
57
- var import_events = require("events");
58
- var DefaultExecutionEventBus = class extends import_events.EventEmitter {
59
- constructor() {
60
- super();
57
+ var CustomEventImpl = typeof CustomEvent !== "undefined" ? CustomEvent : class CustomEventPolyfill extends Event {
58
+ detail;
59
+ constructor(type, eventInitDict) {
60
+ super(type, eventInitDict);
61
+ this.detail = eventInitDict?.detail ?? null;
61
62
  }
63
+ };
64
+ function isAgentExecutionCustomEvent(e) {
65
+ return e instanceof CustomEventImpl;
66
+ }
67
+ var DefaultExecutionEventBus = class extends EventTarget {
68
+ // Separate storage for each event type - both use the interface's Listener type
69
+ // but are invoked differently (with event payload vs. no arguments)
70
+ eventListeners = /* @__PURE__ */ new Map();
71
+ finishedListeners = /* @__PURE__ */ new Map();
62
72
  publish(event) {
63
- this.emit("event", event);
73
+ this.dispatchEvent(new CustomEventImpl("event", { detail: event }));
64
74
  }
65
75
  finished() {
66
- this.emit("finished");
76
+ this.dispatchEvent(new Event("finished"));
77
+ }
78
+ /**
79
+ * EventEmitter-compatible 'on' method.
80
+ * Wraps the listener to extract event detail from CustomEvent.
81
+ * Supports multiple registrations of the same listener (like EventEmitter).
82
+ * @param eventName The event name to listen for.
83
+ * @param listener The callback function to invoke when the event is emitted.
84
+ * @returns This instance for method chaining.
85
+ */
86
+ on(eventName, listener) {
87
+ if (eventName === "event") {
88
+ this.addEventListenerInternal(listener);
89
+ } else {
90
+ this.addFinishedListenerInternal(listener);
91
+ }
92
+ return this;
93
+ }
94
+ /**
95
+ * EventEmitter-compatible 'off' method.
96
+ * Uses the stored wrapped listener for proper removal.
97
+ * Removes at most one instance of a listener per call (like EventEmitter).
98
+ * @param eventName The event name to stop listening for.
99
+ * @param listener The callback function to remove.
100
+ * @returns This instance for method chaining.
101
+ */
102
+ off(eventName, listener) {
103
+ if (eventName === "event") {
104
+ this.removeEventListenerInternal(listener);
105
+ } else {
106
+ this.removeFinishedListenerInternal(listener);
107
+ }
108
+ return this;
109
+ }
110
+ /**
111
+ * EventEmitter-compatible 'once' method.
112
+ * Listener is automatically removed after first invocation.
113
+ * Supports multiple registrations of the same listener (like EventEmitter).
114
+ * @param eventName The event name to listen for once.
115
+ * @param listener The callback function to invoke when the event is emitted.
116
+ * @returns This instance for method chaining.
117
+ */
118
+ once(eventName, listener) {
119
+ if (eventName === "event") {
120
+ this.addEventListenerOnceInternal(listener);
121
+ } else {
122
+ this.addFinishedListenerOnceInternal(listener);
123
+ }
124
+ return this;
125
+ }
126
+ /**
127
+ * EventEmitter-compatible 'removeAllListeners' method.
128
+ * Removes all listeners for a specific event or all events.
129
+ * @param eventName Optional event name to remove listeners for. If omitted, removes all.
130
+ * @returns This instance for method chaining.
131
+ */
132
+ removeAllListeners(eventName) {
133
+ if (eventName === void 0 || eventName === "event") {
134
+ for (const wrappedListeners of this.eventListeners.values()) {
135
+ for (const wrapped of wrappedListeners) {
136
+ this.removeEventListener("event", wrapped);
137
+ }
138
+ }
139
+ this.eventListeners.clear();
140
+ }
141
+ if (eventName === void 0 || eventName === "finished") {
142
+ for (const wrappedListeners of this.finishedListeners.values()) {
143
+ for (const wrapped of wrappedListeners) {
144
+ this.removeEventListener("finished", wrapped);
145
+ }
146
+ }
147
+ this.finishedListeners.clear();
148
+ }
149
+ return this;
150
+ }
151
+ // ========================
152
+ // Helper methods for listener tracking
153
+ // ========================
154
+ /**
155
+ * Adds a wrapped listener to the tracking map.
156
+ */
157
+ trackListener(listenerMap, listener, wrapped) {
158
+ const existing = listenerMap.get(listener);
159
+ if (existing) {
160
+ existing.push(wrapped);
161
+ } else {
162
+ listenerMap.set(listener, [wrapped]);
163
+ }
164
+ }
165
+ /**
166
+ * Removes a wrapped listener from the tracking map (for once cleanup).
167
+ */
168
+ untrackWrappedListener(listenerMap, listener, wrapped) {
169
+ const wrappedList = listenerMap.get(listener);
170
+ if (wrappedList && wrappedList.length > 0) {
171
+ const index = wrappedList.indexOf(wrapped);
172
+ if (index !== -1) {
173
+ wrappedList.splice(index, 1);
174
+ if (wrappedList.length === 0) {
175
+ listenerMap.delete(listener);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ // ========================
181
+ // Internal methods for 'event' listeners
182
+ // ========================
183
+ addEventListenerInternal(listener) {
184
+ const wrapped = (e) => {
185
+ if (!isAgentExecutionCustomEvent(e)) {
186
+ throw new Error('Internal error: expected CustomEvent for "event" type');
187
+ }
188
+ listener.call(this, e.detail);
189
+ };
190
+ this.trackListener(this.eventListeners, listener, wrapped);
191
+ this.addEventListener("event", wrapped);
192
+ }
193
+ removeEventListenerInternal(listener) {
194
+ const wrappedList = this.eventListeners.get(listener);
195
+ if (wrappedList && wrappedList.length > 0) {
196
+ const wrapped = wrappedList.pop();
197
+ if (wrappedList.length === 0) {
198
+ this.eventListeners.delete(listener);
199
+ }
200
+ this.removeEventListener("event", wrapped);
201
+ }
202
+ }
203
+ addEventListenerOnceInternal(listener) {
204
+ const wrapped = (e) => {
205
+ if (!isAgentExecutionCustomEvent(e)) {
206
+ throw new Error('Internal error: expected CustomEvent for "event" type');
207
+ }
208
+ this.untrackWrappedListener(this.eventListeners, listener, wrapped);
209
+ listener.call(this, e.detail);
210
+ };
211
+ this.trackListener(this.eventListeners, listener, wrapped);
212
+ this.addEventListener("event", wrapped, { once: true });
213
+ }
214
+ // ========================
215
+ // Internal methods for 'finished' listeners
216
+ // ========================
217
+ // The interface declares listeners as (event: AgentExecutionEvent) => void,
218
+ // but for 'finished' events they are invoked with no arguments (EventEmitter behavior).
219
+ // We use Function.prototype.call to invoke with `this` as the event bus (matching
220
+ // EventEmitter semantics) and no arguments, which is type-safe.
221
+ addFinishedListenerInternal(listener) {
222
+ const wrapped = () => {
223
+ listener.call(this);
224
+ };
225
+ this.trackListener(this.finishedListeners, listener, wrapped);
226
+ this.addEventListener("finished", wrapped);
227
+ }
228
+ removeFinishedListenerInternal(listener) {
229
+ const wrappedList = this.finishedListeners.get(listener);
230
+ if (wrappedList && wrappedList.length > 0) {
231
+ const wrapped = wrappedList.pop();
232
+ if (wrappedList.length === 0) {
233
+ this.finishedListeners.delete(listener);
234
+ }
235
+ this.removeEventListener("finished", wrapped);
236
+ }
237
+ }
238
+ addFinishedListenerOnceInternal(listener) {
239
+ const wrapped = () => {
240
+ this.untrackWrappedListener(this.finishedListeners, listener, wrapped);
241
+ listener.call(this);
242
+ };
243
+ this.trackListener(this.finishedListeners, listener, wrapped);
244
+ this.addEventListener("finished", wrapped, { once: true });
67
245
  }
68
246
  };
69
247
 
@@ -1,21 +1,81 @@
1
- import { EventEmitter } from 'events';
2
1
  import { F as Message, ay as Task, aQ as TaskStatusUpdateEvent, aS as TaskArtifactUpdateEvent, z as PushNotificationConfig, ae as AgentCard, x as MessageSendParams, X as TaskQueryParams, Z as TaskIdParams, $ as TaskPushNotificationConfig, a3 as GetTaskPushNotificationConfigParams, a7 as ListTaskPushNotificationConfigParams, a9 as DeleteTaskPushNotificationConfigParams, j as JSONRPCResponse, aw as JSONRPCError } from '../extensions-DvruCIzw.cjs';
3
2
  import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-B3LxMq3P.cjs';
4
3
  export { a as UnauthenticatedUser, U as User } from '../a2a_request_handler-B3LxMq3P.cjs';
5
4
 
6
5
  type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
+ /**
7
+ * Event names supported by ExecutionEventBus.
8
+ */
9
+ type ExecutionEventName = 'event' | 'finished';
7
10
  interface ExecutionEventBus {
8
11
  publish(event: AgentExecutionEvent): void;
9
- on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
10
- off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
11
- once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
12
- removeAllListeners(eventName?: 'event' | 'finished'): this;
12
+ on(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
13
+ off(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
14
+ once(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
15
+ removeAllListeners(eventName?: ExecutionEventName): this;
13
16
  finished(): void;
14
17
  }
15
- declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
16
- constructor();
18
+ /**
19
+ * Web-compatible ExecutionEventBus using EventTarget.
20
+ * Works across all modern runtimes: Node.js 15+, browsers, Cloudflare Workers, Deno, Bun.
21
+ *
22
+ * This implementation provides the subset of EventEmitter methods defined in the
23
+ * ExecutionEventBus interface. Users extending DefaultExecutionEventBus should note
24
+ * that other EventEmitter methods (e.g., listenerCount, rawListeners) are not available.
25
+ */
26
+ declare class DefaultExecutionEventBus extends EventTarget implements ExecutionEventBus {
27
+ private readonly eventListeners;
28
+ private readonly finishedListeners;
17
29
  publish(event: AgentExecutionEvent): void;
18
30
  finished(): void;
31
+ /**
32
+ * EventEmitter-compatible 'on' method.
33
+ * Wraps the listener to extract event detail from CustomEvent.
34
+ * Supports multiple registrations of the same listener (like EventEmitter).
35
+ * @param eventName The event name to listen for.
36
+ * @param listener The callback function to invoke when the event is emitted.
37
+ * @returns This instance for method chaining.
38
+ */
39
+ on(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
40
+ /**
41
+ * EventEmitter-compatible 'off' method.
42
+ * Uses the stored wrapped listener for proper removal.
43
+ * Removes at most one instance of a listener per call (like EventEmitter).
44
+ * @param eventName The event name to stop listening for.
45
+ * @param listener The callback function to remove.
46
+ * @returns This instance for method chaining.
47
+ */
48
+ off(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
49
+ /**
50
+ * EventEmitter-compatible 'once' method.
51
+ * Listener is automatically removed after first invocation.
52
+ * Supports multiple registrations of the same listener (like EventEmitter).
53
+ * @param eventName The event name to listen for once.
54
+ * @param listener The callback function to invoke when the event is emitted.
55
+ * @returns This instance for method chaining.
56
+ */
57
+ once(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
58
+ /**
59
+ * EventEmitter-compatible 'removeAllListeners' method.
60
+ * Removes all listeners for a specific event or all events.
61
+ * @param eventName Optional event name to remove listeners for. If omitted, removes all.
62
+ * @returns This instance for method chaining.
63
+ */
64
+ removeAllListeners(eventName?: ExecutionEventName): this;
65
+ /**
66
+ * Adds a wrapped listener to the tracking map.
67
+ */
68
+ private trackListener;
69
+ /**
70
+ * Removes a wrapped listener from the tracking map (for once cleanup).
71
+ */
72
+ private untrackWrappedListener;
73
+ private addEventListenerInternal;
74
+ private removeEventListenerInternal;
75
+ private addEventListenerOnceInternal;
76
+ private addFinishedListenerInternal;
77
+ private removeFinishedListenerInternal;
78
+ private addFinishedListenerOnceInternal;
19
79
  }
20
80
 
21
81
  declare class RequestContext {
@@ -253,4 +313,4 @@ declare class DefaultPushNotificationSender implements PushNotificationSender {
253
313
  private _dispatchNotification;
254
314
  }
255
315
 
256
- export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, type ExtendedAgentCardProvider, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, ServerCallContext, type TaskStore };
316
+ export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, type ExecutionEventName, ExecutionEventQueue, type ExtendedAgentCardProvider, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, ServerCallContext, type TaskStore };
@@ -1,21 +1,81 @@
1
- import { EventEmitter } from 'events';
2
1
  import { F as Message, ay as Task, aQ as TaskStatusUpdateEvent, aS as TaskArtifactUpdateEvent, z as PushNotificationConfig, ae as AgentCard, x as MessageSendParams, X as TaskQueryParams, Z as TaskIdParams, $ as TaskPushNotificationConfig, a3 as GetTaskPushNotificationConfigParams, a7 as ListTaskPushNotificationConfigParams, a9 as DeleteTaskPushNotificationConfigParams, j as JSONRPCResponse, aw as JSONRPCError } from '../extensions-DvruCIzw.js';
3
2
  import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-BuP9LgXH.js';
4
3
  export { a as UnauthenticatedUser, U as User } from '../a2a_request_handler-BuP9LgXH.js';
5
4
 
6
5
  type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
+ /**
7
+ * Event names supported by ExecutionEventBus.
8
+ */
9
+ type ExecutionEventName = 'event' | 'finished';
7
10
  interface ExecutionEventBus {
8
11
  publish(event: AgentExecutionEvent): void;
9
- on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
10
- off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
11
- once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
12
- removeAllListeners(eventName?: 'event' | 'finished'): this;
12
+ on(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
13
+ off(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
14
+ once(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
15
+ removeAllListeners(eventName?: ExecutionEventName): this;
13
16
  finished(): void;
14
17
  }
15
- declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
16
- constructor();
18
+ /**
19
+ * Web-compatible ExecutionEventBus using EventTarget.
20
+ * Works across all modern runtimes: Node.js 15+, browsers, Cloudflare Workers, Deno, Bun.
21
+ *
22
+ * This implementation provides the subset of EventEmitter methods defined in the
23
+ * ExecutionEventBus interface. Users extending DefaultExecutionEventBus should note
24
+ * that other EventEmitter methods (e.g., listenerCount, rawListeners) are not available.
25
+ */
26
+ declare class DefaultExecutionEventBus extends EventTarget implements ExecutionEventBus {
27
+ private readonly eventListeners;
28
+ private readonly finishedListeners;
17
29
  publish(event: AgentExecutionEvent): void;
18
30
  finished(): void;
31
+ /**
32
+ * EventEmitter-compatible 'on' method.
33
+ * Wraps the listener to extract event detail from CustomEvent.
34
+ * Supports multiple registrations of the same listener (like EventEmitter).
35
+ * @param eventName The event name to listen for.
36
+ * @param listener The callback function to invoke when the event is emitted.
37
+ * @returns This instance for method chaining.
38
+ */
39
+ on(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
40
+ /**
41
+ * EventEmitter-compatible 'off' method.
42
+ * Uses the stored wrapped listener for proper removal.
43
+ * Removes at most one instance of a listener per call (like EventEmitter).
44
+ * @param eventName The event name to stop listening for.
45
+ * @param listener The callback function to remove.
46
+ * @returns This instance for method chaining.
47
+ */
48
+ off(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
49
+ /**
50
+ * EventEmitter-compatible 'once' method.
51
+ * Listener is automatically removed after first invocation.
52
+ * Supports multiple registrations of the same listener (like EventEmitter).
53
+ * @param eventName The event name to listen for once.
54
+ * @param listener The callback function to invoke when the event is emitted.
55
+ * @returns This instance for method chaining.
56
+ */
57
+ once(eventName: ExecutionEventName, listener: (event: AgentExecutionEvent) => void): this;
58
+ /**
59
+ * EventEmitter-compatible 'removeAllListeners' method.
60
+ * Removes all listeners for a specific event or all events.
61
+ * @param eventName Optional event name to remove listeners for. If omitted, removes all.
62
+ * @returns This instance for method chaining.
63
+ */
64
+ removeAllListeners(eventName?: ExecutionEventName): this;
65
+ /**
66
+ * Adds a wrapped listener to the tracking map.
67
+ */
68
+ private trackListener;
69
+ /**
70
+ * Removes a wrapped listener from the tracking map (for once cleanup).
71
+ */
72
+ private untrackWrappedListener;
73
+ private addEventListenerInternal;
74
+ private removeEventListenerInternal;
75
+ private addEventListenerOnceInternal;
76
+ private addFinishedListenerInternal;
77
+ private removeFinishedListenerInternal;
78
+ private addFinishedListenerOnceInternal;
19
79
  }
20
80
 
21
81
  declare class RequestContext {
@@ -253,4 +313,4 @@ declare class DefaultPushNotificationSender implements PushNotificationSender {
253
313
  private _dispatchNotification;
254
314
  }
255
315
 
256
- export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, type ExtendedAgentCardProvider, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, ServerCallContext, type TaskStore };
316
+ export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, type ExecutionEventName, ExecutionEventQueue, type ExtendedAgentCardProvider, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, ServerCallContext, type TaskStore };