@promptbook/cli 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.
@@ -8,6 +8,7 @@ import type { Command as Program } from 'commander';
8
8
  */
9
9
  export declare function $initializeAboutCommand(program: Program): void;
10
10
  /**
11
+ * TODO: !!! Test this in `deno`
11
12
  * TODO: [🗽] Unite branding and make single place for it
12
13
  * Note: [💞] Ignore a discrepancy between file name and entity name
13
14
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -1,4 +1,13 @@
1
+ import type { string_filename } from '../../../types/typeAliases';
1
2
  import type { string_markdown } from '../../../types/typeAliases';
3
+ /**
4
+ * Pass the `.env` file which was used to configure LLM tools
5
+ *
6
+ * Note: `$` is used to indicate that this variable is making side effect
7
+ *
8
+ * @private internal log of `$provideLlmToolsConfigurationFromEnv` and `$registeredLlmToolsMessage`
9
+ */
10
+ export declare function $setUsedEnvFilename(filepath: string_filename): void;
2
11
  /**
3
12
  * Creates a message with all registered LLM tools
4
13
  *
@@ -6,3 +6,6 @@
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare const $isRunningInBrowser: Function;
9
+ /**
10
+ * TODO: [☑]
11
+ */
@@ -6,3 +6,6 @@
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare const $isRunningInJest: Function;
9
+ /**
10
+ * TODO: [☑]
11
+ */
@@ -6,3 +6,6 @@
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare const $isRunningInNode: Function;
9
+ /**
10
+ * TODO: [☑]
11
+ */
@@ -6,3 +6,6 @@
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare const $isRunningInWebWorker: Function;
9
+ /**
10
+ * TODO: [☑]
11
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.84.0-21",
3
+ "version": "0.84.0",
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,
@@ -38,7 +38,7 @@
38
38
  "anthropic",
39
39
  "LLMOps"
40
40
  ],
41
- "license": "UNLICENSED",
41
+ "license": "BUSL-1.1",
42
42
  "bugs": {
43
43
  "url": "https://github.com/webgptorg/promptbook/issues"
44
44
  },
package/umd/index.umd.js CHANGED
@@ -51,7 +51,7 @@
51
51
  * @generated
52
52
  * @see https://github.com/webgptorg/promptbook
53
53
  */
54
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-20';
54
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
55
55
  /**
56
56
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
57
57
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -458,6 +458,45 @@
458
458
  * @public exported from `@promptbook/utils`
459
459
  */
460
460
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
461
+ /**
462
+ * TODO: [☑]
463
+ */
464
+
465
+ /**
466
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
467
+ *
468
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
469
+ *
470
+ * @public exported from `@promptbook/utils`
471
+ */
472
+ var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
473
+ /**
474
+ * TODO: [☑]
475
+ */
476
+
477
+ /**
478
+ * Detects if the code is running in jest environment
479
+ *
480
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
481
+ *
482
+ * @public exported from `@promptbook/utils`
483
+ */
484
+ var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
485
+ /**
486
+ * TODO: [☑]
487
+ */
488
+
489
+ /**
490
+ * Detects if the code is running in a web worker
491
+ *
492
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
493
+ *
494
+ * @public exported from `@promptbook/utils`
495
+ */
496
+ var $isRunningInWebWorker = 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");
497
+ /**
498
+ * TODO: [☑]
499
+ */
461
500
 
462
501
  /**
463
502
  * Initializes `about` command for Promptbook CLI utilities
@@ -472,16 +511,37 @@
472
511
  makeCommand.description(spaceTrim__default["default"]("\n Tells about Promptbook CLI and its abilities\n "));
473
512
  makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
474
513
  return __generator(this, function (_a) {
475
- console.info(colors__default["default"].bold(colors__default["default"].cyan("Promptbook: ".concat(CLAIM))));
514
+ console.info(colors__default["default"].bold(colors__default["default"].blue("Promptbook: ".concat(CLAIM))));
476
515
  console.info(colors__default["default"].cyan("Book language version: ".concat(BOOK_LANGUAGE_VERSION)));
477
516
  console.info(colors__default["default"].cyan("Promptbook engine version: ".concat(PROMPTBOOK_ENGINE_VERSION)));
478
- console.info(colors__default["default"].cyan("https://github.com/webgptorg/promptbook"));
479
- console.info(colors__default["default"].cyan("https://ptbk.io"));
517
+ if ($isRunningInNode()) {
518
+ console.info(colors__default["default"].cyan("Environment: Node.js"));
519
+ console.info(colors__default["default"].cyan("Node.js version: ".concat(process.version)));
520
+ // <- TODO: [🧠][☑] Make robust system to check platform requirements like browser/node environment, version of node, available memory, disk space, ...
521
+ console.info(colors__default["default"].cyan("Platform type: ".concat(process.platform)));
522
+ console.info(colors__default["default"].cyan("Platform architecture: ".concat(process.arch)));
523
+ // console.info(colors.cyan(`Available memory: ${process.availableMemory()}`));
524
+ // <- TODO: [🧠] Should we show available memory / disk / ...
525
+ }
526
+ else if ($isRunningInJest()) {
527
+ console.info(colors__default["default"].cyan("Environment: Jest (testing)"));
528
+ }
529
+ else if ($isRunningInBrowser()) {
530
+ // <- Note: This is unreliable because CLI itself is not running in browser but for future use
531
+ console.info(colors__default["default"].cyan("Environment: Browser"));
532
+ }
533
+ else if ($isRunningInWebWorker()) {
534
+ // <- Note: This is unreliable because CLI itself is not running in browser but for future use
535
+ console.info(colors__default["default"].cyan("Environment: Web Worker"));
536
+ }
537
+ console.info(colors__default["default"].gray("https://github.com/webgptorg/promptbook"));
538
+ console.info(colors__default["default"].gray("https://ptbk.io"));
480
539
  return [2 /*return*/, process.exit(0)];
481
540
  });
482
541
  }); });
483
542
  }
484
543
  /**
544
+ * TODO: !!! Test this in `deno`
485
545
  * TODO: [🗽] Unite branding and make single place for it
486
546
  * Note: [💞] Ignore a discrepancy between file name and entity name
487
547
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -2131,107 +2191,6 @@
2131
2191
  * TODO: [🍏] Make for MacOS paths
2132
2192
  */
2133
2193
 
2134
- /**
2135
- * @@@
2136
- *
2137
- * @@@ .env
2138
- *
2139
- * It looks for environment variables:
2140
- * - `process.env.OPENAI_API_KEY`
2141
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2142
- * - ...
2143
- *
2144
- * @returns @@@
2145
- * @public exported from `@promptbook/node`
2146
- */
2147
- function $provideLlmToolsConfigurationFromEnv() {
2148
- return __awaiter(this, void 0, void 0, function () {
2149
- var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
2150
- var e_1, _a;
2151
- return __generator(this, function (_b) {
2152
- switch (_b.label) {
2153
- case 0:
2154
- if (!$isRunningInNode()) {
2155
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2156
- }
2157
- envFilePatterns = [
2158
- '.env',
2159
- '.env.test',
2160
- '.env.local',
2161
- '.env.development.local',
2162
- '.env.development',
2163
- '.env.production.local',
2164
- '.env.production',
2165
- '.env.prod.local',
2166
- '.env.prod',
2167
- // <- TODO: Maybe add more patterns
2168
- ];
2169
- rootDirname = process.cwd();
2170
- i = 0;
2171
- _b.label = 1;
2172
- case 1:
2173
- if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
2174
- _b.label = 2;
2175
- case 2:
2176
- _b.trys.push([2, 7, 8, 9]);
2177
- envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
2178
- _b.label = 3;
2179
- case 3:
2180
- if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
2181
- pattern = envFilePatterns_1_1.value;
2182
- envFilename = path.join(rootDirname, pattern);
2183
- return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
2184
- case 4:
2185
- if (_b.sent()) {
2186
- dotenv__namespace.config({ path: envFilename });
2187
- return [3 /*break*/, 11];
2188
- }
2189
- _b.label = 5;
2190
- case 5:
2191
- envFilePatterns_1_1 = envFilePatterns_1.next();
2192
- return [3 /*break*/, 3];
2193
- case 6: return [3 /*break*/, 9];
2194
- case 7:
2195
- e_1_1 = _b.sent();
2196
- e_1 = { error: e_1_1 };
2197
- return [3 /*break*/, 9];
2198
- case 8:
2199
- try {
2200
- if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
2201
- }
2202
- finally { if (e_1) throw e_1.error; }
2203
- return [7 /*endfinally*/];
2204
- case 9:
2205
- if (isRootPath(rootDirname)) {
2206
- return [3 /*break*/, 11];
2207
- }
2208
- // Note: If the directory does not exist, try the parent directory
2209
- rootDirname = path.join(rootDirname, '..');
2210
- _b.label = 10;
2211
- case 10:
2212
- i++;
2213
- return [3 /*break*/, 1];
2214
- case 11:
2215
- llmToolsConfiguration = $llmToolsMetadataRegister
2216
- .list()
2217
- .map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
2218
- .filter(function (configuration) { return configuration !== null; });
2219
- return [2 /*return*/, llmToolsConfiguration];
2220
- }
2221
- });
2222
- });
2223
- }
2224
- /**
2225
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
2226
- * TODO: Add Azure OpenAI
2227
- * TODO: [🧠][🍛]
2228
- * TODO: [🧠] Is there some meaningfull way how to test this util
2229
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2230
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2231
- * TODO: This should be maybe not under `_common` but under `utils`
2232
- * TODO: [🧠][⚛] Maybe pass env as argument
2233
- * TODO: [®] DRY Register logic */
2234
-
2235
2194
  /**
2236
2195
  * @@@
2237
2196
  *
@@ -2244,6 +2203,22 @@
2244
2203
  * TODO: [®] DRY Register logic
2245
2204
  */
2246
2205
 
2206
+ /**
2207
+ * Path to the `.env` file which was used to configure LLM tools
2208
+ *
2209
+ * Note: `$` is used to indicate that this variable is changed by side effect in `$provideLlmToolsConfigurationFromEnv` through `$setUsedEnvFilename`
2210
+ */
2211
+ var $usedEnvFilename = null;
2212
+ /**
2213
+ * Pass the `.env` file which was used to configure LLM tools
2214
+ *
2215
+ * Note: `$` is used to indicate that this variable is making side effect
2216
+ *
2217
+ * @private internal log of `$provideLlmToolsConfigurationFromEnv` and `$registeredLlmToolsMessage`
2218
+ */
2219
+ function $setUsedEnvFilename(filepath) {
2220
+ $usedEnvFilename = filepath;
2221
+ }
2247
2222
  /**
2248
2223
  * Creates a message with all registered LLM tools
2249
2224
  *
@@ -2322,10 +2297,11 @@
2322
2297
  // <- Note: [🗨]
2323
2298
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
2324
2299
  });
2300
+ var usedEnvMessage = $usedEnvFilename === null ? "Unknown `.env` file" : "Used `.env` file:\n".concat($usedEnvFilename);
2325
2301
  if (metadata.length === 0) {
2326
- return "No LLM providers are available.";
2302
+ return spaceTrim__default["default"](function (block) { return "\n No LLM providers are available.\n\n ".concat(block(usedEnvMessage), "\n "); });
2327
2303
  }
2328
- return spaceTrim__default["default"](function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
2304
+ return spaceTrim__default["default"](function (block) { return "\n\n ".concat(block(usedEnvMessage), "\n\n Relevant environment variables:\n ").concat(block(Object.keys(env)
2329
2305
  .filter(function (envVariableName) {
2330
2306
  return metadata.some(function (_a) {
2331
2307
  var envVariables = _a.envVariables;
@@ -2390,6 +2366,108 @@
2390
2366
  * TODO: [🧠][⚛] Maybe pass env as argument
2391
2367
  */
2392
2368
 
2369
+ /**
2370
+ * @@@
2371
+ *
2372
+ * @@@ .env
2373
+ *
2374
+ * It looks for environment variables:
2375
+ * - `process.env.OPENAI_API_KEY`
2376
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
2377
+ * - ...
2378
+ *
2379
+ * @returns @@@
2380
+ * @public exported from `@promptbook/node`
2381
+ */
2382
+ function $provideLlmToolsConfigurationFromEnv() {
2383
+ return __awaiter(this, void 0, void 0, function () {
2384
+ var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
2385
+ var e_1, _a;
2386
+ return __generator(this, function (_b) {
2387
+ switch (_b.label) {
2388
+ case 0:
2389
+ if (!$isRunningInNode()) {
2390
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
2391
+ }
2392
+ envFilePatterns = [
2393
+ '.env',
2394
+ '.env.test',
2395
+ '.env.local',
2396
+ '.env.development.local',
2397
+ '.env.development',
2398
+ '.env.production.local',
2399
+ '.env.production',
2400
+ '.env.prod.local',
2401
+ '.env.prod',
2402
+ // <- TODO: Maybe add more patterns
2403
+ ];
2404
+ rootDirname = process.cwd();
2405
+ i = 0;
2406
+ _b.label = 1;
2407
+ case 1:
2408
+ if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
2409
+ _b.label = 2;
2410
+ case 2:
2411
+ _b.trys.push([2, 7, 8, 9]);
2412
+ envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
2413
+ _b.label = 3;
2414
+ case 3:
2415
+ if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
2416
+ pattern = envFilePatterns_1_1.value;
2417
+ envFilename = path.join(rootDirname, pattern);
2418
+ return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
2419
+ case 4:
2420
+ if (_b.sent()) {
2421
+ $setUsedEnvFilename(envFilename);
2422
+ dotenv__namespace.config({ path: envFilename });
2423
+ return [3 /*break*/, 11];
2424
+ }
2425
+ _b.label = 5;
2426
+ case 5:
2427
+ envFilePatterns_1_1 = envFilePatterns_1.next();
2428
+ return [3 /*break*/, 3];
2429
+ case 6: return [3 /*break*/, 9];
2430
+ case 7:
2431
+ e_1_1 = _b.sent();
2432
+ e_1 = { error: e_1_1 };
2433
+ return [3 /*break*/, 9];
2434
+ case 8:
2435
+ try {
2436
+ if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
2437
+ }
2438
+ finally { if (e_1) throw e_1.error; }
2439
+ return [7 /*endfinally*/];
2440
+ case 9:
2441
+ if (isRootPath(rootDirname)) {
2442
+ return [3 /*break*/, 11];
2443
+ }
2444
+ // Note: If the directory does not exist, try the parent directory
2445
+ rootDirname = path.join(rootDirname, '..');
2446
+ _b.label = 10;
2447
+ case 10:
2448
+ i++;
2449
+ return [3 /*break*/, 1];
2450
+ case 11:
2451
+ llmToolsConfiguration = $llmToolsMetadataRegister
2452
+ .list()
2453
+ .map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
2454
+ .filter(function (configuration) { return configuration !== null; });
2455
+ return [2 /*return*/, llmToolsConfiguration];
2456
+ }
2457
+ });
2458
+ });
2459
+ }
2460
+ /**
2461
+ * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
2462
+ * TODO: Add Azure OpenAI
2463
+ * TODO: [🧠][🍛]
2464
+ * TODO: [🧠] Is there some meaningfull way how to test this util
2465
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
2466
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2467
+ * TODO: This should be maybe not under `_common` but under `utils`
2468
+ * TODO: [🧠][⚛] Maybe pass env as argument
2469
+ * TODO: [®] DRY Register logic */
2470
+
2393
2471
  /**
2394
2472
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2395
2473
  *
@@ -11217,33 +11295,6 @@
11217
11295
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
11218
11296
  */
11219
11297
 
11220
- /**
11221
- * Detects if the code is running in a browser environment in main thread (Not in a web worker)
11222
- *
11223
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
11224
- *
11225
- * @public exported from `@promptbook/utils`
11226
- */
11227
- var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
11228
-
11229
- /**
11230
- * Detects if the code is running in jest environment
11231
- *
11232
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
11233
- *
11234
- * @public exported from `@promptbook/utils`
11235
- */
11236
- var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
11237
-
11238
- /**
11239
- * Detects if the code is running in a web worker
11240
- *
11241
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
11242
- *
11243
- * @public exported from `@promptbook/utils`
11244
- */
11245
- var $isRunningInWebWorker = 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");
11246
-
11247
11298
  /**
11248
11299
  * Makes first letter of a string uppercase
11249
11300
  *