@multi-agent-protocol/sdk 0.1.0 → 0.1.2

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
@@ -151,7 +151,12 @@ var EVENT_TYPES = {
151
151
  SCOPE_MEMBER_LEFT: "scope_member_left",
152
152
  // Permission events
153
153
  PERMISSIONS_CLIENT_UPDATED: "permissions_client_updated",
154
- PERMISSIONS_AGENT_UPDATED: "permissions_agent_updated"};
154
+ PERMISSIONS_AGENT_UPDATED: "permissions_agent_updated",
155
+ // Task events
156
+ TASK_CREATED: "task.created",
157
+ TASK_ASSIGNED: "task.assigned",
158
+ TASK_STATUS: "task.status",
159
+ TASK_COMPLETED: "task.completed"};
155
160
  var CORE_METHODS = {
156
161
  CONNECT: "map/connect",
157
162
  DISCONNECT: "map/disconnect",
@@ -217,6 +222,12 @@ var MAIL_METHODS = {
217
222
  MAIL_SUMMARY: "mail/summary",
218
223
  MAIL_REPLAY: "mail/replay"
219
224
  };
225
+ var TASK_METHODS = {
226
+ TASKS_CREATE: "map/tasks/create",
227
+ TASKS_ASSIGN: "map/tasks/assign",
228
+ TASKS_UPDATE: "map/tasks/update",
229
+ TASKS_LIST: "map/tasks/list"
230
+ };
220
231
  var NOTIFICATION_METHODS = {
221
232
  EVENT: "map/event",
222
233
  MESSAGE: "map/message",
@@ -1165,6 +1176,7 @@ var TestServer = class {
1165
1176
  #agents = /* @__PURE__ */ new Map();
1166
1177
  #scopes = /* @__PURE__ */ new Map();
1167
1178
  #subscriptions = /* @__PURE__ */ new Map();
1179
+ #tasks = /* @__PURE__ */ new Map();
1168
1180
  #messages = [];
1169
1181
  #eventHistory = [];
1170
1182
  #maxEventHistory;
@@ -1179,6 +1191,7 @@ var TestServer = class {
1179
1191
  #nextScopeId = 1;
1180
1192
  #nextSubscriptionId = 1;
1181
1193
  #nextMessageId = 1;
1194
+ #nextTaskId = 1;
1182
1195
  constructor(options = {}) {
1183
1196
  this.#options = options;
1184
1197
  this.#sessionId = `session-${Date.now()}`;
@@ -1210,6 +1223,12 @@ var TestServer = class {
1210
1223
  get scopes() {
1211
1224
  return this.#scopes;
1212
1225
  }
1226
+ /**
1227
+ * Get all tasks
1228
+ */
1229
+ get tasks() {
1230
+ return this.#tasks;
1231
+ }
1213
1232
  /**
1214
1233
  * Get all messages sent through the server
1215
1234
  */
@@ -1367,6 +1386,17 @@ var TestServer = class {
1367
1386
  connection,
1368
1387
  params
1369
1388
  );
1389
+ // =======================================================================
1390
+ // Task Methods
1391
+ // =======================================================================
1392
+ case TASK_METHODS.TASKS_CREATE:
1393
+ return this.#handleTasksCreate(params);
1394
+ case TASK_METHODS.TASKS_ASSIGN:
1395
+ return this.#handleTasksAssign(params);
1396
+ case TASK_METHODS.TASKS_UPDATE:
1397
+ return this.#handleTasksUpdate(params);
1398
+ case TASK_METHODS.TASKS_LIST:
1399
+ return this.#handleTasksList(params);
1370
1400
  default:
1371
1401
  throw MAPRequestError.methodNotFound(method);
1372
1402
  }
@@ -2185,6 +2215,94 @@ var TestServer = class {
2185
2215
  effectivePermissions
2186
2216
  };
2187
2217
  }
2218
+ // ===========================================================================
2219
+ // Task Handlers
2220
+ // ===========================================================================
2221
+ #handleTasksCreate(params) {
2222
+ const { task: taskInput } = params;
2223
+ const id = taskInput.id ?? `task-${this.#nextTaskId++}`;
2224
+ const task = {
2225
+ id,
2226
+ ...taskInput.assignee !== void 0 && { assignee: taskInput.assignee },
2227
+ ...taskInput.title !== void 0 && { title: taskInput.title },
2228
+ ...taskInput.status !== void 0 && { status: taskInput.status },
2229
+ ...taskInput.description !== void 0 && { description: taskInput.description },
2230
+ ...taskInput.meta !== void 0 && { meta: taskInput.meta }
2231
+ };
2232
+ this.#tasks.set(id, task);
2233
+ this.emitEvent({
2234
+ type: EVENT_TYPES.TASK_CREATED,
2235
+ data: { task }
2236
+ });
2237
+ return { task };
2238
+ }
2239
+ #handleTasksAssign(params) {
2240
+ const { taskId, agentId } = params;
2241
+ const task = this.#tasks.get(taskId);
2242
+ if (!task) {
2243
+ throw MAPRequestError.invalidParams(`Task ${taskId} not found`);
2244
+ }
2245
+ task.assignee = agentId;
2246
+ this.#tasks.set(taskId, task);
2247
+ this.emitEvent({
2248
+ type: EVENT_TYPES.TASK_ASSIGNED,
2249
+ data: { taskId, agentId }
2250
+ });
2251
+ return { task };
2252
+ }
2253
+ #handleTasksUpdate(params) {
2254
+ const { taskId, ...updates } = params;
2255
+ const task = this.#tasks.get(taskId);
2256
+ if (!task) {
2257
+ throw MAPRequestError.invalidParams(`Task ${taskId} not found`);
2258
+ }
2259
+ const previousStatus = task.status;
2260
+ if (updates.status !== void 0) task.status = updates.status;
2261
+ if (updates.title !== void 0) task.title = updates.title;
2262
+ if (updates.description !== void 0) task.description = updates.description;
2263
+ if (updates.assignee !== void 0) task.assignee = updates.assignee;
2264
+ if (updates.meta !== void 0) task.meta = { ...task.meta, ...updates.meta };
2265
+ this.#tasks.set(taskId, task);
2266
+ if (updates.status !== void 0 && updates.status !== previousStatus) {
2267
+ this.emitEvent({
2268
+ type: EVENT_TYPES.TASK_STATUS,
2269
+ data: {
2270
+ taskId,
2271
+ previous: previousStatus ?? "open",
2272
+ current: updates.status
2273
+ }
2274
+ });
2275
+ }
2276
+ if (updates.status === "completed") {
2277
+ this.emitEvent({
2278
+ type: EVENT_TYPES.TASK_COMPLETED,
2279
+ data: { taskId }
2280
+ });
2281
+ }
2282
+ return { task };
2283
+ }
2284
+ #handleTasksList(params) {
2285
+ let tasks = Array.from(this.#tasks.values());
2286
+ if (params?.filter) {
2287
+ const { assignee, status } = params.filter;
2288
+ if (assignee) {
2289
+ tasks = tasks.filter((t) => t.assignee === assignee);
2290
+ }
2291
+ if (status) {
2292
+ const statuses = Array.isArray(status) ? status : [status];
2293
+ tasks = tasks.filter((t) => t.status !== void 0 && statuses.includes(t.status));
2294
+ }
2295
+ }
2296
+ const limit = params?.limit ?? 100;
2297
+ const startIndex = params?.cursor ? parseInt(params.cursor, 10) : 0;
2298
+ const slice = tasks.slice(startIndex, startIndex + limit);
2299
+ const hasMore = startIndex + limit < tasks.length;
2300
+ return {
2301
+ tasks: slice,
2302
+ hasMore,
2303
+ nextCursor: hasMore ? String(startIndex + limit) : void 0
2304
+ };
2305
+ }
2188
2306
  };
2189
2307
 
2190
2308
  // src/stream/index.ts
@@ -4240,6 +4358,58 @@ var ClientConnection = class _ClientConnection {
4240
4358
  });
4241
4359
  }
4242
4360
  // ===========================================================================
4361
+ // Tasks
4362
+ // ===========================================================================
4363
+ /**
4364
+ * Create a new task.
4365
+ *
4366
+ * @param params - Task creation parameters
4367
+ * @returns The created task
4368
+ */
4369
+ async createTask(params) {
4370
+ return this.#connection.sendRequest(
4371
+ TASK_METHODS.TASKS_CREATE,
4372
+ params
4373
+ );
4374
+ }
4375
+ /**
4376
+ * Assign a task to an agent.
4377
+ *
4378
+ * @param taskId - ID of the task to assign
4379
+ * @param agentId - ID of the agent to assign to
4380
+ * @returns The updated task
4381
+ */
4382
+ async assignTask(taskId, agentId) {
4383
+ return this.#connection.sendRequest(
4384
+ TASK_METHODS.TASKS_ASSIGN,
4385
+ { taskId, agentId }
4386
+ );
4387
+ }
4388
+ /**
4389
+ * Update a task's status or fields.
4390
+ *
4391
+ * @param params - Update parameters including taskId and fields to change
4392
+ * @returns The updated task
4393
+ */
4394
+ async updateTask(params) {
4395
+ return this.#connection.sendRequest(
4396
+ TASK_METHODS.TASKS_UPDATE,
4397
+ params
4398
+ );
4399
+ }
4400
+ /**
4401
+ * List tasks with optional filters.
4402
+ *
4403
+ * @param params - Optional filter, limit, and cursor parameters
4404
+ * @returns Paginated list of tasks
4405
+ */
4406
+ async listTasks(params) {
4407
+ return this.#connection.sendRequest(
4408
+ TASK_METHODS.TASKS_LIST,
4409
+ params ?? {}
4410
+ );
4411
+ }
4412
+ // ===========================================================================
4243
4413
  // Reconnection
4244
4414
  // ===========================================================================
4245
4415
  /**
@@ -5382,6 +5552,22 @@ var AgentConnection = class _AgentConnection {
5382
5552
  });
5383
5553
  }
5384
5554
  // ===========================================================================
5555
+ // Extensions
5556
+ // ===========================================================================
5557
+ /**
5558
+ * Call an extension method on the MAP server.
5559
+ *
5560
+ * Sends a raw JSON-RPC request with the given method and params.
5561
+ * Use this for protocol extensions like trajectory, macro-agent, etc.
5562
+ *
5563
+ * @param method - The extension method name (e.g., 'trajectory/checkpoint')
5564
+ * @param params - Optional parameters for the method
5565
+ * @returns The result from the server
5566
+ */
5567
+ async callExtension(method, params) {
5568
+ return await this.#connection.sendRequest(method, params);
5569
+ }
5570
+ // ===========================================================================
5385
5571
  // Internal
5386
5572
  // ===========================================================================
5387
5573
  /**