@promptbook/legacy-documents 0.92.0-9 → 0.93.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 +140 -88
  2. package/esm/index.es.js +584 -403
  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 +15 -3
  198. package/umd/index.umd.js +584 -403
  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
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.93.0';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -36,7 +36,7 @@
36
36
  * Just says that the variable is not used but should be kept
37
37
  * No side effects.
38
38
  *
39
- * Note: It can be usefull for:
39
+ * Note: It can be useful for:
40
40
  *
41
41
  * 1) Suppressing eager optimization of unused imports
42
42
  * 2) Suppressing eslint errors of unused variables in the tests
@@ -53,7 +53,7 @@
53
53
  * Returns the same value that is passed as argument.
54
54
  * No side effects.
55
55
  *
56
- * Note: It can be usefull for:
56
+ * Note: It can be useful for:
57
57
  *
58
58
  * 1) Leveling indentation
59
59
  * 2) Putting always-true or always-false conditions without getting eslint errors
@@ -102,6 +102,21 @@
102
102
  * @public exported from `@promptbook/core`
103
103
  */
104
104
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
105
+ /**
106
+ * Threshold value that determines when a dataset is considered "big"
107
+ * and may require special handling or optimizations
108
+ *
109
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
110
+ *
111
+ * @public exported from `@promptbook/core`
112
+ */
113
+ const BIG_DATASET_TRESHOLD = 50;
114
+ /**
115
+ * Placeholder text used to represent a placeholder value of failed operation
116
+ *
117
+ * @public exported from `@promptbook/core`
118
+ */
119
+ const FAILED_VALUE_PLACEHOLDER = '!?';
105
120
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
106
121
  /**
107
122
  * The maximum number of iterations for a loops
@@ -181,7 +196,7 @@
181
196
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
182
197
  // <- TODO: [🧜‍♂️]
183
198
  /**
184
- * @@@
199
+ * Default settings for parsing and generating CSV files in Promptbook.
185
200
  *
186
201
  * @public exported from `@promptbook/core`
187
202
  */
@@ -192,19 +207,19 @@
192
207
  skipEmptyLines: true,
193
208
  });
194
209
  /**
195
- * @@@
210
+ * Controls whether verbose logging is enabled by default throughout the application.
196
211
  *
197
212
  * @public exported from `@promptbook/core`
198
213
  */
199
214
  let DEFAULT_IS_VERBOSE = false;
200
215
  /**
201
- * @@@
216
+ * Controls whether auto-installation of dependencies is enabled by default.
202
217
  *
203
218
  * @public exported from `@promptbook/core`
204
219
  */
205
220
  const DEFAULT_IS_AUTO_INSTALLED = false;
206
221
  /**
207
- * @@@
222
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
208
223
  *
209
224
  * @private within the repository
210
225
  */
@@ -253,7 +268,7 @@
253
268
  super(spaceTrim.spaceTrim((block) => `
254
269
  ${block(message)}
255
270
 
256
- Note: You have probbably forgot to provide some tools for pipeline execution or preparation
271
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
257
272
 
258
273
  `));
259
274
  this.name = 'MissingToolsError';
@@ -316,7 +331,7 @@
316
331
  ${block(message)}
317
332
 
318
333
  Note: This error should not happen.
319
- It's probbably a bug in the pipeline collection
334
+ It's probably a bug in the pipeline collection
320
335
 
321
336
  Please report issue:
322
337
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -545,7 +560,8 @@
545
560
  */
546
561
 
547
562
  /**
548
- * @@@
563
+ * Converts a name to a properly formatted subfolder path for cache storage.
564
+ * Handles normalization and path formatting to create consistent cache directory structures.
549
565
  *
550
566
  * @private for `FileCacheStorage`
551
567
  */
@@ -798,10 +814,10 @@
798
814
  */
799
815
 
800
816
  /**
801
- * @@@
817
+ * Removes diacritic marks (accents) from characters in a string.
802
818
  *
803
- * @param input @@@
804
- * @returns @@@
819
+ * @param input The string containing diacritics to be normalized.
820
+ * @returns The string with diacritics removed or normalized.
805
821
  * @public exported from `@promptbook/utils`
806
822
  */
807
823
  function removeDiacritics(input) {
@@ -815,10 +831,10 @@
815
831
  */
816
832
 
817
833
  /**
818
- * @@@
834
+ * Converts a given text to kebab-case format.
819
835
  *
820
- * @param text @@@
821
- * @returns @@@
836
+ * @param text The text to be converted.
837
+ * @returns The kebab-case formatted string.
822
838
  * @example 'hello-world'
823
839
  * @example 'i-love-promptbook'
824
840
  * @public exported from `@promptbook/utils`
@@ -934,7 +950,7 @@
934
950
  * Tests if given string is valid URL.
935
951
  *
936
952
  * Note: Dataurl are considered perfectly valid.
937
- * Note: There are two simmilar functions:
953
+ * Note: There are two similar functions:
938
954
  * - `isValidUrl` which tests any URL
939
955
  * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
940
956
  *
@@ -960,11 +976,11 @@
960
976
  }
961
977
 
962
978
  /**
963
- * @@@
979
+ * Converts a title string into a normalized name.
964
980
  *
965
- * @param value @@@
966
- * @returns @@@
967
- * @example @@@
981
+ * @param value The title string to be converted to a name.
982
+ * @returns A normalized name derived from the input title.
983
+ * @example 'Hello World!' -> 'hello-world'
968
984
  * @public exported from `@promptbook/utils`
969
985
  */
970
986
  function titleToName(value) {
@@ -984,9 +1000,8 @@
984
1000
  }
985
1001
 
986
1002
  /**
987
- * Create a filename for intermediate cache for scrapers
988
- *
989
- * Note: It also checks if directory exists and creates it if not
1003
+ * Retrieves an intermediate source for a scraper based on the knowledge source.
1004
+ * Manages the caching and retrieval of intermediate scraper results for optimized performance.
990
1005
  *
991
1006
  * @private as internal utility for scrapers
992
1007
  */
@@ -1122,7 +1137,7 @@
1122
1137
  * Function isValidJsonString will tell you if the string is valid JSON or not
1123
1138
  *
1124
1139
  * @param value The string to check
1125
- * @returns True if the string is a valid JSON string, false otherwise
1140
+ * @returns `true` if the string is a valid JSON string, false otherwise
1126
1141
  *
1127
1142
  * @public exported from `@promptbook/utils`
1128
1143
  */
@@ -1234,7 +1249,7 @@
1234
1249
  if (bookVersion !== `undefined`) {
1235
1250
  commands.push(`BOOK VERSION ${bookVersion}`);
1236
1251
  }
1237
- // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
1252
+ // TODO: [main] !!5 This increases size of the bundle and is probably not necessary
1238
1253
  pipelineString = prettifyMarkdown(pipelineString);
1239
1254
  for (const parameter of parameters.filter(({ isInput }) => isInput)) {
1240
1255
  commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
@@ -1533,8 +1548,12 @@
1533
1548
  */
1534
1549
 
1535
1550
  /**
1536
- * @@@
1551
+ * Creates a deep clone of the given object
1537
1552
  *
1553
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1554
+ *
1555
+ * @param objectValue The object to clone.
1556
+ * @returns A deep, writable clone of the input object.
1538
1557
  * @public exported from `@promptbook/utils`
1539
1558
  */
1540
1559
  function deepClone(objectValue) {
@@ -1616,13 +1635,13 @@
1616
1635
  */
1617
1636
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1618
1637
  /**
1619
- * @@@
1638
+ * Placeholder value indicating a parameter is missing its value.
1620
1639
  *
1621
1640
  * @private within the repository
1622
1641
  */
1623
1642
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1624
1643
  /**
1625
- * @@@
1644
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
1626
1645
  *
1627
1646
  * @private within the repository
1628
1647
  */
@@ -1667,7 +1686,7 @@
1667
1686
  /**
1668
1687
  * Tests if given string is valid semantic version
1669
1688
  *
1670
- * Note: There are two simmilar functions:
1689
+ * Note: There are two similar functions:
1671
1690
  * - `isValidSemanticVersion` which tests any semantic version
1672
1691
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1673
1692
  *
@@ -1689,7 +1708,7 @@
1689
1708
  *
1690
1709
  * @see https://www.npmjs.com/package/promptbook?activeTab=versions
1691
1710
  * 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.
1692
- * Note: There are two simmilar functions:
1711
+ * Note: There are two similar functions:
1693
1712
  * - `isValidSemanticVersion` which tests any semantic version
1694
1713
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1695
1714
  *
@@ -1709,7 +1728,7 @@
1709
1728
  /**
1710
1729
  * Tests if given string is valid pipeline URL URL.
1711
1730
  *
1712
- * Note: There are two simmilar functions:
1731
+ * Note: There are two similar functions:
1713
1732
  * - `isValidUrl` which tests any URL
1714
1733
  * - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
1715
1734
  *
@@ -1806,7 +1825,7 @@
1806
1825
  ${block(pipelineIdentification)}
1807
1826
  `));
1808
1827
  }
1809
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1828
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1810
1829
  if (!Array.isArray(pipeline.parameters)) {
1811
1830
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1812
1831
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -1817,7 +1836,7 @@
1817
1836
  ${block(pipelineIdentification)}
1818
1837
  `));
1819
1838
  }
1820
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1839
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1821
1840
  if (!Array.isArray(pipeline.tasks)) {
1822
1841
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1823
1842
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -2121,7 +2140,7 @@
2121
2140
  /**
2122
2141
  * Constructs a pipeline collection from pipelines
2123
2142
  *
2124
- * @param pipelines @@@
2143
+ * @param pipelines Array of pipeline JSON objects to include in the collection
2125
2144
  *
2126
2145
  * Note: During the construction logic of all pipelines are validated
2127
2146
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -2251,7 +2270,7 @@
2251
2270
  super(message);
2252
2271
  this.name = 'PipelineExecutionError';
2253
2272
  // TODO: [🐙] DRY - Maybe $randomId
2254
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2273
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2255
2274
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
2256
2275
  }
2257
2276
  }
@@ -2267,15 +2286,18 @@
2267
2286
  * @public exported from `@promptbook/core`
2268
2287
  */
2269
2288
  function isPipelinePrepared(pipeline) {
2270
- // Note: Ignoring `pipeline.preparations` @@@
2271
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2289
+ // Note: Ignoring `pipeline.preparations`
2290
+ // Note: Ignoring `pipeline.knowledgePieces`
2272
2291
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2292
+ // console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
2273
2293
  return false;
2274
2294
  }
2275
2295
  if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
2296
+ // console.log('Pipeline is not prepared because personas are not prepared', pipeline.personas);
2276
2297
  return false;
2277
2298
  }
2278
2299
  if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
2300
+ //console.log('Pipeline is not prepared because knowledge sources are not prepared', pipeline.knowledgeSources);
2279
2301
  return false;
2280
2302
  }
2281
2303
  /*
@@ -2296,75 +2318,6 @@
2296
2318
  * - [♨] Are tasks prepared
2297
2319
  */
2298
2320
 
2299
- /**
2300
- * Converts a JavaScript Object Notation (JSON) string into an object.
2301
- *
2302
- * Note: This is wrapper around `JSON.parse()` with better error and type handling
2303
- *
2304
- * @public exported from `@promptbook/utils`
2305
- */
2306
- function jsonParse(value) {
2307
- if (value === undefined) {
2308
- throw new Error(`Can not parse JSON from undefined value.`);
2309
- }
2310
- else if (typeof value !== 'string') {
2311
- console.error('Can not parse JSON from non-string value.', { text: value });
2312
- throw new Error(spaceTrim__default["default"](`
2313
- Can not parse JSON from non-string value.
2314
-
2315
- The value type: ${typeof value}
2316
- See more in console.
2317
- `));
2318
- }
2319
- try {
2320
- return JSON.parse(value);
2321
- }
2322
- catch (error) {
2323
- if (!(error instanceof Error)) {
2324
- throw error;
2325
- }
2326
- throw new Error(spaceTrim__default["default"]((block) => `
2327
- ${block(error.message)}
2328
-
2329
- The JSON text:
2330
- ${block(value)}
2331
- `));
2332
- }
2333
- }
2334
- /**
2335
- * TODO: !!!! Use in Promptbook.studio
2336
- */
2337
-
2338
- /**
2339
- * Recursively converts JSON strings to JSON objects
2340
-
2341
- * @public exported from `@promptbook/utils`
2342
- */
2343
- function jsonStringsToJsons(object) {
2344
- if (object === null) {
2345
- return object;
2346
- }
2347
- if (Array.isArray(object)) {
2348
- return object.map(jsonStringsToJsons);
2349
- }
2350
- if (typeof object !== 'object') {
2351
- return object;
2352
- }
2353
- const newObject = { ...object };
2354
- for (const [key, value] of Object.entries(object)) {
2355
- if (typeof value === 'string' && isValidJsonString(value)) {
2356
- newObject[key] = jsonParse(value);
2357
- }
2358
- else {
2359
- newObject[key] = jsonStringsToJsons(value);
2360
- }
2361
- }
2362
- return newObject;
2363
- }
2364
- /**
2365
- * TODO: Type the return type correctly
2366
- */
2367
-
2368
2321
  /**
2369
2322
  * This error indicates problems parsing the format value
2370
2323
  *
@@ -2409,7 +2362,7 @@
2409
2362
  }
2410
2363
 
2411
2364
  /**
2412
- * This error indicates that the pipeline collection cannot be propperly loaded
2365
+ * This error indicates that the pipeline collection cannot be properly loaded
2413
2366
  *
2414
2367
  * @public exported from `@promptbook/core`
2415
2368
  */
@@ -2548,6 +2501,101 @@
2548
2501
  * Note: [💞] Ignore a discrepancy between file name and entity name
2549
2502
  */
2550
2503
 
2504
+ /**
2505
+ * Serializes an error into a [🚉] JSON-serializable object
2506
+ *
2507
+ * @public exported from `@promptbook/utils`
2508
+ */
2509
+ function serializeError(error) {
2510
+ const { name, message, stack } = error;
2511
+ const { id } = error;
2512
+ if (!Object.keys(ALL_ERRORS).includes(name)) {
2513
+ console.error(spaceTrim__default["default"]((block) => `
2514
+
2515
+ Cannot serialize error with name "${name}"
2516
+
2517
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2518
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2519
+
2520
+
2521
+ ${block(stack || message)}
2522
+
2523
+ `));
2524
+ }
2525
+ return {
2526
+ name: name,
2527
+ message,
2528
+ stack,
2529
+ id, // Include id in the serialized object
2530
+ };
2531
+ }
2532
+
2533
+ /**
2534
+ * Converts a JavaScript Object Notation (JSON) string into an object.
2535
+ *
2536
+ * Note: This is wrapper around `JSON.parse()` with better error and type handling
2537
+ *
2538
+ * @public exported from `@promptbook/utils`
2539
+ */
2540
+ function jsonParse(value) {
2541
+ if (value === undefined) {
2542
+ throw new Error(`Can not parse JSON from undefined value.`);
2543
+ }
2544
+ else if (typeof value !== 'string') {
2545
+ console.error('Can not parse JSON from non-string value.', { text: value });
2546
+ throw new Error(spaceTrim__default["default"](`
2547
+ Can not parse JSON from non-string value.
2548
+
2549
+ The value type: ${typeof value}
2550
+ See more in console.
2551
+ `));
2552
+ }
2553
+ try {
2554
+ return JSON.parse(value);
2555
+ }
2556
+ catch (error) {
2557
+ if (!(error instanceof Error)) {
2558
+ throw error;
2559
+ }
2560
+ throw new Error(spaceTrim__default["default"]((block) => `
2561
+ ${block(error.message)}
2562
+
2563
+ The JSON text:
2564
+ ${block(value)}
2565
+ `));
2566
+ }
2567
+ }
2568
+
2569
+ /**
2570
+ * Recursively converts JSON strings to JSON objects
2571
+
2572
+ * @public exported from `@promptbook/utils`
2573
+ */
2574
+ function jsonStringsToJsons(object) {
2575
+ if (object === null) {
2576
+ return object;
2577
+ }
2578
+ if (Array.isArray(object)) {
2579
+ return object.map(jsonStringsToJsons);
2580
+ }
2581
+ if (typeof object !== 'object') {
2582
+ return object;
2583
+ }
2584
+ const newObject = { ...object };
2585
+ for (const [key, value] of Object.entries(object)) {
2586
+ if (typeof value === 'string' && isValidJsonString(value)) {
2587
+ newObject[key] = jsonParse(value);
2588
+ }
2589
+ else {
2590
+ newObject[key] = jsonStringsToJsons(value);
2591
+ }
2592
+ }
2593
+ return newObject;
2594
+ }
2595
+ /**
2596
+ * TODO: Type the return type correctly
2597
+ */
2598
+
2551
2599
  /**
2552
2600
  * Deserializes the error object
2553
2601
  *
@@ -2622,8 +2670,9 @@
2622
2670
  */
2623
2671
  function createTask(options) {
2624
2672
  const { taskType, taskProcessCallback } = options;
2673
+ let { title } = options;
2625
2674
  // TODO: [🐙] DRY
2626
- const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2675
+ const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2627
2676
  let status = 'RUNNING';
2628
2677
  const createdAt = new Date();
2629
2678
  let updatedAt = createdAt;
@@ -2633,6 +2682,10 @@
2633
2682
  const partialResultSubject = new rxjs.Subject();
2634
2683
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2635
2684
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2685
+ if (newOngoingResult.title) {
2686
+ title = newOngoingResult.title;
2687
+ }
2688
+ updatedAt = new Date();
2636
2689
  Object.assign(currentValue, newOngoingResult);
2637
2690
  // <- TODO: assign deep
2638
2691
  partialResultSubject.next(newOngoingResult);
@@ -2678,17 +2731,24 @@
2678
2731
  return {
2679
2732
  taskType,
2680
2733
  taskId,
2734
+ get promptbookVersion() {
2735
+ return PROMPTBOOK_ENGINE_VERSION;
2736
+ },
2737
+ get title() {
2738
+ return title;
2739
+ // <- Note: [1] These must be getters to allow changing the value in the future
2740
+ },
2681
2741
  get status() {
2682
2742
  return status;
2683
- // <- Note: [1] Theese must be getters to allow changing the value in the future
2743
+ // <- Note: [1] --||--
2684
2744
  },
2685
2745
  get createdAt() {
2686
2746
  return createdAt;
2687
- // <- Note: [1]
2747
+ // <- Note: [1] --||--
2688
2748
  },
2689
2749
  get updatedAt() {
2690
2750
  return updatedAt;
2691
- // <- Note: [1]
2751
+ // <- Note: [1] --||--
2692
2752
  },
2693
2753
  asPromise,
2694
2754
  asObservable() {
@@ -2696,15 +2756,15 @@
2696
2756
  },
2697
2757
  get errors() {
2698
2758
  return errors;
2699
- // <- Note: [1]
2759
+ // <- Note: [1] --||--
2700
2760
  },
2701
2761
  get warnings() {
2702
2762
  return warnings;
2703
- // <- Note: [1]
2763
+ // <- Note: [1] --||--
2704
2764
  },
2705
2765
  get currentValue() {
2706
2766
  return currentValue;
2707
- // <- Note: [1]
2767
+ // <- Note: [1] --||--
2708
2768
  },
2709
2769
  };
2710
2770
  }
@@ -2713,64 +2773,6 @@
2713
2773
  * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2714
2774
  */
2715
2775
 
2716
- /**
2717
- * Serializes an error into a [🚉] JSON-serializable object
2718
- *
2719
- * @public exported from `@promptbook/utils`
2720
- */
2721
- function serializeError(error) {
2722
- const { name, message, stack } = error;
2723
- const { id } = error;
2724
- if (!Object.keys(ALL_ERRORS).includes(name)) {
2725
- console.error(spaceTrim__default["default"]((block) => `
2726
-
2727
- Cannot serialize error with name "${name}"
2728
-
2729
- Authors of Promptbook probably forgot to add this error into the list of errors:
2730
- https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2731
-
2732
-
2733
- ${block(stack || message)}
2734
-
2735
- `));
2736
- }
2737
- return {
2738
- name: name,
2739
- message,
2740
- stack,
2741
- id, // Include id in the serialized object
2742
- };
2743
- }
2744
-
2745
- /**
2746
- * Async version of Array.forEach
2747
- *
2748
- * @param array - Array to iterate over
2749
- * @param options - Options for the function
2750
- * @param callbackfunction - Function to call for each item
2751
- * @public exported from `@promptbook/utils`
2752
- * @deprecated [🪂] Use queues instead
2753
- */
2754
- async function forEachAsync(array, options, callbackfunction) {
2755
- const { maxParallelCount = Infinity } = options;
2756
- let index = 0;
2757
- let runningTasks = [];
2758
- const tasks = [];
2759
- for (const item of array) {
2760
- const currentIndex = index++;
2761
- const task = callbackfunction(item, currentIndex, array);
2762
- tasks.push(task);
2763
- runningTasks.push(task);
2764
- /* not await */ Promise.resolve(task).then(() => {
2765
- runningTasks = runningTasks.filter((t) => t !== task);
2766
- });
2767
- if (maxParallelCount < runningTasks.length) {
2768
- await Promise.race(runningTasks);
2769
- }
2770
- }
2771
- await Promise.all(tasks);
2772
- }
2773
-
2774
2776
  /**
2775
2777
  * Represents the uncertain value
2776
2778
  *
@@ -2814,7 +2816,7 @@
2814
2816
  *
2815
2817
  * @public exported from `@promptbook/core`
2816
2818
  */
2817
- $deepFreeze({
2819
+ const UNCERTAIN_USAGE = $deepFreeze({
2818
2820
  price: UNCERTAIN_ZERO_VALUE,
2819
2821
  input: {
2820
2822
  tokensCount: UNCERTAIN_ZERO_VALUE,
@@ -2839,6 +2841,35 @@
2839
2841
  * Note: [💞] Ignore a discrepancy between file name and entity name
2840
2842
  */
2841
2843
 
2844
+ /**
2845
+ * Async version of Array.forEach
2846
+ *
2847
+ * @param array - Array to iterate over
2848
+ * @param options - Options for the function
2849
+ * @param callbackfunction - Function to call for each item
2850
+ * @public exported from `@promptbook/utils`
2851
+ * @deprecated [🪂] Use queues instead
2852
+ */
2853
+ async function forEachAsync(array, options, callbackfunction) {
2854
+ const { maxParallelCount = Infinity } = options;
2855
+ let index = 0;
2856
+ let runningTasks = [];
2857
+ const tasks = [];
2858
+ for (const item of array) {
2859
+ const currentIndex = index++;
2860
+ const task = callbackfunction(item, currentIndex, array);
2861
+ tasks.push(task);
2862
+ runningTasks.push(task);
2863
+ /* not await */ Promise.resolve(task).then(() => {
2864
+ runningTasks = runningTasks.filter((t) => t !== task);
2865
+ });
2866
+ if (maxParallelCount < runningTasks.length) {
2867
+ await Promise.race(runningTasks);
2868
+ }
2869
+ }
2870
+ await Promise.all(tasks);
2871
+ }
2872
+
2842
2873
  /**
2843
2874
  * Function `addUsage` will add multiple usages into one
2844
2875
  *
@@ -2898,12 +2929,14 @@
2898
2929
  const spending = new rxjs.Subject();
2899
2930
  const proxyTools = {
2900
2931
  get title() {
2901
- // TODO: [🧠] Maybe put here some suffix
2902
- return llmTools.title;
2932
+ return `${llmTools.title} (+usage)`;
2933
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2934
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2903
2935
  },
2904
2936
  get description() {
2905
- // TODO: [🧠] Maybe put here some suffix
2906
- return llmTools.description;
2937
+ return `${llmTools.description} (+usage)`;
2938
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2939
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2907
2940
  },
2908
2941
  checkConfiguration() {
2909
2942
  return /* not await */ llmTools.checkConfiguration();
@@ -2974,29 +3007,40 @@
2974
3007
  return 'Multiple LLM Providers';
2975
3008
  }
2976
3009
  get description() {
2977
- return this.llmExecutionTools.map(({ title }, index) => `${index + 1}) \`${title}\``).join('\n');
3010
+ const innerModelsTitlesAndDescriptions = this.llmExecutionTools
3011
+ .map(({ title, description }, index) => {
3012
+ const headLine = `${index + 1}) \`${title}\``;
3013
+ if (description === undefined) {
3014
+ return headLine;
3015
+ }
3016
+ return spaceTrim__default["default"]((block) => `
3017
+ ${headLine}
3018
+
3019
+ ${ /* <- Note: Indenting the description: */block(description)}
3020
+ `);
3021
+ })
3022
+ .join('\n\n');
3023
+ return spaceTrim__default["default"]((block) => `
3024
+ Multiple LLM Providers:
3025
+
3026
+ ${block(innerModelsTitlesAndDescriptions)}
3027
+ `);
2978
3028
  }
2979
3029
  /**
2980
3030
  * Check the configuration of all execution tools
2981
3031
  */
2982
3032
  async checkConfiguration() {
2983
- // TODO: Maybe do it in parallel
2984
- for (const llmExecutionTools of this.llmExecutionTools) {
2985
- await llmExecutionTools.checkConfiguration();
2986
- }
3033
+ // Note: Run checks in parallel
3034
+ await Promise.all(this.llmExecutionTools.map((tools) => tools.checkConfiguration()));
2987
3035
  }
2988
3036
  /**
2989
3037
  * List all available models that can be used
2990
3038
  * This lists is a combination of all available models from all execution tools
2991
3039
  */
2992
3040
  async listModels() {
2993
- const availableModels = [];
2994
- for (const llmExecutionTools of this.llmExecutionTools) {
2995
- // TODO: [🪂] Obtain models in parallel
2996
- const models = await llmExecutionTools.listModels();
2997
- availableModels.push(...models);
2998
- }
2999
- return availableModels;
3041
+ // Obtain all models in parallel and flatten
3042
+ const modelArrays = await Promise.all(this.llmExecutionTools.map((tools) => tools.listModels()));
3043
+ return modelArrays.flat();
3000
3044
  }
3001
3045
  /**
3002
3046
  * Calls the best available chat model
@@ -3237,7 +3281,8 @@
3237
3281
  */
3238
3282
 
3239
3283
  /**
3240
- * @@@
3284
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3285
+ * regardless of the JavaScript environment in which the code is running
3241
3286
  *
3242
3287
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3243
3288
  *
@@ -3248,10 +3293,10 @@
3248
3293
  }
3249
3294
 
3250
3295
  /**
3251
- * @@@
3296
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
3252
3297
  *
3253
- * @param text @@@
3254
- * @returns @@@
3298
+ * @param text The text string to be converted to SCREAMING_CASE format.
3299
+ * @returns The normalized text in SCREAMING_CASE format.
3255
3300
  * @example 'HELLO_WORLD'
3256
3301
  * @example 'I_LOVE_PROMPTBOOK'
3257
3302
  * @public exported from `@promptbook/utils`
@@ -3303,10 +3348,10 @@
3303
3348
  */
3304
3349
 
3305
3350
  /**
3306
- * @@@
3351
+ * Normalizes a text string to snake_case format.
3307
3352
  *
3308
- * @param text @@@
3309
- * @returns @@@
3353
+ * @param text The text string to be converted to snake_case format.
3354
+ * @returns The normalized text in snake_case format.
3310
3355
  * @example 'hello_world'
3311
3356
  * @example 'i_love_promptbook'
3312
3357
  * @public exported from `@promptbook/utils`
@@ -3316,11 +3361,11 @@
3316
3361
  }
3317
3362
 
3318
3363
  /**
3319
- * Register is @@@
3364
+ * Global registry for storing and managing registered entities of a given type.
3320
3365
  *
3321
3366
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3322
3367
  *
3323
- * @private internal utility, exported are only signleton instances of this class
3368
+ * @private internal utility, exported are only singleton instances of this class
3324
3369
  */
3325
3370
  class $Register {
3326
3371
  constructor(registerName) {
@@ -3364,10 +3409,10 @@
3364
3409
  }
3365
3410
 
3366
3411
  /**
3367
- * @@@
3412
+ * Global registry for storing metadata about all available scrapers and converters.
3368
3413
  *
3369
- * Note: `$` is used to indicate that this interacts with the global scope
3370
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3414
+ * Note: `$` is used to indicate that this interacts with the global scope.
3415
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3371
3416
  * @public exported from `@promptbook/core`
3372
3417
  */
3373
3418
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -3376,10 +3421,11 @@
3376
3421
  */
3377
3422
 
3378
3423
  /**
3379
- * @@@
3424
+ * Registry for all available scrapers in the system.
3425
+ * Central point for registering and accessing different types of content scrapers.
3380
3426
  *
3381
3427
  * Note: `$` is used to indicate that this interacts with the global scope
3382
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3428
+ * @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
3383
3429
  * @public exported from `@promptbook/core`
3384
3430
  */
3385
3431
  const $scrapersRegister = new $Register('scraper_constructors');
@@ -3547,7 +3593,9 @@
3547
3593
  */
3548
3594
 
3549
3595
  /**
3550
- * @@@
3596
+ * Factory function that creates a handler for processing knowledge sources.
3597
+ * Provides standardized processing of different types of knowledge sources
3598
+ * across various scraper implementations.
3551
3599
  *
3552
3600
  * @public exported from `@promptbook/core`
3553
3601
  */
@@ -3686,7 +3734,7 @@
3686
3734
  }
3687
3735
 
3688
3736
  /**
3689
- * Prepares the knowle
3737
+ * Prepares the knowledge pieces
3690
3738
  *
3691
3739
  * @see https://github.com/webgptorg/promptbook/discussions/41
3692
3740
  * @public exported from `@promptbook/core`
@@ -3782,15 +3830,18 @@
3782
3830
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3783
3831
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3784
3832
  * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3785
- * TODO: [🧠][❎] Do here propper M:N mapping
3833
+ * TODO: [🧠][❎] Do here proper M:N mapping
3786
3834
  * [x] One source can make multiple pieces
3787
3835
  * [ ] One piece can have multiple sources
3788
3836
  */
3789
3837
 
3790
3838
  /**
3791
- * @@@
3839
+ * Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
3792
3840
  *
3793
- * @public exported from `@promptbook/core`
3841
+ * @param tasks Sequence of tasks that are chained together to form a pipeline
3842
+ * @returns A promise that resolves to the prepared tasks.
3843
+ *
3844
+ * @private internal utility of `preparePipeline`
3794
3845
  */
3795
3846
  async function prepareTasks(pipeline, tools, options) {
3796
3847
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
@@ -3828,7 +3879,7 @@
3828
3879
  return { tasksPrepared };
3829
3880
  }
3830
3881
  /**
3831
- * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3882
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, similar thing with expectations to sync high-level abstractions
3832
3883
  * TODO: [🧠] Add context to each task (if missing)
3833
3884
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3834
3885
  * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
@@ -3964,7 +4015,7 @@
3964
4015
  order: ORDER_OF_PIPELINE_JSON,
3965
4016
  value: {
3966
4017
  ...pipeline,
3967
- // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
4018
+ // <- TODO: Probably deeply clone the pipeline because `$exportJson` freezes the subobjects
3968
4019
  title,
3969
4020
  knowledgeSources: knowledgeSourcesPrepared,
3970
4021
  knowledgePieces: knowledgePiecesPrepared,
@@ -4227,7 +4278,7 @@
4227
4278
  }
4228
4279
 
4229
4280
  /**
4230
- * @@@
4281
+ * Contains configuration options for parsing and generating CSV files, such as delimiters and quoting rules.
4231
4282
  *
4232
4283
  * @public exported from `@promptbook/core`
4233
4284
  */
@@ -4236,11 +4287,29 @@
4236
4287
  // encoding: 'utf-8',
4237
4288
  });
4238
4289
 
4290
+ /**
4291
+ * Converts a CSV string into an object
4292
+ *
4293
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
4294
+ *
4295
+ * @private - for now until `@promptbook/csv` is released
4296
+ */
4297
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
4298
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
4299
+ // Note: Autoheal invalid '\n' characters
4300
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
4301
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
4302
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
4303
+ }
4304
+ const csv = papaparse.parse(value, settings);
4305
+ return csv;
4306
+ }
4307
+
4239
4308
  /**
4240
4309
  * Function to check if a string is valid CSV
4241
4310
  *
4242
4311
  * @param value The string to check
4243
- * @returns True if the string is a valid CSV string, false otherwise
4312
+ * @returns `true` if the string is a valid CSV string, false otherwise
4244
4313
  *
4245
4314
  * @public exported from `@promptbook/utils`
4246
4315
  */
@@ -4264,7 +4333,7 @@
4264
4333
  * @public exported from `@promptbook/core`
4265
4334
  * <- TODO: [🏢] Export from package `@promptbook/csv`
4266
4335
  */
4267
- const CsvFormatDefinition = {
4336
+ const CsvFormatParser = {
4268
4337
  formatName: 'CSV',
4269
4338
  aliases: ['SPREADSHEET', 'TABLE'],
4270
4339
  isValid(value, settings, schema) {
@@ -4276,12 +4345,12 @@
4276
4345
  heal(value, settings, schema) {
4277
4346
  throw new Error('Not implemented');
4278
4347
  },
4279
- subvalueDefinitions: [
4348
+ subvalueParsers: [
4280
4349
  {
4281
4350
  subvalueName: 'ROW',
4282
- async mapValues(value, outputParameterName, settings, mapCallback) {
4283
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4284
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4351
+ async mapValues(options) {
4352
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4353
+ const csv = csvParse(value, settings);
4285
4354
  if (csv.errors.length !== 0) {
4286
4355
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4287
4356
  CSV parsing error
@@ -4296,23 +4365,37 @@
4296
4365
  ${block(value)}
4297
4366
  `));
4298
4367
  }
4299
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4368
+ const mappedData = [];
4369
+ const length = csv.data.length;
4370
+ for (let index = 0; index < length; index++) {
4371
+ const row = csv.data[index];
4300
4372
  if (row[outputParameterName]) {
4301
4373
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4302
4374
  }
4303
- return {
4375
+ const mappedRow = {
4304
4376
  ...row,
4305
- [outputParameterName]: await mapCallback(row, index),
4377
+ [outputParameterName]: await mapCallback(row, index, length),
4306
4378
  };
4307
- }));
4379
+ mappedData.push(mappedRow);
4380
+ if (onProgress) {
4381
+ // Note: Report the CSV with all rows mapped so far
4382
+ /*
4383
+ // TODO: [🛕] Report progress with all the rows including the pending ones
4384
+ const progressData = mappedData.map((row, i) =>
4385
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4386
+ );
4387
+ */
4388
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4389
+ }
4390
+ }
4308
4391
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4309
4392
  },
4310
4393
  },
4311
4394
  {
4312
4395
  subvalueName: 'CELL',
4313
- async mapValues(value, outputParameterName, settings, mapCallback) {
4314
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4315
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4396
+ async mapValues(options) {
4397
+ const { value, settings, mapCallback, onProgress } = options;
4398
+ const csv = csvParse(value, settings);
4316
4399
  if (csv.errors.length !== 0) {
4317
4400
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4318
4401
  CSV parsing error
@@ -4328,9 +4411,9 @@
4328
4411
  `));
4329
4412
  }
4330
4413
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4331
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4414
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4332
4415
  const index = rowIndex * Object.keys(row).length + columnIndex;
4333
- return /* not await */ mapCallback({ [key]: value }, index);
4416
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4334
4417
  }));
4335
4418
  }));
4336
4419
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4339,10 +4422,10 @@
4339
4422
  ],
4340
4423
  };
4341
4424
  /**
4342
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
4343
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
4344
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
4345
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
4425
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
4426
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
4427
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
4428
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
4346
4429
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4347
4430
  */
4348
4431
 
@@ -4351,7 +4434,7 @@
4351
4434
  *
4352
4435
  * @private still in development [🏢]
4353
4436
  */
4354
- const JsonFormatDefinition = {
4437
+ const JsonFormatParser = {
4355
4438
  formatName: 'JSON',
4356
4439
  mimeType: 'application/json',
4357
4440
  isValid(value, settings, schema) {
@@ -4363,28 +4446,28 @@
4363
4446
  heal(value, settings, schema) {
4364
4447
  throw new Error('Not implemented');
4365
4448
  },
4366
- subvalueDefinitions: [],
4449
+ subvalueParsers: [],
4367
4450
  };
4368
4451
  /**
4369
- * TODO: [🧠] Maybe propper instance of object
4452
+ * TODO: [🧠] Maybe proper instance of object
4370
4453
  * TODO: [0] Make string_serialized_json
4371
4454
  * TODO: [1] Make type for JSON Settings and Schema
4372
4455
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
4373
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
4374
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
4375
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
4376
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
4456
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
4457
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
4458
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
4459
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
4377
4460
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
4378
4461
  */
4379
4462
 
4380
4463
  /**
4381
4464
  * Definition for any text - this will be always valid
4382
4465
  *
4383
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
4466
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
4384
4467
  *
4385
4468
  * @public exported from `@promptbook/core`
4386
4469
  */
4387
- const TextFormatDefinition = {
4470
+ const TextFormatParser = {
4388
4471
  formatName: 'TEXT',
4389
4472
  isValid(value) {
4390
4473
  return typeof value === 'string';
@@ -4393,19 +4476,20 @@
4393
4476
  return typeof partialValue === 'string';
4394
4477
  },
4395
4478
  heal() {
4396
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
4479
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
4397
4480
  },
4398
- subvalueDefinitions: [
4481
+ subvalueParsers: [
4399
4482
  {
4400
4483
  subvalueName: 'LINE',
4401
- async mapValues(value, outputParameterName, settings, mapCallback) {
4484
+ async mapValues(options) {
4485
+ const { value, mapCallback, onProgress } = options;
4402
4486
  const lines = value.split('\n');
4403
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4487
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4404
4488
  // TODO: [🧠] Maybe option to skip empty line
4405
4489
  /* not await */ mapCallback({
4406
4490
  lineContent,
4407
4491
  // TODO: [🧠] Maybe also put here `lineNumber`
4408
- }, lineNumber)));
4492
+ }, lineNumber, array.length)));
4409
4493
  return mappedLines.join('\n');
4410
4494
  },
4411
4495
  },
@@ -4415,10 +4499,10 @@
4415
4499
  /**
4416
4500
  * TODO: [1] Make type for XML Text and Schema
4417
4501
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
4418
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
4419
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
4420
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
4421
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
4502
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
4503
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
4504
+ * TODO: [🍓] In `TextFormatParser` implement `heal
4505
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
4422
4506
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
4423
4507
  */
4424
4508
 
@@ -4426,7 +4510,7 @@
4426
4510
  * Function to check if a string is valid XML
4427
4511
  *
4428
4512
  * @param value
4429
- * @returns True if the string is a valid XML string, false otherwise
4513
+ * @returns `true` if the string is a valid XML string, false otherwise
4430
4514
  *
4431
4515
  * @public exported from `@promptbook/utils`
4432
4516
  */
@@ -4451,7 +4535,7 @@
4451
4535
  *
4452
4536
  * @private still in development [🏢]
4453
4537
  */
4454
- const XmlFormatDefinition = {
4538
+ const XmlFormatParser = {
4455
4539
  formatName: 'XML',
4456
4540
  mimeType: 'application/xml',
4457
4541
  isValid(value, settings, schema) {
@@ -4463,17 +4547,17 @@
4463
4547
  heal(value, settings, schema) {
4464
4548
  throw new Error('Not implemented');
4465
4549
  },
4466
- subvalueDefinitions: [],
4550
+ subvalueParsers: [],
4467
4551
  };
4468
4552
  /**
4469
- * TODO: [🧠] Maybe propper instance of object
4553
+ * TODO: [🧠] Maybe proper instance of object
4470
4554
  * TODO: [0] Make string_serialized_xml
4471
4555
  * TODO: [1] Make type for XML Settings and Schema
4472
4556
  * TODO: [🧠] What to use for validating XMLs - XSD,...
4473
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
4474
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
4475
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
4476
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
4557
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
4558
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
4559
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
4560
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
4477
4561
  * TODO: [🏢] Allow to expect something inside XML and other formats
4478
4562
  */
4479
4563
 
@@ -4482,24 +4566,19 @@
4482
4566
  *
4483
4567
  * @private internal index of `...` <- TODO [🏢]
4484
4568
  */
4485
- const FORMAT_DEFINITIONS = [
4486
- JsonFormatDefinition,
4487
- XmlFormatDefinition,
4488
- TextFormatDefinition,
4489
- CsvFormatDefinition,
4490
- ];
4569
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
4491
4570
  /**
4492
4571
  * Note: [💞] Ignore a discrepancy between file name and entity name
4493
4572
  */
4494
4573
 
4495
4574
  /**
4496
- * Maps available parameters to expected parameters
4575
+ * Maps available parameters to expected parameters for a pipeline task.
4497
4576
  *
4498
4577
  * The strategy is:
4499
- * 1) @@@
4500
- * 2) @@@
4578
+ * 1) First, match parameters by name where both available and expected.
4579
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4501
4580
  *
4502
- * @throws {PipelineExecutionError} @@@
4581
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4503
4582
  * @private within the repository used in `createPipelineExecutor`
4504
4583
  */
4505
4584
  function mapAvailableToExpectedParameters(options) {
@@ -4522,7 +4601,7 @@
4522
4601
  else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
4523
4602
  }
4524
4603
  if (expectedParameterNames.size === 0) {
4525
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4604
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4526
4605
  Object.freeze(mappedParameters);
4527
4606
  return mappedParameters;
4528
4607
  }
@@ -4553,7 +4632,7 @@
4553
4632
  for (let i = 0; i < expectedParameterNames.size; i++) {
4554
4633
  mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
4555
4634
  }
4556
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4635
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4557
4636
  Object.freeze(mappedParameters);
4558
4637
  return mappedParameters;
4559
4638
  }
@@ -4561,8 +4640,8 @@
4561
4640
  /**
4562
4641
  * Extracts all code blocks from markdown.
4563
4642
  *
4564
- * Note: There are multiple simmilar function:
4565
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4643
+ * Note: There are multiple similar functions:
4644
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
4566
4645
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4567
4646
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
4568
4647
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
@@ -4612,7 +4691,7 @@
4612
4691
  if (currentCodeBlock.content !== '') {
4613
4692
  currentCodeBlock.content += '\n';
4614
4693
  }
4615
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
4694
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
4616
4695
  }
4617
4696
  }
4618
4697
  if (currentCodeBlock !== null) {
@@ -4632,7 +4711,7 @@
4632
4711
  * - When there are multiple JSON code blocks the function throws a `ParseError`
4633
4712
  *
4634
4713
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
4635
- * Note: There are multiple simmilar function:
4714
+ * Note: There are multiple similar function:
4636
4715
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4637
4716
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4638
4717
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
@@ -4657,7 +4736,7 @@
4657
4736
  }
4658
4737
  /**
4659
4738
  * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
4660
- * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
4739
+ * TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
4661
4740
  */
4662
4741
 
4663
4742
  /**
@@ -4859,14 +4938,14 @@
4859
4938
  PAGES: countPages,
4860
4939
  };
4861
4940
  /**
4862
- * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
4941
+ * TODO: [🧠][🤠] This should be probably as part of `TextFormatParser`
4863
4942
  * Note: [💞] Ignore a discrepancy between file name and entity name
4864
4943
  */
4865
4944
 
4866
4945
  /**
4867
4946
  * Function checkExpectations will check if the expectations on given value are met
4868
4947
  *
4869
- * Note: There are two simmilar functions:
4948
+ * Note: There are two similar functions:
4870
4949
  * - `checkExpectations` which throws an error if the expectations are not met
4871
4950
  * - `isPassingExpectations` which returns a boolean
4872
4951
  *
@@ -4887,13 +4966,17 @@
4887
4966
  }
4888
4967
  /**
4889
4968
  * TODO: [💝] Unite object for expecting amount and format
4890
- * TODO: [🧠][🤠] This should be part of `TextFormatDefinition`
4969
+ * TODO: [🧠][🤠] This should be part of `TextFormatParser`
4891
4970
  * Note: [💝] and [🤠] are interconnected together
4892
4971
  */
4893
4972
 
4894
4973
  /**
4895
- * @@@
4974
+ * Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
4975
+ * (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
4976
+ * Throws errors if execution fails after all attempts.
4896
4977
  *
4978
+ * @param options - The options for execution, including task, parameters, pipeline, and configuration.
4979
+ * @returns The result string of the executed task.
4897
4980
  * @private internal utility of `createPipelineExecutor`
4898
4981
  */
4899
4982
  async function executeAttempts(options) {
@@ -5115,7 +5198,7 @@
5115
5198
  if (task.format) {
5116
5199
  if (task.format === 'JSON') {
5117
5200
  if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
5118
- // TODO: [🏢] Do more universally via `FormatDefinition`
5201
+ // TODO: [🏢] Do more universally via `FormatParser`
5119
5202
  try {
5120
5203
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
5121
5204
  }
@@ -5217,12 +5300,16 @@
5217
5300
  */
5218
5301
 
5219
5302
  /**
5220
- * @@@
5303
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5304
+ * Handles format and subformat resolution, error handling, and progress reporting.
5305
+ *
5306
+ * @param options - Options for execution, including task details and progress callback.
5307
+ * @returns The result of the subvalue mapping or execution attempts.
5221
5308
  *
5222
5309
  * @private internal utility of `createPipelineExecutor`
5223
5310
  */
5224
5311
  async function executeFormatSubvalues(options) {
5225
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5312
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5226
5313
  if (task.foreach === undefined) {
5227
5314
  return /* not await */ executeAttempts(options);
5228
5315
  }
@@ -5253,16 +5340,16 @@
5253
5340
  ${block(pipelineIdentification)}
5254
5341
  `));
5255
5342
  }
5256
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(task.foreach.subformatName));
5257
- if (subvalueDefinition === undefined) {
5343
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
5344
+ if (subvalueParser === undefined) {
5258
5345
  throw new UnexpectedError(
5259
5346
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5260
5347
  spaceTrim__default["default"]((block) => `
5261
5348
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
5262
5349
 
5263
5350
  Available subformat names for format "${formatDefinition.formatName}":
5264
- ${block(formatDefinition.subvalueDefinitions
5265
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
5351
+ ${block(formatDefinition.subvalueParsers
5352
+ .map((subvalueParser) => subvalueParser.subvalueName)
5266
5353
  .map((subvalueName) => `- ${subvalueName}`)
5267
5354
  .join('\n'))}
5268
5355
 
@@ -5274,55 +5361,85 @@
5274
5361
  let formatSettings;
5275
5362
  if (formatDefinition.formatName === 'CSV') {
5276
5363
  formatSettings = csvSettings;
5277
- // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5278
- }
5279
- const resultString = await subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5280
- let mappedParameters;
5281
- // TODO: [🤹‍♂️][🪂] Limit to N concurrent executions
5282
- // TODO: When done [🐚] Report progress also for each subvalue here
5283
- try {
5284
- mappedParameters = mapAvailableToExpectedParameters({
5285
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5286
- availableParameters: subparameters,
5287
- });
5288
- }
5289
- catch (error) {
5290
- if (!(error instanceof PipelineExecutionError)) {
5291
- throw error;
5364
+ // <- TODO: [🤹‍♂️] More universal, make similar pattern for other formats for example \n vs \r\n in text
5365
+ }
5366
+ const resultString = await subvalueParser.mapValues({
5367
+ value: parameterValue,
5368
+ outputParameterName: task.foreach.outputSubparameterName,
5369
+ settings: formatSettings,
5370
+ onProgress(partialResultString) {
5371
+ return onProgress(Object.freeze({
5372
+ [task.resultingParameterName]: partialResultString,
5373
+ }));
5374
+ },
5375
+ async mapCallback(subparameters, index, length) {
5376
+ let mappedParameters;
5377
+ try {
5378
+ mappedParameters = mapAvailableToExpectedParameters({
5379
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5380
+ availableParameters: subparameters,
5381
+ });
5292
5382
  }
5293
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5294
- ${error.message}
5383
+ catch (error) {
5384
+ if (!(error instanceof PipelineExecutionError)) {
5385
+ throw error;
5386
+ }
5387
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5388
+ ${error.message}
5295
5389
 
5296
- This is error in FOREACH command
5297
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5390
+ This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5391
+ You have probably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5298
5392
 
5299
- ${block(pipelineIdentification)}
5300
- Subparameter index: ${index}
5301
- `));
5302
- }
5303
- const allSubparameters = {
5304
- ...parameters,
5305
- ...mappedParameters,
5306
- };
5307
- // 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
5308
- Object.freeze(allSubparameters);
5309
- const subresultString = await executeAttempts({
5310
- ...options,
5311
- priority: priority + index,
5312
- parameters: allSubparameters,
5313
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5314
- ${block(pipelineIdentification)}
5315
- Subparameter index: ${index}
5316
- `),
5317
- });
5318
- return subresultString;
5393
+ ${block(pipelineIdentification)}
5394
+ `));
5395
+ if (length > BIG_DATASET_TRESHOLD) {
5396
+ console.error(highLevelError);
5397
+ return FAILED_VALUE_PLACEHOLDER;
5398
+ }
5399
+ throw highLevelError;
5400
+ }
5401
+ const allSubparameters = {
5402
+ ...parameters,
5403
+ ...mappedParameters,
5404
+ };
5405
+ Object.freeze(allSubparameters);
5406
+ try {
5407
+ const subresultString = await executeAttempts({
5408
+ ...options,
5409
+ priority: priority + index,
5410
+ parameters: allSubparameters,
5411
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5412
+ ${block(pipelineIdentification)}
5413
+ Subparameter index: ${index}
5414
+ `),
5415
+ });
5416
+ return subresultString;
5417
+ }
5418
+ catch (error) {
5419
+ if (length > BIG_DATASET_TRESHOLD) {
5420
+ console.error(spaceTrim__default["default"]((block) => `
5421
+ ${error.message}
5422
+
5423
+ This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5424
+
5425
+ ${block(pipelineIdentification)}
5426
+ `));
5427
+ return FAILED_VALUE_PLACEHOLDER;
5428
+ }
5429
+ throw error;
5430
+ }
5431
+ },
5319
5432
  });
5320
5433
  return resultString;
5321
5434
  }
5322
5435
 
5323
5436
  /**
5324
- * @@@
5437
+ * Returns the context for a given task, typically used to provide additional information or variables
5438
+ * required for the execution of the task within a pipeline. The context is returned as a string value
5439
+ * that may include markdown formatting.
5325
5440
  *
5441
+ * @param task - The task for which the context is being generated. This should be a deeply immutable TaskJson object.
5442
+ * @returns The context as a string, formatted as markdown and parameter value.
5326
5443
  * @private internal utility of `createPipelineExecutor`
5327
5444
  */
5328
5445
  async function getContextForTask(task) {
@@ -5330,7 +5447,7 @@
5330
5447
  }
5331
5448
 
5332
5449
  /**
5333
- * @@@
5450
+ * Retrieves example values or templates for a given task, used to guide or validate pipeline execution.
5334
5451
  *
5335
5452
  * @private internal utility of `createPipelineExecutor`
5336
5453
  */
@@ -5339,91 +5456,128 @@
5339
5456
  }
5340
5457
 
5341
5458
  /**
5342
- * @@@
5459
+ * Computes the cosine similarity between two embedding vectors
5460
+ *
5461
+ * Note: This is helping function for RAG (retrieval-augmented generation)
5343
5462
  *
5344
- * Here is the place where RAG (retrieval-augmented generation) happens
5463
+ * @param embeddingVector1
5464
+ * @param embeddingVector2
5465
+ * @returns Cosine similarity between the two vectors
5466
+ *
5467
+ * @public exported from `@promptbook/core`
5468
+ */
5469
+ function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5470
+ if (embeddingVector1.length !== embeddingVector2.length) {
5471
+ throw new TypeError('Embedding vectors must have the same length');
5472
+ }
5473
+ const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5474
+ const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5475
+ const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5476
+ return 1 - dotProduct / (magnitude1 * magnitude2);
5477
+ }
5478
+
5479
+ /**
5480
+ *
5481
+ * @param knowledgePieces
5482
+ * @returns
5483
+ *
5484
+ * @private internal utility of `createPipelineExecutor`
5485
+ */
5486
+ function knowledgePiecesToString(knowledgePieces) {
5487
+ return knowledgePieces
5488
+ .map((knowledgePiece) => {
5489
+ const { content } = knowledgePiece;
5490
+ return `- ${content}`;
5491
+ })
5492
+ .join('\n');
5493
+ // <- TODO: [🧠] Some smarter aggregation of knowledge pieces, single-line vs multi-line vs mixed
5494
+ }
5495
+
5496
+ /**
5497
+ * Retrieves the most relevant knowledge pieces for a given task using embedding-based similarity search.
5498
+ * This is where retrieval-augmented generation (RAG) is performed to enhance the task with external knowledge.
5345
5499
  *
5346
5500
  * @private internal utility of `createPipelineExecutor`
5347
5501
  */
5348
5502
  async function getKnowledgeForTask(options) {
5349
- const { tools, preparedPipeline, task } = options;
5503
+ const { tools, preparedPipeline, task, parameters } = options;
5350
5504
  const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5351
5505
  const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5352
5506
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5353
5507
  if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5354
- return 'No knowledge pieces found';
5508
+ return ''; // <- Note: Np knowledge present, return empty string
5355
5509
  }
5356
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5357
- const _llms = arrayableToArray(tools.llm);
5358
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5359
- const taskEmbeddingPrompt = {
5360
- title: 'Knowledge Search',
5361
- modelRequirements: {
5362
- modelVariant: 'EMBEDDING',
5363
- modelName: firstKnowlegeIndex.modelName,
5364
- },
5365
- content: task.content,
5366
- parameters: {
5367
- /* !!!!!!!! */
5368
- },
5369
- };
5370
- const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5371
- const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5372
- const { index } = knowledgePiece;
5373
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5374
- // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5375
- if (knowledgePieceIndex === undefined) {
5510
+ try {
5511
+ // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5512
+ const _llms = arrayableToArray(tools.llm);
5513
+ const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5514
+ const taskEmbeddingPrompt = {
5515
+ title: 'Knowledge Search',
5516
+ modelRequirements: {
5517
+ modelVariant: 'EMBEDDING',
5518
+ modelName: firstKnowlegeIndex.modelName,
5519
+ },
5520
+ content: task.content,
5521
+ parameters,
5522
+ };
5523
+ const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5524
+ const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5525
+ const { index } = knowledgePiece;
5526
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5527
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5528
+ if (knowledgePieceIndex === undefined) {
5529
+ return {
5530
+ content: knowledgePiece.content,
5531
+ relevance: 0,
5532
+ };
5533
+ }
5534
+ const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5376
5535
  return {
5377
5536
  content: knowledgePiece.content,
5378
- relevance: 0,
5537
+ relevance,
5379
5538
  };
5380
- }
5381
- const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5382
- return {
5383
- content: knowledgePiece.content,
5384
- relevance,
5385
- };
5386
- });
5387
- const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5388
- const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5389
- console.log('!!! Embedding', {
5390
- task,
5391
- taskEmbeddingPrompt,
5392
- taskEmbeddingResult,
5393
- firstKnowlegePiece,
5394
- firstKnowlegeIndex,
5395
- knowledgePiecesWithRelevance,
5396
- knowledgePiecesSorted,
5397
- knowledgePiecesLimited,
5398
- });
5399
- return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
5400
- // <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
5401
- }
5402
- // TODO: !!!!!! Annotate + to new file
5403
- function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5404
- if (embeddingVector1.length !== embeddingVector2.length) {
5405
- throw new TypeError('Embedding vectors must have the same length');
5539
+ });
5540
+ const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5541
+ const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5542
+ /*
5543
+ console.log('`getKnowledgeForTask` Embedding', {
5544
+ task,
5545
+ taskEmbeddingPrompt,
5546
+ taskEmbeddingResult,
5547
+ firstKnowlegePiece,
5548
+ firstKnowlegeIndex,
5549
+ knowledgePiecesWithRelevance,
5550
+ knowledgePiecesSorted,
5551
+ knowledgePiecesLimited,
5552
+ });
5553
+ */
5554
+ return knowledgePiecesToString(knowledgePiecesLimited);
5555
+ }
5556
+ catch (error) {
5557
+ assertsError(error);
5558
+ console.error('Error in `getKnowledgeForTask`', error);
5559
+ // Note: If the LLM fails, just return all knowledge pieces
5560
+ return knowledgePiecesToString(preparedPipeline.knowledgePieces);
5406
5561
  }
5407
- const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5408
- const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5409
- const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5410
- return 1 - dotProduct / (magnitude1 * magnitude2);
5411
5562
  }
5412
5563
  /**
5413
- * TODO: !!!! Verify if this is working
5414
5564
  * TODO: [♨] Implement Better - use keyword search
5415
5565
  * TODO: [♨] Examples of values
5416
5566
  */
5417
5567
 
5418
5568
  /**
5419
- * @@@
5569
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5570
+ * Ensures all reserved parameters are defined and throws if any are missing.
5571
+ *
5572
+ * @param options - Options including tools, pipeline, task, and context.
5573
+ * @returns An object containing all reserved parameters for the task.
5420
5574
  *
5421
5575
  * @private internal utility of `createPipelineExecutor`
5422
5576
  */
5423
5577
  async function getReservedParametersForTask(options) {
5424
- const { tools, preparedPipeline, task, pipelineIdentification } = options;
5578
+ const { tools, preparedPipeline, task, parameters, pipelineIdentification, isVerbose } = options;
5425
5579
  const context = await getContextForTask(); // <- [🏍]
5426
- const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
5580
+ const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task, parameters });
5427
5581
  const examples = await getExamplesForTask();
5428
5582
  const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
5429
5583
  const modelName = RESERVED_PARAMETER_MISSING_VALUE;
@@ -5435,6 +5589,9 @@
5435
5589
  currentDate,
5436
5590
  modelName,
5437
5591
  };
5592
+ if (isVerbose) {
5593
+ console.info('Reserved parameters for task:', { options, reservedParameters });
5594
+ }
5438
5595
  // Note: Doublecheck that ALL reserved parameters are defined:
5439
5596
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
5440
5597
  if (reservedParameters[parameterName] === undefined) {
@@ -5449,23 +5606,21 @@
5449
5606
  }
5450
5607
 
5451
5608
  /**
5452
- * @@@
5609
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5610
+ *
5611
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5612
+ * @returns The output parameters produced by the task.
5453
5613
  *
5454
5614
  * @private internal utility of `createPipelineExecutor`
5455
5615
  */
5456
5616
  async function executeTask(options) {
5457
5617
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5458
5618
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5459
- await onProgress({
5460
- outputParameters: {
5461
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5462
- },
5463
- });
5464
5619
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5465
5620
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5466
5621
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
5467
5622
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5468
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
5623
+ if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
5469
5624
  throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5470
5625
  Dependent parameters are not consistent with used parameters:
5471
5626
 
@@ -5483,13 +5638,16 @@
5483
5638
 
5484
5639
  `));
5485
5640
  }
5641
+ const reservedParameters = await getReservedParametersForTask({
5642
+ tools,
5643
+ preparedPipeline,
5644
+ task: currentTask,
5645
+ pipelineIdentification,
5646
+ parameters: parametersToPass,
5647
+ isVerbose,
5648
+ });
5486
5649
  const definedParameters = Object.freeze({
5487
- ...(await getReservedParametersForTask({
5488
- tools,
5489
- preparedPipeline,
5490
- task: currentTask,
5491
- pipelineIdentification,
5492
- })),
5650
+ ...reservedParameters,
5493
5651
  ...parametersToPass,
5494
5652
  });
5495
5653
  const definedParameterNames = new Set(Object.keys(definedParameters));
@@ -5534,6 +5692,7 @@
5534
5692
  preparedPipeline,
5535
5693
  tools,
5536
5694
  $executionReport,
5695
+ onProgress,
5537
5696
  pipelineIdentification,
5538
5697
  maxExecutionAttempts,
5539
5698
  maxParallelCount,
@@ -5561,7 +5720,8 @@
5561
5720
  */
5562
5721
 
5563
5722
  /**
5564
- * @@@
5723
+ * Filters and returns only the output parameters from the provided pipeline execution options.
5724
+ * Adds warnings for any expected output parameters that are missing.
5565
5725
  *
5566
5726
  * @private internal utility of `createPipelineExecutor`
5567
5727
  */
@@ -5586,9 +5746,12 @@
5586
5746
  }
5587
5747
 
5588
5748
  /**
5589
- * @@@
5749
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5590
5750
  *
5591
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5751
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5752
+ *
5753
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5754
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5592
5755
  *
5593
5756
  * @private internal utility of `createPipelineExecutor`
5594
5757
  */
@@ -5911,10 +6074,27 @@
5911
6074
  cacheDirname,
5912
6075
  intermediateFilesStrategy,
5913
6076
  isAutoInstalled,
6077
+ }).catch((error) => {
6078
+ assertsError(error);
6079
+ return exportJson({
6080
+ name: 'pipelineExecutorResult',
6081
+ message: `Unuccessful PipelineExecutorResult, last catch`,
6082
+ order: [],
6083
+ value: {
6084
+ isSuccessful: false,
6085
+ errors: [serializeError(error)],
6086
+ warnings: [],
6087
+ usage: UNCERTAIN_USAGE,
6088
+ executionReport: null,
6089
+ outputParameters: {},
6090
+ preparedPipeline,
6091
+ },
6092
+ });
5914
6093
  });
5915
6094
  };
5916
6095
  const pipelineExecutor = (inputParameters) => createTask({
5917
6096
  taskType: 'EXECUTION',
6097
+ title: pipeline.title,
5918
6098
  taskProcessCallback(updateOngoingResult) {
5919
6099
  return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5920
6100
  updateOngoingResult(newOngoingResult);
@@ -6017,7 +6197,7 @@
6017
6197
  const knowledge = await Promise.all(
6018
6198
  // TODO: [🪂] Do not send all at once but in chunks
6019
6199
  knowledgeTextPieces.map(async (knowledgeTextPiece, i) => {
6020
- // Note: Theese are just default values, they will be overwritten by the actual values:
6200
+ // Note: These are just default values, they will be overwritten by the actual values:
6021
6201
  let name = `piece-${i}`;
6022
6202
  let title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
6023
6203
  const knowledgePieceContent = spaceTrim__default["default"](knowledgeTextPiece);
@@ -6395,7 +6575,8 @@
6395
6575
  */
6396
6576
 
6397
6577
  /**
6398
- * @@@
6578
+ * Creates a scraper for legacy document formats (.doc, .rtf, etc).
6579
+ * Uses LibreOffice for conversion to extract content from older document formats.
6399
6580
  *
6400
6581
  * @public exported from `@promptbook/legacy-documents`
6401
6582
  */