@promptbook/markdown-utils 0.92.0-23 → 0.92.0-25

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 (83) hide show
  1. package/esm/index.es.js +65 -41
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +0 -2
  4. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  5. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  6. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  7. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
  8. package/esm/typings/src/config.d.ts +8 -4
  9. package/esm/typings/src/constants.d.ts +2 -2
  10. package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
  11. package/esm/typings/src/execution/CommonToolsOptions.d.ts +3 -3
  12. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +10 -10
  13. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  14. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  15. package/esm/typings/src/formfactors/index.d.ts +1 -1
  16. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  17. package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
  18. package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
  19. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
  20. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +5 -5
  21. package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +5 -3
  22. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  23. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
  24. package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
  25. package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
  26. package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
  27. package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
  28. package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
  29. package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
  30. package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +9 -6
  31. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +2 -2
  32. package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
  33. package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
  34. package/esm/typings/src/prepare/prepareTasks.d.ts +7 -4
  35. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +2 -1
  36. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
  37. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
  38. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
  39. package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
  40. package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
  41. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
  42. package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
  43. package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
  44. package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
  45. package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
  46. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
  47. package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
  48. package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
  49. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
  50. package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
  51. package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
  52. package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
  53. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
  54. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
  55. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
  56. package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
  57. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
  58. package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
  59. package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
  60. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
  61. package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
  62. package/esm/typings/src/types/ModelVariant.d.ts +5 -5
  63. package/esm/typings/src/types/typeAliases.d.ts +8 -6
  64. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
  65. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
  66. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
  67. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  68. package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
  69. package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
  70. package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
  71. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
  72. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
  73. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
  74. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
  75. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
  76. package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
  77. package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
  78. package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
  79. package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
  80. package/esm/typings/src/version.d.ts +2 -1
  81. package/package.json +1 -1
  82. package/umd/index.umd.js +65 -41
  83. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-25';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -232,11 +232,20 @@ const DEFAULT_BOOK_TITLE = `✨ Untitled Book`;
232
232
  */
233
233
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
234
234
  /**
235
- * @@@
235
+ * Threshold value that determines when a dataset is considered "big"
236
+ * and may require special handling or optimizations
237
+ *
238
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
236
239
  *
237
240
  * @public exported from `@promptbook/core`
238
241
  */
239
242
  const BIG_DATASET_TRESHOLD = 50;
243
+ /**
244
+ * Placeholder text used to represent a placeholder value of failed operation
245
+ *
246
+ * @public exported from `@promptbook/core`
247
+ */
248
+ const FAILED_VALUE_PLACEHOLDER = '!?';
240
249
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
241
250
  /**
242
251
  * The maximum number of iterations for a loops
@@ -1109,13 +1118,13 @@ const ORDER_OF_PIPELINE_JSON = [
1109
1118
  */
1110
1119
  const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1111
1120
  /**
1112
- * @@@
1121
+ * Placeholder value indicating a parameter is missing its value.
1113
1122
  *
1114
1123
  * @private within the repository
1115
1124
  */
1116
1125
  const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1117
1126
  /**
1118
- * @@@
1127
+ * Placeholder value indicating a parameter is restricted and cannot be used directly.
1119
1128
  *
1120
1129
  * @private within the repository
1121
1130
  */
@@ -1614,7 +1623,7 @@ class SimplePipelineCollection {
1614
1623
  /**
1615
1624
  * Constructs a pipeline collection from pipelines
1616
1625
  *
1617
- * @param pipelines @@@
1626
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1618
1627
  *
1619
1628
  * Note: During the construction logic of all pipelines are validated
1620
1629
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -1778,8 +1787,8 @@ class PipelineExecutionError extends Error {
1778
1787
  * @public exported from `@promptbook/core`
1779
1788
  */
1780
1789
  function isPipelinePrepared(pipeline) {
1781
- // Note: Ignoring `pipeline.preparations` @@@
1782
- // Note: Ignoring `pipeline.knowledgePieces` @@@
1790
+ // Note: Ignoring `pipeline.preparations`
1791
+ // Note: Ignoring `pipeline.knowledgePieces`
1783
1792
  if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
1784
1793
  // TODO: !!! Comment this out
1785
1794
  console.log('Pipeline is not prepared because title is undefined or empty', pipeline);
@@ -2777,7 +2786,8 @@ async function preparePersona(personaDescription, tools, options) {
2777
2786
  */
2778
2787
 
2779
2788
  /**
2780
- * @@@
2789
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
2790
+ * regardless of the JavaScript environment in which the code is running
2781
2791
  *
2782
2792
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2783
2793
  *
@@ -2788,10 +2798,10 @@ function $getGlobalScope() {
2788
2798
  }
2789
2799
 
2790
2800
  /**
2791
- * @@@
2801
+ * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2792
2802
  *
2793
- * @param text @@@
2794
- * @returns @@@
2803
+ * @param text The text string to be converted to SCREAMING_CASE format.
2804
+ * @returns The normalized text in SCREAMING_CASE format.
2795
2805
  * @example 'HELLO_WORLD'
2796
2806
  * @example 'I_LOVE_PROMPTBOOK'
2797
2807
  * @public exported from `@promptbook/utils`
@@ -2843,10 +2853,10 @@ function normalizeTo_SCREAMING_CASE(text) {
2843
2853
  */
2844
2854
 
2845
2855
  /**
2846
- * @@@
2856
+ * Normalizes a text string to snake_case format.
2847
2857
  *
2848
- * @param text @@@
2849
- * @returns @@@
2858
+ * @param text The text string to be converted to snake_case format.
2859
+ * @returns The normalized text in snake_case format.
2850
2860
  * @example 'hello_world'
2851
2861
  * @example 'i_love_promptbook'
2852
2862
  * @public exported from `@promptbook/utils`
@@ -2916,10 +2926,11 @@ const $scrapersMetadataRegister = new $Register('scrapers_metadata');
2916
2926
  */
2917
2927
 
2918
2928
  /**
2919
- * @@@
2929
+ * Registry for all available scrapers in the system.
2930
+ * Central point for registering and accessing different types of content scrapers.
2920
2931
  *
2921
2932
  * Note: `$` is used to indicate that this interacts with the global scope
2922
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2933
+ * @singleton Only one instance of each register is created per build, but there can be more than one in different build modules
2923
2934
  * @public exported from `@promptbook/core`
2924
2935
  */
2925
2936
  const $scrapersRegister = new $Register('scraper_constructors');
@@ -3259,10 +3270,10 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
3259
3270
  */
3260
3271
 
3261
3272
  /**
3262
- * @@@
3273
+ * Removes diacritic marks (accents) from characters in a string.
3263
3274
  *
3264
- * @param input @@@
3265
- * @returns @@@
3275
+ * @param input The string containing diacritics to be normalized.
3276
+ * @returns The string with diacritics removed or normalized.
3266
3277
  * @public exported from `@promptbook/utils`
3267
3278
  */
3268
3279
  function removeDiacritics(input) {
@@ -3276,10 +3287,10 @@ function removeDiacritics(input) {
3276
3287
  */
3277
3288
 
3278
3289
  /**
3279
- * @@@
3290
+ * Converts a given text to kebab-case format.
3280
3291
  *
3281
- * @param text @@@
3282
- * @returns @@@
3292
+ * @param text The text to be converted.
3293
+ * @returns The kebab-case formatted string.
3283
3294
  * @example 'hello-world'
3284
3295
  * @example 'i-love-promptbook'
3285
3296
  * @public exported from `@promptbook/utils`
@@ -3348,7 +3359,8 @@ function knowledgeSourceContentToName(knowledgeSourceContent) {
3348
3359
  */
3349
3360
 
3350
3361
  /**
3351
- * @@@
3362
+ * Converts a name to a properly formatted subfolder path for cache storage.
3363
+ * Handles normalization and path formatting to create consistent cache directory structures.
3352
3364
  *
3353
3365
  * @private for `FileCacheStorage`
3354
3366
  */
@@ -3428,11 +3440,11 @@ function removeEmojis(text) {
3428
3440
  }
3429
3441
 
3430
3442
  /**
3431
- * @@@
3443
+ * Converts a title string into a normalized name.
3432
3444
  *
3433
- * @param value @@@
3434
- * @returns @@@
3435
- * @example @@@
3445
+ * @param value The title string to be converted to a name.
3446
+ * @returns A normalized name derived from the input title.
3447
+ * @example 'Hello World!' -> 'hello-world'
3436
3448
  * @public exported from `@promptbook/utils`
3437
3449
  */
3438
3450
  function titleToName(value) {
@@ -3483,7 +3495,9 @@ const promptbookFetch = async (urlOrRequest, init) => {
3483
3495
  */
3484
3496
 
3485
3497
  /**
3486
- * @@@
3498
+ * Factory function that creates a handler for processing knowledge sources.
3499
+ * Provides standardized processing of different types of knowledge sources
3500
+ * across various scraper implementations.
3487
3501
  *
3488
3502
  * @public exported from `@promptbook/core`
3489
3503
  */
@@ -3724,9 +3738,12 @@ TODO: [🧊] This is how it can look in future
3724
3738
  */
3725
3739
 
3726
3740
  /**
3727
- * @@@
3741
+ * Prepares tasks by adding knowledge to the prompt and ensuring all necessary parameters are included.
3728
3742
  *
3729
- * @public exported from `@promptbook/core`
3743
+ * @param tasks Sequence of tasks that are chained together to form a pipeline
3744
+ * @returns A promise that resolves to the prepared tasks.
3745
+ *
3746
+ * @private internal utility of `preparePipeline`
3730
3747
  */
3731
3748
  async function prepareTasks(pipeline, tools, options) {
3732
3749
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT } = options;
@@ -4264,6 +4281,15 @@ const CsvFormatParser = {
4264
4281
  mappedData.push(mappedRow);
4265
4282
  if (onProgress) {
4266
4283
  // Note: Report the CSV with all rows mapped so far
4284
+ /*
4285
+ !!!!
4286
+ // Report progress with updated value
4287
+ const progressData = mappedData.map((row, i) =>
4288
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4289
+ );
4290
+
4291
+
4292
+ */
4267
4293
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4268
4294
  }
4269
4295
  }
@@ -4480,7 +4506,7 @@ function mapAvailableToExpectedParameters(options) {
4480
4506
  else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) ;
4481
4507
  }
4482
4508
  if (expectedParameterNames.size === 0) {
4483
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4509
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4484
4510
  Object.freeze(mappedParameters);
4485
4511
  return mappedParameters;
4486
4512
  }
@@ -4511,7 +4537,7 @@ function mapAvailableToExpectedParameters(options) {
4511
4537
  for (let i = 0; i < expectedParameterNames.size; i++) {
4512
4538
  mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
4513
4539
  }
4514
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
4540
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent accidental modifications after mapping
4515
4541
  Object.freeze(mappedParameters);
4516
4542
  return mappedParameters;
4517
4543
  }
@@ -5162,15 +5188,14 @@ async function executeFormatSubvalues(options) {
5162
5188
  const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5163
5189
  ${error.message}
5164
5190
 
5165
- This is error in FOREACH command when mapping data
5191
+ This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5166
5192
  You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5167
5193
 
5168
5194
  ${block(pipelineIdentification)}
5169
- Subparameter index: ${index}
5170
5195
  `));
5171
5196
  if (length > BIG_DATASET_TRESHOLD) {
5172
5197
  console.error(highLevelError);
5173
- return '~';
5198
+ return FAILED_VALUE_PLACEHOLDER;
5174
5199
  }
5175
5200
  throw highLevelError;
5176
5201
  }
@@ -5194,14 +5219,13 @@ async function executeFormatSubvalues(options) {
5194
5219
  catch (error) {
5195
5220
  if (length > BIG_DATASET_TRESHOLD) {
5196
5221
  console.error(spaceTrim((block) => `
5197
- Error in FOREACH command:
5222
+ ${error.message}
5198
5223
 
5199
- ${block(pipelineIdentification)}
5224
+ This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
5200
5225
 
5201
5226
  ${block(pipelineIdentification)}
5202
- Subparameter index: ${index}
5203
5227
  `));
5204
- return '~';
5228
+ return FAILED_VALUE_PLACEHOLDER;
5205
5229
  }
5206
5230
  throw error;
5207
5231
  }
@@ -6038,7 +6062,7 @@ class MarkdownScraper {
6038
6062
  */
6039
6063
 
6040
6064
  /**
6041
- * @@@
6065
+ * Creates a scraper for markdown content.
6042
6066
  *
6043
6067
  * @public exported from `@promptbook/markdown-utils`
6044
6068
  */
@@ -6193,7 +6217,7 @@ function escapeMarkdownBlock(value) {
6193
6217
  * Note: It can not work with html syntax and comments
6194
6218
  *
6195
6219
  * @param markdown any valid markdown
6196
- * @returns @@@
6220
+ * @returns An array of strings, each representing an individual list item found in the markdown
6197
6221
  * @public exported from `@promptbook/markdown-utils`
6198
6222
  */
6199
6223
  function extractAllListItemsFromMarkdown(markdown) {