@promptbook/pdf 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.
Files changed (26) hide show
  1. package/esm/index.es.js +94 -53
  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/commands/FOREACH/ForeachJson.d.ts +6 -6
  5. package/esm/typings/src/config.d.ts +29 -11
  6. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +12 -9
  7. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +11 -8
  8. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +8 -3
  9. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +10 -8
  10. package/esm/typings/src/formats/_common/FormatParser.d.ts +5 -3
  11. package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +31 -6
  12. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
  13. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
  14. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +4 -1
  16. package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
  17. package/esm/typings/src/types/typeAliases.d.ts +9 -7
  18. package/esm/typings/src/utils/$Register.d.ts +8 -7
  19. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
  20. package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
  21. package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
  22. package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
  23. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
  24. package/package.json +2 -2
  25. package/umd/index.umd.js +94 -53
  26. package/umd/index.umd.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/pdf",
3
- "version": "0.92.0-22",
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/pdf.index.d.ts",
53
53
  "peerDependencies": {
54
- "@promptbook/core": "0.92.0-22"
54
+ "@promptbook/core": "0.92.0-23"
55
55
  },
56
56
  "dependencies": {
57
57
  "crypto": "1.0.1",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-22';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-23';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -101,6 +101,12 @@
101
101
  * @public exported from `@promptbook/core`
102
102
  */
103
103
  const DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
104
+ /**
105
+ * @@@
106
+ *
107
+ * @public exported from `@promptbook/core`
108
+ */
109
+ const BIG_DATASET_TRESHOLD = 50;
104
110
  // <- TODO: [๐Ÿง ] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
105
111
  /**
106
112
  * The maximum number of iterations for a loops
@@ -180,7 +186,7 @@
180
186
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
181
187
  // <- TODO: [๐Ÿงœโ€โ™‚๏ธ]
182
188
  /**
183
- * @@@
189
+ * Default settings for parsing and generating CSV files in Promptbook.
184
190
  *
185
191
  * @public exported from `@promptbook/core`
186
192
  */
@@ -191,19 +197,19 @@
191
197
  skipEmptyLines: true,
192
198
  });
193
199
  /**
194
- * @@@
200
+ * Controls whether verbose logging is enabled by default throughout the application.
195
201
  *
196
202
  * @public exported from `@promptbook/core`
197
203
  */
198
204
  let DEFAULT_IS_VERBOSE = false;
199
205
  /**
200
- * @@@
206
+ * Controls whether auto-installation of dependencies is enabled by default.
201
207
  *
202
208
  * @public exported from `@promptbook/core`
203
209
  */
204
210
  const DEFAULT_IS_AUTO_INSTALLED = false;
205
211
  /**
206
- * @@@
212
+ * Indicates whether pipeline logic validation is enabled. When true, the pipeline logic is checked for consistency.
207
213
  *
208
214
  * @private within the repository
209
215
  */
@@ -944,7 +950,7 @@
944
950
  * Function isValidJsonString will tell you if the string is valid JSON or not
945
951
  *
946
952
  * @param value The string to check
947
- * @returns True if the string is a valid JSON string, false otherwise
953
+ * @returns `true` if the string is a valid JSON string, false otherwise
948
954
  *
949
955
  * @public exported from `@promptbook/utils`
950
956
  */
@@ -1355,8 +1361,12 @@
1355
1361
  */
1356
1362
 
1357
1363
  /**
1358
- * @@@
1364
+ * Creates a deep clone of the given object
1365
+ *
1366
+ * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1359
1367
  *
1368
+ * @param objectValue The object to clone.
1369
+ * @returns A deep, writable clone of the input object.
1360
1370
  * @public exported from `@promptbook/utils`
1361
1371
  */
1362
1372
  function deepClone(objectValue) {
@@ -3159,11 +3169,11 @@
3159
3169
  }
3160
3170
 
3161
3171
  /**
3162
- * Register is @@@
3172
+ * Global registry for storing and managing registered entities of a given type.
3163
3173
  *
3164
3174
  * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
3165
3175
  *
3166
- * @private internal utility, exported are only signleton instances of this class
3176
+ * @private internal utility, exported are only singleton instances of this class
3167
3177
  */
3168
3178
  class $Register {
3169
3179
  constructor(registerName) {
@@ -3207,10 +3217,10 @@
3207
3217
  }
3208
3218
 
3209
3219
  /**
3210
- * @@@
3220
+ * Global registry for storing metadata about all available scrapers and converters.
3211
3221
  *
3212
- * Note: `$` is used to indicate that this interacts with the global scope
3213
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3222
+ * Note: `$` is used to indicate that this interacts with the global scope.
3223
+ * @singleton Only one instance of each register is created per build, but there can be more in different contexts (e.g., tests).
3214
3224
  * @public exported from `@promptbook/core`
3215
3225
  */
3216
3226
  const $scrapersMetadataRegister = new $Register('scrapers_metadata');
@@ -4111,7 +4121,7 @@
4111
4121
  * Function to check if a string is valid CSV
4112
4122
  *
4113
4123
  * @param value The string to check
4114
- * @returns True if the string is a valid CSV string, false otherwise
4124
+ * @returns `true` if the string is a valid CSV string, false otherwise
4115
4125
  *
4116
4126
  * @public exported from `@promptbook/utils`
4117
4127
  */
@@ -4168,14 +4178,15 @@
4168
4178
  `));
4169
4179
  }
4170
4180
  const mappedData = [];
4171
- for (let index = 0; index < csv.data.length; index++) {
4181
+ const length = csv.data.length;
4182
+ for (let index = 0; index < length; index++) {
4172
4183
  const row = csv.data[index];
4173
4184
  if (row[outputParameterName]) {
4174
4185
  throw new CsvFormatError(`Can not overwrite existing column "${outputParameterName}" in CSV row`);
4175
4186
  }
4176
4187
  const mappedRow = {
4177
4188
  ...row,
4178
- [outputParameterName]: await mapCallback(row, index),
4189
+ [outputParameterName]: await mapCallback(row, index, length),
4179
4190
  };
4180
4191
  mappedData.push(mappedRow);
4181
4192
  if (onProgress) {
@@ -4206,9 +4217,9 @@
4206
4217
  `));
4207
4218
  }
4208
4219
  const mappedData = await Promise.all(csv.data.map(async (row, rowIndex) => {
4209
- return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex) => {
4220
+ return /* not await */ Promise.all(Object.entries(row).map(async ([key, value], columnIndex, array) => {
4210
4221
  const index = rowIndex * Object.keys(row).length + columnIndex;
4211
- return /* not await */ mapCallback({ [key]: value }, index);
4222
+ return /* not await */ mapCallback({ [key]: value }, index, array.length);
4212
4223
  }));
4213
4224
  }));
4214
4225
  return papaparse.unparse(mappedData, { ...settings, ...MANDATORY_CSV_SETTINGS });
@@ -4279,12 +4290,12 @@
4279
4290
  async mapValues(options) {
4280
4291
  const { value, mapCallback, onProgress } = options;
4281
4292
  const lines = value.split('\n');
4282
- const mappedLines = await Promise.all(lines.map((lineContent, lineNumber) =>
4293
+ const mappedLines = await Promise.all(lines.map((lineContent, lineNumber, array) =>
4283
4294
  // TODO: [๐Ÿง ] Maybe option to skip empty line
4284
4295
  /* not await */ mapCallback({
4285
4296
  lineContent,
4286
4297
  // TODO: [๐Ÿง ] Maybe also put here `lineNumber`
4287
- }, lineNumber)));
4298
+ }, lineNumber, array.length)));
4288
4299
  return mappedLines.join('\n');
4289
4300
  },
4290
4301
  },
@@ -4305,7 +4316,7 @@
4305
4316
  * Function to check if a string is valid XML
4306
4317
  *
4307
4318
  * @param value
4308
- * @returns True if the string is a valid XML string, false otherwise
4319
+ * @returns `true` if the string is a valid XML string, false otherwise
4309
4320
  *
4310
4321
  * @public exported from `@promptbook/utils`
4311
4322
  */
@@ -4367,13 +4378,13 @@
4367
4378
  */
4368
4379
 
4369
4380
  /**
4370
- * Maps available parameters to expected parameters
4381
+ * Maps available parameters to expected parameters for a pipeline task.
4371
4382
  *
4372
4383
  * The strategy is:
4373
- * 1) @@@
4374
- * 2) @@@
4384
+ * 1) First, match parameters by name where both available and expected.
4385
+ * 2) Then, if there are unmatched expected and available parameters, map them by order.
4375
4386
  *
4376
- * @throws {PipelineExecutionError} @@@
4387
+ * @throws {PipelineExecutionError} If the number of unmatched expected and available parameters does not match, or mapping is ambiguous.
4377
4388
  * @private within the repository used in `createPipelineExecutor`
4378
4389
  */
4379
4390
  function mapAvailableToExpectedParameters(options) {
@@ -5093,7 +5104,11 @@
5093
5104
  */
5094
5105
 
5095
5106
  /**
5096
- * @@@
5107
+ * Executes a pipeline task that requires mapping or iterating over subvalues of a parameter (such as rows in a CSV).
5108
+ * Handles format and subformat resolution, error handling, and progress reporting.
5109
+ *
5110
+ * @param options - Options for execution, including task details and progress callback.
5111
+ * @returns The result of the subvalue mapping or execution attempts.
5097
5112
  *
5098
5113
  * @private internal utility of `createPipelineExecutor`
5099
5114
  */
@@ -5158,15 +5173,11 @@
5158
5173
  settings: formatSettings,
5159
5174
  onProgress(partialResultString) {
5160
5175
  return onProgress(Object.freeze({
5161
- [task.resultingParameterName]:
5162
- // <- Note: [๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ง] No need to detect parameter collision here because pipeline checks logic consistency during construction
5163
- partialResultString,
5176
+ [task.resultingParameterName]: partialResultString,
5164
5177
  }));
5165
5178
  },
5166
- async mapCallback(subparameters, index) {
5179
+ async mapCallback(subparameters, index, length) {
5167
5180
  let mappedParameters;
5168
- // TODO: [๐Ÿคนโ€โ™‚๏ธ][๐Ÿช‚] Limit to N concurrent executions
5169
- // TODO: When done [๐Ÿš] Report progress also for each subvalue here
5170
5181
  try {
5171
5182
  mappedParameters = mapAvailableToExpectedParameters({
5172
5183
  expectedParameters: Object.fromEntries(task.foreach.inputSubparameterNames.map((subparameterName) => [subparameterName, null])),
@@ -5177,32 +5188,52 @@
5177
5188
  if (!(error instanceof PipelineExecutionError)) {
5178
5189
  throw error;
5179
5190
  }
5180
- throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5181
- ${error.message}
5191
+ const highLevelError = new PipelineExecutionError(spaceTrim__default["default"]((block) => `
5192
+ ${error.message}
5182
5193
 
5183
- This is error in FOREACH command
5184
- You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5194
+ This is error in FOREACH command when mapping data
5195
+ You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command
5185
5196
 
5186
- ${block(pipelineIdentification)}
5187
- Subparameter index: ${index}
5188
- `));
5197
+ ${block(pipelineIdentification)}
5198
+ Subparameter index: ${index}
5199
+ `));
5200
+ if (length > BIG_DATASET_TRESHOLD) {
5201
+ console.error(highLevelError);
5202
+ return '~';
5203
+ }
5204
+ throw highLevelError;
5189
5205
  }
5190
5206
  const allSubparameters = {
5191
5207
  ...parameters,
5192
5208
  ...mappedParameters,
5193
5209
  };
5194
- // 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
5195
5210
  Object.freeze(allSubparameters);
5196
- const subresultString = await executeAttempts({
5197
- ...options,
5198
- priority: priority + index,
5199
- parameters: allSubparameters,
5200
- pipelineIdentification: spaceTrim__default["default"]((block) => `
5201
- ${block(pipelineIdentification)}
5202
- Subparameter index: ${index}
5203
- `),
5204
- });
5205
- return subresultString;
5211
+ try {
5212
+ const subresultString = await executeAttempts({
5213
+ ...options,
5214
+ priority: priority + index,
5215
+ parameters: allSubparameters,
5216
+ pipelineIdentification: spaceTrim__default["default"]((block) => `
5217
+ ${block(pipelineIdentification)}
5218
+ Subparameter index: ${index}
5219
+ `),
5220
+ });
5221
+ return subresultString;
5222
+ }
5223
+ catch (error) {
5224
+ if (length > BIG_DATASET_TRESHOLD) {
5225
+ console.error(spaceTrim__default["default"]((block) => `
5226
+ Error in FOREACH command:
5227
+
5228
+ ${block(pipelineIdentification)}
5229
+
5230
+ ${block(pipelineIdentification)}
5231
+ Subparameter index: ${index}
5232
+ `));
5233
+ return '~';
5234
+ }
5235
+ throw error;
5236
+ }
5206
5237
  },
5207
5238
  });
5208
5239
  return resultString;
@@ -5337,7 +5368,11 @@
5337
5368
  */
5338
5369
 
5339
5370
  /**
5340
- * @@@
5371
+ * Retrieves all reserved parameters for a given pipeline task, including context, knowledge, examples, and metadata.
5372
+ * Ensures all reserved parameters are defined and throws if any are missing.
5373
+ *
5374
+ * @param options - Options including tools, pipeline, task, and context.
5375
+ * @returns An object containing all reserved parameters for the task.
5341
5376
  *
5342
5377
  * @private internal utility of `createPipelineExecutor`
5343
5378
  */
@@ -5370,7 +5405,10 @@
5370
5405
  }
5371
5406
 
5372
5407
  /**
5373
- * @@@
5408
+ * Executes a single task within a pipeline, handling parameter validation, error checking, and progress reporting.
5409
+ *
5410
+ * @param options - Options for execution, including the task, pipeline, parameters, and callbacks.
5411
+ * @returns The output parameters produced by the task.
5374
5412
  *
5375
5413
  * @private internal utility of `createPipelineExecutor`
5376
5414
  */
@@ -5504,9 +5542,12 @@
5504
5542
  }
5505
5543
 
5506
5544
  /**
5507
- * @@@
5545
+ * Executes an entire pipeline, resolving tasks in dependency order, handling errors, and reporting progress.
5546
+ *
5547
+ * Note: This is not a `PipelineExecutor` (which is bound to a single pipeline), but a utility function used by `createPipelineExecutor` to create a `PipelineExecutor`.
5508
5548
  *
5509
- * Note: This is not a `PipelineExecutor` (which is binded with one exact pipeline), but a utility function of `createPipelineExecutor` which creates `PipelineExecutor`
5549
+ * @param options - Options for execution, including input parameters, pipeline, and callbacks.
5550
+ * @returns The result of the pipeline execution, including output parameters, errors, and usage statistics.
5510
5551
  *
5511
5552
  * @private internal utility of `createPipelineExecutor`
5512
5553
  */