@promptbook/remote-server 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 +2 -2
  25. package/umd/index.umd.js +94 -53
  26. package/umd/index.umd.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.92.0-22",
3
+ "version": "0.92.0-23",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -51,7 +51,7 @@
51
51
  "module": "./esm/index.es.js",
52
52
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.92.0-22"
54
+ "@promptbook/core": "0.92.0-23"
55
55
  },
56
56
  "dependencies": {
57
57
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -115,6 +115,12 @@
115
115
  * @public exported from `@promptbook/core`
116
116
  */
117
117
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
118
+ /**
119
+ * @@@
120
+ *
121
+ * @public exported from `@promptbook/core`
122
+ */
123
+ const BIG_DATASET_TRESHOLD = 50;
118
124
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
119
125
  /**
120
126
  * The maximum number of iterations for a loops
@@ -194,7 +200,7 @@
194
200
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
195
201
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
196
202
  /**
197
- * @@@
203
+ * Default settings for parsing and generating CSV files in Promptbook.
198
204
  *
199
205
  * @public exported from `@promptbook/core`
200
206
  */
@@ -205,19 +211,19 @@
205
211
  skipEmptyLines: true,
206
212
  });
207
213
  /**
208
- * @@@
214
+ * Controls whether verbose logging is enabled by default throughout the application.
209
215
  *
210
216
  * @public exported from `@promptbook/core`
211
217
  */
212
218
  let DEFAULT_IS_VERBOSE = false;
213
219
  /**
214
- * @@@
220
+ * Controls whether auto-installation of dependencies is enabled by default.
215
221
  *
216
222
  * @public exported from `@promptbook/core`
217
223
  */
218
224
  const DEFAULT_IS_AUTO_INSTALLED = false;
219
225
  /**
220
- * @@@
226
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
221
227
  *
222
228
  * @private within the repository
223
229
  */
@@ -1277,8 +1283,12 @@
1277
1283
  */
1278
1284
 
1279
1285
  /**
1280
- * @@@
1286
+ * Creates a deep clone of the given object
1287
+ *
1288
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1281
1289
  *
1290
+ * @param objectValue The object to clone.
1291
+ * @returns A deep, writable clone of the input object.
1282
1292
  * @public exported from `@promptbook/utils`
1283
1293
  */
1284
1294
  function deepClone(objectValue) {
@@ -1836,7 +1846,7 @@
1836
1846
  * Function isValidJsonString will tell you if the string is valid JSON or not
1837
1847
  *
1838
1848
  * @param value The string to check
1839
- * @returns True if the string is a valid JSON string, false otherwise
1849
+ * @returns `true` if the string is a valid JSON string, false otherwise
1840
1850
  *
1841
1851
  * @public exported from `@promptbook/utils`
1842
1852
  */
@@ -3107,11 +3117,11 @@
3107
3117
  }
3108
3118
 
3109
3119
  /**
3110
- * Register is @@@
3120
+ * Global registry for storing and managing registered entities of a given type.
3111
3121
  *
3112
3122
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3113
3123
  *
3114
- * @private internal utility, exported are only signleton instances of this class
3124
+ * @private internal utility, exported are only singleton instances of this class
3115
3125
  */
3116
3126
  class $Register {
3117
3127
  constructor(registerName) {
@@ -3155,10 +3165,10 @@
3155
3165
  }
3156
3166
 
3157
3167
  /**
3158
- * @@@
3168
+ * Global registry for storing metadata about all available scrapers and converters.
3159
3169
  *
3160
- * Note: `$` is used to indicate that this interacts with the global scope
3161
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3170
+ * Note: `$` is used to indicate that this interacts with the global scope.
3171
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3162
3172
  * @public exported from `@promptbook/core`
3163
3173
  */
3164
3174
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4445,7 +4455,7 @@
4445
4455
  * Function to check if a string is valid CSV
4446
4456
  *
4447
4457
  * @param value The string to check
4448
- * @returns True if the string is a valid CSV string, false otherwise
4458
+ * @returns `true` if the string is a valid CSV string, false otherwise
4449
4459
  *
4450
4460
  * @public exported from `@promptbook/utils`
4451
4461
  */
@@ -4502,14 +4512,15 @@
4502
4512
  `));
4503
4513
  }
4504
4514
  const mappedData = [];
4505
- for (let index = 0; index < csv.data.length; index++) {
4515
+ const length = csv.data.length;
4516
+ for (let index = 0; index < length; index++) {
4506
4517
  const row = csv.data[index];
4507
4518
  if (row[outputParameterName]) {
4508
4519
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4509
4520
  }
4510
4521
  const mappedRow = {
4511
4522
  ...row,
4512
- [outputParameterName]: await mapCallback(row, index),
4523
+ [outputParameterName]: await mapCallback(row, index, length),
4513
4524
  };
4514
4525
  mappedData.push(mappedRow);
4515
4526
  if (onProgress) {
@@ -4540,9 +4551,9 @@
4540
4551
  `));
4541
4552
  }
4542
4553
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4543
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4554
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4544
4555
  const index = rowIndex * Object.keys(row).length + columnIndex;
4545
- return /* not await */ mapCallback({ [key]: value }, index);
4556
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4546
4557
  }));
4547
4558
  }));
4548
4559
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4613,12 +4624,12 @@
4613
4624
  async mapValues(options) {
4614
4625
  const { value, mapCallback, onProgress } = options;
4615
4626
  const lines = value.split('\n');
4616
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4627
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4617
4628
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4618
4629
  /* not await */ mapCallback({
4619
4630
  lineContent,
4620
4631
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4621
- }, lineNumber)));
4632
+ }, lineNumber, array.length)));
4622
4633
  return mappedLines.join('\n');
4623
4634
  },
4624
4635
  },
@@ -4639,7 +4650,7 @@
4639
4650
  * Function to check if a string is valid XML
4640
4651
  *
4641
4652
  * @param value
4642
- * @returns True if the string is a valid XML string, false otherwise
4653
+ * @returns `true` if the string is a valid XML string, false otherwise
4643
4654
  *
4644
4655
  * @public exported from `@promptbook/utils`
4645
4656
  */
@@ -4701,13 +4712,13 @@
4701
4712
  */
4702
4713
 
4703
4714
  /**
4704
- * Maps available parameters to expected parameters
4715
+ * Maps available parameters to expected parameters for a pipeline task.
4705
4716
  *
4706
4717
  * The strategy is:
4707
- * 1) @@@
4708
- * 2) @@@
4718
+ * 1) First, match parameters by name where both available and expected.
4719
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4709
4720
  *
4710
- * @throws {PipelineExecutionError} @@@
4721
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4711
4722
  * @private within the repository used in `createPipelineExecutor`
4712
4723
  */
4713
4724
  function mapAvailableToExpectedParameters(options) {
@@ -5444,7 +5455,11 @@
5444
5455
  */
5445
5456
 
5446
5457
  /**
5447
- * @@@
5458
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5459
+ * Handles format and subformat resolution, error handling, and progress reporting.
5460
+ *
5461
+ * @param options - Options for execution, including task details and progress callback.
5462
+ * @returns The result of the subvalue mapping or execution attempts.
5448
5463
  *
5449
5464
  * @private internal utility of `createPipelineExecutor`
5450
5465
  */
@@ -5509,15 +5524,11 @@
5509
5524
  settings: formatSettings,
5510
5525
  onProgress(partialResultString) {
5511
5526
  return onProgress(Object.freeze({
5512
- [task.resultingParameterName]:
5513
- // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
5514
- partialResultString,
5527
+ [task.resultingParameterName]: partialResultString,
5515
5528
  }));
5516
5529
  },
5517
- async mapCallback(subparameters, index) {
5530
+ async mapCallback(subparameters, index, length) {
5518
5531
  let mappedParameters;
5519
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5520
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5521
5532
  try {
5522
5533
  mappedParameters = mapAvailableToExpectedParameters({
5523
5534
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5528,32 +5539,52 @@
5528
5539
  if (!(error instanceof PipelineExecutionError)) {
5529
5540
  throw error;
5530
5541
  }
5531
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5532
- ${error.message}
5542
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5543
+ ${error.message}
5533
5544
 
5534
- This is error in FOREACH command
5535
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5545
+ This is error in FOREACH command when mapping data
5546
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5536
5547
 
5537
- ${block(pipelineIdentification)}
5538
- Subparameter index: ${index}
5539
- `));
5548
+ ${block(pipelineIdentification)}
5549
+ Subparameter index: ${index}
5550
+ `));
5551
+ if (length > BIG_DATASET_TRESHOLD) {
5552
+ console.error(highLevelError);
5553
+ return '~';
5554
+ }
5555
+ throw highLevelError;
5540
5556
  }
5541
5557
  const allSubparameters = {
5542
5558
  ...parameters,
5543
5559
  ...mappedParameters,
5544
5560
  };
5545
- // 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
5546
5561
  Object.freeze(allSubparameters);
5547
- const subresultString = await executeAttempts({
5548
- ...options,
5549
- priority: priority + index,
5550
- parameters: allSubparameters,
5551
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5552
- ${block(pipelineIdentification)}
5553
- Subparameter index: ${index}
5554
- `),
5555
- });
5556
- return subresultString;
5562
+ try {
5563
+ const subresultString = await executeAttempts({
5564
+ ...options,
5565
+ priority: priority + index,
5566
+ parameters: allSubparameters,
5567
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5568
+ ${block(pipelineIdentification)}
5569
+ Subparameter index: ${index}
5570
+ `),
5571
+ });
5572
+ return subresultString;
5573
+ }
5574
+ catch (error) {
5575
+ if (length > BIG_DATASET_TRESHOLD) {
5576
+ console.error(spaceTrim__default["default"]((block) => `
5577
+ Error in FOREACH command:
5578
+
5579
+ ${block(pipelineIdentification)}
5580
+
5581
+ ${block(pipelineIdentification)}
5582
+ Subparameter index: ${index}
5583
+ `));
5584
+ return '~';
5585
+ }
5586
+ throw error;
5587
+ }
5557
5588
  },
5558
5589
  });
5559
5590
  return resultString;
@@ -5688,7 +5719,11 @@
5688
5719
  */
5689
5720
 
5690
5721
  /**
5691
- * @@@
5722
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5723
+ * Ensures all reserved parameters are defined and throws if any are missing.
5724
+ *
5725
+ * @param options - Options including tools, pipeline, task, and context.
5726
+ * @returns An object containing all reserved parameters for the task.
5692
5727
  *
5693
5728
  * @private internal utility of `createPipelineExecutor`
5694
5729
  */
@@ -5721,7 +5756,10 @@
5721
5756
  }
5722
5757
 
5723
5758
  /**
5724
- * @@@
5759
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5760
+ *
5761
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5762
+ * @returns The output parameters produced by the task.
5725
5763
  *
5726
5764
  * @private internal utility of `createPipelineExecutor`
5727
5765
  */
@@ -5855,9 +5893,12 @@
5855
5893
  }
5856
5894
 
5857
5895
  /**
5858
- * @@@
5896
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5897
+ *
5898
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5859
5899
  *
5860
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5900
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5901
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5861
5902
  *
5862
5903
  * @private internal utility of `createPipelineExecutor`
5863
5904
  */