@promptbook/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/documents",
|
|
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/documents.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
|
@@ -26,7 +26,7 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
*/
|
|
@@ -1122,7 +1128,7 @@
|
|
|
1122
1128
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1123
1129
|
*
|
|
1124
1130
|
* @param value The string to check
|
|
1125
|
-
* @returns
|
|
1131
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1126
1132
|
*
|
|
1127
1133
|
* @public exported from `@promptbook/utils`
|
|
1128
1134
|
*/
|
|
@@ -1533,8 +1539,12 @@
|
|
|
1533
1539
|
*/
|
|
1534
1540
|
|
|
1535
1541
|
/**
|
|
1536
|
-
*
|
|
1542
|
+
* Creates a deep clone of the given object
|
|
1543
|
+
*
|
|
1544
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
1537
1545
|
*
|
|
1546
|
+
* @param objectValue The object to clone.
|
|
1547
|
+
* @returns A deep, writable clone of the input object.
|
|
1538
1548
|
* @public exported from `@promptbook/utils`
|
|
1539
1549
|
*/
|
|
1540
1550
|
function deepClone(objectValue) {
|
|
@@ -3319,11 +3329,11 @@
|
|
|
3319
3329
|
}
|
|
3320
3330
|
|
|
3321
3331
|
/**
|
|
3322
|
-
*
|
|
3332
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
3323
3333
|
*
|
|
3324
3334
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
3325
3335
|
*
|
|
3326
|
-
* @private internal utility, exported are only
|
|
3336
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
3327
3337
|
*/
|
|
3328
3338
|
class $Register {
|
|
3329
3339
|
constructor(registerName) {
|
|
@@ -3367,10 +3377,10 @@
|
|
|
3367
3377
|
}
|
|
3368
3378
|
|
|
3369
3379
|
/**
|
|
3370
|
-
*
|
|
3380
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
3371
3381
|
*
|
|
3372
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
3373
|
-
* @singleton Only one instance of each register is created per build, but
|
|
3382
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
3383
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
3374
3384
|
* @public exported from `@promptbook/core`
|
|
3375
3385
|
*/
|
|
3376
3386
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -4261,7 +4271,7 @@
|
|
|
4261
4271
|
* Function to check if a string is valid CSV
|
|
4262
4272
|
*
|
|
4263
4273
|
* @param value The string to check
|
|
4264
|
-
* @returns
|
|
4274
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
4265
4275
|
*
|
|
4266
4276
|
* @public exported from `@promptbook/utils`
|
|
4267
4277
|
*/
|
|
@@ -4318,14 +4328,15 @@
|
|
|
4318
4328
|
`));
|
|
4319
4329
|
}
|
|
4320
4330
|
const mappedData = [];
|
|
4321
|
-
|
|
4331
|
+
const length = csv.data.length;
|
|
4332
|
+
for (let index = 0; index < length; index++) {
|
|
4322
4333
|
const row = csv.data[index];
|
|
4323
4334
|
if (row[outputParameterName]) {
|
|
4324
4335
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4325
4336
|
}
|
|
4326
4337
|
const mappedRow = {
|
|
4327
4338
|
...row,
|
|
4328
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
4339
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
4329
4340
|
};
|
|
4330
4341
|
mappedData.push(mappedRow);
|
|
4331
4342
|
if (onProgress) {
|
|
@@ -4356,9 +4367,9 @@
|
|
|
4356
4367
|
`));
|
|
4357
4368
|
}
|
|
4358
4369
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
4359
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
4370
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
4360
4371
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
4361
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
4372
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
4362
4373
|
}));
|
|
4363
4374
|
}));
|
|
4364
4375
|
return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -4429,12 +4440,12 @@
|
|
|
4429
4440
|
async mapValues(options) {
|
|
4430
4441
|
const { value, mapCallback, onProgress } = options;
|
|
4431
4442
|
const lines = value.split('\n');
|
|
4432
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4443
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
4433
4444
|
// TODO: [๐ง ] Maybe option to skip empty line
|
|
4434
4445
|
/* not await */ mapCallback({
|
|
4435
4446
|
lineContent,
|
|
4436
4447
|
// TODO: [๐ง ] Maybe also put here `lineNumber`
|
|
4437
|
-
}, lineNumber)));
|
|
4448
|
+
}, lineNumber, array.length)));
|
|
4438
4449
|
return mappedLines.join('\n');
|
|
4439
4450
|
},
|
|
4440
4451
|
},
|
|
@@ -4455,7 +4466,7 @@
|
|
|
4455
4466
|
* Function to check if a string is valid XML
|
|
4456
4467
|
*
|
|
4457
4468
|
* @param value
|
|
4458
|
-
* @returns
|
|
4469
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
4459
4470
|
*
|
|
4460
4471
|
* @public exported from `@promptbook/utils`
|
|
4461
4472
|
*/
|
|
@@ -4517,13 +4528,13 @@
|
|
|
4517
4528
|
*/
|
|
4518
4529
|
|
|
4519
4530
|
/**
|
|
4520
|
-
* Maps available parameters to expected parameters
|
|
4531
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
4521
4532
|
*
|
|
4522
4533
|
* The strategy is:
|
|
4523
|
-
* 1)
|
|
4524
|
-
* 2)
|
|
4534
|
+
* 1) First, match parameters by name where both available and expected.
|
|
4535
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
4525
4536
|
*
|
|
4526
|
-
* @throws {PipelineExecutionError}
|
|
4537
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
4527
4538
|
* @private within the repository used in `createPipelineExecutor`
|
|
4528
4539
|
*/
|
|
4529
4540
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -5243,7 +5254,11 @@
|
|
|
5243
5254
|
*/
|
|
5244
5255
|
|
|
5245
5256
|
/**
|
|
5246
|
-
*
|
|
5257
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
5258
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
5259
|
+
*
|
|
5260
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
5261
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
5247
5262
|
*
|
|
5248
5263
|
* @private internal utility of `createPipelineExecutor`
|
|
5249
5264
|
*/
|
|
@@ -5308,15 +5323,11 @@
|
|
|
5308
5323
|
settings: formatSettings,
|
|
5309
5324
|
onProgress(partialResultString) {
|
|
5310
5325
|
return onProgress(Object.freeze({
|
|
5311
|
-
[task.resultingParameterName]:
|
|
5312
|
-
// <- Note: [๐ฉโ๐ฉโ๐ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5313
|
-
partialResultString,
|
|
5326
|
+
[task.resultingParameterName]: partialResultString,
|
|
5314
5327
|
}));
|
|
5315
5328
|
},
|
|
5316
|
-
async mapCallback(subparameters, index) {
|
|
5329
|
+
async mapCallback(subparameters, index, length) {
|
|
5317
5330
|
let mappedParameters;
|
|
5318
|
-
// TODO: [๐คนโโ๏ธ][๐ช] Limit to N concurrent executions
|
|
5319
|
-
// TODO: When done [๐] Report progress also for each subvalue here
|
|
5320
5331
|
try {
|
|
5321
5332
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
5322
5333
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -5327,32 +5338,52 @@
|
|
|
5327
5338
|
if (!(error instanceof PipelineExecutionError)) {
|
|
5328
5339
|
throw error;
|
|
5329
5340
|
}
|
|
5330
|
-
|
|
5331
|
-
|
|
5341
|
+
const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
5342
|
+
${error.message}
|
|
5332
5343
|
|
|
5333
|
-
|
|
5334
|
-
|
|
5344
|
+
This is error in FOREACH command when mapping data
|
|
5345
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
5335
5346
|
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5347
|
+
${block(pipelineIdentification)}
|
|
5348
|
+
Subparameter index: ${index}
|
|
5349
|
+
`));
|
|
5350
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5351
|
+
console.error(highLevelError);
|
|
5352
|
+
return '~';
|
|
5353
|
+
}
|
|
5354
|
+
throw highLevelError;
|
|
5339
5355
|
}
|
|
5340
5356
|
const allSubparameters = {
|
|
5341
5357
|
...parameters,
|
|
5342
5358
|
...mappedParameters,
|
|
5343
5359
|
};
|
|
5344
|
-
// 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
|
|
5345
5360
|
Object.freeze(allSubparameters);
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5361
|
+
try {
|
|
5362
|
+
const subresultString = await executeAttempts({
|
|
5363
|
+
...options,
|
|
5364
|
+
priority: priority + index,
|
|
5365
|
+
parameters: allSubparameters,
|
|
5366
|
+
pipelineIdentification: spaceTrim__default["default"]((block) => `
|
|
5367
|
+
${block(pipelineIdentification)}
|
|
5368
|
+
Subparameter index: ${index}
|
|
5369
|
+
`),
|
|
5370
|
+
});
|
|
5371
|
+
return subresultString;
|
|
5372
|
+
}
|
|
5373
|
+
catch (error) {
|
|
5374
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5375
|
+
console.error(spaceTrim__default["default"]((block) => `
|
|
5376
|
+
Error in FOREACH command:
|
|
5377
|
+
|
|
5378
|
+
${block(pipelineIdentification)}
|
|
5379
|
+
|
|
5380
|
+
${block(pipelineIdentification)}
|
|
5381
|
+
Subparameter index: ${index}
|
|
5382
|
+
`));
|
|
5383
|
+
return '~';
|
|
5384
|
+
}
|
|
5385
|
+
throw error;
|
|
5386
|
+
}
|
|
5356
5387
|
},
|
|
5357
5388
|
});
|
|
5358
5389
|
return resultString;
|
|
@@ -5487,7 +5518,11 @@
|
|
|
5487
5518
|
*/
|
|
5488
5519
|
|
|
5489
5520
|
/**
|
|
5490
|
-
*
|
|
5521
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
5522
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
5523
|
+
*
|
|
5524
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
5525
|
+
* @returns An object containing all reserved parameters for the task.
|
|
5491
5526
|
*
|
|
5492
5527
|
* @private internal utility of `createPipelineExecutor`
|
|
5493
5528
|
*/
|
|
@@ -5520,7 +5555,10 @@
|
|
|
5520
5555
|
}
|
|
5521
5556
|
|
|
5522
5557
|
/**
|
|
5523
|
-
*
|
|
5558
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
5559
|
+
*
|
|
5560
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
5561
|
+
* @returns The output parameters produced by the task.
|
|
5524
5562
|
*
|
|
5525
5563
|
* @private internal utility of `createPipelineExecutor`
|
|
5526
5564
|
*/
|
|
@@ -5654,9 +5692,12 @@
|
|
|
5654
5692
|
}
|
|
5655
5693
|
|
|
5656
5694
|
/**
|
|
5657
|
-
*
|
|
5695
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
5696
|
+
*
|
|
5697
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
5658
5698
|
*
|
|
5659
|
-
*
|
|
5699
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
5700
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
5660
5701
|
*
|
|
5661
5702
|
* @private internal utility of `createPipelineExecutor`
|
|
5662
5703
|
*/
|