@promptbook/core 0.61.0-9 → 0.61.0

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 (366) hide show
  1. package/README.md +3 -3
  2. package/esm/index.es.js +2066 -1044
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +200 -30
  5. package/esm/typings/src/_packages/core.index.d.ts +7 -2
  6. package/esm/typings/src/_packages/execute-javascript.index.d.ts +1 -1
  7. package/esm/typings/src/_packages/node.index.d.ts +2 -1
  8. package/esm/typings/src/_packages/types.index.d.ts +12 -8
  9. package/esm/typings/src/_packages/utils.index.d.ts +11 -8
  10. package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
  11. package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
  12. package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  13. package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
  14. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  15. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
  16. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +7 -7
  17. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  18. package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
  19. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
  20. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  21. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  22. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
  23. package/esm/typings/src/config.d.ts +46 -1
  24. package/esm/typings/src/config.test.d.ts +4 -0
  25. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  26. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
  27. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +6 -3
  28. package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  29. package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
  30. package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  31. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -0
  32. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
  33. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
  34. package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  35. package/esm/typings/src/errors/LimitReachedError.d.ts +7 -0
  36. package/esm/typings/src/errors/VersionMismatchError.d.ts +8 -0
  37. package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  38. package/esm/typings/src/execution/LlmExecutionTools.d.ts +10 -8
  39. package/esm/typings/src/execution/PipelineExecutor.d.ts +48 -26
  40. package/esm/typings/src/execution/PromptResult.d.ts +39 -54
  41. package/esm/typings/src/execution/PromptResultUsage.d.ts +29 -0
  42. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
  43. package/esm/typings/src/execution/UncertainNumber.d.ts +18 -0
  44. package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  45. package/esm/typings/src/execution/createPipelineExecutor.d.ts +30 -3
  46. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  47. package/esm/typings/src/execution/utils/addUsage.d.ts +58 -2
  48. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
  49. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  50. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
  51. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
  52. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  53. package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
  54. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
  55. package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
  56. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  57. package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  58. package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  59. package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
  60. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  61. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
  62. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  63. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
  64. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
  65. package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  66. package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
  67. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  68. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  69. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  70. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  71. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  72. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
  73. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  74. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  75. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
  76. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  77. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
  78. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  79. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  80. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  81. package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  82. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
  83. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
  84. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
  85. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
  86. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  87. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  88. package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  89. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
  90. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  91. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +10 -8
  92. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  93. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
  94. package/esm/typings/src/personas/preparePersona.d.ts +15 -0
  95. package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
  96. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +14 -0
  97. package/esm/typings/src/prepare/preparePipeline.d.ts +17 -0
  98. package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
  99. package/esm/typings/src/prepare/unpreparePipeline.d.ts +11 -0
  100. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  101. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  102. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
  103. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  104. package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  105. package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  106. package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  107. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  108. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  109. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  110. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  111. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  112. package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  113. package/esm/typings/src/types/ModelRequirements.d.ts +71 -11
  114. package/esm/typings/src/types/ModelVariant.d.ts +14 -0
  115. package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  116. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +70 -0
  117. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
  118. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
  119. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
  120. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
  121. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
  122. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
  123. package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
  124. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
  125. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
  126. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
  127. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
  128. package/esm/typings/src/types/PipelineString.d.ts +1 -1
  129. package/esm/typings/src/types/Prompt.d.ts +54 -10
  130. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  131. package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  132. package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  133. package/esm/typings/src/types/typeAliases.d.ts +114 -15
  134. package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
  135. package/esm/typings/src/utils/currentDate.d.ts +7 -0
  136. package/esm/typings/src/utils/deepClone.d.ts +9 -0
  137. package/esm/typings/src/utils/deepFreeze.d.ts +22 -0
  138. package/esm/typings/src/utils/emojis.d.ts +2 -2
  139. package/esm/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +2 -2
  140. package/esm/typings/src/utils/formatNumber.d.ts +1 -1
  141. package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  142. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
  143. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
  144. package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  145. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
  146. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  147. package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  148. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
  149. package/esm/typings/src/utils/organization/TODO_USE.d.ts +12 -0
  150. package/esm/typings/src/utils/organization/TODO_any.d.ts +6 -0
  151. package/esm/typings/src/utils/organization/TODO_object.d.ts +6 -0
  152. package/esm/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
  153. package/esm/typings/src/utils/organization/___.d.ts +6 -0
  154. package/{umd/typings/src/utils → esm/typings/src/utils/organization}/just.d.ts +5 -1
  155. package/esm/typings/src/utils/organization/keepUnused.d.ts +16 -0
  156. package/esm/typings/src/utils/organization/really_any.d.ts +6 -0
  157. package/esm/typings/src/utils/organization/really_unknown.d.ts +6 -0
  158. package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
  159. package/esm/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
  160. package/esm/typings/src/utils/replaceParameters.test.d.ts +1 -0
  161. package/esm/typings/src/utils/sets/difference.d.ts +3 -0
  162. package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
  163. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
  164. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
  165. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
  166. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
  167. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
  168. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
  169. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
  170. package/package.json +1 -1
  171. package/umd/index.umd.js +2069 -1043
  172. package/umd/index.umd.js.map +1 -1
  173. package/umd/typings/promptbook-collection/index.d.ts +200 -30
  174. package/umd/typings/src/_packages/core.index.d.ts +7 -2
  175. package/umd/typings/src/_packages/execute-javascript.index.d.ts +1 -1
  176. package/umd/typings/src/_packages/node.index.d.ts +2 -1
  177. package/umd/typings/src/_packages/types.index.d.ts +12 -8
  178. package/umd/typings/src/_packages/utils.index.d.ts +11 -8
  179. package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
  180. package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
  181. package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  182. package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
  183. package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
  184. package/umd/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
  185. package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +7 -7
  186. package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  187. package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
  188. package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
  189. package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  190. package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  191. package/umd/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
  192. package/umd/typings/src/config.d.ts +46 -1
  193. package/umd/typings/src/config.test.d.ts +4 -0
  194. package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  195. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
  196. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +6 -3
  197. package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  198. package/{esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
  199. package/umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.test.d.ts +1 -0
  200. package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  201. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -0
  202. package/umd/typings/src/conversion/utils/stringifyPipelineJson.test.d.ts +1 -0
  203. package/umd/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
  204. package/umd/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
  205. package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  206. package/umd/typings/src/errors/LimitReachedError.d.ts +7 -0
  207. package/umd/typings/src/errors/VersionMismatchError.d.ts +8 -0
  208. package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  209. package/umd/typings/src/execution/LlmExecutionTools.d.ts +10 -8
  210. package/umd/typings/src/execution/PipelineExecutor.d.ts +48 -26
  211. package/umd/typings/src/execution/PromptResult.d.ts +39 -54
  212. package/umd/typings/src/execution/PromptResultUsage.d.ts +29 -0
  213. package/umd/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
  214. package/umd/typings/src/execution/UncertainNumber.d.ts +18 -0
  215. package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  216. package/umd/typings/src/execution/createPipelineExecutor.d.ts +30 -3
  217. package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  218. package/umd/typings/src/execution/utils/addUsage.d.ts +58 -2
  219. package/umd/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
  220. package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  221. package/umd/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
  222. package/umd/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
  223. package/umd/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  224. package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
  225. package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
  226. package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
  227. package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  228. package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  229. package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  230. package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
  231. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  232. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
  233. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
  234. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  235. package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
  236. package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
  237. package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  238. package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
  239. package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  240. package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  241. package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  242. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  243. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  244. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
  245. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  246. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  247. package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
  248. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  249. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
  250. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  251. package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  252. package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  253. package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  254. package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
  255. package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
  256. package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
  257. package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
  258. package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  259. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  260. package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  261. package/umd/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
  262. package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  263. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +10 -8
  264. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  265. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
  266. package/umd/typings/src/personas/preparePersona.d.ts +15 -0
  267. package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
  268. package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
  269. package/umd/typings/src/prepare/isPipelinePrepared.d.ts +14 -0
  270. package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
  271. package/umd/typings/src/prepare/preparePipeline.d.ts +17 -0
  272. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  273. package/umd/typings/src/prepare/unpreparePipeline.d.ts +11 -0
  274. package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  275. package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  276. package/umd/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
  277. package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  278. package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  279. package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  280. package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  281. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  282. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  283. package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  284. package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  285. package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  286. package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  287. package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  288. package/umd/typings/src/types/ModelRequirements.d.ts +71 -11
  289. package/umd/typings/src/types/ModelVariant.d.ts +14 -0
  290. package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  291. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +70 -0
  292. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
  293. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
  294. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
  295. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
  296. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
  297. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
  298. package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
  299. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
  300. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
  301. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
  302. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
  303. package/umd/typings/src/types/PipelineString.d.ts +1 -1
  304. package/umd/typings/src/types/Prompt.d.ts +54 -10
  305. package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  306. package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  307. package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  308. package/umd/typings/src/types/typeAliases.d.ts +114 -15
  309. package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
  310. package/umd/typings/src/utils/currentDate.d.ts +7 -0
  311. package/umd/typings/src/utils/deepClone.d.ts +9 -0
  312. package/umd/typings/src/utils/deepFreeze.d.ts +22 -0
  313. package/umd/typings/src/utils/emojis.d.ts +2 -2
  314. package/umd/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +2 -2
  315. package/umd/typings/src/utils/extractParameterNames.test.d.ts +1 -0
  316. package/umd/typings/src/utils/formatNumber.d.ts +1 -1
  317. package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  318. package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
  319. package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
  320. package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  321. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  322. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
  323. package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  324. package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  325. package/umd/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
  326. package/umd/typings/src/utils/organization/TODO_USE.d.ts +12 -0
  327. package/umd/typings/src/utils/organization/TODO_any.d.ts +6 -0
  328. package/umd/typings/src/utils/organization/TODO_object.d.ts +6 -0
  329. package/umd/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
  330. package/umd/typings/src/utils/organization/___.d.ts +6 -0
  331. package/{esm/typings/src/utils → umd/typings/src/utils/organization}/just.d.ts +5 -1
  332. package/umd/typings/src/utils/organization/keepUnused.d.ts +16 -0
  333. package/umd/typings/src/utils/organization/really_any.d.ts +6 -0
  334. package/umd/typings/src/utils/organization/really_unknown.d.ts +6 -0
  335. package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
  336. package/umd/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
  337. package/umd/typings/src/utils/replaceParameters.test.d.ts +1 -0
  338. package/umd/typings/src/utils/sets/difference.d.ts +3 -0
  339. package/umd/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
  340. package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
  341. package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
  342. package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
  343. package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
  344. package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
  345. package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
  346. package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
  347. package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  348. package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  349. package/esm/typings/src/types/Parameters.d.ts +0 -14
  350. package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  351. package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  352. package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  353. package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  354. package/umd/typings/src/types/Parameters.d.ts +0 -14
  355. package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  356. package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  357. /package/esm/typings/src/conversion/utils/{extractParametersFromPromptTemplate.test.d.ts → extractParameterNamesFromPromptTemplate.test.d.ts} +0 -0
  358. /package/esm/typings/src/{execution/addPromptResultUsage.test.d.ts → conversion/utils/stringifyPipelineJson.test.d.ts} +0 -0
  359. /package/esm/typings/src/{execution/utils/replaceParameters.test.d.ts → knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts} +0 -0
  360. /package/esm/typings/src/{utils/extractParameters.test.d.ts → personas/preparePersona.test.d.ts} +0 -0
  361. /package/esm/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
  362. /package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.test.d.ts → esm/typings/src/prepare/isPipelinePrepared.test.d.ts} +0 -0
  363. /package/{umd/typings/src/execution/addPromptResultUsage.test.d.ts → esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts} +0 -0
  364. /package/{umd/typings/src/execution/utils/replaceParameters.test.d.ts → esm/typings/src/utils/extractParameterNames.test.d.ts} +0 -0
  365. /package/{umd/typings/src/utils/extractParameters.test.d.ts → esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts} +0 -0
  366. /package/umd/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
package/umd/index.umd.js CHANGED
@@ -258,7 +258,7 @@
258
258
  /* Note: Not using:> name, */
259
259
  title_1 = promptTemplate.title, description_1 = promptTemplate.description,
260
260
  /* Note: dependentParameterNames, */
261
- jokers = promptTemplate.jokers, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
261
+ jokers = promptTemplate.jokerParameterNames, blockType = promptTemplate.blockType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessingFunctionNames, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
262
262
  pipelineString += '\n\n';
263
263
  pipelineString += "## ".concat(title_1);
264
264
  if (description_1) {
@@ -392,23 +392,119 @@
392
392
  return parameterString;
393
393
  }
394
394
  /**
395
- * TODO: !!!!! Implement new features and commands into `promptTemplateParameterJsonToString`
395
+ * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
396
396
  * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
397
397
  * TODO: Escape all
398
398
  */
399
399
 
400
+ /**
401
+ * @@@
402
+ *
403
+ * @returns The same object as the input, but deeply frozen
404
+ *
405
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
406
+ */
407
+ function deepFreeze(objectValue) {
408
+ var e_1, _a;
409
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
410
+ try {
411
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
412
+ var propertyName = propertyNames_1_1.value;
413
+ var value = objectValue[propertyName];
414
+ if (value && typeof value === 'object') {
415
+ deepFreeze(value);
416
+ }
417
+ }
418
+ }
419
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
420
+ finally {
421
+ try {
422
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
423
+ }
424
+ finally { if (e_1) throw e_1.error; }
425
+ }
426
+ return Object.freeze(objectValue);
427
+ }
428
+ /**
429
+ * @@@
430
+ * @@@
431
+ *
432
+ * @returns The same object as the input, but deeply frozen
433
+ *
434
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
435
+ */
436
+ function deepFreezeWithSameType(objectValue) {
437
+ return deepFreeze(objectValue);
438
+ }
439
+ /**
440
+ * TODO: [🔼] Export from `@promptbook/utils`
441
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
442
+ */
443
+
444
+ /**
445
+ * Returns the same value that is passed as argument.
446
+ * No side effects.
447
+ *
448
+ * Note: It can be usefull for:
449
+ *
450
+ * 1) Leveling indentation
451
+ * 2) Putting always-true or always-false conditions without getting eslint errors
452
+ *
453
+ * @param value any values
454
+ * @returns the same values
455
+ * @private within the repository
456
+ */
457
+ function just(value) {
458
+ if (value === undefined) {
459
+ return undefined;
460
+ }
461
+ return value;
462
+ }
463
+
400
464
  /**
401
465
  * The maximum number of iterations for a loops
402
466
  */
403
467
  var LOOP_LIMIT = 1000;
468
+ /**
469
+ * The maximum number of (LLM) tasks running in parallel
470
+ */
471
+ var MAX_PARALLEL_COUNT = 5;
472
+ /**
473
+ * The maximum number of attempts to execute LLM task before giving up
474
+ */
475
+ var MAX_EXECUTION_ATTEMPTS = 3;
476
+ /**
477
+ * Nonce which is used for replacing things in strings
478
+ */
479
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
404
480
  /**
405
481
  * The names of the parameters that are reserved for special purposes
406
482
  */
407
- var RESERVED_PARAMETER_NAMES = [
483
+ var RESERVED_PARAMETER_NAMES = deepFreeze([
484
+ 'content',
408
485
  'context',
486
+ 'knowledge',
487
+ 'samples',
488
+ 'modelName',
489
+ 'currentDate',
409
490
  // <- TODO: Add more like 'date', 'modelName',...
410
491
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
411
- ];
492
+ ]);
493
+ /**
494
+ * @@@
495
+ */
496
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
497
+ /**
498
+ * @@@
499
+ */
500
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
501
+ /*
502
+ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
503
+ */
504
+ // [🟡][🟢][🔵][⚪]
505
+ /**
506
+ * TODO: [🔼] Export all to core
507
+ */
412
508
 
413
509
  /**
414
510
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -486,7 +582,7 @@
486
582
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
487
583
  return false;
488
584
  }
489
- // <- TODO: !!!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
585
+ // <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
490
586
  return true;
491
587
  }
492
588
 
@@ -611,56 +707,67 @@
611
707
  */
612
708
  function validatePipeline(pipeline) {
613
709
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
614
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
710
+ var e_1, _a, e_2, _b, e_3, _c;
711
+ var pipelineIdentification = (function () {
712
+ // Note: This is a 😐 implementation of [🚞]
713
+ var _ = [];
714
+ if (pipeline.sourceFile !== undefined) {
715
+ _.push("File: ".concat(pipeline.sourceFile));
716
+ }
717
+ if (pipeline.pipelineUrl !== undefined) {
718
+ _.push("Url: ".concat(pipeline.pipelineUrl));
719
+ }
720
+ return _.join('\n');
721
+ })();
615
722
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
616
723
  // <- Note: [🚲]
617
- throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
724
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
618
725
  }
619
726
  if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
620
727
  // <- Note: [🚲]
621
- throw new PipelineLogicError("Invalid promptbook Version \"".concat(pipeline.pipelineUrl, "\""));
728
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
622
729
  }
623
730
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
624
731
  if (!Array.isArray(pipeline.parameters)) {
625
732
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
626
- throw new ParsingError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof pipeline.parameters, "\n ")));
733
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
627
734
  }
628
735
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
629
736
  if (!Array.isArray(pipeline.promptTemplates)) {
630
737
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
631
- throw new ParsingError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n ")));
738
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
632
739
  }
633
740
  var _loop_1 = function (parameter) {
634
741
  if (parameter.isInput && parameter.isOutput) {
635
- throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
742
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
636
743
  }
637
744
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
638
745
  if (!parameter.isInput &&
639
746
  !parameter.isOutput &&
640
747
  !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
641
- throw new PipelineLogicError(spaceTrim.spaceTrim("\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 ")));
748
+ 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 "); }));
642
749
  }
643
750
  // Note: Testing that parameter is either input or result of some template
644
751
  if (!parameter.isInput &&
645
752
  !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
646
- throw new PipelineLogicError(spaceTrim.spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
753
+ 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 - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
647
754
  }
648
755
  };
649
756
  try {
650
757
  // Note: Check each parameter individually
651
- for (var _e = __values(pipeline.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
652
- var parameter = _f.value;
758
+ for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
759
+ var parameter = _e.value;
653
760
  _loop_1(parameter);
654
761
  }
655
762
  }
656
763
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
657
764
  finally {
658
765
  try {
659
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
766
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
660
767
  }
661
768
  finally { if (e_1) throw e_1.error; }
662
769
  }
663
- // Note: Check each template individually
770
+ // Note: All input parameters are defined - so that they can be used as result of some template
664
771
  var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
665
772
  var isInput = _a.isInput;
666
773
  return isInput;
@@ -668,66 +775,80 @@
668
775
  var name = _a.name;
669
776
  return name;
670
777
  }));
671
- try {
672
- for (var _g = __values(pipeline.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
673
- var template = _h.value;
674
- if (definedParameters.has(template.resultingParameterName)) {
675
- throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
778
+ var _loop_2 = function (template) {
779
+ var e_4, _h, e_5, _j;
780
+ if (definedParameters.has(template.resultingParameterName)) {
781
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
782
+ }
783
+ if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
784
+ 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 "); }));
785
+ }
786
+ definedParameters.add(template.resultingParameterName);
787
+ if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
788
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`").concat(/* <- TODO: Dynamic listing of command examples */ '', "\n\n ").concat(block(pipelineIdentification), "\n "); }));
789
+ }
790
+ if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
791
+ if (!template.expectFormat &&
792
+ !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
793
+ 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 "); }));
676
794
  }
677
- definedParameters.add(template.resultingParameterName);
678
- if (template.blockType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
679
- throw new PipelineLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
680
- }
681
- if (template.jokers && template.jokers.length > 0) {
682
- if (!template.expectFormat &&
683
- !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
684
- throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
795
+ var _loop_4 = function (joker) {
796
+ if (!template.dependentParameterNames.includes(joker)) {
797
+ 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 "); }));
798
+ }
799
+ };
800
+ try {
801
+ for (var _k = (e_4 = void 0, __values(template.jokerParameterNames)), _l = _k.next(); !_l.done; _l = _k.next()) {
802
+ var joker = _l.value;
803
+ _loop_4(joker);
685
804
  }
805
+ }
806
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
807
+ finally {
686
808
  try {
687
- for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
688
- var joker = _k.value;
689
- if (!template.dependentParameterNames.includes(joker)) {
690
- throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
691
- }
692
- }
809
+ if (_l && !_l.done && (_h = _k.return)) _h.call(_k);
693
810
  }
694
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
695
- finally {
696
- try {
697
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
698
- }
699
- finally { if (e_3) throw e_3.error; }
811
+ finally { if (e_4) throw e_4.error; }
812
+ }
813
+ }
814
+ if (template.expectations) {
815
+ var _loop_5 = function (unit, min, max) {
816
+ if (min !== undefined && max !== undefined && min > max) {
817
+ 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 "); }));
818
+ }
819
+ if (min !== undefined && min < 0) {
820
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
821
+ }
822
+ if (max !== undefined && max <= 0) {
823
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
824
+ }
825
+ };
826
+ try {
827
+ for (var _m = (e_5 = void 0, __values(Object.entries(template.expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
828
+ var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
829
+ _loop_5(unit, min, max);
700
830
  }
701
831
  }
702
- if (template.expectations) {
832
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
833
+ finally {
703
834
  try {
704
- for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
705
- var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
706
- if (min !== undefined && max !== undefined && min > max) {
707
- throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
708
- }
709
- if (min !== undefined && min < 0) {
710
- throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
711
- }
712
- if (max !== undefined && max <= 0) {
713
- throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
714
- }
715
- }
716
- }
717
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
718
- finally {
719
- try {
720
- if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
721
- }
722
- finally { if (e_4) throw e_4.error; }
835
+ if (_o && !_o.done && (_j = _m.return)) _j.call(_m);
723
836
  }
837
+ finally { if (e_5) throw e_5.error; }
724
838
  }
725
839
  }
840
+ };
841
+ try {
842
+ // Note: Checking each template individually
843
+ for (var _f = __values(pipeline.promptTemplates), _g = _f.next(); !_g.done; _g = _f.next()) {
844
+ var template = _g.value;
845
+ _loop_2(template);
846
+ }
726
847
  }
727
848
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
728
849
  finally {
729
850
  try {
730
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
851
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
731
852
  }
732
853
  finally { if (e_2) throw e_2.error; }
733
854
  }
@@ -741,24 +862,42 @@
741
862
  var name = _a.name;
742
863
  return name;
743
864
  });
865
+ try {
866
+ // Note: All reserved parameters are resolved
867
+ for (var RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
868
+ var reservedParameterName = RESERVED_PARAMETER_NAMES_1_1.value;
869
+ resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), [reservedParameterName], false);
870
+ }
871
+ }
872
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
873
+ finally {
874
+ try {
875
+ if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_c = RESERVED_PARAMETER_NAMES_1.return)) _c.call(RESERVED_PARAMETER_NAMES_1);
876
+ }
877
+ finally { if (e_3) throw e_3.error; }
878
+ }
744
879
  var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
880
+ // <- TODO: [🧠][🥜]
745
881
  var loopLimit = LOOP_LIMIT;
746
- var _loop_2 = function () {
882
+ var _loop_3 = function () {
747
883
  if (loopLimit-- < 0) {
748
- throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePipeline`');
884
+ // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
885
+ 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 "); }));
749
886
  }
750
887
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
751
888
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
752
889
  });
753
890
  if (currentlyResovedTemplates.length === 0) {
754
- throw new PipelineLogicError(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 Can not resolve:\n ".concat(block(unresovedTemplates
891
+ throw new PipelineLogicError(
892
+ // TODO: [🐎] DRY
893
+ 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 Can not resolve:\n ".concat(block(unresovedTemplates
755
894
  .map(function (_a) {
756
895
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
757
- return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
896
+ return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
758
897
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
759
- .join(', '));
898
+ .join(' and '));
760
899
  })
761
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
900
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n ").concat(block(pipelineIdentification), "\n "); }));
762
901
  }
763
902
  resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
764
903
  var resultingParameterName = _a.resultingParameterName;
@@ -767,7 +906,7 @@
767
906
  unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
768
907
  };
769
908
  while (unresovedTemplates.length > 0) {
770
- _loop_2();
909
+ _loop_3();
771
910
  }
772
911
  return pipeline;
773
912
  }
@@ -780,7 +919,16 @@
780
919
  * > * It checks:
781
920
  * > * - it has a valid structure
782
921
  * > * - ...
783
- * > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
922
+ * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
923
+ */
924
+ /**
925
+ * TODO: [🐣] !!!! Validate that all samples match expectations
926
+ * TODO: [🐣][🐝] !!!! Validate that knowledge is valid (non-void)
927
+ * TODO: [🐣] !!!! Validate that persona can be used only with CHAT variant
928
+ * TODO: [🐣] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
929
+ * TODO: [🐣] !!!! Validate that reserved parameter is not used as joker
930
+ * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
931
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
784
932
  */
785
933
 
786
934
  /**
@@ -812,79 +960,137 @@
812
960
  }(Error));
813
961
 
814
962
  /**
815
- * Library of promptbooks that groups together promptbooks for an application.
816
- * This implementation is a very thin wrapper around the Array / Map of promptbooks.
963
+ * Parses the template and returns the list of all parameter names
964
+ *
965
+ * @param template the template with parameters in {curly} braces
966
+ * @returns the list of parameter names
967
+ */
968
+ function extractParameterNames(template) {
969
+ var e_1, _a;
970
+ var matches = template.matchAll(/{\w+}/g);
971
+ var parameterNames = new Set();
972
+ try {
973
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
974
+ var match = matches_1_1.value;
975
+ var parameterName = match[0].slice(1, -1);
976
+ parameterNames.add(parameterName);
977
+ }
978
+ }
979
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
980
+ finally {
981
+ try {
982
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
983
+ }
984
+ finally { if (e_1) throw e_1.error; }
985
+ }
986
+ return parameterNames;
987
+ }
988
+
989
+ /**
990
+ * Unprepare just strips the preparation data of the pipeline
991
+ */
992
+ function unpreparePipeline(pipeline) {
993
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
994
+ personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
995
+ knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
996
+ promptTemplates = promptTemplates.map(function (promptTemplate) {
997
+ var dependentParameterNames = promptTemplate.dependentParameterNames;
998
+ var parameterNames = extractParameterNames(promptTemplate.preparedContent || '');
999
+ dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1000
+ var promptTemplateUnprepared = __assign(__assign({}, promptTemplate), { dependentParameterNames: dependentParameterNames });
1001
+ delete promptTemplateUnprepared.preparedContent;
1002
+ return promptTemplateUnprepared;
1003
+ });
1004
+ return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1005
+ }
1006
+ /**
1007
+ * TODO: [🔼] !!! Export via `@promptbook/core`
1008
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1009
+ * TODO: Write tests for `preparePipeline`
1010
+ * TODO: [🍙] Make some standart order of json properties
1011
+ */
1012
+
1013
+ /**
1014
+ * Library of pipelines that groups together pipelines for an application.
1015
+ * This implementation is a very thin wrapper around the Array / Map of pipelines.
817
1016
  *
818
1017
  * @private use `createCollectionFromJson` instead
819
- * @see https://github.com/webgptorg/promptbook#promptbook-collection
1018
+ * @see https://github.com/webgptorg/pipeline#pipeline-collection
820
1019
  */
821
1020
  var SimplePipelineCollection = /** @class */ (function () {
822
1021
  /**
823
- * Constructs a pipeline collection from promptbooks
1022
+ * Constructs a pipeline collection from pipelines
824
1023
  *
825
- * @param promptbooks !!!
1024
+ * @param pipelines @@@
826
1025
  *
827
1026
  * @private Use instead `createCollectionFromJson`
828
- * Note: During the construction logic of all promptbooks are validated
1027
+ * Note: During the construction logic of all pipelines are validated
829
1028
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
830
1029
  */
831
1030
  function SimplePipelineCollection() {
832
1031
  var e_1, _a;
833
- var promptbooks = [];
1032
+ var pipelines = [];
834
1033
  for (var _i = 0; _i < arguments.length; _i++) {
835
- promptbooks[_i] = arguments[_i];
1034
+ pipelines[_i] = arguments[_i];
836
1035
  }
837
1036
  this.collection = new Map();
838
1037
  try {
839
- for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
840
- var promptbook = promptbooks_1_1.value;
841
- if (promptbook.pipelineUrl === undefined) {
842
- throw new ReferenceError$1(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n File:\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the pipeline collection\n\n ")));
1038
+ for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
1039
+ var pipeline = pipelines_1_1.value;
1040
+ // TODO: [👠] DRY
1041
+ if (pipeline.pipelineUrl === undefined) {
1042
+ throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
843
1043
  }
844
- validatePipeline(promptbook);
1044
+ // Note: [🐨]
1045
+ validatePipeline(pipeline);
1046
+ // TODO: [🦄] DRY
845
1047
  // Note: [🦄]
846
- if (this.collection.has(promptbook.pipelineUrl) &&
847
- pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
848
- var existing = this.collection.get(promptbook.pipelineUrl);
849
- throw new ReferenceError$1(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks with the same URL are not allowed\n Only exepction is when the promptbooks are identical\n\n ")));
1048
+ if (
1049
+ // TODO: [🐽]
1050
+ this.collection.has(pipeline.pipelineUrl) &&
1051
+ pipelineJsonToString(unpreparePipeline(pipeline)) !==
1052
+ pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1053
+ var existing = this.collection.get(pipeline.pipelineUrl);
1054
+ throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
850
1055
  }
851
- this.collection.set(promptbook.pipelineUrl, promptbook);
1056
+ // Note: [🧠] Overwrite existing pipeline with the same URL
1057
+ this.collection.set(pipeline.pipelineUrl, pipeline);
852
1058
  }
853
1059
  }
854
1060
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
855
1061
  finally {
856
1062
  try {
857
- if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
1063
+ if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
858
1064
  }
859
1065
  finally { if (e_1) throw e_1.error; }
860
1066
  }
861
1067
  }
862
1068
  /**
863
- * Gets all promptbooks in the collection
1069
+ * Gets all pipelines in the collection
864
1070
  */
865
1071
  SimplePipelineCollection.prototype.listPipelines = function () {
866
1072
  return Array.from(this.collection.keys());
867
1073
  };
868
1074
  /**
869
- * Gets promptbook by its URL
1075
+ * Gets pipeline by its URL
870
1076
  *
871
1077
  * Note: This is not a direct fetching from the URL, but a lookup in the collection
872
1078
  */
873
1079
  SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
874
1080
  var _this = this;
875
- var promptbook = this.collection.get(url);
876
- if (!promptbook) {
1081
+ var pipeline = this.collection.get(url);
1082
+ if (!pipeline) {
877
1083
  if (this.listPipelines().length === 0) {
878
- throw new NotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1084
+ throw new NotFoundError(spaceTrim.spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
879
1085
  }
880
- throw new NotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
1086
+ throw new NotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
881
1087
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
882
1088
  .join('\n')), "\n\n "); }));
883
1089
  }
884
- return promptbook;
1090
+ return pipeline;
885
1091
  };
886
1092
  /**
887
- * Checks whether given prompt was defined in any promptbook in the collection
1093
+ * Checks whether given prompt was defined in any pipeline in the collection
888
1094
  */
889
1095
  SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
890
1096
  return true;
@@ -1126,7 +1332,199 @@
1126
1332
  // <- [🩻]
1127
1333
  ];
1128
1334
 
1129
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-8",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"knowledge"}],knowledge:[{name:"u",title:"U",content:"I",keywords:["E"],index:[{modelName:"mocked-facked",position:[-0.3453973828882342,-0.3141628639413514,-0.8603436743004793,0.6728018673301928,-0.9605637165286502,0.7088842482142073,-0.34494577682844785,0.6010842971317221,-0.04295184681439013,0.8007417470733849,-0.23697328816097052,-0.017493253490395322,-0.9090876357692248,0.74125281768158,-0.9076135469899738,0.9952187932256056,0.008511414426171982,0.5998098130334704,0.045404859001831,-0.42206311138329067,-0.5595152486651154,-0.47725505806219415,-0.5436970583373815,0.35363956333229396,-0.12693763438108796]}],sources:[{title:"Markdown document",href:"#"}]}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-8",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"keywords"}],knowledge:[{name:"i",title:"I",content:"E",keywords:["M"],index:[{modelName:"mocked-facked",position:[0.19147483113917518,-0.7177848535117057,0.3683965389877679,0.6207547823892003,0.7072367024009303,-0.7579307453180899,-0.5822315355632282,-0.0416838366681902,-0.4651057611764511,-0.611441597920364,-0.601121121299252,0.05822098791382446,0.2250330827083613,0.4148105817390326,0.18938319562858874,0.6690313746510337,0.10932010447666451,0.1045178968783178,0.1588601067610882,0.28034513708196984,0.0025333686672688316,-0.04321089965612668,0.4704061207491228,-0.1911083145243362,0.5679872213373209]}],sources:[{title:"Markdown document",href:"#"}]}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-8",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",resultingParameterName:"title"}],knowledge:[{name:"n",title:"N",content:"C",keywords:["D"],index:[{modelName:"mocked-facked",position:[0.10612659748079523,-0.7856803833631183,0.1409428165697526,0.8467355715298632,0.6864582688662693,-0.4921408940660612,0.14478588507439571,-0.4758184993922012,-0.23667915152261454,0.7956308792170788,0.11585260435556588,-0.26155156872769236,-0.6564981977915396,-0.609952147469647,0.31272094148873597,0.6145702220978193,-0.4267046006405488,0.024211888036476115,0.5375719207498166,0.6604556025691424,-0.7850520501178093,0.06782180782693414,-0.6939426176190544,-0.3795848182232091,0.7308270240270351]}],sources:[{title:"Markdown document",href:"#"}]}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"}];
1335
+ /**
1336
+ * @@@
1337
+ */
1338
+ function deepClone(objectValue) {
1339
+ return JSON.parse(JSON.stringify(objectValue));
1340
+ /*
1341
+ TODO: [🧠] Is there a better implementation?
1342
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
1343
+ > for (const propertyName of propertyNames) {
1344
+ > const value = (objectValue as really_any)[propertyName];
1345
+ > if (value && typeof value === 'object') {
1346
+ > deepClone(value);
1347
+ > }
1348
+ > }
1349
+ > return Object.assign({}, objectValue);
1350
+ */
1351
+ }
1352
+ /**
1353
+ * TODO: [🔼] Export from `@promptbook/utils`
1354
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1355
+ */
1356
+
1357
+ /**
1358
+ * @@@
1359
+ *
1360
+ * TODO: [🔼] Export with addUsage
1361
+ */
1362
+ var ZERO_USAGE = deepFreeze({
1363
+ price: { value: 0 },
1364
+ input: {
1365
+ tokensCount: { value: 0 },
1366
+ charactersCount: { value: 0 },
1367
+ wordsCount: { value: 0 },
1368
+ sentencesCount: { value: 0 },
1369
+ linesCount: { value: 0 },
1370
+ paragraphsCount: { value: 0 },
1371
+ pagesCount: { value: 0 },
1372
+ },
1373
+ output: {
1374
+ tokensCount: { value: 0 },
1375
+ charactersCount: { value: 0 },
1376
+ wordsCount: { value: 0 },
1377
+ sentencesCount: { value: 0 },
1378
+ linesCount: { value: 0 },
1379
+ paragraphsCount: { value: 0 },
1380
+ pagesCount: { value: 0 },
1381
+ },
1382
+ });
1383
+ /**
1384
+ * Function `addUsage` will add multiple usages into one
1385
+ *
1386
+ * Note: If you provide 0 values, it returns ZERO_USAGE
1387
+ */
1388
+ function addUsage() {
1389
+ var usageItems = [];
1390
+ for (var _i = 0; _i < arguments.length; _i++) {
1391
+ usageItems[_i] = arguments[_i];
1392
+ }
1393
+ return usageItems.reduce(function (acc, item) {
1394
+ var e_1, _a, e_2, _b;
1395
+ var _c;
1396
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1397
+ try {
1398
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1399
+ var key = _e.value;
1400
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1401
+ //@ts-ignore
1402
+ if (item.input[key]) {
1403
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1404
+ //@ts-ignore
1405
+ acc.input[key].value += item.input[key].value || 0;
1406
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1407
+ //@ts-ignore
1408
+ if (item.input[key].isUncertain) {
1409
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1410
+ //@ts-ignore
1411
+ acc.input[key].isUncertain = true;
1412
+ }
1413
+ }
1414
+ }
1415
+ }
1416
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1417
+ finally {
1418
+ try {
1419
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1420
+ }
1421
+ finally { if (e_1) throw e_1.error; }
1422
+ }
1423
+ try {
1424
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1425
+ var key = _g.value;
1426
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1427
+ //@ts-ignore
1428
+ if (item.output[key]) {
1429
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1430
+ //@ts-ignore
1431
+ acc.output[key].value += item.output[key].value || 0;
1432
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1433
+ //@ts-ignore
1434
+ if (item.output[key].isUncertain) {
1435
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1436
+ //@ts-ignore
1437
+ acc.output[key].isUncertain = true;
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1443
+ finally {
1444
+ try {
1445
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1446
+ }
1447
+ finally { if (e_2) throw e_2.error; }
1448
+ }
1449
+ return acc;
1450
+ }, deepClone(ZERO_USAGE));
1451
+ }
1452
+
1453
+ /**
1454
+ * Async version of Array.forEach
1455
+ *
1456
+ * @param array - Array to iterate over
1457
+ * @param options - Options for the function
1458
+ * @param callbackfunction - Function to call for each item
1459
+ */
1460
+ function forEachAsync(array, options, callbackfunction) {
1461
+ return __awaiter(this, void 0, void 0, function () {
1462
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
1463
+ var e_1, _d;
1464
+ return __generator(this, function (_e) {
1465
+ switch (_e.label) {
1466
+ case 0:
1467
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
1468
+ index = 0;
1469
+ runningTasks = [];
1470
+ tasks = [];
1471
+ _loop_1 = function (item) {
1472
+ var currentIndex, task;
1473
+ return __generator(this, function (_f) {
1474
+ switch (_f.label) {
1475
+ case 0:
1476
+ currentIndex = index++;
1477
+ task = callbackfunction(item, currentIndex, array);
1478
+ tasks.push(task);
1479
+ runningTasks.push(task);
1480
+ /* not await */ Promise.resolve(task).then(function () {
1481
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
1482
+ });
1483
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
1484
+ return [4 /*yield*/, Promise.race(runningTasks)];
1485
+ case 1:
1486
+ _f.sent();
1487
+ _f.label = 2;
1488
+ case 2: return [2 /*return*/];
1489
+ }
1490
+ });
1491
+ };
1492
+ _e.label = 1;
1493
+ case 1:
1494
+ _e.trys.push([1, 6, 7, 8]);
1495
+ _b = __values(array), _c = _b.next();
1496
+ _e.label = 2;
1497
+ case 2:
1498
+ if (!!_c.done) return [3 /*break*/, 5];
1499
+ item = _c.value;
1500
+ return [5 /*yield**/, _loop_1(item)];
1501
+ case 3:
1502
+ _e.sent();
1503
+ _e.label = 4;
1504
+ case 4:
1505
+ _c = _b.next();
1506
+ return [3 /*break*/, 2];
1507
+ case 5: return [3 /*break*/, 8];
1508
+ case 6:
1509
+ e_1_1 = _e.sent();
1510
+ e_1 = { error: e_1_1 };
1511
+ return [3 /*break*/, 8];
1512
+ case 7:
1513
+ try {
1514
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
1515
+ }
1516
+ finally { if (e_1) throw e_1.error; }
1517
+ return [7 /*endfinally*/];
1518
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
1519
+ case 9:
1520
+ _e.sent();
1521
+ return [2 /*return*/];
1522
+ }
1523
+ });
1524
+ });
1525
+ }
1526
+
1527
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-30",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-30",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-30",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1130
1528
 
1131
1529
  var defaultDiacriticsRemovalMap = [
1132
1530
  {
@@ -1453,6 +1851,14 @@
1453
1851
  * Function normalizes title to name which can be used as identifier
1454
1852
  */
1455
1853
  function titleToName(value) {
1854
+ if (value.startsWith('http://') || value.startsWith('https://')) {
1855
+ // TODO: Maybe check against some list unallowed characters
1856
+ return value;
1857
+ }
1858
+ if (value.startsWith('./') || value.startsWith('../')) {
1859
+ // TODO: Maybe check against some list unallowed characters
1860
+ return value;
1861
+ }
1456
1862
  value = removeEmojis(value);
1457
1863
  value = normalizeToKebabCase(value);
1458
1864
  // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
@@ -1491,7 +1897,11 @@
1491
1897
  throw errors[0];
1492
1898
  }
1493
1899
  else {
1494
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
1900
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
1901
+ .map(function (error, index) {
1902
+ return spaceTrim.spaceTrim(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
1903
+ })
1904
+ .join('\n')), "\n "); }));
1495
1905
  }
1496
1906
  }
1497
1907
  /**
@@ -1499,26 +1909,134 @@
1499
1909
  */
1500
1910
 
1501
1911
  /**
1502
- * This error occurs when some expectation is not met in the execution of the pipeline
1912
+ * Parses the given script and returns the list of all used variables that are not defined in the script
1503
1913
  *
1504
- * @private Always catched and rethrown as `PipelineExecutionError`
1505
- * Note: This is a kindof subtype of PipelineExecutionError
1914
+ * @param script from which to extract the variables
1915
+ * @returns the list of variable names
1916
+ * @throws {ParsingError} if the script is invalid
1506
1917
  */
1507
- var ExpectError = /** @class */ (function (_super) {
1508
- __extends(ExpectError, _super);
1509
- function ExpectError(message) {
1510
- var _this = _super.call(this, message) || this;
1511
- _this.name = 'ExpectError';
1512
- Object.setPrototypeOf(_this, ExpectError.prototype);
1513
- return _this;
1514
- }
1515
- return ExpectError;
1516
- }(Error));
1918
+ function extractVariables(script) {
1919
+ var variables = new Set();
1920
+ script = "(()=>{".concat(script, "})()");
1921
+ try {
1922
+ for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
1923
+ try {
1924
+ eval(script);
1925
+ }
1926
+ catch (error) {
1927
+ if (!(error instanceof ReferenceError)) {
1928
+ throw error;
1929
+ }
1930
+ var undefinedName = error.message.split(' ')[0];
1931
+ /*
1932
+ Note: Parsing the error
1933
+ [ReferenceError: thing is not defined]
1934
+ */
1935
+ if (!undefinedName) {
1936
+ throw error;
1937
+ }
1938
+ if (script.includes(undefinedName + '(')) {
1939
+ script = "const ".concat(undefinedName, " = ()=>'';") + script;
1940
+ }
1941
+ else {
1942
+ variables.add(undefinedName);
1943
+ script = "const ".concat(undefinedName, " = '';") + script;
1944
+ }
1945
+ }
1946
+ }
1947
+ catch (error) {
1948
+ if (!(error instanceof Error)) {
1949
+ throw error;
1950
+ }
1951
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
1952
+ }
1953
+ return variables;
1954
+ }
1955
+ /**
1956
+ * TODO: [🔣] Support for multiple languages - python, java,...
1957
+ */
1958
+
1959
+ /**
1960
+ * Parses the prompt template and returns the set of all used parameters
1961
+ *
1962
+ * @param promptTemplate the template with used parameters
1963
+ * @returns the set of parameter names
1964
+ * @throws {ParsingError} if the script is invalid
1965
+ */
1966
+ function extractParameterNamesFromPromptTemplate(promptTemplate) {
1967
+ var e_1, _a, e_2, _b, e_3, _c;
1968
+ var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
1969
+ var parameterNames = new Set();
1970
+ try {
1971
+ for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
1972
+ var parameterName = _e.value;
1973
+ parameterNames.add(parameterName);
1974
+ }
1975
+ }
1976
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1977
+ finally {
1978
+ try {
1979
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1980
+ }
1981
+ finally { if (e_1) throw e_1.error; }
1982
+ }
1983
+ if (blockType === 'SCRIPT') {
1984
+ try {
1985
+ for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
1986
+ var parameterName = _g.value;
1987
+ parameterNames.add(parameterName);
1988
+ }
1989
+ }
1990
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1991
+ finally {
1992
+ try {
1993
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1994
+ }
1995
+ finally { if (e_2) throw e_2.error; }
1996
+ }
1997
+ }
1998
+ try {
1999
+ for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
2000
+ var jokerName = _j.value;
2001
+ parameterNames.add(jokerName);
2002
+ }
2003
+ }
2004
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2005
+ finally {
2006
+ try {
2007
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
2008
+ }
2009
+ finally { if (e_3) throw e_3.error; }
2010
+ }
2011
+ parameterNames.delete('content');
2012
+ // <- Note {websiteContent} is used in `preparedContent`
2013
+ return parameterNames;
2014
+ }
2015
+ /**
2016
+ * TODO: [🔣] If script require contentLanguage
2017
+ */
2018
+
2019
+ /**
2020
+ * This error occurs when some expectation is not met in the execution of the pipeline
2021
+ *
2022
+ * @private Always catched and rethrown as `PipelineExecutionError`
2023
+ * Note: This is a kindof subtype of PipelineExecutionError
2024
+ */
2025
+ var ExpectError = /** @class */ (function (_super) {
2026
+ __extends(ExpectError, _super);
2027
+ function ExpectError(message) {
2028
+ var _this = _super.call(this, message) || this;
2029
+ _this.name = 'ExpectError';
2030
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2031
+ return _this;
2032
+ }
2033
+ return ExpectError;
2034
+ }(Error));
1517
2035
 
1518
2036
  /**
1519
2037
  * Function isValidJsonString will tell you if the string is valid JSON or not
1520
2038
  */
1521
- function isValidJsonString(value /* <-[👨‍⚖️] */) {
2039
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1522
2040
  try {
1523
2041
  JSON.parse(value);
1524
2042
  return true;
@@ -1661,10 +2179,17 @@
1661
2179
  throw errors[0];
1662
2180
  }
1663
2181
  else if (errors.length > 1) {
1664
- throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
2182
+ throw new PipelineExecutionError(
2183
+ // TODO: Tell which execution tools failed like
2184
+ // 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
2185
+ // 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
2186
+ // 3) ...
2187
+ spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2188
+ .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2189
+ .join('\n')), "\n\n "); }));
1665
2190
  }
1666
2191
  else {
1667
- throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n No execution tools available for model variant \"".concat(prompt.modelRequirements.modelVariant, "\".\n\n tl;dr\n\n You have provided no LLM Execution Tools that support model variant \"").concat(prompt.modelRequirements.modelVariant, ":\n ").concat(block(_this.llmExecutionTools
2192
+ throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
1668
2193
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
1669
2194
  .join('\n')), "\n\n "); }));
1670
2195
  }
@@ -1674,7 +2199,7 @@
1674
2199
  };
1675
2200
  /**
1676
2201
  * List all available models that can be used
1677
- * This liost is a combination of all available models from all execution tools
2202
+ * This lists is a combination of all available models from all execution tools
1678
2203
  */
1679
2204
  MultipleLlmExecutionTools.prototype.listModels = function () {
1680
2205
  return __awaiter(this, void 0, void 0, function () {
@@ -1720,6 +2245,8 @@
1720
2245
  }());
1721
2246
  /**
1722
2247
  * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
2248
+ * TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
2249
+ * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
1723
2250
  */
1724
2251
 
1725
2252
  /**
@@ -1741,7 +2268,7 @@
1741
2268
  llmExecutionTools[_i] = arguments[_i];
1742
2269
  }
1743
2270
  if (llmExecutionTools.length === 0) {
1744
- var warningMessage = spaceTrim__default["default"]("\n You have provided no LLM Execution Tools.\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2271
+ var warningMessage = spaceTrim__default["default"]("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
1745
2272
  // TODO: [🟥] Detect browser / node and make it colorfull
1746
2273
  console.warn(warningMessage);
1747
2274
  /*
@@ -1768,6 +2295,36 @@
1768
2295
  return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
1769
2296
  }
1770
2297
 
2298
+ /**
2299
+ * Determine if the pipeline is fully prepared
2300
+ */
2301
+ function isPipelinePrepared(pipeline) {
2302
+ // Note: Ignoring `pipeline.preparations` @@@
2303
+ // Note: Ignoring `pipeline.knowledgePieces` @@@
2304
+ if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2305
+ return false;
2306
+ }
2307
+ if (!pipeline.knowledgeSources.every(function (knowledgeSource) { return knowledgeSource.preparationIds !== undefined; })) {
2308
+ return false;
2309
+ }
2310
+ /*
2311
+ TODO: [🧠][🍫] `promptTemplates` can not be determined if they are fully prepared SO ignoring them
2312
+ > if (!pipeline.promptTemplates.every(({ preparedContent }) => preparedContent === undefined)) {
2313
+ > return false;
2314
+ > }
2315
+ */
2316
+ return true;
2317
+ }
2318
+ /**
2319
+ * TODO: [🐠] Maybe base this on `makeValidator`
2320
+ * TODO: [🔼] Export via core or utils
2321
+ * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2322
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
2323
+ * - [🏍] ? Is context in each template
2324
+ * - [♨] Are samples prepared
2325
+ * - [♨] Are templates prepared
2326
+ */
2327
+
1771
2328
  /**
1772
2329
  * Takes an item or an array of items and returns an array of items
1773
2330
  *
@@ -1788,106 +2345,197 @@
1788
2345
  }
1789
2346
 
1790
2347
  /**
1791
- * The version of the Promptbook library
2348
+ * Just marks a place of place where should be something implemented
2349
+ * No side effects.
2350
+ *
2351
+ * Note: It can be usefull suppressing eslint errors of unused variables
2352
+ *
2353
+ * @param value any values
2354
+ * @returns void
2355
+ * @private within the repository
1792
2356
  */
1793
- var PROMPTBOOK_VERSION = '0.61.0-8';
1794
- // TODO: !!!! List here all the versions and annotate + put into script
2357
+ function TODO_USE() {
2358
+ var value = [];
2359
+ for (var _i = 0; _i < arguments.length; _i++) {
2360
+ value[_i] = arguments[_i];
2361
+ }
2362
+ }
1795
2363
 
1796
2364
  /**
1797
- * Function `addUsage` will add multiple usages into one
1798
- *
1799
- * Note: If you provide 0 values, it returns void usage
2365
+ * This error type indicates that some limit was reached
1800
2366
  */
1801
- function addUsage() {
1802
- var usageItems = [];
1803
- for (var _i = 0; _i < arguments.length; _i++) {
1804
- usageItems[_i] = arguments[_i];
2367
+ var LimitReachedError = /** @class */ (function (_super) {
2368
+ __extends(LimitReachedError, _super);
2369
+ function LimitReachedError(message) {
2370
+ var _this = _super.call(this, message) || this;
2371
+ _this.name = 'LimitReachedError';
2372
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
2373
+ return _this;
1805
2374
  }
1806
- var initialStructure = {
1807
- price: { value: 0 },
1808
- input: {
1809
- tokensCount: { value: 0 },
1810
- charactersCount: { value: 0 },
1811
- wordsCount: { value: 0 },
1812
- sentencesCount: { value: 0 },
1813
- linesCount: { value: 0 },
1814
- paragraphsCount: { value: 0 },
1815
- pagesCount: { value: 0 },
1816
- },
1817
- output: {
1818
- tokensCount: { value: 0 },
1819
- charactersCount: { value: 0 },
1820
- wordsCount: { value: 0 },
1821
- sentencesCount: { value: 0 },
1822
- linesCount: { value: 0 },
1823
- paragraphsCount: { value: 0 },
1824
- pagesCount: { value: 0 },
1825
- },
1826
- };
1827
- return usageItems.reduce(function (acc, item) {
1828
- var e_1, _a, e_2, _b;
1829
- var _c;
1830
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1831
- try {
1832
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1833
- var key = _e.value;
1834
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1835
- //@ts-ignore
1836
- if (item.input[key]) {
1837
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1838
- //@ts-ignore
1839
- acc.input[key].value += item.input[key].value || 0;
1840
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1841
- //@ts-ignore
1842
- if (item.input[key].isUncertain) {
1843
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1844
- //@ts-ignore
1845
- acc.input[key].isUncertain = true;
1846
- }
1847
- }
2375
+ return LimitReachedError;
2376
+ }(Error));
2377
+
2378
+ /**
2379
+ * Replaces parameters in template with values from parameters object
2380
+ *
2381
+ * @param template the template with parameters in {curly} braces
2382
+ * @param parameters the object with parameters
2383
+ * @returns the template with replaced parameters
2384
+ * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
2385
+ */
2386
+ function replaceParameters(template, parameters) {
2387
+ var e_1, _a;
2388
+ try {
2389
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
2390
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
2391
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
2392
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
1848
2393
  }
1849
- }
1850
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1851
- finally {
1852
- try {
1853
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2394
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
2395
+ // TODO: [🍵]
2396
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
1854
2397
  }
1855
- finally { if (e_1) throw e_1.error; }
1856
2398
  }
2399
+ }
2400
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2401
+ finally {
1857
2402
  try {
1858
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1859
- var key = _g.value;
1860
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1861
- //@ts-ignore
1862
- if (item.output[key]) {
1863
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1864
- //@ts-ignore
1865
- acc.output[key].value += item.output[key].value || 0;
1866
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1867
- //@ts-ignore
1868
- if (item.output[key].isUncertain) {
1869
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1870
- //@ts-ignore
1871
- acc.output[key].isUncertain = true;
1872
- }
1873
- }
1874
- }
2403
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1875
2404
  }
1876
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1877
- finally {
1878
- try {
1879
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1880
- }
1881
- finally { if (e_2) throw e_2.error; }
2405
+ finally { if (e_1) throw e_1.error; }
2406
+ }
2407
+ var replacedTemplate = template;
2408
+ var match;
2409
+ var loopLimit = LOOP_LIMIT;
2410
+ var _loop_1 = function () {
2411
+ if (loopLimit-- < 0) {
2412
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
1882
2413
  }
1883
- return acc;
1884
- }, initialStructure);
2414
+ var precol = match.groups.precol;
2415
+ var parameterName = match.groups.parameterName;
2416
+ if (parameterName === '') {
2417
+ return "continue";
2418
+ }
2419
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
2420
+ throw new PipelineExecutionError('Parameter is already opened or not closed');
2421
+ }
2422
+ if (parameters[parameterName] === undefined) {
2423
+ throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
2424
+ }
2425
+ var parameterValue = parameters[parameterName];
2426
+ if (parameterValue === undefined) {
2427
+ throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
2428
+ }
2429
+ parameterValue = parameterValue.toString();
2430
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2431
+ parameterValue = parameterValue
2432
+ .split('\n')
2433
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
2434
+ .join('\n');
2435
+ }
2436
+ replacedTemplate =
2437
+ replacedTemplate.substring(0, match.index + precol.length) +
2438
+ parameterValue +
2439
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
2440
+ };
2441
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
2442
+ .exec(replacedTemplate))) {
2443
+ _loop_1();
2444
+ }
2445
+ // [💫] Check if there are parameters that are not closed properly
2446
+ if (/{\w+$/.test(replacedTemplate)) {
2447
+ throw new PipelineExecutionError('Parameter is not closed');
2448
+ }
2449
+ // [💫] Check if there are parameters that are not opened properly
2450
+ if (/^\w+}/.test(replacedTemplate)) {
2451
+ throw new PipelineExecutionError('Parameter is not opened');
2452
+ }
2453
+ return replacedTemplate;
1885
2454
  }
1886
2455
 
1887
2456
  /**
1888
- * Counts number of characters in the text
2457
+ * Create difference set of two sets.
2458
+ *
2459
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1889
2460
  */
1890
- function countCharacters(text) {
2461
+ function difference(a, b, isEqual) {
2462
+ var e_1, _a;
2463
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2464
+ var diff = new Set();
2465
+ var _loop_1 = function (itemA) {
2466
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2467
+ diff.add(itemA);
2468
+ }
2469
+ };
2470
+ try {
2471
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2472
+ var itemA = _c.value;
2473
+ _loop_1(itemA);
2474
+ }
2475
+ }
2476
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2477
+ finally {
2478
+ try {
2479
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2480
+ }
2481
+ finally { if (e_1) throw e_1.error; }
2482
+ }
2483
+ return diff;
2484
+ }
2485
+ /**
2486
+ * TODO: [🧠][💯] Maybe also implement symmetricDifference
2487
+ */
2488
+
2489
+ /**
2490
+ * Creates a new set with all elements that are present in either set
2491
+ *
2492
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2493
+ */
2494
+ function union() {
2495
+ var e_1, _a, e_2, _b;
2496
+ var sets = [];
2497
+ for (var _i = 0; _i < arguments.length; _i++) {
2498
+ sets[_i] = arguments[_i];
2499
+ }
2500
+ var union = new Set();
2501
+ try {
2502
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2503
+ var set = sets_1_1.value;
2504
+ try {
2505
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2506
+ var item = _d.value;
2507
+ union.add(item);
2508
+ }
2509
+ }
2510
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2511
+ finally {
2512
+ try {
2513
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2514
+ }
2515
+ finally { if (e_2) throw e_2.error; }
2516
+ }
2517
+ }
2518
+ }
2519
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2520
+ finally {
2521
+ try {
2522
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2523
+ }
2524
+ finally { if (e_1) throw e_1.error; }
2525
+ }
2526
+ return union;
2527
+ }
2528
+
2529
+ /**
2530
+ * The version of the Promptbook library
2531
+ */
2532
+ var PROMPTBOOK_VERSION = '0.61.0-30';
2533
+ // TODO: !!!! List here all the versions and annotate + put into script
2534
+
2535
+ /**
2536
+ * Counts number of characters in the text
2537
+ */
2538
+ function countCharacters(text) {
1891
2539
  // Remove null characters
1892
2540
  text = text.replace(/\0/g, '');
1893
2541
  // Replace emojis (and also ZWJ sequence) with hyphens
@@ -2015,66 +2663,6 @@
2015
2663
  * TODO: [💝] Unite object for expecting amount and format
2016
2664
  */
2017
2665
 
2018
- /**
2019
- * Replaces parameters in template with values from parameters object
2020
- *
2021
- * @param template the template with parameters in {curly} braces
2022
- * @param parameters the object with parameters
2023
- * @returns the template with replaced parameters
2024
- * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
2025
- *
2026
- * @private within the createPipelineExecutor
2027
- */
2028
- function replaceParameters(template, parameters) {
2029
- var replacedTemplate = template;
2030
- var match;
2031
- var loopLimit = LOOP_LIMIT;
2032
- var _loop_1 = function () {
2033
- if (loopLimit-- < 0) {
2034
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
2035
- }
2036
- var precol = match.groups.precol;
2037
- var parameterName = match.groups.parameterName;
2038
- if (parameterName === '') {
2039
- return "continue";
2040
- }
2041
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
2042
- throw new PipelineExecutionError('Parameter is already opened or not closed');
2043
- }
2044
- if (parameters[parameterName] === undefined) {
2045
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
2046
- }
2047
- var parameterValue = parameters[parameterName];
2048
- if (parameterValue === undefined) {
2049
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
2050
- }
2051
- parameterValue = parameterValue.toString();
2052
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2053
- parameterValue = parameterValue
2054
- .split('\n')
2055
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
2056
- .join('\n');
2057
- }
2058
- replacedTemplate =
2059
- replacedTemplate.substring(0, match.index + precol.length) +
2060
- parameterValue +
2061
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
2062
- };
2063
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
2064
- .exec(replacedTemplate))) {
2065
- _loop_1();
2066
- }
2067
- // [💫] Check if there are parameters that are not closed properly
2068
- if (/{\w+$/.test(replacedTemplate)) {
2069
- throw new PipelineExecutionError('Parameter is not closed');
2070
- }
2071
- // [💫] Check if there are parameters that are not opened properly
2072
- if (/^\w+}/.test(replacedTemplate)) {
2073
- throw new PipelineExecutionError('Parameter is not opened');
2074
- }
2075
- return replacedTemplate;
2076
- }
2077
-
2078
2666
  /**
2079
2667
  * Creates executor function from pipeline and execution tools.
2080
2668
  *
@@ -2084,24 +2672,107 @@
2084
2672
  function createPipelineExecutor(options) {
2085
2673
  var _this = this;
2086
2674
  var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
2087
- var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
2088
- // TODO: !!!!! Implement new commands
2675
+ var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? false : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
2089
2676
  validatePipeline(pipeline);
2090
- // TODO: !!!!! Do here materialization of still unmaterialized or dynamic knowledge
2091
- // TODO: !!!!! Do here personaToModelRequirements
2092
2677
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
2678
+ var preparedPipeline;
2679
+ if (isPipelinePrepared(pipeline)) {
2680
+ preparedPipeline = pipeline;
2681
+ }
2682
+ else if (isNotPreparedWarningSupressed !== true) {
2683
+ console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2684
+ }
2093
2685
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2686
+ // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
2687
+ function getContextForTemplate(// <- TODO: [🧠][🥜]
2688
+ template) {
2689
+ return __awaiter(this, void 0, void 0, function () {
2690
+ return __generator(this, function (_a) {
2691
+ TODO_USE(template);
2692
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
2693
+ });
2694
+ });
2695
+ }
2696
+ function getKnowledgeForTemplate(// <- TODO: [🧠][🥜]
2697
+ template) {
2698
+ return __awaiter(this, void 0, void 0, function () {
2699
+ return __generator(this, function (_a) {
2700
+ // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
2701
+ TODO_USE(template);
2702
+ return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
2703
+ var content = _a.content;
2704
+ return "- ".concat(content);
2705
+ }).join('\n')];
2706
+ });
2707
+ });
2708
+ }
2709
+ function getSamplesForTemplate(// <- TODO: [🧠][🥜]
2710
+ template) {
2711
+ return __awaiter(this, void 0, void 0, function () {
2712
+ return __generator(this, function (_a) {
2713
+ // TODO: [♨] Implement Better - use real index and keyword search
2714
+ TODO_USE(template);
2715
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
2716
+ });
2717
+ });
2718
+ }
2719
+ function getReservedParametersForTemplate(template) {
2720
+ return __awaiter(this, void 0, void 0, function () {
2721
+ var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
2722
+ var e_3, _a;
2723
+ return __generator(this, function (_b) {
2724
+ switch (_b.label) {
2725
+ case 0: return [4 /*yield*/, getContextForTemplate(template)];
2726
+ case 1:
2727
+ context = _b.sent();
2728
+ return [4 /*yield*/, getKnowledgeForTemplate(template)];
2729
+ case 2:
2730
+ knowledge = _b.sent();
2731
+ return [4 /*yield*/, getSamplesForTemplate(template)];
2732
+ case 3:
2733
+ samples = _b.sent();
2734
+ currentDate = new Date().toISOString();
2735
+ modelName = RESERVED_PARAMETER_MISSING_VALUE;
2736
+ reservedParameters = {
2737
+ content: RESERVED_PARAMETER_RESTRICTED,
2738
+ context: context,
2739
+ knowledge: knowledge,
2740
+ samples: samples,
2741
+ currentDate: currentDate,
2742
+ modelName: modelName,
2743
+ };
2744
+ try {
2745
+ // Note: Doublecheck that ALL reserved parameters are defined:
2746
+ for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
2747
+ parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
2748
+ if (reservedParameters[parameterName] === undefined) {
2749
+ throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
2750
+ }
2751
+ }
2752
+ }
2753
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2754
+ finally {
2755
+ try {
2756
+ if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
2757
+ }
2758
+ finally { if (e_3) throw e_3.error; }
2759
+ }
2760
+ return [2 /*return*/, reservedParameters];
2761
+ }
2762
+ });
2763
+ });
2764
+ }
2094
2765
  function executeSingleTemplate(currentTemplate) {
2095
2766
  return __awaiter(this, void 0, void 0, function () {
2096
- var name, title, priority, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
2097
- var e_2, _j, e_4, _k, e_3, _l, _m;
2767
+ var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
2768
+ var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2098
2769
  var _this = this;
2099
- return __generator(this, function (_o) {
2100
- switch (_o.label) {
2770
+ return __generator(this, function (_u) {
2771
+ switch (_u.label) {
2101
2772
  case 0:
2102
2773
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
2103
2774
  title = currentTemplate.title;
2104
- priority = pipeline.promptTemplates.length - pipeline.promptTemplates.indexOf(currentTemplate);
2775
+ priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
2105
2776
  if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
2106
2777
  return [4 /*yield*/, onProgress({
2107
2778
  name: name,
@@ -2114,61 +2785,111 @@
2114
2785
  // <- [3]
2115
2786
  })];
2116
2787
  case 1:
2117
- _o.sent();
2118
- _o.label = 2;
2788
+ _u.sent();
2789
+ _u.label = 2;
2119
2790
  case 2:
2791
+ usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
2792
+ dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
2793
+ if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
2794
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
2795
+ }
2796
+ _b = (_a = Object).freeze;
2797
+ _c = [{}];
2798
+ return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
2799
+ case 3:
2800
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
2801
+ definedParameterNames = new Set(Object.keys(definedParameters));
2802
+ parameters = {};
2803
+ try {
2804
+ // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
2805
+ for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
2806
+ parameterName = _e.value;
2807
+ // Situation: Parameter is defined and used
2808
+ if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
2809
+ parameters[parameterName] = definedParameters[parameterName];
2810
+ }
2811
+ // Situation: Parameter is defined but NOT used
2812
+ else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
2813
+ // Do not pass this parameter to prompt
2814
+ }
2815
+ // Situation: Parameter is NOT defined BUT used
2816
+ else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
2817
+ // Houston, we have a problem
2818
+ // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
2819
+ throw new UnexpectedError(spaceTrim.spaceTrim("\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 ")));
2820
+ }
2821
+ }
2822
+ }
2823
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
2824
+ finally {
2825
+ try {
2826
+ if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
2827
+ }
2828
+ finally { if (e_7) throw e_7.error; }
2829
+ }
2830
+ // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
2831
+ Object.freeze(parameters);
2120
2832
  result = null;
2121
2833
  resultString = null;
2122
2834
  expectError = null;
2123
2835
  maxAttempts = currentTemplate.blockType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
2124
- jokers = currentTemplate.jokers || [];
2125
- attempt = -jokers.length;
2126
- _o.label = 3;
2127
- case 3:
2128
- if (!(attempt < maxAttempts)) return [3 /*break*/, 51];
2836
+ jokerParameterNames = currentTemplate.jokerParameterNames || [];
2837
+ preparedContent = (currentTemplate.preparedContent || '{content}')
2838
+ .split('{content}')
2839
+ .join(currentTemplate.content);
2840
+ attempt = -jokerParameterNames.length;
2841
+ _u.label = 4;
2842
+ case 4:
2843
+ if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
2129
2844
  isJokerAttempt = attempt < 0;
2130
- joker = jokers[jokers.length + attempt];
2131
- if (isJokerAttempt && !joker) {
2845
+ jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
2846
+ if (isJokerAttempt && !jokerParameterName) {
2132
2847
  throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
2133
2848
  }
2134
2849
  result = null;
2135
2850
  resultString = null;
2136
2851
  expectError = null;
2137
2852
  if (isJokerAttempt) {
2138
- if (typeof parametersToPass[joker] === 'undefined') {
2139
- throw new PipelineExecutionError("Joker parameter {".concat(joker, "} not defined"));
2853
+ if (parameters[jokerParameterName] === undefined) {
2854
+ throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
2855
+ // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
2856
+ }
2857
+ else {
2858
+ resultString = parameters[jokerParameterName];
2140
2859
  }
2141
- resultString = parametersToPass[joker];
2142
- }
2143
- _o.label = 4;
2144
- case 4:
2145
- _o.trys.push([4, 47, 48, 49]);
2146
- if (!!isJokerAttempt) return [3 /*break*/, 29];
2147
- _a = currentTemplate.blockType;
2148
- switch (_a) {
2149
- case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
2150
- case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
2151
- case 'SCRIPT': return [3 /*break*/, 15];
2152
- case 'PROMPT_DIALOG': return [3 /*break*/, 26];
2153
2860
  }
2154
- return [3 /*break*/, 28];
2861
+ _u.label = 5;
2155
2862
  case 5:
2156
- resultString = replaceParameters(currentTemplate.content, parametersToPass);
2863
+ _u.trys.push([5, 48, 49, 50]);
2864
+ if (!!isJokerAttempt) return [3 /*break*/, 30];
2865
+ _f = currentTemplate.blockType;
2866
+ switch (_f) {
2867
+ case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
2868
+ case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
2869
+ case 'SCRIPT': return [3 /*break*/, 16];
2870
+ case 'PROMPT_DIALOG': return [3 /*break*/, 27];
2871
+ }
2157
2872
  return [3 /*break*/, 29];
2158
2873
  case 6:
2874
+ resultString = replaceParameters(preparedContent, parameters);
2875
+ return [3 /*break*/, 30];
2876
+ case 7:
2159
2877
  prompt = {
2160
2878
  title: currentTemplate.title,
2161
- pipelineUrl: "".concat(pipeline.pipelineUrl
2162
- ? pipeline.pipelineUrl
2879
+ pipelineUrl: "".concat(preparedPipeline.pipelineUrl
2880
+ ? preparedPipeline.pipelineUrl
2163
2881
  : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2164
- parameters: parametersToPass,
2165
- content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
2882
+ parameters: parameters,
2883
+ content: preparedContent,
2166
2884
  modelRequirements: currentTemplate.modelRequirements,
2167
- expectations: currentTemplate.expectations,
2885
+ expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
2886
+ var name = _a.name;
2887
+ return name === currentTemplate.personaName;
2888
+ }) || {})), currentTemplate.expectations),
2168
2889
  expectFormat: currentTemplate.expectFormat,
2169
- postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
2170
- var errors, _a, _b, scriptTools, error_5, e_5_1;
2171
- var e_5, _c;
2890
+ postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
2891
+ var errors, _a, _b, scriptTools, error_5, e_8_1;
2892
+ var e_8, _c;
2172
2893
  return __generator(this, function (_d) {
2173
2894
  switch (_d.label) {
2174
2895
  case 0:
@@ -2189,7 +2910,7 @@
2189
2910
  script: "".concat(functionName, "(result)"),
2190
2911
  parameters: {
2191
2912
  result: result || '',
2192
- // Note: No ...parametersToPass, because working with result only
2913
+ // Note: No ...parametersForTemplate, because working with result only
2193
2914
  },
2194
2915
  })];
2195
2916
  case 4: return [2 /*return*/, _d.sent()];
@@ -2198,6 +2919,9 @@
2198
2919
  if (!(error_5 instanceof Error)) {
2199
2920
  throw error_5;
2200
2921
  }
2922
+ if (error_5 instanceof UnexpectedError) {
2923
+ throw error_5;
2924
+ }
2201
2925
  errors.push(error_5);
2202
2926
  return [3 /*break*/, 6];
2203
2927
  case 6:
@@ -2205,14 +2929,14 @@
2205
2929
  return [3 /*break*/, 2];
2206
2930
  case 7: return [3 /*break*/, 10];
2207
2931
  case 8:
2208
- e_5_1 = _d.sent();
2209
- e_5 = { error: e_5_1 };
2932
+ e_8_1 = _d.sent();
2933
+ e_8 = { error: e_8_1 };
2210
2934
  return [3 /*break*/, 10];
2211
2935
  case 9:
2212
2936
  try {
2213
2937
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2214
2938
  }
2215
- finally { if (e_5) throw e_5.error; }
2939
+ finally { if (e_8) throw e_8.error; }
2216
2940
  return [7 /*endfinally*/];
2217
2941
  case 10:
2218
2942
  if (errors.length === 0) {
@@ -2228,35 +2952,35 @@
2228
2952
  });
2229
2953
  }); }; }),
2230
2954
  };
2231
- _b = currentTemplate.modelRequirements.modelVariant;
2232
- switch (_b) {
2233
- case 'CHAT': return [3 /*break*/, 7];
2234
- case 'COMPLETION': return [3 /*break*/, 9];
2235
- case 'EMBEDDING': return [3 /*break*/, 11];
2955
+ _g = currentTemplate.modelRequirements.modelVariant;
2956
+ switch (_g) {
2957
+ case 'CHAT': return [3 /*break*/, 8];
2958
+ case 'COMPLETION': return [3 /*break*/, 10];
2959
+ case 'EMBEDDING': return [3 /*break*/, 12];
2236
2960
  }
2237
- return [3 /*break*/, 13];
2238
- case 7: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2239
- case 8:
2240
- chatResult = _o.sent();
2961
+ return [3 /*break*/, 14];
2962
+ case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
2963
+ case 9:
2964
+ chatResult = _u.sent();
2241
2965
  // TODO: [🍬] Destroy chatThread
2242
2966
  result = chatResult;
2243
2967
  resultString = chatResult.content;
2244
- return [3 /*break*/, 14];
2245
- case 9: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2246
- case 10:
2247
- completionResult = _o.sent();
2968
+ return [3 /*break*/, 15];
2969
+ case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
2970
+ case 11:
2971
+ completionResult = _u.sent();
2248
2972
  result = completionResult;
2249
2973
  resultString = completionResult.content;
2250
- return [3 /*break*/, 14];
2251
- case 11: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2252
- case 12:
2253
- embeddingResult = _o.sent();
2974
+ return [3 /*break*/, 15];
2975
+ case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
2976
+ case 13:
2977
+ embeddingResult = _u.sent();
2254
2978
  result = embeddingResult;
2255
2979
  resultString = embeddingResult.content.join(',');
2256
- return [3 /*break*/, 14];
2257
- case 13: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
2258
- case 14: return [3 /*break*/, 29];
2259
- case 15:
2980
+ return [3 /*break*/, 15];
2981
+ case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
2982
+ case 15: return [3 /*break*/, 30];
2983
+ case 16:
2260
2984
  if (arrayableToArray(tools.script).length === 0) {
2261
2985
  throw new PipelineExecutionError('No script execution tools are available');
2262
2986
  }
@@ -2265,49 +2989,52 @@
2265
2989
  }
2266
2990
  // TODO: DRY [1]
2267
2991
  scriptPipelineExecutionErrors = [];
2268
- _o.label = 16;
2269
- case 16:
2270
- _o.trys.push([16, 23, 24, 25]);
2271
- _c = (e_2 = void 0, __values(arrayableToArray(tools.script))), _d = _c.next();
2272
- _o.label = 17;
2992
+ _u.label = 17;
2273
2993
  case 17:
2274
- if (!!_d.done) return [3 /*break*/, 22];
2275
- scriptTools = _d.value;
2276
- _o.label = 18;
2994
+ _u.trys.push([17, 24, 25, 26]);
2995
+ _h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
2996
+ _u.label = 18;
2277
2997
  case 18:
2278
- _o.trys.push([18, 20, , 21]);
2279
- return [4 /*yield*/, scriptTools.execute({
2280
- scriptLanguage: currentTemplate.contentLanguage,
2281
- script: currentTemplate.content,
2282
- parameters: parametersToPass,
2283
- })];
2998
+ if (!!_j.done) return [3 /*break*/, 23];
2999
+ scriptTools = _j.value;
3000
+ _u.label = 19;
2284
3001
  case 19:
2285
- resultString = _o.sent();
2286
- return [3 /*break*/, 22];
3002
+ _u.trys.push([19, 21, , 22]);
3003
+ return [4 /*yield*/, scriptTools.execute(deepFreeze({
3004
+ scriptLanguage: currentTemplate.contentLanguage,
3005
+ script: preparedContent,
3006
+ parameters: parameters,
3007
+ }))];
2287
3008
  case 20:
2288
- error_2 = _o.sent();
3009
+ resultString = _u.sent();
3010
+ return [3 /*break*/, 23];
3011
+ case 21:
3012
+ error_2 = _u.sent();
2289
3013
  if (!(error_2 instanceof Error)) {
2290
3014
  throw error_2;
2291
3015
  }
3016
+ if (error_2 instanceof UnexpectedError) {
3017
+ throw error_2;
3018
+ }
2292
3019
  scriptPipelineExecutionErrors.push(error_2);
2293
- return [3 /*break*/, 21];
2294
- case 21:
2295
- _d = _c.next();
2296
- return [3 /*break*/, 17];
2297
- case 22: return [3 /*break*/, 25];
2298
- case 23:
2299
- e_2_1 = _o.sent();
2300
- e_2 = { error: e_2_1 };
2301
- return [3 /*break*/, 25];
3020
+ return [3 /*break*/, 22];
3021
+ case 22:
3022
+ _j = _h.next();
3023
+ return [3 /*break*/, 18];
3024
+ case 23: return [3 /*break*/, 26];
2302
3025
  case 24:
3026
+ e_4_1 = _u.sent();
3027
+ e_4 = { error: e_4_1 };
3028
+ return [3 /*break*/, 26];
3029
+ case 25:
2303
3030
  try {
2304
- if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
3031
+ if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
2305
3032
  }
2306
- finally { if (e_2) throw e_2.error; }
3033
+ finally { if (e_4) throw e_4.error; }
2307
3034
  return [7 /*endfinally*/];
2308
- case 25:
3035
+ case 26:
2309
3036
  if (resultString !== null) {
2310
- return [3 /*break*/, 29];
3037
+ return [3 /*break*/, 30];
2311
3038
  }
2312
3039
  if (scriptPipelineExecutionErrors.length === 1) {
2313
3040
  throw scriptPipelineExecutionErrors[0];
@@ -2317,101 +3044,104 @@
2317
3044
  .map(function (error) { return '- ' + error.message; })
2318
3045
  .join('\n\n')), "\n "); }));
2319
3046
  }
2320
- case 26:
3047
+ case 27:
2321
3048
  if (tools.userInterface === undefined) {
2322
3049
  throw new PipelineExecutionError('User interface tools are not available');
2323
3050
  }
2324
- return [4 /*yield*/, tools.userInterface.promptDialog({
3051
+ return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
2325
3052
  promptTitle: currentTemplate.title,
2326
- promptMessage: replaceParameters(currentTemplate.description || '', parametersToPass),
2327
- defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
3053
+ promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3054
+ defaultValue: replaceParameters(preparedContent, parameters),
2328
3055
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
2329
3056
  placeholder: undefined,
2330
3057
  priority: priority,
2331
- })];
2332
- case 27:
3058
+ }))];
3059
+ case 28:
2333
3060
  // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
2334
- resultString = _o.sent();
2335
- return [3 /*break*/, 29];
2336
- case 28: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
2337
- case 29:
2338
- if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 46];
2339
- _o.label = 30;
3061
+ resultString = _u.sent();
3062
+ return [3 /*break*/, 30];
3063
+ case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
2340
3064
  case 30:
2341
- _o.trys.push([30, 44, 45, 46]);
2342
- _e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
2343
- _o.label = 31;
3065
+ if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
3066
+ _u.label = 31;
2344
3067
  case 31:
2345
- if (!!_f.done) return [3 /*break*/, 43];
2346
- functionName = _f.value;
3068
+ _u.trys.push([31, 45, 46, 47]);
3069
+ _k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
3070
+ _u.label = 32;
3071
+ case 32:
3072
+ if (!!_l.done) return [3 /*break*/, 44];
3073
+ functionName = _l.value;
2347
3074
  // TODO: DRY [1]
2348
3075
  scriptPipelineExecutionErrors = [];
2349
3076
  postprocessingError = null;
2350
- _o.label = 32;
2351
- case 32:
2352
- _o.trys.push([32, 39, 40, 41]);
2353
- _g = (e_3 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
2354
- _o.label = 33;
3077
+ _u.label = 33;
2355
3078
  case 33:
2356
- if (!!_h.done) return [3 /*break*/, 38];
2357
- scriptTools = _h.value;
2358
- _o.label = 34;
3079
+ _u.trys.push([33, 40, 41, 42]);
3080
+ _m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
3081
+ _u.label = 34;
2359
3082
  case 34:
2360
- _o.trys.push([34, 36, , 37]);
3083
+ if (!!_o.done) return [3 /*break*/, 39];
3084
+ scriptTools = _o.value;
3085
+ _u.label = 35;
3086
+ case 35:
3087
+ _u.trys.push([35, 37, , 38]);
2361
3088
  return [4 /*yield*/, scriptTools.execute({
2362
3089
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
2363
3090
  script: "".concat(functionName, "(resultString)"),
2364
3091
  parameters: {
2365
3092
  resultString: resultString || '',
2366
- // Note: No ...parametersToPass, because working with result only
3093
+ // Note: No ...parametersForTemplate, because working with result only
2367
3094
  },
2368
3095
  })];
2369
- case 35:
2370
- resultString = _o.sent();
2371
- postprocessingError = null;
2372
- return [3 /*break*/, 38];
2373
3096
  case 36:
2374
- error_3 = _o.sent();
3097
+ resultString = _u.sent();
3098
+ postprocessingError = null;
3099
+ return [3 /*break*/, 39];
3100
+ case 37:
3101
+ error_3 = _u.sent();
2375
3102
  if (!(error_3 instanceof Error)) {
2376
3103
  throw error_3;
2377
3104
  }
3105
+ if (error_3 instanceof UnexpectedError) {
3106
+ throw error_3;
3107
+ }
2378
3108
  postprocessingError = error_3;
2379
3109
  scriptPipelineExecutionErrors.push(error_3);
2380
- return [3 /*break*/, 37];
2381
- case 37:
2382
- _h = _g.next();
2383
- return [3 /*break*/, 33];
2384
- case 38: return [3 /*break*/, 41];
2385
- case 39:
2386
- e_3_1 = _o.sent();
2387
- e_3 = { error: e_3_1 };
2388
- return [3 /*break*/, 41];
3110
+ return [3 /*break*/, 38];
3111
+ case 38:
3112
+ _o = _m.next();
3113
+ return [3 /*break*/, 34];
3114
+ case 39: return [3 /*break*/, 42];
2389
3115
  case 40:
3116
+ e_5_1 = _u.sent();
3117
+ e_5 = { error: e_5_1 };
3118
+ return [3 /*break*/, 42];
3119
+ case 41:
2390
3120
  try {
2391
- if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
3121
+ if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
2392
3122
  }
2393
- finally { if (e_3) throw e_3.error; }
3123
+ finally { if (e_5) throw e_5.error; }
2394
3124
  return [7 /*endfinally*/];
2395
- case 41:
3125
+ case 42:
2396
3126
  if (postprocessingError) {
2397
3127
  throw postprocessingError;
2398
3128
  }
2399
- _o.label = 42;
2400
- case 42:
2401
- _f = _e.next();
2402
- return [3 /*break*/, 31];
2403
- case 43: return [3 /*break*/, 46];
2404
- case 44:
2405
- e_4_1 = _o.sent();
2406
- e_4 = { error: e_4_1 };
2407
- return [3 /*break*/, 46];
3129
+ _u.label = 43;
3130
+ case 43:
3131
+ _l = _k.next();
3132
+ return [3 /*break*/, 32];
3133
+ case 44: return [3 /*break*/, 47];
2408
3134
  case 45:
3135
+ e_6_1 = _u.sent();
3136
+ e_6 = { error: e_6_1 };
3137
+ return [3 /*break*/, 47];
3138
+ case 46:
2409
3139
  try {
2410
- if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
3140
+ if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
2411
3141
  }
2412
- finally { if (e_4) throw e_4.error; }
3142
+ finally { if (e_6) throw e_6.error; }
2413
3143
  return [7 /*endfinally*/];
2414
- case 46:
3144
+ case 47:
2415
3145
  // TODO: [💝] Unite object for expecting amount and format
2416
3146
  if (currentTemplate.expectFormat) {
2417
3147
  if (currentTemplate.expectFormat === 'JSON') {
@@ -2424,15 +3154,18 @@
2424
3154
  if (currentTemplate.expectations) {
2425
3155
  checkExpectations(currentTemplate.expectations, resultString || '');
2426
3156
  }
2427
- return [3 /*break*/, 51];
2428
- case 47:
2429
- error_4 = _o.sent();
3157
+ return [3 /*break*/, 52];
3158
+ case 48:
3159
+ error_4 = _u.sent();
2430
3160
  if (!(error_4 instanceof ExpectError)) {
2431
3161
  throw error_4;
2432
3162
  }
3163
+ if (error_4 instanceof UnexpectedError) {
3164
+ throw error_4;
3165
+ }
2433
3166
  expectError = error_4;
2434
- return [3 /*break*/, 49];
2435
- case 48:
3167
+ return [3 /*break*/, 50];
3168
+ case 49:
2436
3169
  if (!isJokerAttempt &&
2437
3170
  currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
2438
3171
  prompt
@@ -2441,28 +3174,21 @@
2441
3174
  ) {
2442
3175
  // TODO: [🧠] Maybe put other blockTypes into report
2443
3176
  executionReport.promptExecutions.push({
2444
- prompt: {
2445
- title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */,
2446
- content: prompt.content,
2447
- modelRequirements: prompt.modelRequirements,
2448
- expectations: prompt.expectations,
2449
- expectFormat: prompt.expectFormat,
2450
- // <- Note: Do want to pass ONLY wanted information to the report
2451
- },
3177
+ prompt: __assign({}, prompt),
2452
3178
  result: result || undefined,
2453
3179
  error: expectError || undefined,
2454
3180
  });
2455
3181
  }
2456
3182
  return [7 /*endfinally*/];
2457
- case 49:
3183
+ case 50:
2458
3184
  if (expectError !== null && attempt === maxAttempts - 1) {
2459
3185
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
2460
3186
  }
2461
- _o.label = 50;
2462
- case 50:
2463
- attempt++;
2464
- return [3 /*break*/, 3];
3187
+ _u.label = 51;
2465
3188
  case 51:
3189
+ attempt++;
3190
+ return [3 /*break*/, 4];
3191
+ case 52:
2466
3192
  if (resultString === null) {
2467
3193
  throw new UnexpectedError('Something went wrong and prompt result is null');
2468
3194
  }
@@ -2478,30 +3204,136 @@
2478
3204
  // <- [3]
2479
3205
  });
2480
3206
  }
2481
- parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _m));
3207
+ parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_t = {}, _t[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _t)));
2482
3208
  return [2 /*return*/];
2483
3209
  }
2484
3210
  });
2485
3211
  });
2486
3212
  }
2487
- var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, _a, _b, parameter, usage;
2488
- var e_1, _c;
2489
- return __generator(this, function (_d) {
2490
- switch (_d.label) {
3213
+ function filterJustOutputParameters() {
3214
+ var e_9, _a;
3215
+ var outputParameters = {};
3216
+ try {
3217
+ // Note: Filter ONLY output parameters
3218
+ for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
3219
+ var isOutput = _a.isOutput;
3220
+ return isOutput;
3221
+ })), _c = _b.next(); !_c.done; _c = _b.next()) {
3222
+ var parameter = _c.value;
3223
+ if (parametersToPass[parameter.name] === undefined) {
3224
+ // [4]
3225
+ warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
3226
+ continue;
3227
+ }
3228
+ outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
3229
+ }
3230
+ }
3231
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
3232
+ finally {
3233
+ try {
3234
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3235
+ }
3236
+ finally { if (e_9) throw e_9.error; }
3237
+ }
3238
+ return outputParameters;
3239
+ }
3240
+ var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
3241
+ var e_1, _e, e_2, _f;
3242
+ return __generator(this, function (_g) {
3243
+ switch (_g.label) {
2491
3244
  case 0:
2492
- parametersToPass = inputParameters;
3245
+ if (!(preparedPipeline === undefined)) return [3 /*break*/, 2];
3246
+ return [4 /*yield*/, preparePipeline(pipeline, {
3247
+ llmTools: llmTools,
3248
+ isVerbose: isVerbose,
3249
+ maxParallelCount: maxParallelCount,
3250
+ })];
3251
+ case 1:
3252
+ preparedPipeline = _g.sent();
3253
+ _g.label = 2;
3254
+ case 2:
3255
+ errors = [];
3256
+ warnings = [];
2493
3257
  executionReport = {
2494
- pipelineUrl: pipeline.pipelineUrl,
2495
- title: pipeline.title,
3258
+ pipelineUrl: preparedPipeline.pipelineUrl,
3259
+ title: preparedPipeline.title,
2496
3260
  promptbookUsedVersion: PROMPTBOOK_VERSION,
2497
- promptbookRequestedVersion: pipeline.promptbookVersion,
2498
- description: pipeline.description,
3261
+ promptbookRequestedVersion: preparedPipeline.promptbookVersion,
3262
+ description: preparedPipeline.description,
2499
3263
  promptExecutions: [],
2500
3264
  };
2501
- _d.label = 1;
2502
- case 1:
2503
- _d.trys.push([1, 6, , 7]);
2504
- resovedParameters_1 = pipeline.parameters
3265
+ try {
3266
+ // Note: Check that all input input parameters are defined
3267
+ for (_a = __values(preparedPipeline.parameters.filter(function (_a) {
3268
+ var isInput = _a.isInput;
3269
+ return isInput;
3270
+ })), _b = _a.next(); !_b.done; _b = _a.next()) {
3271
+ parameter = _b.value;
3272
+ if (inputParameters[parameter.name] === undefined) {
3273
+ return [2 /*return*/, deepFreezeWithSameType({
3274
+ isSuccessful: false,
3275
+ errors: __spreadArray([
3276
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3277
+ ], __read(errors), false),
3278
+ warnings: [],
3279
+ executionReport: executionReport,
3280
+ outputParameters: {},
3281
+ usage: ZERO_USAGE,
3282
+ preparedPipeline: preparedPipeline,
3283
+ })];
3284
+ }
3285
+ }
3286
+ }
3287
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3288
+ finally {
3289
+ try {
3290
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
3291
+ }
3292
+ finally { if (e_1) throw e_1.error; }
3293
+ }
3294
+ _loop_1 = function (parameterName) {
3295
+ var parameter = preparedPipeline.parameters.find(function (_a) {
3296
+ var name = _a.name;
3297
+ return name === parameterName;
3298
+ });
3299
+ if (parameter === undefined) {
3300
+ warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3301
+ }
3302
+ else if (parameter.isInput === false) {
3303
+ return { value: deepFreezeWithSameType({
3304
+ isSuccessful: false,
3305
+ errors: __spreadArray([
3306
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3307
+ ], __read(errors), false),
3308
+ warnings: warnings,
3309
+ executionReport: executionReport,
3310
+ outputParameters: {},
3311
+ usage: ZERO_USAGE,
3312
+ preparedPipeline: preparedPipeline,
3313
+ }) };
3314
+ }
3315
+ };
3316
+ try {
3317
+ // Note: Check that no extra input parameters are passed
3318
+ for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
3319
+ parameterName = _d.value;
3320
+ state_1 = _loop_1(parameterName);
3321
+ if (typeof state_1 === "object")
3322
+ return [2 /*return*/, state_1.value];
3323
+ }
3324
+ }
3325
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3326
+ finally {
3327
+ try {
3328
+ if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
3329
+ }
3330
+ finally { if (e_2) throw e_2.error; }
3331
+ }
3332
+ parametersToPass = inputParameters;
3333
+ _g.label = 3;
3334
+ case 3:
3335
+ _g.trys.push([3, 8, , 9]);
3336
+ resovedParameterNames_1 = preparedPipeline.parameters
2505
3337
  .filter(function (_a) {
2506
3338
  var isInput = _a.isInput;
2507
3339
  return isInput;
@@ -2510,187 +3342,191 @@
2510
3342
  var name = _a.name;
2511
3343
  return name;
2512
3344
  });
2513
- unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
3345
+ unresovedTemplates_1 = __spreadArray([], __read(preparedPipeline.promptTemplates), false);
2514
3346
  resolving_1 = [];
2515
3347
  loopLimit = LOOP_LIMIT;
2516
- _loop_1 = function () {
3348
+ _loop_2 = function () {
2517
3349
  var currentTemplate, work_1;
2518
- return __generator(this, function (_e) {
2519
- switch (_e.label) {
3350
+ return __generator(this, function (_h) {
3351
+ switch (_h.label) {
2520
3352
  case 0:
2521
3353
  if (loopLimit-- < 0) {
3354
+ // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
2522
3355
  throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
2523
3356
  }
2524
- currentTemplate = unresovedTemplates.find(function (template) {
2525
- return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
3357
+ currentTemplate = unresovedTemplates_1.find(function (template) {
3358
+ return template.dependentParameterNames.every(function (name) {
3359
+ return __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), __read(RESERVED_PARAMETER_NAMES), false).includes(name);
3360
+ });
2526
3361
  });
2527
3362
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
2528
- throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
3363
+ throw new UnexpectedError(
3364
+ // TODO: [🐎] DRY
3365
+ spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3366
+ .map(function (_a) {
3367
+ var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
3368
+ return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
3369
+ .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
3370
+ .join(' and '));
3371
+ })
3372
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
2529
3373
  case 1:
2530
3374
  if (!!currentTemplate) return [3 /*break*/, 3];
2531
3375
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
2532
3376
  case 2:
2533
- /* [5] */ _e.sent();
3377
+ /* [5] */ _h.sent();
2534
3378
  return [3 /*break*/, 4];
2535
3379
  case 3:
2536
- unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
3380
+ unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
2537
3381
  work_1 = executeSingleTemplate(currentTemplate)
2538
3382
  .then(function () {
2539
- resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
3383
+ resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTemplate.resultingParameterName], false);
2540
3384
  })
2541
3385
  .then(function () {
2542
3386
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
2543
3387
  });
2544
3388
  resolving_1.push(work_1);
2545
- _e.label = 4;
3389
+ _h.label = 4;
2546
3390
  case 4: return [2 /*return*/];
2547
3391
  }
2548
3392
  });
2549
3393
  };
2550
- _d.label = 2;
2551
- case 2:
2552
- if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
2553
- return [5 /*yield**/, _loop_1()];
2554
- case 3:
2555
- _d.sent();
2556
- return [3 /*break*/, 2];
2557
- case 4: return [4 /*yield*/, Promise.all(resolving_1)];
3394
+ _g.label = 4;
3395
+ case 4:
3396
+ if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
3397
+ return [5 /*yield**/, _loop_2()];
2558
3398
  case 5:
2559
- _d.sent();
2560
- return [3 /*break*/, 7];
2561
- case 6:
2562
- error_1 = _d.sent();
3399
+ _g.sent();
3400
+ return [3 /*break*/, 4];
3401
+ case 6: return [4 /*yield*/, Promise.all(resolving_1)];
3402
+ case 7:
3403
+ _g.sent();
3404
+ return [3 /*break*/, 9];
3405
+ case 8:
3406
+ error_1 = _g.sent();
2563
3407
  if (!(error_1 instanceof Error)) {
2564
3408
  throw error_1;
2565
3409
  }
2566
3410
  usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
2567
3411
  var result = _a.result;
2568
- return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
3412
+ return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
2569
3413
  })), false));
2570
- return [2 /*return*/, {
3414
+ outputParameters_1 = filterJustOutputParameters();
3415
+ return [2 /*return*/, deepFreezeWithSameType({
2571
3416
  isSuccessful: false,
2572
- errors: [error_1],
3417
+ errors: __spreadArray([error_1], __read(errors), false),
3418
+ warnings: warnings,
2573
3419
  usage: usage_1,
2574
3420
  executionReport: executionReport,
2575
- outputParameters: parametersToPass,
2576
- }];
2577
- case 7:
2578
- try {
2579
- // Note: Filter ONLY output parameters
2580
- for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
2581
- parameter = _b.value;
2582
- if (parameter.isOutput) {
2583
- continue;
2584
- }
2585
- delete parametersToPass[parameter.name];
2586
- }
2587
- }
2588
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2589
- finally {
2590
- try {
2591
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2592
- }
2593
- finally { if (e_1) throw e_1.error; }
2594
- }
3421
+ outputParameters: outputParameters_1,
3422
+ preparedPipeline: preparedPipeline,
3423
+ })];
3424
+ case 9:
2595
3425
  usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
2596
3426
  var result = _a.result;
2597
- return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
3427
+ return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
2598
3428
  })), false));
2599
- return [2 /*return*/, {
3429
+ outputParameters = filterJustOutputParameters();
3430
+ return [2 /*return*/, deepFreezeWithSameType({
2600
3431
  isSuccessful: true,
2601
- errors: [],
3432
+ errors: errors,
3433
+ warnings: warnings,
2602
3434
  usage: usage,
2603
3435
  executionReport: executionReport,
2604
- outputParameters: parametersToPass,
2605
- }];
3436
+ outputParameters: outputParameters,
3437
+ preparedPipeline: preparedPipeline,
3438
+ })];
2606
3439
  }
2607
3440
  });
2608
3441
  }); };
2609
3442
  return pipelineExecutor;
2610
3443
  }
2611
3444
  /**
3445
+ * TODO: Use isVerbose here (not only pass to `preparePipeline`)
3446
+ * TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
3447
+ * TODO: [♈] Probbably move expectations from templates to parameters
2612
3448
  * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
2613
3449
  * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
2614
3450
  * Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
2615
3451
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
3452
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3453
+ * TODO: [🧠][💷] `assertsExecutionSuccessful` should be the method of `PipelineExecutor` result BUT maybe NOT to preserve pure JSON object
2616
3454
  */
2617
3455
 
2618
- function prepareKnowledgeFromMarkdown(options) {
3456
+ /**
3457
+ * @@@
3458
+ */
3459
+ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
2619
3460
  return __awaiter(this, void 0, void 0, function () {
2620
- var content, llmTools, _a, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _b, prepareTitleExecutor, _c, prepareKeywordsExecutor, _d, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2621
- var _e, _f, _g;
3461
+ var llmTools, _a, maxParallelCount, _b, isVerbose, collection, prepareKnowledgeFromMarkdownExecutor, _c, prepareTitleExecutor, _d, prepareKeywordsExecutor, _e, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
3462
+ var _f, _g, _h;
2622
3463
  var _this = this;
2623
- return __generator(this, function (_h) {
2624
- switch (_h.label) {
3464
+ return __generator(this, function (_j) {
3465
+ switch (_j.label) {
2625
3466
  case 0:
2626
- content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
3467
+ llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
3468
+ TODO_USE(maxParallelCount); // <- [🪂]
2627
3469
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
2628
- _b = createPipelineExecutor;
2629
- _e = {};
2630
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2631
- case 1:
2632
- prepareKnowledgeFromMarkdownExecutor = _b.apply(void 0, [(_e.pipeline = _h.sent(),
2633
- _e.tools = {
2634
- llm: llmTools,
2635
- },
2636
- _e)]);
2637
3470
  _c = createPipelineExecutor;
2638
3471
  _f = {};
2639
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
2640
- case 2:
2641
- prepareTitleExecutor = _c.apply(void 0, [(_f.pipeline = _h.sent(),
3472
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
3473
+ case 1:
3474
+ prepareKnowledgeFromMarkdownExecutor = _c.apply(void 0, [(_f.pipeline = _j.sent(),
2642
3475
  _f.tools = {
2643
3476
  llm: llmTools,
2644
3477
  },
2645
3478
  _f)]);
2646
3479
  _d = createPipelineExecutor;
2647
3480
  _g = {};
2648
- return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
2649
- case 3:
2650
- prepareKeywordsExecutor = _d.apply(void 0, [(_g.pipeline = _h.sent(),
3481
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md')];
3482
+ case 2:
3483
+ prepareTitleExecutor = _d.apply(void 0, [(_g.pipeline = _j.sent(),
2651
3484
  _g.tools = {
2652
3485
  llm: llmTools,
2653
3486
  },
2654
3487
  _g)]);
2655
- return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
3488
+ _e = createPipelineExecutor;
3489
+ _h = {};
3490
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md')];
3491
+ case 3:
3492
+ prepareKeywordsExecutor = _e.apply(void 0, [(_h.pipeline = _j.sent(),
3493
+ _h.tools = {
3494
+ llm: llmTools,
3495
+ },
3496
+ _h)]);
3497
+ return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ knowledgeContent: knowledgeContent })];
2656
3498
  case 4:
2657
- result = _h.sent();
2658
- // TODO: [0] !!! Aggeregate usage
3499
+ result = _j.sent();
2659
3500
  assertsExecutionSuccessful(result);
2660
3501
  outputParameters = result.outputParameters;
2661
- knowledgeRaw = outputParameters.knowledge;
2662
- knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
3502
+ knowledgePiecesRaw = outputParameters.knowledgePieces;
3503
+ knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
3504
+ // <- TODO: !!!!! Smarter split and filter out empty pieces
2663
3505
  if (isVerbose) {
2664
3506
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
2665
3507
  }
2666
3508
  return [4 /*yield*/, Promise.all(
2667
- // TODO: !!! Do not send all at once but in chunks
3509
+ // TODO: [🪂] !! Do not send all at once but in chunks
2668
3510
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2669
- var name, title, content, keywords, index, sources, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
3511
+ var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
2670
3512
  return __generator(this, function (_c) {
2671
3513
  switch (_c.label) {
2672
3514
  case 0:
2673
3515
  name = "piece-".concat(i);
2674
3516
  title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
2675
- content = spaceTrim__default["default"](knowledgeTextPiece);
3517
+ knowledgePieceContent = spaceTrim__default["default"](knowledgeTextPiece);
2676
3518
  keywords = [];
2677
3519
  index = [];
2678
- sources = [
2679
- {
2680
- title: 'Markdown document' /* <- TODO: !!! Unhardcode */,
2681
- href: '#' /* <- TODO: !!! Unhardcode */,
2682
- },
2683
- ];
2684
3520
  _c.label = 1;
2685
3521
  case 1:
2686
3522
  _c.trys.push([1, 7, , 8]);
2687
- return [4 /*yield*/, prepareTitleExecutor({ content: content })];
3523
+ return [4 /*yield*/, prepareTitleExecutor({ knowledgePieceContent: knowledgePieceContent })];
2688
3524
  case 2:
2689
3525
  titleResult = _c.sent();
2690
3526
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
2691
3527
  title = spaceTrim__default["default"](titleRaw) /* <- TODO: Maybe do in pipeline */;
2692
3528
  name = titleToName(title);
2693
- return [4 /*yield*/, prepareKeywordsExecutor({ content: content })];
3529
+ return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
2694
3530
  case 3:
2695
3531
  keywordsResult = _c.sent();
2696
3532
  _b = keywordsResult.outputParameters.keywords, keywordsRaw = _b === void 0 ? '' : _b;
@@ -2708,14 +3544,13 @@
2708
3544
  case 4: return [4 /*yield*/, llmTools.callEmbeddingModel({
2709
3545
  title: "Embedding for ".concat(title) /* <- Note: No impact on embedding result itself, just for logging */,
2710
3546
  parameters: {},
2711
- content: content,
3547
+ content: knowledgePieceContent,
2712
3548
  modelRequirements: {
2713
3549
  modelVariant: 'EMBEDDING',
2714
3550
  },
2715
3551
  })];
2716
3552
  case 5:
2717
3553
  embeddingResult = _c.sent();
2718
- // TODO: [0] !!! Aggeregate usage embeddingResult.usage
2719
3554
  index.push({
2720
3555
  modelName: embeddingResult.modelName,
2721
3556
  position: embeddingResult.content,
@@ -2730,24 +3565,461 @@
2730
3565
  case 8: return [2 /*return*/, {
2731
3566
  name: name,
2732
3567
  title: title,
2733
- content: content,
3568
+ content: knowledgePieceContent,
2734
3569
  keywords: keywords,
2735
3570
  index: index,
2736
- sources: sources,
3571
+ // <- TODO: [☀] sources,
2737
3572
  }];
2738
3573
  }
2739
3574
  });
2740
3575
  }); }))];
2741
3576
  case 5:
2742
- knowledge = _h.sent();
3577
+ knowledge = _j.sent();
2743
3578
  return [2 /*return*/, knowledge];
2744
3579
  }
2745
3580
  });
2746
- });
2747
- }
3581
+ });
3582
+ }
3583
+ /**
3584
+ * TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
3585
+ * TODO: [🪂] Do it in parallel 11:11
3586
+ * Note: No need to aggregate usage here, it is done by intercepting the llmTools
3587
+ */
3588
+
3589
+ /**
3590
+ * Prepares the knowle
3591
+ *
3592
+ * @see https://github.com/webgptorg/promptbook/discussions/41
3593
+ */
3594
+ function prepareKnowledgePieces(knowledgeSources, options) {
3595
+ return __awaiter(this, void 0, void 0, function () {
3596
+ var _a, maxParallelCount, knowledgePrepared;
3597
+ var _this = this;
3598
+ return __generator(this, function (_b) {
3599
+ switch (_b.label) {
3600
+ case 0:
3601
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3602
+ knowledgePrepared = [];
3603
+ return [4 /*yield*/, forEachAsync(knowledgeSources, { maxParallelCount: maxParallelCount }, function (knowledgeSource) { return __awaiter(_this, void 0, void 0, function () {
3604
+ var partialPieces, pieces;
3605
+ return __generator(this, function (_a) {
3606
+ switch (_a.label) {
3607
+ case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
3608
+ options)];
3609
+ case 1:
3610
+ partialPieces = _a.sent();
3611
+ pieces = partialPieces.map(function (partialPiece) { return (__assign(__assign({}, partialPiece), { sources: [
3612
+ {
3613
+ name: knowledgeSource.name,
3614
+ // line, column <- TODO: [☀]
3615
+ // <- TODO: [❎]
3616
+ },
3617
+ ] })); });
3618
+ knowledgePrepared.push.apply(knowledgePrepared, __spreadArray([], __read(pieces), false));
3619
+ return [2 /*return*/];
3620
+ }
3621
+ });
3622
+ }); })];
3623
+ case 1:
3624
+ _b.sent();
3625
+ return [2 /*return*/, knowledgePrepared];
3626
+ }
3627
+ });
3628
+ });
3629
+ }
3630
+ /*
3631
+ TODO: [🧊] This is how it can look in future
3632
+ > type PrepareKnowledgeKnowledge = {
3633
+ > /**
3634
+ > * Unprepared knowledge
3635
+ > * /
3636
+ > readonly knowledgeSources: Array<KnowledgeSourceJson>;
3637
+ > };
3638
+ >
3639
+ > export async function prepareKnowledgePieces(
3640
+ > knowledge: PrepareKnowledgeKnowledge,
3641
+ > options: PrepareOptions,
3642
+ > ):
3643
+ */
3644
+ /**
3645
+ * TODO: [🐝][🔼] !!! Export via `@promptbook/core`
3646
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3647
+ * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3648
+ * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3649
+ * TODO: [🧠][❎] Do here propper M:N mapping
3650
+ * [x] One source can make multiple pieces
3651
+ * [ ] One piece can have multiple sources
3652
+ */
3653
+
3654
+ /**
3655
+ * Prepares the persona for the pipeline
3656
+ *
3657
+ * @see https://github.com/webgptorg/promptbook/discussions/22
3658
+ */
3659
+ function preparePersona(personaDescription, options) {
3660
+ return __awaiter(this, void 0, void 0, function () {
3661
+ var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
3662
+ var _c;
3663
+ return __generator(this, function (_d) {
3664
+ switch (_d.label) {
3665
+ case 0:
3666
+ llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
3667
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
3668
+ _b = createPipelineExecutor;
3669
+ _c = {};
3670
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
3671
+ case 1:
3672
+ preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
3673
+ _c.tools = {
3674
+ llm: llmTools,
3675
+ },
3676
+ _c)]);
3677
+ return [4 /*yield*/, llmTools.listModels()];
3678
+ case 2:
3679
+ availableModels = _d.sent();
3680
+ availableModelNames = availableModels
3681
+ .filter(function (_a) {
3682
+ var modelVariant = _a.modelVariant;
3683
+ return modelVariant === 'CHAT';
3684
+ })
3685
+ .map(function (_a) {
3686
+ var modelName = _a.modelName;
3687
+ return modelName;
3688
+ })
3689
+ .join(',');
3690
+ return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
3691
+ case 3:
3692
+ result = _d.sent();
3693
+ assertsExecutionSuccessful(result);
3694
+ outputParameters = result.outputParameters;
3695
+ modelRequirementsRaw = outputParameters.modelRequirements;
3696
+ modelRequirements = JSON.parse(modelRequirementsRaw);
3697
+ if (isVerbose) {
3698
+ console.info("PERSONA ".concat(personaDescription), modelRequirements);
3699
+ }
3700
+ modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
3701
+ return [2 /*return*/, {
3702
+ modelVariant: 'CHAT',
3703
+ modelName: modelName,
3704
+ systemMessage: systemMessage,
3705
+ temperature: temperature,
3706
+ }];
3707
+ }
3708
+ });
3709
+ });
3710
+ }
3711
+ /**
3712
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3713
+ * TODO: [🏢] !! Check validity of `modelName` in pipeline
3714
+ * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
3715
+ * TODO: [🏢] !! Check validity of `temperature` in pipeline
3716
+ */
3717
+
3718
+ /**
3719
+ * @@@
3720
+ */
3721
+ function prepareTemplates(pipeline, options) {
3722
+ return __awaiter(this, void 0, void 0, function () {
3723
+ var _a, maxParallelCount, promptTemplates, parameters, knowledgePiecesCount, promptTemplatesPrepared;
3724
+ var _this = this;
3725
+ return __generator(this, function (_b) {
3726
+ switch (_b.label) {
3727
+ case 0:
3728
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3729
+ promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3730
+ // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3731
+ TODO_USE(parameters);
3732
+ promptTemplatesPrepared = new Array(promptTemplates.length);
3733
+ return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
3734
+ var dependentParameterNames, preparedContent, preparedTemplate;
3735
+ return __generator(this, function (_a) {
3736
+ dependentParameterNames = template.dependentParameterNames;
3737
+ preparedContent = undefined;
3738
+ if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
3739
+ preparedContent = spaceTrim.spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3740
+ // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3741
+ dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
3742
+ 'knowledge',
3743
+ ], false);
3744
+ }
3745
+ preparedTemplate = __assign(__assign({}, template), { dependentParameterNames: dependentParameterNames, preparedContent: preparedContent });
3746
+ promptTemplatesPrepared[index] = preparedTemplate;
3747
+ return [2 /*return*/];
3748
+ });
3749
+ }); })];
3750
+ case 1:
3751
+ _b.sent();
3752
+ return [2 /*return*/, { promptTemplatesPrepared: promptTemplatesPrepared }];
3753
+ }
3754
+ });
3755
+ });
3756
+ }
3757
+ /**
3758
+ * TODO: [🧠] Add context to each template (if missing)
3759
+ * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
3760
+ * TODO: [♨] !!! Prepare index the samples and maybe templates
3761
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3762
+ * TODO: Write tests for `preparePipeline`
3763
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3764
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3765
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3766
+ * TODO: [🧠][🥜]
3767
+ */
3768
+
3769
+ /**
3770
+ * Prepare pipeline from string (markdown) format to JSON format
3771
+ *
3772
+ * Note: This function does not validate logic of the pipeline
3773
+ * Note: This function acts as part of compilation process
3774
+ */
3775
+ function preparePipeline(pipeline, options) {
3776
+ return __awaiter(this, void 0, void 0, function () {
3777
+ var _a, maxParallelCount, parameters, promptTemplates,
3778
+ /*
3779
+ <- TODO: [🧠][0] `promptbookVersion` */
3780
+ knowledgeSources /*
3781
+ <- TODO: [🧊] `knowledgePieces` */, personas /*
3782
+ <- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
3783
+ var _this = this;
3784
+ return __generator(this, function (_b) {
3785
+ switch (_b.label) {
3786
+ case 0:
3787
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
3788
+ parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
3789
+ currentPreparation = {
3790
+ id: 1,
3791
+ // TODO: [🍥]> date: $currentDate(),
3792
+ promptbookVersion: PROMPTBOOK_VERSION,
3793
+ modelUsage: ZERO_USAGE,
3794
+ };
3795
+ preparations = [
3796
+ // ...preparations
3797
+ // <- TODO: [🧊]
3798
+ currentPreparation,
3799
+ ];
3800
+ preparedPersonas = new Array(personas.length);
3801
+ return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
3802
+ var modelRequirements, preparedPersona;
3803
+ return __generator(this, function (_a) {
3804
+ switch (_a.label) {
3805
+ case 0: return [4 /*yield*/, preparePersona(persona.description, options)];
3806
+ case 1:
3807
+ modelRequirements = _a.sent();
3808
+ preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
3809
+ preparedPersonas[index] = preparedPersona;
3810
+ return [2 /*return*/];
3811
+ }
3812
+ });
3813
+ }); })];
3814
+ case 1:
3815
+ _b.sent();
3816
+ knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3817
+ return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, options)];
3818
+ case 2:
3819
+ partialknowledgePiecesPrepared = _b.sent();
3820
+ knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
3821
+ return [4 /*yield*/, prepareTemplates({
3822
+ parameters: parameters,
3823
+ promptTemplates: promptTemplates,
3824
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
3825
+ }, options)];
3826
+ case 3:
3827
+ promptTemplatesPrepared = (_b.sent()).promptTemplatesPrepared;
3828
+ // ----- /Templates preparation -----
3829
+ return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
3830
+ }
3831
+ });
3832
+ });
3833
+ }
3834
+ /**
3835
+ * TODO: [🔼] !!! Export via `@promptbook/core`
3836
+ * TODO: Write tests for `preparePipeline`
3837
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3838
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3839
+ * TODO: [🎐] !!!!! Use here countTotalUsage
3840
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
3841
+ */
3842
+
3843
+ /**
3844
+ * Tests if given string is valid URL.
3845
+ *
3846
+ * Note: This does not check if the file exists only if the path is valid
3847
+ */
3848
+ function isValidFilePath(filePath) {
3849
+ if (typeof filePath !== 'string') {
3850
+ return false;
3851
+ }
3852
+ var filePathSlashes = filePath.split('\\').join('/');
3853
+ // Absolute Unix path: /hello.txt
3854
+ if (/^(\/)/i.test(filePathSlashes)) {
3855
+ return true;
3856
+ }
3857
+ // Absolute Windows path: /hello.txt
3858
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3859
+ return true;
3860
+ }
3861
+ // Relative path: ./hello.txt
3862
+ if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3863
+ return true;
3864
+ }
3865
+ return false;
3866
+ }
3867
+
3868
+ /**
3869
+ * Parses the knowledge command
3870
+ *
3871
+ * @see ./KNOWLEDGE-README.md for more details
3872
+ * @private within the commands folder
3873
+ */
3874
+ var knowledgeCommandParser = {
3875
+ /**
3876
+ * Name of the command
3877
+ */
3878
+ name: 'KNOWLEDGE',
3879
+ /**
3880
+ * BOILERPLATE command can be used in:
3881
+ */
3882
+ usagePlaces: ['PIPELINE_HEAD'],
3883
+ /**
3884
+ * Description of the KNOWLEDGE command
3885
+ */
3886
+ description: "Tells promptbook which external knowledge to use",
3887
+ /**
3888
+ * Link to discussion
3889
+ */
3890
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3891
+ /**
3892
+ * Example usages of the KNOWLEDGE command
3893
+ */
3894
+ examples: [
3895
+ 'KNOWLEDGE https://www.pavolhejny.com/',
3896
+ 'KNOWLEDGE ./hejny-cv.txt',
3897
+ 'KNOWLEDGE ./hejny-cv.md',
3898
+ 'KNOWLEDGE ./hejny-cv.pdf',
3899
+ 'KNOWLEDGE ./hejny-cv.docx',
3900
+ ],
3901
+ /**
3902
+ * Parses the KNOWLEDGE command
3903
+ */
3904
+ parse: function (input) {
3905
+ var args = input.args;
3906
+ var source = args[0];
3907
+ if (source === undefined) {
3908
+ throw new ParsingError("Source is not defined");
3909
+ }
3910
+ if (source.startsWith('http://')) {
3911
+ throw new ParsingError("Source is not secure");
3912
+ }
3913
+ if (!(isValidFilePath(source) || isValidUrl(source))) {
3914
+ throw new ParsingError("Source not valid");
3915
+ }
3916
+ if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3917
+ throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3918
+ }
3919
+ return {
3920
+ type: 'KNOWLEDGE',
3921
+ source: source,
3922
+ };
3923
+ },
3924
+ /**
3925
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
3926
+ */
3927
+ applyToPipelineJson: function (personaCommand, subjects) {
3928
+ var source = personaCommand.source;
3929
+ var pipelineJson = subjects.pipelineJson;
3930
+ var name = titleToName(source);
3931
+ pipelineJson.knowledgeSources.push({
3932
+ name: name,
3933
+ source: source,
3934
+ });
3935
+ },
3936
+ };
3937
+
2748
3938
  /**
2749
- * 11:11
3939
+ * Parses the persona command
3940
+ *
3941
+ * @see ./PERSONA-README.md for more details
3942
+ * @private within the commands folder
2750
3943
  */
3944
+ var personaCommandParser = {
3945
+ /**
3946
+ * Name of the command
3947
+ */
3948
+ name: 'PERSONA',
3949
+ /**
3950
+ * Aliases for the PERSONA command
3951
+ */
3952
+ aliasNames: ['PERSON'],
3953
+ /**
3954
+ * PERSONA command can be used in:
3955
+ */
3956
+ usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3957
+ /**
3958
+ * Description of the PERSONA command
3959
+ */
3960
+ description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3961
+ /**
3962
+ * Link to discussion
3963
+ */
3964
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3965
+ /**
3966
+ * Example usages of the PERSONA command
3967
+ */
3968
+ examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3969
+ /**
3970
+ * Parses the PERSONA command
3971
+ */
3972
+ parse: function (input) {
3973
+ var rawArgs = input.rawArgs;
3974
+ var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3975
+ var personaName = (personaNameRaw || '').trim();
3976
+ if (personaName === '') {
3977
+ throw new ParsingError("You must set name for the persona");
3978
+ }
3979
+ var personaDescription = (personaDescriptionRaw || '').trim();
3980
+ if (personaDescription === '') {
3981
+ personaDescription = null;
3982
+ }
3983
+ return {
3984
+ type: 'PERSONA',
3985
+ personaName: personaName,
3986
+ personaDescription: personaDescription,
3987
+ };
3988
+ },
3989
+ /**
3990
+ * Note: Prototype of [🍧] (remove this comment after full implementation)
3991
+ */
3992
+ applyToPipelineJson: function (personaCommand, subjects) {
3993
+ var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
3994
+ var pipelineJson = subjects.pipelineJson, templateJson = subjects.templateJson;
3995
+ if (templateJson !== null) {
3996
+ if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
3997
+ throw new ParsingError("PERSONA command can be used only in PROMPT_TEMPLATE block");
3998
+ }
3999
+ templateJson.personaName = personaName;
4000
+ }
4001
+ var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
4002
+ if (persona === undefined) {
4003
+ pipelineJson.personas.push({
4004
+ name: personaName,
4005
+ description: personaDescription || '',
4006
+ });
4007
+ return;
4008
+ }
4009
+ if (persona.description === personaDescription) {
4010
+ return;
4011
+ }
4012
+ if (personaDescription === null) {
4013
+ return;
4014
+ }
4015
+ if (persona.description === '') {
4016
+ persona.description = personaDescription;
4017
+ return;
4018
+ }
4019
+ console.warn(spaceTrim__default["default"]("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
4020
+ persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
4021
+ },
4022
+ };
2751
4023
 
2752
4024
  /**
2753
4025
  * Removes Markdown formatting tags from a string.
@@ -2867,7 +4139,7 @@
2867
4139
  /**
2868
4140
  * Link to discussion
2869
4141
  */
2870
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
4142
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/64',
2871
4143
  /**
2872
4144
  * Example usages of the BLOCK command
2873
4145
  */
@@ -2887,7 +4159,7 @@
2887
4159
  'Knowledge BLOCK',
2888
4160
  // 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
2889
4161
  //---
2890
- /* TODO: !!!! Not implemented block types will be in examples in future -> */
4162
+ /* Note: Not implemented block types will be in examples in future -> */
2891
4163
  'Instrument BLOCK',
2892
4164
  // 'Instrument', // <- Note: [⛱]
2893
4165
  'Action BLOCK',
@@ -2895,6 +4167,7 @@
2895
4167
  //---
2896
4168
  /* <- TODO: [🧠] Maybe dynamic */
2897
4169
  ],
4170
+ // TODO: [♓️] order: -10 /* <- Note: Putting before other commands */
2898
4171
  /**
2899
4172
  * Parses the BLOCK command
2900
4173
  */
@@ -2903,19 +4176,19 @@
2903
4176
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
2904
4177
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
2905
4178
  if (blockTypes.length !== 1) {
2906
- // console.log('!!!', { blockType });
2907
4179
  throw new ParsingError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
2908
4180
  }
2909
- // TODO: !!!! Not supported yet
4181
+ var blockType = blockTypes[0];
2910
4182
  return {
2911
4183
  type: 'BLOCK',
2912
- blockType: blockTypes[0],
4184
+ blockType: blockType,
2913
4185
  };
2914
4186
  },
2915
4187
  };
2916
4188
 
2917
4189
  /**
2918
4190
  * Units of text measurement
4191
+ * @see https://github.com/webgptorg/promptbook/discussions/30
2919
4192
  */
2920
4193
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2921
4194
  /**
@@ -3011,7 +4284,7 @@
3011
4284
  /**
3012
4285
  * Link to discussion
3013
4286
  */
3014
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
4287
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/30',
3015
4288
  /**
3016
4289
  * Example usages of the EXPECT command
3017
4290
  */
@@ -3129,7 +4402,7 @@
3129
4402
  /**
3130
4403
  * Link to discussion
3131
4404
  */
3132
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
4405
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/66',
3133
4406
  /**
3134
4407
  * Example usages of the JOKER command
3135
4408
  */
@@ -3152,94 +4425,11 @@
3152
4425
  };
3153
4426
 
3154
4427
  /**
3155
- * Tests if given string is valid URL.
3156
- *
3157
- * Note: This does not check if the file exists only if the path is valid
3158
- */
3159
- function isValidFilePath(filePath) {
3160
- if (typeof filePath !== 'string') {
3161
- return false;
3162
- }
3163
- var filePathSlashes = filePath.split('\\').join('/');
3164
- // Absolute Unix path: /hello.txt
3165
- if (/^(\/)/i.test(filePathSlashes)) {
3166
- return true;
3167
- }
3168
- // Absolute Windows path: /hello.txt
3169
- if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
3170
- return true;
3171
- }
3172
- // Relative path: ./hello.txt
3173
- if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
3174
- return true;
3175
- }
3176
- return false;
3177
- }
3178
-
3179
- /**
3180
- * Parses the knowledge command
4428
+ * @@@
3181
4429
  *
3182
- * @see ./KNOWLEDGE-README.md for more details
3183
- * @private within the commands folder
4430
+ * @private for `ModelVariant` and `modelCommandParser`
3184
4431
  */
3185
- var knowledgeCommandParser = {
3186
- /**
3187
- * Name of the command
3188
- */
3189
- name: 'KNOWLEDGE',
3190
- /**
3191
- * BOILERPLATE command can be used in:
3192
- */
3193
- usagePlaces: ['PIPELINE_HEAD'],
3194
- /**
3195
- * Description of the KNOWLEDGE command
3196
- */
3197
- description: "Tells promptbook which external knowledge to use",
3198
- /**
3199
- * Link to discussion
3200
- */
3201
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
3202
- /**
3203
- * Example usages of the KNOWLEDGE command
3204
- */
3205
- examples: [
3206
- 'KNOWLEDGE https://www.pavolhejny.com/',
3207
- 'KNOWLEDGE ./hejny-cv.txt',
3208
- 'KNOWLEDGE ./hejny-cv.md',
3209
- 'KNOWLEDGE ./hejny-cv.pdf',
3210
- 'KNOWLEDGE ./hejny-cv.docx',
3211
- ],
3212
- /**
3213
- * Parses the KNOWLEDGE command
3214
- */
3215
- parse: function (input) {
3216
- var args = input.args;
3217
- var source = args[0];
3218
- if (source === undefined) {
3219
- throw new ParsingError("Source is not defined");
3220
- }
3221
- if (source.startsWith('http://')) {
3222
- throw new ParsingError("Source is not secure");
3223
- }
3224
- if (!(isValidFilePath(source) || isValidUrl(source))) {
3225
- throw new ParsingError("Source not valid");
3226
- }
3227
- if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
3228
- throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
3229
- }
3230
- return {
3231
- type: 'KNOWLEDGE',
3232
- source: source,
3233
- };
3234
- },
3235
- };
3236
-
3237
4432
  var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
3238
- /**
3239
- * TODO: Maybe figure out better word than "variant"
3240
- * TODO: Add here more requirement options like max context size, max tokens, etc.
3241
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
3242
- */
3243
4433
 
3244
4434
  /**
3245
4435
  * Parses the model command
@@ -3255,7 +4445,11 @@
3255
4445
  /**
3256
4446
  * BOILERPLATE command can be used in:
3257
4447
  */
3258
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
4448
+ usagePlaces: [
4449
+ 'PIPELINE_HEAD',
4450
+ // <- TODO: [🧠][❔] Should there be possibility to set MODEL for entire pipeline?
4451
+ 'PIPELINE_TEMPLATE',
4452
+ ],
3259
4453
  /**
3260
4454
  * Description of the MODEL command
3261
4455
  */
@@ -3263,7 +4457,7 @@
3263
4457
  /**
3264
4458
  * Link to discussion
3265
4459
  */
3266
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
4460
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/67',
3267
4461
  /**
3268
4462
  * Example usages of the MODEL command
3269
4463
  */
@@ -3343,11 +4537,11 @@
3343
4537
  /**
3344
4538
  * Link to discussion
3345
4539
  */
3346
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
4540
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/68',
3347
4541
  /**
3348
4542
  * Example usages of the PARAMETER command
3349
4543
  */
3350
- examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {content} Content of the book'],
4544
+ examples: ['PARAMETER {title} Title of the book', 'OUTPUT PARAMETER {websiteContent} Content of the book'],
3351
4545
  /**
3352
4546
  * Parses the PARAMETER command
3353
4547
  */
@@ -3377,59 +4571,6 @@
3377
4571
  },
3378
4572
  };
3379
4573
 
3380
- /**
3381
- * Parses the persona command
3382
- *
3383
- * @see ./PERSONA-README.md for more details
3384
- * @private within the commands folder
3385
- */
3386
- var personaCommandParser = {
3387
- /**
3388
- * Name of the command
3389
- */
3390
- name: 'PERSONA',
3391
- /**
3392
- * Aliases for the PERSONA command
3393
- */
3394
- aliasNames: ['PERSON'],
3395
- /**
3396
- * PERSONA command can be used in:
3397
- */
3398
- usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
3399
- /**
3400
- * Description of the PERSONA command
3401
- */
3402
- description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
3403
- /**
3404
- * Link to discussion
3405
- */
3406
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
3407
- /**
3408
- * Example usages of the PERSONA command
3409
- */
3410
- examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
3411
- /**
3412
- * Parses the PERSONA command
3413
- */
3414
- parse: function (input) {
3415
- var rawArgs = input.rawArgs;
3416
- var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
3417
- var personaName = (personaNameRaw || '').trim();
3418
- if (personaName === '') {
3419
- throw new ParsingError("You must set name for the persona");
3420
- }
3421
- var personaDescription = (personaDescriptionRaw || '').trim();
3422
- if (personaDescription === '') {
3423
- personaDescription = null;
3424
- }
3425
- return {
3426
- type: 'PERSONA',
3427
- personaName: personaName,
3428
- personaDescription: personaDescription,
3429
- };
3430
- },
3431
- };
3432
-
3433
4574
  function isValidJavascriptName(javascriptName) {
3434
4575
  if (typeof javascriptName !== 'string') {
3435
4576
  return false;
@@ -3460,7 +4601,7 @@
3460
4601
  /**
3461
4602
  * Link to discussion
3462
4603
  */
3463
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
4604
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/31',
3464
4605
  /**
3465
4606
  * Example usages of the POSTPROCESS command
3466
4607
  */
@@ -3499,11 +4640,8 @@
3499
4640
  /**
3500
4641
  * Name of the command
3501
4642
  */
3502
- name: 'VERSION',
3503
- /*
3504
- Note: [📇] No need to put here "PROMPTBOOK" alias here
3505
- aliasNames: ['PROMPTBOOK_VERSION'],
3506
- */
4643
+ name: 'PROMPTBOOK_VERSION',
4644
+ aliasNames: ['PTBK_VERSION', 'PTBK_V', 'PTBKV'],
3507
4645
  /**
3508
4646
  * BOILERPLATE command can be used in:
3509
4647
  */
@@ -3515,11 +4653,11 @@
3515
4653
  /**
3516
4654
  * Link to discussion
3517
4655
  */
3518
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
4656
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
3519
4657
  /**
3520
4658
  * Example usages of the PROMPTBOOK_VERSION command
3521
4659
  */
3522
- examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "VERSION ".concat(PROMPTBOOK_VERSION)],
4660
+ examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "PTBKV ".concat(PROMPTBOOK_VERSION)],
3523
4661
  /**
3524
4662
  * Parses the PROMPTBOOK_VERSION command
3525
4663
  */
@@ -3553,8 +4691,9 @@
3553
4691
  * Name of the command
3554
4692
  */
3555
4693
  name: 'URL',
4694
+ aliasNames: ['PIPELINE_URL'],
3556
4695
  /*
3557
- Note: [🛵] No need for alias name because it is already preprocessed
4696
+ Note: [🛵] No need for this alias name because it is already preprocessed
3558
4697
  aliasNames: ['HTTPS'],
3559
4698
  */
3560
4699
  /**
@@ -3568,11 +4707,12 @@
3568
4707
  /**
3569
4708
  * Link to discussion
3570
4709
  */
3571
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
4710
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/70',
3572
4711
  /**
3573
4712
  * Example usages of the URL command
3574
4713
  */
3575
4714
  examples: [
4715
+ 'PIPELINE URL https://promptbook.studio/library/write-cv.ptbk.md',
3576
4716
  'URL https://promptbook.studio/library/write-cv.ptbk.md',
3577
4717
  'https://promptbook.studio/library/write-cv.ptbk.md',
3578
4718
  ],
@@ -3616,22 +4756,6 @@
3616
4756
  },
3617
4757
  };
3618
4758
 
3619
- /**
3620
- * Returns the same value that is passed as argument.
3621
- * No side effects.
3622
- *
3623
- * Note: It can be usefull for leveling indentation
3624
- *
3625
- * @param value any values
3626
- * @returns the same values
3627
- */
3628
- function just(value) {
3629
- if (value === undefined) {
3630
- return undefined;
3631
- }
3632
- return value;
3633
- }
3634
-
3635
4759
  /**
3636
4760
  * Parses the action command
3637
4761
  *
@@ -3654,7 +4778,7 @@
3654
4778
  /**
3655
4779
  * Link to discussion
3656
4780
  */
3657
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
4781
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/72',
3658
4782
  /**
3659
4783
  * Example usages of the ACTION command
3660
4784
  */
@@ -3663,7 +4787,8 @@
3663
4787
  * Parses the ACTION command
3664
4788
  */
3665
4789
  parse: function (input) {
3666
- input.args;
4790
+ var args = input.args;
4791
+ TODO_USE(args);
3667
4792
  return {
3668
4793
  type: 'ACTION',
3669
4794
  };
@@ -3692,7 +4817,7 @@
3692
4817
  /**
3693
4818
  * Link to discussion
3694
4819
  */
3695
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
4820
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/71',
3696
4821
  /**
3697
4822
  * Example usages of the INSTRUMENT command
3698
4823
  */
@@ -3701,7 +4826,8 @@
3701
4826
  * Parses the INSTRUMENT command
3702
4827
  */
3703
4828
  parse: function (input) {
3704
- input.args;
4829
+ var args = input.args;
4830
+ TODO_USE(args);
3705
4831
  return {
3706
4832
  type: 'INSTRUMENT',
3707
4833
  };
@@ -3734,7 +4860,7 @@
3734
4860
  /**
3735
4861
  * Link to discussion
3736
4862
  */
3737
- discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
4863
+ documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
3738
4864
  /**
3739
4865
  * Example usages of the BOILERPLATE command
3740
4866
  */
@@ -3759,6 +4885,7 @@
3759
4885
  };
3760
4886
  /**
3761
4887
  * TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
4888
+ * Note: [⚪] This should never be in any released package
3762
4889
  */
3763
4890
 
3764
4891
  /**
@@ -3777,7 +4904,7 @@
3777
4904
  actionCommandParser,
3778
4905
  instrumentCommandParser,
3779
4906
  personaCommandParser,
3780
- boilerplateCommandParser, // <- TODO: !!!! Only in development, remove in production
4907
+ boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
3781
4908
  ];
3782
4909
 
3783
4910
  /**
@@ -3824,10 +4951,6 @@
3824
4951
  .split(' ')
3825
4952
  .map(function (part) { return part.trim(); })
3826
4953
  .filter(function (item) { return item !== ''; })
3827
- // Note: [📇]:
3828
- .filter(function (item) { return !/^PTBK$/i.test(item); })
3829
- .filter(function (item) { return !/^PIPELINE$/i.test(item); })
3830
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
3831
4954
  .map(removeMarkdownFormatting)
3832
4955
  .map(function (item) { return item.trim(); });
3833
4956
  if (items.length === 0 || items[0] === '') {
@@ -3863,18 +4986,18 @@
3863
4986
  }));
3864
4987
  }
3865
4988
  /**
3866
- * !!!
4989
+ * @@@
3867
4990
  */
3868
4991
  function getSupportedCommandsMessage() {
3869
4992
  return COMMANDS.flatMap(function (_a) {
3870
- var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, discussionUrl = _a.discussionUrl;
4993
+ var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
3871
4994
  return __spreadArray([
3872
- "- **".concat(name, "** ").concat(description, ", see [discussion](").concat(discussionUrl, ")")
4995
+ "- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
3873
4996
  ], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
3874
4997
  }).join('\n');
3875
4998
  }
3876
4999
  /**
3877
- * !!!
5000
+ * @@@
3878
5001
  */
3879
5002
  function parseCommandVariant(input) {
3880
5003
  var e_1, _a;
@@ -3883,7 +5006,6 @@
3883
5006
  var _loop_1 = function (commandParser) {
3884
5007
  var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
3885
5008
  var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
3886
- // console.log('!!!', { commandName, names });
3887
5009
  if (names.includes(commandName)) {
3888
5010
  try {
3889
5011
  return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
@@ -3993,25 +5115,42 @@
3993
5115
  var e_1, _a;
3994
5116
  var codeBlocks = [];
3995
5117
  var lines = markdown.split('\n');
5118
+ // Note: [0] Ensure that the last block notated by gt > will be closed
5119
+ lines.push('');
3996
5120
  var currentCodeBlock = null;
3997
5121
  try {
3998
5122
  for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
3999
5123
  var line = lines_1_1.value;
5124
+ if (line.startsWith('> ') || line === '>') {
5125
+ if (currentCodeBlock === null) {
5126
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
5127
+ } /* not else */
5128
+ if (currentCodeBlock.blockNotation === '>') {
5129
+ if (currentCodeBlock.content !== '') {
5130
+ currentCodeBlock.content += '\n';
5131
+ }
5132
+ currentCodeBlock.content += line.slice(2);
5133
+ }
5134
+ }
5135
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
5136
+ codeBlocks.push(currentCodeBlock);
5137
+ currentCodeBlock = null;
5138
+ }
5139
+ /* not else */
4000
5140
  if (line.startsWith('```')) {
4001
5141
  var language = line.slice(3).trim() || null;
4002
5142
  if (currentCodeBlock === null) {
4003
- currentCodeBlock = { language: language, content: '' };
5143
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
4004
5144
  }
4005
5145
  else {
4006
5146
  if (language !== null) {
4007
- // [🌻]
4008
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
5147
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
4009
5148
  }
4010
5149
  codeBlocks.push(currentCodeBlock);
4011
5150
  currentCodeBlock = null;
4012
5151
  }
4013
5152
  }
4014
- else if (currentCodeBlock !== null) {
5153
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
4015
5154
  if (currentCodeBlock.content !== '') {
4016
5155
  currentCodeBlock.content += '\n';
4017
5156
  }
@@ -4027,11 +5166,13 @@
4027
5166
  finally { if (e_1) throw e_1.error; }
4028
5167
  }
4029
5168
  if (currentCodeBlock !== null) {
4030
- // [🌻]
4031
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
5169
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
4032
5170
  }
4033
5171
  return codeBlocks;
4034
5172
  }
5173
+ /**
5174
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
5175
+ */
4035
5176
 
4036
5177
  /**
4037
5178
  * Extracts exactly ONE code block from markdown.
@@ -4049,13 +5190,12 @@
4049
5190
  function extractOneBlockFromMarkdown(markdown) {
4050
5191
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
4051
5192
  if (codeBlocks.length !== 1) {
4052
- // TODO: Report more specific place where the error happened
4053
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
5193
+ throw new ParsingError(spaceTrim__default["default"](function (block) { return "\n There should be exactly 1 code block, 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 "); }));
4054
5194
  }
4055
5195
  return codeBlocks[0];
4056
5196
  }
4057
5197
  /***
4058
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
5198
+ * TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
4059
5199
  */
4060
5200
 
4061
5201
  /**
@@ -4065,13 +5205,13 @@
4065
5205
  var _a, _b;
4066
5206
  var lines = value.split('\n');
4067
5207
  if (!lines[0].startsWith('#')) {
4068
- throw new Error('Markdown section must start with heading');
5208
+ throw new ParsingError('Markdown section must start with heading');
4069
5209
  }
4070
5210
  var title = lines[0].replace(/^#+\s*/, '');
4071
5211
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
4072
5212
  var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
4073
5213
  if (level < 1 || level > 6) {
4074
- throw new Error('Markdown section must have heading level between 1 and 6');
5214
+ throw new ParsingError('Markdown section must have heading level between 1 and 6');
4075
5215
  }
4076
5216
  return { title: title, level: level, content: content };
4077
5217
  }
@@ -4208,203 +5348,14 @@
4208
5348
  }
4209
5349
 
4210
5350
  /**
4211
- * Create difference set of two sets.
4212
- *
4213
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
4214
- */
4215
- function difference(a, b, isEqual) {
4216
- var e_1, _a;
4217
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
4218
- var diff = new Set();
4219
- var _loop_1 = function (itemA) {
4220
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
4221
- diff.add(itemA);
4222
- }
4223
- };
4224
- try {
4225
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
4226
- var itemA = _c.value;
4227
- _loop_1(itemA);
4228
- }
4229
- }
4230
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4231
- finally {
4232
- try {
4233
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4234
- }
4235
- finally { if (e_1) throw e_1.error; }
4236
- }
4237
- return diff;
4238
- }
4239
-
4240
- /**
4241
- * Creates a new set with all elements that are present in either set
4242
- *
4243
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
4244
- */
4245
- function union() {
4246
- var e_1, _a, e_2, _b;
4247
- var sets = [];
4248
- for (var _i = 0; _i < arguments.length; _i++) {
4249
- sets[_i] = arguments[_i];
4250
- }
4251
- var union = new Set();
4252
- try {
4253
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
4254
- var set = sets_1_1.value;
4255
- try {
4256
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
4257
- var item = _d.value;
4258
- union.add(item);
4259
- }
4260
- }
4261
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
4262
- finally {
4263
- try {
4264
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
4265
- }
4266
- finally { if (e_2) throw e_2.error; }
4267
- }
4268
- }
4269
- }
4270
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4271
- finally {
4272
- try {
4273
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
4274
- }
4275
- finally { if (e_1) throw e_1.error; }
4276
- }
4277
- return union;
4278
- }
4279
-
4280
- /**
4281
- * Parses the template and returns the list of all parameter names
4282
- *
4283
- * @param template the template with parameters in {curly} braces
4284
- * @returns the list of parameter names
4285
- */
4286
- function extractParameters(template) {
4287
- var e_1, _a;
4288
- var matches = template.matchAll(/{\w+}/g);
4289
- var parameterNames = new Set();
4290
- try {
4291
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
4292
- var match = matches_1_1.value;
4293
- var parameterName = match[0].slice(1, -1);
4294
- parameterNames.add(parameterName);
4295
- }
4296
- }
4297
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4298
- finally {
4299
- try {
4300
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
4301
- }
4302
- finally { if (e_1) throw e_1.error; }
4303
- }
4304
- return parameterNames;
4305
- }
4306
-
4307
- /**
4308
- * Parses the given script and returns the list of all used variables that are not defined in the script
4309
- *
4310
- * @param script from which to extract the variables
4311
- * @returns the list of variable names
4312
- * @throws {ParsingError} if the script is invalid
4313
- */
4314
- function extractVariables(script) {
4315
- var variables = new Set();
4316
- script = "(()=>{".concat(script, "})()");
4317
- try {
4318
- for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
4319
- try {
4320
- eval(script);
4321
- }
4322
- catch (error) {
4323
- if (!(error instanceof ReferenceError)) {
4324
- throw error;
4325
- }
4326
- var undefinedName = error.message.split(' ')[0];
4327
- /*
4328
- Note: Parsing the error
4329
- [ReferenceError: thing is not defined]
4330
- */
4331
- if (!undefinedName) {
4332
- throw error;
4333
- }
4334
- if (script.includes(undefinedName + '(')) {
4335
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
4336
- }
4337
- else {
4338
- variables.add(undefinedName);
4339
- script = "const ".concat(undefinedName, " = '';") + script;
4340
- }
4341
- }
4342
- }
4343
- catch (error) {
4344
- if (!(error instanceof Error)) {
4345
- throw error;
4346
- }
4347
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
4348
- }
4349
- return variables;
4350
- }
4351
- /**
4352
- * TODO: [🔣] Support for multiple languages - python, java,...
4353
- */
4354
-
4355
- /**
4356
- * Parses the prompt template and returns the set of all used parameters
4357
- *
4358
- * @param promptTemplate the template with used parameters
4359
- * @returns the set of parameter names
4360
- * @throws {ParsingError} if the script is invalid
4361
- */
4362
- function extractParametersFromPromptTemplate(promptTemplate) {
4363
- var e_1, _a, e_2, _b;
4364
- var parameterNames = new Set();
4365
- try {
4366
- for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
4367
- var parameterName = _d.value;
4368
- parameterNames.add(parameterName);
4369
- }
4370
- }
4371
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
4372
- finally {
4373
- try {
4374
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
4375
- }
4376
- finally { if (e_1) throw e_1.error; }
4377
- }
4378
- if (promptTemplate.blockType === 'SCRIPT') {
4379
- try {
4380
- for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
4381
- var parameterName = _f.value;
4382
- parameterNames.add(parameterName);
4383
- }
4384
- }
4385
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
4386
- finally {
4387
- try {
4388
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
4389
- }
4390
- finally { if (e_2) throw e_2.error; }
4391
- }
4392
- }
4393
- return parameterNames;
4394
- }
4395
- /**
4396
- * TODO: [🔣] If script require contentLanguage
4397
- */
4398
-
4399
- /**
4400
- * Compile promptbook from string (markdown) format to JSON format synchronously
5351
+ * Compile pipeline from string (markdown) format to JSON format synchronously
4401
5352
  *
4402
- * Note: There are two similar functions:
5353
+ * Note: There are 3 similar functions:
4403
5354
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4404
5355
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
5356
+ * - `preparePipeline` - just one step in the compilation process
4405
5357
  *
4406
5358
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4407
- * @param options - Options and tools for the compilation
4408
5359
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
4409
5360
  * @throws {ParsingError} if the promptbook string is not valid
4410
5361
  *
@@ -4420,7 +5371,10 @@
4420
5371
  description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
4421
5372
  parameters: [],
4422
5373
  promptTemplates: [],
4423
- knowledge: [],
5374
+ knowledgeSources: [],
5375
+ knowledgePieces: [],
5376
+ personas: [],
5377
+ preparations: [],
4424
5378
  };
4425
5379
  // =============================================================
4426
5380
  // Note: 1️⃣ Parsing of the markdown into object
@@ -4450,7 +5404,7 @@
4450
5404
  existingParameter.description &&
4451
5405
  existingParameter.description !== parameterDescription &&
4452
5406
  parameterDescription) {
4453
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
5407
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
4454
5408
  }
4455
5409
  if (existingParameter) {
4456
5410
  if (parameterDescription) {
@@ -4469,11 +5423,12 @@
4469
5423
  // =============================================================
4470
5424
  // Note: 3️⃣ Process pipeline head
4471
5425
  pipelineJson.title = pipelineHead.title;
4472
- // TODO: [1] DRY description
5426
+ // TODO: [🎾][1] DRY description
4473
5427
  var description = pipelineHead.content;
4474
- // Note: Remove codeblocks - TODO: Maybe put this into util (exported from `@promptbool/utils`)
5428
+ // Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
4475
5429
  description = description.split(/^```.*^```/gms).join('');
4476
- //Note: Remove lists and return statement - TODO: Maybe put this into util (exported from `@promptbool/utils`)
5430
+ description = description.split(/^>.*$/gm).join('');
5431
+ //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
4477
5432
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4478
5433
  description = spaceTrim.spaceTrim(description);
4479
5434
  if (description === '') {
@@ -4501,7 +5456,7 @@
4501
5456
  pipelineJson.pipelineUrl = command.pipelineUrl.href;
4502
5457
  break;
4503
5458
  case 'KNOWLEDGE':
4504
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
5459
+ knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
4505
5460
  break;
4506
5461
  case 'ACTION':
4507
5462
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
@@ -4510,7 +5465,8 @@
4510
5465
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4511
5466
  break;
4512
5467
  case 'PERSONA':
4513
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
5468
+ personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: null });
5469
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4514
5470
  break;
4515
5471
  case 'BOILERPLATE':
4516
5472
  throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
@@ -4533,29 +5489,83 @@
4533
5489
  // TODO: Parse prompt template description (the content out of the codeblock and lists)
4534
5490
  var templateModelRequirements = __assign({}, defaultModelRequirements);
4535
5491
  var listItems_3 = extractAllListItemsFromMarkdown(section.content);
4536
- var dependentParameterNames = new Set();
4537
- var blockType = 'PROMPT_TEMPLATE';
4538
- var jokers = [];
4539
- var postprocessing = [];
4540
- var expectAmount = {};
4541
- var expectFormat = undefined;
4542
- var isBlockTypeChanged = false;
5492
+ var lastLine = section.content.split('\n').pop();
5493
+ var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
5494
+ var resultingParameterName = null;
5495
+ if (resultingParameterNameMatch &&
5496
+ resultingParameterNameMatch.groups !== undefined &&
5497
+ resultingParameterNameMatch.groups.resultingParamName !== undefined) {
5498
+ resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
5499
+ }
5500
+ var expectResultingParameterName = function () {
5501
+ if (resultingParameterName !== null) {
5502
+ return resultingParameterName;
5503
+ }
5504
+ throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
5505
+ // TODO: Show code of invalid sections each time + DRY
5506
+ section.content
5507
+ .split('\n')
5508
+ .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
5509
+ .join('\n')), "\n "); }));
5510
+ };
5511
+ var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
5512
+ // TODO: [🎾][1] DRY description
5513
+ var description_1 = section.content;
5514
+ // Note: Remove codeblocks - TODO: [🎾]
5515
+ description_1 = description_1.split(/^```.*^```/gms).join('');
5516
+ description_1 = description_1.split(/^>.*$/gm).join('');
5517
+ //Note: Remove lists and return statement - TODO: [🎾]
5518
+ description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
5519
+ description_1 = spaceTrim.spaceTrim(description_1);
5520
+ if (description_1 === '') {
5521
+ description_1 = undefined;
5522
+ }
5523
+ var templateJson = {
5524
+ blockType: 'PROMPT_TEMPLATE',
5525
+ name: titleToName(section.title),
5526
+ title: section.title,
5527
+ description: description_1,
5528
+ modelRequirements: templateModelRequirements,
5529
+ content: content,
5530
+ };
5531
+ /**
5532
+ * This is nessesary because block type can be
5533
+ * - Set zero times, so anticipate 'PROMPT_TEMPLATE'
5534
+ * - Set one time
5535
+ * - Set more times - throw error
5536
+ *
5537
+ * Note: [2]
5538
+ */
5539
+ var isBlockTypeSet = false;
4543
5540
  try {
4544
5541
  for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
4545
5542
  var listItem = listItems_2_1.value;
4546
5543
  var command = parseCommand(listItem, 'PIPELINE_TEMPLATE');
5544
+ // TODO [🍧][♓️] List commands and before apply order them
4547
5545
  switch (command.type) {
4548
5546
  // TODO: [🍧] Use here applyToPipelineJson and remove switch statement
4549
5547
  case 'BLOCK':
4550
- if (isBlockTypeChanged) {
5548
+ if (isBlockTypeSet) {
4551
5549
  throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
4552
5550
  }
4553
5551
  if (command.blockType === 'SAMPLE') {
4554
- console.error(new NotYetImplementedError('Block type SAMPLE is not implemented yet'));
5552
+ expectResultingParameterName();
5553
+ var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
5554
+ if (parameter === undefined) {
5555
+ throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
5556
+ }
5557
+ parameter.sampleValues = parameter.sampleValues || [];
5558
+ parameter.sampleValues.push(content);
4555
5559
  return "continue-templates";
4556
5560
  }
4557
5561
  if (command.blockType === 'KNOWLEDGE') {
4558
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
5562
+ knowledgeCommandParser.applyToPipelineJson({
5563
+ type: 'KNOWLEDGE',
5564
+ source: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
5565
+ }, {
5566
+ pipelineJson: pipelineJson,
5567
+ templateJson: templateJson,
5568
+ });
4559
5569
  return "continue-templates";
4560
5570
  }
4561
5571
  if (command.blockType === 'ACTION') {
@@ -4566,35 +5576,37 @@
4566
5576
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4567
5577
  return "continue-templates";
4568
5578
  }
4569
- blockType = command.blockType;
4570
- isBlockTypeChanged = true;
5579
+ expectResultingParameterName();
5580
+ templateJson.blockType = command.blockType;
5581
+ isBlockTypeSet = true; //<- Note: [2]
4571
5582
  break;
4572
5583
  case 'EXPECT_AMOUNT':
4573
5584
  // eslint-disable-next-line no-case-declarations
4574
5585
  var unit = command.unit.toLowerCase();
4575
- expectAmount[unit] = expectAmount[unit] || {};
5586
+ templateJson.expectations = templateJson.expectations || {};
5587
+ templateJson.expectations[unit] = templateJson.expectations[unit] || {};
4576
5588
  if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
4577
- if (expectAmount[unit].min !== undefined) {
4578
- throw new ParsingError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5589
+ if (templateJson.expectations[unit].min !== undefined) {
5590
+ throw new ParsingError("Already defined minumum ".concat(templateJson.expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
4579
5591
  }
4580
- expectAmount[unit].min = command.amount;
5592
+ templateJson.expectations[unit].min = command.amount;
4581
5593
  } /* not else */
4582
5594
  if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
4583
- if (expectAmount[unit].max !== undefined) {
4584
- throw new ParsingError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
5595
+ if (templateJson.expectations[unit].max !== undefined) {
5596
+ throw new ParsingError("Already defined maximum ".concat(templateJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
4585
5597
  }
4586
- expectAmount[unit].max = command.amount;
5598
+ templateJson.expectations[unit].max = command.amount;
4587
5599
  }
4588
5600
  break;
4589
5601
  case 'EXPECT_FORMAT':
4590
- if (expectFormat !== undefined && command.format !== expectFormat) {
4591
- throw new ParsingError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
5602
+ if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
5603
+ throw new ParsingError(spaceTrim.spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
4592
5604
  }
4593
- expectFormat = command.format;
5605
+ templateJson.expectFormat = command.format;
4594
5606
  break;
4595
5607
  case 'JOKER':
4596
- jokers.push(command.parameterName);
4597
- dependentParameterNames.add(command.parameterName);
5608
+ templateJson.jokerParameterNames = templateJson.jokerParameterNames || [];
5609
+ templateJson.jokerParameterNames.push(command.parameterName);
4598
5610
  break;
4599
5611
  case 'MODEL':
4600
5612
  templateModelRequirements[command.key] = command.value;
@@ -4604,19 +5616,24 @@
4604
5616
  defineParam(command);
4605
5617
  break;
4606
5618
  case 'POSTPROCESS':
4607
- postprocessing.push(command.functionName);
5619
+ templateJson.postprocessingFunctionNames = templateJson.postprocessingFunctionNames || [];
5620
+ templateJson.postprocessingFunctionNames.push(command.functionName);
4608
5621
  break;
4609
5622
  case 'KNOWLEDGE':
4610
- console.error(new NotYetImplementedError('Knowledge is not implemented yet'));
5623
+ // TODO: [👙] The knowledge is maybe relevant for just this template
5624
+ knowledgeCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
4611
5625
  break;
4612
5626
  case 'ACTION':
5627
+ // TODO: [👙] The action is maybe relevant for just this template
4613
5628
  console.error(new NotYetImplementedError('Actions are not implemented yet'));
4614
5629
  break;
4615
5630
  case 'INSTRUMENT':
5631
+ // TODO: [👙] The instrument is maybe relevant for just this template
4616
5632
  console.error(new NotYetImplementedError('Instruments are not implemented yet'));
4617
5633
  break;
4618
5634
  case 'PERSONA':
4619
- console.error(new NotYetImplementedError('Personas are not implemented yet'));
5635
+ personaCommandParser.applyToPipelineJson(command, { pipelineJson: pipelineJson, templateJson: templateJson });
5636
+ // <- Note: Prototype of [🍧] (remove this comment after full implementation)
4620
5637
  break;
4621
5638
  case 'BOILERPLATE':
4622
5639
  console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
@@ -4634,70 +5651,29 @@
4634
5651
  }
4635
5652
  finally { if (e_3) throw e_3.error; }
4636
5653
  }
4637
- var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
4638
- if (blockType === 'SCRIPT') {
5654
+ // TODO: [🍧] Should be done in BLOCK command
5655
+ if (templateJson.blockType === 'SCRIPT') {
4639
5656
  if (!language) {
4640
5657
  throw new ParsingError('You must specify the language of the script in the prompt template');
4641
5658
  }
4642
- else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
5659
+ if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
4643
5660
  throw new ParsingError(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 "); }));
4644
5661
  }
5662
+ templateJson.contentLanguage = language;
4645
5663
  }
4646
- var lastLine = section.content.split('\n').pop();
4647
- var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
4648
- if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
4649
- throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
4650
- // TODO: Show code of invalid sections each time + DRY
4651
- section.content
4652
- .split('\n')
4653
- .map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
4654
- .join('\n')), "\n "); }));
4655
- }
4656
- var resultingParameterName = match.groups.resultingParamName;
4657
- // TODO: [1] DRY description
4658
- var description_1 = section.content;
4659
- // Note: Remove codeblocks
4660
- description_1 = description_1.split(/^```.*^```/gms).join('');
4661
- //Note: Remove lists and return statement
4662
- description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
4663
- description_1 = spaceTrim.spaceTrim(description_1);
4664
- if (description_1 === '') {
4665
- description_1 = undefined;
4666
- }
4667
- if (Object.keys(jokers).length === 0) {
4668
- jokers = undefined;
4669
- }
4670
- if (Object.keys(expectAmount).length === 0) {
4671
- expectAmount = undefined;
4672
- }
4673
- if (Object.keys(postprocessing).length === 0) {
4674
- postprocessing = undefined;
4675
- }
4676
- dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, blockType: blockType, content: content })));
5664
+ // TODO: [🍧][❔] Should be done in BLOCK command
4677
5665
  if (templateModelRequirements.modelVariant === undefined) {
4678
5666
  templateModelRequirements.modelVariant = 'CHAT';
4679
5667
  }
4680
- dependentParameterNames = difference(dependentParameterNames, new Set(RESERVED_PARAMETER_NAMES));
4681
- var template = {
4682
- name: titleToName(section.title),
4683
- title: section.title,
4684
- description: description_1,
4685
- dependentParameterNames: Array.from(dependentParameterNames),
4686
- blockType: blockType,
4687
- jokers: jokers,
4688
- postprocessing: postprocessing,
4689
- expectations: expectAmount,
4690
- expectFormat: expectFormat,
4691
- modelRequirements: templateModelRequirements,
4692
- contentLanguage: blockType === 'SCRIPT' ? language : undefined,
4693
- content: content,
4694
- resultingParameterName: resultingParameterName,
4695
- };
4696
- if (blockType !== 'PROMPT_TEMPLATE') {
4697
- delete template.modelRequirements;
5668
+ templateJson.dependentParameterNames = Array.from(extractParameterNamesFromPromptTemplate(templateJson));
5669
+ // TODO: [🍧][❔] Remove this condition - modelRequirements should be put here via BLOCK command not removed when PROMPT_TEMPLATE
5670
+ if (templateJson.blockType !== 'PROMPT_TEMPLATE') {
5671
+ delete templateJson.modelRequirements;
4698
5672
  }
5673
+ // TODO: [🍧] Make this better - for example each command parser can call and apply this
5674
+ templateJson.resultingParameterName = expectResultingParameterName( /* <- Note: This is once more redundant */);
4699
5675
  // TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
4700
- pipelineJson.promptTemplates.push(template /* <- !!! */);
5676
+ pipelineJson.promptTemplates.push(templateJson);
4701
5677
  };
4702
5678
  try {
4703
5679
  // =============================================================
@@ -4764,14 +5740,18 @@
4764
5740
  * TODO: Use spaceTrim more effectively
4765
5741
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
4766
5742
  * TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
5743
+ * TODO: [♈] Probbably move expectations from templates to parameters
5744
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5745
+ * TODO: [🍙] Make some standart order of json properties
4767
5746
  */
4768
5747
 
4769
5748
  /**
4770
- * Compile promptbook from string (markdown) format to JSON format
5749
+ * Compile pipeline from string (markdown) format to JSON format
4771
5750
  *
4772
- * Note: There are two similar functions:
5751
+ * Note: There are 3 similar functions:
4773
5752
  * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
4774
5753
  * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
5754
+ * - `preparePipeline` - just one step in the compilation process
4775
5755
  *
4776
5756
  * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
4777
5757
  * @param options - Options and tools for the compilation
@@ -4782,22 +5762,18 @@
4782
5762
  * Note: This function acts as compilation process
4783
5763
  */
4784
5764
  function pipelineStringToJson(pipelineString, options) {
4785
- if (options === void 0) { options = {}; }
5765
+ if (options === void 0) { options = { llmTools: null }; }
4786
5766
  return __awaiter(this, void 0, void 0, function () {
4787
- var llmTools, pipelineJson, knowledge;
5767
+ var llmTools, pipelineJson;
4788
5768
  return __generator(this, function (_a) {
4789
5769
  switch (_a.label) {
4790
5770
  case 0:
4791
5771
  llmTools = options.llmTools;
4792
5772
  pipelineJson = pipelineStringToJsonSync(pipelineString);
4793
- if (!llmTools) return [3 /*break*/, 2];
4794
- return [4 /*yield*/, prepareKnowledgeFromMarkdown({
4795
- content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
4796
- llmTools: llmTools,
4797
- })];
5773
+ if (!(llmTools !== null)) return [3 /*break*/, 2];
5774
+ return [4 /*yield*/, preparePipeline(pipelineJson, { llmTools: llmTools })];
4798
5775
  case 1:
4799
- knowledge = _a.sent();
4800
- pipelineJson = __assign(__assign({}, pipelineJson), { knowledge: __spreadArray(__spreadArray([], __read((pipelineJson.knowledge || [])), false), __read(knowledge), false) });
5776
+ pipelineJson = _a.sent();
4801
5777
  _a.label = 2;
4802
5778
  case 2: return [2 /*return*/, pipelineJson];
4803
5779
  }
@@ -4806,12 +5782,13 @@
4806
5782
  }
4807
5783
  /**
4808
5784
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
5785
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
4809
5786
  */
4810
5787
 
4811
5788
  /**
4812
5789
  * Add or modify an auto-generated section in a markdown file
4813
5790
  *
4814
- * @private within the package
5791
+ * @private within the repository
4815
5792
  */
4816
5793
  function addAutoGeneratedSection(content, options) {
4817
5794
  var sectionName = options.sectionName, sectionContent = options.sectionContent;
@@ -4823,7 +5800,10 @@
4823
5800
  }
4824
5801
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
4825
5802
  if (!placeForSection) {
4826
- throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
5803
+ throw new ParsingError(
5804
+ // <- [🧠] Maybe something better than `ParsingError`
5805
+ "No place where to put the section <!--".concat(sectionName, "-->"));
5806
+ // <- [🚞]
4827
5807
  }
4828
5808
  var _a = __read(placeForSection, 1), heading = _a[0];
4829
5809
  return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
@@ -4980,6 +5960,28 @@
4980
5960
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
4981
5961
  */
4982
5962
 
5963
+ /**
5964
+ * Stringify the PipelineJson with proper formatting
5965
+ *
5966
+ * Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
5967
+ * Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
5968
+ */
5969
+ function stringifyPipelineJson(pipeline) {
5970
+ var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
5971
+ for (var i = 0; i < LOOP_LIMIT; i++) {
5972
+ pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
5973
+ }
5974
+ pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
5975
+ pipelineJsonStringified += '\n';
5976
+ return pipelineJsonStringified;
5977
+ }
5978
+ /**
5979
+ * TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
5980
+ * TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
5981
+ * TODO: [🧠] Maybe more elegant solution than replacing via regex
5982
+ * TODO: [🍙] Make some standart order of json properties
5983
+ */
5984
+
4983
5985
  /**
4984
5986
  * This error indicates that the pipeline collection cannot be propperly loaded
4985
5987
  */
@@ -4994,6 +5996,20 @@
4994
5996
  return CollectionError;
4995
5997
  }(Error));
4996
5998
 
5999
+ /**
6000
+ * This error type indicates that the version of the pipeline is not matching the expected version
6001
+ */
6002
+ var VersionMismatchError = /** @class */ (function (_super) {
6003
+ __extends(VersionMismatchError, _super);
6004
+ function VersionMismatchError(message, expectedVersion) {
6005
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n This error indicates that there is error with compatibility\n\n Expected version:\n ").concat(expectedVersion, "\n\n Current version:\n ").concat(PROMPTBOOK_VERSION, "\n\n "); })) || this;
6006
+ _this.name = 'UnexpectedError';
6007
+ Object.setPrototypeOf(_this, VersionMismatchError.prototype);
6008
+ return _this;
6009
+ }
6010
+ return VersionMismatchError;
6011
+ }(Error));
6012
+
4997
6013
  /**
4998
6014
  * Pretty print an embedding vector for logging
4999
6015
  */
@@ -5081,6 +6097,9 @@
5081
6097
  };
5082
6098
  return SimplePromptInterfaceTools;
5083
6099
  }());
6100
+ /**
6101
+ * Note: [🔵] This code should never be published outside of `@promptbook/browser`
6102
+ */
5084
6103
 
5085
6104
  /**
5086
6105
  * Default options for generating an execution report string
@@ -5093,7 +6112,7 @@
5093
6112
  /**
5094
6113
  * Format either small or big number
5095
6114
  *
5096
- * @private within the package
6115
+ * @private within the repository
5097
6116
  */
5098
6117
  function formatNumber(value) {
5099
6118
  if (value === 0) {
@@ -5113,7 +6132,7 @@
5113
6132
  /**
5114
6133
  * Create a markdown table from a 2D array of strings
5115
6134
  *
5116
- * @private within the package
6135
+ * @private within the repository
5117
6136
  */
5118
6137
  function createMarkdownTable(table) {
5119
6138
  var columnWidths = table.reduce(function (widths, row) {
@@ -5141,7 +6160,7 @@
5141
6160
  /**
5142
6161
  * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
5143
6162
  *
5144
- * @private within the package
6163
+ * @private within the repository
5145
6164
  */
5146
6165
  function createMarkdownChart(options) {
5147
6166
  var e_1, _a;
@@ -5194,7 +6213,7 @@
5194
6213
  /**
5195
6214
  * Count the duration of working time
5196
6215
  *
5197
- * @private within the package
6216
+ * @private within the repository
5198
6217
  */
5199
6218
  function countWorkingDuration(items) {
5200
6219
  var e_1, _a;
@@ -5351,10 +6370,13 @@
5351
6370
  if (just(true)) {
5352
6371
  executionReportString +=
5353
6372
  '\n\n\n\n' +
5354
- spaceTrim.spaceTrim(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
6373
+ spaceTrim.spaceTrim(function (block) {
6374
+ var _a;
6375
+ 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 ");
6376
+ });
5355
6377
  }
5356
6378
  if (promptExecution.result && promptExecution.result.content) {
5357
- executionReportString += '\n\n\n\n' + '### Result';
6379
+ executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
5358
6380
  if (promptExecution.result === undefined) {
5359
6381
  executionReportString += '*No result*';
5360
6382
  }
@@ -5406,6 +6428,7 @@
5406
6428
  exports.ReferenceError = ReferenceError$1;
5407
6429
  exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
5408
6430
  exports.UnexpectedError = UnexpectedError;
6431
+ exports.VersionMismatchError = VersionMismatchError;
5409
6432
  exports.addUsage = addUsage;
5410
6433
  exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
5411
6434
  exports.checkExpectations = checkExpectations;
@@ -5423,7 +6446,10 @@
5423
6446
  exports.pipelineStringToJson = pipelineStringToJson;
5424
6447
  exports.pipelineStringToJsonSync = pipelineStringToJsonSync;
5425
6448
  exports.prepareKnowledgeFromMarkdown = prepareKnowledgeFromMarkdown;
6449
+ exports.preparePipeline = preparePipeline;
5426
6450
  exports.prettifyPipelineString = prettifyPipelineString;
6451
+ exports.stringifyPipelineJson = stringifyPipelineJson;
6452
+ exports.unpreparePipeline = unpreparePipeline;
5427
6453
  exports.usageToWorktime = usageToWorktime;
5428
6454
  exports.validatePipeline = validatePipeline;
5429
6455