@multi-agent-protocol/sdk 0.1.7 → 0.1.9

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/dist/server.cjs CHANGED
@@ -9104,6 +9104,7 @@ var RouterConnectionImpl = class {
9104
9104
  _started = false;
9105
9105
  _running = false;
9106
9106
  _isClosed = false;
9107
+ _notificationHandler = null;
9107
9108
  constructor(options) {
9108
9109
  this.stream = options.stream;
9109
9110
  this.handlers = options.handlers;
@@ -9188,6 +9189,15 @@ var RouterConnectionImpl = class {
9188
9189
  }
9189
9190
  this._closedResolve();
9190
9191
  }
9192
+ /**
9193
+ * Register a handler for incoming notifications from the client.
9194
+ * By default, notifications are silently ignored. Setting a handler
9195
+ * allows the server to process custom notifications (e.g., opentasks
9196
+ * responses, trajectory content responses).
9197
+ */
9198
+ onNotification(handler) {
9199
+ this._notificationHandler = handler;
9200
+ }
9191
9201
  /**
9192
9202
  * Send a notification to the connected peer.
9193
9203
  */
@@ -9230,8 +9240,22 @@ var RouterConnectionImpl = class {
9230
9240
  async handleMessage(message2) {
9231
9241
  if (this.isRequest(message2)) {
9232
9242
  await this.handleRequest(message2);
9243
+ } else if (this.isNotification(message2)) {
9244
+ if (this._notificationHandler) {
9245
+ try {
9246
+ const msg = message2;
9247
+ this._notificationHandler(msg.method, msg.params);
9248
+ } catch {
9249
+ }
9250
+ }
9233
9251
  }
9234
9252
  }
9253
+ /**
9254
+ * Check if a message is a notification (method but no id).
9255
+ */
9256
+ isNotification(message2) {
9257
+ return typeof message2 === "object" && message2 !== null && "jsonrpc" in message2 && message2.jsonrpc === "2.0" && "method" in message2 && !("id" in message2);
9258
+ }
9235
9259
  /**
9236
9260
  * Check if a message is a request.
9237
9261
  */