@a2a-js/sdk 0.3.3 → 0.3.5

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.
@@ -22,8 +22,10 @@ __export(server_exports, {
22
22
  A2AError: () => A2AError,
23
23
  DefaultExecutionEventBus: () => DefaultExecutionEventBus,
24
24
  DefaultExecutionEventBusManager: () => DefaultExecutionEventBusManager,
25
+ DefaultPushNotificationSender: () => DefaultPushNotificationSender,
25
26
  DefaultRequestHandler: () => DefaultRequestHandler,
26
27
  ExecutionEventQueue: () => ExecutionEventQueue,
28
+ InMemoryPushNotificationStore: () => InMemoryPushNotificationStore,
27
29
  InMemoryTaskStore: () => InMemoryTaskStore,
28
30
  JsonRpcTransportHandler: () => JsonRpcTransportHandler,
29
31
  RequestContext: () => RequestContext,
@@ -366,6 +368,109 @@ var ResultManager = class {
366
368
  }
367
369
  };
368
370
 
371
+ // src/server/push_notification/push_notification_store.ts
372
+ var InMemoryPushNotificationStore = class {
373
+ store = /* @__PURE__ */ new Map();
374
+ async save(taskId, pushNotificationConfig) {
375
+ const configs = this.store.get(taskId) || [];
376
+ if (!pushNotificationConfig.id) {
377
+ pushNotificationConfig.id = taskId;
378
+ }
379
+ const existingIndex = configs.findIndex((config) => config.id === pushNotificationConfig.id);
380
+ if (existingIndex !== -1) {
381
+ configs.splice(existingIndex, 1);
382
+ }
383
+ configs.push(pushNotificationConfig);
384
+ this.store.set(taskId, configs);
385
+ }
386
+ async load(taskId) {
387
+ const configs = this.store.get(taskId);
388
+ return configs || [];
389
+ }
390
+ async delete(taskId, configId) {
391
+ if (configId === void 0) {
392
+ configId = taskId;
393
+ }
394
+ const configs = this.store.get(taskId);
395
+ if (!configs) {
396
+ return;
397
+ }
398
+ const configIndex = configs.findIndex((config) => config.id === configId);
399
+ if (configIndex !== -1) {
400
+ configs.splice(configIndex, 1);
401
+ }
402
+ if (configs.length === 0) {
403
+ this.store.delete(taskId);
404
+ } else {
405
+ this.store.set(taskId, configs);
406
+ }
407
+ }
408
+ };
409
+
410
+ // src/server/push_notification/default_push_notification_sender.ts
411
+ var DefaultPushNotificationSender = class {
412
+ pushNotificationStore;
413
+ notificationChain;
414
+ options;
415
+ constructor(pushNotificationStore, options = {}) {
416
+ this.pushNotificationStore = pushNotificationStore;
417
+ this.notificationChain = /* @__PURE__ */ new Map();
418
+ this.options = {
419
+ timeout: 5e3,
420
+ tokenHeaderName: "X-A2A-Notification-Token",
421
+ ...options
422
+ };
423
+ }
424
+ async send(task) {
425
+ const pushConfigs = await this.pushNotificationStore.load(task.id);
426
+ if (!pushConfigs || pushConfigs.length === 0) {
427
+ return;
428
+ }
429
+ const lastPromise = this.notificationChain.get(task.id) ?? Promise.resolve();
430
+ const newPromise = lastPromise.then(async () => {
431
+ const dispatches = pushConfigs.map(async (pushConfig) => {
432
+ try {
433
+ await this._dispatchNotification(task, pushConfig);
434
+ } catch (error) {
435
+ console.error(`Error sending push notification for task_id=${task.id} to URL: ${pushConfig.url}. Error:`, error);
436
+ }
437
+ });
438
+ await Promise.all(dispatches);
439
+ });
440
+ this.notificationChain.set(task.id, newPromise);
441
+ newPromise.finally(() => {
442
+ if (this.notificationChain.get(task.id) === newPromise) {
443
+ this.notificationChain.delete(task.id);
444
+ }
445
+ });
446
+ }
447
+ async _dispatchNotification(task, pushConfig) {
448
+ const url = pushConfig.url;
449
+ const controller = new AbortController();
450
+ const timeoutId = setTimeout(() => controller.abort(), this.options.timeout);
451
+ try {
452
+ const headers = {
453
+ "Content-Type": "application/json"
454
+ };
455
+ if (pushConfig.token) {
456
+ headers[this.options.tokenHeaderName] = pushConfig.token;
457
+ }
458
+ const response = await fetch(url, {
459
+ method: "POST",
460
+ headers,
461
+ body: JSON.stringify(task),
462
+ signal: controller.signal
463
+ });
464
+ if (!response.ok) {
465
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
466
+ }
467
+ console.info(`Push notification sent for task_id=${task.id} to URL: ${url}`);
468
+ } finally {
469
+ clearTimeout(timeoutId);
470
+ }
471
+ }
472
+ };
473
+
369
474
  // src/server/request_handler/default_request_handler.ts
370
475
  var terminalStates = ["completed", "failed", "canceled", "rejected"];
371
476
  var DefaultRequestHandler = class {
@@ -374,14 +479,18 @@ var DefaultRequestHandler = class {
374
479
  taskStore;
375
480
  agentExecutor;
376
481
  eventBusManager;
377
- // Store for push notification configurations (could be part of TaskStore or separate)
378
- pushNotificationConfigs = /* @__PURE__ */ new Map();
379
- constructor(agentCard, taskStore, agentExecutor, eventBusManager = new DefaultExecutionEventBusManager(), extendedAgentCard) {
482
+ pushNotificationStore;
483
+ pushNotificationSender;
484
+ constructor(agentCard, taskStore, agentExecutor, eventBusManager = new DefaultExecutionEventBusManager(), pushNotificationStore, pushNotificationSender, extendedAgentCard) {
380
485
  this.agentCard = agentCard;
381
486
  this.taskStore = taskStore;
382
487
  this.agentExecutor = agentExecutor;
383
488
  this.eventBusManager = eventBusManager;
384
489
  this.extendedAgentCard = extendedAgentCard;
490
+ if (agentCard.capabilities.pushNotifications) {
491
+ this.pushNotificationStore = pushNotificationStore || new InMemoryPushNotificationStore();
492
+ this.pushNotificationSender = pushNotificationSender || new DefaultPushNotificationSender(this.pushNotificationStore);
493
+ }
385
494
  }
386
495
  async getAgentCard() {
387
496
  return this.agentCard;
@@ -403,6 +512,8 @@ var DefaultRequestHandler = class {
403
512
  if (terminalStates.includes(task.status.state)) {
404
513
  throw A2AError.invalidRequest(`Task ${task.id} is in a terminal state (${task.status.state}) and cannot be modified.`);
405
514
  }
515
+ task.history = [...task.history || [], incomingMessage];
516
+ await this.taskStore.save(task);
406
517
  }
407
518
  if (incomingMessage.referenceTaskIds && incomingMessage.referenceTaskIds.length > 0) {
408
519
  referenceTasks = [];
@@ -433,9 +544,16 @@ var DefaultRequestHandler = class {
433
544
  try {
434
545
  for await (const event of eventQueue.events()) {
435
546
  await resultManager.processEvent(event);
547
+ await this._sendPushNotificationIfNeeded(event);
436
548
  if (options?.firstResultResolver && !firstResultSent) {
437
- if (event.kind === "message" || event.kind === "task") {
438
- options.firstResultResolver(event);
549
+ let firstResult;
550
+ if (event.kind === "message") {
551
+ firstResult = event;
552
+ } else {
553
+ firstResult = resultManager.getCurrentTask();
554
+ }
555
+ if (firstResult) {
556
+ options.firstResultResolver(firstResult);
439
557
  firstResultSent = true;
440
558
  }
441
559
  }
@@ -464,6 +582,9 @@ var DefaultRequestHandler = class {
464
582
  resultManager.setContext(incomingMessage);
465
583
  const requestContext = await this._createRequestContext(incomingMessage, taskId, false);
466
584
  const finalMessageForAgent = requestContext.userMessage;
585
+ if (params.configuration?.pushNotificationConfig && this.agentCard.capabilities.pushNotifications) {
586
+ await this.pushNotificationStore?.save(taskId, params.configuration.pushNotificationConfig);
587
+ }
467
588
  const eventBus = this.eventBusManager.createOrGetByTaskId(taskId);
468
589
  const eventQueue = new ExecutionEventQueue(eventBus);
469
590
  this.agentExecutor.execute(requestContext, eventBus).catch((err) => {
@@ -531,6 +652,9 @@ var DefaultRequestHandler = class {
531
652
  const finalMessageForAgent = requestContext.userMessage;
532
653
  const eventBus = this.eventBusManager.createOrGetByTaskId(taskId);
533
654
  const eventQueue = new ExecutionEventQueue(eventBus);
655
+ if (params.configuration?.pushNotificationConfig && this.agentCard.capabilities.pushNotifications) {
656
+ await this.pushNotificationStore?.save(taskId, params.configuration.pushNotificationConfig);
657
+ }
534
658
  this.agentExecutor.execute(requestContext, eventBus).catch((err) => {
535
659
  console.error(`Agent execution failed for stream message ${finalMessageForAgent.messageId}:`, err);
536
660
  const errorTaskStatus = {
@@ -558,6 +682,7 @@ var DefaultRequestHandler = class {
558
682
  try {
559
683
  for await (const event of eventQueue.events()) {
560
684
  await resultManager.processEvent(event);
685
+ await this._sendPushNotificationIfNeeded(event);
561
686
  yield event;
562
687
  }
563
688
  } finally {
@@ -589,7 +714,9 @@ var DefaultRequestHandler = class {
589
714
  }
590
715
  const eventBus = this.eventBusManager.getByTaskId(params.id);
591
716
  if (eventBus) {
717
+ const eventQueue = new ExecutionEventQueue(eventBus);
592
718
  await this.agentExecutor.cancelTask(params.id, eventBus);
719
+ await this._processEvents(params.id, new ResultManager(this.taskStore), eventQueue);
593
720
  } else {
594
721
  task.status = {
595
722
  state: "canceled",
@@ -608,6 +735,12 @@ var DefaultRequestHandler = class {
608
735
  await this.taskStore.save(task);
609
736
  }
610
737
  const latestTask = await this.taskStore.load(params.id);
738
+ if (!latestTask) {
739
+ throw A2AError.internalError(`Task ${params.id} not found after cancellation.`);
740
+ }
741
+ if (latestTask.status.state != "canceled") {
742
+ throw A2AError.taskNotCancelable(params.id);
743
+ }
611
744
  return latestTask;
612
745
  }
613
746
  async setTaskPushNotificationConfig(params) {
@@ -622,10 +755,7 @@ var DefaultRequestHandler = class {
622
755
  if (!pushNotificationConfig.id) {
623
756
  pushNotificationConfig.id = taskId;
624
757
  }
625
- const configs = this.pushNotificationConfigs.get(taskId) || [];
626
- const updatedConfigs = configs.filter((c) => c.id !== pushNotificationConfig.id);
627
- updatedConfigs.push(pushNotificationConfig);
628
- this.pushNotificationConfigs.set(taskId, updatedConfigs);
758
+ await this.pushNotificationStore?.save(taskId, pushNotificationConfig);
629
759
  return params;
630
760
  }
631
761
  async getTaskPushNotificationConfig(params) {
@@ -636,7 +766,7 @@ var DefaultRequestHandler = class {
636
766
  if (!task) {
637
767
  throw A2AError.taskNotFound(params.id);
638
768
  }
639
- const configs = this.pushNotificationConfigs.get(params.id) || [];
769
+ const configs = await this.pushNotificationStore?.load(params.id) || [];
640
770
  if (configs.length === 0) {
641
771
  throw A2AError.internalError(`Push notification config not found for task ${params.id}.`);
642
772
  }
@@ -660,7 +790,7 @@ var DefaultRequestHandler = class {
660
790
  if (!task) {
661
791
  throw A2AError.taskNotFound(params.id);
662
792
  }
663
- const configs = this.pushNotificationConfigs.get(params.id) || [];
793
+ const configs = await this.pushNotificationStore?.load(params.id) || [];
664
794
  return configs.map((config) => ({
665
795
  taskId: params.id,
666
796
  pushNotificationConfig: config
@@ -675,16 +805,7 @@ var DefaultRequestHandler = class {
675
805
  throw A2AError.taskNotFound(params.id);
676
806
  }
677
807
  const { id: taskId, pushNotificationConfigId } = params;
678
- const configs = this.pushNotificationConfigs.get(taskId);
679
- if (!configs) {
680
- return;
681
- }
682
- const updatedConfigs = configs.filter((c) => c.id !== pushNotificationConfigId);
683
- if (updatedConfigs.length === 0) {
684
- this.pushNotificationConfigs.delete(taskId);
685
- } else if (updatedConfigs.length < configs.length) {
686
- this.pushNotificationConfigs.set(taskId, updatedConfigs);
687
- }
808
+ await this.pushNotificationStore?.delete(taskId, pushNotificationConfigId);
688
809
  }
689
810
  async *resubscribe(params) {
690
811
  if (!this.agentCard.capabilities.streaming) {
@@ -719,6 +840,28 @@ var DefaultRequestHandler = class {
719
840
  eventQueue.stop();
720
841
  }
721
842
  }
843
+ async _sendPushNotificationIfNeeded(event) {
844
+ if (!this.agentCard.capabilities.pushNotifications) {
845
+ return;
846
+ }
847
+ let taskId = "";
848
+ if (event.kind == "task") {
849
+ const task2 = event;
850
+ taskId = task2.id;
851
+ } else {
852
+ taskId = event.taskId;
853
+ }
854
+ if (!taskId) {
855
+ console.error(`Task ID not found for event ${event.kind}.`);
856
+ return;
857
+ }
858
+ const task = await this.taskStore.load(taskId);
859
+ if (!task) {
860
+ console.error(`Task ${taskId} not found.`);
861
+ return;
862
+ }
863
+ this.pushNotificationSender?.send(task);
864
+ }
722
865
  };
723
866
 
724
867
  // src/server/store.ts
@@ -754,10 +897,8 @@ var JsonRpcTransportHandler = class {
754
897
  } else {
755
898
  throw A2AError.parseError("Invalid request body type.");
756
899
  }
757
- if (rpcRequest.jsonrpc !== "2.0" || !rpcRequest.method || typeof rpcRequest.method !== "string") {
758
- throw A2AError.invalidRequest(
759
- "Invalid JSON-RPC request structure."
760
- );
900
+ if (!this.isRequestValid(rpcRequest)) {
901
+ throw A2AError.invalidRequest("Invalid JSON-RPC Request.");
761
902
  }
762
903
  } catch (error) {
763
904
  const a2aError = error instanceof A2AError ? error : A2AError.parseError(error.message || "Failed to parse JSON request.");
@@ -777,8 +918,8 @@ var JsonRpcTransportHandler = class {
777
918
  result
778
919
  };
779
920
  }
780
- if (!rpcRequest.params) {
781
- throw A2AError.invalidParams(`'params' is required for '${method}'`);
921
+ if (!this.paramsAreValid(rpcRequest.params)) {
922
+ throw A2AError.invalidParams(`Invalid method parameters.`);
782
923
  }
783
924
  if (method === "message/stream" || method === "tasks/resubscribe") {
784
925
  const params = rpcRequest.params;
@@ -853,14 +994,47 @@ var JsonRpcTransportHandler = class {
853
994
  };
854
995
  }
855
996
  }
997
+ // Validates the basic structure of a JSON-RPC request
998
+ isRequestValid(rpcRequest) {
999
+ if (rpcRequest.jsonrpc !== "2.0") {
1000
+ return false;
1001
+ }
1002
+ if ("id" in rpcRequest) {
1003
+ const id = rpcRequest.id;
1004
+ const isString = typeof id === "string";
1005
+ const isInteger = typeof id === "number" && Number.isInteger(id);
1006
+ const isNull = id === null;
1007
+ if (!isString && !isInteger && !isNull) {
1008
+ return false;
1009
+ }
1010
+ }
1011
+ if (!rpcRequest.method || typeof rpcRequest.method !== "string") {
1012
+ return false;
1013
+ }
1014
+ return true;
1015
+ }
1016
+ // Validates that params is an object with non-empty string keys
1017
+ paramsAreValid(params) {
1018
+ if (typeof params !== "object" || params === null || Array.isArray(params)) {
1019
+ return false;
1020
+ }
1021
+ for (const key of Object.keys(params)) {
1022
+ if (key === "") {
1023
+ return false;
1024
+ }
1025
+ }
1026
+ return true;
1027
+ }
856
1028
  };
857
1029
  // Annotate the CommonJS export names for ESM import in node:
858
1030
  0 && (module.exports = {
859
1031
  A2AError,
860
1032
  DefaultExecutionEventBus,
861
1033
  DefaultExecutionEventBusManager,
1034
+ DefaultPushNotificationSender,
862
1035
  DefaultRequestHandler,
863
1036
  ExecutionEventQueue,
1037
+ InMemoryPushNotificationStore,
864
1038
  InMemoryTaskStore,
865
1039
  JsonRpcTransportHandler,
866
1040
  RequestContext,
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, ac as AgentCard, w as MessageSendParams, V as TaskQueryParams, X as TaskIdParams, Z as TaskPushNotificationConfig, a1 as GetTaskPushNotificationConfigParams, a5 as ListTaskPushNotificationConfigParams, a7 as DeleteTaskPushNotificationConfigParams, i as JSONRPCResponse, au as JSONRPCError } from '../types-DNKcmF0f.cjs';
2
+ import { B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, y as PushNotificationConfig, ac as AgentCard, w as MessageSendParams, V as TaskQueryParams, X as TaskIdParams, Z as TaskPushNotificationConfig, a1 as GetTaskPushNotificationConfigParams, a5 as ListTaskPushNotificationConfigParams, a7 as DeleteTaskPushNotificationConfigParams, i as JSONRPCResponse, au as JSONRPCError } from '../types-DNKcmF0f.cjs';
3
3
  import { A as A2ARequestHandler } from '../a2a_request_handler-DUvKWfix.cjs';
4
4
 
5
5
  type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
@@ -119,14 +119,31 @@ declare class InMemoryTaskStore implements TaskStore {
119
119
  save(task: Task): Promise<void>;
120
120
  }
121
121
 
122
+ interface PushNotificationStore {
123
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
124
+ load(taskId: string): Promise<PushNotificationConfig[]>;
125
+ delete(taskId: string, configId?: string): Promise<void>;
126
+ }
127
+ declare class InMemoryPushNotificationStore implements PushNotificationStore {
128
+ private store;
129
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
130
+ load(taskId: string): Promise<PushNotificationConfig[]>;
131
+ delete(taskId: string, configId?: string): Promise<void>;
132
+ }
133
+
134
+ interface PushNotificationSender {
135
+ send(task: Task): Promise<void>;
136
+ }
137
+
122
138
  declare class DefaultRequestHandler implements A2ARequestHandler {
123
139
  private readonly agentCard;
124
140
  private readonly extendedAgentCard?;
125
141
  private readonly taskStore;
126
142
  private readonly agentExecutor;
127
143
  private readonly eventBusManager;
128
- private readonly pushNotificationConfigs;
129
- constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, extendedAgentCard?: AgentCard);
144
+ private readonly pushNotificationStore?;
145
+ private readonly pushNotificationSender?;
146
+ constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCard?: AgentCard);
130
147
  getAgentCard(): Promise<AgentCard>;
131
148
  getAuthenticatedExtendedAgentCard(): Promise<AgentCard>;
132
149
  private _createRequestContext;
@@ -140,6 +157,7 @@ declare class DefaultRequestHandler implements A2ARequestHandler {
140
157
  listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams): Promise<TaskPushNotificationConfig[]>;
141
158
  deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<void>;
142
159
  resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
160
+ private _sendPushNotificationIfNeeded;
143
161
  }
144
162
 
145
163
  declare class ResultManager {
@@ -181,6 +199,8 @@ declare class JsonRpcTransportHandler {
181
199
  * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
182
200
  */
183
201
  handle(requestBody: any): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
202
+ private isRequestValid;
203
+ private paramsAreValid;
184
204
  }
185
205
 
186
206
  /**
@@ -207,4 +227,23 @@ declare class A2AError extends Error {
207
227
  static authenticatedExtendedCardNotConfigured(): A2AError;
208
228
  }
209
229
 
210
- export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryTaskStore, JsonRpcTransportHandler, RequestContext, ResultManager, type TaskStore };
230
+ interface DefaultPushNotificationSenderOptions {
231
+ /**
232
+ * Timeout in milliseconds for the abort controller. Defaults to 5000ms.
233
+ */
234
+ timeout?: number;
235
+ /**
236
+ * Custom header name for the token. Defaults to 'X-A2A-Notification-Token'.
237
+ */
238
+ tokenHeaderName?: string;
239
+ }
240
+ declare class DefaultPushNotificationSender implements PushNotificationSender {
241
+ private readonly pushNotificationStore;
242
+ private notificationChain;
243
+ private readonly options;
244
+ constructor(pushNotificationStore: PushNotificationStore, options?: DefaultPushNotificationSenderOptions);
245
+ send(task: Task): Promise<void>;
246
+ private _dispatchNotification;
247
+ }
248
+
249
+ export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, type TaskStore };
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, ac as AgentCard, w as MessageSendParams, V as TaskQueryParams, X as TaskIdParams, Z as TaskPushNotificationConfig, a1 as GetTaskPushNotificationConfigParams, a5 as ListTaskPushNotificationConfigParams, a7 as DeleteTaskPushNotificationConfigParams, i as JSONRPCResponse, au as JSONRPCError } from '../types-DNKcmF0f.js';
2
+ import { B as Message, aw as Task, aO as TaskStatusUpdateEvent, aQ as TaskArtifactUpdateEvent, y as PushNotificationConfig, ac as AgentCard, w as MessageSendParams, V as TaskQueryParams, X as TaskIdParams, Z as TaskPushNotificationConfig, a1 as GetTaskPushNotificationConfigParams, a5 as ListTaskPushNotificationConfigParams, a7 as DeleteTaskPushNotificationConfigParams, i as JSONRPCResponse, au as JSONRPCError } from '../types-DNKcmF0f.js';
3
3
  import { A as A2ARequestHandler } from '../a2a_request_handler-B5t-IxgA.js';
4
4
 
5
5
  type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
@@ -119,14 +119,31 @@ declare class InMemoryTaskStore implements TaskStore {
119
119
  save(task: Task): Promise<void>;
120
120
  }
121
121
 
122
+ interface PushNotificationStore {
123
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
124
+ load(taskId: string): Promise<PushNotificationConfig[]>;
125
+ delete(taskId: string, configId?: string): Promise<void>;
126
+ }
127
+ declare class InMemoryPushNotificationStore implements PushNotificationStore {
128
+ private store;
129
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
130
+ load(taskId: string): Promise<PushNotificationConfig[]>;
131
+ delete(taskId: string, configId?: string): Promise<void>;
132
+ }
133
+
134
+ interface PushNotificationSender {
135
+ send(task: Task): Promise<void>;
136
+ }
137
+
122
138
  declare class DefaultRequestHandler implements A2ARequestHandler {
123
139
  private readonly agentCard;
124
140
  private readonly extendedAgentCard?;
125
141
  private readonly taskStore;
126
142
  private readonly agentExecutor;
127
143
  private readonly eventBusManager;
128
- private readonly pushNotificationConfigs;
129
- constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, extendedAgentCard?: AgentCard);
144
+ private readonly pushNotificationStore?;
145
+ private readonly pushNotificationSender?;
146
+ constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCard?: AgentCard);
130
147
  getAgentCard(): Promise<AgentCard>;
131
148
  getAuthenticatedExtendedAgentCard(): Promise<AgentCard>;
132
149
  private _createRequestContext;
@@ -140,6 +157,7 @@ declare class DefaultRequestHandler implements A2ARequestHandler {
140
157
  listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams): Promise<TaskPushNotificationConfig[]>;
141
158
  deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams): Promise<void>;
142
159
  resubscribe(params: TaskIdParams): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
160
+ private _sendPushNotificationIfNeeded;
143
161
  }
144
162
 
145
163
  declare class ResultManager {
@@ -181,6 +199,8 @@ declare class JsonRpcTransportHandler {
181
199
  * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
182
200
  */
183
201
  handle(requestBody: any): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
202
+ private isRequestValid;
203
+ private paramsAreValid;
184
204
  }
185
205
 
186
206
  /**
@@ -207,4 +227,23 @@ declare class A2AError extends Error {
207
227
  static authenticatedExtendedCardNotConfigured(): A2AError;
208
228
  }
209
229
 
210
- export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryTaskStore, JsonRpcTransportHandler, RequestContext, ResultManager, type TaskStore };
230
+ interface DefaultPushNotificationSenderOptions {
231
+ /**
232
+ * Timeout in milliseconds for the abort controller. Defaults to 5000ms.
233
+ */
234
+ timeout?: number;
235
+ /**
236
+ * Custom header name for the token. Defaults to 'X-A2A-Notification-Token'.
237
+ */
238
+ tokenHeaderName?: string;
239
+ }
240
+ declare class DefaultPushNotificationSender implements PushNotificationSender {
241
+ private readonly pushNotificationStore;
242
+ private notificationChain;
243
+ private readonly options;
244
+ constructor(pushNotificationStore: PushNotificationStore, options?: DefaultPushNotificationSenderOptions);
245
+ send(task: Task): Promise<void>;
246
+ private _dispatchNotification;
247
+ }
248
+
249
+ export { A2AError, A2ARequestHandler, type AgentExecutionEvent, type AgentExecutor, DefaultExecutionEventBus, DefaultExecutionEventBusManager, DefaultPushNotificationSender, type DefaultPushNotificationSenderOptions, DefaultRequestHandler, type ExecutionEventBus, type ExecutionEventBusManager, ExecutionEventQueue, InMemoryPushNotificationStore, InMemoryTaskStore, JsonRpcTransportHandler, type PushNotificationSender, type PushNotificationStore, RequestContext, ResultManager, type TaskStore };