@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.
- package/README.md +171 -93
- package/dist/{a2a_request_handler-DQfg1Q-R.d.ts → a2a_request_handler-1Isk3l-0.d.mts} +16 -4
- package/dist/{a2a_request_handler-DPkhsCMt.d.mts → a2a_request_handler-BuP9LgXH.d.ts} +16 -4
- package/dist/chunk-7JFJW6P6.mjs +38 -0
- package/dist/{chunk-LVD4GF26.mjs → chunk-AZGEDUZX.mjs} +6 -7
- package/dist/chunk-BNBEZNW7.mjs +122 -0
- package/dist/client/index.d.mts +401 -47
- package/dist/client/index.d.ts +401 -47
- package/dist/client/index.js +525 -78
- package/dist/client/index.mjs +1110 -29
- package/dist/{types-Due_Cv6t.d.mts → extensions-DvruCIzw.d.mts} +40 -1
- package/dist/{types-Due_Cv6t.d.ts → extensions-DvruCIzw.d.ts} +40 -1
- package/dist/index.d.mts +5 -33
- package/dist/index.d.ts +5 -33
- package/dist/index.js +27 -2083
- package/dist/index.mjs +6 -42
- package/dist/server/express/index.d.mts +76 -4
- package/dist/server/express/index.d.ts +76 -4
- package/dist/server/express/index.js +563 -37
- package/dist/server/express/index.mjs +642 -6
- package/dist/server/index.d.mts +296 -6
- package/dist/server/index.d.ts +296 -6
- package/dist/server/index.js +265 -52
- package/dist/server/index.mjs +1050 -12
- package/package.json +39 -17
- package/dist/auth-handler-DVLcl8yj.d.mts +0 -209
- package/dist/auth-handler-Gzpf3xHC.d.ts +0 -209
- package/dist/chunk-HZFUOBJQ.mjs +0 -198
- package/dist/chunk-LIEYEFQG.mjs +0 -879
- package/dist/chunk-UBRSFN2J.mjs +0 -776
- package/dist/error-DExKs0Q3.d.mts +0 -233
- package/dist/error-j1vYKII2.d.ts +0 -233
package/dist/server/index.js
CHANGED
|
@@ -54,16 +54,194 @@ var RequestContext = class {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
// src/server/events/execution_event_bus.ts
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
constructor() {
|
|
60
|
-
super();
|
|
57
|
+
var CustomEventImpl = typeof CustomEvent !== "undefined" ? CustomEvent : class CustomEventPolyfill extends Event {
|
|
58
|
+
detail;
|
|
59
|
+
constructor(type, eventInitDict) {
|
|
60
|
+
super(type, eventInitDict);
|
|
61
|
+
this.detail = eventInitDict?.detail ?? null;
|
|
61
62
|
}
|
|
63
|
+
};
|
|
64
|
+
function isAgentExecutionCustomEvent(e) {
|
|
65
|
+
return e instanceof CustomEventImpl;
|
|
66
|
+
}
|
|
67
|
+
var DefaultExecutionEventBus = class extends EventTarget {
|
|
68
|
+
// Separate storage for each event type - both use the interface's Listener type
|
|
69
|
+
// but are invoked differently (with event payload vs. no arguments)
|
|
70
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
71
|
+
finishedListeners = /* @__PURE__ */ new Map();
|
|
62
72
|
publish(event) {
|
|
63
|
-
this.
|
|
73
|
+
this.dispatchEvent(new CustomEventImpl("event", { detail: event }));
|
|
64
74
|
}
|
|
65
75
|
finished() {
|
|
66
|
-
this.
|
|
76
|
+
this.dispatchEvent(new Event("finished"));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* EventEmitter-compatible 'on' method.
|
|
80
|
+
* Wraps the listener to extract event detail from CustomEvent.
|
|
81
|
+
* Supports multiple registrations of the same listener (like EventEmitter).
|
|
82
|
+
* @param eventName The event name to listen for.
|
|
83
|
+
* @param listener The callback function to invoke when the event is emitted.
|
|
84
|
+
* @returns This instance for method chaining.
|
|
85
|
+
*/
|
|
86
|
+
on(eventName, listener) {
|
|
87
|
+
if (eventName === "event") {
|
|
88
|
+
this.addEventListenerInternal(listener);
|
|
89
|
+
} else {
|
|
90
|
+
this.addFinishedListenerInternal(listener);
|
|
91
|
+
}
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* EventEmitter-compatible 'off' method.
|
|
96
|
+
* Uses the stored wrapped listener for proper removal.
|
|
97
|
+
* Removes at most one instance of a listener per call (like EventEmitter).
|
|
98
|
+
* @param eventName The event name to stop listening for.
|
|
99
|
+
* @param listener The callback function to remove.
|
|
100
|
+
* @returns This instance for method chaining.
|
|
101
|
+
*/
|
|
102
|
+
off(eventName, listener) {
|
|
103
|
+
if (eventName === "event") {
|
|
104
|
+
this.removeEventListenerInternal(listener);
|
|
105
|
+
} else {
|
|
106
|
+
this.removeFinishedListenerInternal(listener);
|
|
107
|
+
}
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* EventEmitter-compatible 'once' method.
|
|
112
|
+
* Listener is automatically removed after first invocation.
|
|
113
|
+
* Supports multiple registrations of the same listener (like EventEmitter).
|
|
114
|
+
* @param eventName The event name to listen for once.
|
|
115
|
+
* @param listener The callback function to invoke when the event is emitted.
|
|
116
|
+
* @returns This instance for method chaining.
|
|
117
|
+
*/
|
|
118
|
+
once(eventName, listener) {
|
|
119
|
+
if (eventName === "event") {
|
|
120
|
+
this.addEventListenerOnceInternal(listener);
|
|
121
|
+
} else {
|
|
122
|
+
this.addFinishedListenerOnceInternal(listener);
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* EventEmitter-compatible 'removeAllListeners' method.
|
|
128
|
+
* Removes all listeners for a specific event or all events.
|
|
129
|
+
* @param eventName Optional event name to remove listeners for. If omitted, removes all.
|
|
130
|
+
* @returns This instance for method chaining.
|
|
131
|
+
*/
|
|
132
|
+
removeAllListeners(eventName) {
|
|
133
|
+
if (eventName === void 0 || eventName === "event") {
|
|
134
|
+
for (const wrappedListeners of this.eventListeners.values()) {
|
|
135
|
+
for (const wrapped of wrappedListeners) {
|
|
136
|
+
this.removeEventListener("event", wrapped);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.eventListeners.clear();
|
|
140
|
+
}
|
|
141
|
+
if (eventName === void 0 || eventName === "finished") {
|
|
142
|
+
for (const wrappedListeners of this.finishedListeners.values()) {
|
|
143
|
+
for (const wrapped of wrappedListeners) {
|
|
144
|
+
this.removeEventListener("finished", wrapped);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.finishedListeners.clear();
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
// ========================
|
|
152
|
+
// Helper methods for listener tracking
|
|
153
|
+
// ========================
|
|
154
|
+
/**
|
|
155
|
+
* Adds a wrapped listener to the tracking map.
|
|
156
|
+
*/
|
|
157
|
+
trackListener(listenerMap, listener, wrapped) {
|
|
158
|
+
const existing = listenerMap.get(listener);
|
|
159
|
+
if (existing) {
|
|
160
|
+
existing.push(wrapped);
|
|
161
|
+
} else {
|
|
162
|
+
listenerMap.set(listener, [wrapped]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Removes a wrapped listener from the tracking map (for once cleanup).
|
|
167
|
+
*/
|
|
168
|
+
untrackWrappedListener(listenerMap, listener, wrapped) {
|
|
169
|
+
const wrappedList = listenerMap.get(listener);
|
|
170
|
+
if (wrappedList && wrappedList.length > 0) {
|
|
171
|
+
const index = wrappedList.indexOf(wrapped);
|
|
172
|
+
if (index !== -1) {
|
|
173
|
+
wrappedList.splice(index, 1);
|
|
174
|
+
if (wrappedList.length === 0) {
|
|
175
|
+
listenerMap.delete(listener);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// ========================
|
|
181
|
+
// Internal methods for 'event' listeners
|
|
182
|
+
// ========================
|
|
183
|
+
addEventListenerInternal(listener) {
|
|
184
|
+
const wrapped = (e) => {
|
|
185
|
+
if (!isAgentExecutionCustomEvent(e)) {
|
|
186
|
+
throw new Error('Internal error: expected CustomEvent for "event" type');
|
|
187
|
+
}
|
|
188
|
+
listener.call(this, e.detail);
|
|
189
|
+
};
|
|
190
|
+
this.trackListener(this.eventListeners, listener, wrapped);
|
|
191
|
+
this.addEventListener("event", wrapped);
|
|
192
|
+
}
|
|
193
|
+
removeEventListenerInternal(listener) {
|
|
194
|
+
const wrappedList = this.eventListeners.get(listener);
|
|
195
|
+
if (wrappedList && wrappedList.length > 0) {
|
|
196
|
+
const wrapped = wrappedList.pop();
|
|
197
|
+
if (wrappedList.length === 0) {
|
|
198
|
+
this.eventListeners.delete(listener);
|
|
199
|
+
}
|
|
200
|
+
this.removeEventListener("event", wrapped);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
addEventListenerOnceInternal(listener) {
|
|
204
|
+
const wrapped = (e) => {
|
|
205
|
+
if (!isAgentExecutionCustomEvent(e)) {
|
|
206
|
+
throw new Error('Internal error: expected CustomEvent for "event" type');
|
|
207
|
+
}
|
|
208
|
+
this.untrackWrappedListener(this.eventListeners, listener, wrapped);
|
|
209
|
+
listener.call(this, e.detail);
|
|
210
|
+
};
|
|
211
|
+
this.trackListener(this.eventListeners, listener, wrapped);
|
|
212
|
+
this.addEventListener("event", wrapped, { once: true });
|
|
213
|
+
}
|
|
214
|
+
// ========================
|
|
215
|
+
// Internal methods for 'finished' listeners
|
|
216
|
+
// ========================
|
|
217
|
+
// The interface declares listeners as (event: AgentExecutionEvent) => void,
|
|
218
|
+
// but for 'finished' events they are invoked with no arguments (EventEmitter behavior).
|
|
219
|
+
// We use Function.prototype.call to invoke with `this` as the event bus (matching
|
|
220
|
+
// EventEmitter semantics) and no arguments, which is type-safe.
|
|
221
|
+
addFinishedListenerInternal(listener) {
|
|
222
|
+
const wrapped = () => {
|
|
223
|
+
listener.call(this);
|
|
224
|
+
};
|
|
225
|
+
this.trackListener(this.finishedListeners, listener, wrapped);
|
|
226
|
+
this.addEventListener("finished", wrapped);
|
|
227
|
+
}
|
|
228
|
+
removeFinishedListenerInternal(listener) {
|
|
229
|
+
const wrappedList = this.finishedListeners.get(listener);
|
|
230
|
+
if (wrappedList && wrappedList.length > 0) {
|
|
231
|
+
const wrapped = wrappedList.pop();
|
|
232
|
+
if (wrappedList.length === 0) {
|
|
233
|
+
this.finishedListeners.delete(listener);
|
|
234
|
+
}
|
|
235
|
+
this.removeEventListener("finished", wrapped);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
addFinishedListenerOnceInternal(listener) {
|
|
239
|
+
const wrapped = () => {
|
|
240
|
+
this.untrackWrappedListener(this.finishedListeners, listener, wrapped);
|
|
241
|
+
listener.call(this);
|
|
242
|
+
};
|
|
243
|
+
this.trackListener(this.finishedListeners, listener, wrapped);
|
|
244
|
+
this.addEventListener("finished", wrapped, { once: true });
|
|
67
245
|
}
|
|
68
246
|
};
|
|
69
247
|
|
|
@@ -73,7 +251,7 @@ var DefaultExecutionEventBusManager = class {
|
|
|
73
251
|
/**
|
|
74
252
|
* Creates or retrieves an existing ExecutionEventBus based on the taskId.
|
|
75
253
|
* @param taskId The ID of the task.
|
|
76
|
-
* @returns An instance of
|
|
254
|
+
* @returns An instance of ExecutionEventBus.
|
|
77
255
|
*/
|
|
78
256
|
createOrGetByTaskId(taskId) {
|
|
79
257
|
if (!this.taskIdToBus.has(taskId)) {
|
|
@@ -84,7 +262,7 @@ var DefaultExecutionEventBusManager = class {
|
|
|
84
262
|
/**
|
|
85
263
|
* Retrieves an existing ExecutionEventBus based on the taskId.
|
|
86
264
|
* @param taskId The ID of the task.
|
|
87
|
-
* @returns An instance of
|
|
265
|
+
* @returns An instance of ExecutionEventBus or undefined if not found.
|
|
88
266
|
*/
|
|
89
267
|
getByTaskId(taskId) {
|
|
90
268
|
return this.taskIdToBus.get(taskId);
|
|
@@ -225,13 +403,15 @@ var A2AError = class _A2AError extends Error {
|
|
|
225
403
|
// src/server/result_manager.ts
|
|
226
404
|
var ResultManager = class {
|
|
227
405
|
taskStore;
|
|
406
|
+
serverCallContext;
|
|
228
407
|
currentTask;
|
|
229
408
|
latestUserMessage;
|
|
230
409
|
// To add to history if a new task is created
|
|
231
410
|
finalMessageResult;
|
|
232
411
|
// Stores the message if it's the final result
|
|
233
|
-
constructor(taskStore) {
|
|
412
|
+
constructor(taskStore, serverCallContext) {
|
|
234
413
|
this.taskStore = taskStore;
|
|
414
|
+
this.serverCallContext = serverCallContext;
|
|
235
415
|
}
|
|
236
416
|
setContext(latestUserMessage) {
|
|
237
417
|
this.latestUserMessage = latestUserMessage;
|
|
@@ -270,7 +450,7 @@ var ResultManager = class {
|
|
|
270
450
|
}
|
|
271
451
|
await this.saveCurrentTask();
|
|
272
452
|
} else if (!this.currentTask && updateEvent.taskId) {
|
|
273
|
-
const loaded = await this.taskStore.load(updateEvent.taskId);
|
|
453
|
+
const loaded = await this.taskStore.load(updateEvent.taskId, this.serverCallContext);
|
|
274
454
|
if (loaded) {
|
|
275
455
|
this.currentTask = loaded;
|
|
276
456
|
this.currentTask.status = updateEvent.status;
|
|
@@ -320,7 +500,7 @@ var ResultManager = class {
|
|
|
320
500
|
}
|
|
321
501
|
await this.saveCurrentTask();
|
|
322
502
|
} else if (!this.currentTask && artifactEvent.taskId) {
|
|
323
|
-
const loaded = await this.taskStore.load(artifactEvent.taskId);
|
|
503
|
+
const loaded = await this.taskStore.load(artifactEvent.taskId, this.serverCallContext);
|
|
324
504
|
if (loaded) {
|
|
325
505
|
this.currentTask = loaded;
|
|
326
506
|
if (!this.currentTask.artifacts) this.currentTask.artifacts = [];
|
|
@@ -349,7 +529,7 @@ var ResultManager = class {
|
|
|
349
529
|
}
|
|
350
530
|
async saveCurrentTask() {
|
|
351
531
|
if (this.currentTask) {
|
|
352
|
-
await this.taskStore.save(this.currentTask);
|
|
532
|
+
await this.taskStore.save(this.currentTask, this.serverCallContext);
|
|
353
533
|
}
|
|
354
534
|
}
|
|
355
535
|
/**
|
|
@@ -479,6 +659,41 @@ var DefaultPushNotificationSender = class {
|
|
|
479
659
|
}
|
|
480
660
|
};
|
|
481
661
|
|
|
662
|
+
// src/extensions.ts
|
|
663
|
+
var Extensions = {
|
|
664
|
+
/**
|
|
665
|
+
* Creates new {@link Extensions} from `current` and `additional`.
|
|
666
|
+
* If `current` already contains `additional` it is returned unmodified.
|
|
667
|
+
*/
|
|
668
|
+
createFrom: (current, additional) => {
|
|
669
|
+
if (current?.includes(additional)) {
|
|
670
|
+
return current;
|
|
671
|
+
}
|
|
672
|
+
return [...current ?? [], additional];
|
|
673
|
+
},
|
|
674
|
+
/**
|
|
675
|
+
* Creates {@link Extensions} from comma separated extensions identifiers as per
|
|
676
|
+
* https://a2a-protocol.org/latest/specification/#326-service-parameters.
|
|
677
|
+
* Parses the output of `toServiceParameter`.
|
|
678
|
+
*/
|
|
679
|
+
parseServiceParameter: (value) => {
|
|
680
|
+
if (!value) {
|
|
681
|
+
return [];
|
|
682
|
+
}
|
|
683
|
+
const unique = new Set(
|
|
684
|
+
value.split(",").map((ext) => ext.trim()).filter((ext) => ext.length > 0)
|
|
685
|
+
);
|
|
686
|
+
return Array.from(unique);
|
|
687
|
+
},
|
|
688
|
+
/**
|
|
689
|
+
* Converts {@link Extensions} to comma separated extensions identifiers as per
|
|
690
|
+
* https://a2a-protocol.org/latest/specification/#326-service-parameters.
|
|
691
|
+
*/
|
|
692
|
+
toServiceParameter: (value) => {
|
|
693
|
+
return value.join(",");
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
|
|
482
697
|
// src/server/context.ts
|
|
483
698
|
var ServerCallContext = class {
|
|
484
699
|
_requestedExtensions;
|
|
@@ -498,12 +713,7 @@ var ServerCallContext = class {
|
|
|
498
713
|
return this._requestedExtensions;
|
|
499
714
|
}
|
|
500
715
|
addActivatedExtension(uri) {
|
|
501
|
-
|
|
502
|
-
if (!this._activatedExtensions) {
|
|
503
|
-
this._activatedExtensions = /* @__PURE__ */ new Set();
|
|
504
|
-
}
|
|
505
|
-
this._activatedExtensions.add(uri);
|
|
506
|
-
}
|
|
716
|
+
this._activatedExtensions = Extensions.createFrom(this._activatedExtensions, uri);
|
|
507
717
|
}
|
|
508
718
|
};
|
|
509
719
|
|
|
@@ -550,7 +760,7 @@ var DefaultRequestHandler = class {
|
|
|
550
760
|
let task;
|
|
551
761
|
let referenceTasks;
|
|
552
762
|
if (incomingMessage.taskId) {
|
|
553
|
-
task = await this.taskStore.load(incomingMessage.taskId);
|
|
763
|
+
task = await this.taskStore.load(incomingMessage.taskId, context);
|
|
554
764
|
if (!task) {
|
|
555
765
|
throw A2AError.taskNotFound(incomingMessage.taskId);
|
|
556
766
|
}
|
|
@@ -560,13 +770,13 @@ var DefaultRequestHandler = class {
|
|
|
560
770
|
);
|
|
561
771
|
}
|
|
562
772
|
task.history = [...task.history || [], incomingMessage];
|
|
563
|
-
await this.taskStore.save(task);
|
|
773
|
+
await this.taskStore.save(task, context);
|
|
564
774
|
}
|
|
565
775
|
const taskId = incomingMessage.taskId || (0, import_uuid.v4)();
|
|
566
776
|
if (incomingMessage.referenceTaskIds && incomingMessage.referenceTaskIds.length > 0) {
|
|
567
777
|
referenceTasks = [];
|
|
568
778
|
for (const refId of incomingMessage.referenceTaskIds) {
|
|
569
|
-
const refTask = await this.taskStore.load(refId);
|
|
779
|
+
const refTask = await this.taskStore.load(refId, context);
|
|
570
780
|
if (refTask) {
|
|
571
781
|
referenceTasks.push(refTask);
|
|
572
782
|
} else {
|
|
@@ -580,10 +790,8 @@ var DefaultRequestHandler = class {
|
|
|
580
790
|
const exposedExtensions = new Set(
|
|
581
791
|
agentCard.capabilities.extensions?.map((ext) => ext.uri) || []
|
|
582
792
|
);
|
|
583
|
-
const validExtensions =
|
|
584
|
-
|
|
585
|
-
(extension) => exposedExtensions.has(extension)
|
|
586
|
-
)
|
|
793
|
+
const validExtensions = context.requestedExtensions.filter(
|
|
794
|
+
(extension) => exposedExtensions.has(extension)
|
|
587
795
|
);
|
|
588
796
|
context = new ServerCallContext(validExtensions, context.user);
|
|
589
797
|
}
|
|
@@ -594,13 +802,13 @@ var DefaultRequestHandler = class {
|
|
|
594
802
|
};
|
|
595
803
|
return new RequestContext(messageForContext, taskId, contextId, task, referenceTasks, context);
|
|
596
804
|
}
|
|
597
|
-
async _processEvents(taskId, resultManager, eventQueue, options) {
|
|
805
|
+
async _processEvents(taskId, resultManager, eventQueue, context, options) {
|
|
598
806
|
let firstResultSent = false;
|
|
599
807
|
try {
|
|
600
808
|
for await (const event of eventQueue.events()) {
|
|
601
809
|
await resultManager.processEvent(event);
|
|
602
810
|
try {
|
|
603
|
-
await this._sendPushNotificationIfNeeded(event);
|
|
811
|
+
await this._sendPushNotificationIfNeeded(event, context);
|
|
604
812
|
} catch (error) {
|
|
605
813
|
console.error(`Error sending push notification: ${error}`);
|
|
606
814
|
}
|
|
@@ -641,7 +849,7 @@ var DefaultRequestHandler = class {
|
|
|
641
849
|
throw A2AError.invalidParams("message.messageId is required.");
|
|
642
850
|
}
|
|
643
851
|
const isBlocking = params.configuration?.blocking !== false;
|
|
644
|
-
const resultManager = new ResultManager(this.taskStore);
|
|
852
|
+
const resultManager = new ResultManager(this.taskStore, context);
|
|
645
853
|
resultManager.setContext(incomingMessage);
|
|
646
854
|
const requestContext = await this._createRequestContext(incomingMessage, context);
|
|
647
855
|
const taskId = requestContext.taskId;
|
|
@@ -689,7 +897,7 @@ var DefaultRequestHandler = class {
|
|
|
689
897
|
eventBus.finished();
|
|
690
898
|
});
|
|
691
899
|
if (isBlocking) {
|
|
692
|
-
await this._processEvents(taskId, resultManager, eventQueue);
|
|
900
|
+
await this._processEvents(taskId, resultManager, eventQueue, context);
|
|
693
901
|
const finalResult = resultManager.getFinalResult();
|
|
694
902
|
if (!finalResult) {
|
|
695
903
|
throw A2AError.internalError(
|
|
@@ -699,7 +907,7 @@ var DefaultRequestHandler = class {
|
|
|
699
907
|
return finalResult;
|
|
700
908
|
} else {
|
|
701
909
|
return new Promise((resolve, reject) => {
|
|
702
|
-
this._processEvents(taskId, resultManager, eventQueue, {
|
|
910
|
+
this._processEvents(taskId, resultManager, eventQueue, context, {
|
|
703
911
|
firstResultResolver: resolve,
|
|
704
912
|
firstResultRejector: reject
|
|
705
913
|
});
|
|
@@ -711,7 +919,7 @@ var DefaultRequestHandler = class {
|
|
|
711
919
|
if (!incomingMessage.messageId) {
|
|
712
920
|
throw A2AError.invalidParams("message.messageId is required for streaming.");
|
|
713
921
|
}
|
|
714
|
-
const resultManager = new ResultManager(this.taskStore);
|
|
922
|
+
const resultManager = new ResultManager(this.taskStore, context);
|
|
715
923
|
resultManager.setContext(incomingMessage);
|
|
716
924
|
const requestContext = await this._createRequestContext(incomingMessage, context);
|
|
717
925
|
const taskId = requestContext.taskId;
|
|
@@ -751,15 +959,15 @@ var DefaultRequestHandler = class {
|
|
|
751
959
|
try {
|
|
752
960
|
for await (const event of eventQueue.events()) {
|
|
753
961
|
await resultManager.processEvent(event);
|
|
754
|
-
await this._sendPushNotificationIfNeeded(event);
|
|
962
|
+
await this._sendPushNotificationIfNeeded(event, context);
|
|
755
963
|
yield event;
|
|
756
964
|
}
|
|
757
965
|
} finally {
|
|
758
966
|
this.eventBusManager.cleanupByTaskId(taskId);
|
|
759
967
|
}
|
|
760
968
|
}
|
|
761
|
-
async getTask(params,
|
|
762
|
-
const task = await this.taskStore.load(params.id);
|
|
969
|
+
async getTask(params, context) {
|
|
970
|
+
const task = await this.taskStore.load(params.id, context);
|
|
763
971
|
if (!task) {
|
|
764
972
|
throw A2AError.taskNotFound(params.id);
|
|
765
973
|
}
|
|
@@ -772,8 +980,8 @@ var DefaultRequestHandler = class {
|
|
|
772
980
|
}
|
|
773
981
|
return task;
|
|
774
982
|
}
|
|
775
|
-
async cancelTask(params,
|
|
776
|
-
const task = await this.taskStore.load(params.id);
|
|
983
|
+
async cancelTask(params, context) {
|
|
984
|
+
const task = await this.taskStore.load(params.id, context);
|
|
777
985
|
if (!task) {
|
|
778
986
|
throw A2AError.taskNotFound(params.id);
|
|
779
987
|
}
|
|
@@ -785,7 +993,12 @@ var DefaultRequestHandler = class {
|
|
|
785
993
|
if (eventBus) {
|
|
786
994
|
const eventQueue = new ExecutionEventQueue(eventBus);
|
|
787
995
|
await this.agentExecutor.cancelTask(params.id, eventBus);
|
|
788
|
-
await this._processEvents(
|
|
996
|
+
await this._processEvents(
|
|
997
|
+
params.id,
|
|
998
|
+
new ResultManager(this.taskStore, context),
|
|
999
|
+
eventQueue,
|
|
1000
|
+
context
|
|
1001
|
+
);
|
|
789
1002
|
} else {
|
|
790
1003
|
task.status = {
|
|
791
1004
|
state: "canceled",
|
|
@@ -801,9 +1014,9 @@ var DefaultRequestHandler = class {
|
|
|
801
1014
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
802
1015
|
};
|
|
803
1016
|
task.history = [...task.history || [], task.status.message];
|
|
804
|
-
await this.taskStore.save(task);
|
|
1017
|
+
await this.taskStore.save(task, context);
|
|
805
1018
|
}
|
|
806
|
-
const latestTask = await this.taskStore.load(params.id);
|
|
1019
|
+
const latestTask = await this.taskStore.load(params.id, context);
|
|
807
1020
|
if (!latestTask) {
|
|
808
1021
|
throw A2AError.internalError(`Task ${params.id} not found after cancellation.`);
|
|
809
1022
|
}
|
|
@@ -812,11 +1025,11 @@ var DefaultRequestHandler = class {
|
|
|
812
1025
|
}
|
|
813
1026
|
return latestTask;
|
|
814
1027
|
}
|
|
815
|
-
async setTaskPushNotificationConfig(params,
|
|
1028
|
+
async setTaskPushNotificationConfig(params, context) {
|
|
816
1029
|
if (!this.agentCard.capabilities.pushNotifications) {
|
|
817
1030
|
throw A2AError.pushNotificationNotSupported();
|
|
818
1031
|
}
|
|
819
|
-
const task = await this.taskStore.load(params.taskId);
|
|
1032
|
+
const task = await this.taskStore.load(params.taskId, context);
|
|
820
1033
|
if (!task) {
|
|
821
1034
|
throw A2AError.taskNotFound(params.taskId);
|
|
822
1035
|
}
|
|
@@ -827,11 +1040,11 @@ var DefaultRequestHandler = class {
|
|
|
827
1040
|
await this.pushNotificationStore?.save(taskId, pushNotificationConfig);
|
|
828
1041
|
return params;
|
|
829
1042
|
}
|
|
830
|
-
async getTaskPushNotificationConfig(params,
|
|
1043
|
+
async getTaskPushNotificationConfig(params, context) {
|
|
831
1044
|
if (!this.agentCard.capabilities.pushNotifications) {
|
|
832
1045
|
throw A2AError.pushNotificationNotSupported();
|
|
833
1046
|
}
|
|
834
|
-
const task = await this.taskStore.load(params.id);
|
|
1047
|
+
const task = await this.taskStore.load(params.id, context);
|
|
835
1048
|
if (!task) {
|
|
836
1049
|
throw A2AError.taskNotFound(params.id);
|
|
837
1050
|
}
|
|
@@ -853,11 +1066,11 @@ var DefaultRequestHandler = class {
|
|
|
853
1066
|
}
|
|
854
1067
|
return { taskId: params.id, pushNotificationConfig: config };
|
|
855
1068
|
}
|
|
856
|
-
async listTaskPushNotificationConfigs(params,
|
|
1069
|
+
async listTaskPushNotificationConfigs(params, context) {
|
|
857
1070
|
if (!this.agentCard.capabilities.pushNotifications) {
|
|
858
1071
|
throw A2AError.pushNotificationNotSupported();
|
|
859
1072
|
}
|
|
860
|
-
const task = await this.taskStore.load(params.id);
|
|
1073
|
+
const task = await this.taskStore.load(params.id, context);
|
|
861
1074
|
if (!task) {
|
|
862
1075
|
throw A2AError.taskNotFound(params.id);
|
|
863
1076
|
}
|
|
@@ -867,22 +1080,22 @@ var DefaultRequestHandler = class {
|
|
|
867
1080
|
pushNotificationConfig: config
|
|
868
1081
|
}));
|
|
869
1082
|
}
|
|
870
|
-
async deleteTaskPushNotificationConfig(params,
|
|
1083
|
+
async deleteTaskPushNotificationConfig(params, context) {
|
|
871
1084
|
if (!this.agentCard.capabilities.pushNotifications) {
|
|
872
1085
|
throw A2AError.pushNotificationNotSupported();
|
|
873
1086
|
}
|
|
874
|
-
const task = await this.taskStore.load(params.id);
|
|
1087
|
+
const task = await this.taskStore.load(params.id, context);
|
|
875
1088
|
if (!task) {
|
|
876
1089
|
throw A2AError.taskNotFound(params.id);
|
|
877
1090
|
}
|
|
878
1091
|
const { id: taskId, pushNotificationConfigId } = params;
|
|
879
1092
|
await this.pushNotificationStore?.delete(taskId, pushNotificationConfigId);
|
|
880
1093
|
}
|
|
881
|
-
async *resubscribe(params,
|
|
1094
|
+
async *resubscribe(params, context) {
|
|
882
1095
|
if (!this.agentCard.capabilities.streaming) {
|
|
883
1096
|
throw A2AError.unsupportedOperation("Streaming (and thus resubscription) is not supported.");
|
|
884
1097
|
}
|
|
885
|
-
const task = await this.taskStore.load(params.id);
|
|
1098
|
+
const task = await this.taskStore.load(params.id, context);
|
|
886
1099
|
if (!task) {
|
|
887
1100
|
throw A2AError.taskNotFound(params.id);
|
|
888
1101
|
}
|
|
@@ -911,7 +1124,7 @@ var DefaultRequestHandler = class {
|
|
|
911
1124
|
eventQueue.stop();
|
|
912
1125
|
}
|
|
913
1126
|
}
|
|
914
|
-
async _sendPushNotificationIfNeeded(event) {
|
|
1127
|
+
async _sendPushNotificationIfNeeded(event, context) {
|
|
915
1128
|
if (!this.agentCard.capabilities.pushNotifications) {
|
|
916
1129
|
return;
|
|
917
1130
|
}
|
|
@@ -926,7 +1139,7 @@ var DefaultRequestHandler = class {
|
|
|
926
1139
|
console.error(`Task ID not found for event ${event.kind}.`);
|
|
927
1140
|
return;
|
|
928
1141
|
}
|
|
929
|
-
const task = await this.taskStore.load(taskId);
|
|
1142
|
+
const task = await this.taskStore.load(taskId, context);
|
|
930
1143
|
if (!task) {
|
|
931
1144
|
console.error(`Task ${taskId} not found.`);
|
|
932
1145
|
return;
|
|
@@ -987,7 +1200,7 @@ var InMemoryTaskStore = class {
|
|
|
987
1200
|
}
|
|
988
1201
|
};
|
|
989
1202
|
|
|
990
|
-
// src/server/transports/jsonrpc_transport_handler.ts
|
|
1203
|
+
// src/server/transports/jsonrpc/jsonrpc_transport_handler.ts
|
|
991
1204
|
var JsonRpcTransportHandler = class {
|
|
992
1205
|
requestHandler;
|
|
993
1206
|
constructor(requestHandler) {
|