@promptbook/cli 0.92.0-21 β†’ 0.92.0-22

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.
package/esm/index.es.js CHANGED
@@ -47,7 +47,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
47
47
  * @generated
48
48
  * @see https://github.com/webgptorg/promptbook
49
49
  */
50
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
50
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
51
51
  /**
52
52
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
53
53
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -5465,7 +5465,8 @@ const CsvFormatParser = {
5465
5465
  subvalueParsers: [
5466
5466
  {
5467
5467
  subvalueName: 'ROW',
5468
- async mapValues(value, outputParameterName, settings, mapCallback) {
5468
+ async mapValues(options) {
5469
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
5469
5470
  const csv = csvParse(value, settings);
5470
5471
  if (csv.errors.length !== 0) {
5471
5472
  throw new CsvFormatError(spaceTrim((block) => `
@@ -5481,21 +5482,29 @@ const CsvFormatParser = {
5481
5482
  ${block(value)}
5482
5483
  `));
5483
5484
  }
5484
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
5485
+ const mappedData = [];
5486
+ for (let index = 0; index < csv.data.length; index++) {
5487
+ const row = csv.data[index];
5485
5488
  if (row[outputParameterName]) {
5486
5489
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
5487
5490
  }
5488
- return {
5491
+ const mappedRow = {
5489
5492
  ...row,
5490
5493
  [outputParameterName]: await mapCallback(row, index),
5491
5494
  };
5492
- }));
5495
+ mappedData.push(mappedRow);
5496
+ if (onProgress) {
5497
+ // Note: Report the CSV with all rows mapped so far
5498
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
5499
+ }
5500
+ }
5493
5501
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
5494
5502
  },
5495
5503
  },
5496
5504
  {
5497
5505
  subvalueName: 'CELL',
5498
- async mapValues(value, outputParameterName, settings, mapCallback) {
5506
+ async mapValues(options) {
5507
+ const { value, settings, mapCallback, onProgress } = options;
5499
5508
  const csv = csvParse(value, settings);
5500
5509
  if (csv.errors.length !== 0) {
5501
5510
  throw new CsvFormatError(spaceTrim((block) => `
@@ -5582,7 +5591,8 @@ const TextFormatParser = {
5582
5591
  subvalueParsers: [
5583
5592
  {
5584
5593
  subvalueName: 'LINE',
5585
- async mapValues(value, outputParameterName, settings, mapCallback) {
5594
+ async mapValues(options) {
5595
+ const { value, mapCallback, onProgress } = options;
5586
5596
  const lines = value.split('\n');
5587
5597
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
5588
5598
  // TODO: [🧠] Maybe option to skip empty line
@@ -6422,7 +6432,7 @@ async function executeAttempts(options) {
6422
6432
  * @private internal utility of `createPipelineExecutor`
6423
6433
  */
6424
6434
  async function executeFormatSubvalues(options) {
6425
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
6435
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
6426
6436
  if (task.foreach === undefined) {
6427
6437
  return /* not await */ executeAttempts(options);
6428
6438
  }
@@ -6476,21 +6486,32 @@ async function executeFormatSubvalues(options) {
6476
6486
  formatSettings = csvSettings;
6477
6487
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
6478
6488
  }
6479
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
6480
- let mappedParameters;
6481
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
6482
- // TODO: When done [🐚] Report progress also for each subvalue here
6483
- try {
6484
- mappedParameters = mapAvailableToExpectedParameters({
6485
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
6486
- availableParameters: subparameters,
6487
- });
6488
- }
6489
- catch (error) {
6490
- if (!(error instanceof PipelineExecutionError)) {
6491
- throw error;
6489
+ const resultString = await subvalueParser.mapValues({
6490
+ value: parameterValue,
6491
+ outputParameterName: task.foreach.outputSubparameterName,
6492
+ settings: formatSettings,
6493
+ onProgress(partialResultString) {
6494
+ return onProgress(Object.freeze({
6495
+ [task.resultingParameterName]:
6496
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
6497
+ partialResultString,
6498
+ }));
6499
+ },
6500
+ async mapCallback(subparameters, index) {
6501
+ let mappedParameters;
6502
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
6503
+ // TODO: When done [🐚] Report progress also for each subvalue here
6504
+ try {
6505
+ mappedParameters = mapAvailableToExpectedParameters({
6506
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
6507
+ availableParameters: subparameters,
6508
+ });
6492
6509
  }
6493
- throw new PipelineExecutionError(spaceTrim((block) => `
6510
+ catch (error) {
6511
+ if (!(error instanceof PipelineExecutionError)) {
6512
+ throw error;
6513
+ }
6514
+ throw new PipelineExecutionError(spaceTrim((block) => `
6494
6515
  ${error.message}
6495
6516
 
6496
6517
  This is error in FOREACH command
@@ -6499,23 +6520,24 @@ async function executeFormatSubvalues(options) {
6499
6520
  ${block(pipelineIdentification)}
6500
6521
  Subparameter index: ${index}
6501
6522
  `));
6502
- }
6503
- const allSubparameters = {
6504
- ...parameters,
6505
- ...mappedParameters,
6506
- };
6507
- // 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
6508
- Object.freeze(allSubparameters);
6509
- const subresultString = await executeAttempts({
6510
- ...options,
6511
- priority: priority + index,
6512
- parameters: allSubparameters,
6513
- pipelineIdentification: spaceTrim((block) => `
6523
+ }
6524
+ const allSubparameters = {
6525
+ ...parameters,
6526
+ ...mappedParameters,
6527
+ };
6528
+ // 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
6529
+ Object.freeze(allSubparameters);
6530
+ const subresultString = await executeAttempts({
6531
+ ...options,
6532
+ priority: priority + index,
6533
+ parameters: allSubparameters,
6534
+ pipelineIdentification: spaceTrim((block) => `
6514
6535
  ${block(pipelineIdentification)}
6515
6536
  Subparameter index: ${index}
6516
6537
  `),
6517
- });
6518
- return subresultString;
6538
+ });
6539
+ return subresultString;
6540
+ },
6519
6541
  });
6520
6542
  return resultString;
6521
6543
  }
@@ -6689,11 +6711,6 @@ async function getReservedParametersForTask(options) {
6689
6711
  async function executeTask(options) {
6690
6712
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
6691
6713
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
6692
- await onProgress({
6693
- outputParameters: {
6694
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
6695
- },
6696
- });
6697
6714
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
6698
6715
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
6699
6716
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -6768,6 +6785,7 @@ async function executeTask(options) {
6768
6785
  preparedPipeline,
6769
6786
  tools,
6770
6787
  $executionReport,
6788
+ onProgress,
6771
6789
  pipelineIdentification,
6772
6790
  maxExecutionAttempts,
6773
6791
  maxParallelCount,