@multi-agent-protocol/sdk 0.1.7 → 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.
@@ -5864,6 +5864,32 @@ declare class AgentConnection {
5864
5864
  * Remove a message handler
5865
5865
  */
5866
5866
  offMessage(handler: MessageHandler): this;
5867
+ /**
5868
+ * Register a handler for a specific notification method.
5869
+ *
5870
+ * Handles server-to-agent notifications that aren't standard MAP methods
5871
+ * (e.g., `trajectory/content.request`). When the server sends a JSON-RPC
5872
+ * notification with the specified method, the handler fires with the params.
5873
+ *
5874
+ * @param method - The JSON-RPC notification method name to handle
5875
+ * @param handler - Async function called with the notification params
5876
+ */
5877
+ onNotification(method: string, handler: (params: unknown) => Promise<void> | void): this;
5878
+ /**
5879
+ * Remove a notification handler for a specific method.
5880
+ */
5881
+ offNotification(method: string, handler: (params: unknown) => Promise<void> | void): this;
5882
+ /**
5883
+ * Send a raw JSON-RPC notification to the server.
5884
+ *
5885
+ * Used for custom protocol notifications (e.g., `trajectory/content.response`)
5886
+ * that aren't standard MAP methods. The notification is sent directly on the
5887
+ * underlying connection without any MAP-level wrapping.
5888
+ *
5889
+ * @param method - The JSON-RPC notification method name
5890
+ * @param params - The notification parameters
5891
+ */
5892
+ sendNotification(method: string, params: unknown): Promise<void>;
5867
5893
  /**
5868
5894
  * Update this agent's state
5869
5895
  */
@@ -5864,6 +5864,32 @@ declare class AgentConnection {
5864
5864
  * Remove a message handler
5865
5865
  */
5866
5866
  offMessage(handler: MessageHandler): this;
5867
+ /**
5868
+ * Register a handler for a specific notification method.
5869
+ *
5870
+ * Handles server-to-agent notifications that aren't standard MAP methods
5871
+ * (e.g., `trajectory/content.request`). When the server sends a JSON-RPC
5872
+ * notification with the specified method, the handler fires with the params.
5873
+ *
5874
+ * @param method - The JSON-RPC notification method name to handle
5875
+ * @param handler - Async function called with the notification params
5876
+ */
5877
+ onNotification(method: string, handler: (params: unknown) => Promise<void> | void): this;
5878
+ /**
5879
+ * Remove a notification handler for a specific method.
5880
+ */
5881
+ offNotification(method: string, handler: (params: unknown) => Promise<void> | void): this;
5882
+ /**
5883
+ * Send a raw JSON-RPC notification to the server.
5884
+ *
5885
+ * Used for custom protocol notifications (e.g., `trajectory/content.response`)
5886
+ * that aren't standard MAP methods. The notification is sent directly on the
5887
+ * underlying connection without any MAP-level wrapping.
5888
+ *
5889
+ * @param method - The JSON-RPC notification method name
5890
+ * @param params - The notification parameters
5891
+ */
5892
+ sendNotification(method: string, params: unknown): Promise<void>;
5867
5893
  /**
5868
5894
  * Update this agent's state
5869
5895
  */
package/dist/index.cjs CHANGED
@@ -3864,6 +3864,7 @@ var AgentConnection = class _AgentConnection {
3864
3864
  #options;
3865
3865
  #messageHandlers = /* @__PURE__ */ new Set();
3866
3866
  #reconnectionHandlers = /* @__PURE__ */ new Set();
3867
+ #notificationHandlers = /* @__PURE__ */ new Map();
3867
3868
  #scopeMemberships = /* @__PURE__ */ new Set();
3868
3869
  #agentId = null;
3869
3870
  #sessionId = null;
@@ -4284,6 +4285,47 @@ var AgentConnection = class _AgentConnection {
4284
4285
  this.#messageHandlers.delete(handler);
4285
4286
  return this;
4286
4287
  }
4288
+ /**
4289
+ * Register a handler for a specific notification method.
4290
+ *
4291
+ * Handles server-to-agent notifications that aren't standard MAP methods
4292
+ * (e.g., `trajectory/content.request`). When the server sends a JSON-RPC
4293
+ * notification with the specified method, the handler fires with the params.
4294
+ *
4295
+ * @param method - The JSON-RPC notification method name to handle
4296
+ * @param handler - Async function called with the notification params
4297
+ */
4298
+ onNotification(method, handler) {
4299
+ if (!this.#notificationHandlers.has(method)) {
4300
+ this.#notificationHandlers.set(method, /* @__PURE__ */ new Set());
4301
+ }
4302
+ this.#notificationHandlers.get(method).add(handler);
4303
+ return this;
4304
+ }
4305
+ /**
4306
+ * Remove a notification handler for a specific method.
4307
+ */
4308
+ offNotification(method, handler) {
4309
+ const handlers = this.#notificationHandlers.get(method);
4310
+ if (handlers) {
4311
+ handlers.delete(handler);
4312
+ if (handlers.size === 0) this.#notificationHandlers.delete(method);
4313
+ }
4314
+ return this;
4315
+ }
4316
+ /**
4317
+ * Send a raw JSON-RPC notification to the server.
4318
+ *
4319
+ * Used for custom protocol notifications (e.g., `trajectory/content.response`)
4320
+ * that aren't standard MAP methods. The notification is sent directly on the
4321
+ * underlying connection without any MAP-level wrapping.
4322
+ *
4323
+ * @param method - The JSON-RPC notification method name
4324
+ * @param params - The notification parameters
4325
+ */
4326
+ async sendNotification(method, params) {
4327
+ return this.#connection.sendNotification(method, params);
4328
+ }
4287
4329
  // ===========================================================================
4288
4330
  // State Management
4289
4331
  // ===========================================================================
@@ -4748,8 +4790,19 @@ var AgentConnection = class _AgentConnection {
4748
4790
  }
4749
4791
  break;
4750
4792
  }
4751
- default:
4752
- console.warn("MAP: Unknown notification:", method);
4793
+ default: {
4794
+ const handlers = this.#notificationHandlers.get(method);
4795
+ if (handlers?.size) {
4796
+ for (const handler of handlers) {
4797
+ try {
4798
+ await handler(params);
4799
+ } catch (error) {
4800
+ console.error("MAP: Notification handler error:", error);
4801
+ }
4802
+ }
4803
+ }
4804
+ break;
4805
+ }
4753
4806
  }
4754
4807
  }
4755
4808
  /**