@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/umd/index.umd.js CHANGED
@@ -56,7 +56,7 @@
56
56
  * @generated
57
57
  * @see https://github.com/webgptorg/promptbook
58
58
  */
59
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-8';
59
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
60
60
  /**
61
61
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
62
62
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -929,53 +929,6 @@
929
929
  keepUnused(...sideEffectSubjects);
930
930
  }
931
931
 
932
- /**
933
- * Stores data in memory (HEAP)
934
- *
935
- * @public exported from `@promptbook/core`
936
- */
937
- class MemoryStorage {
938
- constructor() {
939
- this.storage = {};
940
- }
941
- /**
942
- * Returns the number of key/value pairs currently present in the list associated with the object.
943
- */
944
- get length() {
945
- return Object.keys(this.storage).length;
946
- }
947
- /**
948
- * Empties the list associated with the object of all key/value pairs, if there are any.
949
- */
950
- clear() {
951
- this.storage = {};
952
- }
953
- /**
954
- * 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.
955
- */
956
- getItem(key) {
957
- return this.storage[key] || null;
958
- }
959
- /**
960
- * 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.
961
- */
962
- key(index) {
963
- return Object.keys(this.storage)[index] || null;
964
- }
965
- /**
966
- * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
967
- */
968
- setItem(key, value) {
969
- this.storage[key] = value;
970
- }
971
- /**
972
- * 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.
973
- */
974
- removeItem(key) {
975
- delete this.storage[key];
976
- }
977
- }
978
-
979
932
  /**
980
933
  * Just marks a place of place where should be something implemented
981
934
  * No side effects.
@@ -1910,6 +1863,53 @@
1910
1863
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
1911
1864
  */
1912
1865
 
1866
+ /**
1867
+ * Stores data in memory (HEAP)
1868
+ *
1869
+ * @public exported from `@promptbook/core`
1870
+ */
1871
+ class MemoryStorage {
1872
+ constructor() {
1873
+ this.storage = {};
1874
+ }
1875
+ /**
1876
+ * Returns the number of key/value pairs currently present in the list associated with the object.
1877
+ */
1878
+ get length() {
1879
+ return Object.keys(this.storage).length;
1880
+ }
1881
+ /**
1882
+ * Empties the list associated with the object of all key/value pairs, if there are any.
1883
+ */
1884
+ clear() {
1885
+ this.storage = {};
1886
+ }
1887
+ /**
1888
+ * 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.
1889
+ */
1890
+ getItem(key) {
1891
+ return this.storage[key] || null;
1892
+ }
1893
+ /**
1894
+ * 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.
1895
+ */
1896
+ key(index) {
1897
+ return Object.keys(this.storage)[index] || null;
1898
+ }
1899
+ /**
1900
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
1901
+ */
1902
+ setItem(key, value) {
1903
+ this.storage[key] = value;
1904
+ }
1905
+ /**
1906
+ * 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.
1907
+ */
1908
+ removeItem(key) {
1909
+ delete this.storage[key];
1910
+ }
1911
+ }
1912
+
1913
1913
  /**
1914
1914
  * This error indicates problems parsing the format value
1915
1915
  *
@@ -2115,6 +2115,19 @@
2115
2115
  }
2116
2116
  }
2117
2117
 
2118
+ /**
2119
+ * Error thrown when a fetch request fails
2120
+ *
2121
+ * @public exported from `@promptbook/core`
2122
+ */
2123
+ class PromptbookFetchError extends Error {
2124
+ constructor(message) {
2125
+ super(message);
2126
+ this.name = 'PromptbookFetchError';
2127
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2128
+ }
2129
+ }
2130
+
2118
2131
  /**
2119
2132
  * Index of all custom errors
2120
2133
  *
@@ -2153,6 +2166,7 @@
2153
2166
  URIError,
2154
2167
  AggregateError,
2155
2168
  AuthenticationError,
2169
+ PromptbookFetchError,
2156
2170
  /*
2157
2171
  Note: Not widely supported
2158
2172
  > InternalError,
@@ -2651,21 +2665,15 @@
2651
2665
  */
2652
2666
 
2653
2667
  /**
2654
- * @@@
2668
+ * Provides the path to the `.env` file
2655
2669
  *
2656
- * @@@ .env
2670
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2657
2671
  *
2658
- * It looks for environment variables:
2659
- * - `process.env.OPENAI_API_KEY`
2660
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2661
- * - ...
2662
- *
2663
- * @returns @@@
2664
- * @public exported from `@promptbook/node`
2672
+ * @private within the repository - for CLI utils
2665
2673
  */
2666
- async function $provideLlmToolsConfigurationFromEnv() {
2674
+ async function $provideEnvFilepath() {
2667
2675
  if (!$isRunningInNode()) {
2668
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2676
+ throw new EnvironmentMismatchError('Function `$provideEnvFilepath` works only in Node.js environment');
2669
2677
  }
2670
2678
  const envFilePatterns = [
2671
2679
  '.env',
@@ -2685,8 +2693,7 @@
2685
2693
  const envFilename = path.join(rootDirname, pattern);
2686
2694
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
2687
2695
  $setUsedEnvFilename(envFilename);
2688
- dotenv__namespace.config({ path: envFilename });
2689
- break up_to_root;
2696
+ return envFilename;
2690
2697
  }
2691
2698
  }
2692
2699
  if (isRootPath(rootDirname)) {
@@ -2695,6 +2702,34 @@
2695
2702
  // Note: If the directory does not exist, try the parent directory
2696
2703
  rootDirname = path.join(rootDirname, '..');
2697
2704
  }
2705
+ return null;
2706
+ }
2707
+ /**
2708
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2709
+ */
2710
+
2711
+ /**
2712
+ * @@@
2713
+ *
2714
+ * @@@ .env
2715
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2716
+ *
2717
+ * It looks for environment variables:
2718
+ * - `process.env.OPENAI_API_KEY`
2719
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2720
+ * - ...
2721
+ *
2722
+ * @returns @@@
2723
+ * @public exported from `@promptbook/node`
2724
+ */
2725
+ async function $provideLlmToolsConfigurationFromEnv() {
2726
+ if (!$isRunningInNode()) {
2727
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2728
+ }
2729
+ const envFilepath = await $provideEnvFilepath();
2730
+ if (envFilepath !== null) {
2731
+ dotenv__namespace.config({ path: envFilepath });
2732
+ }
2698
2733
  const llmToolsConfiguration = $llmToolsMetadataRegister
2699
2734
  .list()
2700
2735
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -2702,15 +2737,8 @@
2702
2737
  return llmToolsConfiguration;
2703
2738
  }
2704
2739
  /**
2705
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
2706
- * TODO: Add Azure OpenAI
2707
- * TODO: [🧠][🍛]
2708
- * TODO: [🧠] Is there some meaningfull way how to test this util
2709
2740
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2710
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2711
- * TODO: This should be maybe not under `_common` but under `utils`
2712
- * TODO: [🧠][⚛] Maybe pass env as argument
2713
- * TODO: [®] DRY Register logic */
2741
+ */
2714
2742
 
2715
2743
  /**
2716
2744
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
@@ -2960,6 +2988,7 @@
2960
2988
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
2961
2989
  *
2962
2990
  * @@@ .env
2991
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
2963
2992
  *
2964
2993
  * It looks for environment variables:
2965
2994
  * - `process.env.OPENAI_API_KEY`
@@ -3004,6 +3033,8 @@
3004
3033
  /**
3005
3034
  * Returns LLM tools for CLI
3006
3035
  *
3036
+ * 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
3037
+ *
3007
3038
  * @private within the repository - for CLI utils
3008
3039
  */
3009
3040
  async function $provideLlmToolsForWizzardOrCli(options) {
@@ -3015,6 +3046,8 @@
3015
3046
  let llmExecutionTools;
3016
3047
  if (strategy === 'REMOTE_SERVER') {
3017
3048
  const { remoteServerUrl = DEFAULT_REMOTE_SERVER_URL, loginPrompt } = options;
3049
+ // TODO: !!!
3050
+ // const envFilepath = await $provideEnvFilepath();
3018
3051
  const storage = new MemoryStorage(); // <- TODO: !!!!!! Save to `.promptbook` folder
3019
3052
  const key = `${remoteServerUrl}-identification`;
3020
3053
  let identification = await storage.getItem(key);
@@ -3051,6 +3084,39 @@
3051
3084
  * TODO: [®] DRY Register logic
3052
3085
  */
3053
3086
 
3087
+ /**
3088
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3089
+ *
3090
+ * @public exported from `@promptbook/core`
3091
+ */
3092
+ const promptbookFetch = async (urlOrRequest, init) => {
3093
+ try {
3094
+ return await fetch(urlOrRequest, init);
3095
+ }
3096
+ catch (error) {
3097
+ if (!(error instanceof Error)) {
3098
+ throw error;
3099
+ }
3100
+ let url;
3101
+ if (typeof urlOrRequest === 'string') {
3102
+ url = urlOrRequest;
3103
+ }
3104
+ else if (urlOrRequest instanceof Request) {
3105
+ url = urlOrRequest.url;
3106
+ }
3107
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
3108
+ Can not fetch "${url}"
3109
+
3110
+ Fetch error:
3111
+ ${block(error.message)}
3112
+
3113
+ `));
3114
+ }
3115
+ };
3116
+ /**
3117
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3118
+ */
3119
+
3054
3120
  /**
3055
3121
  * Checks if value is valid email
3056
3122
  *
@@ -3119,7 +3185,9 @@
3119
3185
  },
3120
3186
  ]);
3121
3187
  const loginUrl = `${remoteServerUrl}/login`;
3122
- const response = await fetch(loginUrl, {
3188
+ console.log('!!!', { loginUrl });
3189
+ // TODO: [🧠] Should we use normal `fetch` or `scraperFetch`
3190
+ const response = await promptbookFetch(loginUrl, {
3123
3191
  method: 'POST',
3124
3192
  headers: {
3125
3193
  'Content-Type': 'application/json',
@@ -3138,6 +3206,12 @@
3138
3206
  // text: await response.text(),
3139
3207
  });
3140
3208
  const { isSuccess, message, error, identification } = (await response.json());
3209
+ console.log('!!!', {
3210
+ isSuccess,
3211
+ message,
3212
+ error,
3213
+ identification,
3214
+ });
3141
3215
  if (message) {
3142
3216
  if (isSuccess) {
3143
3217
  console.log(colors__default["default"].green(message));
@@ -6817,32 +6891,6 @@
6817
6891
  return mimeTypes.extension(value) || null;
6818
6892
  }
6819
6893
 
6820
- /**
6821
- * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
6822
- *
6823
- * @private as default `fetch` function used in Promptbook scrapers
6824
- */
6825
- const scraperFetch = async (url, init) => {
6826
- try {
6827
- return await fetch(url, init);
6828
- }
6829
- catch (error) {
6830
- if (!(error instanceof Error)) {
6831
- throw error;
6832
- }
6833
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
6834
- Can not fetch "${url}"
6835
-
6836
- Fetch error:
6837
- ${block(error.message)}
6838
-
6839
- `));
6840
- }
6841
- };
6842
- /**
6843
- * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
6844
- */
6845
-
6846
6894
  /**
6847
6895
  * @@@
6848
6896
  *
@@ -6851,7 +6899,7 @@
6851
6899
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6852
6900
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
6853
6901
  var _a;
6854
- const { fetch = scraperFetch } = tools;
6902
+ const { fetch = promptbookFetch } = tools;
6855
6903
  const { knowledgeSourceContent } = knowledgeSource;
6856
6904
  let { name } = knowledgeSource;
6857
6905
  const { rootDirname = null,
@@ -12740,7 +12788,7 @@
12740
12788
  const tools = {
12741
12789
  llm,
12742
12790
  fs,
12743
- fetch: scraperFetch,
12791
+ fetch: promptbookFetch,
12744
12792
  scrapers: await $provideScrapersForNode({ fs, llm, executables }, prepareAndScrapeOptions),
12745
12793
  script: [new JavascriptExecutionTools(cliOptions)],
12746
12794
  };