@multi-agent-protocol/sdk 0.0.7 → 0.0.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
@@ -202,6 +202,21 @@ var PERMISSION_METHODS = {
202
202
  var FEDERATION_METHODS = {
203
203
  FEDERATION_ROUTE: "map/federation/route"
204
204
  };
205
+ var MAIL_METHODS = {
206
+ MAIL_CREATE: "mail/create",
207
+ MAIL_GET: "mail/get",
208
+ MAIL_LIST: "mail/list",
209
+ MAIL_CLOSE: "mail/close",
210
+ MAIL_JOIN: "mail/join",
211
+ MAIL_LEAVE: "mail/leave",
212
+ MAIL_INVITE: "mail/invite",
213
+ MAIL_TURN: "mail/turn",
214
+ MAIL_TURNS_LIST: "mail/turns/list",
215
+ MAIL_THREAD_CREATE: "mail/thread/create",
216
+ MAIL_THREAD_LIST: "mail/thread/list",
217
+ MAIL_SUMMARY: "mail/summary",
218
+ MAIL_REPLAY: "mail/replay"
219
+ };
205
220
  var NOTIFICATION_METHODS = {
206
221
  EVENT: "map/event",
207
222
  MESSAGE: "map/message",
@@ -252,13 +267,27 @@ var FEDERATION_ERROR_CODES = {
252
267
  /** Message exceeded maximum hop count */
253
268
  FEDERATION_MAX_HOPS_EXCEEDED: 5011
254
269
  };
270
+ var MAIL_ERROR_CODES = {
271
+ MAIL_CONVERSATION_NOT_FOUND: 1e4,
272
+ MAIL_CONVERSATION_CLOSED: 10001,
273
+ MAIL_NOT_A_PARTICIPANT: 10002,
274
+ MAIL_PERMISSION_DENIED: 10003,
275
+ MAIL_TURN_NOT_FOUND: 10004,
276
+ MAIL_THREAD_NOT_FOUND: 10005,
277
+ MAIL_INVALID_TURN_CONTENT: 10006,
278
+ MAIL_PARTICIPANT_ALREADY_JOINED: 10007,
279
+ MAIL_INVITATION_REQUIRED: 10008,
280
+ MAIL_HISTORY_ACCESS_DENIED: 10009,
281
+ MAIL_PARENT_CONVERSATION_NOT_FOUND: 10010
282
+ };
255
283
  var ERROR_CODES = {
256
284
  ...PROTOCOL_ERROR_CODES,
257
285
  ...AUTH_ERROR_CODES,
258
286
  ...ROUTING_ERROR_CODES,
259
287
  ...AGENT_ERROR_CODES,
260
288
  ...RESOURCE_ERROR_CODES,
261
- ...FEDERATION_ERROR_CODES
289
+ ...FEDERATION_ERROR_CODES,
290
+ ...MAIL_ERROR_CODES
262
291
  };
263
292
  var PROTOCOL_VERSION = 1;
264
293
 
@@ -3974,6 +4003,187 @@ var ClientConnection = class _ClientConnection {
3974
4003
  return this.#connection.sendRequest(STATE_METHODS.AGENTS_RESUME, { agentId });
3975
4004
  }
3976
4005
  // ===========================================================================
4006
+ // Mail
4007
+ // ===========================================================================
4008
+ /**
4009
+ * Create a new mail conversation.
4010
+ *
4011
+ * @param params - Conversation creation parameters
4012
+ * @returns Created conversation and participant info
4013
+ */
4014
+ async createConversation(params) {
4015
+ return this.#connection.sendRequest(
4016
+ MAIL_METHODS.MAIL_CREATE,
4017
+ params ?? {}
4018
+ );
4019
+ }
4020
+ /**
4021
+ * Get a conversation by ID with optional includes.
4022
+ *
4023
+ * @param conversationId - ID of the conversation to retrieve
4024
+ * @param include - Optional fields to include (participants, threads, recentTurns, stats)
4025
+ * @returns Conversation details with requested includes
4026
+ */
4027
+ async getConversation(conversationId, include) {
4028
+ return this.#connection.sendRequest(
4029
+ MAIL_METHODS.MAIL_GET,
4030
+ { conversationId, include }
4031
+ );
4032
+ }
4033
+ /**
4034
+ * List conversations with optional filters.
4035
+ *
4036
+ * @param params - Optional filter, limit, and cursor parameters
4037
+ * @returns Paginated list of conversations
4038
+ */
4039
+ async listConversations(params) {
4040
+ return this.#connection.sendRequest(
4041
+ MAIL_METHODS.MAIL_LIST,
4042
+ params ?? {}
4043
+ );
4044
+ }
4045
+ /**
4046
+ * Close a conversation.
4047
+ *
4048
+ * @param conversationId - ID of the conversation to close
4049
+ * @param reason - Optional reason for closing
4050
+ * @returns The closed conversation
4051
+ */
4052
+ async closeConversation(conversationId, reason) {
4053
+ return this.#connection.sendRequest(
4054
+ MAIL_METHODS.MAIL_CLOSE,
4055
+ { conversationId, reason }
4056
+ );
4057
+ }
4058
+ /**
4059
+ * Join an existing conversation.
4060
+ *
4061
+ * @param params - Join parameters including conversationId and optional catch-up config
4062
+ * @returns Conversation, participant, and optional history
4063
+ */
4064
+ async joinConversation(params) {
4065
+ return this.#connection.sendRequest(
4066
+ MAIL_METHODS.MAIL_JOIN,
4067
+ params
4068
+ );
4069
+ }
4070
+ /**
4071
+ * Leave a conversation.
4072
+ *
4073
+ * @param conversationId - ID of the conversation to leave
4074
+ * @param reason - Optional reason for leaving
4075
+ * @returns Leave confirmation with timestamp
4076
+ */
4077
+ async leaveConversation(conversationId, reason) {
4078
+ return this.#connection.sendRequest(
4079
+ MAIL_METHODS.MAIL_LEAVE,
4080
+ { conversationId, reason }
4081
+ );
4082
+ }
4083
+ /**
4084
+ * Invite a participant to a conversation.
4085
+ *
4086
+ * @param params - Invite parameters including conversationId and participant info
4087
+ * @returns Invite result
4088
+ */
4089
+ async inviteToConversation(params) {
4090
+ return this.#connection.sendRequest(
4091
+ MAIL_METHODS.MAIL_INVITE,
4092
+ params
4093
+ );
4094
+ }
4095
+ /**
4096
+ * Record a turn (message) in a conversation.
4097
+ *
4098
+ * @param params - Turn parameters including conversationId, contentType, and content
4099
+ * @returns The created turn
4100
+ */
4101
+ async recordTurn(params) {
4102
+ return this.#connection.sendRequest(
4103
+ MAIL_METHODS.MAIL_TURN,
4104
+ params
4105
+ );
4106
+ }
4107
+ /**
4108
+ * List turns in a conversation with optional filters.
4109
+ *
4110
+ * @param params - List parameters including conversationId and optional filters
4111
+ * @returns Paginated list of turns
4112
+ */
4113
+ async listTurns(params) {
4114
+ return this.#connection.sendRequest(
4115
+ MAIL_METHODS.MAIL_TURNS_LIST,
4116
+ params
4117
+ );
4118
+ }
4119
+ /**
4120
+ * Create a thread in a conversation.
4121
+ *
4122
+ * @param params - Thread creation parameters including conversationId and rootTurnId
4123
+ * @returns The created thread
4124
+ */
4125
+ async createThread(params) {
4126
+ return this.#connection.sendRequest(
4127
+ MAIL_METHODS.MAIL_THREAD_CREATE,
4128
+ params
4129
+ );
4130
+ }
4131
+ /**
4132
+ * List threads in a conversation.
4133
+ *
4134
+ * @param params - List parameters including conversationId
4135
+ * @returns Paginated list of threads
4136
+ */
4137
+ async listThreads(params) {
4138
+ return this.#connection.sendRequest(
4139
+ MAIL_METHODS.MAIL_THREAD_LIST,
4140
+ params
4141
+ );
4142
+ }
4143
+ /**
4144
+ * Get a summary of a conversation.
4145
+ *
4146
+ * @param params - Summary parameters including conversationId and optional scope/includes
4147
+ * @returns Generated summary with optional key points, decisions, and questions
4148
+ */
4149
+ async getConversationSummary(params) {
4150
+ return this.#connection.sendRequest(
4151
+ MAIL_METHODS.MAIL_SUMMARY,
4152
+ params
4153
+ );
4154
+ }
4155
+ /**
4156
+ * Replay turns from a conversation, optionally from a specific point.
4157
+ *
4158
+ * @param params - Replay parameters including conversationId and optional starting point
4159
+ * @returns Replayed turns with pagination info
4160
+ */
4161
+ async replayConversation(params) {
4162
+ return this.#connection.sendRequest(
4163
+ MAIL_METHODS.MAIL_REPLAY,
4164
+ params
4165
+ );
4166
+ }
4167
+ /**
4168
+ * Send a message to an address with mail context attached.
4169
+ *
4170
+ * Wraps the standard `send()` method, automatically attaching `meta.mail`
4171
+ * with the specified conversationId so the message is recorded as a turn
4172
+ * in the conversation.
4173
+ *
4174
+ * @param to - Target address
4175
+ * @param payload - Message payload
4176
+ * @param conversationId - Conversation to associate with
4177
+ * @param options - Optional threadId and additional message meta
4178
+ * @returns Send result
4179
+ */
4180
+ async sendWithMail(to, payload, conversationId, options) {
4181
+ return this.send(to, payload, {
4182
+ ...options?.meta,
4183
+ mail: { conversationId, threadId: options?.threadId }
4184
+ });
4185
+ }
4186
+ // ===========================================================================
3977
4187
  // Reconnection
3978
4188
  // ===========================================================================
3979
4189
  /**
@@ -4935,6 +5145,187 @@ var AgentConnection = class _AgentConnection {
4935
5145
  return this.#connection.onStateChange(handler);
4936
5146
  }
4937
5147
  // ===========================================================================
5148
+ // Mail
5149
+ // ===========================================================================
5150
+ /**
5151
+ * Create a new mail conversation.
5152
+ *
5153
+ * @param params - Conversation creation parameters
5154
+ * @returns Created conversation and participant info
5155
+ */
5156
+ async createConversation(params) {
5157
+ return this.#connection.sendRequest(
5158
+ MAIL_METHODS.MAIL_CREATE,
5159
+ params ?? {}
5160
+ );
5161
+ }
5162
+ /**
5163
+ * Get a conversation by ID with optional includes.
5164
+ *
5165
+ * @param conversationId - ID of the conversation to retrieve
5166
+ * @param include - Optional fields to include (participants, threads, recentTurns, stats)
5167
+ * @returns Conversation details with requested includes
5168
+ */
5169
+ async getConversation(conversationId, include) {
5170
+ return this.#connection.sendRequest(
5171
+ MAIL_METHODS.MAIL_GET,
5172
+ { conversationId, include }
5173
+ );
5174
+ }
5175
+ /**
5176
+ * List conversations with optional filters.
5177
+ *
5178
+ * @param params - Optional filter, limit, and cursor parameters
5179
+ * @returns Paginated list of conversations
5180
+ */
5181
+ async listConversations(params) {
5182
+ return this.#connection.sendRequest(
5183
+ MAIL_METHODS.MAIL_LIST,
5184
+ params ?? {}
5185
+ );
5186
+ }
5187
+ /**
5188
+ * Close a conversation.
5189
+ *
5190
+ * @param conversationId - ID of the conversation to close
5191
+ * @param reason - Optional reason for closing
5192
+ * @returns The closed conversation
5193
+ */
5194
+ async closeConversation(conversationId, reason) {
5195
+ return this.#connection.sendRequest(
5196
+ MAIL_METHODS.MAIL_CLOSE,
5197
+ { conversationId, reason }
5198
+ );
5199
+ }
5200
+ /**
5201
+ * Join an existing conversation.
5202
+ *
5203
+ * @param params - Join parameters including conversationId and optional catch-up config
5204
+ * @returns Conversation, participant, and optional history
5205
+ */
5206
+ async joinConversation(params) {
5207
+ return this.#connection.sendRequest(
5208
+ MAIL_METHODS.MAIL_JOIN,
5209
+ params
5210
+ );
5211
+ }
5212
+ /**
5213
+ * Leave a conversation.
5214
+ *
5215
+ * @param conversationId - ID of the conversation to leave
5216
+ * @param reason - Optional reason for leaving
5217
+ * @returns Leave confirmation with timestamp
5218
+ */
5219
+ async leaveConversation(conversationId, reason) {
5220
+ return this.#connection.sendRequest(
5221
+ MAIL_METHODS.MAIL_LEAVE,
5222
+ { conversationId, reason }
5223
+ );
5224
+ }
5225
+ /**
5226
+ * Invite a participant to a conversation.
5227
+ *
5228
+ * @param params - Invite parameters including conversationId and participant info
5229
+ * @returns Invite result
5230
+ */
5231
+ async inviteToConversation(params) {
5232
+ return this.#connection.sendRequest(
5233
+ MAIL_METHODS.MAIL_INVITE,
5234
+ params
5235
+ );
5236
+ }
5237
+ /**
5238
+ * Record a turn (message) in a conversation.
5239
+ *
5240
+ * @param params - Turn parameters including conversationId, contentType, and content
5241
+ * @returns The created turn
5242
+ */
5243
+ async recordTurn(params) {
5244
+ return this.#connection.sendRequest(
5245
+ MAIL_METHODS.MAIL_TURN,
5246
+ params
5247
+ );
5248
+ }
5249
+ /**
5250
+ * List turns in a conversation with optional filters.
5251
+ *
5252
+ * @param params - List parameters including conversationId and optional filters
5253
+ * @returns Paginated list of turns
5254
+ */
5255
+ async listTurns(params) {
5256
+ return this.#connection.sendRequest(
5257
+ MAIL_METHODS.MAIL_TURNS_LIST,
5258
+ params
5259
+ );
5260
+ }
5261
+ /**
5262
+ * Create a thread in a conversation.
5263
+ *
5264
+ * @param params - Thread creation parameters including conversationId and rootTurnId
5265
+ * @returns The created thread
5266
+ */
5267
+ async createThread(params) {
5268
+ return this.#connection.sendRequest(
5269
+ MAIL_METHODS.MAIL_THREAD_CREATE,
5270
+ params
5271
+ );
5272
+ }
5273
+ /**
5274
+ * List threads in a conversation.
5275
+ *
5276
+ * @param params - List parameters including conversationId
5277
+ * @returns Paginated list of threads
5278
+ */
5279
+ async listThreads(params) {
5280
+ return this.#connection.sendRequest(
5281
+ MAIL_METHODS.MAIL_THREAD_LIST,
5282
+ params
5283
+ );
5284
+ }
5285
+ /**
5286
+ * Get a summary of a conversation.
5287
+ *
5288
+ * @param params - Summary parameters including conversationId and optional scope/includes
5289
+ * @returns Generated summary with optional key points, decisions, and questions
5290
+ */
5291
+ async getConversationSummary(params) {
5292
+ return this.#connection.sendRequest(
5293
+ MAIL_METHODS.MAIL_SUMMARY,
5294
+ params
5295
+ );
5296
+ }
5297
+ /**
5298
+ * Replay turns from a conversation, optionally from a specific point.
5299
+ *
5300
+ * @param params - Replay parameters including conversationId and optional starting point
5301
+ * @returns Replayed turns with pagination info
5302
+ */
5303
+ async replayConversation(params) {
5304
+ return this.#connection.sendRequest(
5305
+ MAIL_METHODS.MAIL_REPLAY,
5306
+ params
5307
+ );
5308
+ }
5309
+ /**
5310
+ * Send a message to an agent with mail context attached.
5311
+ *
5312
+ * Wraps the standard `send()` method, automatically attaching `meta.mail`
5313
+ * with the specified conversationId so the message is recorded as a turn
5314
+ * in the conversation.
5315
+ *
5316
+ * @param to - Target address
5317
+ * @param payload - Message payload
5318
+ * @param conversationId - Conversation to associate with
5319
+ * @param options - Optional threadId and additional message meta
5320
+ * @returns Send result
5321
+ */
5322
+ async sendWithMail(to, payload, conversationId, options) {
5323
+ return this.send(to, payload, {
5324
+ ...options?.meta,
5325
+ mail: { conversationId, threadId: options?.threadId }
5326
+ });
5327
+ }
5328
+ // ===========================================================================
4938
5329
  // Internal
4939
5330
  // ===========================================================================
4940
5331
  /**