@promptbook/legacy-documents 0.92.0-9 → 0.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +140 -88
  2. package/esm/index.es.js +584 -403
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +26 -14
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -2
  7. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  8. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  9. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  10. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
  11. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  12. package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
  14. package/esm/typings/src/config.d.ts +41 -11
  15. package/esm/typings/src/constants.d.ts +43 -2
  16. package/esm/typings/src/conversion/parsePipeline.d.ts +2 -2
  17. package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
  18. package/esm/typings/src/errors/CollectionError.d.ts +1 -1
  19. package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
  20. package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
  21. package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
  22. package/esm/typings/src/executables/locateApp.d.ts +2 -2
  23. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
  24. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
  25. package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
  26. package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
  27. package/esm/typings/src/execution/CommonToolsOptions.d.ts +3 -3
  28. package/esm/typings/src/execution/ExecutionTask.d.ts +19 -1
  29. package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +2 -1
  30. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +4 -2
  31. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  32. package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
  33. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
  34. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +13 -10
  35. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +12 -9
  36. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
  37. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +21 -15
  38. package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
  39. package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
  40. package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
  41. package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
  42. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -9
  43. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +18 -5
  44. package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
  45. package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +1 -1
  46. package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
  47. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
  48. package/esm/typings/src/execution/utils/checkExpectations.d.ts +3 -3
  49. package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
  50. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +1 -1
  51. package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
  52. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
  53. package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
  54. package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
  55. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  56. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  57. package/esm/typings/src/formats/index.d.ts +2 -2
  58. package/esm/typings/src/formats/json/JsonFormatParser.d.ts +19 -0
  59. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  60. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
  61. package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
  62. package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
  63. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  64. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  65. package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
  66. package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
  67. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  68. package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
  69. package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
  70. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
  71. package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
  72. package/esm/typings/src/formfactors/index.d.ts +33 -8
  73. package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
  74. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  75. package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
  76. package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
  77. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
  78. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
  79. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
  80. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
  81. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +18 -5
  82. package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
  83. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +21 -42
  84. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
  85. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +13 -4
  86. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
  87. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +11 -3
  88. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  89. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
  90. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -0
  91. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  92. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  93. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -4
  94. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
  95. package/esm/typings/src/llm-providers/google/google-models.d.ts +1 -1
  96. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
  97. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  98. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
  99. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
  100. package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
  101. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  102. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  103. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  104. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  105. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  106. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  107. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +10 -7
  108. package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +1 -1
  109. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
  110. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  111. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  112. package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +1 -1
  113. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +2 -2
  114. package/esm/typings/src/prepare/prepareTasks.d.ts +8 -5
  115. package/esm/typings/src/remote-server/openapi.d.ts +1 -1
  116. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +1 -1
  117. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
  118. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +7 -6
  119. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  120. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  121. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  122. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  123. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  124. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  125. package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
  126. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  127. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  128. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  129. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  130. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  131. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  132. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  133. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  134. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  135. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  136. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  137. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  138. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  139. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  140. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  141. package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
  142. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  143. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  144. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  145. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  146. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  147. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  148. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +11 -0
  149. package/esm/typings/src/storage/local-storage/utils/IndexedDbStorageOptions.d.ts +14 -0
  150. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +8 -0
  151. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  152. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  153. package/esm/typings/src/types/ModelRequirements.d.ts +2 -2
  154. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  155. package/esm/typings/src/types/typeAliases.d.ts +22 -19
  156. package/esm/typings/src/utils/$Register.d.ts +8 -7
  157. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  158. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  159. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  160. package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +1 -1
  161. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  162. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  163. package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
  164. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  165. package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  166. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  167. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  168. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  169. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  170. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  171. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  172. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  173. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  174. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  175. package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
  176. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  177. package/esm/typings/src/utils/organization/just.d.ts +1 -1
  178. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  179. package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
  180. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  181. package/esm/typings/src/utils/removeQuotes.d.ts +2 -2
  182. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  183. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  184. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -1
  185. package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +1 -1
  186. package/esm/typings/src/utils/unwrapResult.d.ts +2 -2
  187. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  188. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  189. package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +1 -1
  190. package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +1 -1
  191. package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +1 -1
  192. package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -1
  193. package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +1 -1
  194. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -1
  195. package/esm/typings/src/version.d.ts +2 -1
  196. package/esm/typings/src/wizzard/wizzard.d.ts +1 -1
  197. package/package.json +15 -3
  198. package/umd/index.umd.js +584 -403
  199. package/umd/index.umd.js.map +1 -1
  200. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
  201. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  202. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +0 -19
  203. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
  204. /package/esm/typings/src/llm-providers/{multiple → _multiple}/MultipleLlmExecutionTools.d.ts +0 -0
  205. /package/esm/typings/src/llm-providers/{multiple → _multiple}/joinLlmExecutionTools.d.ts +0 -0
  206. /package/esm/typings/src/llm-providers/{multiple → _multiple}/playground/playground.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.93.0';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -38,7 +38,7 @@ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-9';
38
38
  * Just says that the variable is not used but should be kept
39
39
  * No side effects.
40
40
  *
41
- * Note: It can be usefull for:
41
+ * Note: It can be useful for:
42
42
  *
43
43
  * 1) Suppressing eager optimization of unused imports
44
44
  * 2) Suppressing eslint errors of unused variables in the tests
@@ -55,7 +55,7 @@ function keepUnused(...valuesToKeep) {
55
55
  * Returns the same value that is passed as argument.
56
56
  * No side effects.
57
57
  *
58
- * Note: It can be usefull for:
58
+ * Note: It can be useful for:
59
59
  *
60
60
  * 1) Leveling indentation
61
61
  * 2) Putting always-true or always-false conditions without getting eslint errors
@@ -104,6 +104,21 @@ const DEFAULT_BOOK_TITLE = `✨ Untitled Book`;
104
104
  * @public exported from `@promptbook/core`
105
105
  */
106
106
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
107
+ /**
108
+ * Threshold value that determines when a dataset is considered "big"
109
+ * and may require special handling or optimizations
110
+ *
111
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
112
+ *
113
+ * @public exported from `@promptbook/core`
114
+ */
115
+ const BIG_DATASET_TRESHOLD = 50;
116
+ /**
117
+ * Placeholder text used to represent a placeholder value of failed operation
118
+ *
119
+ * @public exported from `@promptbook/core`
120
+ */
121
+ const FAILED_VALUE_PLACEHOLDER = '!?';
107
122
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
108
123
  /**
109
124
  * The maximum number of iterations for a loops
@@ -183,7 +198,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
183
198
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
184
199
  // <- TODO: [🧜‍♂️]
185
200
  /**
186
- * @@@
201
+ * Default settings for parsing and generating CSV files in Promptbook.
187
202
  *
188
203
  * @public exported from `@promptbook/core`
189
204
  */
@@ -194,19 +209,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
194
209
  skipEmptyLines: true,
195
210
  });
196
211
  /**
197
- * @@@
212
+ * Controls whether verbose logging is enabled by default throughout the application.
198
213
  *
199
214
  * @public exported from `@promptbook/core`
200
215
  */
201
216
  let DEFAULT_IS_VERBOSE = false;
202
217
  /**
203
- * @@@
218
+ * Controls whether auto-installation of dependencies is enabled by default.
204
219
  *
205
220
  * @public exported from `@promptbook/core`
206
221
  */
207
222
  const DEFAULT_IS_AUTO_INSTALLED = false;
208
223
  /**
209
- * @@@
224
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
210
225
  *
211
226
  * @private within the repository
212
227
  */
@@ -255,7 +270,7 @@ class MissingToolsError extends Error {
255
270
  super(spaceTrim((block) => `
256
271
  ${block(message)}
257
272
 
258
- Note: You have probbably forgot to provide some tools for pipeline execution or preparation
273
+ Note: You have probably forgot to provide some tools for pipeline execution or preparation
259
274
 
260
275
  `));
261
276
  this.name = 'MissingToolsError';
@@ -318,7 +333,7 @@ class UnexpectedError extends Error {
318
333
  ${block(message)}
319
334
 
320
335
  Note: This error should not happen.
321
- It's probbably a bug in the pipeline collection
336
+ It's probably a bug in the pipeline collection
322
337
 
323
338
  Please report issue:
324
339
  ${block(getErrorReportUrl(new Error(message)).href)}
@@ -547,7 +562,8 @@ async function isFileExisting(filename, fs) {
547
562
  */
548
563
 
549
564
  /**
550
- * @@@
565
+ * Converts a name to a properly formatted subfolder path for cache storage.
566
+ * Handles normalization and path formatting to create consistent cache directory structures.
551
567
  *
552
568
  * @private for `FileCacheStorage`
553
569
  */
@@ -800,10 +816,10 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
800
816
  */
801
817
 
802
818
  /**
803
- * @@@
819
+ * Removes diacritic marks (accents) from characters in a string.
804
820
  *
805
- * @param input @@@
806
- * @returns @@@
821
+ * @param input The string containing diacritics to be normalized.
822
+ * @returns The string with diacritics removed or normalized.
807
823
  * @public exported from `@promptbook/utils`
808
824
  */
809
825
  function removeDiacritics(input) {
@@ -817,10 +833,10 @@ function removeDiacritics(input) {
817
833
  */
818
834
 
819
835
  /**
820
- * @@@
836
+ * Converts a given text to kebab-case format.
821
837
  *
822
- * @param text @@@
823
- * @returns @@@
838
+ * @param text The text to be converted.
839
+ * @returns The kebab-case formatted string.
824
840
  * @example 'hello-world'
825
841
  * @example 'i-love-promptbook'
826
842
  * @public exported from `@promptbook/utils`
@@ -936,7 +952,7 @@ function isValidFilePath(filename) {
936
952
  * Tests if given string is valid URL.
937
953
  *
938
954
  * Note: Dataurl are considered perfectly valid.
939
- * Note: There are two simmilar functions:
955
+ * Note: There are two similar functions:
940
956
  * - `isValidUrl` which tests any URL
941
957
  * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
942
958
  *
@@ -962,11 +978,11 @@ function isValidUrl(url) {
962
978
  }
963
979
 
964
980
  /**
965
- * @@@
981
+ * Converts a title string into a normalized name.
966
982
  *
967
- * @param value @@@
968
- * @returns @@@
969
- * @example @@@
983
+ * @param value The title string to be converted to a name.
984
+ * @returns A normalized name derived from the input title.
985
+ * @example 'Hello World!' -> 'hello-world'
970
986
  * @public exported from `@promptbook/utils`
971
987
  */
972
988
  function titleToName(value) {
@@ -986,9 +1002,8 @@ function titleToName(value) {
986
1002
  }
987
1003
 
988
1004
  /**
989
- * Create a filename for intermediate cache for scrapers
990
- *
991
- * Note: It also checks if directory exists and creates it if not
1005
+ * Retrieves an intermediate source for a scraper based on the knowledge source.
1006
+ * Manages the caching and retrieval of intermediate scraper results for optimized performance.
992
1007
  *
993
1008
  * @private as internal utility for scrapers
994
1009
  */
@@ -1124,7 +1139,7 @@ function assertsError(whatWasThrown) {
1124
1139
  * Function isValidJsonString will tell you if the string is valid JSON or not
1125
1140
  *
1126
1141
  * @param value The string to check
1127
- * @returns True if the string is a valid JSON string, false otherwise
1142
+ * @returns `true` if the string is a valid JSON string, false otherwise
1128
1143
  *
1129
1144
  * @public exported from `@promptbook/utils`
1130
1145
  */
@@ -1236,7 +1251,7 @@ function pipelineJsonToString(pipelineJson) {
1236
1251
  if (bookVersion !== `undefined`) {
1237
1252
  commands.push(`BOOK VERSION ${bookVersion}`);
1238
1253
  }
1239
- // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
1254
+ // TODO: [main] !!5 This increases size of the bundle and is probably not necessary
1240
1255
  pipelineString = prettifyMarkdown(pipelineString);
1241
1256
  for (const parameter of parameters.filter(({ isInput }) => isInput)) {
1242
1257
  commands.push(`INPUT PARAMETER ${taskParameterJsonToString(parameter)}`);
@@ -1535,8 +1550,12 @@ function checkSerializableAsJson(options) {
1535
1550
  */
1536
1551
 
1537
1552
  /**
1538
- * @@@
1553
+ * Creates a deep clone of the given object
1539
1554
  *
1555
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1556
+ *
1557
+ * @param objectValue The object to clone.
1558
+ * @returns A deep, writable clone of the input object.
1540
1559
  * @public exported from `@promptbook/utils`
1541
1560
  */
1542
1561
  function deepClone(objectValue) {
@@ -1618,13 +1637,13 @@ const ORDER_OF_PIPELINE_JSON = [
1618
1637
  */
1619
1638
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1620
1639
  /**
1621
- * @@@
1640
+ * Placeholder value indicating a parameter is missing its value.
1622
1641
  *
1623
1642
  * @private within the repository
1624
1643
  */
1625
1644
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1626
1645
  /**
1627
- * @@@
1646
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
1628
1647
  *
1629
1648
  * @private within the repository
1630
1649
  */
@@ -1669,7 +1688,7 @@ class PipelineLogicError extends Error {
1669
1688
  /**
1670
1689
  * Tests if given string is valid semantic version
1671
1690
  *
1672
- * Note: There are two simmilar functions:
1691
+ * Note: There are two similar functions:
1673
1692
  * - `isValidSemanticVersion` which tests any semantic version
1674
1693
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1675
1694
  *
@@ -1691,7 +1710,7 @@ function isValidSemanticVersion(version) {
1691
1710
  *
1692
1711
  * @see https://www.npmjs.com/package/promptbook?activeTab=versions
1693
1712
  * 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.
1694
- * Note: There are two simmilar functions:
1713
+ * Note: There are two similar functions:
1695
1714
  * - `isValidSemanticVersion` which tests any semantic version
1696
1715
  * - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
1697
1716
  *
@@ -1711,7 +1730,7 @@ function isValidPromptbookVersion(version) {
1711
1730
  /**
1712
1731
  * Tests if given string is valid pipeline URL URL.
1713
1732
  *
1714
- * Note: There are two simmilar functions:
1733
+ * Note: There are two similar functions:
1715
1734
  * - `isValidUrl` which tests any URL
1716
1735
  * - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
1717
1736
  *
@@ -1808,7 +1827,7 @@ function validatePipeline_InnerFunction(pipeline) {
1808
1827
  ${block(pipelineIdentification)}
1809
1828
  `));
1810
1829
  }
1811
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1830
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1812
1831
  if (!Array.isArray(pipeline.parameters)) {
1813
1832
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1814
1833
  throw new ParseError(spaceTrim((block) => `
@@ -1819,7 +1838,7 @@ function validatePipeline_InnerFunction(pipeline) {
1819
1838
  ${block(pipelineIdentification)}
1820
1839
  `));
1821
1840
  }
1822
- // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1841
+ // TODO: [🧠] Maybe do here some proper JSON-schema / ZOD checking
1823
1842
  if (!Array.isArray(pipeline.tasks)) {
1824
1843
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1825
1844
  throw new ParseError(spaceTrim((block) => `
@@ -2123,7 +2142,7 @@ class SimplePipelineCollection {
2123
2142
  /**
2124
2143
  * Constructs a pipeline collection from pipelines
2125
2144
  *
2126
- * @param pipelines @@@
2145
+ * @param pipelines Array of pipeline JSON objects to include in the collection
2127
2146
  *
2128
2147
  * Note: During the construction logic of all pipelines are validated
2129
2148
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -2253,7 +2272,7 @@ class PipelineExecutionError extends Error {
2253
2272
  super(message);
2254
2273
  this.name = 'PipelineExecutionError';
2255
2274
  // TODO: [🐙] DRY - Maybe $randomId
2256
- this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2275
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2257
2276
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
2258
2277
  }
2259
2278
  }
@@ -2269,15 +2288,18 @@ class PipelineExecutionError extends Error {
2269
2288
  * @public exported from `@promptbook/core`
2270
2289
  */
2271
2290
  function isPipelinePrepared(pipeline) {
2272
- // Note: Ignoring `pipeline.preparations` @@@
2273
- // Note: Ignoring `pipeline.knowledgePieces` @@@
2291
+ // Note: Ignoring `pipeline.preparations`
2292
+ // Note: Ignoring `pipeline.knowledgePieces`
2274
2293
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2294
+ // console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
2275
2295
  return false;
2276
2296
  }
2277
2297
  if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
2298
+ // console.log('Pipeline is not prepared because personas are not prepared', pipeline.personas);
2278
2299
  return false;
2279
2300
  }
2280
2301
  if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
2302
+ //console.log('Pipeline is not prepared because knowledge sources are not prepared', pipeline.knowledgeSources);
2281
2303
  return false;
2282
2304
  }
2283
2305
  /*
@@ -2298,75 +2320,6 @@ function isPipelinePrepared(pipeline) {
2298
2320
  * - [♨] Are tasks prepared
2299
2321
  */
2300
2322
 
2301
- /**
2302
- * Converts a JavaScript Object Notation (JSON) string into an object.
2303
- *
2304
- * Note: This is wrapper around `JSON.parse()` with better error and type handling
2305
- *
2306
- * @public exported from `@promptbook/utils`
2307
- */
2308
- function jsonParse(value) {
2309
- if (value === undefined) {
2310
- throw new Error(`Can not parse JSON from undefined value.`);
2311
- }
2312
- else if (typeof value !== 'string') {
2313
- console.error('Can not parse JSON from non-string value.', { text: value });
2314
- throw new Error(spaceTrim$1(`
2315
- Can not parse JSON from non-string value.
2316
-
2317
- The value type: ${typeof value}
2318
- See more in console.
2319
- `));
2320
- }
2321
- try {
2322
- return JSON.parse(value);
2323
- }
2324
- catch (error) {
2325
- if (!(error instanceof Error)) {
2326
- throw error;
2327
- }
2328
- throw new Error(spaceTrim$1((block) => `
2329
- ${block(error.message)}
2330
-
2331
- The JSON text:
2332
- ${block(value)}
2333
- `));
2334
- }
2335
- }
2336
- /**
2337
- * TODO: !!!! Use in Promptbook.studio
2338
- */
2339
-
2340
- /**
2341
- * Recursively converts JSON strings to JSON objects
2342
-
2343
- * @public exported from `@promptbook/utils`
2344
- */
2345
- function jsonStringsToJsons(object) {
2346
- if (object === null) {
2347
- return object;
2348
- }
2349
- if (Array.isArray(object)) {
2350
- return object.map(jsonStringsToJsons);
2351
- }
2352
- if (typeof object !== 'object') {
2353
- return object;
2354
- }
2355
- const newObject = { ...object };
2356
- for (const [key, value] of Object.entries(object)) {
2357
- if (typeof value === 'string' && isValidJsonString(value)) {
2358
- newObject[key] = jsonParse(value);
2359
- }
2360
- else {
2361
- newObject[key] = jsonStringsToJsons(value);
2362
- }
2363
- }
2364
- return newObject;
2365
- }
2366
- /**
2367
- * TODO: Type the return type correctly
2368
- */
2369
-
2370
2323
  /**
2371
2324
  * This error indicates problems parsing the format value
2372
2325
  *
@@ -2411,7 +2364,7 @@ class AuthenticationError extends Error {
2411
2364
  }
2412
2365
 
2413
2366
  /**
2414
- * This error indicates that the pipeline collection cannot be propperly loaded
2367
+ * This error indicates that the pipeline collection cannot be properly loaded
2415
2368
  *
2416
2369
  * @public exported from `@promptbook/core`
2417
2370
  */
@@ -2550,6 +2503,101 @@ const ALL_ERRORS = {
2550
2503
  * Note: [💞] Ignore a discrepancy between file name and entity name
2551
2504
  */
2552
2505
 
2506
+ /**
2507
+ * Serializes an error into a [🚉] JSON-serializable object
2508
+ *
2509
+ * @public exported from `@promptbook/utils`
2510
+ */
2511
+ function serializeError(error) {
2512
+ const { name, message, stack } = error;
2513
+ const { id } = error;
2514
+ if (!Object.keys(ALL_ERRORS).includes(name)) {
2515
+ console.error(spaceTrim$1((block) => `
2516
+
2517
+ Cannot serialize error with name "${name}"
2518
+
2519
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2520
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2521
+
2522
+
2523
+ ${block(stack || message)}
2524
+
2525
+ `));
2526
+ }
2527
+ return {
2528
+ name: name,
2529
+ message,
2530
+ stack,
2531
+ id, // Include id in the serialized object
2532
+ };
2533
+ }
2534
+
2535
+ /**
2536
+ * Converts a JavaScript Object Notation (JSON) string into an object.
2537
+ *
2538
+ * Note: This is wrapper around `JSON.parse()` with better error and type handling
2539
+ *
2540
+ * @public exported from `@promptbook/utils`
2541
+ */
2542
+ function jsonParse(value) {
2543
+ if (value === undefined) {
2544
+ throw new Error(`Can not parse JSON from undefined value.`);
2545
+ }
2546
+ else if (typeof value !== 'string') {
2547
+ console.error('Can not parse JSON from non-string value.', { text: value });
2548
+ throw new Error(spaceTrim$1(`
2549
+ Can not parse JSON from non-string value.
2550
+
2551
+ The value type: ${typeof value}
2552
+ See more in console.
2553
+ `));
2554
+ }
2555
+ try {
2556
+ return JSON.parse(value);
2557
+ }
2558
+ catch (error) {
2559
+ if (!(error instanceof Error)) {
2560
+ throw error;
2561
+ }
2562
+ throw new Error(spaceTrim$1((block) => `
2563
+ ${block(error.message)}
2564
+
2565
+ The JSON text:
2566
+ ${block(value)}
2567
+ `));
2568
+ }
2569
+ }
2570
+
2571
+ /**
2572
+ * Recursively converts JSON strings to JSON objects
2573
+
2574
+ * @public exported from `@promptbook/utils`
2575
+ */
2576
+ function jsonStringsToJsons(object) {
2577
+ if (object === null) {
2578
+ return object;
2579
+ }
2580
+ if (Array.isArray(object)) {
2581
+ return object.map(jsonStringsToJsons);
2582
+ }
2583
+ if (typeof object !== 'object') {
2584
+ return object;
2585
+ }
2586
+ const newObject = { ...object };
2587
+ for (const [key, value] of Object.entries(object)) {
2588
+ if (typeof value === 'string' && isValidJsonString(value)) {
2589
+ newObject[key] = jsonParse(value);
2590
+ }
2591
+ else {
2592
+ newObject[key] = jsonStringsToJsons(value);
2593
+ }
2594
+ }
2595
+ return newObject;
2596
+ }
2597
+ /**
2598
+ * TODO: Type the return type correctly
2599
+ */
2600
+
2553
2601
  /**
2554
2602
  * Deserializes the error object
2555
2603
  *
@@ -2624,8 +2672,9 @@ function assertsTaskSuccessful(executionResult) {
2624
2672
  */
2625
2673
  function createTask(options) {
2626
2674
  const { taskType, taskProcessCallback } = options;
2675
+ let { title } = options;
2627
2676
  // TODO: [🐙] DRY
2628
- const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2677
+ const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
2629
2678
  let status = 'RUNNING';
2630
2679
  const createdAt = new Date();
2631
2680
  let updatedAt = createdAt;
@@ -2635,6 +2684,10 @@ function createTask(options) {
2635
2684
  const partialResultSubject = new Subject();
2636
2685
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2637
2686
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2687
+ if (newOngoingResult.title) {
2688
+ title = newOngoingResult.title;
2689
+ }
2690
+ updatedAt = new Date();
2638
2691
  Object.assign(currentValue, newOngoingResult);
2639
2692
  // <- TODO: assign deep
2640
2693
  partialResultSubject.next(newOngoingResult);
@@ -2680,17 +2733,24 @@ function createTask(options) {
2680
2733
  return {
2681
2734
  taskType,
2682
2735
  taskId,
2736
+ get promptbookVersion() {
2737
+ return PROMPTBOOK_ENGINE_VERSION;
2738
+ },
2739
+ get title() {
2740
+ return title;
2741
+ // <- Note: [1] These must be getters to allow changing the value in the future
2742
+ },
2683
2743
  get status() {
2684
2744
  return status;
2685
- // <- Note: [1] Theese must be getters to allow changing the value in the future
2745
+ // <- Note: [1] --||--
2686
2746
  },
2687
2747
  get createdAt() {
2688
2748
  return createdAt;
2689
- // <- Note: [1]
2749
+ // <- Note: [1] --||--
2690
2750
  },
2691
2751
  get updatedAt() {
2692
2752
  return updatedAt;
2693
- // <- Note: [1]
2753
+ // <- Note: [1] --||--
2694
2754
  },
2695
2755
  asPromise,
2696
2756
  asObservable() {
@@ -2698,15 +2758,15 @@ function createTask(options) {
2698
2758
  },
2699
2759
  get errors() {
2700
2760
  return errors;
2701
- // <- Note: [1]
2761
+ // <- Note: [1] --||--
2702
2762
  },
2703
2763
  get warnings() {
2704
2764
  return warnings;
2705
- // <- Note: [1]
2765
+ // <- Note: [1] --||--
2706
2766
  },
2707
2767
  get currentValue() {
2708
2768
  return currentValue;
2709
- // <- Note: [1]
2769
+ // <- Note: [1] --||--
2710
2770
  },
2711
2771
  };
2712
2772
  }
@@ -2715,64 +2775,6 @@ function createTask(options) {
2715
2775
  * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
2716
2776
  */
2717
2777
 
2718
- /**
2719
- * Serializes an error into a [🚉] JSON-serializable object
2720
- *
2721
- * @public exported from `@promptbook/utils`
2722
- */
2723
- function serializeError(error) {
2724
- const { name, message, stack } = error;
2725
- const { id } = error;
2726
- if (!Object.keys(ALL_ERRORS).includes(name)) {
2727
- console.error(spaceTrim$1((block) => `
2728
-
2729
- Cannot serialize error with name "${name}"
2730
-
2731
- Authors of Promptbook probably forgot to add this error into the list of errors:
2732
- https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2733
-
2734
-
2735
- ${block(stack || message)}
2736
-
2737
- `));
2738
- }
2739
- return {
2740
- name: name,
2741
- message,
2742
- stack,
2743
- id, // Include id in the serialized object
2744
- };
2745
- }
2746
-
2747
- /**
2748
- * Async version of Array.forEach
2749
- *
2750
- * @param array - Array to iterate over
2751
- * @param options - Options for the function
2752
- * @param callbackfunction - Function to call for each item
2753
- * @public exported from `@promptbook/utils`
2754
- * @deprecated [🪂] Use queues instead
2755
- */
2756
- async function forEachAsync(array, options, callbackfunction) {
2757
- const { maxParallelCount = Infinity } = options;
2758
- let index = 0;
2759
- let runningTasks = [];
2760
- const tasks = [];
2761
- for (const item of array) {
2762
- const currentIndex = index++;
2763
- const task = callbackfunction(item, currentIndex, array);
2764
- tasks.push(task);
2765
- runningTasks.push(task);
2766
- /* not await */ Promise.resolve(task).then(() => {
2767
- runningTasks = runningTasks.filter((t) => t !== task);
2768
- });
2769
- if (maxParallelCount < runningTasks.length) {
2770
- await Promise.race(runningTasks);
2771
- }
2772
- }
2773
- await Promise.all(tasks);
2774
- }
2775
-
2776
2778
  /**
2777
2779
  * Represents the uncertain value
2778
2780
  *
@@ -2816,7 +2818,7 @@ const ZERO_USAGE = $deepFreeze({
2816
2818
  *
2817
2819
  * @public exported from `@promptbook/core`
2818
2820
  */
2819
- $deepFreeze({
2821
+ const UNCERTAIN_USAGE = $deepFreeze({
2820
2822
  price: UNCERTAIN_ZERO_VALUE,
2821
2823
  input: {
2822
2824
  tokensCount: UNCERTAIN_ZERO_VALUE,
@@ -2841,6 +2843,35 @@ $deepFreeze({
2841
2843
  * Note: [💞] Ignore a discrepancy between file name and entity name
2842
2844
  */
2843
2845
 
2846
+ /**
2847
+ * Async version of Array.forEach
2848
+ *
2849
+ * @param array - Array to iterate over
2850
+ * @param options - Options for the function
2851
+ * @param callbackfunction - Function to call for each item
2852
+ * @public exported from `@promptbook/utils`
2853
+ * @deprecated [🪂] Use queues instead
2854
+ */
2855
+ async function forEachAsync(array, options, callbackfunction) {
2856
+ const { maxParallelCount = Infinity } = options;
2857
+ let index = 0;
2858
+ let runningTasks = [];
2859
+ const tasks = [];
2860
+ for (const item of array) {
2861
+ const currentIndex = index++;
2862
+ const task = callbackfunction(item, currentIndex, array);
2863
+ tasks.push(task);
2864
+ runningTasks.push(task);
2865
+ /* not await */ Promise.resolve(task).then(() => {
2866
+ runningTasks = runningTasks.filter((t) => t !== task);
2867
+ });
2868
+ if (maxParallelCount < runningTasks.length) {
2869
+ await Promise.race(runningTasks);
2870
+ }
2871
+ }
2872
+ await Promise.all(tasks);
2873
+ }
2874
+
2844
2875
  /**
2845
2876
  * Function `addUsage` will add multiple usages into one
2846
2877
  *
@@ -2900,12 +2931,14 @@ function countUsage(llmTools) {
2900
2931
  const spending = new Subject();
2901
2932
  const proxyTools = {
2902
2933
  get title() {
2903
- // TODO: [🧠] Maybe put here some suffix
2904
- return llmTools.title;
2934
+ return `${llmTools.title} (+usage)`;
2935
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2936
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2905
2937
  },
2906
2938
  get description() {
2907
- // TODO: [🧠] Maybe put here some suffix
2908
- return llmTools.description;
2939
+ return `${llmTools.description} (+usage)`;
2940
+ // <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
2941
+ // <- TODO: [🧈][🧠] Does it make sence to suffix "(+usage)"?
2909
2942
  },
2910
2943
  checkConfiguration() {
2911
2944
  return /* not await */ llmTools.checkConfiguration();
@@ -2976,29 +3009,40 @@ class MultipleLlmExecutionTools {
2976
3009
  return 'Multiple LLM Providers';
2977
3010
  }
2978
3011
  get description() {
2979
- return this.llmExecutionTools.map(({ title }, index) => `${index + 1}) \`${title}\``).join('\n');
3012
+ const innerModelsTitlesAndDescriptions = this.llmExecutionTools
3013
+ .map(({ title, description }, index) => {
3014
+ const headLine = `${index + 1}) \`${title}\``;
3015
+ if (description === undefined) {
3016
+ return headLine;
3017
+ }
3018
+ return spaceTrim$1((block) => `
3019
+ ${headLine}
3020
+
3021
+ ${ /* <- Note: Indenting the description: */block(description)}
3022
+ `);
3023
+ })
3024
+ .join('\n\n');
3025
+ return spaceTrim$1((block) => `
3026
+ Multiple LLM Providers:
3027
+
3028
+ ${block(innerModelsTitlesAndDescriptions)}
3029
+ `);
2980
3030
  }
2981
3031
  /**
2982
3032
  * Check the configuration of all execution tools
2983
3033
  */
2984
3034
  async checkConfiguration() {
2985
- // TODO: Maybe do it in parallel
2986
- for (const llmExecutionTools of this.llmExecutionTools) {
2987
- await llmExecutionTools.checkConfiguration();
2988
- }
3035
+ // Note: Run checks in parallel
3036
+ await Promise.all(this.llmExecutionTools.map((tools) => tools.checkConfiguration()));
2989
3037
  }
2990
3038
  /**
2991
3039
  * List all available models that can be used
2992
3040
  * This lists is a combination of all available models from all execution tools
2993
3041
  */
2994
3042
  async listModels() {
2995
- const availableModels = [];
2996
- for (const llmExecutionTools of this.llmExecutionTools) {
2997
- // TODO: [🪂] Obtain models in parallel
2998
- const models = await llmExecutionTools.listModels();
2999
- availableModels.push(...models);
3000
- }
3001
- return availableModels;
3043
+ // Obtain all models in parallel and flatten
3044
+ const modelArrays = await Promise.all(this.llmExecutionTools.map((tools) => tools.listModels()));
3045
+ return modelArrays.flat();
3002
3046
  }
3003
3047
  /**
3004
3048
  * Calls the best available chat model
@@ -3239,7 +3283,8 @@ async function preparePersona(personaDescription, tools, options) {
3239
3283
  */
3240
3284
 
3241
3285
  /**
3242
- * @@@
3286
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3287
+ * regardless of the JavaScript environment in which the code is running
3243
3288
  *
3244
3289
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3245
3290
  *
@@ -3250,10 +3295,10 @@ function $getGlobalScope() {
3250
3295
  }
3251
3296
 
3252
3297
  /**
3253
- * @@@
3298
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
3254
3299
  *
3255
- * @param text @@@
3256
- * @returns @@@
3300
+ * @param text The text string to be converted to SCREAMING_CASE format.
3301
+ * @returns The normalized text in SCREAMING_CASE format.
3257
3302
  * @example 'HELLO_WORLD'
3258
3303
  * @example 'I_LOVE_PROMPTBOOK'
3259
3304
  * @public exported from `@promptbook/utils`
@@ -3305,10 +3350,10 @@ function normalizeTo_SCREAMING_CASE(text) {
3305
3350
  */
3306
3351
 
3307
3352
  /**
3308
- * @@@
3353
+ * Normalizes a text string to snake_case format.
3309
3354
  *
3310
- * @param text @@@
3311
- * @returns @@@
3355
+ * @param text The text string to be converted to snake_case format.
3356
+ * @returns The normalized text in snake_case format.
3312
3357
  * @example 'hello_world'
3313
3358
  * @example 'i_love_promptbook'
3314
3359
  * @public exported from `@promptbook/utils`
@@ -3318,11 +3363,11 @@ function normalizeTo_snake_case(text) {
3318
3363
  }
3319
3364
 
3320
3365
  /**
3321
- * Register is @@@
3366
+ * Global registry for storing and managing registered entities of a given type.
3322
3367
  *
3323
3368
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3324
3369
  *
3325
- * @private internal utility, exported are only signleton instances of this class
3370
+ * @private internal utility, exported are only singleton instances of this class
3326
3371
  */
3327
3372
  class $Register {
3328
3373
  constructor(registerName) {
@@ -3366,10 +3411,10 @@ class $Register {
3366
3411
  }
3367
3412
 
3368
3413
  /**
3369
- * @@@
3414
+ * Global registry for storing metadata about all available scrapers and converters.
3370
3415
  *
3371
- * Note: `$` is used to indicate that this interacts with the global scope
3372
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3416
+ * Note: `$` is used to indicate that this interacts with the global scope.
3417
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3373
3418
  * @public exported from `@promptbook/core`
3374
3419
  */
3375
3420
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -3378,10 +3423,11 @@ const $scrapersMetadataRegister = new $Register('scrapers_metadata');
3378
3423
  */
3379
3424
 
3380
3425
  /**
3381
- * @@@
3426
+ * Registry for all available scrapers in the system.
3427
+ * Central point for registering and accessing different types of content scrapers.
3382
3428
  *
3383
3429
  * Note: `$` is used to indicate that this interacts with the global scope
3384
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3430
+ * @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
3385
3431
  * @public exported from `@promptbook/core`
3386
3432
  */
3387
3433
  const $scrapersRegister = new $Register('scraper_constructors');
@@ -3549,7 +3595,9 @@ const promptbookFetch = async (urlOrRequest, init) => {
3549
3595
  */
3550
3596
 
3551
3597
  /**
3552
- * @@@
3598
+ * Factory function that creates a handler for processing knowledge sources.
3599
+ * Provides standardized processing of different types of knowledge sources
3600
+ * across various scraper implementations.
3553
3601
  *
3554
3602
  * @public exported from `@promptbook/core`
3555
3603
  */
@@ -3688,7 +3736,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3688
3736
  }
3689
3737
 
3690
3738
  /**
3691
- * Prepares the knowle
3739
+ * Prepares the knowledge pieces
3692
3740
  *
3693
3741
  * @see https://github.com/webgptorg/promptbook/discussions/41
3694
3742
  * @public exported from `@promptbook/core`
@@ -3784,15 +3832,18 @@ TODO: [🧊] This is how it can look in future
3784
3832
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
3785
3833
  * Put `knowledgePieces` into `PrepareKnowledgeOptions`
3786
3834
  * TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
3787
- * TODO: [🧠][❎] Do here propper M:N mapping
3835
+ * TODO: [🧠][❎] Do here proper M:N mapping
3788
3836
  * [x] One source can make multiple pieces
3789
3837
  * [ ] One piece can have multiple sources
3790
3838
  */
3791
3839
 
3792
3840
  /**
3793
- * @@@
3841
+ * Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
3794
3842
  *
3795
- * @public exported from `@promptbook/core`
3843
+ * @param tasks Sequence of tasks that are chained together to form a pipeline
3844
+ * @returns A promise that resolves to the prepared tasks.
3845
+ *
3846
+ * @private internal utility of `preparePipeline`
3796
3847
  */
3797
3848
  async function prepareTasks(pipeline, tools, options) {
3798
3849
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
@@ -3830,7 +3881,7 @@ async function prepareTasks(pipeline, tools, options) {
3830
3881
  return { tasksPrepared };
3831
3882
  }
3832
3883
  /**
3833
- * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3884
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, similar thing with expectations to sync high-level abstractions
3834
3885
  * TODO: [🧠] Add context to each task (if missing)
3835
3886
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3836
3887
  * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
@@ -3966,7 +4017,7 @@ async function preparePipeline(pipeline, tools, options) {
3966
4017
  order: ORDER_OF_PIPELINE_JSON,
3967
4018
  value: {
3968
4019
  ...pipeline,
3969
- // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
4020
+ // <- TODO: Probably deeply clone the pipeline because `$exportJson` freezes the subobjects
3970
4021
  title,
3971
4022
  knowledgeSources: knowledgeSourcesPrepared,
3972
4023
  knowledgePieces: knowledgePiecesPrepared,
@@ -4229,7 +4280,7 @@ function union(...sets) {
4229
4280
  }
4230
4281
 
4231
4282
  /**
4232
- * @@@
4283
+ * Contains configuration options for parsing and generating CSV files, such as delimiters and quoting rules.
4233
4284
  *
4234
4285
  * @public exported from `@promptbook/core`
4235
4286
  */
@@ -4238,11 +4289,29 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
4238
4289
  // encoding: 'utf-8',
4239
4290
  });
4240
4291
 
4292
+ /**
4293
+ * Converts a CSV string into an object
4294
+ *
4295
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
4296
+ *
4297
+ * @private - for now until `@promptbook/csv` is released
4298
+ */
4299
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
4300
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
4301
+ // Note: Autoheal invalid '\n' characters
4302
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
4303
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
4304
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
4305
+ }
4306
+ const csv = parse(value, settings);
4307
+ return csv;
4308
+ }
4309
+
4241
4310
  /**
4242
4311
  * Function to check if a string is valid CSV
4243
4312
  *
4244
4313
  * @param value The string to check
4245
- * @returns True if the string is a valid CSV string, false otherwise
4314
+ * @returns `true` if the string is a valid CSV string, false otherwise
4246
4315
  *
4247
4316
  * @public exported from `@promptbook/utils`
4248
4317
  */
@@ -4266,7 +4335,7 @@ function isValidCsvString(value) {
4266
4335
  * @public exported from `@promptbook/core`
4267
4336
  * <- TODO: [🏢] Export from package `@promptbook/csv`
4268
4337
  */
4269
- const CsvFormatDefinition = {
4338
+ const CsvFormatParser = {
4270
4339
  formatName: 'CSV',
4271
4340
  aliases: ['SPREADSHEET', 'TABLE'],
4272
4341
  isValid(value, settings, schema) {
@@ -4278,12 +4347,12 @@ const CsvFormatDefinition = {
4278
4347
  heal(value, settings, schema) {
4279
4348
  throw new Error('Not implemented');
4280
4349
  },
4281
- subvalueDefinitions: [
4350
+ subvalueParsers: [
4282
4351
  {
4283
4352
  subvalueName: 'ROW',
4284
- async mapValues(value, outputParameterName, settings, mapCallback) {
4285
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4286
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4353
+ async mapValues(options) {
4354
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4355
+ const csv = csvParse(value, settings);
4287
4356
  if (csv.errors.length !== 0) {
4288
4357
  throw new CsvFormatError(spaceTrim$1((block) => `
4289
4358
  CSV parsing error
@@ -4298,23 +4367,37 @@ const CsvFormatDefinition = {
4298
4367
  ${block(value)}
4299
4368
  `));
4300
4369
  }
4301
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4370
+ const mappedData = [];
4371
+ const length = csv.data.length;
4372
+ for (let index = 0; index < length; index++) {
4373
+ const row = csv.data[index];
4302
4374
  if (row[outputParameterName]) {
4303
4375
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4304
4376
  }
4305
- return {
4377
+ const mappedRow = {
4306
4378
  ...row,
4307
- [outputParameterName]: await mapCallback(row, index),
4379
+ [outputParameterName]: await mapCallback(row, index, length),
4308
4380
  };
4309
- }));
4381
+ mappedData.push(mappedRow);
4382
+ if (onProgress) {
4383
+ // Note: Report the CSV with all rows mapped so far
4384
+ /*
4385
+ // TODO: [🛕] Report progress with all the rows including the pending ones
4386
+ const progressData = mappedData.map((row, i) =>
4387
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4388
+ );
4389
+ */
4390
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4391
+ }
4392
+ }
4310
4393
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4311
4394
  },
4312
4395
  },
4313
4396
  {
4314
4397
  subvalueName: 'CELL',
4315
- async mapValues(value, outputParameterName, settings, mapCallback) {
4316
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
4317
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
4398
+ async mapValues(options) {
4399
+ const { value, settings, mapCallback, onProgress } = options;
4400
+ const csv = csvParse(value, settings);
4318
4401
  if (csv.errors.length !== 0) {
4319
4402
  throw new CsvFormatError(spaceTrim$1((block) => `
4320
4403
  CSV parsing error
@@ -4330,9 +4413,9 @@ const CsvFormatDefinition = {
4330
4413
  `));
4331
4414
  }
4332
4415
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4333
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4416
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4334
4417
  const index = rowIndex * Object.keys(row).length + columnIndex;
4335
- return /* not await */ mapCallback({ [key]: value }, index);
4418
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4336
4419
  }));
4337
4420
  }));
4338
4421
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4341,10 +4424,10 @@ const CsvFormatDefinition = {
4341
4424
  ],
4342
4425
  };
4343
4426
  /**
4344
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
4345
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
4346
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
4347
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
4427
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
4428
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
4429
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
4430
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
4348
4431
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4349
4432
  */
4350
4433
 
@@ -4353,7 +4436,7 @@ const CsvFormatDefinition = {
4353
4436
  *
4354
4437
  * @private still in development [🏢]
4355
4438
  */
4356
- const JsonFormatDefinition = {
4439
+ const JsonFormatParser = {
4357
4440
  formatName: 'JSON',
4358
4441
  mimeType: 'application/json',
4359
4442
  isValid(value, settings, schema) {
@@ -4365,28 +4448,28 @@ const JsonFormatDefinition = {
4365
4448
  heal(value, settings, schema) {
4366
4449
  throw new Error('Not implemented');
4367
4450
  },
4368
- subvalueDefinitions: [],
4451
+ subvalueParsers: [],
4369
4452
  };
4370
4453
  /**
4371
- * TODO: [🧠] Maybe propper instance of object
4454
+ * TODO: [🧠] Maybe proper instance of object
4372
4455
  * TODO: [0] Make string_serialized_json
4373
4456
  * TODO: [1] Make type for JSON Settings and Schema
4374
4457
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
4375
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
4376
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
4377
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
4378
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
4458
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
4459
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
4460
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
4461
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
4379
4462
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
4380
4463
  */
4381
4464
 
4382
4465
  /**
4383
4466
  * Definition for any text - this will be always valid
4384
4467
  *
4385
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
4468
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
4386
4469
  *
4387
4470
  * @public exported from `@promptbook/core`
4388
4471
  */
4389
- const TextFormatDefinition = {
4472
+ const TextFormatParser = {
4390
4473
  formatName: 'TEXT',
4391
4474
  isValid(value) {
4392
4475
  return typeof value === 'string';
@@ -4395,19 +4478,20 @@ const TextFormatDefinition = {
4395
4478
  return typeof partialValue === 'string';
4396
4479
  },
4397
4480
  heal() {
4398
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
4481
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
4399
4482
  },
4400
- subvalueDefinitions: [
4483
+ subvalueParsers: [
4401
4484
  {
4402
4485
  subvalueName: 'LINE',
4403
- async mapValues(value, outputParameterName, settings, mapCallback) {
4486
+ async mapValues(options) {
4487
+ const { value, mapCallback, onProgress } = options;
4404
4488
  const lines = value.split('\n');
4405
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4489
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4406
4490
  // TODO: [🧠] Maybe option to skip empty line
4407
4491
  /* not await */ mapCallback({
4408
4492
  lineContent,
4409
4493
  // TODO: [🧠] Maybe also put here `lineNumber`
4410
- }, lineNumber)));
4494
+ }, lineNumber, array.length)));
4411
4495
  return mappedLines.join('\n');
4412
4496
  },
4413
4497
  },
@@ -4417,10 +4501,10 @@ const TextFormatDefinition = {
4417
4501
  /**
4418
4502
  * TODO: [1] Make type for XML Text and Schema
4419
4503
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
4420
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
4421
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
4422
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
4423
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
4504
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
4505
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
4506
+ * TODO: [🍓] In `TextFormatParser` implement `heal
4507
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
4424
4508
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
4425
4509
  */
4426
4510
 
@@ -4428,7 +4512,7 @@ const TextFormatDefinition = {
4428
4512
  * Function to check if a string is valid XML
4429
4513
  *
4430
4514
  * @param value
4431
- * @returns True if the string is a valid XML string, false otherwise
4515
+ * @returns `true` if the string is a valid XML string, false otherwise
4432
4516
  *
4433
4517
  * @public exported from `@promptbook/utils`
4434
4518
  */
@@ -4453,7 +4537,7 @@ function isValidXmlString(value) {
4453
4537
  *
4454
4538
  * @private still in development [🏢]
4455
4539
  */
4456
- const XmlFormatDefinition = {
4540
+ const XmlFormatParser = {
4457
4541
  formatName: 'XML',
4458
4542
  mimeType: 'application/xml',
4459
4543
  isValid(value, settings, schema) {
@@ -4465,17 +4549,17 @@ const XmlFormatDefinition = {
4465
4549
  heal(value, settings, schema) {
4466
4550
  throw new Error('Not implemented');
4467
4551
  },
4468
- subvalueDefinitions: [],
4552
+ subvalueParsers: [],
4469
4553
  };
4470
4554
  /**
4471
- * TODO: [🧠] Maybe propper instance of object
4555
+ * TODO: [🧠] Maybe proper instance of object
4472
4556
  * TODO: [0] Make string_serialized_xml
4473
4557
  * TODO: [1] Make type for XML Settings and Schema
4474
4558
  * TODO: [🧠] What to use for validating XMLs - XSD,...
4475
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
4476
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
4477
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
4478
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
4559
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
4560
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
4561
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
4562
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
4479
4563
  * TODO: [🏢] Allow to expect something inside XML and other formats
4480
4564
  */
4481
4565
 
@@ -4484,24 +4568,19 @@ const XmlFormatDefinition = {
4484
4568
  *
4485
4569
  * @private internal index of `...` <- TODO [🏢]
4486
4570
  */
4487
- const FORMAT_DEFINITIONS = [
4488
- JsonFormatDefinition,
4489
- XmlFormatDefinition,
4490
- TextFormatDefinition,
4491
- CsvFormatDefinition,
4492
- ];
4571
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
4493
4572
  /**
4494
4573
  * Note: [💞] Ignore a discrepancy between file name and entity name
4495
4574
  */
4496
4575
 
4497
4576
  /**
4498
- * Maps available parameters to expected parameters
4577
+ * Maps available parameters to expected parameters for a pipeline task.
4499
4578
  *
4500
4579
  * The strategy is:
4501
- * 1) @@@
4502
- * 2) @@@
4580
+ * 1) First, match parameters by name where both available and expected.
4581
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4503
4582
  *
4504
- * @throws {PipelineExecutionError} @@@
4583
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4505
4584
  * @private within the repository used in `createPipelineExecutor`
4506
4585
  */
4507
4586
  function mapAvailableToExpectedParameters(options) {
@@ -4524,7 +4603,7 @@ function mapAvailableToExpectedParameters(options) {
4524
4603
  else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
4525
4604
  }
4526
4605
  if (expectedParameterNames.size === 0) {
4527
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4606
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4528
4607
  Object.freeze(mappedParameters);
4529
4608
  return mappedParameters;
4530
4609
  }
@@ -4555,7 +4634,7 @@ function mapAvailableToExpectedParameters(options) {
4555
4634
  for (let i = 0; i < expectedParameterNames.size; i++) {
4556
4635
  mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
4557
4636
  }
4558
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4637
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4559
4638
  Object.freeze(mappedParameters);
4560
4639
  return mappedParameters;
4561
4640
  }
@@ -4563,8 +4642,8 @@ function mapAvailableToExpectedParameters(options) {
4563
4642
  /**
4564
4643
  * Extracts all code blocks from markdown.
4565
4644
  *
4566
- * Note: There are multiple simmilar function:
4567
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4645
+ * Note: There are multiple similar functions:
4646
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
4568
4647
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4569
4648
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
4570
4649
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
@@ -4614,7 +4693,7 @@ function extractAllBlocksFromMarkdown(markdown) {
4614
4693
  if (currentCodeBlock.content !== '') {
4615
4694
  currentCodeBlock.content += '\n';
4616
4695
  }
4617
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
4696
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
4618
4697
  }
4619
4698
  }
4620
4699
  if (currentCodeBlock !== null) {
@@ -4634,7 +4713,7 @@ function extractAllBlocksFromMarkdown(markdown) {
4634
4713
  * - When there are multiple JSON code blocks the function throws a `ParseError`
4635
4714
  *
4636
4715
  * Note: It is not important if marked as ```json BUT if it is VALID JSON
4637
- * Note: There are multiple simmilar function:
4716
+ * Note: There are multiple similar function:
4638
4717
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
4639
4718
  * - `extractJsonBlock` extracts exactly one valid JSON code block
4640
4719
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
@@ -4659,7 +4738,7 @@ function extractJsonBlock(markdown) {
4659
4738
  }
4660
4739
  /**
4661
4740
  * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
4662
- * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
4741
+ * TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
4663
4742
  */
4664
4743
 
4665
4744
  /**
@@ -4861,14 +4940,14 @@ const CountUtils = {
4861
4940
  PAGES: countPages,
4862
4941
  };
4863
4942
  /**
4864
- * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
4943
+ * TODO: [🧠][🤠] This should be probably as part of `TextFormatParser`
4865
4944
  * Note: [💞] Ignore a discrepancy between file name and entity name
4866
4945
  */
4867
4946
 
4868
4947
  /**
4869
4948
  * Function checkExpectations will check if the expectations on given value are met
4870
4949
  *
4871
- * Note: There are two simmilar functions:
4950
+ * Note: There are two similar functions:
4872
4951
  * - `checkExpectations` which throws an error if the expectations are not met
4873
4952
  * - `isPassingExpectations` which returns a boolean
4874
4953
  *
@@ -4889,13 +4968,17 @@ function checkExpectations(expectations, value) {
4889
4968
  }
4890
4969
  /**
4891
4970
  * TODO: [💝] Unite object for expecting amount and format
4892
- * TODO: [🧠][🤠] This should be part of `TextFormatDefinition`
4971
+ * TODO: [🧠][🤠] This should be part of `TextFormatParser`
4893
4972
  * Note: [💝] and [🤠] are interconnected together
4894
4973
  */
4895
4974
 
4896
4975
  /**
4897
- * @@@
4976
+ * Executes a pipeline task with multiple attempts, including joker and retry logic. Handles different task types
4977
+ * (prompt, script, dialog, etc.), applies postprocessing, checks expectations, and updates the execution report.
4978
+ * Throws errors if execution fails after all attempts.
4898
4979
  *
4980
+ * @param options - The options for execution, including task, parameters, pipeline, and configuration.
4981
+ * @returns The result string of the executed task.
4899
4982
  * @private internal utility of `createPipelineExecutor`
4900
4983
  */
4901
4984
  async function executeAttempts(options) {
@@ -5117,7 +5200,7 @@ async function executeAttempts(options) {
5117
5200
  if (task.format) {
5118
5201
  if (task.format === 'JSON') {
5119
5202
  if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
5120
- // TODO: [🏢] Do more universally via `FormatDefinition`
5203
+ // TODO: [🏢] Do more universally via `FormatParser`
5121
5204
  try {
5122
5205
  $ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
5123
5206
  }
@@ -5219,12 +5302,16 @@ async function executeAttempts(options) {
5219
5302
  */
5220
5303
 
5221
5304
  /**
5222
- * @@@
5305
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5306
+ * Handles format and subformat resolution, error handling, and progress reporting.
5307
+ *
5308
+ * @param options - Options for execution, including task details and progress callback.
5309
+ * @returns The result of the subvalue mapping or execution attempts.
5223
5310
  *
5224
5311
  * @private internal utility of `createPipelineExecutor`
5225
5312
  */
5226
5313
  async function executeFormatSubvalues(options) {
5227
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5314
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5228
5315
  if (task.foreach === undefined) {
5229
5316
  return /* not await */ executeAttempts(options);
5230
5317
  }
@@ -5255,16 +5342,16 @@ async function executeFormatSubvalues(options) {
5255
5342
  ${block(pipelineIdentification)}
5256
5343
  `));
5257
5344
  }
5258
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(task.foreach.subformatName));
5259
- if (subvalueDefinition === undefined) {
5345
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
5346
+ if (subvalueParser === undefined) {
5260
5347
  throw new UnexpectedError(
5261
5348
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5262
5349
  spaceTrim$1((block) => `
5263
5350
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
5264
5351
 
5265
5352
  Available subformat names for format "${formatDefinition.formatName}":
5266
- ${block(formatDefinition.subvalueDefinitions
5267
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
5353
+ ${block(formatDefinition.subvalueParsers
5354
+ .map((subvalueParser) => subvalueParser.subvalueName)
5268
5355
  .map((subvalueName) => `- ${subvalueName}`)
5269
5356
  .join('\n'))}
5270
5357
 
@@ -5276,55 +5363,85 @@ async function executeFormatSubvalues(options) {
5276
5363
  let formatSettings;
5277
5364
  if (formatDefinition.formatName === 'CSV') {
5278
5365
  formatSettings = csvSettings;
5279
- // <- TODO: [🤹‍♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5280
- }
5281
- const resultString = await subvalueDefinition.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5282
- let mappedParameters;
5283
- // TODO: [🤹‍♂️][🪂] Limit to N concurrent executions
5284
- // TODO: When done [🐚] Report progress also for each subvalue here
5285
- try {
5286
- mappedParameters = mapAvailableToExpectedParameters({
5287
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5288
- availableParameters: subparameters,
5289
- });
5290
- }
5291
- catch (error) {
5292
- if (!(error instanceof PipelineExecutionError)) {
5293
- throw error;
5366
+ // <- TODO: [🤹‍♂️] More universal, make similar pattern for other formats for example \n vs \r\n in text
5367
+ }
5368
+ const resultString = await subvalueParser.mapValues({
5369
+ value: parameterValue,
5370
+ outputParameterName: task.foreach.outputSubparameterName,
5371
+ settings: formatSettings,
5372
+ onProgress(partialResultString) {
5373
+ return onProgress(Object.freeze({
5374
+ [task.resultingParameterName]: partialResultString,
5375
+ }));
5376
+ },
5377
+ async mapCallback(subparameters, index, length) {
5378
+ let mappedParameters;
5379
+ try {
5380
+ mappedParameters = mapAvailableToExpectedParameters({
5381
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5382
+ availableParameters: subparameters,
5383
+ });
5294
5384
  }
5295
- throw new PipelineExecutionError(spaceTrim$1((block) => `
5296
- ${error.message}
5385
+ catch (error) {
5386
+ if (!(error instanceof PipelineExecutionError)) {
5387
+ throw error;
5388
+ }
5389
+ const highLevelError = new PipelineExecutionError(spaceTrim$1((block) => `
5390
+ ${error.message}
5297
5391
 
5298
- This is error in FOREACH command
5299
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5392
+ This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5393
+ You have probably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5300
5394
 
5301
- ${block(pipelineIdentification)}
5302
- Subparameter index: ${index}
5303
- `));
5304
- }
5305
- const allSubparameters = {
5306
- ...parameters,
5307
- ...mappedParameters,
5308
- };
5309
- // 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
5310
- Object.freeze(allSubparameters);
5311
- const subresultString = await executeAttempts({
5312
- ...options,
5313
- priority: priority + index,
5314
- parameters: allSubparameters,
5315
- pipelineIdentification: spaceTrim$1((block) => `
5316
- ${block(pipelineIdentification)}
5317
- Subparameter index: ${index}
5318
- `),
5319
- });
5320
- return subresultString;
5395
+ ${block(pipelineIdentification)}
5396
+ `));
5397
+ if (length > BIG_DATASET_TRESHOLD) {
5398
+ console.error(highLevelError);
5399
+ return FAILED_VALUE_PLACEHOLDER;
5400
+ }
5401
+ throw highLevelError;
5402
+ }
5403
+ const allSubparameters = {
5404
+ ...parameters,
5405
+ ...mappedParameters,
5406
+ };
5407
+ Object.freeze(allSubparameters);
5408
+ try {
5409
+ const subresultString = await executeAttempts({
5410
+ ...options,
5411
+ priority: priority + index,
5412
+ parameters: allSubparameters,
5413
+ pipelineIdentification: spaceTrim$1((block) => `
5414
+ ${block(pipelineIdentification)}
5415
+ Subparameter index: ${index}
5416
+ `),
5417
+ });
5418
+ return subresultString;
5419
+ }
5420
+ catch (error) {
5421
+ if (length > BIG_DATASET_TRESHOLD) {
5422
+ console.error(spaceTrim$1((block) => `
5423
+ ${error.message}
5424
+
5425
+ This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5426
+
5427
+ ${block(pipelineIdentification)}
5428
+ `));
5429
+ return FAILED_VALUE_PLACEHOLDER;
5430
+ }
5431
+ throw error;
5432
+ }
5433
+ },
5321
5434
  });
5322
5435
  return resultString;
5323
5436
  }
5324
5437
 
5325
5438
  /**
5326
- * @@@
5439
+ * Returns the context for a given task, typically used to provide additional information or variables
5440
+ * required for the execution of the task within a pipeline. The context is returned as a string value
5441
+ * that may include markdown formatting.
5327
5442
  *
5443
+ * @param task - The task for which the context is being generated. This should be a deeply immutable TaskJson object.
5444
+ * @returns The context as a string, formatted as markdown and parameter value.
5328
5445
  * @private internal utility of `createPipelineExecutor`
5329
5446
  */
5330
5447
  async function getContextForTask(task) {
@@ -5332,7 +5449,7 @@ async function getContextForTask(task) {
5332
5449
  }
5333
5450
 
5334
5451
  /**
5335
- * @@@
5452
+ * Retrieves example values or templates for a given task, used to guide or validate pipeline execution.
5336
5453
  *
5337
5454
  * @private internal utility of `createPipelineExecutor`
5338
5455
  */
@@ -5341,91 +5458,128 @@ async function getExamplesForTask(task) {
5341
5458
  }
5342
5459
 
5343
5460
  /**
5344
- * @@@
5461
+ * Computes the cosine similarity between two embedding vectors
5462
+ *
5463
+ * Note: This is helping function for RAG (retrieval-augmented generation)
5345
5464
  *
5346
- * Here is the place where RAG (retrieval-augmented generation) happens
5465
+ * @param embeddingVector1
5466
+ * @param embeddingVector2
5467
+ * @returns Cosine similarity between the two vectors
5468
+ *
5469
+ * @public exported from `@promptbook/core`
5470
+ */
5471
+ function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5472
+ if (embeddingVector1.length !== embeddingVector2.length) {
5473
+ throw new TypeError('Embedding vectors must have the same length');
5474
+ }
5475
+ const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5476
+ const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5477
+ const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5478
+ return 1 - dotProduct / (magnitude1 * magnitude2);
5479
+ }
5480
+
5481
+ /**
5482
+ *
5483
+ * @param knowledgePieces
5484
+ * @returns
5485
+ *
5486
+ * @private internal utility of `createPipelineExecutor`
5487
+ */
5488
+ function knowledgePiecesToString(knowledgePieces) {
5489
+ return knowledgePieces
5490
+ .map((knowledgePiece) => {
5491
+ const { content } = knowledgePiece;
5492
+ return `- ${content}`;
5493
+ })
5494
+ .join('\n');
5495
+ // <- TODO: [🧠] Some smarter aggregation of knowledge pieces, single-line vs multi-line vs mixed
5496
+ }
5497
+
5498
+ /**
5499
+ * Retrieves the most relevant knowledge pieces for a given task using embedding-based similarity search.
5500
+ * This is where retrieval-augmented generation (RAG) is performed to enhance the task with external knowledge.
5347
5501
  *
5348
5502
  * @private internal utility of `createPipelineExecutor`
5349
5503
  */
5350
5504
  async function getKnowledgeForTask(options) {
5351
- const { tools, preparedPipeline, task } = options;
5505
+ const { tools, preparedPipeline, task, parameters } = options;
5352
5506
  const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
5353
5507
  const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
5354
5508
  // <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
5355
5509
  if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
5356
- return 'No knowledge pieces found';
5510
+ return ''; // <- Note: Np knowledge present, return empty string
5357
5511
  }
5358
- // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5359
- const _llms = arrayableToArray(tools.llm);
5360
- const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5361
- const taskEmbeddingPrompt = {
5362
- title: 'Knowledge Search',
5363
- modelRequirements: {
5364
- modelVariant: 'EMBEDDING',
5365
- modelName: firstKnowlegeIndex.modelName,
5366
- },
5367
- content: task.content,
5368
- parameters: {
5369
- /* !!!!!!!! */
5370
- },
5371
- };
5372
- const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5373
- const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5374
- const { index } = knowledgePiece;
5375
- const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5376
- // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5377
- if (knowledgePieceIndex === undefined) {
5512
+ try {
5513
+ // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5514
+ const _llms = arrayableToArray(tools.llm);
5515
+ const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5516
+ const taskEmbeddingPrompt = {
5517
+ title: 'Knowledge Search',
5518
+ modelRequirements: {
5519
+ modelVariant: 'EMBEDDING',
5520
+ modelName: firstKnowlegeIndex.modelName,
5521
+ },
5522
+ content: task.content,
5523
+ parameters,
5524
+ };
5525
+ const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
5526
+ const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
5527
+ const { index } = knowledgePiece;
5528
+ const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
5529
+ // <- TODO: Do not use just first knowledge piece and first index to determine embedding model
5530
+ if (knowledgePieceIndex === undefined) {
5531
+ return {
5532
+ content: knowledgePiece.content,
5533
+ relevance: 0,
5534
+ };
5535
+ }
5536
+ const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5378
5537
  return {
5379
5538
  content: knowledgePiece.content,
5380
- relevance: 0,
5539
+ relevance,
5381
5540
  };
5382
- }
5383
- const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
5384
- return {
5385
- content: knowledgePiece.content,
5386
- relevance,
5387
- };
5388
- });
5389
- const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5390
- const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5391
- console.log('!!! Embedding', {
5392
- task,
5393
- taskEmbeddingPrompt,
5394
- taskEmbeddingResult,
5395
- firstKnowlegePiece,
5396
- firstKnowlegeIndex,
5397
- knowledgePiecesWithRelevance,
5398
- knowledgePiecesSorted,
5399
- knowledgePiecesLimited,
5400
- });
5401
- return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
5402
- // <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
5403
- }
5404
- // TODO: !!!!!! Annotate + to new file
5405
- function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
5406
- if (embeddingVector1.length !== embeddingVector2.length) {
5407
- throw new TypeError('Embedding vectors must have the same length');
5541
+ });
5542
+ const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
5543
+ const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
5544
+ /*
5545
+ console.log('`getKnowledgeForTask` Embedding', {
5546
+ task,
5547
+ taskEmbeddingPrompt,
5548
+ taskEmbeddingResult,
5549
+ firstKnowlegePiece,
5550
+ firstKnowlegeIndex,
5551
+ knowledgePiecesWithRelevance,
5552
+ knowledgePiecesSorted,
5553
+ knowledgePiecesLimited,
5554
+ });
5555
+ */
5556
+ return knowledgePiecesToString(knowledgePiecesLimited);
5557
+ }
5558
+ catch (error) {
5559
+ assertsError(error);
5560
+ console.error('Error in `getKnowledgeForTask`', error);
5561
+ // Note: If the LLM fails, just return all knowledge pieces
5562
+ return knowledgePiecesToString(preparedPipeline.knowledgePieces);
5408
5563
  }
5409
- const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
5410
- const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
5411
- const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
5412
- return 1 - dotProduct / (magnitude1 * magnitude2);
5413
5564
  }
5414
5565
  /**
5415
- * TODO: !!!! Verify if this is working
5416
5566
  * TODO: [♨] Implement Better - use keyword search
5417
5567
  * TODO: [♨] Examples of values
5418
5568
  */
5419
5569
 
5420
5570
  /**
5421
- * @@@
5571
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5572
+ * Ensures all reserved parameters are defined and throws if any are missing.
5573
+ *
5574
+ * @param options - Options including tools, pipeline, task, and context.
5575
+ * @returns An object containing all reserved parameters for the task.
5422
5576
  *
5423
5577
  * @private internal utility of `createPipelineExecutor`
5424
5578
  */
5425
5579
  async function getReservedParametersForTask(options) {
5426
- const { tools, preparedPipeline, task, pipelineIdentification } = options;
5580
+ const { tools, preparedPipeline, task, parameters, pipelineIdentification, isVerbose } = options;
5427
5581
  const context = await getContextForTask(); // <- [🏍]
5428
- const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
5582
+ const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task, parameters });
5429
5583
  const examples = await getExamplesForTask();
5430
5584
  const currentDate = new Date().toISOString(); // <- TODO: [🧠][💩] Better
5431
5585
  const modelName = RESERVED_PARAMETER_MISSING_VALUE;
@@ -5437,6 +5591,9 @@ async function getReservedParametersForTask(options) {
5437
5591
  currentDate,
5438
5592
  modelName,
5439
5593
  };
5594
+ if (isVerbose) {
5595
+ console.info('Reserved parameters for task:', { options, reservedParameters });
5596
+ }
5440
5597
  // Note: Doublecheck that ALL reserved parameters are defined:
5441
5598
  for (const parameterName of RESERVED_PARAMETER_NAMES) {
5442
5599
  if (reservedParameters[parameterName] === undefined) {
@@ -5451,23 +5608,21 @@ async function getReservedParametersForTask(options) {
5451
5608
  }
5452
5609
 
5453
5610
  /**
5454
- * @@@
5611
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5612
+ *
5613
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5614
+ * @returns The output parameters produced by the task.
5455
5615
  *
5456
5616
  * @private internal utility of `createPipelineExecutor`
5457
5617
  */
5458
5618
  async function executeTask(options) {
5459
5619
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5460
5620
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5461
- await onProgress({
5462
- outputParameters: {
5463
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5464
- },
5465
- });
5466
5621
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5467
5622
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5468
5623
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
5469
5624
  // TODO: [👩🏾‍🤝‍👩🏻] Use here `mapAvailableToExpectedParameters`
5470
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
5625
+ if (difference(union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)), new Set(RESERVED_PARAMETER_NAMES)).size !== 0) {
5471
5626
  throw new UnexpectedError(spaceTrim((block) => `
5472
5627
  Dependent parameters are not consistent with used parameters:
5473
5628
 
@@ -5485,13 +5640,16 @@ async function executeTask(options) {
5485
5640
 
5486
5641
  `));
5487
5642
  }
5643
+ const reservedParameters = await getReservedParametersForTask({
5644
+ tools,
5645
+ preparedPipeline,
5646
+ task: currentTask,
5647
+ pipelineIdentification,
5648
+ parameters: parametersToPass,
5649
+ isVerbose,
5650
+ });
5488
5651
  const definedParameters = Object.freeze({
5489
- ...(await getReservedParametersForTask({
5490
- tools,
5491
- preparedPipeline,
5492
- task: currentTask,
5493
- pipelineIdentification,
5494
- })),
5652
+ ...reservedParameters,
5495
5653
  ...parametersToPass,
5496
5654
  });
5497
5655
  const definedParameterNames = new Set(Object.keys(definedParameters));
@@ -5536,6 +5694,7 @@ async function executeTask(options) {
5536
5694
  preparedPipeline,
5537
5695
  tools,
5538
5696
  $executionReport,
5697
+ onProgress,
5539
5698
  pipelineIdentification,
5540
5699
  maxExecutionAttempts,
5541
5700
  maxParallelCount,
@@ -5563,7 +5722,8 @@ async function executeTask(options) {
5563
5722
  */
5564
5723
 
5565
5724
  /**
5566
- * @@@
5725
+ * Filters and returns only the output parameters from the provided pipeline execution options.
5726
+ * Adds warnings for any expected output parameters that are missing.
5567
5727
  *
5568
5728
  * @private internal utility of `createPipelineExecutor`
5569
5729
  */
@@ -5588,9 +5748,12 @@ function filterJustOutputParameters(options) {
5588
5748
  }
5589
5749
 
5590
5750
  /**
5591
- * @@@
5751
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5592
5752
  *
5593
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5753
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5754
+ *
5755
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5756
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5594
5757
  *
5595
5758
  * @private internal utility of `createPipelineExecutor`
5596
5759
  */
@@ -5913,10 +6076,27 @@ function createPipelineExecutor(options) {
5913
6076
  cacheDirname,
5914
6077
  intermediateFilesStrategy,
5915
6078
  isAutoInstalled,
6079
+ }).catch((error) => {
6080
+ assertsError(error);
6081
+ return exportJson({
6082
+ name: 'pipelineExecutorResult',
6083
+ message: `Unuccessful PipelineExecutorResult, last catch`,
6084
+ order: [],
6085
+ value: {
6086
+ isSuccessful: false,
6087
+ errors: [serializeError(error)],
6088
+ warnings: [],
6089
+ usage: UNCERTAIN_USAGE,
6090
+ executionReport: null,
6091
+ outputParameters: {},
6092
+ preparedPipeline,
6093
+ },
6094
+ });
5916
6095
  });
5917
6096
  };
5918
6097
  const pipelineExecutor = (inputParameters) => createTask({
5919
6098
  taskType: 'EXECUTION',
6099
+ title: pipeline.title,
5920
6100
  taskProcessCallback(updateOngoingResult) {
5921
6101
  return pipelineExecutorWithCallback(inputParameters, async (newOngoingResult) => {
5922
6102
  updateOngoingResult(newOngoingResult);
@@ -6019,7 +6199,7 @@ class MarkdownScraper {
6019
6199
  const knowledge = await Promise.all(
6020
6200
  // TODO: [🪂] Do not send all at once but in chunks
6021
6201
  knowledgeTextPieces.map(async (knowledgeTextPiece, i) => {
6022
- // Note: Theese are just default values, they will be overwritten by the actual values:
6202
+ // Note: These are just default values, they will be overwritten by the actual values:
6023
6203
  let name = `piece-${i}`;
6024
6204
  let title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
6025
6205
  const knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
@@ -6397,7 +6577,8 @@ class LegacyDocumentScraper {
6397
6577
  */
6398
6578
 
6399
6579
  /**
6400
- * @@@
6580
+ * Creates a scraper for legacy document formats (.doc, .rtf, etc).
6581
+ * Uses LibreOffice for conversion to extract content from older document formats.
6401
6582
  *
6402
6583
  * @public exported from `@promptbook/legacy-documents`
6403
6584
  */