@promptbook/pdf 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 +589 -408
  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 +589 -408
  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.93.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
@@ -35,7 +35,7 @@
35
35
  * Just says that the variable is not used but should be kept
36
36
  * No side effects.
37
37
  *
38
- * Note: It can be usefull for:
38
+ * Note: It can be useful for:
39
39
  *
40
40
  * 1) Suppressing eager optimization of unused imports
41
41
  * 2) Suppressing eslint errors of unused variables in the tests
@@ -52,7 +52,7 @@
52
52
  * Returns the same value that is passed as argument.
53
53
  * No side effects.
54
54
  *
55
- * Note: It can be usefull for:
55
+ * Note: It can be useful for:
56
56
  *
57
57
  * 1) Leveling indentation
58
58
  * 2) Putting always-true or always-false conditions without getting eslint errors
@@ -101,6 +101,21 @@
101
101
  * @public exported from `@promptbook/core`
102
102
  */
103
103
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
104
+ /**
105
+ * Threshold value that determines when a dataset is considered "big"
106
+ * and may require special handling or optimizations
107
+ *
108
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
109
+ *
110
+ * @public exported from `@promptbook/core`
111
+ */
112
+ const BIG_DATASET_TRESHOLD = 50;
113
+ /**
114
+ * Placeholder text used to represent a placeholder value of failed operation
115
+ *
116
+ * @public exported from `@promptbook/core`
117
+ */
118
+ const FAILED_VALUE_PLACEHOLDER = '!?';
104
119
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
105
120
  /**
106
121
  * The maximum number of iterations for a loops
@@ -180,7 +195,7 @@
180
195
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
181
196
  // <- TODO: [🧜‍♂️]
182
197
  /**
183
- * @@@
198
+ * Default settings for parsing and generating CSV files in Promptbook.
184
199
  *
185
200
  * @public exported from `@promptbook/core`
186
201
  */
@@ -191,19 +206,19 @@
191
206
  skipEmptyLines: true,
192
207
  });
193
208
  /**
194
- * @@@
209
+ * Controls whether verbose logging is enabled by default throughout the application.
195
210
  *
196
211
  * @public exported from `@promptbook/core`
197
212
  */
198
213
  let DEFAULT_IS_VERBOSE = false;
199
214
  /**
200
- * @@@
215
+ * Controls whether auto-installation of dependencies is enabled by default.
201
216
  *
202
217
  * @public exported from `@promptbook/core`
203
218
  */
204
219
  const DEFAULT_IS_AUTO_INSTALLED = false;
205
220
  /**
206
- * @@@
221
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
207
222
  *
208
223
  * @private within the repository
209
224
  */
@@ -297,7 +312,7 @@
297
312
  ${block(message)}
298
313
 
299
314
  Note: This error should not happen.
300
- It's probbably a bug in the pipeline collection
315
+ It's probably a bug in the pipeline collection
301
316
 
302
317
  Please report issue:
303
318
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -354,7 +369,8 @@
354
369
  */
355
370
 
356
371
  /**
357
- * @@@
372
+ * Converts a name to a properly formatted subfolder path for cache storage.
373
+ * Handles normalization and path formatting to create consistent cache directory structures.
358
374
  *
359
375
  * @private for `FileCacheStorage`
360
376
  */
@@ -607,10 +623,10 @@
607
623
  */
608
624
 
609
625
  /**
610
- * @@@
626
+ * Removes diacritic marks (accents) from characters in a string.
611
627
  *
612
- * @param input @@@
613
- * @returns @@@
628
+ * @param input The string containing diacritics to be normalized.
629
+ * @returns The string with diacritics removed or normalized.
614
630
  * @public exported from `@promptbook/utils`
615
631
  */
616
632
  function removeDiacritics(input) {
@@ -624,10 +640,10 @@
624
640
  */
625
641
 
626
642
  /**
627
- * @@@
643
+ * Converts a given text to kebab-case format.
628
644
  *
629
- * @param text @@@
630
- * @returns @@@
645
+ * @param text The text to be converted.
646
+ * @returns The kebab-case formatted string.
631
647
  * @example 'hello-world'
632
648
  * @example 'i-love-promptbook'
633
649
  * @public exported from `@promptbook/utils`
@@ -743,7 +759,7 @@
743
759
  * Tests if given string is valid URL.
744
760
  *
745
761
  * Note: Dataurl are considered perfectly valid.
746
- * Note: There are two simmilar functions:
762
+ * Note: There are two similar functions:
747
763
  * - `isValidUrl` which tests any URL
748
764
  * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
749
765
  *
@@ -769,11 +785,11 @@
769
785
  }
770
786
 
771
787
  /**
772
- * @@@
788
+ * Converts a title string into a normalized name.
773
789
  *
774
- * @param value @@@
775
- * @returns @@@
776
- * @example @@@
790
+ * @param value The title string to be converted to a name.
791
+ * @returns A normalized name derived from the input title.
792
+ * @example 'Hello World!' -> 'hello-world'
777
793
  * @public exported from `@promptbook/utils`
778
794
  */
779
795
  function titleToName(value) {
@@ -796,7 +812,7 @@
796
812
  * Just marks a place of place where should be something implemented
797
813
  * No side effects.
798
814
  *
799
- * Note: It can be usefull suppressing eslint errors of unused variables
815
+ * Note: It can be useful suppressing eslint errors of unused variables
800
816
  *
801
817
  * @param value any values
802
818
  * @returns void
@@ -806,9 +822,8 @@
806
822
  }
807
823
 
808
824
  /**
809
- * Create a filename for intermediate cache for scrapers
810
- *
811
- * Note: It also checks if directory exists and creates it if not
825
+ * Retrieves an intermediate source for a scraper based on the knowledge source.
826
+ * Manages the caching and retrieval of intermediate scraper results for optimized performance.
812
827
  *
813
828
  * @private as internal utility for scrapers
814
829
  */
@@ -944,7 +959,7 @@
944
959
  * Function isValidJsonString will tell you if the string is valid JSON or not
945
960
  *
946
961
  * @param value The string to check
947
- * @returns True if the string is a valid JSON string, false otherwise
962
+ * @returns `true` if the string is a valid JSON string, false otherwise
948
963
  *
949
964
  * @public exported from `@promptbook/utils`
950
965
  */
@@ -1056,7 +1071,7 @@
1056
1071
  if (bookVersion !== `undefined`) {
1057
1072
  commands.push(`BOOK VERSION ${bookVersion}`);
1058
1073
  }
1059
- // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
1074
+ // TODO: [main] !!5 This increases size of the bundle and is probably not necessary
1060
1075
  pipelineString = prettifyMarkdown(pipelineString);
1061
1076
  for (const parameter of parameters.filter(({ isInput }) => isInput)) {
1062
1077
  commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
@@ -1355,8 +1370,12 @@
1355
1370
  */
1356
1371
 
1357
1372
  /**
1358
- * @@@
1373
+ * Creates a deep clone of the given object
1359
1374
  *
1375
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1376
+ *
1377
+ * @param objectValue The object to clone.
1378
+ * @returns A deep, writable clone of the input object.
1360
1379
  * @public exported from `@promptbook/utils`
1361
1380
  */
1362
1381
  function deepClone(objectValue) {
@@ -1438,13 +1457,13 @@
1438
1457
  */
1439
1458
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1440
1459
  /**
1441
- * @@@
1460
+ * Placeholder value indicating a parameter is missing its value.
1442
1461
  *
1443
1462
  * @private within the repository
1444
1463
  */
1445
1464
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1446
1465
  /**
1447
- * @@@
1466
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
1448
1467
  *
1449
1468
  * @private within the repository
1450
1469
  */
@@ -1489,7 +1508,7 @@
1489
1508
  /**
1490
1509
  * Tests if given string is valid semantic version
1491
1510
  *
1492
- * Note: There are two simmilar functions:
1511
+ * Note: There are two similar functions:
1493
1512
  * - `isValidSemanticVersion` which tests any semantic version
1494
1513
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1495
1514
  *
@@ -1511,7 +1530,7 @@
1511
1530
  *
1512
1531
  * @see https://www.npmjs.com/package/promptbook?activeTab=versions
1513
1532
  * 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.
1514
- * Note: There are two simmilar functions:
1533
+ * Note: There are two similar functions:
1515
1534
  * - `isValidSemanticVersion` which tests any semantic version
1516
1535
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1517
1536
  *
@@ -1531,7 +1550,7 @@
1531
1550
  /**
1532
1551
  * Tests if given string is valid pipeline URL URL.
1533
1552
  *
1534
- * Note: There are two simmilar functions:
1553
+ * Note: There are two similar functions:
1535
1554
  * - `isValidUrl` which tests any URL
1536
1555
  * - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
1537
1556
  *
@@ -1628,7 +1647,7 @@
1628
1647
  ${block(pipelineIdentification)}
1629
1648
  `));
1630
1649
  }
1631
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1650
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1632
1651
  if (!Array.isArray(pipeline.parameters)) {
1633
1652
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1634
1653
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -1639,7 +1658,7 @@
1639
1658
  ${block(pipelineIdentification)}
1640
1659
  `));
1641
1660
  }
1642
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1661
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1643
1662
  if (!Array.isArray(pipeline.tasks)) {
1644
1663
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1645
1664
  throw new ParseError(spaceTrim.spaceTrim((block) => `
@@ -1943,7 +1962,7 @@
1943
1962
  /**
1944
1963
  * Constructs a pipeline collection from pipelines
1945
1964
  *
1946
- * @param pipelines @@@
1965
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1947
1966
  *
1948
1967
  * Note: During the construction logic of all pipelines are validated
1949
1968
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -2057,7 +2076,7 @@
2057
2076
  super(spaceTrim.spaceTrim((block) => `
2058
2077
  ${block(message)}
2059
2078
 
2060
- Note: You have probbably forgot to provide some tools for pipeline execution or preparation
2079
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
2061
2080
 
2062
2081
  `));
2063
2082
  this.name = 'MissingToolsError';
@@ -2091,7 +2110,7 @@
2091
2110
  super(message);
2092
2111
  this.name = 'PipelineExecutionError';
2093
2112
  // TODO: [🐙] DRY - Maybe $randomId
2094
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2113
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2095
2114
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
2096
2115
  }
2097
2116
  }
@@ -2107,15 +2126,18 @@
2107
2126
  * @public exported from `@promptbook/core`
2108
2127
  */
2109
2128
  function isPipelinePrepared(pipeline) {
2110
- // Note: Ignoring `pipeline.preparations` @@@
2111
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2129
+ // Note: Ignoring `pipeline.preparations`
2130
+ // Note: Ignoring `pipeline.knowledgePieces`
2112
2131
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2132
+ // console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
2113
2133
  return false;
2114
2134
  }
2115
2135
  if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
2136
+ // console.log('Pipeline is not prepared because personas are not prepared', pipeline.personas);
2116
2137
  return false;
2117
2138
  }
2118
2139
  if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
2140
+ //console.log('Pipeline is not prepared because knowledge sources are not prepared', pipeline.knowledgeSources);
2119
2141
  return false;
2120
2142
  }
2121
2143
  /*
@@ -2136,75 +2158,6 @@
2136
2158
  * - [♨] Are tasks prepared
2137
2159
  */
2138
2160
 
2139
- /**
2140
- * Converts a JavaScript Object Notation (JSON) string into an object.
2141
- *
2142
- * Note: This is wrapper around `JSON.parse()` with better error and type handling
2143
- *
2144
- * @public exported from `@promptbook/utils`
2145
- */
2146
- function jsonParse(value) {
2147
- if (value === undefined) {
2148
- throw new Error(`Can not parse JSON from undefined value.`);
2149
- }
2150
- else if (typeof value !== 'string') {
2151
- console.error('Can not parse JSON from non-string value.', { text: value });
2152
- throw new Error(spaceTrim__default["default"](`
2153
- Can not parse JSON from non-string value.
2154
-
2155
- The value type: ${typeof value}
2156
- See more in console.
2157
- `));
2158
- }
2159
- try {
2160
- return JSON.parse(value);
2161
- }
2162
- catch (error) {
2163
- if (!(error instanceof Error)) {
2164
- throw error;
2165
- }
2166
- throw new Error(spaceTrim__default["default"]((block) => `
2167
- ${block(error.message)}
2168
-
2169
- The JSON text:
2170
- ${block(value)}
2171
- `));
2172
- }
2173
- }
2174
- /**
2175
- * TODO: !!!! Use in Promptbook.studio
2176
- */
2177
-
2178
- /**
2179
- * Recursively converts JSON strings to JSON objects
2180
-
2181
- * @public exported from `@promptbook/utils`
2182
- */
2183
- function jsonStringsToJsons(object) {
2184
- if (object === null) {
2185
- return object;
2186
- }
2187
- if (Array.isArray(object)) {
2188
- return object.map(jsonStringsToJsons);
2189
- }
2190
- if (typeof object !== 'object') {
2191
- return object;
2192
- }
2193
- const newObject = { ...object };
2194
- for (const [key, value] of Object.entries(object)) {
2195
- if (typeof value === 'string' && isValidJsonString(value)) {
2196
- newObject[key] = jsonParse(value);
2197
- }
2198
- else {
2199
- newObject[key] = jsonStringsToJsons(value);
2200
- }
2201
- }
2202
- return newObject;
2203
- }
2204
- /**
2205
- * TODO: Type the return type correctly
2206
- */
2207
-
2208
2161
  /**
2209
2162
  * This error indicates problems parsing the format value
2210
2163
  *
@@ -2249,7 +2202,7 @@
2249
2202
  }
2250
2203
 
2251
2204
  /**
2252
- * This error indicates that the pipeline collection cannot be propperly loaded
2205
+ * This error indicates that the pipeline collection cannot be properly loaded
2253
2206
  *
2254
2207
  * @public exported from `@promptbook/core`
2255
2208
  */
@@ -2388,6 +2341,101 @@
2388
2341
  * Note: [💞] Ignore a discrepancy between file name and entity name
2389
2342
  */
2390
2343
 
2344
+ /**
2345
+ * Serializes an error into a [🚉] JSON-serializable object
2346
+ *
2347
+ * @public exported from `@promptbook/utils`
2348
+ */
2349
+ function serializeError(error) {
2350
+ const { name, message, stack } = error;
2351
+ const { id } = error;
2352
+ if (!Object.keys(ALL_ERRORS).includes(name)) {
2353
+ console.error(spaceTrim__default["default"]((block) => `
2354
+
2355
+ Cannot serialize error with name "${name}"
2356
+
2357
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2358
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2359
+
2360
+
2361
+ ${block(stack || message)}
2362
+
2363
+ `));
2364
+ }
2365
+ return {
2366
+ name: name,
2367
+ message,
2368
+ stack,
2369
+ id, // Include id in the serialized object
2370
+ };
2371
+ }
2372
+
2373
+ /**
2374
+ * Converts a JavaScript Object Notation (JSON) string into an object.
2375
+ *
2376
+ * Note: This is wrapper around `JSON.parse()` with better error and type handling
2377
+ *
2378
+ * @public exported from `@promptbook/utils`
2379
+ */
2380
+ function jsonParse(value) {
2381
+ if (value === undefined) {
2382
+ throw new Error(`Can not parse JSON from undefined value.`);
2383
+ }
2384
+ else if (typeof value !== 'string') {
2385
+ console.error('Can not parse JSON from non-string value.', { text: value });
2386
+ throw new Error(spaceTrim__default["default"](`
2387
+ Can not parse JSON from non-string value.
2388
+
2389
+ The value type: ${typeof value}
2390
+ See more in console.
2391
+ `));
2392
+ }
2393
+ try {
2394
+ return JSON.parse(value);
2395
+ }
2396
+ catch (error) {
2397
+ if (!(error instanceof Error)) {
2398
+ throw error;
2399
+ }
2400
+ throw new Error(spaceTrim__default["default"]((block) => `
2401
+ ${block(error.message)}
2402
+
2403
+ The JSON text:
2404
+ ${block(value)}
2405
+ `));
2406
+ }
2407
+ }
2408
+
2409
+ /**
2410
+ * Recursively converts JSON strings to JSON objects
2411
+
2412
+ * @public exported from `@promptbook/utils`
2413
+ */
2414
+ function jsonStringsToJsons(object) {
2415
+ if (object === null) {
2416
+ return object;
2417
+ }
2418
+ if (Array.isArray(object)) {
2419
+ return object.map(jsonStringsToJsons);
2420
+ }
2421
+ if (typeof object !== 'object') {
2422
+ return object;
2423
+ }
2424
+ const newObject = { ...object };
2425
+ for (const [key, value] of Object.entries(object)) {
2426
+ if (typeof value === 'string' && isValidJsonString(value)) {
2427
+ newObject[key] = jsonParse(value);
2428
+ }
2429
+ else {
2430
+ newObject[key] = jsonStringsToJsons(value);
2431
+ }
2432
+ }
2433
+ return newObject;
2434
+ }
2435
+ /**
2436
+ * TODO: Type the return type correctly
2437
+ */
2438
+
2391
2439
  /**
2392
2440
  * Deserializes the error object
2393
2441
  *
@@ -2462,8 +2510,9 @@
2462
2510
  */
2463
2511
  function createTask(options) {
2464
2512
  const { taskType, taskProcessCallback } = options;
2513
+ let { title } = options;
2465
2514
  // TODO: [🐙] DRY
2466
- const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2515
+ const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2467
2516
  let status = 'RUNNING';
2468
2517
  const createdAt = new Date();
2469
2518
  let updatedAt = createdAt;
@@ -2473,6 +2522,10 @@
2473
2522
  const partialResultSubject = new rxjs.Subject();
2474
2523
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2475
2524
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2525
+ if (newOngoingResult.title) {
2526
+ title = newOngoingResult.title;
2527
+ }
2528
+ updatedAt = new Date();
2476
2529
  Object.assign(currentValue, newOngoingResult);
2477
2530
  // <- TODO: assign deep
2478
2531
  partialResultSubject.next(newOngoingResult);
@@ -2518,17 +2571,24 @@
2518
2571
  return {
2519
2572
  taskType,
2520
2573
  taskId,
2574
+ get promptbookVersion() {
2575
+ return PROMPTBOOK_ENGINE_VERSION;
2576
+ },
2577
+ get title() {
2578
+ return title;
2579
+ // <- Note: [1] These must be getters to allow changing the value in the future
2580
+ },
2521
2581
  get status() {
2522
2582
  return status;
2523
- // <- Note: [1] Theese must be getters to allow changing the value in the future
2583
+ // <- Note: [1] --||--
2524
2584
  },
2525
2585
  get createdAt() {
2526
2586
  return createdAt;
2527
- // <- Note: [1]
2587
+ // <- Note: [1] --||--
2528
2588
  },
2529
2589
  get updatedAt() {
2530
2590
  return updatedAt;
2531
- // <- Note: [1]
2591
+ // <- Note: [1] --||--
2532
2592
  },
2533
2593
  asPromise,
2534
2594
  asObservable() {
@@ -2536,15 +2596,15 @@
2536
2596
  },
2537
2597
  get errors() {
2538
2598
  return errors;
2539
- // <- Note: [1]
2599
+ // <- Note: [1] --||--
2540
2600
  },
2541
2601
  get warnings() {
2542
2602
  return warnings;
2543
- // <- Note: [1]
2603
+ // <- Note: [1] --||--
2544
2604
  },
2545
2605
  get currentValue() {
2546
2606
  return currentValue;
2547
- // <- Note: [1]
2607
+ // <- Note: [1] --||--
2548
2608
  },
2549
2609
  };
2550
2610
  }
@@ -2553,64 +2613,6 @@
2553
2613
  * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2554
2614
  */
2555
2615
 
2556
- /**
2557
- * Serializes an error into a [🚉] JSON-serializable object
2558
- *
2559
- * @public exported from `@promptbook/utils`
2560
- */
2561
- function serializeError(error) {
2562
- const { name, message, stack } = error;
2563
- const { id } = error;
2564
- if (!Object.keys(ALL_ERRORS).includes(name)) {
2565
- console.error(spaceTrim__default["default"]((block) => `
2566
-
2567
- Cannot serialize error with name "${name}"
2568
-
2569
- Authors of Promptbook probably forgot to add this error into the list of errors:
2570
- https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2571
-
2572
-
2573
- ${block(stack || message)}
2574
-
2575
- `));
2576
- }
2577
- return {
2578
- name: name,
2579
- message,
2580
- stack,
2581
- id, // Include id in the serialized object
2582
- };
2583
- }
2584
-
2585
- /**
2586
- * Async version of Array.forEach
2587
- *
2588
- * @param array - Array to iterate over
2589
- * @param options - Options for the function
2590
- * @param callbackfunction - Function to call for each item
2591
- * @public exported from `@promptbook/utils`
2592
- * @deprecated [🪂] Use queues instead
2593
- */
2594
- async function forEachAsync(array, options, callbackfunction) {
2595
- const { maxParallelCount = Infinity } = options;
2596
- let index = 0;
2597
- let runningTasks = [];
2598
- const tasks = [];
2599
- for (const item of array) {
2600
- const currentIndex = index++;
2601
- const task = callbackfunction(item, currentIndex, array);
2602
- tasks.push(task);
2603
- runningTasks.push(task);
2604
- /* not await */ Promise.resolve(task).then(() => {
2605
- runningTasks = runningTasks.filter((t) => t !== task);
2606
- });
2607
- if (maxParallelCount < runningTasks.length) {
2608
- await Promise.race(runningTasks);
2609
- }
2610
- }
2611
- await Promise.all(tasks);
2612
- }
2613
-
2614
2616
  /**
2615
2617
  * Represents the uncertain value
2616
2618
  *
@@ -2654,7 +2656,7 @@
2654
2656
  *
2655
2657
  * @public exported from `@promptbook/core`
2656
2658
  */
2657
- $deepFreeze({
2659
+ const UNCERTAIN_USAGE = $deepFreeze({
2658
2660
  price: UNCERTAIN_ZERO_VALUE,
2659
2661
  input: {
2660
2662
  tokensCount: UNCERTAIN_ZERO_VALUE,
@@ -2679,6 +2681,35 @@
2679
2681
  * Note: [💞] Ignore a discrepancy between file name and entity name
2680
2682
  */
2681
2683
 
2684
+ /**
2685
+ * Async version of Array.forEach
2686
+ *
2687
+ * @param array - Array to iterate over
2688
+ * @param options - Options for the function
2689
+ * @param callbackfunction - Function to call for each item
2690
+ * @public exported from `@promptbook/utils`
2691
+ * @deprecated [🪂] Use queues instead
2692
+ */
2693
+ async function forEachAsync(array, options, callbackfunction) {
2694
+ const { maxParallelCount = Infinity } = options;
2695
+ let index = 0;
2696
+ let runningTasks = [];
2697
+ const tasks = [];
2698
+ for (const item of array) {
2699
+ const currentIndex = index++;
2700
+ const task = callbackfunction(item, currentIndex, array);
2701
+ tasks.push(task);
2702
+ runningTasks.push(task);
2703
+ /* not await */ Promise.resolve(task).then(() => {
2704
+ runningTasks = runningTasks.filter((t) => t !== task);
2705
+ });
2706
+ if (maxParallelCount < runningTasks.length) {
2707
+ await Promise.race(runningTasks);
2708
+ }
2709
+ }
2710
+ await Promise.all(tasks);
2711
+ }
2712
+
2682
2713
  /**
2683
2714
  * Function `addUsage` will add multiple usages into one
2684
2715
  *
@@ -2738,12 +2769,14 @@
2738
2769
  const spending = new rxjs.Subject();
2739
2770
  const proxyTools = {
2740
2771
  get title() {
2741
- // TODO: [🧠] Maybe put here some suffix
2742
- return llmTools.title;
2772
+ return `${llmTools.title} (+usage)`;
2773
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2774
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2743
2775
  },
2744
2776
  get description() {
2745
- // TODO: [🧠] Maybe put here some suffix
2746
- return llmTools.description;
2777
+ return `${llmTools.description} (+usage)`;
2778
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2779
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2747
2780
  },
2748
2781
  checkConfiguration() {
2749
2782
  return /* not await */ llmTools.checkConfiguration();
@@ -2814,29 +2847,40 @@
2814
2847
  return 'Multiple LLM Providers';
2815
2848
  }
2816
2849
  get description() {
2817
- return this.llmExecutionTools.map(({ title }, index) => `${index + 1}) \`${title}\``).join('\n');
2850
+ const innerModelsTitlesAndDescriptions = this.llmExecutionTools
2851
+ .map(({ title, description }, index) => {
2852
+ const headLine = `${index + 1}) \`${title}\``;
2853
+ if (description === undefined) {
2854
+ return headLine;
2855
+ }
2856
+ return spaceTrim__default["default"]((block) => `
2857
+ ${headLine}
2858
+
2859
+ ${ /* <- Note: Indenting the description: */block(description)}
2860
+ `);
2861
+ })
2862
+ .join('\n\n');
2863
+ return spaceTrim__default["default"]((block) => `
2864
+ Multiple LLM Providers:
2865
+
2866
+ ${block(innerModelsTitlesAndDescriptions)}
2867
+ `);
2818
2868
  }
2819
2869
  /**
2820
2870
  * Check the configuration of all execution tools
2821
2871
  */
2822
2872
  async checkConfiguration() {
2823
- // TODO: Maybe do it in parallel
2824
- for (const llmExecutionTools of this.llmExecutionTools) {
2825
- await llmExecutionTools.checkConfiguration();
2826
- }
2873
+ // Note: Run checks in parallel
2874
+ await Promise.all(this.llmExecutionTools.map((tools) => tools.checkConfiguration()));
2827
2875
  }
2828
2876
  /**
2829
2877
  * List all available models that can be used
2830
2878
  * This lists is a combination of all available models from all execution tools
2831
2879
  */
2832
2880
  async listModels() {
2833
- const availableModels = [];
2834
- for (const llmExecutionTools of this.llmExecutionTools) {
2835
- // TODO: [🪂] Obtain models in parallel
2836
- const models = await llmExecutionTools.listModels();
2837
- availableModels.push(...models);
2838
- }
2839
- return availableModels;
2881
+ // Obtain all models in parallel and flatten
2882
+ const modelArrays = await Promise.all(this.llmExecutionTools.map((tools) => tools.listModels()));
2883
+ return modelArrays.flat();
2840
2884
  }
2841
2885
  /**
2842
2886
  * Calls the best available chat model
@@ -3077,7 +3121,8 @@
3077
3121
  */
3078
3122
 
3079
3123
  /**
3080
- * @@@
3124
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3125
+ * regardless of the JavaScript environment in which the code is running
3081
3126
  *
3082
3127
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3083
3128
  *
@@ -3088,10 +3133,10 @@
3088
3133
  }
3089
3134
 
3090
3135
  /**
3091
- * @@@
3136
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
3092
3137
  *
3093
- * @param text @@@
3094
- * @returns @@@
3138
+ * @param text The text string to be converted to SCREAMING_CASE format.
3139
+ * @returns The normalized text in SCREAMING_CASE format.
3095
3140
  * @example 'HELLO_WORLD'
3096
3141
  * @example 'I_LOVE_PROMPTBOOK'
3097
3142
  * @public exported from `@promptbook/utils`
@@ -3143,10 +3188,10 @@
3143
3188
  */
3144
3189
 
3145
3190
  /**
3146
- * @@@
3191
+ * Normalizes a text string to snake_case format.
3147
3192
  *
3148
- * @param text @@@
3149
- * @returns @@@
3193
+ * @param text The text string to be converted to snake_case format.
3194
+ * @returns The normalized text in snake_case format.
3150
3195
  * @example 'hello_world'
3151
3196
  * @example 'i_love_promptbook'
3152
3197
  * @public exported from `@promptbook/utils`
@@ -3156,11 +3201,11 @@
3156
3201
  }
3157
3202
 
3158
3203
  /**
3159
- * Register is @@@
3204
+ * Global registry for storing and managing registered entities of a given type.
3160
3205
  *
3161
3206
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3162
3207
  *
3163
- * @private internal utility, exported are only signleton instances of this class
3208
+ * @private internal utility, exported are only singleton instances of this class
3164
3209
  */
3165
3210
  class $Register {
3166
3211
  constructor(registerName) {
@@ -3204,10 +3249,10 @@
3204
3249
  }
3205
3250
 
3206
3251
  /**
3207
- * @@@
3252
+ * Global registry for storing metadata about all available scrapers and converters.
3208
3253
  *
3209
- * Note: `$` is used to indicate that this interacts with the global scope
3210
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3254
+ * Note: `$` is used to indicate that this interacts with the global scope.
3255
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3211
3256
  * @public exported from `@promptbook/core`
3212
3257
  */
3213
3258
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -3216,10 +3261,11 @@
3216
3261
  */
3217
3262
 
3218
3263
  /**
3219
- * @@@
3264
+ * Registry for all available scrapers in the system.
3265
+ * Central point for registering and accessing different types of content scrapers.
3220
3266
  *
3221
3267
  * Note: `$` is used to indicate that this interacts with the global scope
3222
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3268
+ * @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
3223
3269
  * @public exported from `@promptbook/core`
3224
3270
  */
3225
3271
  const $scrapersRegister = new $Register('scraper_constructors');
@@ -3397,7 +3443,9 @@
3397
3443
  */
3398
3444
 
3399
3445
  /**
3400
- * @@@
3446
+ * Factory function that creates a handler for processing knowledge sources.
3447
+ * Provides standardized processing of different types of knowledge sources
3448
+ * across various scraper implementations.
3401
3449
  *
3402
3450
  * @public exported from `@promptbook/core`
3403
3451
  */
@@ -3536,7 +3584,7 @@
3536
3584
  }
3537
3585
 
3538
3586
  /**
3539
- * Prepares the knowle
3587
+ * Prepares the knowledge pieces
3540
3588
  *
3541
3589
  * @see https://github.com/webgptorg/promptbook/discussions/41
3542
3590
  * @public exported from `@promptbook/core`
@@ -3632,15 +3680,18 @@
3632
3680
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3633
3681
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3634
3682
  * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3635
- * TODO: [🧠][❎] Do here propper M:N mapping
3683
+ * TODO: [🧠][❎] Do here proper M:N mapping
3636
3684
  * [x] One source can make multiple pieces
3637
3685
  * [ ] One piece can have multiple sources
3638
3686
  */
3639
3687
 
3640
3688
  /**
3641
- * @@@
3689
+ * Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
3642
3690
  *
3643
- * @public exported from `@promptbook/core`
3691
+ * @param tasks Sequence of tasks that are chained together to form a pipeline
3692
+ * @returns A promise that resolves to the prepared tasks.
3693
+ *
3694
+ * @private internal utility of `preparePipeline`
3644
3695
  */
3645
3696
  async function prepareTasks(pipeline, tools, options) {
3646
3697
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
@@ -3678,7 +3729,7 @@
3678
3729
  return { tasksPrepared };
3679
3730
  }
3680
3731
  /**
3681
- * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3732
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, similar thing with expectations to sync high-level abstractions
3682
3733
  * TODO: [🧠] Add context to each task (if missing)
3683
3734
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3684
3735
  * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
@@ -3814,7 +3865,7 @@
3814
3865
  order: ORDER_OF_PIPELINE_JSON,
3815
3866
  value: {
3816
3867
  ...pipeline,
3817
- // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
3868
+ // <- TODO: Probably deeply clone the pipeline because `$exportJson` freezes the subobjects
3818
3869
  title,
3819
3870
  knowledgeSources: knowledgeSourcesPrepared,
3820
3871
  knowledgePieces: knowledgePiecesPrepared,
@@ -4077,7 +4128,7 @@
4077
4128
  }
4078
4129
 
4079
4130
  /**
4080
- * @@@
4131
+ * Contains configuration options for parsing and generating CSV files, such as delimiters and quoting rules.
4081
4132
  *
4082
4133
  * @public exported from `@promptbook/core`
4083
4134
  */
@@ -4086,11 +4137,29 @@
4086
4137
  // encoding: 'utf-8',
4087
4138
  });
4088
4139
 
4140
+ /**
4141
+ * Converts a CSV string into an object
4142
+ *
4143
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
4144
+ *
4145
+ * @private - for now until `@promptbook/csv` is released
4146
+ */
4147
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
4148
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
4149
+ // Note: Autoheal invalid '\n' characters
4150
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
4151
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
4152
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
4153
+ }
4154
+ const csv = papaparse.parse(value, settings);
4155
+ return csv;
4156
+ }
4157
+
4089
4158
  /**
4090
4159
  * Function to check if a string is valid CSV
4091
4160
  *
4092
4161
  * @param value The string to check
4093
- * @returns True if the string is a valid CSV string, false otherwise
4162
+ * @returns `true` if the string is a valid CSV string, false otherwise
4094
4163
  *
4095
4164
  * @public exported from `@promptbook/utils`
4096
4165
  */
@@ -4114,7 +4183,7 @@
4114
4183
  * @public exported from `@promptbook/core`
4115
4184
  * <- TODO: [🏢] Export from package `@promptbook/csv`
4116
4185
  */
4117
- const CsvFormatDefinition = {
4186
+ const CsvFormatParser = {
4118
4187
  formatName: 'CSV',
4119
4188
  aliases: ['SPREADSHEET', 'TABLE'],
4120
4189
  isValid(value, settings, schema) {
@@ -4126,12 +4195,12 @@
4126
4195
  heal(value, settings, schema) {
4127
4196
  throw new Error('Not implemented');
4128
4197
  },
4129
- subvalueDefinitions: [
4198
+ subvalueParsers: [
4130
4199
  {
4131
4200
  subvalueName: 'ROW',
4132
- async mapValues(value, outputParameterName, settings, mapCallback) {
4133
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4134
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4201
+ async mapValues(options) {
4202
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4203
+ const csv = csvParse(value, settings);
4135
4204
  if (csv.errors.length !== 0) {
4136
4205
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4137
4206
  CSV parsing error
@@ -4146,23 +4215,37 @@
4146
4215
  ${block(value)}
4147
4216
  `));
4148
4217
  }
4149
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4218
+ const mappedData = [];
4219
+ const length = csv.data.length;
4220
+ for (let index = 0; index < length; index++) {
4221
+ const row = csv.data[index];
4150
4222
  if (row[outputParameterName]) {
4151
4223
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4152
4224
  }
4153
- return {
4225
+ const mappedRow = {
4154
4226
  ...row,
4155
- [outputParameterName]: await mapCallback(row, index),
4227
+ [outputParameterName]: await mapCallback(row, index, length),
4156
4228
  };
4157
- }));
4229
+ mappedData.push(mappedRow);
4230
+ if (onProgress) {
4231
+ // Note: Report the CSV with all rows mapped so far
4232
+ /*
4233
+ // TODO: [🛕] Report progress with all the rows including the pending ones
4234
+ const progressData = mappedData.map((row, i) =>
4235
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4236
+ );
4237
+ */
4238
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4239
+ }
4240
+ }
4158
4241
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4159
4242
  },
4160
4243
  },
4161
4244
  {
4162
4245
  subvalueName: 'CELL',
4163
- async mapValues(value, outputParameterName, settings, mapCallback) {
4164
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4165
- const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4246
+ async mapValues(options) {
4247
+ const { value, settings, mapCallback, onProgress } = options;
4248
+ const csv = csvParse(value, settings);
4166
4249
  if (csv.errors.length !== 0) {
4167
4250
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
4168
4251
  CSV parsing error
@@ -4178,9 +4261,9 @@
4178
4261
  `));
4179
4262
  }
4180
4263
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4181
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4264
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4182
4265
  const index = rowIndex * Object.keys(row).length + columnIndex;
4183
- return /* not await */ mapCallback({ [key]: value }, index);
4266
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4184
4267
  }));
4185
4268
  }));
4186
4269
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4189,10 +4272,10 @@
4189
4272
  ],
4190
4273
  };
4191
4274
  /**
4192
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
4193
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
4194
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
4195
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
4275
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
4276
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
4277
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
4278
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
4196
4279
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4197
4280
  */
4198
4281
 
@@ -4201,7 +4284,7 @@
4201
4284
  *
4202
4285
  * @private still in development [🏢]
4203
4286
  */
4204
- const JsonFormatDefinition = {
4287
+ const JsonFormatParser = {
4205
4288
  formatName: 'JSON',
4206
4289
  mimeType: 'application/json',
4207
4290
  isValid(value, settings, schema) {
@@ -4213,28 +4296,28 @@
4213
4296
  heal(value, settings, schema) {
4214
4297
  throw new Error('Not implemented');
4215
4298
  },
4216
- subvalueDefinitions: [],
4299
+ subvalueParsers: [],
4217
4300
  };
4218
4301
  /**
4219
- * TODO: [🧠] Maybe propper instance of object
4302
+ * TODO: [🧠] Maybe proper instance of object
4220
4303
  * TODO: [0] Make string_serialized_json
4221
4304
  * TODO: [1] Make type for JSON Settings and Schema
4222
4305
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
4223
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
4224
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
4225
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
4226
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
4306
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
4307
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
4308
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
4309
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
4227
4310
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
4228
4311
  */
4229
4312
 
4230
4313
  /**
4231
4314
  * Definition for any text - this will be always valid
4232
4315
  *
4233
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
4316
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
4234
4317
  *
4235
4318
  * @public exported from `@promptbook/core`
4236
4319
  */
4237
- const TextFormatDefinition = {
4320
+ const TextFormatParser = {
4238
4321
  formatName: 'TEXT',
4239
4322
  isValid(value) {
4240
4323
  return typeof value === 'string';
@@ -4243,19 +4326,20 @@
4243
4326
  return typeof partialValue === 'string';
4244
4327
  },
4245
4328
  heal() {
4246
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
4329
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
4247
4330
  },
4248
- subvalueDefinitions: [
4331
+ subvalueParsers: [
4249
4332
  {
4250
4333
  subvalueName: 'LINE',
4251
- async mapValues(value, outputParameterName, settings, mapCallback) {
4334
+ async mapValues(options) {
4335
+ const { value, mapCallback, onProgress } = options;
4252
4336
  const lines = value.split('\n');
4253
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4337
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4254
4338
  // TODO: [🧠] Maybe option to skip empty line
4255
4339
  /* not await */ mapCallback({
4256
4340
  lineContent,
4257
4341
  // TODO: [🧠] Maybe also put here `lineNumber`
4258
- }, lineNumber)));
4342
+ }, lineNumber, array.length)));
4259
4343
  return mappedLines.join('\n');
4260
4344
  },
4261
4345
  },
@@ -4265,10 +4349,10 @@
4265
4349
  /**
4266
4350
  * TODO: [1] Make type for XML Text and Schema
4267
4351
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
4268
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
4269
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
4270
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
4271
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
4352
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
4353
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
4354
+ * TODO: [🍓] In `TextFormatParser` implement `heal
4355
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
4272
4356
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
4273
4357
  */
4274
4358
 
@@ -4276,7 +4360,7 @@
4276
4360
  * Function to check if a string is valid XML
4277
4361
  *
4278
4362
  * @param value
4279
- * @returns True if the string is a valid XML string, false otherwise
4363
+ * @returns `true` if the string is a valid XML string, false otherwise
4280
4364
  *
4281
4365
  * @public exported from `@promptbook/utils`
4282
4366
  */
@@ -4301,7 +4385,7 @@
4301
4385
  *
4302
4386
  * @private still in development [🏢]
4303
4387
  */
4304
- const XmlFormatDefinition = {
4388
+ const XmlFormatParser = {
4305
4389
  formatName: 'XML',
4306
4390
  mimeType: 'application/xml',
4307
4391
  isValid(value, settings, schema) {
@@ -4313,17 +4397,17 @@
4313
4397
  heal(value, settings, schema) {
4314
4398
  throw new Error('Not implemented');
4315
4399
  },
4316
- subvalueDefinitions: [],
4400
+ subvalueParsers: [],
4317
4401
  };
4318
4402
  /**
4319
- * TODO: [🧠] Maybe propper instance of object
4403
+ * TODO: [🧠] Maybe proper instance of object
4320
4404
  * TODO: [0] Make string_serialized_xml
4321
4405
  * TODO: [1] Make type for XML Settings and Schema
4322
4406
  * TODO: [🧠] What to use for validating XMLs - XSD,...
4323
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
4324
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
4325
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
4326
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
4407
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
4408
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
4409
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
4410
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
4327
4411
  * TODO: [🏢] Allow to expect something inside XML and other formats
4328
4412
  */
4329
4413
 
@@ -4332,24 +4416,19 @@
4332
4416
  *
4333
4417
  * @private internal index of `...` <- TODO [🏢]
4334
4418
  */
4335
- const FORMAT_DEFINITIONS = [
4336
- JsonFormatDefinition,
4337
- XmlFormatDefinition,
4338
- TextFormatDefinition,
4339
- CsvFormatDefinition,
4340
- ];
4419
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
4341
4420
  /**
4342
4421
  * Note: [💞] Ignore a discrepancy between file name and entity name
4343
4422
  */
4344
4423
 
4345
4424
  /**
4346
- * Maps available parameters to expected parameters
4425
+ * Maps available parameters to expected parameters for a pipeline task.
4347
4426
  *
4348
4427
  * The strategy is:
4349
- * 1) @@@
4350
- * 2) @@@
4428
+ * 1) First, match parameters by name where both available and expected.
4429
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4351
4430
  *
4352
- * @throws {PipelineExecutionError} @@@
4431
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4353
4432
  * @private within the repository used in `createPipelineExecutor`
4354
4433
  */
4355
4434
  function mapAvailableToExpectedParameters(options) {
@@ -4372,7 +4451,7 @@
4372
4451
  else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
4373
4452
  }
4374
4453
  if (expectedParameterNames.size === 0) {
4375
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4454
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4376
4455
  Object.freeze(mappedParameters);
4377
4456
  return mappedParameters;
4378
4457
  }
@@ -4403,7 +4482,7 @@
4403
4482
  for (let i = 0; i < expectedParameterNames.size; i++) {
4404
4483
  mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
4405
4484
  }
4406
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4485
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4407
4486
  Object.freeze(mappedParameters);
4408
4487
  return mappedParameters;
4409
4488
  }
@@ -4411,8 +4490,8 @@
4411
4490
  /**
4412
4491
  * Extracts all code blocks from markdown.
4413
4492
  *
4414
- * Note: There are multiple simmilar function:
4415
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4493
+ * Note: There are multiple similar functions:
4494
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
4416
4495
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4417
4496
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
4418
4497
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
@@ -4462,7 +4541,7 @@
4462
4541
  if (currentCodeBlock.content !== '') {
4463
4542
  currentCodeBlock.content += '\n';
4464
4543
  }
4465
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
4544
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
4466
4545
  }
4467
4546
  }
4468
4547
  if (currentCodeBlock !== null) {
@@ -4482,7 +4561,7 @@
4482
4561
  * - When there are multiple JSON code blocks the function throws a `ParseError`
4483
4562
  *
4484
4563
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
4485
- * Note: There are multiple simmilar function:
4564
+ * Note: There are multiple similar function:
4486
4565
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4487
4566
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4488
4567
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
@@ -4507,7 +4586,7 @@
4507
4586
  }
4508
4587
  /**
4509
4588
  * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
4510
- * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
4589
+ * TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
4511
4590
  */
4512
4591
 
4513
4592
  /**
@@ -4709,14 +4788,14 @@
4709
4788
  PAGES: countPages,
4710
4789
  };
4711
4790
  /**
4712
- * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
4791
+ * TODO: [🧠][🤠] This should be probably as part of `TextFormatParser`
4713
4792
  * Note: [💞] Ignore a discrepancy between file name and entity name
4714
4793
  */
4715
4794
 
4716
4795
  /**
4717
4796
  * Function checkExpectations will check if the expectations on given value are met
4718
4797
  *
4719
- * Note: There are two simmilar functions:
4798
+ * Note: There are two similar functions:
4720
4799
  * - `checkExpectations` which throws an error if the expectations are not met
4721
4800
  * - `isPassingExpectations` which returns a boolean
4722
4801
  *
@@ -4737,13 +4816,17 @@
4737
4816
  }
4738
4817
  /**
4739
4818
  * TODO: [💝] Unite object for expecting amount and format
4740
- * TODO: [🧠][🤠] This should be part of `TextFormatDefinition`
4819
+ * TODO: [🧠][🤠] This should be part of `TextFormatParser`
4741
4820
  * Note: [💝] and [🤠] are interconnected together
4742
4821
  */
4743
4822
 
4744
4823
  /**
4745
- * @@@
4824
+ * Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
4825
+ * (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
4826
+ * Throws errors if execution fails after all attempts.
4746
4827
  *
4828
+ * @param options - The options for execution, including task, parameters, pipeline, and configuration.
4829
+ * @returns The result string of the executed task.
4747
4830
  * @private internal utility of `createPipelineExecutor`
4748
4831
  */
4749
4832
  async function executeAttempts(options) {
@@ -4965,7 +5048,7 @@
4965
5048
  if (task.format) {
4966
5049
  if (task.format === 'JSON') {
4967
5050
  if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
4968
- // TODO: [🏢] Do more universally via `FormatDefinition`
5051
+ // TODO: [🏢] Do more universally via `FormatParser`
4969
5052
  try {
4970
5053
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
4971
5054
  }
@@ -5067,12 +5150,16 @@
5067
5150
  */
5068
5151
 
5069
5152
  /**
5070
- * @@@
5153
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5154
+ * Handles format and subformat resolution, error handling, and progress reporting.
5155
+ *
5156
+ * @param options - Options for execution, including task details and progress callback.
5157
+ * @returns The result of the subvalue mapping or execution attempts.
5071
5158
  *
5072
5159
  * @private internal utility of `createPipelineExecutor`
5073
5160
  */
5074
5161
  async function executeFormatSubvalues(options) {
5075
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5162
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5076
5163
  if (task.foreach === undefined) {
5077
5164
  return /* not await */ executeAttempts(options);
5078
5165
  }
@@ -5103,16 +5190,16 @@
5103
5190
  ${block(pipelineIdentification)}
5104
5191
  `));
5105
5192
  }
5106
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(task.foreach.subformatName));
5107
- if (subvalueDefinition === undefined) {
5193
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
5194
+ if (subvalueParser === undefined) {
5108
5195
  throw new UnexpectedError(
5109
5196
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5110
5197
  spaceTrim__default["default"]((block) => `
5111
5198
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
5112
5199
 
5113
5200
  Available subformat names for format "${formatDefinition.formatName}":
5114
- ${block(formatDefinition.subvalueDefinitions
5115
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
5201
+ ${block(formatDefinition.subvalueParsers
5202
+ .map((subvalueParser) => subvalueParser.subvalueName)
5116
5203
  .map((subvalueName) => `- ${subvalueName}`)
5117
5204
  .join('\n'))}
5118
5205
 
@@ -5124,55 +5211,85 @@
5124
5211
  let formatSettings;
5125
5212
  if (formatDefinition.formatName === 'CSV') {
5126
5213
  formatSettings = csvSettings;
5127
- // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5128
- }
5129
- const resultString = await subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5130
- let mappedParameters;
5131
- // TODO: [🤹‍♂️][🪂] Limit to N concurrent executions
5132
- // TODO: When done [🐚] Report progress also for each subvalue here
5133
- try {
5134
- mappedParameters = mapAvailableToExpectedParameters({
5135
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5136
- availableParameters: subparameters,
5137
- });
5138
- }
5139
- catch (error) {
5140
- if (!(error instanceof PipelineExecutionError)) {
5141
- throw error;
5214
+ // <- TODO: [🤹‍♂️] More universal, make similar pattern for other formats for example \n vs \r\n in text
5215
+ }
5216
+ const resultString = await subvalueParser.mapValues({
5217
+ value: parameterValue,
5218
+ outputParameterName: task.foreach.outputSubparameterName,
5219
+ settings: formatSettings,
5220
+ onProgress(partialResultString) {
5221
+ return onProgress(Object.freeze({
5222
+ [task.resultingParameterName]: partialResultString,
5223
+ }));
5224
+ },
5225
+ async mapCallback(subparameters, index, length) {
5226
+ let mappedParameters;
5227
+ try {
5228
+ mappedParameters = mapAvailableToExpectedParameters({
5229
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5230
+ availableParameters: subparameters,
5231
+ });
5142
5232
  }
5143
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5144
- ${error.message}
5233
+ catch (error) {
5234
+ if (!(error instanceof PipelineExecutionError)) {
5235
+ throw error;
5236
+ }
5237
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5238
+ ${error.message}
5145
5239
 
5146
- This is error in FOREACH command
5147
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5240
+ This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5241
+ You have probably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5148
5242
 
5149
- ${block(pipelineIdentification)}
5150
- Subparameter index: ${index}
5151
- `));
5152
- }
5153
- const allSubparameters = {
5154
- ...parameters,
5155
- ...mappedParameters,
5156
- };
5157
- // 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
5158
- Object.freeze(allSubparameters);
5159
- const subresultString = await executeAttempts({
5160
- ...options,
5161
- priority: priority + index,
5162
- parameters: allSubparameters,
5163
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5164
- ${block(pipelineIdentification)}
5165
- Subparameter index: ${index}
5166
- `),
5167
- });
5168
- return subresultString;
5243
+ ${block(pipelineIdentification)}
5244
+ `));
5245
+ if (length > BIG_DATASET_TRESHOLD) {
5246
+ console.error(highLevelError);
5247
+ return FAILED_VALUE_PLACEHOLDER;
5248
+ }
5249
+ throw highLevelError;
5250
+ }
5251
+ const allSubparameters = {
5252
+ ...parameters,
5253
+ ...mappedParameters,
5254
+ };
5255
+ Object.freeze(allSubparameters);
5256
+ try {
5257
+ const subresultString = await executeAttempts({
5258
+ ...options,
5259
+ priority: priority + index,
5260
+ parameters: allSubparameters,
5261
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5262
+ ${block(pipelineIdentification)}
5263
+ Subparameter index: ${index}
5264
+ `),
5265
+ });
5266
+ return subresultString;
5267
+ }
5268
+ catch (error) {
5269
+ if (length > BIG_DATASET_TRESHOLD) {
5270
+ console.error(spaceTrim__default["default"]((block) => `
5271
+ ${error.message}
5272
+
5273
+ This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5274
+
5275
+ ${block(pipelineIdentification)}
5276
+ `));
5277
+ return FAILED_VALUE_PLACEHOLDER;
5278
+ }
5279
+ throw error;
5280
+ }
5281
+ },
5169
5282
  });
5170
5283
  return resultString;
5171
5284
  }
5172
5285
 
5173
5286
  /**
5174
- * @@@
5287
+ * Returns the context for a given task, typically used to provide additional information or variables
5288
+ * required for the execution of the task within a pipeline. The context is returned as a string value
5289
+ * that may include markdown formatting.
5175
5290
  *
5291
+ * @param task - The task for which the context is being generated. This should be a deeply immutable TaskJson object.
5292
+ * @returns The context as a string, formatted as markdown and parameter value.
5176
5293
  * @private internal utility of `createPipelineExecutor`
5177
5294
  */
5178
5295
  async function getContextForTask(task) {
@@ -5180,7 +5297,7 @@
5180
5297
  }
5181
5298
 
5182
5299
  /**
5183
- * @@@
5300
+ * Retrieves example values or templates for a given task, used to guide or validate pipeline execution.
5184
5301
  *
5185
5302
  * @private internal utility of `createPipelineExecutor`
5186
5303
  */
@@ -5189,91 +5306,128 @@
5189
5306
  }
5190
5307
 
5191
5308
  /**
5192
- * @@@
5309
+ * Computes the cosine similarity between two embedding vectors
5310
+ *
5311
+ * Note: This is helping function for RAG (retrieval-augmented generation)
5193
5312
  *
5194
- * Here is the place where RAG (retrieval-augmented generation) happens
5313
+ * @param embeddingVector1
5314
+ * @param embeddingVector2
5315
+ * @returns Cosine similarity between the two vectors
5316
+ *
5317
+ * @public exported from `@promptbook/core`
5318
+ */
5319
+ function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5320
+ if (embeddingVector1.length !== embeddingVector2.length) {
5321
+ throw new TypeError('Embedding vectors must have the same length');
5322
+ }
5323
+ const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5324
+ const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5325
+ const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5326
+ return 1 - dotProduct / (magnitude1 * magnitude2);
5327
+ }
5328
+
5329
+ /**
5330
+ *
5331
+ * @param knowledgePieces
5332
+ * @returns
5333
+ *
5334
+ * @private internal utility of `createPipelineExecutor`
5335
+ */
5336
+ function knowledgePiecesToString(knowledgePieces) {
5337
+ return knowledgePieces
5338
+ .map((knowledgePiece) => {
5339
+ const { content } = knowledgePiece;
5340
+ return `- ${content}`;
5341
+ })
5342
+ .join('\n');
5343
+ // <- TODO: [🧠] Some smarter aggregation of knowledge pieces, single-line vs multi-line vs mixed
5344
+ }
5345
+
5346
+ /**
5347
+ * Retrieves the most relevant knowledge pieces for a given task using embedding-based similarity search.
5348
+ * This is where retrieval-augmented generation (RAG) is performed to enhance the task with external knowledge.
5195
5349
  *
5196
5350
  * @private internal utility of `createPipelineExecutor`
5197
5351
  */
5198
5352
  async function getKnowledgeForTask(options) {
5199
- const { tools, preparedPipeline, task } = options;
5353
+ const { tools, preparedPipeline, task, parameters } = options;
5200
5354
  const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5201
5355
  const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5202
5356
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5203
5357
  if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5204
- return 'No knowledge pieces found';
5358
+ return ''; // <- Note: Np knowledge present, return empty string
5205
5359
  }
5206
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5207
- const _llms = arrayableToArray(tools.llm);
5208
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5209
- const taskEmbeddingPrompt = {
5210
- title: 'Knowledge Search',
5211
- modelRequirements: {
5212
- modelVariant: 'EMBEDDING',
5213
- modelName: firstKnowlegeIndex.modelName,
5214
- },
5215
- content: task.content,
5216
- parameters: {
5217
- /* !!!!!!!! */
5218
- },
5219
- };
5220
- const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5221
- const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5222
- const { index } = knowledgePiece;
5223
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5224
- // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5225
- if (knowledgePieceIndex === undefined) {
5360
+ try {
5361
+ // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5362
+ const _llms = arrayableToArray(tools.llm);
5363
+ const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5364
+ const taskEmbeddingPrompt = {
5365
+ title: 'Knowledge Search',
5366
+ modelRequirements: {
5367
+ modelVariant: 'EMBEDDING',
5368
+ modelName: firstKnowlegeIndex.modelName,
5369
+ },
5370
+ content: task.content,
5371
+ parameters,
5372
+ };
5373
+ const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5374
+ const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5375
+ const { index } = knowledgePiece;
5376
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5377
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5378
+ if (knowledgePieceIndex === undefined) {
5379
+ return {
5380
+ content: knowledgePiece.content,
5381
+ relevance: 0,
5382
+ };
5383
+ }
5384
+ const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5226
5385
  return {
5227
5386
  content: knowledgePiece.content,
5228
- relevance: 0,
5387
+ relevance,
5229
5388
  };
5230
- }
5231
- const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5232
- return {
5233
- content: knowledgePiece.content,
5234
- relevance,
5235
- };
5236
- });
5237
- const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5238
- const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5239
- console.log('!!! Embedding', {
5240
- task,
5241
- taskEmbeddingPrompt,
5242
- taskEmbeddingResult,
5243
- firstKnowlegePiece,
5244
- firstKnowlegeIndex,
5245
- knowledgePiecesWithRelevance,
5246
- knowledgePiecesSorted,
5247
- knowledgePiecesLimited,
5248
- });
5249
- return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
5250
- // <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
5251
- }
5252
- // TODO: !!!!!! Annotate + to new file
5253
- function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5254
- if (embeddingVector1.length !== embeddingVector2.length) {
5255
- throw new TypeError('Embedding vectors must have the same length');
5389
+ });
5390
+ const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5391
+ const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5392
+ /*
5393
+ console.log('`getKnowledgeForTask` Embedding', {
5394
+ task,
5395
+ taskEmbeddingPrompt,
5396
+ taskEmbeddingResult,
5397
+ firstKnowlegePiece,
5398
+ firstKnowlegeIndex,
5399
+ knowledgePiecesWithRelevance,
5400
+ knowledgePiecesSorted,
5401
+ knowledgePiecesLimited,
5402
+ });
5403
+ */
5404
+ return knowledgePiecesToString(knowledgePiecesLimited);
5405
+ }
5406
+ catch (error) {
5407
+ assertsError(error);
5408
+ console.error('Error in `getKnowledgeForTask`', error);
5409
+ // Note: If the LLM fails, just return all knowledge pieces
5410
+ return knowledgePiecesToString(preparedPipeline.knowledgePieces);
5256
5411
  }
5257
- const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5258
- const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5259
- const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5260
- return 1 - dotProduct / (magnitude1 * magnitude2);
5261
5412
  }
5262
5413
  /**
5263
- * TODO: !!!! Verify if this is working
5264
5414
  * TODO: [♨] Implement Better - use keyword search
5265
5415
  * TODO: [♨] Examples of values
5266
5416
  */
5267
5417
 
5268
5418
  /**
5269
- * @@@
5419
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5420
+ * Ensures all reserved parameters are defined and throws if any are missing.
5421
+ *
5422
+ * @param options - Options including tools, pipeline, task, and context.
5423
+ * @returns An object containing all reserved parameters for the task.
5270
5424
  *
5271
5425
  * @private internal utility of `createPipelineExecutor`
5272
5426
  */
5273
5427
  async function getReservedParametersForTask(options) {
5274
- const { tools, preparedPipeline, task, pipelineIdentification } = options;
5428
+ const { tools, preparedPipeline, task, parameters, pipelineIdentification, isVerbose } = options;
5275
5429
  const context = await getContextForTask(); // <- [🏍]
5276
- const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
5430
+ const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task, parameters });
5277
5431
  const examples = await getExamplesForTask();
5278
5432
  const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
5279
5433
  const modelName = RESERVED_PARAMETER_MISSING_VALUE;
@@ -5285,6 +5439,9 @@
5285
5439
  currentDate,
5286
5440
  modelName,
5287
5441
  };
5442
+ if (isVerbose) {
5443
+ console.info('Reserved parameters for task:', { options, reservedParameters });
5444
+ }
5288
5445
  // Note: Doublecheck that ALL reserved parameters are defined:
5289
5446
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
5290
5447
  if (reservedParameters[parameterName] === undefined) {
@@ -5299,23 +5456,21 @@
5299
5456
  }
5300
5457
 
5301
5458
  /**
5302
- * @@@
5459
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5460
+ *
5461
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5462
+ * @returns The output parameters produced by the task.
5303
5463
  *
5304
5464
  * @private internal utility of `createPipelineExecutor`
5305
5465
  */
5306
5466
  async function executeTask(options) {
5307
5467
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5308
5468
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5309
- await onProgress({
5310
- outputParameters: {
5311
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5312
- },
5313
- });
5314
5469
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5315
5470
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5316
5471
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
5317
5472
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5318
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
5473
+ if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
5319
5474
  throw new UnexpectedError(spaceTrim.spaceTrim((block) => `
5320
5475
  Dependent parameters are not consistent with used parameters:
5321
5476
 
@@ -5333,13 +5488,16 @@
5333
5488
 
5334
5489
  `));
5335
5490
  }
5491
+ const reservedParameters = await getReservedParametersForTask({
5492
+ tools,
5493
+ preparedPipeline,
5494
+ task: currentTask,
5495
+ pipelineIdentification,
5496
+ parameters: parametersToPass,
5497
+ isVerbose,
5498
+ });
5336
5499
  const definedParameters = Object.freeze({
5337
- ...(await getReservedParametersForTask({
5338
- tools,
5339
- preparedPipeline,
5340
- task: currentTask,
5341
- pipelineIdentification,
5342
- })),
5500
+ ...reservedParameters,
5343
5501
  ...parametersToPass,
5344
5502
  });
5345
5503
  const definedParameterNames = new Set(Object.keys(definedParameters));
@@ -5384,6 +5542,7 @@
5384
5542
  preparedPipeline,
5385
5543
  tools,
5386
5544
  $executionReport,
5545
+ onProgress,
5387
5546
  pipelineIdentification,
5388
5547
  maxExecutionAttempts,
5389
5548
  maxParallelCount,
@@ -5411,7 +5570,8 @@
5411
5570
  */
5412
5571
 
5413
5572
  /**
5414
- * @@@
5573
+ * Filters and returns only the output parameters from the provided pipeline execution options.
5574
+ * Adds warnings for any expected output parameters that are missing.
5415
5575
  *
5416
5576
  * @private internal utility of `createPipelineExecutor`
5417
5577
  */
@@ -5436,9 +5596,12 @@
5436
5596
  }
5437
5597
 
5438
5598
  /**
5439
- * @@@
5599
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5440
5600
  *
5441
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5601
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5602
+ *
5603
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5604
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5442
5605
  *
5443
5606
  * @private internal utility of `createPipelineExecutor`
5444
5607
  */
@@ -5761,10 +5924,27 @@
5761
5924
  cacheDirname,
5762
5925
  intermediateFilesStrategy,
5763
5926
  isAutoInstalled,
5927
+ }).catch((error) => {
5928
+ assertsError(error);
5929
+ return exportJson({
5930
+ name: 'pipelineExecutorResult',
5931
+ message: `Unuccessful PipelineExecutorResult, last catch`,
5932
+ order: [],
5933
+ value: {
5934
+ isSuccessful: false,
5935
+ errors: [serializeError(error)],
5936
+ warnings: [],
5937
+ usage: UNCERTAIN_USAGE,
5938
+ executionReport: null,
5939
+ outputParameters: {},
5940
+ preparedPipeline,
5941
+ },
5942
+ });
5764
5943
  });
5765
5944
  };
5766
5945
  const pipelineExecutor = (inputParameters) => createTask({
5767
5946
  taskType: 'EXECUTION',
5947
+ title: pipeline.title,
5768
5948
  taskProcessCallback(updateOngoingResult) {
5769
5949
  return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5770
5950
  updateOngoingResult(newOngoingResult);
@@ -5867,7 +6047,7 @@
5867
6047
  const knowledge = await Promise.all(
5868
6048
  // TODO: [🪂] Do not send all at once but in chunks
5869
6049
  knowledgeTextPieces.map(async (knowledgeTextPiece, i) => {
5870
- // Note: Theese are just default values, they will be overwritten by the actual values:
6050
+ // Note: These are just default values, they will be overwritten by the actual values:
5871
6051
  let name = `piece-${i}`;
5872
6052
  let title = spaceTrim__default["default"](knowledgeTextPiece.substring(0, 100));
5873
6053
  const knowledgePieceContent = spaceTrim__default["default"](knowledgeTextPiece);
@@ -6021,8 +6201,8 @@
6021
6201
  extension: 'md',
6022
6202
  isVerbose,
6023
6203
  });
6024
- // TODO: @@@ Preserve, delete or modify
6025
- // Note: Running Pandoc ONLY if the file in the cache does not exist
6204
+ // TODO: Determine if Markitdown conversion should run only if the cache file doesn't exist, or always.
6205
+ // Note: Running Markitdown conversion ONLY if the file in the cache does not exist
6026
6206
  if (!(await isFileExisting(cacheFilehandler.filename, this.tools.fs))) {
6027
6207
  const src = source.filename || source.url || null;
6028
6208
  // console.log('!!', { src, source, cacheFilehandler });
@@ -6044,11 +6224,11 @@
6044
6224
  return cacheFilehandler;
6045
6225
  }
6046
6226
  /**
6047
- * Scrapes the docx file and returns the knowledge pieces or `null` if it can't scrape it
6227
+ * Scrapes the source document (PDF, DOCX, etc.) and returns the knowledge pieces or `null` if it can't scrape it.
6048
6228
  */
6049
6229
  async scrape(source) {
6050
6230
  const cacheFilehandler = await this.$convert(source);
6051
- // TODO: @@@ Preserve, delete or modify
6231
+ // TODO: Ensure this correctly creates the source object for the internal MarkdownScraper using the converted file.
6052
6232
  const markdownSource = {
6053
6233
  source: source.source,
6054
6234
  filename: cacheFilehandler.filename,
@@ -6192,7 +6372,8 @@
6192
6372
  */
6193
6373
 
6194
6374
  /**
6195
- * @@@
6375
+ * Factory function to create an instance of PdfScraper.
6376
+ * It bundles the scraper class with its metadata.
6196
6377
  *
6197
6378
  * @public exported from `@promptbook/pdf`
6198
6379
  */