@multi-agent-protocol/sdk 0.1.6 → 0.1.8

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/testing.cjs CHANGED
@@ -4817,6 +4817,7 @@ var AgentConnection = class _AgentConnection {
4817
4817
  #options;
4818
4818
  #messageHandlers = /* @__PURE__ */ new Set();
4819
4819
  #reconnectionHandlers = /* @__PURE__ */ new Set();
4820
+ #notificationHandlers = /* @__PURE__ */ new Map();
4820
4821
  #scopeMemberships = /* @__PURE__ */ new Set();
4821
4822
  #agentId = null;
4822
4823
  #sessionId = null;
@@ -5237,6 +5238,47 @@ var AgentConnection = class _AgentConnection {
5237
5238
  this.#messageHandlers.delete(handler);
5238
5239
  return this;
5239
5240
  }
5241
+ /**
5242
+ * Register a handler for a specific notification method.
5243
+ *
5244
+ * Handles server-to-agent notifications that aren't standard MAP methods
5245
+ * (e.g., `trajectory/content.request`). When the server sends a JSON-RPC
5246
+ * notification with the specified method, the handler fires with the params.
5247
+ *
5248
+ * @param method - The JSON-RPC notification method name to handle
5249
+ * @param handler - Async function called with the notification params
5250
+ */
5251
+ onNotification(method, handler) {
5252
+ if (!this.#notificationHandlers.has(method)) {
5253
+ this.#notificationHandlers.set(method, /* @__PURE__ */ new Set());
5254
+ }
5255
+ this.#notificationHandlers.get(method).add(handler);
5256
+ return this;
5257
+ }
5258
+ /**
5259
+ * Remove a notification handler for a specific method.
5260
+ */
5261
+ offNotification(method, handler) {
5262
+ const handlers = this.#notificationHandlers.get(method);
5263
+ if (handlers) {
5264
+ handlers.delete(handler);
5265
+ if (handlers.size === 0) this.#notificationHandlers.delete(method);
5266
+ }
5267
+ return this;
5268
+ }
5269
+ /**
5270
+ * Send a raw JSON-RPC notification to the server.
5271
+ *
5272
+ * Used for custom protocol notifications (e.g., `trajectory/content.response`)
5273
+ * that aren't standard MAP methods. The notification is sent directly on the
5274
+ * underlying connection without any MAP-level wrapping.
5275
+ *
5276
+ * @param method - The JSON-RPC notification method name
5277
+ * @param params - The notification parameters
5278
+ */
5279
+ async sendNotification(method, params) {
5280
+ return this.#connection.sendNotification(method, params);
5281
+ }
5240
5282
  // ===========================================================================
5241
5283
  // State Management
5242
5284
  // ===========================================================================
@@ -5701,8 +5743,19 @@ var AgentConnection = class _AgentConnection {
5701
5743
  }
5702
5744
  break;
5703
5745
  }
5704
- default:
5705
- console.warn("MAP: Unknown notification:", method);
5746
+ default: {
5747
+ const handlers = this.#notificationHandlers.get(method);
5748
+ if (handlers?.size) {
5749
+ for (const handler of handlers) {
5750
+ try {
5751
+ await handler(params);
5752
+ } catch (error) {
5753
+ console.error("MAP: Notification handler error:", error);
5754
+ }
5755
+ }
5756
+ }
5757
+ break;
5758
+ }
5706
5759
  }
5707
5760
  }
5708
5761
  /**