Skip to content

Commit 44c9bff

Browse files
author
Jason Victor
committed
added session id to request handler extra data
1 parent 80e1484 commit 44c9bff

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/server/sse.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ export class SSEServerTransport implements Transport {
136136

137137
/**
138138
* Returns the session ID for this transport.
139-
*
140-
* This can be used to route incoming POST requests.
141139
*/
142140
get sessionId(): string {
143141
return this._sessionId;

src/shared/protocol.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export type RequestHandlerExtra = {
7474
* An abort signal used to communicate if the request was cancelled from the sender's side.
7575
*/
7676
signal: AbortSignal;
77+
78+
/**
79+
* The session ID from the transport, if available.
80+
*/
81+
sessionId?: string;
7782
};
7883

7984
/**
@@ -239,9 +244,15 @@ export abstract class Protocol<
239244
const abortController = new AbortController();
240245
this._requestHandlerAbortControllers.set(request.id, abortController);
241246

247+
// Create extra object with both abort signal and sessionId from transport
248+
const extra: RequestHandlerExtra = {
249+
signal: abortController.signal,
250+
sessionId: this._transport?.sessionId,
251+
};
252+
242253
// Starting with Promise.resolve() puts any synchronous errors into the monad as well.
243254
Promise.resolve()
244-
.then(() => handler(request, { signal: abortController.signal }))
255+
.then(() => handler(request, extra))
245256
.then(
246257
(result) => {
247258
if (abortController.signal.aborted) {

src/shared/transport.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ export interface Transport {
4141
* Callback for when a message (request or response) is received over the connection.
4242
*/
4343
onmessage?: (message: JSONRPCMessage) => void;
44+
45+
sessionId?: string;
4446
}

0 commit comments

Comments
 (0)