@lov3kaizen/agentsea-crews 1.0.1 → 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.
- package/README.md +56 -0
- package/dist/Crew-BnvVjN7A.d.mts +1060 -0
- package/dist/Crew-BnvVjN7A.d.ts +1060 -0
- package/dist/DebugMode-CbYgA7Yw.d.mts +190 -0
- package/dist/DebugMode-o5e9gmQ7.d.ts +190 -0
- package/dist/{chunk-TFB7N65B.mjs → chunk-3NMVWRVW.mjs} +1 -1
- package/dist/{chunk-QMK3HWFX.mjs → chunk-J5KQSOGT.mjs} +306 -61
- package/dist/index.d.mts +975 -0
- package/dist/index.d.ts +975 -0
- package/dist/index.js +335 -96
- package/dist/index.mjs +26 -25
- package/dist/nestjs/index.d.mts +98 -0
- package/dist/nestjs/index.d.ts +98 -0
- package/dist/nestjs/index.js +305 -66
- package/dist/nestjs/index.mjs +1 -1
- package/dist/templates/index.d.mts +78 -0
- package/dist/templates/index.d.ts +78 -0
- package/dist/templates/index.js +305 -66
- package/dist/templates/index.mjs +2 -2
- package/package.json +6 -6
package/dist/nestjs/index.js
CHANGED
|
@@ -340,8 +340,37 @@ Background: ${this.backstory}`);
|
|
|
340
340
|
}
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
+
// ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
|
|
344
|
+
var import_node_crypto = require("crypto");
|
|
345
|
+
|
|
346
|
+
// ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
|
|
347
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
348
|
+
|
|
349
|
+
// ../../node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
|
|
350
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
351
|
+
var pool;
|
|
352
|
+
var poolOffset;
|
|
353
|
+
function fillPool(bytes) {
|
|
354
|
+
if (!pool || pool.length < bytes) {
|
|
355
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
356
|
+
import_node_crypto.webcrypto.getRandomValues(pool);
|
|
357
|
+
poolOffset = 0;
|
|
358
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
359
|
+
import_node_crypto.webcrypto.getRandomValues(pool);
|
|
360
|
+
poolOffset = 0;
|
|
361
|
+
}
|
|
362
|
+
poolOffset += bytes;
|
|
363
|
+
}
|
|
364
|
+
function nanoid(size = 21) {
|
|
365
|
+
fillPool(size |= 0);
|
|
366
|
+
let id = "";
|
|
367
|
+
for (let i = poolOffset - size; i < poolOffset; i++) {
|
|
368
|
+
id += urlAlphabet[pool[i] & 63];
|
|
369
|
+
}
|
|
370
|
+
return id;
|
|
371
|
+
}
|
|
372
|
+
|
|
343
373
|
// src/core/Task.ts
|
|
344
|
-
var import_nanoid = require("nanoid");
|
|
345
374
|
var Task = class _Task {
|
|
346
375
|
id;
|
|
347
376
|
description;
|
|
@@ -361,7 +390,7 @@ var Task = class _Task {
|
|
|
361
390
|
_result;
|
|
362
391
|
_metadata;
|
|
363
392
|
constructor(config) {
|
|
364
|
-
this.id = config.id ??
|
|
393
|
+
this.id = config.id ?? nanoid();
|
|
365
394
|
this.description = config.description;
|
|
366
395
|
this.expectedOutput = config.expectedOutput;
|
|
367
396
|
this.priority = config.priority ?? "medium";
|
|
@@ -967,7 +996,6 @@ var TaskQueue = class {
|
|
|
967
996
|
|
|
968
997
|
// src/core/ExecutionContext.ts
|
|
969
998
|
var import_eventemitter3 = __toESM(require("eventemitter3"));
|
|
970
|
-
var import_nanoid2 = require("nanoid");
|
|
971
999
|
var ExecutionContext = class {
|
|
972
1000
|
crewId;
|
|
973
1001
|
crewName;
|
|
@@ -984,7 +1012,7 @@ var ExecutionContext = class {
|
|
|
984
1012
|
startTime;
|
|
985
1013
|
endTime;
|
|
986
1014
|
constructor(config) {
|
|
987
|
-
this.crewId = config.crewId ??
|
|
1015
|
+
this.crewId = config.crewId ?? nanoid();
|
|
988
1016
|
this.crewName = config.crewName;
|
|
989
1017
|
this.state = /* @__PURE__ */ new Map();
|
|
990
1018
|
this.completedTasks = /* @__PURE__ */ new Map();
|
|
@@ -1230,7 +1258,7 @@ var ExecutionContext = class {
|
|
|
1230
1258
|
*/
|
|
1231
1259
|
createCheckpoint() {
|
|
1232
1260
|
return {
|
|
1233
|
-
id:
|
|
1261
|
+
id: nanoid(),
|
|
1234
1262
|
timestamp: /* @__PURE__ */ new Date(),
|
|
1235
1263
|
crewId: this.crewId,
|
|
1236
1264
|
crewName: this.crewName,
|
|
@@ -1316,12 +1344,6 @@ var ExecutionContext = class {
|
|
|
1316
1344
|
}
|
|
1317
1345
|
};
|
|
1318
1346
|
|
|
1319
|
-
// src/core/Crew.ts
|
|
1320
|
-
var import_nanoid4 = require("nanoid");
|
|
1321
|
-
|
|
1322
|
-
// src/agents/CrewAgent.ts
|
|
1323
|
-
var import_nanoid3 = require("nanoid");
|
|
1324
|
-
|
|
1325
1347
|
// src/agents/AgentCapabilities.ts
|
|
1326
1348
|
var PROFICIENCY_WEIGHTS = {
|
|
1327
1349
|
novice: 0.25,
|
|
@@ -1513,7 +1535,80 @@ var AgentCapabilities = class {
|
|
|
1513
1535
|
}
|
|
1514
1536
|
};
|
|
1515
1537
|
|
|
1538
|
+
// src/agents/CoreExecutor.ts
|
|
1539
|
+
async function loadProvider(providerName) {
|
|
1540
|
+
const ctorName = resolveProviderCtorName(providerName);
|
|
1541
|
+
let core;
|
|
1542
|
+
try {
|
|
1543
|
+
core = await import("@lov3kaizen/agentsea-core");
|
|
1544
|
+
} catch {
|
|
1545
|
+
throw new Error(
|
|
1546
|
+
'CrewAgent requires "@lov3kaizen/agentsea-core" to execute against a real LLM. Install it, or pass a custom `execute` function (or `mock: true`) to createCrewAgent / createCrew.'
|
|
1547
|
+
);
|
|
1548
|
+
}
|
|
1549
|
+
const Ctor = core[ctorName];
|
|
1550
|
+
return new Ctor();
|
|
1551
|
+
}
|
|
1552
|
+
function resolveProviderCtorName(providerName) {
|
|
1553
|
+
switch ((providerName ?? "").toLowerCase()) {
|
|
1554
|
+
case "anthropic":
|
|
1555
|
+
case "claude":
|
|
1556
|
+
return "AnthropicProvider";
|
|
1557
|
+
case "openai":
|
|
1558
|
+
case "gpt":
|
|
1559
|
+
return "OpenAIProvider";
|
|
1560
|
+
case "gemini":
|
|
1561
|
+
case "google":
|
|
1562
|
+
return "GeminiProvider";
|
|
1563
|
+
case "ollama":
|
|
1564
|
+
return "OllamaProvider";
|
|
1565
|
+
default:
|
|
1566
|
+
throw new Error(
|
|
1567
|
+
`CrewAgent: unsupported provider "${providerName}". Supported providers are: anthropic, openai, gemini, ollama. Pass a custom \`execute\` function to createCrewAgent for any other provider.`
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
function createCoreExecutor(config, options = {}) {
|
|
1572
|
+
let providerPromise;
|
|
1573
|
+
const getProvider = () => {
|
|
1574
|
+
if (!providerPromise) {
|
|
1575
|
+
providerPromise = options.provider ? Promise.resolve(options.provider) : loadProvider(config.provider);
|
|
1576
|
+
}
|
|
1577
|
+
return providerPromise;
|
|
1578
|
+
};
|
|
1579
|
+
return async (input, systemPrompt) => {
|
|
1580
|
+
const provider = await getProvider();
|
|
1581
|
+
const start = Date.now();
|
|
1582
|
+
const response = await provider.generateResponse(
|
|
1583
|
+
[{ role: "user", content: input }],
|
|
1584
|
+
{
|
|
1585
|
+
model: config.model,
|
|
1586
|
+
systemPrompt,
|
|
1587
|
+
temperature: config.temperature,
|
|
1588
|
+
maxTokens: config.maxTokens
|
|
1589
|
+
}
|
|
1590
|
+
);
|
|
1591
|
+
return {
|
|
1592
|
+
output: response.content,
|
|
1593
|
+
tokensUsed: response.usage.inputTokens + response.usage.outputTokens,
|
|
1594
|
+
latencyMs: Date.now() - start,
|
|
1595
|
+
iterations: 1
|
|
1596
|
+
};
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1516
1600
|
// src/agents/CrewAgent.ts
|
|
1601
|
+
function modelCostWeight(model) {
|
|
1602
|
+
const m = (model ?? "").toLowerCase();
|
|
1603
|
+
if (m.includes("opus") || m.includes("gpt-5") || m.includes("o3")) return 5;
|
|
1604
|
+
if (m.includes("sonnet") || m.includes("gpt-4.1") || m.includes("gpt-4") && !m.includes("mini") || m.includes("gemini-1.5-pro") || m.includes("gemini-2.5-pro")) {
|
|
1605
|
+
return 3;
|
|
1606
|
+
}
|
|
1607
|
+
if (m.includes("haiku") || m.includes("mini") || m.includes("flash") || m.includes("llama") || m.includes("mistral")) {
|
|
1608
|
+
return 1;
|
|
1609
|
+
}
|
|
1610
|
+
return 3;
|
|
1611
|
+
}
|
|
1517
1612
|
var CrewAgent = class _CrewAgent {
|
|
1518
1613
|
id;
|
|
1519
1614
|
name;
|
|
@@ -1533,7 +1628,7 @@ var CrewAgent = class _CrewAgent {
|
|
|
1533
1628
|
totalTokensUsed = 0;
|
|
1534
1629
|
constructor(options) {
|
|
1535
1630
|
const { config, execute } = options;
|
|
1536
|
-
this.id =
|
|
1631
|
+
this.id = nanoid();
|
|
1537
1632
|
this.name = config.name;
|
|
1538
1633
|
this.role = new Role(config.role);
|
|
1539
1634
|
this.capabilities = config.role.capabilities;
|
|
@@ -1552,10 +1647,11 @@ var CrewAgent = class _CrewAgent {
|
|
|
1552
1647
|
*/
|
|
1553
1648
|
async execute(input) {
|
|
1554
1649
|
if (!this.executeFunc) {
|
|
1650
|
+
const tokensUsed = 100 + Math.min(input.length, 400);
|
|
1555
1651
|
const mockResult = {
|
|
1556
1652
|
output: `[Mock response from ${this.name}]: ${input.slice(0, 100)}...`,
|
|
1557
|
-
tokensUsed
|
|
1558
|
-
latencyMs:
|
|
1653
|
+
tokensUsed,
|
|
1654
|
+
latencyMs: 0,
|
|
1559
1655
|
iterations: 1
|
|
1560
1656
|
};
|
|
1561
1657
|
this.totalTokensUsed += mockResult.tokensUsed;
|
|
@@ -1658,16 +1754,27 @@ ${JSON.stringify(task.context, null, 2)}`);
|
|
|
1658
1754
|
) ?? true
|
|
1659
1755
|
).map((c) => c.name);
|
|
1660
1756
|
const estimatedTime = this.estimateTaskTime(task);
|
|
1757
|
+
const estimatedCost = this.estimateTaskCost(estimatedTime);
|
|
1661
1758
|
const reasoning = this.generateBidReasoning(task, confidence, matchedCaps);
|
|
1662
1759
|
return Promise.resolve({
|
|
1663
1760
|
agentName: this.name,
|
|
1664
1761
|
taskId: task.id ?? "unknown",
|
|
1665
1762
|
confidence,
|
|
1666
1763
|
estimatedTime,
|
|
1764
|
+
estimatedCost,
|
|
1667
1765
|
reasoning,
|
|
1668
1766
|
capabilities: matchedCaps
|
|
1669
1767
|
});
|
|
1670
1768
|
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Estimate a relative cost for handling a task. Combines the agent's model
|
|
1771
|
+
* price tier with the estimated effort so the auction `cheapest` criterion
|
|
1772
|
+
* can distinguish a cheap-but-slower model from an expensive-but-faster one.
|
|
1773
|
+
* The unit is arbitrary and only meaningful relative to other bids.
|
|
1774
|
+
*/
|
|
1775
|
+
estimateTaskCost(estimatedTime) {
|
|
1776
|
+
return modelCostWeight(this.model) * Math.max(estimatedTime, 1);
|
|
1777
|
+
}
|
|
1671
1778
|
/**
|
|
1672
1779
|
* Check if agent has all required capabilities
|
|
1673
1780
|
*/
|
|
@@ -1718,7 +1825,7 @@ ${JSON.stringify(task.context, null, 2)}`);
|
|
|
1718
1825
|
*/
|
|
1719
1826
|
createHelpRequest(taskId, request) {
|
|
1720
1827
|
return {
|
|
1721
|
-
requestId:
|
|
1828
|
+
requestId: nanoid(),
|
|
1722
1829
|
fromAgent: this.name,
|
|
1723
1830
|
taskId,
|
|
1724
1831
|
request
|
|
@@ -1853,7 +1960,13 @@ Please provide helpful guidance based on your expertise.
|
|
|
1853
1960
|
}
|
|
1854
1961
|
};
|
|
1855
1962
|
function createCrewAgent(options) {
|
|
1856
|
-
|
|
1963
|
+
if (options.execute || options.mock) {
|
|
1964
|
+
return new CrewAgent(options);
|
|
1965
|
+
}
|
|
1966
|
+
return new CrewAgent({
|
|
1967
|
+
...options,
|
|
1968
|
+
execute: createCoreExecutor(options.config, { provider: options.provider })
|
|
1969
|
+
});
|
|
1857
1970
|
}
|
|
1858
1971
|
|
|
1859
1972
|
// src/agents/AgentRegistry.ts
|
|
@@ -2553,9 +2666,9 @@ var AuctionStrategy = class extends BaseDelegationStrategy {
|
|
|
2553
2666
|
}, bids[0]);
|
|
2554
2667
|
case "cheapest":
|
|
2555
2668
|
return bids.reduce((best, bid) => {
|
|
2556
|
-
const
|
|
2557
|
-
const
|
|
2558
|
-
return
|
|
2669
|
+
const bestCost = best.estimatedCost ?? best.estimatedTime ?? Infinity;
|
|
2670
|
+
const bidCost = bid.estimatedCost ?? bid.estimatedTime ?? Infinity;
|
|
2671
|
+
return bidCost < bestCost ? bid : best;
|
|
2559
2672
|
}, bids[0]);
|
|
2560
2673
|
case "confidence":
|
|
2561
2674
|
default:
|
|
@@ -3038,9 +3151,8 @@ var ConsensusStrategy = class extends BaseDelegationStrategy {
|
|
|
3038
3151
|
*/
|
|
3039
3152
|
async collectVotes(task, voters, candidates) {
|
|
3040
3153
|
const votes = [];
|
|
3041
|
-
const candidateNames = candidates.map((c) => c.name);
|
|
3042
3154
|
for (const voter of voters) {
|
|
3043
|
-
const vote = await this.getVote(voter, task,
|
|
3155
|
+
const vote = await this.getVote(voter, task, candidates);
|
|
3044
3156
|
if (vote) {
|
|
3045
3157
|
votes.push(vote);
|
|
3046
3158
|
}
|
|
@@ -3048,33 +3160,35 @@ var ConsensusStrategy = class extends BaseDelegationStrategy {
|
|
|
3048
3160
|
return votes;
|
|
3049
3161
|
}
|
|
3050
3162
|
/**
|
|
3051
|
-
* Get a vote from an agent
|
|
3163
|
+
* Get a vote from an agent.
|
|
3164
|
+
*
|
|
3165
|
+
* Each voter ranks the candidates by how well their capabilities fit the
|
|
3166
|
+
* task (the same `calculateTaskScore` signal the BestMatch/Auction strategies
|
|
3167
|
+
* use), plus a small self-preference bias so an agent leans toward itself when
|
|
3168
|
+
* candidates are otherwise comparable. This is fully deterministic — given the
|
|
3169
|
+
* same agents and task it always produces the same votes — and explainable,
|
|
3170
|
+
* which is what consensus needs. (A future enhancement could replace this with
|
|
3171
|
+
* an actual LLM deliberation per voter; the tally/agreement logic is unchanged.)
|
|
3052
3172
|
*/
|
|
3053
3173
|
getVote(voter, task, candidates) {
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
scores.push({
|
|
3061
|
-
name: candidateName,
|
|
3062
|
-
score: Math.random() * randomFactor
|
|
3063
|
-
});
|
|
3174
|
+
if (candidates.length === 0) return Promise.resolve(null);
|
|
3175
|
+
const SELF_PREFERENCE_BONUS = 0.15;
|
|
3176
|
+
const scores = candidates.map((candidate) => {
|
|
3177
|
+
let score = candidate.calculateTaskScore(task);
|
|
3178
|
+
if (candidate.name === voter.name) {
|
|
3179
|
+
score += SELF_PREFERENCE_BONUS;
|
|
3064
3180
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
3181
|
+
return { name: candidate.name, score };
|
|
3182
|
+
});
|
|
3183
|
+
scores.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
|
|
3067
3184
|
const selected = scores[0];
|
|
3068
3185
|
if (!selected) return Promise.resolve(null);
|
|
3069
|
-
|
|
3070
|
-
if (this.weightedVoting) {
|
|
3071
|
-
weight = voter.calculateTaskScore(task) || 0.5;
|
|
3072
|
-
}
|
|
3186
|
+
const weight = this.weightedVoting ? voter.calculateTaskScore(task) || 0.5 : 1;
|
|
3073
3187
|
return Promise.resolve({
|
|
3074
3188
|
voter: voter.name,
|
|
3075
3189
|
candidate: selected.name,
|
|
3076
3190
|
weight,
|
|
3077
|
-
reasoning: `
|
|
3191
|
+
reasoning: `Ranked "${selected.name}" highest by capability fit for the task (score: ${selected.score.toFixed(2)})`
|
|
3078
3192
|
});
|
|
3079
3193
|
}
|
|
3080
3194
|
/**
|
|
@@ -3938,13 +4052,24 @@ var ConflictResolver = class {
|
|
|
3938
4052
|
resolved: /* @__PURE__ */ new Date()
|
|
3939
4053
|
};
|
|
3940
4054
|
}
|
|
4055
|
+
/**
|
|
4056
|
+
* Normalize response content for equality comparison: trim, collapse runs of
|
|
4057
|
+
* whitespace, and lowercase. This groups textually-equivalent answers (ignoring
|
|
4058
|
+
* incidental formatting) over their FULL content rather than a fragile first-N
|
|
4059
|
+
* characters prefix. Note: this is exact-match-after-normalization, not semantic
|
|
4060
|
+
* similarity — agents that express the same idea with different wording will not
|
|
4061
|
+
* group. Semantic grouping would require embeddings (future enhancement).
|
|
4062
|
+
*/
|
|
4063
|
+
normalizeContent(content) {
|
|
4064
|
+
return content.trim().replace(/\s+/g, " ").toLowerCase();
|
|
4065
|
+
}
|
|
3941
4066
|
/**
|
|
3942
4067
|
* Resolve by voting
|
|
3943
4068
|
*/
|
|
3944
4069
|
resolveByVoting(conflict, _context) {
|
|
3945
4070
|
const votes = /* @__PURE__ */ new Map();
|
|
3946
4071
|
for (const response of conflict.responses) {
|
|
3947
|
-
const key = response.content
|
|
4072
|
+
const key = this.normalizeContent(response.content);
|
|
3948
4073
|
const current = votes.get(key) ?? 0;
|
|
3949
4074
|
votes.set(key, current + response.confidence);
|
|
3950
4075
|
}
|
|
@@ -3957,7 +4082,7 @@ var ConflictResolver = class {
|
|
|
3957
4082
|
}
|
|
3958
4083
|
}
|
|
3959
4084
|
const winner = conflict.responses.find(
|
|
3960
|
-
(r) => r.content
|
|
4085
|
+
(r) => this.normalizeContent(r.content) === winningKey
|
|
3961
4086
|
);
|
|
3962
4087
|
return Promise.resolve({
|
|
3963
4088
|
conflictId: conflict.id,
|
|
@@ -3973,7 +4098,31 @@ var ConflictResolver = class {
|
|
|
3973
4098
|
* Resolve by authority
|
|
3974
4099
|
*/
|
|
3975
4100
|
resolveByAuthority(conflict, _context) {
|
|
3976
|
-
|
|
4101
|
+
const ranked = conflict.responses.map((r) => ({
|
|
4102
|
+
response: r,
|
|
4103
|
+
authority: typeof r.metadata?.authority === "number" ? r.metadata.authority : void 0
|
|
4104
|
+
})).filter(
|
|
4105
|
+
(x) => x.authority !== void 0
|
|
4106
|
+
);
|
|
4107
|
+
if (ranked.length === 0) {
|
|
4108
|
+
return Promise.resolve({
|
|
4109
|
+
...this.resolveByConfidence(conflict),
|
|
4110
|
+
strategy: "authority",
|
|
4111
|
+
explanation: "No authority metadata provided; fell back to highest confidence"
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
4114
|
+
const winnerEntry = ranked.reduce(
|
|
4115
|
+
(best, cur) => cur.authority > best.authority ? cur : best
|
|
4116
|
+
);
|
|
4117
|
+
return Promise.resolve({
|
|
4118
|
+
conflictId: conflict.id,
|
|
4119
|
+
strategy: "authority",
|
|
4120
|
+
winner: winnerEntry.response,
|
|
4121
|
+
explanation: `Selected response from highest-authority agent "${winnerEntry.response.agentName}" (authority: ${winnerEntry.authority})`,
|
|
4122
|
+
successful: true,
|
|
4123
|
+
escalated: false,
|
|
4124
|
+
resolved: /* @__PURE__ */ new Date()
|
|
4125
|
+
});
|
|
3977
4126
|
}
|
|
3978
4127
|
/**
|
|
3979
4128
|
* Resolve by consensus
|
|
@@ -3981,7 +4130,7 @@ var ConflictResolver = class {
|
|
|
3981
4130
|
resolveByConsensus(conflict, _context) {
|
|
3982
4131
|
const contentGroups = /* @__PURE__ */ new Map();
|
|
3983
4132
|
for (const response of conflict.responses) {
|
|
3984
|
-
const key = response.content
|
|
4133
|
+
const key = this.normalizeContent(response.content);
|
|
3985
4134
|
const group = contentGroups.get(key) ?? [];
|
|
3986
4135
|
group.push(response);
|
|
3987
4136
|
contentGroups.set(key, group);
|
|
@@ -4121,7 +4270,7 @@ var Crew = class {
|
|
|
4121
4270
|
timeline = [];
|
|
4122
4271
|
results = /* @__PURE__ */ new Map();
|
|
4123
4272
|
constructor(config) {
|
|
4124
|
-
this.id =
|
|
4273
|
+
this.id = nanoid();
|
|
4125
4274
|
this.name = config.name;
|
|
4126
4275
|
this.description = config.description;
|
|
4127
4276
|
this.config = config;
|
|
@@ -4141,7 +4290,12 @@ var Crew = class {
|
|
|
4141
4290
|
*/
|
|
4142
4291
|
initializeAgents() {
|
|
4143
4292
|
for (const agentConfig of this.config.agents) {
|
|
4144
|
-
const agent = createCrewAgent({
|
|
4293
|
+
const agent = createCrewAgent({
|
|
4294
|
+
config: agentConfig,
|
|
4295
|
+
execute: this.config.execute,
|
|
4296
|
+
mock: this.config.mock,
|
|
4297
|
+
provider: this.config.provider
|
|
4298
|
+
});
|
|
4145
4299
|
this.addAgent(agent);
|
|
4146
4300
|
}
|
|
4147
4301
|
}
|
|
@@ -4265,27 +4419,40 @@ var Crew = class {
|
|
|
4265
4419
|
await this.sleep(100);
|
|
4266
4420
|
continue;
|
|
4267
4421
|
}
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4422
|
+
const concurrency = Math.max(
|
|
4423
|
+
1,
|
|
4424
|
+
options.maxConcurrentTasks ?? this.config.maxConcurrentTasks ?? 1
|
|
4425
|
+
);
|
|
4426
|
+
if (concurrency === 1) {
|
|
4427
|
+
for (const task of readyTasks) {
|
|
4428
|
+
if (this.state !== "running") break;
|
|
4429
|
+
const delegationResult = await this.delegateTask(task, options);
|
|
4430
|
+
yield this.createEvent({
|
|
4431
|
+
type: "task:assigned",
|
|
4432
|
+
taskId: task.id,
|
|
4433
|
+
agentName: delegationResult.selectedAgent,
|
|
4434
|
+
reason: delegationResult.reason,
|
|
4435
|
+
strategy: this.config.delegationStrategy
|
|
4436
|
+
});
|
|
4437
|
+
const taskResult = await this.executeTask(task, delegationResult);
|
|
4438
|
+
yield this.createEvent({
|
|
4439
|
+
type: "task:completed",
|
|
4440
|
+
taskId: task.id,
|
|
4441
|
+
result: taskResult,
|
|
4442
|
+
agentName: delegationResult.selectedAgent,
|
|
4443
|
+
durationMs: taskResult.latencyMs ?? 0
|
|
4444
|
+
});
|
|
4445
|
+
while (eventQueue.length > 0) {
|
|
4446
|
+
yield eventQueue.shift();
|
|
4447
|
+
}
|
|
4288
4448
|
}
|
|
4449
|
+
} else {
|
|
4450
|
+
yield* this.processReadyTasksConcurrently(
|
|
4451
|
+
readyTasks,
|
|
4452
|
+
options,
|
|
4453
|
+
eventQueue,
|
|
4454
|
+
concurrency
|
|
4455
|
+
);
|
|
4289
4456
|
}
|
|
4290
4457
|
while (this.state === "paused") {
|
|
4291
4458
|
await this.sleep(100);
|
|
@@ -4328,6 +4495,78 @@ var Crew = class {
|
|
|
4328
4495
|
});
|
|
4329
4496
|
this.addTimelineEntry("crew_completed", this.name);
|
|
4330
4497
|
}
|
|
4498
|
+
/**
|
|
4499
|
+
* Execute a batch of ready tasks concurrently with a bounded worker pool.
|
|
4500
|
+
*
|
|
4501
|
+
* Each task still emits its `task:assigned` and `task:completed` events in
|
|
4502
|
+
* order relative to itself, but events across tasks are interleaved as the
|
|
4503
|
+
* workers settle. At most `concurrency` tasks run at once. If any task throws
|
|
4504
|
+
* (after exhausting retries), no further tasks are started, in-flight tasks
|
|
4505
|
+
* are allowed to settle, and the first error is rethrown so the caller's
|
|
4506
|
+
* error handling (crew:error) behaves identically to the sequential path.
|
|
4507
|
+
*/
|
|
4508
|
+
async *processReadyTasksConcurrently(readyTasks, options, eventQueue, concurrency) {
|
|
4509
|
+
let nextIndex = 0;
|
|
4510
|
+
let firstError;
|
|
4511
|
+
const buffer = [];
|
|
4512
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
4513
|
+
const launch = (task) => {
|
|
4514
|
+
const worker = (async () => {
|
|
4515
|
+
const delegationResult = await this.delegateTask(task, options);
|
|
4516
|
+
buffer.push(
|
|
4517
|
+
this.createEvent({
|
|
4518
|
+
type: "task:assigned",
|
|
4519
|
+
taskId: task.id,
|
|
4520
|
+
agentName: delegationResult.selectedAgent,
|
|
4521
|
+
reason: delegationResult.reason,
|
|
4522
|
+
strategy: this.config.delegationStrategy
|
|
4523
|
+
})
|
|
4524
|
+
);
|
|
4525
|
+
const taskResult = await this.executeTask(task, delegationResult);
|
|
4526
|
+
buffer.push(
|
|
4527
|
+
this.createEvent({
|
|
4528
|
+
type: "task:completed",
|
|
4529
|
+
taskId: task.id,
|
|
4530
|
+
result: taskResult,
|
|
4531
|
+
agentName: delegationResult.selectedAgent,
|
|
4532
|
+
durationMs: taskResult.latencyMs ?? 0
|
|
4533
|
+
})
|
|
4534
|
+
);
|
|
4535
|
+
})().catch((error) => {
|
|
4536
|
+
if (firstError === void 0) {
|
|
4537
|
+
firstError = error;
|
|
4538
|
+
}
|
|
4539
|
+
}).finally(() => {
|
|
4540
|
+
inFlight.delete(worker);
|
|
4541
|
+
});
|
|
4542
|
+
inFlight.add(worker);
|
|
4543
|
+
};
|
|
4544
|
+
const fill = () => {
|
|
4545
|
+
while (inFlight.size < concurrency && nextIndex < readyTasks.length && this.state === "running" && firstError === void 0) {
|
|
4546
|
+
launch(readyTasks[nextIndex++]);
|
|
4547
|
+
}
|
|
4548
|
+
};
|
|
4549
|
+
fill();
|
|
4550
|
+
while (inFlight.size > 0) {
|
|
4551
|
+
await Promise.race(inFlight);
|
|
4552
|
+
while (buffer.length > 0) {
|
|
4553
|
+
yield buffer.shift();
|
|
4554
|
+
}
|
|
4555
|
+
while (eventQueue.length > 0) {
|
|
4556
|
+
yield eventQueue.shift();
|
|
4557
|
+
}
|
|
4558
|
+
fill();
|
|
4559
|
+
}
|
|
4560
|
+
while (buffer.length > 0) {
|
|
4561
|
+
yield buffer.shift();
|
|
4562
|
+
}
|
|
4563
|
+
while (eventQueue.length > 0) {
|
|
4564
|
+
yield eventQueue.shift();
|
|
4565
|
+
}
|
|
4566
|
+
if (firstError !== void 0) {
|
|
4567
|
+
throw firstError;
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4331
4570
|
/**
|
|
4332
4571
|
* Delegate a task to an agent
|
|
4333
4572
|
*/
|
|
@@ -4547,7 +4786,7 @@ ${r.output}`).join("\n\n---\n\n");
|
|
|
4547
4786
|
*/
|
|
4548
4787
|
createCheckpoint() {
|
|
4549
4788
|
return {
|
|
4550
|
-
id:
|
|
4789
|
+
id: nanoid(),
|
|
4551
4790
|
crewId: this.id,
|
|
4552
4791
|
crewName: this.name,
|
|
4553
4792
|
timestamp: /* @__PURE__ */ new Date(),
|
package/dist/nestjs/index.mjs
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { d as TaskConfig, a as Crew, e as CrewConfig } from '../Crew-BnvVjN7A.mjs';
|
|
2
|
+
|
|
3
|
+
interface ResearchCrewOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
provider?: string;
|
|
7
|
+
includeWriter?: boolean;
|
|
8
|
+
depth?: 'shallow' | 'standard' | 'deep';
|
|
9
|
+
tools?: string[];
|
|
10
|
+
}
|
|
11
|
+
declare function createResearchCrewConfig(options?: ResearchCrewOptions): CrewConfig;
|
|
12
|
+
declare function createResearchCrew(options?: ResearchCrewOptions): Crew;
|
|
13
|
+
declare const ResearchTasks: {
|
|
14
|
+
research(topic: string, depth?: "shallow" | "standard" | "deep"): TaskConfig;
|
|
15
|
+
analyze(data: string, focusAreas?: string[]): TaskConfig;
|
|
16
|
+
writeReport(topic: string, format?: "summary" | "detailed" | "executive"): TaskConfig;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface WritingCrewOptions {
|
|
20
|
+
name?: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
provider?: string;
|
|
23
|
+
contentType?: 'blog' | 'technical' | 'marketing' | 'creative' | 'general';
|
|
24
|
+
audience?: string;
|
|
25
|
+
tools?: string[];
|
|
26
|
+
}
|
|
27
|
+
declare function createWritingCrewConfig(options?: WritingCrewOptions): CrewConfig;
|
|
28
|
+
declare function createWritingCrew(options?: WritingCrewOptions): Crew;
|
|
29
|
+
declare const WritingTasks: {
|
|
30
|
+
draft(topic: string, wordCount?: number, style?: string): TaskConfig;
|
|
31
|
+
edit(content: string, focusAreas?: string[]): TaskConfig;
|
|
32
|
+
proofread(content: string): TaskConfig;
|
|
33
|
+
blogPost(topic: string, keywords?: string[]): TaskConfig;
|
|
34
|
+
technicalDoc(subject: string, audience?: "beginner" | "intermediate" | "advanced"): TaskConfig;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
interface CodeReviewCrewOptions {
|
|
38
|
+
name?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
provider?: string;
|
|
41
|
+
languages?: string[];
|
|
42
|
+
includeSecurity?: boolean;
|
|
43
|
+
includePerformance?: boolean;
|
|
44
|
+
strictness?: 'relaxed' | 'standard' | 'strict';
|
|
45
|
+
tools?: string[];
|
|
46
|
+
}
|
|
47
|
+
declare function createCodeReviewCrewConfig(options?: CodeReviewCrewOptions): CrewConfig;
|
|
48
|
+
declare function createCodeReviewCrew(options?: CodeReviewCrewOptions): Crew;
|
|
49
|
+
declare const CodeReviewTasks: {
|
|
50
|
+
review(code: string, language?: string, context?: string): TaskConfig;
|
|
51
|
+
securityReview(code: string, language?: string): TaskConfig;
|
|
52
|
+
performanceReview(code: string, language?: string): TaskConfig;
|
|
53
|
+
pullRequestReview(diff: string, prDescription?: string): TaskConfig;
|
|
54
|
+
architectureReview(description: string, codebase?: string): TaskConfig;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
interface CustomerSupportCrewOptions {
|
|
58
|
+
name?: string;
|
|
59
|
+
model?: string;
|
|
60
|
+
provider?: string;
|
|
61
|
+
productName?: string;
|
|
62
|
+
companyName?: string;
|
|
63
|
+
supportStyle?: 'formal' | 'friendly' | 'technical';
|
|
64
|
+
includeSpecialist?: boolean;
|
|
65
|
+
includeEscalation?: boolean;
|
|
66
|
+
tools?: string[];
|
|
67
|
+
}
|
|
68
|
+
declare function createCustomerSupportCrewConfig(options?: CustomerSupportCrewOptions): CrewConfig;
|
|
69
|
+
declare function createCustomerSupportCrew(options?: CustomerSupportCrewOptions): Crew;
|
|
70
|
+
declare const CustomerSupportTasks: {
|
|
71
|
+
handleTicket(customerMessage: string, priority?: "low" | "normal" | "high" | "urgent", customerTier?: string): TaskConfig;
|
|
72
|
+
resolveTechnicalIssue(issueDescription: string, errorLogs?: string, environment?: string): TaskConfig;
|
|
73
|
+
handleEscalation(caseHistory: string, customerSentiment?: "frustrated" | "angry" | "neutral", businessImpact?: string): TaskConfig;
|
|
74
|
+
respondToFeedback(feedback: string, sentiment: "positive" | "neutral" | "negative"): TaskConfig;
|
|
75
|
+
createKnowledgeBaseArticle(topic: string, resolution: string): TaskConfig;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { type CodeReviewCrewOptions, CodeReviewTasks, type CustomerSupportCrewOptions, CustomerSupportTasks, type ResearchCrewOptions, ResearchTasks, type WritingCrewOptions, WritingTasks, createCodeReviewCrew, createCodeReviewCrewConfig, createCustomerSupportCrew, createCustomerSupportCrewConfig, createResearchCrew, createResearchCrewConfig, createWritingCrew, createWritingCrewConfig };
|