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

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 (35) hide show
  1. package/esm/index.es.js +115 -55
  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/collection/PipelineCollection.d.ts +0 -2
  5. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  6. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  7. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  8. package/esm/typings/src/config.d.ts +33 -11
  9. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  10. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  11. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -3
  12. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
  13. package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
  14. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +31 -6
  15. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  16. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  17. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  18. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  19. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  20. package/esm/typings/src/formfactors/index.d.ts +1 -1
  21. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  22. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
  23. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  24. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  25. package/esm/typings/src/types/typeAliases.d.ts +9 -7
  26. package/esm/typings/src/utils/$Register.d.ts +8 -7
  27. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  28. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  29. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  30. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  31. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  32. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  33. package/package.json +1 -1
  34. package/umd/index.umd.js +115 -55
  35. 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-24';
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,21 @@ 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
+ * 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
239
+ *
240
+ * @public exported from `@promptbook/core`
241
+ */
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 = '!?';
234
249
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
235
250
  /**
236
251
  * The maximum number of iterations for a loops
@@ -310,7 +325,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
310
325
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
311
326
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
312
327
  /**
313
- * @@@
328
+ * Default settings for parsing and generating CSV files in Promptbook.
314
329
  *
315
330
  * @public exported from `@promptbook/core`
316
331
  */
@@ -321,19 +336,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
321
336
  skipEmptyLines: true,
322
337
  });
323
338
  /**
324
- * @@@
339
+ * Controls whether verbose logging is enabled by default throughout the application.
325
340
  *
326
341
  * @public exported from `@promptbook/core`
327
342
  */
328
343
  let DEFAULT_IS_VERBOSE = false;
329
344
  /**
330
- * @@@
345
+ * Controls whether auto-installation of dependencies is enabled by default.
331
346
  *
332
347
  * @public exported from `@promptbook/core`
333
348
  */
334
349
  const DEFAULT_IS_AUTO_INSTALLED = false;
335
350
  /**
336
- * @@@
351
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
337
352
  *
338
353
  * @private within the repository
339
354
  */
@@ -466,7 +481,7 @@ function assertsError(whatWasThrown) {
466
481
  * Function isValidJsonString will tell you if the string is valid JSON or not
467
482
  *
468
483
  * @param value The string to check
469
- * @returns True if the string is a valid JSON string, false otherwise
484
+ * @returns `true` if the string is a valid JSON string, false otherwise
470
485
  *
471
486
  * @public exported from `@promptbook/utils`
472
487
  */
@@ -1016,8 +1031,12 @@ function checkSerializableAsJson(options) {
1016
1031
  */
1017
1032
 
1018
1033
  /**
1019
- * @@@
1034
+ * Creates a deep clone of the given object
1035
+ *
1036
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1020
1037
  *
1038
+ * @param objectValue The object to clone.
1039
+ * @returns A deep, writable clone of the input object.
1021
1040
  * @public exported from `@promptbook/utils`
1022
1041
  */
1023
1042
  function deepClone(objectValue) {
@@ -1604,7 +1623,7 @@ class SimplePipelineCollection {
1604
1623
  /**
1605
1624
  * Constructs a pipeline collection from pipelines
1606
1625
  *
1607
- * @param pipelines @@@
1626
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1608
1627
  *
1609
1628
  * Note: During the construction logic of all pipelines are validated
1610
1629
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -2767,7 +2786,8 @@ async function preparePersona(personaDescription, tools, options) {
2767
2786
  */
2768
2787
 
2769
2788
  /**
2770
- * @@@
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
2771
2791
  *
2772
2792
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
2773
2793
  *
@@ -2846,11 +2866,11 @@ function normalizeTo_snake_case(text) {
2846
2866
  }
2847
2867
 
2848
2868
  /**
2849
- * Register is @@@
2869
+ * Global registry for storing and managing registered entities of a given type.
2850
2870
  *
2851
2871
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
2852
2872
  *
2853
- * @private internal utility, exported are only signleton instances of this class
2873
+ * @private internal utility, exported are only singleton instances of this class
2854
2874
  */
2855
2875
  class $Register {
2856
2876
  constructor(registerName) {
@@ -2894,10 +2914,10 @@ class $Register {
2894
2914
  }
2895
2915
 
2896
2916
  /**
2897
- * @@@
2917
+ * Global registry for storing metadata about all available scrapers and converters.
2898
2918
  *
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 @@@
2919
+ * Note: `$` is used to indicate that this interacts with the global scope.
2920
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
2901
2921
  * @public exported from `@promptbook/core`
2902
2922
  */
2903
2923
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4184,7 +4204,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4184
4204
  * Function to check if a string is valid CSV
4185
4205
  *
4186
4206
  * @param value The string to check
4187
- * @returns True if the string is a valid CSV string, false otherwise
4207
+ * @returns `true` if the string is a valid CSV string, false otherwise
4188
4208
  *
4189
4209
  * @public exported from `@promptbook/utils`
4190
4210
  */
@@ -4241,18 +4261,28 @@ const CsvFormatParser = {
4241
4261
  `));
4242
4262
  }
4243
4263
  const mappedData = [];
4244
- for (let index = 0; index < csv.data.length; index++) {
4264
+ const length = csv.data.length;
4265
+ for (let index = 0; index < length; index++) {
4245
4266
  const row = csv.data[index];
4246
4267
  if (row[outputParameterName]) {
4247
4268
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4248
4269
  }
4249
4270
  const mappedRow = {
4250
4271
  ...row,
4251
- [outputParameterName]: await mapCallback(row, index),
4272
+ [outputParameterName]: await mapCallback(row, index, length),
4252
4273
  };
4253
4274
  mappedData.push(mappedRow);
4254
4275
  if (onProgress) {
4255
4276
  // Note: Report the CSV with all rows mapped so far
4277
+ /*
4278
+ !!!!
4279
+ // Report progress with updated value
4280
+ const progressData = mappedData.map((row, i) =>
4281
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4282
+ );
4283
+
4284
+
4285
+ */
4256
4286
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4257
4287
  }
4258
4288
  }
@@ -4279,9 +4309,9 @@ const CsvFormatParser = {
4279
4309
  `));
4280
4310
  }
4281
4311
  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) => {
4312
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4283
4313
  const index = rowIndex * Object.keys(row).length + columnIndex;
4284
- return /* not await */ mapCallback({ [key]: value }, index);
4314
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4285
4315
  }));
4286
4316
  }));
4287
4317
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4352,12 +4382,12 @@ const TextFormatParser = {
4352
4382
  async mapValues(options) {
4353
4383
  const { value, mapCallback, onProgress } = options;
4354
4384
  const lines = value.split('\n');
4355
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4385
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4356
4386
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4357
4387
  /* not await */ mapCallback({
4358
4388
  lineContent,
4359
4389
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4360
- }, lineNumber)));
4390
+ }, lineNumber, array.length)));
4361
4391
  return mappedLines.join('\n');
4362
4392
  },
4363
4393
  },
@@ -4378,7 +4408,7 @@ const TextFormatParser = {
4378
4408
  * Function to check if a string is valid XML
4379
4409
  *
4380
4410
  * @param value
4381
- * @returns True if the string is a valid XML string, false otherwise
4411
+ * @returns `true` if the string is a valid XML string, false otherwise
4382
4412
  *
4383
4413
  * @public exported from `@promptbook/utils`
4384
4414
  */
@@ -4440,13 +4470,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4440
4470
  */
4441
4471
 
4442
4472
  /**
4443
- * Maps available parameters to expected parameters
4473
+ * Maps available parameters to expected parameters for a pipeline task.
4444
4474
  *
4445
4475
  * The strategy is:
4446
- * 1) @@@
4447
- * 2) @@@
4476
+ * 1) First, match parameters by name where both available and expected.
4477
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4448
4478
  *
4449
- * @throws {PipelineExecutionError} @@@
4479
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4450
4480
  * @private within the repository used in `createPipelineExecutor`
4451
4481
  */
4452
4482
  function mapAvailableToExpectedParameters(options) {
@@ -5064,7 +5094,11 @@ async function executeAttempts(options) {
5064
5094
  */
5065
5095
 
5066
5096
  /**
5067
- * @@@
5097
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5098
+ * Handles format and subformat resolution, error handling, and progress reporting.
5099
+ *
5100
+ * @param options - Options for execution, including task details and progress callback.
5101
+ * @returns The result of the subvalue mapping or execution attempts.
5068
5102
  *
5069
5103
  * @private internal utility of `createPipelineExecutor`
5070
5104
  */
@@ -5129,15 +5163,11 @@ async function executeFormatSubvalues(options) {
5129
5163
  settings: formatSettings,
5130
5164
  onProgress(partialResultString) {
5131
5165
  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,
5166
+ [task.resultingParameterName]: partialResultString,
5135
5167
  }));
5136
5168
  },
5137
- async mapCallback(subparameters, index) {
5169
+ async mapCallback(subparameters, index, length) {
5138
5170
  let mappedParameters;
5139
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5140
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5141
5171
  try {
5142
5172
  mappedParameters = mapAvailableToExpectedParameters({
5143
5173
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5148,32 +5178,52 @@ async function executeFormatSubvalues(options) {
5148
5178
  if (!(error instanceof PipelineExecutionError)) {
5149
5179
  throw error;
5150
5180
  }
5151
- throw new PipelineExecutionError(spaceTrim((block) => `
5152
- ${error.message}
5181
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5182
+ ${error.message}
5153
5183
 
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
5184
+ This is error in FOREACH command when mapping data
5185
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5156
5186
 
5157
- ${block(pipelineIdentification)}
5158
- Subparameter index: ${index}
5159
- `));
5187
+ ${block(pipelineIdentification)}
5188
+ Subparameter index: ${index}
5189
+ `));
5190
+ if (length > BIG_DATASET_TRESHOLD) {
5191
+ console.error(highLevelError);
5192
+ return FAILED_VALUE_PLACEHOLDER;
5193
+ }
5194
+ throw highLevelError;
5160
5195
  }
5161
5196
  const allSubparameters = {
5162
5197
  ...parameters,
5163
5198
  ...mappedParameters,
5164
5199
  };
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
5200
  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;
5201
+ try {
5202
+ const subresultString = await executeAttempts({
5203
+ ...options,
5204
+ priority: priority + index,
5205
+ parameters: allSubparameters,
5206
+ pipelineIdentification: spaceTrim((block) => `
5207
+ ${block(pipelineIdentification)}
5208
+ Subparameter index: ${index}
5209
+ `),
5210
+ });
5211
+ return subresultString;
5212
+ }
5213
+ catch (error) {
5214
+ if (length > BIG_DATASET_TRESHOLD) {
5215
+ console.error(spaceTrim((block) => `
5216
+ Error in FOREACH command:
5217
+
5218
+ ${block(pipelineIdentification)}
5219
+
5220
+ ${block(pipelineIdentification)}
5221
+ Subparameter index: ${index}
5222
+ `));
5223
+ return FAILED_VALUE_PLACEHOLDER;
5224
+ }
5225
+ throw error;
5226
+ }
5177
5227
  },
5178
5228
  });
5179
5229
  return resultString;
@@ -5308,7 +5358,11 @@ async function getKnowledgeForTask(options) {
5308
5358
  */
5309
5359
 
5310
5360
  /**
5311
- * @@@
5361
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5362
+ * Ensures all reserved parameters are defined and throws if any are missing.
5363
+ *
5364
+ * @param options - Options including tools, pipeline, task, and context.
5365
+ * @returns An object containing all reserved parameters for the task.
5312
5366
  *
5313
5367
  * @private internal utility of `createPipelineExecutor`
5314
5368
  */
@@ -5341,7 +5395,10 @@ async function getReservedParametersForTask(options) {
5341
5395
  }
5342
5396
 
5343
5397
  /**
5344
- * @@@
5398
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5399
+ *
5400
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5401
+ * @returns The output parameters produced by the task.
5345
5402
  *
5346
5403
  * @private internal utility of `createPipelineExecutor`
5347
5404
  */
@@ -5475,9 +5532,12 @@ function filterJustOutputParameters(options) {
5475
5532
  }
5476
5533
 
5477
5534
  /**
5478
- * @@@
5535
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5536
+ *
5537
+ * 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
5538
  *
5480
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5539
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5540
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5481
5541
  *
5482
5542
  * @private internal utility of `createPipelineExecutor`
5483
5543
  */