@promptbook/markdown-utils 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
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -4223,7 +4223,8 @@ const CsvFormatParser = {
4223
4223
  subvalueParsers: [
4224
4224
  {
4225
4225
  subvalueName: 'ROW',
4226
- async mapValues(value, outputParameterName, settings, mapCallback) {
4226
+ async mapValues(options) {
4227
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4227
4228
  const csv = csvParse(value, settings);
4228
4229
  if (csv.errors.length !== 0) {
4229
4230
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4239,21 +4240,29 @@ const CsvFormatParser = {
4239
4240
  ${block(value)}
4240
4241
  `));
4241
4242
  }
4242
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4243
+ const mappedData = [];
4244
+ for (let index = 0; index < csv.data.length; index++) {
4245
+ const row = csv.data[index];
4243
4246
  if (row[outputParameterName]) {
4244
4247
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4245
4248
  }
4246
- return {
4249
+ const mappedRow = {
4247
4250
  ...row,
4248
4251
  [outputParameterName]: await mapCallback(row, index),
4249
4252
  };
4250
- }));
4253
+ mappedData.push(mappedRow);
4254
+ if (onProgress) {
4255
+ // Note: Report the CSV with all rows mapped so far
4256
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4257
+ }
4258
+ }
4251
4259
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4252
4260
  },
4253
4261
  },
4254
4262
  {
4255
4263
  subvalueName: 'CELL',
4256
- async mapValues(value, outputParameterName, settings, mapCallback) {
4264
+ async mapValues(options) {
4265
+ const { value, settings, mapCallback, onProgress } = options;
4257
4266
  const csv = csvParse(value, settings);
4258
4267
  if (csv.errors.length !== 0) {
4259
4268
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4340,7 +4349,8 @@ const TextFormatParser = {
4340
4349
  subvalueParsers: [
4341
4350
  {
4342
4351
  subvalueName: 'LINE',
4343
- async mapValues(value, outputParameterName, settings, mapCallback) {
4352
+ async mapValues(options) {
4353
+ const { value, mapCallback, onProgress } = options;
4344
4354
  const lines = value.split('\n');
4345
4355
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4346
4356
  // TODO: [🧠] Maybe option to skip empty line
@@ -5059,7 +5069,7 @@ async function executeAttempts(options) {
5059
5069
  * @private internal utility of `createPipelineExecutor`
5060
5070
  */
5061
5071
  async function executeFormatSubvalues(options) {
5062
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5072
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5063
5073
  if (task.foreach === undefined) {
5064
5074
  return /* not await */ executeAttempts(options);
5065
5075
  }
@@ -5113,21 +5123,32 @@ async function executeFormatSubvalues(options) {
5113
5123
  formatSettings = csvSettings;
5114
5124
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5115
5125
  }
5116
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5117
- let mappedParameters;
5118
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5119
- // TODO: When done [🐚] Report progress also for each subvalue here
5120
- try {
5121
- mappedParameters = mapAvailableToExpectedParameters({
5122
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5123
- availableParameters: subparameters,
5124
- });
5125
- }
5126
- catch (error) {
5127
- if (!(error instanceof PipelineExecutionError)) {
5128
- throw error;
5126
+ const resultString = await subvalueParser.mapValues({
5127
+ value: parameterValue,
5128
+ outputParameterName: task.foreach.outputSubparameterName,
5129
+ settings: formatSettings,
5130
+ onProgress(partialResultString) {
5131
+ return onProgress(Object.freeze({
5132
+ [task.resultingParameterName]:
5133
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5134
+ partialResultString,
5135
+ }));
5136
+ },
5137
+ async mapCallback(subparameters, index) {
5138
+ let mappedParameters;
5139
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5140
+ // TODO: When done [🐚] Report progress also for each subvalue here
5141
+ try {
5142
+ mappedParameters = mapAvailableToExpectedParameters({
5143
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5144
+ availableParameters: subparameters,
5145
+ });
5129
5146
  }
5130
- throw new PipelineExecutionError(spaceTrim((block) => `
5147
+ catch (error) {
5148
+ if (!(error instanceof PipelineExecutionError)) {
5149
+ throw error;
5150
+ }
5151
+ throw new PipelineExecutionError(spaceTrim((block) => `
5131
5152
  ${error.message}
5132
5153
 
5133
5154
  This is error in FOREACH command
@@ -5136,23 +5157,24 @@ async function executeFormatSubvalues(options) {
5136
5157
  ${block(pipelineIdentification)}
5137
5158
  Subparameter index: ${index}
5138
5159
  `));
5139
- }
5140
- const allSubparameters = {
5141
- ...parameters,
5142
- ...mappedParameters,
5143
- };
5144
- // 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
5145
- Object.freeze(allSubparameters);
5146
- const subresultString = await executeAttempts({
5147
- ...options,
5148
- priority: priority + index,
5149
- parameters: allSubparameters,
5150
- pipelineIdentification: spaceTrim((block) => `
5160
+ }
5161
+ const allSubparameters = {
5162
+ ...parameters,
5163
+ ...mappedParameters,
5164
+ };
5165
+ // 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
5166
+ Object.freeze(allSubparameters);
5167
+ const subresultString = await executeAttempts({
5168
+ ...options,
5169
+ priority: priority + index,
5170
+ parameters: allSubparameters,
5171
+ pipelineIdentification: spaceTrim((block) => `
5151
5172
  ${block(pipelineIdentification)}
5152
5173
  Subparameter index: ${index}
5153
5174
  `),
5154
- });
5155
- return subresultString;
5175
+ });
5176
+ return subresultString;
5177
+ },
5156
5178
  });
5157
5179
  return resultString;
5158
5180
  }
@@ -5326,11 +5348,6 @@ async function getReservedParametersForTask(options) {
5326
5348
  async function executeTask(options) {
5327
5349
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5328
5350
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5329
- await onProgress({
5330
- outputParameters: {
5331
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5332
- },
5333
- });
5334
5351
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5335
5352
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5336
5353
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5405,6 +5422,7 @@ async function executeTask(options) {
5405
5422
  preparedPipeline,
5406
5423
  tools,
5407
5424
  $executionReport,
5425
+ onProgress,
5408
5426
  pipelineIdentification,
5409
5427
  maxExecutionAttempts,
5410
5428
  maxParallelCount,