@lov3kaizen/agentsea-crews 1.1.0 → 1.1.1

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.
@@ -0,0 +1,190 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { C as CrewStatusDetails, a as Crew, b as CrewEvent, c as CrewMetrics, T as TimelineEntry, d as TaskConfig } from './Crew-BnvVjN7A.mjs';
3
+
4
+ interface AgentStatus {
5
+ name: string;
6
+ role: string;
7
+ status: 'idle' | 'busy' | 'error';
8
+ currentTask?: string;
9
+ tasksCompleted: number;
10
+ tasksFailed: number;
11
+ tokensUsed: number;
12
+ lastActivity?: Date;
13
+ }
14
+ interface DashboardUpdate {
15
+ type: 'status_change' | 'agent_update' | 'task_update' | 'metrics_update' | 'event';
16
+ timestamp: Date;
17
+ data: unknown;
18
+ }
19
+ interface DashboardConfig {
20
+ updateInterval?: number;
21
+ trackEvents?: boolean;
22
+ maxEvents?: number;
23
+ }
24
+ declare class CrewDashboard extends EventEmitter<{
25
+ update: (update: DashboardUpdate) => void;
26
+ statusChange: (status: CrewStatusDetails) => void;
27
+ agentUpdate: (agent: AgentStatus) => void;
28
+ error: (error: Error) => void;
29
+ }> {
30
+ private readonly crew;
31
+ private readonly config;
32
+ private readonly events;
33
+ private updateTimer?;
34
+ private lastStatus?;
35
+ private subscribed;
36
+ constructor(crew: Crew, config?: DashboardConfig);
37
+ start(): void;
38
+ stop(): void;
39
+ subscribe(callback: (update: DashboardUpdate) => void): () => void;
40
+ recordEvent(event: CrewEvent): void;
41
+ getCrewStatus(): CrewStatusDetails;
42
+ getAgentStatuses(): Map<string, AgentStatus>;
43
+ getMetrics(): CrewMetrics;
44
+ getTimeline(): TimelineEntry[];
45
+ getEvents(filter?: {
46
+ type?: string;
47
+ agent?: string;
48
+ since?: Date;
49
+ limit?: number;
50
+ }): CrewEvent[];
51
+ getProgress(): {
52
+ percentage: number;
53
+ completedTasks: number;
54
+ totalTasks: number;
55
+ currentTask?: string;
56
+ elapsedTime: number;
57
+ estimatedRemaining?: number;
58
+ };
59
+ getTaskBreakdown(): {
60
+ pending: number;
61
+ inProgress: number;
62
+ completed: number;
63
+ failed: number;
64
+ total: number;
65
+ };
66
+ getAgentBreakdown(): {
67
+ total: number;
68
+ busy: number;
69
+ idle: number;
70
+ performance: Array<{
71
+ name: string;
72
+ completed: number;
73
+ failed: number;
74
+ successRate: number;
75
+ }>;
76
+ };
77
+ private emitUpdate;
78
+ getSnapshot(): DashboardSnapshot;
79
+ }
80
+ interface DashboardSnapshot {
81
+ timestamp: Date;
82
+ status: CrewStatusDetails;
83
+ metrics: CrewMetrics;
84
+ agents: Record<string, AgentStatus>;
85
+ progress: ReturnType<CrewDashboard['getProgress']>;
86
+ taskBreakdown: ReturnType<CrewDashboard['getTaskBreakdown']>;
87
+ agentBreakdown: ReturnType<CrewDashboard['getAgentBreakdown']>;
88
+ recentEvents: CrewEvent[];
89
+ }
90
+ declare function createDashboard(crew: Crew, config?: DashboardConfig): CrewDashboard;
91
+
92
+ type BreakpointType = 'task:assigned' | 'task:started' | 'task:completed' | 'task:failed' | 'agent:thinking' | 'delegation:decision' | 'custom';
93
+ interface Breakpoint {
94
+ id: string;
95
+ type: BreakpointType;
96
+ condition?: (event: CrewEvent, context: DebugContext) => boolean;
97
+ enabled: boolean;
98
+ hitCount: number;
99
+ }
100
+ interface DebugContext {
101
+ currentEvent?: CrewEvent;
102
+ agents: Map<string, AgentInspection>;
103
+ tasks: TaskConfig[];
104
+ variables: Map<string, unknown>;
105
+ callStack: string[];
106
+ }
107
+ interface AgentInspection {
108
+ name: string;
109
+ role: string;
110
+ status: 'idle' | 'busy' | 'paused';
111
+ currentTask?: string;
112
+ lastThought?: string;
113
+ lastToolCall?: {
114
+ tool: string;
115
+ input: unknown;
116
+ output?: unknown;
117
+ };
118
+ memory: Map<string, unknown>;
119
+ }
120
+ interface StepResult {
121
+ event: CrewEvent;
122
+ breakpointHit?: Breakpoint;
123
+ agentStates: Map<string, AgentInspection>;
124
+ continueExecution: boolean;
125
+ }
126
+ interface DebugModeConfig {
127
+ pauseOnError?: boolean;
128
+ verbose?: boolean;
129
+ maxCallStackDepth?: number;
130
+ }
131
+ declare class DebugMode extends EventEmitter<{
132
+ breakpointHit: (breakpoint: Breakpoint, event: CrewEvent) => void;
133
+ step: (result: StepResult) => void;
134
+ error: (error: Error) => void;
135
+ paused: () => void;
136
+ resumed: () => void;
137
+ }> {
138
+ private readonly crew;
139
+ private readonly config;
140
+ private readonly breakpoints;
141
+ private readonly eventQueue;
142
+ private readonly callStack;
143
+ private context;
144
+ private enabled;
145
+ private paused;
146
+ private stepMode;
147
+ private breakpointCounter;
148
+ private resolveStep?;
149
+ constructor(crew: Crew, config?: DebugModeConfig);
150
+ enable(): void;
151
+ disable(): void;
152
+ isEnabled(): boolean;
153
+ setBreakpoint(type: BreakpointType, condition?: (event: CrewEvent, context: DebugContext) => boolean): string;
154
+ removeBreakpoint(id: string): boolean;
155
+ enableBreakpoint(id: string): boolean;
156
+ disableBreakpoint(id: string): boolean;
157
+ getBreakpoints(): Breakpoint[];
158
+ clearBreakpoints(): void;
159
+ step(): Promise<StepResult>;
160
+ continue(): Promise<void>;
161
+ pause(): void;
162
+ resume(): void;
163
+ isPaused(): boolean;
164
+ inspect(agentName: string): AgentInspection | undefined;
165
+ inspectAll(): Map<string, AgentInspection>;
166
+ getContext(): DebugContext;
167
+ getCallStack(): string[];
168
+ evaluate(expression: string): unknown;
169
+ watch(expression: string): {
170
+ expression: string;
171
+ value: unknown;
172
+ };
173
+ handleEvent(event: CrewEvent): void;
174
+ private createContext;
175
+ private updateContext;
176
+ private checkBreakpoints;
177
+ private getAgentStates;
178
+ private createAgentInspection;
179
+ getSummary(): {
180
+ enabled: boolean;
181
+ paused: boolean;
182
+ stepMode: boolean;
183
+ breakpointCount: number;
184
+ queuedEvents: number;
185
+ callStackDepth: number;
186
+ };
187
+ }
188
+ declare function createDebugMode(crew: Crew, config?: DebugModeConfig): DebugMode;
189
+
190
+ export { type AgentInspection as A, type Breakpoint as B, CrewDashboard as C, DebugMode as D, type StepResult as S, type AgentStatus as a, type BreakpointType as b, type DashboardConfig as c, type DashboardSnapshot as d, type DashboardUpdate as e, type DebugContext as f, type DebugModeConfig as g, createDashboard as h, createDebugMode as i };
@@ -0,0 +1,190 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { C as CrewStatusDetails, a as Crew, b as CrewEvent, c as CrewMetrics, T as TimelineEntry, d as TaskConfig } from './Crew-BnvVjN7A.js';
3
+
4
+ interface AgentStatus {
5
+ name: string;
6
+ role: string;
7
+ status: 'idle' | 'busy' | 'error';
8
+ currentTask?: string;
9
+ tasksCompleted: number;
10
+ tasksFailed: number;
11
+ tokensUsed: number;
12
+ lastActivity?: Date;
13
+ }
14
+ interface DashboardUpdate {
15
+ type: 'status_change' | 'agent_update' | 'task_update' | 'metrics_update' | 'event';
16
+ timestamp: Date;
17
+ data: unknown;
18
+ }
19
+ interface DashboardConfig {
20
+ updateInterval?: number;
21
+ trackEvents?: boolean;
22
+ maxEvents?: number;
23
+ }
24
+ declare class CrewDashboard extends EventEmitter<{
25
+ update: (update: DashboardUpdate) => void;
26
+ statusChange: (status: CrewStatusDetails) => void;
27
+ agentUpdate: (agent: AgentStatus) => void;
28
+ error: (error: Error) => void;
29
+ }> {
30
+ private readonly crew;
31
+ private readonly config;
32
+ private readonly events;
33
+ private updateTimer?;
34
+ private lastStatus?;
35
+ private subscribed;
36
+ constructor(crew: Crew, config?: DashboardConfig);
37
+ start(): void;
38
+ stop(): void;
39
+ subscribe(callback: (update: DashboardUpdate) => void): () => void;
40
+ recordEvent(event: CrewEvent): void;
41
+ getCrewStatus(): CrewStatusDetails;
42
+ getAgentStatuses(): Map<string, AgentStatus>;
43
+ getMetrics(): CrewMetrics;
44
+ getTimeline(): TimelineEntry[];
45
+ getEvents(filter?: {
46
+ type?: string;
47
+ agent?: string;
48
+ since?: Date;
49
+ limit?: number;
50
+ }): CrewEvent[];
51
+ getProgress(): {
52
+ percentage: number;
53
+ completedTasks: number;
54
+ totalTasks: number;
55
+ currentTask?: string;
56
+ elapsedTime: number;
57
+ estimatedRemaining?: number;
58
+ };
59
+ getTaskBreakdown(): {
60
+ pending: number;
61
+ inProgress: number;
62
+ completed: number;
63
+ failed: number;
64
+ total: number;
65
+ };
66
+ getAgentBreakdown(): {
67
+ total: number;
68
+ busy: number;
69
+ idle: number;
70
+ performance: Array<{
71
+ name: string;
72
+ completed: number;
73
+ failed: number;
74
+ successRate: number;
75
+ }>;
76
+ };
77
+ private emitUpdate;
78
+ getSnapshot(): DashboardSnapshot;
79
+ }
80
+ interface DashboardSnapshot {
81
+ timestamp: Date;
82
+ status: CrewStatusDetails;
83
+ metrics: CrewMetrics;
84
+ agents: Record<string, AgentStatus>;
85
+ progress: ReturnType<CrewDashboard['getProgress']>;
86
+ taskBreakdown: ReturnType<CrewDashboard['getTaskBreakdown']>;
87
+ agentBreakdown: ReturnType<CrewDashboard['getAgentBreakdown']>;
88
+ recentEvents: CrewEvent[];
89
+ }
90
+ declare function createDashboard(crew: Crew, config?: DashboardConfig): CrewDashboard;
91
+
92
+ type BreakpointType = 'task:assigned' | 'task:started' | 'task:completed' | 'task:failed' | 'agent:thinking' | 'delegation:decision' | 'custom';
93
+ interface Breakpoint {
94
+ id: string;
95
+ type: BreakpointType;
96
+ condition?: (event: CrewEvent, context: DebugContext) => boolean;
97
+ enabled: boolean;
98
+ hitCount: number;
99
+ }
100
+ interface DebugContext {
101
+ currentEvent?: CrewEvent;
102
+ agents: Map<string, AgentInspection>;
103
+ tasks: TaskConfig[];
104
+ variables: Map<string, unknown>;
105
+ callStack: string[];
106
+ }
107
+ interface AgentInspection {
108
+ name: string;
109
+ role: string;
110
+ status: 'idle' | 'busy' | 'paused';
111
+ currentTask?: string;
112
+ lastThought?: string;
113
+ lastToolCall?: {
114
+ tool: string;
115
+ input: unknown;
116
+ output?: unknown;
117
+ };
118
+ memory: Map<string, unknown>;
119
+ }
120
+ interface StepResult {
121
+ event: CrewEvent;
122
+ breakpointHit?: Breakpoint;
123
+ agentStates: Map<string, AgentInspection>;
124
+ continueExecution: boolean;
125
+ }
126
+ interface DebugModeConfig {
127
+ pauseOnError?: boolean;
128
+ verbose?: boolean;
129
+ maxCallStackDepth?: number;
130
+ }
131
+ declare class DebugMode extends EventEmitter<{
132
+ breakpointHit: (breakpoint: Breakpoint, event: CrewEvent) => void;
133
+ step: (result: StepResult) => void;
134
+ error: (error: Error) => void;
135
+ paused: () => void;
136
+ resumed: () => void;
137
+ }> {
138
+ private readonly crew;
139
+ private readonly config;
140
+ private readonly breakpoints;
141
+ private readonly eventQueue;
142
+ private readonly callStack;
143
+ private context;
144
+ private enabled;
145
+ private paused;
146
+ private stepMode;
147
+ private breakpointCounter;
148
+ private resolveStep?;
149
+ constructor(crew: Crew, config?: DebugModeConfig);
150
+ enable(): void;
151
+ disable(): void;
152
+ isEnabled(): boolean;
153
+ setBreakpoint(type: BreakpointType, condition?: (event: CrewEvent, context: DebugContext) => boolean): string;
154
+ removeBreakpoint(id: string): boolean;
155
+ enableBreakpoint(id: string): boolean;
156
+ disableBreakpoint(id: string): boolean;
157
+ getBreakpoints(): Breakpoint[];
158
+ clearBreakpoints(): void;
159
+ step(): Promise<StepResult>;
160
+ continue(): Promise<void>;
161
+ pause(): void;
162
+ resume(): void;
163
+ isPaused(): boolean;
164
+ inspect(agentName: string): AgentInspection | undefined;
165
+ inspectAll(): Map<string, AgentInspection>;
166
+ getContext(): DebugContext;
167
+ getCallStack(): string[];
168
+ evaluate(expression: string): unknown;
169
+ watch(expression: string): {
170
+ expression: string;
171
+ value: unknown;
172
+ };
173
+ handleEvent(event: CrewEvent): void;
174
+ private createContext;
175
+ private updateContext;
176
+ private checkBreakpoints;
177
+ private getAgentStates;
178
+ private createAgentInspection;
179
+ getSummary(): {
180
+ enabled: boolean;
181
+ paused: boolean;
182
+ stepMode: boolean;
183
+ breakpointCount: number;
184
+ queuedEvents: number;
185
+ callStackDepth: number;
186
+ };
187
+ }
188
+ declare function createDebugMode(crew: Crew, config?: DebugModeConfig): DebugMode;
189
+
190
+ export { type AgentInspection as A, type Breakpoint as B, CrewDashboard as C, DebugMode as D, type StepResult as S, type AgentStatus as a, type BreakpointType as b, type DashboardConfig as c, type DashboardSnapshot as d, type DashboardUpdate as e, type DebugContext as f, type DebugModeConfig as g, createDashboard as h, createDebugMode as i };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCrew
3
- } from "./chunk-V6VK6BOL.mjs";
3
+ } from "./chunk-J5KQSOGT.mjs";
4
4
 
5
5
  // src/templates/ResearchCrew.ts
6
6
  var researcherRole = {
@@ -211,8 +211,37 @@ function createRole(config) {
211
211
  return new Role(config);
212
212
  }
213
213
 
214
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
215
+ import { webcrypto as crypto } from "crypto";
216
+
217
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
218
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
219
+
220
+ // ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
221
+ var POOL_SIZE_MULTIPLIER = 128;
222
+ var pool;
223
+ var poolOffset;
224
+ function fillPool(bytes) {
225
+ if (!pool || pool.length < bytes) {
226
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
227
+ crypto.getRandomValues(pool);
228
+ poolOffset = 0;
229
+ } else if (poolOffset + bytes > pool.length) {
230
+ crypto.getRandomValues(pool);
231
+ poolOffset = 0;
232
+ }
233
+ poolOffset += bytes;
234
+ }
235
+ function nanoid(size = 21) {
236
+ fillPool(size |= 0);
237
+ let id = "";
238
+ for (let i = poolOffset - size; i < poolOffset; i++) {
239
+ id += urlAlphabet[pool[i] & 63];
240
+ }
241
+ return id;
242
+ }
243
+
214
244
  // src/core/Task.ts
215
- import { nanoid } from "nanoid";
216
245
  var Task = class _Task {
217
246
  id;
218
247
  description;
@@ -844,7 +873,6 @@ function createTaskQueue(config) {
844
873
 
845
874
  // src/core/ExecutionContext.ts
846
875
  import EventEmitter from "eventemitter3";
847
- import { nanoid as nanoid2 } from "nanoid";
848
876
  var ExecutionContext = class {
849
877
  crewId;
850
878
  crewName;
@@ -861,7 +889,7 @@ var ExecutionContext = class {
861
889
  startTime;
862
890
  endTime;
863
891
  constructor(config) {
864
- this.crewId = config.crewId ?? nanoid2();
892
+ this.crewId = config.crewId ?? nanoid();
865
893
  this.crewName = config.crewName;
866
894
  this.state = /* @__PURE__ */ new Map();
867
895
  this.completedTasks = /* @__PURE__ */ new Map();
@@ -1107,7 +1135,7 @@ var ExecutionContext = class {
1107
1135
  */
1108
1136
  createCheckpoint() {
1109
1137
  return {
1110
- id: nanoid2(),
1138
+ id: nanoid(),
1111
1139
  timestamp: /* @__PURE__ */ new Date(),
1112
1140
  crewId: this.crewId,
1113
1141
  crewName: this.crewName,
@@ -1450,7 +1478,6 @@ function createCoreExecutor(config, options = {}) {
1450
1478
  }
1451
1479
 
1452
1480
  // src/agents/CrewAgent.ts
1453
- import { nanoid as nanoid3 } from "nanoid";
1454
1481
  function modelCostWeight(model) {
1455
1482
  const m = (model ?? "").toLowerCase();
1456
1483
  if (m.includes("opus") || m.includes("gpt-5") || m.includes("o3")) return 5;
@@ -1481,7 +1508,7 @@ var CrewAgent = class _CrewAgent {
1481
1508
  totalTokensUsed = 0;
1482
1509
  constructor(options) {
1483
1510
  const { config, execute } = options;
1484
- this.id = nanoid3();
1511
+ this.id = nanoid();
1485
1512
  this.name = config.name;
1486
1513
  this.role = new Role(config.role);
1487
1514
  this.capabilities = config.role.capabilities;
@@ -1678,7 +1705,7 @@ ${JSON.stringify(task.context, null, 2)}`);
1678
1705
  */
1679
1706
  createHelpRequest(taskId, request) {
1680
1707
  return {
1681
- requestId: nanoid3(),
1708
+ requestId: nanoid(),
1682
1709
  fromAgent: this.name,
1683
1710
  taskId,
1684
1711
  request
@@ -4131,7 +4158,6 @@ function createConflictResolver(config) {
4131
4158
  }
4132
4159
 
4133
4160
  // src/core/Crew.ts
4134
- import { nanoid as nanoid4 } from "nanoid";
4135
4161
  var Crew = class {
4136
4162
  id;
4137
4163
  name;
@@ -4151,7 +4177,7 @@ var Crew = class {
4151
4177
  timeline = [];
4152
4178
  results = /* @__PURE__ */ new Map();
4153
4179
  constructor(config) {
4154
- this.id = nanoid4();
4180
+ this.id = nanoid();
4155
4181
  this.name = config.name;
4156
4182
  this.description = config.description;
4157
4183
  this.config = config;
@@ -4300,27 +4326,40 @@ var Crew = class {
4300
4326
  await this.sleep(100);
4301
4327
  continue;
4302
4328
  }
4303
- for (const task of readyTasks) {
4304
- if (this.state !== "running") break;
4305
- const delegationResult = await this.delegateTask(task, options);
4306
- yield this.createEvent({
4307
- type: "task:assigned",
4308
- taskId: task.id,
4309
- agentName: delegationResult.selectedAgent,
4310
- reason: delegationResult.reason,
4311
- strategy: this.config.delegationStrategy
4312
- });
4313
- const taskResult = await this.executeTask(task, delegationResult);
4314
- yield this.createEvent({
4315
- type: "task:completed",
4316
- taskId: task.id,
4317
- result: taskResult,
4318
- agentName: delegationResult.selectedAgent,
4319
- durationMs: taskResult.latencyMs ?? 0
4320
- });
4321
- while (eventQueue.length > 0) {
4322
- yield eventQueue.shift();
4329
+ const concurrency = Math.max(
4330
+ 1,
4331
+ options.maxConcurrentTasks ?? this.config.maxConcurrentTasks ?? 1
4332
+ );
4333
+ if (concurrency === 1) {
4334
+ for (const task of readyTasks) {
4335
+ if (this.state !== "running") break;
4336
+ const delegationResult = await this.delegateTask(task, options);
4337
+ yield this.createEvent({
4338
+ type: "task:assigned",
4339
+ taskId: task.id,
4340
+ agentName: delegationResult.selectedAgent,
4341
+ reason: delegationResult.reason,
4342
+ strategy: this.config.delegationStrategy
4343
+ });
4344
+ const taskResult = await this.executeTask(task, delegationResult);
4345
+ yield this.createEvent({
4346
+ type: "task:completed",
4347
+ taskId: task.id,
4348
+ result: taskResult,
4349
+ agentName: delegationResult.selectedAgent,
4350
+ durationMs: taskResult.latencyMs ?? 0
4351
+ });
4352
+ while (eventQueue.length > 0) {
4353
+ yield eventQueue.shift();
4354
+ }
4323
4355
  }
4356
+ } else {
4357
+ yield* this.processReadyTasksConcurrently(
4358
+ readyTasks,
4359
+ options,
4360
+ eventQueue,
4361
+ concurrency
4362
+ );
4324
4363
  }
4325
4364
  while (this.state === "paused") {
4326
4365
  await this.sleep(100);
@@ -4363,6 +4402,78 @@ var Crew = class {
4363
4402
  });
4364
4403
  this.addTimelineEntry("crew_completed", this.name);
4365
4404
  }
4405
+ /**
4406
+ * Execute a batch of ready tasks concurrently with a bounded worker pool.
4407
+ *
4408
+ * Each task still emits its `task:assigned` and `task:completed` events in
4409
+ * order relative to itself, but events across tasks are interleaved as the
4410
+ * workers settle. At most `concurrency` tasks run at once. If any task throws
4411
+ * (after exhausting retries), no further tasks are started, in-flight tasks
4412
+ * are allowed to settle, and the first error is rethrown so the caller's
4413
+ * error handling (crew:error) behaves identically to the sequential path.
4414
+ */
4415
+ async *processReadyTasksConcurrently(readyTasks, options, eventQueue, concurrency) {
4416
+ let nextIndex = 0;
4417
+ let firstError;
4418
+ const buffer = [];
4419
+ const inFlight = /* @__PURE__ */ new Set();
4420
+ const launch = (task) => {
4421
+ const worker = (async () => {
4422
+ const delegationResult = await this.delegateTask(task, options);
4423
+ buffer.push(
4424
+ this.createEvent({
4425
+ type: "task:assigned",
4426
+ taskId: task.id,
4427
+ agentName: delegationResult.selectedAgent,
4428
+ reason: delegationResult.reason,
4429
+ strategy: this.config.delegationStrategy
4430
+ })
4431
+ );
4432
+ const taskResult = await this.executeTask(task, delegationResult);
4433
+ buffer.push(
4434
+ this.createEvent({
4435
+ type: "task:completed",
4436
+ taskId: task.id,
4437
+ result: taskResult,
4438
+ agentName: delegationResult.selectedAgent,
4439
+ durationMs: taskResult.latencyMs ?? 0
4440
+ })
4441
+ );
4442
+ })().catch((error) => {
4443
+ if (firstError === void 0) {
4444
+ firstError = error;
4445
+ }
4446
+ }).finally(() => {
4447
+ inFlight.delete(worker);
4448
+ });
4449
+ inFlight.add(worker);
4450
+ };
4451
+ const fill = () => {
4452
+ while (inFlight.size < concurrency && nextIndex < readyTasks.length && this.state === "running" && firstError === void 0) {
4453
+ launch(readyTasks[nextIndex++]);
4454
+ }
4455
+ };
4456
+ fill();
4457
+ while (inFlight.size > 0) {
4458
+ await Promise.race(inFlight);
4459
+ while (buffer.length > 0) {
4460
+ yield buffer.shift();
4461
+ }
4462
+ while (eventQueue.length > 0) {
4463
+ yield eventQueue.shift();
4464
+ }
4465
+ fill();
4466
+ }
4467
+ while (buffer.length > 0) {
4468
+ yield buffer.shift();
4469
+ }
4470
+ while (eventQueue.length > 0) {
4471
+ yield eventQueue.shift();
4472
+ }
4473
+ if (firstError !== void 0) {
4474
+ throw firstError;
4475
+ }
4476
+ }
4366
4477
  /**
4367
4478
  * Delegate a task to an agent
4368
4479
  */
@@ -4582,7 +4693,7 @@ ${r.output}`).join("\n\n---\n\n");
4582
4693
  */
4583
4694
  createCheckpoint() {
4584
4695
  return {
4585
- id: nanoid4(),
4696
+ id: nanoid(),
4586
4697
  crewId: this.id,
4587
4698
  crewName: this.name,
4588
4699
  timestamp: /* @__PURE__ */ new Date(),
@@ -4680,6 +4791,7 @@ function createCrew(config) {
4680
4791
  export {
4681
4792
  Role,
4682
4793
  createRole,
4794
+ nanoid,
4683
4795
  Task,
4684
4796
  createTask,
4685
4797
  TaskQueue,