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