@promptbook/cli 0.41.109

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 (363) hide show
  1. package/README.md +5 -0
  2. package/bin/promptbook-cli.js +11 -0
  3. package/esm/index.es.js +1356 -0
  4. package/esm/index.es.js.map +1 -0
  5. package/esm/typings/_packages/cli.index.d.ts +8 -0
  6. package/esm/typings/_packages/core.index.d.ts +20 -0
  7. package/esm/typings/_packages/execute-javascript.index.d.ts +3 -0
  8. package/esm/typings/_packages/openai.index.d.ts +3 -0
  9. package/esm/typings/_packages/remote-client.index.d.ts +4 -0
  10. package/esm/typings/_packages/remote-server.index.d.ts +3 -0
  11. package/esm/typings/_packages/types.index.d.ts +27 -0
  12. package/esm/typings/_packages/utils.index.d.ts +31 -0
  13. package/esm/typings/_packages/wizzard.index.d.ts +5 -0
  14. package/esm/typings/config.d.ts +4 -0
  15. package/esm/typings/conversion/prettify/PrettifyOptions.d.ts +7 -0
  16. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +10 -0
  17. package/esm/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +9 -0
  18. package/esm/typings/conversion/promptbookStringToJson.d.ts +13 -0
  19. package/esm/typings/conversion/utils/extractVariables.d.ts +10 -0
  20. package/esm/typings/conversion/utils/extractVariables.test.d.ts +1 -0
  21. package/esm/typings/conversion/utils/parseCommand.d.ts +8 -0
  22. package/esm/typings/conversion/utils/parseCommand.test.d.ts +4 -0
  23. package/esm/typings/conversion/utils/parseNumber.d.ts +12 -0
  24. package/esm/typings/conversion/utils/parseNumber.test.d.ts +1 -0
  25. package/esm/typings/conversion/validation/_importPromptbook.d.ts +12 -0
  26. package/esm/typings/conversion/validation/promptbookStringToJson-syntaxErrors.test.d.ts +1 -0
  27. package/esm/typings/conversion/validation/promptbookStringToJson.test.d.ts +1 -0
  28. package/esm/typings/conversion/validation/validatePromptbookJson-logicErrors.test.d.ts +1 -0
  29. package/esm/typings/conversion/validation/validatePromptbookJson.d.ts +26 -0
  30. package/esm/typings/conversion/validation/validatePromptbookJson.test.d.ts +1 -0
  31. package/esm/typings/errors/ExpectError.d.ts +9 -0
  32. package/esm/typings/errors/NotFoundError.d.ts +7 -0
  33. package/esm/typings/errors/PromptbookExecutionError.d.ts +7 -0
  34. package/esm/typings/errors/PromptbookLogicError.d.ts +7 -0
  35. package/esm/typings/errors/PromptbookReferenceError.d.ts +7 -0
  36. package/esm/typings/errors/PromptbookSyntaxError.d.ts +7 -0
  37. package/esm/typings/errors/UnexpectedError.d.ts +7 -0
  38. package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +9 -0
  39. package/esm/typings/execution/ExecutionTools.d.ts +25 -0
  40. package/esm/typings/execution/NaturalExecutionTools.d.ts +23 -0
  41. package/esm/typings/execution/PromptResult.d.ts +74 -0
  42. package/esm/typings/execution/PromptbookExecutor.d.ts +39 -0
  43. package/esm/typings/execution/ScriptExecutionTools.d.ts +37 -0
  44. package/esm/typings/execution/UserInterfaceTools.d.ts +45 -0
  45. package/esm/typings/execution/assertsExecutionSuccessful.d.ts +11 -0
  46. package/esm/typings/execution/createPromptbookExecutor.d.ts +41 -0
  47. package/esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  48. package/esm/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +4 -0
  49. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  50. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  51. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +28 -0
  52. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +16 -0
  53. package/esm/typings/execution/plugins/natural-execution-tools/openai/computeOpenaiUsage.d.ts +3 -0
  54. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  55. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +23 -0
  56. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -0
  57. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -0
  58. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -0
  59. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -0
  60. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +27 -0
  61. package/esm/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts +17 -0
  62. package/esm/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -0
  63. package/esm/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -0
  64. package/esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -0
  65. package/esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -0
  66. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -0
  67. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  68. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  69. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +22 -0
  70. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  71. package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -0
  72. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  73. package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  74. package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  75. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  76. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  77. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  78. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  79. package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  80. package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -0
  81. package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -0
  82. package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -0
  83. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -0
  84. package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
  85. package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -0
  86. package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
  87. package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -0
  88. package/esm/typings/execution/utils/replaceParameters.d.ts +12 -0
  89. package/esm/typings/execution/utils/replaceParameters.test.d.ts +1 -0
  90. package/esm/typings/library/PromptbookLibrary.d.ts +25 -0
  91. package/esm/typings/library/SimplePromptbookLibrary.d.ts +35 -0
  92. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +5 -0
  93. package/esm/typings/library/constructors/createPromptbookLibraryFromList.d.ts +5 -0
  94. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -0
  95. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -0
  96. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -0
  97. package/esm/typings/types/Command.d.ts +98 -0
  98. package/esm/typings/types/ExecutionTypes.d.ts +13 -0
  99. package/esm/typings/types/ModelRequirements.d.ts +41 -0
  100. package/esm/typings/types/Parameters.d.ts +14 -0
  101. package/esm/typings/types/Prompt.d.ts +41 -0
  102. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +126 -0
  103. package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +25 -0
  104. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +51 -0
  105. package/esm/typings/types/PromptbookString.d.ts +12 -0
  106. package/esm/typings/types/ScriptLanguage.d.ts +9 -0
  107. package/esm/typings/types/TaskProgress.d.ts +42 -0
  108. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +56 -0
  109. package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  110. package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -0
  111. package/esm/typings/types/execution-report/config.d.ts +8 -0
  112. package/esm/typings/types/execution-report/countWorkingDuration.d.ts +7 -0
  113. package/esm/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -0
  114. package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +11 -0
  115. package/esm/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -0
  116. package/esm/typings/types/typeAliasEmoji.d.ts +9 -0
  117. package/esm/typings/types/typeAliases.d.ts +432 -0
  118. package/esm/typings/utils/FromtoItems.d.ts +19 -0
  119. package/esm/typings/utils/emojis.d.ts +22 -0
  120. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  121. package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  122. package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
  123. package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  124. package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
  125. package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  126. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  127. package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  128. package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  129. package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  130. package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
  131. package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  132. package/esm/typings/utils/expectation-counters/index.d.ts +5 -0
  133. package/esm/typings/utils/extractParameters.d.ts +10 -0
  134. package/esm/typings/utils/extractParameters.test.d.ts +1 -0
  135. package/esm/typings/utils/formatNumber.d.ts +6 -0
  136. package/esm/typings/utils/formatNumber.test.d.ts +1 -0
  137. package/esm/typings/utils/getCurrentIsoDate.d.ts +7 -0
  138. package/esm/typings/utils/isRunningInWhatever.d.ts +12 -0
  139. package/esm/typings/utils/isValidJsonString.d.ts +4 -0
  140. package/esm/typings/utils/isValidJsonString.test.d.ts +1 -0
  141. package/esm/typings/utils/just.d.ts +10 -0
  142. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -0
  143. package/esm/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  144. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +41 -0
  145. package/esm/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -0
  146. package/esm/typings/utils/markdown/createMarkdownTable.d.ts +7 -0
  147. package/esm/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -0
  148. package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -0
  149. package/esm/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
  150. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -0
  151. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
  152. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +13 -0
  153. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  154. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -0
  155. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  156. package/esm/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
  157. package/esm/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
  158. package/esm/typings/utils/markdown/removeContentComments.d.ts +8 -0
  159. package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  160. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  161. package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  162. package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  163. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  164. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  165. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  166. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  167. package/esm/typings/utils/postprocessing/extractBlock.d.ts +12 -0
  168. package/esm/typings/utils/removeEmojis.d.ts +7 -0
  169. package/esm/typings/utils/removeEmojis.test.d.ts +1 -0
  170. package/esm/typings/utils/removeQuotes.d.ts +13 -0
  171. package/esm/typings/utils/removeQuotes.test.d.ts +1 -0
  172. package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
  173. package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
  174. package/esm/typings/utils/trimEndOfCodeBlock.d.ts +7 -0
  175. package/esm/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -0
  176. package/esm/typings/utils/unwrapResult.d.ts +36 -0
  177. package/esm/typings/utils/unwrapResult.test.d.ts +1 -0
  178. package/esm/typings/utils/validators/url/isValidUrl.d.ts +7 -0
  179. package/esm/typings/utils/validators/url/isValidUrl.test.d.ts +1 -0
  180. package/esm/typings/version.d.ts +5 -0
  181. package/esm/typings/wizzard/Wizzard.d.ts +4 -0
  182. package/esm/typings/wizzard/sample.d.ts +6 -0
  183. package/package.json +54 -0
  184. package/umd/index.umd.js +1364 -0
  185. package/umd/index.umd.js.map +1 -0
  186. package/umd/typings/_packages/cli.index.d.ts +8 -0
  187. package/umd/typings/_packages/core.index.d.ts +20 -0
  188. package/umd/typings/_packages/execute-javascript.index.d.ts +3 -0
  189. package/umd/typings/_packages/openai.index.d.ts +3 -0
  190. package/umd/typings/_packages/remote-client.index.d.ts +4 -0
  191. package/umd/typings/_packages/remote-server.index.d.ts +3 -0
  192. package/umd/typings/_packages/types.index.d.ts +27 -0
  193. package/umd/typings/_packages/utils.index.d.ts +31 -0
  194. package/umd/typings/_packages/wizzard.index.d.ts +5 -0
  195. package/umd/typings/config.d.ts +4 -0
  196. package/umd/typings/conversion/prettify/PrettifyOptions.d.ts +7 -0
  197. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +10 -0
  198. package/umd/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +9 -0
  199. package/umd/typings/conversion/promptbookStringToJson.d.ts +13 -0
  200. package/umd/typings/conversion/utils/extractVariables.d.ts +10 -0
  201. package/umd/typings/conversion/utils/extractVariables.test.d.ts +1 -0
  202. package/umd/typings/conversion/utils/parseCommand.d.ts +8 -0
  203. package/umd/typings/conversion/utils/parseCommand.test.d.ts +4 -0
  204. package/umd/typings/conversion/utils/parseNumber.d.ts +12 -0
  205. package/umd/typings/conversion/utils/parseNumber.test.d.ts +1 -0
  206. package/umd/typings/conversion/validation/_importPromptbook.d.ts +12 -0
  207. package/umd/typings/conversion/validation/promptbookStringToJson-syntaxErrors.test.d.ts +1 -0
  208. package/umd/typings/conversion/validation/promptbookStringToJson.test.d.ts +1 -0
  209. package/umd/typings/conversion/validation/validatePromptbookJson-logicErrors.test.d.ts +1 -0
  210. package/umd/typings/conversion/validation/validatePromptbookJson.d.ts +26 -0
  211. package/umd/typings/conversion/validation/validatePromptbookJson.test.d.ts +1 -0
  212. package/umd/typings/errors/ExpectError.d.ts +9 -0
  213. package/umd/typings/errors/NotFoundError.d.ts +7 -0
  214. package/umd/typings/errors/PromptbookExecutionError.d.ts +7 -0
  215. package/umd/typings/errors/PromptbookLogicError.d.ts +7 -0
  216. package/umd/typings/errors/PromptbookReferenceError.d.ts +7 -0
  217. package/umd/typings/errors/PromptbookSyntaxError.d.ts +7 -0
  218. package/umd/typings/errors/UnexpectedError.d.ts +7 -0
  219. package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +9 -0
  220. package/umd/typings/execution/ExecutionTools.d.ts +25 -0
  221. package/umd/typings/execution/NaturalExecutionTools.d.ts +23 -0
  222. package/umd/typings/execution/PromptResult.d.ts +74 -0
  223. package/umd/typings/execution/PromptbookExecutor.d.ts +39 -0
  224. package/umd/typings/execution/ScriptExecutionTools.d.ts +37 -0
  225. package/umd/typings/execution/UserInterfaceTools.d.ts +45 -0
  226. package/umd/typings/execution/assertsExecutionSuccessful.d.ts +11 -0
  227. package/umd/typings/execution/createPromptbookExecutor.d.ts +41 -0
  228. package/umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  229. package/umd/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +4 -0
  230. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  231. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  232. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +28 -0
  233. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +16 -0
  234. package/umd/typings/execution/plugins/natural-execution-tools/openai/computeOpenaiUsage.d.ts +3 -0
  235. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  236. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +23 -0
  237. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -0
  238. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -0
  239. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -0
  240. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -0
  241. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +27 -0
  242. package/umd/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts +17 -0
  243. package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -0
  244. package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -0
  245. package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -0
  246. package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -0
  247. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -0
  248. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  249. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  250. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +22 -0
  251. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  252. package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -0
  253. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  254. package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  255. package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  256. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  257. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  258. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  259. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  260. package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  261. package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -0
  262. package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -0
  263. package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -0
  264. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -0
  265. package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
  266. package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -0
  267. package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
  268. package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -0
  269. package/umd/typings/execution/utils/replaceParameters.d.ts +12 -0
  270. package/umd/typings/execution/utils/replaceParameters.test.d.ts +1 -0
  271. package/umd/typings/library/PromptbookLibrary.d.ts +25 -0
  272. package/umd/typings/library/SimplePromptbookLibrary.d.ts +35 -0
  273. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +5 -0
  274. package/umd/typings/library/constructors/createPromptbookLibraryFromList.d.ts +5 -0
  275. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -0
  276. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -0
  277. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -0
  278. package/umd/typings/types/Command.d.ts +98 -0
  279. package/umd/typings/types/ExecutionTypes.d.ts +13 -0
  280. package/umd/typings/types/ModelRequirements.d.ts +41 -0
  281. package/umd/typings/types/Parameters.d.ts +14 -0
  282. package/umd/typings/types/Prompt.d.ts +41 -0
  283. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +126 -0
  284. package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +25 -0
  285. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +51 -0
  286. package/umd/typings/types/PromptbookString.d.ts +12 -0
  287. package/umd/typings/types/ScriptLanguage.d.ts +9 -0
  288. package/umd/typings/types/TaskProgress.d.ts +42 -0
  289. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +56 -0
  290. package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  291. package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -0
  292. package/umd/typings/types/execution-report/config.d.ts +8 -0
  293. package/umd/typings/types/execution-report/countWorkingDuration.d.ts +7 -0
  294. package/umd/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -0
  295. package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +11 -0
  296. package/umd/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -0
  297. package/umd/typings/types/typeAliasEmoji.d.ts +9 -0
  298. package/umd/typings/types/typeAliases.d.ts +432 -0
  299. package/umd/typings/utils/FromtoItems.d.ts +19 -0
  300. package/umd/typings/utils/emojis.d.ts +22 -0
  301. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  302. package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  303. package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
  304. package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  305. package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
  306. package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  307. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  308. package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  309. package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  310. package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  311. package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
  312. package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  313. package/umd/typings/utils/expectation-counters/index.d.ts +5 -0
  314. package/umd/typings/utils/extractParameters.d.ts +10 -0
  315. package/umd/typings/utils/extractParameters.test.d.ts +1 -0
  316. package/umd/typings/utils/formatNumber.d.ts +6 -0
  317. package/umd/typings/utils/formatNumber.test.d.ts +1 -0
  318. package/umd/typings/utils/getCurrentIsoDate.d.ts +7 -0
  319. package/umd/typings/utils/isRunningInWhatever.d.ts +12 -0
  320. package/umd/typings/utils/isValidJsonString.d.ts +4 -0
  321. package/umd/typings/utils/isValidJsonString.test.d.ts +1 -0
  322. package/umd/typings/utils/just.d.ts +10 -0
  323. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -0
  324. package/umd/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  325. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +41 -0
  326. package/umd/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -0
  327. package/umd/typings/utils/markdown/createMarkdownTable.d.ts +7 -0
  328. package/umd/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -0
  329. package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -0
  330. package/umd/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
  331. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -0
  332. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
  333. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +13 -0
  334. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  335. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -0
  336. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  337. package/umd/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
  338. package/umd/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
  339. package/umd/typings/utils/markdown/removeContentComments.d.ts +8 -0
  340. package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  341. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  342. package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  343. package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  344. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  345. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  346. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  347. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  348. package/umd/typings/utils/postprocessing/extractBlock.d.ts +12 -0
  349. package/umd/typings/utils/removeEmojis.d.ts +7 -0
  350. package/umd/typings/utils/removeEmojis.test.d.ts +1 -0
  351. package/umd/typings/utils/removeQuotes.d.ts +13 -0
  352. package/umd/typings/utils/removeQuotes.test.d.ts +1 -0
  353. package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
  354. package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
  355. package/umd/typings/utils/trimEndOfCodeBlock.d.ts +7 -0
  356. package/umd/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -0
  357. package/umd/typings/utils/unwrapResult.d.ts +36 -0
  358. package/umd/typings/utils/unwrapResult.test.d.ts +1 -0
  359. package/umd/typings/utils/validators/url/isValidUrl.d.ts +7 -0
  360. package/umd/typings/utils/validators/url/isValidUrl.test.d.ts +1 -0
  361. package/umd/typings/version.d.ts +5 -0
  362. package/umd/typings/wizzard/Wizzard.d.ts +4 -0
  363. package/umd/typings/wizzard/sample.d.ts +6 -0
@@ -0,0 +1,1364 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('fs/promises'), require('glob-promise'), require('spacetrim'), require('waitasecond'), require('n12'), require('prettier'), require('prettier/parser-html')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'fs/promises', 'glob-promise', 'spacetrim', 'waitasecond', 'n12', 'prettier', 'prettier/parser-html'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.spaceTrim, global.waitasecond, global.n12, global.prettier, global.parserHtml));
5
+ })(this, (function (exports, colors, commander, promises, glob, spaceTrim, waitasecond, n12, prettier, parserHtml) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
+ var commander__default = /*#__PURE__*/_interopDefaultLegacy(commander);
11
+ var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
12
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
13
+ var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
14
+
15
+ /*! *****************************************************************************
16
+ Copyright (c) Microsoft Corporation.
17
+
18
+ Permission to use, copy, modify, and/or distribute this software for any
19
+ purpose with or without fee is hereby granted.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
+ PERFORMANCE OF THIS SOFTWARE.
28
+ ***************************************************************************** */
29
+ /* global Reflect, Promise */
30
+
31
+ var extendStatics = function(d, b) {
32
+ extendStatics = Object.setPrototypeOf ||
33
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
34
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
35
+ return extendStatics(d, b);
36
+ };
37
+
38
+ function __extends(d, b) {
39
+ if (typeof b !== "function" && b !== null)
40
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
41
+ extendStatics(d, b);
42
+ function __() { this.constructor = d; }
43
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
44
+ }
45
+
46
+ var __assign = function() {
47
+ __assign = Object.assign || function __assign(t) {
48
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
49
+ s = arguments[i];
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
51
+ }
52
+ return t;
53
+ };
54
+ return __assign.apply(this, arguments);
55
+ };
56
+
57
+ function __awaiter(thisArg, _arguments, P, generator) {
58
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
59
+ return new (P || (P = Promise))(function (resolve, reject) {
60
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
61
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
62
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
63
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
64
+ });
65
+ }
66
+
67
+ function __generator(thisArg, body) {
68
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
69
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
70
+ function verb(n) { return function (v) { return step([n, v]); }; }
71
+ function step(op) {
72
+ if (f) throw new TypeError("Generator is already executing.");
73
+ while (_) try {
74
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
75
+ if (y = 0, t) op = [op[0] & 2, t.value];
76
+ switch (op[0]) {
77
+ case 0: case 1: t = op; break;
78
+ case 4: _.label++; return { value: op[1], done: false };
79
+ case 5: _.label++; y = op[1]; op = [0]; continue;
80
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
83
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
84
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
85
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
86
+ if (t[2]) _.ops.pop();
87
+ _.trys.pop(); continue;
88
+ }
89
+ op = body.call(thisArg, _);
90
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
91
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
92
+ }
93
+ }
94
+
95
+ function __values(o) {
96
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
97
+ if (m) return m.call(o);
98
+ if (o && typeof o.length === "number") return {
99
+ next: function () {
100
+ if (o && i >= o.length) o = void 0;
101
+ return { value: o && o[i++], done: !o };
102
+ }
103
+ };
104
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
105
+ }
106
+
107
+ function __read(o, n) {
108
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
109
+ if (!m) return o;
110
+ var i = m.call(o), r, ar = [], e;
111
+ try {
112
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
113
+ }
114
+ catch (error) { e = { error: error }; }
115
+ finally {
116
+ try {
117
+ if (r && !r.done && (m = i["return"])) m.call(i);
118
+ }
119
+ finally { if (e) throw e.error; }
120
+ }
121
+ return ar;
122
+ }
123
+
124
+ function __spreadArray(to, from, pack) {
125
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
126
+ if (ar || !(i in from)) {
127
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
128
+ ar[i] = from[i];
129
+ }
130
+ }
131
+ return to.concat(ar || Array.prototype.slice.call(from));
132
+ }
133
+
134
+ /**
135
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
136
+ */
137
+ new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
138
+ /**
139
+ * Detects if the code is running in a Node.js environment
140
+ */
141
+ var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
142
+ /**
143
+ * Detects if the code is running in a web worker
144
+ */
145
+ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
146
+
147
+ /**
148
+ * The version of the Promptbook library
149
+ */
150
+ var PROMPTBOOK_VERSION = '0.41.108';
151
+
152
+ /**
153
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
154
+ */
155
+ var PromptbookSyntaxError = /** @class */ (function (_super) {
156
+ __extends(PromptbookSyntaxError, _super);
157
+ function PromptbookSyntaxError(message) {
158
+ var _this = _super.call(this, message) || this;
159
+ _this.name = 'PromptbookSyntaxError';
160
+ Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
161
+ return _this;
162
+ }
163
+ return PromptbookSyntaxError;
164
+ }(Error));
165
+
166
+ /**
167
+ * Supported script languages
168
+ */
169
+ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
170
+
171
+ /**
172
+ * Parses the template and returns the list of all parameter names
173
+ *
174
+ * @param template the template with parameters in {curly} braces
175
+ * @returns the list of parameter names
176
+ *
177
+ * @private within the library
178
+ */
179
+ function extractParameters(template) {
180
+ var e_1, _a;
181
+ var matches = template.matchAll(/{\w+}/g);
182
+ var parameterNames = [];
183
+ try {
184
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
185
+ var match = matches_1_1.value;
186
+ var parameterName = match[0].slice(1, -1);
187
+ if (!parameterNames.includes(parameterName)) {
188
+ parameterNames.push(parameterName);
189
+ }
190
+ }
191
+ }
192
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
193
+ finally {
194
+ try {
195
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
196
+ }
197
+ finally { if (e_1) throw e_1.error; }
198
+ }
199
+ return parameterNames;
200
+ }
201
+
202
+ /**
203
+ * Computes the deepness of the markdown structure.
204
+ *
205
+ * @private within the library
206
+ */
207
+ function countMarkdownStructureDeepness(markdownStructure) {
208
+ var e_1, _a;
209
+ var maxDeepness = 0;
210
+ try {
211
+ for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
212
+ var section = _c.value;
213
+ maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
214
+ }
215
+ }
216
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
217
+ finally {
218
+ try {
219
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
220
+ }
221
+ finally { if (e_1) throw e_1.error; }
222
+ }
223
+ return maxDeepness + 1;
224
+ }
225
+
226
+ /**
227
+ * The maximum number of iterations for a loops
228
+ */
229
+ var LOOP_LIMIT = 1000;
230
+
231
+ /**
232
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
233
+ */
234
+ var UnexpectedError = /** @class */ (function (_super) {
235
+ __extends(UnexpectedError, _super);
236
+ function UnexpectedError(message) {
237
+ var _this = _super.call(this, spaceTrim__default["default"](function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
238
+ _this.name = 'UnexpectedError';
239
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
240
+ return _this;
241
+ }
242
+ return UnexpectedError;
243
+ }(Error));
244
+
245
+ /**
246
+ * Parse a markdown string into a MarkdownStructure object.
247
+ *
248
+ * Note: This function does work with code blocks
249
+ * Note: This function does not work with markdown comments
250
+ *
251
+ * @param markdown The markdown string to parse.
252
+ * @returns The MarkdownStructure object.
253
+ *
254
+ * @private within the library
255
+ */
256
+ function markdownToMarkdownStructure(markdown) {
257
+ var e_1, _a;
258
+ var lines = markdown.split('\n');
259
+ var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
260
+ var current = root;
261
+ var isInsideCodeBlock = false;
262
+ try {
263
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
264
+ var line = lines_1_1.value;
265
+ var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
266
+ if (isInsideCodeBlock || !headingMatch) {
267
+ if (line.startsWith('```')) {
268
+ isInsideCodeBlock = !isInsideCodeBlock;
269
+ }
270
+ current.contentLines.push(line);
271
+ }
272
+ else {
273
+ var level = headingMatch.groups.mark.length;
274
+ var title = headingMatch.groups.title.trim();
275
+ var parent_1 = void 0;
276
+ if (level > current.level) {
277
+ // Note: Going deeper (next section is child of current)
278
+ parent_1 = current;
279
+ }
280
+ else {
281
+ // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
282
+ parent_1 = current;
283
+ var loopLimit = LOOP_LIMIT;
284
+ while (parent_1.level !== level - 1) {
285
+ if (loopLimit-- < 0) {
286
+ throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
287
+ }
288
+ if (parent_1.parent === null /* <- Note: We are in root */) {
289
+ // [🌻]
290
+ throw new Error(spaceTrim__default["default"]("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
291
+ }
292
+ parent_1 = parent_1.parent;
293
+ }
294
+ }
295
+ var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
296
+ parent_1.sections.push(section);
297
+ current = section;
298
+ }
299
+ }
300
+ }
301
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
302
+ finally {
303
+ try {
304
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
305
+ }
306
+ finally { if (e_1) throw e_1.error; }
307
+ }
308
+ if (root.sections.length === 1) {
309
+ var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
310
+ return markdownStructure;
311
+ }
312
+ // [🌻]
313
+ throw new Error('The markdown file must have exactly one top-level section.');
314
+ // return root;
315
+ }
316
+ /**
317
+ * @private
318
+ */
319
+ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
320
+ var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
321
+ return {
322
+ level: level,
323
+ title: title,
324
+ content: spaceTrim__default["default"](contentLines.join('\n')),
325
+ sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
326
+ };
327
+ }
328
+
329
+ /**
330
+ * Utility function to extract all list items from markdown
331
+ *
332
+ * Note: It works with both ul and ol
333
+ * Note: It omits list items in code blocks
334
+ * Note: It flattens nested lists
335
+ * Note: It can not work with html syntax and comments
336
+ *
337
+ * @param markdown any valid markdown
338
+ * @returns
339
+ */
340
+ function extractAllListItemsFromMarkdown(markdown) {
341
+ var e_1, _a;
342
+ var lines = markdown.split('\n');
343
+ var listItems = [];
344
+ var isInCodeBlock = false;
345
+ try {
346
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
347
+ var line = lines_1_1.value;
348
+ var trimmedLine = line.trim();
349
+ if (trimmedLine.startsWith('```')) {
350
+ isInCodeBlock = !isInCodeBlock;
351
+ }
352
+ if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
353
+ var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
354
+ listItems.push(listItem);
355
+ }
356
+ }
357
+ }
358
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
359
+ finally {
360
+ try {
361
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
362
+ }
363
+ finally { if (e_1) throw e_1.error; }
364
+ }
365
+ return listItems;
366
+ }
367
+
368
+ /**
369
+ * Extracts all code blocks from markdown.
370
+ *
371
+ * Note: There are 3 simmilar function:
372
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
373
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
374
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
375
+ *
376
+ * @param markdown any valid markdown
377
+ * @returns code blocks with language and content
378
+ *
379
+ */
380
+ function extractAllBlocksFromMarkdown(markdown) {
381
+ var e_1, _a;
382
+ var codeBlocks = [];
383
+ var lines = markdown.split('\n');
384
+ var currentCodeBlock = null;
385
+ try {
386
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
387
+ var line = lines_1_1.value;
388
+ if (line.startsWith('```')) {
389
+ var language = line.slice(3).trim() || null;
390
+ if (currentCodeBlock === null) {
391
+ currentCodeBlock = { language: language, content: '' };
392
+ }
393
+ else {
394
+ if (language !== null) {
395
+ // [🌻]
396
+ throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
397
+ }
398
+ codeBlocks.push(currentCodeBlock);
399
+ currentCodeBlock = null;
400
+ }
401
+ }
402
+ else if (currentCodeBlock !== null) {
403
+ if (currentCodeBlock.content !== '') {
404
+ currentCodeBlock.content += '\n';
405
+ }
406
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
407
+ }
408
+ }
409
+ }
410
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
411
+ finally {
412
+ try {
413
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
414
+ }
415
+ finally { if (e_1) throw e_1.error; }
416
+ }
417
+ if (currentCodeBlock !== null) {
418
+ // [🌻]
419
+ throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
420
+ }
421
+ return codeBlocks;
422
+ }
423
+
424
+ /**
425
+ * Extracts exactly ONE code block from markdown.
426
+ *
427
+ * Note: If there are multiple or no code blocks the function throws an error
428
+ *
429
+ * Note: There are 3 simmilar function:
430
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
431
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
432
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
433
+ *
434
+ * @param markdown any valid markdown
435
+ * @returns code block with language and content
436
+ */
437
+ function extractOneBlockFromMarkdown(markdown) {
438
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
439
+ if (codeBlocks.length !== 1) {
440
+ // TODO: Report more specific place where the error happened
441
+ throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
442
+ }
443
+ return codeBlocks[0];
444
+ }
445
+ /***
446
+ * TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
447
+ */
448
+
449
+ /**
450
+ * Removes HTML or Markdown comments from a string.
451
+ *
452
+ * @param {string} content - The string to remove comments from.
453
+ * @returns {string} The input string with all comments removed.
454
+ */
455
+ function removeContentComments(content) {
456
+ return spaceTrim__default["default"](content.replace(/<!--(.*?)-->/gs, ''));
457
+ }
458
+
459
+ /**
460
+ * Parses the given script and returns the list of all used variables that are not defined in the script
461
+ *
462
+ * @param script from which to extract the variables
463
+ * @returns the list of variable names
464
+ *
465
+ * @private within the promptbookStringToJson
466
+ */
467
+ function extractVariables(script) {
468
+ var variables = [];
469
+ script = "(()=>{".concat(script, "})()");
470
+ try {
471
+ for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
472
+ try {
473
+ eval(script);
474
+ }
475
+ catch (error) {
476
+ if (!(error instanceof ReferenceError)) {
477
+ throw error;
478
+ }
479
+ var undefinedName = error.message.split(' ')[0];
480
+ /*
481
+ Note: Remapping error
482
+ From: [ReferenceError: thing is not defined],
483
+ To: [Error: Parameter {thing} is not defined],
484
+ */
485
+ if (!undefinedName) {
486
+ throw error;
487
+ }
488
+ if (script.includes(undefinedName + '(')) {
489
+ script = "const ".concat(undefinedName, " = ()=>'';") + script;
490
+ }
491
+ else {
492
+ variables.push(undefinedName);
493
+ script = "const ".concat(undefinedName, " = '';") + script;
494
+ }
495
+ }
496
+ }
497
+ catch (error) {
498
+ if (!(error instanceof Error)) {
499
+ throw error;
500
+ }
501
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
502
+ }
503
+ return variables;
504
+ }
505
+
506
+ /**
507
+ * Execution type describes the way how the block is executed
508
+ *
509
+ * @see https://github.com/webgptorg/promptbook#execution-type
510
+ */
511
+ var ExecutionTypes = [
512
+ 'PROMPT_TEMPLATE',
513
+ 'SIMPLE_TEMPLATE',
514
+ 'SCRIPT',
515
+ 'PROMPT_DIALOG',
516
+ // <- [🥻] Insert here when making new command
517
+ ];
518
+
519
+ /**
520
+ * Units of text measurement
521
+ */
522
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'PARAGRAPHS', 'LINES', 'PAGES'];
523
+ /**
524
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
525
+ */
526
+
527
+ /**
528
+ * Removes Markdown formatting tags from a string.
529
+ *
530
+ * @param {string} str - The string to remove Markdown tags from.
531
+ * @returns {string} The input string with all Markdown tags removed.
532
+ */
533
+ function removeMarkdownFormatting(str) {
534
+ // Remove bold formatting
535
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
536
+ // Remove italic formatting
537
+ str = str.replace(/\*(.*?)\*/g, '$1');
538
+ // Remove code formatting
539
+ str = str.replace(/`(.*?)`/g, '$1');
540
+ return str;
541
+ }
542
+
543
+ /**
544
+ * Function parseNumber will parse number from string
545
+ *
546
+ * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
547
+ * Note: it also works only with decimal numbers
548
+ *
549
+ * @private within the parseCommand
550
+ */
551
+ function parseNumber(value) {
552
+ var originalValue = value;
553
+ if (typeof value === 'number') {
554
+ value = value.toString(); // <- TODO: Maybe more efficient way to do this
555
+ }
556
+ if (typeof value !== 'string') {
557
+ return 0;
558
+ }
559
+ value = value.trim();
560
+ if (value.startsWith('+')) {
561
+ return parseNumber(value.substring(1));
562
+ }
563
+ if (value.startsWith('-')) {
564
+ var number = parseNumber(value.substring(1));
565
+ if (number === 0) {
566
+ return 0; // <- Note: To prevent -0
567
+ }
568
+ return -number;
569
+ }
570
+ value = value.replace(/,/g, '.');
571
+ value = value.toUpperCase();
572
+ if (value === '') {
573
+ return 0;
574
+ }
575
+ if (value === '♾' || value.startsWith('INF')) {
576
+ return Infinity;
577
+ }
578
+ if (value.includes('/')) {
579
+ var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
580
+ var numerator = parseNumber(numerator_);
581
+ var denominator = parseNumber(denominator_);
582
+ if (denominator === 0) {
583
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
584
+ }
585
+ return numerator / denominator;
586
+ }
587
+ if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
588
+ return 0;
589
+ }
590
+ if (value.includes('E')) {
591
+ var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
592
+ return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
593
+ }
594
+ if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
595
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
596
+ }
597
+ var num = parseFloat(value);
598
+ if (isNaN(num)) {
599
+ throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
600
+ }
601
+ return num;
602
+ }
603
+ /**
604
+ * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
605
+ */
606
+
607
+ /**
608
+ * Parses one line of ul/ol to command
609
+ *
610
+ * @private within the promptbookStringToJson
611
+ */
612
+ function parseCommand(listItem) {
613
+ var e_1, _a;
614
+ if (listItem.includes('\n') || listItem.includes('\r')) {
615
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
616
+ }
617
+ var type = listItem.trim();
618
+ type = type.split('`').join('');
619
+ type = type.split('"').join('');
620
+ type = type.split("'").join('');
621
+ type = type.split('~').join('');
622
+ type = type.split('[').join('');
623
+ type = type.split(']').join('');
624
+ type = type.split('(').join('');
625
+ type = type.split(')').join('');
626
+ type = n12.normalizeTo_SCREAMING_CASE(type);
627
+ type = type.split('DIALOGUE').join('DIALOG');
628
+ var listItemParts = listItem
629
+ .split(' ')
630
+ .map(function (part) { return part.trim(); })
631
+ .filter(function (item) { return item !== ''; })
632
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
633
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
634
+ .map(removeMarkdownFormatting);
635
+ if (type.startsWith('URL') ||
636
+ type.startsWith('PTBK_URL') ||
637
+ type.startsWith('PTBKURL') ||
638
+ type.startsWith('PROMPTBOOK_URL') ||
639
+ type.startsWith('PROMPTBOOKURL') ||
640
+ type.startsWith('HTTPS')) {
641
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
642
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
643
+ }
644
+ var promptbookUrlString = listItemParts.pop();
645
+ var promptbookUrl = new URL(promptbookUrlString);
646
+ if (promptbookUrl.protocol !== 'https:') {
647
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
648
+ }
649
+ if (promptbookUrl.hash !== '') {
650
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\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 ")));
651
+ }
652
+ return {
653
+ type: 'PROMPTBOOK_URL',
654
+ promptbookUrl: promptbookUrl,
655
+ };
656
+ }
657
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
658
+ if (listItemParts.length !== 2) {
659
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
660
+ }
661
+ var promptbookVersion = listItemParts.pop();
662
+ // TODO: Validate version
663
+ return {
664
+ type: 'PROMPTBOOK_VERSION',
665
+ promptbookVersion: promptbookVersion,
666
+ };
667
+ }
668
+ else if (type.startsWith('EXECUTE') ||
669
+ type.startsWith('EXEC') ||
670
+ type.startsWith('PROMPT_DIALOG') ||
671
+ type.startsWith('SIMPLE_TEMPLATE')) {
672
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
673
+ if (executionTypes.length !== 1) {
674
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](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 "); }));
675
+ }
676
+ return {
677
+ type: 'EXECUTE',
678
+ executionType: executionTypes[0],
679
+ };
680
+ }
681
+ else if (type.startsWith('MODEL')) {
682
+ // TODO: Make this more elegant and dynamically
683
+ if (type.startsWith('MODEL_VARIANT')) {
684
+ if (type === 'MODEL_VARIANT_CHAT') {
685
+ return {
686
+ type: 'MODEL',
687
+ key: 'modelVariant',
688
+ value: 'CHAT',
689
+ };
690
+ }
691
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
692
+ return {
693
+ type: 'MODEL',
694
+ key: 'modelVariant',
695
+ value: 'COMPLETION',
696
+ };
697
+ }
698
+ else {
699
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](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 "); }));
700
+ }
701
+ }
702
+ if (type.startsWith('MODEL_NAME')) {
703
+ return {
704
+ type: 'MODEL',
705
+ key: 'modelName',
706
+ value: listItemParts.pop(),
707
+ };
708
+ }
709
+ else {
710
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](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 "); }));
711
+ }
712
+ }
713
+ else if (type.startsWith('PARAM') ||
714
+ type.startsWith('INPUT_PARAM') ||
715
+ type.startsWith('OUTPUT_PARAM') ||
716
+ listItem.startsWith('{') ||
717
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
718
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
719
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
720
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
721
+ }
722
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
723
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
724
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
725
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
726
+ }
727
+ var isInput = type.startsWith('INPUT');
728
+ var isOutput = type.startsWith('OUTPUT');
729
+ return {
730
+ type: 'PARAMETER',
731
+ parameterName: parameterName,
732
+ parameterDescription: parameterDescription.trim() || null,
733
+ isInput: isInput,
734
+ isOutput: isOutput,
735
+ };
736
+ }
737
+ else if (type.startsWith('JOKER')) {
738
+ if (listItemParts.length !== 2) {
739
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
740
+ }
741
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
742
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
743
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
744
+ }
745
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
746
+ var parameterName = parametersMatch.groups.parameterName;
747
+ return {
748
+ type: 'JOKER',
749
+ parameterName: parameterName,
750
+ };
751
+ }
752
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
753
+ if (listItemParts.length !== 2) {
754
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
755
+ }
756
+ var functionName = listItemParts.pop();
757
+ return {
758
+ type: 'POSTPROCESS',
759
+ functionName: functionName,
760
+ };
761
+ }
762
+ else if (type.startsWith('EXPECT_JSON')) {
763
+ return {
764
+ type: 'EXPECT_FORMAT',
765
+ format: 'JSON',
766
+ };
767
+ // [🥤]
768
+ }
769
+ else if (type.startsWith('EXPECT')) {
770
+ try {
771
+ listItemParts.shift();
772
+ var sign = void 0;
773
+ var signRaw = listItemParts.shift();
774
+ if (/^exact/i.test(signRaw)) {
775
+ sign = 'EXACTLY';
776
+ }
777
+ else if (/^min/i.test(signRaw)) {
778
+ sign = 'MINIMUM';
779
+ }
780
+ else if (/^max/i.test(signRaw)) {
781
+ sign = 'MAXIMUM';
782
+ }
783
+ else {
784
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\""));
785
+ }
786
+ var amountRaw = listItemParts.shift();
787
+ var amount = parseNumber(amountRaw);
788
+ if (amount < 0) {
789
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
790
+ }
791
+ if (amount !== Math.floor(amount)) {
792
+ throw new PromptbookSyntaxError('Amount must be whole number');
793
+ }
794
+ var unitRaw = listItemParts.shift();
795
+ var unit = undefined;
796
+ try {
797
+ for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
798
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
799
+ var existingUnitText = existingUnit;
800
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
801
+ if (existingUnitText === 'CHARACTER') {
802
+ existingUnitText = 'CHAR';
803
+ }
804
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
805
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
806
+ if (unit !== undefined) {
807
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
808
+ }
809
+ unit = existingUnit;
810
+ }
811
+ }
812
+ }
813
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
814
+ finally {
815
+ try {
816
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
817
+ }
818
+ finally { if (e_1) throw e_1.error; }
819
+ }
820
+ if (unit === undefined) {
821
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
822
+ }
823
+ return {
824
+ type: 'EXPECT_AMOUNT',
825
+ sign: sign,
826
+ unit: unit,
827
+ amount: amount,
828
+ };
829
+ }
830
+ catch (error) {
831
+ if (!(error instanceof Error)) {
832
+ throw error;
833
+ }
834
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
835
+ }
836
+ /*
837
+ } else if (type.startsWith('__________________')) {
838
+ // <- [🥻] Insert here when making new command
839
+ */
840
+ }
841
+ else {
842
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\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 ")));
843
+ }
844
+ }
845
+
846
+ /**
847
+ * Parse promptbook from string format to JSON format
848
+ *
849
+ * Note: This function does not validate logic of the pipeline only the syntax
850
+ */
851
+ function promptbookStringToJson(promptbookString) {
852
+ var e_1, _a, e_2, _b;
853
+ var promptbookJson = {
854
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
855
+ title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
856
+ promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
857
+ promptbookVersion: PROMPTBOOK_VERSION,
858
+ description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
859
+ parameters: [],
860
+ promptTemplates: [],
861
+ };
862
+ // =============================================================
863
+ // Note: 1️⃣ Normalization of the PROMPTBOOK string
864
+ promptbookString = removeContentComments(promptbookString);
865
+ promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
866
+ promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
867
+ // =============================================================
868
+ ///Note: 2️⃣ Function for adding parameters
869
+ var addParam = function (parameterCommand) {
870
+ var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
871
+ var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
872
+ if (existingParameter &&
873
+ existingParameter.description &&
874
+ existingParameter.description !== parameterDescription &&
875
+ parameterDescription) {
876
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](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 "); }));
877
+ }
878
+ if (existingParameter) {
879
+ if (parameterDescription) {
880
+ existingParameter.description = parameterDescription;
881
+ }
882
+ }
883
+ else {
884
+ promptbookJson.parameters.push({
885
+ name: parameterName,
886
+ description: parameterDescription || undefined,
887
+ isInput: isInput,
888
+ isOutput: isOutput,
889
+ });
890
+ }
891
+ };
892
+ // =============================================================
893
+ // Note: 3️⃣ Parse the dynamic part - the template pipeline
894
+ var markdownStructure = markdownToMarkdownStructure(promptbookString);
895
+ var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
896
+ if (markdownStructureDeepness !== 2) {
897
+ throw new PromptbookSyntaxError(spaceTrim__default["default"]("\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 ")));
898
+ }
899
+ promptbookJson.title = markdownStructure.title;
900
+ // TODO: [1] DRY description
901
+ var description = markdownStructure.content;
902
+ // Note: Remove codeblocks
903
+ description = description.split(/^```.*^```/gms).join('');
904
+ //Note: Remove lists and return statement
905
+ description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
906
+ description = spaceTrim__default["default"](description);
907
+ if (description === '') {
908
+ description = undefined;
909
+ }
910
+ promptbookJson.description = description;
911
+ var defaultModelRequirements = {};
912
+ var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
913
+ try {
914
+ for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
915
+ var listItem = listItems_1_1.value;
916
+ var command = parseCommand(listItem);
917
+ switch (command.type) {
918
+ case 'PROMPTBOOK_URL':
919
+ promptbookJson.promptbookUrl = command.promptbookUrl.href;
920
+ break;
921
+ case 'PROMPTBOOK_VERSION':
922
+ promptbookJson.promptbookVersion = command.promptbookVersion;
923
+ break;
924
+ case 'MODEL':
925
+ defaultModelRequirements[command.key] = command.value;
926
+ break;
927
+ case 'PARAMETER':
928
+ addParam(command);
929
+ break;
930
+ default:
931
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
932
+ }
933
+ }
934
+ }
935
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
936
+ finally {
937
+ try {
938
+ if (listItems_1_1 && !listItems_1_1.done && (_a = listItems_1.return)) _a.call(listItems_1);
939
+ }
940
+ finally { if (e_1) throw e_1.error; }
941
+ }
942
+ var _loop_1 = function (section) {
943
+ var e_3, _e, e_4, _f, e_5, _g;
944
+ // TODO: Parse prompt template description (the content out of the codeblock and lists)
945
+ var templateModelRequirements = __assign({}, defaultModelRequirements);
946
+ var listItems_3 = extractAllListItemsFromMarkdown(section.content);
947
+ var dependentParameterNames = [];
948
+ var executionType = 'PROMPT_TEMPLATE';
949
+ var jokers = [];
950
+ var postprocessing = [];
951
+ var expectAmount = {};
952
+ var expectFormat = undefined;
953
+ var isExecutionTypeChanged = false;
954
+ try {
955
+ for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
956
+ var listItem = listItems_2_1.value;
957
+ var command = parseCommand(listItem);
958
+ switch (command.type) {
959
+ case 'JOKER':
960
+ jokers.push(command.parameterName);
961
+ dependentParameterNames.push(command.parameterName);
962
+ break;
963
+ case 'EXECUTE':
964
+ if (isExecutionTypeChanged) {
965
+ throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
966
+ }
967
+ executionType = command.executionType;
968
+ isExecutionTypeChanged = true;
969
+ break;
970
+ case 'MODEL':
971
+ templateModelRequirements[command.key] = command.value;
972
+ break;
973
+ case 'PARAMETER':
974
+ // Note: This is just for detecting resulitng parameter name
975
+ addParam(command);
976
+ break;
977
+ case 'POSTPROCESS':
978
+ postprocessing.push(command.functionName);
979
+ break;
980
+ case 'EXPECT_AMOUNT':
981
+ // eslint-disable-next-line no-case-declarations
982
+ var unit = command.unit.toLowerCase();
983
+ expectAmount[unit] = expectAmount[unit] || {};
984
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
985
+ if (expectAmount[unit].min !== undefined) {
986
+ throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
987
+ }
988
+ expectAmount[unit].min = command.amount;
989
+ } /* not else */
990
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
991
+ if (expectAmount[unit].max !== undefined) {
992
+ throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
993
+ }
994
+ expectAmount[unit].max = command.amount;
995
+ }
996
+ break;
997
+ case 'EXPECT_FORMAT':
998
+ if (expectFormat !== undefined && command.format !== expectFormat) {
999
+ throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
1000
+ }
1001
+ expectFormat = command.format;
1002
+ break;
1003
+ default:
1004
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
1005
+ }
1006
+ }
1007
+ }
1008
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1009
+ finally {
1010
+ try {
1011
+ if (listItems_2_1 && !listItems_2_1.done && (_e = listItems_2.return)) _e.call(listItems_2);
1012
+ }
1013
+ finally { if (e_3) throw e_3.error; }
1014
+ }
1015
+ var _h = extractOneBlockFromMarkdown(section.content), language = _h.language, content = _h.content;
1016
+ if (executionType === 'SCRIPT') {
1017
+ if (!language) {
1018
+ throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1019
+ }
1020
+ else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1021
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](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 "); }));
1022
+ }
1023
+ }
1024
+ var lastLine = section.content.split('\n').pop();
1025
+ var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1026
+ if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1027
+ throw new PromptbookSyntaxError(spaceTrim__default["default"](function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1028
+ // TODO: Show code of invalid sections each time + DRY
1029
+ section.content
1030
+ .split('\n')
1031
+ .map(function (line) { return "> ".concat(line); })
1032
+ .join('\n')), "\n "); }));
1033
+ }
1034
+ var resultingParameterName = match.groups.resultingParamName;
1035
+ // TODO: [1] DRY description
1036
+ var description_1 = section.content;
1037
+ // Note: Remove codeblocks
1038
+ description_1 = description_1.split(/^```.*^```/gms).join('');
1039
+ //Note: Remove lists and return statement
1040
+ description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1041
+ description_1 = spaceTrim__default["default"](description_1);
1042
+ if (description_1 === '') {
1043
+ description_1 = undefined;
1044
+ }
1045
+ if (Object.keys(jokers).length === 0) {
1046
+ jokers = undefined;
1047
+ }
1048
+ if (Object.keys(expectAmount).length === 0) {
1049
+ expectAmount = undefined;
1050
+ }
1051
+ if (Object.keys(postprocessing).length === 0) {
1052
+ postprocessing = undefined;
1053
+ }
1054
+ try {
1055
+ for (var _j = (e_4 = void 0, __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(section.title)), false), __read(extractParameters(description_1 || '')), false), __read(extractParameters(content)), false))), _k = _j.next(); !_k.done; _k = _j.next()) {
1056
+ var parameterName = _k.value;
1057
+ dependentParameterNames.push(parameterName);
1058
+ }
1059
+ }
1060
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1061
+ finally {
1062
+ try {
1063
+ if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
1064
+ }
1065
+ finally { if (e_4) throw e_4.error; }
1066
+ }
1067
+ if (executionType === 'SCRIPT') {
1068
+ try {
1069
+ for (var _l = (e_5 = void 0, __values(extractVariables(content))), _m = _l.next(); !_m.done; _m = _l.next()) {
1070
+ var parameterName = _m.value;
1071
+ dependentParameterNames.push(parameterName);
1072
+ }
1073
+ }
1074
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1075
+ finally {
1076
+ try {
1077
+ if (_m && !_m.done && (_g = _l.return)) _g.call(_l);
1078
+ }
1079
+ finally { if (e_5) throw e_5.error; }
1080
+ }
1081
+ }
1082
+ dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
1083
+ promptbookJson.promptTemplates.push({
1084
+ name: n12.normalizeTo_PascalCase(section.title),
1085
+ title: section.title,
1086
+ description: description_1,
1087
+ dependentParameterNames: dependentParameterNames,
1088
+ executionType: executionType,
1089
+ jokers: jokers,
1090
+ postprocessing: postprocessing,
1091
+ expectAmount: expectAmount,
1092
+ expectFormat: expectFormat,
1093
+ modelRequirements: templateModelRequirements,
1094
+ contentLanguage: executionType === 'SCRIPT' ? language : undefined,
1095
+ content: content,
1096
+ resultingParameterName: resultingParameterName,
1097
+ });
1098
+ };
1099
+ try {
1100
+ for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
1101
+ var section = _d.value;
1102
+ _loop_1(section);
1103
+ }
1104
+ }
1105
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1106
+ finally {
1107
+ try {
1108
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1109
+ }
1110
+ finally { if (e_2) throw e_2.error; }
1111
+ }
1112
+ // =============================================================
1113
+ return promptbookJson;
1114
+ }
1115
+ /**
1116
+ * TODO: Report here line/column of error
1117
+ * TODO: Use spaceTrim more effectively
1118
+ * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1119
+ */
1120
+
1121
+ /**
1122
+ * Add or modify an auto-generated section in a markdown file
1123
+ *
1124
+ * @private within the library
1125
+ */
1126
+ function addAutoGeneratedSection(content, options) {
1127
+ var sectionName = options.sectionName, sectionContent = options.sectionContent;
1128
+ var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
1129
+ var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
1130
+ var sectionMatch = content.match(sectionRegex);
1131
+ if (sectionMatch) {
1132
+ return content.replace(sectionRegex, spaceTrim__default["default"](function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
1133
+ }
1134
+ var placeForSection = removeContentComments(content).match(/^##.*$/im);
1135
+ if (!placeForSection) {
1136
+ throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
1137
+ }
1138
+ var _a = __read(placeForSection, 1), heading = _a[0];
1139
+ return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
1140
+ }
1141
+
1142
+ /**
1143
+ * Prettify the html code
1144
+ *
1145
+ * @param html raw html code
1146
+ * @returns formatted html code
1147
+ */
1148
+ function prettifyMarkdown(html) {
1149
+ try {
1150
+ return prettier.format(html, {
1151
+ parser: 'markdown',
1152
+ plugins: [parserHtml__default["default"]],
1153
+ // TODO: DRY - make some import or auto-copy of .prettierrc
1154
+ endOfLine: 'lf',
1155
+ tabWidth: 4,
1156
+ singleQuote: true,
1157
+ trailingComma: 'all',
1158
+ arrowParens: 'always',
1159
+ printWidth: 120,
1160
+ htmlWhitespaceSensitivity: 'ignore',
1161
+ jsxBracketSameLine: false,
1162
+ bracketSpacing: true,
1163
+ });
1164
+ }
1165
+ catch (error) {
1166
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1167
+ error: error,
1168
+ html: html,
1169
+ });
1170
+ return html;
1171
+ }
1172
+ }
1173
+
1174
+ /**
1175
+ * !!!
1176
+ */
1177
+ function prettifyPromptbookString(promptbookString, options) {
1178
+ var isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
1179
+ if (isGraphAdded) {
1180
+ var promptbookJson_1 = promptbookStringToJson(promptbookString);
1181
+ var parameterNameToTemplateName_1 = function (parameterName) {
1182
+ var parameter = promptbookJson_1.parameters.find(function (parameter) { return parameter.name === parameterName; });
1183
+ if (!parameter) {
1184
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
1185
+ }
1186
+ if (parameter.isInput) {
1187
+ return 'input';
1188
+ }
1189
+ var template = promptbookJson_1.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
1190
+ if (!template) {
1191
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
1192
+ }
1193
+ return 'template' + n12.normalizeTo_PascalCase(template.title);
1194
+ };
1195
+ var promptbookMermaid_1 = spaceTrim__default["default"](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_1.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson_1.promptTemplates
1196
+ .flatMap(function (_a) {
1197
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1198
+ return __spreadArray([
1199
+ "".concat(parameterNameToTemplateName_1(resultingParameterName), "(\"").concat(title, "\")")
1200
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
1201
+ return "".concat(parameterNameToTemplateName_1(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName_1(resultingParameterName));
1202
+ })), false);
1203
+ })
1204
+ .join('\n')), "\n\n ").concat(block(promptbookJson_1.parameters
1205
+ .filter(function (_a) {
1206
+ var isOutput = _a.isOutput;
1207
+ return isOutput;
1208
+ })
1209
+ .map(function (_a) {
1210
+ var name = _a.name;
1211
+ return "".concat(parameterNameToTemplateName_1(name), "--\"{").concat(name, "}\"-->output");
1212
+ })
1213
+ .join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n\n\n "); });
1214
+ var promptbookMermaidBlock = spaceTrim__default["default"](function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1215
+ promptbookString = addAutoGeneratedSection(promptbookString, {
1216
+ sectionName: 'Graph',
1217
+ sectionContent: promptbookMermaidBlock,
1218
+ });
1219
+ }
1220
+ if (isPrettifyed) {
1221
+ promptbookString = prettifyMarkdown(promptbookString);
1222
+ }
1223
+ return promptbookString;
1224
+ }
1225
+ /**
1226
+ * TODO: Maybe use some Mermaid library instead of string templating
1227
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
1228
+ */
1229
+
1230
+ /**
1231
+ * !!! Initialize
1232
+ */
1233
+ function prettifyPromptbookStringCli() {
1234
+ return __awaiter(this, void 0, void 0, function () {
1235
+ var program, prettifyCommand, helloCommand;
1236
+ var _this = this;
1237
+ return __generator(this, function (_a) {
1238
+ if (!isRunningInNode()) {
1239
+ throw new Error(spaceTrim__default["default"]("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
1240
+ }
1241
+ program = new commander__default["default"].Command();
1242
+ program.name('promptbook');
1243
+ program.version(PROMPTBOOK_VERSION);
1244
+ program.description(spaceTrim__default["default"]("\n Promptbook utilities\n "));
1245
+ prettifyCommand = program.command('prettify');
1246
+ prettifyCommand.description(spaceTrim__default["default"]("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
1247
+ prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
1248
+ prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
1249
+ prettifyCommand.action(function (filesGlob, _a) {
1250
+ var ignore = _a.ignore;
1251
+ return __awaiter(_this, void 0, void 0, function () {
1252
+ var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
1253
+ var e_1, _b;
1254
+ return __generator(this, function (_c) {
1255
+ switch (_c.label) {
1256
+ case 0: return [4 /*yield*/, glob__default["default"](filesGlob, { ignore: ignore })];
1257
+ case 1:
1258
+ filePaths = _c.sent();
1259
+ _c.label = 2;
1260
+ case 2:
1261
+ _c.trys.push([2, 10, 11, 12]);
1262
+ filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
1263
+ _c.label = 3;
1264
+ case 3:
1265
+ if (!!filePaths_1_1.done) return [3 /*break*/, 9];
1266
+ filePath = filePaths_1_1.value;
1267
+ if (!filePath.endsWith('.ptbk.md')) {
1268
+ console.warn(colors__default["default"].yellow("Skipping prettify of non-promptbook ".concat(filePath)));
1269
+ return [3 /*break*/, 8];
1270
+ }
1271
+ return [4 /*yield*/, promises.readFile(filePath, 'utf-8')];
1272
+ case 4:
1273
+ promptbookMarkdown = (_c.sent());
1274
+ _c.label = 5;
1275
+ case 5:
1276
+ _c.trys.push([5, 7, , 8]);
1277
+ promptbookMarkdown = prettifyPromptbookString(promptbookMarkdown, {
1278
+ isGraphAdded: true,
1279
+ isPrettifyed: true,
1280
+ // <- [🕌]
1281
+ });
1282
+ return [4 /*yield*/, promises.writeFile(filePath, promptbookMarkdown)];
1283
+ case 6:
1284
+ _c.sent();
1285
+ console.info(colors__default["default"].green("Prettify ".concat(filePath)));
1286
+ return [3 /*break*/, 8];
1287
+ case 7:
1288
+ error_1 = _c.sent();
1289
+ if (!(error_1 instanceof Error)) {
1290
+ throw error_1;
1291
+ }
1292
+ console.info(colors__default["default"].red("Prettify ".concat(error_1.name, " ").concat(filePath)));
1293
+ console.error(colors__default["default"].bgRed(error_1.name));
1294
+ console.error(error_1);
1295
+ process.exit(1);
1296
+ return [3 /*break*/, 8];
1297
+ case 8:
1298
+ filePaths_1_1 = filePaths_1.next();
1299
+ return [3 /*break*/, 3];
1300
+ case 9: return [3 /*break*/, 12];
1301
+ case 10:
1302
+ e_1_1 = _c.sent();
1303
+ e_1 = { error: e_1_1 };
1304
+ return [3 /*break*/, 12];
1305
+ case 11:
1306
+ try {
1307
+ if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
1308
+ }
1309
+ finally { if (e_1) throw e_1.error; }
1310
+ return [7 /*endfinally*/];
1311
+ case 12:
1312
+ process.exit(0);
1313
+ return [2 /*return*/];
1314
+ }
1315
+ });
1316
+ });
1317
+ });
1318
+ helloCommand = program.command('hello');
1319
+ helloCommand.description(spaceTrim__default["default"]("\n Just command for testing\n "));
1320
+ helloCommand.argument('<name>', 'Your name');
1321
+ helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
1322
+ helloCommand.action(function (name, _a) {
1323
+ var greeting = _a.greeting;
1324
+ return __awaiter(_this, void 0, void 0, function () {
1325
+ return __generator(this, function (_b) {
1326
+ switch (_b.label) {
1327
+ case 0:
1328
+ console.info(colors__default["default"].cyan("".concat(greeting, " ").concat(name)));
1329
+ return [4 /*yield*/, waitasecond.forTime(1000)];
1330
+ case 1:
1331
+ _b.sent();
1332
+ console.info(colors__default["default"].rainbow("Nice to meet you!"));
1333
+ process.exit(0);
1334
+ return [2 /*return*/];
1335
+ }
1336
+ });
1337
+ });
1338
+ });
1339
+ //------
1340
+ program.parse(process.argv);
1341
+ return [2 /*return*/];
1342
+ });
1343
+ });
1344
+ }
1345
+ /**
1346
+ * TODO: [🥠] Do not export to utils directly, its just for CLI script
1347
+ * TODO: [🕌] When more functionalities, rename
1348
+ * Note: 11:11
1349
+ */
1350
+
1351
+ /**
1352
+ * Hidden utilities which should not be used by external consumers.
1353
+ */
1354
+ var __ = {
1355
+ // Note: [🥠]
1356
+ prettifyPromptbookStringCli: prettifyPromptbookStringCli,
1357
+ };
1358
+
1359
+ exports.__ = __;
1360
+
1361
+ Object.defineProperty(exports, '__esModule', { value: true });
1362
+
1363
+ }));
1364
+ //# sourceMappingURL=index.umd.js.map