@promptbook/node 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
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -2585,7 +2585,8 @@ const CsvFormatParser = {
2585
2585
  subvalueParsers: [
2586
2586
  {
2587
2587
  subvalueName: 'ROW',
2588
- async mapValues(value, outputParameterName, settings, mapCallback) {
2588
+ async mapValues(options) {
2589
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
2589
2590
  const csv = csvParse(value, settings);
2590
2591
  if (csv.errors.length !== 0) {
2591
2592
  throw new CsvFormatError(spaceTrim((block) => `
@@ -2601,21 +2602,29 @@ const CsvFormatParser = {
2601
2602
  ${block(value)}
2602
2603
  `));
2603
2604
  }
2604
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
2605
+ const mappedData = [];
2606
+ for (let index = 0; index < csv.data.length; index++) {
2607
+ const row = csv.data[index];
2605
2608
  if (row[outputParameterName]) {
2606
2609
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
2607
2610
  }
2608
- return {
2611
+ const mappedRow = {
2609
2612
  ...row,
2610
2613
  [outputParameterName]: await mapCallback(row, index),
2611
2614
  };
2612
- }));
2615
+ mappedData.push(mappedRow);
2616
+ if (onProgress) {
2617
+ // Note: Report the CSV with all rows mapped so far
2618
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
2619
+ }
2620
+ }
2613
2621
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
2614
2622
  },
2615
2623
  },
2616
2624
  {
2617
2625
  subvalueName: 'CELL',
2618
- async mapValues(value, outputParameterName, settings, mapCallback) {
2626
+ async mapValues(options) {
2627
+ const { value, settings, mapCallback, onProgress } = options;
2619
2628
  const csv = csvParse(value, settings);
2620
2629
  if (csv.errors.length !== 0) {
2621
2630
  throw new CsvFormatError(spaceTrim((block) => `
@@ -2702,7 +2711,8 @@ const TextFormatParser = {
2702
2711
  subvalueParsers: [
2703
2712
  {
2704
2713
  subvalueName: 'LINE',
2705
- async mapValues(value, outputParameterName, settings, mapCallback) {
2714
+ async mapValues(options) {
2715
+ const { value, mapCallback, onProgress } = options;
2706
2716
  const lines = value.split('\n');
2707
2717
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
2708
2718
  // TODO: [🧠] Maybe option to skip empty line
@@ -4012,7 +4022,7 @@ async function executeAttempts(options) {
4012
4022
  * @private internal utility of `createPipelineExecutor`
4013
4023
  */
4014
4024
  async function executeFormatSubvalues(options) {
4015
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
4025
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
4016
4026
  if (task.foreach === undefined) {
4017
4027
  return /* not await */ executeAttempts(options);
4018
4028
  }
@@ -4066,21 +4076,32 @@ async function executeFormatSubvalues(options) {
4066
4076
  formatSettings = csvSettings;
4067
4077
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
4068
4078
  }
4069
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
4070
- let mappedParameters;
4071
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
4072
- // TODO: When done [🐚] Report progress also for each subvalue here
4073
- try {
4074
- mappedParameters = mapAvailableToExpectedParameters({
4075
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
4076
- availableParameters: subparameters,
4077
- });
4078
- }
4079
- catch (error) {
4080
- if (!(error instanceof PipelineExecutionError)) {
4081
- throw error;
4079
+ const resultString = await subvalueParser.mapValues({
4080
+ value: parameterValue,
4081
+ outputParameterName: task.foreach.outputSubparameterName,
4082
+ settings: formatSettings,
4083
+ onProgress(partialResultString) {
4084
+ return onProgress(Object.freeze({
4085
+ [task.resultingParameterName]:
4086
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
4087
+ partialResultString,
4088
+ }));
4089
+ },
4090
+ async mapCallback(subparameters, index) {
4091
+ let mappedParameters;
4092
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
4093
+ // TODO: When done [🐚] Report progress also for each subvalue here
4094
+ try {
4095
+ mappedParameters = mapAvailableToExpectedParameters({
4096
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
4097
+ availableParameters: subparameters,
4098
+ });
4082
4099
  }
4083
- throw new PipelineExecutionError(spaceTrim((block) => `
4100
+ catch (error) {
4101
+ if (!(error instanceof PipelineExecutionError)) {
4102
+ throw error;
4103
+ }
4104
+ throw new PipelineExecutionError(spaceTrim((block) => `
4084
4105
  ${error.message}
4085
4106
 
4086
4107
  This is error in FOREACH command
@@ -4089,23 +4110,24 @@ async function executeFormatSubvalues(options) {
4089
4110
  ${block(pipelineIdentification)}
4090
4111
  Subparameter index: ${index}
4091
4112
  `));
4092
- }
4093
- const allSubparameters = {
4094
- ...parameters,
4095
- ...mappedParameters,
4096
- };
4097
- // 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
4098
- Object.freeze(allSubparameters);
4099
- const subresultString = await executeAttempts({
4100
- ...options,
4101
- priority: priority + index,
4102
- parameters: allSubparameters,
4103
- pipelineIdentification: spaceTrim((block) => `
4113
+ }
4114
+ const allSubparameters = {
4115
+ ...parameters,
4116
+ ...mappedParameters,
4117
+ };
4118
+ // 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
4119
+ Object.freeze(allSubparameters);
4120
+ const subresultString = await executeAttempts({
4121
+ ...options,
4122
+ priority: priority + index,
4123
+ parameters: allSubparameters,
4124
+ pipelineIdentification: spaceTrim((block) => `
4104
4125
  ${block(pipelineIdentification)}
4105
4126
  Subparameter index: ${index}
4106
4127
  `),
4107
- });
4108
- return subresultString;
4128
+ });
4129
+ return subresultString;
4130
+ },
4109
4131
  });
4110
4132
  return resultString;
4111
4133
  }
@@ -4279,11 +4301,6 @@ async function getReservedParametersForTask(options) {
4279
4301
  async function executeTask(options) {
4280
4302
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
4281
4303
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
4282
- await onProgress({
4283
- outputParameters: {
4284
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
4285
- },
4286
- });
4287
4304
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
4288
4305
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
4289
4306
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -4358,6 +4375,7 @@ async function executeTask(options) {
4358
4375
  preparedPipeline,
4359
4376
  tools,
4360
4377
  $executionReport,
4378
+ onProgress,
4361
4379
  pipelineIdentification,
4362
4380
  maxExecutionAttempts,
4363
4381
  maxParallelCount,