@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
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-21';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
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,12 @@ 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
+ * @@@
105
+ *
106
+ * @public exported from `@promptbook/core`
107
+ */
108
+ const BIG_DATASET_TRESHOLD = 50;
103
109
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
104
110
  /**
105
111
  * The maximum number of iterations for a loops
@@ -179,7 +185,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
179
185
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
180
186
  // <- TODO: [πŸ§œβ€β™‚οΈ]
181
187
  /**
182
- * @@@
188
+ * Default settings for parsing and generating CSV files in Promptbook.
183
189
  *
184
190
  * @public exported from `@promptbook/core`
185
191
  */
@@ -190,19 +196,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
190
196
  skipEmptyLines: true,
191
197
  });
192
198
  /**
193
- * @@@
199
+ * Controls whether verbose logging is enabled by default throughout the application.
194
200
  *
195
201
  * @public exported from `@promptbook/core`
196
202
  */
197
203
  let DEFAULT_IS_VERBOSE = false;
198
204
  /**
199
- * @@@
205
+ * Controls whether auto-installation of dependencies is enabled by default.
200
206
  *
201
207
  * @public exported from `@promptbook/core`
202
208
  */
203
209
  const DEFAULT_IS_AUTO_INSTALLED = false;
204
210
  /**
205
- * @@@
211
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
206
212
  *
207
213
  * @private within the repository
208
214
  */
@@ -1262,8 +1268,12 @@ function checkSerializableAsJson(options) {
1262
1268
  */
1263
1269
 
1264
1270
  /**
1265
- * @@@
1271
+ * Creates a deep clone of the given object
1272
+ *
1273
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1266
1274
  *
1275
+ * @param objectValue The object to clone.
1276
+ * @returns A deep, writable clone of the input object.
1267
1277
  * @public exported from `@promptbook/utils`
1268
1278
  */
1269
1279
  function deepClone(objectValue) {
@@ -1821,7 +1831,7 @@ function isPipelinePrepared(pipeline) {
1821
1831
  * Function isValidJsonString will tell you if the string is valid JSON or not
1822
1832
  *
1823
1833
  * @param value The string to check
1824
- * @returns True if the string is a valid JSON string, false otherwise
1834
+ * @returns `true` if the string is a valid JSON string, false otherwise
1825
1835
  *
1826
1836
  * @public exported from `@promptbook/utils`
1827
1837
  */
@@ -3092,11 +3102,11 @@ function normalizeTo_snake_case(text) {
3092
3102
  }
3093
3103
 
3094
3104
  /**
3095
- * Register is @@@
3105
+ * Global registry for storing and managing registered entities of a given type.
3096
3106
  *
3097
3107
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3098
3108
  *
3099
- * @private internal utility, exported are only signleton instances of this class
3109
+ * @private internal utility, exported are only singleton instances of this class
3100
3110
  */
3101
3111
  class $Register {
3102
3112
  constructor(registerName) {
@@ -3140,10 +3150,10 @@ class $Register {
3140
3150
  }
3141
3151
 
3142
3152
  /**
3143
- * @@@
3153
+ * Global registry for storing metadata about all available scrapers and converters.
3144
3154
  *
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 @@@
3155
+ * Note: `$` is used to indicate that this interacts with the global scope.
3156
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3147
3157
  * @public exported from `@promptbook/core`
3148
3158
  */
3149
3159
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4430,7 +4440,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4430
4440
  * Function to check if a string is valid CSV
4431
4441
  *
4432
4442
  * @param value The string to check
4433
- * @returns True if the string is a valid CSV string, false otherwise
4443
+ * @returns `true` if the string is a valid CSV string, false otherwise
4434
4444
  *
4435
4445
  * @public exported from `@promptbook/utils`
4436
4446
  */
@@ -4469,7 +4479,8 @@ const CsvFormatParser = {
4469
4479
  subvalueParsers: [
4470
4480
  {
4471
4481
  subvalueName: 'ROW',
4472
- async mapValues(value, outputParameterName, settings, mapCallback) {
4482
+ async mapValues(options) {
4483
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4473
4484
  const csv = csvParse(value, settings);
4474
4485
  if (csv.errors.length !== 0) {
4475
4486
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4485,21 +4496,30 @@ const CsvFormatParser = {
4485
4496
  ${block(value)}
4486
4497
  `));
4487
4498
  }
4488
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4499
+ const mappedData = [];
4500
+ const length = csv.data.length;
4501
+ for (let index = 0; index < length; index++) {
4502
+ const row = csv.data[index];
4489
4503
  if (row[outputParameterName]) {
4490
4504
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4491
4505
  }
4492
- return {
4506
+ const mappedRow = {
4493
4507
  ...row,
4494
- [outputParameterName]: await mapCallback(row, index),
4508
+ [outputParameterName]: await mapCallback(row, index, length),
4495
4509
  };
4496
- }));
4510
+ mappedData.push(mappedRow);
4511
+ if (onProgress) {
4512
+ // Note: Report the CSV with all rows mapped so far
4513
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4514
+ }
4515
+ }
4497
4516
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4498
4517
  },
4499
4518
  },
4500
4519
  {
4501
4520
  subvalueName: 'CELL',
4502
- async mapValues(value, outputParameterName, settings, mapCallback) {
4521
+ async mapValues(options) {
4522
+ const { value, settings, mapCallback, onProgress } = options;
4503
4523
  const csv = csvParse(value, settings);
4504
4524
  if (csv.errors.length !== 0) {
4505
4525
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4516,9 +4536,9 @@ const CsvFormatParser = {
4516
4536
  `));
4517
4537
  }
4518
4538
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4519
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4539
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4520
4540
  const index = rowIndex * Object.keys(row).length + columnIndex;
4521
- return /* not await */ mapCallback({ [key]: value }, index);
4541
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4522
4542
  }));
4523
4543
  }));
4524
4544
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4586,14 +4606,15 @@ const TextFormatParser = {
4586
4606
  subvalueParsers: [
4587
4607
  {
4588
4608
  subvalueName: 'LINE',
4589
- async mapValues(value, outputParameterName, settings, mapCallback) {
4609
+ async mapValues(options) {
4610
+ const { value, mapCallback, onProgress } = options;
4590
4611
  const lines = value.split('\n');
4591
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4612
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4592
4613
  // TODO: [🧠] Maybe option to skip empty line
4593
4614
  /* not await */ mapCallback({
4594
4615
  lineContent,
4595
4616
  // TODO: [🧠] Maybe also put here `lineNumber`
4596
- }, lineNumber)));
4617
+ }, lineNumber, array.length)));
4597
4618
  return mappedLines.join('\n');
4598
4619
  },
4599
4620
  },
@@ -4614,7 +4635,7 @@ const TextFormatParser = {
4614
4635
  * Function to check if a string is valid XML
4615
4636
  *
4616
4637
  * @param value
4617
- * @returns True if the string is a valid XML string, false otherwise
4638
+ * @returns `true` if the string is a valid XML string, false otherwise
4618
4639
  *
4619
4640
  * @public exported from `@promptbook/utils`
4620
4641
  */
@@ -4676,13 +4697,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4676
4697
  */
4677
4698
 
4678
4699
  /**
4679
- * Maps available parameters to expected parameters
4700
+ * Maps available parameters to expected parameters for a pipeline task.
4680
4701
  *
4681
4702
  * The strategy is:
4682
- * 1) @@@
4683
- * 2) @@@
4703
+ * 1) First, match parameters by name where both available and expected.
4704
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4684
4705
  *
4685
- * @throws {PipelineExecutionError} @@@
4706
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4686
4707
  * @private within the repository used in `createPipelineExecutor`
4687
4708
  */
4688
4709
  function mapAvailableToExpectedParameters(options) {
@@ -5419,12 +5440,16 @@ async function executeAttempts(options) {
5419
5440
  */
5420
5441
 
5421
5442
  /**
5422
- * @@@
5443
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5444
+ * Handles format and subformat resolution, error handling, and progress reporting.
5445
+ *
5446
+ * @param options - Options for execution, including task details and progress callback.
5447
+ * @returns The result of the subvalue mapping or execution attempts.
5423
5448
  *
5424
5449
  * @private internal utility of `createPipelineExecutor`
5425
5450
  */
5426
5451
  async function executeFormatSubvalues(options) {
5427
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5452
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5428
5453
  if (task.foreach === undefined) {
5429
5454
  return /* not await */ executeAttempts(options);
5430
5455
  }
@@ -5478,46 +5503,74 @@ async function executeFormatSubvalues(options) {
5478
5503
  formatSettings = csvSettings;
5479
5504
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5480
5505
  }
5481
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5482
- let mappedParameters;
5483
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5484
- // TODO: When done [🐚] Report progress also for each subvalue here
5485
- try {
5486
- mappedParameters = mapAvailableToExpectedParameters({
5487
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5488
- availableParameters: subparameters,
5489
- });
5490
- }
5491
- catch (error) {
5492
- if (!(error instanceof PipelineExecutionError)) {
5493
- throw error;
5506
+ const resultString = await subvalueParser.mapValues({
5507
+ value: parameterValue,
5508
+ outputParameterName: task.foreach.outputSubparameterName,
5509
+ settings: formatSettings,
5510
+ onProgress(partialResultString) {
5511
+ return onProgress(Object.freeze({
5512
+ [task.resultingParameterName]: partialResultString,
5513
+ }));
5514
+ },
5515
+ async mapCallback(subparameters, index, length) {
5516
+ let mappedParameters;
5517
+ try {
5518
+ mappedParameters = mapAvailableToExpectedParameters({
5519
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5520
+ availableParameters: subparameters,
5521
+ });
5494
5522
  }
5495
- throw new PipelineExecutionError(spaceTrim((block) => `
5496
- ${error.message}
5523
+ catch (error) {
5524
+ if (!(error instanceof PipelineExecutionError)) {
5525
+ throw error;
5526
+ }
5527
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5528
+ ${error.message}
5497
5529
 
5498
- This is error in FOREACH command
5499
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5530
+ This is error in FOREACH command when mapping data
5531
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5500
5532
 
5501
- ${block(pipelineIdentification)}
5502
- Subparameter index: ${index}
5503
- `));
5504
- }
5505
- const allSubparameters = {
5506
- ...parameters,
5507
- ...mappedParameters,
5508
- };
5509
- // 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
5510
- Object.freeze(allSubparameters);
5511
- const subresultString = await executeAttempts({
5512
- ...options,
5513
- priority: priority + index,
5514
- parameters: allSubparameters,
5515
- pipelineIdentification: spaceTrim((block) => `
5516
- ${block(pipelineIdentification)}
5517
- Subparameter index: ${index}
5518
- `),
5519
- });
5520
- return subresultString;
5533
+ ${block(pipelineIdentification)}
5534
+ Subparameter index: ${index}
5535
+ `));
5536
+ if (length > BIG_DATASET_TRESHOLD) {
5537
+ console.error(highLevelError);
5538
+ return '~';
5539
+ }
5540
+ throw highLevelError;
5541
+ }
5542
+ const allSubparameters = {
5543
+ ...parameters,
5544
+ ...mappedParameters,
5545
+ };
5546
+ Object.freeze(allSubparameters);
5547
+ try {
5548
+ const subresultString = await executeAttempts({
5549
+ ...options,
5550
+ priority: priority + index,
5551
+ parameters: allSubparameters,
5552
+ pipelineIdentification: spaceTrim((block) => `
5553
+ ${block(pipelineIdentification)}
5554
+ Subparameter index: ${index}
5555
+ `),
5556
+ });
5557
+ return subresultString;
5558
+ }
5559
+ catch (error) {
5560
+ if (length > BIG_DATASET_TRESHOLD) {
5561
+ console.error(spaceTrim((block) => `
5562
+ Error in FOREACH command:
5563
+
5564
+ ${block(pipelineIdentification)}
5565
+
5566
+ ${block(pipelineIdentification)}
5567
+ Subparameter index: ${index}
5568
+ `));
5569
+ return '~';
5570
+ }
5571
+ throw error;
5572
+ }
5573
+ },
5521
5574
  });
5522
5575
  return resultString;
5523
5576
  }
@@ -5651,7 +5704,11 @@ async function getKnowledgeForTask(options) {
5651
5704
  */
5652
5705
 
5653
5706
  /**
5654
- * @@@
5707
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5708
+ * Ensures all reserved parameters are defined and throws if any are missing.
5709
+ *
5710
+ * @param options - Options including tools, pipeline, task, and context.
5711
+ * @returns An object containing all reserved parameters for the task.
5655
5712
  *
5656
5713
  * @private internal utility of `createPipelineExecutor`
5657
5714
  */
@@ -5684,18 +5741,16 @@ async function getReservedParametersForTask(options) {
5684
5741
  }
5685
5742
 
5686
5743
  /**
5687
- * @@@
5744
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5745
+ *
5746
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5747
+ * @returns The output parameters produced by the task.
5688
5748
  *
5689
5749
  * @private internal utility of `createPipelineExecutor`
5690
5750
  */
5691
5751
  async function executeTask(options) {
5692
5752
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5693
5753
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5694
- await onProgress({
5695
- outputParameters: {
5696
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5697
- },
5698
- });
5699
5754
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5700
5755
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5701
5756
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5770,6 +5825,7 @@ async function executeTask(options) {
5770
5825
  preparedPipeline,
5771
5826
  tools,
5772
5827
  $executionReport,
5828
+ onProgress,
5773
5829
  pipelineIdentification,
5774
5830
  maxExecutionAttempts,
5775
5831
  maxParallelCount,
@@ -5822,9 +5878,12 @@ function filterJustOutputParameters(options) {
5822
5878
  }
5823
5879
 
5824
5880
  /**
5825
- * @@@
5881
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5882
+ *
5883
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5826
5884
  *
5827
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5885
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5886
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5828
5887
  *
5829
5888
  * @private internal utility of `createPipelineExecutor`
5830
5889
  */