@a2a-js/sdk 0.2.2 → 0.2.3

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.
Files changed (48) hide show
  1. package/README.md +106 -89
  2. package/package.json +25 -7
  3. package/build/src/a2a_response.d.ts +0 -5
  4. package/build/src/a2a_response.js +0 -2
  5. package/build/src/client/client.d.ts +0 -118
  6. package/build/src/client/client.js +0 -409
  7. package/build/src/index.d.ts +0 -21
  8. package/build/src/index.js +0 -18
  9. package/build/src/samples/agents/movie-agent/genkit.d.ts +0 -2
  10. package/build/src/samples/agents/movie-agent/genkit.js +0 -11
  11. package/build/src/samples/agents/movie-agent/index.d.ts +0 -1
  12. package/build/src/samples/agents/movie-agent/index.js +0 -252
  13. package/build/src/samples/agents/movie-agent/tmdb.d.ts +0 -7
  14. package/build/src/samples/agents/movie-agent/tmdb.js +0 -32
  15. package/build/src/samples/agents/movie-agent/tools.d.ts +0 -15
  16. package/build/src/samples/agents/movie-agent/tools.js +0 -74
  17. package/build/src/samples/cli.d.ts +0 -2
  18. package/build/src/samples/cli.js +0 -289
  19. package/build/src/server/a2a_express_app.d.ts +0 -14
  20. package/build/src/server/a2a_express_app.js +0 -98
  21. package/build/src/server/agent_execution/agent_executor.d.ts +0 -18
  22. package/build/src/server/agent_execution/agent_executor.js +0 -2
  23. package/build/src/server/agent_execution/request_context.d.ts +0 -9
  24. package/build/src/server/agent_execution/request_context.js +0 -15
  25. package/build/src/server/error.d.ts +0 -23
  26. package/build/src/server/error.js +0 -57
  27. package/build/src/server/events/execution_event_bus.d.ts +0 -16
  28. package/build/src/server/events/execution_event_bus.js +0 -13
  29. package/build/src/server/events/execution_event_bus_manager.d.ts +0 -27
  30. package/build/src/server/events/execution_event_bus_manager.js +0 -36
  31. package/build/src/server/events/execution_event_queue.d.ts +0 -24
  32. package/build/src/server/events/execution_event_queue.js +0 -63
  33. package/build/src/server/request_handler/a2a_request_handler.d.ts +0 -11
  34. package/build/src/server/request_handler/a2a_request_handler.js +0 -2
  35. package/build/src/server/request_handler/default_request_handler.d.ts +0 -23
  36. package/build/src/server/request_handler/default_request_handler.js +0 -340
  37. package/build/src/server/result_manager.d.ts +0 -29
  38. package/build/src/server/result_manager.js +0 -149
  39. package/build/src/server/store.d.ts +0 -25
  40. package/build/src/server/store.js +0 -17
  41. package/build/src/server/transports/jsonrpc_transport_handler.d.ts +0 -15
  42. package/build/src/server/transports/jsonrpc_transport_handler.js +0 -114
  43. package/build/src/server/utils.d.ts +0 -22
  44. package/build/src/server/utils.js +0 -34
  45. package/build/src/types-old.d.ts +0 -832
  46. package/build/src/types-old.js +0 -20
  47. package/build/src/types.d.ts +0 -2046
  48. package/build/src/types.js +0 -8
@@ -1,340 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid'; // For generating unique IDs
2
- import { RequestContext } from "../agent_execution/request_context.js";
3
- import { A2AError } from "../error.js";
4
- import { DefaultExecutionEventBusManager } from "../events/execution_event_bus_manager.js";
5
- import { ExecutionEventQueue } from "../events/execution_event_queue.js";
6
- import { ResultManager } from "../result_manager.js";
7
- const terminalStates = ["completed", "failed", "canceled", "rejected"];
8
- export class DefaultRequestHandler {
9
- agentCard;
10
- taskStore;
11
- agentExecutor;
12
- eventBusManager;
13
- // Store for push notification configurations (could be part of TaskStore or separate)
14
- pushNotificationConfigs = new Map();
15
- constructor(agentCard, taskStore, agentExecutor, eventBusManager = new DefaultExecutionEventBusManager()) {
16
- this.agentCard = agentCard;
17
- this.taskStore = taskStore;
18
- this.agentExecutor = agentExecutor;
19
- this.eventBusManager = eventBusManager;
20
- }
21
- async getAgentCard() {
22
- return this.agentCard;
23
- }
24
- async _createRequestContext(incomingMessage, taskId, isStream) {
25
- let task;
26
- let referenceTasks;
27
- // incomingMessage would contain taskId, if a task already exists.
28
- if (incomingMessage.taskId) {
29
- task = await this.taskStore.load(incomingMessage.taskId);
30
- if (!task) {
31
- throw A2AError.taskNotFound(incomingMessage.taskId);
32
- }
33
- if (terminalStates.includes(task.status.state)) {
34
- // Throw an error that conforms to the JSON-RPC Invalid Request error specification.
35
- throw A2AError.invalidRequest(`Task ${task.id} is in a terminal state (${task.status.state}) and cannot be modified.`);
36
- }
37
- }
38
- if (incomingMessage.referenceTaskIds && incomingMessage.referenceTaskIds.length > 0) {
39
- referenceTasks = [];
40
- for (const refId of incomingMessage.referenceTaskIds) {
41
- const refTask = await this.taskStore.load(refId);
42
- if (refTask) {
43
- referenceTasks.push(refTask);
44
- }
45
- else {
46
- console.warn(`Reference task ${refId} not found.`);
47
- // Optionally, throw an error or handle as per specific requirements
48
- }
49
- }
50
- }
51
- // Ensure contextId is present
52
- const messageForContext = { ...incomingMessage };
53
- if (!messageForContext.contextId) {
54
- messageForContext.contextId = task?.contextId || uuidv4();
55
- }
56
- const contextId = incomingMessage.contextId || uuidv4();
57
- return new RequestContext(messageForContext, taskId, contextId, task, referenceTasks);
58
- }
59
- async _processEvents(taskId, resultManager, eventQueue, options) {
60
- let firstResultSent = false;
61
- try {
62
- for await (const event of eventQueue.events()) {
63
- await resultManager.processEvent(event);
64
- if (options?.firstResultResolver && !firstResultSent) {
65
- if (event.kind === 'message' || event.kind === 'task') {
66
- options.firstResultResolver(event);
67
- firstResultSent = true;
68
- }
69
- }
70
- }
71
- if (options?.firstResultRejector && !firstResultSent) {
72
- options.firstResultRejector(A2AError.internalError('Execution finished before a message or task was produced.'));
73
- }
74
- }
75
- catch (error) {
76
- console.error(`Event processing loop failed for task ${taskId}:`, error);
77
- if (options?.firstResultRejector && !firstResultSent) {
78
- options.firstResultRejector(error);
79
- }
80
- // re-throw error for blocking case to catch
81
- throw error;
82
- }
83
- finally {
84
- this.eventBusManager.cleanupByTaskId(taskId);
85
- }
86
- }
87
- async sendMessage(params) {
88
- const incomingMessage = params.message;
89
- if (!incomingMessage.messageId) {
90
- throw A2AError.invalidParams('message.messageId is required.');
91
- }
92
- // Default to blocking behavior if 'blocking' is not explicitly false.
93
- const isBlocking = params.configuration?.blocking !== false;
94
- const taskId = incomingMessage.taskId || uuidv4();
95
- // Instantiate ResultManager before creating RequestContext
96
- const resultManager = new ResultManager(this.taskStore);
97
- resultManager.setContext(incomingMessage); // Set context for ResultManager
98
- const requestContext = await this._createRequestContext(incomingMessage, taskId, false);
99
- // Use the (potentially updated) contextId from requestContext
100
- const finalMessageForAgent = requestContext.userMessage;
101
- const eventBus = this.eventBusManager.createOrGetByTaskId(taskId);
102
- // EventQueue should be attached to the bus, before the agent execution begins.
103
- const eventQueue = new ExecutionEventQueue(eventBus);
104
- // Start agent execution (non-blocking).
105
- // It runs in the background and publishes events to the eventBus.
106
- this.agentExecutor.execute(requestContext, eventBus).catch(err => {
107
- console.error(`Agent execution failed for message ${finalMessageForAgent.messageId}:`, err);
108
- // Publish a synthetic error event, which will be handled by the ResultManager
109
- // and will also settle the firstResultPromise for non-blocking calls.
110
- const errorTask = {
111
- id: requestContext.task?.id || uuidv4(), // Use existing task ID or generate new
112
- contextId: finalMessageForAgent.contextId,
113
- status: {
114
- state: "failed",
115
- message: {
116
- kind: "message",
117
- role: "agent",
118
- messageId: uuidv4(),
119
- parts: [{ kind: "text", text: `Agent execution error: ${err.message}` }],
120
- taskId: requestContext.task?.id,
121
- contextId: finalMessageForAgent.contextId,
122
- },
123
- timestamp: new Date().toISOString(),
124
- },
125
- history: requestContext.task?.history ? [...requestContext.task.history] : [],
126
- kind: "task",
127
- };
128
- if (finalMessageForAgent) { // Add incoming message to history
129
- if (!errorTask.history?.find(m => m.messageId === finalMessageForAgent.messageId)) {
130
- errorTask.history?.push(finalMessageForAgent);
131
- }
132
- }
133
- eventBus.publish(errorTask);
134
- eventBus.publish({
135
- kind: "status-update",
136
- taskId: errorTask.id,
137
- contextId: errorTask.contextId,
138
- status: errorTask.status,
139
- final: true,
140
- });
141
- eventBus.finished();
142
- });
143
- if (isBlocking) {
144
- // In blocking mode, wait for the full processing to complete.
145
- await this._processEvents(taskId, resultManager, eventQueue);
146
- const finalResult = resultManager.getFinalResult();
147
- if (!finalResult) {
148
- throw A2AError.internalError('Agent execution finished without a result, and no task context found.');
149
- }
150
- return finalResult;
151
- }
152
- else {
153
- // In non-blocking mode, return a promise that will be settled by fullProcessing.
154
- return new Promise((resolve, reject) => {
155
- this._processEvents(taskId, resultManager, eventQueue, {
156
- firstResultResolver: resolve,
157
- firstResultRejector: reject,
158
- });
159
- });
160
- }
161
- }
162
- async *sendMessageStream(params) {
163
- const incomingMessage = params.message;
164
- if (!incomingMessage.messageId) {
165
- // For streams, messageId might be set by client, or server can generate if not present.
166
- // Let's assume client provides it or throw for now.
167
- throw A2AError.invalidParams('message.messageId is required for streaming.');
168
- }
169
- const taskId = incomingMessage.taskId || uuidv4();
170
- // Instantiate ResultManager before creating RequestContext
171
- const resultManager = new ResultManager(this.taskStore);
172
- resultManager.setContext(incomingMessage); // Set context for ResultManager
173
- const requestContext = await this._createRequestContext(incomingMessage, taskId, true);
174
- const finalMessageForAgent = requestContext.userMessage;
175
- const eventBus = this.eventBusManager.createOrGetByTaskId(taskId);
176
- const eventQueue = new ExecutionEventQueue(eventBus);
177
- // Start agent execution (non-blocking)
178
- this.agentExecutor.execute(requestContext, eventBus).catch(err => {
179
- console.error(`Agent execution failed for stream message ${finalMessageForAgent.messageId}:`, err);
180
- // Publish a synthetic error event if needed
181
- const errorTaskStatus = {
182
- kind: "status-update",
183
- taskId: requestContext.task?.id || uuidv4(), // Use existing or a placeholder
184
- contextId: finalMessageForAgent.contextId,
185
- status: {
186
- state: "failed",
187
- message: {
188
- kind: "message",
189
- role: "agent",
190
- messageId: uuidv4(),
191
- parts: [{ kind: "text", text: `Agent execution error: ${err.message}` }],
192
- taskId: requestContext.task?.id,
193
- contextId: finalMessageForAgent.contextId,
194
- },
195
- timestamp: new Date().toISOString(),
196
- },
197
- final: true, // This will terminate the stream for the client
198
- };
199
- eventBus.publish(errorTaskStatus);
200
- });
201
- try {
202
- for await (const event of eventQueue.events()) {
203
- await resultManager.processEvent(event); // Update store in background
204
- yield event; // Stream the event to the client
205
- }
206
- }
207
- finally {
208
- // Cleanup when the stream is fully consumed or breaks
209
- this.eventBusManager.cleanupByTaskId(taskId);
210
- }
211
- }
212
- async getTask(params) {
213
- const task = await this.taskStore.load(params.id);
214
- if (!task) {
215
- throw A2AError.taskNotFound(params.id);
216
- }
217
- if (params.historyLength !== undefined && params.historyLength >= 0) {
218
- if (task.history) {
219
- task.history = task.history.slice(-params.historyLength);
220
- }
221
- }
222
- else {
223
- // Negative or invalid historyLength means no history
224
- task.history = [];
225
- }
226
- return task;
227
- }
228
- async cancelTask(params) {
229
- const task = await this.taskStore.load(params.id);
230
- if (!task) {
231
- throw A2AError.taskNotFound(params.id);
232
- }
233
- // Check if task is in a cancelable state
234
- const nonCancelableStates = ["completed", "failed", "canceled", "rejected"];
235
- if (nonCancelableStates.includes(task.status.state)) {
236
- throw A2AError.taskNotCancelable(params.id);
237
- }
238
- const eventBus = this.eventBusManager.getByTaskId(params.id);
239
- if (eventBus) {
240
- await this.agentExecutor.cancelTask(params.id, eventBus);
241
- }
242
- else {
243
- // Here we are marking task as cancelled. We are not waiting for the executor to actually cancel processing.
244
- task.status = {
245
- state: "canceled",
246
- message: {
247
- kind: "message",
248
- role: "agent",
249
- messageId: uuidv4(),
250
- parts: [{ kind: "text", text: "Task cancellation requested by user." }],
251
- taskId: task.id,
252
- contextId: task.contextId,
253
- },
254
- timestamp: new Date().toISOString(),
255
- };
256
- // Add cancellation message to history
257
- task.history = [...(task.history || []), task.status.message];
258
- await this.taskStore.save(task);
259
- }
260
- const latestTask = await this.taskStore.load(params.id);
261
- return latestTask;
262
- }
263
- async setTaskPushNotificationConfig(params) {
264
- if (!this.agentCard.capabilities.pushNotifications) {
265
- throw A2AError.pushNotificationNotSupported();
266
- }
267
- const taskAndHistory = await this.taskStore.load(params.taskId);
268
- if (!taskAndHistory) {
269
- throw A2AError.taskNotFound(params.taskId);
270
- }
271
- // Store the config. In a real app, this might be stored in the TaskStore
272
- // or a dedicated push notification service.
273
- this.pushNotificationConfigs.set(params.taskId, params.pushNotificationConfig);
274
- return params;
275
- }
276
- async getTaskPushNotificationConfig(params) {
277
- if (!this.agentCard.capabilities.pushNotifications) {
278
- throw A2AError.pushNotificationNotSupported();
279
- }
280
- const taskAndHistory = await this.taskStore.load(params.id); // Ensure task exists
281
- if (!taskAndHistory) {
282
- throw A2AError.taskNotFound(params.id);
283
- }
284
- const config = this.pushNotificationConfigs.get(params.id);
285
- if (!config) {
286
- throw A2AError.internalError(`Push notification config not found for task ${params.id}.`);
287
- }
288
- return { taskId: params.id, pushNotificationConfig: config };
289
- }
290
- async *resubscribe(params) {
291
- if (!this.agentCard.capabilities.streaming) {
292
- throw A2AError.unsupportedOperation("Streaming (and thus resubscription) is not supported.");
293
- }
294
- const task = await this.taskStore.load(params.id);
295
- if (!task) {
296
- throw A2AError.taskNotFound(params.id);
297
- }
298
- // Yield the current task state first
299
- yield task;
300
- // If task is already in a final state, no more events will come.
301
- const finalStates = ["completed", "failed", "canceled", "rejected"];
302
- if (finalStates.includes(task.status.state)) {
303
- return;
304
- }
305
- const eventBus = this.eventBusManager.getByTaskId(params.id);
306
- if (!eventBus) {
307
- // No active execution for this task, so no live events.
308
- console.warn(`Resubscribe: No active event bus for task ${params.id}.`);
309
- return;
310
- }
311
- // Attach a new queue to the existing bus for this resubscription
312
- const eventQueue = new ExecutionEventQueue(eventBus);
313
- // Note: The ResultManager part is already handled by the original execution flow.
314
- // Resubscribe just listens for new events.
315
- try {
316
- for await (const event of eventQueue.events()) {
317
- // We only care about updates related to *this* task.
318
- // The event bus might be shared if messageId was reused, though
319
- // ExecutionEventBusManager tries to give one bus per original message.
320
- if (event.kind === 'status-update' && event.taskId === params.id) {
321
- yield event;
322
- }
323
- else if (event.kind === 'artifact-update' && event.taskId === params.id) {
324
- yield event;
325
- }
326
- else if (event.kind === 'task' && event.id === params.id) {
327
- // This implies the task was re-emitted, yield it.
328
- yield event;
329
- }
330
- // We don't yield 'message' events on resubscribe typically,
331
- // as those signal the end of an interaction for the *original* request.
332
- // If a 'message' event for the original request terminates the bus, this loop will also end.
333
- }
334
- }
335
- finally {
336
- eventQueue.stop();
337
- }
338
- }
339
- }
340
- //# sourceMappingURL=default_request_handler.js.map
@@ -1,29 +0,0 @@
1
- import { Message, Task } from "../types.js";
2
- import { AgentExecutionEvent } from "./events/execution_event_bus.js";
3
- import { TaskStore } from "./store.js";
4
- export declare class ResultManager {
5
- private taskStore;
6
- private currentTask?;
7
- private latestUserMessage?;
8
- private finalMessageResult?;
9
- constructor(taskStore: TaskStore);
10
- setContext(latestUserMessage: Message): void;
11
- /**
12
- * Processes an agent execution event and updates the task store.
13
- * @param event The agent execution event.
14
- */
15
- processEvent(event: AgentExecutionEvent): Promise<void>;
16
- private saveCurrentTask;
17
- /**
18
- * Gets the final result, which could be a Message or a Task.
19
- * This should be called after the event stream has been fully processed.
20
- * @returns The final Message or the current Task.
21
- */
22
- getFinalResult(): Message | Task | undefined;
23
- /**
24
- * Gets the task currently being managed by this ResultManager instance.
25
- * This task could be one that was started with or one created during agent execution.
26
- * @returns The current Task or undefined if no task is active.
27
- */
28
- getCurrentTask(): Task | undefined;
29
- }
@@ -1,149 +0,0 @@
1
- export class ResultManager {
2
- taskStore;
3
- currentTask;
4
- latestUserMessage; // To add to history if a new task is created
5
- finalMessageResult; // Stores the message if it's the final result
6
- constructor(taskStore) {
7
- this.taskStore = taskStore;
8
- }
9
- setContext(latestUserMessage) {
10
- this.latestUserMessage = latestUserMessage;
11
- }
12
- /**
13
- * Processes an agent execution event and updates the task store.
14
- * @param event The agent execution event.
15
- */
16
- async processEvent(event) {
17
- if (event.kind === 'message') {
18
- this.finalMessageResult = event;
19
- // If a message is received, it's usually the final result,
20
- // but we continue processing to ensure task state (if any) is also saved.
21
- // The ExecutionEventQueue will stop after a message event.
22
- }
23
- else if (event.kind === 'task') {
24
- const taskEvent = event;
25
- this.currentTask = { ...taskEvent }; // Make a copy
26
- // Ensure the latest user message is in history if not already present
27
- if (this.latestUserMessage) {
28
- if (!this.currentTask.history?.find(msg => msg.messageId === this.latestUserMessage.messageId)) {
29
- this.currentTask.history = [this.latestUserMessage, ...(this.currentTask.history || [])];
30
- }
31
- }
32
- await this.saveCurrentTask();
33
- }
34
- else if (event.kind === 'status-update') {
35
- const updateEvent = event;
36
- if (this.currentTask && this.currentTask.id === updateEvent.taskId) {
37
- this.currentTask.status = updateEvent.status;
38
- if (updateEvent.status.message) {
39
- // Add message to history if not already present
40
- if (!this.currentTask.history?.find(msg => msg.messageId === updateEvent.status.message.messageId)) {
41
- this.currentTask.history = [...(this.currentTask.history || []), updateEvent.status.message];
42
- }
43
- }
44
- await this.saveCurrentTask();
45
- }
46
- else if (!this.currentTask && updateEvent.taskId) {
47
- // Potentially an update for a task we haven't seen the 'task' event for yet,
48
- // or we are rehydrating. Attempt to load.
49
- const loaded = await this.taskStore.load(updateEvent.taskId);
50
- if (loaded) {
51
- this.currentTask = loaded;
52
- this.currentTask.status = updateEvent.status;
53
- if (updateEvent.status.message) {
54
- if (!this.currentTask.history?.find(msg => msg.messageId === updateEvent.status.message.messageId)) {
55
- this.currentTask.history = [...(this.currentTask.history || []), updateEvent.status.message];
56
- }
57
- }
58
- await this.saveCurrentTask();
59
- }
60
- else {
61
- console.warn(`ResultManager: Received status update for unknown task ${updateEvent.taskId}`);
62
- }
63
- }
64
- // If it's a final status update, the ExecutionEventQueue will stop.
65
- // The final result will be the currentTask.
66
- }
67
- else if (event.kind === 'artifact-update') {
68
- const artifactEvent = event;
69
- if (this.currentTask && this.currentTask.id === artifactEvent.taskId) {
70
- if (!this.currentTask.artifacts) {
71
- this.currentTask.artifacts = [];
72
- }
73
- const existingArtifactIndex = this.currentTask.artifacts.findIndex((art) => art.artifactId === artifactEvent.artifact.artifactId);
74
- if (existingArtifactIndex !== -1) {
75
- if (artifactEvent.append) {
76
- // Basic append logic, assuming parts are compatible
77
- // More sophisticated merging might be needed for specific part types
78
- const existingArtifact = this.currentTask.artifacts[existingArtifactIndex];
79
- existingArtifact.parts.push(...artifactEvent.artifact.parts);
80
- if (artifactEvent.artifact.description)
81
- existingArtifact.description = artifactEvent.artifact.description;
82
- if (artifactEvent.artifact.name)
83
- existingArtifact.name = artifactEvent.artifact.name;
84
- if (artifactEvent.artifact.metadata)
85
- existingArtifact.metadata = { ...existingArtifact.metadata, ...artifactEvent.artifact.metadata };
86
- }
87
- else {
88
- this.currentTask.artifacts[existingArtifactIndex] = artifactEvent.artifact;
89
- }
90
- }
91
- else {
92
- this.currentTask.artifacts.push(artifactEvent.artifact);
93
- }
94
- await this.saveCurrentTask();
95
- }
96
- else if (!this.currentTask && artifactEvent.taskId) {
97
- // Similar to status update, try to load if task not in memory
98
- const loaded = await this.taskStore.load(artifactEvent.taskId);
99
- if (loaded) {
100
- this.currentTask = loaded;
101
- if (!this.currentTask.artifacts)
102
- this.currentTask.artifacts = [];
103
- // Apply artifact update logic (as above)
104
- const existingArtifactIndex = this.currentTask.artifacts.findIndex((art) => art.artifactId === artifactEvent.artifact.artifactId);
105
- if (existingArtifactIndex !== -1) {
106
- if (artifactEvent.append) {
107
- this.currentTask.artifacts[existingArtifactIndex].parts.push(...artifactEvent.artifact.parts);
108
- }
109
- else {
110
- this.currentTask.artifacts[existingArtifactIndex] = artifactEvent.artifact;
111
- }
112
- }
113
- else {
114
- this.currentTask.artifacts.push(artifactEvent.artifact);
115
- }
116
- await this.saveCurrentTask();
117
- }
118
- else {
119
- console.warn(`ResultManager: Received artifact update for unknown task ${artifactEvent.taskId}`);
120
- }
121
- }
122
- }
123
- }
124
- async saveCurrentTask() {
125
- if (this.currentTask) {
126
- await this.taskStore.save(this.currentTask);
127
- }
128
- }
129
- /**
130
- * Gets the final result, which could be a Message or a Task.
131
- * This should be called after the event stream has been fully processed.
132
- * @returns The final Message or the current Task.
133
- */
134
- getFinalResult() {
135
- if (this.finalMessageResult) {
136
- return this.finalMessageResult;
137
- }
138
- return this.currentTask;
139
- }
140
- /**
141
- * Gets the task currently being managed by this ResultManager instance.
142
- * This task could be one that was started with or one created during agent execution.
143
- * @returns The current Task or undefined if no task is active.
144
- */
145
- getCurrentTask() {
146
- return this.currentTask;
147
- }
148
- }
149
- //# sourceMappingURL=result_manager.js.map
@@ -1,25 +0,0 @@
1
- import { Task } from "../types.js";
2
- /**
3
- * Simplified interface for task storage providers.
4
- * Stores and retrieves the task.
5
- */
6
- export interface TaskStore {
7
- /**
8
- * Saves a task.
9
- * Overwrites existing data if the task ID exists.
10
- * @param data An object containing the task.
11
- * @returns A promise resolving when the save operation is complete.
12
- */
13
- save(task: Task): Promise<void>;
14
- /**
15
- * Loads a task by task ID.
16
- * @param taskId The ID of the task to load.
17
- * @returns A promise resolving to an object containing the Task, or undefined if not found.
18
- */
19
- load(taskId: string): Promise<Task | undefined>;
20
- }
21
- export declare class InMemoryTaskStore implements TaskStore {
22
- private store;
23
- load(taskId: string): Promise<Task | undefined>;
24
- save(task: Task): Promise<void>;
25
- }
@@ -1,17 +0,0 @@
1
- // ========================
2
- // InMemoryTaskStore
3
- // ========================
4
- // Use Task directly for storage
5
- export class InMemoryTaskStore {
6
- store = new Map();
7
- async load(taskId) {
8
- const entry = this.store.get(taskId);
9
- // Return copies to prevent external mutation
10
- return entry ? { ...entry } : undefined;
11
- }
12
- async save(task) {
13
- // Store copies to prevent internal mutation if caller reuses objects
14
- this.store.set(task.id, { ...task });
15
- }
16
- }
17
- //# sourceMappingURL=store.js.map
@@ -1,15 +0,0 @@
1
- import { A2AResponse } from "../../a2a_response.js";
2
- import { A2ARequestHandler } from "../request_handler/a2a_request_handler.js";
3
- /**
4
- * Handles JSON-RPC transport layer, routing requests to A2ARequestHandler.
5
- */
6
- export declare class JsonRpcTransportHandler {
7
- private requestHandler;
8
- constructor(requestHandler: A2ARequestHandler);
9
- /**
10
- * Handles an incoming JSON-RPC request.
11
- * For streaming methods, it returns an AsyncGenerator of JSONRPCResult.
12
- * For non-streaming methods, it returns a Promise of a single JSONRPCMessage (Result or ErrorResponse).
13
- */
14
- handle(requestBody: any): Promise<A2AResponse | AsyncGenerator<A2AResponse, void, undefined>>;
15
- }