agent-swarm-kit 1.1.113 → 1.1.115

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 CHANGED
@@ -13211,6 +13211,13 @@ class DocService {
13211
13211
  * @private
13212
13212
  */
13213
13213
  this.agentValidationService = inject(TYPES.agentValidationService);
13214
+ /**
13215
+ * Outline validation service instance, injected via DI.
13216
+ * Used for validating and managing agent outline schemas, ensuring agent outlines conform to expected structure and constraints.
13217
+ * @type {OutlineValidationService}
13218
+ * @private
13219
+ */
13220
+ this.outlineValidationService = inject(TYPES.outlineValidationService);
13214
13221
  /**
13215
13222
  * Swarm schema service instance, injected via DI.
13216
13223
  * Retrieves ISwarmSchema objects for writeSwarmDoc, supplying swarm details like agents and policies.
@@ -13225,6 +13232,13 @@ class DocService {
13225
13232
  * @private
13226
13233
  */
13227
13234
  this.agentSchemaService = inject(TYPES.agentSchemaService);
13235
+ /**
13236
+ * Outline schema service instance, injected via DI.
13237
+ * Retrieves and manages outline schema objects for agents, supporting documentation and validation of agent outlines.
13238
+ * @type {OutlineSchemaService}
13239
+ * @private
13240
+ */
13241
+ this.outlineSchemaService = inject(TYPES.outlineSchemaService);
13228
13242
  /**
13229
13243
  * Model context protocol service instance, injected via DI.
13230
13244
  * Retrieves IMCPSchema objects for writeAgentDoc and agent descriptions in writeSwarmDoc, providing details like tools and prompts.
@@ -13396,6 +13410,142 @@ class DocService {
13396
13410
  maxExec: THREAD_POOL_SIZE,
13397
13411
  delay: THREAD_POOL_DELAY,
13398
13412
  });
13413
+ /**
13414
+ * Writes Markdown documentation for an outline schema, detailing its name, description, main prompt, output format, and callbacks.
13415
+ * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
13416
+ * Outputs to dirName/[outlineName].md, sourced from outlineSchemaService.
13417
+ *
13418
+ * - The Markdown includes YAML frontmatter, outline name, description, prompt(s), output format (with types, descriptions, enums, and required fields), and callbacks.
13419
+ * - Handles both string and function-based prompts, and supports array or string prompt types.
13420
+ * - Output format section documents each property, its type, description, enum values, and required status.
13421
+ * - Callback section lists all callback names used by the outline.
13422
+ *
13423
+ * @param {IOutlineSchema} outlineSchema - The outline schema to document, including properties like prompt, format, and callbacks.
13424
+ * @param {string} prefix - The documentation group or prefix for organizing output.
13425
+ * @param {string} dirName - The base directory for documentation output.
13426
+ * @param {(text: string) => string} [sanitizeMarkdown=(t) => t] - Optional function to sanitize Markdown text.
13427
+ * @returns {Promise<void>} A promise resolving when the outline documentation file is written.
13428
+ * @private
13429
+ */
13430
+ this.writeOutlineDoc = functoolsKit.execpool(async (outlineSchema, prefix, dirName, sanitizeMarkdown = (t) => t) => {
13431
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
13432
+ this.loggerService.info("docService writeOutlineDoc", {
13433
+ outlineSchema,
13434
+ });
13435
+ const result = [];
13436
+ {
13437
+ result.push("---");
13438
+ result.push(`title: ${prefix}/${sanitizeMarkdown(outlineSchema.outlineName)}`);
13439
+ result.push(`group: ${prefix}`);
13440
+ result.push("---");
13441
+ result.push("");
13442
+ }
13443
+ {
13444
+ result.push(`# ${sanitizeMarkdown(outlineSchema.outlineName)}`);
13445
+ if (outlineSchema.docDescription) {
13446
+ result.push("");
13447
+ result.push(`> ${sanitizeMarkdown(outlineSchema.docDescription)}`);
13448
+ }
13449
+ result.push("");
13450
+ }
13451
+ const getPrompt = async () => {
13452
+ try {
13453
+ if (typeof outlineSchema.prompt === "string") {
13454
+ return outlineSchema.prompt;
13455
+ }
13456
+ if (typeof outlineSchema.prompt === "function") {
13457
+ return await outlineSchema.prompt(outlineSchema.outlineName);
13458
+ }
13459
+ return null;
13460
+ }
13461
+ catch {
13462
+ return null;
13463
+ }
13464
+ };
13465
+ const prompt = await getPrompt();
13466
+ if (Array.isArray(prompt)) {
13467
+ result.push(`## Main prompt`);
13468
+ result.push("");
13469
+ for (let i = 0; i !== prompt.length; i++) {
13470
+ if (!prompt[i]) {
13471
+ continue;
13472
+ }
13473
+ result.push(`${i + 1}. \`${sanitizeMarkdown(prompt[i])}\``);
13474
+ result.push("");
13475
+ }
13476
+ }
13477
+ if (typeof prompt === "string") {
13478
+ result.push(`## Main prompt`);
13479
+ result.push("");
13480
+ result.push("```");
13481
+ result.push(sanitizeMarkdown(prompt));
13482
+ result.push("```");
13483
+ result.push("");
13484
+ }
13485
+ if (outlineSchema.format) {
13486
+ result.push("");
13487
+ result.push("## Output format");
13488
+ const entries = Object.entries(outlineSchema.format.properties);
13489
+ entries.forEach(([key, { type, description, enum: e }], idx) => {
13490
+ result.push("");
13491
+ result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
13492
+ {
13493
+ result.push("");
13494
+ result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
13495
+ }
13496
+ {
13497
+ result.push("");
13498
+ result.push(`*Description:* \`${sanitizeMarkdown(description)}\``);
13499
+ }
13500
+ if (e) {
13501
+ result.push("");
13502
+ result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
13503
+ }
13504
+ {
13505
+ result.push("");
13506
+ result.push(`*Required:* [${outlineSchema.format.required.includes(key) ? "x" : " "}]`);
13507
+ }
13508
+ });
13509
+ if (!entries.length) {
13510
+ result.push("");
13511
+ result.push(`*Empty parameters*`);
13512
+ }
13513
+ result.push("");
13514
+ }
13515
+ const getValidations = () => {
13516
+ if (outlineSchema.validations) {
13517
+ return outlineSchema.validations
13518
+ .filter((validation) => typeof validation === "object")
13519
+ .filter((validation) => !!validation.docDescription);
13520
+ }
13521
+ return [];
13522
+ };
13523
+ const validations = getValidations();
13524
+ if (validations.length) {
13525
+ result.push(`## Validations`);
13526
+ result.push("");
13527
+ for (let i = 0; i !== prompt.length; i++) {
13528
+ if (!validations[i].docDescription) {
13529
+ continue;
13530
+ }
13531
+ result.push(`${i + 1}. \`${sanitizeMarkdown(validations[i].docDescription)}\``);
13532
+ result.push("");
13533
+ }
13534
+ }
13535
+ if (outlineSchema.callbacks) {
13536
+ result.push(`## Used callbacks`);
13537
+ result.push("");
13538
+ const callbackList = Object.keys(outlineSchema.callbacks);
13539
+ for (let i = 0; i !== callbackList.length; i++) {
13540
+ result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
13541
+ }
13542
+ result.push("");
13543
+ }
13544
+ await writeFileAtomic(path.join(dirName, `./${outlineSchema.outlineName}.md`), result.join("\n"));
13545
+ }, {
13546
+ maxExec: THREAD_POOL_SIZE,
13547
+ delay: THREAD_POOL_DELAY,
13548
+ });
13399
13549
  /**
13400
13550
  * Writes Markdown documentation for an agent schema, detailing its name, description, UML diagram, prompts, tools, storages, states, and callbacks.
13401
13551
  * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
@@ -13787,6 +13937,14 @@ class DocService {
13787
13937
  const agentSchema = this.agentSchemaService.get(agentName);
13788
13938
  await this.writeAgentDoc(agentSchema, prefix, dirName, sanitizeMarkdown);
13789
13939
  }));
13940
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
13941
+ this.loggerService.info("docService dumpDocs building outline docs");
13942
+ await Promise.all(this.outlineValidationService
13943
+ .getOutlineList()
13944
+ .map(async (outlineName) => {
13945
+ const outlineSchema = this.outlineSchemaService.get(outlineName);
13946
+ await this.writeOutlineDoc(outlineSchema, prefix, dirName, sanitizeMarkdown);
13947
+ }));
13790
13948
  };
13791
13949
  /**
13792
13950
  * Dumps system-wide performance data to a JSON file using PerfService.toRecord.
@@ -18197,6 +18355,16 @@ class OutlineValidationService {
18197
18355
  }
18198
18356
  this._outlineMap.set(outlineName, outlineSchema);
18199
18357
  };
18358
+ /**
18359
+ * Retrieves a list of all registered outline names.
18360
+ * Logs the retrieval operation if info logging is enabled.
18361
+ * @returns {OutlineName[]} An array of registered outline names.
18362
+ */
18363
+ this.getOutlineList = () => {
18364
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
18365
+ this.loggerService.info("outlineValidationService getOutlineList");
18366
+ return [...this._outlineMap.keys()];
18367
+ };
18200
18368
  /**
18201
18369
  * Validates the existence of an outline schema for the given outline name.
18202
18370
  * Memoized to cache results based on the outline name for performance.
@@ -18424,6 +18592,9 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
18424
18592
  console.error(`agent-swarm missing dependsOn for agentName=${agentName}`);
18425
18593
  }
18426
18594
  });
18595
+ swarm$1.outlineValidationService
18596
+ .getOutlineList()
18597
+ .forEach((swarmName) => swarm$1.outlineValidationService.validate(swarmName, METHOD_NAME$1x));
18427
18598
  return swarm$1.docService.dumpDocs(prefix, dirName, sanitizeMarkdown);
18428
18599
  });
18429
18600
 
@@ -20954,9 +21125,18 @@ const MAX_ATTEMPTS = 5;
20954
21125
  * @implements {IOutlineHistory }
20955
21126
  */
20956
21127
  class OutlineHistory {
20957
- constructor() {
21128
+ /**
21129
+ * Constructs an OutlineHistory instance, optionally initializing with a system prompt.
21130
+ * @param {string} [prompt] - An optional system prompt to initialize the history with.
21131
+ * @constructor
21132
+ */
21133
+ constructor(prompt) {
20958
21134
  /** @private */
20959
21135
  this.messages = [];
21136
+ prompt && this.messages.push({
21137
+ role: "system",
21138
+ content: prompt
21139
+ });
20960
21140
  }
20961
21141
  /**
20962
21142
  * Appends one or more messages to the history.
@@ -20997,14 +21177,17 @@ class OutlineHistory {
20997
21177
  const jsonInternal = beginContext(async (outlineName, param) => {
20998
21178
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
20999
21179
  swarm$1.loggerService.log(METHOD_NAME$D, {});
21180
+ swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$D);
21000
21181
  const resultId = functoolsKit.randomString();
21001
- const { getStructuredOutput, validations = [], maxAttempts = MAX_ATTEMPTS, callbacks, } = swarm$1.outlineSchemaService.get(outlineName);
21182
+ const { getStructuredOutput, validations = [], maxAttempts = MAX_ATTEMPTS, format, prompt, callbacks, } = swarm$1.outlineSchemaService.get(outlineName);
21002
21183
  let errorMessage = "";
21003
21184
  let history;
21185
+ const systemPrompt = functoolsKit.str.newline(typeof prompt === "function" ? await prompt(outlineName) : prompt);
21004
21186
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
21005
- history = new OutlineHistory();
21187
+ history = new OutlineHistory(systemPrompt);
21006
21188
  const inputArgs = {
21007
21189
  attempt,
21190
+ format,
21008
21191
  param,
21009
21192
  history,
21010
21193
  };
package/build/index.mjs CHANGED
@@ -13209,6 +13209,13 @@ class DocService {
13209
13209
  * @private
13210
13210
  */
13211
13211
  this.agentValidationService = inject(TYPES.agentValidationService);
13212
+ /**
13213
+ * Outline validation service instance, injected via DI.
13214
+ * Used for validating and managing agent outline schemas, ensuring agent outlines conform to expected structure and constraints.
13215
+ * @type {OutlineValidationService}
13216
+ * @private
13217
+ */
13218
+ this.outlineValidationService = inject(TYPES.outlineValidationService);
13212
13219
  /**
13213
13220
  * Swarm schema service instance, injected via DI.
13214
13221
  * Retrieves ISwarmSchema objects for writeSwarmDoc, supplying swarm details like agents and policies.
@@ -13223,6 +13230,13 @@ class DocService {
13223
13230
  * @private
13224
13231
  */
13225
13232
  this.agentSchemaService = inject(TYPES.agentSchemaService);
13233
+ /**
13234
+ * Outline schema service instance, injected via DI.
13235
+ * Retrieves and manages outline schema objects for agents, supporting documentation and validation of agent outlines.
13236
+ * @type {OutlineSchemaService}
13237
+ * @private
13238
+ */
13239
+ this.outlineSchemaService = inject(TYPES.outlineSchemaService);
13226
13240
  /**
13227
13241
  * Model context protocol service instance, injected via DI.
13228
13242
  * Retrieves IMCPSchema objects for writeAgentDoc and agent descriptions in writeSwarmDoc, providing details like tools and prompts.
@@ -13394,6 +13408,142 @@ class DocService {
13394
13408
  maxExec: THREAD_POOL_SIZE,
13395
13409
  delay: THREAD_POOL_DELAY,
13396
13410
  });
13411
+ /**
13412
+ * Writes Markdown documentation for an outline schema, detailing its name, description, main prompt, output format, and callbacks.
13413
+ * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
13414
+ * Outputs to dirName/[outlineName].md, sourced from outlineSchemaService.
13415
+ *
13416
+ * - The Markdown includes YAML frontmatter, outline name, description, prompt(s), output format (with types, descriptions, enums, and required fields), and callbacks.
13417
+ * - Handles both string and function-based prompts, and supports array or string prompt types.
13418
+ * - Output format section documents each property, its type, description, enum values, and required status.
13419
+ * - Callback section lists all callback names used by the outline.
13420
+ *
13421
+ * @param {IOutlineSchema} outlineSchema - The outline schema to document, including properties like prompt, format, and callbacks.
13422
+ * @param {string} prefix - The documentation group or prefix for organizing output.
13423
+ * @param {string} dirName - The base directory for documentation output.
13424
+ * @param {(text: string) => string} [sanitizeMarkdown=(t) => t] - Optional function to sanitize Markdown text.
13425
+ * @returns {Promise<void>} A promise resolving when the outline documentation file is written.
13426
+ * @private
13427
+ */
13428
+ this.writeOutlineDoc = execpool(async (outlineSchema, prefix, dirName, sanitizeMarkdown = (t) => t) => {
13429
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
13430
+ this.loggerService.info("docService writeOutlineDoc", {
13431
+ outlineSchema,
13432
+ });
13433
+ const result = [];
13434
+ {
13435
+ result.push("---");
13436
+ result.push(`title: ${prefix}/${sanitizeMarkdown(outlineSchema.outlineName)}`);
13437
+ result.push(`group: ${prefix}`);
13438
+ result.push("---");
13439
+ result.push("");
13440
+ }
13441
+ {
13442
+ result.push(`# ${sanitizeMarkdown(outlineSchema.outlineName)}`);
13443
+ if (outlineSchema.docDescription) {
13444
+ result.push("");
13445
+ result.push(`> ${sanitizeMarkdown(outlineSchema.docDescription)}`);
13446
+ }
13447
+ result.push("");
13448
+ }
13449
+ const getPrompt = async () => {
13450
+ try {
13451
+ if (typeof outlineSchema.prompt === "string") {
13452
+ return outlineSchema.prompt;
13453
+ }
13454
+ if (typeof outlineSchema.prompt === "function") {
13455
+ return await outlineSchema.prompt(outlineSchema.outlineName);
13456
+ }
13457
+ return null;
13458
+ }
13459
+ catch {
13460
+ return null;
13461
+ }
13462
+ };
13463
+ const prompt = await getPrompt();
13464
+ if (Array.isArray(prompt)) {
13465
+ result.push(`## Main prompt`);
13466
+ result.push("");
13467
+ for (let i = 0; i !== prompt.length; i++) {
13468
+ if (!prompt[i]) {
13469
+ continue;
13470
+ }
13471
+ result.push(`${i + 1}. \`${sanitizeMarkdown(prompt[i])}\``);
13472
+ result.push("");
13473
+ }
13474
+ }
13475
+ if (typeof prompt === "string") {
13476
+ result.push(`## Main prompt`);
13477
+ result.push("");
13478
+ result.push("```");
13479
+ result.push(sanitizeMarkdown(prompt));
13480
+ result.push("```");
13481
+ result.push("");
13482
+ }
13483
+ if (outlineSchema.format) {
13484
+ result.push("");
13485
+ result.push("## Output format");
13486
+ const entries = Object.entries(outlineSchema.format.properties);
13487
+ entries.forEach(([key, { type, description, enum: e }], idx) => {
13488
+ result.push("");
13489
+ result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
13490
+ {
13491
+ result.push("");
13492
+ result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
13493
+ }
13494
+ {
13495
+ result.push("");
13496
+ result.push(`*Description:* \`${sanitizeMarkdown(description)}\``);
13497
+ }
13498
+ if (e) {
13499
+ result.push("");
13500
+ result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
13501
+ }
13502
+ {
13503
+ result.push("");
13504
+ result.push(`*Required:* [${outlineSchema.format.required.includes(key) ? "x" : " "}]`);
13505
+ }
13506
+ });
13507
+ if (!entries.length) {
13508
+ result.push("");
13509
+ result.push(`*Empty parameters*`);
13510
+ }
13511
+ result.push("");
13512
+ }
13513
+ const getValidations = () => {
13514
+ if (outlineSchema.validations) {
13515
+ return outlineSchema.validations
13516
+ .filter((validation) => typeof validation === "object")
13517
+ .filter((validation) => !!validation.docDescription);
13518
+ }
13519
+ return [];
13520
+ };
13521
+ const validations = getValidations();
13522
+ if (validations.length) {
13523
+ result.push(`## Validations`);
13524
+ result.push("");
13525
+ for (let i = 0; i !== prompt.length; i++) {
13526
+ if (!validations[i].docDescription) {
13527
+ continue;
13528
+ }
13529
+ result.push(`${i + 1}. \`${sanitizeMarkdown(validations[i].docDescription)}\``);
13530
+ result.push("");
13531
+ }
13532
+ }
13533
+ if (outlineSchema.callbacks) {
13534
+ result.push(`## Used callbacks`);
13535
+ result.push("");
13536
+ const callbackList = Object.keys(outlineSchema.callbacks);
13537
+ for (let i = 0; i !== callbackList.length; i++) {
13538
+ result.push(`${i + 1}. \`${sanitizeMarkdown(callbackList[i])}\``);
13539
+ }
13540
+ result.push("");
13541
+ }
13542
+ await writeFileAtomic(join(dirName, `./${outlineSchema.outlineName}.md`), result.join("\n"));
13543
+ }, {
13544
+ maxExec: THREAD_POOL_SIZE,
13545
+ delay: THREAD_POOL_DELAY,
13546
+ });
13397
13547
  /**
13398
13548
  * Writes Markdown documentation for an agent schema, detailing its name, description, UML diagram, prompts, tools, storages, states, and callbacks.
13399
13549
  * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
@@ -13785,6 +13935,14 @@ class DocService {
13785
13935
  const agentSchema = this.agentSchemaService.get(agentName);
13786
13936
  await this.writeAgentDoc(agentSchema, prefix, dirName, sanitizeMarkdown);
13787
13937
  }));
13938
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
13939
+ this.loggerService.info("docService dumpDocs building outline docs");
13940
+ await Promise.all(this.outlineValidationService
13941
+ .getOutlineList()
13942
+ .map(async (outlineName) => {
13943
+ const outlineSchema = this.outlineSchemaService.get(outlineName);
13944
+ await this.writeOutlineDoc(outlineSchema, prefix, dirName, sanitizeMarkdown);
13945
+ }));
13788
13946
  };
13789
13947
  /**
13790
13948
  * Dumps system-wide performance data to a JSON file using PerfService.toRecord.
@@ -18195,6 +18353,16 @@ class OutlineValidationService {
18195
18353
  }
18196
18354
  this._outlineMap.set(outlineName, outlineSchema);
18197
18355
  };
18356
+ /**
18357
+ * Retrieves a list of all registered outline names.
18358
+ * Logs the retrieval operation if info logging is enabled.
18359
+ * @returns {OutlineName[]} An array of registered outline names.
18360
+ */
18361
+ this.getOutlineList = () => {
18362
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
18363
+ this.loggerService.info("outlineValidationService getOutlineList");
18364
+ return [...this._outlineMap.keys()];
18365
+ };
18198
18366
  /**
18199
18367
  * Validates the existence of an outline schema for the given outline name.
18200
18368
  * Memoized to cache results based on the outline name for performance.
@@ -18422,6 +18590,9 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
18422
18590
  console.error(`agent-swarm missing dependsOn for agentName=${agentName}`);
18423
18591
  }
18424
18592
  });
18593
+ swarm$1.outlineValidationService
18594
+ .getOutlineList()
18595
+ .forEach((swarmName) => swarm$1.outlineValidationService.validate(swarmName, METHOD_NAME$1x));
18425
18596
  return swarm$1.docService.dumpDocs(prefix, dirName, sanitizeMarkdown);
18426
18597
  });
18427
18598
 
@@ -20952,9 +21123,18 @@ const MAX_ATTEMPTS = 5;
20952
21123
  * @implements {IOutlineHistory }
20953
21124
  */
20954
21125
  class OutlineHistory {
20955
- constructor() {
21126
+ /**
21127
+ * Constructs an OutlineHistory instance, optionally initializing with a system prompt.
21128
+ * @param {string} [prompt] - An optional system prompt to initialize the history with.
21129
+ * @constructor
21130
+ */
21131
+ constructor(prompt) {
20956
21132
  /** @private */
20957
21133
  this.messages = [];
21134
+ prompt && this.messages.push({
21135
+ role: "system",
21136
+ content: prompt
21137
+ });
20958
21138
  }
20959
21139
  /**
20960
21140
  * Appends one or more messages to the history.
@@ -20995,14 +21175,17 @@ class OutlineHistory {
20995
21175
  const jsonInternal = beginContext(async (outlineName, param) => {
20996
21176
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
20997
21177
  swarm$1.loggerService.log(METHOD_NAME$D, {});
21178
+ swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$D);
20998
21179
  const resultId = randomString();
20999
- const { getStructuredOutput, validations = [], maxAttempts = MAX_ATTEMPTS, callbacks, } = swarm$1.outlineSchemaService.get(outlineName);
21180
+ const { getStructuredOutput, validations = [], maxAttempts = MAX_ATTEMPTS, format, prompt, callbacks, } = swarm$1.outlineSchemaService.get(outlineName);
21000
21181
  let errorMessage = "";
21001
21182
  let history;
21183
+ const systemPrompt = str.newline(typeof prompt === "function" ? await prompt(outlineName) : prompt);
21002
21184
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
21003
- history = new OutlineHistory();
21185
+ history = new OutlineHistory(systemPrompt);
21004
21186
  const inputArgs = {
21005
21187
  attempt,
21188
+ format,
21006
21189
  param,
21007
21190
  history,
21008
21191
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.1.113",
3
+ "version": "1.1.115",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -4736,6 +4736,41 @@ type IOutlineParam = any;
4736
4736
  * @typedef {any} IOutlineData
4737
4737
  */
4738
4738
  type IOutlineData = any;
4739
+ /**
4740
+ * Interface representing the format/schema definition for outline data.
4741
+ * Specifies the structure, required fields, and property metadata for outline operations.
4742
+ * Used to enforce and document the expected shape of outline data.
4743
+ */
4744
+ interface IOutlineFormat {
4745
+ /**
4746
+ * The root type of the outline format (e.g., "object").
4747
+ */
4748
+ type: string;
4749
+ /**
4750
+ * Array of property names that are required in the outline data.
4751
+ */
4752
+ required: string[];
4753
+ /**
4754
+ * An object mapping property names to their type, description, and optional enum values.
4755
+ * Each property describes a field in the outline data.
4756
+ */
4757
+ properties: {
4758
+ [key: string]: {
4759
+ /**
4760
+ * The type of the property (e.g., "string", "number", "boolean", etc.).
4761
+ */
4762
+ type: string;
4763
+ /**
4764
+ * A human-readable description of the property.
4765
+ */
4766
+ description: string;
4767
+ /**
4768
+ * Optional array of allowed values for the property.
4769
+ */
4770
+ enum?: string[];
4771
+ };
4772
+ };
4773
+ }
4739
4774
  /**
4740
4775
  * Interface defining callbacks for outline lifecycle events.
4741
4776
  * Provides hooks for handling attempt initiation, document generation, and validation outcomes.
@@ -4832,6 +4867,10 @@ interface IOutlineArgs<Param extends IOutlineParam = IOutlineParam> {
4832
4867
  * @type {number}
4833
4868
  */
4834
4869
  attempt: number;
4870
+ /**
4871
+ * Format of output taken from outline schema
4872
+ */
4873
+ format: IOutlineFormat;
4835
4874
  /**
4836
4875
  * The history management API for the outline operation.
4837
4876
  * Provides access to message history for context or logging.
@@ -4947,6 +4986,14 @@ interface IOutlineResult<Data extends IOutlineData = IOutlineData, Param extends
4947
4986
  * @interface IOutlineSchema
4948
4987
  */
4949
4988
  interface IOutlineSchema<Data extends IOutlineData = IOutlineData, Param extends IOutlineParam = IOutlineParam> {
4989
+ /**
4990
+ * The prompt or prompt generator for the outline operation.
4991
+ * Can be a string, an array of strings, or a function that returns a string, array of strings, or a promise resolving to either.
4992
+ * If a function is provided, it receives the outline name and can return a prompt dynamically.
4993
+ * Used as the initial instruction or context for the outline process.
4994
+ * @type {string | string[] | ((outlineName: OutlineName) => (string | string[] | Promise<string | string[]>))}
4995
+ */
4996
+ prompt: string | string[] | ((outlineName: OutlineName) => (string | string[] | Promise<string | string[]>));
4950
4997
  /**
4951
4998
  * Optional description for documentation purposes.
4952
4999
  * Aids in understanding the purpose or behavior of the outline.
@@ -4972,6 +5019,12 @@ interface IOutlineSchema<Data extends IOutlineData = IOutlineData, Param extends
4972
5019
  * @type {(IOutlineValidation<Data, Param> | IOutlineValidationFn<Data, Param>)[]}
4973
5020
  */
4974
5021
  validations?: (IOutlineValidation<Data, Param> | IOutlineValidationFn<Data, Param>)[];
5022
+ /**
5023
+ * The format/schema definition for the outline data.
5024
+ * Specifies the expected structure, required fields, and property metadata for validation and documentation.
5025
+ * @type {IOutlineFormat}
5026
+ */
5027
+ format: IOutlineFormat;
4975
5028
  /**
4976
5029
  * Optional maximum number of attempts for the outline operation.
4977
5030
  * Limits the number of retries if validations fail.
@@ -8457,6 +8510,13 @@ declare class DocService {
8457
8510
  * @private
8458
8511
  */
8459
8512
  private readonly agentValidationService;
8513
+ /**
8514
+ * Outline validation service instance, injected via DI.
8515
+ * Used for validating and managing agent outline schemas, ensuring agent outlines conform to expected structure and constraints.
8516
+ * @type {OutlineValidationService}
8517
+ * @private
8518
+ */
8519
+ private readonly outlineValidationService;
8460
8520
  /**
8461
8521
  * Swarm schema service instance, injected via DI.
8462
8522
  * Retrieves ISwarmSchema objects for writeSwarmDoc, supplying swarm details like agents and policies.
@@ -8471,6 +8531,13 @@ declare class DocService {
8471
8531
  * @private
8472
8532
  */
8473
8533
  private readonly agentSchemaService;
8534
+ /**
8535
+ * Outline schema service instance, injected via DI.
8536
+ * Retrieves and manages outline schema objects for agents, supporting documentation and validation of agent outlines.
8537
+ * @type {OutlineSchemaService}
8538
+ * @private
8539
+ */
8540
+ private readonly outlineSchemaService;
8474
8541
  /**
8475
8542
  * Model context protocol service instance, injected via DI.
8476
8543
  * Retrieves IMCPSchema objects for writeAgentDoc and agent descriptions in writeSwarmDoc, providing details like tools and prompts.
@@ -8551,6 +8618,24 @@ declare class DocService {
8551
8618
  * @private
8552
8619
  */
8553
8620
  private writeSwarmDoc;
8621
+ /**
8622
+ * Writes Markdown documentation for an outline schema, detailing its name, description, main prompt, output format, and callbacks.
8623
+ * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
8624
+ * Outputs to dirName/[outlineName].md, sourced from outlineSchemaService.
8625
+ *
8626
+ * - The Markdown includes YAML frontmatter, outline name, description, prompt(s), output format (with types, descriptions, enums, and required fields), and callbacks.
8627
+ * - Handles both string and function-based prompts, and supports array or string prompt types.
8628
+ * - Output format section documents each property, its type, description, enum values, and required status.
8629
+ * - Callback section lists all callback names used by the outline.
8630
+ *
8631
+ * @param {IOutlineSchema} outlineSchema - The outline schema to document, including properties like prompt, format, and callbacks.
8632
+ * @param {string} prefix - The documentation group or prefix for organizing output.
8633
+ * @param {string} dirName - The base directory for documentation output.
8634
+ * @param {(text: string) => string} [sanitizeMarkdown=(t) => t] - Optional function to sanitize Markdown text.
8635
+ * @returns {Promise<void>} A promise resolving when the outline documentation file is written.
8636
+ * @private
8637
+ */
8638
+ private writeOutlineDoc;
8554
8639
  /**
8555
8640
  * Writes Markdown documentation for an agent schema, detailing its name, description, UML diagram, prompts, tools, storages, states, and callbacks.
8556
8641
  * Executes in a thread pool (THREAD_POOL_SIZE) to manage concurrency, logging via loggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is enabled.
@@ -11151,6 +11236,12 @@ declare class OutlineValidationService {
11151
11236
  * @throws {Error} If an outline with the given name already exists in the map.
11152
11237
  */
11153
11238
  addOutline: (outlineName: OutlineName, outlineSchema: IOutlineSchema) => void;
11239
+ /**
11240
+ * Retrieves a list of all registered outline names.
11241
+ * Logs the retrieval operation if info logging is enabled.
11242
+ * @returns {OutlineName[]} An array of registered outline names.
11243
+ */
11244
+ getOutlineList: () => OutlineName[];
11154
11245
  /**
11155
11246
  * Validates the existence of an outline schema for the given outline name.
11156
11247
  * Memoized to cache results based on the outline name for performance.
@@ -11960,7 +12051,7 @@ declare function addPipeline<Payload extends object = any>(pipelineSchema: IPipe
11960
12051
  * @param {IOutlineSchema} outlineSchema - The outline schema to register, containing the outline name and configuration.
11961
12052
  * @returns {string} The name of the registered outline.
11962
12053
  */
11963
- declare function addOutline(outlineSchema: IOutlineSchema): string;
12054
+ declare function addOutline<Data extends IOutlineData = IOutlineData, Param extends IOutlineParam = IOutlineParam>(outlineSchema: IOutlineSchema<Data, Param>): string;
11964
12055
 
11965
12056
  type TAgentSchema = {
11966
12057
  agentName: IAgentSchema["agentName"];
@@ -15557,4 +15648,4 @@ declare const Utils: {
15557
15648
  PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
15558
15649
  };
15559
15650
 
15560
- export { Adapter, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchemaInternal, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineHistory, type IOutlineMessage, type IOutlineResult, type IOutlineSchema, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addAgentNavigation, addCompletion, addCompute, addEmbedding, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute, getEmbeding, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getMCP, getNavigationRoute, getPayload, getPipeline, getPolicy, getRawHistory, getSessionContext, getSessionMode, getState, getStorage, getSwarm, getTool, getToolNameForModel, getUserHistory, getWiki, hasNavigation, hasSession, json, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, overrideAgent, overrideCompletion, overrideCompute, overrideEmbeding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, overrideWiki, question, questionForce, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm };
15651
+ export { Adapter, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchemaInternal, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineFormat, type IOutlineHistory, type IOutlineMessage, type IOutlineResult, type IOutlineSchema, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addAgentNavigation, addCompletion, addCompute, addEmbedding, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute, getEmbeding, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getMCP, getNavigationRoute, getPayload, getPipeline, getPolicy, getRawHistory, getSessionContext, getSessionMode, getState, getStorage, getSwarm, getTool, getToolNameForModel, getUserHistory, getWiki, hasNavigation, hasSession, json, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, overrideAgent, overrideCompletion, overrideCompute, overrideEmbeding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, overrideWiki, question, questionForce, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm };