@promptbook/documents 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 +108 -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 +108 -79
  25. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
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
@@ -430,6 +430,7 @@
430
430
  }
431
431
  else {
432
432
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
433
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
433
434
  resolve('Command exceeded time limit');
434
435
  }
435
436
  });
@@ -455,6 +456,7 @@
455
456
  output.push(stderr.toString());
456
457
  if (isVerbose && stderr.toString().trim()) {
457
458
  console.warn(stderr.toString());
459
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
458
460
  }
459
461
  });
460
462
  const finishWithCode = (code) => {
@@ -466,6 +468,7 @@
466
468
  else {
467
469
  if (isVerbose) {
468
470
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
471
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
469
472
  }
470
473
  resolve(spaceTrim.spaceTrim(output.join('\n')));
471
474
  }
@@ -487,6 +490,7 @@
487
490
  else {
488
491
  if (isVerbose) {
489
492
  console.warn(error);
493
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
490
494
  }
491
495
  resolve(spaceTrim.spaceTrim(output.join('\n')));
492
496
  }
@@ -2465,6 +2469,7 @@
2465
2469
  const { isSuccessful, errors, warnings } = executionResult;
2466
2470
  for (const warning of warnings) {
2467
2471
  console.warn(warning.message);
2472
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2468
2473
  }
2469
2474
  if (isSuccessful === true) {
2470
2475
  return;
@@ -2643,30 +2648,42 @@
2643
2648
  await Promise.all(tasks);
2644
2649
  }
2645
2650
 
2651
+ /**
2652
+ * Represents the uncertain value
2653
+ *
2654
+ * @public exported from `@promptbook/core`
2655
+ */
2656
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2657
+ /**
2658
+ * Represents the uncertain value
2659
+ *
2660
+ * @public exported from `@promptbook/core`
2661
+ */
2662
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2646
2663
  /**
2647
2664
  * Represents the usage with no resources consumed
2648
2665
  *
2649
2666
  * @public exported from `@promptbook/core`
2650
2667
  */
2651
2668
  const ZERO_USAGE = $deepFreeze({
2652
- price: { value: 0 },
2669
+ price: ZERO_VALUE,
2653
2670
  input: {
2654
- tokensCount: { value: 0 },
2655
- charactersCount: { value: 0 },
2656
- wordsCount: { value: 0 },
2657
- sentencesCount: { value: 0 },
2658
- linesCount: { value: 0 },
2659
- paragraphsCount: { value: 0 },
2660
- pagesCount: { value: 0 },
2671
+ tokensCount: ZERO_VALUE,
2672
+ charactersCount: ZERO_VALUE,
2673
+ wordsCount: ZERO_VALUE,
2674
+ sentencesCount: ZERO_VALUE,
2675
+ linesCount: ZERO_VALUE,
2676
+ paragraphsCount: ZERO_VALUE,
2677
+ pagesCount: ZERO_VALUE,
2661
2678
  },
2662
2679
  output: {
2663
- tokensCount: { value: 0 },
2664
- charactersCount: { value: 0 },
2665
- wordsCount: { value: 0 },
2666
- sentencesCount: { value: 0 },
2667
- linesCount: { value: 0 },
2668
- paragraphsCount: { value: 0 },
2669
- pagesCount: { value: 0 },
2680
+ tokensCount: ZERO_VALUE,
2681
+ charactersCount: ZERO_VALUE,
2682
+ wordsCount: ZERO_VALUE,
2683
+ sentencesCount: ZERO_VALUE,
2684
+ linesCount: ZERO_VALUE,
2685
+ paragraphsCount: ZERO_VALUE,
2686
+ pagesCount: ZERO_VALUE,
2670
2687
  },
2671
2688
  });
2672
2689
  /**
@@ -2675,24 +2692,24 @@
2675
2692
  * @public exported from `@promptbook/core`
2676
2693
  */
2677
2694
  $deepFreeze({
2678
- price: { value: 0, isUncertain: true },
2695
+ price: UNCERTAIN_ZERO_VALUE,
2679
2696
  input: {
2680
- tokensCount: { value: 0, isUncertain: true },
2681
- charactersCount: { value: 0, isUncertain: true },
2682
- wordsCount: { value: 0, isUncertain: true },
2683
- sentencesCount: { value: 0, isUncertain: true },
2684
- linesCount: { value: 0, isUncertain: true },
2685
- paragraphsCount: { value: 0, isUncertain: true },
2686
- pagesCount: { value: 0, isUncertain: true },
2697
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2698
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2699
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2700
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2701
+ linesCount: UNCERTAIN_ZERO_VALUE,
2702
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2703
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2687
2704
  },
2688
2705
  output: {
2689
- tokensCount: { value: 0, isUncertain: true },
2690
- charactersCount: { value: 0, isUncertain: true },
2691
- wordsCount: { value: 0, isUncertain: true },
2692
- sentencesCount: { value: 0, isUncertain: true },
2693
- linesCount: { value: 0, isUncertain: true },
2694
- paragraphsCount: { value: 0, isUncertain: true },
2695
- pagesCount: { value: 0, isUncertain: true },
2706
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2707
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2708
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2709
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2710
+ linesCount: UNCERTAIN_ZERO_VALUE,
2711
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2712
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2696
2713
  },
2697
2714
  });
2698
2715
  /**
@@ -2980,6 +2997,7 @@
2980
2997
  `);
2981
2998
  // TODO: [🟥] Detect browser / node and make it colorfull
2982
2999
  console.warn(warningMessage);
3000
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2983
3001
  /*
2984
3002
  return {
2985
3003
  async listModels() {
@@ -3527,63 +3545,73 @@
3527
3545
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3528
3546
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3529
3547
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3530
- let partialPieces = null;
3531
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3532
- const scrapers = arrayableToArray(tools.scrapers);
3533
- for (const scraper of scrapers) {
3534
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3535
- // <- TODO: [🦔] Implement mime-type wildcards
3536
- ) {
3537
- continue;
3538
- }
3539
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3540
- if (partialPiecesUnchecked !== null) {
3541
- partialPieces = [...partialPiecesUnchecked];
3542
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3543
- break;
3544
- }
3545
- console.warn(spaceTrim__default["default"]((block) => `
3546
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3548
+ try {
3549
+ let partialPieces = null;
3550
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3551
+ const scrapers = arrayableToArray(tools.scrapers);
3552
+ for (const scraper of scrapers) {
3553
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3554
+ // <- TODO: [🦔] Implement mime-type wildcards
3555
+ ) {
3556
+ continue;
3557
+ }
3558
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3559
+ if (partialPiecesUnchecked !== null) {
3560
+ partialPieces = [...partialPiecesUnchecked];
3561
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3562
+ break;
3563
+ }
3564
+ console.warn(spaceTrim__default["default"]((block) => `
3565
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3547
3566
 
3548
- The source:
3549
- ${block(knowledgeSource.knowledgeSourceContent
3550
- .split('\n')
3551
- .map((line) => `> ${line}`)
3552
- .join('\n'))}
3567
+ The source:
3568
+ ${block(knowledgeSource.knowledgeSourceContent
3569
+ .split('\n')
3570
+ .map((line) => `> ${line}`)
3571
+ .join('\n'))}
3553
3572
 
3554
- ${block($registeredScrapersMessage(scrapers))}
3573
+ ${block($registeredScrapersMessage(scrapers))}
3555
3574
 
3556
3575
 
3557
- `));
3558
- }
3559
- if (partialPieces === null) {
3560
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3561
- Cannot scrape knowledge
3576
+ `));
3577
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3578
+ }
3579
+ if (partialPieces === null) {
3580
+ throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3581
+ Cannot scrape knowledge
3562
3582
 
3563
- The source:
3564
- > ${block(knowledgeSource.knowledgeSourceContent
3565
- .split('\n')
3566
- .map((line) => `> ${line}`)
3567
- .join('\n'))}
3583
+ The source:
3584
+ > ${block(knowledgeSource.knowledgeSourceContent
3585
+ .split('\n')
3586
+ .map((line) => `> ${line}`)
3587
+ .join('\n'))}
3568
3588
 
3569
- No scraper found for the mime type "${sourceHandler.mimeType}"
3589
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3570
3590
 
3571
- ${block($registeredScrapersMessage(scrapers))}
3591
+ ${block($registeredScrapersMessage(scrapers))}
3572
3592
 
3573
3593
 
3574
- `));
3594
+ `));
3595
+ }
3596
+ const pieces = partialPieces.map((partialPiece) => ({
3597
+ ...partialPiece,
3598
+ sources: [
3599
+ {
3600
+ name: knowledgeSource.name,
3601
+ // line, column <- TODO: [☀]
3602
+ // <- TODO: [❎]
3603
+ },
3604
+ ],
3605
+ }));
3606
+ knowledgePreparedUnflatten[index] = pieces;
3607
+ }
3608
+ catch (error) {
3609
+ if (!(error instanceof Error)) {
3610
+ throw error;
3611
+ }
3612
+ console.warn(error);
3613
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3575
3614
  }
3576
- const pieces = partialPieces.map((partialPiece) => ({
3577
- ...partialPiece,
3578
- sources: [
3579
- {
3580
- name: knowledgeSource.name,
3581
- // line, column <- TODO: [☀]
3582
- // <- TODO: [❎]
3583
- },
3584
- ],
3585
- }));
3586
- knowledgePreparedUnflatten[index] = pieces;
3587
3615
  });
3588
3616
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3589
3617
  return knowledgePrepared;
@@ -4001,7 +4029,7 @@
4001
4029
  if (parameterNames.has(subparameterName)) {
4002
4030
  parameterNames.delete(subparameterName);
4003
4031
  parameterNames.add(foreach.parameterName);
4004
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
4032
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
4005
4033
  }
4006
4034
  }
4007
4035
  }
@@ -5597,6 +5625,7 @@
5597
5625
 
5598
5626
  @see more at https://ptbk.io/prepare-pipeline
5599
5627
  `));
5628
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5600
5629
  }
5601
5630
  let runCount = 0;
5602
5631
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {