@promptbook/pdf 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
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
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
|
|
@@ -4151,7 +4151,8 @@ const CsvFormatParser = {
|
|
|
4151
4151
|
subvalueParsers: [
|
|
4152
4152
|
{
|
|
4153
4153
|
subvalueName: 'ROW',
|
|
4154
|
-
async mapValues(
|
|
4154
|
+
async mapValues(options) {
|
|
4155
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4155
4156
|
const csv = csvParse(value, settings);
|
|
4156
4157
|
if (csv.errors.length !== 0) {
|
|
4157
4158
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4167,21 +4168,29 @@ const CsvFormatParser = {
|
|
|
4167
4168
|
${block(value)}
|
|
4168
4169
|
`));
|
|
4169
4170
|
}
|
|
4170
|
-
const mappedData =
|
|
4171
|
+
const mappedData = [];
|
|
4172
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
4173
|
+
const row = csv.data[index];
|
|
4171
4174
|
if (row[outputParameterName]) {
|
|
4172
4175
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4173
4176
|
}
|
|
4174
|
-
|
|
4177
|
+
const mappedRow = {
|
|
4175
4178
|
...row,
|
|
4176
4179
|
[outputParameterName]: await mapCallback(row, index),
|
|
4177
4180
|
};
|
|
4178
|
-
|
|
4181
|
+
mappedData.push(mappedRow);
|
|
4182
|
+
if (onProgress) {
|
|
4183
|
+
// Note: Report the CSV with all rows mapped so far
|
|
4184
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4179
4187
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4180
4188
|
},
|
|
4181
4189
|
},
|
|
4182
4190
|
{
|
|
4183
4191
|
subvalueName: 'CELL',
|
|
4184
|
-
async mapValues(
|
|
4192
|
+
async mapValues(options) {
|
|
4193
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4185
4194
|
const csv = csvParse(value, settings);
|
|
4186
4195
|
if (csv.errors.length !== 0) {
|
|
4187
4196
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4268,7 +4277,8 @@ const TextFormatParser = {
|
|
|
4268
4277
|
subvalueParsers: [
|
|
4269
4278
|
{
|
|
4270
4279
|
subvalueName: 'LINE',
|
|
4271
|
-
async mapValues(
|
|
4280
|
+
async mapValues(options) {
|
|
4281
|
+
const { value, mapCallback, onProgress } = options;
|
|
4272
4282
|
const lines = value.split('\n');
|
|
4273
4283
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4274
4284
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -5089,7 +5099,7 @@ async function executeAttempts(options) {
|
|
|
5089
5099
|
* @private internal utility of `createPipelineExecutor`
|
|
5090
5100
|
*/
|
|
5091
5101
|
async function executeFormatSubvalues(options) {
|
|
5092
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5102
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5093
5103
|
if (task.foreach === undefined) {
|
|
5094
5104
|
return /* not await */ executeAttempts(options);
|
|
5095
5105
|
}
|
|
@@ -5143,21 +5153,32 @@ async function executeFormatSubvalues(options) {
|
|
|
5143
5153
|
formatSettings = csvSettings;
|
|
5144
5154
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5145
5155
|
}
|
|
5146
|
-
const resultString = await subvalueParser.mapValues(
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5156
|
+
const resultString = await subvalueParser.mapValues({
|
|
5157
|
+
value: parameterValue,
|
|
5158
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
5159
|
+
settings: formatSettings,
|
|
5160
|
+
onProgress(partialResultString) {
|
|
5161
|
+
return onProgress(Object.freeze({
|
|
5162
|
+
[task.resultingParameterName]:
|
|
5163
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5164
|
+
partialResultString,
|
|
5165
|
+
}));
|
|
5166
|
+
},
|
|
5167
|
+
async mapCallback(subparameters, index) {
|
|
5168
|
+
let mappedParameters;
|
|
5169
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
5170
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
5171
|
+
try {
|
|
5172
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
5173
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
5174
|
+
availableParameters: subparameters,
|
|
5175
|
+
});
|
|
5159
5176
|
}
|
|
5160
|
-
|
|
5177
|
+
catch (error) {
|
|
5178
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5179
|
+
throw error;
|
|
5180
|
+
}
|
|
5181
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
5161
5182
|
${error.message}
|
|
5162
5183
|
|
|
5163
5184
|
This is error in FOREACH command
|
|
@@ -5166,23 +5187,24 @@ async function executeFormatSubvalues(options) {
|
|
|
5166
5187
|
${block(pipelineIdentification)}
|
|
5167
5188
|
Subparameter index: ${index}
|
|
5168
5189
|
`));
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5190
|
+
}
|
|
5191
|
+
const allSubparameters = {
|
|
5192
|
+
...parameters,
|
|
5193
|
+
...mappedParameters,
|
|
5194
|
+
};
|
|
5195
|
+
// 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
|
|
5196
|
+
Object.freeze(allSubparameters);
|
|
5197
|
+
const subresultString = await executeAttempts({
|
|
5198
|
+
...options,
|
|
5199
|
+
priority: priority + index,
|
|
5200
|
+
parameters: allSubparameters,
|
|
5201
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
5181
5202
|
${block(pipelineIdentification)}
|
|
5182
5203
|
Subparameter index: ${index}
|
|
5183
5204
|
`),
|
|
5184
|
-
|
|
5185
|
-
|
|
5205
|
+
});
|
|
5206
|
+
return subresultString;
|
|
5207
|
+
},
|
|
5186
5208
|
});
|
|
5187
5209
|
return resultString;
|
|
5188
5210
|
}
|
|
@@ -5356,11 +5378,6 @@ async function getReservedParametersForTask(options) {
|
|
|
5356
5378
|
async function executeTask(options) {
|
|
5357
5379
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5358
5380
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5359
|
-
await onProgress({
|
|
5360
|
-
outputParameters: {
|
|
5361
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
5362
|
-
},
|
|
5363
|
-
});
|
|
5364
5381
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
5365
5382
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5366
5383
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -5435,6 +5452,7 @@ async function executeTask(options) {
|
|
|
5435
5452
|
preparedPipeline,
|
|
5436
5453
|
tools,
|
|
5437
5454
|
$executionReport,
|
|
5455
|
+
onProgress,
|
|
5438
5456
|
pipelineIdentification,
|
|
5439
5457
|
maxExecutionAttempts,
|
|
5440
5458
|
maxParallelCount,
|