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