@promptbook/pdf 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
@@ -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-22';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-24';
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,21 @@ 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
+ * Threshold value that determines when a dataset is considered "big"
107
+ * and may require special handling or optimizations
108
+ *
109
+ * For example, when error occurs in one item of the big dataset, it will not fail the whole pipeline
110
+ *
111
+ * @public exported from `@promptbook/core`
112
+ */
113
+ const BIG_DATASET_TRESHOLD = 50;
114
+ /**
115
+ * Placeholder text used to represent a placeholder value of failed operation
116
+ *
117
+ * @public exported from `@promptbook/core`
118
+ */
119
+ const FAILED_VALUE_PLACEHOLDER = '!?';
105
120
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
106
121
  /**
107
122
  * The maximum number of iterations for a loops
@@ -181,7 +196,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
181
196
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
182
197
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
183
198
  /**
184
- * @@@
199
+ * Default settings for parsing and generating CSV files in Promptbook.
185
200
  *
186
201
  * @public exported from `@promptbook/core`
187
202
  */
@@ -192,19 +207,19 @@ const DEFAULT_CSV_SETTINGS = Object.freeze({
192
207
  skipEmptyLines: true,
193
208
  });
194
209
  /**
195
- * @@@
210
+ * Controls whether verbose logging is enabled by default throughout the application.
196
211
  *
197
212
  * @public exported from `@promptbook/core`
198
213
  */
199
214
  let DEFAULT_IS_VERBOSE = false;
200
215
  /**
201
- * @@@
216
+ * Controls whether auto-installation of dependencies is enabled by default.
202
217
  *
203
218
  * @public exported from `@promptbook/core`
204
219
  */
205
220
  const DEFAULT_IS_AUTO_INSTALLED = false;
206
221
  /**
207
- * @@@
222
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
208
223
  *
209
224
  * @private within the repository
210
225
  */
@@ -945,7 +960,7 @@ function assertsError(whatWasThrown) {
945
960
  * Function isValidJsonString will tell you if the string is valid JSON or not
946
961
  *
947
962
  * @param value The string to check
948
- * @returns True if the string is a valid JSON string, false otherwise
963
+ * @returns `true` if the string is a valid JSON string, false otherwise
949
964
  *
950
965
  * @public exported from `@promptbook/utils`
951
966
  */
@@ -1356,8 +1371,12 @@ function checkSerializableAsJson(options) {
1356
1371
  */
1357
1372
 
1358
1373
  /**
1359
- * @@@
1374
+ * Creates a deep clone of the given object
1375
+ *
1376
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1360
1377
  *
1378
+ * @param objectValue The object to clone.
1379
+ * @returns A deep, writable clone of the input object.
1361
1380
  * @public exported from `@promptbook/utils`
1362
1381
  */
1363
1382
  function deepClone(objectValue) {
@@ -1944,7 +1963,7 @@ class SimplePipelineCollection {
1944
1963
  /**
1945
1964
  * Constructs a pipeline collection from pipelines
1946
1965
  *
1947
- * @param pipelines @@@
1966
+ * @param pipelines Array of pipeline JSON objects to include in the collection
1948
1967
  *
1949
1968
  * Note: During the construction logic of all pipelines are validated
1950
1969
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
@@ -3081,7 +3100,8 @@ async function preparePersona(personaDescription, tools, options) {
3081
3100
  */
3082
3101
 
3083
3102
  /**
3084
- * @@@
3103
+ * Safely retrieves the global scope object (window in browser, global in Node.js)
3104
+ * regardless of the JavaScript environment in which the code is running
3085
3105
  *
3086
3106
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
3087
3107
  *
@@ -3160,11 +3180,11 @@ function normalizeTo_snake_case(text) {
3160
3180
  }
3161
3181
 
3162
3182
  /**
3163
- * Register is @@@
3183
+ * Global registry for storing and managing registered entities of a given type.
3164
3184
  *
3165
3185
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3166
3186
  *
3167
- * @private internal utility, exported are only signleton instances of this class
3187
+ * @private internal utility, exported are only singleton instances of this class
3168
3188
  */
3169
3189
  class $Register {
3170
3190
  constructor(registerName) {
@@ -3208,10 +3228,10 @@ class $Register {
3208
3228
  }
3209
3229
 
3210
3230
  /**
3211
- * @@@
3231
+ * Global registry for storing metadata about all available scrapers and converters.
3212
3232
  *
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 thare can be more @@@
3233
+ * Note: `$` is used to indicate that this interacts with the global scope.
3234
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3215
3235
  * @public exported from `@promptbook/core`
3216
3236
  */
3217
3237
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4112,7 +4132,7 @@ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO:
4112
4132
  * Function to check if a string is valid CSV
4113
4133
  *
4114
4134
  * @param value The string to check
4115
- * @returns True if the string is a valid CSV string, false otherwise
4135
+ * @returns `true` if the string is a valid CSV string, false otherwise
4116
4136
  *
4117
4137
  * @public exported from `@promptbook/utils`
4118
4138
  */
@@ -4169,18 +4189,28 @@ const CsvFormatParser = {
4169
4189
  `));
4170
4190
  }
4171
4191
  const mappedData = [];
4172
- for (let index = 0; index < csv.data.length; index++) {
4192
+ const length = csv.data.length;
4193
+ for (let index = 0; index < length; index++) {
4173
4194
  const row = csv.data[index];
4174
4195
  if (row[outputParameterName]) {
4175
4196
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4176
4197
  }
4177
4198
  const mappedRow = {
4178
4199
  ...row,
4179
- [outputParameterName]: await mapCallback(row, index),
4200
+ [outputParameterName]: await mapCallback(row, index, length),
4180
4201
  };
4181
4202
  mappedData.push(mappedRow);
4182
4203
  if (onProgress) {
4183
4204
  // Note: Report the CSV with all rows mapped so far
4205
+ /*
4206
+ !!!!
4207
+ // Report progress with updated value
4208
+ const progressData = mappedData.map((row, i) =>
4209
+ i > index ? { ...row, [outputParameterName]: PENDING_VALUE_PLACEHOLDER } : row,
4210
+ );
4211
+
4212
+
4213
+ */
4184
4214
  await onProgress(unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS }));
4185
4215
  }
4186
4216
  }
@@ -4207,9 +4237,9 @@ const CsvFormatParser = {
4207
4237
  `));
4208
4238
  }
4209
4239
  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) => {
4240
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4211
4241
  const index = rowIndex * Object.keys(row).length + columnIndex;
4212
- return /* not await */ mapCallback({ [key]: value }, index);
4242
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4213
4243
  }));
4214
4244
  }));
4215
4245
  return unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4280,12 +4310,12 @@ const TextFormatParser = {
4280
4310
  async mapValues(options) {
4281
4311
  const { value, mapCallback, onProgress } = options;
4282
4312
  const lines = value.split('\n');
4283
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4313
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4284
4314
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4285
4315
  /* not await */ mapCallback({
4286
4316
  lineContent,
4287
4317
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4288
- }, lineNumber)));
4318
+ }, lineNumber, array.length)));
4289
4319
  return mappedLines.join('\n');
4290
4320
  },
4291
4321
  },
@@ -4306,7 +4336,7 @@ const TextFormatParser = {
4306
4336
  * Function to check if a string is valid XML
4307
4337
  *
4308
4338
  * @param value
4309
- * @returns True if the string is a valid XML string, false otherwise
4339
+ * @returns `true` if the string is a valid XML string, false otherwise
4310
4340
  *
4311
4341
  * @public exported from `@promptbook/utils`
4312
4342
  */
@@ -4368,13 +4398,13 @@ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser,
4368
4398
  */
4369
4399
 
4370
4400
  /**
4371
- * Maps available parameters to expected parameters
4401
+ * Maps available parameters to expected parameters for a pipeline task.
4372
4402
  *
4373
4403
  * The strategy is:
4374
- * 1) @@@
4375
- * 2) @@@
4404
+ * 1) First, match parameters by name where both available and expected.
4405
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4376
4406
  *
4377
- * @throws {PipelineExecutionError} @@@
4407
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4378
4408
  * @private within the repository used in `createPipelineExecutor`
4379
4409
  */
4380
4410
  function mapAvailableToExpectedParameters(options) {
@@ -5094,7 +5124,11 @@ async function executeAttempts(options) {
5094
5124
  */
5095
5125
 
5096
5126
  /**
5097
- * @@@
5127
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5128
+ * Handles format and subformat resolution, error handling, and progress reporting.
5129
+ *
5130
+ * @param options - Options for execution, including task details and progress callback.
5131
+ * @returns The result of the subvalue mapping or execution attempts.
5098
5132
  *
5099
5133
  * @private internal utility of `createPipelineExecutor`
5100
5134
  */
@@ -5159,15 +5193,11 @@ async function executeFormatSubvalues(options) {
5159
5193
  settings: formatSettings,
5160
5194
  onProgress(partialResultString) {
5161
5195
  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,
5196
+ [task.resultingParameterName]: partialResultString,
5165
5197
  }));
5166
5198
  },
5167
- async mapCallback(subparameters, index) {
5199
+ async mapCallback(subparameters, index, length) {
5168
5200
  let mappedParameters;
5169
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5170
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5171
5201
  try {
5172
5202
  mappedParameters = mapAvailableToExpectedParameters({
5173
5203
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5178,32 +5208,52 @@ async function executeFormatSubvalues(options) {
5178
5208
  if (!(error instanceof PipelineExecutionError)) {
5179
5209
  throw error;
5180
5210
  }
5181
- throw new PipelineExecutionError(spaceTrim((block) => `
5182
- ${error.message}
5211
+ const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5212
+ ${error.message}
5183
5213
 
5184
- This is error in FOREACH command
5185
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5214
+ This is error in FOREACH command when mapping data
5215
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5186
5216
 
5187
- ${block(pipelineIdentification)}
5188
- Subparameter index: ${index}
5189
- `));
5217
+ ${block(pipelineIdentification)}
5218
+ Subparameter index: ${index}
5219
+ `));
5220
+ if (length > BIG_DATASET_TRESHOLD) {
5221
+ console.error(highLevelError);
5222
+ return FAILED_VALUE_PLACEHOLDER;
5223
+ }
5224
+ throw highLevelError;
5190
5225
  }
5191
5226
  const allSubparameters = {
5192
5227
  ...parameters,
5193
5228
  ...mappedParameters,
5194
5229
  };
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
5230
  Object.freeze(allSubparameters);
5197
- const subresultString = await executeAttempts({
5198
- ...options,
5199
- priority: priority + index,
5200
- parameters: allSubparameters,
5201
- pipelineIdentification: spaceTrim((block) => `
5202
- ${block(pipelineIdentification)}
5203
- Subparameter index: ${index}
5204
- `),
5205
- });
5206
- return subresultString;
5231
+ try {
5232
+ const subresultString = await executeAttempts({
5233
+ ...options,
5234
+ priority: priority + index,
5235
+ parameters: allSubparameters,
5236
+ pipelineIdentification: spaceTrim((block) => `
5237
+ ${block(pipelineIdentification)}
5238
+ Subparameter index: ${index}
5239
+ `),
5240
+ });
5241
+ return subresultString;
5242
+ }
5243
+ catch (error) {
5244
+ if (length > BIG_DATASET_TRESHOLD) {
5245
+ console.error(spaceTrim((block) => `
5246
+ Error in FOREACH command:
5247
+
5248
+ ${block(pipelineIdentification)}
5249
+
5250
+ ${block(pipelineIdentification)}
5251
+ Subparameter index: ${index}
5252
+ `));
5253
+ return FAILED_VALUE_PLACEHOLDER;
5254
+ }
5255
+ throw error;
5256
+ }
5207
5257
  },
5208
5258
  });
5209
5259
  return resultString;
@@ -5338,7 +5388,11 @@ async function getKnowledgeForTask(options) {
5338
5388
  */
5339
5389
 
5340
5390
  /**
5341
- * @@@
5391
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5392
+ * Ensures all reserved parameters are defined and throws if any are missing.
5393
+ *
5394
+ * @param options - Options including tools, pipeline, task, and context.
5395
+ * @returns An object containing all reserved parameters for the task.
5342
5396
  *
5343
5397
  * @private internal utility of `createPipelineExecutor`
5344
5398
  */
@@ -5371,7 +5425,10 @@ async function getReservedParametersForTask(options) {
5371
5425
  }
5372
5426
 
5373
5427
  /**
5374
- * @@@
5428
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5429
+ *
5430
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5431
+ * @returns The output parameters produced by the task.
5375
5432
  *
5376
5433
  * @private internal utility of `createPipelineExecutor`
5377
5434
  */
@@ -5505,9 +5562,12 @@ function filterJustOutputParameters(options) {
5505
5562
  }
5506
5563
 
5507
5564
  /**
5508
- * @@@
5565
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5566
+ *
5567
+ * 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
5568
  *
5510
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5569
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5570
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5511
5571
  *
5512
5572
  * @private internal utility of `createPipelineExecutor`
5513
5573
  */