@promptbook/core 0.75.0-1 → 0.75.0-4

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.
Files changed (167) hide show
  1. package/README.md +28 -17
  2. package/esm/index.es.js +1162 -997
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/{promptbook-collection → books}/index.d.ts +6 -6
  5. package/esm/typings/src/_packages/core.index.d.ts +28 -20
  6. package/esm/typings/src/_packages/types.index.d.ts +62 -52
  7. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  8. package/esm/typings/src/cli/cli-commands/about.d.ts +1 -0
  9. package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -0
  10. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -0
  11. package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -0
  12. package/esm/typings/src/cli/cli-commands/run.d.ts +1 -0
  13. package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -0
  14. package/esm/typings/src/cli/main.d.ts +1 -0
  15. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  16. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  17. package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
  18. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
  19. package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
  20. package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +3 -3
  21. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -2
  22. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +2 -2
  23. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +2 -2
  24. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +2 -2
  25. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +2 -2
  26. package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +11 -0
  27. package/esm/typings/src/commands/{TEMPLATE/templateCommandParser.d.ts → SECTION/sectionCommandParser.d.ts} +6 -6
  28. package/esm/typings/src/commands/_common/types/Command.d.ts +1 -1
  29. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +17 -19
  30. package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +1 -1
  31. package/esm/typings/src/commands/index.d.ts +4 -1
  32. package/esm/typings/src/config.d.ts +11 -3
  33. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +3 -3
  34. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -2
  35. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +3 -3
  36. package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
  37. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +4 -4
  38. package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +15 -0
  39. package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  40. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +3 -2
  41. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +1 -1
  42. package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  43. package/esm/typings/src/errors/index.d.ts +3 -0
  44. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  45. package/esm/typings/src/execution/PromptResultUsage.d.ts +1 -1
  46. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
  47. package/esm/typings/src/execution/createPipelineExecutor/{$OngoingTemplateResult.d.ts → $OngoingTaskResult.d.ts} +1 -1
  48. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +1 -1
  49. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
  50. package/esm/typings/src/execution/createPipelineExecutor/{20-executeTemplate.d.ts → 20-executeTask.d.ts} +7 -7
  51. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +5 -5
  52. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +1 -1
  53. package/esm/typings/src/execution/createPipelineExecutor/{getContextForTemplate.d.ts → getContextForTask.d.ts} +2 -2
  54. package/esm/typings/src/execution/createPipelineExecutor/{getExamplesForTemplate.d.ts → getExamplesForTask.d.ts} +2 -2
  55. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +27 -0
  56. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +30 -0
  57. package/esm/typings/src/{types → execution}/execution-report/ExecutionPromptReportJson.d.ts +2 -2
  58. package/esm/typings/src/{types → execution}/execution-report/ExecutionReportJson.d.ts +4 -4
  59. package/esm/typings/src/{types → execution}/execution-report/ExecutionReportStringOptions.d.ts +1 -1
  60. package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
  61. package/esm/typings/src/execution/utils/usage-constants.d.ts +3 -0
  62. package/esm/typings/src/formats/index.d.ts +3 -0
  63. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +2 -2
  64. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +7 -1
  65. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -0
  66. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +45 -0
  67. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +14 -0
  68. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +3 -3
  69. package/esm/typings/src/formfactors/index.d.ts +85 -12
  70. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +14 -0
  71. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +13 -3
  72. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +13 -3
  73. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
  74. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +3 -0
  75. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +1 -0
  76. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +3 -0
  77. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  78. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
  79. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
  80. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +3 -0
  81. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +1 -0
  82. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  83. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +26 -0
  84. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +14 -0
  85. package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/getPipelineInterface.d.ts +3 -1
  86. package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineImplementingInterface.d.ts +5 -1
  87. package/esm/typings/src/pipeline/{pipeline-interface → PipelineInterface}/isPipelineInterfacesEqual.d.ts +2 -0
  88. package/esm/typings/src/{types/PipelineJson/TemplateJsonCommon.d.ts → pipeline/PipelineJson/CommonTaskJson.d.ts} +24 -24
  89. package/esm/typings/src/pipeline/PipelineJson/DialogTaskJson.d.ts +13 -0
  90. package/esm/typings/src/{types → pipeline}/PipelineJson/Expectations.d.ts +2 -2
  91. package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgePieceJson.d.ts +7 -6
  92. package/esm/typings/src/{types → pipeline}/PipelineJson/KnowledgeSourceJson.d.ts +3 -3
  93. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +98 -0
  94. package/esm/typings/src/{types → pipeline}/PipelineJson/PersonaJson.d.ts +5 -5
  95. package/esm/typings/src/{types → pipeline}/PipelineJson/PipelineJson.d.ts +11 -11
  96. package/esm/typings/src/{types → pipeline}/PipelineJson/PreparationJson.d.ts +1 -1
  97. package/esm/typings/src/{types/PipelineJson/PromptTemplateJson.d.ts → pipeline/PipelineJson/PromptTaskJson.d.ts} +8 -8
  98. package/esm/typings/src/pipeline/PipelineJson/ScriptTaskJson.d.ts +20 -0
  99. package/esm/typings/src/pipeline/PipelineJson/SimpleTaskJson.d.ts +13 -0
  100. package/esm/typings/src/pipeline/PipelineJson/TaskJson.d.ts +11 -0
  101. package/esm/typings/src/{types → pipeline}/PipelineString.d.ts +1 -1
  102. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -3
  103. package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
  104. package/esm/typings/src/prepare/prepareTasks.d.ts +32 -0
  105. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -1
  106. package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
  107. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
  108. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  109. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +1 -1
  110. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  111. package/esm/typings/src/scrapers/document/register-metadata.d.ts +3 -0
  112. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +1 -1
  113. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  114. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +3 -0
  115. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +1 -1
  116. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  117. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +3 -0
  118. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -1
  119. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  120. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +3 -0
  121. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +1 -1
  122. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  123. package/esm/typings/src/scrapers/website/register-metadata.d.ts +3 -0
  124. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -0
  125. package/esm/typings/src/types/Prompt.d.ts +4 -4
  126. package/esm/typings/src/types/SectionType.d.ts +21 -0
  127. package/esm/typings/src/types/TaskProgress.d.ts +2 -2
  128. package/esm/typings/src/types/TaskType.d.ts +15 -0
  129. package/esm/typings/src/types/typeAliasEmoji.d.ts +3 -0
  130. package/esm/typings/src/types/typeAliases.d.ts +2 -1
  131. package/esm/typings/src/utils/emojis.d.ts +1 -0
  132. package/esm/typings/src/utils/expectation-counters/constants.d.ts +1 -0
  133. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
  134. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
  135. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
  136. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
  137. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  138. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
  139. package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -2
  140. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -0
  141. package/esm/typings/src/utils/organization/TODO_remove_as.d.ts +6 -0
  142. package/esm/typings/src/utils/parameters/extractParameterNames.d.ts +2 -2
  143. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +1 -1
  144. package/esm/typings/src/version.d.ts +2 -1
  145. package/package.json +4 -3
  146. package/umd/index.umd.js +1173 -1003
  147. package/umd/index.umd.js.map +1 -1
  148. package/esm/typings/src/commands/TEMPLATE/TemplateCommand.d.ts +0 -11
  149. package/esm/typings/src/commands/TEMPLATE/TemplateTypes.d.ts +0 -15
  150. package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +0 -15
  151. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +0 -27
  152. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +0 -30
  153. package/esm/typings/src/formfactors/chat/ChatFormfactorDefinition.d.ts +0 -15
  154. package/esm/typings/src/pipeline/pipeline-interface/PipelineInterface.d.ts +0 -22
  155. package/esm/typings/src/pipeline/pipeline-interface/constants.d.ts +0 -9
  156. package/esm/typings/src/prepare/prepareTemplates.d.ts +0 -32
  157. package/esm/typings/src/types/PipelineJson/DialogTemplateJson.d.ts +0 -13
  158. package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +0 -39
  159. package/esm/typings/src/types/PipelineJson/ScriptTemplateJson.d.ts +0 -20
  160. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +0 -13
  161. package/esm/typings/src/types/PipelineJson/TemplateJson.d.ts +0 -11
  162. /package/esm/typings/src/commands/{TEMPLATE/templateCommand.test.d.ts → SECTION/sectionCommand.test.d.ts} +0 -0
  163. /package/esm/typings/src/conversion/utils/{extractParameterNamesFromTemplate.test.d.ts → extractParameterNamesFromTask.test.d.ts} +0 -0
  164. /package/esm/typings/src/{types → execution}/execution-report/ExecutionReportString.d.ts +0 -0
  165. /package/esm/typings/src/{types → execution}/execution-report/countWorkingDuration.d.ts +0 -0
  166. /package/esm/typings/src/{types → execution}/execution-report/countWorkingDuration.test.d.ts +0 -0
  167. /package/esm/typings/src/{types → execution}/execution-report/executionReportJsonToString.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -7,8 +7,8 @@ import { join, basename } from 'path';
7
7
  import { SHA256 } from 'crypto-js';
8
8
  import hexEncoder from 'crypto-js/enc-hex';
9
9
  import { lookup } from 'mime-types';
10
- import sha256 from 'crypto-js/sha256';
11
10
  import moment from 'moment';
11
+ import sha256 from 'crypto-js/sha256';
12
12
 
13
13
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
14
14
  /**
@@ -22,9 +22,10 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
22
22
  *
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.75.0-0';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.75.0-3';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
+ * Note: [💞] Ignore a discrepancy between file name and entity name
28
29
  */
29
30
 
30
31
  /*! *****************************************************************************
@@ -225,7 +226,7 @@ function capitalize(word) {
225
226
  */
226
227
  function pipelineJsonToString(pipelineJson) {
227
228
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
228
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, templates = pipelineJson.templates;
229
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
229
230
  var pipelineString = "# ".concat(title);
230
231
  if (description) {
231
232
  pipelineString += '\n\n';
@@ -246,7 +247,7 @@ function pipelineJsonToString(pipelineJson) {
246
247
  return isInput;
247
248
  })), _h = _g.next(); !_h.done; _h = _g.next()) {
248
249
  var parameter = _h.value;
249
- commands.push("INPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
250
+ commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
250
251
  }
251
252
  }
252
253
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -262,7 +263,7 @@ function pipelineJsonToString(pipelineJson) {
262
263
  return isOutput;
263
264
  })), _k = _j.next(); !_k.done; _k = _j.next()) {
264
265
  var parameter = _k.value;
265
- commands.push("OUTPUT PARAMETER ".concat(templateParameterJsonToString(parameter)));
266
+ commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
266
267
  }
267
268
  }
268
269
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -275,13 +276,13 @@ function pipelineJsonToString(pipelineJson) {
275
276
  pipelineString += '\n\n';
276
277
  pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
277
278
  try {
278
- for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
279
- var template = templates_1_1.value;
279
+ for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
280
+ var task = tasks_1_1.value;
280
281
  var
281
282
  /* Note: Not using:> name, */
282
- title_1 = template.title, description_1 = template.description,
283
+ title_1 = task.title, description_1 = task.description,
283
284
  /* Note: dependentParameterNames, */
284
- jokers = template.jokerParameterNames, templateType = template.templateType, content = template.content, postprocessing = template.postprocessingFunctionNames, expectations = template.expectations, format = template.format, resultingParameterName = template.resultingParameterName;
285
+ jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
285
286
  pipelineString += '\n\n';
286
287
  pipelineString += "## ".concat(title_1);
287
288
  if (description_1) {
@@ -290,10 +291,11 @@ function pipelineJsonToString(pipelineJson) {
290
291
  }
291
292
  var commands_1 = [];
292
293
  var contentLanguage = 'text';
293
- if (templateType === 'PROMPT_TEMPLATE') {
294
- var modelRequirements = template.modelRequirements;
294
+ if (taskType === 'PROMPT_TASK') {
295
+ var modelRequirements = task.modelRequirements;
295
296
  var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
296
- commands_1.push("EXECUTE PROMPT TEMPLATE");
297
+ // Note: Do nothing, it is default
298
+ // commands.push(`PROMPT`);
297
299
  if (modelVariant) {
298
300
  commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
299
301
  }
@@ -301,21 +303,21 @@ function pipelineJsonToString(pipelineJson) {
301
303
  commands_1.push("MODEL NAME `".concat(modelName, "`"));
302
304
  }
303
305
  }
304
- else if (templateType === 'SIMPLE_TEMPLATE') {
306
+ else if (taskType === 'SIMPLE_TASK') {
305
307
  commands_1.push("SIMPLE TEMPLATE");
306
308
  // Note: Nothing special here
307
309
  }
308
- else if (templateType === 'SCRIPT_TEMPLATE') {
309
- commands_1.push("SCRIPT TEMPLATE");
310
- if (template.contentLanguage) {
311
- contentLanguage = template.contentLanguage;
310
+ else if (taskType === 'SCRIPT_TASK') {
311
+ commands_1.push("SCRIPT");
312
+ if (task.contentLanguage) {
313
+ contentLanguage = task.contentLanguage;
312
314
  }
313
315
  else {
314
316
  contentLanguage = '';
315
317
  }
316
318
  }
317
- else if (templateType === 'DIALOG_TEMPLATE') {
318
- commands_1.push("DIALOG TEMPLATE");
319
+ else if (taskType === 'DIALOG_TASK') {
320
+ commands_1.push("DIALOG");
319
321
  // Note: Nothing special here
320
322
  } // <- }else if([🅱]
321
323
  if (jokers) {
@@ -390,13 +392,13 @@ function pipelineJsonToString(pipelineJson) {
390
392
  pipelineString += '\n';
391
393
  pipelineString += '```';
392
394
  pipelineString += '\n\n';
393
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use templateParameterJsonToString
395
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
394
396
  }
395
397
  }
396
398
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
397
399
  finally {
398
400
  try {
399
- if (templates_1_1 && !templates_1_1.done && (_c = templates_1.return)) _c.call(templates_1);
401
+ if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
400
402
  }
401
403
  finally { if (e_3) throw e_3.error; }
402
404
  }
@@ -405,8 +407,8 @@ function pipelineJsonToString(pipelineJson) {
405
407
  /**
406
408
  * @private internal utility of `pipelineJsonToString`
407
409
  */
408
- function templateParameterJsonToString(templateParameterJson) {
409
- var name = templateParameterJson.name, description = templateParameterJson.description;
410
+ function taskParameterJsonToString(taskParameterJson) {
411
+ var name = taskParameterJson.name, description = taskParameterJson.description;
410
412
  var parameterString = "{".concat(name, "}");
411
413
  if (description) {
412
414
  parameterString = "".concat(parameterString, " ").concat(description);
@@ -414,7 +416,7 @@ function templateParameterJsonToString(templateParameterJson) {
414
416
  return parameterString;
415
417
  }
416
418
  /**
417
- * TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `templateParameterJsonToString` , use `stringifyCommand`
419
+ * TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
418
420
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
419
421
  * TODO: [🏛] Maybe make some markdown builder
420
422
  * TODO: [🏛] Escape all
@@ -647,7 +649,7 @@ var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so t
647
649
  *
648
650
  * @public exported from `@promptbook/core`
649
651
  */
650
- var CLAIM = "Build responsible, controlled and transparent applications on top of LLM models!";
652
+ var CLAIM = "It's time for a paradigm shift. The future of software in plain English, French or Latin";
651
653
  // <- TODO: [🐊] Pick the best claim
652
654
  /**
653
655
  * When the title is not provided, the default title is used
@@ -707,6 +709,13 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = 3;
707
709
  * @public exported from `@promptbook/core`
708
710
  */
709
711
  var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
712
+ /**
713
+ * Where to store your books
714
+ * This is kind of a "src" for your books
715
+ *
716
+ * @public exported from `@promptbook/core`
717
+ */
718
+ var DEFAULT_BOOKS_DIRNAME = './books';
710
719
  /**
711
720
  * Where to store the cache of executions for promptbook CLI
712
721
  *
@@ -714,7 +723,7 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
714
723
  *
715
724
  * @public exported from `@promptbook/core`
716
725
  */
717
- var DEFAULT_EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
726
+ var DEFAULT_EXECUTIONS_CACHE_DIRNAME = './.promptbook/executions-cache';
718
727
  /**
719
728
  * Where to store the scrape cache
720
729
  *
@@ -722,7 +731,7 @@ var DEFAULT_EXECUTIONS_CACHE_DIRNAME = '/.promptbook/executions-cache';
722
731
  *
723
732
  * @public exported from `@promptbook/core`
724
733
  */
725
- var DEFAULT_SCRAPE_CACHE_DIRNAME = '/.promptbook/scrape-cache';
734
+ var DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
726
735
  /**
727
736
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
728
737
  *
@@ -819,6 +828,7 @@ var IS_PIPELINE_LOGIC_VALIDATED = just(
819
828
  true);
820
829
  /**
821
830
  * TODO: Extract `constants.ts` from `config.ts`
831
+ * Note: [💞] Ignore a discrepancy between file name and entity name
822
832
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
823
833
  */
824
834
 
@@ -1074,9 +1084,9 @@ function validatePipelineCore(pipeline) {
1074
1084
  throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1075
1085
  }
1076
1086
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1077
- if (!Array.isArray(pipeline.templates)) {
1087
+ if (!Array.isArray(pipeline.tasks)) {
1078
1088
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1079
- throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.templates` expected to be an array, but got ".concat(typeof pipeline.templates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1089
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1080
1090
  }
1081
1091
  var _loop_1 = function (parameter) {
1082
1092
  if (parameter.isInput && parameter.isOutput) {
@@ -1085,13 +1095,12 @@ function validatePipelineCore(pipeline) {
1085
1095
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
1086
1096
  if (!parameter.isInput &&
1087
1097
  !parameter.isOutput &&
1088
- !pipeline.templates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1098
+ !pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
1089
1099
  throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
1090
1100
  }
1091
- // Note: Testing that parameter is either input or result of some template
1092
- if (!parameter.isInput &&
1093
- !pipeline.templates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1094
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add template that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1101
+ // Note: Testing that parameter is either input or result of some task
1102
+ if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
1103
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1095
1104
  }
1096
1105
  };
1097
1106
  try {
@@ -1108,7 +1117,7 @@ function validatePipelineCore(pipeline) {
1108
1117
  }
1109
1118
  finally { if (e_1) throw e_1.error; }
1110
1119
  }
1111
- // Note: All input parameters are defined - so that they can be used as result of some template
1120
+ // Note: All input parameters are defined - so that they can be used as result of some task
1112
1121
  var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
1113
1122
  var isInput = _a.isInput;
1114
1123
  return isInput;
@@ -1116,27 +1125,27 @@ function validatePipelineCore(pipeline) {
1116
1125
  var name = _a.name;
1117
1126
  return name;
1118
1127
  }));
1119
- var _loop_2 = function (template) {
1128
+ var _loop_2 = function (task) {
1120
1129
  var e_4, _h, e_5, _j;
1121
- if (definedParameters.has(template.resultingParameterName)) {
1122
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(template.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1130
+ if (definedParameters.has(task.resultingParameterName)) {
1131
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1123
1132
  }
1124
- if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
1125
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1133
+ if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
1134
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1126
1135
  }
1127
- definedParameters.add(template.resultingParameterName);
1128
- if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1129
- if (!template.format &&
1130
- !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1131
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1136
+ definedParameters.add(task.resultingParameterName);
1137
+ if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
1138
+ if (!task.format &&
1139
+ !task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1140
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1132
1141
  }
1133
1142
  var _loop_4 = function (joker) {
1134
- if (!template.dependentParameterNames.includes(joker)) {
1135
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1143
+ if (!task.dependentParameterNames.includes(joker)) {
1144
+ throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1136
1145
  }
1137
1146
  };
1138
1147
  try {
1139
- for (var _k = (e_4 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
1148
+ for (var _k = (e_4 = void 0, __values(task.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
1140
1149
  var joker = _l.value;
1141
1150
  _loop_4(joker);
1142
1151
  }
@@ -1149,7 +1158,7 @@ function validatePipelineCore(pipeline) {
1149
1158
  finally { if (e_4) throw e_4.error; }
1150
1159
  }
1151
1160
  }
1152
- if (template.expectations) {
1161
+ if (task.expectations) {
1153
1162
  var _loop_5 = function (unit, min, max) {
1154
1163
  if (min !== undefined && max !== undefined && min > max) {
1155
1164
  throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -1162,7 +1171,7 @@ function validatePipelineCore(pipeline) {
1162
1171
  }
1163
1172
  };
1164
1173
  try {
1165
- for (var _m = (e_5 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
1174
+ for (var _m = (e_5 = void 0, __values(Object.entries(task.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
1166
1175
  var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
1167
1176
  _loop_5(unit, min, max);
1168
1177
  }
@@ -1177,10 +1186,10 @@ function validatePipelineCore(pipeline) {
1177
1186
  }
1178
1187
  };
1179
1188
  try {
1180
- // Note: Checking each template individually
1181
- for (var _f = __values(pipeline.templates), _g = _f.next(); !_g.done; _g = _f.next()) {
1182
- var template = _g.value;
1183
- _loop_2(template);
1189
+ // Note: Checking each task individually
1190
+ for (var _f = __values(pipeline.tasks), _g = _f.next(); !_g.done; _g = _f.next()) {
1191
+ var task = _g.value;
1192
+ _loop_2(task);
1184
1193
  }
1185
1194
  }
1186
1195
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -1214,20 +1223,20 @@ function validatePipelineCore(pipeline) {
1214
1223
  }
1215
1224
  finally { if (e_3) throw e_3.error; }
1216
1225
  }
1217
- var unresovedTemplates = __spreadArray([], __read(pipeline.templates), false);
1226
+ var unresovedTasks = __spreadArray([], __read(pipeline.tasks), false);
1218
1227
  var loopLimit = LOOP_LIMIT;
1219
1228
  var _loop_3 = function () {
1220
1229
  if (loopLimit-- < 0) {
1221
1230
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
1222
1231
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1223
1232
  }
1224
- var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
1225
- return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
1233
+ var currentlyResovedTasks = unresovedTasks.filter(function (task) {
1234
+ return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
1226
1235
  });
1227
- if (currentlyResovedTemplates.length === 0) {
1236
+ if (currentlyResovedTasks.length === 0) {
1228
1237
  throw new PipelineLogicError(
1229
1238
  // TODO: [🐎] DRY
1230
- spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTemplates
1239
+ spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks
1231
1240
  .map(function (_a) {
1232
1241
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1233
1242
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -1246,13 +1255,13 @@ function validatePipelineCore(pipeline) {
1246
1255
  .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
1247
1256
  .join('\n')), "\n\n\n "); }));
1248
1257
  }
1249
- resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1258
+ resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTasks.map(function (_a) {
1250
1259
  var resultingParameterName = _a.resultingParameterName;
1251
1260
  return resultingParameterName;
1252
1261
  })), false);
1253
- unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
1262
+ unresovedTasks = unresovedTasks.filter(function (task) { return !currentlyResovedTasks.includes(task); });
1254
1263
  };
1255
- while (unresovedTemplates.length > 0) {
1264
+ while (unresovedTasks.length > 0) {
1256
1265
  _loop_3();
1257
1266
  }
1258
1267
  // TODO: !!!!!! Test that pipeline interface implements declared formfactor interface
@@ -1312,9 +1321,9 @@ var PipelineUrlError = /** @class */ (function (_super) {
1312
1321
  }(Error));
1313
1322
 
1314
1323
  /**
1315
- * Parses the template and returns the list of all parameter names
1324
+ * Parses the task and returns the list of all parameter names
1316
1325
  *
1317
- * @param template the template with parameters in {curly} braces
1326
+ * @param template the string template with parameters in {curly} braces
1318
1327
  * @returns the list of parameter names
1319
1328
  * @public exported from `@promptbook/utils`
1320
1329
  */
@@ -1345,18 +1354,18 @@ function extractParameterNames(template) {
1345
1354
  * @public exported from `@promptbook/core`
1346
1355
  */
1347
1356
  function unpreparePipeline(pipeline) {
1348
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, templates = pipeline.templates;
1357
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
1349
1358
  personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1350
1359
  knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1351
- templates = templates.map(function (template) {
1352
- var dependentParameterNames = template.dependentParameterNames;
1353
- var parameterNames = extractParameterNames(template.preparedContent || '');
1360
+ tasks = tasks.map(function (task) {
1361
+ var dependentParameterNames = task.dependentParameterNames;
1362
+ var parameterNames = extractParameterNames(task.preparedContent || '');
1354
1363
  dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1355
- var templateUnprepared = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames });
1356
- delete templateUnprepared.preparedContent;
1357
- return templateUnprepared;
1364
+ var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
1365
+ delete taskUnprepared.preparedContent;
1366
+ return taskUnprepared;
1358
1367
  });
1359
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { templates: templates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1368
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1360
1369
  }
1361
1370
  /**
1362
1371
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -1671,24 +1680,6 @@ function createSubcollection(collection, predicate) {
1671
1680
  };
1672
1681
  }
1673
1682
 
1674
- /**
1675
- * Template type describes the way how the template is templated
1676
- *
1677
- * @see https://github.com/webgptorg/promptbook#template-type
1678
- * @public exported from `@promptbook/core`
1679
- */
1680
- var TemplateTypes = [
1681
- 'PROMPT_TEMPLATE',
1682
- 'SIMPLE_TEMPLATE',
1683
- 'SCRIPT_TEMPLATE',
1684
- 'DIALOG_TEMPLATE',
1685
- 'EXAMPLE',
1686
- 'KNOWLEDGE',
1687
- 'INSTRUMENT',
1688
- 'ACTION',
1689
- // <- [🅱]
1690
- ];
1691
-
1692
1683
  /**
1693
1684
  * This error type indicates that some tools are missing for pipeline execution or preparation
1694
1685
  *
@@ -1833,6 +1824,9 @@ var UNCERTAIN_USAGE = $deepFreeze({
1833
1824
  pagesCount: { value: 0, isUncertain: true },
1834
1825
  },
1835
1826
  });
1827
+ /**
1828
+ * Note: [💞] Ignore a discrepancy between file name and entity name
1829
+ */
1836
1830
 
1837
1831
  /**
1838
1832
  * @@@
@@ -2324,7 +2318,7 @@ function joinLlmExecutionTools() {
2324
2318
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2325
2319
  */
2326
2320
 
2327
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.book.md"}];
2321
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-persona.book.md"}];
2328
2322
 
2329
2323
  /**
2330
2324
  * This error indicates that the pipeline collection cannot be propperly loaded
@@ -2428,6 +2422,9 @@ var ERRORS = {
2428
2422
  UnexpectedError: UnexpectedError,
2429
2423
  // TODO: [🪑]> VersionMismatchError,
2430
2424
  };
2425
+ /**
2426
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2427
+ */
2431
2428
 
2432
2429
  /**
2433
2430
  * Deserializes the error object
@@ -2489,8 +2486,8 @@ function isPipelinePrepared(pipeline) {
2489
2486
  return false;
2490
2487
  }
2491
2488
  /*
2492
- TODO: [🧠][🍫] `templates` can not be determined if they are fully prepared SO ignoring them
2493
- > if (!pipeline.templates.every(({ preparedContent }) => preparedContent === undefined)) {
2489
+ TODO: [🧠][🍫] `tasks` can not be determined if they are fully prepared SO ignoring them
2490
+ > if (!pipeline.tasks.every(({ preparedContent }) => preparedContent === undefined)) {
2494
2491
  > return false;
2495
2492
  > }
2496
2493
  */
@@ -2501,9 +2498,9 @@ function isPipelinePrepared(pipeline) {
2501
2498
  * TODO: [🐠] Maybe base this on `makeValidator`
2502
2499
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2503
2500
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2504
- * - [🏍] ? Is context in each template
2501
+ * - [🏍] ? Is context in each task
2505
2502
  * - [♨] Are examples prepared
2506
- * - [♨] Are templates prepared
2503
+ * - [♨] Are tasks prepared
2507
2504
  */
2508
2505
 
2509
2506
  /**
@@ -2573,16 +2570,16 @@ function extractVariables(script) {
2573
2570
  */
2574
2571
 
2575
2572
  /**
2576
- * Parses the template and returns the set of all used parameters
2573
+ * Parses the task and returns the set of all used parameters
2577
2574
  *
2578
- * @param template the template with used parameters
2575
+ * @param task the task with used parameters
2579
2576
  * @returns the set of parameter names
2580
2577
  * @throws {ParseError} if the script is invalid
2581
2578
  * @public exported from `@promptbook/utils`
2582
2579
  */
2583
- function extractParameterNamesFromTemplate(template) {
2580
+ function extractParameterNamesFromTask(task) {
2584
2581
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
2585
- var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
2582
+ var title = task.title, description = task.description, taskType = task.taskType, content = task.content, preparedContent = task.preparedContent, jokerParameterNames = task.jokerParameterNames, foreach = task.foreach;
2586
2583
  var parameterNames = new Set();
2587
2584
  try {
2588
2585
  for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
@@ -2597,7 +2594,7 @@ function extractParameterNamesFromTemplate(template) {
2597
2594
  }
2598
2595
  finally { if (e_1) throw e_1.error; }
2599
2596
  }
2600
- if (templateType === 'SCRIPT_TEMPLATE') {
2597
+ if (taskType === 'SCRIPT_TASK') {
2601
2598
  try {
2602
2599
  for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
2603
2600
  var parameterName = _h.value;
@@ -3028,6 +3025,9 @@ var FORMAT_DEFINITIONS = [
3028
3025
  TextFormatDefinition,
3029
3026
  CsvFormatDefinition,
3030
3027
  ];
3028
+ /**
3029
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3030
+ */
3031
3031
 
3032
3032
  /**
3033
3033
  * Maps available parameters to expected parameters
@@ -3263,7 +3263,7 @@ function replaceParameters(template, parameters) {
3263
3263
  }
3264
3264
  finally { if (e_1) throw e_1.error; }
3265
3265
  }
3266
- var replacedTemplate = template;
3266
+ var replacedTemplates = template;
3267
3267
  var match;
3268
3268
  var loopLimit = LOOP_LIMIT;
3269
3269
  var _loop_1 = function () {
@@ -3292,24 +3292,24 @@ function replaceParameters(template, parameters) {
3292
3292
  .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
3293
3293
  .join('\n');
3294
3294
  }
3295
- replacedTemplate =
3296
- replacedTemplate.substring(0, match.index + precol.length) +
3295
+ replacedTemplates =
3296
+ replacedTemplates.substring(0, match.index + precol.length) +
3297
3297
  parameterValue +
3298
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
3298
+ replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
3299
3299
  };
3300
3300
  while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
3301
- .exec(replacedTemplate))) {
3301
+ .exec(replacedTemplates))) {
3302
3302
  _loop_1();
3303
3303
  }
3304
3304
  // [💫] Check if there are parameters that are not closed properly
3305
- if (/{\w+$/.test(replacedTemplate)) {
3305
+ if (/{\w+$/.test(replacedTemplates)) {
3306
3306
  throw new PipelineExecutionError('Parameter is not closed');
3307
3307
  }
3308
3308
  // [💫] Check if there are parameters that are not opened properly
3309
- if (/^\w+}/.test(replacedTemplate)) {
3309
+ if (/^\w+}/.test(replacedTemplates)) {
3310
3310
  throw new PipelineExecutionError('Parameter is not opened');
3311
3311
  }
3312
- return replacedTemplate;
3312
+ return replacedTemplates;
3313
3313
  }
3314
3314
 
3315
3315
  /**
@@ -3341,6 +3341,7 @@ var CHARACTERS_PER_STANDARD_LINE = 63;
3341
3341
  var LINES_PER_STANDARD_PAGE = 44;
3342
3342
  /**
3343
3343
  * TODO: [🧠] Should be this `constants.ts` or `config.ts`?
3344
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3344
3345
  */
3345
3346
 
3346
3347
  /**
@@ -3681,6 +3682,7 @@ var CountUtils = {
3681
3682
  };
3682
3683
  /**
3683
3684
  * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
3685
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3684
3686
  */
3685
3687
 
3686
3688
  /**
@@ -3751,12 +3753,12 @@ function isPassingExpectations(expectations, value) {
3751
3753
  */
3752
3754
  function executeAttempts(options) {
3753
3755
  return __awaiter(this, void 0, void 0, function () {
3754
- var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _llms, llmTools, _loop_1, attempt, state_1;
3756
+ var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, task, preparedPipeline, tools, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTaskResult, _llms, llmTools, _loop_1, attempt, state_1;
3755
3757
  return __generator(this, function (_a) {
3756
3758
  switch (_a.label) {
3757
3759
  case 0:
3758
- jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts;
3759
- $ongoingTemplateResult = {
3760
+ jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, task = options.task, preparedPipeline = options.preparedPipeline, tools = options.tools, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, maxExecutionAttempts = options.maxExecutionAttempts;
3761
+ $ongoingTaskResult = {
3760
3762
  $result: null,
3761
3763
  $resultString: null,
3762
3764
  $expectError: null,
@@ -3776,52 +3778,51 @@ function executeAttempts(options) {
3776
3778
  if (isJokerAttempt && !jokerParameterName) {
3777
3779
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3778
3780
  }
3779
- $ongoingTemplateResult.$result = null;
3780
- $ongoingTemplateResult.$resultString = null;
3781
- $ongoingTemplateResult.$expectError = null;
3781
+ $ongoingTaskResult.$result = null;
3782
+ $ongoingTaskResult.$resultString = null;
3783
+ $ongoingTaskResult.$expectError = null;
3782
3784
  if (isJokerAttempt) {
3783
3785
  if (parameters[jokerParameterName] === undefined) {
3784
3786
  throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3785
3787
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3786
3788
  }
3787
3789
  else {
3788
- $ongoingTemplateResult.$resultString = parameters[jokerParameterName];
3790
+ $ongoingTaskResult.$resultString = parameters[jokerParameterName];
3789
3791
  }
3790
3792
  }
3791
3793
  _t.label = 1;
3792
3794
  case 1:
3793
3795
  _t.trys.push([1, 43, 44, 45]);
3794
3796
  if (!!isJokerAttempt) return [3 /*break*/, 25];
3795
- _b = template.templateType;
3797
+ _b = task.taskType;
3796
3798
  switch (_b) {
3797
- case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3798
- case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3799
- case 'SCRIPT_TEMPLATE': return [3 /*break*/, 11];
3800
- case 'DIALOG_TEMPLATE': return [3 /*break*/, 22];
3799
+ case 'SIMPLE_TASK': return [3 /*break*/, 2];
3800
+ case 'PROMPT_TASK': return [3 /*break*/, 3];
3801
+ case 'SCRIPT_TASK': return [3 /*break*/, 11];
3802
+ case 'DIALOG_TASK': return [3 /*break*/, 22];
3801
3803
  }
3802
3804
  return [3 /*break*/, 24];
3803
3805
  case 2:
3804
- $ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
3806
+ $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
3805
3807
  return [3 /*break*/, 25];
3806
3808
  case 3:
3807
- modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
3808
- $ongoingTemplateResult.$prompt = {
3809
- title: template.title,
3809
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
3810
+ $ongoingTaskResult.$prompt = {
3811
+ title: task.title,
3810
3812
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3811
3813
  ? preparedPipeline.pipelineUrl
3812
- : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
3813
- // <- TODO: Here should be maybe also subformat index to distinguish between same template with different subformat values
3814
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(task.name
3815
+ // <- TODO: Here should be maybe also subformat index to distinguish between same task with different subformat values
3814
3816
  ),
3815
3817
  parameters: parameters,
3816
3818
  content: preparedContent,
3817
3819
  modelRequirements: modelRequirements,
3818
3820
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3819
3821
  var name = _a.name;
3820
- return name === template.personaName;
3821
- }) ||
3822
- {})), template.expectations),
3823
- format: template.format,
3824
- postprocessingFunctionNames: template.postprocessingFunctionNames,
3822
+ return name === task.personaName;
3823
+ }) || {})), task.expectations),
3824
+ format: task.format,
3825
+ postprocessingFunctionNames: task.postprocessingFunctionNames,
3825
3826
  }; // <- TODO: Not very good type guard
3826
3827
  _c = modelRequirements.modelVariant;
3827
3828
  switch (_c) {
@@ -3831,36 +3832,35 @@ function executeAttempts(options) {
3831
3832
  }
3832
3833
  return [3 /*break*/, 9];
3833
3834
  case 4:
3834
- _d = $ongoingTemplateResult;
3835
+ _d = $ongoingTaskResult;
3835
3836
  return [4 /*yield*/, llmTools.callChatModel(
3836
3837
  // <- TODO: [🧁] Check that `callChatModel` is defined
3837
- $deepFreeze($ongoingTemplateResult.$prompt))];
3838
+ $deepFreeze($ongoingTaskResult.$prompt))];
3838
3839
  case 5:
3839
3840
  _d.$chatResult = _t.sent();
3840
3841
  // TODO: [🍬] Destroy chatThread
3841
- $ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
3842
- $ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
3842
+ $ongoingTaskResult.$result = $ongoingTaskResult.$chatResult;
3843
+ $ongoingTaskResult.$resultString = $ongoingTaskResult.$chatResult.content;
3843
3844
  return [3 /*break*/, 10];
3844
3845
  case 6:
3845
- _e = $ongoingTemplateResult;
3846
+ _e = $ongoingTaskResult;
3846
3847
  return [4 /*yield*/, llmTools.callCompletionModel(
3847
3848
  // <- TODO: [🧁] Check that `callCompletionModel` is defined
3848
- $deepFreeze($ongoingTemplateResult.$prompt))];
3849
+ $deepFreeze($ongoingTaskResult.$prompt))];
3849
3850
  case 7:
3850
3851
  _e.$completionResult = _t.sent();
3851
- $ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
3852
- $ongoingTemplateResult.$resultString =
3853
- $ongoingTemplateResult.$completionResult.content;
3852
+ $ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
3853
+ $ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
3854
3854
  return [3 /*break*/, 10];
3855
3855
  case 8: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
3856
- case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3856
+ case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3857
3857
  case 10: return [3 /*break*/, 25];
3858
3858
  case 11:
3859
3859
  if (arrayableToArray(tools.script).length === 0) {
3860
3860
  throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3861
3861
  }
3862
- if (!template.contentLanguage) {
3863
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3862
+ if (!task.contentLanguage) {
3863
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3864
3864
  }
3865
3865
  _t.label = 12;
3866
3866
  case 12:
@@ -3873,9 +3873,9 @@ function executeAttempts(options) {
3873
3873
  _t.label = 14;
3874
3874
  case 14:
3875
3875
  _t.trys.push([14, 16, , 17]);
3876
- _h = $ongoingTemplateResult;
3876
+ _h = $ongoingTaskResult;
3877
3877
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3878
- scriptLanguage: template.contentLanguage,
3878
+ scriptLanguage: task.contentLanguage,
3879
3879
  script: preparedContent,
3880
3880
  parameters: parameters,
3881
3881
  }))];
@@ -3890,7 +3890,7 @@ function executeAttempts(options) {
3890
3890
  if (error_1 instanceof UnexpectedError) {
3891
3891
  throw error_1;
3892
3892
  }
3893
- $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
3893
+ $ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_1);
3894
3894
  return [3 /*break*/, 17];
3895
3895
  case 17:
3896
3896
  _g = _f.next();
@@ -3907,14 +3907,14 @@ function executeAttempts(options) {
3907
3907
  finally { if (e_1) throw e_1.error; }
3908
3908
  return [7 /*endfinally*/];
3909
3909
  case 21:
3910
- if ($ongoingTemplateResult.$resultString !== null) {
3910
+ if ($ongoingTaskResult.$resultString !== null) {
3911
3911
  return [3 /*break*/, 25];
3912
3912
  }
3913
- if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
3914
- throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
3913
+ if ($ongoingTaskResult.$scriptPipelineExecutionErrors.length === 1) {
3914
+ throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
3915
3915
  }
3916
3916
  else {
3917
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
3917
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
3918
3918
  .map(function (error) { return '- ' + error.message; })
3919
3919
  .join('\n\n')), "\n "); }));
3920
3920
  }
@@ -3922,27 +3922,27 @@ function executeAttempts(options) {
3922
3922
  if (tools.userInterface === undefined) {
3923
3923
  throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3924
3924
  }
3925
- // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3926
- _j = $ongoingTemplateResult;
3925
+ // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
3926
+ _j = $ongoingTaskResult;
3927
3927
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3928
- promptTitle: template.title,
3929
- promptMessage: replaceParameters(template.description || '', parameters),
3928
+ promptTitle: task.title,
3929
+ promptMessage: replaceParameters(task.description || '', parameters),
3930
3930
  defaultValue: replaceParameters(preparedContent, parameters),
3931
3931
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
3932
3932
  placeholder: undefined,
3933
3933
  priority: priority,
3934
3934
  }))];
3935
3935
  case 23:
3936
- // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3936
+ // TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
3937
3937
  _j.$resultString = _t.sent();
3938
3938
  return [3 /*break*/, 25];
3939
- case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3939
+ case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3940
3940
  case 25:
3941
- if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 42];
3941
+ if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
3942
3942
  _t.label = 26;
3943
3943
  case 26:
3944
3944
  _t.trys.push([26, 40, 41, 42]);
3945
- _k = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _l = _k.next();
3945
+ _k = (e_3 = void 0, __values(task.postprocessingFunctionNames)), _l = _k.next();
3946
3946
  _t.label = 27;
3947
3947
  case 27:
3948
3948
  if (!!_l.done) return [3 /*break*/, 39];
@@ -3959,13 +3959,13 @@ function executeAttempts(options) {
3959
3959
  _t.label = 30;
3960
3960
  case 30:
3961
3961
  _t.trys.push([30, 32, , 33]);
3962
- _p = $ongoingTemplateResult;
3962
+ _p = $ongoingTaskResult;
3963
3963
  return [4 /*yield*/, scriptTools.execute({
3964
3964
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3965
3965
  script: "".concat(functionName, "(resultString)"),
3966
3966
  parameters: {
3967
- resultString: $ongoingTemplateResult.$resultString || '',
3968
- // Note: No ...parametersForTemplate, because working with result only
3967
+ resultString: $ongoingTaskResult.$resultString || '',
3968
+ // Note: No ...parametersForTask, because working with result only
3969
3969
  },
3970
3970
  })];
3971
3971
  case 31:
@@ -3981,7 +3981,7 @@ function executeAttempts(options) {
3981
3981
  throw error_2;
3982
3982
  }
3983
3983
  postprocessingError = error_2;
3984
- $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
3984
+ $ongoingTaskResult.$scriptPipelineExecutionErrors.push(error_2);
3985
3985
  return [3 /*break*/, 33];
3986
3986
  case 33:
3987
3987
  _o = _m.next();
@@ -4018,12 +4018,12 @@ function executeAttempts(options) {
4018
4018
  return [7 /*endfinally*/];
4019
4019
  case 42:
4020
4020
  // TODO: [💝] Unite object for expecting amount and format
4021
- if (template.format) {
4022
- if (template.format === 'JSON') {
4023
- if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
4021
+ if (task.format) {
4022
+ if (task.format === 'JSON') {
4023
+ if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
4024
4024
  // TODO: [🏢] Do more universally via `FormatDefinition`
4025
4025
  try {
4026
- $ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
4026
+ $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
4027
4027
  }
4028
4028
  catch (error) {
4029
4029
  throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
@@ -4032,12 +4032,12 @@ function executeAttempts(options) {
4032
4032
  }
4033
4033
  }
4034
4034
  else {
4035
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
4035
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
4036
4036
  }
4037
4037
  }
4038
4038
  // TODO: [💝] Unite object for expecting amount and format
4039
- if (template.expectations) {
4040
- checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
4039
+ if (task.expectations) {
4040
+ checkExpectations(task.expectations, $ongoingTaskResult.$resultString || '');
4041
4041
  }
4042
4042
  return [2 /*return*/, "break-attempts"];
4043
4043
  case 43:
@@ -4045,38 +4045,38 @@ function executeAttempts(options) {
4045
4045
  if (!(error_3 instanceof ExpectError)) {
4046
4046
  throw error_3;
4047
4047
  }
4048
- $ongoingTemplateResult.$expectError = error_3;
4048
+ $ongoingTaskResult.$expectError = error_3;
4049
4049
  return [3 /*break*/, 45];
4050
4050
  case 44:
4051
4051
  if (!isJokerAttempt &&
4052
- template.templateType === 'PROMPT_TEMPLATE' &&
4053
- $ongoingTemplateResult.$prompt
4052
+ task.taskType === 'PROMPT_TASK' &&
4053
+ $ongoingTaskResult.$prompt
4054
4054
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
4055
4055
  // In that case we don’t want to make a report about it because it’s not a llm execution error
4056
4056
  ) {
4057
- // TODO: [🧠] Maybe put other templateTypes into report
4057
+ // TODO: [🧠] Maybe put other taskTypes into report
4058
4058
  $executionReport.promptExecutions.push({
4059
- prompt: __assign({}, $ongoingTemplateResult.$prompt),
4060
- result: $ongoingTemplateResult.$result || undefined,
4061
- error: $ongoingTemplateResult.$expectError === null
4059
+ prompt: __assign({}, $ongoingTaskResult.$prompt),
4060
+ result: $ongoingTaskResult.$result || undefined,
4061
+ error: $ongoingTaskResult.$expectError === null
4062
4062
  ? undefined
4063
- : serializeError($ongoingTemplateResult.$expectError),
4063
+ : serializeError($ongoingTaskResult.$expectError),
4064
4064
  });
4065
4065
  }
4066
4066
  return [7 /*endfinally*/];
4067
4067
  case 45:
4068
- if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
4068
+ if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
4069
4069
  throw new PipelineExecutionError(spaceTrim$1(function (block) {
4070
4070
  var _a, _b, _c;
4071
- return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
4071
+ return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
4072
4072
  .split('\n')
4073
4073
  .map(function (line) { return "> ".concat(line); })
4074
- .join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
4074
+ .join('\n')), "\n\n Last error ").concat(((_b = $ongoingTaskResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTaskResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
4075
4075
  .split('\n')
4076
4076
  .map(function (line) { return "> ".concat(line); })
4077
- .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
4077
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTaskResult.$resultString === null
4078
4078
  ? 'null'
4079
- : $ongoingTemplateResult.$resultString
4079
+ : $ongoingTaskResult.$resultString
4080
4080
  .split('\n')
4081
4081
  .map(function (line) { return "> ".concat(line); })
4082
4082
  .join('\n')), "\n ---\n ");
@@ -4101,10 +4101,10 @@ function executeAttempts(options) {
4101
4101
  attempt++;
4102
4102
  return [3 /*break*/, 1];
4103
4103
  case 4:
4104
- if ($ongoingTemplateResult.$resultString === null) {
4104
+ if ($ongoingTaskResult.$resultString === null) {
4105
4105
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
4106
4106
  }
4107
- return [2 /*return*/, $ongoingTemplateResult.$resultString];
4107
+ return [2 /*return*/, $ongoingTaskResult.$resultString];
4108
4108
  }
4109
4109
  });
4110
4110
  });
@@ -4120,36 +4120,36 @@ function executeAttempts(options) {
4120
4120
  */
4121
4121
  function executeFormatSubvalues(options) {
4122
4122
  return __awaiter(this, void 0, void 0, function () {
4123
- var template, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
4123
+ var task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
4124
4124
  var _this = this;
4125
4125
  return __generator(this, function (_a) {
4126
4126
  switch (_a.label) {
4127
4127
  case 0:
4128
- template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
4129
- if (template.foreach === undefined) {
4128
+ task = options.task, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, csvSettings = options.csvSettings, pipelineIdentification = options.pipelineIdentification;
4129
+ if (task.foreach === undefined) {
4130
4130
  return [2 /*return*/, /* not await */ executeAttempts(options)];
4131
4131
  }
4132
4132
  if (jokerParameterNames.length !== 0) {
4133
4133
  throw new UnexpectedError(spaceTrim(function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
4134
4134
  }
4135
- parameterValue = parameters[template.foreach.parameterName] || '';
4135
+ parameterValue = parameters[task.foreach.parameterName] || '';
4136
4136
  formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
4137
- return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(template.foreach.formatName);
4137
+ return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(task.foreach.formatName);
4138
4138
  });
4139
4139
  if (formatDefinition === undefined) {
4140
4140
  throw new UnexpectedError(
4141
4141
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
4142
- spaceTrim(function (block) { return "\n Unsupported format \"".concat(template.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
4142
+ spaceTrim(function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
4143
4143
  .map(function (formatName) { return "- ".concat(formatName); })
4144
4144
  .join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
4145
4145
  }
4146
4146
  subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
4147
- return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
4147
+ return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(task.foreach.subformatName);
4148
4148
  });
4149
4149
  if (subvalueDefinition === undefined) {
4150
4150
  throw new UnexpectedError(
4151
4151
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
4152
- spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(template.foreach.subformatName, "\" for format \"").concat(template.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
4152
+ spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
4153
4153
  .map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
4154
4154
  .map(function (subvalueName) { return "- ".concat(subvalueName); })
4155
4155
  .join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
@@ -4158,7 +4158,7 @@ function executeFormatSubvalues(options) {
4158
4158
  formatSettings = csvSettings;
4159
4159
  // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
4160
4160
  }
4161
- return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
4161
+ return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
4162
4162
  var mappedParameters, allSubparameters, subresultString;
4163
4163
  return __generator(this, function (_a) {
4164
4164
  switch (_a.label) {
@@ -4167,7 +4167,7 @@ function executeFormatSubvalues(options) {
4167
4167
  // TODO: When done [🐚] Report progress also for each subvalue here
4168
4168
  try {
4169
4169
  mappedParameters = mapAvailableToExpectedParameters({
4170
- expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
4170
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
4171
4171
  availableParameters: subparameters,
4172
4172
  });
4173
4173
  }
@@ -4200,7 +4200,7 @@ function executeFormatSubvalues(options) {
4200
4200
  *
4201
4201
  * @private internal utility of `createPipelineExecutor`
4202
4202
  */
4203
- function getContextForTemplate(template) {
4203
+ function getContextForTask(task) {
4204
4204
  return __awaiter(this, void 0, void 0, function () {
4205
4205
  return __generator(this, function (_a) {
4206
4206
  return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
@@ -4213,15 +4213,10 @@ function getContextForTemplate(template) {
4213
4213
  *
4214
4214
  * @private internal utility of `createPipelineExecutor`
4215
4215
  */
4216
- function getKnowledgeForTemplate(options) {
4216
+ function getExamplesForTask(task) {
4217
4217
  return __awaiter(this, void 0, void 0, function () {
4218
- var preparedPipeline;
4219
4218
  return __generator(this, function (_a) {
4220
- preparedPipeline = options.preparedPipeline, options.template;
4221
- return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
4222
- var content = _a.content;
4223
- return "- ".concat(content);
4224
- }).join('\n')];
4219
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
4225
4220
  });
4226
4221
  });
4227
4222
  }
@@ -4231,10 +4226,15 @@ function getKnowledgeForTemplate(options) {
4231
4226
  *
4232
4227
  * @private internal utility of `createPipelineExecutor`
4233
4228
  */
4234
- function getExamplesForTemplate(template) {
4229
+ function getKnowledgeForTask(options) {
4235
4230
  return __awaiter(this, void 0, void 0, function () {
4231
+ var preparedPipeline;
4236
4232
  return __generator(this, function (_a) {
4237
- return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
4233
+ preparedPipeline = options.preparedPipeline, options.task;
4234
+ return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
4235
+ var content = _a.content;
4236
+ return "- ".concat(content);
4237
+ }).join('\n')];
4238
4238
  });
4239
4239
  });
4240
4240
  }
@@ -4244,21 +4244,21 @@ function getExamplesForTemplate(template) {
4244
4244
  *
4245
4245
  * @private internal utility of `createPipelineExecutor`
4246
4246
  */
4247
- function getReservedParametersForTemplate(options) {
4247
+ function getReservedParametersForTask(options) {
4248
4248
  return __awaiter(this, void 0, void 0, function () {
4249
- var preparedPipeline, template, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
4249
+ var preparedPipeline, task, pipelineIdentification, context, knowledge, examples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
4250
4250
  var e_1, _a;
4251
4251
  return __generator(this, function (_b) {
4252
4252
  switch (_b.label) {
4253
4253
  case 0:
4254
- preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
4255
- return [4 /*yield*/, getContextForTemplate()];
4254
+ preparedPipeline = options.preparedPipeline, task = options.task, pipelineIdentification = options.pipelineIdentification;
4255
+ return [4 /*yield*/, getContextForTask()];
4256
4256
  case 1:
4257
4257
  context = _b.sent();
4258
- return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
4258
+ return [4 /*yield*/, getKnowledgeForTask({ preparedPipeline: preparedPipeline, task: task })];
4259
4259
  case 2:
4260
4260
  knowledge = _b.sent();
4261
- return [4 /*yield*/, getExamplesForTemplate()];
4261
+ return [4 /*yield*/, getExamplesForTask()];
4262
4262
  case 3:
4263
4263
  examples = _b.sent();
4264
4264
  currentDate = new Date().toISOString();
@@ -4301,31 +4301,31 @@ function getReservedParametersForTemplate(options) {
4301
4301
  *
4302
4302
  * @private internal utility of `createPipelineExecutor`
4303
4303
  */
4304
- function executeTemplate(options) {
4304
+ function executeTask(options) {
4305
4305
  return __awaiter(this, void 0, void 0, function () {
4306
- var currentTemplate, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, _a, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _b, _c, _d, definedParameterNames, parameters, _loop_1, _e, _f, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
4306
+ var currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, _a, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _b, _c, _d, definedParameterNames, parameters, _loop_1, _e, _f, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
4307
4307
  var e_1, _g, _h;
4308
4308
  return __generator(this, function (_j) {
4309
4309
  switch (_j.label) {
4310
4310
  case 0:
4311
- currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a;
4312
- name = "pipeline-executor-frame-".concat(currentTemplate.name);
4313
- title = currentTemplate.title;
4314
- priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
4311
+ currentTask = options.currentTask, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, onProgress = options.onProgress, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a;
4312
+ name = "pipeline-executor-frame-".concat(currentTask.name);
4313
+ title = currentTask.title;
4314
+ priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
4315
4315
  return [4 /*yield*/, onProgress({
4316
4316
  name: name,
4317
4317
  title: title,
4318
4318
  isStarted: false,
4319
4319
  isDone: false,
4320
- templateType: currentTemplate.templateType,
4321
- parameterName: currentTemplate.resultingParameterName,
4320
+ taskType: currentTask.taskType,
4321
+ parameterName: currentTask.resultingParameterName,
4322
4322
  parameterValue: null,
4323
4323
  // <- [🍸]
4324
4324
  })];
4325
4325
  case 1:
4326
4326
  _j.sent();
4327
- usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
4328
- dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
4327
+ usedParameterNames = extractParameterNamesFromTask(currentTask);
4328
+ dependentParameterNames = new Set(currentTask.dependentParameterNames);
4329
4329
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
4330
4330
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
4331
4331
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
@@ -4336,9 +4336,9 @@ function executeTemplate(options) {
4336
4336
  }
4337
4337
  _c = (_b = Object).freeze;
4338
4338
  _d = [{}];
4339
- return [4 /*yield*/, getReservedParametersForTemplate({
4339
+ return [4 /*yield*/, getReservedParametersForTask({
4340
4340
  preparedPipeline: preparedPipeline,
4341
- template: currentTemplate,
4341
+ task: currentTask,
4342
4342
  pipelineIdentification: pipelineIdentification,
4343
4343
  })];
4344
4344
  case 2:
@@ -4356,11 +4356,11 @@ function executeTemplate(options) {
4356
4356
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
4357
4357
  // Houston, we have a problem
4358
4358
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
4359
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4359
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
4360
4360
  }
4361
4361
  };
4362
4362
  try {
4363
- // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
4363
+ // Note: [2] Check that all used parameters are defined and removing unused parameters for this task
4364
4364
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
4365
4365
  for (_e = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _f = _e.next(); !_f.done; _f = _e.next()) {
4366
4366
  parameterName = _f.value;
@@ -4376,18 +4376,16 @@ function executeTemplate(options) {
4376
4376
  }
4377
4377
  // Note: [👨‍👨‍👧] Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
4378
4378
  Object.freeze(parameters);
4379
- maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
4380
- jokerParameterNames = currentTemplate.jokerParameterNames || [];
4381
- preparedContent = (currentTemplate.preparedContent || '{content}')
4382
- .split('{content}')
4383
- .join(currentTemplate.content);
4379
+ maxAttempts = currentTask.taskType === 'DIALOG_TASK' ? Infinity : maxExecutionAttempts;
4380
+ jokerParameterNames = currentTask.jokerParameterNames || [];
4381
+ preparedContent = (currentTask.preparedContent || '{content}').split('{content}').join(currentTask.content);
4384
4382
  return [4 /*yield*/, executeFormatSubvalues({
4385
4383
  jokerParameterNames: jokerParameterNames,
4386
4384
  priority: priority,
4387
4385
  maxAttempts: maxAttempts,
4388
4386
  preparedContent: preparedContent,
4389
4387
  parameters: parameters,
4390
- template: currentTemplate,
4388
+ task: currentTask,
4391
4389
  preparedPipeline: preparedPipeline,
4392
4390
  tools: tools,
4393
4391
  $executionReport: $executionReport,
@@ -4400,15 +4398,15 @@ function executeTemplate(options) {
4400
4398
  title: title,
4401
4399
  isStarted: true,
4402
4400
  isDone: true,
4403
- templateType: currentTemplate.templateType,
4404
- parameterName: currentTemplate.resultingParameterName,
4401
+ taskType: currentTask.taskType,
4402
+ parameterName: currentTask.resultingParameterName,
4405
4403
  parameterValue: resultString,
4406
4404
  // <- [🍸]
4407
4405
  })];
4408
4406
  case 4:
4409
4407
  _j.sent();
4410
4408
  return [2 /*return*/, Object.freeze((_h = {},
4411
- _h[currentTemplate.resultingParameterName] =
4409
+ _h[currentTask.resultingParameterName] =
4412
4410
  // <- Note: [👩‍👩‍👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
4413
4411
  resultString,
4414
4412
  _h))];
@@ -4470,7 +4468,7 @@ function filterJustOutputParameters(options) {
4470
4468
  */
4471
4469
  function executePipeline(options) {
4472
4470
  return __awaiter(this, void 0, void 0, function () {
4473
- var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
4471
+ var inputParameters, tools, onProgress, pipeline, setPreparedPipeline, pipelineIdentification, maxParallelCount, rootDirname, _a, isVerbose, preparedPipeline, errors, warnings, executionReport, isReturned, _b, _c, parameter, e_1_1, _loop_1, _d, _e, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTasks_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
4474
4472
  var e_1, _f, e_2, _g;
4475
4473
  return __generator(this, function (_h) {
4476
4474
  switch (_h.label) {
@@ -4624,11 +4622,11 @@ function executePipeline(options) {
4624
4622
  var name = _a.name;
4625
4623
  return name;
4626
4624
  });
4627
- unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.templates), false);
4625
+ unresovedTasks_1 = __spreadArray([], __read(preparedPipeline.tasks), false);
4628
4626
  resolving_1 = [];
4629
4627
  loopLimit = LOOP_LIMIT;
4630
4628
  _loop_2 = function () {
4631
- var currentTemplate, work_1;
4629
+ var currentTask, work_1;
4632
4630
  return __generator(this, function (_k) {
4633
4631
  switch (_k.label) {
4634
4632
  case 0:
@@ -4636,15 +4634,15 @@ function executePipeline(options) {
4636
4634
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
4637
4635
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
4638
4636
  }
4639
- currentTemplate = unresovedTemplates_1.find(function (template) {
4640
- return template.dependentParameterNames.every(function (name) {
4637
+ currentTask = unresovedTasks_1.find(function (task) {
4638
+ return task.dependentParameterNames.every(function (name) {
4641
4639
  return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
4642
4640
  });
4643
4641
  });
4644
- if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
4642
+ if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
4645
4643
  throw new UnexpectedError(
4646
4644
  // TODO: [🐎] DRY
4647
- spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTemplates_1
4645
+ spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
4648
4646
  .map(function (_a) {
4649
4647
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
4650
4648
  return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
@@ -4663,14 +4661,14 @@ function executePipeline(options) {
4663
4661
  .map(function (name) { return "- Parameter `{".concat(name, "}`"); })
4664
4662
  .join('\n')), "\n\n *Note: This should be catched in `validatePipeline`*\n "); }));
4665
4663
  case 1:
4666
- if (!!currentTemplate) return [3 /*break*/, 3];
4664
+ if (!!currentTask) return [3 /*break*/, 3];
4667
4665
  /* [🤹‍♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
4668
4666
  case 2:
4669
4667
  /* [🤹‍♂️] */ _k.sent();
4670
4668
  return [3 /*break*/, 4];
4671
4669
  case 3:
4672
- unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
4673
- work_1 = executeTemplate(__assign(__assign({}, options), { currentTemplate: currentTemplate, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
4670
+ unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
4671
+ work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
4674
4672
  if (isReturned) {
4675
4673
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
4676
4674
  .split('\n')
@@ -4680,16 +4678,16 @@ function executePipeline(options) {
4680
4678
  if (onProgress) {
4681
4679
  onProgress(progress);
4682
4680
  }
4683
- }, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }) }))
4681
+ }, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
4684
4682
  .then(function (newParametersToPass) {
4685
4683
  parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
4686
- resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
4684
+ resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
4687
4685
  })
4688
4686
  .then(function () {
4689
4687
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
4690
4688
  });
4691
4689
  // <- Note: Errors are catched here [3]
4692
- // TODO: BUT if in multiple templates are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
4690
+ // TODO: BUT if in multiple tasks are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
4693
4691
  resolving_1.push(work_1);
4694
4692
  _k.label = 4;
4695
4693
  case 4: return [2 /*return*/];
@@ -4698,7 +4696,7 @@ function executePipeline(options) {
4698
4696
  };
4699
4697
  _h.label = 21;
4700
4698
  case 21:
4701
- if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 23];
4699
+ if (!(unresovedTasks_1.length > 0)) return [3 /*break*/, 23];
4702
4700
  return [5 /*yield**/, _loop_2()];
4703
4701
  case 22:
4704
4702
  _h.sent();
@@ -5239,6 +5237,9 @@ function normalizeToKebabCase(text) {
5239
5237
  normalizedName = normalizedName.replace(/-$/, '');
5240
5238
  return normalizedName;
5241
5239
  }
5240
+ /**
5241
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5242
+ */
5242
5243
 
5243
5244
  /**
5244
5245
  * Creates unique name for the source
@@ -5610,7 +5611,7 @@ TODO: [🧊] This is how it can look in future
5610
5611
  */
5611
5612
  function clonePipeline(pipeline) {
5612
5613
  // Note: Not using spread operator (...) because @@@
5613
- var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
5614
+ var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
5614
5615
  return {
5615
5616
  pipelineUrl: pipelineUrl,
5616
5617
  sourceFile: sourceFile,
@@ -5619,7 +5620,7 @@ function clonePipeline(pipeline) {
5619
5620
  description: description,
5620
5621
  formfactorName: formfactorName,
5621
5622
  parameters: parameters,
5622
- templates: templates,
5623
+ tasks: tasks,
5623
5624
  knowledgeSources: knowledgeSources,
5624
5625
  knowledgePieces: knowledgePieces,
5625
5626
  personas: personas,
@@ -5635,20 +5636,20 @@ function clonePipeline(pipeline) {
5635
5636
  *
5636
5637
  * @public exported from `@promptbook/core`
5637
5638
  */
5638
- function prepareTemplates(pipeline, tools, options) {
5639
+ function prepareTasks(pipeline, tools, options) {
5639
5640
  return __awaiter(this, void 0, void 0, function () {
5640
- var _a, maxParallelCount, templates, knowledgePiecesCount, templatesPrepared;
5641
+ var _a, maxParallelCount, tasks, knowledgePiecesCount, tasksPrepared;
5641
5642
  var _this = this;
5642
5643
  return __generator(this, function (_b) {
5643
5644
  switch (_b.label) {
5644
5645
  case 0:
5645
5646
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
5646
- templates = pipeline.templates, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
5647
- templatesPrepared = new Array(templates.length);
5648
- return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
5649
- var dependentParameterNames, preparedContent, preparedTemplate;
5647
+ tasks = pipeline.tasks, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
5648
+ tasksPrepared = new Array(tasks.length);
5649
+ return [4 /*yield*/, forEachAsync(tasks, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (task, index) { return __awaiter(_this, void 0, void 0, function () {
5650
+ var dependentParameterNames, preparedContent, preparedTask;
5650
5651
  return __generator(this, function (_a) {
5651
- dependentParameterNames = template.dependentParameterNames;
5652
+ dependentParameterNames = task.dependentParameterNames;
5652
5653
  preparedContent = undefined;
5653
5654
  if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
5654
5655
  preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
@@ -5657,22 +5658,22 @@ function prepareTemplates(pipeline, tools, options) {
5657
5658
  'knowledge',
5658
5659
  ], false);
5659
5660
  }
5660
- preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
5661
- templatesPrepared[index] = preparedTemplate;
5661
+ preparedTask = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
5662
+ tasksPrepared[index] = preparedTask;
5662
5663
  return [2 /*return*/];
5663
5664
  });
5664
5665
  }); })];
5665
5666
  case 1:
5666
5667
  _b.sent();
5667
- return [2 /*return*/, { templatesPrepared: templatesPrepared }];
5668
+ return [2 /*return*/, { tasksPrepared: tasksPrepared }];
5668
5669
  }
5669
5670
  });
5670
5671
  });
5671
5672
  }
5672
5673
  /**
5673
- * TODO: [🧠] Add context to each template (if missing)
5674
- * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
5675
- * TODO: [♨][main] !!! Prepare index the examples and maybe templates
5674
+ * TODO: [🧠] Add context to each task (if missing)
5675
+ * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
5676
+ * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
5676
5677
  * TODO: Write tests for `preparePipeline`
5677
5678
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
5678
5679
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -5689,12 +5690,12 @@ function prepareTemplates(pipeline, tools, options) {
5689
5690
  */
5690
5691
  function preparePipeline(pipeline, tools, options) {
5691
5692
  return __awaiter(this, void 0, void 0, function () {
5692
- var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, templates,
5693
+ var rootDirname, _a, maxParallelCount, _b, isVerbose, parameters, tasks,
5693
5694
  /*
5694
5695
  <- TODO: [🧠][🪑] `promptbookVersion` */
5695
5696
  knowledgeSources /*
5696
5697
  <- TODO: [🧊] `knowledgePieces` */, personas /*
5697
- <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, templatesPrepared /* TODO: parameters: parametersPrepared*/;
5698
+ <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
5698
5699
  var _this = this;
5699
5700
  return __generator(this, function (_c) {
5700
5701
  switch (_c.label) {
@@ -5703,7 +5704,7 @@ function preparePipeline(pipeline, tools, options) {
5703
5704
  return [2 /*return*/, pipeline];
5704
5705
  }
5705
5706
  rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
5706
- parameters = pipeline.parameters, templates = pipeline.templates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
5707
+ parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
5707
5708
  if (tools === undefined || tools.llm === undefined) {
5708
5709
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
5709
5710
  }
@@ -5746,9 +5747,9 @@ function preparePipeline(pipeline, tools, options) {
5746
5747
  case 2:
5747
5748
  partialknowledgePiecesPrepared = _c.sent();
5748
5749
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
5749
- return [4 /*yield*/, prepareTemplates({
5750
+ return [4 /*yield*/, prepareTasks({
5750
5751
  parameters: parameters,
5751
- templates: templates,
5752
+ tasks: tasks,
5752
5753
  knowledgePiecesCount: knowledgePiecesPrepared.length,
5753
5754
  }, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
5754
5755
  rootDirname: rootDirname,
@@ -5756,12 +5757,12 @@ function preparePipeline(pipeline, tools, options) {
5756
5757
  isVerbose: isVerbose,
5757
5758
  })];
5758
5759
  case 3:
5759
- templatesPrepared = (_c.sent()).templatesPrepared;
5760
- // ----- /Templates preparation -----
5760
+ tasksPrepared = (_c.sent()).tasksPrepared;
5761
+ // ----- /Tasks preparation -----
5761
5762
  // Note: Count total usage
5762
5763
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
5763
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { templates: __spreadArray([], __read(templatesPrepared), false),
5764
- // <- TODO: [🪓] Here should be no need for spreading new array, just ` templates: templatesPrepared`
5764
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
5765
+ // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
5765
5766
  knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
5766
5767
  }
5767
5768
  });
@@ -5776,6 +5777,40 @@ function preparePipeline(pipeline, tools, options) {
5776
5777
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
5777
5778
  */
5778
5779
 
5780
+ /**
5781
+ * All available task types
5782
+ *
5783
+ * There is is distinction between task types and section types
5784
+ * - Every section in markdown has its SectionType
5785
+ * - Some sections are tasks but other can be non-task sections
5786
+ *
5787
+ * @public exported from `@promptbook/core`
5788
+ */
5789
+ var TaskTypes = [
5790
+ 'PROMPT',
5791
+ 'SIMPLE',
5792
+ 'SCRIPT',
5793
+ 'DIALOG',
5794
+ // <- [🅱]
5795
+ ];
5796
+
5797
+ /**
5798
+ * All available sections which are not tasks
5799
+ *
5800
+ * @public exported from `@promptbook/core`
5801
+ */
5802
+ var NonTaskSectionTypes = ['EXAMPLE', 'KNOWLEDGE', 'INSTRUMENT', 'ACTION'];
5803
+ /**
5804
+ * All available section types
5805
+ *
5806
+ * There is is distinction between task types and section types
5807
+ * - Every section in markdown has its SectionType
5808
+ * - Some sections are tasks but other can be non-task sections
5809
+ *
5810
+ * @public exported from `@promptbook/core`
5811
+ */
5812
+ var SectionTypes = __spreadArray(__spreadArray([], __read(TaskTypes.map(function (TaskType) { return "".concat(TaskType, "_TASK"); })), false), __read(NonTaskSectionTypes), false);
5813
+
5779
5814
  /**
5780
5815
  * Parses the knowledge command
5781
5816
  *
@@ -5791,7 +5826,7 @@ var knowledgeCommandParser = {
5791
5826
  * BOILERPLATE command can be used in:
5792
5827
  */
5793
5828
  isUsedInPipelineHead: true,
5794
- isUsedInPipelineTemplate: false,
5829
+ isUsedInPipelineTask: false,
5795
5830
  /**
5796
5831
  * Description of the KNOWLEDGE command
5797
5832
  */
@@ -5869,18 +5904,18 @@ var knowledgeCommandParser = {
5869
5904
  */
5870
5905
 
5871
5906
  /**
5872
- * Parses the template command
5907
+ * Parses the section command
5873
5908
  *
5874
5909
  * @see `documentationUrl` for more details
5875
5910
  * @private within the commands folder
5876
5911
  */
5877
- var templateCommandParser = {
5912
+ var sectionCommandParser = {
5878
5913
  /**
5879
5914
  * Name of the command
5880
5915
  */
5881
- name: 'TEMPLATE',
5916
+ name: 'SECTION',
5882
5917
  /**
5883
- * Aliases for the TEMPLATE command
5918
+ * Aliases for the SECTION command
5884
5919
  */
5885
5920
  aliasNames: [
5886
5921
  'PROMPT',
@@ -5894,24 +5929,24 @@ var templateCommandParser = {
5894
5929
  'ACTION', // <- Note: [⛱]
5895
5930
  ],
5896
5931
  /**
5897
- * Aliases for the TEMPLATE command
5932
+ * Aliases for the SECTION command
5898
5933
  */
5899
- deprecatedNames: ['BLOCK', 'EXECUTE'],
5934
+ deprecatedNames: ['TEMPLATE', 'BLOCK', 'EXECUTE'],
5900
5935
  /**
5901
5936
  * BOILERPLATE command can be used in:
5902
5937
  */
5903
5938
  isUsedInPipelineHead: false,
5904
- isUsedInPipelineTemplate: true,
5939
+ isUsedInPipelineTask: true,
5905
5940
  /**
5906
- * Description of the TEMPLATE command
5941
+ * Description of the SECTION command
5907
5942
  */
5908
- description: "What should the code template template do",
5943
+ description: "Defines the purpose of the markdown section - if its a task and which type or something else",
5909
5944
  /**
5910
5945
  * Link to documentation
5911
5946
  */
5912
5947
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
5913
5948
  /**
5914
- * Example usages of the TEMPLATE command
5949
+ * Example usages of the SECTION command
5915
5950
  */
5916
5951
  examples: [
5917
5952
  // Short form:
@@ -5926,101 +5961,103 @@ var templateCommandParser = {
5926
5961
  'ACTION',
5927
5962
  // -----------------
5928
5963
  // Recommended (reversed) form:
5929
- 'PROMPT TEMPLATE',
5930
- 'SIMPLE TEMPLATE',
5931
- 'SCRIPT TEMPLATE',
5932
- 'DIALOG TEMPLATE',
5964
+ 'PROMPT SECTION',
5965
+ 'SIMPLE SECTION',
5966
+ 'SCRIPT SECTION',
5967
+ 'DIALOG SECTION',
5933
5968
  // <- [🅱]
5934
- 'SAMPLE TEMPLATE',
5935
- 'KNOWLEDGE TEMPLATE',
5936
- 'INSTRUMENT TEMPLATE',
5937
- 'ACTION TEMPLATE',
5969
+ 'EXAMPLE SECTION',
5970
+ 'KNOWLEDGE SECTION',
5971
+ 'INSTRUMENT SECTION',
5972
+ 'ACTION SECTION',
5938
5973
  // -----------------
5939
5974
  // Standard form:
5940
- 'TEMPLATE PROMPT',
5941
- 'TEMPLATE SIMPLE',
5942
- 'TEMPLATE SCRIPT',
5943
- 'TEMPLATE DIALOG',
5975
+ 'SECTION PROMPT',
5976
+ 'SECTION SIMPLE',
5977
+ 'SECTION SCRIPT',
5978
+ 'SECTION DIALOG',
5944
5979
  // <- [🅱]
5945
- 'SAMPLE TEMPLATE',
5946
- 'KNOWLEDGE TEMPLATE',
5947
- 'INSTRUMENT TEMPLATE',
5948
- 'ACTION TEMPLATE',
5980
+ 'SECTION EXAMPLE',
5981
+ 'SECTION KNOWLEDGE',
5982
+ 'SECTION INSTRUMENT',
5983
+ 'SECTION ACTION',
5949
5984
  ],
5950
5985
  // TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
5951
5986
  /**
5952
- * Parses the TEMPLATE command
5987
+ * Parses the SECTION command
5953
5988
  */
5954
5989
  parse: function (input) {
5955
5990
  var normalized = input.normalized;
5956
5991
  normalized = normalized.split('SAMPLE').join('EXAMPLE');
5957
- var templateTypes = TemplateTypes.filter(function (templateType) {
5958
- return normalized.includes(templateType.split('_TEMPLATE').join(''));
5992
+ normalized = normalized.split('EXECUTE_').join('');
5993
+ normalized = normalized.split('DIALOGUE').join('DIALOG');
5994
+ var taskTypes = SectionTypes.filter(function (sectionType) {
5995
+ return normalized.includes(sectionType.split('_TASK').join(''));
5959
5996
  });
5960
- if (templateTypes.length !== 1) {
5961
- throw new ParseError(spaceTrim(function (template) { return "\n Unknown template type in TEMPLATE command\n\n Supported template types are:\n ".concat(template(TemplateTypes.join(', ')), "\n "); }));
5997
+ if (taskTypes.length !== 1) {
5998
+ throw new ParseError(spaceTrim(function (block) { return "\n Unknown section type \"".concat(normalized, "\"\n\n Supported section types are:\n ").concat(block(SectionTypes.join(', ')), "\n "); }));
5962
5999
  }
5963
- var templateType = templateTypes[0];
6000
+ var taskType = taskTypes[0];
5964
6001
  return {
5965
- type: 'TEMPLATE',
5966
- templateType: templateType,
6002
+ type: 'SECTION',
6003
+ taskType: taskType,
5967
6004
  };
5968
6005
  },
5969
6006
  /**
5970
- * Apply the TEMPLATE command to the `pipelineJson`
6007
+ * Apply the SECTION command to the `pipelineJson`
5971
6008
  *
5972
- * Note: `$` is used to indicate that this function mutates given `templateJson`
6009
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
5973
6010
  */
5974
- $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
5975
- if ($templateJson.isTemplateTypeSet === true) {
5976
- throw new ParseError(spaceTrim("\n Template type is already defined in the template.\n It can be defined only once.\n "));
6011
+ $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
6012
+ if ($taskJson.isSectionTypeSet === true) {
6013
+ throw new ParseError(spaceTrim("\n Section type is already defined in the section.\n It can be defined only once.\n "));
5977
6014
  }
5978
- $templateJson.isTemplateTypeSet = true;
6015
+ $taskJson.isSectionTypeSet = true;
5979
6016
  // TODO: [🍧] Rearrange better - but at bottom and unwrap from function
5980
6017
  var expectResultingParameterName = function () {
5981
- if ($templateJson.resultingParameterName) {
6018
+ if ($taskJson.resultingParameterName) {
5982
6019
  return;
5983
6020
  }
5984
- throw new ParseError(" Template section must end with -> {parameterName}");
6021
+ throw new ParseError("Task section and example section must end with return statement -> {parameterName}");
5985
6022
  };
5986
- if ($templateJson.content === undefined) {
5987
- throw new UnexpectedError("Content is missing in the templateJson - probbably commands are applied in wrong order");
6023
+ if ($taskJson.content === undefined) {
6024
+ throw new UnexpectedError("Content is missing in the taskJson - probbably commands are applied in wrong order");
5988
6025
  }
5989
- if (command.templateType === 'EXAMPLE') {
6026
+ if (command.taskType === 'EXAMPLE') {
5990
6027
  expectResultingParameterName();
5991
- var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $templateJson.resultingParameterName; });
6028
+ var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
5992
6029
  if (parameter === undefined) {
5993
- throw new ParseError("Can not find parameter {".concat($templateJson.resultingParameterName, "} to assign example value on it"));
6030
+ throw new ParseError("Can not find parameter {".concat($taskJson.resultingParameterName, "} to assign example value on it"));
5994
6031
  }
5995
6032
  parameter.exampleValues = parameter.exampleValues || [];
5996
- parameter.exampleValues.push($templateJson.content);
5997
- $templateJson.isTemplate = false;
6033
+ parameter.exampleValues.push($taskJson.content);
6034
+ $taskJson.isTask = false;
5998
6035
  return;
5999
6036
  }
6000
- if (command.templateType === 'KNOWLEDGE') {
6037
+ if (command.taskType === 'KNOWLEDGE') {
6001
6038
  knowledgeCommandParser.$applyToPipelineJson({
6002
6039
  type: 'KNOWLEDGE',
6003
- sourceContent: $templateJson.content, // <- TODO: [🐝][main] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6040
+ sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6004
6041
  }, $pipelineJson);
6005
- $templateJson.isTemplate = false;
6042
+ $taskJson.isTask = false;
6006
6043
  return;
6007
6044
  }
6008
- if (command.templateType === 'ACTION') {
6045
+ if (command.taskType === 'ACTION') {
6009
6046
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
6010
- $templateJson.isTemplate = false;
6047
+ $taskJson.isTask = false;
6011
6048
  return;
6012
6049
  }
6013
- if (command.templateType === 'INSTRUMENT') {
6050
+ if (command.taskType === 'INSTRUMENT') {
6014
6051
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
6015
- $templateJson.isTemplate = false;
6052
+ $taskJson.isTask = false;
6016
6053
  return;
6017
6054
  }
6018
6055
  expectResultingParameterName();
6019
- $templateJson.templateType = command.templateType;
6020
- $templateJson.isTemplate = true;
6056
+ $taskJson.taskType = command.taskType;
6057
+ $taskJson.isTask = true;
6021
6058
  },
6022
6059
  /**
6023
- * Converts the TEMPLATE command back to string
6060
+ * Converts the SECTION command back to string
6024
6061
  *
6025
6062
  * Note: This is used in `pipelineJsonToString` utility
6026
6063
  */
@@ -6028,11 +6065,11 @@ var templateCommandParser = {
6028
6065
  return "---"; // <- TODO: [🛋] Implement
6029
6066
  },
6030
6067
  /**
6031
- * Reads the TEMPLATE command from the `TemplateJson`
6068
+ * Reads the SECTION command from the `TaskJson`
6032
6069
  *
6033
6070
  * Note: This is used in `pipelineJsonToString` utility
6034
6071
  */
6035
- takeFromTemplateJson: function ($templateJson) {
6072
+ takeFromTaskJson: function ($taskJson) {
6036
6073
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6037
6074
  },
6038
6075
  };
@@ -6040,8 +6077,8 @@ var templateCommandParser = {
6040
6077
  * Note: [⛱] There are two types of KNOWLEDGE, ACTION and INSTRUMENT commands:
6041
6078
  * 1) There are commands `KNOWLEDGE`, `ACTION` and `INSTRUMENT` used in the pipeline head, they just define the knowledge, action or instrument as single line after the command
6042
6079
  * - KNOWLEDGE Look at https://en.wikipedia.org/wiki/Artificial_intelligence
6043
- * 2) `KNOWLEDGE TEMPLATE` which has short form `KNOWLEDGE` is used in the template, does not refer the line itself, but the content of the template
6044
- * - KNOWLEDGE TEMPLATE
6080
+ * 2) `KNOWLEDGE SECTION` which has short form `KNOWLEDGE` is used in the sectiom, does not refer the line itself, but the content of the section block
6081
+ * - KNOWLEDGE SECTION
6045
6082
  *
6046
6083
  * ```
6047
6084
  * Look at https://en.wikipedia.org/wiki/Artificial_intelligence
@@ -6069,7 +6106,7 @@ var boilerplateCommandParser = {
6069
6106
  * BOILERPLATE command can be used in:
6070
6107
  */
6071
6108
  isUsedInPipelineHead: true,
6072
- isUsedInPipelineTemplate: true,
6109
+ isUsedInPipelineTask: true,
6073
6110
  /**
6074
6111
  * Description of the BOILERPLATE command
6075
6112
  */
@@ -6110,9 +6147,9 @@ var boilerplateCommandParser = {
6110
6147
  /**
6111
6148
  * Apply the BOILERPLATE command to the `pipelineJson`
6112
6149
  *
6113
- * Note: `$` is used to indicate that this function mutates given `templateJson`
6150
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
6114
6151
  */
6115
- $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6152
+ $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
6116
6153
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
6117
6154
  },
6118
6155
  /**
@@ -6132,11 +6169,11 @@ var boilerplateCommandParser = {
6132
6169
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
6133
6170
  },
6134
6171
  /**
6135
- * Reads the BOILERPLATE command from the `TemplateJson`
6172
+ * Reads the BOILERPLATE command from the `TaskJson`
6136
6173
  *
6137
6174
  * Note: This is used in `pipelineJsonToString` utility
6138
6175
  */
6139
- takeFromTemplateJson: function ($templateJson) {
6176
+ takeFromTaskJson: function ($taskJson) {
6140
6177
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .book.md file");
6141
6178
  },
6142
6179
  };
@@ -6157,7 +6194,7 @@ var bookVersionCommandParser = {
6157
6194
  * BOILERPLATE command can be used in:
6158
6195
  */
6159
6196
  isUsedInPipelineHead: true,
6160
- isUsedInPipelineTemplate: false,
6197
+ isUsedInPipelineTask: false,
6161
6198
  /**
6162
6199
  * Description of the BOOK_VERSION command
6163
6200
  */
@@ -6311,11 +6348,11 @@ var expectCommandParser = {
6311
6348
  * BOILERPLATE command can be used in:
6312
6349
  */
6313
6350
  isUsedInPipelineHead: false,
6314
- isUsedInPipelineTemplate: true,
6351
+ isUsedInPipelineTask: true,
6315
6352
  /**
6316
6353
  * Description of the FORMAT command
6317
6354
  */
6318
- description: spaceTrim("\n Expect command describes the desired output of the template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6355
+ description: spaceTrim("\n Expect command describes the desired output of the task *(after post-processing)*\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6319
6356
  /**
6320
6357
  * Link to documentation
6321
6358
  */
@@ -6407,24 +6444,24 @@ var expectCommandParser = {
6407
6444
  /**
6408
6445
  * Apply the FORMAT command to the `pipelineJson`
6409
6446
  *
6410
- * Note: `$` is used to indicate that this function mutates given `templateJson`
6447
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
6411
6448
  */
6412
- $applyToTemplateJson: function (command, $templateJson) {
6449
+ $applyToTaskJson: function (command, $taskJson) {
6413
6450
  // eslint-disable-next-line no-case-declarations
6414
6451
  var unit = command.unit.toLowerCase();
6415
- $templateJson.expectations = $templateJson.expectations || {};
6416
- $templateJson.expectations[unit] = $templateJson.expectations[unit] || {};
6452
+ $taskJson.expectations = $taskJson.expectations || {};
6453
+ $taskJson.expectations[unit] = $taskJson.expectations[unit] || {};
6417
6454
  if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
6418
- if ($templateJson.expectations[unit].min !== undefined) {
6419
- throw new ParseError("Already defined minumum ".concat($templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6455
+ if ($taskJson.expectations[unit].min !== undefined) {
6456
+ throw new ParseError("Already defined minumum ".concat($taskJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6420
6457
  }
6421
- $templateJson.expectations[unit].min = command.amount;
6458
+ $taskJson.expectations[unit].min = command.amount;
6422
6459
  } /* not else */
6423
6460
  if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
6424
- if ($templateJson.expectations[unit].max !== undefined) {
6425
- throw new ParseError("Already defined maximum ".concat($templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6461
+ if ($taskJson.expectations[unit].max !== undefined) {
6462
+ throw new ParseError("Already defined maximum ".concat($taskJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
6426
6463
  }
6427
- $templateJson.expectations[unit].max = command.amount;
6464
+ $taskJson.expectations[unit].max = command.amount;
6428
6465
  }
6429
6466
  },
6430
6467
  /**
@@ -6436,11 +6473,11 @@ var expectCommandParser = {
6436
6473
  return "---"; // <- TODO: [🛋] Implement
6437
6474
  },
6438
6475
  /**
6439
- * Reads the FORMAT command from the `TemplateJson`
6476
+ * Reads the FORMAT command from the `TaskJson`
6440
6477
  *
6441
6478
  * Note: This is used in `pipelineJsonToString` utility
6442
6479
  */
6443
- takeFromTemplateJson: function ($templateJson) {
6480
+ takeFromTaskJson: function ($taskJson) {
6444
6481
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6445
6482
  },
6446
6483
  };
@@ -6647,7 +6684,7 @@ var foreachCommandParser = {
6647
6684
  * FOREACH command can be used in:
6648
6685
  */
6649
6686
  isUsedInPipelineHead: false,
6650
- isUsedInPipelineTemplate: true,
6687
+ isUsedInPipelineTask: true,
6651
6688
  /**
6652
6689
  * Description of the FOREACH command
6653
6690
  */
@@ -6746,13 +6783,13 @@ var foreachCommandParser = {
6746
6783
  /**
6747
6784
  * Apply the FOREACH command to the `pipelineJson`
6748
6785
  *
6749
- * Note: `$` is used to indicate that this function mutates given `templateJson`
6786
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
6750
6787
  */
6751
- $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6788
+ $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
6752
6789
  var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
6753
6790
  // TODO: [🍭] Detect double use
6754
6791
  // TODO: [🍭] Detect usage with JOKER and don't allow it
6755
- $templateJson.foreach = {
6792
+ $taskJson.foreach = {
6756
6793
  formatName: formatName,
6757
6794
  subformatName: subformatName,
6758
6795
  parameterName: parameterName,
@@ -6770,11 +6807,11 @@ var foreachCommandParser = {
6770
6807
  return "---"; // <- TODO: [🛋] Implement
6771
6808
  },
6772
6809
  /**
6773
- * Reads the FOREACH command from the `TemplateJson`
6810
+ * Reads the FOREACH command from the `TaskJson`
6774
6811
  *
6775
6812
  * Note: This is used in `pipelineJsonToString` utility
6776
6813
  */
6777
- takeFromTemplateJson: function ($templateJson) {
6814
+ takeFromTaskJson: function ($taskJson) {
6778
6815
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6779
6816
  },
6780
6817
  };
@@ -6797,11 +6834,11 @@ var formatCommandParser = {
6797
6834
  * BOILERPLATE command can be used in:
6798
6835
  */
6799
6836
  isUsedInPipelineHead: false,
6800
- isUsedInPipelineTemplate: true,
6837
+ isUsedInPipelineTask: true,
6801
6838
  /**
6802
6839
  * Description of the FORMAT command
6803
6840
  */
6804
- description: spaceTrim("\n Format command describes the desired output of the template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6841
+ description: spaceTrim("\n Format command describes the desired output of the task (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
6805
6842
  /**
6806
6843
  * Link to documentation
6807
6844
  */
@@ -6828,13 +6865,13 @@ var formatCommandParser = {
6828
6865
  /**
6829
6866
  * Apply the FORMAT command to the `pipelineJson`
6830
6867
  *
6831
- * Note: `$` is used to indicate that this function mutates given `templateJson`
6868
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
6832
6869
  */
6833
- $applyToTemplateJson: function (command, $templateJson) {
6834
- if ($templateJson.format !== undefined && command.format !== $templateJson.format) {
6835
- throw new ParseError("Format format is already defined to \"".concat($templateJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
6870
+ $applyToTaskJson: function (command, $taskJson) {
6871
+ if ($taskJson.format !== undefined && command.format !== $taskJson.format) {
6872
+ throw new ParseError("Format format is already defined to \"".concat($taskJson.format, "\".\n Now you try to redefine it by \"").concat(command.format, "\""));
6836
6873
  }
6837
- $templateJson.format = command.format;
6874
+ $taskJson.format = command.format;
6838
6875
  },
6839
6876
  /**
6840
6877
  * Converts the FORMAT command back to string
@@ -6845,11 +6882,11 @@ var formatCommandParser = {
6845
6882
  return "---"; // <- TODO: [🛋] Implement
6846
6883
  },
6847
6884
  /**
6848
- * Reads the FORMAT command from the `TemplateJson`
6885
+ * Reads the FORMAT command from the `TaskJson`
6849
6886
  *
6850
6887
  * Note: This is used in `pipelineJsonToString` utility
6851
6888
  */
6852
- takeFromTemplateJson: function ($templateJson) {
6889
+ takeFromTaskJson: function ($taskJson) {
6853
6890
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6854
6891
  },
6855
6892
  };
@@ -6859,37 +6896,68 @@ var formatCommandParser = {
6859
6896
  *
6860
6897
  * @public exported from `@promptbook/core`
6861
6898
  */
6862
- var ChatFormfactorDefinition = {
6899
+ var ChatbotFormfactorDefinition = {
6863
6900
  name: 'CHATBOT',
6864
6901
  aliasNames: ['CHAT'],
6865
6902
  description: "@@@",
6866
- documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
6903
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/174",
6867
6904
  pipelineInterface: {
6868
- inputParameterNames: ['previousTitle', 'previousConversationSummary', 'userMessage'],
6869
- outputParameterNames: ['title', 'conversationSummary', 'chatbotResponse'],
6870
- /*
6871
- <- TODO: !!!!!! Change to
6872
-
6873
- - INPUT PARAMETER `{previousTitle}` Previous title of the conversation
6874
- - INPUT PARAMETER `{previousConversationSummary}` Previous conversation summary
6875
- - INPUT PARAMETER `{userMessage}` User message
6876
- - OUTPUT PARAMETER `{title}` Title of the conversation
6877
- - OUTPUT PARAMETER `{conversationSummary}` Summary of the conversation
6878
- - OUTPUT PARAMETER `{chatbotResponse}` Chatbot response
6905
+ inputParameters: [
6906
+ {
6907
+ name: 'previousTitle',
6908
+ description: "Previous title of the conversation",
6909
+ isInput: true,
6910
+ isOutput: false,
6911
+ },
6912
+ {
6913
+ name: 'previousConversationSummary',
6914
+ description: "Previous conversation summary",
6915
+ isInput: true,
6916
+ isOutput: false,
6917
+ },
6918
+ { name: 'userMessage', description: "User message", isInput: true, isOutput: false },
6919
+ ],
6920
+ outputParameters: [
6921
+ { name: 'title', description: "Title of the conversation", isInput: false, isOutput: true },
6922
+ { name: 'conversationSummary', description: "Summary of the conversation", isInput: false, isOutput: true },
6923
+ { name: 'chatbotResponse', description: "Chatbot response", isInput: false, isOutput: true },
6924
+ ],
6925
+ },
6926
+ };
6879
6927
 
6880
- */
6928
+ /**
6929
+ * Generator is form of app that @@@
6930
+ *
6931
+ * @public exported from `@promptbook/core`
6932
+ */
6933
+ var GeneratorFormfactorDefinition = {
6934
+ name: 'GENERATOR',
6935
+ description: "@@@",
6936
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
6937
+ pipelineInterface: {
6938
+ inputParameters: [
6939
+ /* @@@ */
6940
+ ],
6941
+ outputParameters: [
6942
+ /* @@@ */
6943
+ ],
6881
6944
  },
6882
6945
  };
6883
6946
 
6884
6947
  /**
6885
6948
  * @@@
6886
6949
  *
6950
+ * @see https://github.com/webgptorg/promptbook/discussions/171
6951
+ *
6887
6952
  * @public exported from `@promptbook/core`
6888
6953
  */
6889
6954
  var GENERIC_PIPELINE_INTERFACE = {
6890
- inputParameterNames: [],
6891
- outputParameterNames: [],
6955
+ inputParameters: [],
6956
+ outputParameters: [],
6892
6957
  };
6958
+ /**
6959
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6960
+ */
6893
6961
 
6894
6962
  /**
6895
6963
  * @@@
@@ -6899,10 +6967,29 @@ var GENERIC_PIPELINE_INTERFACE = {
6899
6967
  var GenericFormfactorDefinition = {
6900
6968
  name: 'GENERIC',
6901
6969
  description: "@@@",
6902
- documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
6970
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/173",
6903
6971
  pipelineInterface: GENERIC_PIPELINE_INTERFACE,
6904
6972
  };
6905
6973
 
6974
+ /**
6975
+ * Matcher is form of app that @@@
6976
+ *
6977
+ * @public exported from `@promptbook/core`
6978
+ */
6979
+ var MatcherFormfactorDefinition = {
6980
+ name: 'EXPERIMENTAL_MATCHER',
6981
+ description: "@@@",
6982
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/177",
6983
+ pipelineInterface: {
6984
+ inputParameters: [
6985
+ /* @@@ */
6986
+ ],
6987
+ outputParameters: [
6988
+ /* @@@ */
6989
+ ],
6990
+ },
6991
+ };
6992
+
6906
6993
  /**
6907
6994
  * Sheets is form of app that @@@
6908
6995
  *
@@ -6911,10 +6998,24 @@ var GenericFormfactorDefinition = {
6911
6998
  var SheetsFormfactorDefinition = {
6912
6999
  name: 'SHEETS',
6913
7000
  description: "@@@",
6914
- documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
7001
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/176",
6915
7002
  pipelineInterface: {
6916
- inputParameterNames: ['inputSheet'],
6917
- outputParameterNames: ['outputSheet'],
7003
+ inputParameters: [
7004
+ {
7005
+ name: 'inputSheet',
7006
+ description: "Input sheet to be processed as csv",
7007
+ isInput: true,
7008
+ isOutput: false,
7009
+ },
7010
+ ],
7011
+ outputParameters: [
7012
+ {
7013
+ name: 'outputSheet',
7014
+ description: "Output sheet as csv",
7015
+ isInput: false,
7016
+ isOutput: true,
7017
+ },
7018
+ ],
6918
7019
  },
6919
7020
  };
6920
7021
 
@@ -6926,10 +7027,26 @@ var SheetsFormfactorDefinition = {
6926
7027
  var TranslatorFormfactorDefinition = {
6927
7028
  name: 'TRANSLATOR',
6928
7029
  description: "@@@",
6929
- documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
7030
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/175",
6930
7031
  pipelineInterface: {
6931
- inputParameterNames: ['inputMessage'],
6932
- outputParameterNames: ['outputMessage'],
7032
+ inputParameters: [
7033
+ {
7034
+ name: 'inputMessage',
7035
+ description: "Input message to be translated",
7036
+ isInput: true,
7037
+ isOutput: false,
7038
+ },
7039
+ ],
7040
+ outputParameters: [
7041
+ {
7042
+ name: 'outputMessage',
7043
+ description: "Translated output message",
7044
+ isInput: false,
7045
+ isOutput: true,
7046
+ },
7047
+ ],
7048
+ // <- TODO: [🤓] Maybe add {summary}
7049
+ // <- TODO: [🧠] maybe change to {inputText}, {inputText} / or make system for any name of first input and first outpur parameter
6933
7050
  },
6934
7051
  };
6935
7052
 
@@ -6940,10 +7057,15 @@ var TranslatorFormfactorDefinition = {
6940
7057
  */
6941
7058
  var FORMFACTOR_DEFINITIONS = [
6942
7059
  GenericFormfactorDefinition,
6943
- ChatFormfactorDefinition,
7060
+ ChatbotFormfactorDefinition,
6944
7061
  TranslatorFormfactorDefinition,
6945
7062
  SheetsFormfactorDefinition,
7063
+ MatcherFormfactorDefinition,
7064
+ GeneratorFormfactorDefinition,
6946
7065
  ];
7066
+ /**
7067
+ * Note: [💞] Ignore a discrepancy between file name and entity name
7068
+ */
6947
7069
 
6948
7070
  /**
6949
7071
  * Parses the formfactor command
@@ -6966,7 +7088,7 @@ var formfactorCommandParser = {
6966
7088
  * FORMFACTOR command can be used in:
6967
7089
  */
6968
7090
  isUsedInPipelineHead: true,
6969
- isUsedInPipelineTemplate: false,
7091
+ isUsedInPipelineTask: false,
6970
7092
  /**
6971
7093
  * Description of the FORMFACTOR command
6972
7094
  */
@@ -7048,11 +7170,11 @@ var jokerCommandParser = {
7048
7170
  * BOILERPLATE command can be used in:
7049
7171
  */
7050
7172
  isUsedInPipelineHead: false,
7051
- isUsedInPipelineTemplate: true,
7173
+ isUsedInPipelineTask: true,
7052
7174
  /**
7053
7175
  * Description of the JOKER command
7054
7176
  */
7055
- description: "Joker parameter is used instead of executing the template result if jokers value meets the expectations requirements",
7177
+ description: "Joker parameter is used instead of executing the task result if jokers value meets the expectations requirements",
7056
7178
  /**
7057
7179
  * Link to documentation
7058
7180
  */
@@ -7079,11 +7201,11 @@ var jokerCommandParser = {
7079
7201
  /**
7080
7202
  * Apply the JOKER command to the `pipelineJson`
7081
7203
  *
7082
- * Note: `$` is used to indicate that this function mutates given `templateJson`
7204
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
7083
7205
  */
7084
- $applyToTemplateJson: function (command, $templateJson) {
7085
- $templateJson.jokerParameterNames = $templateJson.jokerParameterNames || [];
7086
- $templateJson.jokerParameterNames.push(command.parameterName);
7206
+ $applyToTaskJson: function (command, $taskJson) {
7207
+ $taskJson.jokerParameterNames = $taskJson.jokerParameterNames || [];
7208
+ $taskJson.jokerParameterNames.push(command.parameterName);
7087
7209
  },
7088
7210
  /**
7089
7211
  * Converts the JOKER command back to string
@@ -7094,11 +7216,11 @@ var jokerCommandParser = {
7094
7216
  return "---"; // <- TODO: [🛋] Implement
7095
7217
  },
7096
7218
  /**
7097
- * Reads the JOKER command from the `TemplateJson`
7219
+ * Reads the JOKER command from the `TaskJson`
7098
7220
  *
7099
7221
  * Note: This is used in `pipelineJsonToString` utility
7100
7222
  */
7101
- takeFromTemplateJson: function ($templateJson) {
7223
+ takeFromTaskJson: function ($taskJson) {
7102
7224
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7103
7225
  },
7104
7226
  };
@@ -7125,11 +7247,11 @@ var modelCommandParser = {
7125
7247
  * BOILERPLATE command can be used in:
7126
7248
  */
7127
7249
  isUsedInPipelineHead: true,
7128
- isUsedInPipelineTemplate: true,
7250
+ isUsedInPipelineTask: true,
7129
7251
  /**
7130
7252
  * Description of the MODEL command
7131
7253
  */
7132
- description: "Tells which `modelRequirements` (for example which model) to use for the prompt template execution",
7254
+ description: "Tells which `modelRequirements` (for example which model) to use for the prompt task execution",
7133
7255
  /**
7134
7256
  * Link to documentation
7135
7257
  */
@@ -7203,30 +7325,30 @@ var modelCommandParser = {
7203
7325
  /**
7204
7326
  * Apply the MODEL command to the `pipelineJson`
7205
7327
  *
7206
- * Note: `$` is used to indicate that this function mutates given `templateJson`
7328
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
7207
7329
  */
7208
- $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
7209
- if ($templateJson.templateType !== 'PROMPT_TEMPLATE') {
7210
- throw new ParseError("MODEL command can only be used in PROMPT_TEMPLATE block");
7330
+ $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
7331
+ if ($taskJson.taskType !== 'PROMPT_TASK') {
7332
+ throw new ParseError("MODEL command can only be used in PROMPT_TASK block");
7211
7333
  }
7212
- $templateJson.modelRequirements = $templateJson.modelRequirements || {};
7334
+ $taskJson.modelRequirements = $taskJson.modelRequirements || {};
7213
7335
  // TODO: [🚜] DRY
7214
- if ($templateJson.modelRequirements[command.key] !== undefined) {
7215
- if ($templateJson.modelRequirements[command.key] === command.value) {
7336
+ if ($taskJson.modelRequirements[command.key] !== undefined) {
7337
+ if ($taskJson.modelRequirements[command.key] === command.value) {
7216
7338
  console.warn("Multiple commands `MODEL ".concat({
7217
7339
  modelName: 'NAME',
7218
7340
  modelVariant: 'VARIANT',
7219
7341
  maxTokens: '???',
7220
- }[command.key], " ").concat(command.value, "` in the template \"").concat($templateJson.title || $templateJson.name, "\""));
7342
+ }[command.key], " ").concat(command.value, "` in the task \"").concat($taskJson.title || $taskJson.name, "\""));
7221
7343
  }
7222
7344
  else {
7223
- throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the template \"").concat($templateJson.title || $templateJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($templateJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7345
+ throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($taskJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7224
7346
  }
7225
7347
  }
7226
7348
  if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
7227
- console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the template \"").concat($templateJson.title || $templateJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the template:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7349
+ console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the task:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
7228
7350
  }
7229
- $templateJson.modelRequirements[command.key] = command.value;
7351
+ $taskJson.modelRequirements[command.key] = command.value;
7230
7352
  },
7231
7353
  /**
7232
7354
  * Converts the MODEL command back to string
@@ -7245,11 +7367,11 @@ var modelCommandParser = {
7245
7367
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7246
7368
  },
7247
7369
  /**
7248
- * Reads the MODEL command from the `TemplateJson`
7370
+ * Reads the MODEL command from the `TaskJson`
7249
7371
  *
7250
7372
  * Note: This is used in `pipelineJsonToString` utility
7251
7373
  */
7252
- takeFromTemplateJson: function ($templateJson) {
7374
+ takeFromTaskJson: function ($taskJson) {
7253
7375
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7254
7376
  },
7255
7377
  };
@@ -7276,11 +7398,11 @@ var parameterCommandParser = {
7276
7398
  * BOILERPLATE command can be used in:
7277
7399
  */
7278
7400
  isUsedInPipelineHead: true,
7279
- isUsedInPipelineTemplate: true,
7401
+ isUsedInPipelineTask: true,
7280
7402
  /**
7281
7403
  * Description of the PARAMETER command
7282
7404
  */
7283
- description: "Describes one parameter of the template",
7405
+ description: "Describes one parameter of the task",
7284
7406
  /**
7285
7407
  * Link to documentation
7286
7408
  */
@@ -7328,9 +7450,9 @@ var parameterCommandParser = {
7328
7450
  /**
7329
7451
  * Apply the PARAMETER command to the `pipelineJson`
7330
7452
  *
7331
- * Note: `$` is used to indicate that this function mutates given `templateJson`
7453
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
7332
7454
  */
7333
- $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
7455
+ $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
7334
7456
  // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
7335
7457
  },
7336
7458
  /**
@@ -7350,11 +7472,11 @@ var parameterCommandParser = {
7350
7472
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7351
7473
  },
7352
7474
  /**
7353
- * Reads the PARAMETER command from the `TemplateJson`
7475
+ * Reads the PARAMETER command from the `TaskJson`
7354
7476
  *
7355
7477
  * Note: This is used in `pipelineJsonToString` utility
7356
7478
  */
7357
- takeFromTemplateJson: function ($templateJson) {
7479
+ takeFromTaskJson: function ($taskJson) {
7358
7480
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7359
7481
  },
7360
7482
  };
@@ -7378,7 +7500,7 @@ var personaCommandParser = {
7378
7500
  * PERSONA command can be used in:
7379
7501
  */
7380
7502
  isUsedInPipelineHead: true,
7381
- isUsedInPipelineTemplate: true,
7503
+ isUsedInPipelineTask: true,
7382
7504
  /**
7383
7505
  * Description of the PERSONA command
7384
7506
  */
@@ -7417,9 +7539,9 @@ var personaCommandParser = {
7417
7539
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7418
7540
  */
7419
7541
  $applyToPipelineJson: function (command, $pipelineJson) {
7420
- $applyToTemplateJson(command, null, $pipelineJson);
7542
+ $applyToTaskJson(command, null, $pipelineJson);
7421
7543
  },
7422
- $applyToTemplateJson: $applyToTemplateJson,
7544
+ $applyToTaskJson: $applyToTaskJson,
7423
7545
  /**
7424
7546
  * Converts the PERSONA command back to string
7425
7547
  *
@@ -7437,26 +7559,26 @@ var personaCommandParser = {
7437
7559
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7438
7560
  },
7439
7561
  /**
7440
- * Reads the PERSONA command from the `TemplateJson`
7562
+ * Reads the PERSONA command from the `TaskJson`
7441
7563
  *
7442
7564
  * Note: This is used in `pipelineJsonToString` utility
7443
7565
  */
7444
- takeFromTemplateJson: function ($templateJson) {
7566
+ takeFromTaskJson: function ($taskJson) {
7445
7567
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7446
7568
  },
7447
7569
  };
7448
7570
  /**
7449
7571
  * Apply the PERSONA command to the `pipelineJson`
7450
7572
  *
7451
- * Note: `$` is used to indicate that this function mutates given `templateJson`
7573
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
7452
7574
  */
7453
- function $applyToTemplateJson(command, $templateJson, $pipelineJson) {
7575
+ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7454
7576
  var personaName = command.personaName, personaDescription = command.personaDescription;
7455
- if ($templateJson !== null) {
7456
- if ($templateJson.templateType !== 'PROMPT_TEMPLATE') {
7457
- throw new ParseError("PERSONA command can be used only in PROMPT_TEMPLATE block");
7577
+ if ($taskJson !== null) {
7578
+ if ($taskJson.taskType !== 'PROMPT_TASK') {
7579
+ throw new ParseError("PERSONA command can be used only in PROMPT_TASK block");
7458
7580
  }
7459
- $templateJson.personaName = personaName;
7581
+ $taskJson.personaName = personaName;
7460
7582
  }
7461
7583
  var persona = $pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
7462
7584
  if (persona === undefined) {
@@ -7510,7 +7632,7 @@ var postprocessCommandParser = {
7510
7632
  * BOILERPLATE command can be used in:
7511
7633
  */
7512
7634
  isUsedInPipelineHead: false,
7513
- isUsedInPipelineTemplate: true,
7635
+ isUsedInPipelineTask: true,
7514
7636
  /**
7515
7637
  * Description of the POSTPROCESS command
7516
7638
  */
@@ -7548,11 +7670,11 @@ var postprocessCommandParser = {
7548
7670
  /**
7549
7671
  * Apply the POSTPROCESS command to the `pipelineJson`
7550
7672
  *
7551
- * Note: `$` is used to indicate that this function mutates given `templateJson`
7673
+ * Note: `$` is used to indicate that this function mutates given `taskJson`
7552
7674
  */
7553
- $applyToTemplateJson: function (command, $templateJson) {
7554
- $templateJson.postprocessingFunctionNames = $templateJson.postprocessingFunctionNames || [];
7555
- $templateJson.postprocessingFunctionNames.push(command.functionName);
7675
+ $applyToTaskJson: function (command, $taskJson) {
7676
+ $taskJson.postprocessingFunctionNames = $taskJson.postprocessingFunctionNames || [];
7677
+ $taskJson.postprocessingFunctionNames.push(command.functionName);
7556
7678
  },
7557
7679
  /**
7558
7680
  * Converts the POSTPROCESS command back to string
@@ -7563,11 +7685,11 @@ var postprocessCommandParser = {
7563
7685
  return "---"; // <- TODO: [🛋] Implement
7564
7686
  },
7565
7687
  /**
7566
- * Reads the POSTPROCESS command from the `TemplateJson`
7688
+ * Reads the POSTPROCESS command from the `TaskJson`
7567
7689
  *
7568
7690
  * Note: This is used in `pipelineJsonToString` utility
7569
7691
  */
7570
- takeFromTemplateJson: function ($templateJson) {
7692
+ takeFromTaskJson: function ($taskJson) {
7571
7693
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7572
7694
  },
7573
7695
  };
@@ -7592,7 +7714,7 @@ var urlCommandParser = {
7592
7714
  * BOILERPLATE command can be used in:
7593
7715
  */
7594
7716
  isUsedInPipelineHead: true,
7595
- isUsedInPipelineTemplate: false,
7717
+ isUsedInPipelineTask: false,
7596
7718
  /**
7597
7719
  * Description of the URL command
7598
7720
  */
@@ -7636,7 +7758,7 @@ var urlCommandParser = {
7636
7758
  spaceTrim(
7637
7759
  `
7638
7760
  URL must not contain hash
7639
- Hash is used for identification of the template in the pipeline
7761
+ Hash is used for identification of the section of the pipeline
7640
7762
  `,
7641
7763
  ),
7642
7764
  );
@@ -7688,11 +7810,11 @@ var actionCommandParser = {
7688
7810
  * ACTION command can be used in:
7689
7811
  */
7690
7812
  isUsedInPipelineHead: true,
7691
- isUsedInPipelineTemplate: false,
7813
+ isUsedInPipelineTask: false,
7692
7814
  /**
7693
7815
  * Description of the ACTION command
7694
7816
  */
7695
- description: "Actions influences from the pipeline or template into external world. Like turning on a light, sending an email, etc.",
7817
+ description: "Actions influences from the pipeline or task into external world. Like turning on a light, sending an email, etc.",
7696
7818
  /**
7697
7819
  * Link to documentation
7698
7820
  */
@@ -7754,11 +7876,11 @@ var instrumentCommandParser = {
7754
7876
  * INSTRUMENT command can be used in:
7755
7877
  */
7756
7878
  isUsedInPipelineHead: true,
7757
- isUsedInPipelineTemplate: false,
7879
+ isUsedInPipelineTask: false,
7758
7880
  /**
7759
7881
  * Description of the INSTRUMENT command
7760
7882
  */
7761
- description: "Instrument command is used to specify the instrument to be used in the pipeline or template like search, calculate, etc.",
7883
+ description: "Instrument command is used to specify the instrument to be used in the pipeline or task like search, calculate, etc.",
7762
7884
  /**
7763
7885
  * Link to documentation
7764
7886
  */
@@ -7811,7 +7933,7 @@ var instrumentCommandParser = {
7811
7933
  * @private internal index of `parseCommand`
7812
7934
  */
7813
7935
  var COMMANDS = [
7814
- templateCommandParser,
7936
+ sectionCommandParser,
7815
7937
  expectCommandParser,
7816
7938
  formatCommandParser,
7817
7939
  jokerCommandParser,
@@ -7829,6 +7951,9 @@ var COMMANDS = [
7829
7951
  boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
7830
7952
  // <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
7831
7953
  ];
7954
+ /**
7955
+ * Note: [💞] Ignore a discrepancy between file name and entity name
7956
+ */
7832
7957
 
7833
7958
  /**
7834
7959
  * Gets the parser for the command
@@ -7889,7 +8014,6 @@ function parseCommand(raw, usagePlace) {
7889
8014
  normalized = normalized.split('(').join('');
7890
8015
  normalized = normalized.split(')').join('');
7891
8016
  normalized = normalizeTo_SCREAMING_CASE(normalized);
7892
- normalized = normalized.split('DIALOGUE').join('DIALOG');
7893
8017
  var items = raw
7894
8018
  .trim()
7895
8019
  // Note: [🐡]
@@ -7970,12 +8094,12 @@ function parseCommandVariant(input) {
7970
8094
  var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
7971
8095
  var _loop_1 = function (commandParser) {
7972
8096
  // <- Note: [🦦] Its strange that this type assertion is needed
7973
- var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
8097
+ var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTask = commandParser.isUsedInPipelineTask, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
7974
8098
  if (just(false)) ;
7975
8099
  else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
7976
8100
  return "continue";
7977
8101
  }
7978
- else if (usagePlace === 'PIPELINE_TEMPLATE' && !isUsedInPipelineTemplate) {
8102
+ else if (usagePlace === 'PIPELINE_TASK' && !isUsedInPipelineTask) {
7979
8103
  return "continue";
7980
8104
  }
7981
8105
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
@@ -8077,7 +8201,7 @@ function extractAllListItemsFromMarkdown(markdown) {
8077
8201
  function extractOneBlockFromMarkdown(markdown) {
8078
8202
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
8079
8203
  if (codeBlocks.length !== 1) {
8080
- throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in template, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
8204
+ throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
8081
8205
  }
8082
8206
  return codeBlocks[0];
8083
8207
  }
@@ -8292,7 +8416,7 @@ function pipelineStringToJsonSync(pipelineString) {
8292
8416
  description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
8293
8417
  formfactorName: 'GENERIC',
8294
8418
  parameters: [],
8295
- templates: [],
8419
+ tasks: [],
8296
8420
  knowledgeSources: [],
8297
8421
  knowledgePieces: [],
8298
8422
  personas: [],
@@ -8384,7 +8508,7 @@ function pipelineStringToJsonSync(pipelineString) {
8384
8508
  var command = parseCommand(listItem, 'PIPELINE_HEAD');
8385
8509
  var commandParser = getParserForCommand(command);
8386
8510
  if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
8387
- throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the pipeline template\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8511
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8388
8512
  }
8389
8513
  try {
8390
8514
  commandParser.$applyToPipelineJson(command, $pipelineJson);
@@ -8416,7 +8540,7 @@ function pipelineStringToJsonSync(pipelineString) {
8416
8540
  }
8417
8541
  var _loop_2 = function (section) {
8418
8542
  var e_5, _l, e_6, _m;
8419
- // TODO: Parse template description (the content out of the codeblock and lists)
8543
+ // TODO: Parse section's description (the content out of the codeblock and lists)
8420
8544
  var listItems_2 = extractAllListItemsFromMarkdown(section.content);
8421
8545
  var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
8422
8546
  // TODO: [🎾][1] DRY description
@@ -8430,10 +8554,10 @@ function pipelineStringToJsonSync(pipelineString) {
8430
8554
  if (description_1 === '') {
8431
8555
  description_1 = undefined;
8432
8556
  }
8433
- var $templateJson = {
8434
- isTemplateTypeSet: false,
8435
- isTemplate: true,
8436
- templateType: undefined /* <- Note: [🍙] Putting here placeholder to keep `templateType` on top at final JSON */,
8557
+ var $taskJson = {
8558
+ isSectionTypeSet: false,
8559
+ isTask: true,
8560
+ taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
8437
8561
  name: titleToName(section.title),
8438
8562
  title: section.title,
8439
8563
  description: description_1,
@@ -8445,35 +8569,35 @@ function pipelineStringToJsonSync(pipelineString) {
8445
8569
  if (resultingParameterNameMatch &&
8446
8570
  resultingParameterNameMatch.groups !== undefined &&
8447
8571
  resultingParameterNameMatch.groups.resultingParamName !== undefined) {
8448
- $templateJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
8572
+ $taskJson.resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
8449
8573
  }
8450
- // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTemplateCommands`
8574
+ // TODO: [🥥] Maybe move this logic to `$parseAndApplyPipelineTaskCommands`
8451
8575
  var commands = listItems_2.map(function (listItem) { return ({
8452
8576
  listItem: listItem,
8453
- command: parseCommand(listItem, 'PIPELINE_TEMPLATE'),
8577
+ command: parseCommand(listItem, 'PIPELINE_TASK'),
8454
8578
  }); });
8455
- // Note: If block type is not set, set it to 'PROMPT_TEMPLATE'
8579
+ // Note: If block type is not set, set it to 'PROMPT_TASK'
8456
8580
  if (commands.some(function (_a) {
8457
8581
  var command = _a.command;
8458
- return command.type === 'TEMPLATE';
8582
+ return command.type === 'SECTION';
8459
8583
  }) === false) {
8460
- templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
8584
+ sectionCommandParser.$applyToTaskJson({ type: 'SECTION', taskType: 'PROMPT_TASK' }, $taskJson, $pipelineJson);
8461
8585
  }
8462
8586
  var _loop_4 = function (listItem, command) {
8463
8587
  var commandParser = getParserForCommand(command);
8464
- if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
8465
- throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8588
+ if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
8589
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8466
8590
  }
8467
8591
  try {
8468
- commandParser.$applyToTemplateJson(
8592
+ commandParser.$applyToTaskJson(
8469
8593
  // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
8470
- command, $templateJson, $pipelineJson);
8594
+ command, $taskJson, $pipelineJson);
8471
8595
  }
8472
8596
  catch (error) {
8473
8597
  if (!(error instanceof ParseError)) {
8474
8598
  throw error;
8475
8599
  }
8476
- throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " failed to apply to the template\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the template:\n ").concat(block(JSON.stringify($templateJson, null, 4)), "\n <- Maybe wrong order of commands?\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8600
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
8477
8601
  }
8478
8602
  if (command.type === 'PARAMETER') {
8479
8603
  defineParam(command);
@@ -8494,22 +8618,21 @@ function pipelineStringToJsonSync(pipelineString) {
8494
8618
  }
8495
8619
  finally { if (e_5) throw e_5.error; }
8496
8620
  }
8497
- // TODO: [🍧] Should be done in TEMPLATE command
8498
- if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
8621
+ // TODO: [🍧] Should be done in SECTION command
8622
+ if ($taskJson.taskType === 'SCRIPT_TASK') {
8499
8623
  if (!language) {
8500
- throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the SCRIPT TEMPLATE\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
8624
+ throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
8501
8625
  }
8502
8626
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
8503
8627
  throw new ParseError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
8504
8628
  }
8505
- $templateJson.contentLanguage =
8506
- language;
8629
+ $taskJson.contentLanguage = language;
8507
8630
  }
8508
- $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
8631
+ $taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
8509
8632
  try {
8510
- for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
8633
+ for (var _q = (e_6 = void 0, __values($taskJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
8511
8634
  var parameterName = _r.value;
8512
- // TODO: [🧠] This definition should be made first in the template
8635
+ // TODO: [🧠] This definition should be made first in the task
8513
8636
  defineParam({
8514
8637
  parameterName: parameterName,
8515
8638
  parameterDescription: null,
@@ -8528,13 +8651,13 @@ function pipelineStringToJsonSync(pipelineString) {
8528
8651
  }
8529
8652
  /*
8530
8653
  // TODO: [🍧] This should be checked in `MODEL` command + better error message
8531
- if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
8654
+ if ($taskJson.taskType !== 'PROMPT_TASK' && $taskJson.modelRequirements !== undefined) {
8532
8655
  throw new UnexpectedError(
8533
8656
  spaceTrim(
8534
8657
  (block) => `
8535
8658
  Model requirements are defined for the block type ${
8536
- $templateJson.templateType
8537
- } which is not a PROMPT TEMPLATE
8659
+ $taskJson.taskType
8660
+ } which is not a \`PROMPT\` task
8538
8661
 
8539
8662
  This should be avoided by the \`modelCommandParser\`
8540
8663
 
@@ -8544,16 +8667,16 @@ function pipelineStringToJsonSync(pipelineString) {
8544
8667
  );
8545
8668
  }
8546
8669
  */
8547
- if ($templateJson.isTemplate) {
8548
- delete $templateJson.isTemplateTypeSet;
8549
- delete $templateJson.isTemplate;
8550
- // TODO: [🍙] Maybe do reorder of `$templateJson` here
8551
- $pipelineJson.templates.push($templateJson);
8670
+ if ($taskJson.isTask) {
8671
+ delete $taskJson.isSectionTypeSet;
8672
+ delete $taskJson.isTask;
8673
+ // TODO: [🍙] Maybe do reorder of `$taskJson` here
8674
+ $pipelineJson.tasks.push($taskJson);
8552
8675
  }
8553
8676
  };
8554
8677
  try {
8555
8678
  // =============================================================
8556
- // Note: 4️⃣ Process each template of the pipeline
8679
+ // Note: 4️⃣ Process each section of the pipeline
8557
8680
  for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
8558
8681
  var section = pipelineSections_1_1.value;
8559
8682
  _loop_2(section);
@@ -8570,7 +8693,7 @@ function pipelineStringToJsonSync(pipelineString) {
8570
8693
  // Note: 5️⃣ Mark parameters as INPUT if not explicitly set
8571
8694
  if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
8572
8695
  var _loop_3 = function (parameter) {
8573
- var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
8696
+ var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
8574
8697
  if (!isThisParameterResulting) {
8575
8698
  parameter.isInput = true;
8576
8699
  }
@@ -8610,13 +8733,13 @@ function pipelineStringToJsonSync(pipelineString) {
8610
8733
  }
8611
8734
  // =============================================================
8612
8735
  // Note: 7️⃣ Cleanup of undefined values
8613
- $pipelineJson.templates.forEach(function (templates) {
8736
+ $pipelineJson.tasks.forEach(function (tasks) {
8614
8737
  var e_7, _a;
8615
8738
  try {
8616
- for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
8739
+ for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
8617
8740
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
8618
8741
  if (value === undefined) {
8619
- delete templates[key];
8742
+ delete tasks[key];
8620
8743
  }
8621
8744
  }
8622
8745
  }
@@ -8656,7 +8779,7 @@ function pipelineStringToJsonSync(pipelineString) {
8656
8779
  * TODO: Use spaceTrim more effectively
8657
8780
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
8658
8781
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
8659
- * TODO: [♈] Probbably move expectations from templates to parameters
8782
+ * TODO: [♈] Probbably move expectations from tasks to parameters
8660
8783
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
8661
8784
  * TODO: [🍙] Make some standard order of json properties
8662
8785
  */
@@ -8741,8 +8864,8 @@ function addAutoGeneratedSection(content, options) {
8741
8864
  * @public exported from `@promptbook/utils`
8742
8865
  */
8743
8866
  function renderPromptbookMermaid(pipelineJson, options) {
8744
- var _a = (options || {}).linkTemplate, linkTemplate = _a === void 0 ? function () { return null; } : _a;
8745
- var parameterNameToTemplateName = function (parameterName) {
8867
+ var _a = (options || {}).linkTask, linkTask = _a === void 0 ? function () { return null; } : _a;
8868
+ var parameterNameToTaskName = function (parameterName) {
8746
8869
  var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
8747
8870
  if (!parameter) {
8748
8871
  throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
@@ -8750,19 +8873,19 @@ function renderPromptbookMermaid(pipelineJson, options) {
8750
8873
  if (parameter.isInput) {
8751
8874
  return 'input';
8752
8875
  }
8753
- var template = pipelineJson.templates.find(function (template) { return template.resultingParameterName === parameterName; });
8754
- if (!template) {
8755
- throw new Error("Could not find template for {".concat(parameterName, "}"));
8876
+ var task = pipelineJson.tasks.find(function (task) { return task.resultingParameterName === parameterName; });
8877
+ if (!task) {
8878
+ throw new Error("Could not find task for {".concat(parameterName, "}"));
8756
8879
  }
8757
- return normalizeTo_camelCase('template-' + titleToName(template.title));
8880
+ return normalizeTo_camelCase('task-' + titleToName(task.title));
8758
8881
  };
8759
- var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.templates
8882
+ var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
8760
8883
  .flatMap(function (_a) {
8761
8884
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
8762
8885
  return __spreadArray([
8763
- "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
8886
+ "".concat(parameterNameToTaskName(resultingParameterName), "(\"").concat(title, "\")")
8764
8887
  ], __read(dependentParameterNames.map(function (dependentParameterName) {
8765
- return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
8888
+ return "".concat(parameterNameToTaskName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTaskName(resultingParameterName));
8766
8889
  })), false);
8767
8890
  })
8768
8891
  .join('\n')), "\n\n ").concat(block(pipelineJson.parameters
@@ -8772,17 +8895,17 @@ function renderPromptbookMermaid(pipelineJson, options) {
8772
8895
  })
8773
8896
  .map(function (_a) {
8774
8897
  var name = _a.name;
8775
- return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
8898
+ return "".concat(parameterNameToTaskName(name), "--\"{").concat(name, "}\"-->output");
8776
8899
  })
8777
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.templates
8778
- .map(function (template) {
8779
- var link = linkTemplate(template);
8900
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.tasks
8901
+ .map(function (task) {
8902
+ var link = linkTask(task);
8780
8903
  if (link === null) {
8781
8904
  return '';
8782
8905
  }
8783
8906
  var href = link.href, title = link.title;
8784
- var templateName = parameterNameToTemplateName(template.resultingParameterName);
8785
- return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
8907
+ var taskName = parameterNameToTaskName(task.resultingParameterName);
8908
+ return "click ".concat(taskName, " href \"").concat(href, "\" \"").concat(title, "\";");
8786
8909
  })
8787
8910
  .filter(function (line) { return line !== ''; })
8788
8911
  .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
@@ -8813,8 +8936,8 @@ function prettifyPipelineString(pipelineString, options) {
8813
8936
  case 1:
8814
8937
  pipelineJson = _a.sent();
8815
8938
  promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
8816
- linkTemplate: function (template) {
8817
- return { href: "#".concat(template.name), title: template.title };
8939
+ linkTask: function (task) {
8940
+ return { href: "#".concat(task.name), title: task.title };
8818
8941
  },
8819
8942
  });
8820
8943
  promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
@@ -8940,228 +9063,551 @@ function embeddingVectorToString(embeddingVector) {
8940
9063
  }
8941
9064
 
8942
9065
  /**
8943
- * Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
8944
- *
8945
- * Note: This is an estimate based of theese sources:
8946
- * - https://jecas.cz/doba-cteni
8947
- * - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
9066
+ * Format either small or big number
8948
9067
  *
8949
- * @public exported from `@promptbook/core`
9068
+ * @private within the repository
8950
9069
  */
8951
- function usageToWorktime(usage) {
8952
- var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
8953
- usage.output.wordsCount.value / (40 /* words per minute */ * 60);
8954
- var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
8955
- var uncertainNumber = { value: value };
8956
- if (isUncertain === true) {
8957
- uncertainNumber.isUncertain = true;
9070
+ function formatNumber(value) {
9071
+ if (value === 0) {
9072
+ return '0';
8958
9073
  }
8959
- return uncertainNumber;
9074
+ for (var exponent = 0; exponent < 15; exponent++) {
9075
+ var factor = Math.pow(10, exponent);
9076
+ var valueRounded = Math.round(value * factor) / factor;
9077
+ if (Math.abs(value - valueRounded) / value <
9078
+ 0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
9079
+ return valueRounded.toFixed(exponent);
9080
+ }
9081
+ }
9082
+ return value.toString();
8960
9083
  }
8961
9084
 
8962
9085
  /**
8963
- * Function `usageToHuman` will take usage and convert it to human readable report
9086
+ * Create a markdown table from a 2D array of strings
8964
9087
  *
8965
- * @public exported from `@promptbook/core`
9088
+ * @public exported from `@promptbook/markdown-utils`
8966
9089
  */
8967
- function usageToHuman(usage) {
8968
- var reportItems = [];
8969
- var uncertainNumberToHuman = function (_a) {
8970
- var value = _a.value, isUncertain = _a.isUncertain;
8971
- return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
8972
- };
8973
- if (usage.price.value > 0.01
8974
- // <- TODO: [🍓][🧞‍♂️][👩🏽‍🤝‍🧑🏻] Configure negligible value - default value to config + value to `UsageToHumanSettings`
8975
- ) {
8976
- reportItems.push("Cost ".concat(uncertainNumberToHuman(usage.price), " USD"));
8977
- }
8978
- else {
8979
- reportItems.push("Negligible cost");
8980
- }
8981
- var worktime = usageToWorktime(usage);
8982
- if (worktime.value >
8983
- 1 / 60
8984
- // <- TODO: [🍓][🧞‍♂️][👩🏽‍🤝‍🧑🏻]
8985
- ) {
8986
- reportItems.push("Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time"));
8987
- // TODO: [🍓][🧞‍♂️] Show minutes, seconds, days NOT 0.1 hours
8988
- }
8989
- if (usage.output.charactersCount.value > 0) {
8990
- reportItems.push("Written ".concat(uncertainNumberToHuman(usage.output.charactersCount), " characters"));
8991
- }
8992
- if (reportItems.length === 0) {
8993
- // Note: For negligible usage, we report at least something
8994
- reportItems.push('Negligible');
8995
- }
8996
- return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
9090
+ function createMarkdownTable(table) {
9091
+ var columnWidths = table.reduce(function (widths, row) {
9092
+ row.forEach(function (subformat, columnIndex) {
9093
+ var cellLength = subformat.length;
9094
+ if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
9095
+ widths[columnIndex] = cellLength;
9096
+ }
9097
+ });
9098
+ return widths;
9099
+ }, []);
9100
+ var header = "| ".concat(table[0]
9101
+ .map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
9102
+ .join(' | '), " |");
9103
+ var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
9104
+ var rows = table.slice(1).map(function (row) {
9105
+ var paddedRow = row.map(function (subformat, columnIndex) {
9106
+ return subformat.padEnd(columnWidths[columnIndex]);
9107
+ });
9108
+ return "| ".concat(paddedRow.join(' | '), " |");
9109
+ });
9110
+ return __spreadArray([header, separator], __read(rows), false).join('\n');
8997
9111
  }
8998
9112
  /**
8999
- * TODO: [🍓][🧞‍♂️] Use "$1" not "1 USD"
9000
- * TODO: [🍓][🧞‍♂️] Use markdown formatting like "Cost approximately **$1**"
9001
- * TODO: [🍓][🧞‍♂️] Report in minutes, seconds, days NOT 0.1 hours
9002
- * TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
9003
- * TODO: [🧠] Maybe use "~" instead of "approximately"
9004
- * TODO: [🏛] Maybe make some markdown builder
9113
+ * TODO: [🏛] This can be part of markdown builder
9005
9114
  */
9006
9115
 
9007
9116
  /**
9008
- * Boilerplate is form of app that @@@
9117
+ * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
9009
9118
  *
9010
- * @public exported from `@promptbook/core`
9119
+ * @public exported from `@promptbook/markdown-utils`
9120
+ */
9121
+ function createMarkdownChart(options) {
9122
+ var e_1, _a;
9123
+ var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
9124
+ var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
9125
+ var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
9126
+ var scale = width / (to - from);
9127
+ var table = [[nameHeader, valueHeader]];
9128
+ try {
9129
+ for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
9130
+ var item = items_1_1.value;
9131
+ var before = Math.round((item.from - from) * scale);
9132
+ var during = Math.round((item.to - item.from) * scale);
9133
+ var after = width - before - during;
9134
+ table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
9135
+ }
9136
+ }
9137
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9138
+ finally {
9139
+ try {
9140
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
9141
+ }
9142
+ finally { if (e_1) throw e_1.error; }
9143
+ }
9144
+ var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
9145
+ return createMarkdownTable(table) + '\n\n' + legend;
9146
+ }
9147
+ /**
9148
+ * TODO: Maybe use Mermain Gant Diagrams
9149
+ * @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
9011
9150
  */
9012
- var BoilerplateFormfactorDefinition = {
9013
- name: 'BOILERPLATE',
9014
- description: "@@@",
9015
- documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
9016
- pipelineInterface: {
9017
- inputParameterNames: [],
9018
- outputParameterNames: [],
9019
- },
9020
- };
9021
9151
 
9022
9152
  /**
9023
- * @@@
9153
+ * Function escapeMarkdownBlock will escape markdown block if needed
9154
+ * It is useful when you want have block in block
9024
9155
  *
9025
- * Note: `$` is used to indicate that this interacts with the global scope
9026
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
9027
- * @public exported from `@promptbook/core`
9156
+ * @public exported from `@promptbook/markdown-utils`
9028
9157
  */
9029
- var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
9158
+ function escapeMarkdownBlock(value) {
9159
+ return value.replace(/```/g, '\\`\\`\\`');
9160
+ }
9030
9161
  /**
9031
- * TODO: [®] DRY Register logic
9162
+ * TODO: [🏛] This can be part of markdown builder
9032
9163
  */
9033
9164
 
9034
9165
  /**
9035
- * @@@
9166
+ * Default options for generating an execution report string
9036
9167
  *
9037
- * Note: `$` is used to indicate that this interacts with the global scope
9038
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
9039
9168
  * @public exported from `@promptbook/core`
9040
9169
  */
9041
- var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
9042
- /**
9043
- * TODO: [®] DRY Register logic
9044
- */
9170
+ var ExecutionReportStringOptionsDefaults = {
9171
+ taxRate: 0,
9172
+ chartsWidth: 36,
9173
+ };
9045
9174
 
9046
9175
  /**
9047
- * Creates a message with all registered LLM tools
9048
- *
9049
- * Note: This function is used to create a (error) message when there is no constructor for some LLM provider
9176
+ * Count the duration of working time
9050
9177
  *
9051
- * @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
9178
+ * @private within the repository
9052
9179
  */
9053
- function $registeredLlmToolsMessage() {
9054
- var e_1, _a, e_2, _b;
9055
- /**
9056
- * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
9057
- */
9058
- var all = [];
9059
- var _loop_1 = function (packageName, className) {
9060
- if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9061
- return "continue";
9180
+ function countWorkingDuration(items) {
9181
+ var e_1, _a;
9182
+ var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
9183
+ steps.sort(function (a, b) { return a - b; });
9184
+ var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
9185
+ var duration = 0;
9186
+ var _loop_1 = function (interval) {
9187
+ var _b = __read(interval, 2), from = _b[0], to = _b[1];
9188
+ if (items.some(function (item) { return item.from < to && item.to > from; })) {
9189
+ duration += to - from;
9062
9190
  }
9063
- all.push({ packageName: packageName, className: className });
9064
9191
  };
9065
9192
  try {
9066
- for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
9067
- var _e = _d.value, packageName = _e.packageName, className = _e.className;
9068
- _loop_1(packageName, className);
9193
+ for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
9194
+ var interval = intervals_1_1.value;
9195
+ _loop_1(interval);
9069
9196
  }
9070
9197
  }
9071
9198
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
9072
9199
  finally {
9073
9200
  try {
9074
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
9201
+ if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
9075
9202
  }
9076
9203
  finally { if (e_1) throw e_1.error; }
9077
9204
  }
9078
- var _loop_2 = function (packageName, className) {
9079
- if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9080
- return "continue";
9081
- }
9082
- all.push({ packageName: packageName, className: className });
9083
- };
9084
- try {
9085
- for (var _f = __values($llmToolsRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
9086
- var _h = _g.value, packageName = _h.packageName, className = _h.className;
9087
- _loop_2(packageName, className);
9088
- }
9089
- }
9090
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
9091
- finally {
9092
- try {
9093
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
9094
- }
9095
- finally { if (e_2) throw e_2.error; }
9205
+ return duration;
9206
+ }
9207
+
9208
+ /**
9209
+ * Converts execution report from JSON to string format
9210
+ *
9211
+ * @public exported from `@promptbook/core`
9212
+ */
9213
+ function executionReportJsonToString(executionReportJson, options) {
9214
+ var e_1, _a;
9215
+ var _b, _c, _d, _e, _f, _g;
9216
+ var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
9217
+ var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
9218
+ var headerList = [];
9219
+ if (executionReportJson.pipelineUrl) {
9220
+ headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
9096
9221
  }
9097
- var metadata = all.map(function (metadata) {
9098
- var isMetadataAviailable = $llmToolsMetadataRegister
9099
- .list()
9100
- .find(function (_a) {
9101
- var packageName = _a.packageName, className = _a.className;
9102
- return metadata.packageName === packageName && metadata.className === className;
9222
+ headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
9223
+ (!executionReportJson.promptbookRequestedVersion
9224
+ ? ''
9225
+ : " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
9226
+ if (executionReportJson.promptExecutions.length !== 0) {
9227
+ // TODO: What if startedAt OR/AND completedAt is not defined?
9228
+ var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
9229
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
9230
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
9231
+ var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
9232
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
9233
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
9234
+ var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
9235
+ var _a, _b, _c, _d;
9236
+ return ({
9237
+ title: promptExecution.prompt.title,
9238
+ from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
9239
+ to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
9240
+ });
9103
9241
  });
9104
- var isInstalled = $llmToolsRegister
9105
- .list()
9106
- .find(function (_a) {
9107
- var packageName = _a.packageName, className = _a.className;
9108
- return metadata.packageName === packageName && metadata.className === className;
9242
+ var costItems = executionReportJson.promptExecutions
9243
+ .filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
9244
+ .map(function (promptExecution) {
9245
+ var _a, _b;
9246
+ return ({
9247
+ title: promptExecution.prompt.title,
9248
+ from: 0,
9249
+ to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* <- TODO: look at uncertain numbers */ *
9250
+ (1 + taxRate),
9251
+ });
9109
9252
  });
9110
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9111
- });
9112
- if (metadata.length === 0) {
9113
- return "No LLM providers are available.";
9253
+ var duration = moment.duration(completedAt.diff(startedAt));
9254
+ var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
9255
+ var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
9256
+ var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) {
9257
+ return cost + (promptExecution.result.usage.price.value /* <- Look at uncertain number */ || 0);
9258
+ }, 0);
9259
+ headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
9260
+ headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
9261
+ headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
9262
+ headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
9263
+ headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
9264
+ (executionsWithKnownCost.length === executionReportJson.promptExecutions.length
9265
+ ? ''
9266
+ : " *(Some cost is unknown)*") +
9267
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
9268
+ executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
9269
+ executionReportString +=
9270
+ '\n\n' +
9271
+ '## 🗃 Index' +
9272
+ '\n\n' +
9273
+ executionReportJson.promptExecutions
9274
+ .map(function (promptExecution) {
9275
+ // TODO: Make some better system to convert hedings to links
9276
+ var hash = normalizeToKebabCase(promptExecution.prompt.title);
9277
+ if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
9278
+ hash = '-' + hash;
9279
+ }
9280
+ // TODO: Make working hash link for the task in md + pdf
9281
+ return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
9282
+ })
9283
+ .join('\n');
9284
+ executionReportString +=
9285
+ '\n\n' +
9286
+ '## ⌚ Time chart' +
9287
+ '\n\n' +
9288
+ createMarkdownChart({
9289
+ nameHeader: 'Task',
9290
+ valueHeader: 'Timeline',
9291
+ items: timingItems,
9292
+ width: chartsWidth,
9293
+ unitName: 'seconds',
9294
+ });
9295
+ executionReportString +=
9296
+ '\n\n' +
9297
+ '## 💸 Cost chart' +
9298
+ '\n\n' +
9299
+ createMarkdownChart({
9300
+ nameHeader: 'Task',
9301
+ valueHeader: 'Cost',
9302
+ items: costItems,
9303
+ width: chartsWidth,
9304
+ unitName: 'USD',
9305
+ });
9114
9306
  }
9115
- return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9116
- .map(function (_a, i) {
9117
- var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
9118
- var more;
9119
- if (just(false)) {
9120
- more = '';
9307
+ else {
9308
+ headerList.push("TOTAL COST $0 *(Nothing executed)*");
9309
+ }
9310
+ var _loop_1 = function (promptExecution) {
9311
+ executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
9312
+ var taskList = [];
9313
+ // TODO: What if startedAt OR/AND completedAt is not defined?
9314
+ var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
9315
+ var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
9316
+ var duration = moment.duration(completedAt.diff(startedAt));
9317
+ // Not need here:
9318
+ // > taskList.push(`STARTED AT ${moment(startedAt).calendar()}`);
9319
+ taskList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
9320
+ if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
9321
+ taskList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
9322
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
9121
9323
  }
9122
- else if (!isMetadataAviailable && !isInstalled) {
9123
- // TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
9124
- more = "(not installed and no metadata, looks like a unexpected behavior)";
9324
+ else {
9325
+ taskList.push("COST UNKNOWN");
9125
9326
  }
9126
- else if (isMetadataAviailable && !isInstalled) {
9127
- // TODO: [�][�]
9128
- more = "(not installed)";
9327
+ executionReportString += '\n\n' + taskList.map(function (header) { return "- ".concat(header); }).join('\n');
9328
+ /*
9329
+ - MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
9330
+ - MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
9331
+ promptExecution.prompt.modelRequirements.modelName
9332
+
9333
+ */
9334
+ if (just(true)) {
9335
+ executionReportString +=
9336
+ '\n\n\n\n' +
9337
+ spaceTrim$1(function (block) {
9338
+ var _a;
9339
+ return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
9340
+ });
9129
9341
  }
9130
- else if (!isMetadataAviailable && isInstalled) {
9131
- more = "(no metadata, looks like a unexpected behavior)";
9342
+ if (promptExecution.result && promptExecution.result.content) {
9343
+ executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
9344
+ if (promptExecution.result === undefined) {
9345
+ executionReportString += '*No result*';
9346
+ }
9347
+ else if (typeof promptExecution.result.content === 'string') {
9348
+ executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
9349
+ }
9350
+ else {
9351
+ executionReportString += embeddingVectorToString(promptExecution.result.content);
9352
+ }
9132
9353
  }
9133
- else if (isMetadataAviailable && isInstalled) {
9134
- more = "(installed)";
9354
+ if (promptExecution.error && promptExecution.error.message) {
9355
+ executionReportString +=
9356
+ '\n\n\n\n' +
9357
+ spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
9135
9358
  }
9136
- else {
9137
- more = "(unknown state, looks like a unexpected behavior)";
9359
+ };
9360
+ try {
9361
+ for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
9362
+ var promptExecution = _k.value;
9363
+ _loop_1(promptExecution);
9138
9364
  }
9139
- return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` ").concat(more);
9140
- })
9141
- .join('\n')), "\n "); });
9365
+ }
9366
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9367
+ finally {
9368
+ try {
9369
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
9370
+ }
9371
+ finally { if (e_1) throw e_1.error; }
9372
+ }
9373
+ executionReportString = prettifyMarkdown(executionReportString);
9374
+ return executionReportString;
9142
9375
  }
9143
9376
  /**
9144
- * TODO: [®] DRY Register logic
9377
+ * TODO: Add mermaid chart for every report
9378
+ * TODO: [🧠] Allow to filter out some parts of the report by options
9379
+ * TODO: [🧠] Should be in generated file GENERATOR_WARNING
9145
9380
  */
9146
9381
 
9147
9382
  /**
9148
- * @@@
9383
+ * Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
9149
9384
  *
9150
- * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9385
+ * Note: This is an estimate based of theese sources:
9386
+ * - https://jecas.cz/doba-cteni
9387
+ * - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
9151
9388
  *
9152
- * @returns @@@
9153
9389
  * @public exported from `@promptbook/core`
9154
9390
  */
9155
- function createLlmToolsFromConfiguration(configuration, options) {
9156
- if (options === void 0) { options = {}; }
9157
- var _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a, userId = options.userId;
9158
- var llmTools = configuration.map(function (llmConfiguration) {
9159
- var registeredItem = $llmToolsRegister
9160
- .list()
9161
- .find(function (_a) {
9162
- var packageName = _a.packageName, className = _a.className;
9163
- return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
9164
- });
9391
+ function usageToWorktime(usage) {
9392
+ var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
9393
+ usage.output.wordsCount.value / (40 /* words per minute */ * 60);
9394
+ var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
9395
+ var uncertainNumber = { value: value };
9396
+ if (isUncertain === true) {
9397
+ uncertainNumber.isUncertain = true;
9398
+ }
9399
+ return uncertainNumber;
9400
+ }
9401
+
9402
+ /**
9403
+ * Function `usageToHuman` will take usage and convert it to human readable report
9404
+ *
9405
+ * @public exported from `@promptbook/core`
9406
+ */
9407
+ function usageToHuman(usage) {
9408
+ var reportItems = [];
9409
+ var uncertainNumberToHuman = function (_a) {
9410
+ var value = _a.value, isUncertain = _a.isUncertain;
9411
+ return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
9412
+ };
9413
+ if (usage.price.value > 0.01
9414
+ // <- TODO: [🍓][🧞‍♂️][👩🏽‍🤝‍🧑🏻] Configure negligible value - default value to config + value to `UsageToHumanSettings`
9415
+ ) {
9416
+ reportItems.push("Cost ".concat(uncertainNumberToHuman(usage.price), " USD"));
9417
+ }
9418
+ else {
9419
+ reportItems.push("Negligible cost");
9420
+ }
9421
+ var worktime = usageToWorktime(usage);
9422
+ if (worktime.value >
9423
+ 1 / 60
9424
+ // <- TODO: [🍓][🧞‍♂️][👩🏽‍🤝‍🧑🏻]
9425
+ ) {
9426
+ reportItems.push("Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time"));
9427
+ // TODO: [🍓][🧞‍♂️] Show minutes, seconds, days NOT 0.1 hours
9428
+ }
9429
+ if (usage.output.charactersCount.value > 0) {
9430
+ reportItems.push("Written ".concat(uncertainNumberToHuman(usage.output.charactersCount), " characters"));
9431
+ }
9432
+ if (reportItems.length === 0) {
9433
+ // Note: For negligible usage, we report at least something
9434
+ reportItems.push('Negligible');
9435
+ }
9436
+ return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
9437
+ }
9438
+ /**
9439
+ * TODO: [🍓][🧞‍♂️] Use "$1" not "1 USD"
9440
+ * TODO: [🍓][🧞‍♂️] Use markdown formatting like "Cost approximately **$1**"
9441
+ * TODO: [🍓][🧞‍♂️] Report in minutes, seconds, days NOT 0.1 hours
9442
+ * TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
9443
+ * TODO: [🧠] Maybe use "~" instead of "approximately"
9444
+ * TODO: [🏛] Maybe make some markdown builder
9445
+ */
9446
+
9447
+ /**
9448
+ * Boilerplate is form of app that @@@
9449
+ *
9450
+ * @public exported from `@promptbook/core`
9451
+ */
9452
+ var BoilerplateFormfactorDefinition = {
9453
+ name: 'BOILERPLATE',
9454
+ description: "@@@",
9455
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/@@",
9456
+ // <- TODO: https://github.com/webgptorg/promptbook/discussions/new?category=concepts
9457
+ // "🔠 Boilerplate Formfactor"
9458
+ pipelineInterface: {
9459
+ inputParameters: [
9460
+ /* @@@ */
9461
+ ],
9462
+ outputParameters: [
9463
+ /* @@@ */
9464
+ ],
9465
+ },
9466
+ };
9467
+
9468
+ /**
9469
+ * @@@
9470
+ *
9471
+ * Note: `$` is used to indicate that this interacts with the global scope
9472
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
9473
+ * @public exported from `@promptbook/core`
9474
+ */
9475
+ var $llmToolsMetadataRegister = new $Register('llm_tools_metadata');
9476
+ /**
9477
+ * TODO: [®] DRY Register logic
9478
+ */
9479
+
9480
+ /**
9481
+ * @@@
9482
+ *
9483
+ * Note: `$` is used to indicate that this interacts with the global scope
9484
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
9485
+ * @public exported from `@promptbook/core`
9486
+ */
9487
+ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
9488
+ /**
9489
+ * TODO: [®] DRY Register logic
9490
+ */
9491
+
9492
+ /**
9493
+ * Creates a message with all registered LLM tools
9494
+ *
9495
+ * Note: This function is used to create a (error) message when there is no constructor for some LLM provider
9496
+ *
9497
+ * @private internal function of `createLlmToolsFromConfiguration` and `$provideLlmToolsFromEnv`
9498
+ */
9499
+ function $registeredLlmToolsMessage() {
9500
+ var e_1, _a, e_2, _b;
9501
+ /**
9502
+ * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
9503
+ */
9504
+ var all = [];
9505
+ var _loop_1 = function (packageName, className) {
9506
+ if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9507
+ return "continue";
9508
+ }
9509
+ all.push({ packageName: packageName, className: className });
9510
+ };
9511
+ try {
9512
+ for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
9513
+ var _e = _d.value, packageName = _e.packageName, className = _e.className;
9514
+ _loop_1(packageName, className);
9515
+ }
9516
+ }
9517
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9518
+ finally {
9519
+ try {
9520
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
9521
+ }
9522
+ finally { if (e_1) throw e_1.error; }
9523
+ }
9524
+ var _loop_2 = function (packageName, className) {
9525
+ if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9526
+ return "continue";
9527
+ }
9528
+ all.push({ packageName: packageName, className: className });
9529
+ };
9530
+ try {
9531
+ for (var _f = __values($llmToolsRegister.list()), _g = _f.next(); !_g.done; _g = _f.next()) {
9532
+ var _h = _g.value, packageName = _h.packageName, className = _h.className;
9533
+ _loop_2(packageName, className);
9534
+ }
9535
+ }
9536
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
9537
+ finally {
9538
+ try {
9539
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
9540
+ }
9541
+ finally { if (e_2) throw e_2.error; }
9542
+ }
9543
+ var metadata = all.map(function (metadata) {
9544
+ var isMetadataAviailable = $llmToolsMetadataRegister
9545
+ .list()
9546
+ .find(function (_a) {
9547
+ var packageName = _a.packageName, className = _a.className;
9548
+ return metadata.packageName === packageName && metadata.className === className;
9549
+ });
9550
+ var isInstalled = $llmToolsRegister
9551
+ .list()
9552
+ .find(function (_a) {
9553
+ var packageName = _a.packageName, className = _a.className;
9554
+ return metadata.packageName === packageName && metadata.className === className;
9555
+ });
9556
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9557
+ });
9558
+ if (metadata.length === 0) {
9559
+ return "No LLM providers are available.";
9560
+ }
9561
+ return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9562
+ .map(function (_a, i) {
9563
+ var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
9564
+ var more;
9565
+ if (just(false)) {
9566
+ more = '';
9567
+ }
9568
+ else if (!isMetadataAviailable && !isInstalled) {
9569
+ // TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
9570
+ more = "(not installed and no metadata, looks like a unexpected behavior)";
9571
+ }
9572
+ else if (isMetadataAviailable && !isInstalled) {
9573
+ // TODO: [�][�]
9574
+ more = "(not installed)";
9575
+ }
9576
+ else if (!isMetadataAviailable && isInstalled) {
9577
+ more = "(no metadata, looks like a unexpected behavior)";
9578
+ }
9579
+ else if (isMetadataAviailable && isInstalled) {
9580
+ more = "(installed)";
9581
+ }
9582
+ else {
9583
+ more = "(unknown state, looks like a unexpected behavior)";
9584
+ }
9585
+ return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` ").concat(more);
9586
+ })
9587
+ .join('\n')), "\n "); });
9588
+ }
9589
+ /**
9590
+ * TODO: [®] DRY Register logic
9591
+ */
9592
+
9593
+ /**
9594
+ * @@@
9595
+ *
9596
+ * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9597
+ *
9598
+ * @returns @@@
9599
+ * @public exported from `@promptbook/core`
9600
+ */
9601
+ function createLlmToolsFromConfiguration(configuration, options) {
9602
+ if (options === void 0) { options = {}; }
9603
+ var _a = options.isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a, userId = options.userId;
9604
+ var llmTools = configuration.map(function (llmConfiguration) {
9605
+ var registeredItem = $llmToolsRegister
9606
+ .list()
9607
+ .find(function (_a) {
9608
+ var packageName = _a.packageName, className = _a.className;
9609
+ return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
9610
+ });
9165
9611
  if (registeredItem === undefined) {
9166
9612
  throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
9167
9613
  }
@@ -9445,6 +9891,9 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
9445
9891
  return null;
9446
9892
  },
9447
9893
  });
9894
+ /**
9895
+ * Note: [💞] Ignore a discrepancy between file name and entity name
9896
+ */
9448
9897
 
9449
9898
  /**
9450
9899
  * Registration of LLM provider metadata
@@ -9492,6 +9941,9 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
9492
9941
  return null;
9493
9942
  },
9494
9943
  });
9944
+ /**
9945
+ * Note: [💞] Ignore a discrepancy between file name and entity name
9946
+ */
9495
9947
 
9496
9948
  /**
9497
9949
  * Registration of LLM provider metadata
@@ -9572,27 +10024,32 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
9572
10024
  */
9573
10025
  },
9574
10026
  });
10027
+ /**
10028
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10029
+ */
9575
10030
 
9576
10031
  /**
9577
10032
  * @@@
9578
10033
  *
10034
+ * @see https://github.com/webgptorg/promptbook/discussions/171
10035
+ *
9579
10036
  * @public exported from `@promptbook/core`
9580
10037
  */
9581
10038
  function getPipelineInterface(pipeline) {
9582
10039
  var e_1, _a, e_2, _b;
9583
10040
  var pipelineInterface = {
9584
- inputParameterNames: [],
9585
- outputParameterNames: [],
10041
+ inputParameters: [],
10042
+ outputParameters: [],
9586
10043
  };
9587
10044
  try {
9588
10045
  for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
9589
10046
  var parameter = _d.value;
9590
- var name_1 = parameter.name, isInput = parameter.isInput, isOutput = parameter.isOutput;
10047
+ var isInput = parameter.isInput, isOutput = parameter.isOutput;
9591
10048
  if (isInput) {
9592
- pipelineInterface.inputParameterNames.push(name_1);
10049
+ pipelineInterface.inputParameters.push(parameter);
9593
10050
  }
9594
10051
  if (isOutput) {
9595
- pipelineInterface.outputParameterNames.push(name_1);
10052
+ pipelineInterface.outputParameters.push(parameter);
9596
10053
  }
9597
10054
  }
9598
10055
  }
@@ -9604,9 +10061,15 @@ function getPipelineInterface(pipeline) {
9604
10061
  finally { if (e_1) throw e_1.error; }
9605
10062
  }
9606
10063
  try {
9607
- for (var _e = __values(['inputParameterNames', 'outputParameterNames']), _f = _e.next(); !_f.done; _f = _e.next()) {
10064
+ for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
9608
10065
  var key = _f.value;
9609
- pipelineInterface[key].sort(function (a, b) { return a.localeCompare(b); });
10066
+ pipelineInterface[key].sort(function (_a, _b) {
10067
+ var name1 = _a.name;
10068
+ var name2 = _b.name;
10069
+ return name1.localeCompare(name2);
10070
+ });
10071
+ // <- TODO: [🧠] Should we compare a descriptions?
10072
+ // <- TODO: [🧠][🛴] Maybe add type + expectations into the intefrace, like "a person name"
9610
10073
  }
9611
10074
  }
9612
10075
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -9625,6 +10088,8 @@ function getPipelineInterface(pipeline) {
9625
10088
  /**
9626
10089
  * @@@
9627
10090
  *
10091
+ * @see https://github.com/webgptorg/promptbook/discussions/171
10092
+ *
9628
10093
  * @public exported from `@promptbook/core`
9629
10094
  */
9630
10095
  function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
@@ -9639,6 +10104,8 @@ function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
9639
10104
  /**
9640
10105
  * @@@
9641
10106
  *
10107
+ * @see https://github.com/webgptorg/promptbook/discussions/171
10108
+ *
9642
10109
  * @public exported from `@promptbook/core`
9643
10110
  */
9644
10111
  function isPipelineImplementingInterface(options) {
@@ -9677,6 +10144,9 @@ var legacyDocumentScraperMetadata = $deepFreeze({
9677
10144
  * @public exported from `@promptbook/cli`
9678
10145
  */
9679
10146
  var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
10147
+ /**
10148
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10149
+ */
9680
10150
 
9681
10151
  /**
9682
10152
  * Metadata of the scraper
@@ -9701,6 +10171,9 @@ var documentScraperMetadata = $deepFreeze({
9701
10171
  * @public exported from `@promptbook/cli`
9702
10172
  */
9703
10173
  var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
10174
+ /**
10175
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10176
+ */
9704
10177
 
9705
10178
  /**
9706
10179
  * Metadata of the scraper
@@ -9725,6 +10198,9 @@ var markdownScraperMetadata = $deepFreeze({
9725
10198
  * @public exported from `@promptbook/cli`
9726
10199
  */
9727
10200
  var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
10201
+ /**
10202
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10203
+ */
9728
10204
 
9729
10205
  /**
9730
10206
  * Metadata of the scraper
@@ -9749,6 +10225,9 @@ var pdfScraperMetadata = $deepFreeze({
9749
10225
  * @public exported from `@promptbook/cli`
9750
10226
  */
9751
10227
  var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
10228
+ /**
10229
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10230
+ */
9752
10231
 
9753
10232
  /**
9754
10233
  * Metadata of the scraper
@@ -9773,6 +10252,9 @@ var websiteScraperMetadata = $deepFreeze({
9773
10252
  * @public exported from `@promptbook/cli`
9774
10253
  */
9775
10254
  var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
10255
+ /**
10256
+ * Note: [💞] Ignore a discrepancy between file name and entity name
10257
+ */
9776
10258
 
9777
10259
  /**
9778
10260
  * Behaves like a storage but forgets everything you put in it
@@ -9855,322 +10337,5 @@ var PrefixStorage = /** @class */ (function () {
9855
10337
  return PrefixStorage;
9856
10338
  }());
9857
10339
 
9858
- /**
9859
- * Format either small or big number
9860
- *
9861
- * @private within the repository
9862
- */
9863
- function formatNumber(value) {
9864
- if (value === 0) {
9865
- return '0';
9866
- }
9867
- for (var exponent = 0; exponent < 15; exponent++) {
9868
- var factor = Math.pow(10, exponent);
9869
- var valueRounded = Math.round(value * factor) / factor;
9870
- if (Math.abs(value - valueRounded) / value <
9871
- 0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
9872
- return valueRounded.toFixed(exponent);
9873
- }
9874
- }
9875
- return value.toString();
9876
- }
9877
-
9878
- /**
9879
- * Create a markdown table from a 2D array of strings
9880
- *
9881
- * @public exported from `@promptbook/markdown-utils`
9882
- */
9883
- function createMarkdownTable(table) {
9884
- var columnWidths = table.reduce(function (widths, row) {
9885
- row.forEach(function (subformat, columnIndex) {
9886
- var cellLength = subformat.length;
9887
- if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
9888
- widths[columnIndex] = cellLength;
9889
- }
9890
- });
9891
- return widths;
9892
- }, []);
9893
- var header = "| ".concat(table[0]
9894
- .map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
9895
- .join(' | '), " |");
9896
- var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
9897
- var rows = table.slice(1).map(function (row) {
9898
- var paddedRow = row.map(function (subformat, columnIndex) {
9899
- return subformat.padEnd(columnWidths[columnIndex]);
9900
- });
9901
- return "| ".concat(paddedRow.join(' | '), " |");
9902
- });
9903
- return __spreadArray([header, separator], __read(rows), false).join('\n');
9904
- }
9905
- /**
9906
- * TODO: [🏛] This can be part of markdown builder
9907
- */
9908
-
9909
- /**
9910
- * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
9911
- *
9912
- * @public exported from `@promptbook/markdown-utils`
9913
- */
9914
- function createMarkdownChart(options) {
9915
- var e_1, _a;
9916
- var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
9917
- var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
9918
- var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
9919
- var scale = width / (to - from);
9920
- var table = [[nameHeader, valueHeader]];
9921
- try {
9922
- for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
9923
- var item = items_1_1.value;
9924
- var before = Math.round((item.from - from) * scale);
9925
- var during = Math.round((item.to - item.from) * scale);
9926
- var after = width - before - during;
9927
- table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
9928
- }
9929
- }
9930
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
9931
- finally {
9932
- try {
9933
- if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
9934
- }
9935
- finally { if (e_1) throw e_1.error; }
9936
- }
9937
- var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
9938
- return createMarkdownTable(table) + '\n\n' + legend;
9939
- }
9940
- /**
9941
- * TODO: Maybe use Mermain Gant Diagrams
9942
- * @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
9943
- */
9944
-
9945
- /**
9946
- * Function escapeMarkdownBlock will escape markdown block if needed
9947
- * It is useful when you want have block in block
9948
- *
9949
- * @public exported from `@promptbook/markdown-utils`
9950
- */
9951
- function escapeMarkdownBlock(value) {
9952
- return value.replace(/```/g, '\\`\\`\\`');
9953
- }
9954
- /**
9955
- * TODO: [🏛] This can be part of markdown builder
9956
- */
9957
-
9958
- /**
9959
- * Default options for generating an execution report string
9960
- *
9961
- * @public exported from `@promptbook/core`
9962
- */
9963
- var ExecutionReportStringOptionsDefaults = {
9964
- taxRate: 0,
9965
- chartsWidth: 36,
9966
- };
9967
-
9968
- /**
9969
- * Count the duration of working time
9970
- *
9971
- * @private within the repository
9972
- */
9973
- function countWorkingDuration(items) {
9974
- var e_1, _a;
9975
- var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
9976
- steps.sort(function (a, b) { return a - b; });
9977
- var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
9978
- var duration = 0;
9979
- var _loop_1 = function (interval) {
9980
- var _b = __read(interval, 2), from = _b[0], to = _b[1];
9981
- if (items.some(function (item) { return item.from < to && item.to > from; })) {
9982
- duration += to - from;
9983
- }
9984
- };
9985
- try {
9986
- for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
9987
- var interval = intervals_1_1.value;
9988
- _loop_1(interval);
9989
- }
9990
- }
9991
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
9992
- finally {
9993
- try {
9994
- if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
9995
- }
9996
- finally { if (e_1) throw e_1.error; }
9997
- }
9998
- return duration;
9999
- }
10000
-
10001
- /**
10002
- * Converts execution report from JSON to string format
10003
- *
10004
- * @public exported from `@promptbook/core`
10005
- */
10006
- function executionReportJsonToString(executionReportJson, options) {
10007
- var e_1, _a;
10008
- var _b, _c, _d, _e, _f, _g;
10009
- var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
10010
- var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
10011
- var headerList = [];
10012
- if (executionReportJson.pipelineUrl) {
10013
- headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
10014
- }
10015
- headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
10016
- (!executionReportJson.promptbookRequestedVersion
10017
- ? ''
10018
- : " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
10019
- if (executionReportJson.promptExecutions.length !== 0) {
10020
- // TODO: What if startedAt OR/AND completedAt is not defined?
10021
- var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
10022
- .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
10023
- .map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
10024
- var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
10025
- .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
10026
- .map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
10027
- var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
10028
- var _a, _b, _c, _d;
10029
- return ({
10030
- title: promptExecution.prompt.title,
10031
- from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
10032
- to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
10033
- });
10034
- });
10035
- var costItems = executionReportJson.promptExecutions
10036
- .filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
10037
- .map(function (promptExecution) {
10038
- var _a, _b;
10039
- return ({
10040
- title: promptExecution.prompt.title,
10041
- from: 0,
10042
- to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* <- TODO: look at uncertain numbers */ *
10043
- (1 + taxRate),
10044
- });
10045
- });
10046
- var duration = moment.duration(completedAt.diff(startedAt));
10047
- var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
10048
- var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
10049
- var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) {
10050
- return cost + (promptExecution.result.usage.price.value /* <- Look at uncertain number */ || 0);
10051
- }, 0);
10052
- headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
10053
- headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
10054
- headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
10055
- headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
10056
- headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
10057
- (executionsWithKnownCost.length === executionReportJson.promptExecutions.length
10058
- ? ''
10059
- : " *(Some cost is unknown)*") +
10060
- (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
10061
- executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
10062
- executionReportString +=
10063
- '\n\n' +
10064
- '## 🗃 Index' +
10065
- '\n\n' +
10066
- executionReportJson.promptExecutions
10067
- .map(function (promptExecution) {
10068
- // TODO: Make some better system to convert hedings to links
10069
- var hash = normalizeToKebabCase(promptExecution.prompt.title);
10070
- if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
10071
- hash = '-' + hash;
10072
- }
10073
- // TODO: Make working hash link for the template in md + pdf
10074
- return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
10075
- })
10076
- .join('\n');
10077
- executionReportString +=
10078
- '\n\n' +
10079
- '## ⌚ Time chart' +
10080
- '\n\n' +
10081
- createMarkdownChart({
10082
- nameHeader: 'Template',
10083
- valueHeader: 'Timeline',
10084
- items: timingItems,
10085
- width: chartsWidth,
10086
- unitName: 'seconds',
10087
- });
10088
- executionReportString +=
10089
- '\n\n' +
10090
- '## 💸 Cost chart' +
10091
- '\n\n' +
10092
- createMarkdownChart({
10093
- nameHeader: 'Template',
10094
- valueHeader: 'Cost',
10095
- items: costItems,
10096
- width: chartsWidth,
10097
- unitName: 'USD',
10098
- });
10099
- }
10100
- else {
10101
- headerList.push("TOTAL COST $0 *(Nothing executed)*");
10102
- }
10103
- var _loop_1 = function (promptExecution) {
10104
- executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
10105
- var templateList = [];
10106
- // TODO: What if startedAt OR/AND completedAt is not defined?
10107
- var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
10108
- var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
10109
- var duration = moment.duration(completedAt.diff(startedAt));
10110
- // Not need here:
10111
- // > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
10112
- templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
10113
- if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
10114
- templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
10115
- (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
10116
- }
10117
- else {
10118
- templateList.push("COST UNKNOWN");
10119
- }
10120
- executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
10121
- /*
10122
- - MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
10123
- - MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
10124
- promptExecution.prompt.modelRequirements.modelName
10125
-
10126
- */
10127
- if (just(true)) {
10128
- executionReportString +=
10129
- '\n\n\n\n' +
10130
- spaceTrim$1(function (block) {
10131
- var _a;
10132
- return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
10133
- });
10134
- }
10135
- if (promptExecution.result && promptExecution.result.content) {
10136
- executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
10137
- if (promptExecution.result === undefined) {
10138
- executionReportString += '*No result*';
10139
- }
10140
- else if (typeof promptExecution.result.content === 'string') {
10141
- executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
10142
- }
10143
- else {
10144
- executionReportString += embeddingVectorToString(promptExecution.result.content);
10145
- }
10146
- }
10147
- if (promptExecution.error && promptExecution.error.message) {
10148
- executionReportString +=
10149
- '\n\n\n\n' +
10150
- spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
10151
- }
10152
- };
10153
- try {
10154
- for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
10155
- var promptExecution = _k.value;
10156
- _loop_1(promptExecution);
10157
- }
10158
- }
10159
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
10160
- finally {
10161
- try {
10162
- if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
10163
- }
10164
- finally { if (e_1) throw e_1.error; }
10165
- }
10166
- executionReportString = prettifyMarkdown(executionReportString);
10167
- return executionReportString;
10168
- }
10169
- /**
10170
- * TODO: Add mermaid chart for every report
10171
- * TODO: [🧠] Allow to filter out some parts of the report by options
10172
- * TODO: [🧠] Should be in generated file GENERATOR_WARNING
10173
- */
10174
-
10175
- export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GenericFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SheetsFormfactorDefinition, TemplateTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTemplates, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
10340
+ export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, ERRORS, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
10176
10341
  //# sourceMappingURL=index.es.js.map