@promptbook/remote-server 0.92.0-21 β†’ 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 (27) hide show
  1. package/esm/index.es.js +136 -77
  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/_packages/types.index.d.ts +2 -0
  5. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  6. package/esm/typings/src/config.d.ts +29 -11
  7. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  8. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  9. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
  10. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
  11. package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
  12. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +40 -5
  13. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  14. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  15. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
  17. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  18. package/esm/typings/src/types/typeAliases.d.ts +9 -7
  19. package/esm/typings/src/utils/$Register.d.ts +8 -7
  20. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  21. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  22. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  23. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  24. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  25. package/package.json +2 -2
  26. package/umd/index.umd.js +136 -77
  27. package/umd/index.umd.js.map +1 -1
@@ -1,10 +1,11 @@
1
1
  import type { string_parameter_name } from '../../../types/typeAliases';
2
2
  /**
3
- * Function `validateParameterName` will @@@
3
+ * Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
4
+ * It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
4
5
  *
5
- * @param parameterName @@@
6
- * @returns @@@
7
- * @throws {ParseError} @@@
6
+ * @param parameterName The parameter name to validate and normalize.
7
+ * @returns The validated and normalized parameter name.
8
+ * @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
8
9
  * @private within the repository
9
10
  */
10
11
  export declare function validateParameterName(parameterName: string): string_parameter_name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.92.0-21",
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-21"
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-21';
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
  */
@@ -4484,7 +4494,8 @@
4484
4494
  subvalueParsers: [
4485
4495
  {
4486
4496
  subvalueName: 'ROW',
4487
- async mapValues(value, outputParameterName, settings, mapCallback) {
4497
+ async mapValues(options) {
4498
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4488
4499
  const csv = csvParse(value, settings);
4489
4500
  if (csv.errors.length !== 0) {
4490
4501
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4500,21 +4511,30 @@
4500
4511
  ${block(value)}
4501
4512
  `));
4502
4513
  }
4503
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4514
+ const mappedData = [];
4515
+ const length = csv.data.length;
4516
+ for (let index = 0; index < length; index++) {
4517
+ const row = csv.data[index];
4504
4518
  if (row[outputParameterName]) {
4505
4519
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4506
4520
  }
4507
- return {
4521
+ const mappedRow = {
4508
4522
  ...row,
4509
- [outputParameterName]: await mapCallback(row, index),
4523
+ [outputParameterName]: await mapCallback(row, index, length),
4510
4524
  };
4511
- }));
4525
+ mappedData.push(mappedRow);
4526
+ if (onProgress) {
4527
+ // Note: Report the CSV with all rows mapped so far
4528
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4529
+ }
4530
+ }
4512
4531
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4513
4532
  },
4514
4533
  },
4515
4534
  {
4516
4535
  subvalueName: 'CELL',
4517
- async mapValues(value, outputParameterName, settings, mapCallback) {
4536
+ async mapValues(options) {
4537
+ const { value, settings, mapCallback, onProgress } = options;
4518
4538
  const csv = csvParse(value, settings);
4519
4539
  if (csv.errors.length !== 0) {
4520
4540
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4531,9 +4551,9 @@
4531
4551
  `));
4532
4552
  }
4533
4553
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4534
- 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) => {
4535
4555
  const index = rowIndex * Object.keys(row).length + columnIndex;
4536
- return /* not await */ mapCallback({ [key]: value }, index);
4556
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4537
4557
  }));
4538
4558
  }));
4539
4559
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4601,14 +4621,15 @@
4601
4621
  subvalueParsers: [
4602
4622
  {
4603
4623
  subvalueName: 'LINE',
4604
- async mapValues(value, outputParameterName, settings, mapCallback) {
4624
+ async mapValues(options) {
4625
+ const { value, mapCallback, onProgress } = options;
4605
4626
  const lines = value.split('\n');
4606
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4627
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4607
4628
  // TODO: [🧠] Maybe option to skip empty line
4608
4629
  /* not await */ mapCallback({
4609
4630
  lineContent,
4610
4631
  // TODO: [🧠] Maybe also put here `lineNumber`
4611
- }, lineNumber)));
4632
+ }, lineNumber, array.length)));
4612
4633
  return mappedLines.join('\n');
4613
4634
  },
4614
4635
  },
@@ -4629,7 +4650,7 @@
4629
4650
  * Function to check if a string is valid XML
4630
4651
  *
4631
4652
  * @param value
4632
- * @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
4633
4654
  *
4634
4655
  * @public exported from `@promptbook/utils`
4635
4656
  */
@@ -4691,13 +4712,13 @@
4691
4712
  */
4692
4713
 
4693
4714
  /**
4694
- * Maps available parameters to expected parameters
4715
+ * Maps available parameters to expected parameters for a pipeline task.
4695
4716
  *
4696
4717
  * The strategy is:
4697
- * 1) @@@
4698
- * 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.
4699
4720
  *
4700
- * @throws {PipelineExecutionError} @@@
4721
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4701
4722
  * @private within the repository used in `createPipelineExecutor`
4702
4723
  */
4703
4724
  function mapAvailableToExpectedParameters(options) {
@@ -5434,12 +5455,16 @@
5434
5455
  */
5435
5456
 
5436
5457
  /**
5437
- * @@@
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.
5438
5463
  *
5439
5464
  * @private internal utility of `createPipelineExecutor`
5440
5465
  */
5441
5466
  async function executeFormatSubvalues(options) {
5442
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5467
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5443
5468
  if (task.foreach === undefined) {
5444
5469
  return /* not await */ executeAttempts(options);
5445
5470
  }
@@ -5493,46 +5518,74 @@
5493
5518
  formatSettings = csvSettings;
5494
5519
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5495
5520
  }
5496
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5497
- let mappedParameters;
5498
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5499
- // TODO: When done [🐚] Report progress also for each subvalue here
5500
- try {
5501
- mappedParameters = mapAvailableToExpectedParameters({
5502
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5503
- availableParameters: subparameters,
5504
- });
5505
- }
5506
- catch (error) {
5507
- if (!(error instanceof PipelineExecutionError)) {
5508
- throw error;
5521
+ const resultString = await subvalueParser.mapValues({
5522
+ value: parameterValue,
5523
+ outputParameterName: task.foreach.outputSubparameterName,
5524
+ settings: formatSettings,
5525
+ onProgress(partialResultString) {
5526
+ return onProgress(Object.freeze({
5527
+ [task.resultingParameterName]: partialResultString,
5528
+ }));
5529
+ },
5530
+ async mapCallback(subparameters, index, length) {
5531
+ let mappedParameters;
5532
+ try {
5533
+ mappedParameters = mapAvailableToExpectedParameters({
5534
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5535
+ availableParameters: subparameters,
5536
+ });
5509
5537
  }
5510
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5511
- ${error.message}
5538
+ catch (error) {
5539
+ if (!(error instanceof PipelineExecutionError)) {
5540
+ throw error;
5541
+ }
5542
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5543
+ ${error.message}
5512
5544
 
5513
- This is error in FOREACH command
5514
- 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
5515
5547
 
5516
- ${block(pipelineIdentification)}
5517
- Subparameter index: ${index}
5518
- `));
5519
- }
5520
- const allSubparameters = {
5521
- ...parameters,
5522
- ...mappedParameters,
5523
- };
5524
- // 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
5525
- Object.freeze(allSubparameters);
5526
- const subresultString = await executeAttempts({
5527
- ...options,
5528
- priority: priority + index,
5529
- parameters: allSubparameters,
5530
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5531
- ${block(pipelineIdentification)}
5532
- Subparameter index: ${index}
5533
- `),
5534
- });
5535
- return subresultString;
5548
+ ${block(pipelineIdentification)}
5549
+ Subparameter index: ${index}
5550
+ `));
5551
+ if (length > BIG_DATASET_TRESHOLD) {
5552
+ console.error(highLevelError);
5553
+ return '~';
5554
+ }
5555
+ throw highLevelError;
5556
+ }
5557
+ const allSubparameters = {
5558
+ ...parameters,
5559
+ ...mappedParameters,
5560
+ };
5561
+ Object.freeze(allSubparameters);
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
+ }
5588
+ },
5536
5589
  });
5537
5590
  return resultString;
5538
5591
  }
@@ -5666,7 +5719,11 @@
5666
5719
  */
5667
5720
 
5668
5721
  /**
5669
- * @@@
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.
5670
5727
  *
5671
5728
  * @private internal utility of `createPipelineExecutor`
5672
5729
  */
@@ -5699,18 +5756,16 @@
5699
5756
  }
5700
5757
 
5701
5758
  /**
5702
- * @@@
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.
5703
5763
  *
5704
5764
  * @private internal utility of `createPipelineExecutor`
5705
5765
  */
5706
5766
  async function executeTask(options) {
5707
5767
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5708
5768
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5709
- await onProgress({
5710
- outputParameters: {
5711
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5712
- },
5713
- });
5714
5769
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5715
5770
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5716
5771
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5785,6 +5840,7 @@
5785
5840
  preparedPipeline,
5786
5841
  tools,
5787
5842
  $executionReport,
5843
+ onProgress,
5788
5844
  pipelineIdentification,
5789
5845
  maxExecutionAttempts,
5790
5846
  maxParallelCount,
@@ -5837,9 +5893,12 @@
5837
5893
  }
5838
5894
 
5839
5895
  /**
5840
- * @@@
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`.
5841
5899
  *
5842
- * 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.
5843
5902
  *
5844
5903
  * @private internal utility of `createPipelineExecutor`
5845
5904
  */