@multi-agent-protocol/sdk 0.1.4 → 0.1.5

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
@@ -231,6 +231,7 @@ var TASK_METHODS = {
231
231
  var NOTIFICATION_METHODS = {
232
232
  EVENT: "map/event",
233
233
  MESSAGE: "map/message",
234
+ SEND: "map/send",
234
235
  /** Client acknowledges received events (for backpressure) */
235
236
  SUBSCRIBE_ACK: "map/subscribe.ack"};
236
237
  var PROTOCOL_ERROR_CODES = {
@@ -4482,7 +4483,8 @@ var ClientConnection = class _ClientConnection {
4482
4483
  }
4483
4484
  break;
4484
4485
  }
4485
- case NOTIFICATION_METHODS.MESSAGE: {
4486
+ case NOTIFICATION_METHODS.MESSAGE:
4487
+ case "map/send": {
4486
4488
  break;
4487
4489
  }
4488
4490
  default:
@@ -4826,7 +4828,9 @@ var AgentConnection = class _AgentConnection {
4826
4828
  constructor(stream, options = {}) {
4827
4829
  this.#connection = new BaseConnection(stream, options);
4828
4830
  this.#options = options;
4829
- this.#connection.setNotificationHandler(this.#handleNotification.bind(this));
4831
+ this.#connection.setNotificationHandler(
4832
+ this.#handleNotification.bind(this)
4833
+ );
4830
4834
  if (options.reconnection?.enabled && options.createStream) {
4831
4835
  this.#connection.onStateChange((newState) => {
4832
4836
  if (newState === "closed" && this.#connected && !this.#isReconnecting) {
@@ -5062,10 +5066,7 @@ var AgentConnection = class _AgentConnection {
5062
5066
  reason
5063
5067
  });
5064
5068
  }
5065
- const result = await this.#connection.sendRequest(
5066
- CORE_METHODS.DISCONNECT,
5067
- reason ? { reason } : void 0
5068
- );
5069
+ const result = await this.#connection.sendRequest(CORE_METHODS.DISCONNECT, reason ? { reason } : void 0);
5069
5070
  resumeToken = result.resumeToken;
5070
5071
  } finally {
5071
5072
  for (const subscription of this.#subscriptions.values()) {
@@ -5381,10 +5382,7 @@ var AgentConnection = class _AgentConnection {
5381
5382
  * @returns Created conversation and participant info
5382
5383
  */
5383
5384
  async createConversation(params) {
5384
- return this.#connection.sendRequest(
5385
- MAIL_METHODS.MAIL_CREATE,
5386
- params ?? {}
5387
- );
5385
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_CREATE, params ?? {});
5388
5386
  }
5389
5387
  /**
5390
5388
  * Get a conversation by ID with optional includes.
@@ -5394,10 +5392,7 @@ var AgentConnection = class _AgentConnection {
5394
5392
  * @returns Conversation details with requested includes
5395
5393
  */
5396
5394
  async getConversation(conversationId, include) {
5397
- return this.#connection.sendRequest(
5398
- MAIL_METHODS.MAIL_GET,
5399
- { conversationId, include }
5400
- );
5395
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_GET, { conversationId, include });
5401
5396
  }
5402
5397
  /**
5403
5398
  * List conversations with optional filters.
@@ -5406,10 +5401,7 @@ var AgentConnection = class _AgentConnection {
5406
5401
  * @returns Paginated list of conversations
5407
5402
  */
5408
5403
  async listConversations(params) {
5409
- return this.#connection.sendRequest(
5410
- MAIL_METHODS.MAIL_LIST,
5411
- params ?? {}
5412
- );
5404
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_LIST, params ?? {});
5413
5405
  }
5414
5406
  /**
5415
5407
  * Close a conversation.
@@ -5419,10 +5411,7 @@ var AgentConnection = class _AgentConnection {
5419
5411
  * @returns The closed conversation
5420
5412
  */
5421
5413
  async closeConversation(conversationId, reason) {
5422
- return this.#connection.sendRequest(
5423
- MAIL_METHODS.MAIL_CLOSE,
5424
- { conversationId, reason }
5425
- );
5414
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_CLOSE, { conversationId, reason });
5426
5415
  }
5427
5416
  /**
5428
5417
  * Join an existing conversation.
@@ -5431,10 +5420,7 @@ var AgentConnection = class _AgentConnection {
5431
5420
  * @returns Conversation, participant, and optional history
5432
5421
  */
5433
5422
  async joinConversation(params) {
5434
- return this.#connection.sendRequest(
5435
- MAIL_METHODS.MAIL_JOIN,
5436
- params
5437
- );
5423
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_JOIN, params);
5438
5424
  }
5439
5425
  /**
5440
5426
  * Leave a conversation.
@@ -5444,10 +5430,7 @@ var AgentConnection = class _AgentConnection {
5444
5430
  * @returns Leave confirmation with timestamp
5445
5431
  */
5446
5432
  async leaveConversation(conversationId, reason) {
5447
- return this.#connection.sendRequest(
5448
- MAIL_METHODS.MAIL_LEAVE,
5449
- { conversationId, reason }
5450
- );
5433
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_LEAVE, { conversationId, reason });
5451
5434
  }
5452
5435
  /**
5453
5436
  * Invite a participant to a conversation.
@@ -5456,10 +5439,7 @@ var AgentConnection = class _AgentConnection {
5456
5439
  * @returns Invite result
5457
5440
  */
5458
5441
  async inviteToConversation(params) {
5459
- return this.#connection.sendRequest(
5460
- MAIL_METHODS.MAIL_INVITE,
5461
- params
5462
- );
5442
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_INVITE, params);
5463
5443
  }
5464
5444
  /**
5465
5445
  * Record a turn (message) in a conversation.
@@ -5468,10 +5448,7 @@ var AgentConnection = class _AgentConnection {
5468
5448
  * @returns The created turn
5469
5449
  */
5470
5450
  async recordTurn(params) {
5471
- return this.#connection.sendRequest(
5472
- MAIL_METHODS.MAIL_TURN,
5473
- params
5474
- );
5451
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_TURN, params);
5475
5452
  }
5476
5453
  /**
5477
5454
  * List turns in a conversation with optional filters.
@@ -5480,10 +5457,7 @@ var AgentConnection = class _AgentConnection {
5480
5457
  * @returns Paginated list of turns
5481
5458
  */
5482
5459
  async listTurns(params) {
5483
- return this.#connection.sendRequest(
5484
- MAIL_METHODS.MAIL_TURNS_LIST,
5485
- params
5486
- );
5460
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_TURNS_LIST, params);
5487
5461
  }
5488
5462
  /**
5489
5463
  * Create a thread in a conversation.
@@ -5492,10 +5466,7 @@ var AgentConnection = class _AgentConnection {
5492
5466
  * @returns The created thread
5493
5467
  */
5494
5468
  async createThread(params) {
5495
- return this.#connection.sendRequest(
5496
- MAIL_METHODS.MAIL_THREAD_CREATE,
5497
- params
5498
- );
5469
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_THREAD_CREATE, params);
5499
5470
  }
5500
5471
  /**
5501
5472
  * List threads in a conversation.
@@ -5504,10 +5475,7 @@ var AgentConnection = class _AgentConnection {
5504
5475
  * @returns Paginated list of threads
5505
5476
  */
5506
5477
  async listThreads(params) {
5507
- return this.#connection.sendRequest(
5508
- MAIL_METHODS.MAIL_THREAD_LIST,
5509
- params
5510
- );
5478
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_THREAD_LIST, params);
5511
5479
  }
5512
5480
  /**
5513
5481
  * Get a summary of a conversation.
@@ -5516,10 +5484,7 @@ var AgentConnection = class _AgentConnection {
5516
5484
  * @returns Generated summary with optional key points, decisions, and questions
5517
5485
  */
5518
5486
  async getConversationSummary(params) {
5519
- return this.#connection.sendRequest(
5520
- MAIL_METHODS.MAIL_SUMMARY,
5521
- params
5522
- );
5487
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_SUMMARY, params);
5523
5488
  }
5524
5489
  /**
5525
5490
  * Replay turns from a conversation, optionally from a specific point.
@@ -5528,10 +5493,7 @@ var AgentConnection = class _AgentConnection {
5528
5493
  * @returns Replayed turns with pagination info
5529
5494
  */
5530
5495
  async replayConversation(params) {
5531
- return this.#connection.sendRequest(
5532
- MAIL_METHODS.MAIL_REPLAY,
5533
- params
5534
- );
5496
+ return this.#connection.sendRequest(MAIL_METHODS.MAIL_REPLAY, params);
5535
5497
  }
5536
5498
  /**
5537
5499
  * Send a message to an agent with mail context attached.
@@ -5578,10 +5540,7 @@ var AgentConnection = class _AgentConnection {
5578
5540
  * @returns The created task
5579
5541
  */
5580
5542
  async createTask(params) {
5581
- return this.#connection.sendRequest(
5582
- TASK_METHODS.TASKS_CREATE,
5583
- params
5584
- );
5543
+ return this.#connection.sendRequest(TASK_METHODS.TASKS_CREATE, params);
5585
5544
  }
5586
5545
  /**
5587
5546
  * Assign a task to an agent.
@@ -5591,10 +5550,7 @@ var AgentConnection = class _AgentConnection {
5591
5550
  * @returns The updated task
5592
5551
  */
5593
5552
  async assignTask(taskId, agentId) {
5594
- return this.#connection.sendRequest(
5595
- TASK_METHODS.TASKS_ASSIGN,
5596
- { taskId, agentId }
5597
- );
5553
+ return this.#connection.sendRequest(TASK_METHODS.TASKS_ASSIGN, { taskId, agentId });
5598
5554
  }
5599
5555
  /**
5600
5556
  * Update a task's status or fields.
@@ -5603,10 +5559,7 @@ var AgentConnection = class _AgentConnection {
5603
5559
  * @returns The updated task
5604
5560
  */
5605
5561
  async updateTask(params) {
5606
- return this.#connection.sendRequest(
5607
- TASK_METHODS.TASKS_UPDATE,
5608
- params
5609
- );
5562
+ return this.#connection.sendRequest(TASK_METHODS.TASKS_UPDATE, params);
5610
5563
  }
5611
5564
  /**
5612
5565
  * List tasks with optional filters.
@@ -5615,10 +5568,7 @@ var AgentConnection = class _AgentConnection {
5615
5568
  * @returns Paginated list of tasks
5616
5569
  */
5617
5570
  async listTasks(params) {
5618
- return this.#connection.sendRequest(
5619
- TASK_METHODS.TASKS_LIST,
5620
- params ?? {}
5621
- );
5571
+ return this.#connection.sendRequest(TASK_METHODS.TASKS_LIST, params ?? {});
5622
5572
  }
5623
5573
  // ===========================================================================
5624
5574
  // Internal
@@ -5630,17 +5580,21 @@ var AgentConnection = class _AgentConnection {
5630
5580
  switch (method) {
5631
5581
  case NOTIFICATION_METHODS.EVENT: {
5632
5582
  const eventParams = params;
5633
- const subscription = this.#subscriptions.get(eventParams.subscriptionId);
5583
+ const subscription = this.#subscriptions.get(
5584
+ eventParams.subscriptionId
5585
+ );
5634
5586
  if (subscription) {
5635
5587
  subscription._pushEvent(eventParams);
5636
5588
  }
5637
5589
  break;
5638
5590
  }
5639
- case NOTIFICATION_METHODS.MESSAGE: {
5591
+ case NOTIFICATION_METHODS.MESSAGE:
5592
+ case NOTIFICATION_METHODS.SEND: {
5640
5593
  const messageParams = params;
5594
+ const message = messageParams.message ?? messageParams;
5641
5595
  for (const handler of this.#messageHandlers) {
5642
5596
  try {
5643
- await handler(messageParams.message);
5597
+ await handler(message);
5644
5598
  } catch (error) {
5645
5599
  console.error("MAP: Message handler error:", error);
5646
5600
  }
@@ -5733,7 +5687,11 @@ var AgentConnection = class _AgentConnection {
5733
5687
  try {
5734
5688
  await this.joinScope(scopeId);
5735
5689
  } catch (error) {
5736
- console.warn("MAP: Failed to restore scope membership:", scopeId, error);
5690
+ console.warn(
5691
+ "MAP: Failed to restore scope membership:",
5692
+ scopeId,
5693
+ error
5694
+ );
5737
5695
  }
5738
5696
  }
5739
5697
  }