@promptbook/pdf 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
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -4151,7 +4151,8 @@ const CsvFormatParser = {
4151
4151
  subvalueParsers: [
4152
4152
  {
4153
4153
  subvalueName: 'ROW',
4154
- async mapValues(value, outputParameterName, settings, mapCallback) {
4154
+ async mapValues(options) {
4155
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4155
4156
  const csv = csvParse(value, settings);
4156
4157
  if (csv.errors.length !== 0) {
4157
4158
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4167,21 +4168,29 @@ const CsvFormatParser = {
4167
4168
  ${block(value)}
4168
4169
  `));
4169
4170
  }
4170
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4171
+ const mappedData = [];
4172
+ for (let index = 0; index < csv.data.length; index++) {
4173
+ const row = csv.data[index];
4171
4174
  if (row[outputParameterName]) {
4172
4175
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4173
4176
  }
4174
- return {
4177
+ const mappedRow = {
4175
4178
  ...row,
4176
4179
  [outputParameterName]: await mapCallback(row, index),
4177
4180
  };
4178
- }));
4181
+ mappedData.push(mappedRow);
4182
+ if (onProgress) {
4183
+ // Note: Report the CSV with all rows mapped so far
4184
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4185
+ }
4186
+ }
4179
4187
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4180
4188
  },
4181
4189
  },
4182
4190
  {
4183
4191
  subvalueName: 'CELL',
4184
- async mapValues(value, outputParameterName, settings, mapCallback) {
4192
+ async mapValues(options) {
4193
+ const { value, settings, mapCallback, onProgress } = options;
4185
4194
  const csv = csvParse(value, settings);
4186
4195
  if (csv.errors.length !== 0) {
4187
4196
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4268,7 +4277,8 @@ const TextFormatParser = {
4268
4277
  subvalueParsers: [
4269
4278
  {
4270
4279
  subvalueName: 'LINE',
4271
- async mapValues(value, outputParameterName, settings, mapCallback) {
4280
+ async mapValues(options) {
4281
+ const { value, mapCallback, onProgress } = options;
4272
4282
  const lines = value.split('\n');
4273
4283
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4274
4284
  // TODO: [🧠] Maybe option to skip empty line
@@ -5089,7 +5099,7 @@ async function executeAttempts(options) {
5089
5099
  * @private internal utility of `createPipelineExecutor`
5090
5100
  */
5091
5101
  async function executeFormatSubvalues(options) {
5092
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5102
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5093
5103
  if (task.foreach === undefined) {
5094
5104
  return /* not await */ executeAttempts(options);
5095
5105
  }
@@ -5143,21 +5153,32 @@ async function executeFormatSubvalues(options) {
5143
5153
  formatSettings = csvSettings;
5144
5154
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5145
5155
  }
5146
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5147
- let mappedParameters;
5148
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5149
- // TODO: When done [🐚] Report progress also for each subvalue here
5150
- try {
5151
- mappedParameters = mapAvailableToExpectedParameters({
5152
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5153
- availableParameters: subparameters,
5154
- });
5155
- }
5156
- catch (error) {
5157
- if (!(error instanceof PipelineExecutionError)) {
5158
- throw error;
5156
+ const resultString = await subvalueParser.mapValues({
5157
+ value: parameterValue,
5158
+ outputParameterName: task.foreach.outputSubparameterName,
5159
+ settings: formatSettings,
5160
+ onProgress(partialResultString) {
5161
+ return onProgress(Object.freeze({
5162
+ [task.resultingParameterName]:
5163
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5164
+ partialResultString,
5165
+ }));
5166
+ },
5167
+ async mapCallback(subparameters, index) {
5168
+ let mappedParameters;
5169
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5170
+ // TODO: When done [🐚] Report progress also for each subvalue here
5171
+ try {
5172
+ mappedParameters = mapAvailableToExpectedParameters({
5173
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5174
+ availableParameters: subparameters,
5175
+ });
5159
5176
  }
5160
- throw new PipelineExecutionError(spaceTrim((block) => `
5177
+ catch (error) {
5178
+ if (!(error instanceof PipelineExecutionError)) {
5179
+ throw error;
5180
+ }
5181
+ throw new PipelineExecutionError(spaceTrim((block) => `
5161
5182
  ${error.message}
5162
5183
 
5163
5184
  This is error in FOREACH command
@@ -5166,23 +5187,24 @@ async function executeFormatSubvalues(options) {
5166
5187
  ${block(pipelineIdentification)}
5167
5188
  Subparameter index: ${index}
5168
5189
  `));
5169
- }
5170
- const allSubparameters = {
5171
- ...parameters,
5172
- ...mappedParameters,
5173
- };
5174
- // 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
5175
- Object.freeze(allSubparameters);
5176
- const subresultString = await executeAttempts({
5177
- ...options,
5178
- priority: priority + index,
5179
- parameters: allSubparameters,
5180
- pipelineIdentification: spaceTrim((block) => `
5190
+ }
5191
+ const allSubparameters = {
5192
+ ...parameters,
5193
+ ...mappedParameters,
5194
+ };
5195
+ // 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
5196
+ Object.freeze(allSubparameters);
5197
+ const subresultString = await executeAttempts({
5198
+ ...options,
5199
+ priority: priority + index,
5200
+ parameters: allSubparameters,
5201
+ pipelineIdentification: spaceTrim((block) => `
5181
5202
  ${block(pipelineIdentification)}
5182
5203
  Subparameter index: ${index}
5183
5204
  `),
5184
- });
5185
- return subresultString;
5205
+ });
5206
+ return subresultString;
5207
+ },
5186
5208
  });
5187
5209
  return resultString;
5188
5210
  }
@@ -5356,11 +5378,6 @@ async function getReservedParametersForTask(options) {
5356
5378
  async function executeTask(options) {
5357
5379
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5358
5380
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5359
- await onProgress({
5360
- outputParameters: {
5361
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5362
- },
5363
- });
5364
5381
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5365
5382
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5366
5383
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5435,6 +5452,7 @@ async function executeTask(options) {
5435
5452
  preparedPipeline,
5436
5453
  tools,
5437
5454
  $executionReport,
5455
+ onProgress,
5438
5456
  pipelineIdentification,
5439
5457
  maxExecutionAttempts,
5440
5458
  maxParallelCount,