@promptbook/remote-server 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
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -4469,7 +4469,8 @@ const CsvFormatParser = {
4469
4469
  subvalueParsers: [
4470
4470
  {
4471
4471
  subvalueName: 'ROW',
4472
- async mapValues(value, outputParameterName, settings, mapCallback) {
4472
+ async mapValues(options) {
4473
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4473
4474
  const csv = csvParse(value, settings);
4474
4475
  if (csv.errors.length !== 0) {
4475
4476
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4485,21 +4486,29 @@ const CsvFormatParser = {
4485
4486
  ${block(value)}
4486
4487
  `));
4487
4488
  }
4488
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4489
+ const mappedData = [];
4490
+ for (let index = 0; index < csv.data.length; index++) {
4491
+ const row = csv.data[index];
4489
4492
  if (row[outputParameterName]) {
4490
4493
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4491
4494
  }
4492
- return {
4495
+ const mappedRow = {
4493
4496
  ...row,
4494
4497
  [outputParameterName]: await mapCallback(row, index),
4495
4498
  };
4496
- }));
4499
+ mappedData.push(mappedRow);
4500
+ if (onProgress) {
4501
+ // Note: Report the CSV with all rows mapped so far
4502
+ await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4503
+ }
4504
+ }
4497
4505
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4498
4506
  },
4499
4507
  },
4500
4508
  {
4501
4509
  subvalueName: 'CELL',
4502
- async mapValues(value, outputParameterName, settings, mapCallback) {
4510
+ async mapValues(options) {
4511
+ const { value, settings, mapCallback, onProgress } = options;
4503
4512
  const csv = csvParse(value, settings);
4504
4513
  if (csv.errors.length !== 0) {
4505
4514
  throw new CsvFormatError(spaceTrim((block) => `
@@ -4586,7 +4595,8 @@ const TextFormatParser = {
4586
4595
  subvalueParsers: [
4587
4596
  {
4588
4597
  subvalueName: 'LINE',
4589
- async mapValues(value, outputParameterName, settings, mapCallback) {
4598
+ async mapValues(options) {
4599
+ const { value, mapCallback, onProgress } = options;
4590
4600
  const lines = value.split('\n');
4591
4601
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4592
4602
  // TODO: [🧠] Maybe option to skip empty line
@@ -5424,7 +5434,7 @@ async function executeAttempts(options) {
5424
5434
  * @private internal utility of `createPipelineExecutor`
5425
5435
  */
5426
5436
  async function executeFormatSubvalues(options) {
5427
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5437
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5428
5438
  if (task.foreach === undefined) {
5429
5439
  return /* not await */ executeAttempts(options);
5430
5440
  }
@@ -5478,21 +5488,32 @@ async function executeFormatSubvalues(options) {
5478
5488
  formatSettings = csvSettings;
5479
5489
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5480
5490
  }
5481
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5482
- let mappedParameters;
5483
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5484
- // TODO: When done [🐚] Report progress also for each subvalue here
5485
- try {
5486
- mappedParameters = mapAvailableToExpectedParameters({
5487
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5488
- availableParameters: subparameters,
5489
- });
5490
- }
5491
- catch (error) {
5492
- if (!(error instanceof PipelineExecutionError)) {
5493
- throw error;
5491
+ const resultString = await subvalueParser.mapValues({
5492
+ value: parameterValue,
5493
+ outputParameterName: task.foreach.outputSubparameterName,
5494
+ settings: formatSettings,
5495
+ onProgress(partialResultString) {
5496
+ return onProgress(Object.freeze({
5497
+ [task.resultingParameterName]:
5498
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5499
+ partialResultString,
5500
+ }));
5501
+ },
5502
+ async mapCallback(subparameters, index) {
5503
+ let mappedParameters;
5504
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5505
+ // TODO: When done [🐚] Report progress also for each subvalue here
5506
+ try {
5507
+ mappedParameters = mapAvailableToExpectedParameters({
5508
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5509
+ availableParameters: subparameters,
5510
+ });
5494
5511
  }
5495
- throw new PipelineExecutionError(spaceTrim((block) => `
5512
+ catch (error) {
5513
+ if (!(error instanceof PipelineExecutionError)) {
5514
+ throw error;
5515
+ }
5516
+ throw new PipelineExecutionError(spaceTrim((block) => `
5496
5517
  ${error.message}
5497
5518
 
5498
5519
  This is error in FOREACH command
@@ -5501,23 +5522,24 @@ async function executeFormatSubvalues(options) {
5501
5522
  ${block(pipelineIdentification)}
5502
5523
  Subparameter index: ${index}
5503
5524
  `));
5504
- }
5505
- const allSubparameters = {
5506
- ...parameters,
5507
- ...mappedParameters,
5508
- };
5509
- // 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
5510
- Object.freeze(allSubparameters);
5511
- const subresultString = await executeAttempts({
5512
- ...options,
5513
- priority: priority + index,
5514
- parameters: allSubparameters,
5515
- pipelineIdentification: spaceTrim((block) => `
5525
+ }
5526
+ const allSubparameters = {
5527
+ ...parameters,
5528
+ ...mappedParameters,
5529
+ };
5530
+ // 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
5531
+ Object.freeze(allSubparameters);
5532
+ const subresultString = await executeAttempts({
5533
+ ...options,
5534
+ priority: priority + index,
5535
+ parameters: allSubparameters,
5536
+ pipelineIdentification: spaceTrim((block) => `
5516
5537
  ${block(pipelineIdentification)}
5517
5538
  Subparameter index: ${index}
5518
5539
  `),
5519
- });
5520
- return subresultString;
5540
+ });
5541
+ return subresultString;
5542
+ },
5521
5543
  });
5522
5544
  return resultString;
5523
5545
  }
@@ -5691,11 +5713,6 @@ async function getReservedParametersForTask(options) {
5691
5713
  async function executeTask(options) {
5692
5714
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5693
5715
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5694
- await onProgress({
5695
- outputParameters: {
5696
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5697
- },
5698
- });
5699
5716
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5700
5717
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5701
5718
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5770,6 +5787,7 @@ async function executeTask(options) {
5770
5787
  preparedPipeline,
5771
5788
  tools,
5772
5789
  $executionReport,
5790
+ onProgress,
5773
5791
  pipelineIdentification,
5774
5792
  maxExecutionAttempts,
5775
5793
  maxParallelCount,