@promptbook/legacy-documents 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
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -104,6 +104,12 @@ const DEFAULT_BOOK_TITLE = `โจ Untitled Book`;
|
|
|
104
104
|
* @public exported from `@promptbook/core`
|
|
105
105
|
*/
|
|
106
106
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
107
|
+
/**
|
|
108
|
+
* @@@
|
|
109
|
+
*
|
|
110
|
+
* @public exported from `@promptbook/core`
|
|
111
|
+
*/
|
|
112
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
107
113
|
// <- TODO: [๐ง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
108
114
|
/**
|
|
109
115
|
* The maximum number of iterations for a loops
|
|
@@ -183,7 +189,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
183
189
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
184
190
|
// <- TODO: [๐งโโ๏ธ]
|
|
185
191
|
/**
|
|
186
|
-
*
|
|
192
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
187
193
|
*
|
|
188
194
|
* @public exported from `@promptbook/core`
|
|
189
195
|
*/
|
|
@@ -194,19 +200,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
194
200
|
skipEmptyLines: true,
|
|
195
201
|
});
|
|
196
202
|
/**
|
|
197
|
-
*
|
|
203
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
198
204
|
*
|
|
199
205
|
* @public exported from `@promptbook/core`
|
|
200
206
|
*/
|
|
201
207
|
let DEFAULT_IS_VERBOSE = false;
|
|
202
208
|
/**
|
|
203
|
-
*
|
|
209
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
204
210
|
*
|
|
205
211
|
* @public exported from `@promptbook/core`
|
|
206
212
|
*/
|
|
207
213
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
208
214
|
/**
|
|
209
|
-
*
|
|
215
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
210
216
|
*
|
|
211
217
|
* @private within the repository
|
|
212
218
|
*/
|
|
@@ -1124,7 +1130,7 @@ function assertsError(whatWasThrown) {
|
|
|
1124
1130
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1125
1131
|
*
|
|
1126
1132
|
* @param value The string to check
|
|
1127
|
-
* @returns
|
|
1133
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1128
1134
|
*
|
|
1129
1135
|
* @public exported from `@promptbook/utils`
|
|
1130
1136
|
*/
|
|
@@ -1535,8 +1541,12 @@ function checkSerializableAsJson(options) {
|
|
|
1535
1541
|
*/
|
|
1536
1542
|
|
|
1537
1543
|
/**
|
|
1538
|
-
*
|
|
1544
|
+
* Creates a deep clone of the given object
|
|
1545
|
+
*
|
|
1546
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
1539
1547
|
*
|
|
1548
|
+
* @param objectValue The object to clone.
|
|
1549
|
+
* @returns A deep, writable clone of the input object.
|
|
1540
1550
|
* @public exported from `@promptbook/utils`
|
|
1541
1551
|
*/
|
|
1542
1552
|
function deepClone(objectValue) {
|
|
@@ -3321,11 +3331,11 @@ function normalizeTo_snake_case(text) {
|
|
|
3321
3331
|
}
|
|
3322
3332
|
|
|
3323
3333
|
/**
|
|
3324
|
-
*
|
|
3334
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
3325
3335
|
*
|
|
3326
3336
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
3327
3337
|
*
|
|
3328
|
-
* @private internal utility, exported are only
|
|
3338
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
3329
3339
|
*/
|
|
3330
3340
|
class $Register {
|
|
3331
3341
|
constructor(registerName) {
|
|
@@ -3369,10 +3379,10 @@ class $Register {
|
|
|
3369
3379
|
}
|
|
3370
3380
|
|
|
3371
3381
|
/**
|
|
3372
|
-
*
|
|
3382
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
3373
3383
|
*
|
|
3374
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
3375
|
-
* @singleton Only one instance of each register is created per build, but
|
|
3384
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
3385
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
3376
3386
|
* @public exported from `@promptbook/core`
|
|
3377
3387
|
*/
|
|
3378
3388
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -4263,7 +4273,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
|
|
|
4263
4273
|
* Function to check if a string is valid CSV
|
|
4264
4274
|
*
|
|
4265
4275
|
* @param value The string to check
|
|
4266
|
-
* @returns
|
|
4276
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
4267
4277
|
*
|
|
4268
4278
|
* @public exported from `@promptbook/utils`
|
|
4269
4279
|
*/
|
|
@@ -4320,14 +4330,15 @@ const CsvFormatParser = {
|
|
|
4320
4330
|
`));
|
|
4321
4331
|
}
|
|
4322
4332
|
const mappedData = [];
|
|
4323
|
-
|
|
4333
|
+
const length = csv.data.length;
|
|
4334
|
+
for (let index = 0; index < length; index++) {
|
|
4324
4335
|
const row = csv.data[index];
|
|
4325
4336
|
if (row[outputParameterName]) {
|
|
4326
4337
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4327
4338
|
}
|
|
4328
4339
|
const mappedRow = {
|
|
4329
4340
|
...row,
|
|
4330
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
4341
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
4331
4342
|
};
|
|
4332
4343
|
mappedData.push(mappedRow);
|
|
4333
4344
|
if (onProgress) {
|
|
@@ -4358,9 +4369,9 @@ const CsvFormatParser = {
|
|
|
4358
4369
|
`));
|
|
4359
4370
|
}
|
|
4360
4371
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
4361
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
4372
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
4362
4373
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
4363
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
4374
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
4364
4375
|
}));
|
|
4365
4376
|
}));
|
|
4366
4377
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -4431,12 +4442,12 @@ const TextFormatParser = {
|
|
|
4431
4442
|
async mapValues(options) {
|
|
4432
4443
|
const { value, mapCallback, onProgress } = options;
|
|
4433
4444
|
const lines = value.split('\n');
|
|
4434
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4445
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
4435
4446
|
// TODO: [๐ง ] Maybe option to skip empty line
|
|
4436
4447
|
/* not await */ mapCallback({
|
|
4437
4448
|
lineContent,
|
|
4438
4449
|
// TODO: [๐ง ] Maybe also put here `lineNumber`
|
|
4439
|
-
}, lineNumber)));
|
|
4450
|
+
}, lineNumber, array.length)));
|
|
4440
4451
|
return mappedLines.join('\n');
|
|
4441
4452
|
},
|
|
4442
4453
|
},
|
|
@@ -4457,7 +4468,7 @@ const TextFormatParser = {
|
|
|
4457
4468
|
* Function to check if a string is valid XML
|
|
4458
4469
|
*
|
|
4459
4470
|
* @param value
|
|
4460
|
-
* @returns
|
|
4471
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
4461
4472
|
*
|
|
4462
4473
|
* @public exported from `@promptbook/utils`
|
|
4463
4474
|
*/
|
|
@@ -4519,13 +4530,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
|
|
|
4519
4530
|
*/
|
|
4520
4531
|
|
|
4521
4532
|
/**
|
|
4522
|
-
* Maps available parameters to expected parameters
|
|
4533
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
4523
4534
|
*
|
|
4524
4535
|
* The strategy is:
|
|
4525
|
-
* 1)
|
|
4526
|
-
* 2)
|
|
4536
|
+
* 1) First, match parameters by name where both available and expected.
|
|
4537
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
4527
4538
|
*
|
|
4528
|
-
* @throws {PipelineExecutionError}
|
|
4539
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
4529
4540
|
* @private within the repository used in `createPipelineExecutor`
|
|
4530
4541
|
*/
|
|
4531
4542
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -5245,7 +5256,11 @@ async function executeAttempts(options) {
|
|
|
5245
5256
|
*/
|
|
5246
5257
|
|
|
5247
5258
|
/**
|
|
5248
|
-
*
|
|
5259
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
5260
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
5261
|
+
*
|
|
5262
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
5263
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
5249
5264
|
*
|
|
5250
5265
|
* @private internal utility of `createPipelineExecutor`
|
|
5251
5266
|
*/
|
|
@@ -5310,15 +5325,11 @@ async function executeFormatSubvalues(options) {
|
|
|
5310
5325
|
settings: formatSettings,
|
|
5311
5326
|
onProgress(partialResultString) {
|
|
5312
5327
|
return onProgress(Object.freeze({
|
|
5313
|
-
[task.resultingParameterName]:
|
|
5314
|
-
// <- Note: [๐ฉโ๐ฉโ๐ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5315
|
-
partialResultString,
|
|
5328
|
+
[task.resultingParameterName]: partialResultString,
|
|
5316
5329
|
}));
|
|
5317
5330
|
},
|
|
5318
|
-
async mapCallback(subparameters, index) {
|
|
5331
|
+
async mapCallback(subparameters, index, length) {
|
|
5319
5332
|
let mappedParameters;
|
|
5320
|
-
// TODO: [๐คนโโ๏ธ][๐ช] Limit to N concurrent executions
|
|
5321
|
-
// TODO: When done [๐] Report progress also for each subvalue here
|
|
5322
5333
|
try {
|
|
5323
5334
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
5324
5335
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -5329,32 +5340,52 @@ async function executeFormatSubvalues(options) {
|
|
|
5329
5340
|
if (!(error instanceof PipelineExecutionError)) {
|
|
5330
5341
|
throw error;
|
|
5331
5342
|
}
|
|
5332
|
-
|
|
5333
|
-
|
|
5343
|
+
const highLevelError = new PipelineExecutionError(spaceTrim$1((block) => `
|
|
5344
|
+
${error.message}
|
|
5334
5345
|
|
|
5335
|
-
|
|
5336
|
-
|
|
5346
|
+
This is error in FOREACH command when mapping data
|
|
5347
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
5337
5348
|
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5349
|
+
${block(pipelineIdentification)}
|
|
5350
|
+
Subparameter index: ${index}
|
|
5351
|
+
`));
|
|
5352
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5353
|
+
console.error(highLevelError);
|
|
5354
|
+
return '~';
|
|
5355
|
+
}
|
|
5356
|
+
throw highLevelError;
|
|
5341
5357
|
}
|
|
5342
5358
|
const allSubparameters = {
|
|
5343
5359
|
...parameters,
|
|
5344
5360
|
...mappedParameters,
|
|
5345
5361
|
};
|
|
5346
|
-
// 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
|
|
5347
5362
|
Object.freeze(allSubparameters);
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5363
|
+
try {
|
|
5364
|
+
const subresultString = await executeAttempts({
|
|
5365
|
+
...options,
|
|
5366
|
+
priority: priority + index,
|
|
5367
|
+
parameters: allSubparameters,
|
|
5368
|
+
pipelineIdentification: spaceTrim$1((block) => `
|
|
5369
|
+
${block(pipelineIdentification)}
|
|
5370
|
+
Subparameter index: ${index}
|
|
5371
|
+
`),
|
|
5372
|
+
});
|
|
5373
|
+
return subresultString;
|
|
5374
|
+
}
|
|
5375
|
+
catch (error) {
|
|
5376
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5377
|
+
console.error(spaceTrim$1((block) => `
|
|
5378
|
+
Error in FOREACH command:
|
|
5379
|
+
|
|
5380
|
+
${block(pipelineIdentification)}
|
|
5381
|
+
|
|
5382
|
+
${block(pipelineIdentification)}
|
|
5383
|
+
Subparameter index: ${index}
|
|
5384
|
+
`));
|
|
5385
|
+
return '~';
|
|
5386
|
+
}
|
|
5387
|
+
throw error;
|
|
5388
|
+
}
|
|
5358
5389
|
},
|
|
5359
5390
|
});
|
|
5360
5391
|
return resultString;
|
|
@@ -5489,7 +5520,11 @@ async function getKnowledgeForTask(options) {
|
|
|
5489
5520
|
*/
|
|
5490
5521
|
|
|
5491
5522
|
/**
|
|
5492
|
-
*
|
|
5523
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
5524
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
5525
|
+
*
|
|
5526
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
5527
|
+
* @returns An object containing all reserved parameters for the task.
|
|
5493
5528
|
*
|
|
5494
5529
|
* @private internal utility of `createPipelineExecutor`
|
|
5495
5530
|
*/
|
|
@@ -5522,7 +5557,10 @@ async function getReservedParametersForTask(options) {
|
|
|
5522
5557
|
}
|
|
5523
5558
|
|
|
5524
5559
|
/**
|
|
5525
|
-
*
|
|
5560
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
5561
|
+
*
|
|
5562
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
5563
|
+
* @returns The output parameters produced by the task.
|
|
5526
5564
|
*
|
|
5527
5565
|
* @private internal utility of `createPipelineExecutor`
|
|
5528
5566
|
*/
|
|
@@ -5656,9 +5694,12 @@ function filterJustOutputParameters(options) {
|
|
|
5656
5694
|
}
|
|
5657
5695
|
|
|
5658
5696
|
/**
|
|
5659
|
-
*
|
|
5697
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
5698
|
+
*
|
|
5699
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
5660
5700
|
*
|
|
5661
|
-
*
|
|
5701
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
5702
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
5662
5703
|
*
|
|
5663
5704
|
* @private internal utility of `createPipelineExecutor`
|
|
5664
5705
|
*/
|