@promptbook/utils 0.61.0-8 → 0.61.0

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 (366) hide show
  1. package/README.md +3 -3
  2. package/esm/index.es.js +349 -189
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +200 -30
  5. package/esm/typings/src/_packages/core.index.d.ts +7 -2
  6. package/esm/typings/src/_packages/execute-javascript.index.d.ts +1 -1
  7. package/esm/typings/src/_packages/node.index.d.ts +2 -1
  8. package/esm/typings/src/_packages/types.index.d.ts +12 -8
  9. package/esm/typings/src/_packages/utils.index.d.ts +11 -8
  10. package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
  11. package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
  12. package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  13. package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
  14. package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
  15. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
  16. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +7 -7
  17. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  18. package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
  19. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
  20. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  21. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  22. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
  23. package/esm/typings/src/config.d.ts +46 -1
  24. package/esm/typings/src/config.test.d.ts +4 -0
  25. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  26. package/esm/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
  27. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +6 -3
  28. package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  29. package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
  30. package/esm/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  31. package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -0
  32. package/esm/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
  33. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
  34. package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  35. package/esm/typings/src/errors/LimitReachedError.d.ts +7 -0
  36. package/esm/typings/src/errors/VersionMismatchError.d.ts +8 -0
  37. package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  38. package/esm/typings/src/execution/LlmExecutionTools.d.ts +10 -8
  39. package/esm/typings/src/execution/PipelineExecutor.d.ts +48 -26
  40. package/esm/typings/src/execution/PromptResult.d.ts +39 -54
  41. package/esm/typings/src/execution/PromptResultUsage.d.ts +29 -0
  42. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
  43. package/esm/typings/src/execution/UncertainNumber.d.ts +18 -0
  44. package/esm/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  45. package/esm/typings/src/execution/createPipelineExecutor.d.ts +30 -3
  46. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  47. package/esm/typings/src/execution/utils/addUsage.d.ts +58 -2
  48. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
  49. package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  50. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
  51. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
  52. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  53. package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
  54. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
  55. package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
  56. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  57. package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  58. package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  59. package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
  60. package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  61. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
  62. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  63. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
  64. package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
  65. package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  66. package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
  67. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  68. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  69. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  70. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  71. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  72. package/esm/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
  73. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  74. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  75. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
  76. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  77. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
  78. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  79. package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  80. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  81. package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  82. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
  83. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
  84. package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
  85. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
  86. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  87. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  88. package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  89. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
  90. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  91. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +10 -8
  92. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  93. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
  94. package/esm/typings/src/personas/preparePersona.d.ts +15 -0
  95. package/esm/typings/src/prepare/PrepareOptions.d.ts +22 -0
  96. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +14 -0
  97. package/esm/typings/src/prepare/preparePipeline.d.ts +17 -0
  98. package/esm/typings/src/prepare/prepareTemplates.d.ts +31 -0
  99. package/esm/typings/src/prepare/unpreparePipeline.d.ts +11 -0
  100. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  101. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  102. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
  103. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  104. package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  105. package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  106. package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  107. package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  108. package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  109. package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  110. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  111. package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  112. package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  113. package/esm/typings/src/types/ModelRequirements.d.ts +71 -11
  114. package/esm/typings/src/types/ModelVariant.d.ts +14 -0
  115. package/esm/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  116. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +70 -0
  117. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
  118. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
  119. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
  120. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
  121. package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
  122. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
  123. package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
  124. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
  125. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
  126. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
  127. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
  128. package/esm/typings/src/types/PipelineString.d.ts +1 -1
  129. package/esm/typings/src/types/Prompt.d.ts +54 -10
  130. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  131. package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  132. package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  133. package/esm/typings/src/types/typeAliases.d.ts +114 -15
  134. package/esm/typings/src/utils/FromtoItems.d.ts +3 -3
  135. package/esm/typings/src/utils/currentDate.d.ts +7 -0
  136. package/esm/typings/src/utils/deepClone.d.ts +9 -0
  137. package/esm/typings/src/utils/deepFreeze.d.ts +22 -0
  138. package/esm/typings/src/utils/emojis.d.ts +2 -2
  139. package/esm/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +2 -2
  140. package/esm/typings/src/utils/formatNumber.d.ts +1 -1
  141. package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  142. package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
  143. package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
  144. package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  145. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
  146. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  147. package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  148. package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
  149. package/esm/typings/src/utils/organization/TODO_USE.d.ts +12 -0
  150. package/esm/typings/src/utils/organization/TODO_any.d.ts +6 -0
  151. package/esm/typings/src/utils/organization/TODO_object.d.ts +6 -0
  152. package/esm/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
  153. package/esm/typings/src/utils/organization/___.d.ts +6 -0
  154. package/{umd/typings/src/utils → esm/typings/src/utils/organization}/just.d.ts +5 -1
  155. package/esm/typings/src/utils/organization/keepUnused.d.ts +16 -0
  156. package/esm/typings/src/utils/organization/really_any.d.ts +6 -0
  157. package/esm/typings/src/utils/organization/really_unknown.d.ts +6 -0
  158. package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
  159. package/esm/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
  160. package/esm/typings/src/utils/replaceParameters.test.d.ts +1 -0
  161. package/esm/typings/src/utils/sets/difference.d.ts +3 -0
  162. package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
  163. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
  164. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
  165. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
  166. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
  167. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
  168. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
  169. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
  170. package/package.json +1 -1
  171. package/umd/index.umd.js +367 -201
  172. package/umd/index.umd.js.map +1 -1
  173. package/umd/typings/promptbook-collection/index.d.ts +200 -30
  174. package/umd/typings/src/_packages/core.index.d.ts +7 -2
  175. package/umd/typings/src/_packages/execute-javascript.index.d.ts +1 -1
  176. package/umd/typings/src/_packages/node.index.d.ts +2 -1
  177. package/umd/typings/src/_packages/types.index.d.ts +12 -8
  178. package/umd/typings/src/_packages/utils.index.d.ts +11 -8
  179. package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
  180. package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
  181. package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
  182. package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
  183. package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
  184. package/umd/typings/src/collection/SimplePipelineCollection.d.ts +10 -10
  185. package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +7 -7
  186. package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +2 -2
  187. package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -3
  188. package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +2 -2
  189. package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +4 -2
  190. package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
  191. package/umd/typings/src/commands/_common/types/CommandParser.d.ts +42 -14
  192. package/umd/typings/src/config.d.ts +46 -1
  193. package/umd/typings/src/config.test.d.ts +4 -0
  194. package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
  195. package/umd/typings/src/conversion/pipelineStringToJson.d.ts +9 -5
  196. package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +6 -3
  197. package/umd/typings/src/conversion/prettify/PrettifyOptions.d.ts +2 -2
  198. package/{esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts → umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts} +2 -2
  199. package/umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.test.d.ts +1 -0
  200. package/umd/typings/src/conversion/utils/renameParameter.d.ts +3 -3
  201. package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +14 -0
  202. package/umd/typings/src/conversion/utils/stringifyPipelineJson.test.d.ts +1 -0
  203. package/umd/typings/src/conversion/validation/_importPipeline.d.ts +12 -3
  204. package/umd/typings/src/conversion/validation/validatePipeline.d.ts +10 -1
  205. package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
  206. package/umd/typings/src/errors/LimitReachedError.d.ts +7 -0
  207. package/umd/typings/src/errors/VersionMismatchError.d.ts +8 -0
  208. package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
  209. package/umd/typings/src/execution/LlmExecutionTools.d.ts +10 -8
  210. package/umd/typings/src/execution/PipelineExecutor.d.ts +48 -26
  211. package/umd/typings/src/execution/PromptResult.d.ts +39 -54
  212. package/umd/typings/src/execution/PromptResultUsage.d.ts +29 -0
  213. package/umd/typings/src/execution/ScriptExecutionTools.d.ts +5 -4
  214. package/umd/typings/src/execution/UncertainNumber.d.ts +18 -0
  215. package/umd/typings/src/execution/UserInterfaceTools.d.ts +5 -5
  216. package/umd/typings/src/execution/createPipelineExecutor.d.ts +30 -3
  217. package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +2 -2
  218. package/umd/typings/src/execution/utils/addUsage.d.ts +58 -2
  219. package/umd/typings/src/execution/utils/computeUsageCounts.d.ts +1 -1
  220. package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -1
  221. package/umd/typings/src/execution/utils/uncertainNumber.d.ts +1 -1
  222. package/umd/typings/src/execution/utils/usageToWorktime.d.ts +2 -2
  223. package/umd/typings/src/formats/_common/FormatDefinition.d.ts +1 -1
  224. package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +2 -1
  225. package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +2 -1
  226. package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +2 -1
  227. package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
  228. package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +1 -1
  229. package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
  230. package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +27 -0
  231. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +18 -0
  232. package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts +1 -0
  233. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +9 -23
  234. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
  235. package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +8 -14
  236. package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +30 -0
  237. package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
  238. package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +11 -0
  239. package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
  240. package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
  241. package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
  242. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
  243. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
  244. package/umd/typings/src/llm-providers/_common/utils/count-total-cost/limitTotalCost.d.ts +32 -0
  245. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  246. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  247. package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +3 -3
  248. package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
  249. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -4
  250. package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +5 -5
  251. package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
  252. package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
  253. package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
  254. package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -5
  255. package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
  256. package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +12 -8
  257. package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -6
  258. package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  259. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
  260. package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
  261. package/umd/typings/src/llm-providers/openai/openai-models.d.ts +3 -2
  262. package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
  263. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +10 -8
  264. package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  265. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +2 -2
  266. package/umd/typings/src/personas/preparePersona.d.ts +15 -0
  267. package/umd/typings/src/personas/preparePersona.test.d.ts +1 -0
  268. package/umd/typings/src/prepare/PrepareOptions.d.ts +22 -0
  269. package/umd/typings/src/prepare/isPipelinePrepared.d.ts +14 -0
  270. package/umd/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
  271. package/umd/typings/src/prepare/preparePipeline.d.ts +17 -0
  272. package/umd/typings/src/prepare/prepareTemplates.d.ts +31 -0
  273. package/umd/typings/src/prepare/unpreparePipeline.d.ts +11 -0
  274. package/umd/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +1 -1
  275. package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  276. package/umd/typings/src/scripting/javascript/utils/unknownToString.d.ts +2 -1
  277. package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
  278. package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
  279. package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
  280. package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
  281. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
  282. package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
  283. package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
  284. package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
  285. package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
  286. package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
  287. package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
  288. package/umd/typings/src/types/ModelRequirements.d.ts +71 -11
  289. package/umd/typings/src/types/ModelVariant.d.ts +14 -0
  290. package/umd/typings/src/types/PipelineJson/Expectations.d.ts +6 -2
  291. package/umd/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +70 -0
  292. package/umd/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +27 -0
  293. package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +10 -1
  294. package/umd/typings/src/types/PipelineJson/PersonaJson.d.ts +41 -0
  295. package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +31 -5
  296. package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +22 -0
  297. package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +8 -2
  298. package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +5 -1
  299. package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +23 -4
  300. package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +12 -2
  301. package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +7 -2
  302. package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -2
  303. package/umd/typings/src/types/PipelineString.d.ts +1 -1
  304. package/umd/typings/src/types/Prompt.d.ts +54 -10
  305. package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +4 -4
  306. package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +3 -3
  307. package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
  308. package/umd/typings/src/types/typeAliases.d.ts +114 -15
  309. package/umd/typings/src/utils/FromtoItems.d.ts +3 -3
  310. package/umd/typings/src/utils/currentDate.d.ts +7 -0
  311. package/umd/typings/src/utils/deepClone.d.ts +9 -0
  312. package/umd/typings/src/utils/deepFreeze.d.ts +22 -0
  313. package/umd/typings/src/utils/emojis.d.ts +2 -2
  314. package/umd/typings/src/utils/{extractParameters.d.ts → extractParameterNames.d.ts} +2 -2
  315. package/umd/typings/src/utils/extractParameterNames.test.d.ts +1 -0
  316. package/umd/typings/src/utils/formatNumber.d.ts +1 -1
  317. package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
  318. package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +3 -3
  319. package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +7 -10
  320. package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
  321. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
  322. package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +9 -2
  323. package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  324. package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +3 -3
  325. package/umd/typings/src/utils/normalization/parseKeywords.d.ts +2 -1
  326. package/umd/typings/src/utils/organization/TODO_USE.d.ts +12 -0
  327. package/umd/typings/src/utils/organization/TODO_any.d.ts +6 -0
  328. package/umd/typings/src/utils/organization/TODO_object.d.ts +6 -0
  329. package/umd/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
  330. package/umd/typings/src/utils/organization/___.d.ts +6 -0
  331. package/{esm/typings/src/utils → umd/typings/src/utils/organization}/just.d.ts +5 -1
  332. package/umd/typings/src/utils/organization/keepUnused.d.ts +16 -0
  333. package/umd/typings/src/utils/organization/really_any.d.ts +6 -0
  334. package/umd/typings/src/utils/organization/really_unknown.d.ts +6 -0
  335. package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
  336. package/umd/typings/src/{execution/utils → utils}/replaceParameters.d.ts +2 -4
  337. package/umd/typings/src/utils/replaceParameters.test.d.ts +1 -0
  338. package/umd/typings/src/utils/sets/difference.d.ts +3 -0
  339. package/umd/typings/src/utils/validators/email/isValidEmail.d.ts +2 -1
  340. package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +2 -1
  341. package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -1
  342. package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -1
  343. package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -1
  344. package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -1
  345. package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +2 -1
  346. package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -1
  347. package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  348. package/esm/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  349. package/esm/typings/src/types/Parameters.d.ts +0 -14
  350. package/esm/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  351. package/esm/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  352. package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
  353. package/umd/typings/src/personas/personaToModelRequirements.d.ts +0 -6
  354. package/umd/typings/src/types/Parameters.d.ts +0 -14
  355. package/umd/typings/src/types/PipelineJson/KnowledgeJson.d.ts +0 -6
  356. package/umd/typings/src/types/PipelineJson/MaterialKnowledgePieceJson.d.ts +0 -28
  357. /package/esm/typings/src/conversion/utils/{extractParametersFromPromptTemplate.test.d.ts → extractParameterNamesFromPromptTemplate.test.d.ts} +0 -0
  358. /package/esm/typings/src/{execution/addPromptResultUsage.test.d.ts → conversion/utils/stringifyPipelineJson.test.d.ts} +0 -0
  359. /package/esm/typings/src/{execution/utils/replaceParameters.test.d.ts → knowledge/prepare-knowledge/_common/prepareKnowledgePieces.test.d.ts} +0 -0
  360. /package/esm/typings/src/{utils/extractParameters.test.d.ts → personas/preparePersona.test.d.ts} +0 -0
  361. /package/esm/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
  362. /package/{umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.test.d.ts → esm/typings/src/prepare/isPipelinePrepared.test.d.ts} +0 -0
  363. /package/{umd/typings/src/execution/addPromptResultUsage.test.d.ts → esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts} +0 -0
  364. /package/{umd/typings/src/execution/utils/replaceParameters.test.d.ts → esm/typings/src/utils/extractParameterNames.test.d.ts} +0 -0
  365. /package/{umd/typings/src/utils/extractParameters.test.d.ts → esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts} +0 -0
  366. /package/umd/typings/src/{utils/postprocessing → postprocessing/utils}/extractBlock.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { spaceTrim } from 'spacetrim';
1
+ import spaceTrim$1, { spaceTrim } from 'spacetrim';
2
2
  export { spaceTrim } from 'spacetrim';
3
3
 
4
4
  /*! *****************************************************************************
@@ -513,6 +513,14 @@ function removeEmojis(text) {
513
513
  * Function normalizes title to name which can be used as identifier
514
514
  */
515
515
  function titleToName(value) {
516
+ if (value.startsWith('http://') || value.startsWith('https://')) {
517
+ // TODO: Maybe check against some list unallowed characters
518
+ return value;
519
+ }
520
+ if (value.startsWith('./') || value.startsWith('../')) {
521
+ // TODO: Maybe check against some list unallowed characters
522
+ return value;
523
+ }
516
524
  value = removeEmojis(value);
517
525
  value = normalizeToKebabCase(value);
518
526
  // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
@@ -583,7 +591,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
583
591
  * @param template the template with parameters in {curly} braces
584
592
  * @returns the list of parameter names
585
593
  */
586
- function extractParameters(template) {
594
+ function extractParameterNames(template) {
587
595
  var e_1, _a;
588
596
  var matches = template.matchAll(/{\w+}/g);
589
597
  var parameterNames = new Set();
@@ -673,37 +681,53 @@ function extractVariables(script) {
673
681
  * @returns the set of parameter names
674
682
  * @throws {ParsingError} if the script is invalid
675
683
  */
676
- function extractParametersFromPromptTemplate(promptTemplate) {
677
- var e_1, _a, e_2, _b;
684
+ function extractParameterNamesFromPromptTemplate(promptTemplate) {
685
+ var e_1, _a, e_2, _b, e_3, _c;
686
+ var title = promptTemplate.title, description = promptTemplate.description, blockType = promptTemplate.blockType, content = promptTemplate.content, preparedContent = promptTemplate.preparedContent, jokerParameterNames = promptTemplate.jokerParameterNames;
678
687
  var parameterNames = new Set();
679
688
  try {
680
- for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
681
- var parameterName = _d.value;
689
+ for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
690
+ var parameterName = _e.value;
682
691
  parameterNames.add(parameterName);
683
692
  }
684
693
  }
685
694
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
686
695
  finally {
687
696
  try {
688
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
697
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
689
698
  }
690
699
  finally { if (e_1) throw e_1.error; }
691
700
  }
692
- if (promptTemplate.blockType === 'SCRIPT') {
701
+ if (blockType === 'SCRIPT') {
693
702
  try {
694
- for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
695
- var parameterName = _f.value;
703
+ for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
704
+ var parameterName = _g.value;
696
705
  parameterNames.add(parameterName);
697
706
  }
698
707
  }
699
708
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
700
709
  finally {
701
710
  try {
702
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
711
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
703
712
  }
704
713
  finally { if (e_2) throw e_2.error; }
705
714
  }
706
715
  }
716
+ try {
717
+ for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
718
+ var jokerName = _j.value;
719
+ parameterNames.add(jokerName);
720
+ }
721
+ }
722
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
723
+ finally {
724
+ try {
725
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
726
+ }
727
+ finally { if (e_3) throw e_3.error; }
728
+ }
729
+ parameterNames.delete('content');
730
+ // <- Note {websiteContent} is used in `preparedContent`
707
731
  return parameterNames;
708
732
  }
709
733
  /**
@@ -789,12 +813,12 @@ function renameParameter(options) {
789
813
  */
790
814
  function forEachAsync(array, options, callbackfunction) {
791
815
  return __awaiter(this, void 0, void 0, function () {
792
- var _a, inParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
816
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
793
817
  var e_1, _d;
794
818
  return __generator(this, function (_e) {
795
819
  switch (_e.label) {
796
820
  case 0:
797
- _a = options.inParallelCount, inParallelCount = _a === void 0 ? Infinity : _a;
821
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
798
822
  index = 0;
799
823
  runningTasks = [];
800
824
  tasks = [];
@@ -810,7 +834,7 @@ function forEachAsync(array, options, callbackfunction) {
810
834
  /* not await */ Promise.resolve(task).then(function () {
811
835
  runningTasks = runningTasks.filter(function (t) { return t !== task; });
812
836
  });
813
- if (!(inParallelCount < runningTasks.length)) return [3 /*break*/, 2];
837
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
814
838
  return [4 /*yield*/, Promise.race(runningTasks)];
815
839
  case 1:
816
840
  _f.sent();
@@ -855,101 +879,154 @@ function forEachAsync(array, options, callbackfunction) {
855
879
  }
856
880
 
857
881
  /**
858
- * The maximum number of iterations for a loops
882
+ * Function isValidJsonString will tell you if the string is valid JSON or not
859
883
  */
860
- var LOOP_LIMIT = 1000;
884
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
885
+ try {
886
+ JSON.parse(value);
887
+ return true;
888
+ }
889
+ catch (error) {
890
+ if (!(error instanceof Error)) {
891
+ throw error;
892
+ }
893
+ if (error.message.includes('Unexpected token')) {
894
+ return false;
895
+ }
896
+ return false;
897
+ }
898
+ }
861
899
 
862
900
  /**
863
- * This error indicates errors during the execution of the pipeline
901
+ * Makes first letter of a string uppercase
902
+ *
864
903
  */
865
- var PipelineExecutionError = /** @class */ (function (_super) {
866
- __extends(PipelineExecutionError, _super);
867
- function PipelineExecutionError(message) {
868
- var _this = _super.call(this, message) || this;
869
- _this.name = 'PipelineExecutionError';
870
- Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
871
- return _this;
872
- }
873
- return PipelineExecutionError;
874
- }(Error));
904
+ function capitalize(word) {
905
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
906
+ }
875
907
 
876
908
  /**
877
- * Replaces parameters in template with values from parameters object
909
+ * Extracts all code blocks from markdown.
878
910
  *
879
- * @param template the template with parameters in {curly} braces
880
- * @param parameters the object with parameters
881
- * @returns the template with replaced parameters
882
- * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
911
+ * Note: There are 3 simmilar function:
912
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
913
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
914
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
915
+ *
916
+ * @param markdown any valid markdown
917
+ * @returns code blocks with language and content
883
918
  *
884
- * @private within the createPipelineExecutor
885
919
  */
886
- function replaceParameters(template, parameters) {
887
- var replacedTemplate = template;
888
- var match;
889
- var loopLimit = LOOP_LIMIT;
890
- var _loop_1 = function () {
891
- if (loopLimit-- < 0) {
892
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
893
- }
894
- var precol = match.groups.precol;
895
- var parameterName = match.groups.parameterName;
896
- if (parameterName === '') {
897
- return "continue";
898
- }
899
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
900
- throw new PipelineExecutionError('Parameter is already opened or not closed');
901
- }
902
- if (parameters[parameterName] === undefined) {
903
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
904
- }
905
- var parameterValue = parameters[parameterName];
906
- if (parameterValue === undefined) {
907
- throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
908
- }
909
- parameterValue = parameterValue.toString();
910
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
911
- parameterValue = parameterValue
912
- .split('\n')
913
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
914
- .join('\n');
920
+ function extractAllBlocksFromMarkdown(markdown) {
921
+ var e_1, _a;
922
+ var codeBlocks = [];
923
+ var lines = markdown.split('\n');
924
+ // Note: [0] Ensure that the last block notated by gt > will be closed
925
+ lines.push('');
926
+ var currentCodeBlock = null;
927
+ try {
928
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
929
+ var line = lines_1_1.value;
930
+ if (line.startsWith('> ') || line === '>') {
931
+ if (currentCodeBlock === null) {
932
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
933
+ } /* not else */
934
+ if (currentCodeBlock.blockNotation === '>') {
935
+ if (currentCodeBlock.content !== '') {
936
+ currentCodeBlock.content += '\n';
937
+ }
938
+ currentCodeBlock.content += line.slice(2);
939
+ }
940
+ }
941
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
942
+ codeBlocks.push(currentCodeBlock);
943
+ currentCodeBlock = null;
944
+ }
945
+ /* not else */
946
+ if (line.startsWith('```')) {
947
+ var language = line.slice(3).trim() || null;
948
+ if (currentCodeBlock === null) {
949
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
950
+ }
951
+ else {
952
+ if (language !== null) {
953
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
954
+ }
955
+ codeBlocks.push(currentCodeBlock);
956
+ currentCodeBlock = null;
957
+ }
958
+ }
959
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
960
+ if (currentCodeBlock.content !== '') {
961
+ currentCodeBlock.content += '\n';
962
+ }
963
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
964
+ }
915
965
  }
916
- replacedTemplate =
917
- replacedTemplate.substring(0, match.index + precol.length) +
918
- parameterValue +
919
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
920
- };
921
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
922
- .exec(replacedTemplate))) {
923
- _loop_1();
924
966
  }
925
- // [💫] Check if there are parameters that are not closed properly
926
- if (/{\w+$/.test(replacedTemplate)) {
927
- throw new PipelineExecutionError('Parameter is not closed');
967
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
968
+ finally {
969
+ try {
970
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
971
+ }
972
+ finally { if (e_1) throw e_1.error; }
928
973
  }
929
- // [💫] Check if there are parameters that are not opened properly
930
- if (/^\w+}/.test(replacedTemplate)) {
931
- throw new PipelineExecutionError('Parameter is not opened');
974
+ if (currentCodeBlock !== null) {
975
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
932
976
  }
933
- return replacedTemplate;
977
+ return codeBlocks;
934
978
  }
979
+ /**
980
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
981
+ */
935
982
 
936
983
  /**
937
- * Function isValidJsonString will tell you if the string is valid JSON or not
984
+ * Extracts exactly ONE code block from markdown.
985
+ *
986
+ * Note: If there are multiple or no code blocks the function throws an error
987
+ *
988
+ * Note: There are 3 simmilar function:
989
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
990
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
991
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
992
+ *
993
+ * @param markdown any valid markdown
994
+ * @returns code block with language and content
938
995
  */
939
- function isValidJsonString(value /* <-[👨‍⚖️] */) {
940
- try {
941
- JSON.parse(value);
942
- return true;
943
- }
944
- catch (error) {
945
- if (!(error instanceof Error)) {
946
- throw error;
947
- }
948
- if (error.message.includes('Unexpected token')) {
949
- return false;
950
- }
951
- return false;
996
+ function extractOneBlockFromMarkdown(markdown) {
997
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
998
+ if (codeBlocks.length !== 1) {
999
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
952
1000
  }
1001
+ return codeBlocks[0];
1002
+ }
1003
+ /***
1004
+ * TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
1005
+ */
1006
+
1007
+ /**
1008
+ * Extracts code block from markdown.
1009
+ *
1010
+ * Note: If there are multiple or no code blocks the function throws an error
1011
+ *
1012
+ * Note: There are 3 simmilar function:
1013
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1014
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1015
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1016
+ */
1017
+ function extractBlock(markdown) {
1018
+ var content = extractOneBlockFromMarkdown(markdown).content;
1019
+ return content;
1020
+ }
1021
+ //
1022
+
1023
+ /**
1024
+ * Simple wrapper `new Date().toISOString()`
1025
+ *
1026
+ * @returns string_date branded type
1027
+ */
1028
+ function $currentDate() {
1029
+ return new Date().toISOString();
953
1030
  }
954
1031
 
955
1032
  /**
@@ -1026,14 +1103,6 @@ var CountUtils = {
1026
1103
  PAGES: countPages,
1027
1104
  };
1028
1105
 
1029
- /**
1030
- * Makes first letter of a string uppercase
1031
- *
1032
- */
1033
- function capitalize(word) {
1034
- return word.substring(0, 1).toUpperCase() + word.substring(1);
1035
- }
1036
-
1037
1106
  /**
1038
1107
  * Makes first letter of a string uppercase
1039
1108
  *
@@ -1292,122 +1361,210 @@ function parseNumber(value) {
1292
1361
  */
1293
1362
 
1294
1363
  /**
1295
- * Extracts all code blocks from markdown.
1364
+ * Generates random seed
1296
1365
  *
1297
- * Note: There are 3 simmilar function:
1298
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1299
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1300
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1366
+ * Warning: This function is not cryptographically secure (it uses Math.random internally)
1367
+ */
1368
+ function $randomSeed() {
1369
+ return Math.random();
1370
+ }
1371
+
1372
+ /**
1373
+ * Removes quotes from a string
1301
1374
  *
1302
- * @param markdown any valid markdown
1303
- * @returns code blocks with language and content
1375
+ * Tip: This is very usefull for post-processing of the result of the LLM model
1376
+ * Note: This function removes only the same quotes from the beginning and the end of the string
1377
+ * Note: There are two simmilar functions:
1378
+ * - `removeQuotes` which removes only bounding quotes
1379
+ * - `unwrapResult` which removes whole introduce sentence
1304
1380
  *
1381
+ * @param text optionally quoted text
1382
+ * @returns text without quotes
1305
1383
  */
1306
- function extractAllBlocksFromMarkdown(markdown) {
1384
+ function removeQuotes(text) {
1385
+ if (text.startsWith('"') && text.endsWith('"')) {
1386
+ return text.slice(1, -1);
1387
+ }
1388
+ if (text.startsWith('\'') && text.endsWith('\'')) {
1389
+ return text.slice(1, -1);
1390
+ }
1391
+ return text;
1392
+ }
1393
+
1394
+ /**
1395
+ * @@@
1396
+ *
1397
+ * @returns The same object as the input, but deeply frozen
1398
+ *
1399
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1400
+ */
1401
+ function deepFreeze(objectValue) {
1307
1402
  var e_1, _a;
1308
- var codeBlocks = [];
1309
- var lines = markdown.split('\n');
1310
- var currentCodeBlock = null;
1403
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
1311
1404
  try {
1312
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
1313
- var line = lines_1_1.value;
1314
- if (line.startsWith('```')) {
1315
- var language = line.slice(3).trim() || null;
1316
- if (currentCodeBlock === null) {
1317
- currentCodeBlock = { language: language, content: '' };
1318
- }
1319
- else {
1320
- if (language !== null) {
1321
- // [🌻]
1322
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
1323
- }
1324
- codeBlocks.push(currentCodeBlock);
1325
- currentCodeBlock = null;
1326
- }
1327
- }
1328
- else if (currentCodeBlock !== null) {
1329
- if (currentCodeBlock.content !== '') {
1330
- currentCodeBlock.content += '\n';
1331
- }
1332
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
1405
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1406
+ var propertyName = propertyNames_1_1.value;
1407
+ var value = objectValue[propertyName];
1408
+ if (value && typeof value === 'object') {
1409
+ deepFreeze(value);
1333
1410
  }
1334
1411
  }
1335
1412
  }
1336
1413
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1337
1414
  finally {
1338
1415
  try {
1339
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
1416
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1340
1417
  }
1341
1418
  finally { if (e_1) throw e_1.error; }
1342
1419
  }
1343
- if (currentCodeBlock !== null) {
1344
- // [🌻]
1345
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
1346
- }
1347
- return codeBlocks;
1420
+ return Object.freeze(objectValue);
1348
1421
  }
1422
+ /**
1423
+ * TODO: [🔼] Export from `@promptbook/utils`
1424
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1425
+ */
1349
1426
 
1350
1427
  /**
1351
- * Extracts exactly ONE code block from markdown.
1352
- *
1353
- * Note: If there are multiple or no code blocks the function throws an error
1354
- *
1355
- * Note: There are 3 simmilar function:
1356
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1357
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1358
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1359
- *
1360
- * @param markdown any valid markdown
1361
- * @returns code block with language and content
1428
+ * The maximum number of iterations for a loops
1362
1429
  */
1363
- function extractOneBlockFromMarkdown(markdown) {
1364
- var codeBlocks = extractAllBlocksFromMarkdown(markdown);
1365
- if (codeBlocks.length !== 1) {
1366
- // TODO: Report more specific place where the error happened
1367
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
1368
- }
1369
- return codeBlocks[0];
1370
- }
1371
- /***
1372
- * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
1430
+ var LOOP_LIMIT = 1000;
1431
+ /**
1432
+ * Nonce which is used for replacing things in strings
1433
+ */
1434
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
1435
+ /**
1436
+ * The names of the parameters that are reserved for special purposes
1437
+ */
1438
+ deepFreeze([
1439
+ 'content',
1440
+ 'context',
1441
+ 'knowledge',
1442
+ 'samples',
1443
+ 'modelName',
1444
+ 'currentDate',
1445
+ // <- TODO: Add more like 'date', 'modelName',...
1446
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
1447
+ ]);
1448
+ /**
1449
+ * @@@
1450
+ */
1451
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1452
+ /**
1453
+ * @@@
1454
+ */
1455
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1456
+ /*
1457
+ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
1458
+ */
1459
+ // [🟡][🟢][🔵][⚪]
1460
+ /**
1461
+ * TODO: [🔼] Export all to core
1373
1462
  */
1374
1463
 
1375
1464
  /**
1376
- * Extracts code block from markdown.
1377
- *
1378
- * Note: If there are multiple or no code blocks the function throws an error
1379
- *
1380
- * Note: There are 3 simmilar function:
1381
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
1382
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
1383
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
1465
+ * This error type indicates that some limit was reached
1384
1466
  */
1385
- function extractBlock(markdown) {
1386
- var content = extractOneBlockFromMarkdown(markdown).content;
1387
- return content;
1388
- }
1389
- //
1467
+ var LimitReachedError = /** @class */ (function (_super) {
1468
+ __extends(LimitReachedError, _super);
1469
+ function LimitReachedError(message) {
1470
+ var _this = _super.call(this, message) || this;
1471
+ _this.name = 'LimitReachedError';
1472
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
1473
+ return _this;
1474
+ }
1475
+ return LimitReachedError;
1476
+ }(Error));
1390
1477
 
1391
1478
  /**
1392
- * Removes quotes from a string
1393
- *
1394
- * Tip: This is very usefull for post-processing of the result of the LLM model
1395
- * Note: This function removes only the same quotes from the beginning and the end of the string
1396
- * Note: There are two simmilar functions:
1397
- * - `removeQuotes` which removes only bounding quotes
1398
- * - `unwrapResult` which removes whole introduce sentence
1479
+ * This error indicates errors during the execution of the pipeline
1480
+ */
1481
+ var PipelineExecutionError = /** @class */ (function (_super) {
1482
+ __extends(PipelineExecutionError, _super);
1483
+ function PipelineExecutionError(message) {
1484
+ var _this = _super.call(this, message) || this;
1485
+ _this.name = 'PipelineExecutionError';
1486
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
1487
+ return _this;
1488
+ }
1489
+ return PipelineExecutionError;
1490
+ }(Error));
1491
+
1492
+ /**
1493
+ * Replaces parameters in template with values from parameters object
1399
1494
  *
1400
- * @param text optionally quoted text
1401
- * @returns text without quotes
1495
+ * @param template the template with parameters in {curly} braces
1496
+ * @param parameters the object with parameters
1497
+ * @returns the template with replaced parameters
1498
+ * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
1402
1499
  */
1403
- function removeQuotes(text) {
1404
- if (text.startsWith('"') && text.endsWith('"')) {
1405
- return text.slice(1, -1);
1500
+ function replaceParameters(template, parameters) {
1501
+ var e_1, _a;
1502
+ try {
1503
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
1504
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
1505
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
1506
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} has missing value"));
1507
+ }
1508
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
1509
+ // TODO: [🍵]
1510
+ throw new UnexpectedError("Parameter {".concat(parameterName, "} is restricted to use"));
1511
+ }
1512
+ }
1406
1513
  }
1407
- if (text.startsWith('\'') && text.endsWith('\'')) {
1408
- return text.slice(1, -1);
1514
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1515
+ finally {
1516
+ try {
1517
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1518
+ }
1519
+ finally { if (e_1) throw e_1.error; }
1409
1520
  }
1410
- return text;
1521
+ var replacedTemplate = template;
1522
+ var match;
1523
+ var loopLimit = LOOP_LIMIT;
1524
+ var _loop_1 = function () {
1525
+ if (loopLimit-- < 0) {
1526
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
1527
+ }
1528
+ var precol = match.groups.precol;
1529
+ var parameterName = match.groups.parameterName;
1530
+ if (parameterName === '') {
1531
+ return "continue";
1532
+ }
1533
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
1534
+ throw new PipelineExecutionError('Parameter is already opened or not closed');
1535
+ }
1536
+ if (parameters[parameterName] === undefined) {
1537
+ throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
1538
+ }
1539
+ var parameterValue = parameters[parameterName];
1540
+ if (parameterValue === undefined) {
1541
+ throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
1542
+ }
1543
+ parameterValue = parameterValue.toString();
1544
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
1545
+ parameterValue = parameterValue
1546
+ .split('\n')
1547
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
1548
+ .join('\n');
1549
+ }
1550
+ replacedTemplate =
1551
+ replacedTemplate.substring(0, match.index + precol.length) +
1552
+ parameterValue +
1553
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
1554
+ };
1555
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1556
+ .exec(replacedTemplate))) {
1557
+ _loop_1();
1558
+ }
1559
+ // [💫] Check if there are parameters that are not closed properly
1560
+ if (/{\w+$/.test(replacedTemplate)) {
1561
+ throw new PipelineExecutionError('Parameter is not closed');
1562
+ }
1563
+ // [💫] Check if there are parameters that are not opened properly
1564
+ if (/^\w+}/.test(replacedTemplate)) {
1565
+ throw new PipelineExecutionError('Parameter is not opened');
1566
+ }
1567
+ return replacedTemplate;
1411
1568
  }
1412
1569
 
1413
1570
  /**
@@ -1439,6 +1596,9 @@ function difference(a, b, isEqual) {
1439
1596
  }
1440
1597
  return diff;
1441
1598
  }
1599
+ /**
1600
+ * TODO: [🧠][💯] Maybe also implement symmetricDifference
1601
+ */
1442
1602
 
1443
1603
  /**
1444
1604
  * Creates a new set with all elements that are present in all sets
@@ -1687,7 +1847,7 @@ function isValidPromptbookVersion(version) {
1687
1847
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1688
1848
  return false;
1689
1849
  }
1690
- // <- TODO: !!!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
1850
+ // <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
1691
1851
  return true;
1692
1852
  }
1693
1853
 
@@ -1809,7 +1969,7 @@ function isValidUuid(value) {
1809
1969
  /**
1810
1970
  * The version of the Promptbook library
1811
1971
  */
1812
- var PROMPTBOOK_VERSION = '0.61.0-7';
1972
+ var PROMPTBOOK_VERSION = '0.61.0-30';
1813
1973
  // TODO: !!!! List here all the versions and annotate + put into script
1814
1974
 
1815
1975
  // @promptbook/utils
@@ -1827,5 +1987,5 @@ var normalizeTo = {
1827
1987
  * Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
1828
1988
  */
1829
1989
 
1830
- export { CountUtils, DIACRITIC_VARIANTS_LETTERS, PROMPTBOOK_VERSION, capitalize, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, difference, extractBlock, extractParameters, extractParametersFromPromptTemplate, extractVariables, forEachAsync, intersection, isHostnameOnPrivateNetwork, isUrlOnPrivateNetwork, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeTo, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renameParameter, renderPromptbookMermaid, replaceParameters, searchKeywords, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
1990
+ export { $currentDate, $randomSeed, CountUtils, DIACRITIC_VARIANTS_LETTERS, PROMPTBOOK_VERSION, capitalize, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, difference, extractBlock, extractParameterNames, extractParameterNamesFromPromptTemplate, extractVariables, forEachAsync, intersection, isHostnameOnPrivateNetwork, isUrlOnPrivateNetwork, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeTo, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renameParameter, renderPromptbookMermaid, replaceParameters, searchKeywords, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
1831
1991
  //# sourceMappingURL=index.es.js.map