@promptbook/documents 0.89.0-1 → 0.89.0-2

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 (24) hide show
  1. package/esm/index.es.js +108 -79
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +6 -4
  5. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  6. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  7. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  8. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  9. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  10. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  11. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  12. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  13. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  14. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  16. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  17. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  18. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  19. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  20. package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
  21. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  22. package/package.json +2 -2
  23. package/umd/index.umd.js +108 -79
  24. 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.89.0-1';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
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
@@ -432,6 +432,7 @@ function $execCommand(options) {
432
432
  }
433
433
  else {
434
434
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
435
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
435
436
  resolve('Command exceeded time limit');
436
437
  }
437
438
  });
@@ -457,6 +458,7 @@ function $execCommand(options) {
457
458
  output.push(stderr.toString());
458
459
  if (isVerbose && stderr.toString().trim()) {
459
460
  console.warn(stderr.toString());
461
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
460
462
  }
461
463
  });
462
464
  const finishWithCode = (code) => {
@@ -468,6 +470,7 @@ function $execCommand(options) {
468
470
  else {
469
471
  if (isVerbose) {
470
472
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
473
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
471
474
  }
472
475
  resolve(spaceTrim(output.join('\n')));
473
476
  }
@@ -489,6 +492,7 @@ function $execCommand(options) {
489
492
  else {
490
493
  if (isVerbose) {
491
494
  console.warn(error);
495
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
492
496
  }
493
497
  resolve(spaceTrim(output.join('\n')));
494
498
  }
@@ -2467,6 +2471,7 @@ function assertsTaskSuccessful(executionResult) {
2467
2471
  const { isSuccessful, errors, warnings } = executionResult;
2468
2472
  for (const warning of warnings) {
2469
2473
  console.warn(warning.message);
2474
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2470
2475
  }
2471
2476
  if (isSuccessful === true) {
2472
2477
  return;
@@ -2645,30 +2650,42 @@ async function forEachAsync(array, options, callbackfunction) {
2645
2650
  await Promise.all(tasks);
2646
2651
  }
2647
2652
 
2653
+ /**
2654
+ * Represents the uncertain value
2655
+ *
2656
+ * @public exported from `@promptbook/core`
2657
+ */
2658
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2659
+ /**
2660
+ * Represents the uncertain value
2661
+ *
2662
+ * @public exported from `@promptbook/core`
2663
+ */
2664
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2648
2665
  /**
2649
2666
  * Represents the usage with no resources consumed
2650
2667
  *
2651
2668
  * @public exported from `@promptbook/core`
2652
2669
  */
2653
2670
  const ZERO_USAGE = $deepFreeze({
2654
- price: { value: 0 },
2671
+ price: ZERO_VALUE,
2655
2672
  input: {
2656
- tokensCount: { value: 0 },
2657
- charactersCount: { value: 0 },
2658
- wordsCount: { value: 0 },
2659
- sentencesCount: { value: 0 },
2660
- linesCount: { value: 0 },
2661
- paragraphsCount: { value: 0 },
2662
- pagesCount: { value: 0 },
2673
+ tokensCount: ZERO_VALUE,
2674
+ charactersCount: ZERO_VALUE,
2675
+ wordsCount: ZERO_VALUE,
2676
+ sentencesCount: ZERO_VALUE,
2677
+ linesCount: ZERO_VALUE,
2678
+ paragraphsCount: ZERO_VALUE,
2679
+ pagesCount: ZERO_VALUE,
2663
2680
  },
2664
2681
  output: {
2665
- tokensCount: { value: 0 },
2666
- charactersCount: { value: 0 },
2667
- wordsCount: { value: 0 },
2668
- sentencesCount: { value: 0 },
2669
- linesCount: { value: 0 },
2670
- paragraphsCount: { value: 0 },
2671
- pagesCount: { value: 0 },
2682
+ tokensCount: ZERO_VALUE,
2683
+ charactersCount: ZERO_VALUE,
2684
+ wordsCount: ZERO_VALUE,
2685
+ sentencesCount: ZERO_VALUE,
2686
+ linesCount: ZERO_VALUE,
2687
+ paragraphsCount: ZERO_VALUE,
2688
+ pagesCount: ZERO_VALUE,
2672
2689
  },
2673
2690
  });
2674
2691
  /**
@@ -2677,24 +2694,24 @@ const ZERO_USAGE = $deepFreeze({
2677
2694
  * @public exported from `@promptbook/core`
2678
2695
  */
2679
2696
  $deepFreeze({
2680
- price: { value: 0, isUncertain: true },
2697
+ price: UNCERTAIN_ZERO_VALUE,
2681
2698
  input: {
2682
- tokensCount: { value: 0, isUncertain: true },
2683
- charactersCount: { value: 0, isUncertain: true },
2684
- wordsCount: { value: 0, isUncertain: true },
2685
- sentencesCount: { value: 0, isUncertain: true },
2686
- linesCount: { value: 0, isUncertain: true },
2687
- paragraphsCount: { value: 0, isUncertain: true },
2688
- pagesCount: { value: 0, isUncertain: true },
2699
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2700
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2701
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2702
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2703
+ linesCount: UNCERTAIN_ZERO_VALUE,
2704
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2705
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2689
2706
  },
2690
2707
  output: {
2691
- tokensCount: { value: 0, isUncertain: true },
2692
- charactersCount: { value: 0, isUncertain: true },
2693
- wordsCount: { value: 0, isUncertain: true },
2694
- sentencesCount: { value: 0, isUncertain: true },
2695
- linesCount: { value: 0, isUncertain: true },
2696
- paragraphsCount: { value: 0, isUncertain: true },
2697
- pagesCount: { value: 0, isUncertain: true },
2708
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2709
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2710
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2711
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2712
+ linesCount: UNCERTAIN_ZERO_VALUE,
2713
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2714
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2698
2715
  },
2699
2716
  });
2700
2717
  /**
@@ -2982,6 +2999,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2982
2999
  `);
2983
3000
  // TODO: [🟥] Detect browser / node and make it colorfull
2984
3001
  console.warn(warningMessage);
3002
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2985
3003
  /*
2986
3004
  return {
2987
3005
  async listModels() {
@@ -3529,63 +3547,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3529
3547
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3530
3548
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3531
3549
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3532
- let partialPieces = null;
3533
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3534
- const scrapers = arrayableToArray(tools.scrapers);
3535
- for (const scraper of scrapers) {
3536
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3537
- // <- TODO: [🦔] Implement mime-type wildcards
3538
- ) {
3539
- continue;
3540
- }
3541
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3542
- if (partialPiecesUnchecked !== null) {
3543
- partialPieces = [...partialPiecesUnchecked];
3544
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3545
- break;
3546
- }
3547
- console.warn(spaceTrim$1((block) => `
3548
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3550
+ try {
3551
+ let partialPieces = null;
3552
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3553
+ const scrapers = arrayableToArray(tools.scrapers);
3554
+ for (const scraper of scrapers) {
3555
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3556
+ // <- TODO: [🦔] Implement mime-type wildcards
3557
+ ) {
3558
+ continue;
3559
+ }
3560
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3561
+ if (partialPiecesUnchecked !== null) {
3562
+ partialPieces = [...partialPiecesUnchecked];
3563
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3564
+ break;
3565
+ }
3566
+ console.warn(spaceTrim$1((block) => `
3567
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3549
3568
 
3550
- The source:
3551
- ${block(knowledgeSource.knowledgeSourceContent
3552
- .split('\n')
3553
- .map((line) => `> ${line}`)
3554
- .join('\n'))}
3569
+ The source:
3570
+ ${block(knowledgeSource.knowledgeSourceContent
3571
+ .split('\n')
3572
+ .map((line) => `> ${line}`)
3573
+ .join('\n'))}
3555
3574
 
3556
- ${block($registeredScrapersMessage(scrapers))}
3575
+ ${block($registeredScrapersMessage(scrapers))}
3557
3576
 
3558
3577
 
3559
- `));
3560
- }
3561
- if (partialPieces === null) {
3562
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3563
- Cannot scrape knowledge
3578
+ `));
3579
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3580
+ }
3581
+ if (partialPieces === null) {
3582
+ throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3583
+ Cannot scrape knowledge
3564
3584
 
3565
- The source:
3566
- > ${block(knowledgeSource.knowledgeSourceContent
3567
- .split('\n')
3568
- .map((line) => `> ${line}`)
3569
- .join('\n'))}
3585
+ The source:
3586
+ > ${block(knowledgeSource.knowledgeSourceContent
3587
+ .split('\n')
3588
+ .map((line) => `> ${line}`)
3589
+ .join('\n'))}
3570
3590
 
3571
- No scraper found for the mime type "${sourceHandler.mimeType}"
3591
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3572
3592
 
3573
- ${block($registeredScrapersMessage(scrapers))}
3593
+ ${block($registeredScrapersMessage(scrapers))}
3574
3594
 
3575
3595
 
3576
- `));
3596
+ `));
3597
+ }
3598
+ const pieces = partialPieces.map((partialPiece) => ({
3599
+ ...partialPiece,
3600
+ sources: [
3601
+ {
3602
+ name: knowledgeSource.name,
3603
+ // line, column <- TODO: [☀]
3604
+ // <- TODO: [❎]
3605
+ },
3606
+ ],
3607
+ }));
3608
+ knowledgePreparedUnflatten[index] = pieces;
3609
+ }
3610
+ catch (error) {
3611
+ if (!(error instanceof Error)) {
3612
+ throw error;
3613
+ }
3614
+ console.warn(error);
3615
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3577
3616
  }
3578
- const pieces = partialPieces.map((partialPiece) => ({
3579
- ...partialPiece,
3580
- sources: [
3581
- {
3582
- name: knowledgeSource.name,
3583
- // line, column <- TODO: [☀]
3584
- // <- TODO: [❎]
3585
- },
3586
- ],
3587
- }));
3588
- knowledgePreparedUnflatten[index] = pieces;
3589
3617
  });
3590
3618
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3591
3619
  return knowledgePrepared;
@@ -4003,7 +4031,7 @@ function extractParameterNamesFromTask(task) {
4003
4031
  if (parameterNames.has(subparameterName)) {
4004
4032
  parameterNames.delete(subparameterName);
4005
4033
  parameterNames.add(foreach.parameterName);
4006
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
4034
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
4007
4035
  }
4008
4036
  }
4009
4037
  }
@@ -5599,6 +5627,7 @@ function createPipelineExecutor(options) {
5599
5627
 
5600
5628
  @see more at https://ptbk.io/prepare-pipeline
5601
5629
  `));
5630
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5602
5631
  }
5603
5632
  let runCount = 0;
5604
5633
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {