@promptbook/node 0.56.0-3

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 (534) hide show
  1. package/README.md +706 -0
  2. package/esm/index.es.js +2491 -0
  3. package/esm/index.es.js.map +1 -0
  4. package/esm/typings/_packages/anthropic-claude.index.d.ts +5 -0
  5. package/esm/typings/_packages/azure-openai.index.d.ts +5 -0
  6. package/esm/typings/_packages/cli.index.d.ts +10 -0
  7. package/esm/typings/_packages/core.index.d.ts +41 -0
  8. package/esm/typings/_packages/execute-javascript.index.d.ts +48 -0
  9. package/esm/typings/_packages/fake-llm.index.d.ts +7 -0
  10. package/esm/typings/_packages/langtail.index.d.ts +5 -0
  11. package/esm/typings/_packages/node.index.d.ts +4 -0
  12. package/esm/typings/_packages/openai.index.d.ts +6 -0
  13. package/esm/typings/_packages/remote-client.index.d.ts +6 -0
  14. package/esm/typings/_packages/remote-server.index.d.ts +5 -0
  15. package/esm/typings/_packages/types.index.d.ts +28 -0
  16. package/esm/typings/_packages/utils.index.d.ts +71 -0
  17. package/esm/typings/config.d.ts +8 -0
  18. package/esm/typings/conversion/prettify/PrettifyOptions.d.ts +13 -0
  19. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +10 -0
  20. package/esm/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +9 -0
  21. package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +25 -0
  22. package/esm/typings/conversion/promptbookJsonToString.d.ts +12 -0
  23. package/esm/typings/conversion/promptbookStringToJson.d.ts +15 -0
  24. package/esm/typings/conversion/promptbookStringToJson.test.d.ts +1 -0
  25. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  26. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  27. package/esm/typings/conversion/utils/extractVariables.d.ts +13 -0
  28. package/esm/typings/conversion/utils/extractVariables.test.d.ts +1 -0
  29. package/esm/typings/conversion/utils/parseCommand.d.ts +11 -0
  30. package/esm/typings/conversion/utils/parseCommand.test.d.ts +4 -0
  31. package/esm/typings/conversion/utils/parseNumber.d.ts +15 -0
  32. package/esm/typings/conversion/utils/parseNumber.test.d.ts +1 -0
  33. package/esm/typings/conversion/utils/renameParameter.d.ts +25 -0
  34. package/esm/typings/conversion/utils/renameParameter.test.d.ts +1 -0
  35. package/esm/typings/conversion/utils/titleToName.d.ts +4 -0
  36. package/esm/typings/conversion/utils/titleToName.test.d.ts +1 -0
  37. package/esm/typings/conversion/validation/_importPromptbook.d.ts +13 -0
  38. package/esm/typings/conversion/validation/promptbookStringToJson-syntaxErrors.test.d.ts +1 -0
  39. package/esm/typings/conversion/validation/validatePromptbookJson-logicErrors.test.d.ts +1 -0
  40. package/esm/typings/conversion/validation/validatePromptbookJson.d.ts +27 -0
  41. package/esm/typings/conversion/validation/validatePromptbookJson.test.d.ts +1 -0
  42. package/esm/typings/errors/PromptbookExecutionError.d.ts +7 -0
  43. package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
  44. package/esm/typings/errors/PromptbookLogicError.d.ts +7 -0
  45. package/esm/typings/errors/PromptbookNotFoundError.d.ts +7 -0
  46. package/esm/typings/errors/PromptbookReferenceError.d.ts +7 -0
  47. package/esm/typings/errors/PromptbookSyntaxError.d.ts +7 -0
  48. package/esm/typings/errors/TemplateError.d.ts +9 -0
  49. package/esm/typings/errors/UnexpectedError.d.ts +7 -0
  50. package/esm/typings/errors/_ExpectError.d.ts +10 -0
  51. package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +9 -0
  52. package/esm/typings/execution/ExecutionTools.d.ts +32 -0
  53. package/esm/typings/execution/LlmExecutionTools.d.ts +50 -0
  54. package/esm/typings/execution/PromptResult.d.ts +103 -0
  55. package/esm/typings/execution/PromptbookExecutor.d.ts +42 -0
  56. package/esm/typings/execution/ScriptExecutionTools.d.ts +38 -0
  57. package/esm/typings/execution/UserInterfaceTools.d.ts +46 -0
  58. package/esm/typings/execution/addPromptResultUsage.test.d.ts +1 -0
  59. package/esm/typings/execution/assertsExecutionSuccessful.d.ts +11 -0
  60. package/esm/typings/execution/createPromptbookExecutor.d.ts +42 -0
  61. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +43 -0
  62. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +8 -0
  63. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +20 -0
  64. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/playground/playground.d.ts +2 -0
  65. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +42 -0
  66. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +35 -0
  67. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/playground/playground.d.ts +2 -0
  68. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +7 -0
  69. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
  70. package/esm/typings/execution/plugins/llm-execution-tools/langtail/playground/playground.d.ts +2 -0
  71. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +28 -0
  72. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +25 -0
  73. package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +14 -0
  74. package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.test.d.ts +1 -0
  75. package/esm/typings/execution/plugins/llm-execution-tools/mocked/faked-completion.test.d.ts +1 -0
  76. package/esm/typings/execution/plugins/llm-execution-tools/mocked/joker.test.d.ts +4 -0
  77. package/esm/typings/execution/plugins/llm-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  78. package/esm/typings/execution/plugins/llm-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  79. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +37 -0
  80. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +24 -0
  81. package/esm/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
  82. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +47 -0
  83. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +18 -0
  84. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +12 -0
  85. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +16 -0
  86. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
  87. package/esm/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +26 -0
  88. package/esm/typings/execution/plugins/llm-execution-tools/openai/playground/playground.d.ts +2 -0
  89. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +42 -0
  90. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +24 -0
  91. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -0
  92. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -0
  93. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -0
  94. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -0
  95. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +28 -0
  96. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +18 -0
  97. package/esm/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -0
  98. package/esm/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -0
  99. package/esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -0
  100. package/esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -0
  101. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -0
  102. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  103. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +7 -0
  104. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +26 -0
  105. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  106. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
  107. package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -0
  108. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +16 -0
  109. package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  110. package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  111. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +16 -0
  112. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +15 -0
  113. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  114. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +17 -0
  115. package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  116. package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -0
  117. package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -0
  118. package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -0
  119. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -0
  120. package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
  121. package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +7 -0
  122. package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
  123. package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -0
  124. package/esm/typings/execution/utils/addUsage.d.ts +7 -0
  125. package/esm/typings/execution/utils/addUsage.test.d.ts +1 -0
  126. package/esm/typings/execution/utils/checkExpectations.d.ts +25 -0
  127. package/esm/typings/execution/utils/checkExpectations.test.d.ts +1 -0
  128. package/esm/typings/execution/utils/computeUsageCounts.d.ts +10 -0
  129. package/esm/typings/execution/utils/forEachAsync.d.ts +18 -0
  130. package/esm/typings/execution/utils/replaceParameters.d.ts +13 -0
  131. package/esm/typings/execution/utils/replaceParameters.test.d.ts +1 -0
  132. package/esm/typings/execution/utils/uncertainNumber.d.ts +9 -0
  133. package/esm/typings/execution/utils/usageToWorktime.d.ts +10 -0
  134. package/esm/typings/execution/utils/usageToWorktime.test.d.ts +1 -0
  135. package/esm/typings/library/PromptbookLibrary.d.ts +25 -0
  136. package/esm/typings/library/SimplePromptbookLibrary.d.ts +36 -0
  137. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +43 -0
  138. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  139. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +23 -0
  140. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  141. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +13 -0
  142. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  143. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +26 -0
  144. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +12 -0
  145. package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
  146. package/esm/typings/types/Command.d.ts +101 -0
  147. package/esm/typings/types/ExecutionTypes.d.ts +13 -0
  148. package/esm/typings/types/ModelRequirements.d.ts +43 -0
  149. package/esm/typings/types/Parameters.d.ts +14 -0
  150. package/esm/typings/types/Prompt.d.ts +57 -0
  151. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +145 -0
  152. package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +26 -0
  153. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +53 -0
  154. package/esm/typings/types/PromptbookString.d.ts +12 -0
  155. package/esm/typings/types/ScriptLanguage.d.ts +9 -0
  156. package/esm/typings/types/TaskProgress.d.ts +43 -0
  157. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +58 -0
  158. package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  159. package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -0
  160. package/esm/typings/types/execution-report/config.d.ts +8 -0
  161. package/esm/typings/types/execution-report/countWorkingDuration.d.ts +7 -0
  162. package/esm/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -0
  163. package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +11 -0
  164. package/esm/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -0
  165. package/esm/typings/types/typeAliasEmoji.d.ts +9 -0
  166. package/esm/typings/types/typeAliases.d.ts +430 -0
  167. package/esm/typings/utils/FromtoItems.d.ts +19 -0
  168. package/esm/typings/utils/emojis.d.ts +22 -0
  169. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  170. package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  171. package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
  172. package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  173. package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
  174. package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  175. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  176. package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  177. package/esm/typings/utils/expectation-counters/countSentences.d.ts +9 -0
  178. package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  179. package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
  180. package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  181. package/esm/typings/utils/expectation-counters/index.d.ts +6 -0
  182. package/esm/typings/utils/extractParameters.d.ts +9 -0
  183. package/esm/typings/utils/extractParameters.test.d.ts +1 -0
  184. package/esm/typings/utils/formatNumber.d.ts +6 -0
  185. package/esm/typings/utils/formatNumber.test.d.ts +1 -0
  186. package/esm/typings/utils/getCurrentIsoDate.d.ts +7 -0
  187. package/esm/typings/utils/isRunningInWhatever.d.ts +12 -0
  188. package/esm/typings/utils/isValidJsonString.d.ts +4 -0
  189. package/esm/typings/utils/isValidJsonString.test.d.ts +1 -0
  190. package/esm/typings/utils/just.d.ts +10 -0
  191. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +11 -0
  192. package/esm/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  193. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +41 -0
  194. package/esm/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -0
  195. package/esm/typings/utils/markdown/createMarkdownTable.d.ts +8 -0
  196. package/esm/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -0
  197. package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -0
  198. package/esm/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
  199. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -0
  200. package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
  201. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +14 -0
  202. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  203. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -0
  204. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  205. package/esm/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
  206. package/esm/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
  207. package/esm/typings/utils/markdown/removeContentComments.d.ts +9 -0
  208. package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  209. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  210. package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  211. package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  212. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  213. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  214. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  215. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  216. package/esm/typings/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +10 -0
  217. package/esm/typings/utils/normalization/IKeywords.d.ts +18 -0
  218. package/esm/typings/utils/normalization/capitalize.d.ts +5 -0
  219. package/esm/typings/utils/normalization/capitalize.test.d.ts +1 -0
  220. package/esm/typings/utils/normalization/decapitalize.d.ts +5 -0
  221. package/esm/typings/utils/normalization/decapitalize.test.d.ts +1 -0
  222. package/esm/typings/utils/normalization/isValidKeyword.d.ts +8 -0
  223. package/esm/typings/utils/normalization/isValidKeyword.test.d.ts +1 -0
  224. package/esm/typings/utils/normalization/nameToUriPart.d.ts +1 -0
  225. package/esm/typings/utils/normalization/nameToUriPart.test.d.ts +1 -0
  226. package/esm/typings/utils/normalization/nameToUriParts.d.ts +1 -0
  227. package/esm/typings/utils/normalization/nameToUriParts.test.d.ts +1 -0
  228. package/esm/typings/utils/normalization/normalize-to-kebab-case.d.ts +1 -0
  229. package/esm/typings/utils/normalization/normalize-to-kebab-case.test.d.ts +1 -0
  230. package/esm/typings/utils/normalization/normalizeTo_PascalCase.d.ts +1 -0
  231. package/esm/typings/utils/normalization/normalizeTo_PascalCase.test.d.ts +1 -0
  232. package/esm/typings/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +4 -0
  233. package/esm/typings/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +1 -0
  234. package/esm/typings/utils/normalization/normalizeTo_camelCase.d.ts +4 -0
  235. package/esm/typings/utils/normalization/normalizeTo_camelCase.test.d.ts +1 -0
  236. package/esm/typings/utils/normalization/normalizeTo_snake_case.d.ts +1 -0
  237. package/esm/typings/utils/normalization/normalizeTo_snake_case.test.d.ts +1 -0
  238. package/esm/typings/utils/normalization/normalizeWhitespaces.d.ts +4 -0
  239. package/esm/typings/utils/normalization/normalizeWhitespaces.test.d.ts +1 -0
  240. package/esm/typings/utils/normalization/parseKeywords.d.ts +14 -0
  241. package/esm/typings/utils/normalization/parseKeywords.test.d.ts +1 -0
  242. package/esm/typings/utils/normalization/parseKeywordsFromString.d.ts +8 -0
  243. package/esm/typings/utils/normalization/parseKeywordsFromString.test.d.ts +1 -0
  244. package/esm/typings/utils/normalization/removeDiacritics.d.ts +4 -0
  245. package/esm/typings/utils/normalization/removeDiacritics.test.d.ts +1 -0
  246. package/esm/typings/utils/normalization/searchKeywords.d.ts +5 -0
  247. package/esm/typings/utils/normalization/searchKeywords.test.d.ts +1 -0
  248. package/esm/typings/utils/postprocessing/extractBlock.d.ts +12 -0
  249. package/esm/typings/utils/removeEmojis.d.ts +7 -0
  250. package/esm/typings/utils/removeEmojis.test.d.ts +1 -0
  251. package/esm/typings/utils/removeQuotes.d.ts +13 -0
  252. package/esm/typings/utils/removeQuotes.test.d.ts +1 -0
  253. package/esm/typings/utils/sets/difference.d.ts +4 -0
  254. package/esm/typings/utils/sets/difference.test.d.ts +1 -0
  255. package/esm/typings/utils/sets/intersection.d.ts +4 -0
  256. package/esm/typings/utils/sets/intersection.test.d.ts +1 -0
  257. package/esm/typings/utils/sets/union.d.ts +4 -0
  258. package/esm/typings/utils/sets/union.test.d.ts +1 -0
  259. package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
  260. package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
  261. package/esm/typings/utils/trimEndOfCodeBlock.d.ts +7 -0
  262. package/esm/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -0
  263. package/esm/typings/utils/unwrapResult.d.ts +36 -0
  264. package/esm/typings/utils/unwrapResult.test.d.ts +1 -0
  265. package/esm/typings/utils/validators/url/isValidUrl.d.ts +7 -0
  266. package/esm/typings/utils/validators/url/isValidUrl.test.d.ts +1 -0
  267. package/esm/typings/version.d.ts +5 -0
  268. package/package.json +56 -0
  269. package/umd/index.umd.js +2501 -0
  270. package/umd/index.umd.js.map +1 -0
  271. package/umd/typings/_packages/anthropic-claude.index.d.ts +5 -0
  272. package/umd/typings/_packages/azure-openai.index.d.ts +5 -0
  273. package/umd/typings/_packages/cli.index.d.ts +10 -0
  274. package/umd/typings/_packages/core.index.d.ts +41 -0
  275. package/umd/typings/_packages/execute-javascript.index.d.ts +48 -0
  276. package/umd/typings/_packages/fake-llm.index.d.ts +7 -0
  277. package/umd/typings/_packages/langtail.index.d.ts +5 -0
  278. package/umd/typings/_packages/node.index.d.ts +4 -0
  279. package/umd/typings/_packages/openai.index.d.ts +6 -0
  280. package/umd/typings/_packages/remote-client.index.d.ts +6 -0
  281. package/umd/typings/_packages/remote-server.index.d.ts +5 -0
  282. package/umd/typings/_packages/types.index.d.ts +28 -0
  283. package/umd/typings/_packages/utils.index.d.ts +71 -0
  284. package/umd/typings/config.d.ts +8 -0
  285. package/umd/typings/conversion/prettify/PrettifyOptions.d.ts +13 -0
  286. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +10 -0
  287. package/umd/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +9 -0
  288. package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +25 -0
  289. package/umd/typings/conversion/promptbookJsonToString.d.ts +12 -0
  290. package/umd/typings/conversion/promptbookStringToJson.d.ts +15 -0
  291. package/umd/typings/conversion/promptbookStringToJson.test.d.ts +1 -0
  292. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +13 -0
  293. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.test.d.ts +1 -0
  294. package/umd/typings/conversion/utils/extractVariables.d.ts +13 -0
  295. package/umd/typings/conversion/utils/extractVariables.test.d.ts +1 -0
  296. package/umd/typings/conversion/utils/parseCommand.d.ts +11 -0
  297. package/umd/typings/conversion/utils/parseCommand.test.d.ts +4 -0
  298. package/umd/typings/conversion/utils/parseNumber.d.ts +15 -0
  299. package/umd/typings/conversion/utils/parseNumber.test.d.ts +1 -0
  300. package/umd/typings/conversion/utils/renameParameter.d.ts +25 -0
  301. package/umd/typings/conversion/utils/renameParameter.test.d.ts +1 -0
  302. package/umd/typings/conversion/utils/titleToName.d.ts +4 -0
  303. package/umd/typings/conversion/utils/titleToName.test.d.ts +1 -0
  304. package/umd/typings/conversion/validation/_importPromptbook.d.ts +13 -0
  305. package/umd/typings/conversion/validation/promptbookStringToJson-syntaxErrors.test.d.ts +1 -0
  306. package/umd/typings/conversion/validation/validatePromptbookJson-logicErrors.test.d.ts +1 -0
  307. package/umd/typings/conversion/validation/validatePromptbookJson.d.ts +27 -0
  308. package/umd/typings/conversion/validation/validatePromptbookJson.test.d.ts +1 -0
  309. package/umd/typings/errors/PromptbookExecutionError.d.ts +7 -0
  310. package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
  311. package/umd/typings/errors/PromptbookLogicError.d.ts +7 -0
  312. package/umd/typings/errors/PromptbookNotFoundError.d.ts +7 -0
  313. package/umd/typings/errors/PromptbookReferenceError.d.ts +7 -0
  314. package/umd/typings/errors/PromptbookSyntaxError.d.ts +7 -0
  315. package/umd/typings/errors/TemplateError.d.ts +9 -0
  316. package/umd/typings/errors/UnexpectedError.d.ts +7 -0
  317. package/umd/typings/errors/_ExpectError.d.ts +10 -0
  318. package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +9 -0
  319. package/umd/typings/execution/ExecutionTools.d.ts +32 -0
  320. package/umd/typings/execution/LlmExecutionTools.d.ts +50 -0
  321. package/umd/typings/execution/PromptResult.d.ts +103 -0
  322. package/umd/typings/execution/PromptbookExecutor.d.ts +42 -0
  323. package/umd/typings/execution/ScriptExecutionTools.d.ts +38 -0
  324. package/umd/typings/execution/UserInterfaceTools.d.ts +46 -0
  325. package/umd/typings/execution/addPromptResultUsage.test.d.ts +1 -0
  326. package/umd/typings/execution/assertsExecutionSuccessful.d.ts +11 -0
  327. package/umd/typings/execution/createPromptbookExecutor.d.ts +42 -0
  328. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +43 -0
  329. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +8 -0
  330. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +20 -0
  331. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/playground/playground.d.ts +2 -0
  332. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +42 -0
  333. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +35 -0
  334. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/playground/playground.d.ts +2 -0
  335. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +7 -0
  336. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionToolsOptions.d.ts +11 -0
  337. package/umd/typings/execution/plugins/llm-execution-tools/langtail/playground/playground.d.ts +2 -0
  338. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +28 -0
  339. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +25 -0
  340. package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +14 -0
  341. package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.test.d.ts +1 -0
  342. package/umd/typings/execution/plugins/llm-execution-tools/mocked/faked-completion.test.d.ts +1 -0
  343. package/umd/typings/execution/plugins/llm-execution-tools/mocked/joker.test.d.ts +4 -0
  344. package/umd/typings/execution/plugins/llm-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  345. package/umd/typings/execution/plugins/llm-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  346. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +37 -0
  347. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +24 -0
  348. package/umd/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
  349. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +47 -0
  350. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +18 -0
  351. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +12 -0
  352. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.d.ts +16 -0
  353. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts +1 -0
  354. package/umd/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +26 -0
  355. package/umd/typings/execution/plugins/llm-execution-tools/openai/playground/playground.d.ts +2 -0
  356. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +42 -0
  357. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +24 -0
  358. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -0
  359. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -0
  360. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -0
  361. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -0
  362. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +28 -0
  363. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +18 -0
  364. package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -0
  365. package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -0
  366. package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -0
  367. package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -0
  368. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -0
  369. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  370. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +7 -0
  371. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +26 -0
  372. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  373. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/unknownToString.d.ts +7 -0
  374. package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -0
  375. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +16 -0
  376. package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  377. package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  378. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +16 -0
  379. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +15 -0
  380. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  381. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +17 -0
  382. package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  383. package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -0
  384. package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -0
  385. package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -0
  386. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -0
  387. package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
  388. package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +7 -0
  389. package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
  390. package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -0
  391. package/umd/typings/execution/utils/addUsage.d.ts +7 -0
  392. package/umd/typings/execution/utils/addUsage.test.d.ts +1 -0
  393. package/umd/typings/execution/utils/checkExpectations.d.ts +25 -0
  394. package/umd/typings/execution/utils/checkExpectations.test.d.ts +1 -0
  395. package/umd/typings/execution/utils/computeUsageCounts.d.ts +10 -0
  396. package/umd/typings/execution/utils/forEachAsync.d.ts +18 -0
  397. package/umd/typings/execution/utils/replaceParameters.d.ts +13 -0
  398. package/umd/typings/execution/utils/replaceParameters.test.d.ts +1 -0
  399. package/umd/typings/execution/utils/uncertainNumber.d.ts +9 -0
  400. package/umd/typings/execution/utils/usageToWorktime.d.ts +10 -0
  401. package/umd/typings/execution/utils/usageToWorktime.test.d.ts +1 -0
  402. package/umd/typings/library/PromptbookLibrary.d.ts +25 -0
  403. package/umd/typings/library/SimplePromptbookLibrary.d.ts +36 -0
  404. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +43 -0
  405. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  406. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +23 -0
  407. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  408. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +13 -0
  409. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  410. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +26 -0
  411. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +12 -0
  412. package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
  413. package/umd/typings/types/Command.d.ts +101 -0
  414. package/umd/typings/types/ExecutionTypes.d.ts +13 -0
  415. package/umd/typings/types/ModelRequirements.d.ts +43 -0
  416. package/umd/typings/types/Parameters.d.ts +14 -0
  417. package/umd/typings/types/Prompt.d.ts +57 -0
  418. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +145 -0
  419. package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +26 -0
  420. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +53 -0
  421. package/umd/typings/types/PromptbookString.d.ts +12 -0
  422. package/umd/typings/types/ScriptLanguage.d.ts +9 -0
  423. package/umd/typings/types/TaskProgress.d.ts +43 -0
  424. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +58 -0
  425. package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  426. package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -0
  427. package/umd/typings/types/execution-report/config.d.ts +8 -0
  428. package/umd/typings/types/execution-report/countWorkingDuration.d.ts +7 -0
  429. package/umd/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -0
  430. package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +11 -0
  431. package/umd/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -0
  432. package/umd/typings/types/typeAliasEmoji.d.ts +9 -0
  433. package/umd/typings/types/typeAliases.d.ts +430 -0
  434. package/umd/typings/utils/FromtoItems.d.ts +19 -0
  435. package/umd/typings/utils/emojis.d.ts +22 -0
  436. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  437. package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  438. package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
  439. package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  440. package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
  441. package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  442. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  443. package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  444. package/umd/typings/utils/expectation-counters/countSentences.d.ts +9 -0
  445. package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  446. package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
  447. package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  448. package/umd/typings/utils/expectation-counters/index.d.ts +6 -0
  449. package/umd/typings/utils/extractParameters.d.ts +9 -0
  450. package/umd/typings/utils/extractParameters.test.d.ts +1 -0
  451. package/umd/typings/utils/formatNumber.d.ts +6 -0
  452. package/umd/typings/utils/formatNumber.test.d.ts +1 -0
  453. package/umd/typings/utils/getCurrentIsoDate.d.ts +7 -0
  454. package/umd/typings/utils/isRunningInWhatever.d.ts +12 -0
  455. package/umd/typings/utils/isValidJsonString.d.ts +4 -0
  456. package/umd/typings/utils/isValidJsonString.test.d.ts +1 -0
  457. package/umd/typings/utils/just.d.ts +10 -0
  458. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +11 -0
  459. package/umd/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  460. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +41 -0
  461. package/umd/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -0
  462. package/umd/typings/utils/markdown/createMarkdownTable.d.ts +8 -0
  463. package/umd/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -0
  464. package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -0
  465. package/umd/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
  466. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -0
  467. package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
  468. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +14 -0
  469. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  470. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -0
  471. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  472. package/umd/typings/utils/markdown/prettifyMarkdown.d.ts +8 -0
  473. package/umd/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
  474. package/umd/typings/utils/markdown/removeContentComments.d.ts +9 -0
  475. package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  476. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  477. package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  478. package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  479. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  480. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  481. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  482. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  483. package/umd/typings/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +10 -0
  484. package/umd/typings/utils/normalization/IKeywords.d.ts +18 -0
  485. package/umd/typings/utils/normalization/capitalize.d.ts +5 -0
  486. package/umd/typings/utils/normalization/capitalize.test.d.ts +1 -0
  487. package/umd/typings/utils/normalization/decapitalize.d.ts +5 -0
  488. package/umd/typings/utils/normalization/decapitalize.test.d.ts +1 -0
  489. package/umd/typings/utils/normalization/isValidKeyword.d.ts +8 -0
  490. package/umd/typings/utils/normalization/isValidKeyword.test.d.ts +1 -0
  491. package/umd/typings/utils/normalization/nameToUriPart.d.ts +1 -0
  492. package/umd/typings/utils/normalization/nameToUriPart.test.d.ts +1 -0
  493. package/umd/typings/utils/normalization/nameToUriParts.d.ts +1 -0
  494. package/umd/typings/utils/normalization/nameToUriParts.test.d.ts +1 -0
  495. package/umd/typings/utils/normalization/normalize-to-kebab-case.d.ts +1 -0
  496. package/umd/typings/utils/normalization/normalize-to-kebab-case.test.d.ts +1 -0
  497. package/umd/typings/utils/normalization/normalizeTo_PascalCase.d.ts +1 -0
  498. package/umd/typings/utils/normalization/normalizeTo_PascalCase.test.d.ts +1 -0
  499. package/umd/typings/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +4 -0
  500. package/umd/typings/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +1 -0
  501. package/umd/typings/utils/normalization/normalizeTo_camelCase.d.ts +4 -0
  502. package/umd/typings/utils/normalization/normalizeTo_camelCase.test.d.ts +1 -0
  503. package/umd/typings/utils/normalization/normalizeTo_snake_case.d.ts +1 -0
  504. package/umd/typings/utils/normalization/normalizeTo_snake_case.test.d.ts +1 -0
  505. package/umd/typings/utils/normalization/normalizeWhitespaces.d.ts +4 -0
  506. package/umd/typings/utils/normalization/normalizeWhitespaces.test.d.ts +1 -0
  507. package/umd/typings/utils/normalization/parseKeywords.d.ts +14 -0
  508. package/umd/typings/utils/normalization/parseKeywords.test.d.ts +1 -0
  509. package/umd/typings/utils/normalization/parseKeywordsFromString.d.ts +8 -0
  510. package/umd/typings/utils/normalization/parseKeywordsFromString.test.d.ts +1 -0
  511. package/umd/typings/utils/normalization/removeDiacritics.d.ts +4 -0
  512. package/umd/typings/utils/normalization/removeDiacritics.test.d.ts +1 -0
  513. package/umd/typings/utils/normalization/searchKeywords.d.ts +5 -0
  514. package/umd/typings/utils/normalization/searchKeywords.test.d.ts +1 -0
  515. package/umd/typings/utils/postprocessing/extractBlock.d.ts +12 -0
  516. package/umd/typings/utils/removeEmojis.d.ts +7 -0
  517. package/umd/typings/utils/removeEmojis.test.d.ts +1 -0
  518. package/umd/typings/utils/removeQuotes.d.ts +13 -0
  519. package/umd/typings/utils/removeQuotes.test.d.ts +1 -0
  520. package/umd/typings/utils/sets/difference.d.ts +4 -0
  521. package/umd/typings/utils/sets/difference.test.d.ts +1 -0
  522. package/umd/typings/utils/sets/intersection.d.ts +4 -0
  523. package/umd/typings/utils/sets/intersection.test.d.ts +1 -0
  524. package/umd/typings/utils/sets/union.d.ts +4 -0
  525. package/umd/typings/utils/sets/union.test.d.ts +1 -0
  526. package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
  527. package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
  528. package/umd/typings/utils/trimEndOfCodeBlock.d.ts +7 -0
  529. package/umd/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -0
  530. package/umd/typings/utils/unwrapResult.d.ts +36 -0
  531. package/umd/typings/utils/unwrapResult.test.d.ts +1 -0
  532. package/umd/typings/utils/validators/url/isValidUrl.d.ts +7 -0
  533. package/umd/typings/utils/validators/url/isValidUrl.test.d.ts +1 -0
  534. package/umd/typings/version.d.ts +5 -0
@@ -0,0 +1,2501 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml));
5
+ })(this, (function (exports, promises, path, spaceTrim, prettier, parserHtml) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
10
+ var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
11
+
12
+ /*! *****************************************************************************
13
+ Copyright (c) Microsoft Corporation.
14
+
15
+ Permission to use, copy, modify, and/or distribute this software for any
16
+ purpose with or without fee is hereby granted.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
+ PERFORMANCE OF THIS SOFTWARE.
25
+ ***************************************************************************** */
26
+ /* global Reflect, Promise */
27
+
28
+ var extendStatics = function(d, b) {
29
+ extendStatics = Object.setPrototypeOf ||
30
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
32
+ return extendStatics(d, b);
33
+ };
34
+
35
+ function __extends(d, b) {
36
+ if (typeof b !== "function" && b !== null)
37
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
38
+ extendStatics(d, b);
39
+ function __() { this.constructor = d; }
40
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41
+ }
42
+
43
+ var __assign = function() {
44
+ __assign = Object.assign || function __assign(t) {
45
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
46
+ s = arguments[i];
47
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48
+ }
49
+ return t;
50
+ };
51
+ return __assign.apply(this, arguments);
52
+ };
53
+
54
+ function __awaiter(thisArg, _arguments, P, generator) {
55
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
56
+ return new (P || (P = Promise))(function (resolve, reject) {
57
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
58
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
59
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
60
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
61
+ });
62
+ }
63
+
64
+ function __generator(thisArg, body) {
65
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
66
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
67
+ function verb(n) { return function (v) { return step([n, v]); }; }
68
+ function step(op) {
69
+ if (f) throw new TypeError("Generator is already executing.");
70
+ while (_) try {
71
+ 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;
72
+ if (y = 0, t) op = [op[0] & 2, t.value];
73
+ switch (op[0]) {
74
+ case 0: case 1: t = op; break;
75
+ case 4: _.label++; return { value: op[1], done: false };
76
+ case 5: _.label++; y = op[1]; op = [0]; continue;
77
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
78
+ default:
79
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
80
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
81
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
82
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
83
+ if (t[2]) _.ops.pop();
84
+ _.trys.pop(); continue;
85
+ }
86
+ op = body.call(thisArg, _);
87
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
88
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
89
+ }
90
+ }
91
+
92
+ function __values(o) {
93
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
94
+ if (m) return m.call(o);
95
+ if (o && typeof o.length === "number") return {
96
+ next: function () {
97
+ if (o && i >= o.length) o = void 0;
98
+ return { value: o && o[i++], done: !o };
99
+ }
100
+ };
101
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
102
+ }
103
+
104
+ function __read(o, n) {
105
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
106
+ if (!m) return o;
107
+ var i = m.call(o), r, ar = [], e;
108
+ try {
109
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
110
+ }
111
+ catch (error) { e = { error: error }; }
112
+ finally {
113
+ try {
114
+ if (r && !r.done && (m = i["return"])) m.call(i);
115
+ }
116
+ finally { if (e) throw e.error; }
117
+ }
118
+ return ar;
119
+ }
120
+
121
+ function __spreadArray(to, from, pack) {
122
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
123
+ if (ar || !(i in from)) {
124
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
125
+ ar[i] = from[i];
126
+ }
127
+ }
128
+ return to.concat(ar || Array.prototype.slice.call(from));
129
+ }
130
+
131
+ /**
132
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
133
+ */
134
+ var PromptbookSyntaxError = /** @class */ (function (_super) {
135
+ __extends(PromptbookSyntaxError, _super);
136
+ function PromptbookSyntaxError(message) {
137
+ var _this = _super.call(this, message) || this;
138
+ _this.name = 'PromptbookSyntaxError';
139
+ Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
140
+ return _this;
141
+ }
142
+ return PromptbookSyntaxError;
143
+ }(Error));
144
+
145
+ /**
146
+ * Supported script languages
147
+ */
148
+ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
149
+
150
+ /**
151
+ * Computes the deepness of the markdown structure.
152
+ *
153
+ * @private within the library
154
+ */
155
+ function countMarkdownStructureDeepness(markdownStructure) {
156
+ var e_1, _a;
157
+ var maxDeepness = 0;
158
+ try {
159
+ for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
160
+ var section = _c.value;
161
+ maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
162
+ }
163
+ }
164
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
165
+ finally {
166
+ try {
167
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
168
+ }
169
+ finally { if (e_1) throw e_1.error; }
170
+ }
171
+ return maxDeepness + 1;
172
+ }
173
+
174
+ /**
175
+ * The maximum number of iterations for a loops
176
+ */
177
+ var LOOP_LIMIT = 1000;
178
+
179
+ /**
180
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
181
+ */
182
+ var UnexpectedError = /** @class */ (function (_super) {
183
+ __extends(UnexpectedError, _super);
184
+ function UnexpectedError(message) {
185
+ var _this = _super.call(this, spaceTrim.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;
186
+ _this.name = 'UnexpectedError';
187
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
188
+ return _this;
189
+ }
190
+ return UnexpectedError;
191
+ }(Error));
192
+
193
+ /**
194
+ * Parse a markdown string into a MarkdownStructure object.
195
+ *
196
+ * Note: This function does work with code blocks
197
+ * Note: This function does not work with markdown comments
198
+ *
199
+ * @param markdown The markdown string to parse.
200
+ * @returns The MarkdownStructure object.
201
+ *
202
+ * @private within the library
203
+ */
204
+ function markdownToMarkdownStructure(markdown) {
205
+ var e_1, _a;
206
+ var lines = markdown.split('\n');
207
+ var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
208
+ var current = root;
209
+ var isInsideCodeBlock = false;
210
+ try {
211
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
212
+ var line = lines_1_1.value;
213
+ var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
214
+ if (isInsideCodeBlock || !headingMatch) {
215
+ if (line.startsWith('```')) {
216
+ isInsideCodeBlock = !isInsideCodeBlock;
217
+ }
218
+ current.contentLines.push(line);
219
+ }
220
+ else {
221
+ var level = headingMatch.groups.mark.length;
222
+ var title = headingMatch.groups.title.trim();
223
+ var parent_1 = void 0;
224
+ if (level > current.level) {
225
+ // Note: Going deeper (next section is child of current)
226
+ parent_1 = current;
227
+ }
228
+ else {
229
+ // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
230
+ parent_1 = current;
231
+ var loopLimit = LOOP_LIMIT;
232
+ while (parent_1.level !== level - 1) {
233
+ if (loopLimit-- < 0) {
234
+ throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
235
+ }
236
+ if (parent_1.parent === null /* <- Note: We are in root */) {
237
+ // [🌻]
238
+ throw new Error(spaceTrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
239
+ }
240
+ parent_1 = parent_1.parent;
241
+ }
242
+ }
243
+ var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
244
+ parent_1.sections.push(section);
245
+ current = section;
246
+ }
247
+ }
248
+ }
249
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
250
+ finally {
251
+ try {
252
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
253
+ }
254
+ finally { if (e_1) throw e_1.error; }
255
+ }
256
+ if (root.sections.length === 1) {
257
+ var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
258
+ return markdownStructure;
259
+ }
260
+ // [🌻]
261
+ throw new Error('The markdown file must have exactly one top-level section.');
262
+ // return root;
263
+ }
264
+ /**
265
+ * @private
266
+ */
267
+ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
268
+ var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
269
+ return {
270
+ level: level,
271
+ title: title,
272
+ content: spaceTrim.spaceTrim(contentLines.join('\n')),
273
+ sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
274
+ };
275
+ }
276
+
277
+ /**
278
+ * Utility function to extract all list items from markdown
279
+ *
280
+ * Note: It works with both ul and ol
281
+ * Note: It omits list items in code blocks
282
+ * Note: It flattens nested lists
283
+ * Note: It can not work with html syntax and comments
284
+ *
285
+ * @param markdown any valid markdown
286
+ * @returns
287
+ */
288
+ function extractAllListItemsFromMarkdown(markdown) {
289
+ var e_1, _a;
290
+ var lines = markdown.split('\n');
291
+ var listItems = [];
292
+ var isInCodeBlock = false;
293
+ try {
294
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
295
+ var line = lines_1_1.value;
296
+ var trimmedLine = line.trim();
297
+ if (trimmedLine.startsWith('```')) {
298
+ isInCodeBlock = !isInCodeBlock;
299
+ }
300
+ if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
301
+ var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
302
+ listItems.push(listItem);
303
+ }
304
+ }
305
+ }
306
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
307
+ finally {
308
+ try {
309
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
310
+ }
311
+ finally { if (e_1) throw e_1.error; }
312
+ }
313
+ return listItems;
314
+ }
315
+
316
+ /**
317
+ * Makes first letter of a string uppercase
318
+ *
319
+ */
320
+ function capitalize(word) {
321
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
322
+ }
323
+
324
+ /**
325
+ * Extracts all code blocks from markdown.
326
+ *
327
+ * Note: There are 3 simmilar function:
328
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
329
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
330
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
331
+ *
332
+ * @param markdown any valid markdown
333
+ * @returns code blocks with language and content
334
+ *
335
+ */
336
+ function extractAllBlocksFromMarkdown(markdown) {
337
+ var e_1, _a;
338
+ var codeBlocks = [];
339
+ var lines = markdown.split('\n');
340
+ var currentCodeBlock = null;
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
+ if (line.startsWith('```')) {
345
+ var language = line.slice(3).trim() || null;
346
+ if (currentCodeBlock === null) {
347
+ currentCodeBlock = { language: language, content: '' };
348
+ }
349
+ else {
350
+ if (language !== null) {
351
+ // [🌻]
352
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
353
+ }
354
+ codeBlocks.push(currentCodeBlock);
355
+ currentCodeBlock = null;
356
+ }
357
+ }
358
+ else if (currentCodeBlock !== null) {
359
+ if (currentCodeBlock.content !== '') {
360
+ currentCodeBlock.content += '\n';
361
+ }
362
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
363
+ }
364
+ }
365
+ }
366
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
367
+ finally {
368
+ try {
369
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
370
+ }
371
+ finally { if (e_1) throw e_1.error; }
372
+ }
373
+ if (currentCodeBlock !== null) {
374
+ // [🌻]
375
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
376
+ }
377
+ return codeBlocks;
378
+ }
379
+
380
+ /**
381
+ * Extracts exactly ONE code block from markdown.
382
+ *
383
+ * Note: If there are multiple or no code blocks the function throws an error
384
+ *
385
+ * Note: There are 3 simmilar function:
386
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
387
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
388
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
389
+ *
390
+ * @param markdown any valid markdown
391
+ * @returns code block with language and content
392
+ */
393
+ function extractOneBlockFromMarkdown(markdown) {
394
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
395
+ if (codeBlocks.length !== 1) {
396
+ // TODO: Report more specific place where the error happened
397
+ throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
398
+ }
399
+ return codeBlocks[0];
400
+ }
401
+ /***
402
+ * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
403
+ */
404
+
405
+ /**
406
+ * Removes HTML or Markdown comments from a string.
407
+ *
408
+ * @param {string} content - The string to remove comments from.
409
+ * @returns {string} The input string with all comments removed.
410
+ */
411
+ function removeContentComments(content) {
412
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
413
+ }
414
+
415
+ /**
416
+ * Creates a new set with all elements that are present in either set
417
+ */
418
+ function union() {
419
+ var e_1, _a, e_2, _b;
420
+ var sets = [];
421
+ for (var _i = 0; _i < arguments.length; _i++) {
422
+ sets[_i] = arguments[_i];
423
+ }
424
+ var union = new Set();
425
+ try {
426
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
427
+ var set = sets_1_1.value;
428
+ try {
429
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
430
+ var item = _d.value;
431
+ union.add(item);
432
+ }
433
+ }
434
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
435
+ finally {
436
+ try {
437
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
438
+ }
439
+ finally { if (e_2) throw e_2.error; }
440
+ }
441
+ }
442
+ }
443
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
444
+ finally {
445
+ try {
446
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
447
+ }
448
+ finally { if (e_1) throw e_1.error; }
449
+ }
450
+ return union;
451
+ }
452
+
453
+ /**
454
+ * The version of the Promptbook library
455
+ */
456
+ var PROMPTBOOK_VERSION = '0.56.0-2';
457
+
458
+ /**
459
+ * Parses the template and returns the list of all parameter names
460
+ *
461
+ * @param template the template with parameters in {curly} braces
462
+ * @returns the list of parameter names
463
+ */
464
+ function extractParameters(template) {
465
+ var e_1, _a;
466
+ var matches = template.matchAll(/{\w+}/g);
467
+ var parameterNames = new Set();
468
+ try {
469
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
470
+ var match = matches_1_1.value;
471
+ var parameterName = match[0].slice(1, -1);
472
+ parameterNames.add(parameterName);
473
+ }
474
+ }
475
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
476
+ finally {
477
+ try {
478
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
479
+ }
480
+ finally { if (e_1) throw e_1.error; }
481
+ }
482
+ return parameterNames;
483
+ }
484
+
485
+ /**
486
+ * Parses the given script and returns the list of all used variables that are not defined in the script
487
+ *
488
+ * @param script from which to extract the variables
489
+ * @returns the list of variable names
490
+ * @throws {PromptbookSyntaxError} if the script is invalid
491
+ */
492
+ function extractVariables(script) {
493
+ var variables = new Set();
494
+ script = "(()=>{".concat(script, "})()");
495
+ try {
496
+ for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
497
+ try {
498
+ eval(script);
499
+ }
500
+ catch (error) {
501
+ if (!(error instanceof ReferenceError)) {
502
+ throw error;
503
+ }
504
+ var undefinedName = error.message.split(' ')[0];
505
+ /*
506
+ Note: Remapping error
507
+ From: [ReferenceError: thing is not defined],
508
+ To: [Error: Parameter {thing} is not defined],
509
+ */
510
+ if (!undefinedName) {
511
+ throw error;
512
+ }
513
+ if (script.includes(undefinedName + '(')) {
514
+ script = "const ".concat(undefinedName, " = ()=>'';") + script;
515
+ }
516
+ else {
517
+ variables.add(undefinedName);
518
+ script = "const ".concat(undefinedName, " = '';") + script;
519
+ }
520
+ }
521
+ }
522
+ catch (error) {
523
+ if (!(error instanceof Error)) {
524
+ throw error;
525
+ }
526
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
527
+ }
528
+ return variables;
529
+ }
530
+ /**
531
+ * TODO: [🔣] Support for multiple languages - python, java,...
532
+ */
533
+
534
+ /**
535
+ * Parses the prompt template and returns the set of all used parameters
536
+ *
537
+ * @param promptTemplate the template with used parameters
538
+ * @returns the set of parameter names
539
+ * @throws {PromptbookSyntaxError} if the script is invalid
540
+ */
541
+ function extractParametersFromPromptTemplate(promptTemplate) {
542
+ var e_1, _a, e_2, _b;
543
+ var parameterNames = new Set();
544
+ try {
545
+ for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
546
+ var parameterName = _d.value;
547
+ parameterNames.add(parameterName);
548
+ }
549
+ }
550
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
551
+ finally {
552
+ try {
553
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
554
+ }
555
+ finally { if (e_1) throw e_1.error; }
556
+ }
557
+ if (promptTemplate.executionType === 'SCRIPT') {
558
+ try {
559
+ for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
560
+ var parameterName = _f.value;
561
+ parameterNames.add(parameterName);
562
+ }
563
+ }
564
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
565
+ finally {
566
+ try {
567
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
568
+ }
569
+ finally { if (e_2) throw e_2.error; }
570
+ }
571
+ }
572
+ return parameterNames;
573
+ }
574
+ /**
575
+ * TODO: [🔣] If script require contentLanguage
576
+ */
577
+
578
+ /* tslint:disable */
579
+ /*
580
+ TODO: Tests
581
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
582
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
583
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
584
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
585
+ */
586
+ function normalizeTo_SCREAMING_CASE(sentence) {
587
+ var e_1, _a;
588
+ var charType;
589
+ var lastCharType = 'OTHER';
590
+ var normalizedName = '';
591
+ try {
592
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
593
+ var char = sentence_1_1.value;
594
+ var normalizedChar = void 0;
595
+ if (/^[a-z]$/.test(char)) {
596
+ charType = 'LOWERCASE';
597
+ normalizedChar = char.toUpperCase();
598
+ }
599
+ else if (/^[A-Z]$/.test(char)) {
600
+ charType = 'UPPERCASE';
601
+ normalizedChar = char;
602
+ }
603
+ else if (/^[0-9]$/.test(char)) {
604
+ charType = 'NUMBER';
605
+ normalizedChar = char;
606
+ }
607
+ else if (/^\/$/.test(char)) {
608
+ charType = 'SLASH';
609
+ normalizedChar = char;
610
+ }
611
+ else {
612
+ charType = 'OTHER';
613
+ normalizedChar = '_';
614
+ }
615
+ if (charType !== lastCharType &&
616
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
617
+ !(lastCharType === 'NUMBER') &&
618
+ !(charType === 'NUMBER')) {
619
+ normalizedName += '_';
620
+ }
621
+ normalizedName += normalizedChar;
622
+ lastCharType = charType;
623
+ }
624
+ }
625
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
626
+ finally {
627
+ try {
628
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
629
+ }
630
+ finally { if (e_1) throw e_1.error; }
631
+ }
632
+ normalizedName = normalizedName.replace(/_+/g, '_');
633
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
634
+ normalizedName = normalizedName.replace(/^_/, '');
635
+ normalizedName = normalizedName.replace(/_$/, '');
636
+ return normalizedName;
637
+ }
638
+ /**
639
+ * TODO: [🌺] Use some intermediate util splitWords
640
+ */
641
+
642
+ /**
643
+ * Execution type describes the way how the block is executed
644
+ *
645
+ * @see https://github.com/webgptorg/promptbook#execution-type
646
+ */
647
+ var ExecutionTypes = [
648
+ 'PROMPT_TEMPLATE',
649
+ 'SIMPLE_TEMPLATE',
650
+ 'SCRIPT',
651
+ 'PROMPT_DIALOG',
652
+ // <- [🥻] Insert here when making new command
653
+ ];
654
+
655
+ /**
656
+ * Units of text measurement
657
+ */
658
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
659
+ /**
660
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
661
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
662
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
663
+ */
664
+
665
+ /**
666
+ * Removes Markdown formatting tags from a string.
667
+ *
668
+ * @param {string} str - The string to remove Markdown tags from.
669
+ * @returns {string} The input string with all Markdown tags removed.
670
+ */
671
+ function removeMarkdownFormatting(str) {
672
+ // Remove bold formatting
673
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
674
+ // Remove italic formatting
675
+ str = str.replace(/\*(.*?)\*/g, '$1');
676
+ // Remove code formatting
677
+ str = str.replace(/`(.*?)`/g, '$1');
678
+ return str;
679
+ }
680
+
681
+ /**
682
+ * Function parseNumber will parse number from string
683
+ *
684
+ * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
685
+ * Note: it also works only with decimal numbers
686
+ *
687
+ * @returns parsed number
688
+ * @throws {PromptbookSyntaxError} if the value is not a number
689
+ *
690
+ * @private within the parseCommand
691
+ */
692
+ function parseNumber(value) {
693
+ var originalValue = value;
694
+ if (typeof value === 'number') {
695
+ value = value.toString(); // <- TODO: Maybe more efficient way to do this
696
+ }
697
+ if (typeof value !== 'string') {
698
+ return 0;
699
+ }
700
+ value = value.trim();
701
+ if (value.startsWith('+')) {
702
+ return parseNumber(value.substring(1));
703
+ }
704
+ if (value.startsWith('-')) {
705
+ var number = parseNumber(value.substring(1));
706
+ if (number === 0) {
707
+ return 0; // <- Note: To prevent -0
708
+ }
709
+ return -number;
710
+ }
711
+ value = value.replace(/,/g, '.');
712
+ value = value.toUpperCase();
713
+ if (value === '') {
714
+ return 0;
715
+ }
716
+ if (value === '♾' || value.startsWith('INF')) {
717
+ return Infinity;
718
+ }
719
+ if (value.includes('/')) {
720
+ var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
721
+ var numerator = parseNumber(numerator_);
722
+ var denominator = parseNumber(denominator_);
723
+ if (denominator === 0) {
724
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
725
+ }
726
+ return numerator / denominator;
727
+ }
728
+ if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
729
+ return 0;
730
+ }
731
+ if (value.includes('E')) {
732
+ var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
733
+ return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
734
+ }
735
+ if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
736
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
737
+ }
738
+ var num = parseFloat(value);
739
+ if (isNaN(num)) {
740
+ throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
741
+ }
742
+ return num;
743
+ }
744
+ /**
745
+ * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
746
+ */
747
+
748
+ /**
749
+ * Parses one line of ul/ol to command
750
+ *
751
+ * @returns parsed command object
752
+ * @throws {PromptbookSyntaxError} if the command is invalid
753
+ *
754
+ * @private within the promptbookStringToJson
755
+ */
756
+ function parseCommand(listItem) {
757
+ var e_1, _a;
758
+ if (listItem.includes('\n') || listItem.includes('\r')) {
759
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
760
+ }
761
+ var type = listItem.trim();
762
+ type = type.split('`').join('');
763
+ type = type.split('"').join('');
764
+ type = type.split("'").join('');
765
+ type = type.split('~').join('');
766
+ type = type.split('[').join('');
767
+ type = type.split(']').join('');
768
+ type = type.split('(').join('');
769
+ type = type.split(')').join('');
770
+ type = normalizeTo_SCREAMING_CASE(type);
771
+ type = type.split('DIALOGUE').join('DIALOG');
772
+ var listItemParts = listItem
773
+ .split(' ')
774
+ .map(function (part) { return part.trim(); })
775
+ .filter(function (item) { return item !== ''; })
776
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
777
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
778
+ .map(removeMarkdownFormatting);
779
+ if (type.startsWith('URL') ||
780
+ type.startsWith('PTBK_URL') ||
781
+ type.startsWith('PTBKURL') ||
782
+ type.startsWith('PROMPTBOOK_URL') ||
783
+ type.startsWith('PROMPTBOOKURL') ||
784
+ type.startsWith('HTTPS')) {
785
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
786
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
787
+ }
788
+ var promptbookUrlString = listItemParts.pop();
789
+ var promptbookUrl = new URL(promptbookUrlString);
790
+ if (promptbookUrl.protocol !== 'https:') {
791
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
792
+ }
793
+ if (promptbookUrl.hash !== '') {
794
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
795
+ }
796
+ return {
797
+ type: 'PROMPTBOOK_URL',
798
+ promptbookUrl: promptbookUrl,
799
+ };
800
+ }
801
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
802
+ if (listItemParts.length !== 2) {
803
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
804
+ }
805
+ var promptbookVersion = listItemParts.pop();
806
+ // TODO: Validate version
807
+ return {
808
+ type: 'PROMPTBOOK_VERSION',
809
+ promptbookVersion: promptbookVersion,
810
+ };
811
+ }
812
+ else if (type.startsWith('EXECUTE') ||
813
+ type.startsWith('EXEC') ||
814
+ type.startsWith('PROMPT_DIALOG') ||
815
+ type.startsWith('SIMPLE_TEMPLATE')) {
816
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
817
+ if (executionTypes.length !== 1) {
818
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
819
+ }
820
+ return {
821
+ type: 'EXECUTE',
822
+ executionType: executionTypes[0],
823
+ };
824
+ }
825
+ else if (type.startsWith('MODEL')) {
826
+ // TODO: Make this more elegant and dynamically
827
+ if (type.startsWith('MODEL_VARIANT')) {
828
+ if (type === 'MODEL_VARIANT_CHAT') {
829
+ return {
830
+ type: 'MODEL',
831
+ key: 'modelVariant',
832
+ value: 'CHAT',
833
+ };
834
+ }
835
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
836
+ return {
837
+ type: 'MODEL',
838
+ key: 'modelVariant',
839
+ value: 'COMPLETION',
840
+ };
841
+ }
842
+ else {
843
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
844
+ }
845
+ }
846
+ if (type.startsWith('MODEL_NAME')) {
847
+ return {
848
+ type: 'MODEL',
849
+ key: 'modelName',
850
+ value: listItemParts.pop(),
851
+ };
852
+ }
853
+ else {
854
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
855
+ }
856
+ }
857
+ else if (type.startsWith('PARAM') ||
858
+ type.startsWith('INPUT_PARAM') ||
859
+ type.startsWith('OUTPUT_PARAM') ||
860
+ listItem.startsWith('{') ||
861
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
862
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
863
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
864
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
865
+ }
866
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
867
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
868
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
869
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
870
+ }
871
+ var isInput = type.startsWith('INPUT');
872
+ var isOutput = type.startsWith('OUTPUT');
873
+ if (listItem.startsWith('> {')) {
874
+ isInput = false;
875
+ isOutput = false;
876
+ }
877
+ return {
878
+ type: 'PARAMETER',
879
+ parameterName: parameterName,
880
+ parameterDescription: parameterDescription.trim() || null,
881
+ isInput: isInput,
882
+ isOutput: isOutput,
883
+ };
884
+ }
885
+ else if (type.startsWith('JOKER')) {
886
+ if (listItemParts.length !== 2) {
887
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
888
+ }
889
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
890
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
891
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
892
+ }
893
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
894
+ var parameterName = parametersMatch.groups.parameterName;
895
+ return {
896
+ type: 'JOKER',
897
+ parameterName: parameterName,
898
+ };
899
+ }
900
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
901
+ if (listItemParts.length !== 2) {
902
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
903
+ }
904
+ var functionName = listItemParts.pop();
905
+ return {
906
+ type: 'POSTPROCESS',
907
+ functionName: functionName,
908
+ };
909
+ }
910
+ else if (type.startsWith('EXPECT_JSON')) {
911
+ return {
912
+ type: 'EXPECT_FORMAT',
913
+ format: 'JSON',
914
+ };
915
+ // [🥤]
916
+ }
917
+ else if (type.startsWith('EXPECT')) {
918
+ try {
919
+ listItemParts.shift();
920
+ var sign = void 0;
921
+ var signRaw = listItemParts.shift();
922
+ if (/^exact/i.test(signRaw)) {
923
+ sign = 'EXACTLY';
924
+ }
925
+ else if (/^min/i.test(signRaw)) {
926
+ sign = 'MINIMUM';
927
+ }
928
+ else if (/^max/i.test(signRaw)) {
929
+ sign = 'MAXIMUM';
930
+ }
931
+ else {
932
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
933
+ }
934
+ var amountRaw = listItemParts.shift();
935
+ var amount = parseNumber(amountRaw);
936
+ if (amount < 0) {
937
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
938
+ }
939
+ if (amount !== Math.floor(amount)) {
940
+ throw new PromptbookSyntaxError('Amount must be whole number');
941
+ }
942
+ var unitRaw = listItemParts.shift();
943
+ var unit = undefined;
944
+ try {
945
+ 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()) {
946
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
947
+ var existingUnitText = existingUnit;
948
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
949
+ if (existingUnitText === 'CHARACTER') {
950
+ existingUnitText = 'CHAR';
951
+ }
952
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
953
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
954
+ if (unit !== undefined) {
955
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
956
+ }
957
+ unit = existingUnit;
958
+ }
959
+ }
960
+ }
961
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
962
+ finally {
963
+ try {
964
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
965
+ }
966
+ finally { if (e_1) throw e_1.error; }
967
+ }
968
+ if (unit === undefined) {
969
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
970
+ }
971
+ return {
972
+ type: 'EXPECT_AMOUNT',
973
+ sign: sign,
974
+ unit: unit,
975
+ amount: amount,
976
+ };
977
+ }
978
+ catch (error) {
979
+ if (!(error instanceof Error)) {
980
+ throw error;
981
+ }
982
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
983
+ }
984
+ /*
985
+ } else if (type.startsWith('__________________')) {
986
+ // <- [🥻] Insert here when making new command
987
+ */
988
+ }
989
+ else {
990
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
991
+ }
992
+ }
993
+
994
+ var defaultDiacriticsRemovalMap = [
995
+ {
996
+ base: 'A',
997
+ letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
998
+ },
999
+ { base: 'AA', letters: '\uA732' },
1000
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
1001
+ { base: 'AO', letters: '\uA734' },
1002
+ { base: 'AU', letters: '\uA736' },
1003
+ { base: 'AV', letters: '\uA738\uA73A' },
1004
+ { base: 'AY', letters: '\uA73C' },
1005
+ {
1006
+ base: 'B',
1007
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
1008
+ },
1009
+ {
1010
+ base: 'C',
1011
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
1012
+ },
1013
+ {
1014
+ base: 'D',
1015
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1016
+ },
1017
+ { base: 'DZ', letters: '\u01F1\u01C4' },
1018
+ { base: 'Dz', letters: '\u01F2\u01C5' },
1019
+ {
1020
+ base: 'E',
1021
+ letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
1022
+ },
1023
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1024
+ {
1025
+ base: 'G',
1026
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1027
+ },
1028
+ {
1029
+ base: 'H',
1030
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1031
+ },
1032
+ {
1033
+ base: 'I',
1034
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1035
+ },
1036
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1037
+ {
1038
+ base: 'K',
1039
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1040
+ },
1041
+ {
1042
+ base: 'L',
1043
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1044
+ },
1045
+ { base: 'LJ', letters: '\u01C7' },
1046
+ { base: 'Lj', letters: '\u01C8' },
1047
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1048
+ {
1049
+ base: 'N',
1050
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1051
+ },
1052
+ { base: 'NJ', letters: '\u01CA' },
1053
+ { base: 'Nj', letters: '\u01CB' },
1054
+ {
1055
+ base: 'O',
1056
+ letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
1057
+ },
1058
+ { base: 'OI', letters: '\u01A2' },
1059
+ { base: 'OO', letters: '\uA74E' },
1060
+ { base: 'OU', letters: '\u0222' },
1061
+ { base: 'OE', letters: '\u008C\u0152' },
1062
+ { base: 'oe', letters: '\u009C\u0153' },
1063
+ {
1064
+ base: 'P',
1065
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1066
+ },
1067
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1068
+ {
1069
+ base: 'R',
1070
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1071
+ },
1072
+ {
1073
+ base: 'S',
1074
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1075
+ },
1076
+ {
1077
+ base: 'T',
1078
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1079
+ },
1080
+ { base: 'TZ', letters: '\uA728' },
1081
+ {
1082
+ base: 'U',
1083
+ letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
1084
+ },
1085
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1086
+ { base: 'VY', letters: '\uA760' },
1087
+ {
1088
+ base: 'W',
1089
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
1090
+ },
1091
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
1092
+ {
1093
+ base: 'Y',
1094
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
1095
+ },
1096
+ {
1097
+ base: 'Z',
1098
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
1099
+ },
1100
+ {
1101
+ base: 'a',
1102
+ letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
1103
+ },
1104
+ { base: 'aa', letters: '\uA733' },
1105
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
1106
+ { base: 'ao', letters: '\uA735' },
1107
+ { base: 'au', letters: '\uA737' },
1108
+ { base: 'av', letters: '\uA739\uA73B' },
1109
+ { base: 'ay', letters: '\uA73D' },
1110
+ {
1111
+ base: 'b',
1112
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
1113
+ },
1114
+ {
1115
+ base: 'c',
1116
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
1117
+ },
1118
+ {
1119
+ base: 'd',
1120
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
1121
+ },
1122
+ { base: 'dz', letters: '\u01F3\u01C6' },
1123
+ {
1124
+ base: 'e',
1125
+ letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
1126
+ },
1127
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1128
+ {
1129
+ base: 'g',
1130
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1131
+ },
1132
+ {
1133
+ base: 'h',
1134
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1135
+ },
1136
+ { base: 'hv', letters: '\u0195' },
1137
+ {
1138
+ base: 'i',
1139
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1140
+ },
1141
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1142
+ {
1143
+ base: 'k',
1144
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1145
+ },
1146
+ {
1147
+ base: 'l',
1148
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1149
+ },
1150
+ { base: 'lj', letters: '\u01C9' },
1151
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1152
+ {
1153
+ base: 'n',
1154
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1155
+ },
1156
+ { base: 'nj', letters: '\u01CC' },
1157
+ {
1158
+ base: 'o',
1159
+ letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
1160
+ },
1161
+ { base: 'oi', letters: '\u01A3' },
1162
+ { base: 'ou', letters: '\u0223' },
1163
+ { base: 'oo', letters: '\uA74F' },
1164
+ {
1165
+ base: 'p',
1166
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1167
+ },
1168
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1169
+ {
1170
+ base: 'r',
1171
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1172
+ },
1173
+ {
1174
+ base: 's',
1175
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1176
+ },
1177
+ {
1178
+ base: 't',
1179
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1180
+ },
1181
+ { base: 'tz', letters: '\uA729' },
1182
+ {
1183
+ base: 'u',
1184
+ letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
1185
+ },
1186
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1187
+ { base: 'vy', letters: '\uA761' },
1188
+ {
1189
+ base: 'w',
1190
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1191
+ },
1192
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1193
+ {
1194
+ base: 'y',
1195
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1196
+ },
1197
+ {
1198
+ base: 'z',
1199
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1200
+ },
1201
+ ];
1202
+ /**
1203
+ * Map of letters from diacritic variant to diacritless variant
1204
+ * Contains lowercase and uppercase separatelly
1205
+ *
1206
+ * > "á" => "a"
1207
+ * > "ě" => "e"
1208
+ * > "Ă" => "A"
1209
+ * > ...
1210
+ */
1211
+ var DIACRITIC_VARIANTS_LETTERS = {};
1212
+ // tslint:disable-next-line: prefer-for-of
1213
+ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1214
+ var letters = defaultDiacriticsRemovalMap[i].letters;
1215
+ // tslint:disable-next-line: prefer-for-of
1216
+ for (var j = 0; j < letters.length; j++) {
1217
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1218
+ }
1219
+ }
1220
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
1221
+ /*
1222
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1223
+ Licensed under the Apache License, Version 2.0 (the "License");
1224
+ you may not use this file except in compliance with the License.
1225
+ You may obtain a copy of the License at
1226
+
1227
+ http://www.apache.org/licenses/LICENSE-2.0
1228
+
1229
+ Unless required by applicable law or agreed to in writing, software
1230
+ distributed under the License is distributed on an "AS IS" BASIS,
1231
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232
+ See the License for the specific language governing permissions and
1233
+ limitations under the License.
1234
+ */
1235
+
1236
+ /**
1237
+ *
1238
+ */
1239
+ function removeDiacritics(input) {
1240
+ /*eslint no-control-regex: "off"*/
1241
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
1242
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
1243
+ });
1244
+ }
1245
+
1246
+ /* tslint:disable */
1247
+ function normalizeToKebabCase(sentence) {
1248
+ var e_1, _a;
1249
+ sentence = removeDiacritics(sentence);
1250
+ var charType;
1251
+ var lastCharType = 'OTHER';
1252
+ var normalizedName = '';
1253
+ try {
1254
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1255
+ var char = sentence_1_1.value;
1256
+ var normalizedChar = void 0;
1257
+ if (/^[a-z]$/.test(char)) {
1258
+ charType = 'LOWERCASE';
1259
+ normalizedChar = char;
1260
+ }
1261
+ else if (/^[A-Z]$/.test(char)) {
1262
+ charType = 'UPPERCASE';
1263
+ normalizedChar = char.toLowerCase();
1264
+ }
1265
+ else if (/^[0-9]$/.test(char)) {
1266
+ charType = 'NUMBER';
1267
+ normalizedChar = char;
1268
+ }
1269
+ else if (/^\/$/.test(char)) {
1270
+ charType = 'SLASH';
1271
+ normalizedChar = char;
1272
+ }
1273
+ else {
1274
+ charType = 'OTHER';
1275
+ normalizedChar = '-';
1276
+ }
1277
+ if (charType !== lastCharType &&
1278
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1279
+ !(lastCharType === 'NUMBER') &&
1280
+ !(charType === 'NUMBER')) {
1281
+ normalizedName += '-';
1282
+ }
1283
+ normalizedName += normalizedChar;
1284
+ lastCharType = charType;
1285
+ }
1286
+ }
1287
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1288
+ finally {
1289
+ try {
1290
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1291
+ }
1292
+ finally { if (e_1) throw e_1.error; }
1293
+ }
1294
+ normalizedName = normalizedName.split(/-+/g).join('-');
1295
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1296
+ normalizedName = normalizedName.replace(/^-/, '');
1297
+ normalizedName = normalizedName.replace(/-$/, '');
1298
+ return normalizedName;
1299
+ }
1300
+
1301
+ /**
1302
+ * Removes emojis from a string and fix whitespaces
1303
+ *
1304
+ * @param text with emojis
1305
+ * @returns text without emojis
1306
+ */
1307
+ function removeEmojis(text) {
1308
+ // Replace emojis (and also ZWJ sequence) with hyphens
1309
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1310
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1311
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1312
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
1313
+ return text;
1314
+ }
1315
+
1316
+ /**
1317
+ * Function normalizes title to name which can be used as identifier
1318
+ */
1319
+ function titleToName(value) {
1320
+ value = removeEmojis(value);
1321
+ value = normalizeToKebabCase(value);
1322
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
1323
+ return value;
1324
+ }
1325
+
1326
+ /**
1327
+ * Parse promptbook from string format to JSON format
1328
+ *
1329
+ * @throws {PromptbookSyntaxError} if the promptbook string is not valid
1330
+ *
1331
+ * Note: This function does not validate logic of the pipeline only the syntax
1332
+ */
1333
+ function promptbookStringToJson(promptbookString) {
1334
+ var e_1, _a, e_2, _b;
1335
+ var promptbookJson = {
1336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1337
+ title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
1338
+ promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
1339
+ promptbookVersion: PROMPTBOOK_VERSION,
1340
+ description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
1341
+ parameters: [],
1342
+ promptTemplates: [],
1343
+ };
1344
+ // =============================================================
1345
+ // Note: 1️⃣ Normalization of the PROMPTBOOK string
1346
+ promptbookString = removeContentComments(promptbookString);
1347
+ promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
1348
+ promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
1349
+ // =============================================================
1350
+ ///Note: 2️⃣ Function for adding parameters
1351
+ var addParam = function (parameterCommand) {
1352
+ var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
1353
+ var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1354
+ if (existingParameter &&
1355
+ existingParameter.description &&
1356
+ existingParameter.description !== parameterDescription &&
1357
+ parameterDescription) {
1358
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
1359
+ }
1360
+ if (existingParameter) {
1361
+ if (parameterDescription) {
1362
+ existingParameter.description = parameterDescription;
1363
+ }
1364
+ }
1365
+ else {
1366
+ promptbookJson.parameters.push({
1367
+ name: parameterName,
1368
+ description: parameterDescription || undefined,
1369
+ isInput: isInput,
1370
+ isOutput: isOutput,
1371
+ });
1372
+ }
1373
+ };
1374
+ // =============================================================
1375
+ // Note: 3️⃣ Parse the dynamic part - the template pipeline
1376
+ var markdownStructure = markdownToMarkdownStructure(promptbookString);
1377
+ var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1378
+ if (markdownStructureDeepness !== 2) {
1379
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
1380
+ }
1381
+ promptbookJson.title = markdownStructure.title;
1382
+ // TODO: [1] DRY description
1383
+ var description = markdownStructure.content;
1384
+ // Note: Remove codeblocks
1385
+ description = description.split(/^```.*^```/gms).join('');
1386
+ //Note: Remove lists and return statement
1387
+ description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1388
+ description = spaceTrim.spaceTrim(description);
1389
+ if (description === '') {
1390
+ description = undefined;
1391
+ }
1392
+ promptbookJson.description = description;
1393
+ var defaultModelRequirements = {};
1394
+ var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
1395
+ try {
1396
+ for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
1397
+ var listItem = listItems_1_1.value;
1398
+ var command = parseCommand(listItem);
1399
+ switch (command.type) {
1400
+ case 'PROMPTBOOK_URL':
1401
+ promptbookJson.promptbookUrl = command.promptbookUrl.href;
1402
+ break;
1403
+ case 'PROMPTBOOK_VERSION':
1404
+ promptbookJson.promptbookVersion = command.promptbookVersion;
1405
+ break;
1406
+ case 'MODEL':
1407
+ defaultModelRequirements[command.key] = command.value;
1408
+ break;
1409
+ case 'PARAMETER':
1410
+ addParam(command);
1411
+ break;
1412
+ default:
1413
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
1414
+ }
1415
+ }
1416
+ }
1417
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1418
+ finally {
1419
+ try {
1420
+ if (listItems_1_1 && !listItems_1_1.done && (_a = listItems_1.return)) _a.call(listItems_1);
1421
+ }
1422
+ finally { if (e_1) throw e_1.error; }
1423
+ }
1424
+ var _loop_1 = function (section) {
1425
+ var e_3, _e;
1426
+ // TODO: Parse prompt template description (the content out of the codeblock and lists)
1427
+ var templateModelRequirements = __assign({}, defaultModelRequirements);
1428
+ var listItems_3 = extractAllListItemsFromMarkdown(section.content);
1429
+ var dependentParameterNames = new Set();
1430
+ var executionType = 'PROMPT_TEMPLATE';
1431
+ var jokers = [];
1432
+ var postprocessing = [];
1433
+ var expectAmount = {};
1434
+ var expectFormat = undefined;
1435
+ var isExecutionTypeChanged = false;
1436
+ try {
1437
+ 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()) {
1438
+ var listItem = listItems_2_1.value;
1439
+ var command = parseCommand(listItem);
1440
+ switch (command.type) {
1441
+ case 'JOKER':
1442
+ jokers.push(command.parameterName);
1443
+ dependentParameterNames.add(command.parameterName);
1444
+ break;
1445
+ case 'EXECUTE':
1446
+ if (isExecutionTypeChanged) {
1447
+ throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
1448
+ }
1449
+ executionType = command.executionType;
1450
+ isExecutionTypeChanged = true;
1451
+ break;
1452
+ case 'MODEL':
1453
+ templateModelRequirements[command.key] = command.value;
1454
+ break;
1455
+ case 'PARAMETER':
1456
+ // Note: This is just for detecting resulitng parameter name
1457
+ addParam(command);
1458
+ break;
1459
+ case 'POSTPROCESS':
1460
+ postprocessing.push(command.functionName);
1461
+ break;
1462
+ case 'EXPECT_AMOUNT':
1463
+ // eslint-disable-next-line no-case-declarations
1464
+ var unit = command.unit.toLowerCase();
1465
+ expectAmount[unit] = expectAmount[unit] || {};
1466
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
1467
+ if (expectAmount[unit].min !== undefined) {
1468
+ throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1469
+ }
1470
+ expectAmount[unit].min = command.amount;
1471
+ } /* not else */
1472
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
1473
+ if (expectAmount[unit].max !== undefined) {
1474
+ throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1475
+ }
1476
+ expectAmount[unit].max = command.amount;
1477
+ }
1478
+ break;
1479
+ case 'EXPECT_FORMAT':
1480
+ if (expectFormat !== undefined && command.format !== expectFormat) {
1481
+ throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
1482
+ }
1483
+ expectFormat = command.format;
1484
+ break;
1485
+ default:
1486
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
1487
+ }
1488
+ }
1489
+ }
1490
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1491
+ finally {
1492
+ try {
1493
+ if (listItems_2_1 && !listItems_2_1.done && (_e = listItems_2.return)) _e.call(listItems_2);
1494
+ }
1495
+ finally { if (e_3) throw e_3.error; }
1496
+ }
1497
+ var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
1498
+ if (executionType === 'SCRIPT') {
1499
+ if (!language) {
1500
+ throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1501
+ }
1502
+ else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1503
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
1504
+ }
1505
+ }
1506
+ var lastLine = section.content.split('\n').pop();
1507
+ var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1508
+ if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1509
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1510
+ // TODO: Show code of invalid sections each time + DRY
1511
+ section.content
1512
+ .split('\n')
1513
+ .map(function (line) { return "> ".concat(line); })
1514
+ .join('\n')), "\n "); }));
1515
+ }
1516
+ var resultingParameterName = match.groups.resultingParamName;
1517
+ // TODO: [1] DRY description
1518
+ var description_1 = section.content;
1519
+ // Note: Remove codeblocks
1520
+ description_1 = description_1.split(/^```.*^```/gms).join('');
1521
+ //Note: Remove lists and return statement
1522
+ description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1523
+ description_1 = spaceTrim.spaceTrim(description_1);
1524
+ if (description_1 === '') {
1525
+ description_1 = undefined;
1526
+ }
1527
+ if (Object.keys(jokers).length === 0) {
1528
+ jokers = undefined;
1529
+ }
1530
+ if (Object.keys(expectAmount).length === 0) {
1531
+ expectAmount = undefined;
1532
+ }
1533
+ if (Object.keys(postprocessing).length === 0) {
1534
+ postprocessing = undefined;
1535
+ }
1536
+ dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
1537
+ if (templateModelRequirements.modelVariant === undefined) {
1538
+ templateModelRequirements.modelVariant = 'CHAT';
1539
+ }
1540
+ promptbookJson.promptTemplates.push({
1541
+ name: titleToName(section.title),
1542
+ title: section.title,
1543
+ description: description_1,
1544
+ dependentParameterNames: Array.from(dependentParameterNames),
1545
+ executionType: executionType,
1546
+ jokers: jokers,
1547
+ postprocessing: postprocessing,
1548
+ expectations: expectAmount,
1549
+ expectFormat: expectFormat,
1550
+ modelRequirements: templateModelRequirements,
1551
+ contentLanguage: executionType === 'SCRIPT' ? language : undefined,
1552
+ content: content,
1553
+ resultingParameterName: resultingParameterName,
1554
+ });
1555
+ };
1556
+ try {
1557
+ for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
1558
+ var section = _d.value;
1559
+ _loop_1(section);
1560
+ }
1561
+ }
1562
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1563
+ finally {
1564
+ try {
1565
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1566
+ }
1567
+ finally { if (e_2) throw e_2.error; }
1568
+ }
1569
+ // =============================================================
1570
+ return promptbookJson;
1571
+ }
1572
+ /**
1573
+ * TODO: Report here line/column of error
1574
+ * TODO: Use spaceTrim more effectively
1575
+ * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1576
+ */
1577
+
1578
+ /**
1579
+ * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
1580
+ */
1581
+ var PromptbookLogicError = /** @class */ (function (_super) {
1582
+ __extends(PromptbookLogicError, _super);
1583
+ function PromptbookLogicError(message) {
1584
+ var _this = _super.call(this, message) || this;
1585
+ _this.name = 'PromptbookLogicError';
1586
+ Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
1587
+ return _this;
1588
+ }
1589
+ return PromptbookLogicError;
1590
+ }(Error));
1591
+
1592
+ /**
1593
+ * Tests if given string is valid URL.
1594
+ *
1595
+ * Note: Dataurl are considered perfectly valid.
1596
+ */
1597
+ function isValidUrl(url) {
1598
+ if (typeof url !== 'string') {
1599
+ return false;
1600
+ }
1601
+ try {
1602
+ if (url.startsWith('blob:')) {
1603
+ url = url.replace(/^blob:/, '');
1604
+ }
1605
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1606
+ var urlObject = new URL(url);
1607
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1608
+ return false;
1609
+ }
1610
+ return true;
1611
+ }
1612
+ catch (error) {
1613
+ return false;
1614
+ }
1615
+ }
1616
+
1617
+ /**
1618
+ * Validates PromptbookJson if it is logically valid
1619
+ *
1620
+ * It checks:
1621
+ * - if it has correct parameters dependency
1622
+ *
1623
+ * It does NOT check:
1624
+ * - if it is valid json
1625
+ * - if it is meaningful
1626
+ *
1627
+ * @param promptbook valid or invalid PromptbookJson
1628
+ * @returns the same promptbook if it is logically valid
1629
+ * @throws {PromptbookLogicError} on logical error in the promptbook
1630
+ */
1631
+ function validatePromptbookJson(promptbook) {
1632
+ // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1633
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
1634
+ if (promptbook.promptbookUrl !== undefined) {
1635
+ if (!isValidUrl(promptbook.promptbookUrl)) {
1636
+ // TODO: This should be maybe the syntax error detected during parsing
1637
+ throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
1638
+ }
1639
+ }
1640
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1641
+ if (!Array.isArray(promptbook.parameters)) {
1642
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1643
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
1644
+ }
1645
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1646
+ if (!Array.isArray(promptbook.promptTemplates)) {
1647
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1648
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
1649
+ }
1650
+ var _loop_1 = function (parameter) {
1651
+ if (parameter.isInput && parameter.isOutput) {
1652
+ throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
1653
+ }
1654
+ // Note: Testing that parameter is either intermediate or output BUT not created and unused
1655
+ if (!parameter.isInput &&
1656
+ !parameter.isOutput &&
1657
+ !promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1658
+ throw new PromptbookLogicError(spaceTrim.spaceTrim("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
1659
+ }
1660
+ // Note: Testing that parameter is either input or result of some template
1661
+ if (!parameter.isInput &&
1662
+ !promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1663
+ throw new PromptbookLogicError(spaceTrim.spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
1664
+ }
1665
+ };
1666
+ try {
1667
+ // Note: Check each parameter individually
1668
+ for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
1669
+ var parameter = _f.value;
1670
+ _loop_1(parameter);
1671
+ }
1672
+ }
1673
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1674
+ finally {
1675
+ try {
1676
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
1677
+ }
1678
+ finally { if (e_1) throw e_1.error; }
1679
+ }
1680
+ // Note: Check each template individually
1681
+ var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
1682
+ var isInput = _a.isInput;
1683
+ return isInput;
1684
+ }).map(function (_a) {
1685
+ var name = _a.name;
1686
+ return name;
1687
+ }));
1688
+ try {
1689
+ for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
1690
+ var template = _h.value;
1691
+ if (definedParameters.has(template.resultingParameterName)) {
1692
+ throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
1693
+ }
1694
+ definedParameters.add(template.resultingParameterName);
1695
+ if (template.executionType === 'PROMPT_TEMPLATE' &&
1696
+ (template.modelRequirements.modelVariant === undefined)) {
1697
+ throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
1698
+ }
1699
+ if (template.jokers && template.jokers.length > 0) {
1700
+ if (!template.expectFormat &&
1701
+ !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1702
+ throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
1703
+ }
1704
+ try {
1705
+ for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
1706
+ var joker = _k.value;
1707
+ if (!template.dependentParameterNames.includes(joker)) {
1708
+ throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
1709
+ }
1710
+ }
1711
+ }
1712
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1713
+ finally {
1714
+ try {
1715
+ if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
1716
+ }
1717
+ finally { if (e_3) throw e_3.error; }
1718
+ }
1719
+ }
1720
+ if (template.expectations) {
1721
+ try {
1722
+ for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
1723
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
1724
+ if (min !== undefined && max !== undefined && min > max) {
1725
+ throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
1726
+ }
1727
+ if (min !== undefined && min < 0) {
1728
+ throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
1729
+ }
1730
+ if (max !== undefined && max <= 0) {
1731
+ throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
1732
+ }
1733
+ }
1734
+ }
1735
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1736
+ finally {
1737
+ try {
1738
+ if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
1739
+ }
1740
+ finally { if (e_4) throw e_4.error; }
1741
+ }
1742
+ }
1743
+ }
1744
+ }
1745
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1746
+ finally {
1747
+ try {
1748
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
1749
+ }
1750
+ finally { if (e_2) throw e_2.error; }
1751
+ }
1752
+ // Note: Detect circular dependencies
1753
+ var resovedParameters = promptbook.parameters
1754
+ .filter(function (_a) {
1755
+ var isInput = _a.isInput;
1756
+ return isInput;
1757
+ })
1758
+ .map(function (_a) {
1759
+ var name = _a.name;
1760
+ return name;
1761
+ });
1762
+ var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
1763
+ var loopLimit = LOOP_LIMIT;
1764
+ var _loop_2 = function () {
1765
+ if (loopLimit-- < 0) {
1766
+ throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
1767
+ }
1768
+ var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
1769
+ return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
1770
+ });
1771
+ if (currentlyResovedTemplates.length === 0) {
1772
+ throw new PromptbookLogicError(spaceTrim.spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
1773
+ .map(function (_a) {
1774
+ var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1775
+ return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
1776
+ .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
1777
+ .join(', '));
1778
+ })
1779
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
1780
+ }
1781
+ resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
1782
+ var resultingParameterName = _a.resultingParameterName;
1783
+ return resultingParameterName;
1784
+ })), false);
1785
+ unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
1786
+ };
1787
+ while (unresovedTemplates.length > 0) {
1788
+ _loop_2();
1789
+ }
1790
+ return promptbook;
1791
+ }
1792
+ /**
1793
+ * TODO: [🧠] Work with promptbookVersion
1794
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
1795
+ * > /**
1796
+ * > * Validates PromptbookJson if it is logically valid.
1797
+ * > *
1798
+ * > * It checks:
1799
+ * > * - it has a valid structure
1800
+ * > * - ...
1801
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
1802
+ */
1803
+
1804
+ /**
1805
+ * This error indicates that the promptbook library cannot be propperly loaded
1806
+ */
1807
+ var PromptbookLibraryError = /** @class */ (function (_super) {
1808
+ __extends(PromptbookLibraryError, _super);
1809
+ function PromptbookLibraryError(message) {
1810
+ var _this = _super.call(this, message) || this;
1811
+ _this.name = 'PromptbookLibraryError';
1812
+ Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
1813
+ return _this;
1814
+ }
1815
+ return PromptbookLibraryError;
1816
+ }(Error));
1817
+
1818
+ /**
1819
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
1820
+ */
1821
+ new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
1822
+ /**
1823
+ * Detects if the code is running in a Node.js environment
1824
+ */
1825
+ var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
1826
+ /**
1827
+ * Detects if the code is running in a web worker
1828
+ */
1829
+ 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");
1830
+
1831
+ /**
1832
+ * Prettify the html code
1833
+ *
1834
+ * @param content raw html code
1835
+ * @returns formatted html code
1836
+ */
1837
+ function prettifyMarkdown(content) {
1838
+ try {
1839
+ return prettier.format(content, {
1840
+ parser: 'markdown',
1841
+ plugins: [parserHtml__default["default"]],
1842
+ // TODO: DRY - make some import or auto-copy of .prettierrc
1843
+ endOfLine: 'lf',
1844
+ tabWidth: 4,
1845
+ singleQuote: true,
1846
+ trailingComma: 'all',
1847
+ arrowParens: 'always',
1848
+ printWidth: 120,
1849
+ htmlWhitespaceSensitivity: 'ignore',
1850
+ jsxBracketSameLine: false,
1851
+ bracketSpacing: true,
1852
+ });
1853
+ }
1854
+ catch (error) {
1855
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1856
+ error: error,
1857
+ html: content,
1858
+ });
1859
+ return content;
1860
+ }
1861
+ }
1862
+
1863
+ /**
1864
+ * Converts promptbook in JSON format to string format
1865
+ *
1866
+ * @param promptbookJson Promptbook in JSON format (.ptbk.json)
1867
+ * @returns Promptbook in string format (.ptbk.md)
1868
+ */
1869
+ function promptbookJsonToString(promptbookJson) {
1870
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
1871
+ var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
1872
+ var promptbookString = "# ".concat(title);
1873
+ if (description) {
1874
+ promptbookString += '\n\n';
1875
+ promptbookString += description;
1876
+ }
1877
+ // TODO:> const commands: Array<Command>
1878
+ var commands = [];
1879
+ if (promptbookUrl) {
1880
+ commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
1881
+ }
1882
+ commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
1883
+ promptbookString = prettifyMarkdown(promptbookString);
1884
+ try {
1885
+ for (var _g = __values(parameters.filter(function (_a) {
1886
+ var isInput = _a.isInput;
1887
+ return isInput;
1888
+ })), _h = _g.next(); !_h.done; _h = _g.next()) {
1889
+ var parameter = _h.value;
1890
+ commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1891
+ }
1892
+ }
1893
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1894
+ finally {
1895
+ try {
1896
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
1897
+ }
1898
+ finally { if (e_1) throw e_1.error; }
1899
+ }
1900
+ try {
1901
+ for (var _j = __values(parameters.filter(function (_a) {
1902
+ var isOutput = _a.isOutput;
1903
+ return isOutput;
1904
+ })), _k = _j.next(); !_k.done; _k = _j.next()) {
1905
+ var parameter = _k.value;
1906
+ commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1907
+ }
1908
+ }
1909
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1910
+ finally {
1911
+ try {
1912
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1913
+ }
1914
+ finally { if (e_2) throw e_2.error; }
1915
+ }
1916
+ promptbookString += '\n\n';
1917
+ promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
1918
+ try {
1919
+ for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
1920
+ var promptTemplate = promptTemplates_1_1.value;
1921
+ var
1922
+ /* Note: Not using:> name, */
1923
+ title_1 = promptTemplate.title, description_1 = promptTemplate.description,
1924
+ /* Note: dependentParameterNames, */
1925
+ jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
1926
+ promptbookString += '\n\n';
1927
+ promptbookString += "## ".concat(title_1);
1928
+ if (description_1) {
1929
+ promptbookString += '\n\n';
1930
+ promptbookString += description_1;
1931
+ }
1932
+ // TODO:> const commands: Array<Command>
1933
+ var commands_1 = [];
1934
+ var contentLanguage = 'text';
1935
+ if (executionType === 'PROMPT_TEMPLATE') {
1936
+ var modelRequirements = promptTemplate.modelRequirements;
1937
+ var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
1938
+ commands_1.push("EXECUTE PROMPT TEMPLATE");
1939
+ if (modelVariant) {
1940
+ commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
1941
+ }
1942
+ if (modelName) {
1943
+ commands_1.push("MODEL NAME `".concat(modelName, "`"));
1944
+ }
1945
+ }
1946
+ else if (executionType === 'SIMPLE_TEMPLATE') {
1947
+ commands_1.push("SIMPLE TEMPLATE");
1948
+ // Note: Nothing special here
1949
+ }
1950
+ else if (executionType === 'SCRIPT') {
1951
+ commands_1.push("EXECUTE SCRIPT");
1952
+ if (promptTemplate.contentLanguage) {
1953
+ contentLanguage = promptTemplate.contentLanguage;
1954
+ }
1955
+ else {
1956
+ contentLanguage = '';
1957
+ }
1958
+ }
1959
+ else if (executionType === 'PROMPT_DIALOG') {
1960
+ commands_1.push("PROMPT DIALOG");
1961
+ // Note: Nothing special here
1962
+ }
1963
+ if (jokers) {
1964
+ try {
1965
+ for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
1966
+ var joker = jokers_1_1.value;
1967
+ commands_1.push("JOKER {".concat(joker, "}"));
1968
+ }
1969
+ }
1970
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1971
+ finally {
1972
+ try {
1973
+ if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
1974
+ }
1975
+ finally { if (e_4) throw e_4.error; }
1976
+ }
1977
+ } /* not else */
1978
+ if (postprocessing) {
1979
+ try {
1980
+ for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
1981
+ var postprocessingFunctionName = postprocessing_1_1.value;
1982
+ commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
1983
+ }
1984
+ }
1985
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1986
+ finally {
1987
+ try {
1988
+ if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
1989
+ }
1990
+ finally { if (e_5) throw e_5.error; }
1991
+ }
1992
+ } /* not else */
1993
+ if (expectations) {
1994
+ try {
1995
+ for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
1996
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
1997
+ if (min === max) {
1998
+ commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1999
+ }
2000
+ else {
2001
+ if (min !== undefined) {
2002
+ commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
2003
+ } /* not else */
2004
+ if (max !== undefined) {
2005
+ commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
2006
+ }
2007
+ }
2008
+ }
2009
+ }
2010
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
2011
+ finally {
2012
+ try {
2013
+ if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
2014
+ }
2015
+ finally { if (e_6) throw e_6.error; }
2016
+ }
2017
+ } /* not else */
2018
+ if (expectFormat) {
2019
+ if (expectFormat === 'JSON') {
2020
+ // TODO: @deprecated remove
2021
+ commands_1.push("EXPECT JSON");
2022
+ }
2023
+ } /* not else */
2024
+ promptbookString += '\n\n';
2025
+ promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
2026
+ promptbookString += '\n\n';
2027
+ promptbookString += '```' + contentLanguage;
2028
+ promptbookString += '\n';
2029
+ promptbookString += spaceTrim__default["default"](content);
2030
+ // <- TODO: !!! Escape
2031
+ // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
2032
+ promptbookString += '\n';
2033
+ promptbookString += '```';
2034
+ promptbookString += '\n\n';
2035
+ promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
2036
+ }
2037
+ }
2038
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2039
+ finally {
2040
+ try {
2041
+ if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
2042
+ }
2043
+ finally { if (e_3) throw e_3.error; }
2044
+ }
2045
+ return promptbookString;
2046
+ }
2047
+ /**
2048
+ * @private internal util of promptbookJsonToString
2049
+ */
2050
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
2051
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
2052
+ var parameterString = "{".concat(name, "}");
2053
+ if (description) {
2054
+ parameterString = "".concat(parameterString, " ").concat(description);
2055
+ }
2056
+ return parameterString;
2057
+ }
2058
+ /**
2059
+ * TODO: Escape all
2060
+ */
2061
+
2062
+ /**
2063
+ * This error indicates that promptbook not found in the library
2064
+ */
2065
+ var PromptbookNotFoundError = /** @class */ (function (_super) {
2066
+ __extends(PromptbookNotFoundError, _super);
2067
+ function PromptbookNotFoundError(message) {
2068
+ var _this = _super.call(this, message) || this;
2069
+ _this.name = 'PromptbookNotFoundError';
2070
+ Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
2071
+ return _this;
2072
+ }
2073
+ return PromptbookNotFoundError;
2074
+ }(Error));
2075
+
2076
+ /**
2077
+ * This error indicates errors in referencing promptbooks between each other
2078
+ */
2079
+ var PromptbookReferenceError = /** @class */ (function (_super) {
2080
+ __extends(PromptbookReferenceError, _super);
2081
+ function PromptbookReferenceError(message) {
2082
+ var _this = _super.call(this, message) || this;
2083
+ _this.name = 'PromptbookReferenceError';
2084
+ Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
2085
+ return _this;
2086
+ }
2087
+ return PromptbookReferenceError;
2088
+ }(Error));
2089
+
2090
+ /**
2091
+ * Library of promptbooks that groups together promptbooks for an application.
2092
+ * This implementation is a very thin wrapper around the Array / Map of promptbooks.
2093
+ *
2094
+ * @see https://github.com/webgptorg/promptbook#promptbook-library
2095
+ */
2096
+ var SimplePromptbookLibrary = /** @class */ (function () {
2097
+ /**
2098
+ * Constructs a promptbook library from promptbooks
2099
+ *
2100
+ * @param promptbooks !!!
2101
+ *
2102
+ * Note: During the construction logic of all promptbooks are validated
2103
+ * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
2104
+ */
2105
+ function SimplePromptbookLibrary() {
2106
+ var e_1, _a;
2107
+ var promptbooks = [];
2108
+ for (var _i = 0; _i < arguments.length; _i++) {
2109
+ promptbooks[_i] = arguments[_i];
2110
+ }
2111
+ this.library = new Map();
2112
+ try {
2113
+ for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
2114
+ var promptbook = promptbooks_1_1.value;
2115
+ if (promptbook.promptbookUrl === undefined) {
2116
+ throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
2117
+ }
2118
+ validatePromptbookJson(promptbook);
2119
+ // Note: [🦄]
2120
+ if (this.library.has(promptbook.promptbookUrl) &&
2121
+ promptbookJsonToString(promptbook) !==
2122
+ promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
2123
+ throw new PromptbookReferenceError(spaceTrim.spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
2124
+ }
2125
+ this.library.set(promptbook.promptbookUrl, promptbook);
2126
+ }
2127
+ }
2128
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2129
+ finally {
2130
+ try {
2131
+ if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
2132
+ }
2133
+ finally { if (e_1) throw e_1.error; }
2134
+ }
2135
+ }
2136
+ /**
2137
+ * Gets all promptbooks in the library
2138
+ */
2139
+ SimplePromptbookLibrary.prototype.listPromptbooks = function () {
2140
+ return Array.from(this.library.keys());
2141
+ };
2142
+ /**
2143
+ * Gets promptbook by its URL
2144
+ *
2145
+ * Note: This is not a direct fetching from the URL, but a lookup in the library
2146
+ */
2147
+ SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
2148
+ var _this = this;
2149
+ var promptbook = this.library.get(url);
2150
+ if (!promptbook) {
2151
+ if (this.listPromptbooks().length === 0) {
2152
+ throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
2153
+ }
2154
+ throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
2155
+ .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
2156
+ .join('\n')), "\n\n "); }));
2157
+ }
2158
+ return promptbook;
2159
+ };
2160
+ /**
2161
+ * Checks whether given prompt was defined in any promptbook in the library
2162
+ */
2163
+ SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
2164
+ return true;
2165
+ };
2166
+ return SimplePromptbookLibrary;
2167
+ }());
2168
+
2169
+ /**
2170
+ * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
2171
+ *
2172
+ * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
2173
+ * Note: During the construction syntax and logic of all sources are validated
2174
+ *
2175
+ * @param promptbookSources
2176
+ * @returns PromptbookLibrary
2177
+ */
2178
+ function createPromptbookLibraryFromSources() {
2179
+ var e_1, _a;
2180
+ var promptbookSources = [];
2181
+ for (var _i = 0; _i < arguments.length; _i++) {
2182
+ promptbookSources[_i] = arguments[_i];
2183
+ }
2184
+ var promptbooks = new Array();
2185
+ try {
2186
+ for (var promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next(); !promptbookSources_1_1.done; promptbookSources_1_1 = promptbookSources_1.next()) {
2187
+ var source = promptbookSources_1_1.value;
2188
+ var promptbook = void 0;
2189
+ if (typeof source === 'string') {
2190
+ // Note: When directly creating from string, no need to validate the source
2191
+ // The validation is performed always before execution
2192
+ promptbook = promptbookStringToJson(source);
2193
+ }
2194
+ else {
2195
+ promptbook = source;
2196
+ }
2197
+ promptbooks.push(promptbook);
2198
+ }
2199
+ }
2200
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2201
+ finally {
2202
+ try {
2203
+ if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
2204
+ }
2205
+ finally { if (e_1) throw e_1.error; }
2206
+ }
2207
+ return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
2208
+ }
2209
+
2210
+ /**
2211
+ * Constructs Promptbook from async sources
2212
+ * It can be one of the following:
2213
+ * - Promise of array of PromptbookJson or PromptbookString
2214
+ * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
2215
+ *
2216
+ * Note: This is useful as internal tool for other constructor functions like
2217
+ * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2218
+ * Consider using those functions instead of this one
2219
+ *
2220
+ * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
2221
+ * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
2222
+ *
2223
+ * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
2224
+ *
2225
+ * @param promptbookSourcesPromiseOrFactory
2226
+ * @returns PromptbookLibrary
2227
+ * @private Just internal tool for other constructor functions
2228
+ */
2229
+ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
2230
+ var library;
2231
+ function forSources() {
2232
+ return __awaiter(this, void 0, void 0, function () {
2233
+ var promptbookSources;
2234
+ return __generator(this, function (_a) {
2235
+ switch (_a.label) {
2236
+ case 0:
2237
+ if (typeof promptbookSourcesPromiseOrFactory === 'function') {
2238
+ // Note: Calling factory function only once despite multiple calls to resolveSources
2239
+ promptbookSourcesPromiseOrFactory = promptbookSourcesPromiseOrFactory();
2240
+ }
2241
+ return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
2242
+ case 1:
2243
+ promptbookSources = _a.sent();
2244
+ library = createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false));
2245
+ return [2 /*return*/];
2246
+ }
2247
+ });
2248
+ });
2249
+ }
2250
+ function listPromptbooks() {
2251
+ return __awaiter(this, void 0, void 0, function () {
2252
+ return __generator(this, function (_a) {
2253
+ switch (_a.label) {
2254
+ case 0: return [4 /*yield*/, forSources()];
2255
+ case 1:
2256
+ _a.sent();
2257
+ return [2 /*return*/, /* not await */ library.listPromptbooks()];
2258
+ }
2259
+ });
2260
+ });
2261
+ }
2262
+ function getPromptbookByUrl(url) {
2263
+ return __awaiter(this, void 0, void 0, function () {
2264
+ return __generator(this, function (_a) {
2265
+ switch (_a.label) {
2266
+ case 0: return [4 /*yield*/, forSources()];
2267
+ case 1:
2268
+ _a.sent();
2269
+ return [2 /*return*/, /* not await */ library.getPromptbookByUrl(url)];
2270
+ }
2271
+ });
2272
+ });
2273
+ }
2274
+ function isResponsibleForPrompt(prompt) {
2275
+ return __awaiter(this, void 0, void 0, function () {
2276
+ return __generator(this, function (_a) {
2277
+ switch (_a.label) {
2278
+ case 0: return [4 /*yield*/, forSources()];
2279
+ case 1:
2280
+ _a.sent();
2281
+ return [2 /*return*/, /* not await */ library.isResponsibleForPrompt(prompt)];
2282
+ }
2283
+ });
2284
+ });
2285
+ }
2286
+ return {
2287
+ listPromptbooks: listPromptbooks,
2288
+ getPromptbookByUrl: getPromptbookByUrl,
2289
+ isResponsibleForPrompt: isResponsibleForPrompt,
2290
+ };
2291
+ }
2292
+
2293
+ /**
2294
+ * Constructs Promptbook from given directory
2295
+ *
2296
+ * Note: Works only in Node.js environment because it reads the file system
2297
+ *
2298
+ * @param path - path to the directory with promptbooks
2299
+ * @param options - Misc options for the library
2300
+ * @returns PromptbookLibrary
2301
+ */
2302
+ function createPromptbookLibraryFromDirectory(path, options) {
2303
+ return __awaiter(this, void 0, void 0, function () {
2304
+ var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
2305
+ var _this = this;
2306
+ return __generator(this, function (_f) {
2307
+ switch (_f.label) {
2308
+ case 0:
2309
+ if (!isRunningInNode()) {
2310
+ throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
2311
+ }
2312
+ _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
2313
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
2314
+ var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
2315
+ var e_1, _a;
2316
+ return __generator(this, function (_b) {
2317
+ switch (_b.label) {
2318
+ case 0:
2319
+ if (isVerbose) {
2320
+ console.info("Creating promptbook library from path ".concat(path));
2321
+ }
2322
+ return [4 /*yield*/, listAllFiles(path, isRecursive)];
2323
+ case 1:
2324
+ fileNames = _b.sent();
2325
+ if (isVerbose) {
2326
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
2327
+ }
2328
+ promptbooks = [];
2329
+ _loop_1 = function (fileName) {
2330
+ var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
2331
+ return __generator(this, function (_e) {
2332
+ switch (_e.label) {
2333
+ case 0:
2334
+ _e.trys.push([0, 6, , 7]);
2335
+ promptbook = null;
2336
+ if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 2];
2337
+ return [4 /*yield*/, promises.readFile(fileName, 'utf8')];
2338
+ case 1:
2339
+ promptbookString = (_e.sent());
2340
+ promptbook = promptbookStringToJson(promptbookString);
2341
+ return [3 /*break*/, 5];
2342
+ case 2:
2343
+ if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 4];
2344
+ if (isVerbose) {
2345
+ console.info("Loading ".concat(fileName));
2346
+ }
2347
+ _d = (_c = JSON).parse;
2348
+ return [4 /*yield*/, promises.readFile(fileName, 'utf8')];
2349
+ case 3:
2350
+ // TODO: Handle non-valid JSON files
2351
+ promptbook = _d.apply(_c, [_e.sent()]);
2352
+ return [3 /*break*/, 5];
2353
+ case 4:
2354
+ if (isVerbose) {
2355
+ console.info("Skipping file ".concat(fileName));
2356
+ }
2357
+ _e.label = 5;
2358
+ case 5:
2359
+ // ---
2360
+ if (promptbook !== null) {
2361
+ if (!promptbook.promptbookUrl) {
2362
+ if (isVerbose) {
2363
+ console.info("Not loading ".concat(fileName, " - missing URL"));
2364
+ }
2365
+ }
2366
+ else {
2367
+ if (isVerbose) {
2368
+ console.info("Loading ".concat(fileName));
2369
+ }
2370
+ if (!isCrashOnError) {
2371
+ // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
2372
+ // But be handled in current try-catch block
2373
+ validatePromptbookJson(promptbook);
2374
+ }
2375
+ // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
2376
+ promptbooks.push(promptbook);
2377
+ }
2378
+ }
2379
+ return [3 /*break*/, 7];
2380
+ case 6:
2381
+ error_1 = _e.sent();
2382
+ if (!(error_1 instanceof Error)) {
2383
+ throw error_1;
2384
+ }
2385
+ wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading promptbook from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
2386
+ if (isCrashOnError) {
2387
+ throw new PromptbookLibraryError(wrappedErrorMessage);
2388
+ }
2389
+ console.error(wrappedErrorMessage);
2390
+ return [3 /*break*/, 7];
2391
+ case 7: return [2 /*return*/];
2392
+ }
2393
+ });
2394
+ };
2395
+ _b.label = 2;
2396
+ case 2:
2397
+ _b.trys.push([2, 7, 8, 9]);
2398
+ fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
2399
+ _b.label = 3;
2400
+ case 3:
2401
+ if (!!fileNames_1_1.done) return [3 /*break*/, 6];
2402
+ fileName = fileNames_1_1.value;
2403
+ return [5 /*yield**/, _loop_1(fileName)];
2404
+ case 4:
2405
+ _b.sent();
2406
+ _b.label = 5;
2407
+ case 5:
2408
+ fileNames_1_1 = fileNames_1.next();
2409
+ return [3 /*break*/, 3];
2410
+ case 6: return [3 /*break*/, 9];
2411
+ case 7:
2412
+ e_1_1 = _b.sent();
2413
+ e_1 = { error: e_1_1 };
2414
+ return [3 /*break*/, 9];
2415
+ case 8:
2416
+ try {
2417
+ if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
2418
+ }
2419
+ finally { if (e_1) throw e_1.error; }
2420
+ return [7 /*endfinally*/];
2421
+ case 9: return [2 /*return*/, promptbooks];
2422
+ }
2423
+ });
2424
+ }); });
2425
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
2426
+ return [4 /*yield*/, library.listPromptbooks()];
2427
+ case 1:
2428
+ _f.sent();
2429
+ _f.label = 2;
2430
+ case 2: return [2 /*return*/, library];
2431
+ }
2432
+ });
2433
+ });
2434
+ }
2435
+ /**
2436
+ * Reads all files in the directory
2437
+ *
2438
+ * @param path
2439
+ * @param isRecursive
2440
+ * @returns List of all files in the directory
2441
+ * @private internal function for `createPromptbookLibraryFromDirectory`
2442
+ */
2443
+ function listAllFiles(path$1, isRecursive) {
2444
+ return __awaiter(this, void 0, void 0, function () {
2445
+ var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_2_1;
2446
+ var e_2, _g;
2447
+ return __generator(this, function (_h) {
2448
+ switch (_h.label) {
2449
+ case 0: return [4 /*yield*/, promises.readdir(path$1, {
2450
+ withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
2451
+ })];
2452
+ case 1:
2453
+ dirents = _h.sent();
2454
+ fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
2455
+ var name = _a.name;
2456
+ return path.join(path$1, name);
2457
+ });
2458
+ if (!isRecursive) return [3 /*break*/, 9];
2459
+ _h.label = 2;
2460
+ case 2:
2461
+ _h.trys.push([2, 7, 8, 9]);
2462
+ _a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
2463
+ _h.label = 3;
2464
+ case 3:
2465
+ if (!!_b.done) return [3 /*break*/, 6];
2466
+ dirent = _b.value;
2467
+ subPath = path.join(path$1, dirent.name);
2468
+ _d = (_c = fileNames.push).apply;
2469
+ _e = [fileNames];
2470
+ _f = [[]];
2471
+ return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
2472
+ case 4:
2473
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
2474
+ _h.label = 5;
2475
+ case 5:
2476
+ _b = _a.next();
2477
+ return [3 /*break*/, 3];
2478
+ case 6: return [3 /*break*/, 9];
2479
+ case 7:
2480
+ e_2_1 = _h.sent();
2481
+ e_2 = { error: e_2_1 };
2482
+ return [3 /*break*/, 9];
2483
+ case 8:
2484
+ try {
2485
+ if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
2486
+ }
2487
+ finally { if (e_2) throw e_2.error; }
2488
+ return [7 /*endfinally*/];
2489
+ case 9: return [2 /*return*/, fileNames];
2490
+ }
2491
+ });
2492
+ });
2493
+ }
2494
+
2495
+ exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
2496
+ exports.createPromptbookLibraryFromDirectory = createPromptbookLibraryFromDirectory;
2497
+
2498
+ Object.defineProperty(exports, '__esModule', { value: true });
2499
+
2500
+ }));
2501
+ //# sourceMappingURL=index.umd.js.map