@promptbook/cli 0.89.0-8 → 0.89.0-9

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/esm/index.es.js +146 -98
  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/remote-client.index.d.ts +6 -6
  5. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -18
  7. package/esm/typings/src/errors/0-index.d.ts +3 -0
  8. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  9. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilepath.d.ts +12 -0
  10. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  11. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  12. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +5 -3
  13. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  14. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  15. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  16. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  17. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  18. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
  19. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +43 -30
  20. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  21. package/package.json +1 -1
  22. package/umd/index.umd.js +146 -98
  23. package/umd/index.umd.js.map +1 -1
  24. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  25. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/esm/index.es.js CHANGED
@@ -46,7 +46,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-8';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -919,53 +919,6 @@ function $sideEffect(...sideEffectSubjects) {
919
919
  keepUnused(...sideEffectSubjects);
920
920
  }
921
921
 
922
- /**
923
- * Stores data in memory (HEAP)
924
- *
925
- * @public exported from `@promptbook/core`
926
- */
927
- class MemoryStorage {
928
- constructor() {
929
- this.storage = {};
930
- }
931
- /**
932
- * Returns the number of key/value pairs currently present in the list associated with the object.
933
- */
934
- get length() {
935
- return Object.keys(this.storage).length;
936
- }
937
- /**
938
- * Empties the list associated with the object of all key/value pairs, if there are any.
939
- */
940
- clear() {
941
- this.storage = {};
942
- }
943
- /**
944
- * Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
945
- */
946
- getItem(key) {
947
- return this.storage[key] || null;
948
- }
949
- /**
950
- * Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
951
- */
952
- key(index) {
953
- return Object.keys(this.storage)[index] || null;
954
- }
955
- /**
956
- * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
957
- */
958
- setItem(key, value) {
959
- this.storage[key] = value;
960
- }
961
- /**
962
- * Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
963
- */
964
- removeItem(key) {
965
- delete this.storage[key];
966
- }
967
- }
968
-
969
922
  /**
970
923
  * Just marks a place of place where should be something implemented
971
924
  * No side effects.
@@ -1900,6 +1853,53 @@ class FileCacheStorage {
1900
1853
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1901
1854
  */
1902
1855
 
1856
+ /**
1857
+ * Stores data in memory (HEAP)
1858
+ *
1859
+ * @public exported from `@promptbook/core`
1860
+ */
1861
+ class MemoryStorage {
1862
+ constructor() {
1863
+ this.storage = {};
1864
+ }
1865
+ /**
1866
+ * Returns the number of key/value pairs currently present in the list associated with the object.
1867
+ */
1868
+ get length() {
1869
+ return Object.keys(this.storage).length;
1870
+ }
1871
+ /**
1872
+ * Empties the list associated with the object of all key/value pairs, if there are any.
1873
+ */
1874
+ clear() {
1875
+ this.storage = {};
1876
+ }
1877
+ /**
1878
+ * Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
1879
+ */
1880
+ getItem(key) {
1881
+ return this.storage[key] || null;
1882
+ }
1883
+ /**
1884
+ * Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
1885
+ */
1886
+ key(index) {
1887
+ return Object.keys(this.storage)[index] || null;
1888
+ }
1889
+ /**
1890
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
1891
+ */
1892
+ setItem(key, value) {
1893
+ this.storage[key] = value;
1894
+ }
1895
+ /**
1896
+ * Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
1897
+ */
1898
+ removeItem(key) {
1899
+ delete this.storage[key];
1900
+ }
1901
+ }
1902
+
1903
1903
  /**
1904
1904
  * This error indicates problems parsing the format value
1905
1905
  *
@@ -2105,6 +2105,19 @@ class PipelineUrlError extends Error {
2105
2105
  }
2106
2106
  }
2107
2107
 
2108
+ /**
2109
+ * Error thrown when a fetch request fails
2110
+ *
2111
+ * @public exported from `@promptbook/core`
2112
+ */
2113
+ class PromptbookFetchError extends Error {
2114
+ constructor(message) {
2115
+ super(message);
2116
+ this.name = 'PromptbookFetchError';
2117
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2118
+ }
2119
+ }
2120
+
2108
2121
  /**
2109
2122
  * Index of all custom errors
2110
2123
  *
@@ -2143,6 +2156,7 @@ const COMMON_JAVASCRIPT_ERRORS = {
2143
2156
  URIError,
2144
2157
  AggregateError,
2145
2158
  AuthenticationError,
2159
+ PromptbookFetchError,
2146
2160
  /*
2147
2161
  Note: Not widely supported
2148
2162
  > InternalError,
@@ -2641,21 +2655,15 @@ function isRootPath(value) {
2641
2655
  */
2642
2656
 
2643
2657
  /**
2644
- * @@@
2658
+ * Provides the path to the `.env` file
2645
2659
  *
2646
- * @@@ .env
2660
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2647
2661
  *
2648
- * It looks for environment variables:
2649
- * - `process.env.OPENAI_API_KEY`
2650
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2651
- * - ...
2652
- *
2653
- * @returns @@@
2654
- * @public exported from `@promptbook/node`
2662
+ * @private within the repository - for CLI utils
2655
2663
  */
2656
- async function $provideLlmToolsConfigurationFromEnv() {
2664
+ async function $provideEnvFilepath() {
2657
2665
  if (!$isRunningInNode()) {
2658
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2666
+ throw new EnvironmentMismatchError('Function `$provideEnvFilepath` works only in Node.js environment');
2659
2667
  }
2660
2668
  const envFilePatterns = [
2661
2669
  '.env',
@@ -2675,8 +2683,7 @@ async function $provideLlmToolsConfigurationFromEnv() {
2675
2683
  const envFilename = join(rootDirname, pattern);
2676
2684
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
2677
2685
  $setUsedEnvFilename(envFilename);
2678
- dotenv.config({ path: envFilename });
2679
- break up_to_root;
2686
+ return envFilename;
2680
2687
  }
2681
2688
  }
2682
2689
  if (isRootPath(rootDirname)) {
@@ -2685,6 +2692,34 @@ async function $provideLlmToolsConfigurationFromEnv() {
2685
2692
  // Note: If the directory does not exist, try the parent directory
2686
2693
  rootDirname = join(rootDirname, '..');
2687
2694
  }
2695
+ return null;
2696
+ }
2697
+ /**
2698
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2699
+ */
2700
+
2701
+ /**
2702
+ * @@@
2703
+ *
2704
+ * @@@ .env
2705
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2706
+ *
2707
+ * It looks for environment variables:
2708
+ * - `process.env.OPENAI_API_KEY`
2709
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2710
+ * - ...
2711
+ *
2712
+ * @returns @@@
2713
+ * @public exported from `@promptbook/node`
2714
+ */
2715
+ async function $provideLlmToolsConfigurationFromEnv() {
2716
+ if (!$isRunningInNode()) {
2717
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2718
+ }
2719
+ const envFilepath = await $provideEnvFilepath();
2720
+ if (envFilepath !== null) {
2721
+ dotenv.config({ path: envFilepath });
2722
+ }
2688
2723
  const llmToolsConfiguration = $llmToolsMetadataRegister
2689
2724
  .list()
2690
2725
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -2692,15 +2727,8 @@ async function $provideLlmToolsConfigurationFromEnv() {
2692
2727
  return llmToolsConfiguration;
2693
2728
  }
2694
2729
  /**
2695
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
2696
- * TODO: Add Azure OpenAI
2697
- * TODO: [🧠][🍛]
2698
- * TODO: [🧠] Is there some meaningfull way how to test this util
2699
2730
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2700
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2701
- * TODO: This should be maybe not under `_common` but under `utils`
2702
- * TODO: [🧠][⚛] Maybe pass env as argument
2703
- * TODO: [®] DRY Register logic */
2731
+ */
2704
2732
 
2705
2733
  /**
2706
2734
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
@@ -2950,6 +2978,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
2950
2978
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
2951
2979
  *
2952
2980
  * @@@ .env
2981
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2953
2982
  *
2954
2983
  * It looks for environment variables:
2955
2984
  * - `process.env.OPENAI_API_KEY`
@@ -2994,6 +3023,8 @@ async function $provideLlmToolsFromEnv(options = {}) {
2994
3023
  /**
2995
3024
  * Returns LLM tools for CLI
2996
3025
  *
3026
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file and also writes this .env file
3027
+ *
2997
3028
  * @private within the repository - for CLI utils
2998
3029
  */
2999
3030
  async function $provideLlmToolsForWizzardOrCli(options) {
@@ -3005,6 +3036,8 @@ async function $provideLlmToolsForWizzardOrCli(options) {
3005
3036
  let llmExecutionTools;
3006
3037
  if (strategy === 'REMOTE_SERVER') {
3007
3038
  const { remoteServerUrl = DEFAULT_REMOTE_SERVER_URL, loginPrompt } = options;
3039
+ // TODO: !!!
3040
+ // const envFilepath = await $provideEnvFilepath();
3008
3041
  const storage = new MemoryStorage(); // <- TODO: !!!!!! Save to `.promptbook` folder
3009
3042
  const key = `${remoteServerUrl}-identification`;
3010
3043
  let identification = await storage.getItem(key);
@@ -3041,6 +3074,39 @@ async function $provideLlmToolsForWizzardOrCli(options) {
3041
3074
  * TODO: [®] DRY Register logic
3042
3075
  */
3043
3076
 
3077
+ /**
3078
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3079
+ *
3080
+ * @public exported from `@promptbook/core`
3081
+ */
3082
+ const promptbookFetch = async (urlOrRequest, init) => {
3083
+ try {
3084
+ return await fetch(urlOrRequest, init);
3085
+ }
3086
+ catch (error) {
3087
+ if (!(error instanceof Error)) {
3088
+ throw error;
3089
+ }
3090
+ let url;
3091
+ if (typeof urlOrRequest === 'string') {
3092
+ url = urlOrRequest;
3093
+ }
3094
+ else if (urlOrRequest instanceof Request) {
3095
+ url = urlOrRequest.url;
3096
+ }
3097
+ throw new PromptbookFetchError(spaceTrim((block) => `
3098
+ Can not fetch "${url}"
3099
+
3100
+ Fetch error:
3101
+ ${block(error.message)}
3102
+
3103
+ `));
3104
+ }
3105
+ };
3106
+ /**
3107
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3108
+ */
3109
+
3044
3110
  /**
3045
3111
  * Checks if value is valid email
3046
3112
  *
@@ -3109,7 +3175,9 @@ function $provideLlmToolsForCli(options) {
3109
3175
  },
3110
3176
  ]);
3111
3177
  const loginUrl = `${remoteServerUrl}/login`;
3112
- const response = await fetch(loginUrl, {
3178
+ console.log('!!!', { loginUrl });
3179
+ // TODO: [🧠] Should we use normal `fetch` or `scraperFetch`
3180
+ const response = await promptbookFetch(loginUrl, {
3113
3181
  method: 'POST',
3114
3182
  headers: {
3115
3183
  'Content-Type': 'application/json',
@@ -3128,6 +3196,12 @@ function $provideLlmToolsForCli(options) {
3128
3196
  // text: await response.text(),
3129
3197
  });
3130
3198
  const { isSuccess, message, error, identification } = (await response.json());
3199
+ console.log('!!!', {
3200
+ isSuccess,
3201
+ message,
3202
+ error,
3203
+ identification,
3204
+ });
3131
3205
  if (message) {
3132
3206
  if (isSuccess) {
3133
3207
  console.log(colors.green(message));
@@ -6807,32 +6881,6 @@ function mimeTypeToExtension(value) {
6807
6881
  return extension(value) || null;
6808
6882
  }
6809
6883
 
6810
- /**
6811
- * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
6812
- *
6813
- * @private as default `fetch` function used in Promptbook scrapers
6814
- */
6815
- const scraperFetch = async (url, init) => {
6816
- try {
6817
- return await fetch(url, init);
6818
- }
6819
- catch (error) {
6820
- if (!(error instanceof Error)) {
6821
- throw error;
6822
- }
6823
- throw new KnowledgeScrapeError(spaceTrim((block) => `
6824
- Can not fetch "${url}"
6825
-
6826
- Fetch error:
6827
- ${block(error.message)}
6828
-
6829
- `));
6830
- }
6831
- };
6832
- /**
6833
- * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
6834
- */
6835
-
6836
6884
  /**
6837
6885
  * @@@
6838
6886
  *
@@ -6841,7 +6889,7 @@ const scraperFetch = async (url, init) => {
6841
6889
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6842
6890
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
6843
6891
  var _a;
6844
- const { fetch = scraperFetch } = tools;
6892
+ const { fetch = promptbookFetch } = tools;
6845
6893
  const { knowledgeSourceContent } = knowledgeSource;
6846
6894
  let { name } = knowledgeSource;
6847
6895
  const { rootDirname = null,
@@ -12730,7 +12778,7 @@ function $initializeRunCommand(program) {
12730
12778
  const tools = {
12731
12779
  llm,
12732
12780
  fs,
12733
- fetch: scraperFetch,
12781
+ fetch: promptbookFetch,
12734
12782
  scrapers: await $provideScrapersForNode({ fs, llm, executables }, prepareAndScrapeOptions),
12735
12783
  script: [new JavascriptExecutionTools(cliOptions)],
12736
12784
  };