@promptbook/pdf 0.89.0-1 → 0.89.0-3

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 (25) hide show
  1. package/README.md +3 -1
  2. package/esm/index.es.js +104 -79
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +6 -4
  6. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  7. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  8. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  9. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  10. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  11. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  12. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  13. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  14. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  17. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  19. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  20. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  21. package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
  22. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  23. package/package.json +2 -2
  24. package/umd/index.umd.js +105 -80
  25. package/umd/index.umd.js.map +1 -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.89.0-1';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
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
@@ -2309,6 +2309,7 @@
2309
2309
  const { isSuccessful, errors, warnings } = executionResult;
2310
2310
  for (const warning of warnings) {
2311
2311
  console.warn(warning.message);
2312
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2312
2313
  }
2313
2314
  if (isSuccessful === true) {
2314
2315
  return;
@@ -2487,30 +2488,42 @@
2487
2488
  await Promise.all(tasks);
2488
2489
  }
2489
2490
 
2491
+ /**
2492
+ * Represents the uncertain value
2493
+ *
2494
+ * @public exported from `@promptbook/core`
2495
+ */
2496
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2497
+ /**
2498
+ * Represents the uncertain value
2499
+ *
2500
+ * @public exported from `@promptbook/core`
2501
+ */
2502
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2490
2503
  /**
2491
2504
  * Represents the usage with no resources consumed
2492
2505
  *
2493
2506
  * @public exported from `@promptbook/core`
2494
2507
  */
2495
2508
  const ZERO_USAGE = $deepFreeze({
2496
- price: { value: 0 },
2509
+ price: ZERO_VALUE,
2497
2510
  input: {
2498
- tokensCount: { value: 0 },
2499
- charactersCount: { value: 0 },
2500
- wordsCount: { value: 0 },
2501
- sentencesCount: { value: 0 },
2502
- linesCount: { value: 0 },
2503
- paragraphsCount: { value: 0 },
2504
- pagesCount: { value: 0 },
2511
+ tokensCount: ZERO_VALUE,
2512
+ charactersCount: ZERO_VALUE,
2513
+ wordsCount: ZERO_VALUE,
2514
+ sentencesCount: ZERO_VALUE,
2515
+ linesCount: ZERO_VALUE,
2516
+ paragraphsCount: ZERO_VALUE,
2517
+ pagesCount: ZERO_VALUE,
2505
2518
  },
2506
2519
  output: {
2507
- tokensCount: { value: 0 },
2508
- charactersCount: { value: 0 },
2509
- wordsCount: { value: 0 },
2510
- sentencesCount: { value: 0 },
2511
- linesCount: { value: 0 },
2512
- paragraphsCount: { value: 0 },
2513
- pagesCount: { value: 0 },
2520
+ tokensCount: ZERO_VALUE,
2521
+ charactersCount: ZERO_VALUE,
2522
+ wordsCount: ZERO_VALUE,
2523
+ sentencesCount: ZERO_VALUE,
2524
+ linesCount: ZERO_VALUE,
2525
+ paragraphsCount: ZERO_VALUE,
2526
+ pagesCount: ZERO_VALUE,
2514
2527
  },
2515
2528
  });
2516
2529
  /**
@@ -2519,24 +2532,24 @@
2519
2532
  * @public exported from `@promptbook/core`
2520
2533
  */
2521
2534
  $deepFreeze({
2522
- price: { value: 0, isUncertain: true },
2535
+ price: UNCERTAIN_ZERO_VALUE,
2523
2536
  input: {
2524
- tokensCount: { value: 0, isUncertain: true },
2525
- charactersCount: { value: 0, isUncertain: true },
2526
- wordsCount: { value: 0, isUncertain: true },
2527
- sentencesCount: { value: 0, isUncertain: true },
2528
- linesCount: { value: 0, isUncertain: true },
2529
- paragraphsCount: { value: 0, isUncertain: true },
2530
- pagesCount: { value: 0, isUncertain: true },
2537
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2538
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2539
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2540
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2541
+ linesCount: UNCERTAIN_ZERO_VALUE,
2542
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2543
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2531
2544
  },
2532
2545
  output: {
2533
- tokensCount: { value: 0, isUncertain: true },
2534
- charactersCount: { value: 0, isUncertain: true },
2535
- wordsCount: { value: 0, isUncertain: true },
2536
- sentencesCount: { value: 0, isUncertain: true },
2537
- linesCount: { value: 0, isUncertain: true },
2538
- paragraphsCount: { value: 0, isUncertain: true },
2539
- pagesCount: { value: 0, isUncertain: true },
2546
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2547
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2548
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2549
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2550
+ linesCount: UNCERTAIN_ZERO_VALUE,
2551
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2552
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2540
2553
  },
2541
2554
  });
2542
2555
  /**
@@ -2824,6 +2837,7 @@
2824
2837
  `);
2825
2838
  // TODO: [🟥] Detect browser / node and make it colorfull
2826
2839
  console.warn(warningMessage);
2840
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2827
2841
  /*
2828
2842
  return {
2829
2843
  async listModels() {
@@ -3381,63 +3395,73 @@
3381
3395
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3382
3396
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3383
3397
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3384
- let partialPieces = null;
3385
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3386
- const scrapers = arrayableToArray(tools.scrapers);
3387
- for (const scraper of scrapers) {
3388
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3389
- // <- TODO: [🦔] Implement mime-type wildcards
3390
- ) {
3391
- continue;
3392
- }
3393
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3394
- if (partialPiecesUnchecked !== null) {
3395
- partialPieces = [...partialPiecesUnchecked];
3396
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3397
- break;
3398
- }
3399
- console.warn(spaceTrim__default["default"]((block) => `
3400
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3398
+ try {
3399
+ let partialPieces = null;
3400
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3401
+ const scrapers = arrayableToArray(tools.scrapers);
3402
+ for (const scraper of scrapers) {
3403
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3404
+ // <- TODO: [🦔] Implement mime-type wildcards
3405
+ ) {
3406
+ continue;
3407
+ }
3408
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3409
+ if (partialPiecesUnchecked !== null) {
3410
+ partialPieces = [...partialPiecesUnchecked];
3411
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3412
+ break;
3413
+ }
3414
+ console.warn(spaceTrim__default["default"]((block) => `
3415
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3401
3416
 
3402
- The source:
3403
- ${block(knowledgeSource.knowledgeSourceContent
3404
- .split('\n')
3405
- .map((line) => `> ${line}`)
3406
- .join('\n'))}
3417
+ The source:
3418
+ ${block(knowledgeSource.knowledgeSourceContent
3419
+ .split('\n')
3420
+ .map((line) => `> ${line}`)
3421
+ .join('\n'))}
3407
3422
 
3408
- ${block($registeredScrapersMessage(scrapers))}
3423
+ ${block($registeredScrapersMessage(scrapers))}
3409
3424
 
3410
3425
 
3411
- `));
3412
- }
3413
- if (partialPieces === null) {
3414
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3415
- Cannot scrape knowledge
3416
-
3417
- The source:
3418
- > ${block(knowledgeSource.knowledgeSourceContent
3419
- .split('\n')
3420
- .map((line) => `> ${line}`)
3421
- .join('\n'))}
3426
+ `));
3427
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3428
+ }
3429
+ if (partialPieces === null) {
3430
+ throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3431
+ Cannot scrape knowledge
3432
+
3433
+ The source:
3434
+ > ${block(knowledgeSource.knowledgeSourceContent
3435
+ .split('\n')
3436
+ .map((line) => `> ${line}`)
3437
+ .join('\n'))}
3422
3438
 
3423
- No scraper found for the mime type "${sourceHandler.mimeType}"
3439
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3424
3440
 
3425
- ${block($registeredScrapersMessage(scrapers))}
3441
+ ${block($registeredScrapersMessage(scrapers))}
3426
3442
 
3427
3443
 
3428
- `));
3444
+ `));
3445
+ }
3446
+ const pieces = partialPieces.map((partialPiece) => ({
3447
+ ...partialPiece,
3448
+ sources: [
3449
+ {
3450
+ name: knowledgeSource.name,
3451
+ // line, column <- TODO: [☀]
3452
+ // <- TODO: [❎]
3453
+ },
3454
+ ],
3455
+ }));
3456
+ knowledgePreparedUnflatten[index] = pieces;
3457
+ }
3458
+ catch (error) {
3459
+ if (!(error instanceof Error)) {
3460
+ throw error;
3461
+ }
3462
+ console.warn(error);
3463
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3429
3464
  }
3430
- const pieces = partialPieces.map((partialPiece) => ({
3431
- ...partialPiece,
3432
- sources: [
3433
- {
3434
- name: knowledgeSource.name,
3435
- // line, column <- TODO: [☀]
3436
- // <- TODO: [❎]
3437
- },
3438
- ],
3439
- }));
3440
- knowledgePreparedUnflatten[index] = pieces;
3441
3465
  });
3442
3466
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3443
3467
  return knowledgePrepared;
@@ -3855,7 +3879,7 @@
3855
3879
  if (parameterNames.has(subparameterName)) {
3856
3880
  parameterNames.delete(subparameterName);
3857
3881
  parameterNames.add(foreach.parameterName);
3858
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3882
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3859
3883
  }
3860
3884
  }
3861
3885
  }
@@ -5451,6 +5475,7 @@
5451
5475
 
5452
5476
  @see more at https://ptbk.io/prepare-pipeline
5453
5477
  `));
5478
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5454
5479
  }
5455
5480
  let runCount = 0;
5456
5481
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {