@promptbook/node 0.92.0-22 → 0.92.0-23
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 +102 -60
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
- package/esm/typings/src/config.d.ts +29 -11
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -3
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
- package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
- package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +31 -6
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +9 -7
- package/esm/typings/src/utils/$Register.d.ts +8 -7
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
- package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
- package/package.json +2 -2
- package/umd/index.umd.js +102 -60
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
30
30
|
* @generated
|
|
31
31
|
* @see https://github.com/webgptorg/promptbook
|
|
32
32
|
*/
|
|
33
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
33
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
|
|
34
34
|
/**
|
|
35
35
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
36
36
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -101,6 +101,12 @@ const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
|
101
101
|
* @public exported from `@promptbook/core`
|
|
102
102
|
*/
|
|
103
103
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
104
|
+
/**
|
|
105
|
+
* @@@
|
|
106
|
+
*
|
|
107
|
+
* @public exported from `@promptbook/core`
|
|
108
|
+
*/
|
|
109
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
104
110
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
105
111
|
/**
|
|
106
112
|
* The maximum number of iterations for a loops
|
|
@@ -195,7 +201,7 @@ ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
|
195
201
|
const DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = `index`;
|
|
196
202
|
// <- TODO: [🧜♂️]
|
|
197
203
|
/**
|
|
198
|
-
*
|
|
204
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
199
205
|
*
|
|
200
206
|
* @public exported from `@promptbook/core`
|
|
201
207
|
*/
|
|
@@ -206,19 +212,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
206
212
|
skipEmptyLines: true,
|
|
207
213
|
});
|
|
208
214
|
/**
|
|
209
|
-
*
|
|
215
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
210
216
|
*
|
|
211
217
|
* @public exported from `@promptbook/core`
|
|
212
218
|
*/
|
|
213
219
|
let DEFAULT_IS_VERBOSE = false;
|
|
214
220
|
/**
|
|
215
|
-
*
|
|
221
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
216
222
|
*
|
|
217
223
|
* @public exported from `@promptbook/core`
|
|
218
224
|
*/
|
|
219
225
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
220
226
|
/**
|
|
221
|
-
*
|
|
227
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
222
228
|
*
|
|
223
229
|
* @private within the repository
|
|
224
230
|
*/
|
|
@@ -564,8 +570,12 @@ function checkSerializableAsJson(options) {
|
|
|
564
570
|
*/
|
|
565
571
|
|
|
566
572
|
/**
|
|
567
|
-
*
|
|
573
|
+
* Creates a deep clone of the given object
|
|
574
|
+
*
|
|
575
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
568
576
|
*
|
|
577
|
+
* @param objectValue The object to clone.
|
|
578
|
+
* @returns A deep, writable clone of the input object.
|
|
569
579
|
* @public exported from `@promptbook/utils`
|
|
570
580
|
*/
|
|
571
581
|
function deepClone(objectValue) {
|
|
@@ -1204,7 +1214,7 @@ function isValidFilePath(filename) {
|
|
|
1204
1214
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1205
1215
|
*
|
|
1206
1216
|
* @param value The string to check
|
|
1207
|
-
* @returns
|
|
1217
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1208
1218
|
*
|
|
1209
1219
|
* @public exported from `@promptbook/utils`
|
|
1210
1220
|
*/
|
|
@@ -2546,7 +2556,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
|
|
|
2546
2556
|
* Function to check if a string is valid CSV
|
|
2547
2557
|
*
|
|
2548
2558
|
* @param value The string to check
|
|
2549
|
-
* @returns
|
|
2559
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
2550
2560
|
*
|
|
2551
2561
|
* @public exported from `@promptbook/utils`
|
|
2552
2562
|
*/
|
|
@@ -2603,14 +2613,15 @@ const CsvFormatParser = {
|
|
|
2603
2613
|
`));
|
|
2604
2614
|
}
|
|
2605
2615
|
const mappedData = [];
|
|
2606
|
-
|
|
2616
|
+
const length = csv.data.length;
|
|
2617
|
+
for (let index = 0; index < length; index++) {
|
|
2607
2618
|
const row = csv.data[index];
|
|
2608
2619
|
if (row[outputParameterName]) {
|
|
2609
2620
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
2610
2621
|
}
|
|
2611
2622
|
const mappedRow = {
|
|
2612
2623
|
...row,
|
|
2613
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
2624
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
2614
2625
|
};
|
|
2615
2626
|
mappedData.push(mappedRow);
|
|
2616
2627
|
if (onProgress) {
|
|
@@ -2641,9 +2652,9 @@ const CsvFormatParser = {
|
|
|
2641
2652
|
`));
|
|
2642
2653
|
}
|
|
2643
2654
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
2644
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
2655
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
2645
2656
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
2646
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
2657
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
2647
2658
|
}));
|
|
2648
2659
|
}));
|
|
2649
2660
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -2714,12 +2725,12 @@ const TextFormatParser = {
|
|
|
2714
2725
|
async mapValues(options) {
|
|
2715
2726
|
const { value, mapCallback, onProgress } = options;
|
|
2716
2727
|
const lines = value.split('\n');
|
|
2717
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
2728
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
2718
2729
|
// TODO: [🧠] Maybe option to skip empty line
|
|
2719
2730
|
/* not await */ mapCallback({
|
|
2720
2731
|
lineContent,
|
|
2721
2732
|
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
2722
|
-
}, lineNumber)));
|
|
2733
|
+
}, lineNumber, array.length)));
|
|
2723
2734
|
return mappedLines.join('\n');
|
|
2724
2735
|
},
|
|
2725
2736
|
},
|
|
@@ -2740,7 +2751,7 @@ const TextFormatParser = {
|
|
|
2740
2751
|
* Function to check if a string is valid XML
|
|
2741
2752
|
*
|
|
2742
2753
|
* @param value
|
|
2743
|
-
* @returns
|
|
2754
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
2744
2755
|
*
|
|
2745
2756
|
* @public exported from `@promptbook/utils`
|
|
2746
2757
|
*/
|
|
@@ -2802,13 +2813,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
|
|
|
2802
2813
|
*/
|
|
2803
2814
|
|
|
2804
2815
|
/**
|
|
2805
|
-
* Maps available parameters to expected parameters
|
|
2816
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
2806
2817
|
*
|
|
2807
2818
|
* The strategy is:
|
|
2808
|
-
* 1)
|
|
2809
|
-
* 2)
|
|
2819
|
+
* 1) First, match parameters by name where both available and expected.
|
|
2820
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
2810
2821
|
*
|
|
2811
|
-
* @throws {PipelineExecutionError}
|
|
2822
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
2812
2823
|
* @private within the repository used in `createPipelineExecutor`
|
|
2813
2824
|
*/
|
|
2814
2825
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -4017,7 +4028,11 @@ async function executeAttempts(options) {
|
|
|
4017
4028
|
*/
|
|
4018
4029
|
|
|
4019
4030
|
/**
|
|
4020
|
-
*
|
|
4031
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
4032
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
4033
|
+
*
|
|
4034
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
4035
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
4021
4036
|
*
|
|
4022
4037
|
* @private internal utility of `createPipelineExecutor`
|
|
4023
4038
|
*/
|
|
@@ -4082,15 +4097,11 @@ async function executeFormatSubvalues(options) {
|
|
|
4082
4097
|
settings: formatSettings,
|
|
4083
4098
|
onProgress(partialResultString) {
|
|
4084
4099
|
return onProgress(Object.freeze({
|
|
4085
|
-
[task.resultingParameterName]:
|
|
4086
|
-
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4087
|
-
partialResultString,
|
|
4100
|
+
[task.resultingParameterName]: partialResultString,
|
|
4088
4101
|
}));
|
|
4089
4102
|
},
|
|
4090
|
-
async mapCallback(subparameters, index) {
|
|
4103
|
+
async mapCallback(subparameters, index, length) {
|
|
4091
4104
|
let mappedParameters;
|
|
4092
|
-
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
4093
|
-
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4094
4105
|
try {
|
|
4095
4106
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4096
4107
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -4101,32 +4112,52 @@ async function executeFormatSubvalues(options) {
|
|
|
4101
4112
|
if (!(error instanceof PipelineExecutionError)) {
|
|
4102
4113
|
throw error;
|
|
4103
4114
|
}
|
|
4104
|
-
|
|
4105
|
-
|
|
4115
|
+
const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
|
|
4116
|
+
${error.message}
|
|
4106
4117
|
|
|
4107
|
-
|
|
4108
|
-
|
|
4118
|
+
This is error in FOREACH command when mapping data
|
|
4119
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
4109
4120
|
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4121
|
+
${block(pipelineIdentification)}
|
|
4122
|
+
Subparameter index: ${index}
|
|
4123
|
+
`));
|
|
4124
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
4125
|
+
console.error(highLevelError);
|
|
4126
|
+
return '~';
|
|
4127
|
+
}
|
|
4128
|
+
throw highLevelError;
|
|
4113
4129
|
}
|
|
4114
4130
|
const allSubparameters = {
|
|
4115
4131
|
...parameters,
|
|
4116
4132
|
...mappedParameters,
|
|
4117
4133
|
};
|
|
4118
|
-
// 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
|
|
4119
4134
|
Object.freeze(allSubparameters);
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4135
|
+
try {
|
|
4136
|
+
const subresultString = await executeAttempts({
|
|
4137
|
+
...options,
|
|
4138
|
+
priority: priority + index,
|
|
4139
|
+
parameters: allSubparameters,
|
|
4140
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
4141
|
+
${block(pipelineIdentification)}
|
|
4142
|
+
Subparameter index: ${index}
|
|
4143
|
+
`),
|
|
4144
|
+
});
|
|
4145
|
+
return subresultString;
|
|
4146
|
+
}
|
|
4147
|
+
catch (error) {
|
|
4148
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
4149
|
+
console.error(spaceTrim((block) => `
|
|
4150
|
+
Error in FOREACH command:
|
|
4151
|
+
|
|
4152
|
+
${block(pipelineIdentification)}
|
|
4153
|
+
|
|
4154
|
+
${block(pipelineIdentification)}
|
|
4155
|
+
Subparameter index: ${index}
|
|
4156
|
+
`));
|
|
4157
|
+
return '~';
|
|
4158
|
+
}
|
|
4159
|
+
throw error;
|
|
4160
|
+
}
|
|
4130
4161
|
},
|
|
4131
4162
|
});
|
|
4132
4163
|
return resultString;
|
|
@@ -4261,7 +4292,11 @@ async function getKnowledgeForTask(options) {
|
|
|
4261
4292
|
*/
|
|
4262
4293
|
|
|
4263
4294
|
/**
|
|
4264
|
-
*
|
|
4295
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
4296
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
4297
|
+
*
|
|
4298
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
4299
|
+
* @returns An object containing all reserved parameters for the task.
|
|
4265
4300
|
*
|
|
4266
4301
|
* @private internal utility of `createPipelineExecutor`
|
|
4267
4302
|
*/
|
|
@@ -4294,7 +4329,10 @@ async function getReservedParametersForTask(options) {
|
|
|
4294
4329
|
}
|
|
4295
4330
|
|
|
4296
4331
|
/**
|
|
4297
|
-
*
|
|
4332
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
4333
|
+
*
|
|
4334
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
4335
|
+
* @returns The output parameters produced by the task.
|
|
4298
4336
|
*
|
|
4299
4337
|
* @private internal utility of `createPipelineExecutor`
|
|
4300
4338
|
*/
|
|
@@ -4428,9 +4466,12 @@ function filterJustOutputParameters(options) {
|
|
|
4428
4466
|
}
|
|
4429
4467
|
|
|
4430
4468
|
/**
|
|
4431
|
-
*
|
|
4469
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
4470
|
+
*
|
|
4471
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
4432
4472
|
*
|
|
4433
|
-
*
|
|
4473
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
4474
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
4434
4475
|
*
|
|
4435
4476
|
* @private internal utility of `createPipelineExecutor`
|
|
4436
4477
|
*/
|
|
@@ -5031,11 +5072,11 @@ function normalizeTo_snake_case(text) {
|
|
|
5031
5072
|
}
|
|
5032
5073
|
|
|
5033
5074
|
/**
|
|
5034
|
-
*
|
|
5075
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
5035
5076
|
*
|
|
5036
5077
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
5037
5078
|
*
|
|
5038
|
-
* @private internal utility, exported are only
|
|
5079
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
5039
5080
|
*/
|
|
5040
5081
|
class $Register {
|
|
5041
5082
|
constructor(registerName) {
|
|
@@ -5079,10 +5120,10 @@ class $Register {
|
|
|
5079
5120
|
}
|
|
5080
5121
|
|
|
5081
5122
|
/**
|
|
5082
|
-
*
|
|
5123
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
5083
5124
|
*
|
|
5084
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
5085
|
-
* @singleton Only one instance of each register is created per build, but
|
|
5125
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
5126
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
5086
5127
|
* @public exported from `@promptbook/core`
|
|
5087
5128
|
*/
|
|
5088
5129
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -6621,11 +6662,12 @@ function removeQuotes(text) {
|
|
|
6621
6662
|
}
|
|
6622
6663
|
|
|
6623
6664
|
/**
|
|
6624
|
-
* Function `validateParameterName` will
|
|
6665
|
+
* Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
|
|
6666
|
+
* It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
|
|
6625
6667
|
*
|
|
6626
|
-
* @param parameterName
|
|
6627
|
-
* @returns
|
|
6628
|
-
* @throws {ParseError}
|
|
6668
|
+
* @param parameterName The parameter name to validate and normalize.
|
|
6669
|
+
* @returns The validated and normalized parameter name.
|
|
6670
|
+
* @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
|
|
6629
6671
|
* @private within the repository
|
|
6630
6672
|
*/
|
|
6631
6673
|
function validateParameterName(parameterName) {
|
|
@@ -7799,10 +7841,10 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
7799
7841
|
}
|
|
7800
7842
|
|
|
7801
7843
|
/**
|
|
7802
|
-
*
|
|
7844
|
+
* Checks if the given value is a valid JavaScript identifier name.
|
|
7803
7845
|
*
|
|
7804
|
-
* @param javascriptName
|
|
7805
|
-
* @returns
|
|
7846
|
+
* @param javascriptName The value to check for JavaScript identifier validity.
|
|
7847
|
+
* @returns `true` if the value is a valid JavaScript name, false otherwise.
|
|
7806
7848
|
* @public exported from `@promptbook/utils`
|
|
7807
7849
|
*/
|
|
7808
7850
|
function isValidJavascriptName(javascriptName) {
|