@promptbook/website-crawler 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 +104 -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 +105 -80
  24. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2425,6 +2425,7 @@ function assertsTaskSuccessful(executionResult) {
2425
2425
  const { isSuccessful, errors, warnings } = executionResult;
2426
2426
  for (const warning of warnings) {
2427
2427
  console.warn(warning.message);
2428
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2428
2429
  }
2429
2430
  if (isSuccessful === true) {
2430
2431
  return;
@@ -2603,30 +2604,42 @@ async function forEachAsync(array, options, callbackfunction) {
2603
2604
  await Promise.all(tasks);
2604
2605
  }
2605
2606
 
2607
+ /**
2608
+ * Represents the uncertain value
2609
+ *
2610
+ * @public exported from `@promptbook/core`
2611
+ */
2612
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2613
+ /**
2614
+ * Represents the uncertain value
2615
+ *
2616
+ * @public exported from `@promptbook/core`
2617
+ */
2618
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2606
2619
  /**
2607
2620
  * Represents the usage with no resources consumed
2608
2621
  *
2609
2622
  * @public exported from `@promptbook/core`
2610
2623
  */
2611
2624
  const ZERO_USAGE = $deepFreeze({
2612
- price: { value: 0 },
2625
+ price: ZERO_VALUE,
2613
2626
  input: {
2614
- tokensCount: { value: 0 },
2615
- charactersCount: { value: 0 },
2616
- wordsCount: { value: 0 },
2617
- sentencesCount: { value: 0 },
2618
- linesCount: { value: 0 },
2619
- paragraphsCount: { value: 0 },
2620
- pagesCount: { value: 0 },
2627
+ tokensCount: ZERO_VALUE,
2628
+ charactersCount: ZERO_VALUE,
2629
+ wordsCount: ZERO_VALUE,
2630
+ sentencesCount: ZERO_VALUE,
2631
+ linesCount: ZERO_VALUE,
2632
+ paragraphsCount: ZERO_VALUE,
2633
+ pagesCount: ZERO_VALUE,
2621
2634
  },
2622
2635
  output: {
2623
- tokensCount: { value: 0 },
2624
- charactersCount: { value: 0 },
2625
- wordsCount: { value: 0 },
2626
- sentencesCount: { value: 0 },
2627
- linesCount: { value: 0 },
2628
- paragraphsCount: { value: 0 },
2629
- pagesCount: { value: 0 },
2636
+ tokensCount: ZERO_VALUE,
2637
+ charactersCount: ZERO_VALUE,
2638
+ wordsCount: ZERO_VALUE,
2639
+ sentencesCount: ZERO_VALUE,
2640
+ linesCount: ZERO_VALUE,
2641
+ paragraphsCount: ZERO_VALUE,
2642
+ pagesCount: ZERO_VALUE,
2630
2643
  },
2631
2644
  });
2632
2645
  /**
@@ -2635,24 +2648,24 @@ const ZERO_USAGE = $deepFreeze({
2635
2648
  * @public exported from `@promptbook/core`
2636
2649
  */
2637
2650
  $deepFreeze({
2638
- price: { value: 0, isUncertain: true },
2651
+ price: UNCERTAIN_ZERO_VALUE,
2639
2652
  input: {
2640
- tokensCount: { value: 0, isUncertain: true },
2641
- charactersCount: { value: 0, isUncertain: true },
2642
- wordsCount: { value: 0, isUncertain: true },
2643
- sentencesCount: { value: 0, isUncertain: true },
2644
- linesCount: { value: 0, isUncertain: true },
2645
- paragraphsCount: { value: 0, isUncertain: true },
2646
- pagesCount: { value: 0, isUncertain: true },
2653
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2654
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2655
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2656
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2657
+ linesCount: UNCERTAIN_ZERO_VALUE,
2658
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2659
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2647
2660
  },
2648
2661
  output: {
2649
- tokensCount: { value: 0, isUncertain: true },
2650
- charactersCount: { value: 0, isUncertain: true },
2651
- wordsCount: { value: 0, isUncertain: true },
2652
- sentencesCount: { value: 0, isUncertain: true },
2653
- linesCount: { value: 0, isUncertain: true },
2654
- paragraphsCount: { value: 0, isUncertain: true },
2655
- pagesCount: { value: 0, isUncertain: true },
2662
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2663
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2664
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2665
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2666
+ linesCount: UNCERTAIN_ZERO_VALUE,
2667
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2668
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2656
2669
  },
2657
2670
  });
2658
2671
  /**
@@ -2940,6 +2953,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2940
2953
  `);
2941
2954
  // TODO: [🟥] Detect browser / node and make it colorfull
2942
2955
  console.warn(warningMessage);
2956
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2943
2957
  /*
2944
2958
  return {
2945
2959
  async listModels() {
@@ -3383,63 +3397,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3383
3397
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3384
3398
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3385
3399
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3386
- let partialPieces = null;
3387
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3388
- const scrapers = arrayableToArray(tools.scrapers);
3389
- for (const scraper of scrapers) {
3390
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3391
- // <- TODO: [🦔] Implement mime-type wildcards
3392
- ) {
3393
- continue;
3394
- }
3395
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3396
- if (partialPiecesUnchecked !== null) {
3397
- partialPieces = [...partialPiecesUnchecked];
3398
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3399
- break;
3400
- }
3401
- console.warn(spaceTrim$1((block) => `
3402
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3400
+ try {
3401
+ let partialPieces = null;
3402
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3403
+ const scrapers = arrayableToArray(tools.scrapers);
3404
+ for (const scraper of scrapers) {
3405
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3406
+ // <- TODO: [🦔] Implement mime-type wildcards
3407
+ ) {
3408
+ continue;
3409
+ }
3410
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3411
+ if (partialPiecesUnchecked !== null) {
3412
+ partialPieces = [...partialPiecesUnchecked];
3413
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3414
+ break;
3415
+ }
3416
+ console.warn(spaceTrim$1((block) => `
3417
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3403
3418
 
3404
- The source:
3405
- ${block(knowledgeSource.knowledgeSourceContent
3406
- .split('\n')
3407
- .map((line) => `> ${line}`)
3408
- .join('\n'))}
3419
+ The source:
3420
+ ${block(knowledgeSource.knowledgeSourceContent
3421
+ .split('\n')
3422
+ .map((line) => `> ${line}`)
3423
+ .join('\n'))}
3409
3424
 
3410
- ${block($registeredScrapersMessage(scrapers))}
3425
+ ${block($registeredScrapersMessage(scrapers))}
3411
3426
 
3412
3427
 
3413
- `));
3414
- }
3415
- if (partialPieces === null) {
3416
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3417
- Cannot scrape knowledge
3428
+ `));
3429
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3430
+ }
3431
+ if (partialPieces === null) {
3432
+ throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3433
+ Cannot scrape knowledge
3418
3434
 
3419
- The source:
3420
- > ${block(knowledgeSource.knowledgeSourceContent
3421
- .split('\n')
3422
- .map((line) => `> ${line}`)
3423
- .join('\n'))}
3435
+ The source:
3436
+ > ${block(knowledgeSource.knowledgeSourceContent
3437
+ .split('\n')
3438
+ .map((line) => `> ${line}`)
3439
+ .join('\n'))}
3424
3440
 
3425
- No scraper found for the mime type "${sourceHandler.mimeType}"
3441
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3426
3442
 
3427
- ${block($registeredScrapersMessage(scrapers))}
3443
+ ${block($registeredScrapersMessage(scrapers))}
3428
3444
 
3429
3445
 
3430
- `));
3446
+ `));
3447
+ }
3448
+ const pieces = partialPieces.map((partialPiece) => ({
3449
+ ...partialPiece,
3450
+ sources: [
3451
+ {
3452
+ name: knowledgeSource.name,
3453
+ // line, column <- TODO: [☀]
3454
+ // <- TODO: [❎]
3455
+ },
3456
+ ],
3457
+ }));
3458
+ knowledgePreparedUnflatten[index] = pieces;
3459
+ }
3460
+ catch (error) {
3461
+ if (!(error instanceof Error)) {
3462
+ throw error;
3463
+ }
3464
+ console.warn(error);
3465
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3431
3466
  }
3432
- const pieces = partialPieces.map((partialPiece) => ({
3433
- ...partialPiece,
3434
- sources: [
3435
- {
3436
- name: knowledgeSource.name,
3437
- // line, column <- TODO: [☀]
3438
- // <- TODO: [❎]
3439
- },
3440
- ],
3441
- }));
3442
- knowledgePreparedUnflatten[index] = pieces;
3443
3467
  });
3444
3468
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3445
3469
  return knowledgePrepared;
@@ -3857,7 +3881,7 @@ function extractParameterNamesFromTask(task) {
3857
3881
  if (parameterNames.has(subparameterName)) {
3858
3882
  parameterNames.delete(subparameterName);
3859
3883
  parameterNames.add(foreach.parameterName);
3860
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3884
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3861
3885
  }
3862
3886
  }
3863
3887
  }
@@ -5453,6 +5477,7 @@ function createPipelineExecutor(options) {
5453
5477
 
5454
5478
  @see more at https://ptbk.io/prepare-pipeline
5455
5479
  `));
5480
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5456
5481
  }
5457
5482
  let runCount = 0;
5458
5483
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {