@promptbook/remote-server 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
|
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
33
33
|
* @generated
|
|
34
34
|
* @see https://github.com/webgptorg/promptbook
|
|
35
35
|
*/
|
|
36
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
36
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
|
|
37
37
|
/**
|
|
38
38
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
39
39
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -100,6 +100,12 @@ const DEFAULT_BOOK_TITLE = `โจ Untitled Book`;
|
|
|
100
100
|
* @public exported from `@promptbook/core`
|
|
101
101
|
*/
|
|
102
102
|
const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
|
103
|
+
/**
|
|
104
|
+
* @@@
|
|
105
|
+
*
|
|
106
|
+
* @public exported from `@promptbook/core`
|
|
107
|
+
*/
|
|
108
|
+
const BIG_DATASET_TRESHOLD = 50;
|
|
103
109
|
// <- TODO: [๐ง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
104
110
|
/**
|
|
105
111
|
* The maximum number of iterations for a loops
|
|
@@ -179,7 +185,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
179
185
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
180
186
|
// <- TODO: [๐งโโ๏ธ]
|
|
181
187
|
/**
|
|
182
|
-
*
|
|
188
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
183
189
|
*
|
|
184
190
|
* @public exported from `@promptbook/core`
|
|
185
191
|
*/
|
|
@@ -190,19 +196,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
|
190
196
|
skipEmptyLines: true,
|
|
191
197
|
});
|
|
192
198
|
/**
|
|
193
|
-
*
|
|
199
|
+
* Controls whether verbose logging is enabled by default throughout the application.
|
|
194
200
|
*
|
|
195
201
|
* @public exported from `@promptbook/core`
|
|
196
202
|
*/
|
|
197
203
|
let DEFAULT_IS_VERBOSE = false;
|
|
198
204
|
/**
|
|
199
|
-
*
|
|
205
|
+
* Controls whether auto-installation of dependencies is enabled by default.
|
|
200
206
|
*
|
|
201
207
|
* @public exported from `@promptbook/core`
|
|
202
208
|
*/
|
|
203
209
|
const DEFAULT_IS_AUTO_INSTALLED = false;
|
|
204
210
|
/**
|
|
205
|
-
*
|
|
211
|
+
* Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
|
|
206
212
|
*
|
|
207
213
|
* @private within the repository
|
|
208
214
|
*/
|
|
@@ -1262,8 +1268,12 @@ function checkSerializableAsJson(options) {
|
|
|
1262
1268
|
*/
|
|
1263
1269
|
|
|
1264
1270
|
/**
|
|
1265
|
-
*
|
|
1271
|
+
* Creates a deep clone of the given object
|
|
1272
|
+
*
|
|
1273
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
1266
1274
|
*
|
|
1275
|
+
* @param objectValue The object to clone.
|
|
1276
|
+
* @returns A deep, writable clone of the input object.
|
|
1267
1277
|
* @public exported from `@promptbook/utils`
|
|
1268
1278
|
*/
|
|
1269
1279
|
function deepClone(objectValue) {
|
|
@@ -1821,7 +1831,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
1821
1831
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1822
1832
|
*
|
|
1823
1833
|
* @param value The string to check
|
|
1824
|
-
* @returns
|
|
1834
|
+
* @returns `true` if the string is a valid JSON string, false otherwise
|
|
1825
1835
|
*
|
|
1826
1836
|
* @public exported from `@promptbook/utils`
|
|
1827
1837
|
*/
|
|
@@ -3092,11 +3102,11 @@ function normalizeTo_snake_case(text) {
|
|
|
3092
3102
|
}
|
|
3093
3103
|
|
|
3094
3104
|
/**
|
|
3095
|
-
*
|
|
3105
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
3096
3106
|
*
|
|
3097
3107
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
3098
3108
|
*
|
|
3099
|
-
* @private internal utility, exported are only
|
|
3109
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
3100
3110
|
*/
|
|
3101
3111
|
class $Register {
|
|
3102
3112
|
constructor(registerName) {
|
|
@@ -3140,10 +3150,10 @@ class $Register {
|
|
|
3140
3150
|
}
|
|
3141
3151
|
|
|
3142
3152
|
/**
|
|
3143
|
-
*
|
|
3153
|
+
* Global registry for storing metadata about all available scrapers and converters.
|
|
3144
3154
|
*
|
|
3145
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
3146
|
-
* @singleton Only one instance of each register is created per build, but
|
|
3155
|
+
* Note: `$` is used to indicate that this interacts with the global scope.
|
|
3156
|
+
* @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
|
|
3147
3157
|
* @public exported from `@promptbook/core`
|
|
3148
3158
|
*/
|
|
3149
3159
|
const $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
@@ -4430,7 +4440,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
|
|
|
4430
4440
|
* Function to check if a string is valid CSV
|
|
4431
4441
|
*
|
|
4432
4442
|
* @param value The string to check
|
|
4433
|
-
* @returns
|
|
4443
|
+
* @returns `true` if the string is a valid CSV string, false otherwise
|
|
4434
4444
|
*
|
|
4435
4445
|
* @public exported from `@promptbook/utils`
|
|
4436
4446
|
*/
|
|
@@ -4487,14 +4497,15 @@ const CsvFormatParser = {
|
|
|
4487
4497
|
`));
|
|
4488
4498
|
}
|
|
4489
4499
|
const mappedData = [];
|
|
4490
|
-
|
|
4500
|
+
const length = csv.data.length;
|
|
4501
|
+
for (let index = 0; index < length; index++) {
|
|
4491
4502
|
const row = csv.data[index];
|
|
4492
4503
|
if (row[outputParameterName]) {
|
|
4493
4504
|
throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
|
|
4494
4505
|
}
|
|
4495
4506
|
const mappedRow = {
|
|
4496
4507
|
...row,
|
|
4497
|
-
[outputParameterName]: await mapCallback(row, index),
|
|
4508
|
+
[outputParameterName]: await mapCallback(row, index, length),
|
|
4498
4509
|
};
|
|
4499
4510
|
mappedData.push(mappedRow);
|
|
4500
4511
|
if (onProgress) {
|
|
@@ -4525,9 +4536,9 @@ const CsvFormatParser = {
|
|
|
4525
4536
|
`));
|
|
4526
4537
|
}
|
|
4527
4538
|
const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
|
|
4528
|
-
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
|
|
4539
|
+
return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
|
|
4529
4540
|
const index = rowIndex * Object.keys(row).length + columnIndex;
|
|
4530
|
-
return /* not await */ mapCallback({ [key]: value }, index);
|
|
4541
|
+
return /* not await */ mapCallback({ [key]: value }, index, array.length);
|
|
4531
4542
|
}));
|
|
4532
4543
|
}));
|
|
4533
4544
|
return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
@@ -4598,12 +4609,12 @@ const TextFormatParser = {
|
|
|
4598
4609
|
async mapValues(options) {
|
|
4599
4610
|
const { value, mapCallback, onProgress } = options;
|
|
4600
4611
|
const lines = value.split('\n');
|
|
4601
|
-
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
|
|
4612
|
+
const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
|
|
4602
4613
|
// TODO: [๐ง ] Maybe option to skip empty line
|
|
4603
4614
|
/* not await */ mapCallback({
|
|
4604
4615
|
lineContent,
|
|
4605
4616
|
// TODO: [๐ง ] Maybe also put here `lineNumber`
|
|
4606
|
-
}, lineNumber)));
|
|
4617
|
+
}, lineNumber, array.length)));
|
|
4607
4618
|
return mappedLines.join('\n');
|
|
4608
4619
|
},
|
|
4609
4620
|
},
|
|
@@ -4624,7 +4635,7 @@ const TextFormatParser = {
|
|
|
4624
4635
|
* Function to check if a string is valid XML
|
|
4625
4636
|
*
|
|
4626
4637
|
* @param value
|
|
4627
|
-
* @returns
|
|
4638
|
+
* @returns `true` if the string is a valid XML string, false otherwise
|
|
4628
4639
|
*
|
|
4629
4640
|
* @public exported from `@promptbook/utils`
|
|
4630
4641
|
*/
|
|
@@ -4686,13 +4697,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
|
|
|
4686
4697
|
*/
|
|
4687
4698
|
|
|
4688
4699
|
/**
|
|
4689
|
-
* Maps available parameters to expected parameters
|
|
4700
|
+
* Maps available parameters to expected parameters for a pipeline task.
|
|
4690
4701
|
*
|
|
4691
4702
|
* The strategy is:
|
|
4692
|
-
* 1)
|
|
4693
|
-
* 2)
|
|
4703
|
+
* 1) First, match parameters by name where both available and expected.
|
|
4704
|
+
* 2) Then, if there are unmatched expected and available parameters, map them by order.
|
|
4694
4705
|
*
|
|
4695
|
-
* @throws {PipelineExecutionError}
|
|
4706
|
+
* @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
|
|
4696
4707
|
* @private within the repository used in `createPipelineExecutor`
|
|
4697
4708
|
*/
|
|
4698
4709
|
function mapAvailableToExpectedParameters(options) {
|
|
@@ -5429,7 +5440,11 @@ async function executeAttempts(options) {
|
|
|
5429
5440
|
*/
|
|
5430
5441
|
|
|
5431
5442
|
/**
|
|
5432
|
-
*
|
|
5443
|
+
* Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
|
|
5444
|
+
* Handles format and subformat resolution, error handling, and progress reporting.
|
|
5445
|
+
*
|
|
5446
|
+
* @param options - Options for execution, including task details and progress callback.
|
|
5447
|
+
* @returns The result of the subvalue mapping or execution attempts.
|
|
5433
5448
|
*
|
|
5434
5449
|
* @private internal utility of `createPipelineExecutor`
|
|
5435
5450
|
*/
|
|
@@ -5494,15 +5509,11 @@ async function executeFormatSubvalues(options) {
|
|
|
5494
5509
|
settings: formatSettings,
|
|
5495
5510
|
onProgress(partialResultString) {
|
|
5496
5511
|
return onProgress(Object.freeze({
|
|
5497
|
-
[task.resultingParameterName]:
|
|
5498
|
-
// <- Note: [๐ฉโ๐ฉโ๐ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
5499
|
-
partialResultString,
|
|
5512
|
+
[task.resultingParameterName]: partialResultString,
|
|
5500
5513
|
}));
|
|
5501
5514
|
},
|
|
5502
|
-
async mapCallback(subparameters, index) {
|
|
5515
|
+
async mapCallback(subparameters, index, length) {
|
|
5503
5516
|
let mappedParameters;
|
|
5504
|
-
// TODO: [๐คนโโ๏ธ][๐ช] Limit to N concurrent executions
|
|
5505
|
-
// TODO: When done [๐] Report progress also for each subvalue here
|
|
5506
5517
|
try {
|
|
5507
5518
|
mappedParameters = mapAvailableToExpectedParameters({
|
|
5508
5519
|
expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
|
|
@@ -5513,32 +5524,52 @@ async function executeFormatSubvalues(options) {
|
|
|
5513
5524
|
if (!(error instanceof PipelineExecutionError)) {
|
|
5514
5525
|
throw error;
|
|
5515
5526
|
}
|
|
5516
|
-
|
|
5517
|
-
|
|
5527
|
+
const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
|
|
5528
|
+
${error.message}
|
|
5518
5529
|
|
|
5519
|
-
|
|
5520
|
-
|
|
5530
|
+
This is error in FOREACH command when mapping data
|
|
5531
|
+
You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
|
|
5521
5532
|
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5533
|
+
${block(pipelineIdentification)}
|
|
5534
|
+
Subparameter index: ${index}
|
|
5535
|
+
`));
|
|
5536
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5537
|
+
console.error(highLevelError);
|
|
5538
|
+
return '~';
|
|
5539
|
+
}
|
|
5540
|
+
throw highLevelError;
|
|
5525
5541
|
}
|
|
5526
5542
|
const allSubparameters = {
|
|
5527
5543
|
...parameters,
|
|
5528
5544
|
...mappedParameters,
|
|
5529
5545
|
};
|
|
5530
|
-
// 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
|
|
5531
5546
|
Object.freeze(allSubparameters);
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5547
|
+
try {
|
|
5548
|
+
const subresultString = await executeAttempts({
|
|
5549
|
+
...options,
|
|
5550
|
+
priority: priority + index,
|
|
5551
|
+
parameters: allSubparameters,
|
|
5552
|
+
pipelineIdentification: spaceTrim((block) => `
|
|
5553
|
+
${block(pipelineIdentification)}
|
|
5554
|
+
Subparameter index: ${index}
|
|
5555
|
+
`),
|
|
5556
|
+
});
|
|
5557
|
+
return subresultString;
|
|
5558
|
+
}
|
|
5559
|
+
catch (error) {
|
|
5560
|
+
if (length > BIG_DATASET_TRESHOLD) {
|
|
5561
|
+
console.error(spaceTrim((block) => `
|
|
5562
|
+
Error in FOREACH command:
|
|
5563
|
+
|
|
5564
|
+
${block(pipelineIdentification)}
|
|
5565
|
+
|
|
5566
|
+
${block(pipelineIdentification)}
|
|
5567
|
+
Subparameter index: ${index}
|
|
5568
|
+
`));
|
|
5569
|
+
return '~';
|
|
5570
|
+
}
|
|
5571
|
+
throw error;
|
|
5572
|
+
}
|
|
5542
5573
|
},
|
|
5543
5574
|
});
|
|
5544
5575
|
return resultString;
|
|
@@ -5673,7 +5704,11 @@ async function getKnowledgeForTask(options) {
|
|
|
5673
5704
|
*/
|
|
5674
5705
|
|
|
5675
5706
|
/**
|
|
5676
|
-
*
|
|
5707
|
+
* Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
|
|
5708
|
+
* Ensures all reserved parameters are defined and throws if any are missing.
|
|
5709
|
+
*
|
|
5710
|
+
* @param options - Options including tools, pipeline, task, and context.
|
|
5711
|
+
* @returns An object containing all reserved parameters for the task.
|
|
5677
5712
|
*
|
|
5678
5713
|
* @private internal utility of `createPipelineExecutor`
|
|
5679
5714
|
*/
|
|
@@ -5706,7 +5741,10 @@ async function getReservedParametersForTask(options) {
|
|
|
5706
5741
|
}
|
|
5707
5742
|
|
|
5708
5743
|
/**
|
|
5709
|
-
*
|
|
5744
|
+
* Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
|
|
5745
|
+
*
|
|
5746
|
+
* @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
|
|
5747
|
+
* @returns The output parameters produced by the task.
|
|
5710
5748
|
*
|
|
5711
5749
|
* @private internal utility of `createPipelineExecutor`
|
|
5712
5750
|
*/
|
|
@@ -5840,9 +5878,12 @@ function filterJustOutputParameters(options) {
|
|
|
5840
5878
|
}
|
|
5841
5879
|
|
|
5842
5880
|
/**
|
|
5843
|
-
*
|
|
5881
|
+
* Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
|
|
5882
|
+
*
|
|
5883
|
+
* Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
|
|
5844
5884
|
*
|
|
5845
|
-
*
|
|
5885
|
+
* @param options - Options for execution, including input parameters, pipeline, and callbacks.
|
|
5886
|
+
* @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
|
|
5846
5887
|
*
|
|
5847
5888
|
* @private internal utility of `createPipelineExecutor`
|
|
5848
5889
|
*/
|