@promptbook/markdown-utils 0.92.0-20 β 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 +60 -45
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +8 -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/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
- package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
- package/esm/typings/src/formfactors/index.d.ts +28 -3
- package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
- package/esm/typings/src/migrations/migratePipeline.d.ts +2 -0
- package/package.json +1 -1
- package/umd/index.umd.js +60 -45
- 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
|
|
@@ -2070,15 +2070,12 @@ function jsonParse(value) {
|
|
|
2070
2070
|
}
|
|
2071
2071
|
throw new Error(spaceTrim((block) => `
|
|
2072
2072
|
${block(error.message)}
|
|
2073
|
-
|
|
2073
|
+
|
|
2074
2074
|
The JSON text:
|
|
2075
2075
|
${block(value)}
|
|
2076
2076
|
`));
|
|
2077
2077
|
}
|
|
2078
2078
|
}
|
|
2079
|
-
/**
|
|
2080
|
-
* TODO: !!!! Use in Promptbook.studio
|
|
2081
|
-
*/
|
|
2082
2079
|
|
|
2083
2080
|
/**
|
|
2084
2081
|
* Recursively converts JSON strings to JSON objects
|
|
@@ -4226,7 +4223,8 @@ const CsvFormatParser = {
|
|
|
4226
4223
|
subvalueParsers: [
|
|
4227
4224
|
{
|
|
4228
4225
|
subvalueName: 'ROW',
|
|
4229
|
-
async mapValues(
|
|
4226
|
+
async mapValues(options) {
|
|
4227
|
+
const { value, outputParameterName, settings, mapCallback, onProgress } = options;
|
|
4230
4228
|
const csv = csvParse(value, settings);
|
|
4231
4229
|
if (csv.errors.length !== 0) {
|
|
4232
4230
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4242,21 +4240,29 @@ const CsvFormatParser = {
|
|
|
4242
4240
|
${block(value)}
|
|
4243
4241
|
`));
|
|
4244
4242
|
}
|
|
4245
|
-
const mappedData =
|
|
4243
|
+
const mappedData = [];
|
|
4244
|
+
for (let index = 0; index < csv.data.length; index++) {
|
|
4245
|
+
const row = csv.data[index];
|
|
4246
4246
|
if (row[outputParameterName]) {
|
|
4247
4247
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4248
4248
|
}
|
|
4249
|
-
|
|
4249
|
+
const mappedRow = {
|
|
4250
4250
|
...row,
|
|
4251
4251
|
[outputParameterName]: await mapCallback(row, index),
|
|
4252
4252
|
};
|
|
4253
|
-
|
|
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
|
+
}
|
|
4254
4259
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4255
4260
|
},
|
|
4256
4261
|
},
|
|
4257
4262
|
{
|
|
4258
4263
|
subvalueName: 'CELL',
|
|
4259
|
-
async mapValues(
|
|
4264
|
+
async mapValues(options) {
|
|
4265
|
+
const { value, settings, mapCallback, onProgress } = options;
|
|
4260
4266
|
const csv = csvParse(value, settings);
|
|
4261
4267
|
if (csv.errors.length !== 0) {
|
|
4262
4268
|
throw new CsvFormatError(spaceTrim((block) => `
|
|
@@ -4343,7 +4349,8 @@ const TextFormatParser = {
|
|
|
4343
4349
|
subvalueParsers: [
|
|
4344
4350
|
{
|
|
4345
4351
|
subvalueName: 'LINE',
|
|
4346
|
-
async mapValues(
|
|
4352
|
+
async mapValues(options) {
|
|
4353
|
+
const { value, mapCallback, onProgress } = options;
|
|
4347
4354
|
const lines = value.split('\n');
|
|
4348
4355
|
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4349
4356
|
// TODO: [π§ ] Maybe option to skip empty line
|
|
@@ -5062,7 +5069,7 @@ async function executeAttempts(options) {
|
|
|
5062
5069
|
* @private internal utility of `createPipelineExecutor`
|
|
5063
5070
|
*/
|
|
5064
5071
|
async function executeFormatSubvalues(options) {
|
|
5065
|
-
const { task, jokerParameterNames, parameters, priority, csvSettings, pipelineIdentification } = options;
|
|
5072
|
+
const { task, jokerParameterNames, parameters, priority, csvSettings, onProgress, pipelineIdentification } = options;
|
|
5066
5073
|
if (task.foreach === undefined) {
|
|
5067
5074
|
return /* not await */ executeAttempts(options);
|
|
5068
5075
|
}
|
|
@@ -5116,21 +5123,32 @@ async function executeFormatSubvalues(options) {
|
|
|
5116
5123
|
formatSettings = csvSettings;
|
|
5117
5124
|
// <- TODO: [π€ΉββοΈ] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5118
5125
|
}
|
|
5119
|
-
const resultString = await subvalueParser.mapValues(
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
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
|
+
});
|
|
5132
5146
|
}
|
|
5133
|
-
|
|
5147
|
+
catch (error) {
|
|
5148
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
5149
|
+
throw error;
|
|
5150
|
+
}
|
|
5151
|
+
throw new PipelineExecutionError(spaceTrim((block) => `
|
|
5134
5152
|
${error.message}
|
|
5135
5153
|
|
|
5136
5154
|
This is error in FOREACH command
|
|
@@ -5139,23 +5157,24 @@ async function executeFormatSubvalues(options) {
|
|
|
5139
5157
|
${block(pipelineIdentification)}
|
|
5140
5158
|
Subparameter index: ${index}
|
|
5141
5159
|
`));
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
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) => `
|
|
5154
5172
|
${block(pipelineIdentification)}
|
|
5155
5173
|
Subparameter index: ${index}
|
|
5156
5174
|
`),
|
|
5157
|
-
|
|
5158
|
-
|
|
5175
|
+
});
|
|
5176
|
+
return subresultString;
|
|
5177
|
+
},
|
|
5159
5178
|
});
|
|
5160
5179
|
return resultString;
|
|
5161
5180
|
}
|
|
@@ -5329,11 +5348,6 @@ async function getReservedParametersForTask(options) {
|
|
|
5329
5348
|
async function executeTask(options) {
|
|
5330
5349
|
const { currentTask, preparedPipeline, parametersToPass, tools, onProgress, $executionReport, pipelineIdentification, maxExecutionAttempts, maxParallelCount, csvSettings, isVerbose, rootDirname, cacheDirname, intermediateFilesStrategy, isAutoInstalled, isNotPreparedWarningSupressed, } = options;
|
|
5331
5350
|
const priority = preparedPipeline.tasks.length - preparedPipeline.tasks.indexOf(currentTask);
|
|
5332
|
-
await onProgress({
|
|
5333
|
-
outputParameters: {
|
|
5334
|
-
[currentTask.resultingParameterName]: '', // <- TODO: [π§ ] What is the best value here?
|
|
5335
|
-
},
|
|
5336
|
-
});
|
|
5337
5351
|
// Note: Check consistency of used and dependent parameters which was also done in `validatePipeline`, but itβs good to doublecheck
|
|
5338
5352
|
const usedParameterNames = extractParameterNamesFromTask(currentTask);
|
|
5339
5353
|
const dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
@@ -5408,6 +5422,7 @@ async function executeTask(options) {
|
|
|
5408
5422
|
preparedPipeline,
|
|
5409
5423
|
tools,
|
|
5410
5424
|
$executionReport,
|
|
5425
|
+
onProgress,
|
|
5411
5426
|
pipelineIdentification,
|
|
5412
5427
|
maxExecutionAttempts,
|
|
5413
5428
|
maxParallelCount,
|