@promptbook/markdown-utils 0.92.0-9 → 0.92.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 (206) hide show
  1. package/README.md +1 -5
  2. package/esm/index.es.js +585 -404
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +26 -14
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -2
  7. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  8. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  9. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  10. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
  11. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  12. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
  14. package/esm/typings/src/config.d.ts +41 -11
  15. package/esm/typings/src/constants.d.ts +43 -2
  16. package/esm/typings/src/conversion/parsePipeline.d.ts +2 -2
  17. package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
  18. package/esm/typings/src/errors/CollectionError.d.ts +1 -1
  19. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
  20. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
  21. package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
  22. package/esm/typings/src/executables/locateApp.d.ts +2 -2
  23. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
  24. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
  25. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
  26. package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
  27. package/esm/typings/src/execution/CommonToolsOptions.d.ts +3 -3
  28. package/esm/typings/src/execution/ExecutionTask.d.ts +19 -1
  29. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +2 -1
  30. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +4 -2
  31. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  32. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
  33. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
  34. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +13 -10
  35. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +12 -9
  36. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
  37. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +21 -15
  38. package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
  39. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
  40. package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
  41. package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
  42. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -9
  43. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +18 -5
  44. package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
  45. package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +1 -1
  46. package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
  47. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
  48. package/esm/typings/src/execution/utils/checkExpectations.d.ts +3 -3
  49. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
  50. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +1 -1
  51. package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
  52. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
  53. package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
  54. package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
  55. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  56. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  57. package/esm/typings/src/formats/index.d.ts +2 -2
  58. package/esm/typings/src/formats/json/JsonFormatParser.d.ts +19 -0
  59. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  60. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
  61. package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
  62. package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
  63. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  64. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  65. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
  66. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
  67. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  68. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
  69. package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
  70. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
  71. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
  72. package/esm/typings/src/formfactors/index.d.ts +33 -8
  73. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
  74. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  75. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
  76. package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
  77. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
  78. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
  79. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
  80. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
  81. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +18 -5
  82. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
  83. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +21 -42
  84. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
  85. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +13 -4
  86. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
  87. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +11 -3
  88. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  89. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
  90. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -0
  91. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  92. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  93. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -4
  94. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
  95. package/esm/typings/src/llm-providers/google/google-models.d.ts +1 -1
  96. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
  97. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  98. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
  99. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
  100. package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
  101. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  102. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  103. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  104. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  105. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  106. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  107. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +10 -7
  108. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +1 -1
  109. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
  110. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  111. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  112. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +1 -1
  113. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +2 -2
  114. package/esm/typings/src/prepare/prepareTasks.d.ts +8 -5
  115. package/esm/typings/src/remote-server/openapi.d.ts +1 -1
  116. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +1 -1
  117. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
  118. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +7 -6
  119. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  120. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  121. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  122. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  123. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  124. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  125. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
  126. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  127. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  128. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  129. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  130. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  131. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  132. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  133. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  134. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  135. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  136. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  137. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  138. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  139. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  140. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  141. package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
  142. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  143. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  144. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  145. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  146. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  147. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  148. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +11 -0
  149. package/esm/typings/src/storage/local-storage/utils/IndexedDbStorageOptions.d.ts +14 -0
  150. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +8 -0
  151. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  152. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  153. package/esm/typings/src/types/ModelRequirements.d.ts +2 -2
  154. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  155. package/esm/typings/src/types/typeAliases.d.ts +22 -19
  156. package/esm/typings/src/utils/$Register.d.ts +8 -7
  157. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  158. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  159. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  160. package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +1 -1
  161. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  162. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  163. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  164. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  165. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  166. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  167. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  168. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  169. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  170. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  171. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  172. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  173. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  174. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  175. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  176. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  177. package/esm/typings/src/utils/organization/just.d.ts +1 -1
  178. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  179. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  180. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  181. package/esm/typings/src/utils/removeQuotes.d.ts +2 -2
  182. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  183. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  184. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -1
  185. package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +1 -1
  186. package/esm/typings/src/utils/unwrapResult.d.ts +2 -2
  187. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  188. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  189. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +1 -1
  190. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +1 -1
  191. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +1 -1
  192. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -1
  193. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +1 -1
  194. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -1
  195. package/esm/typings/src/version.d.ts +2 -1
  196. package/esm/typings/src/wizzard/wizzard.d.ts +1 -1
  197. package/package.json +13 -1
  198. package/umd/index.umd.js +585 -404
  199. package/umd/index.umd.js.map +1 -1
  200. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
  201. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  202. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +0 -19
  203. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
  204. /package/esm/typings/src/llm-providers/{multiple → _multiple}/MultipleLlmExecutionTools.d.ts +0 -0
  205. /package/esm/typings/src/llm-providers/{multiple → _multiple}/joinLlmExecutionTools.d.ts +0 -0
  206. /package/esm/typings/src/llm-providers/{multiple → _multiple}/playground/playground.d.ts +0 -0
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -59,8 +59,8 @@
59
59
  /**
60
60
  * Extracts all code blocks from markdown.
61
61
  *
62
- * Note: There are multiple simmilar function:
63
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
62
+ * Note: There are multiple similar functions:
63
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
64
64
  * - `extractJsonBlock` extracts exactly one valid JSON code block
65
65
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
66
66
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
@@ -110,7 +110,7 @@
110
110
  if (currentCodeBlock.content !== '') {
111
111
  currentCodeBlock.content += '\n';
112
112
  }
113
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
113
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
114
114
  }
115
115
  }
116
116
  if (currentCodeBlock !== null) {
@@ -127,8 +127,8 @@
127
127
  *
128
128
  * - When there are multiple or no code blocks the function throws a `ParseError`
129
129
  *
130
- * Note: There are multiple simmilar function:
131
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
130
+ * Note: There are multiple similar functions:
131
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
132
132
  * - `extractJsonBlock` extracts exactly one valid JSON code block
133
133
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
134
134
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
@@ -158,7 +158,7 @@
158
158
  *
159
159
  * - When there are multiple or no code blocks the function throws a `ParseError`
160
160
  *
161
- * Note: There are multiple simmilar function:
161
+ * Note: There are multiple similar function:
162
162
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
163
163
  * - `extractJsonBlock` extracts exactly one valid JSON code block
164
164
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
@@ -176,7 +176,7 @@
176
176
  * Returns the same value that is passed as argument.
177
177
  * No side effects.
178
178
  *
179
- * Note: It can be usefull for:
179
+ * Note: It can be useful for:
180
180
  *
181
181
  * 1) Leveling indentation
182
182
  * 2) Putting always-true or always-false conditions without getting eslint errors
@@ -231,6 +231,21 @@
231
231
  * @public exported from `@promptbook/core`
232
232
  */
233
233
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
234
+ /**
235
+ * Threshold value that determines when a dataset is considered "big"
236
+ * and may require special handling or optimizations
237
+ *
238
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
239
+ *
240
+ * @public exported from `@promptbook/core`
241
+ */
242
+ const BIG_DATASET_TRESHOLD = 50;
243
+ /**
244
+ * Placeholder text used to represent a placeholder value of failed operation
245
+ *
246
+ * @public exported from `@promptbook/core`
247
+ */
248
+ const FAILED_VALUE_PLACEHOLDER = '!?';
234
249
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
235
250
  /**
236
251
  * The maximum number of iterations for a loops
@@ -310,7 +325,7 @@
310
325
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
311
326
  // <- TODO: [🧜‍♂️]
312
327
  /**
313
- * @@@
328
+ * Default settings for parsing and generating CSV files in Promptbook.
314
329
  *
315
330
  * @public exported from `@promptbook/core`
316
331
  */
@@ -321,19 +336,19 @@
321
336
  skipEmptyLines: true,
322
337
  });
323
338
  /**
324
- * @@@
339
+ * Controls whether verbose logging is enabled by default throughout the application.
325
340
  *
326
341
  * @public exported from `@promptbook/core`
327
342
  */
328
343
  let DEFAULT_IS_VERBOSE = false;
329
344
  /**
330
- * @@@
345
+ * Controls whether auto-installation of dependencies is enabled by default.
331
346
  *
332
347
  * @public exported from `@promptbook/core`
333
348
  */
334
349
  const DEFAULT_IS_AUTO_INSTALLED = false;
335
350
  /**
336
- * @@@
351
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
337
352
  *
338
353
  * @private within the repository
339
354
  */
@@ -401,7 +416,7 @@
401
416
  ${block(message)}
402
417
 
403
418
  Note: This error should not happen.
404
- It's probbably a bug in the pipeline collection
419
+ It's probably a bug in the pipeline collection
405
420
 
406
421
  Please report issue:
407
422
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -466,7 +481,7 @@
466
481
  * Function isValidJsonString will tell you if the string is valid JSON or not
467
482
  *
468
483
  * @param value The string to check
469
- * @returns True if the string is a valid JSON string, false otherwise
484
+ * @returns `true` if the string is a valid JSON string, false otherwise
470
485
  *
471
486
  * @public exported from `@promptbook/utils`
472
487
  */
@@ -492,7 +507,7 @@
492
507
  * - When there are multiple JSON code blocks the function throws a `ParseError`
493
508
  *
494
509
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
495
- * Note: There are multiple simmilar function:
510
+ * Note: There are multiple similar function:
496
511
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
497
512
  * - `extractJsonBlock` extracts exactly one valid JSON code block
498
513
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
@@ -517,14 +532,14 @@
517
532
  }
518
533
  /**
519
534
  * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
520
- * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
535
+ * TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
521
536
  */
522
537
 
523
538
  /**
524
539
  * Just says that the variable is not used but should be kept
525
540
  * No side effects.
526
541
  *
527
- * Note: It can be usefull for:
542
+ * Note: It can be useful for:
528
543
  *
529
544
  * 1) Suppressing eager optimization of unused imports
530
545
  * 2) Suppressing eslint errors of unused variables in the tests
@@ -607,7 +622,7 @@
607
622
  * Tests if given string is valid URL.
608
623
  *
609
624
  * Note: Dataurl are considered perfectly valid.
610
- * Note: There are two simmilar functions:
625
+ * Note: There are two similar functions:
611
626
  * - `isValidUrl` which tests any URL
612
627
  * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
613
628
  *
@@ -717,7 +732,7 @@
717
732
  if (bookVersion !== `undefined`) {
718
733
  commands.push(`BOOK VERSION ${bookVersion}`);
719
734
  }
720
- // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
735
+ // TODO: [main] !!5 This increases size of the bundle and is probably not necessary
721
736
  pipelineString = prettifyMarkdown(pipelineString);
722
737
  for (const parameter of parameters.filter(({ isInput }) => isInput)) {
723
738
  commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
@@ -1016,8 +1031,12 @@
1016
1031
  */
1017
1032
 
1018
1033
  /**
1019
- * @@@
1034
+ * Creates a deep clone of the given object
1035
+ *
1036
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1020
1037
  *
1038
+ * @param objectValue The object to clone.
1039
+ * @returns A deep, writable clone of the input object.
1021
1040
  * @public exported from `@promptbook/utils`
1022
1041
  */
1023
1042
  function deepClone(objectValue) {
@@ -1099,13 +1118,13 @@
1099
1118
  */
1100
1119
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1101
1120
  /**
1102
- * @@@
1121
+ * Placeholder value indicating a parameter is missing its value.
1103
1122
  *
1104
1123
  * @private within the repository
1105
1124
  */
1106
1125
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1107
1126
  /**
1108
- * @@@
1127
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
1109
1128
  *
1110
1129
  * @private within the repository
1111
1130
  */
@@ -1150,7 +1169,7 @@
1150
1169
  /**
1151
1170
  * Tests if given string is valid semantic version
1152
1171
  *
1153
- * Note: There are two simmilar functions:
1172
+ * Note: There are two similar functions:
1154
1173
  * - `isValidSemanticVersion` which tests any semantic version
1155
1174
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1156
1175
  *
@@ -1172,7 +1191,7 @@
1172
1191
  *
1173
1192
  * @see https://www.npmjs.com/package/promptbook?activeTab=versions
1174
1193
  * Note: When you are using for example promptbook 2.0.0 and there already is promptbook 3.0.0 it don`t know about it.
1175
- * Note: There are two simmilar functions:
1194
+ * Note: There are two similar functions:
1176
1195
  * - `isValidSemanticVersion` which tests any semantic version
1177
1196
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1178
1197
  *
@@ -1192,7 +1211,7 @@
1192
1211
  /**
1193
1212
  * Tests if given string is valid pipeline URL URL.
1194
1213
  *
1195
- * Note: There are two simmilar functions:
1214
+ * Note: There are two similar functions:
1196
1215
  * - `isValidUrl` which tests any URL
1197
1216
  * - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
1198
1217
  *
@@ -1289,7 +1308,7 @@
1289
1308
  ${block(pipelineIdentification)}
1290
1309
  `));
1291
1310
  }
1292
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1311
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1293
1312
  if (!Array.isArray(pipeline.parameters)) {
1294
1313
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1295
1314
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -1300,7 +1319,7 @@
1300
1319
  ${block(pipelineIdentification)}
1301
1320
  `));
1302
1321
  }
1303
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1322
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1304
1323
  if (!Array.isArray(pipeline.tasks)) {
1305
1324
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1306
1325
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -1604,7 +1623,7 @@
1604
1623
  /**
1605
1624
  * Constructs a pipeline collection from pipelines
1606
1625
  *
1607
- * @param pipelines @@@
1626
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1608
1627
  *
1609
1628
  * Note: During the construction logic of all pipelines are validated
1610
1629
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -1718,7 +1737,7 @@
1718
1737
  super(spaceTrim.spaceTrim((block) => `
1719
1738
  ${block(message)}
1720
1739
 
1721
- Note: You have probbably forgot to provide some tools for pipeline execution or preparation
1740
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
1722
1741
 
1723
1742
  `));
1724
1743
  this.name = 'MissingToolsError';
@@ -1752,7 +1771,7 @@
1752
1771
  super(message);
1753
1772
  this.name = 'PipelineExecutionError';
1754
1773
  // TODO: [🐙] DRY - Maybe $randomId
1755
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1774
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
1756
1775
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1757
1776
  }
1758
1777
  }
@@ -1768,15 +1787,18 @@
1768
1787
  * @public exported from `@promptbook/core`
1769
1788
  */
1770
1789
  function isPipelinePrepared(pipeline) {
1771
- // Note: Ignoring `pipeline.preparations` @@@
1772
- // Note: Ignoring `pipeline.knowledgePieces` @@@
1790
+ // Note: Ignoring `pipeline.preparations`
1791
+ // Note: Ignoring `pipeline.knowledgePieces`
1773
1792
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
1793
+ // console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
1774
1794
  return false;
1775
1795
  }
1776
1796
  if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
1797
+ // console.log('Pipeline is not prepared because personas are not prepared', pipeline.personas);
1777
1798
  return false;
1778
1799
  }
1779
1800
  if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
1801
+ //console.log('Pipeline is not prepared because knowledge sources are not prepared', pipeline.knowledgeSources);
1780
1802
  return false;
1781
1803
  }
1782
1804
  /*
@@ -1797,75 +1819,6 @@
1797
1819
  * - [♨] Are tasks prepared
1798
1820
  */
1799
1821
 
1800
- /**
1801
- * Converts a JavaScript Object Notation (JSON) string into an object.
1802
- *
1803
- * Note: This is wrapper around `JSON.parse()` with better error and type handling
1804
- *
1805
- * @public exported from `@promptbook/utils`
1806
- */
1807
- function jsonParse(value) {
1808
- if (value === undefined) {
1809
- throw new Error(`Can not parse JSON from undefined value.`);
1810
- }
1811
- else if (typeof value !== 'string') {
1812
- console.error('Can not parse JSON from non-string value.', { text: value });
1813
- throw new Error(spaceTrim__default["default"](`
1814
- Can not parse JSON from non-string value.
1815
-
1816
- The value type: ${typeof value}
1817
- See more in console.
1818
- `));
1819
- }
1820
- try {
1821
- return JSON.parse(value);
1822
- }
1823
- catch (error) {
1824
- if (!(error instanceof Error)) {
1825
- throw error;
1826
- }
1827
- throw new Error(spaceTrim__default["default"]((block) => `
1828
- ${block(error.message)}
1829
-
1830
- The JSON text:
1831
- ${block(value)}
1832
- `));
1833
- }
1834
- }
1835
- /**
1836
- * TODO: !!!! Use in Promptbook.studio
1837
- */
1838
-
1839
- /**
1840
- * Recursively converts JSON strings to JSON objects
1841
-
1842
- * @public exported from `@promptbook/utils`
1843
- */
1844
- function jsonStringsToJsons(object) {
1845
- if (object === null) {
1846
- return object;
1847
- }
1848
- if (Array.isArray(object)) {
1849
- return object.map(jsonStringsToJsons);
1850
- }
1851
- if (typeof object !== 'object') {
1852
- return object;
1853
- }
1854
- const newObject = { ...object };
1855
- for (const [key, value] of Object.entries(object)) {
1856
- if (typeof value === 'string' && isValidJsonString(value)) {
1857
- newObject[key] = jsonParse(value);
1858
- }
1859
- else {
1860
- newObject[key] = jsonStringsToJsons(value);
1861
- }
1862
- }
1863
- return newObject;
1864
- }
1865
- /**
1866
- * TODO: Type the return type correctly
1867
- */
1868
-
1869
1822
  /**
1870
1823
  * This error indicates problems parsing the format value
1871
1824
  *
@@ -1910,7 +1863,7 @@
1910
1863
  }
1911
1864
 
1912
1865
  /**
1913
- * This error indicates that the pipeline collection cannot be propperly loaded
1866
+ * This error indicates that the pipeline collection cannot be properly loaded
1914
1867
  *
1915
1868
  * @public exported from `@promptbook/core`
1916
1869
  */
@@ -2075,6 +2028,101 @@
2075
2028
  * Note: [💞] Ignore a discrepancy between file name and entity name
2076
2029
  */
2077
2030
 
2031
+ /**
2032
+ * Serializes an error into a [🚉] JSON-serializable object
2033
+ *
2034
+ * @public exported from `@promptbook/utils`
2035
+ */
2036
+ function serializeError(error) {
2037
+ const { name, message, stack } = error;
2038
+ const { id } = error;
2039
+ if (!Object.keys(ALL_ERRORS).includes(name)) {
2040
+ console.error(spaceTrim__default["default"]((block) => `
2041
+
2042
+ Cannot serialize error with name "${name}"
2043
+
2044
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2045
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2046
+
2047
+
2048
+ ${block(stack || message)}
2049
+
2050
+ `));
2051
+ }
2052
+ return {
2053
+ name: name,
2054
+ message,
2055
+ stack,
2056
+ id, // Include id in the serialized object
2057
+ };
2058
+ }
2059
+
2060
+ /**
2061
+ * Converts a JavaScript Object Notation (JSON) string into an object.
2062
+ *
2063
+ * Note: This is wrapper around `JSON.parse()` with better error and type handling
2064
+ *
2065
+ * @public exported from `@promptbook/utils`
2066
+ */
2067
+ function jsonParse(value) {
2068
+ if (value === undefined) {
2069
+ throw new Error(`Can not parse JSON from undefined value.`);
2070
+ }
2071
+ else if (typeof value !== 'string') {
2072
+ console.error('Can not parse JSON from non-string value.', { text: value });
2073
+ throw new Error(spaceTrim__default["default"](`
2074
+ Can not parse JSON from non-string value.
2075
+
2076
+ The value type: ${typeof value}
2077
+ See more in console.
2078
+ `));
2079
+ }
2080
+ try {
2081
+ return JSON.parse(value);
2082
+ }
2083
+ catch (error) {
2084
+ if (!(error instanceof Error)) {
2085
+ throw error;
2086
+ }
2087
+ throw new Error(spaceTrim__default["default"]((block) => `
2088
+ ${block(error.message)}
2089
+
2090
+ The JSON text:
2091
+ ${block(value)}
2092
+ `));
2093
+ }
2094
+ }
2095
+
2096
+ /**
2097
+ * Recursively converts JSON strings to JSON objects
2098
+
2099
+ * @public exported from `@promptbook/utils`
2100
+ */
2101
+ function jsonStringsToJsons(object) {
2102
+ if (object === null) {
2103
+ return object;
2104
+ }
2105
+ if (Array.isArray(object)) {
2106
+ return object.map(jsonStringsToJsons);
2107
+ }
2108
+ if (typeof object !== 'object') {
2109
+ return object;
2110
+ }
2111
+ const newObject = { ...object };
2112
+ for (const [key, value] of Object.entries(object)) {
2113
+ if (typeof value === 'string' && isValidJsonString(value)) {
2114
+ newObject[key] = jsonParse(value);
2115
+ }
2116
+ else {
2117
+ newObject[key] = jsonStringsToJsons(value);
2118
+ }
2119
+ }
2120
+ return newObject;
2121
+ }
2122
+ /**
2123
+ * TODO: Type the return type correctly
2124
+ */
2125
+
2078
2126
  /**
2079
2127
  * Deserializes the error object
2080
2128
  *
@@ -2149,8 +2197,9 @@
2149
2197
  */
2150
2198
  function createTask(options) {
2151
2199
  const { taskType, taskProcessCallback } = options;
2200
+ let { title } = options;
2152
2201
  // TODO: [🐙] DRY
2153
- const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2202
+ const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2154
2203
  let status = 'RUNNING';
2155
2204
  const createdAt = new Date();
2156
2205
  let updatedAt = createdAt;
@@ -2160,6 +2209,10 @@
2160
2209
  const partialResultSubject = new rxjs.Subject();
2161
2210
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2162
2211
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2212
+ if (newOngoingResult.title) {
2213
+ title = newOngoingResult.title;
2214
+ }
2215
+ updatedAt = new Date();
2163
2216
  Object.assign(currentValue, newOngoingResult);
2164
2217
  // <- TODO: assign deep
2165
2218
  partialResultSubject.next(newOngoingResult);
@@ -2205,17 +2258,24 @@
2205
2258
  return {
2206
2259
  taskType,
2207
2260
  taskId,
2261
+ get promptbookVersion() {
2262
+ return PROMPTBOOK_ENGINE_VERSION;
2263
+ },
2264
+ get title() {
2265
+ return title;
2266
+ // <- Note: [1] These must be getters to allow changing the value in the future
2267
+ },
2208
2268
  get status() {
2209
2269
  return status;
2210
- // <- Note: [1] Theese must be getters to allow changing the value in the future
2270
+ // <- Note: [1] --||--
2211
2271
  },
2212
2272
  get createdAt() {
2213
2273
  return createdAt;
2214
- // <- Note: [1]
2274
+ // <- Note: [1] --||--
2215
2275
  },
2216
2276
  get updatedAt() {
2217
2277
  return updatedAt;
2218
- // <- Note: [1]
2278
+ // <- Note: [1] --||--
2219
2279
  },
2220
2280
  asPromise,
2221
2281
  asObservable() {
@@ -2223,15 +2283,15 @@
2223
2283
  },
2224
2284
  get errors() {
2225
2285
  return errors;
2226
- // <- Note: [1]
2286
+ // <- Note: [1] --||--
2227
2287
  },
2228
2288
  get warnings() {
2229
2289
  return warnings;
2230
- // <- Note: [1]
2290
+ // <- Note: [1] --||--
2231
2291
  },
2232
2292
  get currentValue() {
2233
2293
  return currentValue;
2234
- // <- Note: [1]
2294
+ // <- Note: [1] --||--
2235
2295
  },
2236
2296
  };
2237
2297
  }
@@ -2240,64 +2300,6 @@
2240
2300
  * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2241
2301
  */
2242
2302
 
2243
- /**
2244
- * Serializes an error into a [🚉] JSON-serializable object
2245
- *
2246
- * @public exported from `@promptbook/utils`
2247
- */
2248
- function serializeError(error) {
2249
- const { name, message, stack } = error;
2250
- const { id } = error;
2251
- if (!Object.keys(ALL_ERRORS).includes(name)) {
2252
- console.error(spaceTrim__default["default"]((block) => `
2253
-
2254
- Cannot serialize error with name "${name}"
2255
-
2256
- Authors of Promptbook probably forgot to add this error into the list of errors:
2257
- https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2258
-
2259
-
2260
- ${block(stack || message)}
2261
-
2262
- `));
2263
- }
2264
- return {
2265
- name: name,
2266
- message,
2267
- stack,
2268
- id, // Include id in the serialized object
2269
- };
2270
- }
2271
-
2272
- /**
2273
- * Async version of Array.forEach
2274
- *
2275
- * @param array - Array to iterate over
2276
- * @param options - Options for the function
2277
- * @param callbackfunction - Function to call for each item
2278
- * @public exported from `@promptbook/utils`
2279
- * @deprecated [🪂] Use queues instead
2280
- */
2281
- async function forEachAsync(array, options, callbackfunction) {
2282
- const { maxParallelCount = Infinity } = options;
2283
- let index = 0;
2284
- let runningTasks = [];
2285
- const tasks = [];
2286
- for (const item of array) {
2287
- const currentIndex = index++;
2288
- const task = callbackfunction(item, currentIndex, array);
2289
- tasks.push(task);
2290
- runningTasks.push(task);
2291
- /* not await */ Promise.resolve(task).then(() => {
2292
- runningTasks = runningTasks.filter((t) => t !== task);
2293
- });
2294
- if (maxParallelCount < runningTasks.length) {
2295
- await Promise.race(runningTasks);
2296
- }
2297
- }
2298
- await Promise.all(tasks);
2299
- }
2300
-
2301
2303
  /**
2302
2304
  * Represents the uncertain value
2303
2305
  *
@@ -2341,7 +2343,7 @@
2341
2343
  *
2342
2344
  * @public exported from `@promptbook/core`
2343
2345
  */
2344
- $deepFreeze({
2346
+ const UNCERTAIN_USAGE = $deepFreeze({
2345
2347
  price: UNCERTAIN_ZERO_VALUE,
2346
2348
  input: {
2347
2349
  tokensCount: UNCERTAIN_ZERO_VALUE,
@@ -2366,6 +2368,35 @@
2366
2368
  * Note: [💞] Ignore a discrepancy between file name and entity name
2367
2369
  */
2368
2370
 
2371
+ /**
2372
+ * Async version of Array.forEach
2373
+ *
2374
+ * @param array - Array to iterate over
2375
+ * @param options - Options for the function
2376
+ * @param callbackfunction - Function to call for each item
2377
+ * @public exported from `@promptbook/utils`
2378
+ * @deprecated [🪂] Use queues instead
2379
+ */
2380
+ async function forEachAsync(array, options, callbackfunction) {
2381
+ const { maxParallelCount = Infinity } = options;
2382
+ let index = 0;
2383
+ let runningTasks = [];
2384
+ const tasks = [];
2385
+ for (const item of array) {
2386
+ const currentIndex = index++;
2387
+ const task = callbackfunction(item, currentIndex, array);
2388
+ tasks.push(task);
2389
+ runningTasks.push(task);
2390
+ /* not await */ Promise.resolve(task).then(() => {
2391
+ runningTasks = runningTasks.filter((t) => t !== task);
2392
+ });
2393
+ if (maxParallelCount < runningTasks.length) {
2394
+ await Promise.race(runningTasks);
2395
+ }
2396
+ }
2397
+ await Promise.all(tasks);
2398
+ }
2399
+
2369
2400
  /**
2370
2401
  * Function `addUsage` will add multiple usages into one
2371
2402
  *
@@ -2425,12 +2456,14 @@
2425
2456
  const spending = new rxjs.Subject();
2426
2457
  const proxyTools = {
2427
2458
  get title() {
2428
- // TODO: [🧠] Maybe put here some suffix
2429
- return llmTools.title;
2459
+ return `${llmTools.title} (+usage)`;
2460
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2461
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2430
2462
  },
2431
2463
  get description() {
2432
- // TODO: [🧠] Maybe put here some suffix
2433
- return llmTools.description;
2464
+ return `${llmTools.description} (+usage)`;
2465
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2466
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2434
2467
  },
2435
2468
  checkConfiguration() {
2436
2469
  return /* not await */ llmTools.checkConfiguration();
@@ -2501,29 +2534,40 @@
2501
2534
  return 'Multiple LLM Providers';
2502
2535
  }
2503
2536
  get description() {
2504
- return this.llmExecutionTools.map(({ title }, index) => `${index + 1}) \`${title}\``).join('\n');
2537
+ const innerModelsTitlesAndDescriptions = this.llmExecutionTools
2538
+ .map(({ title, description }, index) => {
2539
+ const headLine = `${index + 1}) \`${title}\``;
2540
+ if (description === undefined) {
2541
+ return headLine;
2542
+ }
2543
+ return spaceTrim__default["default"]((block) => `
2544
+ ${headLine}
2545
+
2546
+ ${ /* <- Note: Indenting the description: */block(description)}
2547
+ `);
2548
+ })
2549
+ .join('\n\n');
2550
+ return spaceTrim__default["default"]((block) => `
2551
+ Multiple LLM Providers:
2552
+
2553
+ ${block(innerModelsTitlesAndDescriptions)}
2554
+ `);
2505
2555
  }
2506
2556
  /**
2507
2557
  * Check the configuration of all execution tools
2508
2558
  */
2509
2559
  async checkConfiguration() {
2510
- // TODO: Maybe do it in parallel
2511
- for (const llmExecutionTools of this.llmExecutionTools) {
2512
- await llmExecutionTools.checkConfiguration();
2513
- }
2560
+ // Note: Run checks in parallel
2561
+ await Promise.all(this.llmExecutionTools.map((tools) => tools.checkConfiguration()));
2514
2562
  }
2515
2563
  /**
2516
2564
  * List all available models that can be used
2517
2565
  * This lists is a combination of all available models from all execution tools
2518
2566
  */
2519
2567
  async listModels() {
2520
- const availableModels = [];
2521
- for (const llmExecutionTools of this.llmExecutionTools) {
2522
- // TODO: [🪂] Obtain models in parallel
2523
- const models = await llmExecutionTools.listModels();
2524
- availableModels.push(...models);
2525
- }
2526
- return availableModels;
2568
+ // Obtain all models in parallel and flatten
2569
+ const modelArrays = await Promise.all(this.llmExecutionTools.map((tools) => tools.listModels()));
2570
+ return modelArrays.flat();
2527
2571
  }
2528
2572
  /**
2529
2573
  * Calls the best available chat model
@@ -2764,7 +2808,8 @@
2764
2808
  */
2765
2809
 
2766
2810
  /**
2767
- * @@@
2811
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
2812
+ * regardless of the JavaScript environment in which the code is running
2768
2813
  *
2769
2814
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2770
2815
  *
@@ -2775,10 +2820,10 @@
2775
2820
  }
2776
2821
 
2777
2822
  /**
2778
- * @@@
2823
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2779
2824
  *
2780
- * @param text @@@
2781
- * @returns @@@
2825
+ * @param text The text string to be converted to SCREAMING_CASE format.
2826
+ * @returns The normalized text in SCREAMING_CASE format.
2782
2827
  * @example 'HELLO_WORLD'
2783
2828
  * @example 'I_LOVE_PROMPTBOOK'
2784
2829
  * @public exported from `@promptbook/utils`
@@ -2830,10 +2875,10 @@
2830
2875
  */
2831
2876
 
2832
2877
  /**
2833
- * @@@
2878
+ * Normalizes a text string to snake_case format.
2834
2879
  *
2835
- * @param text @@@
2836
- * @returns @@@
2880
+ * @param text The text string to be converted to snake_case format.
2881
+ * @returns The normalized text in snake_case format.
2837
2882
  * @example 'hello_world'
2838
2883
  * @example 'i_love_promptbook'
2839
2884
  * @public exported from `@promptbook/utils`
@@ -2843,11 +2888,11 @@
2843
2888
  }
2844
2889
 
2845
2890
  /**
2846
- * Register is @@@
2891
+ * Global registry for storing and managing registered entities of a given type.
2847
2892
  *
2848
2893
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2849
2894
  *
2850
- * @private internal utility, exported are only signleton instances of this class
2895
+ * @private internal utility, exported are only singleton instances of this class
2851
2896
  */
2852
2897
  class $Register {
2853
2898
  constructor(registerName) {
@@ -2891,10 +2936,10 @@
2891
2936
  }
2892
2937
 
2893
2938
  /**
2894
- * @@@
2939
+ * Global registry for storing metadata about all available scrapers and converters.
2895
2940
  *
2896
- * Note: `$` is used to indicate that this interacts with the global scope
2897
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2941
+ * Note: `$` is used to indicate that this interacts with the global scope.
2942
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
2898
2943
  * @public exported from `@promptbook/core`
2899
2944
  */
2900
2945
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -2903,10 +2948,11 @@
2903
2948
  */
2904
2949
 
2905
2950
  /**
2906
- * @@@
2951
+ * Registry for all available scrapers in the system.
2952
+ * Central point for registering and accessing different types of content scrapers.
2907
2953
  *
2908
2954
  * Note: `$` is used to indicate that this interacts with the global scope
2909
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2955
+ * @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
2910
2956
  * @public exported from `@promptbook/core`
2911
2957
  */
2912
2958
  const $scrapersRegister = new $Register('scraper_constructors');
@@ -3246,10 +3292,10 @@
3246
3292
  */
3247
3293
 
3248
3294
  /**
3249
- * @@@
3295
+ * Removes diacritic marks (accents) from characters in a string.
3250
3296
  *
3251
- * @param input @@@
3252
- * @returns @@@
3297
+ * @param input The string containing diacritics to be normalized.
3298
+ * @returns The string with diacritics removed or normalized.
3253
3299
  * @public exported from `@promptbook/utils`
3254
3300
  */
3255
3301
  function removeDiacritics(input) {
@@ -3263,10 +3309,10 @@
3263
3309
  */
3264
3310
 
3265
3311
  /**
3266
- * @@@
3312
+ * Converts a given text to kebab-case format.
3267
3313
  *
3268
- * @param text @@@
3269
- * @returns @@@
3314
+ * @param text The text to be converted.
3315
+ * @returns The kebab-case formatted string.
3270
3316
  * @example 'hello-world'
3271
3317
  * @example 'i-love-promptbook'
3272
3318
  * @public exported from `@promptbook/utils`
@@ -3335,7 +3381,8 @@
3335
3381
  */
3336
3382
 
3337
3383
  /**
3338
- * @@@
3384
+ * Converts a name to a properly formatted subfolder path for cache storage.
3385
+ * Handles normalization and path formatting to create consistent cache directory structures.
3339
3386
  *
3340
3387
  * @private for `FileCacheStorage`
3341
3388
  */
@@ -3415,11 +3462,11 @@
3415
3462
  }
3416
3463
 
3417
3464
  /**
3418
- * @@@
3465
+ * Converts a title string into a normalized name.
3419
3466
  *
3420
- * @param value @@@
3421
- * @returns @@@
3422
- * @example @@@
3467
+ * @param value The title string to be converted to a name.
3468
+ * @returns A normalized name derived from the input title.
3469
+ * @example 'Hello World!' -> 'hello-world'
3423
3470
  * @public exported from `@promptbook/utils`
3424
3471
  */
3425
3472
  function titleToName(value) {
@@ -3470,7 +3517,9 @@
3470
3517
  */
3471
3518
 
3472
3519
  /**
3473
- * @@@
3520
+ * Factory function that creates a handler for processing knowledge sources.
3521
+ * Provides standardized processing of different types of knowledge sources
3522
+ * across various scraper implementations.
3474
3523
  *
3475
3524
  * @public exported from `@promptbook/core`
3476
3525
  */
@@ -3609,7 +3658,7 @@
3609
3658
  }
3610
3659
 
3611
3660
  /**
3612
- * Prepares the knowle
3661
+ * Prepares the knowledge pieces
3613
3662
  *
3614
3663
  * @see https://github.com/webgptorg/promptbook/discussions/41
3615
3664
  * @public exported from `@promptbook/core`
@@ -3705,15 +3754,18 @@
3705
3754
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3706
3755
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3707
3756
  * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3708
- * TODO: [🧠][❎] Do here propper M:N mapping
3757
+ * TODO: [🧠][❎] Do here proper M:N mapping
3709
3758
  * [x] One source can make multiple pieces
3710
3759
  * [ ] One piece can have multiple sources
3711
3760
  */
3712
3761
 
3713
3762
  /**
3714
- * @@@
3763
+ * Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
3715
3764
  *
3716
- * @public exported from `@promptbook/core`
3765
+ * @param tasks Sequence of tasks that are chained together to form a pipeline
3766
+ * @returns A promise that resolves to the prepared tasks.
3767
+ *
3768
+ * @private internal utility of `preparePipeline`
3717
3769
  */
3718
3770
  async function prepareTasks(pipeline, tools, options) {
3719
3771
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
@@ -3751,7 +3803,7 @@
3751
3803
  return { tasksPrepared };
3752
3804
  }
3753
3805
  /**
3754
- * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3806
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, similar thing with expectations to sync high-level abstractions
3755
3807
  * TODO: [🧠] Add context to each task (if missing)
3756
3808
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3757
3809
  * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
@@ -3887,7 +3939,7 @@
3887
3939
  order: ORDER_OF_PIPELINE_JSON,
3888
3940
  value: {
3889
3941
  ...pipeline,
3890
- // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
3942
+ // <- TODO: Probably deeply clone the pipeline because `$exportJson` freezes the subobjects
3891
3943
  title,
3892
3944
  knowledgeSources: knowledgeSourcesPrepared,
3893
3945
  knowledgePieces: knowledgePiecesPrepared,
@@ -4150,7 +4202,7 @@
4150
4202
  }
4151
4203
 
4152
4204
  /**
4153
- * @@@
4205
+ * Contains configuration options for parsing and generating CSV files, such as delimiters and quoting rules.
4154
4206
  *
4155
4207
  * @public exported from `@promptbook/core`
4156
4208
  */
@@ -4159,11 +4211,29 @@
4159
4211
  // encoding: 'utf-8',
4160
4212
  });
4161
4213
 
4214
+ /**
4215
+ * Converts a CSV string into an object
4216
+ *
4217
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
4218
+ *
4219
+ * @private - for now until `@promptbook/csv` is released
4220
+ */
4221
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
4222
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
4223
+ // Note: Autoheal invalid '\n' characters
4224
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
4225
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
4226
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
4227
+ }
4228
+ const csv = papaparse.parse(value, settings);
4229
+ return csv;
4230
+ }
4231
+
4162
4232
  /**
4163
4233
  * Function to check if a string is valid CSV
4164
4234
  *
4165
4235
  * @param value The string to check
4166
- * @returns True if the string is a valid CSV string, false otherwise
4236
+ * @returns `true` if the string is a valid CSV string, false otherwise
4167
4237
  *
4168
4238
  * @public exported from `@promptbook/utils`
4169
4239
  */
@@ -4187,7 +4257,7 @@
4187
4257
  * @public exported from `@promptbook/core`
4188
4258
  * <- TODO: [🏢] Export from package `@promptbook/csv`
4189
4259
  */
4190
- const CsvFormatDefinition = {
4260
+ const CsvFormatParser = {
4191
4261
  formatName: 'CSV',
4192
4262
  aliases: ['SPREADSHEET', 'TABLE'],
4193
4263
  isValid(value, settings, schema) {
@@ -4199,12 +4269,12 @@
4199
4269
  heal(value, settings, schema) {
4200
4270
  throw new Error('Not implemented');
4201
4271
  },
4202
- subvalueDefinitions: [
4272
+ subvalueParsers: [
4203
4273
  {
4204
4274
  subvalueName: 'ROW',
4205
- async mapValues(value, outputParameterName, settings, mapCallback) {
4206
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4207
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4275
+ async mapValues(options) {
4276
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4277
+ const csv = csvParse(value, settings);
4208
4278
  if (csv.errors.length !== 0) {
4209
4279
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4210
4280
  CSV parsing error
@@ -4219,23 +4289,37 @@
4219
4289
  ${block(value)}
4220
4290
  `));
4221
4291
  }
4222
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4292
+ const mappedData = [];
4293
+ const length = csv.data.length;
4294
+ for (let index = 0; index < length; index++) {
4295
+ const row = csv.data[index];
4223
4296
  if (row[outputParameterName]) {
4224
4297
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4225
4298
  }
4226
- return {
4299
+ const mappedRow = {
4227
4300
  ...row,
4228
- [outputParameterName]: await mapCallback(row, index),
4301
+ [outputParameterName]: await mapCallback(row, index, length),
4229
4302
  };
4230
- }));
4303
+ mappedData.push(mappedRow);
4304
+ if (onProgress) {
4305
+ // Note: Report the CSV with all rows mapped so far
4306
+ /*
4307
+ // TODO: [🛕] Report progress with all the rows including the pending ones
4308
+ const progressData = mappedData.map((row, i) =>
4309
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4310
+ );
4311
+ */
4312
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4313
+ }
4314
+ }
4231
4315
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4232
4316
  },
4233
4317
  },
4234
4318
  {
4235
4319
  subvalueName: 'CELL',
4236
- async mapValues(value, outputParameterName, settings, mapCallback) {
4237
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4238
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4320
+ async mapValues(options) {
4321
+ const { value, settings, mapCallback, onProgress } = options;
4322
+ const csv = csvParse(value, settings);
4239
4323
  if (csv.errors.length !== 0) {
4240
4324
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4241
4325
  CSV parsing error
@@ -4251,9 +4335,9 @@
4251
4335
  `));
4252
4336
  }
4253
4337
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4254
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4338
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4255
4339
  const index = rowIndex * Object.keys(row).length + columnIndex;
4256
- return /* not await */ mapCallback({ [key]: value }, index);
4340
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4257
4341
  }));
4258
4342
  }));
4259
4343
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4262,10 +4346,10 @@
4262
4346
  ],
4263
4347
  };
4264
4348
  /**
4265
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
4266
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
4267
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
4268
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
4349
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
4350
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
4351
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
4352
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
4269
4353
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4270
4354
  */
4271
4355
 
@@ -4274,7 +4358,7 @@
4274
4358
  *
4275
4359
  * @private still in development [🏢]
4276
4360
  */
4277
- const JsonFormatDefinition = {
4361
+ const JsonFormatParser = {
4278
4362
  formatName: 'JSON',
4279
4363
  mimeType: 'application/json',
4280
4364
  isValid(value, settings, schema) {
@@ -4286,28 +4370,28 @@
4286
4370
  heal(value, settings, schema) {
4287
4371
  throw new Error('Not implemented');
4288
4372
  },
4289
- subvalueDefinitions: [],
4373
+ subvalueParsers: [],
4290
4374
  };
4291
4375
  /**
4292
- * TODO: [🧠] Maybe propper instance of object
4376
+ * TODO: [🧠] Maybe proper instance of object
4293
4377
  * TODO: [0] Make string_serialized_json
4294
4378
  * TODO: [1] Make type for JSON Settings and Schema
4295
4379
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
4296
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
4297
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
4298
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
4299
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
4380
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
4381
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
4382
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
4383
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
4300
4384
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
4301
4385
  */
4302
4386
 
4303
4387
  /**
4304
4388
  * Definition for any text - this will be always valid
4305
4389
  *
4306
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
4390
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
4307
4391
  *
4308
4392
  * @public exported from `@promptbook/core`
4309
4393
  */
4310
- const TextFormatDefinition = {
4394
+ const TextFormatParser = {
4311
4395
  formatName: 'TEXT',
4312
4396
  isValid(value) {
4313
4397
  return typeof value === 'string';
@@ -4316,19 +4400,20 @@
4316
4400
  return typeof partialValue === 'string';
4317
4401
  },
4318
4402
  heal() {
4319
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
4403
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
4320
4404
  },
4321
- subvalueDefinitions: [
4405
+ subvalueParsers: [
4322
4406
  {
4323
4407
  subvalueName: 'LINE',
4324
- async mapValues(value, outputParameterName, settings, mapCallback) {
4408
+ async mapValues(options) {
4409
+ const { value, mapCallback, onProgress } = options;
4325
4410
  const lines = value.split('\n');
4326
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4411
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4327
4412
  // TODO: [🧠] Maybe option to skip empty line
4328
4413
  /* not await */ mapCallback({
4329
4414
  lineContent,
4330
4415
  // TODO: [🧠] Maybe also put here `lineNumber`
4331
- }, lineNumber)));
4416
+ }, lineNumber, array.length)));
4332
4417
  return mappedLines.join('\n');
4333
4418
  },
4334
4419
  },
@@ -4338,10 +4423,10 @@
4338
4423
  /**
4339
4424
  * TODO: [1] Make type for XML Text and Schema
4340
4425
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
4341
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
4342
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
4343
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
4344
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
4426
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
4427
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
4428
+ * TODO: [🍓] In `TextFormatParser` implement `heal
4429
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
4345
4430
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
4346
4431
  */
4347
4432
 
@@ -4349,7 +4434,7 @@
4349
4434
  * Function to check if a string is valid XML
4350
4435
  *
4351
4436
  * @param value
4352
- * @returns True if the string is a valid XML string, false otherwise
4437
+ * @returns `true` if the string is a valid XML string, false otherwise
4353
4438
  *
4354
4439
  * @public exported from `@promptbook/utils`
4355
4440
  */
@@ -4374,7 +4459,7 @@
4374
4459
  *
4375
4460
  * @private still in development [🏢]
4376
4461
  */
4377
- const XmlFormatDefinition = {
4462
+ const XmlFormatParser = {
4378
4463
  formatName: 'XML',
4379
4464
  mimeType: 'application/xml',
4380
4465
  isValid(value, settings, schema) {
@@ -4386,17 +4471,17 @@
4386
4471
  heal(value, settings, schema) {
4387
4472
  throw new Error('Not implemented');
4388
4473
  },
4389
- subvalueDefinitions: [],
4474
+ subvalueParsers: [],
4390
4475
  };
4391
4476
  /**
4392
- * TODO: [🧠] Maybe propper instance of object
4477
+ * TODO: [🧠] Maybe proper instance of object
4393
4478
  * TODO: [0] Make string_serialized_xml
4394
4479
  * TODO: [1] Make type for XML Settings and Schema
4395
4480
  * TODO: [🧠] What to use for validating XMLs - XSD,...
4396
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
4397
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
4398
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
4399
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
4481
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
4482
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
4483
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
4484
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
4400
4485
  * TODO: [🏢] Allow to expect something inside XML and other formats
4401
4486
  */
4402
4487
 
@@ -4405,24 +4490,19 @@
4405
4490
  *
4406
4491
  * @private internal index of `...` <- TODO [🏢]
4407
4492
  */
4408
- const FORMAT_DEFINITIONS = [
4409
- JsonFormatDefinition,
4410
- XmlFormatDefinition,
4411
- TextFormatDefinition,
4412
- CsvFormatDefinition,
4413
- ];
4493
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
4414
4494
  /**
4415
4495
  * Note: [💞] Ignore a discrepancy between file name and entity name
4416
4496
  */
4417
4497
 
4418
4498
  /**
4419
- * Maps available parameters to expected parameters
4499
+ * Maps available parameters to expected parameters for a pipeline task.
4420
4500
  *
4421
4501
  * The strategy is:
4422
- * 1) @@@
4423
- * 2) @@@
4502
+ * 1) First, match parameters by name where both available and expected.
4503
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4424
4504
  *
4425
- * @throws {PipelineExecutionError} @@@
4505
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4426
4506
  * @private within the repository used in `createPipelineExecutor`
4427
4507
  */
4428
4508
  function mapAvailableToExpectedParameters(options) {
@@ -4445,7 +4525,7 @@
4445
4525
  else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
4446
4526
  }
4447
4527
  if (expectedParameterNames.size === 0) {
4448
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4528
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4449
4529
  Object.freeze(mappedParameters);
4450
4530
  return mappedParameters;
4451
4531
  }
@@ -4476,7 +4556,7 @@
4476
4556
  for (let i = 0; i < expectedParameterNames.size; i++) {
4477
4557
  mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
4478
4558
  }
4479
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4559
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4480
4560
  Object.freeze(mappedParameters);
4481
4561
  return mappedParameters;
4482
4562
  }
@@ -4680,14 +4760,14 @@
4680
4760
  PAGES: countPages,
4681
4761
  };
4682
4762
  /**
4683
- * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
4763
+ * TODO: [🧠][🤠] This should be probably as part of `TextFormatParser`
4684
4764
  * Note: [💞] Ignore a discrepancy between file name and entity name
4685
4765
  */
4686
4766
 
4687
4767
  /**
4688
4768
  * Function checkExpectations will check if the expectations on given value are met
4689
4769
  *
4690
- * Note: There are two simmilar functions:
4770
+ * Note: There are two similar functions:
4691
4771
  * - `checkExpectations` which throws an error if the expectations are not met
4692
4772
  * - `isPassingExpectations` which returns a boolean
4693
4773
  *
@@ -4708,13 +4788,17 @@
4708
4788
  }
4709
4789
  /**
4710
4790
  * TODO: [💝] Unite object for expecting amount and format
4711
- * TODO: [🧠][🤠] This should be part of `TextFormatDefinition`
4791
+ * TODO: [🧠][🤠] This should be part of `TextFormatParser`
4712
4792
  * Note: [💝] and [🤠] are interconnected together
4713
4793
  */
4714
4794
 
4715
4795
  /**
4716
- * @@@
4796
+ * Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
4797
+ * (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
4798
+ * Throws errors if execution fails after all attempts.
4717
4799
  *
4800
+ * @param options - The options for execution, including task, parameters, pipeline, and configuration.
4801
+ * @returns The result string of the executed task.
4718
4802
  * @private internal utility of `createPipelineExecutor`
4719
4803
  */
4720
4804
  async function executeAttempts(options) {
@@ -4936,7 +5020,7 @@
4936
5020
  if (task.format) {
4937
5021
  if (task.format === 'JSON') {
4938
5022
  if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
4939
- // TODO: [🏢] Do more universally via `FormatDefinition`
5023
+ // TODO: [🏢] Do more universally via `FormatParser`
4940
5024
  try {
4941
5025
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
4942
5026
  }
@@ -5038,12 +5122,16 @@
5038
5122
  */
5039
5123
 
5040
5124
  /**
5041
- * @@@
5125
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5126
+ * Handles format and subformat resolution, error handling, and progress reporting.
5127
+ *
5128
+ * @param options - Options for execution, including task details and progress callback.
5129
+ * @returns The result of the subvalue mapping or execution attempts.
5042
5130
  *
5043
5131
  * @private internal utility of `createPipelineExecutor`
5044
5132
  */
5045
5133
  async function executeFormatSubvalues(options) {
5046
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5134
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5047
5135
  if (task.foreach === undefined) {
5048
5136
  return /* not await */ executeAttempts(options);
5049
5137
  }
@@ -5074,16 +5162,16 @@
5074
5162
  ${block(pipelineIdentification)}
5075
5163
  `));
5076
5164
  }
5077
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(task.foreach.subformatName));
5078
- if (subvalueDefinition === undefined) {
5165
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
5166
+ if (subvalueParser === undefined) {
5079
5167
  throw new UnexpectedError(
5080
5168
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5081
5169
  spaceTrim__default["default"]((block) => `
5082
5170
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
5083
5171
 
5084
5172
  Available subformat names for format "${formatDefinition.formatName}":
5085
- ${block(formatDefinition.subvalueDefinitions
5086
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
5173
+ ${block(formatDefinition.subvalueParsers
5174
+ .map((subvalueParser) => subvalueParser.subvalueName)
5087
5175
  .map((subvalueName) => `- ${subvalueName}`)
5088
5176
  .join('\n'))}
5089
5177
 
@@ -5095,55 +5183,85 @@
5095
5183
  let formatSettings;
5096
5184
  if (formatDefinition.formatName === 'CSV') {
5097
5185
  formatSettings = csvSettings;
5098
- // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5099
- }
5100
- const resultString = await subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5101
- let mappedParameters;
5102
- // TODO: [🤹‍♂️][🪂] Limit to N concurrent executions
5103
- // TODO: When done [🐚] Report progress also for each subvalue here
5104
- try {
5105
- mappedParameters = mapAvailableToExpectedParameters({
5106
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5107
- availableParameters: subparameters,
5108
- });
5109
- }
5110
- catch (error) {
5111
- if (!(error instanceof PipelineExecutionError)) {
5112
- throw error;
5186
+ // <- TODO: [🤹‍♂️] More universal, make similar pattern for other formats for example \n vs \r\n in text
5187
+ }
5188
+ const resultString = await subvalueParser.mapValues({
5189
+ value: parameterValue,
5190
+ outputParameterName: task.foreach.outputSubparameterName,
5191
+ settings: formatSettings,
5192
+ onProgress(partialResultString) {
5193
+ return onProgress(Object.freeze({
5194
+ [task.resultingParameterName]: partialResultString,
5195
+ }));
5196
+ },
5197
+ async mapCallback(subparameters, index, length) {
5198
+ let mappedParameters;
5199
+ try {
5200
+ mappedParameters = mapAvailableToExpectedParameters({
5201
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5202
+ availableParameters: subparameters,
5203
+ });
5113
5204
  }
5114
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5115
- ${error.message}
5205
+ catch (error) {
5206
+ if (!(error instanceof PipelineExecutionError)) {
5207
+ throw error;
5208
+ }
5209
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5210
+ ${error.message}
5116
5211
 
5117
- This is error in FOREACH command
5118
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5212
+ This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5213
+ You have probably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5119
5214
 
5120
- ${block(pipelineIdentification)}
5121
- Subparameter index: ${index}
5122
- `));
5123
- }
5124
- const allSubparameters = {
5125
- ...parameters,
5126
- ...mappedParameters,
5127
- };
5128
- // Note: [👨‍👨‍👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
5129
- Object.freeze(allSubparameters);
5130
- const subresultString = await executeAttempts({
5131
- ...options,
5132
- priority: priority + index,
5133
- parameters: allSubparameters,
5134
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5135
- ${block(pipelineIdentification)}
5136
- Subparameter index: ${index}
5137
- `),
5138
- });
5139
- return subresultString;
5215
+ ${block(pipelineIdentification)}
5216
+ `));
5217
+ if (length > BIG_DATASET_TRESHOLD) {
5218
+ console.error(highLevelError);
5219
+ return FAILED_VALUE_PLACEHOLDER;
5220
+ }
5221
+ throw highLevelError;
5222
+ }
5223
+ const allSubparameters = {
5224
+ ...parameters,
5225
+ ...mappedParameters,
5226
+ };
5227
+ Object.freeze(allSubparameters);
5228
+ try {
5229
+ const subresultString = await executeAttempts({
5230
+ ...options,
5231
+ priority: priority + index,
5232
+ parameters: allSubparameters,
5233
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5234
+ ${block(pipelineIdentification)}
5235
+ Subparameter index: ${index}
5236
+ `),
5237
+ });
5238
+ return subresultString;
5239
+ }
5240
+ catch (error) {
5241
+ if (length > BIG_DATASET_TRESHOLD) {
5242
+ console.error(spaceTrim__default["default"]((block) => `
5243
+ ${error.message}
5244
+
5245
+ This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5246
+
5247
+ ${block(pipelineIdentification)}
5248
+ `));
5249
+ return FAILED_VALUE_PLACEHOLDER;
5250
+ }
5251
+ throw error;
5252
+ }
5253
+ },
5140
5254
  });
5141
5255
  return resultString;
5142
5256
  }
5143
5257
 
5144
5258
  /**
5145
- * @@@
5259
+ * Returns the context for a given task, typically used to provide additional information or variables
5260
+ * required for the execution of the task within a pipeline. The context is returned as a string value
5261
+ * that may include markdown formatting.
5146
5262
  *
5263
+ * @param task - The task for which the context is being generated. This should be a deeply immutable TaskJson object.
5264
+ * @returns The context as a string, formatted as markdown and parameter value.
5147
5265
  * @private internal utility of `createPipelineExecutor`
5148
5266
  */
5149
5267
  async function getContextForTask(task) {
@@ -5151,7 +5269,7 @@
5151
5269
  }
5152
5270
 
5153
5271
  /**
5154
- * @@@
5272
+ * Retrieves example values or templates for a given task, used to guide or validate pipeline execution.
5155
5273
  *
5156
5274
  * @private internal utility of `createPipelineExecutor`
5157
5275
  */
@@ -5160,91 +5278,128 @@
5160
5278
  }
5161
5279
 
5162
5280
  /**
5163
- * @@@
5281
+ * Computes the cosine similarity between two embedding vectors
5282
+ *
5283
+ * Note: This is helping function for RAG (retrieval-augmented generation)
5164
5284
  *
5165
- * Here is the place where RAG (retrieval-augmented generation) happens
5285
+ * @param embeddingVector1
5286
+ * @param embeddingVector2
5287
+ * @returns Cosine similarity between the two vectors
5288
+ *
5289
+ * @public exported from `@promptbook/core`
5290
+ */
5291
+ function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5292
+ if (embeddingVector1.length !== embeddingVector2.length) {
5293
+ throw new TypeError('Embedding vectors must have the same length');
5294
+ }
5295
+ const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5296
+ const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5297
+ const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5298
+ return 1 - dotProduct / (magnitude1 * magnitude2);
5299
+ }
5300
+
5301
+ /**
5302
+ *
5303
+ * @param knowledgePieces
5304
+ * @returns
5305
+ *
5306
+ * @private internal utility of `createPipelineExecutor`
5307
+ */
5308
+ function knowledgePiecesToString(knowledgePieces) {
5309
+ return knowledgePieces
5310
+ .map((knowledgePiece) => {
5311
+ const { content } = knowledgePiece;
5312
+ return `- ${content}`;
5313
+ })
5314
+ .join('\n');
5315
+ // <- TODO: [🧠] Some smarter aggregation of knowledge pieces, single-line vs multi-line vs mixed
5316
+ }
5317
+
5318
+ /**
5319
+ * Retrieves the most relevant knowledge pieces for a given task using embedding-based similarity search.
5320
+ * This is where retrieval-augmented generation (RAG) is performed to enhance the task with external knowledge.
5166
5321
  *
5167
5322
  * @private internal utility of `createPipelineExecutor`
5168
5323
  */
5169
5324
  async function getKnowledgeForTask(options) {
5170
- const { tools, preparedPipeline, task } = options;
5325
+ const { tools, preparedPipeline, task, parameters } = options;
5171
5326
  const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5172
5327
  const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5173
5328
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5174
5329
  if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5175
- return 'No knowledge pieces found';
5330
+ return ''; // <- Note: Np knowledge present, return empty string
5176
5331
  }
5177
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5178
- const _llms = arrayableToArray(tools.llm);
5179
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5180
- const taskEmbeddingPrompt = {
5181
- title: 'Knowledge Search',
5182
- modelRequirements: {
5183
- modelVariant: 'EMBEDDING',
5184
- modelName: firstKnowlegeIndex.modelName,
5185
- },
5186
- content: task.content,
5187
- parameters: {
5188
- /* !!!!!!!! */
5189
- },
5190
- };
5191
- const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5192
- const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5193
- const { index } = knowledgePiece;
5194
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5195
- // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5196
- if (knowledgePieceIndex === undefined) {
5332
+ try {
5333
+ // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5334
+ const _llms = arrayableToArray(tools.llm);
5335
+ const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5336
+ const taskEmbeddingPrompt = {
5337
+ title: 'Knowledge Search',
5338
+ modelRequirements: {
5339
+ modelVariant: 'EMBEDDING',
5340
+ modelName: firstKnowlegeIndex.modelName,
5341
+ },
5342
+ content: task.content,
5343
+ parameters,
5344
+ };
5345
+ const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5346
+ const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5347
+ const { index } = knowledgePiece;
5348
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5349
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5350
+ if (knowledgePieceIndex === undefined) {
5351
+ return {
5352
+ content: knowledgePiece.content,
5353
+ relevance: 0,
5354
+ };
5355
+ }
5356
+ const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5197
5357
  return {
5198
5358
  content: knowledgePiece.content,
5199
- relevance: 0,
5359
+ relevance,
5200
5360
  };
5201
- }
5202
- const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5203
- return {
5204
- content: knowledgePiece.content,
5205
- relevance,
5206
- };
5207
- });
5208
- const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5209
- const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5210
- console.log('!!! Embedding', {
5211
- task,
5212
- taskEmbeddingPrompt,
5213
- taskEmbeddingResult,
5214
- firstKnowlegePiece,
5215
- firstKnowlegeIndex,
5216
- knowledgePiecesWithRelevance,
5217
- knowledgePiecesSorted,
5218
- knowledgePiecesLimited,
5219
- });
5220
- return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
5221
- // <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
5222
- }
5223
- // TODO: !!!!!! Annotate + to new file
5224
- function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5225
- if (embeddingVector1.length !== embeddingVector2.length) {
5226
- throw new TypeError('Embedding vectors must have the same length');
5361
+ });
5362
+ const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5363
+ const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5364
+ /*
5365
+ console.log('`getKnowledgeForTask` Embedding', {
5366
+ task,
5367
+ taskEmbeddingPrompt,
5368
+ taskEmbeddingResult,
5369
+ firstKnowlegePiece,
5370
+ firstKnowlegeIndex,
5371
+ knowledgePiecesWithRelevance,
5372
+ knowledgePiecesSorted,
5373
+ knowledgePiecesLimited,
5374
+ });
5375
+ */
5376
+ return knowledgePiecesToString(knowledgePiecesLimited);
5377
+ }
5378
+ catch (error) {
5379
+ assertsError(error);
5380
+ console.error('Error in `getKnowledgeForTask`', error);
5381
+ // Note: If the LLM fails, just return all knowledge pieces
5382
+ return knowledgePiecesToString(preparedPipeline.knowledgePieces);
5227
5383
  }
5228
- const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5229
- const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5230
- const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5231
- return 1 - dotProduct / (magnitude1 * magnitude2);
5232
5384
  }
5233
5385
  /**
5234
- * TODO: !!!! Verify if this is working
5235
5386
  * TODO: [♨] Implement Better - use keyword search
5236
5387
  * TODO: [♨] Examples of values
5237
5388
  */
5238
5389
 
5239
5390
  /**
5240
- * @@@
5391
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5392
+ * Ensures all reserved parameters are defined and throws if any are missing.
5393
+ *
5394
+ * @param options - Options including tools, pipeline, task, and context.
5395
+ * @returns An object containing all reserved parameters for the task.
5241
5396
  *
5242
5397
  * @private internal utility of `createPipelineExecutor`
5243
5398
  */
5244
5399
  async function getReservedParametersForTask(options) {
5245
- const { tools, preparedPipeline, task, pipelineIdentification } = options;
5400
+ const { tools, preparedPipeline, task, parameters, pipelineIdentification, isVerbose } = options;
5246
5401
  const context = await getContextForTask(); // <- [🏍]
5247
- const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
5402
+ const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task, parameters });
5248
5403
  const examples = await getExamplesForTask();
5249
5404
  const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
5250
5405
  const modelName = RESERVED_PARAMETER_MISSING_VALUE;
@@ -5256,6 +5411,9 @@
5256
5411
  currentDate,
5257
5412
  modelName,
5258
5413
  };
5414
+ if (isVerbose) {
5415
+ console.info('Reserved parameters for task:', { options, reservedParameters });
5416
+ }
5259
5417
  // Note: Doublecheck that ALL reserved parameters are defined:
5260
5418
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
5261
5419
  if (reservedParameters[parameterName] === undefined) {
@@ -5270,23 +5428,21 @@
5270
5428
  }
5271
5429
 
5272
5430
  /**
5273
- * @@@
5431
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5432
+ *
5433
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5434
+ * @returns The output parameters produced by the task.
5274
5435
  *
5275
5436
  * @private internal utility of `createPipelineExecutor`
5276
5437
  */
5277
5438
  async function executeTask(options) {
5278
5439
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5279
5440
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5280
- await onProgress({
5281
- outputParameters: {
5282
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5283
- },
5284
- });
5285
5441
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5286
5442
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5287
5443
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
5288
5444
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5289
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
5445
+ if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
5290
5446
  throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5291
5447
  Dependent parameters are not consistent with used parameters:
5292
5448
 
@@ -5304,13 +5460,16 @@
5304
5460
 
5305
5461
  `));
5306
5462
  }
5463
+ const reservedParameters = await getReservedParametersForTask({
5464
+ tools,
5465
+ preparedPipeline,
5466
+ task: currentTask,
5467
+ pipelineIdentification,
5468
+ parameters: parametersToPass,
5469
+ isVerbose,
5470
+ });
5307
5471
  const definedParameters = Object.freeze({
5308
- ...(await getReservedParametersForTask({
5309
- tools,
5310
- preparedPipeline,
5311
- task: currentTask,
5312
- pipelineIdentification,
5313
- })),
5472
+ ...reservedParameters,
5314
5473
  ...parametersToPass,
5315
5474
  });
5316
5475
  const definedParameterNames = new Set(Object.keys(definedParameters));
@@ -5355,6 +5514,7 @@
5355
5514
  preparedPipeline,
5356
5515
  tools,
5357
5516
  $executionReport,
5517
+ onProgress,
5358
5518
  pipelineIdentification,
5359
5519
  maxExecutionAttempts,
5360
5520
  maxParallelCount,
@@ -5382,7 +5542,8 @@
5382
5542
  */
5383
5543
 
5384
5544
  /**
5385
- * @@@
5545
+ * Filters and returns only the output parameters from the provided pipeline execution options.
5546
+ * Adds warnings for any expected output parameters that are missing.
5386
5547
  *
5387
5548
  * @private internal utility of `createPipelineExecutor`
5388
5549
  */
@@ -5407,9 +5568,12 @@
5407
5568
  }
5408
5569
 
5409
5570
  /**
5410
- * @@@
5571
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5411
5572
  *
5412
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5573
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5574
+ *
5575
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5576
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5413
5577
  *
5414
5578
  * @private internal utility of `createPipelineExecutor`
5415
5579
  */
@@ -5732,10 +5896,27 @@
5732
5896
  cacheDirname,
5733
5897
  intermediateFilesStrategy,
5734
5898
  isAutoInstalled,
5899
+ }).catch((error) => {
5900
+ assertsError(error);
5901
+ return exportJson({
5902
+ name: 'pipelineExecutorResult',
5903
+ message: `Unuccessful PipelineExecutorResult, last catch`,
5904
+ order: [],
5905
+ value: {
5906
+ isSuccessful: false,
5907
+ errors: [serializeError(error)],
5908
+ warnings: [],
5909
+ usage: UNCERTAIN_USAGE,
5910
+ executionReport: null,
5911
+ outputParameters: {},
5912
+ preparedPipeline,
5913
+ },
5914
+ });
5735
5915
  });
5736
5916
  };
5737
5917
  const pipelineExecutor = (inputParameters) => createTask({
5738
5918
  taskType: 'EXECUTION',
5919
+ title: pipeline.title,
5739
5920
  taskProcessCallback(updateOngoingResult) {
5740
5921
  return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5741
5922
  updateOngoingResult(newOngoingResult);
@@ -5838,7 +6019,7 @@
5838
6019
  const knowledge = await Promise.all(
5839
6020
  // TODO: [🪂] Do not send all at once but in chunks
5840
6021
  knowledgeTextPieces.map(async (knowledgeTextPiece, i) => {
5841
- // Note: Theese are just default values, they will be overwritten by the actual values:
6022
+ // Note: These are just default values, they will be overwritten by the actual values:
5842
6023
  let name = `piece-${i}`;
5843
6024
  let title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
5844
6025
  const knowledgePieceContent = spaceTrim__default["default"](knowledgeTextPiece);
@@ -5913,7 +6094,7 @@
5913
6094
  */
5914
6095
 
5915
6096
  /**
5916
- * @@@
6097
+ * Creates a scraper for markdown content.
5917
6098
  *
5918
6099
  * @public exported from `@promptbook/markdown-utils`
5919
6100
  */
@@ -6068,7 +6249,7 @@
6068
6249
  * Note: It can not work with html syntax and comments
6069
6250
  *
6070
6251
  * @param markdown any valid markdown
6071
- * @returns @@@
6252
+ * @returns An array of strings, each representing an individual list item found in the markdown
6072
6253
  * @public exported from `@promptbook/markdown-utils`
6073
6254
  */
6074
6255
  function extractAllListItemsFromMarkdown(markdown) {