@promptbook/node 0.84.0-21 → 0.84.0

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.
package/README.md CHANGED
@@ -24,10 +24,6 @@
24
24
 
25
25
 
26
26
 
27
- <blockquote style="color: #ff8811">
28
- <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>.
29
- </blockquote>
30
-
31
27
  ## 📦 Package `@promptbook/node`
32
28
 
33
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-20';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -9554,6 +9554,9 @@ function compilePipeline(pipelineString, tools, options) {
9554
9554
  * @public exported from `@promptbook/utils`
9555
9555
  */
9556
9556
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
9557
+ /**
9558
+ * TODO: [☑]
9559
+ */
9557
9560
 
9558
9561
  /**
9559
9562
  * Normalize options for `execCommand` and `execCommands`
@@ -10060,107 +10063,6 @@ function isRootPath(value) {
10060
10063
  * TODO: [🍏] Make for MacOS paths
10061
10064
  */
10062
10065
 
10063
- /**
10064
- * @@@
10065
- *
10066
- * @@@ .env
10067
- *
10068
- * It looks for environment variables:
10069
- * - `process.env.OPENAI_API_KEY`
10070
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
10071
- * - ...
10072
- *
10073
- * @returns @@@
10074
- * @public exported from `@promptbook/node`
10075
- */
10076
- function $provideLlmToolsConfigurationFromEnv() {
10077
- return __awaiter(this, void 0, void 0, function () {
10078
- var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
10079
- var e_1, _a;
10080
- return __generator(this, function (_b) {
10081
- switch (_b.label) {
10082
- case 0:
10083
- if (!$isRunningInNode()) {
10084
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
10085
- }
10086
- envFilePatterns = [
10087
- '.env',
10088
- '.env.test',
10089
- '.env.local',
10090
- '.env.development.local',
10091
- '.env.development',
10092
- '.env.production.local',
10093
- '.env.production',
10094
- '.env.prod.local',
10095
- '.env.prod',
10096
- // <- TODO: Maybe add more patterns
10097
- ];
10098
- rootDirname = process.cwd();
10099
- i = 0;
10100
- _b.label = 1;
10101
- case 1:
10102
- if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
10103
- _b.label = 2;
10104
- case 2:
10105
- _b.trys.push([2, 7, 8, 9]);
10106
- envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
10107
- _b.label = 3;
10108
- case 3:
10109
- if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
10110
- pattern = envFilePatterns_1_1.value;
10111
- envFilename = join(rootDirname, pattern);
10112
- return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
10113
- case 4:
10114
- if (_b.sent()) {
10115
- dotenv.config({ path: envFilename });
10116
- return [3 /*break*/, 11];
10117
- }
10118
- _b.label = 5;
10119
- case 5:
10120
- envFilePatterns_1_1 = envFilePatterns_1.next();
10121
- return [3 /*break*/, 3];
10122
- case 6: return [3 /*break*/, 9];
10123
- case 7:
10124
- e_1_1 = _b.sent();
10125
- e_1 = { error: e_1_1 };
10126
- return [3 /*break*/, 9];
10127
- case 8:
10128
- try {
10129
- if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
10130
- }
10131
- finally { if (e_1) throw e_1.error; }
10132
- return [7 /*endfinally*/];
10133
- case 9:
10134
- if (isRootPath(rootDirname)) {
10135
- return [3 /*break*/, 11];
10136
- }
10137
- // Note: If the directory does not exist, try the parent directory
10138
- rootDirname = join(rootDirname, '..');
10139
- _b.label = 10;
10140
- case 10:
10141
- i++;
10142
- return [3 /*break*/, 1];
10143
- case 11:
10144
- llmToolsConfiguration = $llmToolsMetadataRegister
10145
- .list()
10146
- .map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
10147
- .filter(function (configuration) { return configuration !== null; });
10148
- return [2 /*return*/, llmToolsConfiguration];
10149
- }
10150
- });
10151
- });
10152
- }
10153
- /**
10154
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
10155
- * TODO: Add Azure OpenAI
10156
- * TODO: [🧠][🍛]
10157
- * TODO: [🧠] Is there some meaningfull way how to test this util
10158
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
10159
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
10160
- * TODO: This should be maybe not under `_common` but under `utils`
10161
- * TODO: [🧠][⚛] Maybe pass env as argument
10162
- * TODO: [®] DRY Register logic */
10163
-
10164
10066
  /**
10165
10067
  * @@@
10166
10068
  *
@@ -10173,6 +10075,22 @@ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
10173
10075
  * TODO: [®] DRY Register logic
10174
10076
  */
10175
10077
 
10078
+ /**
10079
+ * Path to the `.env` file which was used to configure LLM tools
10080
+ *
10081
+ * Note: `$` is used to indicate that this variable is changed by side effect in `$provideLlmToolsConfigurationFromEnv` through `$setUsedEnvFilename`
10082
+ */
10083
+ var $usedEnvFilename = null;
10084
+ /**
10085
+ * Pass the `.env` file which was used to configure LLM tools
10086
+ *
10087
+ * Note: `$` is used to indicate that this variable is making side effect
10088
+ *
10089
+ * @private internal log of `$provideLlmToolsConfigurationFromEnv` and `$registeredLlmToolsMessage`
10090
+ */
10091
+ function $setUsedEnvFilename(filepath) {
10092
+ $usedEnvFilename = filepath;
10093
+ }
10176
10094
  /**
10177
10095
  * Creates a message with all registered LLM tools
10178
10096
  *
@@ -10251,10 +10169,11 @@ function $registeredLlmToolsMessage() {
10251
10169
  // <- Note: [🗨]
10252
10170
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
10253
10171
  });
10172
+ var usedEnvMessage = $usedEnvFilename === null ? "Unknown `.env` file" : "Used `.env` file:\n".concat($usedEnvFilename);
10254
10173
  if (metadata.length === 0) {
10255
- return "No LLM providers are available.";
10174
+ return spaceTrim(function (block) { return "\n No LLM providers are available.\n\n ".concat(block(usedEnvMessage), "\n "); });
10256
10175
  }
10257
- return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
10176
+ return spaceTrim(function (block) { return "\n\n ".concat(block(usedEnvMessage), "\n\n Relevant environment variables:\n ").concat(block(Object.keys(env)
10258
10177
  .filter(function (envVariableName) {
10259
10178
  return metadata.some(function (_a) {
10260
10179
  var envVariables = _a.envVariables;
@@ -10319,6 +10238,108 @@ function $registeredLlmToolsMessage() {
10319
10238
  * TODO: [🧠][⚛] Maybe pass env as argument
10320
10239
  */
10321
10240
 
10241
+ /**
10242
+ * @@@
10243
+ *
10244
+ * @@@ .env
10245
+ *
10246
+ * It looks for environment variables:
10247
+ * - `process.env.OPENAI_API_KEY`
10248
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
10249
+ * - ...
10250
+ *
10251
+ * @returns @@@
10252
+ * @public exported from `@promptbook/node`
10253
+ */
10254
+ function $provideLlmToolsConfigurationFromEnv() {
10255
+ return __awaiter(this, void 0, void 0, function () {
10256
+ var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
10257
+ var e_1, _a;
10258
+ return __generator(this, function (_b) {
10259
+ switch (_b.label) {
10260
+ case 0:
10261
+ if (!$isRunningInNode()) {
10262
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
10263
+ }
10264
+ envFilePatterns = [
10265
+ '.env',
10266
+ '.env.test',
10267
+ '.env.local',
10268
+ '.env.development.local',
10269
+ '.env.development',
10270
+ '.env.production.local',
10271
+ '.env.production',
10272
+ '.env.prod.local',
10273
+ '.env.prod',
10274
+ // <- TODO: Maybe add more patterns
10275
+ ];
10276
+ rootDirname = process.cwd();
10277
+ i = 0;
10278
+ _b.label = 1;
10279
+ case 1:
10280
+ if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
10281
+ _b.label = 2;
10282
+ case 2:
10283
+ _b.trys.push([2, 7, 8, 9]);
10284
+ envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
10285
+ _b.label = 3;
10286
+ case 3:
10287
+ if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
10288
+ pattern = envFilePatterns_1_1.value;
10289
+ envFilename = join(rootDirname, pattern);
10290
+ return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
10291
+ case 4:
10292
+ if (_b.sent()) {
10293
+ $setUsedEnvFilename(envFilename);
10294
+ dotenv.config({ path: envFilename });
10295
+ return [3 /*break*/, 11];
10296
+ }
10297
+ _b.label = 5;
10298
+ case 5:
10299
+ envFilePatterns_1_1 = envFilePatterns_1.next();
10300
+ return [3 /*break*/, 3];
10301
+ case 6: return [3 /*break*/, 9];
10302
+ case 7:
10303
+ e_1_1 = _b.sent();
10304
+ e_1 = { error: e_1_1 };
10305
+ return [3 /*break*/, 9];
10306
+ case 8:
10307
+ try {
10308
+ if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
10309
+ }
10310
+ finally { if (e_1) throw e_1.error; }
10311
+ return [7 /*endfinally*/];
10312
+ case 9:
10313
+ if (isRootPath(rootDirname)) {
10314
+ return [3 /*break*/, 11];
10315
+ }
10316
+ // Note: If the directory does not exist, try the parent directory
10317
+ rootDirname = join(rootDirname, '..');
10318
+ _b.label = 10;
10319
+ case 10:
10320
+ i++;
10321
+ return [3 /*break*/, 1];
10322
+ case 11:
10323
+ llmToolsConfiguration = $llmToolsMetadataRegister
10324
+ .list()
10325
+ .map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
10326
+ .filter(function (configuration) { return configuration !== null; });
10327
+ return [2 /*return*/, llmToolsConfiguration];
10328
+ }
10329
+ });
10330
+ });
10331
+ }
10332
+ /**
10333
+ * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
10334
+ * TODO: Add Azure OpenAI
10335
+ * TODO: [🧠][🍛]
10336
+ * TODO: [🧠] Is there some meaningfull way how to test this util
10337
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
10338
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
10339
+ * TODO: This should be maybe not under `_common` but under `utils`
10340
+ * TODO: [🧠][⚛] Maybe pass env as argument
10341
+ * TODO: [®] DRY Register logic */
10342
+
10322
10343
  /**
10323
10344
  * @@@
10324
10345
  *
@@ -10472,6 +10493,9 @@ function $provideScrapersForNode(tools, options) {
10472
10493
  * @public exported from `@promptbook/utils`
10473
10494
  */
10474
10495
  new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
10496
+ /**
10497
+ * TODO: [☑]
10498
+ */
10475
10499
 
10476
10500
  /**
10477
10501
  * Detects if the code is running in jest environment
@@ -10481,6 +10505,9 @@ new Function("\n try {\n return this === window;\n } catch (e) {\n
10481
10505
  * @public exported from `@promptbook/utils`
10482
10506
  */
10483
10507
  new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
10508
+ /**
10509
+ * TODO: [☑]
10510
+ */
10484
10511
 
10485
10512
  /**
10486
10513
  * Detects if the code is running in a web worker
@@ -10490,6 +10517,9 @@ new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefin
10490
10517
  * @public exported from `@promptbook/utils`
10491
10518
  */
10492
10519
  new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
10520
+ /**
10521
+ * TODO: [☑]
10522
+ */
10493
10523
 
10494
10524
  /**
10495
10525
  * Makes first letter of a string uppercase