@promptbook/markitdown 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
@@ -2371,15 +2371,12 @@ function jsonParse(value) {
2371
2371
  }
2372
2372
  throw new Error(spaceTrim((block) => `
2373
2373
  ${block(error.message)}
2374
-
2374
+
2375
2375
  The JSON text:
2376
2376
  ${block(value)}
2377
2377
  `));
2378
2378
  }
2379
2379
  }
2380
- /**
2381
- * TODO: !!!! Use in Promptbook.studio
2382
- */
2383
2380
 
2384
2381
  /**
2385
2382
  * Recursively converts JSON strings to JSON objects
@@ -4141,7 +4138,8 @@ const CsvFormatParser = {
4141
4138
  subvalueParsers: [
4142
4139
  {
4143
4140
  subvalueName: 'ROW',
4144
- async mapValues(value, outputParameterName, settings, mapCallback) {
4141
+ async mapValues(options) {
4142
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4145
4143
  const csv = csvParse(value, settings);
4146
4144
  if (csv.errors.length !== 0) {
4147
4145
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4157,21 +4155,29 @@ const CsvFormatParser = {
4157
4155
  ${block(value)}
4158
4156
  `));
4159
4157
  }
4160
- 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];
4161
4161
  if (row[outputParameterName]) {
4162
4162
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4163
4163
  }
4164
- return {
4164
+ const mappedRow = {
4165
4165
  ...row,
4166
4166
  [outputParameterName]: await mapCallback(row, index),
4167
4167
  };
4168
- }));
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
+ }
4169
4174
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4170
4175
  },
4171
4176
  },
4172
4177
  {
4173
4178
  subvalueName: 'CELL',
4174
- async mapValues(value, outputParameterName, settings, mapCallback) {
4179
+ async mapValues(options) {
4180
+ const { value, settings, mapCallback, onProgress } = options;
4175
4181
  const csv = csvParse(value, settings);
4176
4182
  if (csv.errors.length !== 0) {
4177
4183
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4258,7 +4264,8 @@ const TextFormatParser = {
4258
4264
  subvalueParsers: [
4259
4265
  {
4260
4266
  subvalueName: 'LINE',
4261
- async mapValues(value, outputParameterName, settings, mapCallback) {
4267
+ async mapValues(options) {
4268
+ const { value, mapCallback, onProgress } = options;
4262
4269
  const lines = value.split('\n');
4263
4270
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4264
4271
  // TODO: [🧠] Maybe option to skip empty line
@@ -5079,7 +5086,7 @@ async function executeAttempts(options) {
5079
5086
  * @private internal utility of `createPipelineExecutor`
5080
5087
  */
5081
5088
  async function executeFormatSubvalues(options) {
5082
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5089
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5083
5090
  if (task.foreach === undefined) {
5084
5091
  return /* not await */ executeAttempts(options);
5085
5092
  }
@@ -5133,21 +5140,32 @@ async function executeFormatSubvalues(options) {
5133
5140
  formatSettings = csvSettings;
5134
5141
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5135
5142
  }
5136
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5137
- let mappedParameters;
5138
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5139
- // TODO: When done [🐚] Report progress also for each subvalue here
5140
- try {
5141
- mappedParameters = mapAvailableToExpectedParameters({
5142
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5143
- availableParameters: subparameters,
5144
- });
5145
- }
5146
- catch (error) {
5147
- if (!(error instanceof PipelineExecutionError)) {
5148
- 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
+ });
5149
5163
  }
5150
- throw new PipelineExecutionError(spaceTrim((block) => `
5164
+ catch (error) {
5165
+ if (!(error instanceof PipelineExecutionError)) {
5166
+ throw error;
5167
+ }
5168
+ throw new PipelineExecutionError(spaceTrim((block) => `
5151
5169
  ${error.message}
5152
5170
 
5153
5171
  This is error in FOREACH command
@@ -5156,23 +5174,24 @@ async function executeFormatSubvalues(options) {
5156
5174
  ${block(pipelineIdentification)}
5157
5175
  Subparameter index: ${index}
5158
5176
  `));
5159
- }
5160
- const allSubparameters = {
5161
- ...parameters,
5162
- ...mappedParameters,
5163
- };
5164
- // 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
5165
- Object.freeze(allSubparameters);
5166
- const subresultString = await executeAttempts({
5167
- ...options,
5168
- priority: priority + index,
5169
- parameters: allSubparameters,
5170
- 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) => `
5171
5189
  ${block(pipelineIdentification)}
5172
5190
  Subparameter index: ${index}
5173
5191
  `),
5174
- });
5175
- return subresultString;
5192
+ });
5193
+ return subresultString;
5194
+ },
5176
5195
  });
5177
5196
  return resultString;
5178
5197
  }
@@ -5346,11 +5365,6 @@ async function getReservedParametersForTask(options) {
5346
5365
  async function executeTask(options) {
5347
5366
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5348
5367
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5349
- await onProgress({
5350
- outputParameters: {
5351
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5352
- },
5353
- });
5354
5368
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5355
5369
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5356
5370
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5425,6 +5439,7 @@ async function executeTask(options) {
5425
5439
  preparedPipeline,
5426
5440
  tools,
5427
5441
  $executionReport,
5442
+ onProgress,
5428
5443
  pipelineIdentification,
5429
5444
  maxExecutionAttempts,
5430
5445
  maxParallelCount,