@lov3kaizen/agentsea-crews 0.5.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.
- package/LICENSE +21 -0
- package/README.md +325 -0
- package/dist/chunk-4PF73ECN.mjs +587 -0
- package/dist/chunk-G3PAPYOI.mjs +1070 -0
- package/dist/chunk-QMK3HWFX.mjs +4584 -0
- package/dist/index.js +8761 -0
- package/dist/index.mjs +2528 -0
- package/dist/nestjs/index.js +5589 -0
- package/dist/nestjs/index.mjs +453 -0
- package/dist/templates/index.js +5625 -0
- package/dist/templates/index.mjs +29 -0
- package/package.json +89 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CrewDashboard,
|
|
3
|
+
DebugMode
|
|
4
|
+
} from "../chunk-4PF73ECN.mjs";
|
|
5
|
+
import {
|
|
6
|
+
createCrew
|
|
7
|
+
} from "../chunk-QMK3HWFX.mjs";
|
|
8
|
+
|
|
9
|
+
// src/nestjs/crews.module.ts
|
|
10
|
+
var CREWS_MODULE_OPTIONS = "CREWS_MODULE_OPTIONS";
|
|
11
|
+
var CREWS_SERVICE = "CREWS_SERVICE";
|
|
12
|
+
var CrewsModule = class _CrewsModule {
|
|
13
|
+
/**
|
|
14
|
+
* Configure module with static options
|
|
15
|
+
*/
|
|
16
|
+
static forRoot(options = {}) {
|
|
17
|
+
const providers = this.createProviders(options);
|
|
18
|
+
return {
|
|
19
|
+
module: _CrewsModule,
|
|
20
|
+
global: options.global ?? false,
|
|
21
|
+
providers,
|
|
22
|
+
exports: providers
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Configure module with async options
|
|
27
|
+
*/
|
|
28
|
+
static forRootAsync(options) {
|
|
29
|
+
const providers = this.createAsyncProviders(options);
|
|
30
|
+
return {
|
|
31
|
+
module: _CrewsModule,
|
|
32
|
+
imports: options.imports ?? [],
|
|
33
|
+
global: options.global ?? false,
|
|
34
|
+
providers,
|
|
35
|
+
exports: providers
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register crew configurations
|
|
40
|
+
*/
|
|
41
|
+
static forFeature(crews) {
|
|
42
|
+
const providers = crews.map((config) => ({
|
|
43
|
+
provide: `CREW_${config.name.toUpperCase().replace(/-/g, "_")}`,
|
|
44
|
+
useValue: config
|
|
45
|
+
}));
|
|
46
|
+
return {
|
|
47
|
+
module: _CrewsModule,
|
|
48
|
+
providers,
|
|
49
|
+
exports: providers
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create providers from static options
|
|
54
|
+
*/
|
|
55
|
+
static createProviders(options) {
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
provide: CREWS_MODULE_OPTIONS,
|
|
59
|
+
useValue: options
|
|
60
|
+
},
|
|
61
|
+
// Crew configurations
|
|
62
|
+
...(options.crews ?? []).map((config) => ({
|
|
63
|
+
provide: `CREW_CONFIG_${config.name.toUpperCase().replace(/-/g, "_")}`,
|
|
64
|
+
useValue: config
|
|
65
|
+
}))
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create providers from async options
|
|
70
|
+
*/
|
|
71
|
+
static createAsyncProviders(options) {
|
|
72
|
+
const providers = [];
|
|
73
|
+
if (options.useFactory) {
|
|
74
|
+
providers.push({
|
|
75
|
+
provide: CREWS_MODULE_OPTIONS,
|
|
76
|
+
useFactory: options.useFactory,
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
78
|
+
inject: options.inject ?? []
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return providers;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/nestjs/crews.service.ts
|
|
86
|
+
var CrewsService = class {
|
|
87
|
+
crews = /* @__PURE__ */ new Map();
|
|
88
|
+
options;
|
|
89
|
+
constructor(options = {}) {
|
|
90
|
+
this.options = options;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Initialize module
|
|
94
|
+
*/
|
|
95
|
+
async onModuleInit() {
|
|
96
|
+
for (const config of this.options.crews ?? []) {
|
|
97
|
+
await this.registerCrew(config);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Cleanup on module destroy
|
|
102
|
+
*/
|
|
103
|
+
onModuleDestroy() {
|
|
104
|
+
for (const managed of this.crews.values()) {
|
|
105
|
+
if (managed.crew.getStatus().state === "running") {
|
|
106
|
+
managed.crew.abort();
|
|
107
|
+
}
|
|
108
|
+
managed.dashboard?.stop();
|
|
109
|
+
}
|
|
110
|
+
this.crews.clear();
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
// ============ Crew Management ============
|
|
114
|
+
/**
|
|
115
|
+
* Register a crew
|
|
116
|
+
*/
|
|
117
|
+
registerCrew(config) {
|
|
118
|
+
if (this.crews.has(config.name)) {
|
|
119
|
+
throw new Error(`Crew already registered: ${config.name}`);
|
|
120
|
+
}
|
|
121
|
+
const crew = createCrew({
|
|
122
|
+
...config,
|
|
123
|
+
delegationStrategy: config.delegationStrategy ?? this.options.defaultStrategy
|
|
124
|
+
});
|
|
125
|
+
const managed = { crew };
|
|
126
|
+
if (this.options.enableMonitoring) {
|
|
127
|
+
managed.dashboard = new CrewDashboard(crew);
|
|
128
|
+
managed.dashboard.start();
|
|
129
|
+
}
|
|
130
|
+
if (this.options.enableDebug) {
|
|
131
|
+
managed.debugMode = new DebugMode(crew);
|
|
132
|
+
managed.debugMode.enable();
|
|
133
|
+
}
|
|
134
|
+
this.crews.set(config.name, managed);
|
|
135
|
+
return Promise.resolve(crew);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Unregister a crew
|
|
139
|
+
*/
|
|
140
|
+
unregisterCrew(name) {
|
|
141
|
+
const managed = this.crews.get(name);
|
|
142
|
+
if (!managed) return false;
|
|
143
|
+
managed.dashboard?.stop();
|
|
144
|
+
managed.debugMode?.disable();
|
|
145
|
+
return this.crews.delete(name);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get a crew by name
|
|
149
|
+
*/
|
|
150
|
+
getCrew(name) {
|
|
151
|
+
return this.crews.get(name)?.crew;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get all crew names
|
|
155
|
+
*/
|
|
156
|
+
getCrewNames() {
|
|
157
|
+
return Array.from(this.crews.keys());
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if crew exists
|
|
161
|
+
*/
|
|
162
|
+
hasCrew(name) {
|
|
163
|
+
return this.crews.has(name);
|
|
164
|
+
}
|
|
165
|
+
// ============ Execution ============
|
|
166
|
+
/**
|
|
167
|
+
* Run a crew
|
|
168
|
+
*/
|
|
169
|
+
async runCrew(name, options) {
|
|
170
|
+
const crew = this.getCrew(name);
|
|
171
|
+
if (!crew) {
|
|
172
|
+
throw new Error(`Crew not found: ${name}`);
|
|
173
|
+
}
|
|
174
|
+
return crew.kickoff(options);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Run a crew with streaming
|
|
178
|
+
*/
|
|
179
|
+
async *runCrewStream(name, options) {
|
|
180
|
+
const crew = this.getCrew(name);
|
|
181
|
+
if (!crew) {
|
|
182
|
+
throw new Error(`Crew not found: ${name}`);
|
|
183
|
+
}
|
|
184
|
+
yield* crew.kickoffStream(options);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Run crew with callback for events
|
|
188
|
+
*/
|
|
189
|
+
async runCrewWithCallback(name, onEvent, options) {
|
|
190
|
+
const crew = this.getCrew(name);
|
|
191
|
+
if (!crew) {
|
|
192
|
+
throw new Error(`Crew not found: ${name}`);
|
|
193
|
+
}
|
|
194
|
+
const events = [];
|
|
195
|
+
for await (const event of crew.kickoffStream(options)) {
|
|
196
|
+
events.push(event);
|
|
197
|
+
onEvent(event);
|
|
198
|
+
}
|
|
199
|
+
const taskResults = Array.from(crew.getTasks()).filter((t) => t.getState().result).map((t) => t.getState().result);
|
|
200
|
+
return {
|
|
201
|
+
success: crew.getStatus().state === "completed",
|
|
202
|
+
taskResults,
|
|
203
|
+
metrics: crew.getMetrics(),
|
|
204
|
+
timeline: crew.getTimeline(),
|
|
205
|
+
finalOutput: taskResults.map((r) => r.output).join("\n\n"),
|
|
206
|
+
events
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// ============ Control ============
|
|
210
|
+
/**
|
|
211
|
+
* Pause a crew
|
|
212
|
+
*/
|
|
213
|
+
pauseCrew(name) {
|
|
214
|
+
const crew = this.getCrew(name);
|
|
215
|
+
if (!crew) {
|
|
216
|
+
throw new Error(`Crew not found: ${name}`);
|
|
217
|
+
}
|
|
218
|
+
crew.pause();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resume a crew
|
|
222
|
+
*/
|
|
223
|
+
resumeCrew(name) {
|
|
224
|
+
const crew = this.getCrew(name);
|
|
225
|
+
if (!crew) {
|
|
226
|
+
throw new Error(`Crew not found: ${name}`);
|
|
227
|
+
}
|
|
228
|
+
crew.resume();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Abort a crew
|
|
232
|
+
*/
|
|
233
|
+
abortCrew(name) {
|
|
234
|
+
const crew = this.getCrew(name);
|
|
235
|
+
if (!crew) {
|
|
236
|
+
throw new Error(`Crew not found: ${name}`);
|
|
237
|
+
}
|
|
238
|
+
crew.abort();
|
|
239
|
+
}
|
|
240
|
+
// ============ Monitoring ============
|
|
241
|
+
/**
|
|
242
|
+
* Get dashboard for a crew
|
|
243
|
+
*/
|
|
244
|
+
getDashboard(name) {
|
|
245
|
+
return this.crews.get(name)?.dashboard;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get debug mode for a crew
|
|
249
|
+
*/
|
|
250
|
+
getDebugMode(name) {
|
|
251
|
+
return this.crews.get(name)?.debugMode;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get crew status
|
|
255
|
+
*/
|
|
256
|
+
getCrewStatus(name) {
|
|
257
|
+
return this.getCrew(name)?.getStatus();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get crew metrics
|
|
261
|
+
*/
|
|
262
|
+
getCrewMetrics(name) {
|
|
263
|
+
return this.getCrew(name)?.getMetrics();
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get all crews status
|
|
267
|
+
*/
|
|
268
|
+
getAllStatus() {
|
|
269
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
270
|
+
for (const [name, managed] of this.crews) {
|
|
271
|
+
statuses.set(name, managed.crew.getStatus());
|
|
272
|
+
}
|
|
273
|
+
return statuses;
|
|
274
|
+
}
|
|
275
|
+
// ============ Health ============
|
|
276
|
+
/**
|
|
277
|
+
* Health check
|
|
278
|
+
*/
|
|
279
|
+
healthCheck() {
|
|
280
|
+
const crewsHealth = [];
|
|
281
|
+
let allHealthy = true;
|
|
282
|
+
for (const [name, managed] of this.crews) {
|
|
283
|
+
const status = managed.crew.getStatus();
|
|
284
|
+
const healthy = status.state !== "failed";
|
|
285
|
+
crewsHealth.push({
|
|
286
|
+
name,
|
|
287
|
+
status: status.state,
|
|
288
|
+
healthy
|
|
289
|
+
});
|
|
290
|
+
if (!healthy) {
|
|
291
|
+
allHealthy = false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return Promise.resolve({
|
|
295
|
+
healthy: allHealthy,
|
|
296
|
+
crews: crewsHealth
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
function createCrewsService(options) {
|
|
301
|
+
return new CrewsService(options);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/nestjs/decorators.ts
|
|
305
|
+
import "reflect-metadata";
|
|
306
|
+
var CREW_METADATA = "crews:crew";
|
|
307
|
+
var ROLE_METADATA = "crews:role";
|
|
308
|
+
var TASK_METADATA = "crews:task";
|
|
309
|
+
var ON_CREW_EVENT_METADATA = "crews:on_event";
|
|
310
|
+
var INJECT_CREW_METADATA = "crews:inject_crew";
|
|
311
|
+
function CrewDef(config) {
|
|
312
|
+
return (target) => {
|
|
313
|
+
Reflect.defineMetadata(CREW_METADATA, config, target);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function RoleDef(config) {
|
|
317
|
+
return (target, propertyKey) => {
|
|
318
|
+
const existingRoles = Reflect.getMetadata(ROLE_METADATA, target.constructor) || [];
|
|
319
|
+
existingRoles.push({
|
|
320
|
+
propertyKey,
|
|
321
|
+
config
|
|
322
|
+
});
|
|
323
|
+
Reflect.defineMetadata(ROLE_METADATA, existingRoles, target.constructor);
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function TaskDef(config) {
|
|
327
|
+
return (target, propertyKey, descriptor) => {
|
|
328
|
+
const existingTasks = Reflect.getMetadata(TASK_METADATA, target.constructor) || [];
|
|
329
|
+
existingTasks.push({
|
|
330
|
+
methodKey: propertyKey,
|
|
331
|
+
config,
|
|
332
|
+
handler: descriptor.value
|
|
333
|
+
});
|
|
334
|
+
Reflect.defineMetadata(TASK_METADATA, existingTasks, target.constructor);
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function OnCrewEvent(eventType) {
|
|
338
|
+
return (target, propertyKey, descriptor) => {
|
|
339
|
+
const existingHandlers = Reflect.getMetadata(ON_CREW_EVENT_METADATA, target.constructor) || [];
|
|
340
|
+
existingHandlers.push({
|
|
341
|
+
eventType,
|
|
342
|
+
methodKey: propertyKey,
|
|
343
|
+
handler: descriptor.value
|
|
344
|
+
});
|
|
345
|
+
Reflect.defineMetadata(
|
|
346
|
+
ON_CREW_EVENT_METADATA,
|
|
347
|
+
existingHandlers,
|
|
348
|
+
target.constructor
|
|
349
|
+
);
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function InjectCrew(name) {
|
|
353
|
+
return (target, propertyKey, parameterIndex) => {
|
|
354
|
+
const existingInjections = Reflect.getMetadata(INJECT_CREW_METADATA, target) || [];
|
|
355
|
+
existingInjections.push({
|
|
356
|
+
index: parameterIndex,
|
|
357
|
+
name
|
|
358
|
+
});
|
|
359
|
+
Reflect.defineMetadata(INJECT_CREW_METADATA, existingInjections, target);
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function getCrewMetadata(target) {
|
|
363
|
+
return Reflect.getMetadata(CREW_METADATA, target);
|
|
364
|
+
}
|
|
365
|
+
function getRoleMetadata(target) {
|
|
366
|
+
return Reflect.getMetadata(ROLE_METADATA, target) || [];
|
|
367
|
+
}
|
|
368
|
+
function getTaskMetadata(target) {
|
|
369
|
+
return Reflect.getMetadata(TASK_METADATA, target) || [];
|
|
370
|
+
}
|
|
371
|
+
function getEventHandlerMetadata(target) {
|
|
372
|
+
return Reflect.getMetadata(ON_CREW_EVENT_METADATA, target) || [];
|
|
373
|
+
}
|
|
374
|
+
function getInjectCrewMetadata(target) {
|
|
375
|
+
return Reflect.getMetadata(INJECT_CREW_METADATA, target) || [];
|
|
376
|
+
}
|
|
377
|
+
function RequireCapability(...capabilities) {
|
|
378
|
+
return (target, propertyKey) => {
|
|
379
|
+
const existing = Reflect.getMetadata("crews:required_capabilities", target.constructor) || {};
|
|
380
|
+
existing[propertyKey] = capabilities;
|
|
381
|
+
Reflect.defineMetadata(
|
|
382
|
+
"crews:required_capabilities",
|
|
383
|
+
existing,
|
|
384
|
+
target.constructor
|
|
385
|
+
);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function Priority(priority) {
|
|
389
|
+
return (target, propertyKey) => {
|
|
390
|
+
const existing = Reflect.getMetadata("crews:task_priority", target.constructor) || {};
|
|
391
|
+
existing[propertyKey] = priority;
|
|
392
|
+
Reflect.defineMetadata("crews:task_priority", existing, target.constructor);
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function Timeout(ms) {
|
|
396
|
+
return (target, propertyKey) => {
|
|
397
|
+
const existing = Reflect.getMetadata("crews:task_timeout", target.constructor) || {};
|
|
398
|
+
existing[propertyKey] = ms;
|
|
399
|
+
Reflect.defineMetadata("crews:task_timeout", existing, target.constructor);
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function Retry(maxRetries) {
|
|
403
|
+
return (target, propertyKey) => {
|
|
404
|
+
const existing = Reflect.getMetadata("crews:task_retries", target.constructor) || {};
|
|
405
|
+
existing[propertyKey] = maxRetries;
|
|
406
|
+
Reflect.defineMetadata("crews:task_retries", existing, target.constructor);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function DependsOn(...taskNames) {
|
|
410
|
+
return (target, propertyKey) => {
|
|
411
|
+
const existing = Reflect.getMetadata("crews:task_dependencies", target.constructor) || {};
|
|
412
|
+
existing[propertyKey] = taskNames;
|
|
413
|
+
Reflect.defineMetadata(
|
|
414
|
+
"crews:task_dependencies",
|
|
415
|
+
existing,
|
|
416
|
+
target.constructor
|
|
417
|
+
);
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function AssignTo(agentName) {
|
|
421
|
+
return (target, propertyKey) => {
|
|
422
|
+
const existing = Reflect.getMetadata("crews:task_assignment", target.constructor) || {};
|
|
423
|
+
existing[propertyKey] = agentName;
|
|
424
|
+
Reflect.defineMetadata(
|
|
425
|
+
"crews:task_assignment",
|
|
426
|
+
existing,
|
|
427
|
+
target.constructor
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
export {
|
|
432
|
+
AssignTo,
|
|
433
|
+
CREWS_MODULE_OPTIONS,
|
|
434
|
+
CREWS_SERVICE,
|
|
435
|
+
CrewDef,
|
|
436
|
+
CrewsModule,
|
|
437
|
+
CrewsService,
|
|
438
|
+
DependsOn,
|
|
439
|
+
InjectCrew,
|
|
440
|
+
OnCrewEvent,
|
|
441
|
+
Priority,
|
|
442
|
+
RequireCapability,
|
|
443
|
+
Retry,
|
|
444
|
+
RoleDef,
|
|
445
|
+
TaskDef,
|
|
446
|
+
Timeout,
|
|
447
|
+
createCrewsService,
|
|
448
|
+
getCrewMetadata,
|
|
449
|
+
getEventHandlerMetadata,
|
|
450
|
+
getInjectCrewMetadata,
|
|
451
|
+
getRoleMetadata,
|
|
452
|
+
getTaskMetadata
|
|
453
|
+
};
|