Refactor notification handling to include all notifications
This commit is contained in:
@@ -8,9 +8,6 @@ import {
|
|||||||
ClientRequest,
|
ClientRequest,
|
||||||
CreateMessageRequestSchema,
|
CreateMessageRequestSchema,
|
||||||
ListRootsRequestSchema,
|
ListRootsRequestSchema,
|
||||||
ProgressNotificationSchema,
|
|
||||||
ResourceUpdatedNotificationSchema,
|
|
||||||
LoggingMessageNotificationSchema,
|
|
||||||
Request,
|
Request,
|
||||||
Result,
|
Result,
|
||||||
ServerCapabilities,
|
ServerCapabilities,
|
||||||
@@ -250,20 +247,12 @@ export function useConnection({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (onNotification) {
|
if (onNotification) {
|
||||||
client.setNotificationHandler(
|
client.fallbackNotificationHandler = (
|
||||||
ProgressNotificationSchema,
|
notification: Notification,
|
||||||
onNotification,
|
): Promise<void> => {
|
||||||
);
|
onNotification(notification);
|
||||||
|
return Promise.resolve();
|
||||||
client.setNotificationHandler(
|
};
|
||||||
ResourceUpdatedNotificationSchema,
|
|
||||||
onNotification,
|
|
||||||
);
|
|
||||||
|
|
||||||
client.setNotificationHandler(
|
|
||||||
LoggingMessageNotificationSchema,
|
|
||||||
onNotification,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onStdErrNotification) {
|
if (onStdErrNotification) {
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ export const StdErrNotificationSchema = BaseNotificationSchema.extend({
|
|||||||
|
|
||||||
export const NotificationSchema = ClientNotificationSchema.or(
|
export const NotificationSchema = ClientNotificationSchema.or(
|
||||||
StdErrNotificationSchema,
|
StdErrNotificationSchema,
|
||||||
).or(ServerNotificationSchema);
|
)
|
||||||
|
.or(ServerNotificationSchema)
|
||||||
|
.or(BaseNotificationSchema);
|
||||||
|
|
||||||
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
|
export type StdErrNotification = z.infer<typeof StdErrNotificationSchema>;
|
||||||
export type Notification = z.infer<typeof NotificationSchema>;
|
export type Notification = z.infer<typeof NotificationSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user