@mailmodo/a2a 0.3.5 → 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.
@@ -1,233 +0,0 @@
1
- import { a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, V as PushNotificationConfig, A as AgentCard, M as MessageSendParams, i as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, a8 as GetTaskPushNotificationConfigParams, L as ListTaskPushNotificationConfigParams, D as DeleteTaskPushNotificationConfigParams, J as JSONRPCResponse, ax as JSONRPCError } from './types-Due_Cv6t.mjs';
2
- import { S as ServerCallContext, A as A2ARequestHandler } from './a2a_request_handler-DPkhsCMt.mjs';
3
- import { EventEmitter } from 'events';
4
-
5
- type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
- interface ExecutionEventBus {
7
- publish(event: AgentExecutionEvent): void;
8
- on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
9
- off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
10
- once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
11
- removeAllListeners(eventName?: 'event' | 'finished'): this;
12
- finished(): void;
13
- }
14
- declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
15
- constructor();
16
- publish(event: AgentExecutionEvent): void;
17
- finished(): void;
18
- }
19
-
20
- declare class RequestContext {
21
- readonly userMessage: Message;
22
- readonly taskId: string;
23
- readonly contextId: string;
24
- readonly task?: Task;
25
- readonly referenceTasks?: Task[];
26
- readonly context?: ServerCallContext;
27
- constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[], context?: ServerCallContext);
28
- }
29
-
30
- interface AgentExecutor {
31
- /**
32
- * Executes the agent logic based on the request context and publishes events.
33
- * @param requestContext The context of the current request.
34
- * @param eventBus The bus to publish execution events to.
35
- */
36
- execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
37
- /**
38
- * Method to explicitly cancel a running task.
39
- * The implementation should handle the logic of stopping the execution
40
- * and publishing the final 'canceled' status event on the provided event bus.
41
- * @param taskId The ID of the task to cancel.
42
- * @param eventBus The event bus associated with the task's execution.
43
- */
44
- cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
45
- }
46
-
47
- interface ExecutionEventBusManager {
48
- createOrGetByTaskId(taskId: string): ExecutionEventBus;
49
- getByTaskId(taskId: string): ExecutionEventBus | undefined;
50
- cleanupByTaskId(taskId: string): void;
51
- }
52
- declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
53
- private taskIdToBus;
54
- /**
55
- * Creates or retrieves an existing ExecutionEventBus based on the taskId.
56
- * @param taskId The ID of the task.
57
- * @returns An instance of IExecutionEventBus.
58
- */
59
- createOrGetByTaskId(taskId: string): ExecutionEventBus;
60
- /**
61
- * Retrieves an existing ExecutionEventBus based on the taskId.
62
- * @param taskId The ID of the task.
63
- * @returns An instance of IExecutionEventBus or undefined if not found.
64
- */
65
- getByTaskId(taskId: string): ExecutionEventBus | undefined;
66
- /**
67
- * Removes the event bus for a given taskId.
68
- * This should be called when an execution flow is complete to free resources.
69
- * @param taskId The ID of the task.
70
- */
71
- cleanupByTaskId(taskId: string): void;
72
- }
73
-
74
- /**
75
- * An async queue that subscribes to an ExecutionEventBus for events
76
- * and provides an async generator to consume them.
77
- */
78
- declare class ExecutionEventQueue {
79
- private eventBus;
80
- private eventQueue;
81
- private resolvePromise?;
82
- private stopped;
83
- private boundHandleEvent;
84
- constructor(eventBus: ExecutionEventBus);
85
- private handleEvent;
86
- private handleFinished;
87
- /**
88
- * Provides an async generator that yields events from the event bus.
89
- * Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
90
- */
91
- events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
92
- /**
93
- * Stops the event queue from processing further events.
94
- */
95
- stop(): void;
96
- }
97
-
98
- /**
99
- * Simplified interface for task storage providers.
100
- * Stores and retrieves the task.
101
- */
102
- interface TaskStore {
103
- /**
104
- * Saves a task.
105
- * Overwrites existing data if the task ID exists.
106
- * @param data An object containing the task.
107
- * @returns A promise resolving when the save operation is complete.
108
- */
109
- save(task: Task): Promise<void>;
110
- /**
111
- * Loads a task by task ID.
112
- * @param taskId The ID of the task to load.
113
- * @returns A promise resolving to an object containing the Task, or undefined if not found.
114
- */
115
- load(taskId: string): Promise<Task | undefined>;
116
- }
117
- declare class InMemoryTaskStore implements TaskStore {
118
- private store;
119
- load(taskId: string): Promise<Task | undefined>;
120
- save(task: Task): Promise<void>;
121
- }
122
-
123
- interface PushNotificationStore {
124
- save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
125
- load(taskId: string): Promise<PushNotificationConfig[]>;
126
- delete(taskId: string, configId?: string): Promise<void>;
127
- }
128
- declare class InMemoryPushNotificationStore implements PushNotificationStore {
129
- private store;
130
- save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
131
- load(taskId: string): Promise<PushNotificationConfig[]>;
132
- delete(taskId: string, configId?: string): Promise<void>;
133
- }
134
-
135
- interface PushNotificationSender {
136
- send(task: Task): Promise<void>;
137
- }
138
-
139
- declare class DefaultRequestHandler implements A2ARequestHandler {
140
- private readonly agentCard;
141
- private readonly taskStore;
142
- private readonly agentExecutor;
143
- private readonly eventBusManager;
144
- private readonly pushNotificationStore?;
145
- private readonly pushNotificationSender?;
146
- private readonly extendedAgentCardProvider?;
147
- constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCardProvider?: AgentCard | ExtendedAgentCardProvider);
148
- getAgentCard(): Promise<AgentCard>;
149
- getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
150
- private _createRequestContext;
151
- private _processEvents;
152
- sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
153
- sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
154
- getTask(params: TaskQueryParams, _context?: ServerCallContext): Promise<Task>;
155
- cancelTask(params: TaskIdParams, _context?: ServerCallContext): Promise<Task>;
156
- setTaskPushNotificationConfig(params: TaskPushNotificationConfig, _context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
157
- getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
158
- listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
159
- deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<void>;
160
- resubscribe(params: TaskIdParams, _context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
161
- private _sendPushNotificationIfNeeded;
162
- private _handleProcessingError;
163
- }
164
- type ExtendedAgentCardProvider = (context?: ServerCallContext) => Promise<AgentCard>;
165
-
166
- declare class ResultManager {
167
- private taskStore;
168
- private currentTask?;
169
- private latestUserMessage?;
170
- private finalMessageResult?;
171
- constructor(taskStore: TaskStore);
172
- setContext(latestUserMessage: Message): void;
173
- /**
174
- * Processes an agent execution event and updates the task store.
175
- * @param event The agent execution event.
176
- */
177
- processEvent(event: AgentExecutionEvent): Promise<void>;
178
- private saveCurrentTask;
179
- /**
180
- * Gets the final result, which could be a Message or a Task.
181
- * This should be called after the event stream has been fully processed.
182
- * @returns The final Message or the current Task.
183
- */
184
- getFinalResult(): Message | Task | undefined;
185
- /**
186
- * Gets the task currently being managed by this ResultManager instance.
187
- * This task could be one that was started with or one created during agent execution.
188
- * @returns The current Task or undefined if no task is active.
189
- */
190
- getCurrentTask(): Task | undefined;
191
- }
192
-
193
- /**
194
- * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
195
- */
196
- declare class JsonRpcTransportHandler {
197
- private requestHandler;
198
- constructor(requestHandler: A2ARequestHandler);
199
- /**
200
- * Handles an incoming JSON-RPC request.
201
- * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
202
- * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
203
- */
204
- handle(requestBody: any, context?: ServerCallContext): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
205
- private isRequestValid;
206
- private paramsAreValid;
207
- }
208
-
209
- /**
210
- * Custom error class for A2A server operations, incorporating JSON-RPC error codes.
211
- */
212
- declare class A2AError extends Error {
213
- code: number;
214
- data?: Record<string, unknown>;
215
- taskId?: string;
216
- constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
217
- /**
218
- * Formats the error into a standard JSON-RPC error object structure.
219
- */
220
- toJSONRPCError(): JSONRPCError;
221
- static parseError(message: string, data?: Record<string, unknown>): A2AError;
222
- static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
223
- static methodNotFound(method: string): A2AError;
224
- static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
225
- static internalError(message: string, data?: Record<string, unknown>): A2AError;
226
- static taskNotFound(taskId: string): A2AError;
227
- static taskNotCancelable(taskId: string): A2AError;
228
- static pushNotificationNotSupported(): A2AError;
229
- static unsupportedOperation(operation: string): A2AError;
230
- static authenticatedExtendedCardNotConfigured(): A2AError;
231
- }
232
-
233
- export { type AgentExecutor as A, DefaultExecutionEventBus as D, type ExecutionEventBus as E, InMemoryTaskStore as I, JsonRpcTransportHandler as J, type PushNotificationSender as P, RequestContext as R, type TaskStore as T, type PushNotificationStore as a, type AgentExecutionEvent as b, type ExecutionEventBusManager as c, DefaultExecutionEventBusManager as d, ExecutionEventQueue as e, DefaultRequestHandler as f, type ExtendedAgentCardProvider as g, ResultManager as h, A2AError as i, InMemoryPushNotificationStore as j };
@@ -1,233 +0,0 @@
1
- import { a as Message, T as Task, b as TaskStatusUpdateEvent, c as TaskArtifactUpdateEvent, V as PushNotificationConfig, A as AgentCard, M as MessageSendParams, i as TaskQueryParams, f as TaskIdParams, d as TaskPushNotificationConfig, a8 as GetTaskPushNotificationConfigParams, L as ListTaskPushNotificationConfigParams, D as DeleteTaskPushNotificationConfigParams, J as JSONRPCResponse, ax as JSONRPCError } from './types-Due_Cv6t.js';
2
- import { S as ServerCallContext, A as A2ARequestHandler } from './a2a_request_handler-DQfg1Q-R.js';
3
- import { EventEmitter } from 'events';
4
-
5
- type AgentExecutionEvent = Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent;
6
- interface ExecutionEventBus {
7
- publish(event: AgentExecutionEvent): void;
8
- on(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
9
- off(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
10
- once(eventName: 'event' | 'finished', listener: (event: AgentExecutionEvent) => void): this;
11
- removeAllListeners(eventName?: 'event' | 'finished'): this;
12
- finished(): void;
13
- }
14
- declare class DefaultExecutionEventBus extends EventEmitter implements ExecutionEventBus {
15
- constructor();
16
- publish(event: AgentExecutionEvent): void;
17
- finished(): void;
18
- }
19
-
20
- declare class RequestContext {
21
- readonly userMessage: Message;
22
- readonly taskId: string;
23
- readonly contextId: string;
24
- readonly task?: Task;
25
- readonly referenceTasks?: Task[];
26
- readonly context?: ServerCallContext;
27
- constructor(userMessage: Message, taskId: string, contextId: string, task?: Task, referenceTasks?: Task[], context?: ServerCallContext);
28
- }
29
-
30
- interface AgentExecutor {
31
- /**
32
- * Executes the agent logic based on the request context and publishes events.
33
- * @param requestContext The context of the current request.
34
- * @param eventBus The bus to publish execution events to.
35
- */
36
- execute: (requestContext: RequestContext, eventBus: ExecutionEventBus) => Promise<void>;
37
- /**
38
- * Method to explicitly cancel a running task.
39
- * The implementation should handle the logic of stopping the execution
40
- * and publishing the final 'canceled' status event on the provided event bus.
41
- * @param taskId The ID of the task to cancel.
42
- * @param eventBus The event bus associated with the task's execution.
43
- */
44
- cancelTask: (taskId: string, eventBus: ExecutionEventBus) => Promise<void>;
45
- }
46
-
47
- interface ExecutionEventBusManager {
48
- createOrGetByTaskId(taskId: string): ExecutionEventBus;
49
- getByTaskId(taskId: string): ExecutionEventBus | undefined;
50
- cleanupByTaskId(taskId: string): void;
51
- }
52
- declare class DefaultExecutionEventBusManager implements ExecutionEventBusManager {
53
- private taskIdToBus;
54
- /**
55
- * Creates or retrieves an existing ExecutionEventBus based on the taskId.
56
- * @param taskId The ID of the task.
57
- * @returns An instance of IExecutionEventBus.
58
- */
59
- createOrGetByTaskId(taskId: string): ExecutionEventBus;
60
- /**
61
- * Retrieves an existing ExecutionEventBus based on the taskId.
62
- * @param taskId The ID of the task.
63
- * @returns An instance of IExecutionEventBus or undefined if not found.
64
- */
65
- getByTaskId(taskId: string): ExecutionEventBus | undefined;
66
- /**
67
- * Removes the event bus for a given taskId.
68
- * This should be called when an execution flow is complete to free resources.
69
- * @param taskId The ID of the task.
70
- */
71
- cleanupByTaskId(taskId: string): void;
72
- }
73
-
74
- /**
75
- * An async queue that subscribes to an ExecutionEventBus for events
76
- * and provides an async generator to consume them.
77
- */
78
- declare class ExecutionEventQueue {
79
- private eventBus;
80
- private eventQueue;
81
- private resolvePromise?;
82
- private stopped;
83
- private boundHandleEvent;
84
- constructor(eventBus: ExecutionEventBus);
85
- private handleEvent;
86
- private handleFinished;
87
- /**
88
- * Provides an async generator that yields events from the event bus.
89
- * Stops when a Message event is received or a TaskStatusUpdateEvent with final=true is received.
90
- */
91
- events(): AsyncGenerator<AgentExecutionEvent, void, undefined>;
92
- /**
93
- * Stops the event queue from processing further events.
94
- */
95
- stop(): void;
96
- }
97
-
98
- /**
99
- * Simplified interface for task storage providers.
100
- * Stores and retrieves the task.
101
- */
102
- interface TaskStore {
103
- /**
104
- * Saves a task.
105
- * Overwrites existing data if the task ID exists.
106
- * @param data An object containing the task.
107
- * @returns A promise resolving when the save operation is complete.
108
- */
109
- save(task: Task): Promise<void>;
110
- /**
111
- * Loads a task by task ID.
112
- * @param taskId The ID of the task to load.
113
- * @returns A promise resolving to an object containing the Task, or undefined if not found.
114
- */
115
- load(taskId: string): Promise<Task | undefined>;
116
- }
117
- declare class InMemoryTaskStore implements TaskStore {
118
- private store;
119
- load(taskId: string): Promise<Task | undefined>;
120
- save(task: Task): Promise<void>;
121
- }
122
-
123
- interface PushNotificationStore {
124
- save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
125
- load(taskId: string): Promise<PushNotificationConfig[]>;
126
- delete(taskId: string, configId?: string): Promise<void>;
127
- }
128
- declare class InMemoryPushNotificationStore implements PushNotificationStore {
129
- private store;
130
- save(taskId: string, pushNotificationConfig: PushNotificationConfig): Promise<void>;
131
- load(taskId: string): Promise<PushNotificationConfig[]>;
132
- delete(taskId: string, configId?: string): Promise<void>;
133
- }
134
-
135
- interface PushNotificationSender {
136
- send(task: Task): Promise<void>;
137
- }
138
-
139
- declare class DefaultRequestHandler implements A2ARequestHandler {
140
- private readonly agentCard;
141
- private readonly taskStore;
142
- private readonly agentExecutor;
143
- private readonly eventBusManager;
144
- private readonly pushNotificationStore?;
145
- private readonly pushNotificationSender?;
146
- private readonly extendedAgentCardProvider?;
147
- constructor(agentCard: AgentCard, taskStore: TaskStore, agentExecutor: AgentExecutor, eventBusManager?: ExecutionEventBusManager, pushNotificationStore?: PushNotificationStore, pushNotificationSender?: PushNotificationSender, extendedAgentCardProvider?: AgentCard | ExtendedAgentCardProvider);
148
- getAgentCard(): Promise<AgentCard>;
149
- getAuthenticatedExtendedAgentCard(context?: ServerCallContext): Promise<AgentCard>;
150
- private _createRequestContext;
151
- private _processEvents;
152
- sendMessage(params: MessageSendParams, context?: ServerCallContext): Promise<Message | Task>;
153
- sendMessageStream(params: MessageSendParams, context?: ServerCallContext): AsyncGenerator<Message | Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
154
- getTask(params: TaskQueryParams, _context?: ServerCallContext): Promise<Task>;
155
- cancelTask(params: TaskIdParams, _context?: ServerCallContext): Promise<Task>;
156
- setTaskPushNotificationConfig(params: TaskPushNotificationConfig, _context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
157
- getTaskPushNotificationConfig(params: TaskIdParams | GetTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<TaskPushNotificationConfig>;
158
- listTaskPushNotificationConfigs(params: ListTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
159
- deleteTaskPushNotificationConfig(params: DeleteTaskPushNotificationConfigParams, _context?: ServerCallContext): Promise<void>;
160
- resubscribe(params: TaskIdParams, _context?: ServerCallContext): AsyncGenerator<Task | TaskStatusUpdateEvent | TaskArtifactUpdateEvent, void, undefined>;
161
- private _sendPushNotificationIfNeeded;
162
- private _handleProcessingError;
163
- }
164
- type ExtendedAgentCardProvider = (context?: ServerCallContext) => Promise<AgentCard>;
165
-
166
- declare class ResultManager {
167
- private taskStore;
168
- private currentTask?;
169
- private latestUserMessage?;
170
- private finalMessageResult?;
171
- constructor(taskStore: TaskStore);
172
- setContext(latestUserMessage: Message): void;
173
- /**
174
- * Processes an agent execution event and updates the task store.
175
- * @param event The agent execution event.
176
- */
177
- processEvent(event: AgentExecutionEvent): Promise<void>;
178
- private saveCurrentTask;
179
- /**
180
- * Gets the final result, which could be a Message or a Task.
181
- * This should be called after the event stream has been fully processed.
182
- * @returns The final Message or the current Task.
183
- */
184
- getFinalResult(): Message | Task | undefined;
185
- /**
186
- * Gets the task currently being managed by this ResultManager instance.
187
- * This task could be one that was started with or one created during agent execution.
188
- * @returns The current Task or undefined if no task is active.
189
- */
190
- getCurrentTask(): Task | undefined;
191
- }
192
-
193
- /**
194
- * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
195
- */
196
- declare class JsonRpcTransportHandler {
197
- private requestHandler;
198
- constructor(requestHandler: A2ARequestHandler);
199
- /**
200
- * Handles an incoming JSON-RPC request.
201
- * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
202
- * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
203
- */
204
- handle(requestBody: any, context?: ServerCallContext): Promise<JSONRPCResponse | AsyncGenerator<JSONRPCResponse, void, undefined>>;
205
- private isRequestValid;
206
- private paramsAreValid;
207
- }
208
-
209
- /**
210
- * Custom error class for A2A server operations, incorporating JSON-RPC error codes.
211
- */
212
- declare class A2AError extends Error {
213
- code: number;
214
- data?: Record<string, unknown>;
215
- taskId?: string;
216
- constructor(code: number, message: string, data?: Record<string, unknown>, taskId?: string);
217
- /**
218
- * Formats the error into a standard JSON-RPC error object structure.
219
- */
220
- toJSONRPCError(): JSONRPCError;
221
- static parseError(message: string, data?: Record<string, unknown>): A2AError;
222
- static invalidRequest(message: string, data?: Record<string, unknown>): A2AError;
223
- static methodNotFound(method: string): A2AError;
224
- static invalidParams(message: string, data?: Record<string, unknown>): A2AError;
225
- static internalError(message: string, data?: Record<string, unknown>): A2AError;
226
- static taskNotFound(taskId: string): A2AError;
227
- static taskNotCancelable(taskId: string): A2AError;
228
- static pushNotificationNotSupported(): A2AError;
229
- static unsupportedOperation(operation: string): A2AError;
230
- static authenticatedExtendedCardNotConfigured(): A2AError;
231
- }
232
-
233
- export { type AgentExecutor as A, DefaultExecutionEventBus as D, type ExecutionEventBus as E, InMemoryTaskStore as I, JsonRpcTransportHandler as J, type PushNotificationSender as P, RequestContext as R, type TaskStore as T, type PushNotificationStore as a, type AgentExecutionEvent as b, type ExecutionEventBusManager as c, DefaultExecutionEventBusManager as d, ExecutionEventQueue as e, DefaultRequestHandler as f, type ExtendedAgentCardProvider as g, ResultManager as h, A2AError as i, InMemoryPushNotificationStore as j };