@promptbook/documents 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 +59 -41
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -1
- package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +11 -1
- package/package.json +2 -2
- package/umd/index.umd.js +59 -41
- package/umd/index.umd.js.map +1 -1
|
@@ -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(
|
|
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/documents",
|
|
3
|
-
"version": "0.92.0-
|
|
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/documents.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.92.0-
|
|
54
|
+
"@promptbook/core": "0.92.0-22"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
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
|
|
@@ -4300,7 +4300,8 @@
|
|
|
4300
4300
|
subvalueParsers: [
|
|
4301
4301
|
{
|
|
4302
4302
|
subvalueName: 'ROW',
|
|
4303
|
-
async mapValues(
|
|
4303
|
+
async mapValues(options) {
|
|
4304
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4304
4305
|
const csv = csvParse(value, settings);
|
|
4305
4306
|
if (csv.errors.length !== 0) {
|
|
4306
4307
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
@@ -4316,21 +4317,29 @@
|
|
|
4316
4317
|
${block(value)}
|
|
4317
4318
|
`));
|
|
4318
4319
|
}
|
|
4319
|
-
const mappedData =
|
|
4320
|
+
const mappedData = [];
|
|
4321
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
4322
|
+
const row = csv.data[index];
|
|
4320
4323
|
if (row[outputParameterName]) {
|
|
4321
4324
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4322
4325
|
}
|
|
4323
|
-
|
|
4326
|
+
const mappedRow = {
|
|
4324
4327
|
...row,
|
|
4325
4328
|
[outputParameterName]: await mapCallback(row, index),
|
|
4326
4329
|
};
|
|
4327
|
-
|
|
4330
|
+
mappedData.push(mappedRow);
|
|
4331
|
+
if (onProgress) {
|
|
4332
|
+
// Note: Report the CSV with all rows mapped so far
|
|
4333
|
+
await onProgress(papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4328
4336
|
return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4329
4337
|
},
|
|
4330
4338
|
},
|
|
4331
4339
|
{
|
|
4332
4340
|
subvalueName: 'CELL',
|
|
4333
|
-
async mapValues(
|
|
4341
|
+
async mapValues(options) {
|
|
4342
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4334
4343
|
const csv = csvParse(value, settings);
|
|
4335
4344
|
if (csv.errors.length !== 0) {
|
|
4336
4345
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
@@ -4417,7 +4426,8 @@
|
|
|
4417
4426
|
subvalueParsers: [
|
|
4418
4427
|
{
|
|
4419
4428
|
subvalueName: 'LINE',
|
|
4420
|
-
async mapValues(
|
|
4429
|
+
async mapValues(options) {
|
|
4430
|
+
const { value, mapCallback, onProgress } = options;
|
|
4421
4431
|
const lines = value.split('\n');
|
|
4422
4432
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4423
4433
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -5238,7 +5248,7 @@
|
|
|
5238
5248
|
* @private internal utility of `createPipelineExecutor`
|
|
5239
5249
|
*/
|
|
5240
5250
|
async function executeFormatSubvalues(options) {
|
|
5241
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5251
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5242
5252
|
if (task.foreach === undefined) {
|
|
5243
5253
|
return /* not await */ executeAttempts(options);
|
|
5244
5254
|
}
|
|
@@ -5292,21 +5302,32 @@
|
|
|
5292
5302
|
formatSettings = csvSettings;
|
|
5293
5303
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5294
5304
|
}
|
|
5295
|
-
const resultString = await subvalueParser.mapValues(
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5305
|
+
const resultString = await subvalueParser.mapValues({
|
|
5306
|
+
value: parameterValue,
|
|
5307
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
5308
|
+
settings: formatSettings,
|
|
5309
|
+
onProgress(partialResultString) {
|
|
5310
|
+
return onProgress(Object.freeze({
|
|
5311
|
+
[task.resultingParameterName]:
|
|
5312
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5313
|
+
partialResultString,
|
|
5314
|
+
}));
|
|
5315
|
+
},
|
|
5316
|
+
async mapCallback(subparameters, index) {
|
|
5317
|
+
let mappedParameters;
|
|
5318
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
5319
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
5320
|
+
try {
|
|
5321
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
5322
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
5323
|
+
availableParameters: subparameters,
|
|
5324
|
+
});
|
|
5308
5325
|
}
|
|
5309
|
-
|
|
5326
|
+
catch (error) {
|
|
5327
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5328
|
+
throw error;
|
|
5329
|
+
}
|
|
5330
|
+
throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
5310
5331
|
${error.message}
|
|
5311
5332
|
|
|
5312
5333
|
This is error in FOREACH command
|
|
@@ -5315,23 +5336,24 @@
|
|
|
5315
5336
|
${block(pipelineIdentification)}
|
|
5316
5337
|
Subparameter index: ${index}
|
|
5317
5338
|
`));
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5339
|
+
}
|
|
5340
|
+
const allSubparameters = {
|
|
5341
|
+
...parameters,
|
|
5342
|
+
...mappedParameters,
|
|
5343
|
+
};
|
|
5344
|
+
// 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
|
|
5345
|
+
Object.freeze(allSubparameters);
|
|
5346
|
+
const subresultString = await executeAttempts({
|
|
5347
|
+
...options,
|
|
5348
|
+
priority: priority + index,
|
|
5349
|
+
parameters: allSubparameters,
|
|
5350
|
+
pipelineIdentification: spaceTrim__default["default"]((block) => `
|
|
5330
5351
|
${block(pipelineIdentification)}
|
|
5331
5352
|
Subparameter index: ${index}
|
|
5332
5353
|
`),
|
|
5333
|
-
|
|
5334
|
-
|
|
5354
|
+
});
|
|
5355
|
+
return subresultString;
|
|
5356
|
+
},
|
|
5335
5357
|
});
|
|
5336
5358
|
return resultString;
|
|
5337
5359
|
}
|
|
@@ -5505,11 +5527,6 @@
|
|
|
5505
5527
|
async function executeTask(options) {
|
|
5506
5528
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5507
5529
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5508
|
-
await onProgress({
|
|
5509
|
-
outputParameters: {
|
|
5510
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
5511
|
-
},
|
|
5512
|
-
});
|
|
5513
5530
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
5514
5531
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5515
5532
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -5584,6 +5601,7 @@
|
|
|
5584
5601
|
preparedPipeline,
|
|
5585
5602
|
tools,
|
|
5586
5603
|
$executionReport,
|
|
5604
|
+
onProgress,
|
|
5587
5605
|
pipelineIdentification,
|
|
5588
5606
|
maxExecutionAttempts,
|
|
5589
5607
|
maxParallelCount,
|