@promptbook/node 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 +128 -66
  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 +2 -2
  34. package/umd/index.umd.js +128 -66
  35. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-24';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -101,6 +101,21 @@ const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
101
101
  * @public exported from `@promptbook/core`
102
102
  */
103
103
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
104
+ /**
105
+ * Threshold value that determines when a dataset is considered "big"
106
+ * and may require special handling or optimizations
107
+ *
108
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
109
+ *
110
+ * @public exported from `@promptbook/core`
111
+ */
112
+ const BIG_DATASET_TRESHOLD = 50;
113
+ /**
114
+ * Placeholder text used to represent a placeholder value of failed operation
115
+ *
116
+ * @public exported from `@promptbook/core`
117
+ */
118
+ const FAILED_VALUE_PLACEHOLDER = '!?';
104
119
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
105
120
  /**
106
121
  * The maximum number of iterations for a loops
@@ -195,7 +210,7 @@ ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
195
210
  const DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = `index`;
196
211
  // <- TODO: [🧜‍♂️]
197
212
  /**
198
- * @@@
213
+ * Default settings for parsing and generating CSV files in Promptbook.
199
214
  *
200
215
  * @public exported from `@promptbook/core`
201
216
  */
@@ -206,19 +221,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
206
221
  skipEmptyLines: true,
207
222
  });
208
223
  /**
209
- * @@@
224
+ * Controls whether verbose logging is enabled by default throughout the application.
210
225
  *
211
226
  * @public exported from `@promptbook/core`
212
227
  */
213
228
  let DEFAULT_IS_VERBOSE = false;
214
229
  /**
215
- * @@@
230
+ * Controls whether auto-installation of dependencies is enabled by default.
216
231
  *
217
232
  * @public exported from `@promptbook/core`
218
233
  */
219
234
  const DEFAULT_IS_AUTO_INSTALLED = false;
220
235
  /**
221
- * @@@
236
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
222
237
  *
223
238
  * @private within the repository
224
239
  */
@@ -564,8 +579,12 @@ function checkSerializableAsJson(options) {
564
579
  */
565
580
 
566
581
  /**
567
- * @@@
582
+ * Creates a deep clone of the given object
583
+ *
584
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
568
585
  *
586
+ * @param objectValue The object to clone.
587
+ * @returns A deep, writable clone of the input object.
569
588
  * @public exported from `@promptbook/utils`
570
589
  */
571
590
  function deepClone(objectValue) {
@@ -1204,7 +1223,7 @@ function isValidFilePath(filename) {
1204
1223
  * Function isValidJsonString will tell you if the string is valid JSON or not
1205
1224
  *
1206
1225
  * @param value The string to check
1207
- * @returns True if the string is a valid JSON string, false otherwise
1226
+ * @returns `true` if the string is a valid JSON string, false otherwise
1208
1227
  *
1209
1228
  * @public exported from `@promptbook/utils`
1210
1229
  */
@@ -1526,7 +1545,7 @@ class SimplePipelineCollection {
1526
1545
  /**
1527
1546
  * Constructs a pipeline collection from pipelines
1528
1547
  *
1529
- * @param pipelines @@@
1548
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1530
1549
  *
1531
1550
  * Note: During the construction logic of all pipelines are validated
1532
1551
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -2546,7 +2565,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
2546
2565
  * Function to check if a string is valid CSV
2547
2566
  *
2548
2567
  * @param value The string to check
2549
- * @returns True if the string is a valid CSV string, false otherwise
2568
+ * @returns `true` if the string is a valid CSV string, false otherwise
2550
2569
  *
2551
2570
  * @public exported from `@promptbook/utils`
2552
2571
  */
@@ -2603,18 +2622,28 @@ const CsvFormatParser = {
2603
2622
  `));
2604
2623
  }
2605
2624
  const mappedData = [];
2606
- for (let index = 0; index < csv.data.length; index++) {
2625
+ const length = csv.data.length;
2626
+ for (let index = 0; index < length; index++) {
2607
2627
  const row = csv.data[index];
2608
2628
  if (row[outputParameterName]) {
2609
2629
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
2610
2630
  }
2611
2631
  const mappedRow = {
2612
2632
  ...row,
2613
- [outputParameterName]: await mapCallback(row, index),
2633
+ [outputParameterName]: await mapCallback(row, index, length),
2614
2634
  };
2615
2635
  mappedData.push(mappedRow);
2616
2636
  if (onProgress) {
2617
2637
  // Note: Report the CSV with all rows mapped so far
2638
+ /*
2639
+ !!!!
2640
+ // Report progress with updated value
2641
+ const progressData = mappedData.map((row, i) =>
2642
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
2643
+ );
2644
+
2645
+
2646
+ */
2618
2647
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
2619
2648
  }
2620
2649
  }
@@ -2641,9 +2670,9 @@ const CsvFormatParser = {
2641
2670
  `));
2642
2671
  }
2643
2672
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
2644
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
2673
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
2645
2674
  const index = rowIndex * Object.keys(row).length + columnIndex;
2646
- return /* not await */ mapCallback({ [key]: value }, index);
2675
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
2647
2676
  }));
2648
2677
  }));
2649
2678
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -2714,12 +2743,12 @@ const TextFormatParser = {
2714
2743
  async mapValues(options) {
2715
2744
  const { value, mapCallback, onProgress } = options;
2716
2745
  const lines = value.split('\n');
2717
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
2746
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
2718
2747
  // TODO: [🧠] Maybe option to skip empty line
2719
2748
  /* not await */ mapCallback({
2720
2749
  lineContent,
2721
2750
  // TODO: [🧠] Maybe also put here `lineNumber`
2722
- }, lineNumber)));
2751
+ }, lineNumber, array.length)));
2723
2752
  return mappedLines.join('\n');
2724
2753
  },
2725
2754
  },
@@ -2740,7 +2769,7 @@ const TextFormatParser = {
2740
2769
  * Function to check if a string is valid XML
2741
2770
  *
2742
2771
  * @param value
2743
- * @returns True if the string is a valid XML string, false otherwise
2772
+ * @returns `true` if the string is a valid XML string, false otherwise
2744
2773
  *
2745
2774
  * @public exported from `@promptbook/utils`
2746
2775
  */
@@ -2802,13 +2831,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
2802
2831
  */
2803
2832
 
2804
2833
  /**
2805
- * Maps available parameters to expected parameters
2834
+ * Maps available parameters to expected parameters for a pipeline task.
2806
2835
  *
2807
2836
  * The strategy is:
2808
- * 1) @@@
2809
- * 2) @@@
2837
+ * 1) First, match parameters by name where both available and expected.
2838
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
2810
2839
  *
2811
- * @throws {PipelineExecutionError} @@@
2840
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
2812
2841
  * @private within the repository used in `createPipelineExecutor`
2813
2842
  */
2814
2843
  function mapAvailableToExpectedParameters(options) {
@@ -4017,7 +4046,11 @@ async function executeAttempts(options) {
4017
4046
  */
4018
4047
 
4019
4048
  /**
4020
- * @@@
4049
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
4050
+ * Handles format and subformat resolution, error handling, and progress reporting.
4051
+ *
4052
+ * @param options - Options for execution, including task details and progress callback.
4053
+ * @returns The result of the subvalue mapping or execution attempts.
4021
4054
  *
4022
4055
  * @private internal utility of `createPipelineExecutor`
4023
4056
  */
@@ -4082,15 +4115,11 @@ async function executeFormatSubvalues(options) {
4082
4115
  settings: formatSettings,
4083
4116
  onProgress(partialResultString) {
4084
4117
  return onProgress(Object.freeze({
4085
- [task.resultingParameterName]:
4086
- // <- Note: [👩‍👩‍👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
4087
- partialResultString,
4118
+ [task.resultingParameterName]: partialResultString,
4088
4119
  }));
4089
4120
  },
4090
- async mapCallback(subparameters, index) {
4121
+ async mapCallback(subparameters, index, length) {
4091
4122
  let mappedParameters;
4092
- // TODO: [🤹‍♂️][🪂] Limit to N concurrent executions
4093
- // TODO: When done [🐚] Report progress also for each subvalue here
4094
4123
  try {
4095
4124
  mappedParameters = mapAvailableToExpectedParameters({
4096
4125
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -4101,32 +4130,52 @@ async function executeFormatSubvalues(options) {
4101
4130
  if (!(error instanceof PipelineExecutionError)) {
4102
4131
  throw error;
4103
4132
  }
4104
- throw new PipelineExecutionError(spaceTrim((block) => `
4105
- ${error.message}
4133
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
4134
+ ${error.message}
4106
4135
 
4107
- This is error in FOREACH command
4108
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
4136
+ This is error in FOREACH command when mapping data
4137
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
4109
4138
 
4110
- ${block(pipelineIdentification)}
4111
- Subparameter index: ${index}
4112
- `));
4139
+ ${block(pipelineIdentification)}
4140
+ Subparameter index: ${index}
4141
+ `));
4142
+ if (length > BIG_DATASET_TRESHOLD) {
4143
+ console.error(highLevelError);
4144
+ return FAILED_VALUE_PLACEHOLDER;
4145
+ }
4146
+ throw highLevelError;
4113
4147
  }
4114
4148
  const allSubparameters = {
4115
4149
  ...parameters,
4116
4150
  ...mappedParameters,
4117
4151
  };
4118
- // 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
4119
4152
  Object.freeze(allSubparameters);
4120
- const subresultString = await executeAttempts({
4121
- ...options,
4122
- priority: priority + index,
4123
- parameters: allSubparameters,
4124
- pipelineIdentification: spaceTrim((block) => `
4125
- ${block(pipelineIdentification)}
4126
- Subparameter index: ${index}
4127
- `),
4128
- });
4129
- return subresultString;
4153
+ try {
4154
+ const subresultString = await executeAttempts({
4155
+ ...options,
4156
+ priority: priority + index,
4157
+ parameters: allSubparameters,
4158
+ pipelineIdentification: spaceTrim((block) => `
4159
+ ${block(pipelineIdentification)}
4160
+ Subparameter index: ${index}
4161
+ `),
4162
+ });
4163
+ return subresultString;
4164
+ }
4165
+ catch (error) {
4166
+ if (length > BIG_DATASET_TRESHOLD) {
4167
+ console.error(spaceTrim((block) => `
4168
+ Error in FOREACH command:
4169
+
4170
+ ${block(pipelineIdentification)}
4171
+
4172
+ ${block(pipelineIdentification)}
4173
+ Subparameter index: ${index}
4174
+ `));
4175
+ return FAILED_VALUE_PLACEHOLDER;
4176
+ }
4177
+ throw error;
4178
+ }
4130
4179
  },
4131
4180
  });
4132
4181
  return resultString;
@@ -4261,7 +4310,11 @@ async function getKnowledgeForTask(options) {
4261
4310
  */
4262
4311
 
4263
4312
  /**
4264
- * @@@
4313
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
4314
+ * Ensures all reserved parameters are defined and throws if any are missing.
4315
+ *
4316
+ * @param options - Options including tools, pipeline, task, and context.
4317
+ * @returns An object containing all reserved parameters for the task.
4265
4318
  *
4266
4319
  * @private internal utility of `createPipelineExecutor`
4267
4320
  */
@@ -4294,7 +4347,10 @@ async function getReservedParametersForTask(options) {
4294
4347
  }
4295
4348
 
4296
4349
  /**
4297
- * @@@
4350
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
4351
+ *
4352
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
4353
+ * @returns The output parameters produced by the task.
4298
4354
  *
4299
4355
  * @private internal utility of `createPipelineExecutor`
4300
4356
  */
@@ -4428,9 +4484,12 @@ function filterJustOutputParameters(options) {
4428
4484
  }
4429
4485
 
4430
4486
  /**
4431
- * @@@
4487
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
4432
4488
  *
4433
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
4489
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
4490
+ *
4491
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
4492
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
4434
4493
  *
4435
4494
  * @private internal utility of `createPipelineExecutor`
4436
4495
  */
@@ -4952,7 +5011,8 @@ async function preparePersona(personaDescription, tools, options) {
4952
5011
  */
4953
5012
 
4954
5013
  /**
4955
- * @@@
5014
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
5015
+ * regardless of the JavaScript environment in which the code is running
4956
5016
  *
4957
5017
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
4958
5018
  *
@@ -5031,11 +5091,11 @@ function normalizeTo_snake_case(text) {
5031
5091
  }
5032
5092
 
5033
5093
  /**
5034
- * Register is @@@
5094
+ * Global registry for storing and managing registered entities of a given type.
5035
5095
  *
5036
5096
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
5037
5097
  *
5038
- * @private internal utility, exported are only signleton instances of this class
5098
+ * @private internal utility, exported are only singleton instances of this class
5039
5099
  */
5040
5100
  class $Register {
5041
5101
  constructor(registerName) {
@@ -5079,10 +5139,10 @@ class $Register {
5079
5139
  }
5080
5140
 
5081
5141
  /**
5082
- * @@@
5142
+ * Global registry for storing metadata about all available scrapers and converters.
5083
5143
  *
5084
- * Note: `$` is used to indicate that this interacts with the global scope
5085
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
5144
+ * Note: `$` is used to indicate that this interacts with the global scope.
5145
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
5086
5146
  * @public exported from `@promptbook/core`
5087
5147
  */
5088
5148
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -6621,11 +6681,12 @@ function removeQuotes(text) {
6621
6681
  }
6622
6682
 
6623
6683
  /**
6624
- * Function `validateParameterName` will @@@
6684
+ * Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
6685
+ * It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
6625
6686
  *
6626
- * @param parameterName @@@
6627
- * @returns @@@
6628
- * @throws {ParseError} @@@
6687
+ * @param parameterName The parameter name to validate and normalize.
6688
+ * @returns The validated and normalized parameter name.
6689
+ * @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
6629
6690
  * @private within the repository
6630
6691
  */
6631
6692
  function validateParameterName(parameterName) {
@@ -7118,14 +7179,15 @@ const MatcherFormfactorDefinition = {
7118
7179
  };
7119
7180
 
7120
7181
  /**
7121
- * Sheets is form of app that @@@
7182
+ * Sheets is form of app that processes tabular data in CSV format, allowing transformation
7183
+ * and analysis of structured data through AI-powered operations
7122
7184
  *
7123
7185
  * @public exported from `@promptbook/core`
7124
7186
  */
7125
7187
  const SheetsFormfactorDefinition = {
7126
7188
  name: 'SHEETS',
7127
7189
  aliasNames: ['SHEETS', 'SHEET'],
7128
- description: `@@@`,
7190
+ description: `A formfactor for processing spreadsheet-like data in CSV format, enabling AI transformations on tabular data`,
7129
7191
  documentationUrl: `https://github.com/webgptorg/promptbook/discussions/176`,
7130
7192
  pipelineInterface: {
7131
7193
  inputParameters: [
@@ -7201,7 +7263,7 @@ const FORMFACTOR_DEFINITIONS = [
7201
7263
  /**
7202
7264
  * Parses the formfactor command
7203
7265
  *
7204
- * Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book` file
7266
+ * Note: This command is used as a formfactor for new commands and defines the app type format - it should NOT be used in any `.book` file
7205
7267
  *
7206
7268
  * @see `documentationUrl` for more details
7207
7269
  * @public exported from `@promptbook/editable`
@@ -7223,7 +7285,7 @@ const formfactorCommandParser = {
7223
7285
  /**
7224
7286
  * Description of the FORMFACTOR command
7225
7287
  */
7226
- description: `@@`,
7288
+ description: `Specifies the application type and interface requirements that this promptbook should conform to`,
7227
7289
  /**
7228
7290
  * Link to documentation
7229
7291
  */
@@ -7799,10 +7861,10 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7799
7861
  }
7800
7862
 
7801
7863
  /**
7802
- * @@@
7864
+ * Checks if the given value is a valid JavaScript identifier name.
7803
7865
  *
7804
- * @param javascriptName @@@
7805
- * @returns @@@
7866
+ * @param javascriptName The value to check for JavaScript identifier validity.
7867
+ * @returns `true` if the value is a valid JavaScript name, false otherwise.
7806
7868
  * @public exported from `@promptbook/utils`
7807
7869
  */
7808
7870
  function isValidJavascriptName(javascriptName) {