@promptbook/cli 0.59.0-2 → 0.59.0-21

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 (567) hide show
  1. package/esm/index.es.js +2523 -977
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/promptbook-library/promptbook-library.d.ts +25 -0
  4. package/{umd/typings → esm/typings/src}/_packages/core.index.d.ts +7 -6
  5. package/esm/typings/{_packages → src/_packages}/node.index.d.ts +1 -1
  6. package/{umd/typings → esm/typings/src}/_packages/types.index.d.ts +1 -1
  7. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +21 -0
  8. package/{umd/typings → esm/typings/src}/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +3 -0
  9. package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
  10. package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
  11. package/{umd/typings → esm/typings/src}/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
  12. package/esm/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
  13. package/package.json +3 -3
  14. package/umd/index.umd.js +2528 -981
  15. package/umd/index.umd.js.map +1 -1
  16. package/umd/typings/promptbook-library/promptbook-library.d.ts +25 -0
  17. package/{esm/typings → umd/typings/src}/_packages/core.index.d.ts +7 -6
  18. package/umd/typings/{_packages → src/_packages}/node.index.d.ts +1 -1
  19. package/{esm/typings → umd/typings/src}/_packages/types.index.d.ts +1 -1
  20. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +21 -0
  21. package/{esm/typings → umd/typings/src}/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +3 -0
  22. package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
  23. package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
  24. package/{esm/typings → umd/typings/src}/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
  25. package/umd/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
  26. package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -7
  27. package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -7
  28. /package/esm/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
  29. /package/esm/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
  30. /package/esm/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
  31. /package/esm/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
  32. /package/esm/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
  33. /package/esm/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
  34. /package/esm/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
  35. /package/esm/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
  36. /package/esm/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
  37. /package/esm/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
  38. /package/esm/typings/{config.d.ts → src/config.d.ts} +0 -0
  39. /package/esm/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
  40. /package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
  41. /package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
  42. /package/esm/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
  43. /package/esm/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
  44. /package/esm/typings/{conversion → src/conversion}/promptbookStringToJson.d.ts +0 -0
  45. /package/esm/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
  46. /package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
  47. /package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
  48. /package/esm/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
  49. /package/esm/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
  50. /package/esm/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
  51. /package/esm/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
  52. /package/esm/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
  53. /package/esm/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
  54. /package/esm/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
  55. /package/esm/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
  56. /package/esm/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
  57. /package/esm/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
  58. /package/esm/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
  59. /package/esm/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
  60. /package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
  61. /package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
  62. /package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
  63. /package/esm/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
  64. /package/esm/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
  65. /package/esm/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
  66. /package/esm/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
  67. /package/esm/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
  68. /package/esm/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
  69. /package/esm/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
  70. /package/esm/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
  71. /package/esm/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
  72. /package/esm/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
  73. /package/esm/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
  74. /package/esm/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
  75. /package/esm/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
  76. /package/esm/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
  77. /package/esm/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
  78. /package/esm/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
  79. /package/esm/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
  80. /package/esm/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
  81. /package/esm/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
  82. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
  83. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
  84. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
  85. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
  86. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
  87. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
  88. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
  89. /package/esm/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
  90. /package/esm/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
  91. /package/esm/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
  92. /package/esm/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
  93. /package/esm/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
  94. /package/esm/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
  95. /package/esm/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
  96. /package/esm/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
  97. /package/esm/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
  98. /package/esm/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
  99. /package/esm/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
  100. /package/esm/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
  101. /package/esm/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
  102. /package/esm/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
  103. /package/esm/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
  104. /package/esm/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
  105. /package/esm/typings/{formats → src/formats}/index.d.ts +0 -0
  106. /package/esm/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
  107. /package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
  108. /package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
  109. /package/esm/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
  110. /package/esm/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
  111. /package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
  112. /package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
  113. /package/esm/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
  114. /package/esm/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
  115. /package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
  116. /package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -0
  117. /package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
  118. /package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +0 -0
  119. /package/esm/typings/{promptbook-library → src/library}/PromptbookLibrary.d.ts +0 -0
  120. /package/esm/typings/{promptbook-library → src/library}/SimplePromptbookLibrary.d.ts +0 -0
  121. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
  122. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
  123. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
  124. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
  125. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
  126. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
  127. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
  128. /package/esm/typings/{promptbook-library → src/library}/constructors/createPromptbookSublibrary.d.ts +0 -0
  129. /package/esm/typings/{promptbook-library → src/library}/constructors/justTestFsImport.d.ts +0 -0
  130. /package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -0
  131. /package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
  132. /package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
  133. /package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
  134. /package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
  135. /package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
  136. /package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/playground/playground.d.ts +0 -0
  137. /package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
  138. /package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
  139. /package/esm/typings/{llm-providers → src/llm-providers}/langtail/playground/playground.d.ts +0 -0
  140. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
  141. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.test.d.ts +0 -0
  142. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/faked-completion.test.d.ts +0 -0
  143. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
  144. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
  145. /package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
  146. /package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
  147. /package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
  148. /package/esm/typings/{llm-providers → src/llm-providers}/multiple/playground/playground.d.ts +0 -0
  149. /package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
  150. /package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
  151. /package/esm/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
  152. /package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
  153. /package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.test.d.ts +0 -0
  154. /package/esm/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
  155. /package/esm/typings/{llm-providers → src/llm-providers}/openai/playground/playground.d.ts +0 -0
  156. /package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
  157. /package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
  158. /package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
  159. /package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
  160. /package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
  161. /package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
  162. /package/esm/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
  163. /package/esm/typings/{scripting → src/scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
  164. /package/esm/typings/{scripting → src/scripting}/_test/custom-function-missing.test.d.ts +0 -0
  165. /package/esm/typings/{scripting → src/scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
  166. /package/esm/typings/{scripting → src/scripting}/_test/custom-function.test.d.ts +0 -0
  167. /package/esm/typings/{scripting → src/scripting}/_test/postprocessing.test.d.ts +0 -0
  168. /package/esm/typings/{scripting → src/scripting}/_test/script-execution-errors.test.d.ts +0 -0
  169. /package/esm/typings/{scripting → src/scripting}/_test/script-execution-tools.test.d.ts +0 -0
  170. /package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
  171. /package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
  172. /package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
  173. /package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
  174. /package/esm/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
  175. /package/esm/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
  176. /package/esm/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
  177. /package/esm/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
  178. /package/esm/typings/{types → src/types}/Command.d.ts +0 -0
  179. /package/esm/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
  180. /package/esm/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
  181. /package/esm/typings/{types → src/types}/Parameters.d.ts +0 -0
  182. /package/esm/typings/{types → src/types}/Prompt.d.ts +0 -0
  183. /package/esm/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
  184. /package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
  185. /package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
  186. /package/esm/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
  187. /package/esm/typings/{types → src/types}/PromptbookString.d.ts +0 -0
  188. /package/esm/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
  189. /package/esm/typings/{types → src/types}/TaskProgress.d.ts +0 -0
  190. /package/esm/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
  191. /package/esm/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
  192. /package/esm/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
  193. /package/esm/typings/{types → src/types}/execution-report/config.d.ts +0 -0
  194. /package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
  195. /package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.test.d.ts +0 -0
  196. /package/esm/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
  197. /package/esm/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
  198. /package/esm/typings/{types → src/types}/typeAliases.d.ts +0 -0
  199. /package/esm/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
  200. /package/esm/typings/{utils → src/utils}/emojis.d.ts +0 -0
  201. /package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
  202. /package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.test.d.ts +0 -0
  203. /package/esm/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
  204. /package/esm/typings/{utils → src/utils}/expectation-counters/countLines.test.d.ts +0 -0
  205. /package/esm/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
  206. /package/esm/typings/{utils → src/utils}/expectation-counters/countPages.test.d.ts +0 -0
  207. /package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
  208. /package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
  209. /package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
  210. /package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.test.d.ts +0 -0
  211. /package/esm/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
  212. /package/esm/typings/{utils → src/utils}/expectation-counters/countWords.test.d.ts +0 -0
  213. /package/esm/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
  214. /package/esm/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
  215. /package/esm/typings/{utils → src/utils}/extractParameters.test.d.ts +0 -0
  216. /package/esm/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
  217. /package/esm/typings/{utils → src/utils}/formatNumber.test.d.ts +0 -0
  218. /package/esm/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
  219. /package/esm/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
  220. /package/esm/typings/{utils → src/utils}/just.d.ts +0 -0
  221. /package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
  222. /package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
  223. /package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
  224. /package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.test.d.ts +0 -0
  225. /package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
  226. /package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.test.d.ts +0 -0
  227. /package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
  228. /package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
  229. /package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
  230. /package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
  231. /package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
  232. /package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
  233. /package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
  234. /package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
  235. /package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
  236. /package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
  237. /package/esm/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
  238. /package/esm/typings/{utils → src/utils}/markdown/removeContentComments.test.d.ts +0 -0
  239. /package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
  240. /package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
  241. /package/esm/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
  242. /package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
  243. /package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
  244. /package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
  245. /package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
  246. /package/esm/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
  247. /package/esm/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
  248. /package/esm/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
  249. /package/esm/typings/{utils → src/utils}/normalization/capitalize.test.d.ts +0 -0
  250. /package/esm/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
  251. /package/esm/typings/{utils → src/utils}/normalization/decapitalize.test.d.ts +0 -0
  252. /package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
  253. /package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.test.d.ts +0 -0
  254. /package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
  255. /package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.test.d.ts +0 -0
  256. /package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
  257. /package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.test.d.ts +0 -0
  258. /package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
  259. /package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
  260. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
  261. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
  262. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
  263. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
  264. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
  265. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
  266. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
  267. /package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
  268. /package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
  269. /package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
  270. /package/esm/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
  271. /package/esm/typings/{utils → src/utils}/normalization/parseKeywords.test.d.ts +0 -0
  272. /package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
  273. /package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
  274. /package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
  275. /package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.test.d.ts +0 -0
  276. /package/esm/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
  277. /package/esm/typings/{utils → src/utils}/normalization/searchKeywords.test.d.ts +0 -0
  278. /package/esm/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
  279. /package/esm/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
  280. /package/esm/typings/{utils → src/utils}/removeEmojis.test.d.ts +0 -0
  281. /package/esm/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
  282. /package/esm/typings/{utils → src/utils}/removeQuotes.test.d.ts +0 -0
  283. /package/esm/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
  284. /package/esm/typings/{utils → src/utils}/sets/difference.test.d.ts +0 -0
  285. /package/esm/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
  286. /package/esm/typings/{utils → src/utils}/sets/intersection.test.d.ts +0 -0
  287. /package/esm/typings/{utils → src/utils}/sets/union.d.ts +0 -0
  288. /package/esm/typings/{utils → src/utils}/sets/union.test.d.ts +0 -0
  289. /package/esm/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
  290. /package/esm/typings/{utils → src/utils}/trimCodeBlock.test.d.ts +0 -0
  291. /package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
  292. /package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.test.d.ts +0 -0
  293. /package/esm/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
  294. /package/esm/typings/{utils → src/utils}/unwrapResult.test.d.ts +0 -0
  295. /package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
  296. /package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.test.d.ts +0 -0
  297. /package/esm/typings/{version.d.ts → src/version.d.ts} +0 -0
  298. /package/umd/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
  299. /package/umd/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
  300. /package/umd/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
  301. /package/umd/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
  302. /package/umd/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
  303. /package/umd/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
  304. /package/umd/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
  305. /package/umd/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
  306. /package/umd/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
  307. /package/umd/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
  308. /package/umd/typings/{config.d.ts → src/config.d.ts} +0 -0
  309. /package/umd/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
  310. /package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
  311. /package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
  312. /package/umd/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
  313. /package/umd/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
  314. /package/umd/typings/{conversion → src/conversion}/promptbookStringToJson.d.ts +0 -0
  315. /package/umd/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
  316. /package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
  317. /package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
  318. /package/umd/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
  319. /package/umd/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
  320. /package/umd/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
  321. /package/umd/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
  322. /package/umd/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
  323. /package/umd/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
  324. /package/umd/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
  325. /package/umd/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
  326. /package/umd/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
  327. /package/umd/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
  328. /package/umd/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
  329. /package/umd/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
  330. /package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
  331. /package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
  332. /package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
  333. /package/umd/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
  334. /package/umd/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
  335. /package/umd/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
  336. /package/umd/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
  337. /package/umd/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
  338. /package/umd/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
  339. /package/umd/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
  340. /package/umd/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
  341. /package/umd/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
  342. /package/umd/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
  343. /package/umd/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
  344. /package/umd/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
  345. /package/umd/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
  346. /package/umd/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
  347. /package/umd/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
  348. /package/umd/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
  349. /package/umd/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
  350. /package/umd/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
  351. /package/umd/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
  352. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
  353. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
  354. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
  355. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
  356. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
  357. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
  358. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
  359. /package/umd/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
  360. /package/umd/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
  361. /package/umd/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
  362. /package/umd/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
  363. /package/umd/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
  364. /package/umd/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
  365. /package/umd/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
  366. /package/umd/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
  367. /package/umd/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
  368. /package/umd/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
  369. /package/umd/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
  370. /package/umd/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
  371. /package/umd/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
  372. /package/umd/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
  373. /package/umd/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
  374. /package/umd/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
  375. /package/umd/typings/{formats → src/formats}/index.d.ts +0 -0
  376. /package/umd/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
  377. /package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
  378. /package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
  379. /package/umd/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
  380. /package/umd/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
  381. /package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
  382. /package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
  383. /package/umd/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
  384. /package/umd/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
  385. /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
  386. /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -0
  387. /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
  388. /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +0 -0
  389. /package/umd/typings/{promptbook-library → src/library}/PromptbookLibrary.d.ts +0 -0
  390. /package/umd/typings/{promptbook-library → src/library}/SimplePromptbookLibrary.d.ts +0 -0
  391. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
  392. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
  393. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
  394. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
  395. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
  396. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
  397. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
  398. /package/umd/typings/{promptbook-library → src/library}/constructors/createPromptbookSublibrary.d.ts +0 -0
  399. /package/umd/typings/{promptbook-library → src/library}/constructors/justTestFsImport.d.ts +0 -0
  400. /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -0
  401. /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
  402. /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
  403. /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
  404. /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
  405. /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
  406. /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/playground/playground.d.ts +0 -0
  407. /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
  408. /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
  409. /package/umd/typings/{llm-providers → src/llm-providers}/langtail/playground/playground.d.ts +0 -0
  410. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
  411. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.test.d.ts +0 -0
  412. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/faked-completion.test.d.ts +0 -0
  413. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
  414. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
  415. /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
  416. /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
  417. /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
  418. /package/umd/typings/{llm-providers → src/llm-providers}/multiple/playground/playground.d.ts +0 -0
  419. /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
  420. /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
  421. /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
  422. /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
  423. /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeUsage.test.d.ts +0 -0
  424. /package/umd/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
  425. /package/umd/typings/{llm-providers → src/llm-providers}/openai/playground/playground.d.ts +0 -0
  426. /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
  427. /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
  428. /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
  429. /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
  430. /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
  431. /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
  432. /package/umd/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
  433. /package/umd/typings/{scripting → src/scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
  434. /package/umd/typings/{scripting → src/scripting}/_test/custom-function-missing.test.d.ts +0 -0
  435. /package/umd/typings/{scripting → src/scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
  436. /package/umd/typings/{scripting → src/scripting}/_test/custom-function.test.d.ts +0 -0
  437. /package/umd/typings/{scripting → src/scripting}/_test/postprocessing.test.d.ts +0 -0
  438. /package/umd/typings/{scripting → src/scripting}/_test/script-execution-errors.test.d.ts +0 -0
  439. /package/umd/typings/{scripting → src/scripting}/_test/script-execution-tools.test.d.ts +0 -0
  440. /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
  441. /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
  442. /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
  443. /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
  444. /package/umd/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
  445. /package/umd/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
  446. /package/umd/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
  447. /package/umd/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
  448. /package/umd/typings/{types → src/types}/Command.d.ts +0 -0
  449. /package/umd/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
  450. /package/umd/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
  451. /package/umd/typings/{types → src/types}/Parameters.d.ts +0 -0
  452. /package/umd/typings/{types → src/types}/Prompt.d.ts +0 -0
  453. /package/umd/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
  454. /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
  455. /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
  456. /package/umd/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
  457. /package/umd/typings/{types → src/types}/PromptbookString.d.ts +0 -0
  458. /package/umd/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
  459. /package/umd/typings/{types → src/types}/TaskProgress.d.ts +0 -0
  460. /package/umd/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
  461. /package/umd/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
  462. /package/umd/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
  463. /package/umd/typings/{types → src/types}/execution-report/config.d.ts +0 -0
  464. /package/umd/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
  465. /package/umd/typings/{types → src/types}/execution-report/countWorkingDuration.test.d.ts +0 -0
  466. /package/umd/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
  467. /package/umd/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
  468. /package/umd/typings/{types → src/types}/typeAliases.d.ts +0 -0
  469. /package/umd/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
  470. /package/umd/typings/{utils → src/utils}/emojis.d.ts +0 -0
  471. /package/umd/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
  472. /package/umd/typings/{utils → src/utils}/expectation-counters/countCharacters.test.d.ts +0 -0
  473. /package/umd/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
  474. /package/umd/typings/{utils → src/utils}/expectation-counters/countLines.test.d.ts +0 -0
  475. /package/umd/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
  476. /package/umd/typings/{utils → src/utils}/expectation-counters/countPages.test.d.ts +0 -0
  477. /package/umd/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
  478. /package/umd/typings/{utils → src/utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
  479. /package/umd/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
  480. /package/umd/typings/{utils → src/utils}/expectation-counters/countSentences.test.d.ts +0 -0
  481. /package/umd/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
  482. /package/umd/typings/{utils → src/utils}/expectation-counters/countWords.test.d.ts +0 -0
  483. /package/umd/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
  484. /package/umd/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
  485. /package/umd/typings/{utils → src/utils}/extractParameters.test.d.ts +0 -0
  486. /package/umd/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
  487. /package/umd/typings/{utils → src/utils}/formatNumber.test.d.ts +0 -0
  488. /package/umd/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
  489. /package/umd/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
  490. /package/umd/typings/{utils → src/utils}/just.d.ts +0 -0
  491. /package/umd/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
  492. /package/umd/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
  493. /package/umd/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
  494. /package/umd/typings/{utils → src/utils}/markdown/createMarkdownChart.test.d.ts +0 -0
  495. /package/umd/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
  496. /package/umd/typings/{utils → src/utils}/markdown/createMarkdownTable.test.d.ts +0 -0
  497. /package/umd/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
  498. /package/umd/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
  499. /package/umd/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
  500. /package/umd/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
  501. /package/umd/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
  502. /package/umd/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
  503. /package/umd/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
  504. /package/umd/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
  505. /package/umd/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
  506. /package/umd/typings/{utils → src/utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
  507. /package/umd/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
  508. /package/umd/typings/{utils → src/utils}/markdown/removeContentComments.test.d.ts +0 -0
  509. /package/umd/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
  510. /package/umd/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
  511. /package/umd/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
  512. /package/umd/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
  513. /package/umd/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
  514. /package/umd/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
  515. /package/umd/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
  516. /package/umd/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
  517. /package/umd/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
  518. /package/umd/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
  519. /package/umd/typings/{utils → src/utils}/normalization/capitalize.test.d.ts +0 -0
  520. /package/umd/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
  521. /package/umd/typings/{utils → src/utils}/normalization/decapitalize.test.d.ts +0 -0
  522. /package/umd/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
  523. /package/umd/typings/{utils → src/utils}/normalization/isValidKeyword.test.d.ts +0 -0
  524. /package/umd/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
  525. /package/umd/typings/{utils → src/utils}/normalization/nameToUriPart.test.d.ts +0 -0
  526. /package/umd/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
  527. /package/umd/typings/{utils → src/utils}/normalization/nameToUriParts.test.d.ts +0 -0
  528. /package/umd/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
  529. /package/umd/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
  530. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
  531. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
  532. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
  533. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
  534. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
  535. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
  536. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
  537. /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
  538. /package/umd/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
  539. /package/umd/typings/{utils → src/utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
  540. /package/umd/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
  541. /package/umd/typings/{utils → src/utils}/normalization/parseKeywords.test.d.ts +0 -0
  542. /package/umd/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
  543. /package/umd/typings/{utils → src/utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
  544. /package/umd/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
  545. /package/umd/typings/{utils → src/utils}/normalization/removeDiacritics.test.d.ts +0 -0
  546. /package/umd/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
  547. /package/umd/typings/{utils → src/utils}/normalization/searchKeywords.test.d.ts +0 -0
  548. /package/umd/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
  549. /package/umd/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
  550. /package/umd/typings/{utils → src/utils}/removeEmojis.test.d.ts +0 -0
  551. /package/umd/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
  552. /package/umd/typings/{utils → src/utils}/removeQuotes.test.d.ts +0 -0
  553. /package/umd/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
  554. /package/umd/typings/{utils → src/utils}/sets/difference.test.d.ts +0 -0
  555. /package/umd/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
  556. /package/umd/typings/{utils → src/utils}/sets/intersection.test.d.ts +0 -0
  557. /package/umd/typings/{utils → src/utils}/sets/union.d.ts +0 -0
  558. /package/umd/typings/{utils → src/utils}/sets/union.test.d.ts +0 -0
  559. /package/umd/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
  560. /package/umd/typings/{utils → src/utils}/trimCodeBlock.test.d.ts +0 -0
  561. /package/umd/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
  562. /package/umd/typings/{utils → src/utils}/trimEndOfCodeBlock.test.d.ts +0 -0
  563. /package/umd/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
  564. /package/umd/typings/{utils → src/utils}/unwrapResult.test.d.ts +0 -0
  565. /package/umd/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
  566. /package/umd/typings/{utils → src/utils}/validators/url/isValidUrl.test.d.ts +0 -0
  567. /package/umd/typings/{version.d.ts → src/version.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -1,14 +1,15 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('commander'), require('fs/promises'), require('glob-promise'), require('spacetrim'), require('waitasecond'), require('prettier'), require('prettier/parser-html')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'colors', 'commander', 'fs/promises', 'glob-promise', 'spacetrim', 'waitasecond', 'prettier', 'prettier/parser-html'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.spacetrim, global.waitasecond, global.prettier, global.parserHtml));
5
- })(this, (function (exports, colors, commander, promises, glob, spacetrim, waitasecond, prettier, parserHtml) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.colors, global.commander, global.promises, global.glob, global.spaceTrim, global.waitasecond, global.prettier, global.parserHtml));
5
+ })(this, (function (exports, colors, commander, promises, glob, spaceTrim, waitasecond, prettier, parserHtml) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
10
  var commander__default = /*#__PURE__*/_interopDefaultLegacy(commander);
11
11
  var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
12
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
12
13
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
13
14
 
14
15
  /*! *****************************************************************************
@@ -146,7 +147,7 @@
146
147
  /**
147
148
  * The version of the Promptbook library
148
149
  */
149
- var PROMPTBOOK_VERSION = '0.59.0-1';
150
+ var PROMPTBOOK_VERSION = '0.59.0-20';
150
151
 
151
152
  /**
152
153
  * Removes HTML or Markdown comments from a string.
@@ -155,7 +156,7 @@
155
156
  * @returns {string} The input string with all comments removed.
156
157
  */
157
158
  function removeContentComments(content) {
158
- return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
159
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
159
160
  }
160
161
 
161
162
  /**
@@ -169,7 +170,7 @@
169
170
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
170
171
  var sectionMatch = content.match(sectionRegex);
171
172
  if (sectionMatch) {
172
- return content.replace(sectionRegex, spacetrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
173
+ return content.replace(sectionRegex, spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
173
174
  }
174
175
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
175
176
  if (!placeForSection) {
@@ -225,56 +226,73 @@
225
226
  return PromptbookSyntaxError;
226
227
  }(Error));
227
228
 
228
- // import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
229
- function prepareKnowledgeFromMarkdown(options) {
230
- return __awaiter(this, void 0, void 0, function () {
231
- return __generator(this, function (_a) {
232
- return [2 /*return*/, []];
233
- });
234
- });
235
- }
229
+ var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-20",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
236
230
 
237
231
  /**
238
- * Supported script languages
232
+ * This error indicates errors during the execution of the promptbook
239
233
  */
240
- var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
234
+ var PromptbookExecutionError = /** @class */ (function (_super) {
235
+ __extends(PromptbookExecutionError, _super);
236
+ function PromptbookExecutionError(message) {
237
+ var _this = _super.call(this, message) || this;
238
+ _this.name = 'PromptbookExecutionError';
239
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
240
+ return _this;
241
+ }
242
+ return PromptbookExecutionError;
243
+ }(Error));
241
244
 
242
245
  /**
243
- * Computes the deepness of the markdown structure.
246
+ * Asserts that the execution of a promptnook is successful
244
247
  *
245
- * @private within the library
248
+ * @param executionResult - The partial result of the promptnook execution
249
+ * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
246
250
  */
247
- function countMarkdownStructureDeepness(markdownStructure) {
248
- var e_1, _a;
249
- var maxDeepness = 0;
250
- try {
251
- for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
252
- var section = _c.value;
253
- maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
254
- }
251
+ function assertsExecutionSuccessful(executionResult) {
252
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
253
+ if (isSuccessful === true) {
254
+ return;
255
255
  }
256
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
257
- finally {
258
- try {
259
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
260
- }
261
- finally { if (e_1) throw e_1.error; }
256
+ if (errors.length === 0) {
257
+ throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
258
+ }
259
+ else if (errors.length === 1) {
260
+ throw errors[0];
261
+ }
262
+ else {
263
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
262
264
  }
263
- return maxDeepness + 1;
264
265
  }
266
+ /**
267
+ * TODO: [🧠] Can this return type be better typed than void
268
+ */
265
269
 
266
270
  /**
267
271
  * The maximum number of iterations for a loops
268
272
  */
269
273
  var LOOP_LIMIT = 1000;
270
274
 
275
+ /**
276
+ * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
277
+ */
278
+ var PromptbookLogicError = /** @class */ (function (_super) {
279
+ __extends(PromptbookLogicError, _super);
280
+ function PromptbookLogicError(message) {
281
+ var _this = _super.call(this, message) || this;
282
+ _this.name = 'PromptbookLogicError';
283
+ Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
284
+ return _this;
285
+ }
286
+ return PromptbookLogicError;
287
+ }(Error));
288
+
271
289
  /**
272
290
  * This error type indicates that the error should not happen and its last check before crashing with some other error
273
291
  */
274
292
  var UnexpectedError = /** @class */ (function (_super) {
275
293
  __extends(UnexpectedError, _super);
276
294
  function UnexpectedError(message) {
277
- 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;
295
+ 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;
278
296
  _this.name = 'UnexpectedError';
279
297
  Object.setPrototypeOf(_this, UnexpectedError.prototype);
280
298
  return _this;
@@ -283,1096 +301,2622 @@
283
301
  }(Error));
284
302
 
285
303
  /**
286
- * Parse a markdown string into a MarkdownStructure object.
287
- *
288
- * Note: This function does work with code blocks
289
- * Note: This function does not work with markdown comments
290
- *
291
- * @param markdown The markdown string to parse.
292
- * @returns The MarkdownStructure object.
304
+ * Tests if given string is valid URL.
293
305
  *
294
- * @private within the library
306
+ * Note: Dataurl are considered perfectly valid.
295
307
  */
296
- function markdownToMarkdownStructure(markdown) {
297
- var e_1, _a;
298
- var lines = markdown.split('\n');
299
- var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
300
- var current = root;
301
- var isInsideCodeBlock = false;
308
+ function isValidUrl(url) {
309
+ if (typeof url !== 'string') {
310
+ return false;
311
+ }
302
312
  try {
303
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
304
- var line = lines_1_1.value;
305
- var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
306
- if (isInsideCodeBlock || !headingMatch) {
307
- if (line.startsWith('```')) {
308
- isInsideCodeBlock = !isInsideCodeBlock;
309
- }
310
- current.contentLines.push(line);
311
- }
312
- else {
313
- var level = headingMatch.groups.mark.length;
314
- var title = headingMatch.groups.title.trim();
315
- var parent_1 = void 0;
316
- if (level > current.level) {
317
- // Note: Going deeper (next section is child of current)
318
- parent_1 = current;
319
- }
320
- else {
321
- // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
322
- parent_1 = current;
323
- var loopLimit = LOOP_LIMIT;
324
- while (parent_1.level !== level - 1) {
325
- if (loopLimit-- < 0) {
326
- throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
327
- }
328
- if (parent_1.parent === null /* <- Note: We are in root */) {
329
- // [🌻]
330
- throw new Error(spacetrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
331
- }
332
- parent_1 = parent_1.parent;
333
- }
334
- }
335
- var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
336
- parent_1.sections.push(section);
337
- current = section;
338
- }
313
+ if (url.startsWith('blob:')) {
314
+ url = url.replace(/^blob:/, '');
339
315
  }
340
- }
341
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
342
- finally {
343
- try {
344
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
+ var urlObject = new URL(url);
318
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
319
+ return false;
345
320
  }
346
- finally { if (e_1) throw e_1.error; }
321
+ return true;
347
322
  }
348
- if (root.sections.length === 1) {
349
- var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
350
- return markdownStructure;
323
+ catch (error) {
324
+ return false;
351
325
  }
352
- // [🌻]
353
- throw new Error('The markdown file must have exactly one top-level section.');
354
- // return root;
355
- }
356
- /**
357
- * @private
358
- */
359
- function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
360
- var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
361
- return {
362
- level: level,
363
- title: title,
364
- content: spacetrim.spaceTrim(contentLines.join('\n')),
365
- sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
366
- };
367
326
  }
368
327
 
369
328
  /**
370
- * Utility function to extract all list items from markdown
329
+ * Validates PromptbookJson if it is logically valid
371
330
  *
372
- * Note: It works with both ul and ol
373
- * Note: It omits list items in code blocks
374
- * Note: It flattens nested lists
375
- * Note: It can not work with html syntax and comments
331
+ * It checks:
332
+ * - if it has correct parameters dependency
376
333
  *
377
- * @param markdown any valid markdown
378
- * @returns
334
+ * It does NOT check:
335
+ * - if it is valid json
336
+ * - if it is meaningful
337
+ *
338
+ * @param promptbook valid or invalid PromptbookJson
339
+ * @returns the same promptbook if it is logically valid
340
+ * @throws {PromptbookLogicError} on logical error in the promptbook
379
341
  */
380
- function extractAllListItemsFromMarkdown(markdown) {
381
- var e_1, _a;
382
- var lines = markdown.split('\n');
383
- var listItems = [];
384
- var isInCodeBlock = false;
342
+ function validatePromptbookJson(promptbook) {
343
+ // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
344
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
345
+ if (promptbook.promptbookUrl !== undefined) {
346
+ if (!isValidUrl(promptbook.promptbookUrl)) {
347
+ // TODO: This should be maybe the syntax error detected during parsing
348
+ throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
349
+ }
350
+ }
351
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
352
+ if (!Array.isArray(promptbook.parameters)) {
353
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
354
+ 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 ")));
355
+ }
356
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
357
+ if (!Array.isArray(promptbook.promptTemplates)) {
358
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
359
+ 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 ")));
360
+ }
361
+ var _loop_1 = function (parameter) {
362
+ if (parameter.isInput && parameter.isOutput) {
363
+ throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
364
+ }
365
+ // Note: Testing that parameter is either intermediate or output BUT not created and unused
366
+ if (!parameter.isInput &&
367
+ !parameter.isOutput &&
368
+ !promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
369
+ 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 ")));
370
+ }
371
+ // Note: Testing that parameter is either input or result of some template
372
+ if (!parameter.isInput &&
373
+ !promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
374
+ 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 ")));
375
+ }
376
+ };
385
377
  try {
386
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
387
- var line = lines_1_1.value;
388
- var trimmedLine = line.trim();
389
- if (trimmedLine.startsWith('```')) {
390
- isInCodeBlock = !isInCodeBlock;
391
- }
392
- if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
393
- var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
394
- listItems.push(listItem);
395
- }
378
+ // Note: Check each parameter individually
379
+ for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
380
+ var parameter = _f.value;
381
+ _loop_1(parameter);
396
382
  }
397
383
  }
398
384
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
399
385
  finally {
400
386
  try {
401
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
387
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
402
388
  }
403
389
  finally { if (e_1) throw e_1.error; }
404
390
  }
405
- return listItems;
406
- }
407
-
408
- /**
409
- * Makes first letter of a string uppercase
410
- *
411
- */
412
- function capitalize(word) {
413
- return word.substring(0, 1).toUpperCase() + word.substring(1);
414
- }
415
-
416
- /**
417
- * Extracts all code blocks from markdown.
418
- *
419
- * Note: There are 3 simmilar function:
420
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
421
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
422
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
423
- *
424
- * @param markdown any valid markdown
425
- * @returns code blocks with language and content
426
- *
427
- */
428
- function extractAllBlocksFromMarkdown(markdown) {
429
- var e_1, _a;
430
- var codeBlocks = [];
431
- var lines = markdown.split('\n');
432
- var currentCodeBlock = null;
391
+ // Note: Check each template individually
392
+ var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
393
+ var isInput = _a.isInput;
394
+ return isInput;
395
+ }).map(function (_a) {
396
+ var name = _a.name;
397
+ return name;
398
+ }));
433
399
  try {
434
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
435
- var line = lines_1_1.value;
436
- if (line.startsWith('```')) {
437
- var language = line.slice(3).trim() || null;
438
- if (currentCodeBlock === null) {
439
- currentCodeBlock = { language: language, content: '' };
400
+ for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
401
+ var template = _h.value;
402
+ if (definedParameters.has(template.resultingParameterName)) {
403
+ throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
404
+ }
405
+ definedParameters.add(template.resultingParameterName);
406
+ if (template.executionType === 'PROMPT_TEMPLATE' &&
407
+ (template.modelRequirements.modelVariant === undefined)) {
408
+ 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 ")));
409
+ }
410
+ if (template.jokers && template.jokers.length > 0) {
411
+ if (!template.expectFormat &&
412
+ !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
413
+ throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
440
414
  }
441
- else {
442
- if (language !== null) {
443
- // [🌻]
444
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
415
+ try {
416
+ for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
417
+ var joker = _k.value;
418
+ if (!template.dependentParameterNames.includes(joker)) {
419
+ throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
420
+ }
445
421
  }
446
- codeBlocks.push(currentCodeBlock);
447
- currentCodeBlock = null;
422
+ }
423
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
424
+ finally {
425
+ try {
426
+ if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
427
+ }
428
+ finally { if (e_3) throw e_3.error; }
448
429
  }
449
430
  }
450
- else if (currentCodeBlock !== null) {
451
- if (currentCodeBlock.content !== '') {
452
- currentCodeBlock.content += '\n';
431
+ if (template.expectations) {
432
+ try {
433
+ for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
434
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
435
+ if (min !== undefined && max !== undefined && min > max) {
436
+ throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
437
+ }
438
+ if (min !== undefined && min < 0) {
439
+ throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
440
+ }
441
+ if (max !== undefined && max <= 0) {
442
+ throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
443
+ }
444
+ }
445
+ }
446
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
447
+ finally {
448
+ try {
449
+ if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
450
+ }
451
+ finally { if (e_4) throw e_4.error; }
453
452
  }
454
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
455
453
  }
456
454
  }
457
455
  }
458
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
456
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
459
457
  finally {
460
458
  try {
461
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
459
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
462
460
  }
463
- finally { if (e_1) throw e_1.error; }
461
+ finally { if (e_2) throw e_2.error; }
464
462
  }
465
- if (currentCodeBlock !== null) {
466
- // [🌻]
467
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
463
+ // Note: Detect circular dependencies
464
+ var resovedParameters = promptbook.parameters
465
+ .filter(function (_a) {
466
+ var isInput = _a.isInput;
467
+ return isInput;
468
+ })
469
+ .map(function (_a) {
470
+ var name = _a.name;
471
+ return name;
472
+ });
473
+ var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
474
+ var loopLimit = LOOP_LIMIT;
475
+ var _loop_2 = function () {
476
+ if (loopLimit-- < 0) {
477
+ throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
478
+ }
479
+ var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
480
+ return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
481
+ });
482
+ if (currentlyResovedTemplates.length === 0) {
483
+ 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
484
+ .map(function (_a) {
485
+ var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
486
+ return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
487
+ .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
488
+ .join(', '));
489
+ })
490
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
491
+ }
492
+ resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
493
+ var resultingParameterName = _a.resultingParameterName;
494
+ return resultingParameterName;
495
+ })), false);
496
+ unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
497
+ };
498
+ while (unresovedTemplates.length > 0) {
499
+ _loop_2();
468
500
  }
469
- return codeBlocks;
501
+ return promptbook;
470
502
  }
503
+ /**
504
+ * TODO: [🧠] Work with promptbookVersion
505
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
506
+ * > /**
507
+ * > * Validates PromptbookJson if it is logically valid.
508
+ * > *
509
+ * > * It checks:
510
+ * > * - it has a valid structure
511
+ * > * - ...
512
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
513
+ */
471
514
 
472
515
  /**
473
- * Extracts exactly ONE code block from markdown.
474
- *
475
- * Note: If there are multiple or no code blocks the function throws an error
476
- *
477
- * Note: There are 3 simmilar function:
478
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
479
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
480
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
516
+ * This error occurs when some expectation is not met in the execution of the pipeline
481
517
  *
482
- * @param markdown any valid markdown
483
- * @returns code block with language and content
518
+ * @private Always catched and rethrown as `PromptbookExecutionError`
519
+ * Note: This is a kindof subtype of PromptbookExecutionError
484
520
  */
485
- function extractOneBlockFromMarkdown(markdown) {
486
- var codeBlocks = extractAllBlocksFromMarkdown(markdown);
487
- if (codeBlocks.length !== 1) {
488
- // TODO: Report more specific place where the error happened
489
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
521
+ var ExpectError = /** @class */ (function (_super) {
522
+ __extends(ExpectError, _super);
523
+ function ExpectError(message) {
524
+ var _this = _super.call(this, message) || this;
525
+ _this.name = 'ExpectError';
526
+ Object.setPrototypeOf(_this, ExpectError.prototype);
527
+ return _this;
490
528
  }
491
- return codeBlocks[0];
492
- }
493
- /***
494
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
495
- */
529
+ return ExpectError;
530
+ }(Error));
496
531
 
497
532
  /**
498
- * Creates a new set with all elements that are present in either set
533
+ * Function isValidJsonString will tell you if the string is valid JSON or not
499
534
  */
500
- function union() {
501
- var e_1, _a, e_2, _b;
502
- var sets = [];
503
- for (var _i = 0; _i < arguments.length; _i++) {
504
- sets[_i] = arguments[_i];
505
- }
506
- var union = new Set();
507
- try {
508
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
509
- var set = sets_1_1.value;
510
- try {
511
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
512
- var item = _d.value;
513
- union.add(item);
514
- }
515
- }
516
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
517
- finally {
518
- try {
519
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
520
- }
521
- finally { if (e_2) throw e_2.error; }
522
- }
523
- }
524
- }
525
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
526
- finally {
527
- try {
528
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
529
- }
530
- finally { if (e_1) throw e_1.error; }
531
- }
532
- return union;
533
- }
534
-
535
- /**
536
- * Parses the template and returns the list of all parameter names
537
- *
538
- * @param template the template with parameters in {curly} braces
539
- * @returns the list of parameter names
540
- */
541
- function extractParameters(template) {
542
- var e_1, _a;
543
- var matches = template.matchAll(/{\w+}/g);
544
- var parameterNames = new Set();
545
- try {
546
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
547
- var match = matches_1_1.value;
548
- var parameterName = match[0].slice(1, -1);
549
- parameterNames.add(parameterName);
550
- }
551
- }
552
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
553
- finally {
554
- try {
555
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
556
- }
557
- finally { if (e_1) throw e_1.error; }
558
- }
559
- return parameterNames;
560
- }
561
-
562
- /**
563
- * Parses the given script and returns the list of all used variables that are not defined in the script
564
- *
565
- * @param script from which to extract the variables
566
- * @returns the list of variable names
567
- * @throws {PromptbookSyntaxError} if the script is invalid
568
- */
569
- function extractVariables(script) {
570
- var variables = new Set();
571
- script = "(()=>{".concat(script, "})()");
535
+ function isValidJsonString(value /* <-[👨‍⚖️] */) {
572
536
  try {
573
- for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
574
- try {
575
- eval(script);
576
- }
577
- catch (error) {
578
- if (!(error instanceof ReferenceError)) {
579
- throw error;
580
- }
581
- var undefinedName = error.message.split(' ')[0];
582
- /*
583
- Note: Remapping error
584
- From: [ReferenceError: thing is not defined],
585
- To: [Error: Parameter {thing} is not defined],
586
- */
587
- if (!undefinedName) {
588
- throw error;
589
- }
590
- if (script.includes(undefinedName + '(')) {
591
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
592
- }
593
- else {
594
- variables.add(undefinedName);
595
- script = "const ".concat(undefinedName, " = '';") + script;
596
- }
597
- }
537
+ JSON.parse(value);
538
+ return true;
598
539
  }
599
540
  catch (error) {
600
541
  if (!(error instanceof Error)) {
601
542
  throw error;
602
543
  }
603
- 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 "); }));
544
+ if (error.message.includes('Unexpected token')) {
545
+ return false;
546
+ }
547
+ return false;
604
548
  }
605
- return variables;
606
549
  }
607
- /**
608
- * TODO: [🔣] Support for multiple languages - python, java,...
609
- */
610
550
 
611
551
  /**
612
- * Parses the prompt template and returns the set of all used parameters
552
+ * Function `addUsage` will add multiple usages into one
613
553
  *
614
- * @param promptTemplate the template with used parameters
615
- * @returns the set of parameter names
616
- * @throws {PromptbookSyntaxError} if the script is invalid
554
+ * Note: If you provide 0 values, it returns void usage
617
555
  */
618
- function extractParametersFromPromptTemplate(promptTemplate) {
619
- var e_1, _a, e_2, _b;
620
- var parameterNames = new Set();
621
- try {
622
- 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()) {
623
- var parameterName = _d.value;
624
- parameterNames.add(parameterName);
625
- }
556
+ function addUsage() {
557
+ var usageItems = [];
558
+ for (var _i = 0; _i < arguments.length; _i++) {
559
+ usageItems[_i] = arguments[_i];
626
560
  }
627
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
628
- finally {
561
+ var initialStructure = {
562
+ price: { value: 0 },
563
+ input: {
564
+ tokensCount: { value: 0 },
565
+ charactersCount: { value: 0 },
566
+ wordsCount: { value: 0 },
567
+ sentencesCount: { value: 0 },
568
+ linesCount: { value: 0 },
569
+ paragraphsCount: { value: 0 },
570
+ pagesCount: { value: 0 },
571
+ },
572
+ output: {
573
+ tokensCount: { value: 0 },
574
+ charactersCount: { value: 0 },
575
+ wordsCount: { value: 0 },
576
+ sentencesCount: { value: 0 },
577
+ linesCount: { value: 0 },
578
+ paragraphsCount: { value: 0 },
579
+ pagesCount: { value: 0 },
580
+ },
581
+ };
582
+ return usageItems.reduce(function (acc, item) {
583
+ var e_1, _a, e_2, _b;
584
+ var _c;
585
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
629
586
  try {
630
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
587
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
588
+ var key = _e.value;
589
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
590
+ //@ts-ignore
591
+ if (item.input[key]) {
592
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
593
+ //@ts-ignore
594
+ acc.input[key].value += item.input[key].value || 0;
595
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
596
+ //@ts-ignore
597
+ if (item.input[key].isUncertain) {
598
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
599
+ //@ts-ignore
600
+ acc.input[key].isUncertain = true;
601
+ }
602
+ }
603
+ }
604
+ }
605
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
606
+ finally {
607
+ try {
608
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
609
+ }
610
+ finally { if (e_1) throw e_1.error; }
631
611
  }
632
- finally { if (e_1) throw e_1.error; }
633
- }
634
- if (promptTemplate.executionType === 'SCRIPT') {
635
612
  try {
636
- for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
637
- var parameterName = _f.value;
638
- parameterNames.add(parameterName);
613
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
614
+ var key = _g.value;
615
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
616
+ //@ts-ignore
617
+ if (item.output[key]) {
618
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
619
+ //@ts-ignore
620
+ acc.output[key].value += item.output[key].value || 0;
621
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
622
+ //@ts-ignore
623
+ if (item.output[key].isUncertain) {
624
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
625
+ //@ts-ignore
626
+ acc.output[key].isUncertain = true;
627
+ }
628
+ }
639
629
  }
640
630
  }
641
631
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
642
632
  finally {
643
633
  try {
644
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
634
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
645
635
  }
646
636
  finally { if (e_2) throw e_2.error; }
647
637
  }
648
- }
649
- return parameterNames;
638
+ return acc;
639
+ }, initialStructure);
650
640
  }
651
- /**
652
- * TODO: [🔣] If script require contentLanguage
653
- */
654
641
 
655
- /* tslint:disable */
656
- /*
657
- TODO: Tests
658
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
659
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
660
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
661
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
662
- */
663
- function normalizeTo_SCREAMING_CASE(sentence) {
664
- var e_1, _a;
665
- var charType;
666
- var lastCharType = 'OTHER';
667
- var normalizedName = '';
668
- try {
669
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
670
- var char = sentence_1_1.value;
671
- var normalizedChar = void 0;
672
- if (/^[a-z]$/.test(char)) {
673
- charType = 'LOWERCASE';
674
- normalizedChar = char.toUpperCase();
675
- }
676
- else if (/^[A-Z]$/.test(char)) {
677
- charType = 'UPPERCASE';
678
- normalizedChar = char;
679
- }
680
- else if (/^[0-9]$/.test(char)) {
681
- charType = 'NUMBER';
682
- normalizedChar = char;
683
- }
684
- else if (/^\/$/.test(char)) {
685
- charType = 'SLASH';
686
- normalizedChar = char;
687
- }
688
- else {
689
- charType = 'OTHER';
690
- normalizedChar = '_';
691
- }
692
- if (charType !== lastCharType &&
693
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
694
- !(lastCharType === 'NUMBER') &&
695
- !(charType === 'NUMBER')) {
696
- normalizedName += '_';
697
- }
698
- normalizedName += normalizedChar;
699
- lastCharType = charType;
700
- }
701
- }
702
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
703
- finally {
704
- try {
705
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
706
- }
707
- finally { if (e_1) throw e_1.error; }
708
- }
709
- normalizedName = normalizedName.replace(/_+/g, '_');
710
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
711
- normalizedName = normalizedName.replace(/^_/, '');
712
- normalizedName = normalizedName.replace(/_$/, '');
713
- return normalizedName;
714
- }
715
642
  /**
716
- * TODO: [🌺] Use some intermediate util splitWords
643
+ * Counts number of characters in the text
717
644
  */
645
+ function countCharacters(text) {
646
+ // Remove null characters
647
+ text = text.replace(/\0/g, '');
648
+ // Replace emojis (and also ZWJ sequence) with hyphens
649
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
650
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
651
+ text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
652
+ return text.length;
653
+ }
718
654
 
719
655
  /**
720
- * Execution type describes the way how the block is executed
721
- *
722
- * @see https://github.com/webgptorg/promptbook#execution-type
656
+ * Counts number of lines in the text
723
657
  */
724
- var ExecutionTypes = [
725
- 'PROMPT_TEMPLATE',
726
- 'SIMPLE_TEMPLATE',
727
- 'SCRIPT',
728
- 'PROMPT_DIALOG',
729
- // <- [🥻] Insert here when making new command
730
- ];
658
+ function countLines(text) {
659
+ if (text === '') {
660
+ return 0;
661
+ }
662
+ return text.split('\n').length;
663
+ }
731
664
 
732
665
  /**
733
- * Units of text measurement
666
+ * Counts number of pages in the text
734
667
  */
735
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
668
+ function countPages(text) {
669
+ var sentencesPerPage = 5; // Assuming each page has 5 sentences
670
+ var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
671
+ var pageCount = Math.ceil(sentences.length / sentencesPerPage);
672
+ return pageCount;
673
+ }
674
+
736
675
  /**
737
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
738
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
739
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
676
+ * Counts number of paragraphs in the text
740
677
  */
678
+ function countParagraphs(text) {
679
+ return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
680
+ }
741
681
 
742
682
  /**
743
- * Removes Markdown formatting tags from a string.
744
- *
745
- * @param {string} str - The string to remove Markdown tags from.
746
- * @returns {string} The input string with all Markdown tags removed.
683
+ * Split text into sentences
747
684
  */
748
- function removeMarkdownFormatting(str) {
749
- // Remove bold formatting
750
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
751
- // Remove italic formatting
752
- str = str.replace(/\*(.*?)\*/g, '$1');
753
- // Remove code formatting
754
- str = str.replace(/`(.*?)`/g, '$1');
755
- return str;
685
+ function splitIntoSentences(text) {
686
+ return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
756
687
  }
757
-
758
688
  /**
759
- * Function parseNumber will parse number from string
760
- *
761
- * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
762
- * Note: it also works only with decimal numbers
763
- *
764
- * @returns parsed number
765
- * @throws {PromptbookSyntaxError} if the value is not a number
766
- *
767
- * @private within the parseCommand
689
+ * Counts number of sentences in the text
768
690
  */
769
- function parseNumber(value) {
770
- var originalValue = value;
771
- if (typeof value === 'number') {
772
- value = value.toString(); // <- TODO: Maybe more efficient way to do this
773
- }
774
- if (typeof value !== 'string') {
775
- return 0;
776
- }
777
- value = value.trim();
778
- if (value.startsWith('+')) {
779
- return parseNumber(value.substring(1));
780
- }
781
- if (value.startsWith('-')) {
782
- var number = parseNumber(value.substring(1));
783
- if (number === 0) {
784
- return 0; // <- Note: To prevent -0
691
+ function countSentences(text) {
692
+ return splitIntoSentences(text).length;
693
+ }
694
+
695
+ var defaultDiacriticsRemovalMap = [
696
+ {
697
+ base: 'A',
698
+ 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',
699
+ },
700
+ { base: 'AA', letters: '\uA732' },
701
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
702
+ { base: 'AO', letters: '\uA734' },
703
+ { base: 'AU', letters: '\uA736' },
704
+ { base: 'AV', letters: '\uA738\uA73A' },
705
+ { base: 'AY', letters: '\uA73C' },
706
+ {
707
+ base: 'B',
708
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
709
+ },
710
+ {
711
+ base: 'C',
712
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
713
+ },
714
+ {
715
+ base: 'D',
716
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
717
+ },
718
+ { base: 'DZ', letters: '\u01F1\u01C4' },
719
+ { base: 'Dz', letters: '\u01F2\u01C5' },
720
+ {
721
+ base: 'E',
722
+ 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',
723
+ },
724
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
725
+ {
726
+ base: 'G',
727
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
728
+ },
729
+ {
730
+ base: 'H',
731
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
732
+ },
733
+ {
734
+ base: 'I',
735
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
736
+ },
737
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
738
+ {
739
+ base: 'K',
740
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
741
+ },
742
+ {
743
+ base: 'L',
744
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
745
+ },
746
+ { base: 'LJ', letters: '\u01C7' },
747
+ { base: 'Lj', letters: '\u01C8' },
748
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
749
+ {
750
+ base: 'N',
751
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
752
+ },
753
+ { base: 'NJ', letters: '\u01CA' },
754
+ { base: 'Nj', letters: '\u01CB' },
755
+ {
756
+ base: 'O',
757
+ 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',
758
+ },
759
+ { base: 'OI', letters: '\u01A2' },
760
+ { base: 'OO', letters: '\uA74E' },
761
+ { base: 'OU', letters: '\u0222' },
762
+ { base: 'OE', letters: '\u008C\u0152' },
763
+ { base: 'oe', letters: '\u009C\u0153' },
764
+ {
765
+ base: 'P',
766
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
767
+ },
768
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
769
+ {
770
+ base: 'R',
771
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
772
+ },
773
+ {
774
+ base: 'S',
775
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
776
+ },
777
+ {
778
+ base: 'T',
779
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
780
+ },
781
+ { base: 'TZ', letters: '\uA728' },
782
+ {
783
+ base: 'U',
784
+ 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',
785
+ },
786
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
787
+ { base: 'VY', letters: '\uA760' },
788
+ {
789
+ base: 'W',
790
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
791
+ },
792
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
793
+ {
794
+ base: 'Y',
795
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
796
+ },
797
+ {
798
+ base: 'Z',
799
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
800
+ },
801
+ {
802
+ base: 'a',
803
+ 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',
804
+ },
805
+ { base: 'aa', letters: '\uA733' },
806
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
807
+ { base: 'ao', letters: '\uA735' },
808
+ { base: 'au', letters: '\uA737' },
809
+ { base: 'av', letters: '\uA739\uA73B' },
810
+ { base: 'ay', letters: '\uA73D' },
811
+ {
812
+ base: 'b',
813
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
814
+ },
815
+ {
816
+ base: 'c',
817
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
818
+ },
819
+ {
820
+ base: 'd',
821
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
822
+ },
823
+ { base: 'dz', letters: '\u01F3\u01C6' },
824
+ {
825
+ base: 'e',
826
+ 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',
827
+ },
828
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
829
+ {
830
+ base: 'g',
831
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
832
+ },
833
+ {
834
+ base: 'h',
835
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
836
+ },
837
+ { base: 'hv', letters: '\u0195' },
838
+ {
839
+ base: 'i',
840
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
841
+ },
842
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
843
+ {
844
+ base: 'k',
845
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
846
+ },
847
+ {
848
+ base: 'l',
849
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
850
+ },
851
+ { base: 'lj', letters: '\u01C9' },
852
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
853
+ {
854
+ base: 'n',
855
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
856
+ },
857
+ { base: 'nj', letters: '\u01CC' },
858
+ {
859
+ base: 'o',
860
+ 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',
861
+ },
862
+ { base: 'oi', letters: '\u01A3' },
863
+ { base: 'ou', letters: '\u0223' },
864
+ { base: 'oo', letters: '\uA74F' },
865
+ {
866
+ base: 'p',
867
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
868
+ },
869
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
870
+ {
871
+ base: 'r',
872
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
873
+ },
874
+ {
875
+ base: 's',
876
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
877
+ },
878
+ {
879
+ base: 't',
880
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
881
+ },
882
+ { base: 'tz', letters: '\uA729' },
883
+ {
884
+ base: 'u',
885
+ 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',
886
+ },
887
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
888
+ { base: 'vy', letters: '\uA761' },
889
+ {
890
+ base: 'w',
891
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
892
+ },
893
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
894
+ {
895
+ base: 'y',
896
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
897
+ },
898
+ {
899
+ base: 'z',
900
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
901
+ },
902
+ ];
903
+ /**
904
+ * Map of letters from diacritic variant to diacritless variant
905
+ * Contains lowercase and uppercase separatelly
906
+ *
907
+ * > "á" => "a"
908
+ * > "ě" => "e"
909
+ * > "Ă" => "A"
910
+ * > ...
911
+ */
912
+ var DIACRITIC_VARIANTS_LETTERS = {};
913
+ // tslint:disable-next-line: prefer-for-of
914
+ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
915
+ var letters = defaultDiacriticsRemovalMap[i].letters;
916
+ // tslint:disable-next-line: prefer-for-of
917
+ for (var j = 0; j < letters.length; j++) {
918
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
919
+ }
920
+ }
921
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
922
+ /*
923
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
924
+ Licensed under the Apache License, Version 2.0 (the "License");
925
+ you may not use this file except in compliance with the License.
926
+ You may obtain a copy of the License at
927
+
928
+ http://www.apache.org/licenses/LICENSE-2.0
929
+
930
+ Unless required by applicable law or agreed to in writing, software
931
+ distributed under the License is distributed on an "AS IS" BASIS,
932
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
933
+ See the License for the specific language governing permissions and
934
+ limitations under the License.
935
+ */
936
+
937
+ /**
938
+ *
939
+ */
940
+ function removeDiacritics(input) {
941
+ /*eslint no-control-regex: "off"*/
942
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
943
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
944
+ });
945
+ }
946
+
947
+ /**
948
+ * Counts number of words in the text
949
+ */
950
+ function countWords(text) {
951
+ text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
952
+ text = removeDiacritics(text);
953
+ return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
954
+ }
955
+
956
+ /**
957
+ * Index of all counter functions
958
+ */
959
+ var CountUtils = {
960
+ CHARACTERS: countCharacters,
961
+ WORDS: countWords,
962
+ SENTENCES: countSentences,
963
+ PARAGRAPHS: countParagraphs,
964
+ LINES: countLines,
965
+ PAGES: countPages,
966
+ };
967
+
968
+ /**
969
+ * Function checkExpectations will check if the expectations on given value are met
970
+ *
971
+ * Note: There are two simmilar functions:
972
+ * - `checkExpectations` which throws an error if the expectations are not met
973
+ * - `isPassingExpectations` which returns a boolean
974
+ *
975
+ * @throws {ExpectError} if the expectations are not met
976
+ * @returns {void} Nothing
977
+ */
978
+ function checkExpectations(expectations, value) {
979
+ var e_1, _a;
980
+ try {
981
+ for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
982
+ var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
983
+ var amount = CountUtils[unit.toUpperCase()](value);
984
+ if (min && amount < min) {
985
+ throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
986
+ } /* not else */
987
+ if (max && amount > max) {
988
+ throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
989
+ }
990
+ }
991
+ }
992
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
993
+ finally {
994
+ try {
995
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
996
+ }
997
+ finally { if (e_1) throw e_1.error; }
998
+ }
999
+ }
1000
+ /**
1001
+ * TODO: [💝] Unite object for expecting amount and format
1002
+ */
1003
+
1004
+ /**
1005
+ * This error occurs during the parameter replacement in the template
1006
+ *
1007
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
1008
+ */
1009
+ var TemplateError = /** @class */ (function (_super) {
1010
+ __extends(TemplateError, _super);
1011
+ function TemplateError(message) {
1012
+ var _this = _super.call(this, message) || this;
1013
+ _this.name = 'TemplateError';
1014
+ Object.setPrototypeOf(_this, TemplateError.prototype);
1015
+ return _this;
1016
+ }
1017
+ return TemplateError;
1018
+ }(Error));
1019
+
1020
+ /**
1021
+ * Replaces parameters in template with values from parameters object
1022
+ *
1023
+ * @param template the template with parameters in {curly} braces
1024
+ * @param parameters the object with parameters
1025
+ * @returns the template with replaced parameters
1026
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
1027
+ *
1028
+ * @private within the createPromptbookExecutor
1029
+ */
1030
+ function replaceParameters(template, parameters) {
1031
+ var replacedTemplate = template;
1032
+ var match;
1033
+ var loopLimit = LOOP_LIMIT;
1034
+ var _loop_1 = function () {
1035
+ if (loopLimit-- < 0) {
1036
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
1037
+ }
1038
+ var precol = match.groups.precol;
1039
+ var parameterName = match.groups.parameterName;
1040
+ if (parameterName === '') {
1041
+ return "continue";
1042
+ }
1043
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
1044
+ throw new TemplateError('Parameter is already opened or not closed');
1045
+ }
1046
+ if (parameters[parameterName] === undefined) {
1047
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
1048
+ }
1049
+ var parameterValue = parameters[parameterName];
1050
+ if (parameterValue === undefined) {
1051
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
1052
+ }
1053
+ parameterValue = parameterValue.toString();
1054
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
1055
+ parameterValue = parameterValue
1056
+ .split('\n')
1057
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
1058
+ .join('\n');
1059
+ }
1060
+ replacedTemplate =
1061
+ replacedTemplate.substring(0, match.index + precol.length) +
1062
+ parameterValue +
1063
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
1064
+ };
1065
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1066
+ .exec(replacedTemplate))) {
1067
+ _loop_1();
1068
+ }
1069
+ // [💫] Check if there are parameters that are not closed properly
1070
+ if (/{\w+$/.test(replacedTemplate)) {
1071
+ throw new TemplateError('Parameter is not closed');
1072
+ }
1073
+ // [💫] Check if there are parameters that are not opened properly
1074
+ if (/^\w+}/.test(replacedTemplate)) {
1075
+ throw new TemplateError('Parameter is not opened');
1076
+ }
1077
+ return replacedTemplate;
1078
+ }
1079
+
1080
+ /**
1081
+ * Creates executor function from promptbook and execution tools.
1082
+ *
1083
+ * @returns The executor function
1084
+ * @throws {PromptbookLogicError} on logical error in the promptbook
1085
+ */
1086
+ function createPromptbookExecutor(options) {
1087
+ var _this = this;
1088
+ var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
1089
+ var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
1090
+ validatePromptbookJson(promptbook);
1091
+ var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1092
+ function executeSingleTemplate(currentTemplate) {
1093
+ return __awaiter(this, void 0, void 0, function () {
1094
+ var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
1095
+ var e_2, _j, e_4, _k, e_3, _l, _m;
1096
+ var _this = this;
1097
+ return __generator(this, function (_o) {
1098
+ switch (_o.label) {
1099
+ case 0:
1100
+ name = "promptbook-executor-frame-".concat(currentTemplate.name);
1101
+ title = currentTemplate.title;
1102
+ priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
1103
+ if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
1104
+ return [4 /*yield*/, onProgress({
1105
+ name: name,
1106
+ title: title,
1107
+ isStarted: false,
1108
+ isDone: false,
1109
+ executionType: currentTemplate.executionType,
1110
+ parameterName: currentTemplate.resultingParameterName,
1111
+ parameterValue: null,
1112
+ // <- [3]
1113
+ })];
1114
+ case 1:
1115
+ _o.sent();
1116
+ _o.label = 2;
1117
+ case 2:
1118
+ result = null;
1119
+ resultString = null;
1120
+ expectError = null;
1121
+ maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
1122
+ jokers = currentTemplate.jokers || [];
1123
+ attempt = -jokers.length;
1124
+ _o.label = 3;
1125
+ case 3:
1126
+ if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
1127
+ isJokerAttempt = attempt < 0;
1128
+ joker = jokers[jokers.length + attempt];
1129
+ if (isJokerAttempt && !joker) {
1130
+ throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
1131
+ }
1132
+ result = null;
1133
+ resultString = null;
1134
+ expectError = null;
1135
+ if (isJokerAttempt) {
1136
+ if (typeof parametersToPass[joker] === 'undefined') {
1137
+ throw new PromptbookExecutionError("Joker parameter {".concat(joker, "} not defined"));
1138
+ }
1139
+ resultString = parametersToPass[joker];
1140
+ }
1141
+ _o.label = 4;
1142
+ case 4:
1143
+ _o.trys.push([4, 45, 46, 47]);
1144
+ if (!!isJokerAttempt) return [3 /*break*/, 27];
1145
+ _a = currentTemplate.executionType;
1146
+ switch (_a) {
1147
+ case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
1148
+ case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
1149
+ case 'SCRIPT': return [3 /*break*/, 13];
1150
+ case 'PROMPT_DIALOG': return [3 /*break*/, 24];
1151
+ }
1152
+ return [3 /*break*/, 26];
1153
+ case 5:
1154
+ resultString = replaceParameters(currentTemplate.content, parametersToPass);
1155
+ return [3 /*break*/, 27];
1156
+ case 6:
1157
+ prompt = {
1158
+ title: currentTemplate.title,
1159
+ promptbookUrl: "".concat(promptbook.promptbookUrl
1160
+ ? promptbook.promptbookUrl
1161
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
1162
+ parameters: parametersToPass,
1163
+ content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
1164
+ modelRequirements: currentTemplate.modelRequirements,
1165
+ expectations: currentTemplate.expectations,
1166
+ expectFormat: currentTemplate.expectFormat,
1167
+ postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
1168
+ var errors, _a, _b, scriptTools, error_5, e_5_1;
1169
+ var e_5, _c;
1170
+ return __generator(this, function (_d) {
1171
+ switch (_d.label) {
1172
+ case 0:
1173
+ errors = [];
1174
+ _d.label = 1;
1175
+ case 1:
1176
+ _d.trys.push([1, 8, 9, 10]);
1177
+ _a = __values(tools.script), _b = _a.next();
1178
+ _d.label = 2;
1179
+ case 2:
1180
+ if (!!_b.done) return [3 /*break*/, 7];
1181
+ scriptTools = _b.value;
1182
+ _d.label = 3;
1183
+ case 3:
1184
+ _d.trys.push([3, 5, , 6]);
1185
+ return [4 /*yield*/, scriptTools.execute({
1186
+ scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
1187
+ script: "".concat(functionName, "(result)"),
1188
+ parameters: {
1189
+ result: result || '',
1190
+ // Note: No ...parametersToPass, because working with result only
1191
+ },
1192
+ })];
1193
+ case 4: return [2 /*return*/, _d.sent()];
1194
+ case 5:
1195
+ error_5 = _d.sent();
1196
+ if (!(error_5 instanceof Error)) {
1197
+ throw error_5;
1198
+ }
1199
+ errors.push(error_5);
1200
+ return [3 /*break*/, 6];
1201
+ case 6:
1202
+ _b = _a.next();
1203
+ return [3 /*break*/, 2];
1204
+ case 7: return [3 /*break*/, 10];
1205
+ case 8:
1206
+ e_5_1 = _d.sent();
1207
+ e_5 = { error: e_5_1 };
1208
+ return [3 /*break*/, 10];
1209
+ case 9:
1210
+ try {
1211
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1212
+ }
1213
+ finally { if (e_5) throw e_5.error; }
1214
+ return [7 /*endfinally*/];
1215
+ case 10:
1216
+ if (errors.length === 0) {
1217
+ throw new PromptbookExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
1218
+ }
1219
+ else if (errors.length === 1) {
1220
+ throw errors[0];
1221
+ }
1222
+ else {
1223
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
1224
+ }
1225
+ }
1226
+ });
1227
+ }); }; }),
1228
+ };
1229
+ _b = currentTemplate.modelRequirements.modelVariant;
1230
+ switch (_b) {
1231
+ case 'CHAT': return [3 /*break*/, 7];
1232
+ case 'COMPLETION': return [3 /*break*/, 9];
1233
+ }
1234
+ return [3 /*break*/, 11];
1235
+ case 7: return [4 /*yield*/, tools.llm.gptChat(prompt)];
1236
+ case 8:
1237
+ chatThread = _o.sent();
1238
+ // TODO: [🍬] Destroy chatThread
1239
+ result = chatThread;
1240
+ resultString = chatThread.content;
1241
+ return [3 /*break*/, 12];
1242
+ case 9: return [4 /*yield*/, tools.llm.gptComplete(prompt)];
1243
+ case 10:
1244
+ completionResult = _o.sent();
1245
+ result = completionResult;
1246
+ resultString = completionResult.content;
1247
+ return [3 /*break*/, 12];
1248
+ case 11: throw new PromptbookExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
1249
+ case 12: return [3 /*break*/, 27];
1250
+ case 13:
1251
+ if (tools.script.length === 0) {
1252
+ throw new PromptbookExecutionError('No script execution tools are available');
1253
+ }
1254
+ if (!currentTemplate.contentLanguage) {
1255
+ throw new PromptbookExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
1256
+ }
1257
+ // TODO: DRY [1]
1258
+ scriptExecutionErrors = [];
1259
+ _o.label = 14;
1260
+ case 14:
1261
+ _o.trys.push([14, 21, 22, 23]);
1262
+ _c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
1263
+ _o.label = 15;
1264
+ case 15:
1265
+ if (!!_d.done) return [3 /*break*/, 20];
1266
+ scriptTools = _d.value;
1267
+ _o.label = 16;
1268
+ case 16:
1269
+ _o.trys.push([16, 18, , 19]);
1270
+ return [4 /*yield*/, scriptTools.execute({
1271
+ scriptLanguage: currentTemplate.contentLanguage,
1272
+ script: currentTemplate.content,
1273
+ parameters: parametersToPass,
1274
+ })];
1275
+ case 17:
1276
+ resultString = _o.sent();
1277
+ return [3 /*break*/, 20];
1278
+ case 18:
1279
+ error_2 = _o.sent();
1280
+ if (!(error_2 instanceof Error)) {
1281
+ throw error_2;
1282
+ }
1283
+ scriptExecutionErrors.push(error_2);
1284
+ return [3 /*break*/, 19];
1285
+ case 19:
1286
+ _d = _c.next();
1287
+ return [3 /*break*/, 15];
1288
+ case 20: return [3 /*break*/, 23];
1289
+ case 21:
1290
+ e_2_1 = _o.sent();
1291
+ e_2 = { error: e_2_1 };
1292
+ return [3 /*break*/, 23];
1293
+ case 22:
1294
+ try {
1295
+ if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
1296
+ }
1297
+ finally { if (e_2) throw e_2.error; }
1298
+ return [7 /*endfinally*/];
1299
+ case 23:
1300
+ if (resultString !== null) {
1301
+ return [3 /*break*/, 27];
1302
+ }
1303
+ if (scriptExecutionErrors.length === 1) {
1304
+ throw scriptExecutionErrors[0];
1305
+ }
1306
+ else {
1307
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
1308
+ .map(function (error) { return '- ' + error.message; })
1309
+ .join('\n\n')), "\n "); }));
1310
+ }
1311
+ case 24:
1312
+ if (tools.userInterface === undefined) {
1313
+ throw new PromptbookExecutionError('User interface tools are not available');
1314
+ }
1315
+ return [4 /*yield*/, tools.userInterface.promptDialog({
1316
+ promptTitle: currentTemplate.title,
1317
+ promptMessage: replaceParameters(currentTemplate.description || '', parametersToPass),
1318
+ defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
1319
+ // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
1320
+ placeholder: undefined,
1321
+ priority: priority,
1322
+ })];
1323
+ case 25:
1324
+ // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
1325
+ resultString = _o.sent();
1326
+ return [3 /*break*/, 27];
1327
+ case 26: throw new PromptbookExecutionError(
1328
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1329
+ "Unknown execution type \"".concat(currentTemplate.executionType, "\""));
1330
+ case 27:
1331
+ if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
1332
+ _o.label = 28;
1333
+ case 28:
1334
+ _o.trys.push([28, 42, 43, 44]);
1335
+ _e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
1336
+ _o.label = 29;
1337
+ case 29:
1338
+ if (!!_f.done) return [3 /*break*/, 41];
1339
+ functionName = _f.value;
1340
+ // TODO: DRY [1]
1341
+ scriptExecutionErrors = [];
1342
+ postprocessingError = null;
1343
+ _o.label = 30;
1344
+ case 30:
1345
+ _o.trys.push([30, 37, 38, 39]);
1346
+ _g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
1347
+ _o.label = 31;
1348
+ case 31:
1349
+ if (!!_h.done) return [3 /*break*/, 36];
1350
+ scriptTools = _h.value;
1351
+ _o.label = 32;
1352
+ case 32:
1353
+ _o.trys.push([32, 34, , 35]);
1354
+ return [4 /*yield*/, scriptTools.execute({
1355
+ scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
1356
+ script: "".concat(functionName, "(resultString)"),
1357
+ parameters: {
1358
+ resultString: resultString || '',
1359
+ // Note: No ...parametersToPass, because working with result only
1360
+ },
1361
+ })];
1362
+ case 33:
1363
+ resultString = _o.sent();
1364
+ postprocessingError = null;
1365
+ return [3 /*break*/, 36];
1366
+ case 34:
1367
+ error_3 = _o.sent();
1368
+ if (!(error_3 instanceof Error)) {
1369
+ throw error_3;
1370
+ }
1371
+ postprocessingError = error_3;
1372
+ scriptExecutionErrors.push(error_3);
1373
+ return [3 /*break*/, 35];
1374
+ case 35:
1375
+ _h = _g.next();
1376
+ return [3 /*break*/, 31];
1377
+ case 36: return [3 /*break*/, 39];
1378
+ case 37:
1379
+ e_3_1 = _o.sent();
1380
+ e_3 = { error: e_3_1 };
1381
+ return [3 /*break*/, 39];
1382
+ case 38:
1383
+ try {
1384
+ if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
1385
+ }
1386
+ finally { if (e_3) throw e_3.error; }
1387
+ return [7 /*endfinally*/];
1388
+ case 39:
1389
+ if (postprocessingError) {
1390
+ throw postprocessingError;
1391
+ }
1392
+ _o.label = 40;
1393
+ case 40:
1394
+ _f = _e.next();
1395
+ return [3 /*break*/, 29];
1396
+ case 41: return [3 /*break*/, 44];
1397
+ case 42:
1398
+ e_4_1 = _o.sent();
1399
+ e_4 = { error: e_4_1 };
1400
+ return [3 /*break*/, 44];
1401
+ case 43:
1402
+ try {
1403
+ if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
1404
+ }
1405
+ finally { if (e_4) throw e_4.error; }
1406
+ return [7 /*endfinally*/];
1407
+ case 44:
1408
+ // TODO: [💝] Unite object for expecting amount and format
1409
+ if (currentTemplate.expectFormat) {
1410
+ if (currentTemplate.expectFormat === 'JSON') {
1411
+ if (!isValidJsonString(resultString || '')) {
1412
+ throw new ExpectError('Expected valid JSON string');
1413
+ }
1414
+ }
1415
+ }
1416
+ // TODO: [💝] Unite object for expecting amount and format
1417
+ if (currentTemplate.expectations) {
1418
+ checkExpectations(currentTemplate.expectations, resultString || '');
1419
+ }
1420
+ return [3 /*break*/, 49];
1421
+ case 45:
1422
+ error_4 = _o.sent();
1423
+ if (!(error_4 instanceof ExpectError)) {
1424
+ throw error_4;
1425
+ }
1426
+ expectError = error_4;
1427
+ return [3 /*break*/, 47];
1428
+ case 46:
1429
+ if (!isJokerAttempt &&
1430
+ currentTemplate.executionType === 'PROMPT_TEMPLATE' &&
1431
+ prompt
1432
+ // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
1433
+ // In that case we don’t want to make a report about it because it’s not a llm execution error
1434
+ ) {
1435
+ // TODO: [🧠] Maybe put other executionTypes into report
1436
+ executionReport.promptExecutions.push({
1437
+ prompt: {
1438
+ title: currentTemplate.title /* <- Note: If title in promptbook contains emojis, pass it innto report */,
1439
+ content: prompt.content,
1440
+ modelRequirements: prompt.modelRequirements,
1441
+ expectations: prompt.expectations,
1442
+ expectFormat: prompt.expectFormat,
1443
+ // <- Note: Do want to pass ONLY wanted information to the report
1444
+ },
1445
+ result: result || undefined,
1446
+ error: expectError || undefined,
1447
+ });
1448
+ }
1449
+ return [7 /*endfinally*/];
1450
+ case 47:
1451
+ if (expectError !== null && attempt === maxAttempts - 1) {
1452
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
1453
+ }
1454
+ _o.label = 48;
1455
+ case 48:
1456
+ attempt++;
1457
+ return [3 /*break*/, 3];
1458
+ case 49:
1459
+ if (resultString === null) {
1460
+ throw new UnexpectedError('Something went wrong and prompt result is null');
1461
+ }
1462
+ if (onProgress /* <- [3] */) {
1463
+ onProgress({
1464
+ name: name,
1465
+ title: title,
1466
+ isStarted: true,
1467
+ isDone: true,
1468
+ executionType: currentTemplate.executionType,
1469
+ parameterName: currentTemplate.resultingParameterName,
1470
+ parameterValue: resultString,
1471
+ // <- [3]
1472
+ });
1473
+ }
1474
+ parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _m));
1475
+ return [2 /*return*/];
1476
+ }
1477
+ });
1478
+ });
1479
+ }
1480
+ var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, _a, _b, parameter, usage;
1481
+ var e_1, _c;
1482
+ return __generator(this, function (_d) {
1483
+ switch (_d.label) {
1484
+ case 0:
1485
+ parametersToPass = inputParameters;
1486
+ executionReport = {
1487
+ promptbookUrl: promptbook.promptbookUrl,
1488
+ title: promptbook.title,
1489
+ promptbookUsedVersion: PROMPTBOOK_VERSION,
1490
+ promptbookRequestedVersion: promptbook.promptbookVersion,
1491
+ description: promptbook.description,
1492
+ promptExecutions: [],
1493
+ };
1494
+ _d.label = 1;
1495
+ case 1:
1496
+ _d.trys.push([1, 6, , 7]);
1497
+ resovedParameters_1 = promptbook.parameters
1498
+ .filter(function (_a) {
1499
+ var isInput = _a.isInput;
1500
+ return isInput;
1501
+ })
1502
+ .map(function (_a) {
1503
+ var name = _a.name;
1504
+ return name;
1505
+ });
1506
+ unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
1507
+ resolving_1 = [];
1508
+ loopLimit = LOOP_LIMIT;
1509
+ _loop_1 = function () {
1510
+ var currentTemplate, work_1;
1511
+ return __generator(this, function (_e) {
1512
+ switch (_e.label) {
1513
+ case 0:
1514
+ if (loopLimit-- < 0) {
1515
+ throw new UnexpectedError('Loop limit reached during resolving parameters promptbook execution');
1516
+ }
1517
+ currentTemplate = unresovedTemplates.find(function (template) {
1518
+ return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
1519
+ });
1520
+ if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
1521
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
1522
+ case 1:
1523
+ if (!!currentTemplate) return [3 /*break*/, 3];
1524
+ /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
1525
+ case 2:
1526
+ /* [5] */ _e.sent();
1527
+ return [3 /*break*/, 4];
1528
+ case 3:
1529
+ unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
1530
+ work_1 = executeSingleTemplate(currentTemplate)
1531
+ .then(function () {
1532
+ resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
1533
+ })
1534
+ .then(function () {
1535
+ resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
1536
+ });
1537
+ resolving_1.push(work_1);
1538
+ _e.label = 4;
1539
+ case 4: return [2 /*return*/];
1540
+ }
1541
+ });
1542
+ };
1543
+ _d.label = 2;
1544
+ case 2:
1545
+ if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
1546
+ return [5 /*yield**/, _loop_1()];
1547
+ case 3:
1548
+ _d.sent();
1549
+ return [3 /*break*/, 2];
1550
+ case 4: return [4 /*yield*/, Promise.all(resolving_1)];
1551
+ case 5:
1552
+ _d.sent();
1553
+ return [3 /*break*/, 7];
1554
+ case 6:
1555
+ error_1 = _d.sent();
1556
+ if (!(error_1 instanceof Error)) {
1557
+ throw error_1;
1558
+ }
1559
+ usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1560
+ var result = _a.result;
1561
+ return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1562
+ })), false));
1563
+ return [2 /*return*/, {
1564
+ isSuccessful: false,
1565
+ errors: [error_1],
1566
+ usage: usage_1,
1567
+ executionReport: executionReport,
1568
+ outputParameters: parametersToPass,
1569
+ }];
1570
+ case 7:
1571
+ try {
1572
+ // Note: Filter ONLY output parameters
1573
+ for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
1574
+ parameter = _b.value;
1575
+ if (parameter.isOutput) {
1576
+ continue;
1577
+ }
1578
+ delete parametersToPass[parameter.name];
1579
+ }
1580
+ }
1581
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1582
+ finally {
1583
+ try {
1584
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1585
+ }
1586
+ finally { if (e_1) throw e_1.error; }
1587
+ }
1588
+ usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
1589
+ var result = _a.result;
1590
+ return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
1591
+ })), false));
1592
+ return [2 /*return*/, {
1593
+ isSuccessful: true,
1594
+ errors: [],
1595
+ usage: usage,
1596
+ executionReport: executionReport,
1597
+ outputParameters: parametersToPass,
1598
+ }];
1599
+ }
1600
+ });
1601
+ }); };
1602
+ return promptbookExecutor;
1603
+ }
1604
+ /**
1605
+ * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
1606
+ * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
1607
+ * Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
1608
+ * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
1609
+ */
1610
+
1611
+ /**
1612
+ * Makes first letter of a string uppercase
1613
+ *
1614
+ */
1615
+ function capitalize(word) {
1616
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
1617
+ }
1618
+
1619
+ /**
1620
+ * Converts promptbook in JSON format to string format
1621
+ *
1622
+ * @param promptbookJson Promptbook in JSON format (.ptbk.json)
1623
+ * @returns Promptbook in string format (.ptbk.md)
1624
+ */
1625
+ function promptbookJsonToString(promptbookJson) {
1626
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
1627
+ var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
1628
+ var promptbookString = "# ".concat(title);
1629
+ if (description) {
1630
+ promptbookString += '\n\n';
1631
+ promptbookString += description;
1632
+ }
1633
+ // TODO:> const commands: Array<Command>
1634
+ var commands = [];
1635
+ if (promptbookUrl) {
1636
+ commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
1637
+ }
1638
+ commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
1639
+ promptbookString = prettifyMarkdown(promptbookString);
1640
+ try {
1641
+ for (var _g = __values(parameters.filter(function (_a) {
1642
+ var isInput = _a.isInput;
1643
+ return isInput;
1644
+ })), _h = _g.next(); !_h.done; _h = _g.next()) {
1645
+ var parameter = _h.value;
1646
+ commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1647
+ }
1648
+ }
1649
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1650
+ finally {
1651
+ try {
1652
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
1653
+ }
1654
+ finally { if (e_1) throw e_1.error; }
1655
+ }
1656
+ try {
1657
+ for (var _j = __values(parameters.filter(function (_a) {
1658
+ var isOutput = _a.isOutput;
1659
+ return isOutput;
1660
+ })), _k = _j.next(); !_k.done; _k = _j.next()) {
1661
+ var parameter = _k.value;
1662
+ commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
1663
+ }
1664
+ }
1665
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1666
+ finally {
1667
+ try {
1668
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1669
+ }
1670
+ finally { if (e_2) throw e_2.error; }
1671
+ }
1672
+ promptbookString += '\n\n';
1673
+ promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
1674
+ try {
1675
+ for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
1676
+ var promptTemplate = promptTemplates_1_1.value;
1677
+ var
1678
+ /* Note: Not using:> name, */
1679
+ title_1 = promptTemplate.title, description_1 = promptTemplate.description,
1680
+ /* Note: dependentParameterNames, */
1681
+ jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
1682
+ promptbookString += '\n\n';
1683
+ promptbookString += "## ".concat(title_1);
1684
+ if (description_1) {
1685
+ promptbookString += '\n\n';
1686
+ promptbookString += description_1;
1687
+ }
1688
+ // TODO:> const commands: Array<Command>
1689
+ var commands_1 = [];
1690
+ var contentLanguage = 'text';
1691
+ if (executionType === 'PROMPT_TEMPLATE') {
1692
+ var modelRequirements = promptTemplate.modelRequirements;
1693
+ var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
1694
+ commands_1.push("EXECUTE PROMPT TEMPLATE");
1695
+ if (modelVariant) {
1696
+ commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
1697
+ }
1698
+ if (modelName) {
1699
+ commands_1.push("MODEL NAME `".concat(modelName, "`"));
1700
+ }
1701
+ }
1702
+ else if (executionType === 'SIMPLE_TEMPLATE') {
1703
+ commands_1.push("SIMPLE TEMPLATE");
1704
+ // Note: Nothing special here
1705
+ }
1706
+ else if (executionType === 'SCRIPT') {
1707
+ commands_1.push("EXECUTE SCRIPT");
1708
+ if (promptTemplate.contentLanguage) {
1709
+ contentLanguage = promptTemplate.contentLanguage;
1710
+ }
1711
+ else {
1712
+ contentLanguage = '';
1713
+ }
1714
+ }
1715
+ else if (executionType === 'PROMPT_DIALOG') {
1716
+ commands_1.push("PROMPT DIALOG");
1717
+ // Note: Nothing special here
1718
+ }
1719
+ if (jokers) {
1720
+ try {
1721
+ 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()) {
1722
+ var joker = jokers_1_1.value;
1723
+ commands_1.push("JOKER {".concat(joker, "}"));
1724
+ }
1725
+ }
1726
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1727
+ finally {
1728
+ try {
1729
+ if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
1730
+ }
1731
+ finally { if (e_4) throw e_4.error; }
1732
+ }
1733
+ } /* not else */
1734
+ if (postprocessing) {
1735
+ try {
1736
+ 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()) {
1737
+ var postprocessingFunctionName = postprocessing_1_1.value;
1738
+ commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
1739
+ }
1740
+ }
1741
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1742
+ finally {
1743
+ try {
1744
+ if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
1745
+ }
1746
+ finally { if (e_5) throw e_5.error; }
1747
+ }
1748
+ } /* not else */
1749
+ if (expectations) {
1750
+ try {
1751
+ for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
1752
+ var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
1753
+ if (min === max) {
1754
+ commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1755
+ }
1756
+ else {
1757
+ if (min !== undefined) {
1758
+ commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1759
+ } /* not else */
1760
+ if (max !== undefined) {
1761
+ commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
1762
+ }
1763
+ }
1764
+ }
1765
+ }
1766
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1767
+ finally {
1768
+ try {
1769
+ if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
1770
+ }
1771
+ finally { if (e_6) throw e_6.error; }
1772
+ }
1773
+ } /* not else */
1774
+ if (expectFormat) {
1775
+ if (expectFormat === 'JSON') {
1776
+ // TODO: @deprecated remove
1777
+ commands_1.push("EXPECT JSON");
1778
+ }
1779
+ } /* not else */
1780
+ promptbookString += '\n\n';
1781
+ promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
1782
+ promptbookString += '\n\n';
1783
+ promptbookString += '```' + contentLanguage;
1784
+ promptbookString += '\n';
1785
+ promptbookString += spaceTrim__default["default"](content);
1786
+ // <- TODO: !!! Escape
1787
+ // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1788
+ promptbookString += '\n';
1789
+ promptbookString += '```';
1790
+ promptbookString += '\n\n';
1791
+ promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
1792
+ }
1793
+ }
1794
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1795
+ finally {
1796
+ try {
1797
+ if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
1798
+ }
1799
+ finally { if (e_3) throw e_3.error; }
1800
+ }
1801
+ return promptbookString;
1802
+ }
1803
+ /**
1804
+ * @private internal util of promptbookJsonToString
1805
+ */
1806
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
1807
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
1808
+ var parameterString = "{".concat(name, "}");
1809
+ if (description) {
1810
+ parameterString = "".concat(parameterString, " ").concat(description);
1811
+ }
1812
+ return parameterString;
1813
+ }
1814
+ /**
1815
+ * TODO: Escape all
1816
+ */
1817
+
1818
+ /**
1819
+ * This error indicates that promptbook not found in the library
1820
+ */
1821
+ var PromptbookNotFoundError = /** @class */ (function (_super) {
1822
+ __extends(PromptbookNotFoundError, _super);
1823
+ function PromptbookNotFoundError(message) {
1824
+ var _this = _super.call(this, message) || this;
1825
+ _this.name = 'PromptbookNotFoundError';
1826
+ Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
1827
+ return _this;
1828
+ }
1829
+ return PromptbookNotFoundError;
1830
+ }(Error));
1831
+
1832
+ /**
1833
+ * This error indicates errors in referencing promptbooks between each other
1834
+ */
1835
+ var PromptbookReferenceError = /** @class */ (function (_super) {
1836
+ __extends(PromptbookReferenceError, _super);
1837
+ function PromptbookReferenceError(message) {
1838
+ var _this = _super.call(this, message) || this;
1839
+ _this.name = 'PromptbookReferenceError';
1840
+ Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
1841
+ return _this;
1842
+ }
1843
+ return PromptbookReferenceError;
1844
+ }(Error));
1845
+
1846
+ /**
1847
+ * Library of promptbooks that groups together promptbooks for an application.
1848
+ * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1849
+ *
1850
+ * @see https://github.com/webgptorg/promptbook#promptbook-library
1851
+ */
1852
+ var SimplePromptbookLibrary = /** @class */ (function () {
1853
+ /**
1854
+ * Constructs a promptbook library from promptbooks
1855
+ *
1856
+ * @param promptbooks !!!
1857
+ *
1858
+ * Note: During the construction logic of all promptbooks are validated
1859
+ * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
1860
+ */
1861
+ function SimplePromptbookLibrary() {
1862
+ var e_1, _a;
1863
+ var promptbooks = [];
1864
+ for (var _i = 0; _i < arguments.length; _i++) {
1865
+ promptbooks[_i] = arguments[_i];
1866
+ }
1867
+ this.library = new Map();
1868
+ try {
1869
+ for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1870
+ var promptbook = promptbooks_1_1.value;
1871
+ if (promptbook.promptbookUrl === undefined) {
1872
+ 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 ")));
1873
+ }
1874
+ validatePromptbookJson(promptbook);
1875
+ // Note: [🦄]
1876
+ if (this.library.has(promptbook.promptbookUrl) &&
1877
+ promptbookJsonToString(promptbook) !==
1878
+ promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
1879
+ 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 ")));
1880
+ }
1881
+ this.library.set(promptbook.promptbookUrl, promptbook);
1882
+ }
1883
+ }
1884
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1885
+ finally {
1886
+ try {
1887
+ if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
1888
+ }
1889
+ finally { if (e_1) throw e_1.error; }
1890
+ }
1891
+ }
1892
+ /**
1893
+ * Gets all promptbooks in the library
1894
+ */
1895
+ SimplePromptbookLibrary.prototype.listPromptbooks = function () {
1896
+ return Array.from(this.library.keys());
1897
+ };
1898
+ /**
1899
+ * Gets promptbook by its URL
1900
+ *
1901
+ * Note: This is not a direct fetching from the URL, but a lookup in the library
1902
+ */
1903
+ SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
1904
+ var _this = this;
1905
+ var promptbook = this.library.get(url);
1906
+ if (!promptbook) {
1907
+ if (this.listPromptbooks().length === 0) {
1908
+ throw new PromptbookNotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1909
+ }
1910
+ 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()
1911
+ .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
1912
+ .join('\n')), "\n\n "); }));
1913
+ }
1914
+ return promptbook;
1915
+ };
1916
+ /**
1917
+ * Checks whether given prompt was defined in any promptbook in the library
1918
+ */
1919
+ SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
1920
+ return true;
1921
+ };
1922
+ return SimplePromptbookLibrary;
1923
+ }());
1924
+
1925
+ /**
1926
+ * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1927
+ *
1928
+ * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
1929
+ * Note: During the construction syntax and logic of all sources are validated
1930
+ *
1931
+ * @param promptbookSources
1932
+ * @returns PromptbookLibrary
1933
+ */
1934
+ function createPromptbookLibraryFromSources() {
1935
+ var promptbookSources = [];
1936
+ for (var _i = 0; _i < arguments.length; _i++) {
1937
+ promptbookSources[_i] = arguments[_i];
1938
+ }
1939
+ return __awaiter(this, void 0, void 0, function () {
1940
+ var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
1941
+ var e_1, _a;
1942
+ return __generator(this, function (_b) {
1943
+ switch (_b.label) {
1944
+ case 0:
1945
+ promptbooks = new Array();
1946
+ _b.label = 1;
1947
+ case 1:
1948
+ _b.trys.push([1, 8, 9, 10]);
1949
+ promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
1950
+ _b.label = 2;
1951
+ case 2:
1952
+ if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
1953
+ source = promptbookSources_1_1.value;
1954
+ promptbook = void 0;
1955
+ if (!(typeof source === 'string')) return [3 /*break*/, 4];
1956
+ return [4 /*yield*/, promptbookStringToJson(source)];
1957
+ case 3:
1958
+ // Note: When directly creating from string, no need to validate the source
1959
+ // The validation is performed always before execution
1960
+ promptbook = _b.sent();
1961
+ return [3 /*break*/, 5];
1962
+ case 4:
1963
+ promptbook = source;
1964
+ _b.label = 5;
1965
+ case 5:
1966
+ promptbooks.push(promptbook);
1967
+ _b.label = 6;
1968
+ case 6:
1969
+ promptbookSources_1_1 = promptbookSources_1.next();
1970
+ return [3 /*break*/, 2];
1971
+ case 7: return [3 /*break*/, 10];
1972
+ case 8:
1973
+ e_1_1 = _b.sent();
1974
+ e_1 = { error: e_1_1 };
1975
+ return [3 /*break*/, 10];
1976
+ case 9:
1977
+ try {
1978
+ if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
1979
+ }
1980
+ finally { if (e_1) throw e_1.error; }
1981
+ return [7 /*endfinally*/];
1982
+ case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1983
+ }
1984
+ });
1985
+ });
1986
+ }
1987
+ /**
1988
+ * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1989
+ */
1990
+
1991
+ /* tslint:disable */
1992
+ function normalizeToKebabCase(sentence) {
1993
+ var e_1, _a;
1994
+ sentence = removeDiacritics(sentence);
1995
+ var charType;
1996
+ var lastCharType = 'OTHER';
1997
+ var normalizedName = '';
1998
+ try {
1999
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
2000
+ var char = sentence_1_1.value;
2001
+ var normalizedChar = void 0;
2002
+ if (/^[a-z]$/.test(char)) {
2003
+ charType = 'LOWERCASE';
2004
+ normalizedChar = char;
2005
+ }
2006
+ else if (/^[A-Z]$/.test(char)) {
2007
+ charType = 'UPPERCASE';
2008
+ normalizedChar = char.toLowerCase();
2009
+ }
2010
+ else if (/^[0-9]$/.test(char)) {
2011
+ charType = 'NUMBER';
2012
+ normalizedChar = char;
2013
+ }
2014
+ else if (/^\/$/.test(char)) {
2015
+ charType = 'SLASH';
2016
+ normalizedChar = char;
2017
+ }
2018
+ else {
2019
+ charType = 'OTHER';
2020
+ normalizedChar = '-';
2021
+ }
2022
+ if (charType !== lastCharType &&
2023
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
2024
+ !(lastCharType === 'NUMBER') &&
2025
+ !(charType === 'NUMBER')) {
2026
+ normalizedName += '-';
2027
+ }
2028
+ normalizedName += normalizedChar;
2029
+ lastCharType = charType;
785
2030
  }
786
- return -number;
787
- }
788
- value = value.replace(/,/g, '.');
789
- value = value.toUpperCase();
790
- if (value === '') {
791
- return 0;
792
- }
793
- if (value === '♾' || value.startsWith('INF')) {
794
- return Infinity;
795
2031
  }
796
- if (value.includes('/')) {
797
- var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
798
- var numerator = parseNumber(numerator_);
799
- var denominator = parseNumber(denominator_);
800
- if (denominator === 0) {
801
- throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2032
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2033
+ finally {
2034
+ try {
2035
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
802
2036
  }
803
- return numerator / denominator;
804
- }
805
- if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
806
- return 0;
807
- }
808
- if (value.includes('E')) {
809
- var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
810
- return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
811
- }
812
- if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
813
- throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
814
- }
815
- var num = parseFloat(value);
816
- if (isNaN(num)) {
817
- throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2037
+ finally { if (e_1) throw e_1.error; }
818
2038
  }
819
- return num;
2039
+ normalizedName = normalizedName.split(/-+/g).join('-');
2040
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
2041
+ normalizedName = normalizedName.replace(/^-/, '');
2042
+ normalizedName = normalizedName.replace(/-$/, '');
2043
+ return normalizedName;
2044
+ }
2045
+
2046
+ function prepareKnowledgeFromMarkdown(options) {
2047
+ return __awaiter(this, void 0, void 0, function () {
2048
+ var content, llmTools, _a, isVerbose, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2049
+ var _this = this;
2050
+ return __generator(this, function (_b) {
2051
+ switch (_b.label) {
2052
+ case 0:
2053
+ content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2054
+ return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2055
+ case 1:
2056
+ library = _b.sent();
2057
+ promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2058
+ executor = createPromptbookExecutor({
2059
+ promptbook: promptbook,
2060
+ tools: {
2061
+ llm: llmTools,
2062
+ script: [
2063
+ /* <- TODO: Allow to just keep script undefined */
2064
+ ],
2065
+ },
2066
+ });
2067
+ return [4 /*yield*/, executor({ content: content })];
2068
+ case 2:
2069
+ result = _b.sent();
2070
+ assertsExecutionSuccessful(result);
2071
+ outputParameters = result.outputParameters;
2072
+ knowledgeRaw = outputParameters.knowledge;
2073
+ knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
2074
+ if (isVerbose) {
2075
+ console.info('knowledgeTextPieces:', knowledgeTextPieces);
2076
+ }
2077
+ return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2078
+ var name, title, content, keywords, index, sources;
2079
+ return __generator(this, function (_a) {
2080
+ name = "piece-".concat(i);
2081
+ title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
2082
+ content = spaceTrim__default["default"](knowledgeTextPiece);
2083
+ keywords = [];
2084
+ index = [];
2085
+ sources = [];
2086
+ try {
2087
+ // TODO: !!!! Summarize name and title from the content
2088
+ title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 30));
2089
+ name = normalizeToKebabCase(title);
2090
+ // TODO: !!!! Extract keywords via prompt
2091
+ // TODO: !!!! Index through LLM model
2092
+ // TODO: [🖖] !!!! Make system for sources and identification of sources
2093
+ }
2094
+ catch (error) {
2095
+ console.error(error);
2096
+ }
2097
+ return [2 /*return*/, {
2098
+ name: name,
2099
+ title: title,
2100
+ content: content,
2101
+ keywords: keywords,
2102
+ index: index,
2103
+ sources: sources,
2104
+ }];
2105
+ });
2106
+ }); }))];
2107
+ case 3:
2108
+ knowledge = _b.sent();
2109
+ return [2 /*return*/, knowledge];
2110
+ }
2111
+ });
2112
+ });
820
2113
  }
2114
+
821
2115
  /**
822
- * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
2116
+ * Supported script languages
823
2117
  */
2118
+ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
824
2119
 
825
2120
  /**
826
- * Parses one line of ul/ol to command
827
- *
828
- * @returns parsed command object
829
- * @throws {PromptbookSyntaxError} if the command is invalid
2121
+ * Computes the deepness of the markdown structure.
830
2122
  *
831
- * @private within the promptbookStringToJson
2123
+ * @private within the library
832
2124
  */
833
- function parseCommand(listItem) {
2125
+ function countMarkdownStructureDeepness(markdownStructure) {
834
2126
  var e_1, _a;
835
- if (listItem.includes('\n') || listItem.includes('\r')) {
836
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
837
- }
838
- var type = listItem.trim();
839
- type = type.split('`').join('');
840
- type = type.split('"').join('');
841
- type = type.split("'").join('');
842
- type = type.split('~').join('');
843
- type = type.split('[').join('');
844
- type = type.split(']').join('');
845
- type = type.split('(').join('');
846
- type = type.split(')').join('');
847
- type = normalizeTo_SCREAMING_CASE(type);
848
- type = type.split('DIALOGUE').join('DIALOG');
849
- var listItemParts = listItem
850
- .split(' ')
851
- .map(function (part) { return part.trim(); })
852
- .filter(function (item) { return item !== ''; })
853
- .filter(function (item) { return !/^PTBK$/i.test(item); })
854
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
855
- .map(removeMarkdownFormatting);
856
- if (type.startsWith('URL') ||
857
- type.startsWith('PTBK_URL') ||
858
- type.startsWith('PTBKURL') ||
859
- type.startsWith('PROMPTBOOK_URL') ||
860
- type.startsWith('PROMPTBOOKURL') ||
861
- type.startsWith('HTTPS')) {
862
- if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
863
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
864
- }
865
- var promptbookUrlString = listItemParts.pop();
866
- var promptbookUrl = new URL(promptbookUrlString);
867
- if (promptbookUrl.protocol !== 'https:') {
868
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2127
+ var maxDeepness = 0;
2128
+ try {
2129
+ for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
2130
+ var section = _c.value;
2131
+ maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
869
2132
  }
870
- if (promptbookUrl.hash !== '') {
871
- 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 ")));
2133
+ }
2134
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2135
+ finally {
2136
+ try {
2137
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
872
2138
  }
873
- return {
874
- type: 'PROMPTBOOK_URL',
875
- promptbookUrl: promptbookUrl,
876
- };
2139
+ finally { if (e_1) throw e_1.error; }
877
2140
  }
878
- else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
879
- if (listItemParts.length !== 2) {
880
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2141
+ return maxDeepness + 1;
2142
+ }
2143
+
2144
+ /**
2145
+ * Parse a markdown string into a MarkdownStructure object.
2146
+ *
2147
+ * Note: This function does work with code blocks
2148
+ * Note: This function does not work with markdown comments
2149
+ *
2150
+ * @param markdown The markdown string to parse.
2151
+ * @returns The MarkdownStructure object.
2152
+ *
2153
+ * @private within the library
2154
+ */
2155
+ function markdownToMarkdownStructure(markdown) {
2156
+ var e_1, _a;
2157
+ var lines = markdown.split('\n');
2158
+ var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
2159
+ var current = root;
2160
+ var isInsideCodeBlock = false;
2161
+ try {
2162
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
2163
+ var line = lines_1_1.value;
2164
+ var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
2165
+ if (isInsideCodeBlock || !headingMatch) {
2166
+ if (line.startsWith('```')) {
2167
+ isInsideCodeBlock = !isInsideCodeBlock;
2168
+ }
2169
+ current.contentLines.push(line);
2170
+ }
2171
+ else {
2172
+ var level = headingMatch.groups.mark.length;
2173
+ var title = headingMatch.groups.title.trim();
2174
+ var parent_1 = void 0;
2175
+ if (level > current.level) {
2176
+ // Note: Going deeper (next section is child of current)
2177
+ parent_1 = current;
2178
+ }
2179
+ else {
2180
+ // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
2181
+ parent_1 = current;
2182
+ var loopLimit = LOOP_LIMIT;
2183
+ while (parent_1.level !== level - 1) {
2184
+ if (loopLimit-- < 0) {
2185
+ throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
2186
+ }
2187
+ if (parent_1.parent === null /* <- Note: We are in root */) {
2188
+ // [🌻]
2189
+ throw new Error(spaceTrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
2190
+ }
2191
+ parent_1 = parent_1.parent;
2192
+ }
2193
+ }
2194
+ var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
2195
+ parent_1.sections.push(section);
2196
+ current = section;
2197
+ }
881
2198
  }
882
- var promptbookVersion = listItemParts.pop();
883
- // TODO: Validate version
884
- return {
885
- type: 'PROMPTBOOK_VERSION',
886
- promptbookVersion: promptbookVersion,
887
- };
888
2199
  }
889
- else if (type.startsWith('EXECUTE') ||
890
- type.startsWith('EXEC') ||
891
- type.startsWith('PROMPT_DIALOG') ||
892
- type.startsWith('SIMPLE_TEMPLATE')) {
893
- var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
894
- if (executionTypes.length !== 1) {
895
- 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 "); }));
2200
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2201
+ finally {
2202
+ try {
2203
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
896
2204
  }
897
- return {
898
- type: 'EXECUTE',
899
- executionType: executionTypes[0],
900
- };
2205
+ finally { if (e_1) throw e_1.error; }
901
2206
  }
902
- else if (type.startsWith('MODEL')) {
903
- // TODO: Make this more elegant and dynamically
904
- if (type.startsWith('MODEL_VARIANT')) {
905
- if (type === 'MODEL_VARIANT_CHAT') {
906
- return {
907
- type: 'MODEL',
908
- key: 'modelVariant',
909
- value: 'CHAT',
910
- };
911
- }
912
- else if (type === 'MODEL_VARIANT_COMPLETION') {
913
- return {
914
- type: 'MODEL',
915
- key: 'modelVariant',
916
- value: 'COMPLETION',
917
- };
2207
+ if (root.sections.length === 1) {
2208
+ var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
2209
+ return markdownStructure;
2210
+ }
2211
+ // [🌻]
2212
+ throw new Error('The markdown file must have exactly one top-level section.');
2213
+ // return root;
2214
+ }
2215
+ /**
2216
+ * @private
2217
+ */
2218
+ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
2219
+ var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
2220
+ return {
2221
+ level: level,
2222
+ title: title,
2223
+ content: spaceTrim.spaceTrim(contentLines.join('\n')),
2224
+ sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
2225
+ };
2226
+ }
2227
+
2228
+ /**
2229
+ * Utility function to extract all list items from markdown
2230
+ *
2231
+ * Note: It works with both ul and ol
2232
+ * Note: It omits list items in code blocks
2233
+ * Note: It flattens nested lists
2234
+ * Note: It can not work with html syntax and comments
2235
+ *
2236
+ * @param markdown any valid markdown
2237
+ * @returns
2238
+ */
2239
+ function extractAllListItemsFromMarkdown(markdown) {
2240
+ var e_1, _a;
2241
+ var lines = markdown.split('\n');
2242
+ var listItems = [];
2243
+ var isInCodeBlock = false;
2244
+ try {
2245
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
2246
+ var line = lines_1_1.value;
2247
+ var trimmedLine = line.trim();
2248
+ if (trimmedLine.startsWith('```')) {
2249
+ isInCodeBlock = !isInCodeBlock;
918
2250
  }
919
- else {
920
- 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 "); }));
2251
+ if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
2252
+ var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
2253
+ listItems.push(listItem);
921
2254
  }
922
2255
  }
923
- if (type.startsWith('MODEL_NAME')) {
924
- return {
925
- type: 'MODEL',
926
- key: 'modelName',
927
- value: listItemParts.pop(),
928
- };
929
- }
930
- else {
931
- 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 "); }));
932
- }
933
2256
  }
934
- else if (type.startsWith('PARAM') ||
935
- type.startsWith('INPUT_PARAM') ||
936
- type.startsWith('OUTPUT_PARAM') ||
937
- listItem.startsWith('{') ||
938
- listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
939
- var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
940
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
941
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
942
- }
943
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
944
- var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
945
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
946
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
947
- }
948
- var isInput = type.startsWith('INPUT');
949
- var isOutput = type.startsWith('OUTPUT');
950
- if (listItem.startsWith('> {')) {
951
- isInput = false;
952
- isOutput = false;
2257
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2258
+ finally {
2259
+ try {
2260
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
953
2261
  }
954
- return {
955
- type: 'PARAMETER',
956
- parameterName: parameterName,
957
- parameterDescription: parameterDescription.trim() || null,
958
- isInput: isInput,
959
- isOutput: isOutput,
960
- };
2262
+ finally { if (e_1) throw e_1.error; }
961
2263
  }
962
- else if (type.startsWith('JOKER')) {
963
- if (listItemParts.length !== 2) {
964
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
965
- }
966
- var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
967
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
968
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2264
+ return listItems;
2265
+ }
2266
+
2267
+ /**
2268
+ * Extracts all code blocks from markdown.
2269
+ *
2270
+ * Note: There are 3 simmilar function:
2271
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2272
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2273
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2274
+ *
2275
+ * @param markdown any valid markdown
2276
+ * @returns code blocks with language and content
2277
+ *
2278
+ */
2279
+ function extractAllBlocksFromMarkdown(markdown) {
2280
+ var e_1, _a;
2281
+ var codeBlocks = [];
2282
+ var lines = markdown.split('\n');
2283
+ var currentCodeBlock = null;
2284
+ try {
2285
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
2286
+ var line = lines_1_1.value;
2287
+ if (line.startsWith('```')) {
2288
+ var language = line.slice(3).trim() || null;
2289
+ if (currentCodeBlock === null) {
2290
+ currentCodeBlock = { language: language, content: '' };
2291
+ }
2292
+ else {
2293
+ if (language !== null) {
2294
+ // [🌻]
2295
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2296
+ }
2297
+ codeBlocks.push(currentCodeBlock);
2298
+ currentCodeBlock = null;
2299
+ }
2300
+ }
2301
+ else if (currentCodeBlock !== null) {
2302
+ if (currentCodeBlock.content !== '') {
2303
+ currentCodeBlock.content += '\n';
2304
+ }
2305
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
2306
+ }
969
2307
  }
970
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
971
- var parameterName = parametersMatch.groups.parameterName;
972
- return {
973
- type: 'JOKER',
974
- parameterName: parameterName,
975
- };
976
2308
  }
977
- else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
978
- if (listItemParts.length !== 2) {
979
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2309
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2310
+ finally {
2311
+ try {
2312
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
980
2313
  }
981
- var functionName = listItemParts.pop();
982
- return {
983
- type: 'POSTPROCESS',
984
- functionName: functionName,
985
- };
2314
+ finally { if (e_1) throw e_1.error; }
986
2315
  }
987
- else if (type.startsWith('EXPECT_JSON')) {
988
- return {
989
- type: 'EXPECT_FORMAT',
990
- format: 'JSON',
991
- };
992
- // [🥤]
2316
+ if (currentCodeBlock !== null) {
2317
+ // [🌻]
2318
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
993
2319
  }
994
- else if (type.startsWith('EXPECT')) {
995
- try {
996
- listItemParts.shift();
997
- var sign = void 0;
998
- var signRaw = listItemParts.shift();
999
- if (/^exact/i.test(signRaw)) {
1000
- sign = 'EXACTLY';
1001
- }
1002
- else if (/^min/i.test(signRaw)) {
1003
- sign = 'MINIMUM';
1004
- }
1005
- else if (/^max/i.test(signRaw)) {
1006
- sign = 'MAXIMUM';
1007
- }
1008
- else {
1009
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1010
- }
1011
- var amountRaw = listItemParts.shift();
1012
- var amount = parseNumber(amountRaw);
1013
- if (amount < 0) {
1014
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
1015
- }
1016
- if (amount !== Math.floor(amount)) {
1017
- throw new PromptbookSyntaxError('Amount must be whole number');
1018
- }
1019
- var unitRaw = listItemParts.shift();
1020
- var unit = undefined;
2320
+ return codeBlocks;
2321
+ }
2322
+
2323
+ /**
2324
+ * Extracts exactly ONE code block from markdown.
2325
+ *
2326
+ * Note: If there are multiple or no code blocks the function throws an error
2327
+ *
2328
+ * Note: There are 3 simmilar function:
2329
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2330
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2331
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2332
+ *
2333
+ * @param markdown any valid markdown
2334
+ * @returns code block with language and content
2335
+ */
2336
+ function extractOneBlockFromMarkdown(markdown) {
2337
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
2338
+ if (codeBlocks.length !== 1) {
2339
+ // TODO: Report more specific place where the error happened
2340
+ throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
2341
+ }
2342
+ return codeBlocks[0];
2343
+ }
2344
+ /***
2345
+ * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
2346
+ */
2347
+
2348
+ /**
2349
+ * Creates a new set with all elements that are present in either set
2350
+ */
2351
+ function union() {
2352
+ var e_1, _a, e_2, _b;
2353
+ var sets = [];
2354
+ for (var _i = 0; _i < arguments.length; _i++) {
2355
+ sets[_i] = arguments[_i];
2356
+ }
2357
+ var union = new Set();
2358
+ try {
2359
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2360
+ var set = sets_1_1.value;
1021
2361
  try {
1022
- 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()) {
1023
- var existingUnit = EXPECTATION_UNITS_1_1.value;
1024
- var existingUnitText = existingUnit;
1025
- existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
1026
- if (existingUnitText === 'CHARACTER') {
1027
- existingUnitText = 'CHAR';
1028
- }
1029
- if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
1030
- new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
1031
- if (unit !== undefined) {
1032
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
1033
- }
1034
- unit = existingUnit;
1035
- }
2362
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2363
+ var item = _d.value;
2364
+ union.add(item);
1036
2365
  }
1037
2366
  }
1038
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2367
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1039
2368
  finally {
1040
2369
  try {
1041
- if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
2370
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1042
2371
  }
1043
- finally { if (e_1) throw e_1.error; }
1044
- }
1045
- if (unit === undefined) {
1046
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
2372
+ finally { if (e_2) throw e_2.error; }
1047
2373
  }
1048
- return {
1049
- type: 'EXPECT_AMOUNT',
1050
- sign: sign,
1051
- unit: unit,
1052
- amount: amount,
1053
- };
1054
2374
  }
1055
- catch (error) {
1056
- if (!(error instanceof Error)) {
1057
- throw error;
1058
- }
1059
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
2375
+ }
2376
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2377
+ finally {
2378
+ try {
2379
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2380
+ }
2381
+ finally { if (e_1) throw e_1.error; }
2382
+ }
2383
+ return union;
2384
+ }
2385
+
2386
+ /**
2387
+ * Parses the template and returns the list of all parameter names
2388
+ *
2389
+ * @param template the template with parameters in {curly} braces
2390
+ * @returns the list of parameter names
2391
+ */
2392
+ function extractParameters(template) {
2393
+ var e_1, _a;
2394
+ var matches = template.matchAll(/{\w+}/g);
2395
+ var parameterNames = new Set();
2396
+ try {
2397
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
2398
+ var match = matches_1_1.value;
2399
+ var parameterName = match[0].slice(1, -1);
2400
+ parameterNames.add(parameterName);
1060
2401
  }
1061
- /*
1062
- } else if (type.startsWith('__________________')) {
1063
- // <- [🥻] Insert here when making new command
1064
- */
1065
2402
  }
1066
- else {
1067
- 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 ")));
2403
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2404
+ finally {
2405
+ try {
2406
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
2407
+ }
2408
+ finally { if (e_1) throw e_1.error; }
1068
2409
  }
2410
+ return parameterNames;
1069
2411
  }
1070
2412
 
1071
- var defaultDiacriticsRemovalMap = [
1072
- {
1073
- base: 'A',
1074
- 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',
1075
- },
1076
- { base: 'AA', letters: '\uA732' },
1077
- { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
1078
- { base: 'AO', letters: '\uA734' },
1079
- { base: 'AU', letters: '\uA736' },
1080
- { base: 'AV', letters: '\uA738\uA73A' },
1081
- { base: 'AY', letters: '\uA73C' },
1082
- {
1083
- base: 'B',
1084
- letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
1085
- },
1086
- {
1087
- base: 'C',
1088
- letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
1089
- },
1090
- {
1091
- base: 'D',
1092
- letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1093
- },
1094
- { base: 'DZ', letters: '\u01F1\u01C4' },
1095
- { base: 'Dz', letters: '\u01F2\u01C5' },
1096
- {
1097
- base: 'E',
1098
- 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',
1099
- },
1100
- { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1101
- {
1102
- base: 'G',
1103
- letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1104
- },
1105
- {
1106
- base: 'H',
1107
- letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1108
- },
1109
- {
1110
- base: 'I',
1111
- letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1112
- },
1113
- { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1114
- {
1115
- base: 'K',
1116
- letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1117
- },
1118
- {
1119
- base: 'L',
1120
- letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1121
- },
1122
- { base: 'LJ', letters: '\u01C7' },
1123
- { base: 'Lj', letters: '\u01C8' },
1124
- { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1125
- {
1126
- base: 'N',
1127
- letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1128
- },
1129
- { base: 'NJ', letters: '\u01CA' },
1130
- { base: 'Nj', letters: '\u01CB' },
1131
- {
1132
- base: 'O',
1133
- 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',
1134
- },
1135
- { base: 'OI', letters: '\u01A2' },
1136
- { base: 'OO', letters: '\uA74E' },
1137
- { base: 'OU', letters: '\u0222' },
1138
- { base: 'OE', letters: '\u008C\u0152' },
1139
- { base: 'oe', letters: '\u009C\u0153' },
1140
- {
1141
- base: 'P',
1142
- letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1143
- },
1144
- { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1145
- {
1146
- base: 'R',
1147
- letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1148
- },
1149
- {
1150
- base: 'S',
1151
- letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1152
- },
1153
- {
1154
- base: 'T',
1155
- letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1156
- },
1157
- { base: 'TZ', letters: '\uA728' },
1158
- {
1159
- base: 'U',
1160
- 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',
1161
- },
1162
- { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1163
- { base: 'VY', letters: '\uA760' },
1164
- {
1165
- base: 'W',
1166
- letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
1167
- },
1168
- { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
1169
- {
1170
- base: 'Y',
1171
- letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
1172
- },
1173
- {
1174
- base: 'Z',
1175
- letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
1176
- },
1177
- {
1178
- base: 'a',
1179
- 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',
1180
- },
1181
- { base: 'aa', letters: '\uA733' },
1182
- { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
1183
- { base: 'ao', letters: '\uA735' },
1184
- { base: 'au', letters: '\uA737' },
1185
- { base: 'av', letters: '\uA739\uA73B' },
1186
- { base: 'ay', letters: '\uA73D' },
1187
- {
1188
- base: 'b',
1189
- letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
1190
- },
1191
- {
1192
- base: 'c',
1193
- letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
1194
- },
1195
- {
1196
- base: 'd',
1197
- letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
1198
- },
1199
- { base: 'dz', letters: '\u01F3\u01C6' },
1200
- {
1201
- base: 'e',
1202
- 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',
1203
- },
1204
- { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1205
- {
1206
- base: 'g',
1207
- letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1208
- },
1209
- {
1210
- base: 'h',
1211
- letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1212
- },
1213
- { base: 'hv', letters: '\u0195' },
1214
- {
1215
- base: 'i',
1216
- letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1217
- },
1218
- { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1219
- {
1220
- base: 'k',
1221
- letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1222
- },
1223
- {
1224
- base: 'l',
1225
- letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1226
- },
1227
- { base: 'lj', letters: '\u01C9' },
1228
- { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1229
- {
1230
- base: 'n',
1231
- letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1232
- },
1233
- { base: 'nj', letters: '\u01CC' },
1234
- {
1235
- base: 'o',
1236
- 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',
1237
- },
1238
- { base: 'oi', letters: '\u01A3' },
1239
- { base: 'ou', letters: '\u0223' },
1240
- { base: 'oo', letters: '\uA74F' },
1241
- {
1242
- base: 'p',
1243
- letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1244
- },
1245
- { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1246
- {
1247
- base: 'r',
1248
- letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1249
- },
1250
- {
1251
- base: 's',
1252
- letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1253
- },
1254
- {
1255
- base: 't',
1256
- letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1257
- },
1258
- { base: 'tz', letters: '\uA729' },
1259
- {
1260
- base: 'u',
1261
- 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',
1262
- },
1263
- { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1264
- { base: 'vy', letters: '\uA761' },
1265
- {
1266
- base: 'w',
1267
- letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1268
- },
1269
- { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1270
- {
1271
- base: 'y',
1272
- letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1273
- },
1274
- {
1275
- base: 'z',
1276
- letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1277
- },
1278
- ];
1279
2413
  /**
1280
- * Map of letters from diacritic variant to diacritless variant
1281
- * Contains lowercase and uppercase separatelly
2414
+ * Parses the given script and returns the list of all used variables that are not defined in the script
2415
+ *
2416
+ * @param script from which to extract the variables
2417
+ * @returns the list of variable names
2418
+ * @throws {PromptbookSyntaxError} if the script is invalid
2419
+ */
2420
+ function extractVariables(script) {
2421
+ var variables = new Set();
2422
+ script = "(()=>{".concat(script, "})()");
2423
+ try {
2424
+ for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
2425
+ try {
2426
+ eval(script);
2427
+ }
2428
+ catch (error) {
2429
+ if (!(error instanceof ReferenceError)) {
2430
+ throw error;
2431
+ }
2432
+ var undefinedName = error.message.split(' ')[0];
2433
+ /*
2434
+ Note: Remapping error
2435
+ From: [ReferenceError: thing is not defined],
2436
+ To: [Error: Parameter {thing} is not defined],
2437
+ */
2438
+ if (!undefinedName) {
2439
+ throw error;
2440
+ }
2441
+ if (script.includes(undefinedName + '(')) {
2442
+ script = "const ".concat(undefinedName, " = ()=>'';") + script;
2443
+ }
2444
+ else {
2445
+ variables.add(undefinedName);
2446
+ script = "const ".concat(undefinedName, " = '';") + script;
2447
+ }
2448
+ }
2449
+ }
2450
+ catch (error) {
2451
+ if (!(error instanceof Error)) {
2452
+ throw error;
2453
+ }
2454
+ 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 "); }));
2455
+ }
2456
+ return variables;
2457
+ }
2458
+ /**
2459
+ * TODO: [🔣] Support for multiple languages - python, java,...
2460
+ */
2461
+
2462
+ /**
2463
+ * Parses the prompt template and returns the set of all used parameters
1282
2464
  *
1283
- * > "á" => "a"
1284
- * > "ě" => "e"
1285
- * > "Ă" => "A"
1286
- * > ...
2465
+ * @param promptTemplate the template with used parameters
2466
+ * @returns the set of parameter names
2467
+ * @throws {PromptbookSyntaxError} if the script is invalid
1287
2468
  */
1288
- var DIACRITIC_VARIANTS_LETTERS = {};
1289
- // tslint:disable-next-line: prefer-for-of
1290
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1291
- var letters = defaultDiacriticsRemovalMap[i].letters;
1292
- // tslint:disable-next-line: prefer-for-of
1293
- for (var j = 0; j < letters.length; j++) {
1294
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
2469
+ function extractParametersFromPromptTemplate(promptTemplate) {
2470
+ var e_1, _a, e_2, _b;
2471
+ var parameterNames = new Set();
2472
+ try {
2473
+ 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()) {
2474
+ var parameterName = _d.value;
2475
+ parameterNames.add(parameterName);
2476
+ }
2477
+ }
2478
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2479
+ finally {
2480
+ try {
2481
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2482
+ }
2483
+ finally { if (e_1) throw e_1.error; }
2484
+ }
2485
+ if (promptTemplate.executionType === 'SCRIPT') {
2486
+ try {
2487
+ for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
2488
+ var parameterName = _f.value;
2489
+ parameterNames.add(parameterName);
2490
+ }
2491
+ }
2492
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2493
+ finally {
2494
+ try {
2495
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
2496
+ }
2497
+ finally { if (e_2) throw e_2.error; }
2498
+ }
1295
2499
  }
2500
+ return parameterNames;
1296
2501
  }
1297
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
2502
+ /**
2503
+ * TODO: [🔣] If script require contentLanguage
2504
+ */
2505
+
2506
+ /* tslint:disable */
1298
2507
  /*
1299
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1300
- Licensed under the Apache License, Version 2.0 (the "License");
1301
- you may not use this file except in compliance with the License.
1302
- You may obtain a copy of the License at
2508
+ TODO: Tests
2509
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
2510
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
2511
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
2512
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
2513
+ */
2514
+ function normalizeTo_SCREAMING_CASE(sentence) {
2515
+ var e_1, _a;
2516
+ var charType;
2517
+ var lastCharType = 'OTHER';
2518
+ var normalizedName = '';
2519
+ try {
2520
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
2521
+ var char = sentence_1_1.value;
2522
+ var normalizedChar = void 0;
2523
+ if (/^[a-z]$/.test(char)) {
2524
+ charType = 'LOWERCASE';
2525
+ normalizedChar = char.toUpperCase();
2526
+ }
2527
+ else if (/^[A-Z]$/.test(char)) {
2528
+ charType = 'UPPERCASE';
2529
+ normalizedChar = char;
2530
+ }
2531
+ else if (/^[0-9]$/.test(char)) {
2532
+ charType = 'NUMBER';
2533
+ normalizedChar = char;
2534
+ }
2535
+ else if (/^\/$/.test(char)) {
2536
+ charType = 'SLASH';
2537
+ normalizedChar = char;
2538
+ }
2539
+ else {
2540
+ charType = 'OTHER';
2541
+ normalizedChar = '_';
2542
+ }
2543
+ if (charType !== lastCharType &&
2544
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
2545
+ !(lastCharType === 'NUMBER') &&
2546
+ !(charType === 'NUMBER')) {
2547
+ normalizedName += '_';
2548
+ }
2549
+ normalizedName += normalizedChar;
2550
+ lastCharType = charType;
2551
+ }
2552
+ }
2553
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2554
+ finally {
2555
+ try {
2556
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
2557
+ }
2558
+ finally { if (e_1) throw e_1.error; }
2559
+ }
2560
+ normalizedName = normalizedName.replace(/_+/g, '_');
2561
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
2562
+ normalizedName = normalizedName.replace(/^_/, '');
2563
+ normalizedName = normalizedName.replace(/_$/, '');
2564
+ return normalizedName;
2565
+ }
2566
+ /**
2567
+ * TODO: [🌺] Use some intermediate util splitWords
2568
+ */
1303
2569
 
1304
- http://www.apache.org/licenses/LICENSE-2.0
2570
+ /**
2571
+ * Execution type describes the way how the block is executed
2572
+ *
2573
+ * @see https://github.com/webgptorg/promptbook#execution-type
2574
+ */
2575
+ var ExecutionTypes = [
2576
+ 'PROMPT_TEMPLATE',
2577
+ 'SIMPLE_TEMPLATE',
2578
+ 'SCRIPT',
2579
+ 'PROMPT_DIALOG',
2580
+ // <- [🥻] Insert here when making new command
2581
+ ];
1305
2582
 
1306
- Unless required by applicable law or agreed to in writing, software
1307
- distributed under the License is distributed on an "AS IS" BASIS,
1308
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1309
- See the License for the specific language governing permissions and
1310
- limitations under the License.
1311
- */
2583
+ /**
2584
+ * Units of text measurement
2585
+ */
2586
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
2587
+ /**
2588
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
2589
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
2590
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
2591
+ */
1312
2592
 
1313
2593
  /**
2594
+ * Removes Markdown formatting tags from a string.
1314
2595
  *
2596
+ * @param {string} str - The string to remove Markdown tags from.
2597
+ * @returns {string} The input string with all Markdown tags removed.
1315
2598
  */
1316
- function removeDiacritics(input) {
1317
- /*eslint no-control-regex: "off"*/
1318
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1319
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1320
- });
2599
+ function removeMarkdownFormatting(str) {
2600
+ // Remove bold formatting
2601
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
2602
+ // Remove italic formatting
2603
+ str = str.replace(/\*(.*?)\*/g, '$1');
2604
+ // Remove code formatting
2605
+ str = str.replace(/`(.*?)`/g, '$1');
2606
+ return str;
1321
2607
  }
1322
2608
 
1323
- /* tslint:disable */
1324
- function normalizeToKebabCase(sentence) {
2609
+ /**
2610
+ * Function parseNumber will parse number from string
2611
+ *
2612
+ * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
2613
+ * Note: it also works only with decimal numbers
2614
+ *
2615
+ * @returns parsed number
2616
+ * @throws {PromptbookSyntaxError} if the value is not a number
2617
+ *
2618
+ * @private within the parseCommand
2619
+ */
2620
+ function parseNumber(value) {
2621
+ var originalValue = value;
2622
+ if (typeof value === 'number') {
2623
+ value = value.toString(); // <- TODO: Maybe more efficient way to do this
2624
+ }
2625
+ if (typeof value !== 'string') {
2626
+ return 0;
2627
+ }
2628
+ value = value.trim();
2629
+ if (value.startsWith('+')) {
2630
+ return parseNumber(value.substring(1));
2631
+ }
2632
+ if (value.startsWith('-')) {
2633
+ var number = parseNumber(value.substring(1));
2634
+ if (number === 0) {
2635
+ return 0; // <- Note: To prevent -0
2636
+ }
2637
+ return -number;
2638
+ }
2639
+ value = value.replace(/,/g, '.');
2640
+ value = value.toUpperCase();
2641
+ if (value === '') {
2642
+ return 0;
2643
+ }
2644
+ if (value === '♾' || value.startsWith('INF')) {
2645
+ return Infinity;
2646
+ }
2647
+ if (value.includes('/')) {
2648
+ var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
2649
+ var numerator = parseNumber(numerator_);
2650
+ var denominator = parseNumber(denominator_);
2651
+ if (denominator === 0) {
2652
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2653
+ }
2654
+ return numerator / denominator;
2655
+ }
2656
+ if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
2657
+ return 0;
2658
+ }
2659
+ if (value.includes('E')) {
2660
+ var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
2661
+ return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
2662
+ }
2663
+ if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
2664
+ throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
2665
+ }
2666
+ var num = parseFloat(value);
2667
+ if (isNaN(num)) {
2668
+ throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2669
+ }
2670
+ return num;
2671
+ }
2672
+ /**
2673
+ * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
2674
+ */
2675
+
2676
+ /**
2677
+ * Parses one line of ul/ol to command
2678
+ *
2679
+ * @returns parsed command object
2680
+ * @throws {PromptbookSyntaxError} if the command is invalid
2681
+ *
2682
+ * @private within the promptbookStringToJson
2683
+ */
2684
+ function parseCommand(listItem) {
1325
2685
  var e_1, _a;
1326
- sentence = removeDiacritics(sentence);
1327
- var charType;
1328
- var lastCharType = 'OTHER';
1329
- var normalizedName = '';
1330
- try {
1331
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1332
- var char = sentence_1_1.value;
1333
- var normalizedChar = void 0;
1334
- if (/^[a-z]$/.test(char)) {
1335
- charType = 'LOWERCASE';
1336
- normalizedChar = char;
2686
+ if (listItem.includes('\n') || listItem.includes('\r')) {
2687
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
2688
+ }
2689
+ var type = listItem.trim();
2690
+ type = type.split('`').join('');
2691
+ type = type.split('"').join('');
2692
+ type = type.split("'").join('');
2693
+ type = type.split('~').join('');
2694
+ type = type.split('[').join('');
2695
+ type = type.split(']').join('');
2696
+ type = type.split('(').join('');
2697
+ type = type.split(')').join('');
2698
+ type = normalizeTo_SCREAMING_CASE(type);
2699
+ type = type.split('DIALOGUE').join('DIALOG');
2700
+ var listItemParts = listItem
2701
+ .split(' ')
2702
+ .map(function (part) { return part.trim(); })
2703
+ .filter(function (item) { return item !== ''; })
2704
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
2705
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
2706
+ .map(removeMarkdownFormatting);
2707
+ if (type.startsWith('URL') ||
2708
+ type.startsWith('PTBK_URL') ||
2709
+ type.startsWith('PTBKURL') ||
2710
+ type.startsWith('PROMPTBOOK_URL') ||
2711
+ type.startsWith('PROMPTBOOKURL') ||
2712
+ type.startsWith('HTTPS')) {
2713
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
2714
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
2715
+ }
2716
+ var promptbookUrlString = listItemParts.pop();
2717
+ var promptbookUrl = new URL(promptbookUrlString);
2718
+ if (promptbookUrl.protocol !== 'https:') {
2719
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2720
+ }
2721
+ if (promptbookUrl.hash !== '') {
2722
+ 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 ")));
2723
+ }
2724
+ return {
2725
+ type: 'PROMPTBOOK_URL',
2726
+ promptbookUrl: promptbookUrl,
2727
+ };
2728
+ }
2729
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
2730
+ if (listItemParts.length !== 2) {
2731
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2732
+ }
2733
+ var promptbookVersion = listItemParts.pop();
2734
+ // TODO: Validate version
2735
+ return {
2736
+ type: 'PROMPTBOOK_VERSION',
2737
+ promptbookVersion: promptbookVersion,
2738
+ };
2739
+ }
2740
+ else if (type.startsWith('EXECUTE') ||
2741
+ type.startsWith('EXEC') ||
2742
+ type.startsWith('PROMPT_DIALOG') ||
2743
+ type.startsWith('SIMPLE_TEMPLATE')) {
2744
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
2745
+ if (executionTypes.length !== 1) {
2746
+ 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 "); }));
2747
+ }
2748
+ return {
2749
+ type: 'EXECUTE',
2750
+ executionType: executionTypes[0],
2751
+ };
2752
+ }
2753
+ else if (type.startsWith('MODEL')) {
2754
+ // TODO: Make this more elegant and dynamically
2755
+ if (type.startsWith('MODEL_VARIANT')) {
2756
+ if (type === 'MODEL_VARIANT_CHAT') {
2757
+ return {
2758
+ type: 'MODEL',
2759
+ key: 'modelVariant',
2760
+ value: 'CHAT',
2761
+ };
1337
2762
  }
1338
- else if (/^[A-Z]$/.test(char)) {
1339
- charType = 'UPPERCASE';
1340
- normalizedChar = char.toLowerCase();
2763
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
2764
+ return {
2765
+ type: 'MODEL',
2766
+ key: 'modelVariant',
2767
+ value: 'COMPLETION',
2768
+ };
1341
2769
  }
1342
- else if (/^[0-9]$/.test(char)) {
1343
- charType = 'NUMBER';
1344
- normalizedChar = char;
2770
+ else {
2771
+ 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 "); }));
1345
2772
  }
1346
- else if (/^\/$/.test(char)) {
1347
- charType = 'SLASH';
1348
- normalizedChar = char;
2773
+ }
2774
+ if (type.startsWith('MODEL_NAME')) {
2775
+ return {
2776
+ type: 'MODEL',
2777
+ key: 'modelName',
2778
+ value: listItemParts.pop(),
2779
+ };
2780
+ }
2781
+ else {
2782
+ 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 "); }));
2783
+ }
2784
+ }
2785
+ else if (type.startsWith('PARAM') ||
2786
+ type.startsWith('INPUT_PARAM') ||
2787
+ type.startsWith('OUTPUT_PARAM') ||
2788
+ listItem.startsWith('{') ||
2789
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
2790
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
2791
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2792
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2793
+ }
2794
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2795
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
2796
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
2797
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
2798
+ }
2799
+ var isInput = type.startsWith('INPUT');
2800
+ var isOutput = type.startsWith('OUTPUT');
2801
+ if (listItem.startsWith('> {')) {
2802
+ isInput = false;
2803
+ isOutput = false;
2804
+ }
2805
+ return {
2806
+ type: 'PARAMETER',
2807
+ parameterName: parameterName,
2808
+ parameterDescription: parameterDescription.trim() || null,
2809
+ isInput: isInput,
2810
+ isOutput: isOutput,
2811
+ };
2812
+ }
2813
+ else if (type.startsWith('JOKER')) {
2814
+ if (listItemParts.length !== 2) {
2815
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
2816
+ }
2817
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
2818
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2819
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2820
+ }
2821
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2822
+ var parameterName = parametersMatch.groups.parameterName;
2823
+ return {
2824
+ type: 'JOKER',
2825
+ parameterName: parameterName,
2826
+ };
2827
+ }
2828
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
2829
+ if (listItemParts.length !== 2) {
2830
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2831
+ }
2832
+ var functionName = listItemParts.pop();
2833
+ return {
2834
+ type: 'POSTPROCESS',
2835
+ functionName: functionName,
2836
+ };
2837
+ }
2838
+ else if (type.startsWith('EXPECT_JSON')) {
2839
+ return {
2840
+ type: 'EXPECT_FORMAT',
2841
+ format: 'JSON',
2842
+ };
2843
+ // [🥤]
2844
+ }
2845
+ else if (type.startsWith('EXPECT')) {
2846
+ try {
2847
+ listItemParts.shift();
2848
+ var sign = void 0;
2849
+ var signRaw = listItemParts.shift();
2850
+ if (/^exact/i.test(signRaw)) {
2851
+ sign = 'EXACTLY';
2852
+ }
2853
+ else if (/^min/i.test(signRaw)) {
2854
+ sign = 'MINIMUM';
2855
+ }
2856
+ else if (/^max/i.test(signRaw)) {
2857
+ sign = 'MAXIMUM';
1349
2858
  }
1350
2859
  else {
1351
- charType = 'OTHER';
1352
- normalizedChar = '-';
2860
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1353
2861
  }
1354
- if (charType !== lastCharType &&
1355
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1356
- !(lastCharType === 'NUMBER') &&
1357
- !(charType === 'NUMBER')) {
1358
- normalizedName += '-';
2862
+ var amountRaw = listItemParts.shift();
2863
+ var amount = parseNumber(amountRaw);
2864
+ if (amount < 0) {
2865
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
1359
2866
  }
1360
- normalizedName += normalizedChar;
1361
- lastCharType = charType;
2867
+ if (amount !== Math.floor(amount)) {
2868
+ throw new PromptbookSyntaxError('Amount must be whole number');
2869
+ }
2870
+ var unitRaw = listItemParts.shift();
2871
+ var unit = undefined;
2872
+ try {
2873
+ 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()) {
2874
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
2875
+ var existingUnitText = existingUnit;
2876
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
2877
+ if (existingUnitText === 'CHARACTER') {
2878
+ existingUnitText = 'CHAR';
2879
+ }
2880
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
2881
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
2882
+ if (unit !== undefined) {
2883
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
2884
+ }
2885
+ unit = existingUnit;
2886
+ }
2887
+ }
2888
+ }
2889
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2890
+ finally {
2891
+ try {
2892
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
2893
+ }
2894
+ finally { if (e_1) throw e_1.error; }
2895
+ }
2896
+ if (unit === undefined) {
2897
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
2898
+ }
2899
+ return {
2900
+ type: 'EXPECT_AMOUNT',
2901
+ sign: sign,
2902
+ unit: unit,
2903
+ amount: amount,
2904
+ };
1362
2905
  }
1363
- }
1364
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1365
- finally {
1366
- try {
1367
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
2906
+ catch (error) {
2907
+ if (!(error instanceof Error)) {
2908
+ throw error;
2909
+ }
2910
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1368
2911
  }
1369
- finally { if (e_1) throw e_1.error; }
2912
+ /*
2913
+ } else if (type.startsWith('__________________')) {
2914
+ // <- [🥻] Insert here when making new command
2915
+ */
2916
+ }
2917
+ else {
2918
+ 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 ")));
1370
2919
  }
1371
- normalizedName = normalizedName.split(/-+/g).join('-');
1372
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1373
- normalizedName = normalizedName.replace(/^-/, '');
1374
- normalizedName = normalizedName.replace(/-$/, '');
1375
- return normalizedName;
1376
2920
  }
1377
2921
 
1378
2922
  /**
@@ -1431,7 +2975,10 @@
1431
2975
  knowledge: [],
1432
2976
  };
1433
2977
  if (!llmTools) return [3 /*break*/, 2];
1434
- return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
2978
+ return [4 /*yield*/, prepareKnowledgeFromMarkdown({
2979
+ content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
2980
+ llmTools: llmTools,
2981
+ })];
1435
2982
  case 1:
1436
2983
  knowledge = _e.sent();
1437
2984
  console.info('!!!! knowledge', knowledge);
@@ -1449,7 +2996,7 @@
1449
2996
  existingParameter.description &&
1450
2997
  existingParameter.description !== parameterDescription &&
1451
2998
  parameterDescription) {
1452
- 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 "); }));
2999
+ 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 "); }));
1453
3000
  }
1454
3001
  if (existingParameter) {
1455
3002
  if (parameterDescription) {
@@ -1468,7 +3015,7 @@
1468
3015
  markdownStructure = markdownToMarkdownStructure(promptbookString);
1469
3016
  markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1470
3017
  if (markdownStructureDeepness !== 2) {
1471
- 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 ")));
3018
+ 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 ")));
1472
3019
  }
1473
3020
  promptbookJson.title = markdownStructure.title;
1474
3021
  description = markdownStructure.content;
@@ -1476,7 +3023,7 @@
1476
3023
  description = description.split(/^```.*^```/gms).join('');
1477
3024
  //Note: Remove lists and return statement
1478
3025
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1479
- description = spacetrim.spaceTrim(description);
3026
+ description = spaceTrim.spaceTrim(description);
1480
3027
  if (description === '') {
1481
3028
  description = undefined;
1482
3029
  }
@@ -1591,13 +3138,13 @@
1591
3138
  throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1592
3139
  }
1593
3140
  else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1594
- 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 "); }));
3141
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
1595
3142
  }
1596
3143
  }
1597
3144
  var lastLine = section.content.split('\n').pop();
1598
3145
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1599
3146
  if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1600
- throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
3147
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1601
3148
  // TODO: Show code of invalid sections each time + DRY
1602
3149
  section.content
1603
3150
  .split('\n')
@@ -1611,7 +3158,7 @@
1611
3158
  description_1 = description_1.split(/^```.*^```/gms).join('');
1612
3159
  //Note: Remove lists and return statement
1613
3160
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1614
- description_1 = spacetrim.spaceTrim(description_1);
3161
+ description_1 = spaceTrim.spaceTrim(description_1);
1615
3162
  if (description_1 === '') {
1616
3163
  description_1 = undefined;
1617
3164
  }
@@ -1745,7 +3292,7 @@
1745
3292
  }
1746
3293
  return normalizeTo_camelCase('template-' + titleToName(template.title));
1747
3294
  };
1748
- var promptbookMermaid = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
3295
+ var promptbookMermaid = spaceTrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
1749
3296
  .flatMap(function (_a) {
1750
3297
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1751
3298
  return __spreadArray([
@@ -1801,7 +3348,7 @@
1801
3348
  return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
1802
3349
  },
1803
3350
  });
1804
- promptbookMermaidBlock = spacetrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
3351
+ promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1805
3352
  promptbookString = addAutoGeneratedSection(promptbookString, {
1806
3353
  sectionName: 'Graph',
1807
3354
  sectionContent: promptbookMermaidBlock,
@@ -1830,14 +3377,14 @@
1830
3377
  var _this = this;
1831
3378
  return __generator(this, function (_a) {
1832
3379
  if (!isRunningInNode()) {
1833
- throw new Error(spacetrim.spaceTrim("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
3380
+ throw new Error(spaceTrim.spaceTrim("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
1834
3381
  }
1835
3382
  program = new commander__default["default"].Command();
1836
3383
  program.name('promptbook');
1837
3384
  program.version(PROMPTBOOK_VERSION);
1838
- program.description(spacetrim.spaceTrim("\n Promptbook utilities\n "));
3385
+ program.description(spaceTrim.spaceTrim("\n Promptbook utilities\n "));
1839
3386
  prettifyCommand = program.command('prettify');
1840
- prettifyCommand.description(spacetrim.spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
3387
+ prettifyCommand.description(spaceTrim.spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
1841
3388
  prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
1842
3389
  prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
1843
3390
  prettifyCommand.action(function (filesGlob, _a) {
@@ -1912,7 +3459,7 @@
1912
3459
  });
1913
3460
  });
1914
3461
  helloCommand = program.command('hello');
1915
- helloCommand.description(spacetrim.spaceTrim("\n Just command for testing\n "));
3462
+ helloCommand.description(spaceTrim.spaceTrim("\n Just command for testing\n "));
1916
3463
  helloCommand.argument('<name>', 'Your name');
1917
3464
  helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
1918
3465
  helloCommand.action(function (name, _a) {