@promptbook/node 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.
@@ -62,6 +62,7 @@ import type { UsageCounts } from '../execution/Usage';
62
62
  import type { UserInterfaceTools } from '../execution/UserInterfaceTools';
63
63
  import type { UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
64
64
  import type { FormatSubvalueParser } from '../formats/_common/FormatSubvalueParser';
65
+ import type { FormatSubvalueParserMapValuesOptions } from '../formats/_common/FormatSubvalueParser';
65
66
  import type { CsvSettings } from '../formats/csv/CsvSettings';
66
67
  import type { AbstractFormfactorDefinition } from '../formfactors/_common/AbstractFormfactorDefinition';
67
68
  import type { FormfactorDefinition } from '../formfactors/_common/FormfactorDefinition';
@@ -358,6 +359,7 @@ export type { UsageCounts };
358
359
  export type { UserInterfaceTools };
359
360
  export type { UserInterfaceToolsPromptDialogOptions };
360
361
  export type { FormatSubvalueParser };
362
+ export type { FormatSubvalueParserMapValuesOptions };
361
363
  export type { CsvSettings };
362
364
  export type { AbstractFormfactorDefinition };
363
365
  export type { FormfactorDefinition };
@@ -1,11 +1,18 @@
1
+ import type { PartialDeep, Promisable } from 'type-fest';
1
2
  import type { TODO_any } from '../../utils/organization/TODO_any';
3
+ import type { PipelineExecutorResult } from '../PipelineExecutorResult';
2
4
  import type { ExecuteAttemptsOptions } from './40-executeAttempts';
3
5
  /**
4
6
  * @@@
5
7
  *
6
8
  * @private internal type of `executeFormatSubvalues`
7
9
  */
8
- type ExecuteFormatCellsOptions = ExecuteAttemptsOptions;
10
+ type ExecuteFormatCellsOptions = ExecuteAttemptsOptions & {
11
+ /**
12
+ * @@@
13
+ */
14
+ readonly onProgress: (newOngoingResult: PartialDeep<PipelineExecutorResult>) => Promisable<void>;
15
+ };
9
16
  /**
10
17
  * @@@
11
18
  *
@@ -24,7 +24,17 @@ export type FormatSubvalueParser<TValue extends string, TSettings extends empty_
24
24
  * For example, if you have a JSON object and you want to map all values to uppercase
25
25
  * Or iterate over all CSV cells @@@
26
26
  */
27
- mapValues(value: TValue, outputParameterName: string_parameter_name, settings: TSettings, mapCallback: (subvalues: Parameters, index: number) => Promisable<string>): Promise<string>;
27
+ mapValues(options: FormatSubvalueParserMapValuesOptions<TValue, TSettings>): Promise<string>;
28
+ };
29
+ /**
30
+ * @@@
31
+ */
32
+ export type FormatSubvalueParserMapValuesOptions<TValue extends string, TSettings extends empty_object> = {
33
+ readonly value: TValue;
34
+ readonly outputParameterName: string_parameter_name;
35
+ readonly settings: TSettings;
36
+ mapCallback: (subvalues: Parameters, index: number) => Promisable<TValue>;
37
+ onProgress(partialResultString: TValue): Promisable<void>;
28
38
  };
29
39
  /**
30
40
  * Note: [πŸ‘©πŸΎβ€πŸ€β€πŸ§‘πŸ½]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.92.0-21",
3
+ "version": "0.92.0-22",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -51,7 +51,7 @@
51
51
  "module": "./esm/index.es.js",
52
52
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.92.0-21"
54
+ "@promptbook/core": "0.92.0-22"
55
55
  },
56
56
  "dependencies": {
57
57
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -46,7 +46,7 @@
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -2601,7 +2601,8 @@
2601
2601
  subvalueParsers: [
2602
2602
  {
2603
2603
  subvalueName: 'ROW',
2604
- async mapValues(value, outputParameterName, settings, mapCallback) {
2604
+ async mapValues(options) {
2605
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
2605
2606
  const csv = csvParse(value, settings);
2606
2607
  if (csv.errors.length !== 0) {
2607
2608
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -2617,21 +2618,29 @@
2617
2618
  ${block(value)}
2618
2619
  `));
2619
2620
  }
2620
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
2621
+ const mappedData = [];
2622
+ for (let index = 0; index < csv.data.length; index++) {
2623
+ const row = csv.data[index];
2621
2624
  if (row[outputParameterName]) {
2622
2625
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
2623
2626
  }
2624
- return {
2627
+ const mappedRow = {
2625
2628
  ...row,
2626
2629
  [outputParameterName]: await mapCallback(row, index),
2627
2630
  };
2628
- }));
2631
+ mappedData.push(mappedRow);
2632
+ if (onProgress) {
2633
+ // Note: Report the CSV with all rows mapped so far
2634
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
2635
+ }
2636
+ }
2629
2637
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
2630
2638
  },
2631
2639
  },
2632
2640
  {
2633
2641
  subvalueName: 'CELL',
2634
- async mapValues(value, outputParameterName, settings, mapCallback) {
2642
+ async mapValues(options) {
2643
+ const { value, settings, mapCallback, onProgress } = options;
2635
2644
  const csv = csvParse(value, settings);
2636
2645
  if (csv.errors.length !== 0) {
2637
2646
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -2718,7 +2727,8 @@
2718
2727
  subvalueParsers: [
2719
2728
  {
2720
2729
  subvalueName: 'LINE',
2721
- async mapValues(value, outputParameterName, settings, mapCallback) {
2730
+ async mapValues(options) {
2731
+ const { value, mapCallback, onProgress } = options;
2722
2732
  const lines = value.split('\n');
2723
2733
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
2724
2734
  // TODO: [🧠] Maybe option to skip empty line
@@ -4028,7 +4038,7 @@
4028
4038
  * @private internal utility of `createPipelineExecutor`
4029
4039
  */
4030
4040
  async function executeFormatSubvalues(options) {
4031
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
4041
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
4032
4042
  if (task.foreach === undefined) {
4033
4043
  return /* not await */ executeAttempts(options);
4034
4044
  }
@@ -4082,21 +4092,32 @@
4082
4092
  formatSettings = csvSettings;
4083
4093
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
4084
4094
  }
4085
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
4086
- let mappedParameters;
4087
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
4088
- // TODO: When done [🐚] Report progress also for each subvalue here
4089
- try {
4090
- mappedParameters = mapAvailableToExpectedParameters({
4091
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
4092
- availableParameters: subparameters,
4093
- });
4094
- }
4095
- catch (error) {
4096
- if (!(error instanceof PipelineExecutionError)) {
4097
- throw error;
4095
+ const resultString = await subvalueParser.mapValues({
4096
+ value: parameterValue,
4097
+ outputParameterName: task.foreach.outputSubparameterName,
4098
+ settings: formatSettings,
4099
+ onProgress(partialResultString) {
4100
+ return onProgress(Object.freeze({
4101
+ [task.resultingParameterName]:
4102
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
4103
+ partialResultString,
4104
+ }));
4105
+ },
4106
+ async mapCallback(subparameters, index) {
4107
+ let mappedParameters;
4108
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
4109
+ // TODO: When done [🐚] Report progress also for each subvalue here
4110
+ try {
4111
+ mappedParameters = mapAvailableToExpectedParameters({
4112
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
4113
+ availableParameters: subparameters,
4114
+ });
4098
4115
  }
4099
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
4116
+ catch (error) {
4117
+ if (!(error instanceof PipelineExecutionError)) {
4118
+ throw error;
4119
+ }
4120
+ throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
4100
4121
  ${error.message}
4101
4122
 
4102
4123
  This is error in FOREACH command
@@ -4105,23 +4126,24 @@
4105
4126
  ${block(pipelineIdentification)}
4106
4127
  Subparameter index: ${index}
4107
4128
  `));
4108
- }
4109
- const allSubparameters = {
4110
- ...parameters,
4111
- ...mappedParameters,
4112
- };
4113
- // 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
4114
- Object.freeze(allSubparameters);
4115
- const subresultString = await executeAttempts({
4116
- ...options,
4117
- priority: priority + index,
4118
- parameters: allSubparameters,
4119
- pipelineIdentification: spaceTrim__default["default"]((block) => `
4129
+ }
4130
+ const allSubparameters = {
4131
+ ...parameters,
4132
+ ...mappedParameters,
4133
+ };
4134
+ // 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
4135
+ Object.freeze(allSubparameters);
4136
+ const subresultString = await executeAttempts({
4137
+ ...options,
4138
+ priority: priority + index,
4139
+ parameters: allSubparameters,
4140
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
4120
4141
  ${block(pipelineIdentification)}
4121
4142
  Subparameter index: ${index}
4122
4143
  `),
4123
- });
4124
- return subresultString;
4144
+ });
4145
+ return subresultString;
4146
+ },
4125
4147
  });
4126
4148
  return resultString;
4127
4149
  }
@@ -4295,11 +4317,6 @@
4295
4317
  async function executeTask(options) {
4296
4318
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
4297
4319
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
4298
- await onProgress({
4299
- outputParameters: {
4300
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
4301
- },
4302
- });
4303
4320
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
4304
4321
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
4305
4322
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -4374,6 +4391,7 @@
4374
4391
  preparedPipeline,
4375
4392
  tools,
4376
4393
  $executionReport,
4394
+ onProgress,
4377
4395
  pipelineIdentification,
4378
4396
  maxExecutionAttempts,
4379
4397
  maxParallelCount,