@promptbook/remote-server 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 +2 -2
  34. package/umd/index.umd.js +115 -55
  35. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-24';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -100,6 +100,21 @@ const DEFAULT_BOOK_TITLE = `โœจ Untitled Book`;
100
100
  * @public exported from `@promptbook/core`
101
101
  */
102
102
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
103
+ /**
104
+ * Threshold value that determines when a dataset is considered "big"
105
+ * and may require special handling or optimizations
106
+ *
107
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
108
+ *
109
+ * @public exported from `@promptbook/core`
110
+ */
111
+ const BIG_DATASET_TRESHOLD = 50;
112
+ /**
113
+ * Placeholder text used to represent a placeholder value of failed operation
114
+ *
115
+ * @public exported from `@promptbook/core`
116
+ */
117
+ const FAILED_VALUE_PLACEHOLDER = '!?';
103
118
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
104
119
  /**
105
120
  * The maximum number of iterations for a loops
@@ -179,7 +194,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
179
194
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
180
195
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
181
196
  /**
182
- * @@@
197
+ * Default settings for parsing and generating CSV files in Promptbook.
183
198
  *
184
199
  * @public exported from `@promptbook/core`
185
200
  */
@@ -190,19 +205,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
190
205
  skipEmptyLines: true,
191
206
  });
192
207
  /**
193
- * @@@
208
+ * Controls whether verbose logging is enabled by default throughout the application.
194
209
  *
195
210
  * @public exported from `@promptbook/core`
196
211
  */
197
212
  let DEFAULT_IS_VERBOSE = false;
198
213
  /**
199
- * @@@
214
+ * Controls whether auto-installation of dependencies is enabled by default.
200
215
  *
201
216
  * @public exported from `@promptbook/core`
202
217
  */
203
218
  const DEFAULT_IS_AUTO_INSTALLED = false;
204
219
  /**
205
- * @@@
220
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
206
221
  *
207
222
  * @private within the repository
208
223
  */
@@ -1262,8 +1277,12 @@ function checkSerializableAsJson(options) {
1262
1277
  */
1263
1278
 
1264
1279
  /**
1265
- * @@@
1280
+ * Creates a deep clone of the given object
1281
+ *
1282
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1266
1283
  *
1284
+ * @param objectValue The object to clone.
1285
+ * @returns A deep, writable clone of the input object.
1267
1286
  * @public exported from `@promptbook/utils`
1268
1287
  */
1269
1288
  function deepClone(objectValue) {
@@ -1821,7 +1840,7 @@ function isPipelinePrepared(pipeline) {
1821
1840
  * Function isValidJsonString will tell you if the string is valid JSON or not
1822
1841
  *
1823
1842
  * @param value The string to check
1824
- * @returns True if the string is a valid JSON string, false otherwise
1843
+ * @returns `true` if the string is a valid JSON string, false otherwise
1825
1844
  *
1826
1845
  * @public exported from `@promptbook/utils`
1827
1846
  */
@@ -2482,7 +2501,7 @@ class SimplePipelineCollection {
2482
2501
  /**
2483
2502
  * Constructs a pipeline collection from pipelines
2484
2503
  *
2485
- * @param pipelines @@@
2504
+ * @param pipelines Array of pipeline JSON objects to include in the collection
2486
2505
  *
2487
2506
  * Note: During the construction logic of all pipelines are validated
2488
2507
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -3013,7 +3032,8 @@ async function preparePersona(personaDescription, tools, options) {
3013
3032
  */
3014
3033
 
3015
3034
  /**
3016
- * @@@
3035
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3036
+ * regardless of the JavaScript environment in which the code is running
3017
3037
  *
3018
3038
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3019
3039
  *
@@ -3092,11 +3112,11 @@ function normalizeTo_snake_case(text) {
3092
3112
  }
3093
3113
 
3094
3114
  /**
3095
- * Register is @@@
3115
+ * Global registry for storing and managing registered entities of a given type.
3096
3116
  *
3097
3117
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3098
3118
  *
3099
- * @private internal utility, exported are only signleton instances of this class
3119
+ * @private internal utility, exported are only singleton instances of this class
3100
3120
  */
3101
3121
  class $Register {
3102
3122
  constructor(registerName) {
@@ -3140,10 +3160,10 @@ class $Register {
3140
3160
  }
3141
3161
 
3142
3162
  /**
3143
- * @@@
3163
+ * Global registry for storing metadata about all available scrapers and converters.
3144
3164
  *
3145
- * Note: `$` is used to indicate that this interacts with the global scope
3146
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3165
+ * Note: `$` is used to indicate that this interacts with the global scope.
3166
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3147
3167
  * @public exported from `@promptbook/core`
3148
3168
  */
3149
3169
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4430,7 +4450,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4430
4450
  * Function to check if a string is valid CSV
4431
4451
  *
4432
4452
  * @param value The string to check
4433
- * @returns True if the string is a valid CSV string, false otherwise
4453
+ * @returns `true` if the string is a valid CSV string, false otherwise
4434
4454
  *
4435
4455
  * @public exported from `@promptbook/utils`
4436
4456
  */
@@ -4487,18 +4507,28 @@ const CsvFormatParser = {
4487
4507
  `));
4488
4508
  }
4489
4509
  const mappedData = [];
4490
- for (let index = 0; index < csv.data.length; index++) {
4510
+ const length = csv.data.length;
4511
+ for (let index = 0; index < length; index++) {
4491
4512
  const row = csv.data[index];
4492
4513
  if (row[outputParameterName]) {
4493
4514
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4494
4515
  }
4495
4516
  const mappedRow = {
4496
4517
  ...row,
4497
- [outputParameterName]: await mapCallback(row, index),
4518
+ [outputParameterName]: await mapCallback(row, index, length),
4498
4519
  };
4499
4520
  mappedData.push(mappedRow);
4500
4521
  if (onProgress) {
4501
4522
  // Note: Report the CSV with all rows mapped so far
4523
+ /*
4524
+ !!!!
4525
+ // Report progress with updated value
4526
+ const progressData = mappedData.map((row, i) =>
4527
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4528
+ );
4529
+
4530
+
4531
+ */
4502
4532
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4503
4533
  }
4504
4534
  }
@@ -4525,9 +4555,9 @@ const CsvFormatParser = {
4525
4555
  `));
4526
4556
  }
4527
4557
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4528
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4558
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4529
4559
  const index = rowIndex * Object.keys(row).length + columnIndex;
4530
- return /* not await */ mapCallback({ [key]: value }, index);
4560
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4531
4561
  }));
4532
4562
  }));
4533
4563
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4598,12 +4628,12 @@ const TextFormatParser = {
4598
4628
  async mapValues(options) {
4599
4629
  const { value, mapCallback, onProgress } = options;
4600
4630
  const lines = value.split('\n');
4601
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4631
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4602
4632
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4603
4633
  /* not await */ mapCallback({
4604
4634
  lineContent,
4605
4635
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4606
- }, lineNumber)));
4636
+ }, lineNumber, array.length)));
4607
4637
  return mappedLines.join('\n');
4608
4638
  },
4609
4639
  },
@@ -4624,7 +4654,7 @@ const TextFormatParser = {
4624
4654
  * Function to check if a string is valid XML
4625
4655
  *
4626
4656
  * @param value
4627
- * @returns True if the string is a valid XML string, false otherwise
4657
+ * @returns `true` if the string is a valid XML string, false otherwise
4628
4658
  *
4629
4659
  * @public exported from `@promptbook/utils`
4630
4660
  */
@@ -4686,13 +4716,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4686
4716
  */
4687
4717
 
4688
4718
  /**
4689
- * Maps available parameters to expected parameters
4719
+ * Maps available parameters to expected parameters for a pipeline task.
4690
4720
  *
4691
4721
  * The strategy is:
4692
- * 1) @@@
4693
- * 2) @@@
4722
+ * 1) First, match parameters by name where both available and expected.
4723
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4694
4724
  *
4695
- * @throws {PipelineExecutionError} @@@
4725
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4696
4726
  * @private within the repository used in `createPipelineExecutor`
4697
4727
  */
4698
4728
  function mapAvailableToExpectedParameters(options) {
@@ -5429,7 +5459,11 @@ async function executeAttempts(options) {
5429
5459
  */
5430
5460
 
5431
5461
  /**
5432
- * @@@
5462
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5463
+ * Handles format and subformat resolution, error handling, and progress reporting.
5464
+ *
5465
+ * @param options - Options for execution, including task details and progress callback.
5466
+ * @returns The result of the subvalue mapping or execution attempts.
5433
5467
  *
5434
5468
  * @private internal utility of `createPipelineExecutor`
5435
5469
  */
@@ -5494,15 +5528,11 @@ async function executeFormatSubvalues(options) {
5494
5528
  settings: formatSettings,
5495
5529
  onProgress(partialResultString) {
5496
5530
  return onProgress(Object.freeze({
5497
- [task.resultingParameterName]:
5498
- // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
5499
- partialResultString,
5531
+ [task.resultingParameterName]: partialResultString,
5500
5532
  }));
5501
5533
  },
5502
- async mapCallback(subparameters, index) {
5534
+ async mapCallback(subparameters, index, length) {
5503
5535
  let mappedParameters;
5504
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5505
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5506
5536
  try {
5507
5537
  mappedParameters = mapAvailableToExpectedParameters({
5508
5538
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5513,32 +5543,52 @@ async function executeFormatSubvalues(options) {
5513
5543
  if (!(error instanceof PipelineExecutionError)) {
5514
5544
  throw error;
5515
5545
  }
5516
- throw new PipelineExecutionError(spaceTrim((block) => `
5517
- ${error.message}
5546
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5547
+ ${error.message}
5518
5548
 
5519
- This is error in FOREACH command
5520
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5549
+ This is error in FOREACH command when mapping data
5550
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5521
5551
 
5522
- ${block(pipelineIdentification)}
5523
- Subparameter index: ${index}
5524
- `));
5552
+ ${block(pipelineIdentification)}
5553
+ Subparameter index: ${index}
5554
+ `));
5555
+ if (length > BIG_DATASET_TRESHOLD) {
5556
+ console.error(highLevelError);
5557
+ return FAILED_VALUE_PLACEHOLDER;
5558
+ }
5559
+ throw highLevelError;
5525
5560
  }
5526
5561
  const allSubparameters = {
5527
5562
  ...parameters,
5528
5563
  ...mappedParameters,
5529
5564
  };
5530
- // 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
5531
5565
  Object.freeze(allSubparameters);
5532
- const subresultString = await executeAttempts({
5533
- ...options,
5534
- priority: priority + index,
5535
- parameters: allSubparameters,
5536
- pipelineIdentification: spaceTrim((block) => `
5537
- ${block(pipelineIdentification)}
5538
- Subparameter index: ${index}
5539
- `),
5540
- });
5541
- return subresultString;
5566
+ try {
5567
+ const subresultString = await executeAttempts({
5568
+ ...options,
5569
+ priority: priority + index,
5570
+ parameters: allSubparameters,
5571
+ pipelineIdentification: spaceTrim((block) => `
5572
+ ${block(pipelineIdentification)}
5573
+ Subparameter index: ${index}
5574
+ `),
5575
+ });
5576
+ return subresultString;
5577
+ }
5578
+ catch (error) {
5579
+ if (length > BIG_DATASET_TRESHOLD) {
5580
+ console.error(spaceTrim((block) => `
5581
+ Error in FOREACH command:
5582
+
5583
+ ${block(pipelineIdentification)}
5584
+
5585
+ ${block(pipelineIdentification)}
5586
+ Subparameter index: ${index}
5587
+ `));
5588
+ return FAILED_VALUE_PLACEHOLDER;
5589
+ }
5590
+ throw error;
5591
+ }
5542
5592
  },
5543
5593
  });
5544
5594
  return resultString;
@@ -5673,7 +5723,11 @@ async function getKnowledgeForTask(options) {
5673
5723
  */
5674
5724
 
5675
5725
  /**
5676
- * @@@
5726
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5727
+ * Ensures all reserved parameters are defined and throws if any are missing.
5728
+ *
5729
+ * @param options - Options including tools, pipeline, task, and context.
5730
+ * @returns An object containing all reserved parameters for the task.
5677
5731
  *
5678
5732
  * @private internal utility of `createPipelineExecutor`
5679
5733
  */
@@ -5706,7 +5760,10 @@ async function getReservedParametersForTask(options) {
5706
5760
  }
5707
5761
 
5708
5762
  /**
5709
- * @@@
5763
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5764
+ *
5765
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5766
+ * @returns The output parameters produced by the task.
5710
5767
  *
5711
5768
  * @private internal utility of `createPipelineExecutor`
5712
5769
  */
@@ -5840,9 +5897,12 @@ function filterJustOutputParameters(options) {
5840
5897
  }
5841
5898
 
5842
5899
  /**
5843
- * @@@
5900
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5901
+ *
5902
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5844
5903
  *
5845
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5904
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5905
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5846
5906
  *
5847
5907
  * @private internal utility of `createPipelineExecutor`
5848
5908
  */