@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.92.0-
|
|
3
|
+
"version": "0.92.0-23",
|
|
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/node.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.92.0-
|
|
54
|
+
"@promptbook/core": "0.92.0-23"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* @generated
|
|
47
47
|
* @see https://github.com/webgptorg/promptbook
|
|
48
48
|
*/
|
|
49
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
49
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
|
|
50
50
|
/**
|
|
51
51
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
52
52
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -117,6 +117,12 @@
|
|
|
117
117
|
* @public exported from `@promptbook/core`
|
|
118
118
|
*/
|
|
119
119
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
120
|
+
/**
|
|
121
|
+
* @@@
|
|
122
|
+
*
|
|
123
|
+
* @public exported from `@promptbook/core`
|
|
124
|
+
*/
|
|
125
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
120
126
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
121
127
|
/**
|
|
122
128
|
* The maximum number of iterations for a loops
|
|
@@ -211,7 +217,7 @@
|
|
|
211
217
|
const DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = `index`;
|
|
212
218
|
// <- TODO: [🧜♂️]
|
|
213
219
|
/**
|
|
214
|
-
*
|
|
220
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
215
221
|
*
|
|
216
222
|
* @public exported from `@promptbook/core`
|
|
217
223
|
*/
|
|
@@ -222,19 +228,19 @@
|
|
|
222
228
|
skipEmptyLines: true,
|
|
223
229
|
});
|
|
224
230
|
/**
|
|
225
|
-
*
|
|
231
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
226
232
|
*
|
|
227
233
|
* @public exported from `@promptbook/core`
|
|
228
234
|
*/
|
|
229
235
|
let DEFAULT_IS_VERBOSE = false;
|
|
230
236
|
/**
|
|
231
|
-
*
|
|
237
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
232
238
|
*
|
|
233
239
|
* @public exported from `@promptbook/core`
|
|
234
240
|
*/
|
|
235
241
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
236
242
|
/**
|
|
237
|
-
*
|
|
243
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
238
244
|
*
|
|
239
245
|
* @private within the repository
|
|
240
246
|
*/
|
|
@@ -580,8 +586,12 @@
|
|
|
580
586
|
*/
|
|
581
587
|
|
|
582
588
|
/**
|
|
583
|
-
*
|
|
589
|
+
* Creates a deep clone of the given object
|
|
590
|
+
*
|
|
591
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
584
592
|
*
|
|
593
|
+
* @param objectValue The object to clone.
|
|
594
|
+
* @returns A deep, writable clone of the input object.
|
|
585
595
|
* @public exported from `@promptbook/utils`
|
|
586
596
|
*/
|
|
587
597
|
function deepClone(objectValue) {
|
|
@@ -1220,7 +1230,7 @@
|
|
|
1220
1230
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1221
1231
|
*
|
|
1222
1232
|
* @param value The string to check
|
|
1223
|
-
* @returns
|
|
1233
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1224
1234
|
*
|
|
1225
1235
|
* @public exported from `@promptbook/utils`
|
|
1226
1236
|
*/
|
|
@@ -2562,7 +2572,7 @@
|
|
|
2562
2572
|
* Function to check if a string is valid CSV
|
|
2563
2573
|
*
|
|
2564
2574
|
* @param value The string to check
|
|
2565
|
-
* @returns
|
|
2575
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
2566
2576
|
*
|
|
2567
2577
|
* @public exported from `@promptbook/utils`
|
|
2568
2578
|
*/
|
|
@@ -2619,14 +2629,15 @@
|
|
|
2619
2629
|
`));
|
|
2620
2630
|
}
|
|
2621
2631
|
const mappedData = [];
|
|
2622
|
-
|
|
2632
|
+
const length = csv.data.length;
|
|
2633
|
+
for (let index = 0; index < length; index++) {
|
|
2623
2634
|
const row = csv.data[index];
|
|
2624
2635
|
if (row[outputParameterName]) {
|
|
2625
2636
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
2626
2637
|
}
|
|
2627
2638
|
const mappedRow = {
|
|
2628
2639
|
...row,
|
|
2629
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
2640
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
2630
2641
|
};
|
|
2631
2642
|
mappedData.push(mappedRow);
|
|
2632
2643
|
if (onProgress) {
|
|
@@ -2657,9 +2668,9 @@
|
|
|
2657
2668
|
`));
|
|
2658
2669
|
}
|
|
2659
2670
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
2660
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
2671
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
2661
2672
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
2662
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
2673
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
2663
2674
|
}));
|
|
2664
2675
|
}));
|
|
2665
2676
|
return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -2730,12 +2741,12 @@
|
|
|
2730
2741
|
async mapValues(options) {
|
|
2731
2742
|
const { value, mapCallback, onProgress } = options;
|
|
2732
2743
|
const lines = value.split('\n');
|
|
2733
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
2744
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
2734
2745
|
// TODO: [🧠] Maybe option to skip empty line
|
|
2735
2746
|
/* not await */ mapCallback({
|
|
2736
2747
|
lineContent,
|
|
2737
2748
|
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
2738
|
-
}, lineNumber)));
|
|
2749
|
+
}, lineNumber, array.length)));
|
|
2739
2750
|
return mappedLines.join('\n');
|
|
2740
2751
|
},
|
|
2741
2752
|
},
|
|
@@ -2756,7 +2767,7 @@
|
|
|
2756
2767
|
* Function to check if a string is valid XML
|
|
2757
2768
|
*
|
|
2758
2769
|
* @param value
|
|
2759
|
-
* @returns
|
|
2770
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
2760
2771
|
*
|
|
2761
2772
|
* @public exported from `@promptbook/utils`
|
|
2762
2773
|
*/
|
|
@@ -2818,13 +2829,13 @@
|
|
|
2818
2829
|
*/
|
|
2819
2830
|
|
|
2820
2831
|
/**
|
|
2821
|
-
* Maps available parameters to expected parameters
|
|
2832
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
2822
2833
|
*
|
|
2823
2834
|
* The strategy is:
|
|
2824
|
-
* 1)
|
|
2825
|
-
* 2)
|
|
2835
|
+
* 1) First, match parameters by name where both available and expected.
|
|
2836
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
2826
2837
|
*
|
|
2827
|
-
* @throws {PipelineExecutionError}
|
|
2838
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
2828
2839
|
* @private within the repository used in `createPipelineExecutor`
|
|
2829
2840
|
*/
|
|
2830
2841
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -4033,7 +4044,11 @@
|
|
|
4033
4044
|
*/
|
|
4034
4045
|
|
|
4035
4046
|
/**
|
|
4036
|
-
*
|
|
4047
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
4048
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
4049
|
+
*
|
|
4050
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
4051
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
4037
4052
|
*
|
|
4038
4053
|
* @private internal utility of `createPipelineExecutor`
|
|
4039
4054
|
*/
|
|
@@ -4098,15 +4113,11 @@
|
|
|
4098
4113
|
settings: formatSettings,
|
|
4099
4114
|
onProgress(partialResultString) {
|
|
4100
4115
|
return onProgress(Object.freeze({
|
|
4101
|
-
[task.resultingParameterName]:
|
|
4102
|
-
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4103
|
-
partialResultString,
|
|
4116
|
+
[task.resultingParameterName]: partialResultString,
|
|
4104
4117
|
}));
|
|
4105
4118
|
},
|
|
4106
|
-
async mapCallback(subparameters, index) {
|
|
4119
|
+
async mapCallback(subparameters, index, length) {
|
|
4107
4120
|
let mappedParameters;
|
|
4108
|
-
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
4109
|
-
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
4110
4121
|
try {
|
|
4111
4122
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
4112
4123
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -4117,32 +4128,52 @@
|
|
|
4117
4128
|
if (!(error instanceof PipelineExecutionError)) {
|
|
4118
4129
|
throw error;
|
|
4119
4130
|
}
|
|
4120
|
-
|
|
4121
|
-
|
|
4131
|
+
const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
4132
|
+
${error.message}
|
|
4122
4133
|
|
|
4123
|
-
|
|
4124
|
-
|
|
4134
|
+
This is error in FOREACH command when mapping data
|
|
4135
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
4125
4136
|
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4137
|
+
${block(pipelineIdentification)}
|
|
4138
|
+
Subparameter index: ${index}
|
|
4139
|
+
`));
|
|
4140
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
4141
|
+
console.error(highLevelError);
|
|
4142
|
+
return '~';
|
|
4143
|
+
}
|
|
4144
|
+
throw highLevelError;
|
|
4129
4145
|
}
|
|
4130
4146
|
const allSubparameters = {
|
|
4131
4147
|
...parameters,
|
|
4132
4148
|
...mappedParameters,
|
|
4133
4149
|
};
|
|
4134
|
-
// 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
|
|
4135
4150
|
Object.freeze(allSubparameters);
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4151
|
+
try {
|
|
4152
|
+
const subresultString = await executeAttempts({
|
|
4153
|
+
...options,
|
|
4154
|
+
priority: priority + index,
|
|
4155
|
+
parameters: allSubparameters,
|
|
4156
|
+
pipelineIdentification: spaceTrim__default["default"]((block) => `
|
|
4157
|
+
${block(pipelineIdentification)}
|
|
4158
|
+
Subparameter index: ${index}
|
|
4159
|
+
`),
|
|
4160
|
+
});
|
|
4161
|
+
return subresultString;
|
|
4162
|
+
}
|
|
4163
|
+
catch (error) {
|
|
4164
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
4165
|
+
console.error(spaceTrim__default["default"]((block) => `
|
|
4166
|
+
Error in FOREACH command:
|
|
4167
|
+
|
|
4168
|
+
${block(pipelineIdentification)}
|
|
4169
|
+
|
|
4170
|
+
${block(pipelineIdentification)}
|
|
4171
|
+
Subparameter index: ${index}
|
|
4172
|
+
`));
|
|
4173
|
+
return '~';
|
|
4174
|
+
}
|
|
4175
|
+
throw error;
|
|
4176
|
+
}
|
|
4146
4177
|
},
|
|
4147
4178
|
});
|
|
4148
4179
|
return resultString;
|
|
@@ -4277,7 +4308,11 @@
|
|
|
4277
4308
|
*/
|
|
4278
4309
|
|
|
4279
4310
|
/**
|
|
4280
|
-
*
|
|
4311
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
4312
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
4313
|
+
*
|
|
4314
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
4315
|
+
* @returns An object containing all reserved parameters for the task.
|
|
4281
4316
|
*
|
|
4282
4317
|
* @private internal utility of `createPipelineExecutor`
|
|
4283
4318
|
*/
|
|
@@ -4310,7 +4345,10 @@
|
|
|
4310
4345
|
}
|
|
4311
4346
|
|
|
4312
4347
|
/**
|
|
4313
|
-
*
|
|
4348
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
4349
|
+
*
|
|
4350
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
4351
|
+
* @returns The output parameters produced by the task.
|
|
4314
4352
|
*
|
|
4315
4353
|
* @private internal utility of `createPipelineExecutor`
|
|
4316
4354
|
*/
|
|
@@ -4444,9 +4482,12 @@
|
|
|
4444
4482
|
}
|
|
4445
4483
|
|
|
4446
4484
|
/**
|
|
4447
|
-
*
|
|
4485
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
4486
|
+
*
|
|
4487
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
4448
4488
|
*
|
|
4449
|
-
*
|
|
4489
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
4490
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
4450
4491
|
*
|
|
4451
4492
|
* @private internal utility of `createPipelineExecutor`
|
|
4452
4493
|
*/
|
|
@@ -5047,11 +5088,11 @@
|
|
|
5047
5088
|
}
|
|
5048
5089
|
|
|
5049
5090
|
/**
|
|
5050
|
-
*
|
|
5091
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
5051
5092
|
*
|
|
5052
5093
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
5053
5094
|
*
|
|
5054
|
-
* @private internal utility, exported are only
|
|
5095
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
5055
5096
|
*/
|
|
5056
5097
|
class $Register {
|
|
5057
5098
|
constructor(registerName) {
|
|
@@ -5095,10 +5136,10 @@
|
|
|
5095
5136
|
}
|
|
5096
5137
|
|
|
5097
5138
|
/**
|
|
5098
|
-
*
|
|
5139
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
5099
5140
|
*
|
|
5100
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
5101
|
-
* @singleton Only one instance of each register is created per build, but
|
|
5141
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
5142
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
5102
5143
|
* @public exported from `@promptbook/core`
|
|
5103
5144
|
*/
|
|
5104
5145
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -6637,11 +6678,12 @@
|
|
|
6637
6678
|
}
|
|
6638
6679
|
|
|
6639
6680
|
/**
|
|
6640
|
-
* Function `validateParameterName` will
|
|
6681
|
+
* Function `validateParameterName` will normalize and validate a parameter name for use in pipelines.
|
|
6682
|
+
* It removes diacritics, emojis, and quotes, normalizes to camelCase, and checks for reserved names and invalid characters.
|
|
6641
6683
|
*
|
|
6642
|
-
* @param parameterName
|
|
6643
|
-
* @returns
|
|
6644
|
-
* @throws {ParseError}
|
|
6684
|
+
* @param parameterName The parameter name to validate and normalize.
|
|
6685
|
+
* @returns The validated and normalized parameter name.
|
|
6686
|
+
* @throws {ParseError} If the parameter name is empty, reserved, or contains invalid characters.
|
|
6645
6687
|
* @private within the repository
|
|
6646
6688
|
*/
|
|
6647
6689
|
function validateParameterName(parameterName) {
|
|
@@ -7815,10 +7857,10 @@
|
|
|
7815
7857
|
}
|
|
7816
7858
|
|
|
7817
7859
|
/**
|
|
7818
|
-
*
|
|
7860
|
+
* Checks if the given value is a valid JavaScript identifier name.
|
|
7819
7861
|
*
|
|
7820
|
-
* @param javascriptName
|
|
7821
|
-
* @returns
|
|
7862
|
+
* @param javascriptName The value to check for JavaScript identifier validity.
|
|
7863
|
+
* @returns `true` if the value is a valid JavaScript name, false otherwise.
|
|
7822
7864
|
* @public exported from `@promptbook/utils`
|
|
7823
7865
|
*/
|
|
7824
7866
|
function isValidJavascriptName(javascriptName) {
|