@lov3kaizen/agentsea-crews 1.1.0 → 1.2.0

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.
@@ -255,8 +255,37 @@ Background: ${this.backstory}`);
255
255
  }
256
256
  };
257
257
 
258
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
259
+ var import_node_crypto = require("crypto");
260
+
261
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
262
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
263
+
264
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
265
+ var POOL_SIZE_MULTIPLIER = 128;
266
+ var pool;
267
+ var poolOffset;
268
+ function fillPool(bytes) {
269
+ if (!pool || pool.length < bytes) {
270
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
271
+ import_node_crypto.webcrypto.getRandomValues(pool);
272
+ poolOffset = 0;
273
+ } else if (poolOffset + bytes > pool.length) {
274
+ import_node_crypto.webcrypto.getRandomValues(pool);
275
+ poolOffset = 0;
276
+ }
277
+ poolOffset += bytes;
278
+ }
279
+ function nanoid(size = 21) {
280
+ fillPool(size |= 0);
281
+ let id = "";
282
+ for (let i = poolOffset - size; i < poolOffset; i++) {
283
+ id += urlAlphabet[pool[i] & 63];
284
+ }
285
+ return id;
286
+ }
287
+
258
288
  // src/core/Task.ts
259
- var import_nanoid = require("nanoid");
260
289
  var Task = class _Task {
261
290
  id;
262
291
  description;
@@ -276,7 +305,7 @@ var Task = class _Task {
276
305
  _result;
277
306
  _metadata;
278
307
  constructor(config) {
279
- this.id = config.id ?? (0, import_nanoid.nanoid)();
308
+ this.id = config.id ?? nanoid();
280
309
  this.description = config.description;
281
310
  this.expectedOutput = config.expectedOutput;
282
311
  this.priority = config.priority ?? "medium";
@@ -882,7 +911,6 @@ var TaskQueue = class {
882
911
 
883
912
  // src/core/ExecutionContext.ts
884
913
  var import_eventemitter3 = __toESM(require("eventemitter3"));
885
- var import_nanoid2 = require("nanoid");
886
914
  var ExecutionContext = class {
887
915
  crewId;
888
916
  crewName;
@@ -899,7 +927,7 @@ var ExecutionContext = class {
899
927
  startTime;
900
928
  endTime;
901
929
  constructor(config) {
902
- this.crewId = config.crewId ?? (0, import_nanoid2.nanoid)();
930
+ this.crewId = config.crewId ?? nanoid();
903
931
  this.crewName = config.crewName;
904
932
  this.state = /* @__PURE__ */ new Map();
905
933
  this.completedTasks = /* @__PURE__ */ new Map();
@@ -1145,7 +1173,7 @@ var ExecutionContext = class {
1145
1173
  */
1146
1174
  createCheckpoint() {
1147
1175
  return {
1148
- id: (0, import_nanoid2.nanoid)(),
1176
+ id: nanoid(),
1149
1177
  timestamp: /* @__PURE__ */ new Date(),
1150
1178
  crewId: this.crewId,
1151
1179
  crewName: this.crewName,
@@ -1231,12 +1259,6 @@ var ExecutionContext = class {
1231
1259
  }
1232
1260
  };
1233
1261
 
1234
- // src/core/Crew.ts
1235
- var import_nanoid4 = require("nanoid");
1236
-
1237
- // src/agents/CrewAgent.ts
1238
- var import_nanoid3 = require("nanoid");
1239
-
1240
1262
  // src/agents/AgentCapabilities.ts
1241
1263
  var PROFICIENCY_WEIGHTS = {
1242
1264
  novice: 0.25,
@@ -1521,7 +1543,7 @@ var CrewAgent = class _CrewAgent {
1521
1543
  totalTokensUsed = 0;
1522
1544
  constructor(options) {
1523
1545
  const { config, execute } = options;
1524
- this.id = (0, import_nanoid3.nanoid)();
1546
+ this.id = nanoid();
1525
1547
  this.name = config.name;
1526
1548
  this.role = new Role(config.role);
1527
1549
  this.capabilities = config.role.capabilities;
@@ -1718,7 +1740,7 @@ ${JSON.stringify(task.context, null, 2)}`);
1718
1740
  */
1719
1741
  createHelpRequest(taskId, request) {
1720
1742
  return {
1721
- requestId: (0, import_nanoid3.nanoid)(),
1743
+ requestId: nanoid(),
1722
1744
  fromAgent: this.name,
1723
1745
  taskId,
1724
1746
  request
@@ -4163,7 +4185,7 @@ var Crew = class {
4163
4185
  timeline = [];
4164
4186
  results = /* @__PURE__ */ new Map();
4165
4187
  constructor(config) {
4166
- this.id = (0, import_nanoid4.nanoid)();
4188
+ this.id = nanoid();
4167
4189
  this.name = config.name;
4168
4190
  this.description = config.description;
4169
4191
  this.config = config;
@@ -4312,27 +4334,40 @@ var Crew = class {
4312
4334
  await this.sleep(100);
4313
4335
  continue;
4314
4336
  }
4315
- for (const task of readyTasks) {
4316
- if (this.state !== "running") break;
4317
- const delegationResult = await this.delegateTask(task, options);
4318
- yield this.createEvent({
4319
- type: "task:assigned",
4320
- taskId: task.id,
4321
- agentName: delegationResult.selectedAgent,
4322
- reason: delegationResult.reason,
4323
- strategy: this.config.delegationStrategy
4324
- });
4325
- const taskResult = await this.executeTask(task, delegationResult);
4326
- yield this.createEvent({
4327
- type: "task:completed",
4328
- taskId: task.id,
4329
- result: taskResult,
4330
- agentName: delegationResult.selectedAgent,
4331
- durationMs: taskResult.latencyMs ?? 0
4332
- });
4333
- while (eventQueue.length > 0) {
4334
- yield eventQueue.shift();
4337
+ const concurrency = Math.max(
4338
+ 1,
4339
+ options.maxConcurrentTasks ?? this.config.maxConcurrentTasks ?? 1
4340
+ );
4341
+ if (concurrency === 1) {
4342
+ for (const task of readyTasks) {
4343
+ if (this.state !== "running") break;
4344
+ const delegationResult = await this.delegateTask(task, options);
4345
+ yield this.createEvent({
4346
+ type: "task:assigned",
4347
+ taskId: task.id,
4348
+ agentName: delegationResult.selectedAgent,
4349
+ reason: delegationResult.reason,
4350
+ strategy: this.config.delegationStrategy
4351
+ });
4352
+ const taskResult = await this.executeTask(task, delegationResult);
4353
+ yield this.createEvent({
4354
+ type: "task:completed",
4355
+ taskId: task.id,
4356
+ result: taskResult,
4357
+ agentName: delegationResult.selectedAgent,
4358
+ durationMs: taskResult.latencyMs ?? 0
4359
+ });
4360
+ while (eventQueue.length > 0) {
4361
+ yield eventQueue.shift();
4362
+ }
4335
4363
  }
4364
+ } else {
4365
+ yield* this.processReadyTasksConcurrently(
4366
+ readyTasks,
4367
+ options,
4368
+ eventQueue,
4369
+ concurrency
4370
+ );
4336
4371
  }
4337
4372
  while (this.state === "paused") {
4338
4373
  await this.sleep(100);
@@ -4375,6 +4410,78 @@ var Crew = class {
4375
4410
  });
4376
4411
  this.addTimelineEntry("crew_completed", this.name);
4377
4412
  }
4413
+ /**
4414
+ * Execute a batch of ready tasks concurrently with a bounded worker pool.
4415
+ *
4416
+ * Each task still emits its `task:assigned` and `task:completed` events in
4417
+ * order relative to itself, but events across tasks are interleaved as the
4418
+ * workers settle. At most `concurrency` tasks run at once. If any task throws
4419
+ * (after exhausting retries), no further tasks are started, in-flight tasks
4420
+ * are allowed to settle, and the first error is rethrown so the caller's
4421
+ * error handling (crew:error) behaves identically to the sequential path.
4422
+ */
4423
+ async *processReadyTasksConcurrently(readyTasks, options, eventQueue, concurrency) {
4424
+ let nextIndex = 0;
4425
+ let firstError;
4426
+ const buffer = [];
4427
+ const inFlight = /* @__PURE__ */ new Set();
4428
+ const launch = (task) => {
4429
+ const worker = (async () => {
4430
+ const delegationResult = await this.delegateTask(task, options);
4431
+ buffer.push(
4432
+ this.createEvent({
4433
+ type: "task:assigned",
4434
+ taskId: task.id,
4435
+ agentName: delegationResult.selectedAgent,
4436
+ reason: delegationResult.reason,
4437
+ strategy: this.config.delegationStrategy
4438
+ })
4439
+ );
4440
+ const taskResult = await this.executeTask(task, delegationResult);
4441
+ buffer.push(
4442
+ this.createEvent({
4443
+ type: "task:completed",
4444
+ taskId: task.id,
4445
+ result: taskResult,
4446
+ agentName: delegationResult.selectedAgent,
4447
+ durationMs: taskResult.latencyMs ?? 0
4448
+ })
4449
+ );
4450
+ })().catch((error) => {
4451
+ if (firstError === void 0) {
4452
+ firstError = error;
4453
+ }
4454
+ }).finally(() => {
4455
+ inFlight.delete(worker);
4456
+ });
4457
+ inFlight.add(worker);
4458
+ };
4459
+ const fill = () => {
4460
+ while (inFlight.size < concurrency && nextIndex < readyTasks.length && this.state === "running" && firstError === void 0) {
4461
+ launch(readyTasks[nextIndex++]);
4462
+ }
4463
+ };
4464
+ fill();
4465
+ while (inFlight.size > 0) {
4466
+ await Promise.race(inFlight);
4467
+ while (buffer.length > 0) {
4468
+ yield buffer.shift();
4469
+ }
4470
+ while (eventQueue.length > 0) {
4471
+ yield eventQueue.shift();
4472
+ }
4473
+ fill();
4474
+ }
4475
+ while (buffer.length > 0) {
4476
+ yield buffer.shift();
4477
+ }
4478
+ while (eventQueue.length > 0) {
4479
+ yield eventQueue.shift();
4480
+ }
4481
+ if (firstError !== void 0) {
4482
+ throw firstError;
4483
+ }
4484
+ }
4378
4485
  /**
4379
4486
  * Delegate a task to an agent
4380
4487
  */
@@ -4594,7 +4701,7 @@ ${r.output}`).join("\n\n---\n\n");
4594
4701
  */
4595
4702
  createCheckpoint() {
4596
4703
  return {
4597
- id: (0, import_nanoid4.nanoid)(),
4704
+ id: nanoid(),
4598
4705
  crewId: this.id,
4599
4706
  crewName: this.name,
4600
4707
  timestamp: /* @__PURE__ */ new Date(),
@@ -11,8 +11,8 @@ import {
11
11
  createResearchCrewConfig,
12
12
  createWritingCrew,
13
13
  createWritingCrewConfig
14
- } from "../chunk-6JLVFEU6.mjs";
15
- import "../chunk-V6VK6BOL.mjs";
14
+ } from "../chunk-3NMVWRVW.mjs";
15
+ import "../chunk-J5KQSOGT.mjs";
16
16
  export {
17
17
  CodeReviewTasks,
18
18
  CustomerSupportTasks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lov3kaizen/agentsea-crews",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Multi-agent orchestration framework for AgentSea. Build, compose, and orchestrate agent crews with role-based coordination, task delegation, and workflow automation.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -27,12 +27,12 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "eventemitter3": "^5.0.0",
31
- "nanoid": "^5.0.0"
30
+ "eventemitter3": "^5.0.0"
32
31
  },
33
32
  "devDependencies": {
34
33
  "@types/node": "^20.11.0",
35
34
  "@vitest/coverage-v8": "^3.2.6",
35
+ "nanoid": "^5.0.0",
36
36
  "tsup": "^8.0.1",
37
37
  "typescript": "^5.3.3",
38
38
  "vitest": "^3.2.6"
@@ -40,7 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "@nestjs/common": "^10.0.0 || ^11.0.0",
42
42
  "@nestjs/core": "^10.0.0 || ^11.0.0",
43
- "@lov3kaizen/agentsea-core": "1.1.0"
43
+ "@lov3kaizen/agentsea-core": "1.2.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@nestjs/common": {
@@ -78,8 +78,8 @@
78
78
  "access": "public"
79
79
  },
80
80
  "scripts": {
81
- "build": "tsup src/index.ts src/nestjs/index.ts src/templates/index.ts --format cjs,esm --clean --external reflect-metadata --external @nestjs/common --external @nestjs/core",
82
- "dev": "tsup src/index.ts src/nestjs/index.ts src/templates/index.ts --format cjs,esm --dts --watch --external reflect-metadata --external @nestjs/common --external @nestjs/core",
81
+ "build": "tsup",
82
+ "dev": "tsup --watch",
83
83
  "test": "vitest run",
84
84
  "test:watch": "vitest",
85
85
  "test:cov": "vitest run --coverage",