@promptbook/documents 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 +118 -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 +118 -82
  30. package/umd/index.umd.js.map +1 -1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ts-node
2
+ export {};
3
+ /**
4
+ * Note: [⚫] Code in this file should never be published in any package
5
+ */
@@ -37,7 +37,8 @@ export type PromptbookServer_AnonymousIdentification = {
37
37
  /**
38
38
  * Identifier of the end user
39
39
  *
40
- * Note: this is passed to the certain model providers to identify misuse
40
+ * Note: This can be either some id or email or any other identifier
41
+ * Note: In anonymous mode, this is passed to the certain model providers to identify misuse
41
42
  * Note: In anonymous mode, there is no need to identify yourself, nor does it change the actual configuration of LLM Tools (unlike in application mode)
42
43
  */
43
44
  readonly userId?: string_user_id;
@@ -58,15 +58,27 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
58
58
  };
59
59
  export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
60
60
  /**
61
- * @@@
61
+ * Identifier of the application
62
+ *
63
+ * Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
64
+ * Note: This can be some id or some semantic name like "email-agent"
62
65
  */
63
66
  readonly appId: string_app_id | null;
64
67
  /**
65
- * @@@
68
+ * Identifier of the end user
69
+ *
70
+ * Note: This can be either some id or email or any other identifier
71
+ * Note: This is also passed to the certain model providers to identify misuse
66
72
  */
67
73
  readonly userId?: string_user_id;
68
74
  /**
69
- * @@@
75
+ * Token of the user to verify its identity
76
+ *
77
+ * Note: This is passed for example to `createLlmExecutionTools`
78
+ */
79
+ readonly userToken?: string_user_id;
80
+ /**
81
+ * Additional arbitrary options to identify the client or to pass custom metadata
70
82
  */
71
83
  readonly customOptions?: TCustomOptions;
72
84
  };
@@ -242,6 +242,12 @@ export type string_promptbook_documentation_url = `https://github.com/webgptorg/
242
242
  * For example `"towns.cz"`
243
243
  */
244
244
  export type string_domain = string;
245
+ /**
246
+ * Semantic helper
247
+ *
248
+ * For example `"https://*.pavolhejny.com/*"`
249
+ */
250
+ export type string_origin = string;
245
251
  /**
246
252
  * Semantic helper
247
253
  *
@@ -433,13 +439,13 @@ export type string_uuid = string & {
433
439
  *
434
440
  * @@@
435
441
  */
436
- export type string_app_id = id;
442
+ export type string_app_id = id | 'app';
437
443
  /**
438
444
  * End user identifier
439
445
  *
440
446
  * @@@
441
447
  */
442
- export type string_user_id = id;
448
+ export type string_user_id = id | string_email;
443
449
  /**
444
450
  * Semantic helper
445
451
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/documents",
3
- "version": "0.88.0",
3
+ "version": "0.89.0-2",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/documents.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.88.0"
50
+ "@promptbook/core": "0.89.0-2"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
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.88.0';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
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
  /**
@@ -2753,8 +2770,9 @@
2753
2770
  * @returns LLM tools with same functionality with added total cost counting
2754
2771
  * @public exported from `@promptbook/core`
2755
2772
  */
2756
- function countTotalUsage(llmTools) {
2773
+ function countUsage(llmTools) {
2757
2774
  let totalUsage = ZERO_USAGE;
2775
+ const spending = new rxjs.Subject();
2758
2776
  const proxyTools = {
2759
2777
  get title() {
2760
2778
  // TODO: [🧠] Maybe put here some suffix
@@ -2764,12 +2782,15 @@
2764
2782
  // TODO: [🧠] Maybe put here some suffix
2765
2783
  return llmTools.description;
2766
2784
  },
2767
- async checkConfiguration() {
2785
+ checkConfiguration() {
2768
2786
  return /* not await */ llmTools.checkConfiguration();
2769
2787
  },
2770
2788
  listModels() {
2771
2789
  return /* not await */ llmTools.listModels();
2772
2790
  },
2791
+ spending() {
2792
+ return spending.asObservable();
2793
+ },
2773
2794
  getTotalUsage() {
2774
2795
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2775
2796
  return totalUsage;
@@ -2780,6 +2801,7 @@
2780
2801
  // console.info('[🚕] callChatModel through countTotalUsage');
2781
2802
  const promptResult = await llmTools.callChatModel(prompt);
2782
2803
  totalUsage = addUsage(totalUsage, promptResult.usage);
2804
+ spending.next(promptResult.usage);
2783
2805
  return promptResult;
2784
2806
  };
2785
2807
  }
@@ -2788,6 +2810,7 @@
2788
2810
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2789
2811
  const promptResult = await llmTools.callCompletionModel(prompt);
2790
2812
  totalUsage = addUsage(totalUsage, promptResult.usage);
2813
+ spending.next(promptResult.usage);
2791
2814
  return promptResult;
2792
2815
  };
2793
2816
  }
@@ -2796,6 +2819,7 @@
2796
2819
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2797
2820
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2798
2821
  totalUsage = addUsage(totalUsage, promptResult.usage);
2822
+ spending.next(promptResult.usage);
2799
2823
  return promptResult;
2800
2824
  };
2801
2825
  }
@@ -2973,6 +2997,7 @@
2973
2997
  `);
2974
2998
  // TODO: [🟥] Detect browser / node and make it colorfull
2975
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
2976
3001
  /*
2977
3002
  return {
2978
3003
  async listModels() {
@@ -3520,63 +3545,73 @@
3520
3545
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3521
3546
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3522
3547
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3523
- let partialPieces = null;
3524
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3525
- const scrapers = arrayableToArray(tools.scrapers);
3526
- for (const scraper of scrapers) {
3527
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3528
- // <- TODO: [🦔] Implement mime-type wildcards
3529
- ) {
3530
- continue;
3531
- }
3532
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3533
- if (partialPiecesUnchecked !== null) {
3534
- partialPieces = [...partialPiecesUnchecked];
3535
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3536
- break;
3537
- }
3538
- console.warn(spaceTrim__default["default"]((block) => `
3539
- 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}".
3540
3566
 
3541
- The source:
3542
- ${block(knowledgeSource.knowledgeSourceContent
3543
- .split('\n')
3544
- .map((line) => `> ${line}`)
3545
- .join('\n'))}
3567
+ The source:
3568
+ ${block(knowledgeSource.knowledgeSourceContent
3569
+ .split('\n')
3570
+ .map((line) => `> ${line}`)
3571
+ .join('\n'))}
3546
3572
 
3547
- ${block($registeredScrapersMessage(scrapers))}
3573
+ ${block($registeredScrapersMessage(scrapers))}
3548
3574
 
3549
3575
 
3550
- `));
3551
- }
3552
- if (partialPieces === null) {
3553
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3554
- 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
3555
3582
 
3556
- The source:
3557
- > ${block(knowledgeSource.knowledgeSourceContent
3558
- .split('\n')
3559
- .map((line) => `> ${line}`)
3560
- .join('\n'))}
3583
+ The source:
3584
+ > ${block(knowledgeSource.knowledgeSourceContent
3585
+ .split('\n')
3586
+ .map((line) => `> ${line}`)
3587
+ .join('\n'))}
3561
3588
 
3562
- No scraper found for the mime type "${sourceHandler.mimeType}"
3589
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3563
3590
 
3564
- ${block($registeredScrapersMessage(scrapers))}
3591
+ ${block($registeredScrapersMessage(scrapers))}
3565
3592
 
3566
3593
 
3567
- `));
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
3568
3614
  }
3569
- const pieces = partialPieces.map((partialPiece) => ({
3570
- ...partialPiece,
3571
- sources: [
3572
- {
3573
- name: knowledgeSource.name,
3574
- // line, column <- TODO: [☀]
3575
- // <- TODO: [❎]
3576
- },
3577
- ],
3578
- }));
3579
- knowledgePreparedUnflatten[index] = pieces;
3580
3615
  });
3581
3616
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3582
3617
  return knowledgePrepared;
@@ -3682,7 +3717,7 @@
3682
3717
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3683
3718
  const _llms = arrayableToArray(tools.llm);
3684
3719
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3685
- const llmToolsWithUsage = countTotalUsage(llmTools);
3720
+ const llmToolsWithUsage = countUsage(llmTools);
3686
3721
  // <- TODO: [🌯]
3687
3722
  /*
3688
3723
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -3994,7 +4029,7 @@
3994
4029
  if (parameterNames.has(subparameterName)) {
3995
4030
  parameterNames.delete(subparameterName);
3996
4031
  parameterNames.add(foreach.parameterName);
3997
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
4032
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3998
4033
  }
3999
4034
  }
4000
4035
  }
@@ -5590,6 +5625,7 @@
5590
5625
 
5591
5626
  @see more at https://ptbk.io/prepare-pipeline
5592
5627
  `));
5628
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5593
5629
  }
5594
5630
  let runCount = 0;
5595
5631
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {