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