Pass requestId to handlers via metadata

This commit is contained in:
Luca Forstner 2025-04-17 11:41:11 +02:00
commit ec23b71f4e
No known key found for this signature in database

View file

@ -115,6 +115,12 @@ export type RequestHandlerExtra<SendRequestT extends Request,
*/
sessionId?: string;
/**
* The JSON-RPC ID of the request being handled.
* This can be useful for tracking or logging purposes.
*/
requestId: RequestId;
/**
* Sends a notification that relates to the current request being handled.
*
@ -361,6 +367,7 @@ export abstract class Protocol<
sendRequest: (r, resultSchema, options?) =>
this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
authInfo: extra?.authInfo,
requestId: request.id,
};
// Starting with Promise.resolve() puts any synchronous errors into the monad as well.