@promptbook/core 0.60.0-0 → 0.60.0-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +3 -3
  2. package/esm/index.es.js +630 -631
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +23 -23
  5. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +11 -11
  7. package/esm/typings/src/_packages/utils.index.d.ts +9 -11
  8. package/esm/typings/src/config.d.ts +1 -1
  9. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +12 -0
  10. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +32 -0
  11. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +23 -0
  12. package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +1 -1
  13. package/{umd/typings/src/conversion/prettify/prettifyPromptbookString.d.ts → esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts} +2 -2
  14. package/esm/typings/src/conversion/prettify/{renderPromptbookMermaid.d.ts → renderPipelineMermaidOptions.d.ts} +4 -4
  15. package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
  16. package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
  17. package/esm/typings/src/conversion/utils/parseCommand.d.ts +2 -2
  18. package/esm/typings/src/conversion/utils/parseNumber.d.ts +1 -1
  19. package/esm/typings/src/conversion/utils/renameParameter.d.ts +4 -4
  20. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +13 -0
  21. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +27 -0
  22. package/{umd/typings/src/errors/PromptbookLibraryError.d.ts → esm/typings/src/errors/CollectionError.d.ts} +2 -2
  23. package/esm/typings/src/errors/{PromptbookExecutionError.d.ts → ExecutionError.d.ts} +2 -2
  24. package/{umd/typings/src/errors/PromptbookNotFoundError.d.ts → esm/typings/src/errors/NotFoundError.d.ts} +2 -2
  25. package/{umd/typings/src/errors/PromptbookLogicError.d.ts → esm/typings/src/errors/PipelineLogicError.d.ts} +2 -2
  26. package/{umd/typings/src/errors/PromptbookReferenceError.d.ts → esm/typings/src/errors/ReferenceError.d.ts} +2 -2
  27. package/esm/typings/src/errors/{PromptbookSyntaxError.d.ts → SyntaxError.d.ts} +2 -2
  28. package/esm/typings/src/errors/TemplateError.d.ts +1 -1
  29. package/esm/typings/src/errors/_ExpectError.d.ts +2 -2
  30. package/esm/typings/src/execution/ExecutionTools.d.ts +1 -1
  31. package/esm/typings/src/execution/LlmExecutionTools.d.ts +4 -4
  32. package/esm/typings/src/execution/PromptResult.d.ts +1 -1
  33. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
  34. package/esm/typings/src/execution/createPromptbookExecutor.d.ts +3 -3
  35. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
  36. package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
  37. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
  38. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
  39. package/esm/typings/src/library/PipelineCollection.d.ts +25 -0
  40. package/esm/typings/src/library/{SimplePromptbookLibrary.d.ts → SimplePipelineCollection.d.ts} +11 -11
  41. package/{umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createCollectionFromDirectory.d.ts} +5 -5
  42. package/esm/typings/src/library/constructors/createCollectionFromJson.d.ts +12 -0
  43. package/esm/typings/src/library/constructors/createCollectionFromPromise.d.ts +22 -0
  44. package/esm/typings/src/library/constructors/{createLibraryFromUrl.d.ts → createCollectionFromUrl.d.ts} +5 -5
  45. package/esm/typings/src/library/constructors/createSubcollection.d.ts +12 -0
  46. package/esm/typings/src/library/libraryToJson.d.ts +5 -5
  47. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
  48. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -3
  49. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
  50. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
  51. package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
  52. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -3
  53. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
  54. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  55. package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  56. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -3
  57. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
  58. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  59. package/esm/typings/src/types/Command.d.ts +4 -4
  60. package/esm/typings/src/types/Parameters.d.ts +1 -1
  61. package/esm/typings/src/types/{PromptbookJson/PromptbookJson.d.ts → PipelineJson/PipelineJson.d.ts} +5 -5
  62. package/{umd/typings/src/types/PromptbookString.d.ts → esm/typings/src/types/PipelineString.d.ts} +3 -3
  63. package/esm/typings/src/types/Prompt.d.ts +4 -4
  64. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +2 -2
  65. package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  66. package/esm/typings/src/types/typeAliases.d.ts +4 -4
  67. package/esm/typings/src/utils/emojis.d.ts +2 -2
  68. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
  69. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
  70. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
  71. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
  72. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  73. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
  74. package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -2
  75. package/esm/typings/src/utils/formatNumber.d.ts +1 -1
  76. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
  77. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
  78. package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  79. package/esm/typings/src/utils/markdown-json/MarkdownStructure.d.ts +1 -1
  80. package/esm/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  81. package/esm/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  82. package/package.json +2 -2
  83. package/umd/index.umd.js +624 -625
  84. package/umd/index.umd.js.map +1 -1
  85. package/umd/typings/src/_packages/core.index.d.ts +23 -23
  86. package/umd/typings/src/_packages/node.index.d.ts +2 -2
  87. package/umd/typings/src/_packages/types.index.d.ts +11 -11
  88. package/umd/typings/src/_packages/utils.index.d.ts +9 -11
  89. package/umd/typings/src/config.d.ts +1 -1
  90. package/umd/typings/src/conversion/pipelineJsonToString.d.ts +12 -0
  91. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +32 -0
  92. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +23 -0
  93. package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +1 -1
  94. package/{esm/typings/src/conversion/prettify/prettifyPromptbookString.d.ts → umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts} +2 -2
  95. package/umd/typings/src/conversion/prettify/{renderPromptbookMermaid.d.ts → renderPipelineMermaidOptions.d.ts} +4 -4
  96. package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
  97. package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -1
  98. package/umd/typings/src/conversion/utils/parseCommand.d.ts +2 -2
  99. package/umd/typings/src/conversion/utils/parseNumber.d.ts +1 -1
  100. package/umd/typings/src/conversion/utils/renameParameter.d.ts +4 -4
  101. package/umd/typings/src/conversion/validation/_importPipeline.d.ts +13 -0
  102. package/umd/typings/src/conversion/validation/validatePipeline.d.ts +27 -0
  103. package/{esm/typings/src/errors/PromptbookLibraryError.d.ts → umd/typings/src/errors/CollectionError.d.ts} +2 -2
  104. package/umd/typings/src/errors/{PromptbookExecutionError.d.ts → ExecutionError.d.ts} +2 -2
  105. package/{esm/typings/src/errors/PromptbookNotFoundError.d.ts → umd/typings/src/errors/NotFoundError.d.ts} +2 -2
  106. package/{esm/typings/src/errors/PromptbookLogicError.d.ts → umd/typings/src/errors/PipelineLogicError.d.ts} +2 -2
  107. package/{esm/typings/src/errors/PromptbookReferenceError.d.ts → umd/typings/src/errors/ReferenceError.d.ts} +2 -2
  108. package/umd/typings/src/errors/{PromptbookSyntaxError.d.ts → SyntaxError.d.ts} +2 -2
  109. package/umd/typings/src/errors/TemplateError.d.ts +1 -1
  110. package/umd/typings/src/errors/_ExpectError.d.ts +2 -2
  111. package/umd/typings/src/execution/ExecutionTools.d.ts +1 -1
  112. package/umd/typings/src/execution/LlmExecutionTools.d.ts +4 -4
  113. package/umd/typings/src/execution/PromptResult.d.ts +1 -1
  114. package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
  115. package/umd/typings/src/execution/createPromptbookExecutor.d.ts +3 -3
  116. package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
  117. package/umd/typings/src/execution/utils/checkExpectations.d.ts +1 -1
  118. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
  119. package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
  120. package/umd/typings/src/library/PipelineCollection.d.ts +25 -0
  121. package/umd/typings/src/library/{SimplePromptbookLibrary.d.ts → SimplePipelineCollection.d.ts} +11 -11
  122. package/{esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createCollectionFromDirectory.d.ts} +5 -5
  123. package/umd/typings/src/library/constructors/createCollectionFromJson.d.ts +12 -0
  124. package/umd/typings/src/library/constructors/createCollectionFromPromise.d.ts +22 -0
  125. package/umd/typings/src/library/constructors/{createLibraryFromUrl.d.ts → createCollectionFromUrl.d.ts} +5 -5
  126. package/umd/typings/src/library/constructors/createSubcollection.d.ts +12 -0
  127. package/umd/typings/src/library/libraryToJson.d.ts +5 -5
  128. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -3
  129. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -3
  130. package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -2
  131. package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
  132. package/umd/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
  133. package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -3
  134. package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -3
  135. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  136. package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  137. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -3
  138. package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +2 -2
  139. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  140. package/umd/typings/src/types/Command.d.ts +4 -4
  141. package/umd/typings/src/types/Parameters.d.ts +1 -1
  142. package/umd/typings/src/types/{PromptbookJson/PromptbookJson.d.ts → PipelineJson/PipelineJson.d.ts} +5 -5
  143. package/{esm/typings/src/types/PromptbookString.d.ts → umd/typings/src/types/PipelineString.d.ts} +3 -3
  144. package/umd/typings/src/types/Prompt.d.ts +4 -4
  145. package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +2 -2
  146. package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  147. package/umd/typings/src/types/typeAliases.d.ts +4 -4
  148. package/umd/typings/src/utils/emojis.d.ts +2 -2
  149. package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
  150. package/umd/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
  151. package/umd/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
  152. package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
  153. package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
  154. package/umd/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
  155. package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -2
  156. package/umd/typings/src/utils/formatNumber.d.ts +1 -1
  157. package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
  158. package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
  159. package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  160. package/umd/typings/src/utils/markdown-json/MarkdownStructure.d.ts +1 -1
  161. package/umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  162. package/umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  163. package/esm/typings/src/conversion/promptbookJsonToString.d.ts +0 -12
  164. package/esm/typings/src/conversion/promptbookStringToJson.d.ts +0 -32
  165. package/esm/typings/src/conversion/promptbookStringToJsonSync.d.ts +0 -23
  166. package/esm/typings/src/conversion/validation/_importPromptbook.d.ts +0 -13
  167. package/esm/typings/src/conversion/validation/validatePromptbook.d.ts +0 -27
  168. package/esm/typings/src/library/PromptbookLibrary.d.ts +0 -25
  169. package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +0 -12
  170. package/esm/typings/src/library/constructors/createLibraryFromPromise.d.ts +0 -22
  171. package/esm/typings/src/library/constructors/createSublibrary.d.ts +0 -12
  172. package/umd/typings/src/conversion/promptbookJsonToString.d.ts +0 -12
  173. package/umd/typings/src/conversion/promptbookStringToJson.d.ts +0 -32
  174. package/umd/typings/src/conversion/promptbookStringToJsonSync.d.ts +0 -23
  175. package/umd/typings/src/conversion/validation/_importPromptbook.d.ts +0 -13
  176. package/umd/typings/src/conversion/validation/validatePromptbook.d.ts +0 -27
  177. package/umd/typings/src/library/PromptbookLibrary.d.ts +0 -25
  178. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +0 -12
  179. package/umd/typings/src/library/constructors/createLibraryFromPromise.d.ts +0 -22
  180. package/umd/typings/src/library/constructors/createSublibrary.d.ts +0 -12
  181. /package/esm/typings/{promptbook-library → promptbook-collection}/index.d.ts +0 -0
  182. /package/esm/typings/src/conversion/{promptbookStringToJson.test.d.ts → pipelineStringToJson.test.d.ts} +0 -0
  183. /package/esm/typings/src/conversion/{promptbookStringToJsonSync.test.d.ts → pipelineStringToJsonSync.test.d.ts} +0 -0
  184. /package/esm/typings/src/conversion/validation/{promptbookStringToJson-syntaxErrors.test.d.ts → pipelineStringToJson-syntaxErrors.test.d.ts} +0 -0
  185. /package/esm/typings/src/conversion/validation/{validatePromptbook-logicErrors.test.d.ts → validatePipeline-logicErrors.test.d.ts} +0 -0
  186. /package/esm/typings/src/conversion/validation/{validatePromptbook.test.d.ts → validatePipeline.test.d.ts} +0 -0
  187. /package/esm/typings/src/library/constructors/{createLibraryFromDirectory.test.d.ts → createCollectionFromDirectory.test.d.ts} +0 -0
  188. /package/esm/typings/src/library/constructors/{createLibraryFromJson.test.d.ts → createCollectionFromJson.test.d.ts} +0 -0
  189. /package/esm/typings/src/library/constructors/{createLibraryFromPromise.test.d.ts → createCollectionFromPromise.test.d.ts} +0 -0
  190. /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/KnowledgeJson.d.ts +0 -0
  191. /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/MaterialKnowledgePieceJson.d.ts +0 -0
  192. /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateJson.d.ts +0 -0
  193. /package/esm/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateParameterJson.d.ts +0 -0
  194. /package/umd/typings/{promptbook-library → promptbook-collection}/index.d.ts +0 -0
  195. /package/umd/typings/src/conversion/{promptbookStringToJson.test.d.ts → pipelineStringToJson.test.d.ts} +0 -0
  196. /package/umd/typings/src/conversion/{promptbookStringToJsonSync.test.d.ts → pipelineStringToJsonSync.test.d.ts} +0 -0
  197. /package/umd/typings/src/conversion/validation/{promptbookStringToJson-syntaxErrors.test.d.ts → pipelineStringToJson-syntaxErrors.test.d.ts} +0 -0
  198. /package/umd/typings/src/conversion/validation/{validatePromptbook-logicErrors.test.d.ts → validatePipeline-logicErrors.test.d.ts} +0 -0
  199. /package/umd/typings/src/conversion/validation/{validatePromptbook.test.d.ts → validatePipeline.test.d.ts} +0 -0
  200. /package/umd/typings/src/library/constructors/{createLibraryFromDirectory.test.d.ts → createCollectionFromDirectory.test.d.ts} +0 -0
  201. /package/umd/typings/src/library/constructors/{createLibraryFromJson.test.d.ts → createCollectionFromJson.test.d.ts} +0 -0
  202. /package/umd/typings/src/library/constructors/{createLibraryFromPromise.test.d.ts → createCollectionFromPromise.test.d.ts} +0 -0
  203. /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/KnowledgeJson.d.ts +0 -0
  204. /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/MaterialKnowledgePieceJson.d.ts +0 -0
  205. /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateJson.d.ts +0 -0
  206. /package/umd/typings/src/types/{PromptbookJson → PipelineJson}/PromptTemplateParameterJson.d.ts +0 -0
package/umd/index.umd.js CHANGED
@@ -129,37 +129,6 @@
129
129
  return to.concat(ar || Array.prototype.slice.call(from));
130
130
  }
131
131
 
132
- /**
133
- * Removes HTML or Markdown comments from a string.
134
- *
135
- * @param {string} content - The string to remove comments from.
136
- * @returns {string} The input string with all comments removed.
137
- */
138
- function removeContentComments(content) {
139
- return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
140
- }
141
-
142
- /**
143
- * Add or modify an auto-generated section in a markdown file
144
- *
145
- * @private within the library
146
- */
147
- function addAutoGeneratedSection(content, options) {
148
- var sectionName = options.sectionName, sectionContent = options.sectionContent;
149
- var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
150
- var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
151
- var sectionMatch = content.match(sectionRegex);
152
- if (sectionMatch) {
153
- return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
154
- }
155
- var placeForSection = removeContentComments(content).match(/^##.*$/im);
156
- if (!placeForSection) {
157
- throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
158
- }
159
- var _a = __read(placeForSection, 1), heading = _a[0];
160
- return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
161
- }
162
-
163
132
  /**
164
133
  * Prettify the html code
165
134
  *
@@ -192,27 +161,234 @@
192
161
  }
193
162
  }
194
163
 
195
- var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0",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"],executionType:"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:[]},{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0",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"],executionType:"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:[]}];
164
+ /**
165
+ * Makes first letter of a string uppercase
166
+ *
167
+ */
168
+ function capitalize(word) {
169
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
170
+ }
171
+
172
+ /**
173
+ * Converts promptbook in JSON format to string format
174
+ *
175
+ * @param pipelineJson Promptbook in JSON format (.ptbk.json)
176
+ * @returns Promptbook in string format (.ptbk.md)
177
+ */
178
+ function pipelineJsonToString(pipelineJson) {
179
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
180
+ var title = pipelineJson.title, promptbookUrl = pipelineJson.promptbookUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
181
+ var pipelineString = "# ".concat(title);
182
+ if (description) {
183
+ pipelineString += '\n\n';
184
+ pipelineString += description;
185
+ }
186
+ // TODO:> const commands: Array<Command>
187
+ var commands = [];
188
+ if (promptbookUrl) {
189
+ commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
190
+ }
191
+ commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
192
+ pipelineString = prettifyMarkdown(pipelineString);
193
+ try {
194
+ for (var _g = __values(parameters.filter(function (_a) {
195
+ var isInput = _a.isInput;
196
+ return isInput;
197
+ })), _h = _g.next(); !_h.done; _h = _g.next()) {
198
+ var parameter = _h.value;
199
+ commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
200
+ }
201
+ }
202
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
203
+ finally {
204
+ try {
205
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
206
+ }
207
+ finally { if (e_1) throw e_1.error; }
208
+ }
209
+ try {
210
+ for (var _j = __values(parameters.filter(function (_a) {
211
+ var isOutput = _a.isOutput;
212
+ return isOutput;
213
+ })), _k = _j.next(); !_k.done; _k = _j.next()) {
214
+ var parameter = _k.value;
215
+ commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
216
+ }
217
+ }
218
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
219
+ finally {
220
+ try {
221
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
222
+ }
223
+ finally { if (e_2) throw e_2.error; }
224
+ }
225
+ pipelineString += '\n\n';
226
+ pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
227
+ try {
228
+ for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
229
+ var promptTemplate = promptTemplates_1_1.value;
230
+ var
231
+ /* Note: Not using:> name, */
232
+ title_1 = promptTemplate.title, description_1 = promptTemplate.description,
233
+ /* Note: dependentParameterNames, */
234
+ jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
235
+ pipelineString += '\n\n';
236
+ pipelineString += "## ".concat(title_1);
237
+ if (description_1) {
238
+ pipelineString += '\n\n';
239
+ pipelineString += description_1;
240
+ }
241
+ // TODO:> const commands: Array<Command>
242
+ var commands_1 = [];
243
+ var contentLanguage = 'text';
244
+ if (executionType === 'PROMPT_TEMPLATE') {
245
+ var modelRequirements = promptTemplate.modelRequirements;
246
+ var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
247
+ commands_1.push("EXECUTE PROMPT TEMPLATE");
248
+ if (modelVariant) {
249
+ commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
250
+ }
251
+ if (modelName) {
252
+ commands_1.push("MODEL NAME `".concat(modelName, "`"));
253
+ }
254
+ }
255
+ else if (executionType === 'SIMPLE_TEMPLATE') {
256
+ commands_1.push("SIMPLE TEMPLATE");
257
+ // Note: Nothing special here
258
+ }
259
+ else if (executionType === 'SCRIPT') {
260
+ commands_1.push("EXECUTE SCRIPT");
261
+ if (promptTemplate.contentLanguage) {
262
+ contentLanguage = promptTemplate.contentLanguage;
263
+ }
264
+ else {
265
+ contentLanguage = '';
266
+ }
267
+ }
268
+ else if (executionType === 'PROMPT_DIALOG') {
269
+ commands_1.push("PROMPT DIALOG");
270
+ // Note: Nothing special here
271
+ }
272
+ if (jokers) {
273
+ try {
274
+ for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
275
+ var joker = jokers_1_1.value;
276
+ commands_1.push("JOKER {".concat(joker, "}"));
277
+ }
278
+ }
279
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
280
+ finally {
281
+ try {
282
+ if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
283
+ }
284
+ finally { if (e_4) throw e_4.error; }
285
+ }
286
+ } /* not else */
287
+ if (postprocessing) {
288
+ try {
289
+ for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
290
+ var postprocessingFunctionName = postprocessing_1_1.value;
291
+ commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
292
+ }
293
+ }
294
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
295
+ finally {
296
+ try {
297
+ if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
298
+ }
299
+ finally { if (e_5) throw e_5.error; }
300
+ }
301
+ } /* not else */
302
+ if (expectations) {
303
+ try {
304
+ for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
305
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
306
+ if (min === max) {
307
+ commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
308
+ }
309
+ else {
310
+ if (min !== undefined) {
311
+ commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
312
+ } /* not else */
313
+ if (max !== undefined) {
314
+ commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
315
+ }
316
+ }
317
+ }
318
+ }
319
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
320
+ finally {
321
+ try {
322
+ if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
323
+ }
324
+ finally { if (e_6) throw e_6.error; }
325
+ }
326
+ } /* not else */
327
+ if (expectFormat) {
328
+ if (expectFormat === 'JSON') {
329
+ // TODO: @deprecated remove
330
+ commands_1.push("EXPECT JSON");
331
+ }
332
+ } /* not else */
333
+ pipelineString += '\n\n';
334
+ pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
335
+ pipelineString += '\n\n';
336
+ pipelineString += '```' + contentLanguage;
337
+ pipelineString += '\n';
338
+ pipelineString += spaceTrim__default["default"](content);
339
+ // <- TODO: !!! Escape
340
+ // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
341
+ pipelineString += '\n';
342
+ pipelineString += '```';
343
+ pipelineString += '\n\n';
344
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
345
+ }
346
+ }
347
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
348
+ finally {
349
+ try {
350
+ if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
351
+ }
352
+ finally { if (e_3) throw e_3.error; }
353
+ }
354
+ return pipelineString;
355
+ }
356
+ /**
357
+ * @private internal util of pipelineJsonToString
358
+ */
359
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
360
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
361
+ var parameterString = "{".concat(name, "}");
362
+ if (description) {
363
+ parameterString = "".concat(parameterString, " ").concat(description);
364
+ }
365
+ return parameterString;
366
+ }
367
+ /**
368
+ * TODO: Escape all
369
+ */
370
+
371
+ var PipelineCollection = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-3",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"],executionType:"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:[]},{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.60.0-3",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"],executionType:"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:[]}];
196
372
 
197
373
  /**
198
374
  * This error indicates errors during the execution of the promptbook
199
375
  */
200
- var PromptbookExecutionError = /** @class */ (function (_super) {
201
- __extends(PromptbookExecutionError, _super);
202
- function PromptbookExecutionError(message) {
376
+ var ExecutionError = /** @class */ (function (_super) {
377
+ __extends(ExecutionError, _super);
378
+ function ExecutionError(message) {
203
379
  var _this = _super.call(this, message) || this;
204
- _this.name = 'PromptbookExecutionError';
205
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
380
+ _this.name = 'ExecutionError';
381
+ Object.setPrototypeOf(_this, ExecutionError.prototype);
206
382
  return _this;
207
383
  }
208
- return PromptbookExecutionError;
384
+ return ExecutionError;
209
385
  }(Error));
210
386
 
211
387
  /**
212
388
  * Asserts that the execution of a promptnook is successful
213
389
  *
214
390
  * @param executionResult - The partial result of the promptnook execution
215
- * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
391
+ * @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
216
392
  */
217
393
  function assertsExecutionSuccessful(executionResult) {
218
394
  var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
@@ -220,13 +396,13 @@
220
396
  return;
221
397
  }
222
398
  if (errors.length === 0) {
223
- throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
399
+ throw new ExecutionError("Promptnook Execution failed because of unknown reason");
224
400
  }
225
401
  else if (errors.length === 1) {
226
402
  throw errors[0];
227
403
  }
228
404
  else {
229
- throw new PromptbookExecutionError(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 "); }));
405
+ throw new ExecutionError(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 "); }));
230
406
  }
231
407
  }
232
408
  /**
@@ -241,29 +417,29 @@
241
417
  /**
242
418
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
243
419
  */
244
- var PromptbookLogicError = /** @class */ (function (_super) {
245
- __extends(PromptbookLogicError, _super);
246
- function PromptbookLogicError(message) {
420
+ var PipelineLogicError = /** @class */ (function (_super) {
421
+ __extends(PipelineLogicError, _super);
422
+ function PipelineLogicError(message) {
247
423
  var _this = _super.call(this, message) || this;
248
- _this.name = 'PromptbookLogicError';
249
- Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
424
+ _this.name = 'PipelineLogicError';
425
+ Object.setPrototypeOf(_this, PipelineLogicError.prototype);
250
426
  return _this;
251
427
  }
252
- return PromptbookLogicError;
428
+ return PipelineLogicError;
253
429
  }(Error));
254
430
 
255
431
  /**
256
432
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
257
433
  */
258
- var PromptbookSyntaxError = /** @class */ (function (_super) {
259
- __extends(PromptbookSyntaxError, _super);
260
- function PromptbookSyntaxError(message) {
434
+ var SyntaxError = /** @class */ (function (_super) {
435
+ __extends(SyntaxError, _super);
436
+ function SyntaxError(message) {
261
437
  var _this = _super.call(this, message) || this;
262
- _this.name = 'PromptbookSyntaxError';
263
- Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
438
+ _this.name = 'SyntaxError';
439
+ Object.setPrototypeOf(_this, SyntaxError.prototype);
264
440
  return _this;
265
441
  }
266
- return PromptbookSyntaxError;
442
+ return SyntaxError;
267
443
  }(Error));
268
444
 
269
445
  /**
@@ -306,7 +482,7 @@
306
482
  }
307
483
 
308
484
  /**
309
- * Validates PromptbookJson if it is logically valid
485
+ * Validates PipelineJson if it is logically valid
310
486
  *
311
487
  * It checks:
312
488
  * - if it has correct parameters dependency
@@ -315,48 +491,48 @@
315
491
  * - if it is valid json
316
492
  * - if it is meaningful
317
493
  *
318
- * @param promptbook valid or invalid PromptbookJson
319
- * @returns the same promptbook if it is logically valid
320
- * @throws {PromptbookLogicError} on logical error in the promptbook
494
+ * @param pipeline valid or invalid PipelineJson
495
+ * @returns the same pipeline if it is logically valid
496
+ * @throws {PipelineLogicError} on logical error in the pipeline
321
497
  */
322
- function validatePromptbook(promptbook) {
498
+ function validatePipeline(pipeline) {
323
499
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
324
500
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
325
- if (promptbook.promptbookUrl !== undefined) {
326
- if (!isValidUrl(promptbook.promptbookUrl)) {
501
+ if (pipeline.promptbookUrl !== undefined) {
502
+ if (!isValidUrl(pipeline.promptbookUrl)) {
327
503
  // TODO: This should be maybe the syntax error detected during parsing
328
- throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
504
+ throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.promptbookUrl, "\""));
329
505
  }
330
506
  }
331
507
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
332
- if (!Array.isArray(promptbook.parameters)) {
508
+ if (!Array.isArray(pipeline.parameters)) {
333
509
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
334
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
510
+ throw new SyntaxError(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 ")));
335
511
  }
336
512
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
337
- if (!Array.isArray(promptbook.promptTemplates)) {
513
+ if (!Array.isArray(pipeline.promptTemplates)) {
338
514
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
339
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
515
+ throw new SyntaxError(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 ")));
340
516
  }
341
517
  var _loop_1 = function (parameter) {
342
518
  if (parameter.isInput && parameter.isOutput) {
343
- throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
519
+ throw new PipelineLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
344
520
  }
345
521
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
346
522
  if (!parameter.isInput &&
347
523
  !parameter.isOutput &&
348
- !promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
349
- throw new PromptbookLogicError(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 ")));
524
+ !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
525
+ 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 ")));
350
526
  }
351
527
  // Note: Testing that parameter is either input or result of some template
352
528
  if (!parameter.isInput &&
353
- !promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
354
- throw new PromptbookLogicError(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 ")));
529
+ !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
530
+ 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 ")));
355
531
  }
356
532
  };
357
533
  try {
358
534
  // Note: Check each parameter individually
359
- for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
535
+ for (var _e = __values(pipeline.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
360
536
  var parameter = _f.value;
361
537
  _loop_1(parameter);
362
538
  }
@@ -369,7 +545,7 @@
369
545
  finally { if (e_1) throw e_1.error; }
370
546
  }
371
547
  // Note: Check each template individually
372
- var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
548
+ var definedParameters = new Set(pipeline.parameters.filter(function (_a) {
373
549
  var isInput = _a.isInput;
374
550
  return isInput;
375
551
  }).map(function (_a) {
@@ -377,25 +553,25 @@
377
553
  return name;
378
554
  }));
379
555
  try {
380
- for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
556
+ for (var _g = __values(pipeline.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
381
557
  var template = _h.value;
382
558
  if (definedParameters.has(template.resultingParameterName)) {
383
- throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
559
+ throw new PipelineLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
384
560
  }
385
561
  definedParameters.add(template.resultingParameterName);
386
562
  if (template.executionType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
387
- throw new PromptbookLogicError(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 ")));
563
+ 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 ")));
388
564
  }
389
565
  if (template.jokers && template.jokers.length > 0) {
390
566
  if (!template.expectFormat &&
391
567
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
392
- throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
568
+ throw new PipelineLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
393
569
  }
394
570
  try {
395
571
  for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
396
572
  var joker = _k.value;
397
573
  if (!template.dependentParameterNames.includes(joker)) {
398
- throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
574
+ throw new PipelineLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
399
575
  }
400
576
  }
401
577
  }
@@ -412,13 +588,13 @@
412
588
  for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
413
589
  var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
414
590
  if (min !== undefined && max !== undefined && min > max) {
415
- throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
591
+ throw new PipelineLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
416
592
  }
417
593
  if (min !== undefined && min < 0) {
418
- throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
594
+ throw new PipelineLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
419
595
  }
420
596
  if (max !== undefined && max <= 0) {
421
- throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
597
+ throw new PipelineLogicError("Max expectation of ".concat(unit, " must be positive"));
422
598
  }
423
599
  }
424
600
  }
@@ -440,7 +616,7 @@
440
616
  finally { if (e_2) throw e_2.error; }
441
617
  }
442
618
  // Note: Detect circular dependencies
443
- var resovedParameters = promptbook.parameters
619
+ var resovedParameters = pipeline.parameters
444
620
  .filter(function (_a) {
445
621
  var isInput = _a.isInput;
446
622
  return isInput;
@@ -449,17 +625,17 @@
449
625
  var name = _a.name;
450
626
  return name;
451
627
  });
452
- var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
628
+ var unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
453
629
  var loopLimit = LOOP_LIMIT;
454
630
  var _loop_2 = function () {
455
631
  if (loopLimit-- < 0) {
456
- throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbook`');
632
+ throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePipeline`');
457
633
  }
458
634
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
459
635
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
460
636
  });
461
637
  if (currentlyResovedTemplates.length === 0) {
462
- throw new PromptbookLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
638
+ throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
463
639
  .map(function (_a) {
464
640
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
465
641
  return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
@@ -477,25 +653,25 @@
477
653
  while (unresovedTemplates.length > 0) {
478
654
  _loop_2();
479
655
  }
480
- return promptbook;
656
+ return pipeline;
481
657
  }
482
658
  /**
483
659
  * TODO: [🧠] Work with promptbookVersion
484
660
  * TODO: Use here some json-schema, Zod or something similar and change it to:
485
661
  * > /**
486
- * > * Validates PromptbookJson if it is logically valid.
662
+ * > * Validates PipelineJson if it is logically valid.
487
663
  * > *
488
664
  * > * It checks:
489
665
  * > * - it has a valid structure
490
666
  * > * - ...
491
- * > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
667
+ * > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
492
668
  */
493
669
 
494
670
  /**
495
671
  * This error occurs when some expectation is not met in the execution of the pipeline
496
672
  *
497
- * @private Always catched and rethrown as `PromptbookExecutionError`
498
- * Note: This is a kindof subtype of PromptbookExecutionError
673
+ * @private Always catched and rethrown as `ExecutionError`
674
+ * Note: This is a kindof subtype of ExecutionError
499
675
  */
500
676
  var ExpectError = /** @class */ (function (_super) {
501
677
  __extends(ExpectError, _super);
@@ -530,7 +706,7 @@
530
706
  /**
531
707
  * The version of the Promptbook library
532
708
  */
533
- var PROMPTBOOK_VERSION = '0.59.0';
709
+ var PROMPTBOOK_VERSION = '0.60.0-3';
534
710
 
535
711
  /**
536
712
  * Function `addUsage` will add multiple usages into one
@@ -1009,7 +1185,7 @@
1009
1185
  /**
1010
1186
  * This error occurs during the parameter replacement in the template
1011
1187
  *
1012
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
1188
+ * Note: This is a kindof subtype of ExecutionError because it occurs during the execution of the pipeline
1013
1189
  */
1014
1190
  var TemplateError = /** @class */ (function (_super) {
1015
1191
  __extends(TemplateError, _super);
@@ -1086,13 +1262,13 @@
1086
1262
  * Creates executor function from promptbook and execution tools.
1087
1263
  *
1088
1264
  * @returns The executor function
1089
- * @throws {PromptbookLogicError} on logical error in the promptbook
1265
+ * @throws {PipelineLogicError} on logical error in the promptbook
1090
1266
  */
1091
1267
  function createPromptbookExecutor(options) {
1092
1268
  var _this = this;
1093
1269
  var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1094
1270
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1095
- validatePromptbook(promptbook);
1271
+ validatePipeline(promptbook);
1096
1272
  var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1097
1273
  function executeSingleTemplate(currentTemplate) {
1098
1274
  return __awaiter(this, void 0, void 0, function () {
@@ -1139,7 +1315,7 @@
1139
1315
  expectError = null;
1140
1316
  if (isJokerAttempt) {
1141
1317
  if (typeof parametersToPass[joker] === 'undefined') {
1142
- throw new PromptbookExecutionError("Joker parameter {".concat(joker, "} not defined"));
1318
+ throw new ExecutionError("Joker parameter {".concat(joker, "} not defined"));
1143
1319
  }
1144
1320
  resultString = parametersToPass[joker];
1145
1321
  }
@@ -1219,13 +1395,13 @@
1219
1395
  return [7 /*endfinally*/];
1220
1396
  case 10:
1221
1397
  if (errors.length === 0) {
1222
- throw new PromptbookExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
1398
+ throw new ExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
1223
1399
  }
1224
1400
  else if (errors.length === 1) {
1225
1401
  throw errors[0];
1226
1402
  }
1227
1403
  else {
1228
- throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
1404
+ throw new ExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
1229
1405
  }
1230
1406
  }
1231
1407
  });
@@ -1237,27 +1413,27 @@
1237
1413
  case 'COMPLETION': return [3 /*break*/, 9];
1238
1414
  }
1239
1415
  return [3 /*break*/, 11];
1240
- case 7: return [4 /*yield*/, tools.llm.gptChat(prompt)];
1416
+ case 7: return [4 /*yield*/, tools.llm.callChatModel(prompt)];
1241
1417
  case 8:
1242
1418
  chatThread = _o.sent();
1243
1419
  // TODO: [🍬] Destroy chatThread
1244
1420
  result = chatThread;
1245
1421
  resultString = chatThread.content;
1246
1422
  return [3 /*break*/, 12];
1247
- case 9: return [4 /*yield*/, tools.llm.gptComplete(prompt)];
1423
+ case 9: return [4 /*yield*/, tools.llm.callCompletionModel(prompt)];
1248
1424
  case 10:
1249
1425
  completionResult = _o.sent();
1250
1426
  result = completionResult;
1251
1427
  resultString = completionResult.content;
1252
1428
  return [3 /*break*/, 12];
1253
- case 11: throw new PromptbookExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
1429
+ case 11: throw new ExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
1254
1430
  case 12: return [3 /*break*/, 27];
1255
1431
  case 13:
1256
1432
  if (tools.script.length === 0) {
1257
- throw new PromptbookExecutionError('No script execution tools are available');
1433
+ throw new ExecutionError('No script execution tools are available');
1258
1434
  }
1259
1435
  if (!currentTemplate.contentLanguage) {
1260
- throw new PromptbookExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
1436
+ throw new ExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
1261
1437
  }
1262
1438
  // TODO: DRY [1]
1263
1439
  scriptExecutionErrors = [];
@@ -1309,13 +1485,13 @@
1309
1485
  throw scriptExecutionErrors[0];
1310
1486
  }
1311
1487
  else {
1312
- throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
1488
+ throw new ExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
1313
1489
  .map(function (error) { return '- ' + error.message; })
1314
1490
  .join('\n\n')), "\n "); }));
1315
1491
  }
1316
1492
  case 24:
1317
1493
  if (tools.userInterface === undefined) {
1318
- throw new PromptbookExecutionError('User interface tools are not available');
1494
+ throw new ExecutionError('User interface tools are not available');
1319
1495
  }
1320
1496
  return [4 /*yield*/, tools.userInterface.promptDialog({
1321
1497
  promptTitle: currentTemplate.title,
@@ -1329,7 +1505,7 @@
1329
1505
  // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
1330
1506
  resultString = _o.sent();
1331
1507
  return [3 /*break*/, 27];
1332
- case 26: throw new PromptbookExecutionError(
1508
+ case 26: throw new ExecutionError(
1333
1509
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1334
1510
  "Unknown execution type \"".concat(currentTemplate.executionType, "\""));
1335
1511
  case 27:
@@ -1454,7 +1630,7 @@
1454
1630
  return [7 /*endfinally*/];
1455
1631
  case 47:
1456
1632
  if (expectError !== null && attempt === maxAttempts - 1) {
1457
- throw new PromptbookExecutionError(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 "); }));
1633
+ throw new ExecutionError(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 "); }));
1458
1634
  }
1459
1635
  _o.label = 48;
1460
1636
  case 48:
@@ -1523,349 +1699,142 @@
1523
1699
  return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
1524
1700
  });
1525
1701
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
1526
- throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbook\n "));
1702
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
1527
1703
  case 1:
1528
1704
  if (!!currentTemplate) return [3 /*break*/, 3];
1529
1705
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
1530
1706
  case 2:
1531
- /* [5] */ _e.sent();
1532
- return [3 /*break*/, 4];
1533
- case 3:
1534
- unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
1535
- work_1 = executeSingleTemplate(currentTemplate)
1536
- .then(function () {
1537
- resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
1538
- })
1539
- .then(function () {
1540
- resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
1541
- });
1542
- resolving_1.push(work_1);
1543
- _e.label = 4;
1544
- case 4: return [2 /*return*/];
1545
- }
1546
- });
1547
- };
1548
- _d.label = 2;
1549
- case 2:
1550
- if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
1551
- return [5 /*yield**/, _loop_1()];
1552
- case 3:
1553
- _d.sent();
1554
- return [3 /*break*/, 2];
1555
- case 4: return [4 /*yield*/, Promise.all(resolving_1)];
1556
- case 5:
1557
- _d.sent();
1558
- return [3 /*break*/, 7];
1559
- case 6:
1560
- error_1 = _d.sent();
1561
- if (!(error_1 instanceof Error)) {
1562
- throw error_1;
1563
- }
1564
- usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1565
- var result = _a.result;
1566
- return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1567
- })), false));
1568
- return [2 /*return*/, {
1569
- isSuccessful: false,
1570
- errors: [error_1],
1571
- usage: usage_1,
1572
- executionReport: executionReport,
1573
- outputParameters: parametersToPass,
1574
- }];
1575
- case 7:
1576
- try {
1577
- // Note: Filter ONLY output parameters
1578
- for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
1579
- parameter = _b.value;
1580
- if (parameter.isOutput) {
1581
- continue;
1582
- }
1583
- delete parametersToPass[parameter.name];
1584
- }
1585
- }
1586
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1587
- finally {
1588
- try {
1589
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1590
- }
1591
- finally { if (e_1) throw e_1.error; }
1592
- }
1593
- usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1594
- var result = _a.result;
1595
- return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1596
- })), false));
1597
- return [2 /*return*/, {
1598
- isSuccessful: true,
1599
- errors: [],
1600
- usage: usage,
1601
- executionReport: executionReport,
1602
- outputParameters: parametersToPass,
1603
- }];
1604
- }
1605
- });
1606
- }); };
1607
- return promptbookExecutor;
1608
- }
1609
- /**
1610
- * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
1611
- * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
1612
- * Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
1613
- * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
1614
- */
1615
-
1616
- /**
1617
- * Makes first letter of a string uppercase
1618
- *
1619
- */
1620
- function capitalize(word) {
1621
- return word.substring(0, 1).toUpperCase() + word.substring(1);
1622
- }
1623
-
1624
- /**
1625
- * Converts promptbook in JSON format to string format
1626
- *
1627
- * @param promptbookJson Promptbook in JSON format (.ptbk.json)
1628
- * @returns Promptbook in string format (.ptbk.md)
1629
- */
1630
- function promptbookJsonToString(promptbookJson) {
1631
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
1632
- var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
1633
- var promptbookString = "# ".concat(title);
1634
- if (description) {
1635
- promptbookString += '\n\n';
1636
- promptbookString += description;
1637
- }
1638
- // TODO:> const commands: Array<Command>
1639
- var commands = [];
1640
- if (promptbookUrl) {
1641
- commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
1642
- }
1643
- commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
1644
- promptbookString = prettifyMarkdown(promptbookString);
1645
- try {
1646
- for (var _g = __values(parameters.filter(function (_a) {
1647
- var isInput = _a.isInput;
1648
- return isInput;
1649
- })), _h = _g.next(); !_h.done; _h = _g.next()) {
1650
- var parameter = _h.value;
1651
- commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1652
- }
1653
- }
1654
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1655
- finally {
1656
- try {
1657
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
1658
- }
1659
- finally { if (e_1) throw e_1.error; }
1660
- }
1661
- try {
1662
- for (var _j = __values(parameters.filter(function (_a) {
1663
- var isOutput = _a.isOutput;
1664
- return isOutput;
1665
- })), _k = _j.next(); !_k.done; _k = _j.next()) {
1666
- var parameter = _k.value;
1667
- commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1668
- }
1669
- }
1670
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1671
- finally {
1672
- try {
1673
- if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1674
- }
1675
- finally { if (e_2) throw e_2.error; }
1676
- }
1677
- promptbookString += '\n\n';
1678
- promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
1679
- try {
1680
- for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
1681
- var promptTemplate = promptTemplates_1_1.value;
1682
- var
1683
- /* Note: Not using:> name, */
1684
- title_1 = promptTemplate.title, description_1 = promptTemplate.description,
1685
- /* Note: dependentParameterNames, */
1686
- jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
1687
- promptbookString += '\n\n';
1688
- promptbookString += "## ".concat(title_1);
1689
- if (description_1) {
1690
- promptbookString += '\n\n';
1691
- promptbookString += description_1;
1692
- }
1693
- // TODO:> const commands: Array<Command>
1694
- var commands_1 = [];
1695
- var contentLanguage = 'text';
1696
- if (executionType === 'PROMPT_TEMPLATE') {
1697
- var modelRequirements = promptTemplate.modelRequirements;
1698
- var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
1699
- commands_1.push("EXECUTE PROMPT TEMPLATE");
1700
- if (modelVariant) {
1701
- commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
1702
- }
1703
- if (modelName) {
1704
- commands_1.push("MODEL NAME `".concat(modelName, "`"));
1705
- }
1706
- }
1707
- else if (executionType === 'SIMPLE_TEMPLATE') {
1708
- commands_1.push("SIMPLE TEMPLATE");
1709
- // Note: Nothing special here
1710
- }
1711
- else if (executionType === 'SCRIPT') {
1712
- commands_1.push("EXECUTE SCRIPT");
1713
- if (promptTemplate.contentLanguage) {
1714
- contentLanguage = promptTemplate.contentLanguage;
1715
- }
1716
- else {
1717
- contentLanguage = '';
1718
- }
1719
- }
1720
- else if (executionType === 'PROMPT_DIALOG') {
1721
- commands_1.push("PROMPT DIALOG");
1722
- // Note: Nothing special here
1723
- }
1724
- if (jokers) {
1725
- try {
1726
- for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
1727
- var joker = jokers_1_1.value;
1728
- commands_1.push("JOKER {".concat(joker, "}"));
1729
- }
1730
- }
1731
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1732
- finally {
1733
- try {
1734
- if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
1735
- }
1736
- finally { if (e_4) throw e_4.error; }
1737
- }
1738
- } /* not else */
1739
- if (postprocessing) {
1740
- try {
1741
- for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
1742
- var postprocessingFunctionName = postprocessing_1_1.value;
1743
- commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
1707
+ /* [5] */ _e.sent();
1708
+ return [3 /*break*/, 4];
1709
+ case 3:
1710
+ unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
1711
+ work_1 = executeSingleTemplate(currentTemplate)
1712
+ .then(function () {
1713
+ resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
1714
+ })
1715
+ .then(function () {
1716
+ resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
1717
+ });
1718
+ resolving_1.push(work_1);
1719
+ _e.label = 4;
1720
+ case 4: return [2 /*return*/];
1721
+ }
1722
+ });
1723
+ };
1724
+ _d.label = 2;
1725
+ case 2:
1726
+ if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
1727
+ return [5 /*yield**/, _loop_1()];
1728
+ case 3:
1729
+ _d.sent();
1730
+ return [3 /*break*/, 2];
1731
+ case 4: return [4 /*yield*/, Promise.all(resolving_1)];
1732
+ case 5:
1733
+ _d.sent();
1734
+ return [3 /*break*/, 7];
1735
+ case 6:
1736
+ error_1 = _d.sent();
1737
+ if (!(error_1 instanceof Error)) {
1738
+ throw error_1;
1744
1739
  }
1745
- }
1746
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1747
- finally {
1740
+ usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1741
+ var result = _a.result;
1742
+ return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1743
+ })), false));
1744
+ return [2 /*return*/, {
1745
+ isSuccessful: false,
1746
+ errors: [error_1],
1747
+ usage: usage_1,
1748
+ executionReport: executionReport,
1749
+ outputParameters: parametersToPass,
1750
+ }];
1751
+ case 7:
1748
1752
  try {
1749
- if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
1750
- }
1751
- finally { if (e_5) throw e_5.error; }
1752
- }
1753
- } /* not else */
1754
- if (expectations) {
1755
- try {
1756
- for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
1757
- var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
1758
- if (min === max) {
1759
- commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1760
- }
1761
- else {
1762
- if (min !== undefined) {
1763
- commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1764
- } /* not else */
1765
- if (max !== undefined) {
1766
- commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
1753
+ // Note: Filter ONLY output parameters
1754
+ for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
1755
+ parameter = _b.value;
1756
+ if (parameter.isOutput) {
1757
+ continue;
1767
1758
  }
1759
+ delete parametersToPass[parameter.name];
1768
1760
  }
1769
1761
  }
1770
- }
1771
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1772
- finally {
1773
- try {
1774
- if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
1762
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1763
+ finally {
1764
+ try {
1765
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1766
+ }
1767
+ finally { if (e_1) throw e_1.error; }
1775
1768
  }
1776
- finally { if (e_6) throw e_6.error; }
1777
- }
1778
- } /* not else */
1779
- if (expectFormat) {
1780
- if (expectFormat === 'JSON') {
1781
- // TODO: @deprecated remove
1782
- commands_1.push("EXPECT JSON");
1783
- }
1784
- } /* not else */
1785
- promptbookString += '\n\n';
1786
- promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
1787
- promptbookString += '\n\n';
1788
- promptbookString += '```' + contentLanguage;
1789
- promptbookString += '\n';
1790
- promptbookString += spaceTrim__default["default"](content);
1791
- // <- TODO: !!! Escape
1792
- // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1793
- promptbookString += '\n';
1794
- promptbookString += '```';
1795
- promptbookString += '\n\n';
1796
- promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
1797
- }
1798
- }
1799
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1800
- finally {
1801
- try {
1802
- if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
1803
- }
1804
- finally { if (e_3) throw e_3.error; }
1805
- }
1806
- return promptbookString;
1807
- }
1808
- /**
1809
- * @private internal util of promptbookJsonToString
1810
- */
1811
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
1812
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
1813
- var parameterString = "{".concat(name, "}");
1814
- if (description) {
1815
- parameterString = "".concat(parameterString, " ").concat(description);
1816
- }
1817
- return parameterString;
1769
+ usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1770
+ var result = _a.result;
1771
+ return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1772
+ })), false));
1773
+ return [2 /*return*/, {
1774
+ isSuccessful: true,
1775
+ errors: [],
1776
+ usage: usage,
1777
+ executionReport: executionReport,
1778
+ outputParameters: parametersToPass,
1779
+ }];
1780
+ }
1781
+ });
1782
+ }); };
1783
+ return promptbookExecutor;
1818
1784
  }
1819
1785
  /**
1820
- * TODO: Escape all
1786
+ * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
1787
+ * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
1788
+ * Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
1789
+ * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
1821
1790
  */
1822
1791
 
1823
1792
  /**
1824
1793
  * This error indicates that promptbook not found in the library
1825
1794
  */
1826
- var PromptbookNotFoundError = /** @class */ (function (_super) {
1827
- __extends(PromptbookNotFoundError, _super);
1828
- function PromptbookNotFoundError(message) {
1795
+ var NotFoundError = /** @class */ (function (_super) {
1796
+ __extends(NotFoundError, _super);
1797
+ function NotFoundError(message) {
1829
1798
  var _this = _super.call(this, message) || this;
1830
- _this.name = 'PromptbookNotFoundError';
1831
- Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
1799
+ _this.name = 'NotFoundError';
1800
+ Object.setPrototypeOf(_this, NotFoundError.prototype);
1832
1801
  return _this;
1833
1802
  }
1834
- return PromptbookNotFoundError;
1803
+ return NotFoundError;
1835
1804
  }(Error));
1836
1805
 
1837
1806
  /**
1838
1807
  * This error indicates errors in referencing promptbooks between each other
1839
1808
  */
1840
- var PromptbookReferenceError = /** @class */ (function (_super) {
1841
- __extends(PromptbookReferenceError, _super);
1842
- function PromptbookReferenceError(message) {
1809
+ var ReferenceError$1 = /** @class */ (function (_super) {
1810
+ __extends(ReferenceError, _super);
1811
+ function ReferenceError(message) {
1843
1812
  var _this = _super.call(this, message) || this;
1844
- _this.name = 'PromptbookReferenceError';
1845
- Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
1813
+ _this.name = 'ReferenceError';
1814
+ Object.setPrototypeOf(_this, ReferenceError.prototype);
1846
1815
  return _this;
1847
1816
  }
1848
- return PromptbookReferenceError;
1817
+ return ReferenceError;
1849
1818
  }(Error));
1850
1819
 
1851
1820
  /**
1852
1821
  * Library of promptbooks that groups together promptbooks for an application.
1853
1822
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1854
1823
  *
1855
- * @private use `createLibraryFromJson` instead
1856
- * @see https://github.com/webgptorg/promptbook#promptbook-library
1824
+ * @private use `createCollectionFromJson` instead
1825
+ * @see https://github.com/webgptorg/promptbook#promptbook-collection
1857
1826
  */
1858
- var SimplePromptbookLibrary = /** @class */ (function () {
1827
+ var SimplePipelineCollection = /** @class */ (function () {
1859
1828
  /**
1860
1829
  * Constructs a promptbook library from promptbooks
1861
1830
  *
1862
1831
  * @param promptbooks !!!
1863
1832
  *
1864
- * @private Use instead `createLibraryFromJson`
1833
+ * @private Use instead `createCollectionFromJson`
1865
1834
  * Note: During the construction logic of all promptbooks are validated
1866
- * Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
1835
+ * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
1867
1836
  */
1868
- function SimplePromptbookLibrary() {
1837
+ function SimplePipelineCollection() {
1869
1838
  var e_1, _a;
1870
1839
  var promptbooks = [];
1871
1840
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1876,14 +1845,13 @@
1876
1845
  for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1877
1846
  var promptbook = promptbooks_1_1.value;
1878
1847
  if (promptbook.promptbookUrl === undefined) {
1879
- throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\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 promptbook library\n\n ")));
1848
+ throw new ReferenceError$1(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\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 promptbook library\n\n ")));
1880
1849
  }
1881
- validatePromptbook(promptbook);
1850
+ validatePipeline(promptbook);
1882
1851
  // Note: [🦄]
1883
1852
  if (this.library.has(promptbook.promptbookUrl) &&
1884
- promptbookJsonToString(promptbook) !==
1885
- promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
1886
- throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
1853
+ pipelineJsonToString(promptbook) !== pipelineJsonToString(this.library.get(promptbook.promptbookUrl))) {
1854
+ throw new ReferenceError$1(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
1887
1855
  }
1888
1856
  this.library.set(promptbook.promptbookUrl, promptbook);
1889
1857
  }
@@ -1899,7 +1867,7 @@
1899
1867
  /**
1900
1868
  * Gets all promptbooks in the library
1901
1869
  */
1902
- SimplePromptbookLibrary.prototype.listPromptbooks = function () {
1870
+ SimplePipelineCollection.prototype.listPipelines = function () {
1903
1871
  return Array.from(this.library.keys());
1904
1872
  };
1905
1873
  /**
@@ -1907,14 +1875,14 @@
1907
1875
  *
1908
1876
  * Note: This is not a direct fetching from the URL, but a lookup in the library
1909
1877
  */
1910
- SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
1878
+ SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
1911
1879
  var _this = this;
1912
1880
  var promptbook = this.library.get(url);
1913
1881
  if (!promptbook) {
1914
- if (this.listPromptbooks().length === 0) {
1915
- throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1882
+ if (this.listPipelines().length === 0) {
1883
+ throw new NotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1916
1884
  }
1917
- throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
1885
+ 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()
1918
1886
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
1919
1887
  .join('\n')), "\n\n "); }));
1920
1888
  }
@@ -1923,27 +1891,27 @@
1923
1891
  /**
1924
1892
  * Checks whether given prompt was defined in any promptbook in the library
1925
1893
  */
1926
- SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
1894
+ SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
1927
1895
  return true;
1928
1896
  };
1929
- return SimplePromptbookLibrary;
1897
+ return SimplePipelineCollection;
1930
1898
  }());
1931
1899
 
1932
1900
  /**
1933
- * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1901
+ * Creates PipelineCollection from array of PipelineJson or PipelineString
1934
1902
  *
1935
- * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
1903
+ * Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
1936
1904
  * Note: During the construction syntax and logic of all sources are validated
1937
1905
  *
1938
1906
  * @param promptbookSources
1939
- * @returns PromptbookLibrary
1907
+ * @returns PipelineCollection
1940
1908
  */
1941
- function createLibraryFromJson() {
1909
+ function createCollectionFromJson() {
1942
1910
  var promptbooks = [];
1943
1911
  for (var _i = 0; _i < arguments.length; _i++) {
1944
1912
  promptbooks[_i] = arguments[_i];
1945
1913
  }
1946
- return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
1914
+ return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
1947
1915
  }
1948
1916
 
1949
1917
  /* tslint:disable */
@@ -2009,8 +1977,8 @@
2009
1977
  switch (_b.label) {
2010
1978
  case 0:
2011
1979
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2012
- library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false));
2013
- return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
1980
+ library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
1981
+ return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
2014
1982
  case 1:
2015
1983
  prepareKnowledgeFromMarkdownPromptbook = _b.sent();
2016
1984
  prepareKnowledgeFromMarkdownExecutor = createPromptbookExecutor({
@@ -2022,7 +1990,7 @@
2022
1990
  ],
2023
1991
  },
2024
1992
  });
2025
- return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
1993
+ return [4 /*yield*/, library.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
2026
1994
  case 2:
2027
1995
  prepareKeywordsPromptbook = _b.sent();
2028
1996
  prepareKeywordsExecutor = createPromptbookExecutor({
@@ -2128,7 +2096,7 @@
2128
2096
  /**
2129
2097
  * Computes the deepness of the markdown structure.
2130
2098
  *
2131
- * @private within the library
2099
+ * @private within the package
2132
2100
  */
2133
2101
  function countMarkdownStructureDeepness(markdownStructure) {
2134
2102
  var e_1, _a;
@@ -2158,7 +2126,7 @@
2158
2126
  * @param markdown The markdown string to parse.
2159
2127
  * @returns The MarkdownStructure object.
2160
2128
  *
2161
- * @private within the library
2129
+ * @private within the package
2162
2130
  */
2163
2131
  function markdownToMarkdownStructure(markdown) {
2164
2132
  var e_1, _a;
@@ -2353,6 +2321,16 @@
2353
2321
  * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
2354
2322
  */
2355
2323
 
2324
+ /**
2325
+ * Removes HTML or Markdown comments from a string.
2326
+ *
2327
+ * @param {string} content - The string to remove comments from.
2328
+ * @returns {string} The input string with all comments removed.
2329
+ */
2330
+ function removeContentComments(content) {
2331
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
2332
+ }
2333
+
2356
2334
  /**
2357
2335
  * Creates a new set with all elements that are present in either set
2358
2336
  */
@@ -2423,7 +2401,7 @@
2423
2401
  *
2424
2402
  * @param script from which to extract the variables
2425
2403
  * @returns the list of variable names
2426
- * @throws {PromptbookSyntaxError} if the script is invalid
2404
+ * @throws {SyntaxError} if the script is invalid
2427
2405
  */
2428
2406
  function extractVariables(script) {
2429
2407
  var variables = new Set();
@@ -2459,7 +2437,7 @@
2459
2437
  if (!(error instanceof Error)) {
2460
2438
  throw error;
2461
2439
  }
2462
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
2440
+ throw new SyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
2463
2441
  }
2464
2442
  return variables;
2465
2443
  }
@@ -2472,7 +2450,7 @@
2472
2450
  *
2473
2451
  * @param promptTemplate the template with used parameters
2474
2452
  * @returns the set of parameter names
2475
- * @throws {PromptbookSyntaxError} if the script is invalid
2453
+ * @throws {SyntaxError} if the script is invalid
2476
2454
  */
2477
2455
  function extractParametersFromPromptTemplate(promptTemplate) {
2478
2456
  var e_1, _a, e_2, _b;
@@ -2511,6 +2489,45 @@
2511
2489
  * TODO: [🔣] If script require contentLanguage
2512
2490
  */
2513
2491
 
2492
+ /**
2493
+ * Execution type describes the way how the block is executed
2494
+ *
2495
+ * @see https://github.com/webgptorg/promptbook#execution-type
2496
+ */
2497
+ var ExecutionTypes = [
2498
+ 'PROMPT_TEMPLATE',
2499
+ 'SIMPLE_TEMPLATE',
2500
+ 'SCRIPT',
2501
+ 'PROMPT_DIALOG',
2502
+ // <- [🥻] Insert here when making new command
2503
+ ];
2504
+
2505
+ /**
2506
+ * Units of text measurement
2507
+ */
2508
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2509
+ /**
2510
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
2511
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
2512
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
2513
+ */
2514
+
2515
+ /**
2516
+ * Removes Markdown formatting tags from a string.
2517
+ *
2518
+ * @param {string} str - The string to remove Markdown tags from.
2519
+ * @returns {string} The input string with all Markdown tags removed.
2520
+ */
2521
+ function removeMarkdownFormatting(str) {
2522
+ // Remove bold formatting
2523
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
2524
+ // Remove italic formatting
2525
+ str = str.replace(/\*(.*?)\*/g, '$1');
2526
+ // Remove code formatting
2527
+ str = str.replace(/`(.*?)`/g, '$1');
2528
+ return str;
2529
+ }
2530
+
2514
2531
  /* tslint:disable */
2515
2532
  /*
2516
2533
  TODO: Tests
@@ -2575,45 +2592,6 @@
2575
2592
  * TODO: [🌺] Use some intermediate util splitWords
2576
2593
  */
2577
2594
 
2578
- /**
2579
- * Execution type describes the way how the block is executed
2580
- *
2581
- * @see https://github.com/webgptorg/promptbook#execution-type
2582
- */
2583
- var ExecutionTypes = [
2584
- 'PROMPT_TEMPLATE',
2585
- 'SIMPLE_TEMPLATE',
2586
- 'SCRIPT',
2587
- 'PROMPT_DIALOG',
2588
- // <- [🥻] Insert here when making new command
2589
- ];
2590
-
2591
- /**
2592
- * Units of text measurement
2593
- */
2594
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2595
- /**
2596
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
2597
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
2598
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
2599
- */
2600
-
2601
- /**
2602
- * Removes Markdown formatting tags from a string.
2603
- *
2604
- * @param {string} str - The string to remove Markdown tags from.
2605
- * @returns {string} The input string with all Markdown tags removed.
2606
- */
2607
- function removeMarkdownFormatting(str) {
2608
- // Remove bold formatting
2609
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
2610
- // Remove italic formatting
2611
- str = str.replace(/\*(.*?)\*/g, '$1');
2612
- // Remove code formatting
2613
- str = str.replace(/`(.*?)`/g, '$1');
2614
- return str;
2615
- }
2616
-
2617
2595
  /**
2618
2596
  * Function parseNumber will parse number from string
2619
2597
  *
@@ -2621,7 +2599,7 @@
2621
2599
  * Note: it also works only with decimal numbers
2622
2600
  *
2623
2601
  * @returns parsed number
2624
- * @throws {PromptbookSyntaxError} if the value is not a number
2602
+ * @throws {SyntaxError} if the value is not a number
2625
2603
  *
2626
2604
  * @private within the parseCommand
2627
2605
  */
@@ -2657,7 +2635,7 @@
2657
2635
  var numerator = parseNumber(numerator_);
2658
2636
  var denominator = parseNumber(denominator_);
2659
2637
  if (denominator === 0) {
2660
- throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2638
+ throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2661
2639
  }
2662
2640
  return numerator / denominator;
2663
2641
  }
@@ -2669,11 +2647,11 @@
2669
2647
  return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
2670
2648
  }
2671
2649
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
2672
- throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
2650
+ throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
2673
2651
  }
2674
2652
  var num = parseFloat(value);
2675
2653
  if (isNaN(num)) {
2676
- throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2654
+ throw new SyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2677
2655
  }
2678
2656
  return num;
2679
2657
  }
@@ -2685,14 +2663,14 @@
2685
2663
  * Parses one line of ul/ol to command
2686
2664
  *
2687
2665
  * @returns parsed command object
2688
- * @throws {PromptbookSyntaxError} if the command is invalid
2666
+ * @throws {SyntaxError} if the command is invalid
2689
2667
  *
2690
- * @private within the promptbookStringToJson
2668
+ * @private within the pipelineStringToJson
2691
2669
  */
2692
2670
  function parseCommand(listItem) {
2693
2671
  var e_1, _a;
2694
2672
  if (listItem.includes('\n') || listItem.includes('\r')) {
2695
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
2673
+ throw new SyntaxError('Command can not contain new line characters:');
2696
2674
  }
2697
2675
  var type = listItem.trim();
2698
2676
  type = type.split('`').join('');
@@ -2719,15 +2697,15 @@
2719
2697
  type.startsWith('PROMPTBOOKURL') ||
2720
2698
  type.startsWith('HTTPS')) {
2721
2699
  if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
2722
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
2700
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
2723
2701
  }
2724
2702
  var promptbookUrlString = listItemParts.pop();
2725
2703
  var promptbookUrl = new URL(promptbookUrlString);
2726
2704
  if (promptbookUrl.protocol !== 'https:') {
2727
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2705
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2728
2706
  }
2729
2707
  if (promptbookUrl.hash !== '') {
2730
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
2708
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
2731
2709
  }
2732
2710
  return {
2733
2711
  type: 'PROMPTBOOK_URL',
@@ -2736,7 +2714,7 @@
2736
2714
  }
2737
2715
  else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
2738
2716
  if (listItemParts.length !== 2) {
2739
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2717
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2740
2718
  }
2741
2719
  var promptbookVersion = listItemParts.pop();
2742
2720
  // TODO: Validate version
@@ -2751,7 +2729,7 @@
2751
2729
  type.startsWith('SIMPLE_TEMPLATE')) {
2752
2730
  var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
2753
2731
  if (executionTypes.length !== 1) {
2754
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
2732
+ throw new SyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
2755
2733
  }
2756
2734
  return {
2757
2735
  type: 'EXECUTE',
@@ -2776,7 +2754,7 @@
2776
2754
  };
2777
2755
  }
2778
2756
  else {
2779
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
2757
+ throw new SyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
2780
2758
  }
2781
2759
  }
2782
2760
  if (type.startsWith('MODEL_NAME')) {
@@ -2787,7 +2765,7 @@
2787
2765
  };
2788
2766
  }
2789
2767
  else {
2790
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
2768
+ throw new SyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
2791
2769
  }
2792
2770
  }
2793
2771
  else if (type.startsWith('PARAM') ||
@@ -2797,12 +2775,12 @@
2797
2775
  listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
2798
2776
  var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
2799
2777
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2800
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2778
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2801
2779
  }
2802
2780
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2803
2781
  var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
2804
2782
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
2805
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
2783
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
2806
2784
  }
2807
2785
  var isInput = type.startsWith('INPUT');
2808
2786
  var isOutput = type.startsWith('OUTPUT');
@@ -2820,11 +2798,11 @@
2820
2798
  }
2821
2799
  else if (type.startsWith('JOKER')) {
2822
2800
  if (listItemParts.length !== 2) {
2823
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
2801
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
2824
2802
  }
2825
2803
  var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
2826
2804
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2827
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2805
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2828
2806
  }
2829
2807
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2830
2808
  var parameterName = parametersMatch.groups.parameterName;
@@ -2835,7 +2813,7 @@
2835
2813
  }
2836
2814
  else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
2837
2815
  if (listItemParts.length !== 2) {
2838
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2816
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2839
2817
  }
2840
2818
  var functionName = listItemParts.pop();
2841
2819
  return {
@@ -2865,15 +2843,15 @@
2865
2843
  sign = 'MAXIMUM';
2866
2844
  }
2867
2845
  else {
2868
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
2846
+ throw new SyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
2869
2847
  }
2870
2848
  var amountRaw = listItemParts.shift();
2871
2849
  var amount = parseNumber(amountRaw);
2872
2850
  if (amount < 0) {
2873
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
2851
+ throw new SyntaxError('Amount must be positive number or zero');
2874
2852
  }
2875
2853
  if (amount !== Math.floor(amount)) {
2876
- throw new PromptbookSyntaxError('Amount must be whole number');
2854
+ throw new SyntaxError('Amount must be whole number');
2877
2855
  }
2878
2856
  var unitRaw = listItemParts.shift();
2879
2857
  var unit = undefined;
@@ -2888,7 +2866,7 @@
2888
2866
  if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
2889
2867
  new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
2890
2868
  if (unit !== undefined) {
2891
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
2869
+ throw new SyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
2892
2870
  }
2893
2871
  unit = existingUnit;
2894
2872
  }
@@ -2902,7 +2880,7 @@
2902
2880
  finally { if (e_1) throw e_1.error; }
2903
2881
  }
2904
2882
  if (unit === undefined) {
2905
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
2883
+ throw new SyntaxError("Invalid unit \"".concat(unitRaw, "\""));
2906
2884
  }
2907
2885
  return {
2908
2886
  type: 'EXPECT_AMOUNT',
@@ -2915,7 +2893,7 @@
2915
2893
  if (!(error instanceof Error)) {
2916
2894
  throw error;
2917
2895
  }
2918
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
2896
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
2919
2897
  }
2920
2898
  /*
2921
2899
  } else if (type.startsWith('__________________')) {
@@ -2923,7 +2901,7 @@
2923
2901
  */
2924
2902
  }
2925
2903
  else {
2926
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
2904
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
2927
2905
  }
2928
2906
  }
2929
2907
 
@@ -2956,20 +2934,20 @@
2956
2934
  * Compile promptbook from string (markdown) format to JSON format synchronously
2957
2935
  *
2958
2936
  * Note: There are two similar functions:
2959
- * - `promptbookStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
2960
- * - `promptbookStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
2937
+ * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
2938
+ * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
2961
2939
  *
2962
- * @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
2940
+ * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
2963
2941
  * @param options - Options and tools for the compilation
2964
2942
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
2965
- * @throws {PromptbookSyntaxError} if the promptbook string is not valid
2943
+ * @throws {SyntaxError} if the promptbook string is not valid
2966
2944
  *
2967
2945
  * Note: This function does not validate logic of the pipeline only the syntax
2968
2946
  * Note: This function acts as compilation process
2969
2947
  */
2970
- function promptbookStringToJsonSync(promptbookString) {
2948
+ function pipelineStringToJsonSync(pipelineString) {
2971
2949
  var e_1, _a, e_2, _b;
2972
- var promptbookJson = {
2950
+ var pipelineJson = {
2973
2951
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2974
2952
  title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
2975
2953
  promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
@@ -2981,19 +2959,19 @@
2981
2959
  };
2982
2960
  // =============================================================
2983
2961
  // Note: 1️⃣ Normalization of the PROMPTBOOK string
2984
- promptbookString = removeContentComments(promptbookString);
2985
- promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
2986
- promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
2962
+ pipelineString = removeContentComments(pipelineString);
2963
+ pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
2964
+ pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
2987
2965
  // =============================================================
2988
2966
  ///Note: 2️⃣ Function for adding parameters
2989
2967
  var addParam = function (parameterCommand) {
2990
2968
  var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
2991
- var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
2969
+ var existingParameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
2992
2970
  if (existingParameter &&
2993
2971
  existingParameter.description &&
2994
2972
  existingParameter.description !== parameterDescription &&
2995
2973
  parameterDescription) {
2996
- throw new PromptbookSyntaxError(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 "); }));
2974
+ throw new SyntaxError(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 "); }));
2997
2975
  }
2998
2976
  if (existingParameter) {
2999
2977
  if (parameterDescription) {
@@ -3001,7 +2979,7 @@
3001
2979
  }
3002
2980
  }
3003
2981
  else {
3004
- promptbookJson.parameters.push({
2982
+ pipelineJson.parameters.push({
3005
2983
  name: parameterName,
3006
2984
  description: parameterDescription || undefined,
3007
2985
  isInput: isInput,
@@ -3010,13 +2988,13 @@
3010
2988
  }
3011
2989
  };
3012
2990
  // =============================================================
3013
- // Note: 3️⃣ Parse the dynamic part - the template pipeline
3014
- var markdownStructure = markdownToMarkdownStructure(promptbookString);
2991
+ // Note: 3️⃣ Parse the dynamic part - the pipeline
2992
+ var markdownStructure = markdownToMarkdownStructure(pipelineString);
3015
2993
  var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
3016
2994
  if (markdownStructureDeepness !== 2) {
3017
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
2995
+ throw new SyntaxError(spaceTrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
3018
2996
  }
3019
- promptbookJson.title = markdownStructure.title;
2997
+ pipelineJson.title = markdownStructure.title;
3020
2998
  // TODO: [1] DRY description
3021
2999
  var description = markdownStructure.content;
3022
3000
  // Note: Remove codeblocks
@@ -3027,7 +3005,7 @@
3027
3005
  if (description === '') {
3028
3006
  description = undefined;
3029
3007
  }
3030
- promptbookJson.description = description;
3008
+ pipelineJson.description = description;
3031
3009
  var defaultModelRequirements = {};
3032
3010
  var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
3033
3011
  try {
@@ -3036,10 +3014,10 @@
3036
3014
  var command = parseCommand(listItem);
3037
3015
  switch (command.type) {
3038
3016
  case 'PROMPTBOOK_URL':
3039
- promptbookJson.promptbookUrl = command.promptbookUrl.href;
3017
+ pipelineJson.promptbookUrl = command.promptbookUrl.href;
3040
3018
  break;
3041
3019
  case 'PROMPTBOOK_VERSION':
3042
- promptbookJson.promptbookVersion = command.promptbookVersion;
3020
+ pipelineJson.promptbookVersion = command.promptbookVersion;
3043
3021
  break;
3044
3022
  case 'MODEL':
3045
3023
  defaultModelRequirements[command.key] = command.value;
@@ -3048,7 +3026,7 @@
3048
3026
  addParam(command);
3049
3027
  break;
3050
3028
  default:
3051
- throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
3029
+ throw new SyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
3052
3030
  }
3053
3031
  }
3054
3032
  }
@@ -3082,7 +3060,7 @@
3082
3060
  break;
3083
3061
  case 'EXECUTE':
3084
3062
  if (isExecutionTypeChanged) {
3085
- throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
3063
+ throw new SyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
3086
3064
  }
3087
3065
  executionType = command.executionType;
3088
3066
  isExecutionTypeChanged = true;
@@ -3103,25 +3081,25 @@
3103
3081
  expectAmount[unit] = expectAmount[unit] || {};
3104
3082
  if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
3105
3083
  if (expectAmount[unit].min !== undefined) {
3106
- throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
3084
+ throw new SyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
3107
3085
  }
3108
3086
  expectAmount[unit].min = command.amount;
3109
3087
  } /* not else */
3110
3088
  if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
3111
3089
  if (expectAmount[unit].max !== undefined) {
3112
- throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
3090
+ throw new SyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
3113
3091
  }
3114
3092
  expectAmount[unit].max = command.amount;
3115
3093
  }
3116
3094
  break;
3117
3095
  case 'EXPECT_FORMAT':
3118
3096
  if (expectFormat !== undefined && command.format !== expectFormat) {
3119
- throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
3097
+ throw new SyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
3120
3098
  }
3121
3099
  expectFormat = command.format;
3122
3100
  break;
3123
3101
  default:
3124
- throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
3102
+ throw new SyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
3125
3103
  }
3126
3104
  }
3127
3105
  }
@@ -3135,16 +3113,16 @@
3135
3113
  var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
3136
3114
  if (executionType === 'SCRIPT') {
3137
3115
  if (!language) {
3138
- throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
3116
+ throw new SyntaxError('You must specify the language of the script in the prompt template');
3139
3117
  }
3140
3118
  else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
3141
- throw new PromptbookSyntaxError(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 "); }));
3119
+ throw new SyntaxError(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 "); }));
3142
3120
  }
3143
3121
  }
3144
3122
  var lastLine = section.content.split('\n').pop();
3145
3123
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
3146
3124
  if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
3147
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
3125
+ throw new SyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
3148
3126
  // TODO: Show code of invalid sections each time + DRY
3149
3127
  section.content
3150
3128
  .split('\n')
@@ -3194,7 +3172,7 @@
3194
3172
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3195
3173
  delete template.modelRequirements;
3196
3174
  }
3197
- promptbookJson.promptTemplates.push(template);
3175
+ pipelineJson.promptTemplates.push(template);
3198
3176
  };
3199
3177
  try {
3200
3178
  for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
@@ -3210,7 +3188,7 @@
3210
3188
  finally { if (e_2) throw e_2.error; }
3211
3189
  }
3212
3190
  // =============================================================
3213
- return promptbookJson;
3191
+ return pipelineJson;
3214
3192
  }
3215
3193
  /**
3216
3194
  * TODO: Report here line/column of error
@@ -3222,21 +3200,21 @@
3222
3200
  * Compile promptbook from string (markdown) format to JSON format
3223
3201
  *
3224
3202
  * Note: There are two similar functions:
3225
- * - `promptbookStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
3226
- * - `promptbookStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
3203
+ * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
3204
+ * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
3227
3205
  *
3228
- * @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
3206
+ * @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
3229
3207
  * @param options - Options and tools for the compilation
3230
3208
  * @returns {Promptbook} compiled in JSON format (.ptbk.json)
3231
- * @throws {PromptbookSyntaxError} if the promptbook string is not valid
3209
+ * @throws {SyntaxError} if the promptbook string is not valid
3232
3210
  *
3233
3211
  * Note: This function does not validate logic of the pipeline only the syntax
3234
3212
  * Note: This function acts as compilation process
3235
3213
  */
3236
- function promptbookStringToJson(promptbookString, options) {
3214
+ function pipelineStringToJson(pipelineString, options) {
3237
3215
  if (options === void 0) { options = {}; }
3238
3216
  return __awaiter(this, void 0, void 0, function () {
3239
- var llmTools, knowledge, promptbookJson;
3217
+ var llmTools, knowledge, pipelineJson;
3240
3218
  return __generator(this, function (_a) {
3241
3219
  switch (_a.label) {
3242
3220
  case 0:
@@ -3251,8 +3229,8 @@
3251
3229
  console.info('!!!! knowledge', knowledge);
3252
3230
  _a.label = 2;
3253
3231
  case 2:
3254
- promptbookJson = promptbookStringToJsonSync(promptbookString);
3255
- return [2 /*return*/, promptbookJson];
3232
+ pipelineJson = pipelineStringToJsonSync(pipelineString);
3233
+ return [2 /*return*/, pipelineJson];
3256
3234
  }
3257
3235
  });
3258
3236
  });
@@ -3261,6 +3239,27 @@
3261
3239
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3262
3240
  */
3263
3241
 
3242
+ /**
3243
+ * Add or modify an auto-generated section in a markdown file
3244
+ *
3245
+ * @private within the package
3246
+ */
3247
+ function addAutoGeneratedSection(content, options) {
3248
+ var sectionName = options.sectionName, sectionContent = options.sectionContent;
3249
+ var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
3250
+ var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
3251
+ var sectionMatch = content.match(sectionRegex);
3252
+ if (sectionMatch) {
3253
+ return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
3254
+ }
3255
+ var placeForSection = removeContentComments(content).match(/^##.*$/im);
3256
+ if (!placeForSection) {
3257
+ throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
3258
+ }
3259
+ var _a = __read(placeForSection, 1), heading = _a[0];
3260
+ return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
3261
+ }
3262
+
3264
3263
  /* tslint:disable */
3265
3264
  function normalizeTo_camelCase(sentence, __firstLetterCapital) {
3266
3265
  var e_1, _a;
@@ -3321,23 +3320,23 @@
3321
3320
  *
3322
3321
  * Note: The result is not wrapped in a Markdown code block
3323
3322
  */
3324
- function renderPromptbookMermaid(promptbookJson, options) {
3323
+ function renderPromptbookMermaid(pipelineJson, options) {
3325
3324
  var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
3326
3325
  var parameterNameToTemplateName = function (parameterName) {
3327
- var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
3326
+ var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
3328
3327
  if (!parameter) {
3329
3328
  throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
3330
3329
  }
3331
3330
  if (parameter.isInput) {
3332
3331
  return 'input';
3333
3332
  }
3334
- var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
3333
+ var template = pipelineJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
3335
3334
  if (!template) {
3336
3335
  throw new Error("Could not find template for {".concat(parameterName, "}"));
3337
3336
  }
3338
3337
  return normalizeTo_camelCase('template-' + titleToName(template.title));
3339
3338
  };
3340
- var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
3339
+ var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
3341
3340
  .flatMap(function (_a) {
3342
3341
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
3343
3342
  return __spreadArray([
@@ -3346,7 +3345,7 @@
3346
3345
  return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
3347
3346
  })), false);
3348
3347
  })
3349
- .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
3348
+ .join('\n')), "\n\n ").concat(block(pipelineJson.parameters
3350
3349
  .filter(function (_a) {
3351
3350
  var isOutput = _a.isOutput;
3352
3351
  return isOutput;
@@ -3355,7 +3354,7 @@
3355
3354
  var name = _a.name;
3356
3355
  return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
3357
3356
  })
3358
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
3357
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.promptTemplates
3359
3358
  .map(function (promptTemplate) {
3360
3359
  var link = linkPromptTemplate(promptTemplate);
3361
3360
  if (link === null) {
@@ -3377,33 +3376,33 @@
3377
3376
  /**
3378
3377
  * Prettyfies Promptbook string and adds Mermaid graph
3379
3378
  */
3380
- function prettifyPromptbookString(promptbookString, options) {
3379
+ function prettifyPipelineString(pipelineString, options) {
3381
3380
  return __awaiter(this, void 0, void 0, function () {
3382
- var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
3381
+ var isGraphAdded, isPrettifyed, pipelineJson, promptbookMermaid_1, promptbookMermaidBlock;
3383
3382
  return __generator(this, function (_a) {
3384
3383
  switch (_a.label) {
3385
3384
  case 0:
3386
3385
  isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
3387
3386
  if (!isGraphAdded) return [3 /*break*/, 2];
3388
- return [4 /*yield*/, promptbookStringToJson(promptbookString)];
3387
+ return [4 /*yield*/, pipelineStringToJson(pipelineString)];
3389
3388
  case 1:
3390
- promptbookJson = _a.sent();
3391
- promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
3389
+ pipelineJson = _a.sent();
3390
+ promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
3392
3391
  linkPromptTemplate: function (promptTemplate) {
3393
3392
  return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
3394
3393
  },
3395
3394
  });
3396
3395
  promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
3397
- promptbookString = addAutoGeneratedSection(promptbookString, {
3396
+ pipelineString = addAutoGeneratedSection(pipelineString, {
3398
3397
  sectionName: 'Graph',
3399
3398
  sectionContent: promptbookMermaidBlock,
3400
3399
  });
3401
3400
  _a.label = 2;
3402
3401
  case 2:
3403
3402
  if (isPrettifyed) {
3404
- promptbookString = prettifyMarkdown(promptbookString);
3403
+ pipelineString = prettifyMarkdown(pipelineString);
3405
3404
  }
3406
- return [2 /*return*/, promptbookString];
3405
+ return [2 /*return*/, pipelineString];
3407
3406
  }
3408
3407
  });
3409
3408
  });
@@ -3416,15 +3415,15 @@
3416
3415
  /**
3417
3416
  * This error indicates that the promptbook library cannot be propperly loaded
3418
3417
  */
3419
- var PromptbookLibraryError = /** @class */ (function (_super) {
3420
- __extends(PromptbookLibraryError, _super);
3421
- function PromptbookLibraryError(message) {
3418
+ var CollectionError = /** @class */ (function (_super) {
3419
+ __extends(CollectionError, _super);
3420
+ function CollectionError(message) {
3422
3421
  var _this = _super.call(this, message) || this;
3423
- _this.name = 'PromptbookLibraryError';
3424
- Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
3422
+ _this.name = 'CollectionError';
3423
+ Object.setPrototypeOf(_this, CollectionError.prototype);
3425
3424
  return _this;
3426
3425
  }
3427
- return PromptbookLibraryError;
3426
+ return CollectionError;
3428
3427
  }(Error));
3429
3428
 
3430
3429
  /**
@@ -3506,7 +3505,7 @@
3506
3505
  console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
3507
3506
  }
3508
3507
  if (answer === null) {
3509
- throw new PromptbookExecutionError('User cancelled prompt');
3508
+ throw new ExecutionError('User cancelled prompt');
3510
3509
  }
3511
3510
  return [2 /*return*/, answer];
3512
3511
  });
@@ -3518,23 +3517,23 @@
3518
3517
  /**
3519
3518
  * Constructs Promptbook from async sources
3520
3519
  * It can be one of the following:
3521
- * - Promise of array of PromptbookJson or PromptbookString
3522
- * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
3520
+ * - Promise of array of PipelineJson or PipelineString
3521
+ * - Factory function that returns Promise of array of PipelineJson or PipelineString
3523
3522
  *
3524
3523
  * Note: This is useful as internal tool for other constructor functions like
3525
- * `createLibraryFromUrl` or `createLibraryFromDirectory`
3524
+ * `createCollectionFromUrl` or `createCollectionFromDirectory`
3526
3525
  * Consider using those functions instead of this one
3527
3526
  *
3528
3527
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3529
- * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3528
+ * when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
3530
3529
  *
3531
- * Note: Consider using `createLibraryFromDirectory` or `createLibraryFromUrl`
3530
+ * Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
3532
3531
  *
3533
3532
  * @param promptbookSourcesPromiseOrFactory
3534
- * @returns PromptbookLibrary
3533
+ * @returns PipelineCollection
3535
3534
  * @deprecated Do not use, it will became internal tool for other constructor functions
3536
3535
  */
3537
- function createLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3536
+ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
3538
3537
  var library;
3539
3538
  function forSources() {
3540
3539
  return __awaiter(this, void 0, void 0, function () {
@@ -3549,32 +3548,32 @@
3549
3548
  return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
3550
3549
  case 1:
3551
3550
  promptbookSources = _a.sent();
3552
- library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
3551
+ library = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
3553
3552
  return [2 /*return*/];
3554
3553
  }
3555
3554
  });
3556
3555
  });
3557
3556
  }
3558
- function listPromptbooks() {
3557
+ function listPipelines() {
3559
3558
  return __awaiter(this, void 0, void 0, function () {
3560
3559
  return __generator(this, function (_a) {
3561
3560
  switch (_a.label) {
3562
3561
  case 0: return [4 /*yield*/, forSources()];
3563
3562
  case 1:
3564
3563
  _a.sent();
3565
- return [2 /*return*/, /* not await */ library.listPromptbooks()];
3564
+ return [2 /*return*/, /* not await */ library.listPipelines()];
3566
3565
  }
3567
3566
  });
3568
3567
  });
3569
3568
  }
3570
- function getPromptbookByUrl(url) {
3569
+ function getPipelineByUrl(url) {
3571
3570
  return __awaiter(this, void 0, void 0, function () {
3572
3571
  return __generator(this, function (_a) {
3573
3572
  switch (_a.label) {
3574
3573
  case 0: return [4 /*yield*/, forSources()];
3575
3574
  case 1:
3576
3575
  _a.sent();
3577
- return [2 /*return*/, /* not await */ library.getPromptbookByUrl(url)];
3576
+ return [2 /*return*/, /* not await */ library.getPipelineByUrl(url)];
3578
3577
  }
3579
3578
  });
3580
3579
  });
@@ -3592,8 +3591,8 @@
3592
3591
  });
3593
3592
  }
3594
3593
  return {
3595
- listPromptbooks: listPromptbooks,
3596
- getPromptbookByUrl: getPromptbookByUrl,
3594
+ listPipelines: listPipelines,
3595
+ getPipelineByUrl: getPipelineByUrl,
3597
3596
  isResponsibleForPrompt: isResponsibleForPrompt,
3598
3597
  };
3599
3598
  }
@@ -3601,9 +3600,9 @@
3601
3600
  /**
3602
3601
  * Constructs Promptbook from remote Promptbase URL
3603
3602
 
3604
- * @returns PromptbookLibrary
3603
+ * @returns PipelineCollection
3605
3604
  */
3606
- function createLibraryFromUrl(url, options) {
3605
+ function createCollectionFromUrl(url, options) {
3607
3606
  return __awaiter(this, void 0, void 0, function () {
3608
3607
  var _a, _b, isVerbose, _c, isLazyLoaded, library;
3609
3608
  var _this = this;
@@ -3611,7 +3610,7 @@
3611
3610
  switch (_d.label) {
3612
3611
  case 0:
3613
3612
  _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3614
- library = createLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3613
+ library = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3615
3614
  return __generator(this, function (_a) {
3616
3615
  if (isVerbose) {
3617
3616
  console.info("Creating promptbook library from url ".concat(url.toString()));
@@ -3620,7 +3619,7 @@
3620
3619
  });
3621
3620
  }); });
3622
3621
  if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3623
- return [4 /*yield*/, library.listPromptbooks()];
3622
+ return [4 /*yield*/, library.listPipelines()];
3624
3623
  case 1:
3625
3624
  _d.sent();
3626
3625
  _d.label = 2;
@@ -3634,21 +3633,21 @@
3634
3633
  */
3635
3634
 
3636
3635
  /**
3637
- * Creates PromptbookLibrary as a subset of another PromptbookLibrary
3636
+ * Creates PipelineCollection as a subset of another PipelineCollection
3638
3637
  *
3639
3638
  * Note: You can use any type of library as a parent library - local, remote, etc.
3640
3639
  * Note: This is just a thin wrapper / proxy around the parent library
3641
3640
  *
3642
3641
  * @param promptbookSources
3643
- * @returns PromptbookLibrary
3642
+ * @returns PipelineCollection
3644
3643
  */
3645
- function createSublibrary(library, predicate) {
3646
- function listPromptbooks() {
3644
+ function createSubcollection(library, predicate) {
3645
+ function listPipelines() {
3647
3646
  return __awaiter(this, void 0, void 0, function () {
3648
3647
  var promptbooks;
3649
3648
  return __generator(this, function (_a) {
3650
3649
  switch (_a.label) {
3651
- case 0: return [4 /*yield*/, library.listPromptbooks()];
3650
+ case 0: return [4 /*yield*/, library.listPipelines()];
3652
3651
  case 1:
3653
3652
  promptbooks = _a.sent();
3654
3653
  promptbooks = promptbooks.filter(predicate);
@@ -3657,7 +3656,7 @@
3657
3656
  });
3658
3657
  });
3659
3658
  }
3660
- function getPromptbookByUrl(url) {
3659
+ function getPipelineByUrl(url) {
3661
3660
  return __awaiter(this, void 0, void 0, function () {
3662
3661
  var _a, promptbook;
3663
3662
  var _this = this;
@@ -3665,7 +3664,7 @@
3665
3664
  switch (_b.label) {
3666
3665
  case 0:
3667
3666
  if (!!predicate(url)) return [3 /*break*/, 2];
3668
- _a = PromptbookNotFoundError.bind;
3667
+ _a = NotFoundError.bind;
3669
3668
  return [4 /*yield*/, spaceTrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
3670
3669
  var _a, _b, _c, _d, _e, _f;
3671
3670
  return __generator(this, function (_g) {
@@ -3673,17 +3672,17 @@
3673
3672
  case 0:
3674
3673
  _c = (_b = "\n Promptbook with url \"".concat(url, "\" not found or not accessible\n\n Available promptbooks:\n ")).concat;
3675
3674
  _d = block;
3676
- return [4 /*yield*/, listPromptbooks()];
3675
+ return [4 /*yield*/, listPipelines()];
3677
3676
  case 1:
3678
3677
  _e = (_a = _c.apply(_b, [_d.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n All available promptbooks in parent library:\n "])).concat;
3679
3678
  _f = block;
3680
- return [4 /*yield*/, library.listPromptbooks()];
3679
+ return [4 /*yield*/, library.listPipelines()];
3681
3680
  case 2: return [2 /*return*/, _e.apply(_a, [_f.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n "])];
3682
3681
  }
3683
3682
  });
3684
3683
  }); })];
3685
- case 1: throw new (_a.apply(PromptbookNotFoundError, [void 0, _b.sent()]))();
3686
- case 2: return [4 /*yield*/, library.getPromptbookByUrl(url)];
3684
+ case 1: throw new (_a.apply(NotFoundError, [void 0, _b.sent()]))();
3685
+ case 2: return [4 /*yield*/, library.getPipelineByUrl(url)];
3687
3686
  case 3:
3688
3687
  promptbook = _b.sent();
3689
3688
  return [2 /*return*/, promptbook];
@@ -3706,26 +3705,26 @@
3706
3705
  });
3707
3706
  }
3708
3707
  return {
3709
- listPromptbooks: listPromptbooks,
3710
- getPromptbookByUrl: getPromptbookByUrl,
3708
+ listPipelines: listPipelines,
3709
+ getPipelineByUrl: getPipelineByUrl,
3711
3710
  isResponsibleForPrompt: isResponsibleForPrompt,
3712
3711
  };
3713
3712
  }
3714
3713
 
3715
3714
  /**
3716
- * Converts PromptbookLibrary to serialized JSON
3715
+ * Converts PipelineCollection to serialized JSON
3717
3716
  *
3718
- * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
3717
+ * Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
3719
3718
  */
3720
3719
  function libraryToJson(library) {
3721
3720
  return __awaiter(this, void 0, void 0, function () {
3722
3721
  var promptbookUrls, promptbooks;
3723
3722
  return __generator(this, function (_a) {
3724
3723
  switch (_a.label) {
3725
- case 0: return [4 /*yield*/, library.listPromptbooks()];
3724
+ case 0: return [4 /*yield*/, library.listPipelines()];
3726
3725
  case 1:
3727
3726
  promptbookUrls = _a.sent();
3728
- return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.getPromptbookByUrl(url); }))];
3727
+ return [4 /*yield*/, Promise.all(promptbookUrls.map(function (url) { return library.getPipelineByUrl(url); }))];
3729
3728
  case 2:
3730
3729
  promptbooks = _a.sent();
3731
3730
  return [2 /*return*/, promptbooks];
@@ -3753,19 +3752,19 @@
3753
3752
  /**
3754
3753
  * Calls the best available chat model
3755
3754
  */
3756
- MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
3757
- return this.gptCommon(prompt);
3755
+ MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
3756
+ return this.callModelCommon(prompt);
3758
3757
  };
3759
3758
  /**
3760
3759
  * Calls the best available completion model
3761
3760
  */
3762
- MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
3763
- return this.gptCommon(prompt);
3761
+ MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
3762
+ return this.callModelCommon(prompt);
3764
3763
  };
3765
3764
  /**
3766
3765
  * Calls the best available model
3767
3766
  */
3768
- MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
3767
+ MultipleLlmExecutionTools.prototype.callModelCommon = function (prompt) {
3769
3768
  return __awaiter(this, void 0, void 0, function () {
3770
3769
  var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
3771
3770
  var e_1, _c;
@@ -3785,11 +3784,11 @@
3785
3784
  case 3:
3786
3785
  _d.trys.push([3, 8, , 9]);
3787
3786
  if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
3788
- return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
3787
+ return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
3789
3788
  case 4: return [2 /*return*/, _d.sent()];
3790
3789
  case 5:
3791
3790
  if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
3792
- return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
3791
+ return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
3793
3792
  case 6: return [2 /*return*/, _d.sent()];
3794
3793
  case 7: return [3 /*break*/, 9];
3795
3794
  case 8:
@@ -3813,7 +3812,7 @@
3813
3812
  }
3814
3813
  finally { if (e_1) throw e_1.error; }
3815
3814
  return [7 /*endfinally*/];
3816
- case 13: throw new Error(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 "); }));
3815
+ case 13: throw new Error(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 "); }));
3817
3816
  }
3818
3817
  });
3819
3818
  });
@@ -3865,10 +3864,18 @@
3865
3864
  return MultipleLlmExecutionTools;
3866
3865
  }());
3867
3866
 
3867
+ /**
3868
+ * Default options for generating an execution report string
3869
+ */
3870
+ var ExecutionReportStringOptionsDefaults = {
3871
+ taxRate: 0,
3872
+ chartsWidth: 36,
3873
+ };
3874
+
3868
3875
  /**
3869
3876
  * Format either small or big number
3870
3877
  *
3871
- * @private within the library
3878
+ * @private within the package
3872
3879
  */
3873
3880
  function formatNumber(value) {
3874
3881
  if (value === 0) {
@@ -3888,7 +3895,7 @@
3888
3895
  /**
3889
3896
  * Create a markdown table from a 2D array of strings
3890
3897
  *
3891
- * @private within the library
3898
+ * @private within the package
3892
3899
  */
3893
3900
  function createMarkdownTable(table) {
3894
3901
  var columnWidths = table.reduce(function (widths, row) {
@@ -3916,7 +3923,7 @@
3916
3923
  /**
3917
3924
  * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
3918
3925
  *
3919
- * @private within the library
3926
+ * @private within the package
3920
3927
  */
3921
3928
  function createMarkdownChart(options) {
3922
3929
  var e_1, _a;
@@ -3957,14 +3964,6 @@
3957
3964
  return value.replace(/```/g, '\\`\\`\\`');
3958
3965
  }
3959
3966
 
3960
- /**
3961
- * Default options for generating an execution report string
3962
- */
3963
- var ExecutionReportStringOptionsDefaults = {
3964
- taxRate: 0,
3965
- chartsWidth: 36,
3966
- };
3967
-
3968
3967
  /**
3969
3968
  * The thresholds for the relative time in the `moment` library.
3970
3969
  *
@@ -3977,7 +3976,7 @@
3977
3976
  /**
3978
3977
  * Count the duration of working time
3979
3978
  *
3980
- * @private within the library
3979
+ * @private within the package
3981
3980
  */
3982
3981
  function countWorkingDuration(items) {
3983
3982
  var e_1, _a;
@@ -4169,39 +4168,39 @@
4169
4168
  */
4170
4169
 
4171
4170
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
4171
+ exports.CollectionError = CollectionError;
4172
+ exports.ExecutionError = ExecutionError;
4172
4173
  exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
4173
4174
  exports.ExecutionTypes = ExecutionTypes;
4174
4175
  exports.ExpectError = ExpectError;
4175
4176
  exports.MultipleLlmExecutionTools = MultipleLlmExecutionTools;
4177
+ exports.NotFoundError = NotFoundError;
4176
4178
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
4177
- exports.PromptbookExecutionError = PromptbookExecutionError;
4178
- exports.PromptbookLibraryError = PromptbookLibraryError;
4179
- exports.PromptbookLogicError = PromptbookLogicError;
4180
- exports.PromptbookNotFoundError = PromptbookNotFoundError;
4181
- exports.PromptbookReferenceError = PromptbookReferenceError;
4182
- exports.PromptbookSyntaxError = PromptbookSyntaxError;
4179
+ exports.PipelineLogicError = PipelineLogicError;
4180
+ exports.ReferenceError = ReferenceError$1;
4183
4181
  exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
4182
+ exports.SyntaxError = SyntaxError;
4184
4183
  exports.TemplateError = TemplateError;
4185
4184
  exports.UnexpectedError = UnexpectedError;
4186
4185
  exports.addUsage = addUsage;
4187
4186
  exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
4188
4187
  exports.checkExpectations = checkExpectations;
4189
- exports.createLibraryFromJson = createLibraryFromJson;
4190
- exports.createLibraryFromPromise = createLibraryFromPromise;
4191
- exports.createLibraryFromUrl = createLibraryFromUrl;
4188
+ exports.createCollectionFromJson = createCollectionFromJson;
4189
+ exports.createCollectionFromPromise = createCollectionFromPromise;
4190
+ exports.createCollectionFromUrl = createCollectionFromUrl;
4192
4191
  exports.createPromptbookExecutor = createPromptbookExecutor;
4193
- exports.createSublibrary = createSublibrary;
4192
+ exports.createSublibrary = createSubcollection;
4194
4193
  exports.embeddingVectorToString = embeddingVectorToString;
4195
4194
  exports.executionReportJsonToString = executionReportJsonToString;
4196
4195
  exports.isPassingExpectations = isPassingExpectations;
4197
4196
  exports.libraryToJson = libraryToJson;
4197
+ exports.pipelineJsonToString = pipelineJsonToString;
4198
+ exports.pipelineStringToJson = pipelineStringToJson;
4199
+ exports.pipelineStringToJsonSync = pipelineStringToJsonSync;
4198
4200
  exports.prepareKnowledgeFromMarkdown = prepareKnowledgeFromMarkdown;
4199
- exports.prettifyPromptbookString = prettifyPromptbookString;
4200
- exports.promptbookJsonToString = promptbookJsonToString;
4201
- exports.promptbookStringToJson = promptbookStringToJson;
4202
- exports.promptbookStringToJsonSync = promptbookStringToJsonSync;
4201
+ exports.prettifyPipelineString = prettifyPipelineString;
4203
4202
  exports.usageToWorktime = usageToWorktime;
4204
- exports.validatePromptbook = validatePromptbook;
4203
+ exports.validatePipeline = validatePipeline;
4205
4204
 
4206
4205
  Object.defineProperty(exports, '__esModule', { value: true });
4207
4206