@promptbook/markdown-utils 0.92.0-22 โ†’ 0.92.0-23

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 (26) hide show
  1. package/esm/index.es.js +94 -53
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  4. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  5. package/esm/typings/src/config.d.ts +29 -11
  6. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  7. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  8. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -3
  9. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
  10. package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
  11. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +31 -6
  12. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  13. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  14. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
  16. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  17. package/esm/typings/src/types/typeAliases.d.ts +9 -7
  18. package/esm/typings/src/utils/$Register.d.ts +8 -7
  19. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  20. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  21. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  22. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  23. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  24. package/package.json +1 -1
  25. package/umd/index.umd.js +94 -53
  26. 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-22';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
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
@@ -231,6 +231,12 @@ const DEFAULT_BOOK_TITLE = `โœจ Untitled Book`;
231
231
  * @public exported from `@promptbook/core`
232
232
  */
233
233
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
234
+ /**
235
+ * @@@
236
+ *
237
+ * @public exported from `@promptbook/core`
238
+ */
239
+ const BIG_DATASET_TRESHOLD = 50;
234
240
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
235
241
  /**
236
242
  * The maximum number of iterations for a loops
@@ -310,7 +316,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
310
316
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
311
317
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
312
318
  /**
313
- * @@@
319
+ * Default settings for parsing and generating CSV files in Promptbook.
314
320
  *
315
321
  * @public exported from `@promptbook/core`
316
322
  */
@@ -321,19 +327,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
321
327
  skipEmptyLines: true,
322
328
  });
323
329
  /**
324
- * @@@
330
+ * Controls whether verbose logging is enabled by default throughout the application.
325
331
  *
326
332
  * @public exported from `@promptbook/core`
327
333
  */
328
334
  let DEFAULT_IS_VERBOSE = false;
329
335
  /**
330
- * @@@
336
+ * Controls whether auto-installation of dependencies is enabled by default.
331
337
  *
332
338
  * @public exported from `@promptbook/core`
333
339
  */
334
340
  const DEFAULT_IS_AUTO_INSTALLED = false;
335
341
  /**
336
- * @@@
342
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
337
343
  *
338
344
  * @private within the repository
339
345
  */
@@ -466,7 +472,7 @@ function assertsError(whatWasThrown) {
466
472
  * Function isValidJsonString will tell you if the string is valid JSON or not
467
473
  *
468
474
  * @param value The string to check
469
- * @returns True if the string is a valid JSON string, false otherwise
475
+ * @returns `true` if the string is a valid JSON string, false otherwise
470
476
  *
471
477
  * @public exported from `@promptbook/utils`
472
478
  */
@@ -1016,8 +1022,12 @@ function checkSerializableAsJson(options) {
1016
1022
  */
1017
1023
 
1018
1024
  /**
1019
- * @@@
1025
+ * Creates a deep clone of the given object
1026
+ *
1027
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1020
1028
  *
1029
+ * @param objectValue The object to clone.
1030
+ * @returns A deep, writable clone of the input object.
1021
1031
  * @public exported from `@promptbook/utils`
1022
1032
  */
1023
1033
  function deepClone(objectValue) {
@@ -2846,11 +2856,11 @@ function normalizeTo_snake_case(text) {
2846
2856
  }
2847
2857
 
2848
2858
  /**
2849
- * Register is @@@
2859
+ * Global registry for storing and managing registered entities of a given type.
2850
2860
  *
2851
2861
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2852
2862
  *
2853
- * @private internal utility, exported are only signleton instances of this class
2863
+ * @private internal utility, exported are only singleton instances of this class
2854
2864
  */
2855
2865
  class $Register {
2856
2866
  constructor(registerName) {
@@ -2894,10 +2904,10 @@ class $Register {
2894
2904
  }
2895
2905
 
2896
2906
  /**
2897
- * @@@
2907
+ * Global registry for storing metadata about all available scrapers and converters.
2898
2908
  *
2899
- * Note: `$` is used to indicate that this interacts with the global scope
2900
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
2909
+ * Note: `$` is used to indicate that this interacts with the global scope.
2910
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
2901
2911
  * @public exported from `@promptbook/core`
2902
2912
  */
2903
2913
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4184,7 +4194,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4184
4194
  * Function to check if a string is valid CSV
4185
4195
  *
4186
4196
  * @param value The string to check
4187
- * @returns True if the string is a valid CSV string, false otherwise
4197
+ * @returns `true` if the string is a valid CSV string, false otherwise
4188
4198
  *
4189
4199
  * @public exported from `@promptbook/utils`
4190
4200
  */
@@ -4241,14 +4251,15 @@ const CsvFormatParser = {
4241
4251
  `));
4242
4252
  }
4243
4253
  const mappedData = [];
4244
- for (let index = 0; index < csv.data.length; index++) {
4254
+ const length = csv.data.length;
4255
+ for (let index = 0; index < length; index++) {
4245
4256
  const row = csv.data[index];
4246
4257
  if (row[outputParameterName]) {
4247
4258
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4248
4259
  }
4249
4260
  const mappedRow = {
4250
4261
  ...row,
4251
- [outputParameterName]: await mapCallback(row, index),
4262
+ [outputParameterName]: await mapCallback(row, index, length),
4252
4263
  };
4253
4264
  mappedData.push(mappedRow);
4254
4265
  if (onProgress) {
@@ -4279,9 +4290,9 @@ const CsvFormatParser = {
4279
4290
  `));
4280
4291
  }
4281
4292
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4282
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4293
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4283
4294
  const index = rowIndex * Object.keys(row).length + columnIndex;
4284
- return /* not await */ mapCallback({ [key]: value }, index);
4295
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4285
4296
  }));
4286
4297
  }));
4287
4298
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4352,12 +4363,12 @@ const TextFormatParser = {
4352
4363
  async mapValues(options) {
4353
4364
  const { value, mapCallback, onProgress } = options;
4354
4365
  const lines = value.split('\n');
4355
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4366
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4356
4367
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4357
4368
  /* not await */ mapCallback({
4358
4369
  lineContent,
4359
4370
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4360
- }, lineNumber)));
4371
+ }, lineNumber, array.length)));
4361
4372
  return mappedLines.join('\n');
4362
4373
  },
4363
4374
  },
@@ -4378,7 +4389,7 @@ const TextFormatParser = {
4378
4389
  * Function to check if a string is valid XML
4379
4390
  *
4380
4391
  * @param value
4381
- * @returns True if the string is a valid XML string, false otherwise
4392
+ * @returns `true` if the string is a valid XML string, false otherwise
4382
4393
  *
4383
4394
  * @public exported from `@promptbook/utils`
4384
4395
  */
@@ -4440,13 +4451,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4440
4451
  */
4441
4452
 
4442
4453
  /**
4443
- * Maps available parameters to expected parameters
4454
+ * Maps available parameters to expected parameters for a pipeline task.
4444
4455
  *
4445
4456
  * The strategy is:
4446
- * 1) @@@
4447
- * 2) @@@
4457
+ * 1) First, match parameters by name where both available and expected.
4458
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4448
4459
  *
4449
- * @throws {PipelineExecutionError} @@@
4460
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4450
4461
  * @private within the repository used in `createPipelineExecutor`
4451
4462
  */
4452
4463
  function mapAvailableToExpectedParameters(options) {
@@ -5064,7 +5075,11 @@ async function executeAttempts(options) {
5064
5075
  */
5065
5076
 
5066
5077
  /**
5067
- * @@@
5078
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5079
+ * Handles format and subformat resolution, error handling, and progress reporting.
5080
+ *
5081
+ * @param options - Options for execution, including task details and progress callback.
5082
+ * @returns The result of the subvalue mapping or execution attempts.
5068
5083
  *
5069
5084
  * @private internal utility of `createPipelineExecutor`
5070
5085
  */
@@ -5129,15 +5144,11 @@ async function executeFormatSubvalues(options) {
5129
5144
  settings: formatSettings,
5130
5145
  onProgress(partialResultString) {
5131
5146
  return onProgress(Object.freeze({
5132
- [task.resultingParameterName]:
5133
- // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
5134
- partialResultString,
5147
+ [task.resultingParameterName]: partialResultString,
5135
5148
  }));
5136
5149
  },
5137
- async mapCallback(subparameters, index) {
5150
+ async mapCallback(subparameters, index, length) {
5138
5151
  let mappedParameters;
5139
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5140
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5141
5152
  try {
5142
5153
  mappedParameters = mapAvailableToExpectedParameters({
5143
5154
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5148,32 +5159,52 @@ async function executeFormatSubvalues(options) {
5148
5159
  if (!(error instanceof PipelineExecutionError)) {
5149
5160
  throw error;
5150
5161
  }
5151
- throw new PipelineExecutionError(spaceTrim((block) => `
5152
- ${error.message}
5162
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5163
+ ${error.message}
5153
5164
 
5154
- This is error in FOREACH command
5155
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5165
+ This is error in FOREACH command when mapping data
5166
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5156
5167
 
5157
- ${block(pipelineIdentification)}
5158
- Subparameter index: ${index}
5159
- `));
5168
+ ${block(pipelineIdentification)}
5169
+ Subparameter index: ${index}
5170
+ `));
5171
+ if (length > BIG_DATASET_TRESHOLD) {
5172
+ console.error(highLevelError);
5173
+ return '~';
5174
+ }
5175
+ throw highLevelError;
5160
5176
  }
5161
5177
  const allSubparameters = {
5162
5178
  ...parameters,
5163
5179
  ...mappedParameters,
5164
5180
  };
5165
- // 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
5166
5181
  Object.freeze(allSubparameters);
5167
- const subresultString = await executeAttempts({
5168
- ...options,
5169
- priority: priority + index,
5170
- parameters: allSubparameters,
5171
- pipelineIdentification: spaceTrim((block) => `
5172
- ${block(pipelineIdentification)}
5173
- Subparameter index: ${index}
5174
- `),
5175
- });
5176
- return subresultString;
5182
+ try {
5183
+ const subresultString = await executeAttempts({
5184
+ ...options,
5185
+ priority: priority + index,
5186
+ parameters: allSubparameters,
5187
+ pipelineIdentification: spaceTrim((block) => `
5188
+ ${block(pipelineIdentification)}
5189
+ Subparameter index: ${index}
5190
+ `),
5191
+ });
5192
+ return subresultString;
5193
+ }
5194
+ catch (error) {
5195
+ if (length > BIG_DATASET_TRESHOLD) {
5196
+ console.error(spaceTrim((block) => `
5197
+ Error in FOREACH command:
5198
+
5199
+ ${block(pipelineIdentification)}
5200
+
5201
+ ${block(pipelineIdentification)}
5202
+ Subparameter index: ${index}
5203
+ `));
5204
+ return '~';
5205
+ }
5206
+ throw error;
5207
+ }
5177
5208
  },
5178
5209
  });
5179
5210
  return resultString;
@@ -5308,7 +5339,11 @@ async function getKnowledgeForTask(options) {
5308
5339
  */
5309
5340
 
5310
5341
  /**
5311
- * @@@
5342
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5343
+ * Ensures all reserved parameters are defined and throws if any are missing.
5344
+ *
5345
+ * @param options - Options including tools, pipeline, task, and context.
5346
+ * @returns An object containing all reserved parameters for the task.
5312
5347
  *
5313
5348
  * @private internal utility of `createPipelineExecutor`
5314
5349
  */
@@ -5341,7 +5376,10 @@ async function getReservedParametersForTask(options) {
5341
5376
  }
5342
5377
 
5343
5378
  /**
5344
- * @@@
5379
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5380
+ *
5381
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5382
+ * @returns The output parameters produced by the task.
5345
5383
  *
5346
5384
  * @private internal utility of `createPipelineExecutor`
5347
5385
  */
@@ -5475,9 +5513,12 @@ function filterJustOutputParameters(options) {
5475
5513
  }
5476
5514
 
5477
5515
  /**
5478
- * @@@
5516
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5517
+ *
5518
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5479
5519
  *
5480
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5520
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5521
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5481
5522
  *
5482
5523
  * @private internal utility of `createPipelineExecutor`
5483
5524
  */