@promptbook/pdf 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 +94 -53
- 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 +94 -53
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -102,6 +102,12 @@ const DEFAULT_BOOK_TITLE = `โจ Untitled Book`;
|
|
|
102
102
|
* @public exported from `@promptbook/core`
|
|
103
103
|
*/
|
|
104
104
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
105
|
+
/**
|
|
106
|
+
* @@@
|
|
107
|
+
*
|
|
108
|
+
* @public exported from `@promptbook/core`
|
|
109
|
+
*/
|
|
110
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
105
111
|
// <- TODO: [๐ง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
106
112
|
/**
|
|
107
113
|
* The maximum number of iterations for a loops
|
|
@@ -181,7 +187,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
181
187
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
182
188
|
// <- TODO: [๐งโโ๏ธ]
|
|
183
189
|
/**
|
|
184
|
-
*
|
|
190
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
185
191
|
*
|
|
186
192
|
* @public exported from `@promptbook/core`
|
|
187
193
|
*/
|
|
@@ -192,19 +198,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
192
198
|
skipEmptyLines: true,
|
|
193
199
|
});
|
|
194
200
|
/**
|
|
195
|
-
*
|
|
201
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
196
202
|
*
|
|
197
203
|
* @public exported from `@promptbook/core`
|
|
198
204
|
*/
|
|
199
205
|
let DEFAULT_IS_VERBOSE = false;
|
|
200
206
|
/**
|
|
201
|
-
*
|
|
207
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
202
208
|
*
|
|
203
209
|
* @public exported from `@promptbook/core`
|
|
204
210
|
*/
|
|
205
211
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
206
212
|
/**
|
|
207
|
-
*
|
|
213
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
208
214
|
*
|
|
209
215
|
* @private within the repository
|
|
210
216
|
*/
|
|
@@ -945,7 +951,7 @@ function assertsError(whatWasThrown) {
|
|
|
945
951
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
946
952
|
*
|
|
947
953
|
* @param value The string to check
|
|
948
|
-
* @returns
|
|
954
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
949
955
|
*
|
|
950
956
|
* @public exported from `@promptbook/utils`
|
|
951
957
|
*/
|
|
@@ -1356,8 +1362,12 @@ function checkSerializableAsJson(options) {
|
|
|
1356
1362
|
*/
|
|
1357
1363
|
|
|
1358
1364
|
/**
|
|
1359
|
-
*
|
|
1365
|
+
* Creates a deep clone of the given object
|
|
1366
|
+
*
|
|
1367
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
1360
1368
|
*
|
|
1369
|
+
* @param objectValue The object to clone.
|
|
1370
|
+
* @returns A deep, writable clone of the input object.
|
|
1361
1371
|
* @public exported from `@promptbook/utils`
|
|
1362
1372
|
*/
|
|
1363
1373
|
function deepClone(objectValue) {
|
|
@@ -3160,11 +3170,11 @@ function normalizeTo_snake_case(text) {
|
|
|
3160
3170
|
}
|
|
3161
3171
|
|
|
3162
3172
|
/**
|
|
3163
|
-
*
|
|
3173
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
3164
3174
|
*
|
|
3165
3175
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
3166
3176
|
*
|
|
3167
|
-
* @private internal utility, exported are only
|
|
3177
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
3168
3178
|
*/
|
|
3169
3179
|
class $Register {
|
|
3170
3180
|
constructor(registerName) {
|
|
@@ -3208,10 +3218,10 @@ class $Register {
|
|
|
3208
3218
|
}
|
|
3209
3219
|
|
|
3210
3220
|
/**
|
|
3211
|
-
*
|
|
3221
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
3212
3222
|
*
|
|
3213
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
3214
|
-
* @singleton Only one instance of each register is created per build, but
|
|
3223
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
3224
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
3215
3225
|
* @public exported from `@promptbook/core`
|
|
3216
3226
|
*/
|
|
3217
3227
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -4112,7 +4122,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
|
|
|
4112
4122
|
* Function to check if a string is valid CSV
|
|
4113
4123
|
*
|
|
4114
4124
|
* @param value The string to check
|
|
4115
|
-
* @returns
|
|
4125
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
4116
4126
|
*
|
|
4117
4127
|
* @public exported from `@promptbook/utils`
|
|
4118
4128
|
*/
|
|
@@ -4169,14 +4179,15 @@ const CsvFormatParser = {
|
|
|
4169
4179
|
`));
|
|
4170
4180
|
}
|
|
4171
4181
|
const mappedData = [];
|
|
4172
|
-
|
|
4182
|
+
const length = csv.data.length;
|
|
4183
|
+
for (let index = 0; index < length; index++) {
|
|
4173
4184
|
const row = csv.data[index];
|
|
4174
4185
|
if (row[outputParameterName]) {
|
|
4175
4186
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4176
4187
|
}
|
|
4177
4188
|
const mappedRow = {
|
|
4178
4189
|
...row,
|
|
4179
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
4190
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
4180
4191
|
};
|
|
4181
4192
|
mappedData.push(mappedRow);
|
|
4182
4193
|
if (onProgress) {
|
|
@@ -4207,9 +4218,9 @@ const CsvFormatParser = {
|
|
|
4207
4218
|
`));
|
|
4208
4219
|
}
|
|
4209
4220
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
4210
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
4221
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
4211
4222
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
4212
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
4223
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
4213
4224
|
}));
|
|
4214
4225
|
}));
|
|
4215
4226
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -4280,12 +4291,12 @@ const TextFormatParser = {
|
|
|
4280
4291
|
async mapValues(options) {
|
|
4281
4292
|
const { value, mapCallback, onProgress } = options;
|
|
4282
4293
|
const lines = value.split('\n');
|
|
4283
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4294
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
4284
4295
|
// TODO: [๐ง ] Maybe option to skip empty line
|
|
4285
4296
|
/* not await */ mapCallback({
|
|
4286
4297
|
lineContent,
|
|
4287
4298
|
// TODO: [๐ง ] Maybe also put here `lineNumber`
|
|
4288
|
-
}, lineNumber)));
|
|
4299
|
+
}, lineNumber, array.length)));
|
|
4289
4300
|
return mappedLines.join('\n');
|
|
4290
4301
|
},
|
|
4291
4302
|
},
|
|
@@ -4306,7 +4317,7 @@ const TextFormatParser = {
|
|
|
4306
4317
|
* Function to check if a string is valid XML
|
|
4307
4318
|
*
|
|
4308
4319
|
* @param value
|
|
4309
|
-
* @returns
|
|
4320
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
4310
4321
|
*
|
|
4311
4322
|
* @public exported from `@promptbook/utils`
|
|
4312
4323
|
*/
|
|
@@ -4368,13 +4379,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
|
|
|
4368
4379
|
*/
|
|
4369
4380
|
|
|
4370
4381
|
/**
|
|
4371
|
-
* Maps available parameters to expected parameters
|
|
4382
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
4372
4383
|
*
|
|
4373
4384
|
* The strategy is:
|
|
4374
|
-
* 1)
|
|
4375
|
-
* 2)
|
|
4385
|
+
* 1) First, match parameters by name where both available and expected.
|
|
4386
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
4376
4387
|
*
|
|
4377
|
-
* @throws {PipelineExecutionError}
|
|
4388
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
4378
4389
|
* @private within the repository used in `createPipelineExecutor`
|
|
4379
4390
|
*/
|
|
4380
4391
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -5094,7 +5105,11 @@ async function executeAttempts(options) {
|
|
|
5094
5105
|
*/
|
|
5095
5106
|
|
|
5096
5107
|
/**
|
|
5097
|
-
*
|
|
5108
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
5109
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
5110
|
+
*
|
|
5111
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
5112
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
5098
5113
|
*
|
|
5099
5114
|
* @private internal utility of `createPipelineExecutor`
|
|
5100
5115
|
*/
|
|
@@ -5159,15 +5174,11 @@ async function executeFormatSubvalues(options) {
|
|
|
5159
5174
|
settings: formatSettings,
|
|
5160
5175
|
onProgress(partialResultString) {
|
|
5161
5176
|
return onProgress(Object.freeze({
|
|
5162
|
-
[task.resultingParameterName]:
|
|
5163
|
-
// <- Note: [๐ฉโ๐ฉโ๐ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5164
|
-
partialResultString,
|
|
5177
|
+
[task.resultingParameterName]: partialResultString,
|
|
5165
5178
|
}));
|
|
5166
5179
|
},
|
|
5167
|
-
async mapCallback(subparameters, index) {
|
|
5180
|
+
async mapCallback(subparameters, index, length) {
|
|
5168
5181
|
let mappedParameters;
|
|
5169
|
-
// TODO: [๐คนโโ๏ธ][๐ช] Limit to N concurrent executions
|
|
5170
|
-
// TODO: When done [๐] Report progress also for each subvalue here
|
|
5171
5182
|
try {
|
|
5172
5183
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
5173
5184
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -5178,32 +5189,52 @@ async function executeFormatSubvalues(options) {
|
|
|
5178
5189
|
if (!(error instanceof PipelineExecutionError)) {
|
|
5179
5190
|
throw error;
|
|
5180
5191
|
}
|
|
5181
|
-
|
|
5182
|
-
|
|
5192
|
+
const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
|
|
5193
|
+
${error.message}
|
|
5183
5194
|
|
|
5184
|
-
|
|
5185
|
-
|
|
5195
|
+
This is error in FOREACH command when mapping data
|
|
5196
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
5186
5197
|
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5198
|
+
${block(pipelineIdentification)}
|
|
5199
|
+
Subparameter index: ${index}
|
|
5200
|
+
`));
|
|
5201
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5202
|
+
console.error(highLevelError);
|
|
5203
|
+
return '~';
|
|
5204
|
+
}
|
|
5205
|
+
throw highLevelError;
|
|
5190
5206
|
}
|
|
5191
5207
|
const allSubparameters = {
|
|
5192
5208
|
...parameters,
|
|
5193
5209
|
...mappedParameters,
|
|
5194
5210
|
};
|
|
5195
|
-
// 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
|
|
5196
5211
|
Object.freeze(allSubparameters);
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5212
|
+
try {
|
|
5213
|
+
const subresultString = await executeAttempts({
|
|
5214
|
+
...options,
|
|
5215
|
+
priority: priority + index,
|
|
5216
|
+
parameters: allSubparameters,
|
|
5217
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
5218
|
+
${block(pipelineIdentification)}
|
|
5219
|
+
Subparameter index: ${index}
|
|
5220
|
+
`),
|
|
5221
|
+
});
|
|
5222
|
+
return subresultString;
|
|
5223
|
+
}
|
|
5224
|
+
catch (error) {
|
|
5225
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5226
|
+
console.error(spaceTrim((block) => `
|
|
5227
|
+
Error in FOREACH command:
|
|
5228
|
+
|
|
5229
|
+
${block(pipelineIdentification)}
|
|
5230
|
+
|
|
5231
|
+
${block(pipelineIdentification)}
|
|
5232
|
+
Subparameter index: ${index}
|
|
5233
|
+
`));
|
|
5234
|
+
return '~';
|
|
5235
|
+
}
|
|
5236
|
+
throw error;
|
|
5237
|
+
}
|
|
5207
5238
|
},
|
|
5208
5239
|
});
|
|
5209
5240
|
return resultString;
|
|
@@ -5338,7 +5369,11 @@ async function getKnowledgeForTask(options) {
|
|
|
5338
5369
|
*/
|
|
5339
5370
|
|
|
5340
5371
|
/**
|
|
5341
|
-
*
|
|
5372
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
5373
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
5374
|
+
*
|
|
5375
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
5376
|
+
* @returns An object containing all reserved parameters for the task.
|
|
5342
5377
|
*
|
|
5343
5378
|
* @private internal utility of `createPipelineExecutor`
|
|
5344
5379
|
*/
|
|
@@ -5371,7 +5406,10 @@ async function getReservedParametersForTask(options) {
|
|
|
5371
5406
|
}
|
|
5372
5407
|
|
|
5373
5408
|
/**
|
|
5374
|
-
*
|
|
5409
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
5410
|
+
*
|
|
5411
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
5412
|
+
* @returns The output parameters produced by the task.
|
|
5375
5413
|
*
|
|
5376
5414
|
* @private internal utility of `createPipelineExecutor`
|
|
5377
5415
|
*/
|
|
@@ -5505,9 +5543,12 @@ function filterJustOutputParameters(options) {
|
|
|
5505
5543
|
}
|
|
5506
5544
|
|
|
5507
5545
|
/**
|
|
5508
|
-
*
|
|
5546
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
5547
|
+
*
|
|
5548
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
5509
5549
|
*
|
|
5510
|
-
*
|
|
5550
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
5551
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
5511
5552
|
*
|
|
5512
5553
|
* @private internal utility of `createPipelineExecutor`
|
|
5513
5554
|
*/
|