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