@promptbook/cli 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 +106 -60
  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 +106 -60
  26. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -163,6 +163,13 @@ const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
163
163
  * @public exported from `@promptbook/core`
164
164
  */
165
165
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
166
+ /**
167
+ * @@@
168
+ *
169
+ * @public exported from `@promptbook/core`
170
+ */
171
+ const BIG_DATASET_TRESHOLD = 50;
172
+ // <- TODO: !!!! Use
166
173
  /**
167
174
  * Warning message for the generated sections and files files
168
175
  *
@@ -247,6 +254,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
247
254
  * @public exported from `@promptbook/core`
248
255
  */
249
256
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
257
+ // <- TODO: [๐Ÿ]
250
258
  /**
251
259
  * Where to store your books
252
260
  * This is kind of a "src" for your books
@@ -318,7 +326,7 @@ const MOMENT_ARG_THRESHOLDS = {
318
326
  const DEFAULT_REMOTE_SERVER_URL = REMOTE_SERVER_URLS[0].urls[0];
319
327
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
320
328
  /**
321
- * @@@
329
+ * Default settings for parsing and generating CSV files in Promptbook.
322
330
  *
323
331
  * @public exported from `@promptbook/core`
324
332
  */
@@ -329,13 +337,13 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
329
337
  skipEmptyLines: true,
330
338
  });
331
339
  /**
332
- * @@@
340
+ * Controls whether verbose logging is enabled by default throughout the application.
333
341
  *
334
342
  * @public exported from `@promptbook/core`
335
343
  */
336
344
  let DEFAULT_IS_VERBOSE = false;
337
345
  /**
338
- * @@@
346
+ * Controls whether auto-installation of dependencies is enabled by default.
339
347
  *
340
348
  * @public exported from `@promptbook/core`
341
349
  */
@@ -355,7 +363,7 @@ const DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = `getPipelineCollection`;
355
363
  */
356
364
  const DEFAULT_RPM$1 = 60;
357
365
  /**
358
- * @@@
366
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
359
367
  *
360
368
  * @private within the repository
361
369
  */
@@ -774,11 +782,11 @@ function normalizeTo_snake_case(text) {
774
782
  }
775
783
 
776
784
  /**
777
- * Register is @@@
785
+ * Global registry for storing and managing registered entities of a given type.
778
786
  *
779
787
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
780
788
  *
781
- * @private internal utility, exported are only signleton instances of this class
789
+ * @private internal utility, exported are only singleton instances of this class
782
790
  */
783
791
  class $Register {
784
792
  constructor(registerName) {
@@ -1472,8 +1480,12 @@ function checkSerializableAsJson(options) {
1472
1480
  */
1473
1481
 
1474
1482
  /**
1475
- * @@@
1483
+ * Creates a deep clone of the given object
1484
+ *
1485
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1476
1486
  *
1487
+ * @param objectValue The object to clone.
1488
+ * @returns A deep, writable clone of the input object.
1477
1489
  * @public exported from `@promptbook/utils`
1478
1490
  */
1479
1491
  function deepClone(objectValue) {
@@ -2720,8 +2732,10 @@ function cacheLlmTools(llmTools, options = {}) {
2720
2732
  sha256(hexEncoder.parse(JSON.stringify({ parameters, content, modelRequirements }))).toString( /* hex */));
2721
2733
  const cacheItem = !isCacheReloaded ? await storage.getItem(key) : null;
2722
2734
  if (cacheItem) {
2735
+ console.log('!!! Cache hit for key:', key);
2723
2736
  return cacheItem.promptResult;
2724
2737
  }
2738
+ console.log('!!! Cache miss for key:', key);
2725
2739
  let promptResult;
2726
2740
  variant: switch (prompt.modelRequirements.modelVariant) {
2727
2741
  case 'CHAT':
@@ -3929,10 +3943,10 @@ async function $provideScrapersForNode(tools, options) {
3929
3943
  */
3930
3944
 
3931
3945
  /**
3932
- * @@@
3946
+ * Global registry for storing metadata about all available scrapers and converters.
3933
3947
  *
3934
- * Note: `$` is used to indicate that this interacts with the global scope
3935
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3948
+ * Note: `$` is used to indicate that this interacts with the global scope.
3949
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3936
3950
  * @public exported from `@promptbook/core`
3937
3951
  */
3938
3952
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4512,7 +4526,7 @@ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"
4512
4526
  * Function isValidJsonString will tell you if the string is valid JSON or not
4513
4527
  *
4514
4528
  * @param value The string to check
4515
- * @returns True if the string is a valid JSON string, false otherwise
4529
+ * @returns `true` if the string is a valid JSON string, false otherwise
4516
4530
  *
4517
4531
  * @public exported from `@promptbook/utils`
4518
4532
  */
@@ -5426,7 +5440,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
5426
5440
  * Function to check if a string is valid CSV
5427
5441
  *
5428
5442
  * @param value The string to check
5429
- * @returns True if the string is a valid CSV string, false otherwise
5443
+ * @returns `true` if the string is a valid CSV string, false otherwise
5430
5444
  *
5431
5445
  * @public exported from `@promptbook/utils`
5432
5446
  */
@@ -5483,14 +5497,15 @@ const CsvFormatParser = {
5483
5497
  `));
5484
5498
  }
5485
5499
  const mappedData = [];
5486
- for (let index = 0; index < csv.data.length; index++) {
5500
+ const length = csv.data.length;
5501
+ for (let index = 0; index < length; index++) {
5487
5502
  const row = csv.data[index];
5488
5503
  if (row[outputParameterName]) {
5489
5504
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
5490
5505
  }
5491
5506
  const mappedRow = {
5492
5507
  ...row,
5493
- [outputParameterName]: await mapCallback(row, index),
5508
+ [outputParameterName]: await mapCallback(row, index, length),
5494
5509
  };
5495
5510
  mappedData.push(mappedRow);
5496
5511
  if (onProgress) {
@@ -5521,9 +5536,9 @@ const CsvFormatParser = {
5521
5536
  `));
5522
5537
  }
5523
5538
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
5524
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
5539
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
5525
5540
  const index = rowIndex * Object.keys(row).length + columnIndex;
5526
- return /* not await */ mapCallback({ [key]: value }, index);
5541
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
5527
5542
  }));
5528
5543
  }));
5529
5544
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -5594,12 +5609,12 @@ const TextFormatParser = {
5594
5609
  async mapValues(options) {
5595
5610
  const { value, mapCallback, onProgress } = options;
5596
5611
  const lines = value.split('\n');
5597
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
5612
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
5598
5613
  // TODO: [๐Ÿง ] Maybe option to skip empty line
5599
5614
  /* not await */ mapCallback({
5600
5615
  lineContent,
5601
5616
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
5602
- }, lineNumber)));
5617
+ }, lineNumber, array.length)));
5603
5618
  return mappedLines.join('\n');
5604
5619
  },
5605
5620
  },
@@ -5620,7 +5635,7 @@ const TextFormatParser = {
5620
5635
  * Function to check if a string is valid XML
5621
5636
  *
5622
5637
  * @param value
5623
- * @returns True if the string is a valid XML string, false otherwise
5638
+ * @returns `true` if the string is a valid XML string, false otherwise
5624
5639
  *
5625
5640
  * @public exported from `@promptbook/utils`
5626
5641
  */
@@ -5682,13 +5697,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
5682
5697
  */
5683
5698
 
5684
5699
  /**
5685
- * Maps available parameters to expected parameters
5700
+ * Maps available parameters to expected parameters for a pipeline task.
5686
5701
  *
5687
5702
  * The strategy is:
5688
- * 1) @@@
5689
- * 2) @@@
5703
+ * 1) First, match parameters by name where both available and expected.
5704
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
5690
5705
  *
5691
- * @throws {PipelineExecutionError} @@@
5706
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
5692
5707
  * @private within the repository used in `createPipelineExecutor`
5693
5708
  */
5694
5709
  function mapAvailableToExpectedParameters(options) {
@@ -6427,7 +6442,11 @@ async function executeAttempts(options) {
6427
6442
  */
6428
6443
 
6429
6444
  /**
6430
- * @@@
6445
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
6446
+ * Handles format and subformat resolution, error handling, and progress reporting.
6447
+ *
6448
+ * @param options - Options for execution, including task details and progress callback.
6449
+ * @returns The result of the subvalue mapping or execution attempts.
6431
6450
  *
6432
6451
  * @private internal utility of `createPipelineExecutor`
6433
6452
  */
@@ -6492,15 +6511,11 @@ async function executeFormatSubvalues(options) {
6492
6511
  settings: formatSettings,
6493
6512
  onProgress(partialResultString) {
6494
6513
  return onProgress(Object.freeze({
6495
- [task.resultingParameterName]:
6496
- // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
6497
- partialResultString,
6514
+ [task.resultingParameterName]: partialResultString,
6498
6515
  }));
6499
6516
  },
6500
- async mapCallback(subparameters, index) {
6517
+ async mapCallback(subparameters, index, length) {
6501
6518
  let mappedParameters;
6502
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
6503
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
6504
6519
  try {
6505
6520
  mappedParameters = mapAvailableToExpectedParameters({
6506
6521
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -6511,32 +6526,52 @@ async function executeFormatSubvalues(options) {
6511
6526
  if (!(error instanceof PipelineExecutionError)) {
6512
6527
  throw error;
6513
6528
  }
6514
- throw new PipelineExecutionError(spaceTrim((block) => `
6515
- ${error.message}
6529
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
6530
+ ${error.message}
6516
6531
 
6517
- This is error in FOREACH command
6518
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
6532
+ This is error in FOREACH command when mapping data
6533
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
6519
6534
 
6520
- ${block(pipelineIdentification)}
6521
- Subparameter index: ${index}
6522
- `));
6535
+ ${block(pipelineIdentification)}
6536
+ Subparameter index: ${index}
6537
+ `));
6538
+ if (length > BIG_DATASET_TRESHOLD) {
6539
+ console.error(highLevelError);
6540
+ return '~';
6541
+ }
6542
+ throw highLevelError;
6523
6543
  }
6524
6544
  const allSubparameters = {
6525
6545
  ...parameters,
6526
6546
  ...mappedParameters,
6527
6547
  };
6528
- // 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
6529
6548
  Object.freeze(allSubparameters);
6530
- const subresultString = await executeAttempts({
6531
- ...options,
6532
- priority: priority + index,
6533
- parameters: allSubparameters,
6534
- pipelineIdentification: spaceTrim((block) => `
6535
- ${block(pipelineIdentification)}
6536
- Subparameter index: ${index}
6537
- `),
6538
- });
6539
- return subresultString;
6549
+ try {
6550
+ const subresultString = await executeAttempts({
6551
+ ...options,
6552
+ priority: priority + index,
6553
+ parameters: allSubparameters,
6554
+ pipelineIdentification: spaceTrim((block) => `
6555
+ ${block(pipelineIdentification)}
6556
+ Subparameter index: ${index}
6557
+ `),
6558
+ });
6559
+ return subresultString;
6560
+ }
6561
+ catch (error) {
6562
+ if (length > BIG_DATASET_TRESHOLD) {
6563
+ console.error(spaceTrim((block) => `
6564
+ Error in FOREACH command:
6565
+
6566
+ ${block(pipelineIdentification)}
6567
+
6568
+ ${block(pipelineIdentification)}
6569
+ Subparameter index: ${index}
6570
+ `));
6571
+ return '~';
6572
+ }
6573
+ throw error;
6574
+ }
6540
6575
  },
6541
6576
  });
6542
6577
  return resultString;
@@ -6671,7 +6706,11 @@ async function getKnowledgeForTask(options) {
6671
6706
  */
6672
6707
 
6673
6708
  /**
6674
- * @@@
6709
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
6710
+ * Ensures all reserved parameters are defined and throws if any are missing.
6711
+ *
6712
+ * @param options - Options including tools, pipeline, task, and context.
6713
+ * @returns An object containing all reserved parameters for the task.
6675
6714
  *
6676
6715
  * @private internal utility of `createPipelineExecutor`
6677
6716
  */
@@ -6704,7 +6743,10 @@ async function getReservedParametersForTask(options) {
6704
6743
  }
6705
6744
 
6706
6745
  /**
6707
- * @@@
6746
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
6747
+ *
6748
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
6749
+ * @returns The output parameters produced by the task.
6708
6750
  *
6709
6751
  * @private internal utility of `createPipelineExecutor`
6710
6752
  */
@@ -6838,9 +6880,12 @@ function filterJustOutputParameters(options) {
6838
6880
  }
6839
6881
 
6840
6882
  /**
6841
- * @@@
6883
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
6884
+ *
6885
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
6842
6886
  *
6843
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
6887
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
6888
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
6844
6889
  *
6845
6890
  * @private internal utility of `createPipelineExecutor`
6846
6891
  */
@@ -8566,11 +8611,12 @@ function removeQuotes(text) {
8566
8611
  }
8567
8612
 
8568
8613
  /**
8569
- * Function `validateParameterName` will @@@
8614
+ * Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
8615
+ * It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
8570
8616
  *
8571
- * @param parameterName @@@
8572
- * @returns @@@
8573
- * @throws {ParseError} @@@
8617
+ * @param parameterName The parameter name to validate and normalize.
8618
+ * @returns The validated and normalized parameter name.
8619
+ * @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
8574
8620
  * @private within the repository
8575
8621
  */
8576
8622
  function validateParameterName(parameterName) {
@@ -9744,10 +9790,10 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
9744
9790
  }
9745
9791
 
9746
9792
  /**
9747
- * @@@
9793
+ * Checks if the given value is a valid JavaScript identifier name.
9748
9794
  *
9749
- * @param javascriptName @@@
9750
- * @returns @@@
9795
+ * @param javascriptName The value to check for JavaScript identifier validity.
9796
+ * @returns `true` if the value is a valid JavaScript name, false otherwise.
9751
9797
  * @public exported from `@promptbook/utils`
9752
9798
  */
9753
9799
  function isValidJavascriptName(javascriptName) {