@promptbook/javascript 0.88.0-1

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 (694) hide show
  1. package/README.md +431 -0
  2. package/esm/index.es.js +1796 -0
  3. package/esm/index.es.js.map +1 -0
  4. package/esm/typings/books/index.d.ts +131 -0
  5. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +16 -0
  6. package/esm/typings/src/_packages/azure-openai.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/browser.index.d.ts +10 -0
  8. package/esm/typings/src/_packages/cli.index.d.ts +56 -0
  9. package/esm/typings/src/_packages/core.index.d.ts +260 -0
  10. package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
  11. package/esm/typings/src/_packages/documents.index.d.ts +8 -0
  12. package/esm/typings/src/_packages/editable.index.d.ts +90 -0
  13. package/esm/typings/src/_packages/fake-llm.index.d.ts +6 -0
  14. package/esm/typings/src/_packages/google.index.d.ts +10 -0
  15. package/esm/typings/src/_packages/javascript.index.d.ts +10 -0
  16. package/esm/typings/src/_packages/legacy-documents.index.d.ts +8 -0
  17. package/esm/typings/src/_packages/markdown-utils.index.d.ts +48 -0
  18. package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
  19. package/esm/typings/src/_packages/node.index.d.ts +24 -0
  20. package/esm/typings/src/_packages/openai.index.d.ts +20 -0
  21. package/esm/typings/src/_packages/pdf.index.d.ts +14 -0
  22. package/esm/typings/src/_packages/remote-client.index.d.ts +18 -0
  23. package/esm/typings/src/_packages/remote-server.index.d.ts +12 -0
  24. package/esm/typings/src/_packages/templates.index.d.ts +4 -0
  25. package/esm/typings/src/_packages/types.index.d.ts +564 -0
  26. package/esm/typings/src/_packages/utils.index.d.ts +162 -0
  27. package/esm/typings/src/_packages/vercel.index.d.ts +6 -0
  28. package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
  29. package/esm/typings/src/_packages/wizzard.index.d.ts +56 -0
  30. package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
  31. package/esm/typings/src/cli/cli-commands/about.d.ts +14 -0
  32. package/esm/typings/src/cli/cli-commands/hello.d.ts +14 -0
  33. package/esm/typings/src/cli/cli-commands/list-models.d.ts +13 -0
  34. package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
  35. package/esm/typings/src/cli/cli-commands/make.d.ts +16 -0
  36. package/esm/typings/src/cli/cli-commands/prettify.d.ts +15 -0
  37. package/esm/typings/src/cli/cli-commands/run.d.ts +17 -0
  38. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
  39. package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
  40. package/esm/typings/src/cli/cli-commands/test-command.d.ts +16 -0
  41. package/esm/typings/src/cli/main.d.ts +16 -0
  42. package/esm/typings/src/cli/promptbookCli.d.ts +13 -0
  43. package/esm/typings/src/cli/test/ptbk.d.ts +5 -0
  44. package/esm/typings/src/cli/test/ptbk.test.d.ts +1 -0
  45. package/esm/typings/src/cli/test/ptbk2.d.ts +5 -0
  46. package/esm/typings/src/collection/PipelineCollection.d.ts +27 -0
  47. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +37 -0
  48. package/esm/typings/src/collection/collectionToJson.d.ts +13 -0
  49. package/esm/typings/src/collection/collectionToJson.test.d.ts +7 -0
  50. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +65 -0
  51. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.test.d.ts +1 -0
  52. package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +13 -0
  53. package/esm/typings/src/collection/constructors/createCollectionFromJson.test.d.ts +1 -0
  54. package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +23 -0
  55. package/esm/typings/src/collection/constructors/createCollectionFromPromise.test.d.ts +1 -0
  56. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +29 -0
  57. package/esm/typings/src/collection/constructors/createSubcollection.d.ts +13 -0
  58. package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +11 -0
  59. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommand.test.d.ts +1 -0
  60. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
  61. package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +17 -0
  62. package/esm/typings/src/commands/EXPECT/expectCommand.test.d.ts +1 -0
  63. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
  64. package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +10 -0
  65. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +27 -0
  66. package/esm/typings/src/commands/FOREACH/foreachCommand.test.d.ts +1 -0
  67. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +14 -0
  68. package/esm/typings/src/commands/FORMAT/FormatCommand.d.ts +9 -0
  69. package/esm/typings/src/commands/FORMAT/formatCommand.test.d.ts +1 -0
  70. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +9 -0
  71. package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +11 -0
  72. package/esm/typings/src/commands/FORMFACTOR/formfactorCommand.test.d.ts +1 -0
  73. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +11 -0
  74. package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
  75. package/esm/typings/src/commands/JOKER/jokerCommand.test.d.ts +1 -0
  76. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
  77. package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +11 -0
  78. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommand.test.d.ts +1 -0
  79. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +12 -0
  80. package/esm/typings/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.d.ts +11 -0
  81. package/esm/typings/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.test.d.ts +4 -0
  82. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +14 -0
  83. package/esm/typings/src/commands/MODEL/modelCommand.test.d.ts +1 -0
  84. package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +10 -0
  85. package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
  86. package/esm/typings/src/commands/PARAMETER/parameterCommand.test.d.ts +1 -0
  87. package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
  88. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +13 -0
  89. package/esm/typings/src/commands/PERSONA/personaCommand.test.d.ts +1 -0
  90. package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
  91. package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
  92. package/esm/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts +1 -0
  93. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
  94. package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +11 -0
  95. package/esm/typings/src/commands/SECTION/sectionCommand.test.d.ts +1 -0
  96. package/esm/typings/src/commands/SECTION/sectionCommandParser.d.ts +20 -0
  97. package/esm/typings/src/commands/URL/UrlCommand.d.ts +10 -0
  98. package/esm/typings/src/commands/URL/urlCommand.test.d.ts +1 -0
  99. package/esm/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
  100. package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
  101. package/esm/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
  102. package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +12 -0
  103. package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
  104. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
  105. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +12 -0
  106. package/esm/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
  107. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
  108. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +11 -0
  109. package/esm/typings/src/commands/_common/getParserForCommand.d.ts +11 -0
  110. package/esm/typings/src/commands/_common/getParserForCommand.test.d.ts +1 -0
  111. package/esm/typings/src/commands/_common/parseCommand.d.ts +12 -0
  112. package/esm/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
  113. package/esm/typings/src/commands/_common/stringifyCommand.d.ts +12 -0
  114. package/esm/typings/src/commands/_common/stringifyCommand.test.d.ts +1 -0
  115. package/esm/typings/src/commands/_common/types/Command.d.ts +6 -0
  116. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +197 -0
  117. package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
  118. package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +13 -0
  119. package/esm/typings/src/commands/index.d.ts +9 -0
  120. package/esm/typings/src/config.d.ts +285 -0
  121. package/esm/typings/src/config.test.d.ts +4 -0
  122. package/esm/typings/src/constants.d.ts +35 -0
  123. package/esm/typings/src/conversion/archive/loadArchive.d.ts +16 -0
  124. package/esm/typings/src/conversion/archive/saveArchive.d.ts +18 -0
  125. package/esm/typings/src/conversion/compilePipeline.d.ts +25 -0
  126. package/esm/typings/src/conversion/compilePipeline.test.d.ts +1 -0
  127. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +21 -0
  128. package/esm/typings/src/conversion/parsePipeline.d.ts +30 -0
  129. package/esm/typings/src/conversion/parsePipeline.test.d.ts +1 -0
  130. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +18 -0
  131. package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +13 -0
  132. package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +12 -0
  133. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +30 -0
  134. package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +15 -0
  135. package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.test.d.ts +1 -0
  136. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +23 -0
  137. package/esm/typings/src/conversion/validation/pipelineStringToJson-parseErrors.test.d.ts +4 -0
  138. package/esm/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +4 -0
  139. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +42 -0
  140. package/esm/typings/src/conversion/validation/validatePipeline.test.d.ts +4 -0
  141. package/esm/typings/src/dialogs/callback/CallbackInterfaceTools.d.ts +17 -0
  142. package/esm/typings/src/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +14 -0
  143. package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +22 -0
  144. package/esm/typings/src/dialogs/user-interface-execution-tools.test.d.ts +1 -0
  145. package/esm/typings/src/errors/0-BoilerplateError.d.ts +12 -0
  146. package/esm/typings/src/errors/0-index.d.ts +85 -0
  147. package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
  148. package/esm/typings/src/errors/CollectionError.d.ts +9 -0
  149. package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +9 -0
  150. package/esm/typings/src/errors/ExpectError.d.ts +12 -0
  151. package/esm/typings/src/errors/KnowledgeScrapeError.d.ts +9 -0
  152. package/esm/typings/src/errors/LimitReachedError.d.ts +9 -0
  153. package/esm/typings/src/errors/MissingToolsError.d.ts +9 -0
  154. package/esm/typings/src/errors/NotFoundError.d.ts +9 -0
  155. package/esm/typings/src/errors/NotYetImplementedError.d.ts +9 -0
  156. package/esm/typings/src/errors/ParseError.d.ts +12 -0
  157. package/esm/typings/src/errors/PipelineExecutionError.d.ts +9 -0
  158. package/esm/typings/src/errors/PipelineLogicError.d.ts +9 -0
  159. package/esm/typings/src/errors/PipelineUrlError.d.ts +9 -0
  160. package/esm/typings/src/errors/UnexpectedError.d.ts +9 -0
  161. package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
  162. package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
  163. package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
  164. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
  165. package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
  166. package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
  167. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
  168. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
  169. package/esm/typings/src/executables/apps/locateLibreoffice.test.d.ts +1 -0
  170. package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
  171. package/esm/typings/src/executables/apps/locatePandoc.test.d.ts +1 -0
  172. package/esm/typings/src/executables/locateApp.d.ts +33 -0
  173. package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
  174. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
  175. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
  176. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
  177. package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
  178. package/esm/typings/src/execution/AvailableModel.d.ts +38 -0
  179. package/esm/typings/src/execution/CommonToolsOptions.d.ts +24 -0
  180. package/esm/typings/src/execution/EmbeddingVector.d.ts +8 -0
  181. package/esm/typings/src/execution/Executables.d.ts +18 -0
  182. package/esm/typings/src/execution/ExecutionTask.d.ts +75 -0
  183. package/esm/typings/src/execution/ExecutionTools.d.ts +69 -0
  184. package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
  185. package/esm/typings/src/execution/LlmExecutionTools.d.ts +61 -0
  186. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +10 -0
  187. package/esm/typings/src/execution/PipelineExecutor.d.ts +16 -0
  188. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +37 -0
  189. package/esm/typings/src/execution/PromptResult.d.ts +101 -0
  190. package/esm/typings/src/execution/PromptResultUsage.d.ts +33 -0
  191. package/esm/typings/src/execution/PromptbookFetch.d.ts +12 -0
  192. package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
  193. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +39 -0
  194. package/esm/typings/src/execution/UncertainNumber.d.ts +19 -0
  195. package/esm/typings/src/execution/UserInterfaceTools.d.ts +46 -0
  196. package/esm/typings/src/execution/assertsTaskSuccessful.d.ts +14 -0
  197. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +45 -0
  198. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +46 -0
  199. package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +10 -0
  200. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +45 -0
  201. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +48 -0
  202. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -0
  203. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +64 -0
  204. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +34 -0
  205. package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +10 -0
  206. package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +10 -0
  207. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +27 -0
  208. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +30 -0
  209. package/esm/typings/src/execution/embeddingVectorToString.d.ts +7 -0
  210. package/esm/typings/src/execution/execution-report/ExecutionPromptReportJson.d.ts +24 -0
  211. package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +41 -0
  212. package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +16 -0
  213. package/esm/typings/src/execution/execution-report/ExecutionReportStringOptions.d.ts +25 -0
  214. package/esm/typings/src/execution/execution-report/countWorkingDuration.d.ts +7 -0
  215. package/esm/typings/src/execution/execution-report/countWorkingDuration.test.d.ts +1 -0
  216. package/esm/typings/src/execution/execution-report/executionReportJsonToString.d.ts +15 -0
  217. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +7 -0
  218. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +11 -0
  219. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +8 -0
  220. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +22 -0
  221. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +7 -0
  222. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +8 -0
  223. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
  224. package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +12 -0
  225. package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
  226. package/esm/typings/src/execution/utils/addUsage.d.ts +9 -0
  227. package/esm/typings/src/execution/utils/addUsage.test.d.ts +1 -0
  228. package/esm/typings/src/execution/utils/checkExpectations.d.ts +29 -0
  229. package/esm/typings/src/execution/utils/checkExpectations.test.d.ts +1 -0
  230. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +10 -0
  231. package/esm/typings/src/execution/utils/forEachAsync.d.ts +20 -0
  232. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +9 -0
  233. package/esm/typings/src/execution/utils/usage-constants.d.ts +130 -0
  234. package/esm/typings/src/execution/utils/usageToHuman.d.ts +26 -0
  235. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +20 -0
  236. package/esm/typings/src/execution/utils/usageToWorktime.test.d.ts +1 -0
  237. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +10 -0
  238. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +10 -0
  239. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +70 -0
  240. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +31 -0
  241. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +17 -0
  242. package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
  243. package/esm/typings/src/formats/csv/CsvSettings.d.ts +13 -0
  244. package/esm/typings/src/formats/index.d.ts +9 -0
  245. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +19 -0
  246. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +6 -0
  247. package/esm/typings/src/formats/json/utils/isValidJsonString.test.d.ts +1 -0
  248. package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +19 -0
  249. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +19 -0
  250. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +14 -0
  251. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +40 -0
  252. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +8 -0
  253. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +5 -0
  254. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +45 -0
  255. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +24 -0
  256. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +14 -0
  257. package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
  258. package/esm/typings/src/formfactors/index.d.ts +145 -0
  259. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +19 -0
  260. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +25 -0
  261. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +24 -0
  262. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
  263. package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
  264. package/esm/typings/src/high-level-abstractions/index.d.ts +54 -0
  265. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +13 -0
  266. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +13 -0
  267. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +13 -0
  268. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +25 -0
  269. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +24 -0
  270. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +15 -0
  271. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +27 -0
  272. package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +22 -0
  273. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +23 -0
  274. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +36 -0
  275. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +10 -0
  276. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +40 -0
  277. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
  278. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +28 -0
  279. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +19 -0
  280. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +19 -0
  281. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
  282. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +17 -0
  283. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +36 -0
  284. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +60 -0
  285. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +31 -0
  286. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +24 -0
  287. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +18 -0
  288. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.test.d.ts +4 -0
  289. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +19 -0
  290. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +7 -0
  291. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +14 -0
  292. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +16 -0
  293. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +63 -0
  294. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +37 -0
  295. package/esm/typings/src/llm-providers/azure-openai/createAzureOpenAiExecutionTools.d.ts +15 -0
  296. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +6 -0
  297. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +14 -0
  298. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +15 -0
  299. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
  300. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
  301. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
  302. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
  303. package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +9 -0
  304. package/esm/typings/src/llm-providers/google/createGoogleExecutionTools.d.ts +14 -0
  305. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +14 -0
  306. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +15 -0
  307. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +15 -0
  308. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +40 -0
  309. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +44 -0
  310. package/esm/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
  311. package/esm/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
  312. package/esm/typings/src/llm-providers/mocked/test/joker.test.d.ts +4 -0
  313. package/esm/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
  314. package/esm/typings/src/llm-providers/mocked/test/mocked-completion.test.d.ts +4 -0
  315. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +63 -0
  316. package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +21 -0
  317. package/esm/typings/src/llm-providers/multiple/playground/playground.d.ts +5 -0
  318. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +36 -0
  319. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +14 -0
  320. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +84 -0
  321. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
  322. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +18 -0
  323. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.test.d.ts +4 -0
  324. package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +16 -0
  325. package/esm/typings/src/llm-providers/openai/computeUsage.test.d.ts +1 -0
  326. package/esm/typings/src/llm-providers/openai/createOpenAiAssistantExecutionTools.d.ts +15 -0
  327. package/esm/typings/src/llm-providers/openai/createOpenAiExecutionTools.d.ts +15 -0
  328. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +31 -0
  329. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +6 -0
  330. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +24 -0
  331. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +25 -0
  332. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +59 -0
  333. package/esm/typings/src/llm-providers/remote/playground/playground.d.ts +5 -0
  334. package/esm/typings/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +23 -0
  335. package/esm/typings/src/llm-providers/vercel/VercelProvider.d.ts +13 -0
  336. package/esm/typings/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.d.ts +8 -0
  337. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +6 -0
  338. package/esm/typings/src/other/templates/getBookTemplates.d.ts +24 -0
  339. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
  340. package/esm/typings/src/personas/preparePersona.d.ts +17 -0
  341. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +22 -0
  342. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +14 -0
  343. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +11 -0
  344. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +26 -0
  345. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +10 -0
  346. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +100 -0
  347. package/esm/typings/src/pipeline/PipelineJson/DialogTaskJson.d.ts +13 -0
  348. package/esm/typings/src/pipeline/PipelineJson/Expectations.d.ts +40 -0
  349. package/esm/typings/src/pipeline/PipelineJson/KnowledgePieceJson.d.ts +73 -0
  350. package/esm/typings/src/pipeline/PipelineJson/KnowledgeSourceJson.d.ts +44 -0
  351. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +98 -0
  352. package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +45 -0
  353. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +112 -0
  354. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +22 -0
  355. package/esm/typings/src/pipeline/PipelineJson/PromptTaskJson.d.ts +26 -0
  356. package/esm/typings/src/pipeline/PipelineJson/ScriptTaskJson.d.ts +20 -0
  357. package/esm/typings/src/pipeline/PipelineJson/SimpleTaskJson.d.ts +13 -0
  358. package/esm/typings/src/pipeline/PipelineJson/TaskJson.d.ts +11 -0
  359. package/esm/typings/src/pipeline/PipelineString.d.ts +9 -0
  360. package/esm/typings/src/pipeline/book-notation.d.ts +19 -0
  361. package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
  362. package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
  363. package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
  364. package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
  365. package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
  366. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +16 -0
  367. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +25 -0
  368. package/esm/typings/src/postprocessing/utils/extractJsonBlock.test.d.ts +1 -0
  369. package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +51 -0
  370. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +18 -0
  371. package/esm/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
  372. package/esm/typings/src/prepare/preparePipeline.d.ts +22 -0
  373. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +17 -0
  374. package/esm/typings/src/prepare/prepareTasks.d.ts +33 -0
  375. package/esm/typings/src/prepare/unpreparePipeline.d.ts +13 -0
  376. package/esm/typings/src/remote-server/createRemoteClient.d.ts +10 -0
  377. package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Error.d.ts +7 -0
  378. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +52 -0
  379. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +17 -0
  380. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +17 -0
  381. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +17 -0
  382. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Response.d.ts +12 -0
  383. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +17 -0
  384. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Response.d.ts +12 -0
  385. package/esm/typings/src/remote-server/startRemoteServer.d.ts +26 -0
  386. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +32 -0
  387. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +75 -0
  388. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
  389. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
  390. package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
  391. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
  392. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
  393. package/esm/typings/src/scrapers/_common/Converter.d.ts +23 -0
  394. package/esm/typings/src/scrapers/_common/Scraper.d.ts +59 -0
  395. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +14 -0
  396. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +19 -0
  397. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.test.d.ts +1 -0
  398. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
  399. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
  400. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
  401. package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
  402. package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +13 -0
  403. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
  404. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
  405. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +43 -0
  406. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
  407. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +34 -0
  408. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.test.d.ts +4 -0
  409. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +11 -0
  410. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +10 -0
  411. package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +43 -0
  412. package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +4 -0
  413. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
  414. package/esm/typings/src/scrapers/document/playground/document-scraper-playground.d.ts +5 -0
  415. package/esm/typings/src/scrapers/document/register-constructor.d.ts +15 -0
  416. package/esm/typings/src/scrapers/document/register-metadata.d.ts +28 -0
  417. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
  418. package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +4 -0
  419. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
  420. package/esm/typings/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.d.ts +5 -0
  421. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +15 -0
  422. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +28 -0
  423. package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
  424. package/esm/typings/src/scrapers/markdown/MarkdownScraper.test.d.ts +4 -0
  425. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
  426. package/esm/typings/src/scrapers/markdown/playground/markdown-scraper-playground.d.ts +5 -0
  427. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +15 -0
  428. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +28 -0
  429. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
  430. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
  431. package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
  432. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
  433. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
  434. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +41 -0
  435. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
  436. package/esm/typings/src/scrapers/pdf/playground/pdf-scraper-playground.d.ts +5 -0
  437. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +15 -0
  438. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +28 -0
  439. package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +50 -0
  440. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +22 -0
  441. package/esm/typings/src/scrapers/website/playground/website-scraper-playground.d.ts +5 -0
  442. package/esm/typings/src/scrapers/website/register-constructor.d.ts +15 -0
  443. package/esm/typings/src/scrapers/website/register-metadata.d.ts +28 -0
  444. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
  445. package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
  446. package/esm/typings/src/scripting/_test/custom-function-async.test.ts.test.d.ts +1 -0
  447. package/esm/typings/src/scripting/_test/custom-function-missing.test.d.ts +1 -0
  448. package/esm/typings/src/scripting/_test/custom-function-with-dependencies.test.d.ts +1 -0
  449. package/esm/typings/src/scripting/_test/custom-function.test.d.ts +1 -0
  450. package/esm/typings/src/scripting/_test/postprocessing.test.d.ts +1 -0
  451. package/esm/typings/src/scripting/_test/script-execution-errors.test.d.ts +1 -0
  452. package/esm/typings/src/scripting/_test/script-execution-tools.test.d.ts +1 -0
  453. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +22 -0
  454. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  455. package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +8 -0
  456. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +26 -0
  457. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +52 -0
  458. package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +14 -0
  459. package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.test.d.ts +1 -0
  460. package/esm/typings/src/scripting/javascript/utils/extractVariablesFromScript.test.d.ts +1 -0
  461. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +14 -0
  462. package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +18 -0
  463. package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +18 -0
  464. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
  465. package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  466. package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
  467. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +33 -0
  468. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +10 -0
  469. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +7 -0
  470. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  471. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +10 -0
  472. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +10 -0
  473. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  474. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +33 -0
  475. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +25 -0
  476. package/esm/typings/src/types/Arrayable.d.ts +11 -0
  477. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
  478. package/esm/typings/src/types/ModelRequirements.d.ts +104 -0
  479. package/esm/typings/src/types/ModelVariant.d.ts +15 -0
  480. package/esm/typings/src/types/NonEmptyArray.d.ts +8 -0
  481. package/esm/typings/src/types/Prompt.d.ts +111 -0
  482. package/esm/typings/src/types/ScriptLanguage.d.ts +13 -0
  483. package/esm/typings/src/types/SectionType.d.ts +21 -0
  484. package/esm/typings/src/types/TaskType.d.ts +15 -0
  485. package/esm/typings/src/types/typeAliasEmoji.d.ts +12 -0
  486. package/esm/typings/src/types/typeAliases.d.ts +644 -0
  487. package/esm/typings/src/utils/$Register.d.ts +39 -0
  488. package/esm/typings/src/utils/$getCurrentDate.d.ts +10 -0
  489. package/esm/typings/src/utils/FromtoItems.d.ts +19 -0
  490. package/esm/typings/src/utils/arrayableToArray.d.ts +11 -0
  491. package/esm/typings/src/utils/arrayableToArray.test.d.ts +1 -0
  492. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
  493. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.test.d.ts +1 -0
  494. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
  495. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
  496. package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.d.ts +22 -0
  497. package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
  498. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
  499. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
  500. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
  501. package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +29 -0
  502. package/esm/typings/src/utils/editable/utils/renamePipelineParameter.test.d.ts +1 -0
  503. package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +16 -0
  504. package/esm/typings/src/utils/emojis.d.ts +24 -0
  505. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +9 -0
  506. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +11 -0
  507. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +11 -0
  508. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +11 -0
  509. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +11 -0
  510. package/esm/typings/src/utils/execCommand/$execCommand.d.ts +16 -0
  511. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
  512. package/esm/typings/src/utils/execCommand/$execCommands.d.ts +18 -0
  513. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
  514. package/esm/typings/src/utils/execCommand/execCommand.test.d.ts +1 -0
  515. package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.test.d.ts +1 -0
  516. package/esm/typings/src/utils/expectation-counters/constants.d.ts +16 -0
  517. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +7 -0
  518. package/esm/typings/src/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  519. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +9 -0
  520. package/esm/typings/src/utils/expectation-counters/countLines.test.d.ts +1 -0
  521. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +9 -0
  522. package/esm/typings/src/utils/expectation-counters/countPages.test.d.ts +1 -0
  523. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +7 -0
  524. package/esm/typings/src/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  525. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +13 -0
  526. package/esm/typings/src/utils/expectation-counters/countSentences.test.d.ts +1 -0
  527. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +7 -0
  528. package/esm/typings/src/utils/expectation-counters/countWords.test.d.ts +1 -0
  529. package/esm/typings/src/utils/expectation-counters/index.d.ts +12 -0
  530. package/esm/typings/src/utils/files/extensionToMimeType.d.ts +8 -0
  531. package/esm/typings/src/utils/files/extensionToMimeType.test.d.ts +1 -0
  532. package/esm/typings/src/utils/files/getFileExtension.d.ts +8 -0
  533. package/esm/typings/src/utils/files/getFileExtension.test.d.ts +1 -0
  534. package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +14 -0
  535. package/esm/typings/src/utils/files/isDirectoryExisting.test.d.ts +1 -0
  536. package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
  537. package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
  538. package/esm/typings/src/utils/files/isFileExisting.test.d.ts +1 -0
  539. package/esm/typings/src/utils/files/listAllFiles.d.ts +17 -0
  540. package/esm/typings/src/utils/files/listAllFiles.test.d.ts +1 -0
  541. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
  542. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
  543. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +14 -0
  544. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
  545. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +38 -0
  546. package/esm/typings/src/utils/markdown/createMarkdownChart.test.d.ts +1 -0
  547. package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +11 -0
  548. package/esm/typings/src/utils/markdown/createMarkdownTable.test.d.ts +1 -0
  549. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +11 -0
  550. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
  551. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  552. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +36 -0
  553. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
  554. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
  555. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  556. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +22 -0
  557. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  558. package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +17 -0
  559. package/esm/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
  560. package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +34 -0
  561. package/esm/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
  562. package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +9 -0
  563. package/esm/typings/src/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
  564. package/esm/typings/src/utils/markdown/removeMarkdownComments.d.ts +10 -0
  565. package/esm/typings/src/utils/markdown/removeMarkdownComments.test.d.ts +1 -0
  566. package/esm/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +9 -0
  567. package/esm/typings/src/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  568. package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +15 -0
  569. package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
  570. package/esm/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +12 -0
  571. package/esm/typings/src/utils/normalization/IKeywords.d.ts +21 -0
  572. package/esm/typings/src/utils/normalization/capitalize.d.ts +6 -0
  573. package/esm/typings/src/utils/normalization/capitalize.test.d.ts +1 -0
  574. package/esm/typings/src/utils/normalization/decapitalize.d.ts +6 -0
  575. package/esm/typings/src/utils/normalization/decapitalize.test.d.ts +1 -0
  576. package/esm/typings/src/utils/normalization/isValidKeyword.d.ts +10 -0
  577. package/esm/typings/src/utils/normalization/isValidKeyword.test.d.ts +1 -0
  578. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +9 -0
  579. package/esm/typings/src/utils/normalization/nameToUriPart.test.d.ts +1 -0
  580. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +9 -0
  581. package/esm/typings/src/utils/normalization/nameToUriParts.test.d.ts +1 -0
  582. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +21 -0
  583. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.test.d.ts +1 -0
  584. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +17 -0
  585. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.test.d.ts +1 -0
  586. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +26 -0
  587. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +1 -0
  588. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +22 -0
  589. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.test.d.ts +1 -0
  590. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +17 -0
  591. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.test.d.ts +1 -0
  592. package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +6 -0
  593. package/esm/typings/src/utils/normalization/normalizeWhitespaces.test.d.ts +1 -0
  594. package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
  595. package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
  596. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +16 -0
  597. package/esm/typings/src/utils/normalization/parseKeywords.test.d.ts +1 -0
  598. package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +9 -0
  599. package/esm/typings/src/utils/normalization/parseKeywordsFromString.test.d.ts +1 -0
  600. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +11 -0
  601. package/esm/typings/src/utils/normalization/removeDiacritics.test.d.ts +1 -0
  602. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +10 -0
  603. package/esm/typings/src/utils/normalization/searchKeywords.test.d.ts +1 -0
  604. package/esm/typings/src/utils/normalization/suffixUrl.d.ts +7 -0
  605. package/esm/typings/src/utils/normalization/suffixUrl.test.d.ts +1 -0
  606. package/esm/typings/src/utils/normalization/titleToName.d.ts +9 -0
  607. package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
  608. package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
  609. package/esm/typings/src/utils/organization/TODO_USE.d.ts +12 -0
  610. package/esm/typings/src/utils/organization/TODO_any.d.ts +6 -0
  611. package/esm/typings/src/utils/organization/TODO_object.d.ts +6 -0
  612. package/esm/typings/src/utils/organization/TODO_remove_as.d.ts +6 -0
  613. package/esm/typings/src/utils/organization/TODO_string.d.ts +6 -0
  614. package/esm/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
  615. package/esm/typings/src/utils/organization/___and___.d.ts +7 -0
  616. package/esm/typings/src/utils/organization/___or___.d.ts +6 -0
  617. package/esm/typings/src/utils/organization/empty_object.d.ts +10 -0
  618. package/esm/typings/src/utils/organization/just.d.ts +14 -0
  619. package/esm/typings/src/utils/organization/just_empty_object.d.ts +12 -0
  620. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
  621. package/esm/typings/src/utils/organization/keepUnused.d.ts +16 -0
  622. package/esm/typings/src/utils/organization/really_any.d.ts +6 -0
  623. package/esm/typings/src/utils/organization/really_unknown.d.ts +6 -0
  624. package/esm/typings/src/utils/organization/spaceTrim.d.ts +11 -0
  625. package/esm/typings/src/utils/parameters/extractParameterNames.d.ts +10 -0
  626. package/esm/typings/src/utils/parameters/extractParameterNames.test.d.ts +1 -0
  627. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +27 -0
  628. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.test.d.ts +1 -0
  629. package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
  630. package/esm/typings/src/utils/parameters/numberToString.test.d.ts +1 -0
  631. package/esm/typings/src/utils/parameters/templateParameters.d.ts +16 -0
  632. package/esm/typings/src/utils/parameters/templateParameters.test.d.ts +1 -0
  633. package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
  634. package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
  635. package/esm/typings/src/utils/parseNumber.d.ts +16 -0
  636. package/esm/typings/src/utils/parseNumber.test.d.ts +1 -0
  637. package/esm/typings/src/utils/random/$randomSeed.d.ts +10 -0
  638. package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
  639. package/esm/typings/src/utils/removeEmojis.d.ts +8 -0
  640. package/esm/typings/src/utils/removeEmojis.test.d.ts +1 -0
  641. package/esm/typings/src/utils/removeQuotes.d.ts +14 -0
  642. package/esm/typings/src/utils/removeQuotes.test.d.ts +1 -0
  643. package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +14 -0
  644. package/esm/typings/src/utils/serialization/asSerializable.d.ts +15 -0
  645. package/esm/typings/src/utils/serialization/asSerializable.test.d.ts +1 -0
  646. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +45 -0
  647. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +13 -0
  648. package/esm/typings/src/utils/serialization/deepClone.d.ts +10 -0
  649. package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
  650. package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
  651. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +25 -0
  652. package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
  653. package/esm/typings/src/utils/sets/difference.d.ts +10 -0
  654. package/esm/typings/src/utils/sets/difference.test.d.ts +1 -0
  655. package/esm/typings/src/utils/sets/intersection.d.ts +7 -0
  656. package/esm/typings/src/utils/sets/intersection.test.d.ts +1 -0
  657. package/esm/typings/src/utils/sets/union.d.ts +7 -0
  658. package/esm/typings/src/utils/sets/union.test.d.ts +1 -0
  659. package/esm/typings/src/utils/trimCodeBlock.d.ts +9 -0
  660. package/esm/typings/src/utils/trimCodeBlock.test.d.ts +1 -0
  661. package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +9 -0
  662. package/esm/typings/src/utils/trimEndOfCodeBlock.test.d.ts +1 -0
  663. package/esm/typings/src/utils/unwrapResult.d.ts +37 -0
  664. package/esm/typings/src/utils/unwrapResult.test.d.ts +1 -0
  665. package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +8 -0
  666. package/esm/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
  667. package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
  668. package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
  669. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +12 -0
  670. package/esm/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
  671. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +10 -0
  672. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
  673. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +10 -0
  674. package/esm/typings/src/utils/validators/parameterName/validateParameterName.test.d.ts +1 -0
  675. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +15 -0
  676. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
  677. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +12 -0
  678. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
  679. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +11 -0
  680. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
  681. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +13 -0
  682. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
  683. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +15 -0
  684. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
  685. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +13 -0
  686. package/esm/typings/src/utils/validators/url/isValidUrl.test.d.ts +1 -0
  687. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +8 -0
  688. package/esm/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
  689. package/esm/typings/src/version.d.ts +25 -0
  690. package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
  691. package/esm/typings/src/wizzard/wizzard.d.ts +68 -0
  692. package/package.json +57 -0
  693. package/umd/index.umd.js +1810 -0
  694. package/umd/index.umd.js.map +1 -0
@@ -0,0 +1,1796 @@
1
+ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
+ import 'path';
3
+ import { format } from 'prettier';
4
+ import parserHtml from 'prettier/parser-html';
5
+ import { forTime } from 'waitasecond';
6
+
7
+ // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
8
+ /**
9
+ * The version of the Book language
10
+ *
11
+ * @generated
12
+ * @see https://github.com/webgptorg/book
13
+ */
14
+ const BOOK_LANGUAGE_VERSION = '1.0.0';
15
+ /**
16
+ * The version of the Promptbook engine
17
+ *
18
+ * @generated
19
+ * @see https://github.com/webgptorg/promptbook
20
+ */
21
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
22
+ /**
23
+ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
24
+ * Note: [💞] Ignore a discrepancy between file name and entity name
25
+ */
26
+
27
+ /**
28
+ * Name for the Promptbook
29
+ *
30
+ * TODO: [🗽] Unite branding and make single place for it
31
+ *
32
+ * @public exported from `@promptbook/core`
33
+ */
34
+ const NAME = `Promptbook`;
35
+ /**
36
+ * Email of the responsible person
37
+ *
38
+ * @public exported from `@promptbook/core`
39
+ */
40
+ const ADMIN_EMAIL = 'pavol@ptbk.io';
41
+ /**
42
+ * Name of the responsible person for the Promptbook on GitHub
43
+ *
44
+ * @public exported from `@promptbook/core`
45
+ */
46
+ const ADMIN_GITHUB_NAME = 'hejny';
47
+ // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
48
+ /**
49
+ * The maximum number of iterations for a loops
50
+ *
51
+ * @private within the repository - too low-level in comparison with other `MAX_...`
52
+ */
53
+ const LOOP_LIMIT = 1000;
54
+ /**
55
+ * Strings to represent various values in the context of parameter values
56
+ *
57
+ * @public exported from `@promptbook/utils`
58
+ */
59
+ const VALUE_STRINGS = {
60
+ empty: '(nothing; empty string)',
61
+ null: '(no value; null)',
62
+ undefined: '(unknown value; undefined)',
63
+ nan: '(not a number; NaN)',
64
+ infinity: '(infinity; ∞)',
65
+ negativeInfinity: '(negative infinity; -∞)',
66
+ unserializable: '(unserializable value)',
67
+ };
68
+ /**
69
+ * Small number limit
70
+ *
71
+ * @public exported from `@promptbook/utils`
72
+ */
73
+ const SMALL_NUMBER = 0.001;
74
+ // <- TODO: [🧜‍♂️]
75
+ /**
76
+ * @@@
77
+ *
78
+ * @public exported from `@promptbook/core`
79
+ */
80
+ Object.freeze({
81
+ delimiter: ',',
82
+ quoteChar: '"',
83
+ newline: '\n',
84
+ skipEmptyLines: true,
85
+ });
86
+ /**
87
+ * Note: [💞] Ignore a discrepancy between file name and entity name
88
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
89
+ */
90
+
91
+ /**
92
+ * Make error report URL for the given error
93
+ *
94
+ * @private private within the repository
95
+ */
96
+ function getErrorReportUrl(error) {
97
+ const report = {
98
+ title: `🐜 Error report from ${NAME}`,
99
+ body: spaceTrim((block) => `
100
+
101
+
102
+ \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
103
+
104
+ \`\`\`
105
+ ${block(error.message || '(no error message)')}
106
+ \`\`\`
107
+
108
+
109
+ ## More info:
110
+
111
+ - **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
112
+ - **Book language version:** ${BOOK_LANGUAGE_VERSION}
113
+ - **Time:** ${new Date().toISOString()}
114
+
115
+ <details>
116
+ <summary>Stack trace:</summary>
117
+
118
+ ## Stack trace:
119
+
120
+ \`\`\`stacktrace
121
+ ${block(error.stack || '(empty)')}
122
+ \`\`\`
123
+ </details>
124
+
125
+ `),
126
+ };
127
+ const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
128
+ reportUrl.searchParams.set('labels', 'bug');
129
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
130
+ reportUrl.searchParams.set('title', report.title);
131
+ reportUrl.searchParams.set('body', report.body);
132
+ return reportUrl;
133
+ }
134
+
135
+ /**
136
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
137
+ *
138
+ * @public exported from `@promptbook/core`
139
+ */
140
+ class UnexpectedError extends Error {
141
+ constructor(message) {
142
+ super(spaceTrim$1((block) => `
143
+ ${block(message)}
144
+
145
+ Note: This error should not happen.
146
+ It's probbably a bug in the pipeline collection
147
+
148
+ Please report issue:
149
+ ${block(getErrorReportUrl(new Error(message)).href)}
150
+
151
+ Or contact us on ${ADMIN_EMAIL}
152
+
153
+ `));
154
+ this.name = 'UnexpectedError';
155
+ Object.setPrototypeOf(this, UnexpectedError.prototype);
156
+ }
157
+ }
158
+
159
+ /**
160
+ * @@@
161
+ *
162
+ * @param text @@@
163
+ * @param _isFirstLetterCapital @@@
164
+ * @returns @@@
165
+ * @example 'helloWorld'
166
+ * @example 'iLovePromptbook'
167
+ * @public exported from `@promptbook/utils`
168
+ */
169
+ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
170
+ let charType;
171
+ let lastCharType = null;
172
+ let normalizedName = '';
173
+ for (const char of text) {
174
+ let normalizedChar;
175
+ if (/^[a-z]$/.test(char)) {
176
+ charType = 'LOWERCASE';
177
+ normalizedChar = char;
178
+ }
179
+ else if (/^[A-Z]$/.test(char)) {
180
+ charType = 'UPPERCASE';
181
+ normalizedChar = char.toLowerCase();
182
+ }
183
+ else if (/^[0-9]$/.test(char)) {
184
+ charType = 'NUMBER';
185
+ normalizedChar = char;
186
+ }
187
+ else {
188
+ charType = 'OTHER';
189
+ normalizedChar = '';
190
+ }
191
+ if (!lastCharType) {
192
+ if (_isFirstLetterCapital) {
193
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
194
+ }
195
+ }
196
+ else if (charType !== lastCharType &&
197
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
198
+ !(lastCharType === 'NUMBER') &&
199
+ !(charType === 'NUMBER')) {
200
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
201
+ }
202
+ normalizedName += normalizedChar;
203
+ lastCharType = charType;
204
+ }
205
+ return normalizedName;
206
+ }
207
+ /**
208
+ * TODO: [🌺] Use some intermediate util splitWords
209
+ */
210
+
211
+ /**
212
+ * Removes emojis from a string and fix whitespaces
213
+ *
214
+ * @param text with emojis
215
+ * @returns text without emojis
216
+ * @public exported from `@promptbook/utils`
217
+ */
218
+ function removeEmojis(text) {
219
+ // Replace emojis (and also ZWJ sequence) with hyphens
220
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
221
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
222
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
223
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
224
+ return text;
225
+ }
226
+
227
+ const defaultDiacriticsRemovalMap = [
228
+ {
229
+ base: 'A',
230
+ 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',
231
+ },
232
+ { base: 'AA', letters: '\uA732' },
233
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
234
+ { base: 'AO', letters: '\uA734' },
235
+ { base: 'AU', letters: '\uA736' },
236
+ { base: 'AV', letters: '\uA738\uA73A' },
237
+ { base: 'AY', letters: '\uA73C' },
238
+ {
239
+ base: 'B',
240
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
241
+ },
242
+ {
243
+ base: 'C',
244
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
245
+ },
246
+ {
247
+ base: 'D',
248
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
249
+ },
250
+ { base: 'DZ', letters: '\u01F1\u01C4' },
251
+ { base: 'Dz', letters: '\u01F2\u01C5' },
252
+ {
253
+ base: 'E',
254
+ 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',
255
+ },
256
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
257
+ {
258
+ base: 'G',
259
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
260
+ },
261
+ {
262
+ base: 'H',
263
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
264
+ },
265
+ {
266
+ base: 'I',
267
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
268
+ },
269
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
270
+ {
271
+ base: 'K',
272
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
273
+ },
274
+ {
275
+ base: 'L',
276
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
277
+ },
278
+ { base: 'LJ', letters: '\u01C7' },
279
+ { base: 'Lj', letters: '\u01C8' },
280
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
281
+ {
282
+ base: 'N',
283
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
284
+ },
285
+ { base: 'NJ', letters: '\u01CA' },
286
+ { base: 'Nj', letters: '\u01CB' },
287
+ {
288
+ base: 'O',
289
+ 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',
290
+ },
291
+ { base: 'OI', letters: '\u01A2' },
292
+ { base: 'OO', letters: '\uA74E' },
293
+ { base: 'OU', letters: '\u0222' },
294
+ { base: 'OE', letters: '\u008C\u0152' },
295
+ { base: 'oe', letters: '\u009C\u0153' },
296
+ {
297
+ base: 'P',
298
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
299
+ },
300
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
301
+ {
302
+ base: 'R',
303
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
304
+ },
305
+ {
306
+ base: 'S',
307
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
308
+ },
309
+ {
310
+ base: 'T',
311
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
312
+ },
313
+ { base: 'TZ', letters: '\uA728' },
314
+ {
315
+ base: 'U',
316
+ 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',
317
+ },
318
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
319
+ { base: 'VY', letters: '\uA760' },
320
+ {
321
+ base: 'W',
322
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
323
+ },
324
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
325
+ {
326
+ base: 'Y',
327
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
328
+ },
329
+ {
330
+ base: 'Z',
331
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
332
+ },
333
+ {
334
+ base: 'a',
335
+ 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',
336
+ },
337
+ { base: 'aa', letters: '\uA733' },
338
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
339
+ { base: 'ao', letters: '\uA735' },
340
+ { base: 'au', letters: '\uA737' },
341
+ { base: 'av', letters: '\uA739\uA73B' },
342
+ { base: 'ay', letters: '\uA73D' },
343
+ {
344
+ base: 'b',
345
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
346
+ },
347
+ {
348
+ base: 'c',
349
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
350
+ },
351
+ {
352
+ base: 'd',
353
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
354
+ },
355
+ { base: 'dz', letters: '\u01F3\u01C6' },
356
+ {
357
+ base: 'e',
358
+ 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',
359
+ },
360
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
361
+ {
362
+ base: 'g',
363
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
364
+ },
365
+ {
366
+ base: 'h',
367
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
368
+ },
369
+ { base: 'hv', letters: '\u0195' },
370
+ {
371
+ base: 'i',
372
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
373
+ },
374
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
375
+ {
376
+ base: 'k',
377
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
378
+ },
379
+ {
380
+ base: 'l',
381
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
382
+ },
383
+ { base: 'lj', letters: '\u01C9' },
384
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
385
+ {
386
+ base: 'n',
387
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
388
+ },
389
+ { base: 'nj', letters: '\u01CC' },
390
+ {
391
+ base: 'o',
392
+ 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',
393
+ },
394
+ { base: 'oi', letters: '\u01A3' },
395
+ { base: 'ou', letters: '\u0223' },
396
+ { base: 'oo', letters: '\uA74F' },
397
+ {
398
+ base: 'p',
399
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
400
+ },
401
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
402
+ {
403
+ base: 'r',
404
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
405
+ },
406
+ {
407
+ base: 's',
408
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
409
+ },
410
+ {
411
+ base: 't',
412
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
413
+ },
414
+ { base: 'tz', letters: '\uA729' },
415
+ {
416
+ base: 'u',
417
+ 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',
418
+ },
419
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
420
+ { base: 'vy', letters: '\uA761' },
421
+ {
422
+ base: 'w',
423
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
424
+ },
425
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
426
+ {
427
+ base: 'y',
428
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
429
+ },
430
+ {
431
+ base: 'z',
432
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
433
+ },
434
+ ];
435
+ /**
436
+ * Map of letters from diacritic variant to diacritless variant
437
+ * Contains lowercase and uppercase separatelly
438
+ *
439
+ * > "á" => "a"
440
+ * > "ě" => "e"
441
+ * > "Ă" => "A"
442
+ * > ...
443
+ *
444
+ * @public exported from `@promptbook/utils`
445
+ */
446
+ const DIACRITIC_VARIANTS_LETTERS = {};
447
+ // tslint:disable-next-line: prefer-for-of
448
+ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
449
+ const letters = defaultDiacriticsRemovalMap[i].letters;
450
+ // tslint:disable-next-line: prefer-for-of
451
+ for (let j = 0; j < letters.length; j++) {
452
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
453
+ }
454
+ }
455
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
456
+ /*
457
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
458
+ Licensed under the Apache License, Version 2.0 (the "License");
459
+ you may not use this file except in compliance with the License.
460
+ You may obtain a copy of the License at
461
+
462
+ http://www.apache.org/licenses/LICENSE-2.0
463
+
464
+ Unless required by applicable law or agreed to in writing, software
465
+ distributed under the License is distributed on an "AS IS" BASIS,
466
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
467
+ See the License for the specific language governing permissions and
468
+ limitations under the License.
469
+ */
470
+
471
+ /**
472
+ * @@@
473
+ *
474
+ * @param input @@@
475
+ * @returns @@@
476
+ * @public exported from `@promptbook/utils`
477
+ */
478
+ function removeDiacritics(input) {
479
+ /*eslint no-control-regex: "off"*/
480
+ return input.replace(/[^\u0000-\u007E]/g, (a) => {
481
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
482
+ });
483
+ }
484
+ /**
485
+ * TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
486
+ */
487
+
488
+ /**
489
+ * @@@
490
+ *
491
+ * @param text @@@
492
+ * @returns @@@
493
+ * @example 'hello-world'
494
+ * @example 'i-love-promptbook'
495
+ * @public exported from `@promptbook/utils`
496
+ */
497
+ function normalizeToKebabCase(text) {
498
+ text = removeDiacritics(text);
499
+ let charType;
500
+ let lastCharType = 'OTHER';
501
+ let normalizedName = '';
502
+ for (const char of text) {
503
+ let normalizedChar;
504
+ if (/^[a-z]$/.test(char)) {
505
+ charType = 'LOWERCASE';
506
+ normalizedChar = char;
507
+ }
508
+ else if (/^[A-Z]$/.test(char)) {
509
+ charType = 'UPPERCASE';
510
+ normalizedChar = char.toLowerCase();
511
+ }
512
+ else if (/^[0-9]$/.test(char)) {
513
+ charType = 'NUMBER';
514
+ normalizedChar = char;
515
+ }
516
+ else {
517
+ charType = 'OTHER';
518
+ normalizedChar = '-';
519
+ }
520
+ if (charType !== lastCharType &&
521
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
522
+ !(lastCharType === 'NUMBER') &&
523
+ !(charType === 'NUMBER')) {
524
+ normalizedName += '-';
525
+ }
526
+ normalizedName += normalizedChar;
527
+ lastCharType = charType;
528
+ }
529
+ normalizedName = normalizedName.split(/-+/g).join('-');
530
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
531
+ normalizedName = normalizedName.replace(/^-/, '');
532
+ normalizedName = normalizedName.replace(/-$/, '');
533
+ return normalizedName;
534
+ }
535
+ /**
536
+ * Note: [💞] Ignore a discrepancy between file name and entity name
537
+ */
538
+
539
+ /**
540
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
541
+ *
542
+ * @public exported from `@promptbook/core`
543
+ */
544
+ class ParseError extends Error {
545
+ constructor(message) {
546
+ super(message);
547
+ this.name = 'ParseError';
548
+ Object.setPrototypeOf(this, ParseError.prototype);
549
+ }
550
+ }
551
+ /**
552
+ * TODO: Maybe split `ParseError` and `ApplyError`
553
+ */
554
+
555
+ /**
556
+ * This error indicates errors during the execution of the pipeline
557
+ *
558
+ * @public exported from `@promptbook/core`
559
+ */
560
+ class PipelineExecutionError extends Error {
561
+ constructor(message) {
562
+ super(message);
563
+ this.name = 'PipelineExecutionError';
564
+ Object.setPrototypeOf(this, PipelineExecutionError.prototype);
565
+ }
566
+ }
567
+
568
+ /**
569
+ * Index of all javascript errors
570
+ *
571
+ * @private for internal usage
572
+ */
573
+ ({
574
+ Error,
575
+ EvalError,
576
+ RangeError,
577
+ ReferenceError,
578
+ SyntaxError,
579
+ TypeError,
580
+ URIError,
581
+ AggregateError,
582
+ /*
583
+ Note: Not widely supported
584
+ > InternalError,
585
+ > ModuleError,
586
+ > HeapError,
587
+ > WebAssemblyCompileError,
588
+ > WebAssemblyRuntimeError,
589
+ */
590
+ });
591
+ /**
592
+ * Note: [💞] Ignore a discrepancy between file name and entity name
593
+ */
594
+
595
+ /**
596
+ * Orders JSON object by keys
597
+ *
598
+ * @returns The same type of object as the input re-ordered
599
+ * @public exported from `@promptbook/utils`
600
+ */
601
+ function orderJson(options) {
602
+ const { value, order } = options;
603
+ const orderedValue = {
604
+ ...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
605
+ ...value,
606
+ };
607
+ return orderedValue;
608
+ }
609
+
610
+ /**
611
+ * Freezes the given object and all its nested objects recursively
612
+ *
613
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
614
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
615
+ *
616
+ * @returns The same object as the input, but deeply frozen
617
+ * @public exported from `@promptbook/utils`
618
+ */
619
+ function $deepFreeze(objectValue) {
620
+ if (Array.isArray(objectValue)) {
621
+ return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
622
+ }
623
+ const propertyNames = Object.getOwnPropertyNames(objectValue);
624
+ for (const propertyName of propertyNames) {
625
+ const value = objectValue[propertyName];
626
+ if (value && typeof value === 'object') {
627
+ $deepFreeze(value);
628
+ }
629
+ }
630
+ Object.freeze(objectValue);
631
+ return objectValue;
632
+ }
633
+ /**
634
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
635
+ */
636
+
637
+ /**
638
+ * Checks if the value is [🚉] serializable as JSON
639
+ * If not, throws an UnexpectedError with a rich error message and tracking
640
+ *
641
+ * - Almost all primitives are serializable BUT:
642
+ * - `undefined` is not serializable
643
+ * - `NaN` is not serializable
644
+ * - Objects and arrays are serializable if all their properties are serializable
645
+ * - Functions are not serializable
646
+ * - Circular references are not serializable
647
+ * - `Date` objects are not serializable
648
+ * - `Map` and `Set` objects are not serializable
649
+ * - `RegExp` objects are not serializable
650
+ * - `Error` objects are not serializable
651
+ * - `Symbol` objects are not serializable
652
+ * - And much more...
653
+ *
654
+ * @throws UnexpectedError if the value is not serializable as JSON
655
+ * @public exported from `@promptbook/utils`
656
+ */
657
+ function checkSerializableAsJson(options) {
658
+ const { value, name, message } = options;
659
+ if (value === undefined) {
660
+ throw new UnexpectedError(`${name} is undefined`);
661
+ }
662
+ else if (value === null) {
663
+ return;
664
+ }
665
+ else if (typeof value === 'boolean') {
666
+ return;
667
+ }
668
+ else if (typeof value === 'number' && !isNaN(value)) {
669
+ return;
670
+ }
671
+ else if (typeof value === 'string') {
672
+ return;
673
+ }
674
+ else if (typeof value === 'symbol') {
675
+ throw new UnexpectedError(`${name} is symbol`);
676
+ }
677
+ else if (typeof value === 'function') {
678
+ throw new UnexpectedError(`${name} is function`);
679
+ }
680
+ else if (typeof value === 'object' && Array.isArray(value)) {
681
+ for (let i = 0; i < value.length; i++) {
682
+ checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
683
+ }
684
+ }
685
+ else if (typeof value === 'object') {
686
+ if (value instanceof Date) {
687
+ throw new UnexpectedError(spaceTrim((block) => `
688
+ \`${name}\` is Date
689
+
690
+ Use \`string_date_iso8601\` instead
691
+
692
+ Additional message for \`${name}\`:
693
+ ${block(message || '(nothing)')}
694
+ `));
695
+ }
696
+ else if (value instanceof Map) {
697
+ throw new UnexpectedError(`${name} is Map`);
698
+ }
699
+ else if (value instanceof Set) {
700
+ throw new UnexpectedError(`${name} is Set`);
701
+ }
702
+ else if (value instanceof RegExp) {
703
+ throw new UnexpectedError(`${name} is RegExp`);
704
+ }
705
+ else if (value instanceof Error) {
706
+ throw new UnexpectedError(spaceTrim((block) => `
707
+ \`${name}\` is unserialized Error
708
+
709
+ Use function \`serializeError\`
710
+
711
+ Additional message for \`${name}\`:
712
+ ${block(message || '(nothing)')}
713
+
714
+ `));
715
+ }
716
+ else {
717
+ for (const [subName, subValue] of Object.entries(value)) {
718
+ if (subValue === undefined) {
719
+ // Note: undefined in object is serializable - it is just omited
720
+ continue;
721
+ }
722
+ checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
723
+ }
724
+ try {
725
+ JSON.stringify(value); // <- TODO: [0]
726
+ }
727
+ catch (error) {
728
+ if (!(error instanceof Error)) {
729
+ throw error;
730
+ }
731
+ throw new UnexpectedError(spaceTrim((block) => `
732
+ \`${name}\` is not serializable
733
+
734
+ ${block(error.stack || error.message)}
735
+
736
+ Additional message for \`${name}\`:
737
+ ${block(message || '(nothing)')}
738
+ `));
739
+ }
740
+ /*
741
+ TODO: [0] Is there some more elegant way to check circular references?
742
+ const seen = new Set();
743
+ const stack = [{ value }];
744
+ while (stack.length > 0) {
745
+ const { value } = stack.pop()!;
746
+ if (typeof value === 'object' && value !== null) {
747
+ if (seen.has(value)) {
748
+ throw new UnexpectedError(`${name} has circular reference`);
749
+ }
750
+ seen.add(value);
751
+ if (Array.isArray(value)) {
752
+ stack.push(...value.map((value) => ({ value })));
753
+ } else {
754
+ stack.push(...Object.values(value).map((value) => ({ value })));
755
+ }
756
+ }
757
+ }
758
+ */
759
+ return;
760
+ }
761
+ }
762
+ else {
763
+ throw new UnexpectedError(spaceTrim((block) => `
764
+ \`${name}\` is unknown type
765
+
766
+ Additional message for \`${name}\`:
767
+ ${block(message || '(nothing)')}
768
+ `));
769
+ }
770
+ }
771
+ /**
772
+ * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
773
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
774
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
775
+ */
776
+
777
+ /**
778
+ * @@@
779
+ *
780
+ * @public exported from `@promptbook/utils`
781
+ */
782
+ function deepClone(objectValue) {
783
+ return JSON.parse(JSON.stringify(objectValue));
784
+ /*
785
+ TODO: [🧠] Is there a better implementation?
786
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
787
+ > for (const propertyName of propertyNames) {
788
+ > const value = (objectValue as really_any)[propertyName];
789
+ > if (value && typeof value === 'object') {
790
+ > deepClone(value);
791
+ > }
792
+ > }
793
+ > return Object.assign({}, objectValue);
794
+ */
795
+ }
796
+ /**
797
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
798
+ */
799
+
800
+ /**
801
+ * Utility to export a JSON object from a function
802
+ *
803
+ * 1) Checks if the value is serializable as JSON
804
+ * 2) Makes a deep clone of the object
805
+ * 2) Orders the object properties
806
+ * 2) Deeply freezes the cloned object
807
+ *
808
+ * Note: This function does not mutates the given object
809
+ *
810
+ * @returns The same type of object as the input but read-only and re-ordered
811
+ * @public exported from `@promptbook/utils`
812
+ */
813
+ function exportJson(options) {
814
+ const { name, value, order, message } = options;
815
+ checkSerializableAsJson({ name, value, message });
816
+ const orderedValue =
817
+ // TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
818
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
819
+ // @ts-ignore
820
+ order === undefined
821
+ ? deepClone(value)
822
+ : orderJson({
823
+ value: value,
824
+ // <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
825
+ order: order,
826
+ });
827
+ $deepFreeze(orderedValue);
828
+ return orderedValue;
829
+ }
830
+ /**
831
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
832
+ */
833
+
834
+ /**
835
+ * The names of the parameters that are reserved for special purposes
836
+ *
837
+ * @public exported from `@promptbook/core`
838
+ */
839
+ exportJson({
840
+ name: 'RESERVED_PARAMETER_NAMES',
841
+ message: `The names of the parameters that are reserved for special purposes`,
842
+ value: [
843
+ 'content',
844
+ 'context',
845
+ 'knowledge',
846
+ 'examples',
847
+ 'modelName',
848
+ 'currentDate',
849
+ // <- TODO: list here all command names
850
+ // <- TODO: Add more like 'date', 'modelName',...
851
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
852
+ ],
853
+ });
854
+ /**
855
+ * Note: [💞] Ignore a discrepancy between file name and entity name
856
+ */
857
+
858
+ /**
859
+ * Format either small or big number
860
+ *
861
+ * @public exported from `@promptbook/utils`
862
+ */
863
+ function numberToString(value) {
864
+ if (value === 0) {
865
+ return '0';
866
+ }
867
+ else if (Number.isNaN(value)) {
868
+ return VALUE_STRINGS.nan;
869
+ }
870
+ else if (value === Infinity) {
871
+ return VALUE_STRINGS.infinity;
872
+ }
873
+ else if (value === -Infinity) {
874
+ return VALUE_STRINGS.negativeInfinity;
875
+ }
876
+ for (let exponent = 0; exponent < 15; exponent++) {
877
+ const factor = 10 ** exponent;
878
+ const valueRounded = Math.round(value * factor) / factor;
879
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
880
+ return valueRounded.toFixed(exponent);
881
+ }
882
+ }
883
+ return value.toString();
884
+ }
885
+
886
+ /**
887
+ * Function `valueToString` will convert the given value to string
888
+ * This is useful and used in the `templateParameters` function
889
+ *
890
+ * Note: This function is not just calling `toString` method
891
+ * It's more complex and can handle this conversion specifically for LLM models
892
+ * See `VALUE_STRINGS`
893
+ *
894
+ * Note: There are 2 similar functions
895
+ * - `valueToString` converts value to string for LLM models as human-readable string
896
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
897
+ *
898
+ * @public exported from `@promptbook/utils`
899
+ */
900
+ function valueToString(value) {
901
+ try {
902
+ if (value === '') {
903
+ return VALUE_STRINGS.empty;
904
+ }
905
+ else if (value === null) {
906
+ return VALUE_STRINGS.null;
907
+ }
908
+ else if (value === undefined) {
909
+ return VALUE_STRINGS.undefined;
910
+ }
911
+ else if (typeof value === 'string') {
912
+ return value;
913
+ }
914
+ else if (typeof value === 'number') {
915
+ return numberToString(value);
916
+ }
917
+ else if (value instanceof Date) {
918
+ return value.toISOString();
919
+ }
920
+ else {
921
+ return JSON.stringify(value);
922
+ }
923
+ }
924
+ catch (error) {
925
+ if (!(error instanceof Error)) {
926
+ throw error;
927
+ }
928
+ console.error(error);
929
+ return VALUE_STRINGS.unserializable;
930
+ }
931
+ }
932
+
933
+ /**
934
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
935
+ *
936
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
937
+ *
938
+ * @public exported from `@promptbook/utils`
939
+ */
940
+ new Function(`
941
+ try {
942
+ return this === window;
943
+ } catch (e) {
944
+ return false;
945
+ }
946
+ `);
947
+ /**
948
+ * TODO: [🎺]
949
+ */
950
+
951
+ /**
952
+ * Detects if the code is running in jest environment
953
+ *
954
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
955
+ *
956
+ * @public exported from `@promptbook/utils`
957
+ */
958
+ new Function(`
959
+ try {
960
+ return process.env.JEST_WORKER_ID !== undefined;
961
+ } catch (e) {
962
+ return false;
963
+ }
964
+ `);
965
+ /**
966
+ * TODO: [🎺]
967
+ */
968
+
969
+ /**
970
+ * Detects if the code is running in a Node.js environment
971
+ *
972
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
973
+ *
974
+ * @public exported from `@promptbook/utils`
975
+ */
976
+ new Function(`
977
+ try {
978
+ return this === global;
979
+ } catch (e) {
980
+ return false;
981
+ }
982
+ `);
983
+ /**
984
+ * TODO: [🎺]
985
+ */
986
+
987
+ /**
988
+ * Detects if the code is running in a web worker
989
+ *
990
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
991
+ *
992
+ * @public exported from `@promptbook/utils`
993
+ */
994
+ new Function(`
995
+ try {
996
+ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
997
+ return true;
998
+ } else {
999
+ return false;
1000
+ }
1001
+ } catch (e) {
1002
+ return false;
1003
+ }
1004
+ `);
1005
+ /**
1006
+ * TODO: [🎺]
1007
+ */
1008
+
1009
+ /**
1010
+ * Makes first letter of a string uppercase
1011
+ *
1012
+ * @public exported from `@promptbook/utils`
1013
+ */
1014
+ function capitalize(word) {
1015
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
1016
+ }
1017
+
1018
+ /**
1019
+ * Makes first letter of a string uppercase
1020
+ *
1021
+ * @public exported from `@promptbook/utils`
1022
+ */
1023
+ function decapitalize(word) {
1024
+ return word.substring(0, 1).toLowerCase() + word.substring(1);
1025
+ }
1026
+
1027
+ /**
1028
+ * @@@
1029
+ *
1030
+ * @param text @@@
1031
+ * @returns @@@
1032
+ * @example 'HELLO_WORLD'
1033
+ * @example 'I_LOVE_PROMPTBOOK'
1034
+ * @public exported from `@promptbook/utils`
1035
+ */
1036
+ function normalizeTo_SCREAMING_CASE(text) {
1037
+ let charType;
1038
+ let lastCharType = 'OTHER';
1039
+ let normalizedName = '';
1040
+ for (const char of text) {
1041
+ let normalizedChar;
1042
+ if (/^[a-z]$/.test(char)) {
1043
+ charType = 'LOWERCASE';
1044
+ normalizedChar = char.toUpperCase();
1045
+ }
1046
+ else if (/^[A-Z]$/.test(char)) {
1047
+ charType = 'UPPERCASE';
1048
+ normalizedChar = char;
1049
+ }
1050
+ else if (/^[0-9]$/.test(char)) {
1051
+ charType = 'NUMBER';
1052
+ normalizedChar = char;
1053
+ }
1054
+ else {
1055
+ charType = 'OTHER';
1056
+ normalizedChar = '_';
1057
+ }
1058
+ if (charType !== lastCharType &&
1059
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1060
+ !(lastCharType === 'NUMBER') &&
1061
+ !(charType === 'NUMBER')) {
1062
+ normalizedName += '_';
1063
+ }
1064
+ normalizedName += normalizedChar;
1065
+ lastCharType = charType;
1066
+ }
1067
+ normalizedName = normalizedName.replace(/_+/g, '_');
1068
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1069
+ normalizedName = normalizedName.replace(/^_/, '');
1070
+ normalizedName = normalizedName.replace(/_$/, '');
1071
+ return normalizedName;
1072
+ }
1073
+ /**
1074
+ * TODO: Tests
1075
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1076
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1077
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1078
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1079
+ * TODO: [🌺] Use some intermediate util splitWords
1080
+ */
1081
+
1082
+ /**
1083
+ * Parses keywords from a string
1084
+ *
1085
+ * @param {string} input
1086
+ * @returns {Set} of keywords without diacritics in lowercase
1087
+ * @public exported from `@promptbook/utils`
1088
+ */
1089
+ function parseKeywordsFromString(input) {
1090
+ const keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
1091
+ .toLowerCase()
1092
+ .split(/[^a-z0-9]+/gs)
1093
+ .filter((value) => value);
1094
+ return new Set(keywords);
1095
+ }
1096
+
1097
+ /**
1098
+ * @@@
1099
+ *
1100
+ * @param name @@@
1101
+ * @returns @@@
1102
+ * @example @@@
1103
+ * @public exported from `@promptbook/utils`
1104
+ */
1105
+ function nameToUriPart(name) {
1106
+ let uriPart = name;
1107
+ uriPart = uriPart.toLowerCase();
1108
+ uriPart = removeDiacritics(uriPart);
1109
+ uriPart = uriPart.replace(/[^a-zA-Z0-9]+/g, '-');
1110
+ uriPart = uriPart.replace(/^-+/, '');
1111
+ uriPart = uriPart.replace(/-+$/, '');
1112
+ return uriPart;
1113
+ }
1114
+
1115
+ /**
1116
+ * @@@
1117
+ *
1118
+ * @param name @@@
1119
+ * @returns @@@
1120
+ * @example @@@
1121
+ * @public exported from `@promptbook/utils`
1122
+ */
1123
+ function nameToUriParts(name) {
1124
+ return nameToUriPart(name)
1125
+ .split('-')
1126
+ .filter((value) => value !== '');
1127
+ }
1128
+
1129
+ /**
1130
+ *
1131
+ * @param text @public exported from `@promptbook/utils`
1132
+ * @returns
1133
+ * @example 'HelloWorld'
1134
+ * @example 'ILovePromptbook'
1135
+ * @public exported from `@promptbook/utils`
1136
+ */
1137
+ function normalizeTo_PascalCase(text) {
1138
+ return normalizeTo_camelCase(text, true);
1139
+ }
1140
+
1141
+ /**
1142
+ * @@@
1143
+ *
1144
+ * @param text @@@
1145
+ * @returns @@@
1146
+ * @example 'hello_world'
1147
+ * @example 'i_love_promptbook'
1148
+ * @public exported from `@promptbook/utils`
1149
+ */
1150
+ function normalizeTo_snake_case(text) {
1151
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
1152
+ }
1153
+
1154
+ /**
1155
+ * Take every whitespace (space, new line, tab) and replace it with a single space
1156
+ *
1157
+ * @public exported from `@promptbook/utils`
1158
+ */
1159
+ function normalizeWhitespaces(sentence) {
1160
+ return sentence.replace(/\s+/gs, ' ').trim();
1161
+ }
1162
+
1163
+ /**
1164
+ * Removes quotes from a string
1165
+ *
1166
+ * Tip: This is very usefull for post-processing of the result of the LLM model
1167
+ * Note: This function removes only the same quotes from the beginning and the end of the string
1168
+ * Note: There are two simmilar functions:
1169
+ * - `removeQuotes` which removes only bounding quotes
1170
+ * - `unwrapResult` which removes whole introduce sentence
1171
+ *
1172
+ * @param text optionally quoted text
1173
+ * @returns text without quotes
1174
+ * @public exported from `@promptbook/utils`
1175
+ */
1176
+ function removeQuotes(text) {
1177
+ if (text.startsWith('"') && text.endsWith('"')) {
1178
+ return text.slice(1, -1);
1179
+ }
1180
+ if (text.startsWith('\'') && text.endsWith('\'')) {
1181
+ return text.slice(1, -1);
1182
+ }
1183
+ return text;
1184
+ }
1185
+
1186
+ /**
1187
+ * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
1188
+ *
1189
+ * Note: This is usefull for post-processing of the result of the chat LLM model
1190
+ * when the model wraps the result in the (markdown) code block.
1191
+ *
1192
+ * @public exported from `@promptbook/utils`
1193
+ */
1194
+ function trimCodeBlock(value) {
1195
+ value = spaceTrim$1(value);
1196
+ if (!/^```[a-z]*(.*)```$/is.test(value)) {
1197
+ return value;
1198
+ }
1199
+ value = value.replace(/^```[a-z]*/i, '');
1200
+ value = value.replace(/```$/i, '');
1201
+ value = spaceTrim$1(value);
1202
+ return value;
1203
+ }
1204
+
1205
+ /**
1206
+ * Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
1207
+ *
1208
+ * Note: This is usefull for post-processing of the result of the completion LLM model
1209
+ * if you want to start code block in the prompt but you don't want to end it in the result.
1210
+ *
1211
+ * @public exported from `@promptbook/utils`
1212
+ */
1213
+ function trimEndOfCodeBlock(value) {
1214
+ value = spaceTrim$1(value);
1215
+ value = value.replace(/```$/g, '');
1216
+ value = spaceTrim$1(value);
1217
+ return value;
1218
+ }
1219
+
1220
+ /**
1221
+ * Removes quotes and optional introduce text from a string
1222
+ *
1223
+ * Tip: This is very usefull for post-processing of the result of the LLM model
1224
+ * Note: This function trims the text and removes whole introduce sentence if it is present
1225
+ * Note: There are two simmilar functions:
1226
+ * - `removeQuotes` which removes only bounding quotes
1227
+ * - `unwrapResult` which removes whole introduce sentence
1228
+ *
1229
+ * @param text optionally quoted text
1230
+ * @returns text without quotes
1231
+ * @public exported from `@promptbook/utils`
1232
+ */
1233
+ function unwrapResult(text, options) {
1234
+ const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
1235
+ let trimmedText = text;
1236
+ // Remove leading and trailing spaces and newlines
1237
+ if (isTrimmed) {
1238
+ trimmedText = spaceTrim$1(trimmedText);
1239
+ }
1240
+ let processedText = trimmedText;
1241
+ if (isIntroduceSentenceRemoved) {
1242
+ const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
1243
+ if (introduceSentenceRegex.test(text)) {
1244
+ // Remove the introduce sentence and quotes by replacing it with an empty string
1245
+ processedText = processedText.replace(introduceSentenceRegex, '');
1246
+ }
1247
+ processedText = spaceTrim$1(processedText);
1248
+ }
1249
+ if (processedText.length < 3) {
1250
+ return trimmedText;
1251
+ }
1252
+ if (processedText.includes('\n')) {
1253
+ return trimmedText;
1254
+ }
1255
+ // Remove the quotes by extracting the substring without the first and last characters
1256
+ const unquotedText = processedText.slice(1, -1);
1257
+ // Check if the text starts and ends with quotes
1258
+ if ([
1259
+ ['"', '"'],
1260
+ ["'", "'"],
1261
+ ['`', '`'],
1262
+ ['*', '*'],
1263
+ ['_', '_'],
1264
+ ['„', '“'],
1265
+ ['«', '»'] /* <- QUOTES to config */,
1266
+ ].some(([startQuote, endQuote]) => {
1267
+ if (!processedText.startsWith(startQuote)) {
1268
+ return false;
1269
+ }
1270
+ if (!processedText.endsWith(endQuote)) {
1271
+ return false;
1272
+ }
1273
+ if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
1274
+ return false;
1275
+ }
1276
+ if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
1277
+ return false;
1278
+ }
1279
+ return true;
1280
+ })) {
1281
+ return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
1282
+ }
1283
+ else {
1284
+ return processedText;
1285
+ }
1286
+ }
1287
+ /**
1288
+ * TODO: [🧠] Should this also unwrap the (parenthesis)
1289
+ */
1290
+
1291
+ /**
1292
+ * Extracts all code blocks from markdown.
1293
+ *
1294
+ * Note: There are multiple simmilar function:
1295
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1296
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
1297
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1298
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1299
+ *
1300
+ * @param markdown any valid markdown
1301
+ * @returns code blocks with language and content
1302
+ * @throws {ParseError} if block is not closed properly
1303
+ * @public exported from `@promptbook/markdown-utils`
1304
+ */
1305
+ function extractAllBlocksFromMarkdown(markdown) {
1306
+ const codeBlocks = [];
1307
+ const lines = markdown.split('\n');
1308
+ // Note: [0] Ensure that the last block notated by gt > will be closed
1309
+ lines.push('');
1310
+ let currentCodeBlock = null;
1311
+ for (const line of lines) {
1312
+ if (line.startsWith('> ') || line === '>') {
1313
+ if (currentCodeBlock === null) {
1314
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
1315
+ } /* not else */
1316
+ if (currentCodeBlock.blockNotation === '>') {
1317
+ if (currentCodeBlock.content !== '') {
1318
+ currentCodeBlock.content += '\n';
1319
+ }
1320
+ currentCodeBlock.content += line.slice(2);
1321
+ }
1322
+ }
1323
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
1324
+ codeBlocks.push(currentCodeBlock);
1325
+ currentCodeBlock = null;
1326
+ }
1327
+ /* not else */
1328
+ if (line.startsWith('```')) {
1329
+ const language = line.slice(3).trim() || null;
1330
+ if (currentCodeBlock === null) {
1331
+ currentCodeBlock = { blockNotation: '```', language, content: '' };
1332
+ }
1333
+ else {
1334
+ if (language !== null) {
1335
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
1336
+ }
1337
+ codeBlocks.push(currentCodeBlock);
1338
+ currentCodeBlock = null;
1339
+ }
1340
+ }
1341
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
1342
+ if (currentCodeBlock.content !== '') {
1343
+ currentCodeBlock.content += '\n';
1344
+ }
1345
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
1346
+ }
1347
+ }
1348
+ if (currentCodeBlock !== null) {
1349
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
1350
+ }
1351
+ return codeBlocks;
1352
+ }
1353
+ /**
1354
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
1355
+ */
1356
+
1357
+ /**
1358
+ * Extracts exactly ONE code block from markdown.
1359
+ *
1360
+ * - When there are multiple or no code blocks the function throws a `ParseError`
1361
+ *
1362
+ * Note: There are multiple simmilar function:
1363
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1364
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
1365
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1366
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1367
+ *
1368
+ * @param markdown any valid markdown
1369
+ * @returns code block with language and content
1370
+ * @public exported from `@promptbook/markdown-utils`
1371
+ * @throws {ParseError} if there is not exactly one code block in the markdown
1372
+ */
1373
+ function extractOneBlockFromMarkdown(markdown) {
1374
+ const codeBlocks = extractAllBlocksFromMarkdown(markdown);
1375
+ if (codeBlocks.length !== 1) {
1376
+ throw new ParseError(spaceTrim((block) => `
1377
+ There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
1378
+
1379
+ ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
1380
+ `));
1381
+ }
1382
+ return codeBlocks[0];
1383
+ }
1384
+ /***
1385
+ * TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
1386
+ */
1387
+
1388
+ /**
1389
+ * Extracts code block from markdown.
1390
+ *
1391
+ * - When there are multiple or no code blocks the function throws a `ParseError`
1392
+ *
1393
+ * Note: There are multiple simmilar function:
1394
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1395
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
1396
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1397
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1398
+ *
1399
+ * @public exported from `@promptbook/markdown-utils`
1400
+ * @throws {ParseError} if there is not exactly one code block in the markdown
1401
+ */
1402
+ function extractBlock(markdown) {
1403
+ const { content } = extractOneBlockFromMarkdown(markdown);
1404
+ return content;
1405
+ }
1406
+
1407
+ /**
1408
+ * Prettify the html code
1409
+ *
1410
+ * @param content raw html code
1411
+ * @returns formatted html code
1412
+ * @private withing the package because of HUGE size of prettier dependency
1413
+ */
1414
+ function prettifyMarkdown(content) {
1415
+ try {
1416
+ return format(content, {
1417
+ parser: 'markdown',
1418
+ plugins: [parserHtml],
1419
+ // TODO: DRY - make some import or auto-copy of .prettierrc
1420
+ endOfLine: 'lf',
1421
+ tabWidth: 4,
1422
+ singleQuote: true,
1423
+ trailingComma: 'all',
1424
+ arrowParens: 'always',
1425
+ printWidth: 120,
1426
+ htmlWhitespaceSensitivity: 'ignore',
1427
+ jsxBracketSameLine: false,
1428
+ bracketSpacing: true,
1429
+ });
1430
+ }
1431
+ catch (error) {
1432
+ // TODO: [🟥] Detect browser / node and make it colorfull
1433
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1434
+ error,
1435
+ html: content,
1436
+ });
1437
+ return content;
1438
+ }
1439
+ }
1440
+
1441
+ /**
1442
+ * Does nothing, but preserves the function in the bundle
1443
+ * Compiler is tricked into thinking the function is used
1444
+ *
1445
+ * @param value any function to preserve
1446
+ * @returns nothing
1447
+ * @private internal function of `JavascriptExecutionTools` and `JavascriptEvalExecutionTools`
1448
+ */
1449
+ function preserve(func) {
1450
+ // Note: NOT calling the function
1451
+ (async () => {
1452
+ // TODO: [💩] Change to `await forEver` or something better
1453
+ await forTime(100000000);
1454
+ // [1]
1455
+ try {
1456
+ await func();
1457
+ }
1458
+ finally {
1459
+ // do nothing
1460
+ }
1461
+ })();
1462
+ }
1463
+ /**
1464
+ * TODO: Probbably remove in favour of `keepImported`
1465
+ * TODO: [1] This maybe does memory leak
1466
+ */
1467
+
1468
+ // Note: [💎]
1469
+ /**
1470
+ * ScriptExecutionTools for JavaScript implemented via eval
1471
+ *
1472
+ * Warning: It is used for testing and mocking
1473
+ * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
1474
+ *
1475
+ * @public exported from `@promptbook/javascript`
1476
+ */
1477
+ class JavascriptEvalExecutionTools {
1478
+ constructor(options) {
1479
+ this.options = options || {};
1480
+ }
1481
+ /**
1482
+ * Executes a JavaScript
1483
+ */
1484
+ async execute(options) {
1485
+ const { scriptLanguage, parameters } = options;
1486
+ let { script } = options;
1487
+ if (scriptLanguage !== 'javascript') {
1488
+ throw new PipelineExecutionError(`Script language ${scriptLanguage} not supported to be executed by JavascriptEvalExecutionTools`);
1489
+ }
1490
+ // Note: [💎]
1491
+ // Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
1492
+ const spaceTrim$1 = (_) => spaceTrim(_);
1493
+ preserve(spaceTrim$1);
1494
+ const removeQuotes$1 = removeQuotes;
1495
+ preserve(removeQuotes$1);
1496
+ const unwrapResult$1 = unwrapResult;
1497
+ preserve(unwrapResult$1);
1498
+ const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
1499
+ preserve(trimEndOfCodeBlock$1);
1500
+ const trimCodeBlock$1 = trimCodeBlock;
1501
+ preserve(trimCodeBlock$1);
1502
+ // TODO: DRY [🍯]
1503
+ const trim = (str) => str.trim();
1504
+ preserve(trim);
1505
+ // TODO: DRY [🍯]
1506
+ const reverse = (str) => str.split('').reverse().join('');
1507
+ preserve(reverse);
1508
+ const removeEmojis$1 = removeEmojis;
1509
+ preserve(removeEmojis$1);
1510
+ const prettifyMarkdown$1 = prettifyMarkdown;
1511
+ preserve(prettifyMarkdown$1);
1512
+ //-------[n12:]---
1513
+ const capitalize$1 = capitalize;
1514
+ const decapitalize$1 = decapitalize;
1515
+ const nameToUriPart$1 = nameToUriPart;
1516
+ const nameToUriParts$1 = nameToUriParts;
1517
+ const removeDiacritics$1 = removeDiacritics;
1518
+ const normalizeWhitespaces$1 = normalizeWhitespaces;
1519
+ const normalizeToKebabCase$1 = normalizeToKebabCase;
1520
+ const normalizeTo_camelCase$1 = normalizeTo_camelCase;
1521
+ const normalizeTo_snake_case$1 = normalizeTo_snake_case;
1522
+ const normalizeTo_PascalCase$1 = normalizeTo_PascalCase;
1523
+ const parseKeywords = (input) =>
1524
+ // TODO: DRY [🍯]
1525
+ Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
1526
+ const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
1527
+ preserve(capitalize$1);
1528
+ preserve(decapitalize$1);
1529
+ preserve(nameToUriPart$1);
1530
+ preserve(nameToUriParts$1);
1531
+ preserve(removeDiacritics$1);
1532
+ preserve(normalizeWhitespaces$1);
1533
+ preserve(normalizeToKebabCase$1);
1534
+ preserve(normalizeTo_camelCase$1);
1535
+ preserve(normalizeTo_snake_case$1);
1536
+ preserve(normalizeTo_PascalCase$1);
1537
+ preserve(parseKeywords);
1538
+ preserve(normalizeTo_SCREAMING_CASE$1);
1539
+ //-------[/n12]---
1540
+ if (!script.includes('return')) {
1541
+ script = `return ${script}`;
1542
+ }
1543
+ // TODO: DRY [🍯]
1544
+ const buildinFunctions = {
1545
+ // TODO: [🍯] DRY all these functions across the file
1546
+ spaceTrim: spaceTrim$1,
1547
+ removeQuotes: removeQuotes$1,
1548
+ unwrapResult: unwrapResult$1,
1549
+ trimEndOfCodeBlock: trimEndOfCodeBlock$1,
1550
+ trimCodeBlock: trimCodeBlock$1,
1551
+ trim,
1552
+ reverse,
1553
+ removeEmojis: removeEmojis$1,
1554
+ prettifyMarkdown: prettifyMarkdown$1,
1555
+ capitalize: capitalize$1,
1556
+ decapitalize: decapitalize$1,
1557
+ nameToUriPart: nameToUriPart$1,
1558
+ nameToUriParts: nameToUriParts$1,
1559
+ removeDiacritics: removeDiacritics$1,
1560
+ normalizeWhitespaces: normalizeWhitespaces$1,
1561
+ normalizeToKebabCase: normalizeToKebabCase$1,
1562
+ normalizeTo_camelCase: normalizeTo_camelCase$1,
1563
+ normalizeTo_snake_case: normalizeTo_snake_case$1,
1564
+ normalizeTo_PascalCase: normalizeTo_PascalCase$1,
1565
+ parseKeywords,
1566
+ normalizeTo_SCREAMING_CASE: normalizeTo_SCREAMING_CASE$1,
1567
+ extractBlock, // <- [🍓] Remove balast in all other functions, use this one as example
1568
+ };
1569
+ const buildinFunctionsStatement = Object.keys(buildinFunctions)
1570
+ .map((functionName) =>
1571
+ // Note: Custom functions are exposed to the current scope as variables
1572
+ `const ${functionName} = buildinFunctions.${functionName};`)
1573
+ .join('\n');
1574
+ // TODO: DRY [🍯]
1575
+ const customFunctions = this.options.functions || {};
1576
+ const customFunctionsStatement = Object.keys(customFunctions)
1577
+ .map((functionName) =>
1578
+ // Note: Custom functions are exposed to the current scope as variables
1579
+ `const ${functionName} = customFunctions.${functionName};`)
1580
+ .join('\n');
1581
+ // script = templateParameters(script, parameters);
1582
+ // <- TODO: [🧠][🥳] Should be this is one of two variants how to use parameters in script
1583
+ const statementToEvaluate = spaceTrim((block) => `
1584
+
1585
+ // Build-in functions:
1586
+ ${block(buildinFunctionsStatement)}
1587
+
1588
+ // Custom functions:
1589
+ ${block(customFunctionsStatement || '// -- No custom functions --')}
1590
+
1591
+ // The script:
1592
+ ${block(Object.entries(parameters)
1593
+ .map(([key, value]) => `const ${key} = ${JSON.stringify(value)};`)
1594
+ .join('\n'))}
1595
+ (()=>{ ${script} })()
1596
+ `);
1597
+ if (this.options.isVerbose) {
1598
+ console.info(spaceTrim((block) => `
1599
+ 🚀 Evaluating ${scriptLanguage} script:
1600
+
1601
+ ${block(statementToEvaluate)}`));
1602
+ }
1603
+ let result;
1604
+ try {
1605
+ result = await eval(statementToEvaluate);
1606
+ if (typeof result !== 'string') {
1607
+ throw new PipelineExecutionError(`Script must return a string, but returned ${valueToString(result)}`);
1608
+ }
1609
+ }
1610
+ catch (error) {
1611
+ if (!(error instanceof Error)) {
1612
+ throw error;
1613
+ }
1614
+ if (error instanceof ReferenceError) {
1615
+ const undefinedName = error.message.split(' ')[0];
1616
+ /*
1617
+ Note: Remapping error
1618
+ From: [PipelineUrlError: thing is not defined],
1619
+ To: [PipelineExecutionError: Parameter `{thing}` is not defined],
1620
+ */
1621
+ if (!statementToEvaluate.includes(undefinedName + '(')) {
1622
+ throw new PipelineExecutionError(spaceTrim((block) => `
1623
+
1624
+ Parameter \`{${undefinedName}}\` is not defined
1625
+
1626
+ This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:
1627
+
1628
+ ${block(Object.keys(parameters)
1629
+ .map((key) => ` - ${key}\n`)
1630
+ .join(''))}
1631
+
1632
+ The script is:
1633
+ \`\`\`javascript
1634
+ ${block(script)}
1635
+ \`\`\`
1636
+
1637
+ Original error message:
1638
+ ${block(error.message)}
1639
+
1640
+
1641
+ `));
1642
+ }
1643
+ else {
1644
+ throw new PipelineExecutionError(spaceTrim((block) => `
1645
+ Function ${undefinedName}() is not defined
1646
+
1647
+ - Make sure that the function is one of built-in functions
1648
+ - Or you have to defined the function during construction of JavascriptEvalExecutionTools
1649
+
1650
+ Original error message:
1651
+ ${block(error.message)}
1652
+
1653
+ `));
1654
+ }
1655
+ }
1656
+ throw error;
1657
+ }
1658
+ if (typeof result !== 'string') {
1659
+ throw new PipelineExecutionError(`Script must return a string, but ${valueToString(result)}`);
1660
+ }
1661
+ return result;
1662
+ }
1663
+ }
1664
+ /**
1665
+ * TODO: Put predefined functions (like removeQuotes, spaceTrim, etc.) into annotation OR pass into constructor
1666
+ * TODO: [🧠][💙] Distinct between options passed into ExecutionTools and to ExecutionTools.execute
1667
+ */
1668
+
1669
+ /**
1670
+ * Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
1671
+ *
1672
+ * @alias JavascriptExecutionTools
1673
+ * @public exported from `@promptbook/javascript`
1674
+ */
1675
+ const JavascriptExecutionTools = JavascriptEvalExecutionTools;
1676
+
1677
+ const parseKeywords = (input) =>
1678
+ // TODO: DRY [🍯]
1679
+ Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
1680
+ // TODO: DRY [🍯]
1681
+ const trim = (str) => str.trim();
1682
+ // TODO: DRY [🍯]
1683
+ const reverse = (str) => str.split('').reverse().join('');
1684
+ /**
1685
+ * @@@
1686
+ *
1687
+ * @public exported from `@promptbook/javascript`
1688
+ */
1689
+ const POSTPROCESSING_FUNCTIONS = {
1690
+ spaceTrim,
1691
+ removeQuotes,
1692
+ unwrapResult,
1693
+ trimEndOfCodeBlock,
1694
+ trimCodeBlock,
1695
+ trim,
1696
+ reverse,
1697
+ removeEmojis,
1698
+ prettifyMarkdown,
1699
+ capitalize,
1700
+ decapitalize,
1701
+ nameToUriPart,
1702
+ nameToUriParts,
1703
+ removeDiacritics,
1704
+ normalizeWhitespaces,
1705
+ normalizeToKebabCase,
1706
+ normalizeTo_camelCase,
1707
+ normalizeTo_snake_case,
1708
+ normalizeTo_PascalCase,
1709
+ parseKeywords,
1710
+ normalizeTo_SCREAMING_CASE,
1711
+ extractBlock, // <- [🍓] Remove balast in all other functions, use this one as example
1712
+ };
1713
+ /**
1714
+ * TODO: DRY [🍯], [🧠] Where should be POSTPROCESSING_FUNCTIONS located and how it should be named
1715
+ * Note: [💞] Ignore a discrepancy between file name and entity name
1716
+ */
1717
+
1718
+ /**
1719
+ * Parses the given script and returns the list of all used variables that are not defined in the script
1720
+ *
1721
+ * @param script from which to extract the variables
1722
+ * @returns the list of variable names
1723
+ * @throws {ParseError} if the script is invalid
1724
+ * @public exported from `@promptbook/javascript`
1725
+ */
1726
+ function extractVariablesFromJavascript(script) {
1727
+ const variables = new Set();
1728
+ const originalScript = script;
1729
+ script = `(()=>{${script}})()`;
1730
+ try {
1731
+ for (let i = 0; i < LOOP_LIMIT; i++)
1732
+ try {
1733
+ eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
1734
+ }
1735
+ catch (error) {
1736
+ if (!(error instanceof ReferenceError)) {
1737
+ throw error;
1738
+ }
1739
+ /*
1740
+ Note: Parsing the error
1741
+ 🌟 Most devices:
1742
+ [PipelineUrlError: thing is not defined]
1743
+
1744
+ 🍏 iPhone`s Safari:
1745
+ [PipelineUrlError: Can't find variable: thing]
1746
+ */
1747
+ let variableName = undefined;
1748
+ if (error.message.startsWith(`Can't`)) {
1749
+ // 🍏 Case
1750
+ variableName = error.message.split(' ').pop();
1751
+ }
1752
+ else {
1753
+ // 🌟 Case
1754
+ variableName = error.message.split(' ').shift();
1755
+ }
1756
+ if (variableName === undefined) {
1757
+ throw error;
1758
+ }
1759
+ if (script.includes(variableName + '(')) {
1760
+ script = `const ${variableName} = ()=>'';` + script;
1761
+ }
1762
+ else {
1763
+ variables.add(variableName);
1764
+ script = `const ${variableName} = '';` + script;
1765
+ }
1766
+ }
1767
+ }
1768
+ catch (error) {
1769
+ if (!(error instanceof Error)) {
1770
+ throw error;
1771
+ }
1772
+ throw new ParseError(spaceTrim$1((block) => `
1773
+ Can not extract variables from the script
1774
+ ${block(error.stack || error.message)}
1775
+
1776
+ Found variables:
1777
+ ${Array.from(variables)
1778
+ .map((variableName, i) => `${i + 1}) ${variableName}`)
1779
+ .join('\n')}
1780
+
1781
+
1782
+ The script:
1783
+
1784
+ \`\`\`javascript
1785
+ ${block(originalScript)}
1786
+ \`\`\`
1787
+ `));
1788
+ }
1789
+ return variables;
1790
+ }
1791
+ /**
1792
+ * TODO: [🔣] Support for multiple languages - python, java,...
1793
+ */
1794
+
1795
+ export { BOOK_LANGUAGE_VERSION, JavascriptEvalExecutionTools, JavascriptExecutionTools, POSTPROCESSING_FUNCTIONS, PROMPTBOOK_ENGINE_VERSION, extractVariablesFromJavascript };
1796
+ //# sourceMappingURL=index.es.js.map