@promptbook/website-crawler 0.88.0 → 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 (30) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +114 -82
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +16 -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 +9 -2
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
  17. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  19. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  20. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  21. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  22. package/esm/typings/src/playground/BrjappConnector.d.ts +67 -0
  23. package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
  24. package/esm/typings/src/playground/playground.d.ts +5 -0
  25. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
  26. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
  27. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +115 -83
  30. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/website-crawler`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
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.88.0';
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
  /**
@@ -2713,8 +2726,9 @@ function addUsage(...usageItems) {
2713
2726
  * @returns LLM tools with same functionality with added total cost counting
2714
2727
  * @public exported from `@promptbook/core`
2715
2728
  */
2716
- function countTotalUsage(llmTools) {
2729
+ function countUsage(llmTools) {
2717
2730
  let totalUsage = ZERO_USAGE;
2731
+ const spending = new Subject();
2718
2732
  const proxyTools = {
2719
2733
  get title() {
2720
2734
  // TODO: [🧠] Maybe put here some suffix
@@ -2724,12 +2738,15 @@ function countTotalUsage(llmTools) {
2724
2738
  // TODO: [🧠] Maybe put here some suffix
2725
2739
  return llmTools.description;
2726
2740
  },
2727
- async checkConfiguration() {
2741
+ checkConfiguration() {
2728
2742
  return /* not await */ llmTools.checkConfiguration();
2729
2743
  },
2730
2744
  listModels() {
2731
2745
  return /* not await */ llmTools.listModels();
2732
2746
  },
2747
+ spending() {
2748
+ return spending.asObservable();
2749
+ },
2733
2750
  getTotalUsage() {
2734
2751
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2735
2752
  return totalUsage;
@@ -2740,6 +2757,7 @@ function countTotalUsage(llmTools) {
2740
2757
  // console.info('[🚕] callChatModel through countTotalUsage');
2741
2758
  const promptResult = await llmTools.callChatModel(prompt);
2742
2759
  totalUsage = addUsage(totalUsage, promptResult.usage);
2760
+ spending.next(promptResult.usage);
2743
2761
  return promptResult;
2744
2762
  };
2745
2763
  }
@@ -2748,6 +2766,7 @@ function countTotalUsage(llmTools) {
2748
2766
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2749
2767
  const promptResult = await llmTools.callCompletionModel(prompt);
2750
2768
  totalUsage = addUsage(totalUsage, promptResult.usage);
2769
+ spending.next(promptResult.usage);
2751
2770
  return promptResult;
2752
2771
  };
2753
2772
  }
@@ -2756,6 +2775,7 @@ function countTotalUsage(llmTools) {
2756
2775
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2757
2776
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2758
2777
  totalUsage = addUsage(totalUsage, promptResult.usage);
2778
+ spending.next(promptResult.usage);
2759
2779
  return promptResult;
2760
2780
  };
2761
2781
  }
@@ -2933,6 +2953,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2933
2953
  `);
2934
2954
  // TODO: [🟥] Detect browser / node and make it colorfull
2935
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
2936
2957
  /*
2937
2958
  return {
2938
2959
  async listModels() {
@@ -3376,63 +3397,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3376
3397
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3377
3398
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3378
3399
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3379
- let partialPieces = null;
3380
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3381
- const scrapers = arrayableToArray(tools.scrapers);
3382
- for (const scraper of scrapers) {
3383
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3384
- // <- TODO: [🦔] Implement mime-type wildcards
3385
- ) {
3386
- continue;
3387
- }
3388
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3389
- if (partialPiecesUnchecked !== null) {
3390
- partialPieces = [...partialPiecesUnchecked];
3391
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3392
- break;
3393
- }
3394
- console.warn(spaceTrim$1((block) => `
3395
- 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}".
3396
3418
 
3397
- The source:
3398
- ${block(knowledgeSource.knowledgeSourceContent
3399
- .split('\n')
3400
- .map((line) => `> ${line}`)
3401
- .join('\n'))}
3419
+ The source:
3420
+ ${block(knowledgeSource.knowledgeSourceContent
3421
+ .split('\n')
3422
+ .map((line) => `> ${line}`)
3423
+ .join('\n'))}
3402
3424
 
3403
- ${block($registeredScrapersMessage(scrapers))}
3425
+ ${block($registeredScrapersMessage(scrapers))}
3404
3426
 
3405
3427
 
3406
- `));
3407
- }
3408
- if (partialPieces === null) {
3409
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3410
- 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
3411
3434
 
3412
- The source:
3413
- > ${block(knowledgeSource.knowledgeSourceContent
3414
- .split('\n')
3415
- .map((line) => `> ${line}`)
3416
- .join('\n'))}
3435
+ The source:
3436
+ > ${block(knowledgeSource.knowledgeSourceContent
3437
+ .split('\n')
3438
+ .map((line) => `> ${line}`)
3439
+ .join('\n'))}
3417
3440
 
3418
- No scraper found for the mime type "${sourceHandler.mimeType}"
3441
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3419
3442
 
3420
- ${block($registeredScrapersMessage(scrapers))}
3443
+ ${block($registeredScrapersMessage(scrapers))}
3421
3444
 
3422
3445
 
3423
- `));
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
3424
3466
  }
3425
- const pieces = partialPieces.map((partialPiece) => ({
3426
- ...partialPiece,
3427
- sources: [
3428
- {
3429
- name: knowledgeSource.name,
3430
- // line, column <- TODO: [☀]
3431
- // <- TODO: [❎]
3432
- },
3433
- ],
3434
- }));
3435
- knowledgePreparedUnflatten[index] = pieces;
3436
3467
  });
3437
3468
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3438
3469
  return knowledgePrepared;
@@ -3538,7 +3569,7 @@ async function preparePipeline(pipeline, tools, options) {
3538
3569
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3539
3570
  const _llms = arrayableToArray(tools.llm);
3540
3571
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3541
- const llmToolsWithUsage = countTotalUsage(llmTools);
3572
+ const llmToolsWithUsage = countUsage(llmTools);
3542
3573
  // <- TODO: [🌯]
3543
3574
  /*
3544
3575
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -3850,7 +3881,7 @@ function extractParameterNamesFromTask(task) {
3850
3881
  if (parameterNames.has(subparameterName)) {
3851
3882
  parameterNames.delete(subparameterName);
3852
3883
  parameterNames.add(foreach.parameterName);
3853
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3884
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3854
3885
  }
3855
3886
  }
3856
3887
  }
@@ -5446,6 +5477,7 @@ function createPipelineExecutor(options) {
5446
5477
 
5447
5478
  @see more at https://ptbk.io/prepare-pipeline
5448
5479
  `));
5480
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5449
5481
  }
5450
5482
  let runCount = 0;
5451
5483
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {