@promptbook/legacy-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
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [π] Ignore a discrepancy between file name and entity name
|
|
@@ -4302,7 +4302,8 @@ const CsvFormatParser = {
|
|
|
4302
4302
|
subvalueParsers: [
|
|
4303
4303
|
{
|
|
4304
4304
|
subvalueName: 'ROW',
|
|
4305
|
-
async mapValues(
|
|
4305
|
+
async mapValues(options) {
|
|
4306
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4306
4307
|
const csv = csvParse(value, settings);
|
|
4307
4308
|
if (csv.errors.length !== 0) {
|
|
4308
4309
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
@@ -4318,21 +4319,29 @@ const CsvFormatParser = {
|
|
|
4318
4319
|
${block(value)}
|
|
4319
4320
|
`));
|
|
4320
4321
|
}
|
|
4321
|
-
const mappedData =
|
|
4322
|
+
const mappedData = [];
|
|
4323
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
4324
|
+
const row = csv.data[index];
|
|
4322
4325
|
if (row[outputParameterName]) {
|
|
4323
4326
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4324
4327
|
}
|
|
4325
|
-
|
|
4328
|
+
const mappedRow = {
|
|
4326
4329
|
...row,
|
|
4327
4330
|
[outputParameterName]: await mapCallback(row, index),
|
|
4328
4331
|
};
|
|
4329
|
-
|
|
4332
|
+
mappedData.push(mappedRow);
|
|
4333
|
+
if (onProgress) {
|
|
4334
|
+
// Note: Report the CSV with all rows mapped so far
|
|
4335
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4330
4338
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4331
4339
|
},
|
|
4332
4340
|
},
|
|
4333
4341
|
{
|
|
4334
4342
|
subvalueName: 'CELL',
|
|
4335
|
-
async mapValues(
|
|
4343
|
+
async mapValues(options) {
|
|
4344
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4336
4345
|
const csv = csvParse(value, settings);
|
|
4337
4346
|
if (csv.errors.length !== 0) {
|
|
4338
4347
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
@@ -4419,7 +4428,8 @@ const TextFormatParser = {
|
|
|
4419
4428
|
subvalueParsers: [
|
|
4420
4429
|
{
|
|
4421
4430
|
subvalueName: 'LINE',
|
|
4422
|
-
async mapValues(
|
|
4431
|
+
async mapValues(options) {
|
|
4432
|
+
const { value, mapCallback, onProgress } = options;
|
|
4423
4433
|
const lines = value.split('\n');
|
|
4424
4434
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4425
4435
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -5240,7 +5250,7 @@ async function executeAttempts(options) {
|
|
|
5240
5250
|
* @private internal utility of `createPipelineExecutor`
|
|
5241
5251
|
*/
|
|
5242
5252
|
async function executeFormatSubvalues(options) {
|
|
5243
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5253
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5244
5254
|
if (task.foreach === undefined) {
|
|
5245
5255
|
return /* not await */ executeAttempts(options);
|
|
5246
5256
|
}
|
|
@@ -5294,21 +5304,32 @@ async function executeFormatSubvalues(options) {
|
|
|
5294
5304
|
formatSettings = csvSettings;
|
|
5295
5305
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5296
5306
|
}
|
|
5297
|
-
const resultString = await subvalueParser.mapValues(
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5307
|
+
const resultString = await subvalueParser.mapValues({
|
|
5308
|
+
value: parameterValue,
|
|
5309
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
5310
|
+
settings: formatSettings,
|
|
5311
|
+
onProgress(partialResultString) {
|
|
5312
|
+
return onProgress(Object.freeze({
|
|
5313
|
+
[task.resultingParameterName]:
|
|
5314
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5315
|
+
partialResultString,
|
|
5316
|
+
}));
|
|
5317
|
+
},
|
|
5318
|
+
async mapCallback(subparameters, index) {
|
|
5319
|
+
let mappedParameters;
|
|
5320
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
5321
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
5322
|
+
try {
|
|
5323
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
5324
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
5325
|
+
availableParameters: subparameters,
|
|
5326
|
+
});
|
|
5310
5327
|
}
|
|
5311
|
-
|
|
5328
|
+
catch (error) {
|
|
5329
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5330
|
+
throw error;
|
|
5331
|
+
}
|
|
5332
|
+
throw new PipelineExecutionError(spaceTrim$1((block) => `
|
|
5312
5333
|
${error.message}
|
|
5313
5334
|
|
|
5314
5335
|
This is error in FOREACH command
|
|
@@ -5317,23 +5338,24 @@ async function executeFormatSubvalues(options) {
|
|
|
5317
5338
|
${block(pipelineIdentification)}
|
|
5318
5339
|
Subparameter index: ${index}
|
|
5319
5340
|
`));
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5341
|
+
}
|
|
5342
|
+
const allSubparameters = {
|
|
5343
|
+
...parameters,
|
|
5344
|
+
...mappedParameters,
|
|
5345
|
+
};
|
|
5346
|
+
// 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
|
|
5347
|
+
Object.freeze(allSubparameters);
|
|
5348
|
+
const subresultString = await executeAttempts({
|
|
5349
|
+
...options,
|
|
5350
|
+
priority: priority + index,
|
|
5351
|
+
parameters: allSubparameters,
|
|
5352
|
+
pipelineIdentification: spaceTrim$1((block) => `
|
|
5332
5353
|
${block(pipelineIdentification)}
|
|
5333
5354
|
Subparameter index: ${index}
|
|
5334
5355
|
`),
|
|
5335
|
-
|
|
5336
|
-
|
|
5356
|
+
});
|
|
5357
|
+
return subresultString;
|
|
5358
|
+
},
|
|
5337
5359
|
});
|
|
5338
5360
|
return resultString;
|
|
5339
5361
|
}
|
|
@@ -5507,11 +5529,6 @@ async function getReservedParametersForTask(options) {
|
|
|
5507
5529
|
async function executeTask(options) {
|
|
5508
5530
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5509
5531
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5510
|
-
await onProgress({
|
|
5511
|
-
outputParameters: {
|
|
5512
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
5513
|
-
},
|
|
5514
|
-
});
|
|
5515
5532
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
5516
5533
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5517
5534
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -5586,6 +5603,7 @@ async function executeTask(options) {
|
|
|
5586
5603
|
preparedPipeline,
|
|
5587
5604
|
tools,
|
|
5588
5605
|
$executionReport,
|
|
5606
|
+
onProgress,
|
|
5589
5607
|
pipelineIdentification,
|
|
5590
5608
|
maxExecutionAttempts,
|
|
5591
5609
|
maxParallelCount,
|