@promptbook/legacy-documents 0.92.0-22 โ†’ 0.92.0-24

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.
Files changed (35) hide show
  1. package/esm/index.es.js +115 -55
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  4. package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
  5. package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
  6. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
  7. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  8. package/esm/typings/src/config.d.ts +33 -11
  9. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  10. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  11. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -3
  12. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
  13. package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
  14. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +31 -6
  15. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  16. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  17. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  18. package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
  19. package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
  20. package/esm/typings/src/formfactors/index.d.ts +1 -1
  21. package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
  22. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
  23. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
  24. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  25. package/esm/typings/src/types/typeAliases.d.ts +9 -7
  26. package/esm/typings/src/utils/$Register.d.ts +8 -7
  27. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
  28. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  29. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  30. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  31. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  32. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  33. package/package.json +2 -2
  34. package/umd/index.umd.js +115 -55
  35. 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-22';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-24';
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,21 @@ 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
+ * Threshold value that determines when a dataset is considered "big"
109
+ * and may require special handling or optimizations
110
+ *
111
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
112
+ *
113
+ * @public exported from `@promptbook/core`
114
+ */
115
+ const BIG_DATASET_TRESHOLD = 50;
116
+ /**
117
+ * Placeholder text used to represent a placeholder value of failed operation
118
+ *
119
+ * @public exported from `@promptbook/core`
120
+ */
121
+ const FAILED_VALUE_PLACEHOLDER = '!?';
107
122
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
108
123
  /**
109
124
  * The maximum number of iterations for a loops
@@ -183,7 +198,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
183
198
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
184
199
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
185
200
  /**
186
- * @@@
201
+ * Default settings for parsing and generating CSV files in Promptbook.
187
202
  *
188
203
  * @public exported from `@promptbook/core`
189
204
  */
@@ -194,19 +209,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
194
209
  skipEmptyLines: true,
195
210
  });
196
211
  /**
197
- * @@@
212
+ * Controls whether verbose logging is enabled by default throughout the application.
198
213
  *
199
214
  * @public exported from `@promptbook/core`
200
215
  */
201
216
  let DEFAULT_IS_VERBOSE = false;
202
217
  /**
203
- * @@@
218
+ * Controls whether auto-installation of dependencies is enabled by default.
204
219
  *
205
220
  * @public exported from `@promptbook/core`
206
221
  */
207
222
  const DEFAULT_IS_AUTO_INSTALLED = false;
208
223
  /**
209
- * @@@
224
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
210
225
  *
211
226
  * @private within the repository
212
227
  */
@@ -1124,7 +1139,7 @@ function assertsError(whatWasThrown) {
1124
1139
  * Function isValidJsonString will tell you if the string is valid JSON or not
1125
1140
  *
1126
1141
  * @param value The string to check
1127
- * @returns True if the string is a valid JSON string, false otherwise
1142
+ * @returns `true` if the string is a valid JSON string, false otherwise
1128
1143
  *
1129
1144
  * @public exported from `@promptbook/utils`
1130
1145
  */
@@ -1535,8 +1550,12 @@ function checkSerializableAsJson(options) {
1535
1550
  */
1536
1551
 
1537
1552
  /**
1538
- * @@@
1553
+ * Creates a deep clone of the given object
1554
+ *
1555
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1539
1556
  *
1557
+ * @param objectValue The object to clone.
1558
+ * @returns A deep, writable clone of the input object.
1540
1559
  * @public exported from `@promptbook/utils`
1541
1560
  */
1542
1561
  function deepClone(objectValue) {
@@ -2123,7 +2142,7 @@ class SimplePipelineCollection {
2123
2142
  /**
2124
2143
  * Constructs a pipeline collection from pipelines
2125
2144
  *
2126
- * @param pipelines @@@
2145
+ * @param pipelines Array of pipeline JSON objects to include in the collection
2127
2146
  *
2128
2147
  * Note: During the construction logic of all pipelines are validated
2129
2148
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -3242,7 +3261,8 @@ async function preparePersona(personaDescription, tools, options) {
3242
3261
  */
3243
3262
 
3244
3263
  /**
3245
- * @@@
3264
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3265
+ * regardless of the JavaScript environment in which the code is running
3246
3266
  *
3247
3267
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3248
3268
  *
@@ -3321,11 +3341,11 @@ function normalizeTo_snake_case(text) {
3321
3341
  }
3322
3342
 
3323
3343
  /**
3324
- * Register is @@@
3344
+ * Global registry for storing and managing registered entities of a given type.
3325
3345
  *
3326
3346
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3327
3347
  *
3328
- * @private internal utility, exported are only signleton instances of this class
3348
+ * @private internal utility, exported are only singleton instances of this class
3329
3349
  */
3330
3350
  class $Register {
3331
3351
  constructor(registerName) {
@@ -3369,10 +3389,10 @@ class $Register {
3369
3389
  }
3370
3390
 
3371
3391
  /**
3372
- * @@@
3392
+ * Global registry for storing metadata about all available scrapers and converters.
3373
3393
  *
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 thare can be more @@@
3394
+ * Note: `$` is used to indicate that this interacts with the global scope.
3395
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3376
3396
  * @public exported from `@promptbook/core`
3377
3397
  */
3378
3398
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4263,7 +4283,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4263
4283
  * Function to check if a string is valid CSV
4264
4284
  *
4265
4285
  * @param value The string to check
4266
- * @returns True if the string is a valid CSV string, false otherwise
4286
+ * @returns `true` if the string is a valid CSV string, false otherwise
4267
4287
  *
4268
4288
  * @public exported from `@promptbook/utils`
4269
4289
  */
@@ -4320,18 +4340,28 @@ const CsvFormatParser = {
4320
4340
  `));
4321
4341
  }
4322
4342
  const mappedData = [];
4323
- for (let index = 0; index < csv.data.length; index++) {
4343
+ const length = csv.data.length;
4344
+ for (let index = 0; index < length; index++) {
4324
4345
  const row = csv.data[index];
4325
4346
  if (row[outputParameterName]) {
4326
4347
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4327
4348
  }
4328
4349
  const mappedRow = {
4329
4350
  ...row,
4330
- [outputParameterName]: await mapCallback(row, index),
4351
+ [outputParameterName]: await mapCallback(row, index, length),
4331
4352
  };
4332
4353
  mappedData.push(mappedRow);
4333
4354
  if (onProgress) {
4334
4355
  // Note: Report the CSV with all rows mapped so far
4356
+ /*
4357
+ !!!!
4358
+ // Report progress with updated value
4359
+ const progressData = mappedData.map((row, i) =>
4360
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4361
+ );
4362
+
4363
+
4364
+ */
4335
4365
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4336
4366
  }
4337
4367
  }
@@ -4358,9 +4388,9 @@ const CsvFormatParser = {
4358
4388
  `));
4359
4389
  }
4360
4390
  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) => {
4391
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4362
4392
  const index = rowIndex * Object.keys(row).length + columnIndex;
4363
- return /* not await */ mapCallback({ [key]: value }, index);
4393
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4364
4394
  }));
4365
4395
  }));
4366
4396
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4431,12 +4461,12 @@ const TextFormatParser = {
4431
4461
  async mapValues(options) {
4432
4462
  const { value, mapCallback, onProgress } = options;
4433
4463
  const lines = value.split('\n');
4434
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4464
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4435
4465
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4436
4466
  /* not await */ mapCallback({
4437
4467
  lineContent,
4438
4468
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4439
- }, lineNumber)));
4469
+ }, lineNumber, array.length)));
4440
4470
  return mappedLines.join('\n');
4441
4471
  },
4442
4472
  },
@@ -4457,7 +4487,7 @@ const TextFormatParser = {
4457
4487
  * Function to check if a string is valid XML
4458
4488
  *
4459
4489
  * @param value
4460
- * @returns True if the string is a valid XML string, false otherwise
4490
+ * @returns `true` if the string is a valid XML string, false otherwise
4461
4491
  *
4462
4492
  * @public exported from `@promptbook/utils`
4463
4493
  */
@@ -4519,13 +4549,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4519
4549
  */
4520
4550
 
4521
4551
  /**
4522
- * Maps available parameters to expected parameters
4552
+ * Maps available parameters to expected parameters for a pipeline task.
4523
4553
  *
4524
4554
  * The strategy is:
4525
- * 1) @@@
4526
- * 2) @@@
4555
+ * 1) First, match parameters by name where both available and expected.
4556
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4527
4557
  *
4528
- * @throws {PipelineExecutionError} @@@
4558
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4529
4559
  * @private within the repository used in `createPipelineExecutor`
4530
4560
  */
4531
4561
  function mapAvailableToExpectedParameters(options) {
@@ -5245,7 +5275,11 @@ async function executeAttempts(options) {
5245
5275
  */
5246
5276
 
5247
5277
  /**
5248
- * @@@
5278
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5279
+ * Handles format and subformat resolution, error handling, and progress reporting.
5280
+ *
5281
+ * @param options - Options for execution, including task details and progress callback.
5282
+ * @returns The result of the subvalue mapping or execution attempts.
5249
5283
  *
5250
5284
  * @private internal utility of `createPipelineExecutor`
5251
5285
  */
@@ -5310,15 +5344,11 @@ async function executeFormatSubvalues(options) {
5310
5344
  settings: formatSettings,
5311
5345
  onProgress(partialResultString) {
5312
5346
  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,
5347
+ [task.resultingParameterName]: partialResultString,
5316
5348
  }));
5317
5349
  },
5318
- async mapCallback(subparameters, index) {
5350
+ async mapCallback(subparameters, index, length) {
5319
5351
  let mappedParameters;
5320
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5321
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5322
5352
  try {
5323
5353
  mappedParameters = mapAvailableToExpectedParameters({
5324
5354
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5329,32 +5359,52 @@ async function executeFormatSubvalues(options) {
5329
5359
  if (!(error instanceof PipelineExecutionError)) {
5330
5360
  throw error;
5331
5361
  }
5332
- throw new PipelineExecutionError(spaceTrim$1((block) => `
5333
- ${error.message}
5362
+ const highLevelError = new PipelineExecutionError(spaceTrim$1((block) => `
5363
+ ${error.message}
5334
5364
 
5335
- This is error in FOREACH command
5336
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5365
+ This is error in FOREACH command when mapping data
5366
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5337
5367
 
5338
- ${block(pipelineIdentification)}
5339
- Subparameter index: ${index}
5340
- `));
5368
+ ${block(pipelineIdentification)}
5369
+ Subparameter index: ${index}
5370
+ `));
5371
+ if (length > BIG_DATASET_TRESHOLD) {
5372
+ console.error(highLevelError);
5373
+ return FAILED_VALUE_PLACEHOLDER;
5374
+ }
5375
+ throw highLevelError;
5341
5376
  }
5342
5377
  const allSubparameters = {
5343
5378
  ...parameters,
5344
5379
  ...mappedParameters,
5345
5380
  };
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
5381
  Object.freeze(allSubparameters);
5348
- const subresultString = await executeAttempts({
5349
- ...options,
5350
- priority: priority + index,
5351
- parameters: allSubparameters,
5352
- pipelineIdentification: spaceTrim$1((block) => `
5353
- ${block(pipelineIdentification)}
5354
- Subparameter index: ${index}
5355
- `),
5356
- });
5357
- return subresultString;
5382
+ try {
5383
+ const subresultString = await executeAttempts({
5384
+ ...options,
5385
+ priority: priority + index,
5386
+ parameters: allSubparameters,
5387
+ pipelineIdentification: spaceTrim$1((block) => `
5388
+ ${block(pipelineIdentification)}
5389
+ Subparameter index: ${index}
5390
+ `),
5391
+ });
5392
+ return subresultString;
5393
+ }
5394
+ catch (error) {
5395
+ if (length > BIG_DATASET_TRESHOLD) {
5396
+ console.error(spaceTrim$1((block) => `
5397
+ Error in FOREACH command:
5398
+
5399
+ ${block(pipelineIdentification)}
5400
+
5401
+ ${block(pipelineIdentification)}
5402
+ Subparameter index: ${index}
5403
+ `));
5404
+ return FAILED_VALUE_PLACEHOLDER;
5405
+ }
5406
+ throw error;
5407
+ }
5358
5408
  },
5359
5409
  });
5360
5410
  return resultString;
@@ -5489,7 +5539,11 @@ async function getKnowledgeForTask(options) {
5489
5539
  */
5490
5540
 
5491
5541
  /**
5492
- * @@@
5542
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5543
+ * Ensures all reserved parameters are defined and throws if any are missing.
5544
+ *
5545
+ * @param options - Options including tools, pipeline, task, and context.
5546
+ * @returns An object containing all reserved parameters for the task.
5493
5547
  *
5494
5548
  * @private internal utility of `createPipelineExecutor`
5495
5549
  */
@@ -5522,7 +5576,10 @@ async function getReservedParametersForTask(options) {
5522
5576
  }
5523
5577
 
5524
5578
  /**
5525
- * @@@
5579
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5580
+ *
5581
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5582
+ * @returns The output parameters produced by the task.
5526
5583
  *
5527
5584
  * @private internal utility of `createPipelineExecutor`
5528
5585
  */
@@ -5656,9 +5713,12 @@ function filterJustOutputParameters(options) {
5656
5713
  }
5657
5714
 
5658
5715
  /**
5659
- * @@@
5716
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5717
+ *
5718
+ * 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
5719
  *
5661
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5720
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5721
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5662
5722
  *
5663
5723
  * @private internal utility of `createPipelineExecutor`
5664
5724
  */