@promptbook/pdf 0.92.0-20 β†’ 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-20';
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
@@ -2384,15 +2384,12 @@ function jsonParse(value) {
2384
2384
  }
2385
2385
  throw new Error(spaceTrim((block) => `
2386
2386
  ${block(error.message)}
2387
-
2387
+
2388
2388
  The JSON text:
2389
2389
  ${block(value)}
2390
2390
  `));
2391
2391
  }
2392
2392
  }
2393
- /**
2394
- * TODO: !!!! Use in Promptbook.studio
2395
- */
2396
2393
 
2397
2394
  /**
2398
2395
  * Recursively converts JSON strings to JSON objects
@@ -4154,7 +4151,8 @@ const CsvFormatParser = {
4154
4151
  subvalueParsers: [
4155
4152
  {
4156
4153
  subvalueName: 'ROW',
4157
- async mapValues(value, outputParameterName, settings, mapCallback) {
4154
+ async mapValues(options) {
4155
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4158
4156
  const csv = csvParse(value, settings);
4159
4157
  if (csv.errors.length !== 0) {
4160
4158
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4170,21 +4168,29 @@ const CsvFormatParser = {
4170
4168
  ${block(value)}
4171
4169
  `));
4172
4170
  }
4173
- 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];
4174
4174
  if (row[outputParameterName]) {
4175
4175
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4176
4176
  }
4177
- return {
4177
+ const mappedRow = {
4178
4178
  ...row,
4179
4179
  [outputParameterName]: await mapCallback(row, index),
4180
4180
  };
4181
- }));
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
+ }
4182
4187
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4183
4188
  },
4184
4189
  },
4185
4190
  {
4186
4191
  subvalueName: 'CELL',
4187
- async mapValues(value, outputParameterName, settings, mapCallback) {
4192
+ async mapValues(options) {
4193
+ const { value, settings, mapCallback, onProgress } = options;
4188
4194
  const csv = csvParse(value, settings);
4189
4195
  if (csv.errors.length !== 0) {
4190
4196
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4271,7 +4277,8 @@ const TextFormatParser = {
4271
4277
  subvalueParsers: [
4272
4278
  {
4273
4279
  subvalueName: 'LINE',
4274
- async mapValues(value, outputParameterName, settings, mapCallback) {
4280
+ async mapValues(options) {
4281
+ const { value, mapCallback, onProgress } = options;
4275
4282
  const lines = value.split('\n');
4276
4283
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4277
4284
  // TODO: [🧠] Maybe option to skip empty line
@@ -5092,7 +5099,7 @@ async function executeAttempts(options) {
5092
5099
  * @private internal utility of `createPipelineExecutor`
5093
5100
  */
5094
5101
  async function executeFormatSubvalues(options) {
5095
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5102
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5096
5103
  if (task.foreach === undefined) {
5097
5104
  return /* not await */ executeAttempts(options);
5098
5105
  }
@@ -5146,21 +5153,32 @@ async function executeFormatSubvalues(options) {
5146
5153
  formatSettings = csvSettings;
5147
5154
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5148
5155
  }
5149
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5150
- let mappedParameters;
5151
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5152
- // TODO: When done [🐚] Report progress also for each subvalue here
5153
- try {
5154
- mappedParameters = mapAvailableToExpectedParameters({
5155
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5156
- availableParameters: subparameters,
5157
- });
5158
- }
5159
- catch (error) {
5160
- if (!(error instanceof PipelineExecutionError)) {
5161
- 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
+ });
5162
5176
  }
5163
- throw new PipelineExecutionError(spaceTrim((block) => `
5177
+ catch (error) {
5178
+ if (!(error instanceof PipelineExecutionError)) {
5179
+ throw error;
5180
+ }
5181
+ throw new PipelineExecutionError(spaceTrim((block) => `
5164
5182
  ${error.message}
5165
5183
 
5166
5184
  This is error in FOREACH command
@@ -5169,23 +5187,24 @@ async function executeFormatSubvalues(options) {
5169
5187
  ${block(pipelineIdentification)}
5170
5188
  Subparameter index: ${index}
5171
5189
  `));
5172
- }
5173
- const allSubparameters = {
5174
- ...parameters,
5175
- ...mappedParameters,
5176
- };
5177
- // 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
5178
- Object.freeze(allSubparameters);
5179
- const subresultString = await executeAttempts({
5180
- ...options,
5181
- priority: priority + index,
5182
- parameters: allSubparameters,
5183
- 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) => `
5184
5202
  ${block(pipelineIdentification)}
5185
5203
  Subparameter index: ${index}
5186
5204
  `),
5187
- });
5188
- return subresultString;
5205
+ });
5206
+ return subresultString;
5207
+ },
5189
5208
  });
5190
5209
  return resultString;
5191
5210
  }
@@ -5359,11 +5378,6 @@ async function getReservedParametersForTask(options) {
5359
5378
  async function executeTask(options) {
5360
5379
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5361
5380
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5362
- await onProgress({
5363
- outputParameters: {
5364
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5365
- },
5366
- });
5367
5381
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5368
5382
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5369
5383
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5438,6 +5452,7 @@ async function executeTask(options) {
5438
5452
  preparedPipeline,
5439
5453
  tools,
5440
5454
  $executionReport,
5455
+ onProgress,
5441
5456
  pipelineIdentification,
5442
5457
  maxExecutionAttempts,
5443
5458
  maxParallelCount,