@promptbook/markdown-utils 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 +1 -1
- package/umd/index.umd.js +59 -41
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [π] Ignore a discrepancy between file name and entity name
|
|
@@ -4223,7 +4223,8 @@ const CsvFormatParser = {
|
|
|
4223
4223
|
subvalueParsers: [
|
|
4224
4224
|
{
|
|
4225
4225
|
subvalueName: 'ROW',
|
|
4226
|
-
async mapValues(
|
|
4226
|
+
async mapValues(options) {
|
|
4227
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4227
4228
|
const csv = csvParse(value, settings);
|
|
4228
4229
|
if (csv.errors.length !== 0) {
|
|
4229
4230
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4239,21 +4240,29 @@ const CsvFormatParser = {
|
|
|
4239
4240
|
${block(value)}
|
|
4240
4241
|
`));
|
|
4241
4242
|
}
|
|
4242
|
-
const mappedData =
|
|
4243
|
+
const mappedData = [];
|
|
4244
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
4245
|
+
const row = csv.data[index];
|
|
4243
4246
|
if (row[outputParameterName]) {
|
|
4244
4247
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4245
4248
|
}
|
|
4246
|
-
|
|
4249
|
+
const mappedRow = {
|
|
4247
4250
|
...row,
|
|
4248
4251
|
[outputParameterName]: await mapCallback(row, index),
|
|
4249
4252
|
};
|
|
4250
|
-
|
|
4253
|
+
mappedData.push(mappedRow);
|
|
4254
|
+
if (onProgress) {
|
|
4255
|
+
// Note: Report the CSV with all rows mapped so far
|
|
4256
|
+
await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4251
4259
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4252
4260
|
},
|
|
4253
4261
|
},
|
|
4254
4262
|
{
|
|
4255
4263
|
subvalueName: 'CELL',
|
|
4256
|
-
async mapValues(
|
|
4264
|
+
async mapValues(options) {
|
|
4265
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4257
4266
|
const csv = csvParse(value, settings);
|
|
4258
4267
|
if (csv.errors.length !== 0) {
|
|
4259
4268
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4340,7 +4349,8 @@ const TextFormatParser = {
|
|
|
4340
4349
|
subvalueParsers: [
|
|
4341
4350
|
{
|
|
4342
4351
|
subvalueName: 'LINE',
|
|
4343
|
-
async mapValues(
|
|
4352
|
+
async mapValues(options) {
|
|
4353
|
+
const { value, mapCallback, onProgress } = options;
|
|
4344
4354
|
const lines = value.split('\n');
|
|
4345
4355
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4346
4356
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -5059,7 +5069,7 @@ async function executeAttempts(options) {
|
|
|
5059
5069
|
* @private internal utility of `createPipelineExecutor`
|
|
5060
5070
|
*/
|
|
5061
5071
|
async function executeFormatSubvalues(options) {
|
|
5062
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5072
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5063
5073
|
if (task.foreach === undefined) {
|
|
5064
5074
|
return /* not await */ executeAttempts(options);
|
|
5065
5075
|
}
|
|
@@ -5113,21 +5123,32 @@ async function executeFormatSubvalues(options) {
|
|
|
5113
5123
|
formatSettings = csvSettings;
|
|
5114
5124
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5115
5125
|
}
|
|
5116
|
-
const resultString = await subvalueParser.mapValues(
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5126
|
+
const resultString = await subvalueParser.mapValues({
|
|
5127
|
+
value: parameterValue,
|
|
5128
|
+
outputParameterName: task.foreach.outputSubparameterName,
|
|
5129
|
+
settings: formatSettings,
|
|
5130
|
+
onProgress(partialResultString) {
|
|
5131
|
+
return onProgress(Object.freeze({
|
|
5132
|
+
[task.resultingParameterName]:
|
|
5133
|
+
// <- Note: [π©βπ©βπ§] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5134
|
+
partialResultString,
|
|
5135
|
+
}));
|
|
5136
|
+
},
|
|
5137
|
+
async mapCallback(subparameters, index) {
|
|
5138
|
+
let mappedParameters;
|
|
5139
|
+
// TODO: [π€ΉββοΈ][πͺ] Limit to N concurrent executions
|
|
5140
|
+
// TODO: When done [π] Report progress also for each subvalue here
|
|
5141
|
+
try {
|
|
5142
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
5143
|
+
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
5144
|
+
availableParameters: subparameters,
|
|
5145
|
+
});
|
|
5129
5146
|
}
|
|
5130
|
-
|
|
5147
|
+
catch (error) {
|
|
5148
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5149
|
+
throw error;
|
|
5150
|
+
}
|
|
5151
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
5131
5152
|
${error.message}
|
|
5132
5153
|
|
|
5133
5154
|
This is error in FOREACH command
|
|
@@ -5136,23 +5157,24 @@ async function executeFormatSubvalues(options) {
|
|
|
5136
5157
|
${block(pipelineIdentification)}
|
|
5137
5158
|
Subparameter index: ${index}
|
|
5138
5159
|
`));
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5160
|
+
}
|
|
5161
|
+
const allSubparameters = {
|
|
5162
|
+
...parameters,
|
|
5163
|
+
...mappedParameters,
|
|
5164
|
+
};
|
|
5165
|
+
// 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
|
|
5166
|
+
Object.freeze(allSubparameters);
|
|
5167
|
+
const subresultString = await executeAttempts({
|
|
5168
|
+
...options,
|
|
5169
|
+
priority: priority + index,
|
|
5170
|
+
parameters: allSubparameters,
|
|
5171
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
5151
5172
|
${block(pipelineIdentification)}
|
|
5152
5173
|
Subparameter index: ${index}
|
|
5153
5174
|
`),
|
|
5154
|
-
|
|
5155
|
-
|
|
5175
|
+
});
|
|
5176
|
+
return subresultString;
|
|
5177
|
+
},
|
|
5156
5178
|
});
|
|
5157
5179
|
return resultString;
|
|
5158
5180
|
}
|
|
@@ -5326,11 +5348,6 @@ async function getReservedParametersForTask(options) {
|
|
|
5326
5348
|
async function executeTask(options) {
|
|
5327
5349
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5328
5350
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5329
|
-
await onProgress({
|
|
5330
|
-
outputParameters: {
|
|
5331
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
5332
|
-
},
|
|
5333
|
-
});
|
|
5334
5351
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
5335
5352
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5336
5353
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -5405,6 +5422,7 @@ async function executeTask(options) {
|
|
|
5405
5422
|
preparedPipeline,
|
|
5406
5423
|
tools,
|
|
5407
5424
|
$executionReport,
|
|
5425
|
+
onProgress,
|
|
5408
5426
|
pipelineIdentification,
|
|
5409
5427
|
maxExecutionAttempts,
|
|
5410
5428
|
maxParallelCount,
|