@promptbook/markitdown 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
@@ -4138,7 +4138,8 @@ const CsvFormatParser = {
4138
4138
  subvalueParsers: [
4139
4139
  {
4140
4140
  subvalueName: 'ROW',
4141
- async mapValues(value, outputParameterName, settings, mapCallback) {
4141
+ async mapValues(options) {
4142
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4142
4143
  const csv = csvParse(value, settings);
4143
4144
  if (csv.errors.length !== 0) {
4144
4145
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4154,21 +4155,29 @@ const CsvFormatParser = {
4154
4155
  ${block(value)}
4155
4156
  `));
4156
4157
  }
4157
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4158
+ const mappedData = [];
4159
+ for (let index = 0; index < csv.data.length; index++) {
4160
+ const row = csv.data[index];
4158
4161
  if (row[outputParameterName]) {
4159
4162
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4160
4163
  }
4161
- return {
4164
+ const mappedRow = {
4162
4165
  ...row,
4163
4166
  [outputParameterName]: await mapCallback(row, index),
4164
4167
  };
4165
- }));
4168
+ mappedData.push(mappedRow);
4169
+ if (onProgress) {
4170
+ // Note: Report the CSV with all rows mapped so far
4171
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4172
+ }
4173
+ }
4166
4174
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4167
4175
  },
4168
4176
  },
4169
4177
  {
4170
4178
  subvalueName: 'CELL',
4171
- async mapValues(value, outputParameterName, settings, mapCallback) {
4179
+ async mapValues(options) {
4180
+ const { value, settings, mapCallback, onProgress } = options;
4172
4181
  const csv = csvParse(value, settings);
4173
4182
  if (csv.errors.length !== 0) {
4174
4183
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4255,7 +4264,8 @@ const TextFormatParser = {
4255
4264
  subvalueParsers: [
4256
4265
  {
4257
4266
  subvalueName: 'LINE',
4258
- async mapValues(value, outputParameterName, settings, mapCallback) {
4267
+ async mapValues(options) {
4268
+ const { value, mapCallback, onProgress } = options;
4259
4269
  const lines = value.split('\n');
4260
4270
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4261
4271
  // TODO: [🧠] Maybe option to skip empty line
@@ -5076,7 +5086,7 @@ async function executeAttempts(options) {
5076
5086
  * @private internal utility of `createPipelineExecutor`
5077
5087
  */
5078
5088
  async function executeFormatSubvalues(options) {
5079
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5089
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5080
5090
  if (task.foreach === undefined) {
5081
5091
  return /* not await */ executeAttempts(options);
5082
5092
  }
@@ -5130,21 +5140,32 @@ async function executeFormatSubvalues(options) {
5130
5140
  formatSettings = csvSettings;
5131
5141
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5132
5142
  }
5133
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5134
- let mappedParameters;
5135
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5136
- // TODO: When done [🐚] Report progress also for each subvalue here
5137
- try {
5138
- mappedParameters = mapAvailableToExpectedParameters({
5139
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5140
- availableParameters: subparameters,
5141
- });
5142
- }
5143
- catch (error) {
5144
- if (!(error instanceof PipelineExecutionError)) {
5145
- throw error;
5143
+ const resultString = await subvalueParser.mapValues({
5144
+ value: parameterValue,
5145
+ outputParameterName: task.foreach.outputSubparameterName,
5146
+ settings: formatSettings,
5147
+ onProgress(partialResultString) {
5148
+ return onProgress(Object.freeze({
5149
+ [task.resultingParameterName]:
5150
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5151
+ partialResultString,
5152
+ }));
5153
+ },
5154
+ async mapCallback(subparameters, index) {
5155
+ let mappedParameters;
5156
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5157
+ // TODO: When done [🐚] Report progress also for each subvalue here
5158
+ try {
5159
+ mappedParameters = mapAvailableToExpectedParameters({
5160
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5161
+ availableParameters: subparameters,
5162
+ });
5146
5163
  }
5147
- throw new PipelineExecutionError(spaceTrim((block) => `
5164
+ catch (error) {
5165
+ if (!(error instanceof PipelineExecutionError)) {
5166
+ throw error;
5167
+ }
5168
+ throw new PipelineExecutionError(spaceTrim((block) => `
5148
5169
  ${error.message}
5149
5170
 
5150
5171
  This is error in FOREACH command
@@ -5153,23 +5174,24 @@ async function executeFormatSubvalues(options) {
5153
5174
  ${block(pipelineIdentification)}
5154
5175
  Subparameter index: ${index}
5155
5176
  `));
5156
- }
5157
- const allSubparameters = {
5158
- ...parameters,
5159
- ...mappedParameters,
5160
- };
5161
- // 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
5162
- Object.freeze(allSubparameters);
5163
- const subresultString = await executeAttempts({
5164
- ...options,
5165
- priority: priority + index,
5166
- parameters: allSubparameters,
5167
- pipelineIdentification: spaceTrim((block) => `
5177
+ }
5178
+ const allSubparameters = {
5179
+ ...parameters,
5180
+ ...mappedParameters,
5181
+ };
5182
+ // 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
5183
+ Object.freeze(allSubparameters);
5184
+ const subresultString = await executeAttempts({
5185
+ ...options,
5186
+ priority: priority + index,
5187
+ parameters: allSubparameters,
5188
+ pipelineIdentification: spaceTrim((block) => `
5168
5189
  ${block(pipelineIdentification)}
5169
5190
  Subparameter index: ${index}
5170
5191
  `),
5171
- });
5172
- return subresultString;
5192
+ });
5193
+ return subresultString;
5194
+ },
5173
5195
  });
5174
5196
  return resultString;
5175
5197
  }
@@ -5343,11 +5365,6 @@ async function getReservedParametersForTask(options) {
5343
5365
  async function executeTask(options) {
5344
5366
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5345
5367
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5346
- await onProgress({
5347
- outputParameters: {
5348
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5349
- },
5350
- });
5351
5368
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5352
5369
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5353
5370
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5422,6 +5439,7 @@ async function executeTask(options) {
5422
5439
  preparedPipeline,
5423
5440
  tools,
5424
5441
  $executionReport,
5442
+ onProgress,
5425
5443
  pipelineIdentification,
5426
5444
  maxExecutionAttempts,
5427
5445
  maxParallelCount,