@multi-agent-protocol/sdk 0.0.7 → 0.0.9

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