agent-swarm-kit 1.1.73 → 1.1.75
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/build/index.cjs +119 -46
- package/build/index.mjs +119 -46
- package/package.json +1 -1
- package/types.d.ts +7 -0
package/build/index.cjs
CHANGED
|
@@ -13052,6 +13052,23 @@ class SwarmMetaService {
|
|
|
13052
13052
|
}
|
|
13053
13053
|
}
|
|
13054
13054
|
|
|
13055
|
+
const sanitizeMarkdown = (input) => {
|
|
13056
|
+
return input
|
|
13057
|
+
// Remove Markdown headers, emphasis, bold, etc.
|
|
13058
|
+
.replace(/[_*~`>#-]/g, '')
|
|
13059
|
+
// Remove links and images
|
|
13060
|
+
.replace(/\[.*?\]\(.*?\)/g, '')
|
|
13061
|
+
// Remove inline code blocks
|
|
13062
|
+
.replace(/`{1,3}[^`]*`{1,3}/g, '')
|
|
13063
|
+
// Remove horizontal rules
|
|
13064
|
+
.replace(/-{3,}/g, '')
|
|
13065
|
+
// Remove blockquotes
|
|
13066
|
+
.replace(/^>+/gm, '')
|
|
13067
|
+
// Remove HTML tags (often used in Markdown)
|
|
13068
|
+
.replace(/<\/?[^>]+(>|$)/g, '')
|
|
13069
|
+
.trim();
|
|
13070
|
+
};
|
|
13071
|
+
|
|
13055
13072
|
/**
|
|
13056
13073
|
* Maximum number of concurrent threads for documentation generation tasks.
|
|
13057
13074
|
* Used by execpool in writeSwarmDoc and writeAgentDoc to limit parallel execution, balancing performance and resource usage.
|
|
@@ -13212,22 +13229,22 @@ class DocService {
|
|
|
13212
13229
|
const result = [];
|
|
13213
13230
|
{
|
|
13214
13231
|
result.push("---");
|
|
13215
|
-
result.push(`title: ${prefix}/${swarmSchema.swarmName}`);
|
|
13232
|
+
result.push(`title: ${prefix}/${sanitizeMarkdown(swarmSchema.swarmName)}`);
|
|
13216
13233
|
result.push(`group: ${prefix}`);
|
|
13217
13234
|
result.push("---");
|
|
13218
13235
|
result.push("");
|
|
13219
13236
|
}
|
|
13220
13237
|
{
|
|
13221
|
-
result.push(`# ${swarmSchema.swarmName}`);
|
|
13238
|
+
result.push(`# ${sanitizeMarkdown(swarmSchema.swarmName)}`);
|
|
13222
13239
|
if (swarmSchema.docDescription) {
|
|
13223
13240
|
result.push("");
|
|
13224
|
-
result.push(`> ${swarmSchema.docDescription}`);
|
|
13241
|
+
result.push(`> ${sanitizeMarkdown(swarmSchema.docDescription)}`);
|
|
13225
13242
|
}
|
|
13226
13243
|
result.push("");
|
|
13227
13244
|
}
|
|
13228
13245
|
{
|
|
13229
13246
|
const umlSchema = this.swarmMetaService.toUML(swarmSchema.swarmName);
|
|
13230
|
-
const umlName = `swarm_schema_${swarmSchema.swarmName}.svg`;
|
|
13247
|
+
const umlName = `swarm_schema_${sanitizeMarkdown(swarmSchema.swarmName)}.svg`;
|
|
13231
13248
|
const umlSvg = await GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema);
|
|
13232
13249
|
if (umlSvg) {
|
|
13233
13250
|
await writeFileAtomic(path.join(dirName, "image", umlName), umlSvg);
|
|
@@ -13238,11 +13255,11 @@ class DocService {
|
|
|
13238
13255
|
if (swarmSchema.defaultAgent) {
|
|
13239
13256
|
result.push("## Default agent");
|
|
13240
13257
|
result.push("");
|
|
13241
|
-
result.push(` - [${swarmSchema.defaultAgent}](./agent/${swarmSchema.defaultAgent}.md)`);
|
|
13258
|
+
result.push(` - [${sanitizeMarkdown(swarmSchema.defaultAgent)}](./agent/${sanitizeMarkdown(swarmSchema.defaultAgent)}.md)`);
|
|
13242
13259
|
const { docDescription } = this.agentSchemaService.get(swarmSchema.defaultAgent);
|
|
13243
13260
|
if (docDescription) {
|
|
13244
13261
|
result.push("");
|
|
13245
|
-
result.push(`\t${docDescription}`);
|
|
13262
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13246
13263
|
}
|
|
13247
13264
|
result.push("");
|
|
13248
13265
|
}
|
|
@@ -13253,11 +13270,11 @@ class DocService {
|
|
|
13253
13270
|
if (!swarmSchema.agentList[i]) {
|
|
13254
13271
|
continue;
|
|
13255
13272
|
}
|
|
13256
|
-
result.push(`${i + 1}. [${swarmSchema.agentList[i]}](./agent/${swarmSchema.agentList[i]}.md)`);
|
|
13273
|
+
result.push(`${i + 1}. [${sanitizeMarkdown(swarmSchema.agentList[i])}](./agent/${sanitizeMarkdown(swarmSchema.agentList[i])}.md)`);
|
|
13257
13274
|
const { docDescription } = this.agentSchemaService.get(swarmSchema.agentList[i]);
|
|
13258
13275
|
if (docDescription) {
|
|
13259
13276
|
result.push("");
|
|
13260
|
-
result.push(`\t${docDescription}`);
|
|
13277
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13261
13278
|
}
|
|
13262
13279
|
result.push("");
|
|
13263
13280
|
}
|
|
@@ -13269,11 +13286,11 @@ class DocService {
|
|
|
13269
13286
|
if (!swarmSchema.policies[i]) {
|
|
13270
13287
|
continue;
|
|
13271
13288
|
}
|
|
13272
|
-
result.push(`${i + 1}. ${swarmSchema.policies[i]}`);
|
|
13289
|
+
result.push(`${i + 1}. ${sanitizeMarkdown(swarmSchema.policies[i])}`);
|
|
13273
13290
|
const { docDescription } = this.policySchemaService.get(swarmSchema.policies[i]);
|
|
13274
13291
|
if (docDescription) {
|
|
13275
13292
|
result.push("");
|
|
13276
|
-
result.push(`\t${docDescription}`);
|
|
13293
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13277
13294
|
}
|
|
13278
13295
|
result.push("");
|
|
13279
13296
|
}
|
|
@@ -13287,11 +13304,11 @@ class DocService {
|
|
|
13287
13304
|
result.push("");
|
|
13288
13305
|
const callbackList = Object.keys(swarmSchema.callbacks);
|
|
13289
13306
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13290
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13307
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13291
13308
|
}
|
|
13292
13309
|
result.push("");
|
|
13293
13310
|
}
|
|
13294
|
-
await writeFileAtomic(path.join(dirName, `./${swarmSchema.swarmName}.md`), result.join("\n"));
|
|
13311
|
+
await writeFileAtomic(path.join(dirName, `./${sanitizeMarkdown(swarmSchema.swarmName)}.md`), result.join("\n"));
|
|
13295
13312
|
}, {
|
|
13296
13313
|
maxExec: THREAD_POOL_SIZE,
|
|
13297
13314
|
delay: THREAD_POOL_DELAY,
|
|
@@ -13313,21 +13330,21 @@ class DocService {
|
|
|
13313
13330
|
const result = [];
|
|
13314
13331
|
{
|
|
13315
13332
|
result.push("---");
|
|
13316
|
-
result.push(`title: ${prefix}/${agentSchema.agentName}`);
|
|
13333
|
+
result.push(`title: ${prefix}/${sanitizeMarkdown(agentSchema.agentName)}`);
|
|
13317
13334
|
result.push(`group: ${prefix}`);
|
|
13318
13335
|
result.push("---");
|
|
13319
13336
|
result.push("");
|
|
13320
13337
|
}
|
|
13321
13338
|
{
|
|
13322
|
-
result.push(`# ${agentSchema.agentName}`);
|
|
13339
|
+
result.push(`# ${sanitizeMarkdown(agentSchema.agentName)}`);
|
|
13323
13340
|
if (agentSchema.docDescription) {
|
|
13324
13341
|
result.push("");
|
|
13325
|
-
result.push(`> ${agentSchema.docDescription}`);
|
|
13342
|
+
result.push(`> ${sanitizeMarkdown(agentSchema.docDescription)}`);
|
|
13326
13343
|
}
|
|
13327
13344
|
result.push("");
|
|
13328
13345
|
}
|
|
13329
13346
|
if (agentSchema.completion) {
|
|
13330
|
-
result.push(`**Completion:** \`${agentSchema.completion}\``);
|
|
13347
|
+
result.push(`**Completion:** \`${sanitizeMarkdown(agentSchema.completion)}\``);
|
|
13331
13348
|
result.push("");
|
|
13332
13349
|
}
|
|
13333
13350
|
{
|
|
@@ -13336,7 +13353,7 @@ class DocService {
|
|
|
13336
13353
|
}
|
|
13337
13354
|
{
|
|
13338
13355
|
const umlSchema = this.agentMetaService.toUML(agentSchema.agentName, true);
|
|
13339
|
-
const umlName = `agent_schema_${agentSchema.agentName}.svg`;
|
|
13356
|
+
const umlName = `agent_schema_${sanitizeMarkdown(agentSchema.agentName)}.svg`;
|
|
13340
13357
|
const umlSvg = await GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema);
|
|
13341
13358
|
if (umlSvg) {
|
|
13342
13359
|
await writeFileAtomic(path.join(dirName, "image", umlName), umlSvg);
|
|
@@ -13363,7 +13380,7 @@ class DocService {
|
|
|
13363
13380
|
result.push(`## Main prompt`);
|
|
13364
13381
|
result.push("");
|
|
13365
13382
|
result.push("```");
|
|
13366
|
-
result.push(prompt);
|
|
13383
|
+
result.push(sanitizeMarkdown(prompt));
|
|
13367
13384
|
result.push("```");
|
|
13368
13385
|
result.push("");
|
|
13369
13386
|
}
|
|
@@ -13392,7 +13409,7 @@ class DocService {
|
|
|
13392
13409
|
if (!system[i]) {
|
|
13393
13410
|
continue;
|
|
13394
13411
|
}
|
|
13395
|
-
result.push(`${i + 1}. \`${system[i]}\``);
|
|
13412
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(system[i])}\``);
|
|
13396
13413
|
result.push("");
|
|
13397
13414
|
}
|
|
13398
13415
|
}
|
|
@@ -13403,11 +13420,11 @@ class DocService {
|
|
|
13403
13420
|
if (!agentSchema.dependsOn[i]) {
|
|
13404
13421
|
continue;
|
|
13405
13422
|
}
|
|
13406
|
-
result.push(`${i + 1}. [${agentSchema.dependsOn[i]}](./${agentSchema.dependsOn[i]}.md)`);
|
|
13423
|
+
result.push(`${i + 1}. [${sanitizeMarkdown(agentSchema.dependsOn[i])}](./${sanitizeMarkdown(agentSchema.dependsOn[i])}.md)`);
|
|
13407
13424
|
const { docDescription } = this.agentSchemaService.get(agentSchema.dependsOn[i]);
|
|
13408
13425
|
if (docDescription) {
|
|
13409
13426
|
result.push("");
|
|
13410
|
-
result.push(docDescription);
|
|
13427
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13411
13428
|
}
|
|
13412
13429
|
result.push("");
|
|
13413
13430
|
}
|
|
@@ -13419,11 +13436,11 @@ class DocService {
|
|
|
13419
13436
|
if (!agentSchema.mcp[i]) {
|
|
13420
13437
|
continue;
|
|
13421
13438
|
}
|
|
13422
|
-
result.push(`${i + 1}. ${agentSchema.mcp[i]}`);
|
|
13439
|
+
result.push(`${i + 1}. ${sanitizeMarkdown(agentSchema.mcp[i])}`);
|
|
13423
13440
|
const { docDescription } = this.mcpSchemaService.get(agentSchema.mcp[i]);
|
|
13424
13441
|
if (docDescription) {
|
|
13425
13442
|
result.push("");
|
|
13426
|
-
result.push(docDescription);
|
|
13443
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13427
13444
|
}
|
|
13428
13445
|
result.push("");
|
|
13429
13446
|
}
|
|
@@ -13459,18 +13476,18 @@ class DocService {
|
|
|
13459
13476
|
continue;
|
|
13460
13477
|
}
|
|
13461
13478
|
const { function: fn, docNote, callbacks } = tools[i];
|
|
13462
|
-
result.push(`### ${i + 1}. ${agentSchema.tools[i]}`);
|
|
13479
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.tools[i])}`);
|
|
13463
13480
|
if (fn.name) {
|
|
13464
13481
|
result.push("");
|
|
13465
13482
|
result.push("#### Name for model");
|
|
13466
13483
|
result.push("");
|
|
13467
|
-
result.push(`\`${fn.name}\``);
|
|
13484
|
+
result.push(`\`${sanitizeMarkdown(fn.name)}\``);
|
|
13468
13485
|
}
|
|
13469
13486
|
if (fn.description) {
|
|
13470
13487
|
result.push("");
|
|
13471
13488
|
result.push("#### Description for model");
|
|
13472
13489
|
result.push("");
|
|
13473
|
-
result.push(`\`${fn.description}\``);
|
|
13490
|
+
result.push(`\`${sanitizeMarkdown(fn.description)}\``);
|
|
13474
13491
|
}
|
|
13475
13492
|
if (fn.parameters?.properties) {
|
|
13476
13493
|
result.push("");
|
|
@@ -13478,18 +13495,18 @@ class DocService {
|
|
|
13478
13495
|
const entries = Object.entries(fn.parameters.properties);
|
|
13479
13496
|
entries.forEach(([key, { type, description, enum: e }], idx) => {
|
|
13480
13497
|
result.push("");
|
|
13481
|
-
result.push(`> **${idx + 1}. ${key}**`);
|
|
13498
|
+
result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
|
|
13482
13499
|
{
|
|
13483
13500
|
result.push("");
|
|
13484
|
-
result.push(`*Type:* \`${type}\``);
|
|
13501
|
+
result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
|
|
13485
13502
|
}
|
|
13486
13503
|
{
|
|
13487
13504
|
result.push("");
|
|
13488
|
-
result.push(`*Description:* \`${description}\``);
|
|
13505
|
+
result.push(`*Description:* \`${sanitizeMarkdown(description)}\``);
|
|
13489
13506
|
}
|
|
13490
13507
|
if (e) {
|
|
13491
13508
|
result.push("");
|
|
13492
|
-
result.push(`*Enum:* \`${e.join(", ")}\``);
|
|
13509
|
+
result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
|
|
13493
13510
|
}
|
|
13494
13511
|
{
|
|
13495
13512
|
result.push("");
|
|
@@ -13507,14 +13524,14 @@ class DocService {
|
|
|
13507
13524
|
result.push("");
|
|
13508
13525
|
const callbackList = Object.keys(callbacks);
|
|
13509
13526
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13510
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13527
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13511
13528
|
}
|
|
13512
13529
|
}
|
|
13513
13530
|
if (docNote) {
|
|
13514
13531
|
result.push("");
|
|
13515
13532
|
result.push("#### Note for developer");
|
|
13516
13533
|
result.push("");
|
|
13517
|
-
result.push(`*${docNote}*`);
|
|
13534
|
+
result.push(`*${sanitizeMarkdown(docNote)}*`);
|
|
13518
13535
|
}
|
|
13519
13536
|
result.push("");
|
|
13520
13537
|
}
|
|
@@ -13526,17 +13543,17 @@ class DocService {
|
|
|
13526
13543
|
if (!agentSchema.storages[i]) {
|
|
13527
13544
|
continue;
|
|
13528
13545
|
}
|
|
13529
|
-
result.push(`### ${i + 1}. ${agentSchema.storages[i]}`);
|
|
13546
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.storages[i])}`);
|
|
13530
13547
|
const { docDescription, embedding, shared, callbacks } = this.storageSchemaService.get(agentSchema.storages[i]);
|
|
13531
13548
|
if (docDescription) {
|
|
13532
13549
|
result.push("");
|
|
13533
13550
|
result.push(`#### Storage description`);
|
|
13534
13551
|
result.push("");
|
|
13535
|
-
result.push(docDescription);
|
|
13552
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13536
13553
|
}
|
|
13537
13554
|
if (embedding) {
|
|
13538
13555
|
result.push("");
|
|
13539
|
-
result.push(`*Embedding:* \`${embedding}\``);
|
|
13556
|
+
result.push(`*Embedding:* \`${sanitizeMarkdown(embedding)}\``);
|
|
13540
13557
|
}
|
|
13541
13558
|
{
|
|
13542
13559
|
result.push("");
|
|
@@ -13548,7 +13565,7 @@ class DocService {
|
|
|
13548
13565
|
result.push("");
|
|
13549
13566
|
const callbackList = Object.keys(callbacks);
|
|
13550
13567
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13551
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13568
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13552
13569
|
}
|
|
13553
13570
|
}
|
|
13554
13571
|
result.push("");
|
|
@@ -13572,13 +13589,13 @@ class DocService {
|
|
|
13572
13589
|
if (!agentSchema.states[i]) {
|
|
13573
13590
|
continue;
|
|
13574
13591
|
}
|
|
13575
|
-
result.push(`### ${i + 1}. ${agentSchema.states[i]}`);
|
|
13592
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.states[i])}`);
|
|
13576
13593
|
const { docDescription, shared, callbacks } = this.stateSchemaService.get(agentSchema.states[i]);
|
|
13577
13594
|
if (docDescription) {
|
|
13578
13595
|
result.push("");
|
|
13579
13596
|
result.push(`#### State description`);
|
|
13580
13597
|
result.push("");
|
|
13581
|
-
result.push(docDescription);
|
|
13598
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13582
13599
|
}
|
|
13583
13600
|
{
|
|
13584
13601
|
const computeSchemasCurrentList = computeSchemasTotalList.filter(([stateName]) => stateName === agentSchema.states[i]);
|
|
@@ -13589,10 +13606,10 @@ class DocService {
|
|
|
13589
13606
|
for (let i = 0; i !== computeSchemasCurrentList.length; i++) {
|
|
13590
13607
|
const [, { computeName, docDescription }] = computeSchemasCurrentList[i];
|
|
13591
13608
|
result.push("");
|
|
13592
|
-
result.push(`> **${i + 1}. ${computeName}**`);
|
|
13609
|
+
result.push(`> **${i + 1}. ${sanitizeMarkdown(computeName)}**`);
|
|
13593
13610
|
{
|
|
13594
13611
|
result.push("");
|
|
13595
|
-
result.push(`*Description:* \`${docDescription}\``);
|
|
13612
|
+
result.push(`*Description:* \`${sanitizeMarkdown(docDescription)}\``);
|
|
13596
13613
|
}
|
|
13597
13614
|
}
|
|
13598
13615
|
result.push("");
|
|
@@ -13605,7 +13622,7 @@ class DocService {
|
|
|
13605
13622
|
result.push("");
|
|
13606
13623
|
const callbackList = Object.keys(callbacks);
|
|
13607
13624
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13608
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13625
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13609
13626
|
}
|
|
13610
13627
|
}
|
|
13611
13628
|
}
|
|
@@ -13623,13 +13640,13 @@ class DocService {
|
|
|
13623
13640
|
if (!agentSchema.wikiList[i]) {
|
|
13624
13641
|
continue;
|
|
13625
13642
|
}
|
|
13626
|
-
result.push(`### ${i + 1}. ${agentSchema.wikiList[i]}`);
|
|
13643
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.wikiList[i])}`);
|
|
13627
13644
|
const { docDescription, callbacks } = this.wikiSchemaService.get(agentSchema.wikiList[i]);
|
|
13628
13645
|
if (docDescription) {
|
|
13629
13646
|
result.push("");
|
|
13630
13647
|
result.push(`#### Wiki description`);
|
|
13631
13648
|
result.push("");
|
|
13632
|
-
result.push(docDescription);
|
|
13649
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13633
13650
|
}
|
|
13634
13651
|
if (callbacks) {
|
|
13635
13652
|
result.push("");
|
|
@@ -13637,7 +13654,7 @@ class DocService {
|
|
|
13637
13654
|
result.push("");
|
|
13638
13655
|
const callbackList = Object.keys(callbacks);
|
|
13639
13656
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13640
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13657
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13641
13658
|
}
|
|
13642
13659
|
}
|
|
13643
13660
|
result.push("");
|
|
@@ -13648,11 +13665,11 @@ class DocService {
|
|
|
13648
13665
|
result.push("");
|
|
13649
13666
|
const callbackList = Object.keys(agentSchema.callbacks);
|
|
13650
13667
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13651
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13668
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13652
13669
|
}
|
|
13653
13670
|
result.push("");
|
|
13654
13671
|
}
|
|
13655
|
-
await writeFileAtomic(path.join(dirName, `./agent/${agentSchema.agentName}.md`), result.join("\n"));
|
|
13672
|
+
await writeFileAtomic(path.join(dirName, `./agent/${sanitizeMarkdown(agentSchema.agentName)}.md`), result.join("\n"));
|
|
13656
13673
|
}, {
|
|
13657
13674
|
maxExec: THREAD_POOL_SIZE,
|
|
13658
13675
|
delay: THREAD_POOL_DELAY,
|
|
@@ -24072,6 +24089,62 @@ const RETRY_DELAY = 5000;
|
|
|
24072
24089
|
*/
|
|
24073
24090
|
class AdapterUtils {
|
|
24074
24091
|
constructor() {
|
|
24092
|
+
/**
|
|
24093
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
24094
|
+
* @param {any} grok - The Grok client instance.
|
|
24095
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
24096
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
24097
|
+
*/
|
|
24098
|
+
this.fromGrok = (grok, model = "grok-3-mini") =>
|
|
24099
|
+
/**
|
|
24100
|
+
* Handles a completion request to Grok, transforming messages and tools into the required format.
|
|
24101
|
+
* Executes requests in a pool to limit concurrency with retry logic for reliability.
|
|
24102
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
24103
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
24104
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to Grok.
|
|
24105
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
24106
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
24107
|
+
* @returns {Promise<IModelMessage>} The response from Grok in `agent-swarm-kit` format.
|
|
24108
|
+
*/
|
|
24109
|
+
functoolsKit.execpool(functoolsKit.retry(async ({ agentName, messages: rawMessages, mode, tools, clientId, }) => {
|
|
24110
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromGrok completion", JSON.stringify(rawMessages));
|
|
24111
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
24112
|
+
role,
|
|
24113
|
+
tool_call_id,
|
|
24114
|
+
content,
|
|
24115
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24116
|
+
...rest,
|
|
24117
|
+
function: {
|
|
24118
|
+
name: f.name,
|
|
24119
|
+
arguments: JSON.stringify(f.arguments),
|
|
24120
|
+
},
|
|
24121
|
+
})),
|
|
24122
|
+
}));
|
|
24123
|
+
const { choices: [{ message: { content, role, tool_calls }, },], } = await grok.chat.completions.create({
|
|
24124
|
+
model,
|
|
24125
|
+
messages: messages,
|
|
24126
|
+
tools: tools,
|
|
24127
|
+
response_format: {
|
|
24128
|
+
type: "text",
|
|
24129
|
+
},
|
|
24130
|
+
});
|
|
24131
|
+
return {
|
|
24132
|
+
content: content,
|
|
24133
|
+
mode,
|
|
24134
|
+
agentName,
|
|
24135
|
+
role,
|
|
24136
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24137
|
+
...rest,
|
|
24138
|
+
function: {
|
|
24139
|
+
name: f.name,
|
|
24140
|
+
arguments: JSON.parse(f.arguments),
|
|
24141
|
+
},
|
|
24142
|
+
})),
|
|
24143
|
+
};
|
|
24144
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
24145
|
+
maxExec: EXECPOOL_SIZE,
|
|
24146
|
+
delay: EXECPOOL_WAIT,
|
|
24147
|
+
});
|
|
24075
24148
|
/**
|
|
24076
24149
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
24077
24150
|
* @param {any} openai - The CohereClientV2 client instance.
|
package/build/index.mjs
CHANGED
|
@@ -13050,6 +13050,23 @@ class SwarmMetaService {
|
|
|
13050
13050
|
}
|
|
13051
13051
|
}
|
|
13052
13052
|
|
|
13053
|
+
const sanitizeMarkdown = (input) => {
|
|
13054
|
+
return input
|
|
13055
|
+
// Remove Markdown headers, emphasis, bold, etc.
|
|
13056
|
+
.replace(/[_*~`>#-]/g, '')
|
|
13057
|
+
// Remove links and images
|
|
13058
|
+
.replace(/\[.*?\]\(.*?\)/g, '')
|
|
13059
|
+
// Remove inline code blocks
|
|
13060
|
+
.replace(/`{1,3}[^`]*`{1,3}/g, '')
|
|
13061
|
+
// Remove horizontal rules
|
|
13062
|
+
.replace(/-{3,}/g, '')
|
|
13063
|
+
// Remove blockquotes
|
|
13064
|
+
.replace(/^>+/gm, '')
|
|
13065
|
+
// Remove HTML tags (often used in Markdown)
|
|
13066
|
+
.replace(/<\/?[^>]+(>|$)/g, '')
|
|
13067
|
+
.trim();
|
|
13068
|
+
};
|
|
13069
|
+
|
|
13053
13070
|
/**
|
|
13054
13071
|
* Maximum number of concurrent threads for documentation generation tasks.
|
|
13055
13072
|
* Used by execpool in writeSwarmDoc and writeAgentDoc to limit parallel execution, balancing performance and resource usage.
|
|
@@ -13210,22 +13227,22 @@ class DocService {
|
|
|
13210
13227
|
const result = [];
|
|
13211
13228
|
{
|
|
13212
13229
|
result.push("---");
|
|
13213
|
-
result.push(`title: ${prefix}/${swarmSchema.swarmName}`);
|
|
13230
|
+
result.push(`title: ${prefix}/${sanitizeMarkdown(swarmSchema.swarmName)}`);
|
|
13214
13231
|
result.push(`group: ${prefix}`);
|
|
13215
13232
|
result.push("---");
|
|
13216
13233
|
result.push("");
|
|
13217
13234
|
}
|
|
13218
13235
|
{
|
|
13219
|
-
result.push(`# ${swarmSchema.swarmName}`);
|
|
13236
|
+
result.push(`# ${sanitizeMarkdown(swarmSchema.swarmName)}`);
|
|
13220
13237
|
if (swarmSchema.docDescription) {
|
|
13221
13238
|
result.push("");
|
|
13222
|
-
result.push(`> ${swarmSchema.docDescription}`);
|
|
13239
|
+
result.push(`> ${sanitizeMarkdown(swarmSchema.docDescription)}`);
|
|
13223
13240
|
}
|
|
13224
13241
|
result.push("");
|
|
13225
13242
|
}
|
|
13226
13243
|
{
|
|
13227
13244
|
const umlSchema = this.swarmMetaService.toUML(swarmSchema.swarmName);
|
|
13228
|
-
const umlName = `swarm_schema_${swarmSchema.swarmName}.svg`;
|
|
13245
|
+
const umlName = `swarm_schema_${sanitizeMarkdown(swarmSchema.swarmName)}.svg`;
|
|
13229
13246
|
const umlSvg = await GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema);
|
|
13230
13247
|
if (umlSvg) {
|
|
13231
13248
|
await writeFileAtomic(join(dirName, "image", umlName), umlSvg);
|
|
@@ -13236,11 +13253,11 @@ class DocService {
|
|
|
13236
13253
|
if (swarmSchema.defaultAgent) {
|
|
13237
13254
|
result.push("## Default agent");
|
|
13238
13255
|
result.push("");
|
|
13239
|
-
result.push(` - [${swarmSchema.defaultAgent}](./agent/${swarmSchema.defaultAgent}.md)`);
|
|
13256
|
+
result.push(` - [${sanitizeMarkdown(swarmSchema.defaultAgent)}](./agent/${sanitizeMarkdown(swarmSchema.defaultAgent)}.md)`);
|
|
13240
13257
|
const { docDescription } = this.agentSchemaService.get(swarmSchema.defaultAgent);
|
|
13241
13258
|
if (docDescription) {
|
|
13242
13259
|
result.push("");
|
|
13243
|
-
result.push(`\t${docDescription}`);
|
|
13260
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13244
13261
|
}
|
|
13245
13262
|
result.push("");
|
|
13246
13263
|
}
|
|
@@ -13251,11 +13268,11 @@ class DocService {
|
|
|
13251
13268
|
if (!swarmSchema.agentList[i]) {
|
|
13252
13269
|
continue;
|
|
13253
13270
|
}
|
|
13254
|
-
result.push(`${i + 1}. [${swarmSchema.agentList[i]}](./agent/${swarmSchema.agentList[i]}.md)`);
|
|
13271
|
+
result.push(`${i + 1}. [${sanitizeMarkdown(swarmSchema.agentList[i])}](./agent/${sanitizeMarkdown(swarmSchema.agentList[i])}.md)`);
|
|
13255
13272
|
const { docDescription } = this.agentSchemaService.get(swarmSchema.agentList[i]);
|
|
13256
13273
|
if (docDescription) {
|
|
13257
13274
|
result.push("");
|
|
13258
|
-
result.push(`\t${docDescription}`);
|
|
13275
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13259
13276
|
}
|
|
13260
13277
|
result.push("");
|
|
13261
13278
|
}
|
|
@@ -13267,11 +13284,11 @@ class DocService {
|
|
|
13267
13284
|
if (!swarmSchema.policies[i]) {
|
|
13268
13285
|
continue;
|
|
13269
13286
|
}
|
|
13270
|
-
result.push(`${i + 1}. ${swarmSchema.policies[i]}`);
|
|
13287
|
+
result.push(`${i + 1}. ${sanitizeMarkdown(swarmSchema.policies[i])}`);
|
|
13271
13288
|
const { docDescription } = this.policySchemaService.get(swarmSchema.policies[i]);
|
|
13272
13289
|
if (docDescription) {
|
|
13273
13290
|
result.push("");
|
|
13274
|
-
result.push(`\t${docDescription}`);
|
|
13291
|
+
result.push(`\t${sanitizeMarkdown(docDescription)}`);
|
|
13275
13292
|
}
|
|
13276
13293
|
result.push("");
|
|
13277
13294
|
}
|
|
@@ -13285,11 +13302,11 @@ class DocService {
|
|
|
13285
13302
|
result.push("");
|
|
13286
13303
|
const callbackList = Object.keys(swarmSchema.callbacks);
|
|
13287
13304
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13288
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13305
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13289
13306
|
}
|
|
13290
13307
|
result.push("");
|
|
13291
13308
|
}
|
|
13292
|
-
await writeFileAtomic(join(dirName, `./${swarmSchema.swarmName}.md`), result.join("\n"));
|
|
13309
|
+
await writeFileAtomic(join(dirName, `./${sanitizeMarkdown(swarmSchema.swarmName)}.md`), result.join("\n"));
|
|
13293
13310
|
}, {
|
|
13294
13311
|
maxExec: THREAD_POOL_SIZE,
|
|
13295
13312
|
delay: THREAD_POOL_DELAY,
|
|
@@ -13311,21 +13328,21 @@ class DocService {
|
|
|
13311
13328
|
const result = [];
|
|
13312
13329
|
{
|
|
13313
13330
|
result.push("---");
|
|
13314
|
-
result.push(`title: ${prefix}/${agentSchema.agentName}`);
|
|
13331
|
+
result.push(`title: ${prefix}/${sanitizeMarkdown(agentSchema.agentName)}`);
|
|
13315
13332
|
result.push(`group: ${prefix}`);
|
|
13316
13333
|
result.push("---");
|
|
13317
13334
|
result.push("");
|
|
13318
13335
|
}
|
|
13319
13336
|
{
|
|
13320
|
-
result.push(`# ${agentSchema.agentName}`);
|
|
13337
|
+
result.push(`# ${sanitizeMarkdown(agentSchema.agentName)}`);
|
|
13321
13338
|
if (agentSchema.docDescription) {
|
|
13322
13339
|
result.push("");
|
|
13323
|
-
result.push(`> ${agentSchema.docDescription}`);
|
|
13340
|
+
result.push(`> ${sanitizeMarkdown(agentSchema.docDescription)}`);
|
|
13324
13341
|
}
|
|
13325
13342
|
result.push("");
|
|
13326
13343
|
}
|
|
13327
13344
|
if (agentSchema.completion) {
|
|
13328
|
-
result.push(`**Completion:** \`${agentSchema.completion}\``);
|
|
13345
|
+
result.push(`**Completion:** \`${sanitizeMarkdown(agentSchema.completion)}\``);
|
|
13329
13346
|
result.push("");
|
|
13330
13347
|
}
|
|
13331
13348
|
{
|
|
@@ -13334,7 +13351,7 @@ class DocService {
|
|
|
13334
13351
|
}
|
|
13335
13352
|
{
|
|
13336
13353
|
const umlSchema = this.agentMetaService.toUML(agentSchema.agentName, true);
|
|
13337
|
-
const umlName = `agent_schema_${agentSchema.agentName}.svg`;
|
|
13354
|
+
const umlName = `agent_schema_${sanitizeMarkdown(agentSchema.agentName)}.svg`;
|
|
13338
13355
|
const umlSvg = await GLOBAL_CONFIG.CC_FN_PLANTUML(umlSchema);
|
|
13339
13356
|
if (umlSvg) {
|
|
13340
13357
|
await writeFileAtomic(join(dirName, "image", umlName), umlSvg);
|
|
@@ -13361,7 +13378,7 @@ class DocService {
|
|
|
13361
13378
|
result.push(`## Main prompt`);
|
|
13362
13379
|
result.push("");
|
|
13363
13380
|
result.push("```");
|
|
13364
|
-
result.push(prompt);
|
|
13381
|
+
result.push(sanitizeMarkdown(prompt));
|
|
13365
13382
|
result.push("```");
|
|
13366
13383
|
result.push("");
|
|
13367
13384
|
}
|
|
@@ -13390,7 +13407,7 @@ class DocService {
|
|
|
13390
13407
|
if (!system[i]) {
|
|
13391
13408
|
continue;
|
|
13392
13409
|
}
|
|
13393
|
-
result.push(`${i + 1}. \`${system[i]}\``);
|
|
13410
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(system[i])}\``);
|
|
13394
13411
|
result.push("");
|
|
13395
13412
|
}
|
|
13396
13413
|
}
|
|
@@ -13401,11 +13418,11 @@ class DocService {
|
|
|
13401
13418
|
if (!agentSchema.dependsOn[i]) {
|
|
13402
13419
|
continue;
|
|
13403
13420
|
}
|
|
13404
|
-
result.push(`${i + 1}. [${agentSchema.dependsOn[i]}](./${agentSchema.dependsOn[i]}.md)`);
|
|
13421
|
+
result.push(`${i + 1}. [${sanitizeMarkdown(agentSchema.dependsOn[i])}](./${sanitizeMarkdown(agentSchema.dependsOn[i])}.md)`);
|
|
13405
13422
|
const { docDescription } = this.agentSchemaService.get(agentSchema.dependsOn[i]);
|
|
13406
13423
|
if (docDescription) {
|
|
13407
13424
|
result.push("");
|
|
13408
|
-
result.push(docDescription);
|
|
13425
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13409
13426
|
}
|
|
13410
13427
|
result.push("");
|
|
13411
13428
|
}
|
|
@@ -13417,11 +13434,11 @@ class DocService {
|
|
|
13417
13434
|
if (!agentSchema.mcp[i]) {
|
|
13418
13435
|
continue;
|
|
13419
13436
|
}
|
|
13420
|
-
result.push(`${i + 1}. ${agentSchema.mcp[i]}`);
|
|
13437
|
+
result.push(`${i + 1}. ${sanitizeMarkdown(agentSchema.mcp[i])}`);
|
|
13421
13438
|
const { docDescription } = this.mcpSchemaService.get(agentSchema.mcp[i]);
|
|
13422
13439
|
if (docDescription) {
|
|
13423
13440
|
result.push("");
|
|
13424
|
-
result.push(docDescription);
|
|
13441
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13425
13442
|
}
|
|
13426
13443
|
result.push("");
|
|
13427
13444
|
}
|
|
@@ -13457,18 +13474,18 @@ class DocService {
|
|
|
13457
13474
|
continue;
|
|
13458
13475
|
}
|
|
13459
13476
|
const { function: fn, docNote, callbacks } = tools[i];
|
|
13460
|
-
result.push(`### ${i + 1}. ${agentSchema.tools[i]}`);
|
|
13477
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.tools[i])}`);
|
|
13461
13478
|
if (fn.name) {
|
|
13462
13479
|
result.push("");
|
|
13463
13480
|
result.push("#### Name for model");
|
|
13464
13481
|
result.push("");
|
|
13465
|
-
result.push(`\`${fn.name}\``);
|
|
13482
|
+
result.push(`\`${sanitizeMarkdown(fn.name)}\``);
|
|
13466
13483
|
}
|
|
13467
13484
|
if (fn.description) {
|
|
13468
13485
|
result.push("");
|
|
13469
13486
|
result.push("#### Description for model");
|
|
13470
13487
|
result.push("");
|
|
13471
|
-
result.push(`\`${fn.description}\``);
|
|
13488
|
+
result.push(`\`${sanitizeMarkdown(fn.description)}\``);
|
|
13472
13489
|
}
|
|
13473
13490
|
if (fn.parameters?.properties) {
|
|
13474
13491
|
result.push("");
|
|
@@ -13476,18 +13493,18 @@ class DocService {
|
|
|
13476
13493
|
const entries = Object.entries(fn.parameters.properties);
|
|
13477
13494
|
entries.forEach(([key, { type, description, enum: e }], idx) => {
|
|
13478
13495
|
result.push("");
|
|
13479
|
-
result.push(`> **${idx + 1}. ${key}**`);
|
|
13496
|
+
result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
|
|
13480
13497
|
{
|
|
13481
13498
|
result.push("");
|
|
13482
|
-
result.push(`*Type:* \`${type}\``);
|
|
13499
|
+
result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
|
|
13483
13500
|
}
|
|
13484
13501
|
{
|
|
13485
13502
|
result.push("");
|
|
13486
|
-
result.push(`*Description:* \`${description}\``);
|
|
13503
|
+
result.push(`*Description:* \`${sanitizeMarkdown(description)}\``);
|
|
13487
13504
|
}
|
|
13488
13505
|
if (e) {
|
|
13489
13506
|
result.push("");
|
|
13490
|
-
result.push(`*Enum:* \`${e.join(", ")}\``);
|
|
13507
|
+
result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
|
|
13491
13508
|
}
|
|
13492
13509
|
{
|
|
13493
13510
|
result.push("");
|
|
@@ -13505,14 +13522,14 @@ class DocService {
|
|
|
13505
13522
|
result.push("");
|
|
13506
13523
|
const callbackList = Object.keys(callbacks);
|
|
13507
13524
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13508
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13525
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13509
13526
|
}
|
|
13510
13527
|
}
|
|
13511
13528
|
if (docNote) {
|
|
13512
13529
|
result.push("");
|
|
13513
13530
|
result.push("#### Note for developer");
|
|
13514
13531
|
result.push("");
|
|
13515
|
-
result.push(`*${docNote}*`);
|
|
13532
|
+
result.push(`*${sanitizeMarkdown(docNote)}*`);
|
|
13516
13533
|
}
|
|
13517
13534
|
result.push("");
|
|
13518
13535
|
}
|
|
@@ -13524,17 +13541,17 @@ class DocService {
|
|
|
13524
13541
|
if (!agentSchema.storages[i]) {
|
|
13525
13542
|
continue;
|
|
13526
13543
|
}
|
|
13527
|
-
result.push(`### ${i + 1}. ${agentSchema.storages[i]}`);
|
|
13544
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.storages[i])}`);
|
|
13528
13545
|
const { docDescription, embedding, shared, callbacks } = this.storageSchemaService.get(agentSchema.storages[i]);
|
|
13529
13546
|
if (docDescription) {
|
|
13530
13547
|
result.push("");
|
|
13531
13548
|
result.push(`#### Storage description`);
|
|
13532
13549
|
result.push("");
|
|
13533
|
-
result.push(docDescription);
|
|
13550
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13534
13551
|
}
|
|
13535
13552
|
if (embedding) {
|
|
13536
13553
|
result.push("");
|
|
13537
|
-
result.push(`*Embedding:* \`${embedding}\``);
|
|
13554
|
+
result.push(`*Embedding:* \`${sanitizeMarkdown(embedding)}\``);
|
|
13538
13555
|
}
|
|
13539
13556
|
{
|
|
13540
13557
|
result.push("");
|
|
@@ -13546,7 +13563,7 @@ class DocService {
|
|
|
13546
13563
|
result.push("");
|
|
13547
13564
|
const callbackList = Object.keys(callbacks);
|
|
13548
13565
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13549
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13566
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13550
13567
|
}
|
|
13551
13568
|
}
|
|
13552
13569
|
result.push("");
|
|
@@ -13570,13 +13587,13 @@ class DocService {
|
|
|
13570
13587
|
if (!agentSchema.states[i]) {
|
|
13571
13588
|
continue;
|
|
13572
13589
|
}
|
|
13573
|
-
result.push(`### ${i + 1}. ${agentSchema.states[i]}`);
|
|
13590
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.states[i])}`);
|
|
13574
13591
|
const { docDescription, shared, callbacks } = this.stateSchemaService.get(agentSchema.states[i]);
|
|
13575
13592
|
if (docDescription) {
|
|
13576
13593
|
result.push("");
|
|
13577
13594
|
result.push(`#### State description`);
|
|
13578
13595
|
result.push("");
|
|
13579
|
-
result.push(docDescription);
|
|
13596
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13580
13597
|
}
|
|
13581
13598
|
{
|
|
13582
13599
|
const computeSchemasCurrentList = computeSchemasTotalList.filter(([stateName]) => stateName === agentSchema.states[i]);
|
|
@@ -13587,10 +13604,10 @@ class DocService {
|
|
|
13587
13604
|
for (let i = 0; i !== computeSchemasCurrentList.length; i++) {
|
|
13588
13605
|
const [, { computeName, docDescription }] = computeSchemasCurrentList[i];
|
|
13589
13606
|
result.push("");
|
|
13590
|
-
result.push(`> **${i + 1}. ${computeName}**`);
|
|
13607
|
+
result.push(`> **${i + 1}. ${sanitizeMarkdown(computeName)}**`);
|
|
13591
13608
|
{
|
|
13592
13609
|
result.push("");
|
|
13593
|
-
result.push(`*Description:* \`${docDescription}\``);
|
|
13610
|
+
result.push(`*Description:* \`${sanitizeMarkdown(docDescription)}\``);
|
|
13594
13611
|
}
|
|
13595
13612
|
}
|
|
13596
13613
|
result.push("");
|
|
@@ -13603,7 +13620,7 @@ class DocService {
|
|
|
13603
13620
|
result.push("");
|
|
13604
13621
|
const callbackList = Object.keys(callbacks);
|
|
13605
13622
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13606
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13623
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13607
13624
|
}
|
|
13608
13625
|
}
|
|
13609
13626
|
}
|
|
@@ -13621,13 +13638,13 @@ class DocService {
|
|
|
13621
13638
|
if (!agentSchema.wikiList[i]) {
|
|
13622
13639
|
continue;
|
|
13623
13640
|
}
|
|
13624
|
-
result.push(`### ${i + 1}. ${agentSchema.wikiList[i]}`);
|
|
13641
|
+
result.push(`### ${i + 1}. ${sanitizeMarkdown(agentSchema.wikiList[i])}`);
|
|
13625
13642
|
const { docDescription, callbacks } = this.wikiSchemaService.get(agentSchema.wikiList[i]);
|
|
13626
13643
|
if (docDescription) {
|
|
13627
13644
|
result.push("");
|
|
13628
13645
|
result.push(`#### Wiki description`);
|
|
13629
13646
|
result.push("");
|
|
13630
|
-
result.push(docDescription);
|
|
13647
|
+
result.push(sanitizeMarkdown(docDescription));
|
|
13631
13648
|
}
|
|
13632
13649
|
if (callbacks) {
|
|
13633
13650
|
result.push("");
|
|
@@ -13635,7 +13652,7 @@ class DocService {
|
|
|
13635
13652
|
result.push("");
|
|
13636
13653
|
const callbackList = Object.keys(callbacks);
|
|
13637
13654
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13638
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13655
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13639
13656
|
}
|
|
13640
13657
|
}
|
|
13641
13658
|
result.push("");
|
|
@@ -13646,11 +13663,11 @@ class DocService {
|
|
|
13646
13663
|
result.push("");
|
|
13647
13664
|
const callbackList = Object.keys(agentSchema.callbacks);
|
|
13648
13665
|
for (let i = 0; i !== callbackList.length; i++) {
|
|
13649
|
-
result.push(`${i + 1}. \`${callbackList[i]}\``);
|
|
13666
|
+
result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
|
|
13650
13667
|
}
|
|
13651
13668
|
result.push("");
|
|
13652
13669
|
}
|
|
13653
|
-
await writeFileAtomic(join(dirName, `./agent/${agentSchema.agentName}.md`), result.join("\n"));
|
|
13670
|
+
await writeFileAtomic(join(dirName, `./agent/${sanitizeMarkdown(agentSchema.agentName)}.md`), result.join("\n"));
|
|
13654
13671
|
}, {
|
|
13655
13672
|
maxExec: THREAD_POOL_SIZE,
|
|
13656
13673
|
delay: THREAD_POOL_DELAY,
|
|
@@ -24070,6 +24087,62 @@ const RETRY_DELAY = 5000;
|
|
|
24070
24087
|
*/
|
|
24071
24088
|
class AdapterUtils {
|
|
24072
24089
|
constructor() {
|
|
24090
|
+
/**
|
|
24091
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
24092
|
+
* @param {any} grok - The Grok client instance.
|
|
24093
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
24094
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
24095
|
+
*/
|
|
24096
|
+
this.fromGrok = (grok, model = "grok-3-mini") =>
|
|
24097
|
+
/**
|
|
24098
|
+
* Handles a completion request to Grok, transforming messages and tools into the required format.
|
|
24099
|
+
* Executes requests in a pool to limit concurrency with retry logic for reliability.
|
|
24100
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
24101
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
24102
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to Grok.
|
|
24103
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
24104
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
24105
|
+
* @returns {Promise<IModelMessage>} The response from Grok in `agent-swarm-kit` format.
|
|
24106
|
+
*/
|
|
24107
|
+
execpool(retry(async ({ agentName, messages: rawMessages, mode, tools, clientId, }) => {
|
|
24108
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromGrok completion", JSON.stringify(rawMessages));
|
|
24109
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
24110
|
+
role,
|
|
24111
|
+
tool_call_id,
|
|
24112
|
+
content,
|
|
24113
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24114
|
+
...rest,
|
|
24115
|
+
function: {
|
|
24116
|
+
name: f.name,
|
|
24117
|
+
arguments: JSON.stringify(f.arguments),
|
|
24118
|
+
},
|
|
24119
|
+
})),
|
|
24120
|
+
}));
|
|
24121
|
+
const { choices: [{ message: { content, role, tool_calls }, },], } = await grok.chat.completions.create({
|
|
24122
|
+
model,
|
|
24123
|
+
messages: messages,
|
|
24124
|
+
tools: tools,
|
|
24125
|
+
response_format: {
|
|
24126
|
+
type: "text",
|
|
24127
|
+
},
|
|
24128
|
+
});
|
|
24129
|
+
return {
|
|
24130
|
+
content: content,
|
|
24131
|
+
mode,
|
|
24132
|
+
agentName,
|
|
24133
|
+
role,
|
|
24134
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24135
|
+
...rest,
|
|
24136
|
+
function: {
|
|
24137
|
+
name: f.name,
|
|
24138
|
+
arguments: JSON.parse(f.arguments),
|
|
24139
|
+
},
|
|
24140
|
+
})),
|
|
24141
|
+
};
|
|
24142
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
24143
|
+
maxExec: EXECPOOL_SIZE,
|
|
24144
|
+
delay: EXECPOOL_WAIT,
|
|
24145
|
+
});
|
|
24073
24146
|
/**
|
|
24074
24147
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
24075
24148
|
* @param {any} openai - The CohereClientV2 client instance.
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -14751,6 +14751,13 @@ type TCompleteFn = (args: ICompletionArgs) => Promise<IModelMessage>;
|
|
|
14751
14751
|
* Utility class providing adapter functions for interacting with various AI completion providers.
|
|
14752
14752
|
*/
|
|
14753
14753
|
declare class AdapterUtils {
|
|
14754
|
+
/**
|
|
14755
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
14756
|
+
* @param {any} grok - The Grok client instance.
|
|
14757
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
14758
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
14759
|
+
*/
|
|
14760
|
+
fromGrok: (grok: any, model?: string) => TCompleteFn;
|
|
14754
14761
|
/**
|
|
14755
14762
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
14756
14763
|
* @param {any} openai - The CohereClientV2 client instance.
|