@mailmodo/a2a 0.3.3 → 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.
@@ -0,0 +1,316 @@
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.mjs';
2
+ import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-1Isk3l-0.mjs';
3
+ export { a as UnauthenticatedUser, U as User } from '../a2a_request_handler-1Isk3l-0.mjs';
4
+
5
+ type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
+ /**
7
+ * Event names supported by ExecutionEventBus.
8
+ */
9
+ type ExecutionEventName = 'event' | 'finished';
10
+ interface ExecutionEventBus {
11
+ publish(event: AgentExecutionEvent): void;
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;
16
+ finished(): void;
17
+ }
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;
29
+ publish(event: AgentExecutionEvent): void;
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;
79
+ }
80
+
81
+ declare class RequestContext {
82
+ readonly userMessage: Message;
83
+ readonly taskId: string;
84
+ readonly contextId: string;
85
+ readonly task?: Task;
86
+ readonly referenceTasks?: Task[];
87
+ readonly context?: ServerCallContext;
88
+ constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[], context?: ServerCallContext);
89
+ }
90
+
91
+ interface AgentExecutor {
92
+ /**
93
+ * Executes the agent logic based on the request context and publishes events.
94
+ * @param requestContext The context of the current request.
95
+ * @param eventBus The bus to publish execution events to.
96
+ */
97
+ execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
98
+ /**
99
+ * Method to explicitly cancel a running task.
100
+ * The implementation should handle the logic of stopping the execution
101
+ * and publishing the final 'canceled' status event on the provided event bus.
102
+ * @param taskId The ID of the task to cancel.
103
+ * @param eventBus The event bus associated with the task's execution.
104
+ */
105
+ cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
106
+ }
107
+
108
+ interface ExecutionEventBusManager {
109
+ createOrGetByTaskId(taskId: string): ExecutionEventBus;
110
+ getByTaskId(taskId: string): ExecutionEventBus | undefined;
111
+ cleanupByTaskId(taskId: string): void;
112
+ }
113
+ declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
114
+ private taskIdToBus;
115
+ /**
116
+ * Creates or retrieves an existing ExecutionEventBus based on the taskId.
117
+ * @param taskId The ID of the task.
118
+ * @returns An instance of ExecutionEventBus.
119
+ */
120
+ createOrGetByTaskId(taskId: string): ExecutionEventBus;
121
+ /**
122
+ * Retrieves an existing ExecutionEventBus based on the taskId.
123
+ * @param taskId The ID of the task.
124
+ * @returns An instance of ExecutionEventBus or undefined if not found.
125
+ */
126
+ getByTaskId(taskId: string): ExecutionEventBus | undefined;
127
+ /**
128
+ * Removes the event bus for a given taskId.
129
+ * This should be called when an execution flow is complete to free resources.
130
+ * @param taskId The ID of the task.
131
+ */
132
+ cleanupByTaskId(taskId: string): void;
133
+ }
134
+
135
+ /**
136
+ * An async queue that subscribes to an ExecutionEventBus for events
137
+ * and provides an async generator to consume them.
138
+ */
139
+ declare class ExecutionEventQueue {
140
+ private eventBus;
141
+ private eventQueue;
142
+ private resolvePromise?;
143
+ private stopped;
144
+ private boundHandleEvent;
145
+ constructor(eventBus: ExecutionEventBus);
146
+ private handleEvent;
147
+ private handleFinished;
148
+ /**
149
+ * Provides an async generator that yields events from the event bus.
150
+ * Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
151
+ */
152
+ events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
153
+ /**
154
+ * Stops the event queue from processing further events.
155
+ */
156
+ stop(): void;
157
+ }
158
+
159
+ /**
160
+ * Simplified interface for task storage providers.
161
+ * Stores and retrieves the task.
162
+ */
163
+ interface TaskStore {
164
+ /**
165
+ * Saves a task.
166
+ * Overwrites existing data if the task ID exists.
167
+ * @param task The task to save.
168
+ * @param context The context of the current call.
169
+ * @returns A promise resolving when the save operation is complete.
170
+ */
171
+ save(task: Task, context?: ServerCallContext): Promise<void>;
172
+ /**
173
+ * Loads a task by task ID.
174
+ * @param taskId The ID of the task to load.
175
+ * @param context The context of the current call.
176
+ * @returns A promise resolving to an object containing the Task, or undefined if not found.
177
+ */
178
+ load(taskId: string, context?: ServerCallContext): Promise<Task | undefined>;
179
+ }
180
+ declare class InMemoryTaskStore implements TaskStore {
181
+ private store;
182
+ load(taskId: string): Promise<Task | undefined>;
183
+ save(task: Task): Promise<void>;
184
+ }
185
+
186
+ interface PushNotificationStore {
187
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
188
+ load(taskId: string): Promise<PushNotificationConfig[]>;
189
+ delete(taskId: string, configId?: string): Promise<void>;
190
+ }
191
+ declare class InMemoryPushNotificationStore implements PushNotificationStore {
192
+ private store;
193
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
194
+ load(taskId: string): Promise<PushNotificationConfig[]>;
195
+ delete(taskId: string, configId?: string): Promise<void>;
196
+ }
197
+
198
+ interface PushNotificationSender {
199
+ send(task: Task): Promise<void>;
200
+ }
201
+
202
+ declare class DefaultRequestHandler implements A2ARequestHandler {
203
+ private readonly agentCard;
204
+ private readonly taskStore;
205
+ private readonly agentExecutor;
206
+ private readonly eventBusManager;
207
+ private readonly pushNotificationStore?;
208
+ private readonly pushNotificationSender?;
209
+ private readonly extendedAgentCardProvider?;
210
+ constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCardProvider?: AgentCard | ExtendedAgentCardProvider);
211
+ getAgentCard(): Promise<AgentCard>;
212
+ getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
213
+ private _createRequestContext;
214
+ private _processEvents;
215
+ sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
216
+ sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
217
+ getTask(params: TaskQueryParams, context?: ServerCallContext): Promise<Task>;
218
+ cancelTask(params: TaskIdParams, context?: ServerCallContext): Promise<Task>;
219
+ setTaskPushNotificationConfig(params: TaskPushNotificationConfig, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
220
+ getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
221
+ listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
222
+ deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<void>;
223
+ resubscribe(params: TaskIdParams, context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
224
+ private _sendPushNotificationIfNeeded;
225
+ private _handleProcessingError;
226
+ }
227
+ type ExtendedAgentCardProvider = (context?: ServerCallContext) => Promise<AgentCard>;
228
+
229
+ declare class ResultManager {
230
+ private readonly taskStore;
231
+ private readonly serverCallContext?;
232
+ private currentTask?;
233
+ private latestUserMessage?;
234
+ private finalMessageResult?;
235
+ constructor(taskStore: TaskStore, serverCallContext?: ServerCallContext);
236
+ setContext(latestUserMessage: Message): void;
237
+ /**
238
+ * Processes an agent execution event and updates the task store.
239
+ * @param event The agent execution event.
240
+ */
241
+ processEvent(event: AgentExecutionEvent): Promise<void>;
242
+ private saveCurrentTask;
243
+ /**
244
+ * Gets the final result, which could be a Message or a Task.
245
+ * This should be called after the event stream has been fully processed.
246
+ * @returns The final Message or the current Task.
247
+ */
248
+ getFinalResult(): Message | Task | undefined;
249
+ /**
250
+ * Gets the task currently being managed by this ResultManager instance.
251
+ * This task could be one that was started with or one created during agent execution.
252
+ * @returns The current Task or undefined if no task is active.
253
+ */
254
+ getCurrentTask(): Task | undefined;
255
+ }
256
+
257
+ /**
258
+ * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
259
+ */
260
+ declare class JsonRpcTransportHandler {
261
+ private requestHandler;
262
+ constructor(requestHandler: A2ARequestHandler);
263
+ /**
264
+ * Handles an incoming JSON-RPC request.
265
+ * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
266
+ * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
267
+ */
268
+ handle(requestBody: any, context?: ServerCallContext): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
269
+ private isRequestValid;
270
+ private paramsAreValid;
271
+ }
272
+
273
+ /**
274
+ * Custom error class for A2A server operations, incorporating JSON-RPC error codes.
275
+ */
276
+ declare class A2AError extends Error {
277
+ code: number;
278
+ data?: Record<string, unknown>;
279
+ taskId?: string;
280
+ constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
281
+ /**
282
+ * Formats the error into a standard JSON-RPC error object structure.
283
+ */
284
+ toJSONRPCError(): JSONRPCError;
285
+ static parseError(message: string, data?: Record<string, unknown>): A2AError;
286
+ static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
287
+ static methodNotFound(method: string): A2AError;
288
+ static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
289
+ static internalError(message: string, data?: Record<string, unknown>): A2AError;
290
+ static taskNotFound(taskId: string): A2AError;
291
+ static taskNotCancelable(taskId: string): A2AError;
292
+ static pushNotificationNotSupported(): A2AError;
293
+ static unsupportedOperation(operation: string): A2AError;
294
+ static authenticatedExtendedCardNotConfigured(): A2AError;
295
+ }
296
+
297
+ interface DefaultPushNotificationSenderOptions {
298
+ /**
299
+ * Timeout in milliseconds for the abort controller. Defaults to 5000ms.
300
+ */
301
+ timeout?: number;
302
+ /**
303
+ * Custom header name for the token. Defaults to 'X-A2A-Notification-Token'.
304
+ */
305
+ tokenHeaderName?: string;
306
+ }
307
+ declare class DefaultPushNotificationSender implements PushNotificationSender {
308
+ private readonly pushNotificationStore;
309
+ private notificationChain;
310
+ private readonly options;
311
+ constructor(pushNotificationStore: PushNotificationStore, options?: DefaultPushNotificationSenderOptions);
312
+ send(task: Task): Promise<void>;
313
+ private _dispatchNotification;
314
+ }
315
+
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 };
@@ -0,0 +1,316 @@
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';
2
+ import { S as ServerCallContext, A as A2ARequestHandler } from '../a2a_request_handler-BuP9LgXH.js';
3
+ export { a as UnauthenticatedUser, U as User } from '../a2a_request_handler-BuP9LgXH.js';
4
+
5
+ type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
+ /**
7
+ * Event names supported by ExecutionEventBus.
8
+ */
9
+ type ExecutionEventName = 'event' | 'finished';
10
+ interface ExecutionEventBus {
11
+ publish(event: AgentExecutionEvent): void;
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;
16
+ finished(): void;
17
+ }
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;
29
+ publish(event: AgentExecutionEvent): void;
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;
79
+ }
80
+
81
+ declare class RequestContext {
82
+ readonly userMessage: Message;
83
+ readonly taskId: string;
84
+ readonly contextId: string;
85
+ readonly task?: Task;
86
+ readonly referenceTasks?: Task[];
87
+ readonly context?: ServerCallContext;
88
+ constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[], context?: ServerCallContext);
89
+ }
90
+
91
+ interface AgentExecutor {
92
+ /**
93
+ * Executes the agent logic based on the request context and publishes events.
94
+ * @param requestContext The context of the current request.
95
+ * @param eventBus The bus to publish execution events to.
96
+ */
97
+ execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
98
+ /**
99
+ * Method to explicitly cancel a running task.
100
+ * The implementation should handle the logic of stopping the execution
101
+ * and publishing the final 'canceled' status event on the provided event bus.
102
+ * @param taskId The ID of the task to cancel.
103
+ * @param eventBus The event bus associated with the task's execution.
104
+ */
105
+ cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
106
+ }
107
+
108
+ interface ExecutionEventBusManager {
109
+ createOrGetByTaskId(taskId: string): ExecutionEventBus;
110
+ getByTaskId(taskId: string): ExecutionEventBus | undefined;
111
+ cleanupByTaskId(taskId: string): void;
112
+ }
113
+ declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
114
+ private taskIdToBus;
115
+ /**
116
+ * Creates or retrieves an existing ExecutionEventBus based on the taskId.
117
+ * @param taskId The ID of the task.
118
+ * @returns An instance of ExecutionEventBus.
119
+ */
120
+ createOrGetByTaskId(taskId: string): ExecutionEventBus;
121
+ /**
122
+ * Retrieves an existing ExecutionEventBus based on the taskId.
123
+ * @param taskId The ID of the task.
124
+ * @returns An instance of ExecutionEventBus or undefined if not found.
125
+ */
126
+ getByTaskId(taskId: string): ExecutionEventBus | undefined;
127
+ /**
128
+ * Removes the event bus for a given taskId.
129
+ * This should be called when an execution flow is complete to free resources.
130
+ * @param taskId The ID of the task.
131
+ */
132
+ cleanupByTaskId(taskId: string): void;
133
+ }
134
+
135
+ /**
136
+ * An async queue that subscribes to an ExecutionEventBus for events
137
+ * and provides an async generator to consume them.
138
+ */
139
+ declare class ExecutionEventQueue {
140
+ private eventBus;
141
+ private eventQueue;
142
+ private resolvePromise?;
143
+ private stopped;
144
+ private boundHandleEvent;
145
+ constructor(eventBus: ExecutionEventBus);
146
+ private handleEvent;
147
+ private handleFinished;
148
+ /**
149
+ * Provides an async generator that yields events from the event bus.
150
+ * Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
151
+ */
152
+ events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
153
+ /**
154
+ * Stops the event queue from processing further events.
155
+ */
156
+ stop(): void;
157
+ }
158
+
159
+ /**
160
+ * Simplified interface for task storage providers.
161
+ * Stores and retrieves the task.
162
+ */
163
+ interface TaskStore {
164
+ /**
165
+ * Saves a task.
166
+ * Overwrites existing data if the task ID exists.
167
+ * @param task The task to save.
168
+ * @param context The context of the current call.
169
+ * @returns A promise resolving when the save operation is complete.
170
+ */
171
+ save(task: Task, context?: ServerCallContext): Promise<void>;
172
+ /**
173
+ * Loads a task by task ID.
174
+ * @param taskId The ID of the task to load.
175
+ * @param context The context of the current call.
176
+ * @returns A promise resolving to an object containing the Task, or undefined if not found.
177
+ */
178
+ load(taskId: string, context?: ServerCallContext): Promise<Task | undefined>;
179
+ }
180
+ declare class InMemoryTaskStore implements TaskStore {
181
+ private store;
182
+ load(taskId: string): Promise<Task | undefined>;
183
+ save(task: Task): Promise<void>;
184
+ }
185
+
186
+ interface PushNotificationStore {
187
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
188
+ load(taskId: string): Promise<PushNotificationConfig[]>;
189
+ delete(taskId: string, configId?: string): Promise<void>;
190
+ }
191
+ declare class InMemoryPushNotificationStore implements PushNotificationStore {
192
+ private store;
193
+ save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
194
+ load(taskId: string): Promise<PushNotificationConfig[]>;
195
+ delete(taskId: string, configId?: string): Promise<void>;
196
+ }
197
+
198
+ interface PushNotificationSender {
199
+ send(task: Task): Promise<void>;
200
+ }
201
+
202
+ declare class DefaultRequestHandler implements A2ARequestHandler {
203
+ private readonly agentCard;
204
+ private readonly taskStore;
205
+ private readonly agentExecutor;
206
+ private readonly eventBusManager;
207
+ private readonly pushNotificationStore?;
208
+ private readonly pushNotificationSender?;
209
+ private readonly extendedAgentCardProvider?;
210
+ constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCardProvider?: AgentCard | ExtendedAgentCardProvider);
211
+ getAgentCard(): Promise<AgentCard>;
212
+ getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
213
+ private _createRequestContext;
214
+ private _processEvents;
215
+ sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
216
+ sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
217
+ getTask(params: TaskQueryParams, context?: ServerCallContext): Promise<Task>;
218
+ cancelTask(params: TaskIdParams, context?: ServerCallContext): Promise<Task>;
219
+ setTaskPushNotificationConfig(params: TaskPushNotificationConfig, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
220
+ getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
221
+ listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
222
+ deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, context?: ServerCallContext): Promise<void>;
223
+ resubscribe(params: TaskIdParams, context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
224
+ private _sendPushNotificationIfNeeded;
225
+ private _handleProcessingError;
226
+ }
227
+ type ExtendedAgentCardProvider = (context?: ServerCallContext) => Promise<AgentCard>;
228
+
229
+ declare class ResultManager {
230
+ private readonly taskStore;
231
+ private readonly serverCallContext?;
232
+ private currentTask?;
233
+ private latestUserMessage?;
234
+ private finalMessageResult?;
235
+ constructor(taskStore: TaskStore, serverCallContext?: ServerCallContext);
236
+ setContext(latestUserMessage: Message): void;
237
+ /**
238
+ * Processes an agent execution event and updates the task store.
239
+ * @param event The agent execution event.
240
+ */
241
+ processEvent(event: AgentExecutionEvent): Promise<void>;
242
+ private saveCurrentTask;
243
+ /**
244
+ * Gets the final result, which could be a Message or a Task.
245
+ * This should be called after the event stream has been fully processed.
246
+ * @returns The final Message or the current Task.
247
+ */
248
+ getFinalResult(): Message | Task | undefined;
249
+ /**
250
+ * Gets the task currently being managed by this ResultManager instance.
251
+ * This task could be one that was started with or one created during agent execution.
252
+ * @returns The current Task or undefined if no task is active.
253
+ */
254
+ getCurrentTask(): Task | undefined;
255
+ }
256
+
257
+ /**
258
+ * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
259
+ */
260
+ declare class JsonRpcTransportHandler {
261
+ private requestHandler;
262
+ constructor(requestHandler: A2ARequestHandler);
263
+ /**
264
+ * Handles an incoming JSON-RPC request.
265
+ * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
266
+ * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
267
+ */
268
+ handle(requestBody: any, context?: ServerCallContext): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
269
+ private isRequestValid;
270
+ private paramsAreValid;
271
+ }
272
+
273
+ /**
274
+ * Custom error class for A2A server operations, incorporating JSON-RPC error codes.
275
+ */
276
+ declare class A2AError extends Error {
277
+ code: number;
278
+ data?: Record<string, unknown>;
279
+ taskId?: string;
280
+ constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
281
+ /**
282
+ * Formats the error into a standard JSON-RPC error object structure.
283
+ */
284
+ toJSONRPCError(): JSONRPCError;
285
+ static parseError(message: string, data?: Record<string, unknown>): A2AError;
286
+ static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
287
+ static methodNotFound(method: string): A2AError;
288
+ static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
289
+ static internalError(message: string, data?: Record<string, unknown>): A2AError;
290
+ static taskNotFound(taskId: string): A2AError;
291
+ static taskNotCancelable(taskId: string): A2AError;
292
+ static pushNotificationNotSupported(): A2AError;
293
+ static unsupportedOperation(operation: string): A2AError;
294
+ static authenticatedExtendedCardNotConfigured(): A2AError;
295
+ }
296
+
297
+ interface DefaultPushNotificationSenderOptions {
298
+ /**
299
+ * Timeout in milliseconds for the abort controller. Defaults to 5000ms.
300
+ */
301
+ timeout?: number;
302
+ /**
303
+ * Custom header name for the token. Defaults to 'X-A2A-Notification-Token'.
304
+ */
305
+ tokenHeaderName?: string;
306
+ }
307
+ declare class DefaultPushNotificationSender implements PushNotificationSender {
308
+ private readonly pushNotificationStore;
309
+ private notificationChain;
310
+ private readonly options;
311
+ constructor(pushNotificationStore: PushNotificationStore, options?: DefaultPushNotificationSenderOptions);
312
+ send(task: Task): Promise<void>;
313
+ private _dispatchNotification;
314
+ }
315
+
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 };