@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.
@@ -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/remote-server",
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/remote-server.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
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-21';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -4484,7 +4484,8 @@
4484
4484
  subvalueParsers: [
4485
4485
  {
4486
4486
  subvalueName: 'ROW',
4487
- async mapValues(value, outputParameterName, settings, mapCallback) {
4487
+ async mapValues(options) {
4488
+ const { value, outputParameterName, settings, mapCallback, onProgress } = options;
4488
4489
  const csv = csvParse(value, settings);
4489
4490
  if (csv.errors.length !== 0) {
4490
4491
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4500,21 +4501,29 @@
4500
4501
  ${block(value)}
4501
4502
  `));
4502
4503
  }
4503
- const mappedData = await Promise.all(csv.data.map(async (row, index) => {
4504
+ const mappedData = [];
4505
+ for (let index = 0; index < csv.data.length; index++) {
4506
+ const row = csv.data[index];
4504
4507
  if (row[outputParameterName]) {
4505
4508
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4506
4509
  }
4507
- return {
4510
+ const mappedRow = {
4508
4511
  ...row,
4509
4512
  [outputParameterName]: await mapCallback(row, index),
4510
4513
  };
4511
- }));
4514
+ mappedData.push(mappedRow);
4515
+ if (onProgress) {
4516
+ // Note: Report the CSV with all rows mapped so far
4517
+ await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4518
+ }
4519
+ }
4512
4520
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
4513
4521
  },
4514
4522
  },
4515
4523
  {
4516
4524
  subvalueName: 'CELL',
4517
- async mapValues(value, outputParameterName, settings, mapCallback) {
4525
+ async mapValues(options) {
4526
+ const { value, settings, mapCallback, onProgress } = options;
4518
4527
  const csv = csvParse(value, settings);
4519
4528
  if (csv.errors.length !== 0) {
4520
4529
  throw new CsvFormatError(spaceTrim__default["default"]((block) => `
@@ -4601,7 +4610,8 @@
4601
4610
  subvalueParsers: [
4602
4611
  {
4603
4612
  subvalueName: 'LINE',
4604
- async mapValues(value, outputParameterName, settings, mapCallback) {
4613
+ async mapValues(options) {
4614
+ const { value, mapCallback, onProgress } = options;
4605
4615
  const lines = value.split('\n');
4606
4616
  const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4607
4617
  // TODO: [🧠] Maybe option to skip empty line
@@ -5439,7 +5449,7 @@
5439
5449
  * @private internal utility of `createPipelineExecutor`
5440
5450
  */
5441
5451
  async function executeFormatSubvalues(options) {
5442
- const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
5452
+ const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
5443
5453
  if (task.foreach === undefined) {
5444
5454
  return /* not await */ executeAttempts(options);
5445
5455
  }
@@ -5493,21 +5503,32 @@
5493
5503
  formatSettings = csvSettings;
5494
5504
  // <- TODO: [πŸ€Ήβ€β™‚οΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
5495
5505
  }
5496
- const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
5497
- let mappedParameters;
5498
- // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5499
- // TODO: When done [🐚] Report progress also for each subvalue here
5500
- try {
5501
- mappedParameters = mapAvailableToExpectedParameters({
5502
- expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5503
- availableParameters: subparameters,
5504
- });
5505
- }
5506
- catch (error) {
5507
- if (!(error instanceof PipelineExecutionError)) {
5508
- throw error;
5506
+ const resultString = await subvalueParser.mapValues({
5507
+ value: parameterValue,
5508
+ outputParameterName: task.foreach.outputSubparameterName,
5509
+ settings: formatSettings,
5510
+ onProgress(partialResultString) {
5511
+ return onProgress(Object.freeze({
5512
+ [task.resultingParameterName]:
5513
+ // <- Note: [πŸ‘©β€πŸ‘©β€πŸ‘§] No need to detect parameter collision here because pipeline checks logic consistency during construction
5514
+ partialResultString,
5515
+ }));
5516
+ },
5517
+ async mapCallback(subparameters, index) {
5518
+ let mappedParameters;
5519
+ // TODO: [πŸ€Ήβ€β™‚οΈ][πŸͺ‚] Limit to N concurrent executions
5520
+ // TODO: When done [🐚] Report progress also for each subvalue here
5521
+ try {
5522
+ mappedParameters = mapAvailableToExpectedParameters({
5523
+ expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
5524
+ availableParameters: subparameters,
5525
+ });
5509
5526
  }
5510
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5527
+ catch (error) {
5528
+ if (!(error instanceof PipelineExecutionError)) {
5529
+ throw error;
5530
+ }
5531
+ throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5511
5532
  ${error.message}
5512
5533
 
5513
5534
  This is error in FOREACH command
@@ -5516,23 +5537,24 @@
5516
5537
  ${block(pipelineIdentification)}
5517
5538
  Subparameter index: ${index}
5518
5539
  `));
5519
- }
5520
- const allSubparameters = {
5521
- ...parameters,
5522
- ...mappedParameters,
5523
- };
5524
- // 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
5525
- Object.freeze(allSubparameters);
5526
- const subresultString = await executeAttempts({
5527
- ...options,
5528
- priority: priority + index,
5529
- parameters: allSubparameters,
5530
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5540
+ }
5541
+ const allSubparameters = {
5542
+ ...parameters,
5543
+ ...mappedParameters,
5544
+ };
5545
+ // 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
5546
+ Object.freeze(allSubparameters);
5547
+ const subresultString = await executeAttempts({
5548
+ ...options,
5549
+ priority: priority + index,
5550
+ parameters: allSubparameters,
5551
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5531
5552
  ${block(pipelineIdentification)}
5532
5553
  Subparameter index: ${index}
5533
5554
  `),
5534
- });
5535
- return subresultString;
5555
+ });
5556
+ return subresultString;
5557
+ },
5536
5558
  });
5537
5559
  return resultString;
5538
5560
  }
@@ -5706,11 +5728,6 @@
5706
5728
  async function executeTask(options) {
5707
5729
  const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
5708
5730
  const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
5709
- await onProgress({
5710
- outputParameters: {
5711
- [currentTask.resultingParameterName]: '', // <- TODO: [🧠] What is the best value here?
5712
- },
5713
- });
5714
5731
  // Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but it’s good to doublecheck
5715
5732
  const usedParameterNames = extractParameterNamesFromTask(currentTask);
5716
5733
  const dependentParameterNames = new Set(currentTask.dependentParameterNames);
@@ -5785,6 +5802,7 @@
5785
5802
  preparedPipeline,
5786
5803
  tools,
5787
5804
  $executionReport,
5805
+ onProgress,
5788
5806
  pipelineIdentification,
5789
5807
  maxExecutionAttempts,
5790
5808
  maxParallelCount,