@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 +0 -4
- package/esm/index.es.js +134 -104
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/cli/cli-commands/about.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +9 -0
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +3 -0
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +3 -0
- package/package.json +3 -3
- package/umd/index.umd.js +134 -104
- package/umd/index.umd.js.map +1 -1
|
@@ -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
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.84.0
|
|
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": "
|
|
41
|
+
"license": "BUSL-1.1",
|
|
42
42
|
"bugs": {
|
|
43
43
|
"url": "https://github.com/webgptorg/promptbook/issues"
|
|
44
44
|
},
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.84.0
|
|
50
|
+
"@promptbook/core": "0.84.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* @generated
|
|
46
46
|
* @see https://github.com/webgptorg/promptbook
|
|
47
47
|
*/
|
|
48
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
48
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
|
|
49
49
|
/**
|
|
50
50
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
51
51
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -9572,6 +9572,9 @@
|
|
|
9572
9572
|
* @public exported from `@promptbook/utils`
|
|
9573
9573
|
*/
|
|
9574
9574
|
var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
9575
|
+
/**
|
|
9576
|
+
* TODO: [☑]
|
|
9577
|
+
*/
|
|
9575
9578
|
|
|
9576
9579
|
/**
|
|
9577
9580
|
* Normalize options for `execCommand` and `execCommands`
|
|
@@ -10078,107 +10081,6 @@
|
|
|
10078
10081
|
* TODO: [🍏] Make for MacOS paths
|
|
10079
10082
|
*/
|
|
10080
10083
|
|
|
10081
|
-
/**
|
|
10082
|
-
* @@@
|
|
10083
|
-
*
|
|
10084
|
-
* @@@ .env
|
|
10085
|
-
*
|
|
10086
|
-
* It looks for environment variables:
|
|
10087
|
-
* - `process.env.OPENAI_API_KEY`
|
|
10088
|
-
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
10089
|
-
* - ...
|
|
10090
|
-
*
|
|
10091
|
-
* @returns @@@
|
|
10092
|
-
* @public exported from `@promptbook/node`
|
|
10093
|
-
*/
|
|
10094
|
-
function $provideLlmToolsConfigurationFromEnv() {
|
|
10095
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
10096
|
-
var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
|
|
10097
|
-
var e_1, _a;
|
|
10098
|
-
return __generator(this, function (_b) {
|
|
10099
|
-
switch (_b.label) {
|
|
10100
|
-
case 0:
|
|
10101
|
-
if (!$isRunningInNode()) {
|
|
10102
|
-
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
10103
|
-
}
|
|
10104
|
-
envFilePatterns = [
|
|
10105
|
-
'.env',
|
|
10106
|
-
'.env.test',
|
|
10107
|
-
'.env.local',
|
|
10108
|
-
'.env.development.local',
|
|
10109
|
-
'.env.development',
|
|
10110
|
-
'.env.production.local',
|
|
10111
|
-
'.env.production',
|
|
10112
|
-
'.env.prod.local',
|
|
10113
|
-
'.env.prod',
|
|
10114
|
-
// <- TODO: Maybe add more patterns
|
|
10115
|
-
];
|
|
10116
|
-
rootDirname = process.cwd();
|
|
10117
|
-
i = 0;
|
|
10118
|
-
_b.label = 1;
|
|
10119
|
-
case 1:
|
|
10120
|
-
if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
|
|
10121
|
-
_b.label = 2;
|
|
10122
|
-
case 2:
|
|
10123
|
-
_b.trys.push([2, 7, 8, 9]);
|
|
10124
|
-
envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
|
|
10125
|
-
_b.label = 3;
|
|
10126
|
-
case 3:
|
|
10127
|
-
if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
|
|
10128
|
-
pattern = envFilePatterns_1_1.value;
|
|
10129
|
-
envFilename = path.join(rootDirname, pattern);
|
|
10130
|
-
return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
|
|
10131
|
-
case 4:
|
|
10132
|
-
if (_b.sent()) {
|
|
10133
|
-
dotenv__namespace.config({ path: envFilename });
|
|
10134
|
-
return [3 /*break*/, 11];
|
|
10135
|
-
}
|
|
10136
|
-
_b.label = 5;
|
|
10137
|
-
case 5:
|
|
10138
|
-
envFilePatterns_1_1 = envFilePatterns_1.next();
|
|
10139
|
-
return [3 /*break*/, 3];
|
|
10140
|
-
case 6: return [3 /*break*/, 9];
|
|
10141
|
-
case 7:
|
|
10142
|
-
e_1_1 = _b.sent();
|
|
10143
|
-
e_1 = { error: e_1_1 };
|
|
10144
|
-
return [3 /*break*/, 9];
|
|
10145
|
-
case 8:
|
|
10146
|
-
try {
|
|
10147
|
-
if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
|
|
10148
|
-
}
|
|
10149
|
-
finally { if (e_1) throw e_1.error; }
|
|
10150
|
-
return [7 /*endfinally*/];
|
|
10151
|
-
case 9:
|
|
10152
|
-
if (isRootPath(rootDirname)) {
|
|
10153
|
-
return [3 /*break*/, 11];
|
|
10154
|
-
}
|
|
10155
|
-
// Note: If the directory does not exist, try the parent directory
|
|
10156
|
-
rootDirname = path.join(rootDirname, '..');
|
|
10157
|
-
_b.label = 10;
|
|
10158
|
-
case 10:
|
|
10159
|
-
i++;
|
|
10160
|
-
return [3 /*break*/, 1];
|
|
10161
|
-
case 11:
|
|
10162
|
-
llmToolsConfiguration = $llmToolsMetadataRegister
|
|
10163
|
-
.list()
|
|
10164
|
-
.map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
|
|
10165
|
-
.filter(function (configuration) { return configuration !== null; });
|
|
10166
|
-
return [2 /*return*/, llmToolsConfiguration];
|
|
10167
|
-
}
|
|
10168
|
-
});
|
|
10169
|
-
});
|
|
10170
|
-
}
|
|
10171
|
-
/**
|
|
10172
|
-
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
10173
|
-
* TODO: Add Azure OpenAI
|
|
10174
|
-
* TODO: [🧠][🍛]
|
|
10175
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
10176
|
-
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
10177
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
10178
|
-
* TODO: This should be maybe not under `_common` but under `utils`
|
|
10179
|
-
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
10180
|
-
* TODO: [®] DRY Register logic */
|
|
10181
|
-
|
|
10182
10084
|
/**
|
|
10183
10085
|
* @@@
|
|
10184
10086
|
*
|
|
@@ -10191,6 +10093,22 @@
|
|
|
10191
10093
|
* TODO: [®] DRY Register logic
|
|
10192
10094
|
*/
|
|
10193
10095
|
|
|
10096
|
+
/**
|
|
10097
|
+
* Path to the `.env` file which was used to configure LLM tools
|
|
10098
|
+
*
|
|
10099
|
+
* Note: `$` is used to indicate that this variable is changed by side effect in `$provideLlmToolsConfigurationFromEnv` through `$setUsedEnvFilename`
|
|
10100
|
+
*/
|
|
10101
|
+
var $usedEnvFilename = null;
|
|
10102
|
+
/**
|
|
10103
|
+
* Pass the `.env` file which was used to configure LLM tools
|
|
10104
|
+
*
|
|
10105
|
+
* Note: `$` is used to indicate that this variable is making side effect
|
|
10106
|
+
*
|
|
10107
|
+
* @private internal log of `$provideLlmToolsConfigurationFromEnv` and `$registeredLlmToolsMessage`
|
|
10108
|
+
*/
|
|
10109
|
+
function $setUsedEnvFilename(filepath) {
|
|
10110
|
+
$usedEnvFilename = filepath;
|
|
10111
|
+
}
|
|
10194
10112
|
/**
|
|
10195
10113
|
* Creates a message with all registered LLM tools
|
|
10196
10114
|
*
|
|
@@ -10269,10 +10187,11 @@
|
|
|
10269
10187
|
// <- Note: [🗨]
|
|
10270
10188
|
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
|
|
10271
10189
|
});
|
|
10190
|
+
var usedEnvMessage = $usedEnvFilename === null ? "Unknown `.env` file" : "Used `.env` file:\n".concat($usedEnvFilename);
|
|
10272
10191
|
if (metadata.length === 0) {
|
|
10273
|
-
return "No LLM providers are available.";
|
|
10192
|
+
return spaceTrim__default["default"](function (block) { return "\n No LLM providers are available.\n\n ".concat(block(usedEnvMessage), "\n "); });
|
|
10274
10193
|
}
|
|
10275
|
-
return spaceTrim__default["default"](function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
|
|
10194
|
+
return spaceTrim__default["default"](function (block) { return "\n\n ".concat(block(usedEnvMessage), "\n\n Relevant environment variables:\n ").concat(block(Object.keys(env)
|
|
10276
10195
|
.filter(function (envVariableName) {
|
|
10277
10196
|
return metadata.some(function (_a) {
|
|
10278
10197
|
var envVariables = _a.envVariables;
|
|
@@ -10337,6 +10256,108 @@
|
|
|
10337
10256
|
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
10338
10257
|
*/
|
|
10339
10258
|
|
|
10259
|
+
/**
|
|
10260
|
+
* @@@
|
|
10261
|
+
*
|
|
10262
|
+
* @@@ .env
|
|
10263
|
+
*
|
|
10264
|
+
* It looks for environment variables:
|
|
10265
|
+
* - `process.env.OPENAI_API_KEY`
|
|
10266
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
10267
|
+
* - ...
|
|
10268
|
+
*
|
|
10269
|
+
* @returns @@@
|
|
10270
|
+
* @public exported from `@promptbook/node`
|
|
10271
|
+
*/
|
|
10272
|
+
function $provideLlmToolsConfigurationFromEnv() {
|
|
10273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
10274
|
+
var envFilePatterns, rootDirname, i, envFilePatterns_1, envFilePatterns_1_1, pattern, envFilename, e_1_1, llmToolsConfiguration;
|
|
10275
|
+
var e_1, _a;
|
|
10276
|
+
return __generator(this, function (_b) {
|
|
10277
|
+
switch (_b.label) {
|
|
10278
|
+
case 0:
|
|
10279
|
+
if (!$isRunningInNode()) {
|
|
10280
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
10281
|
+
}
|
|
10282
|
+
envFilePatterns = [
|
|
10283
|
+
'.env',
|
|
10284
|
+
'.env.test',
|
|
10285
|
+
'.env.local',
|
|
10286
|
+
'.env.development.local',
|
|
10287
|
+
'.env.development',
|
|
10288
|
+
'.env.production.local',
|
|
10289
|
+
'.env.production',
|
|
10290
|
+
'.env.prod.local',
|
|
10291
|
+
'.env.prod',
|
|
10292
|
+
// <- TODO: Maybe add more patterns
|
|
10293
|
+
];
|
|
10294
|
+
rootDirname = process.cwd();
|
|
10295
|
+
i = 0;
|
|
10296
|
+
_b.label = 1;
|
|
10297
|
+
case 1:
|
|
10298
|
+
if (!(i < LOOP_LIMIT)) return [3 /*break*/, 11];
|
|
10299
|
+
_b.label = 2;
|
|
10300
|
+
case 2:
|
|
10301
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
10302
|
+
envFilePatterns_1 = (e_1 = void 0, __values(envFilePatterns)), envFilePatterns_1_1 = envFilePatterns_1.next();
|
|
10303
|
+
_b.label = 3;
|
|
10304
|
+
case 3:
|
|
10305
|
+
if (!!envFilePatterns_1_1.done) return [3 /*break*/, 6];
|
|
10306
|
+
pattern = envFilePatterns_1_1.value;
|
|
10307
|
+
envFilename = path.join(rootDirname, pattern);
|
|
10308
|
+
return [4 /*yield*/, isFileExisting(envFilename, $provideFilesystemForNode())];
|
|
10309
|
+
case 4:
|
|
10310
|
+
if (_b.sent()) {
|
|
10311
|
+
$setUsedEnvFilename(envFilename);
|
|
10312
|
+
dotenv__namespace.config({ path: envFilename });
|
|
10313
|
+
return [3 /*break*/, 11];
|
|
10314
|
+
}
|
|
10315
|
+
_b.label = 5;
|
|
10316
|
+
case 5:
|
|
10317
|
+
envFilePatterns_1_1 = envFilePatterns_1.next();
|
|
10318
|
+
return [3 /*break*/, 3];
|
|
10319
|
+
case 6: return [3 /*break*/, 9];
|
|
10320
|
+
case 7:
|
|
10321
|
+
e_1_1 = _b.sent();
|
|
10322
|
+
e_1 = { error: e_1_1 };
|
|
10323
|
+
return [3 /*break*/, 9];
|
|
10324
|
+
case 8:
|
|
10325
|
+
try {
|
|
10326
|
+
if (envFilePatterns_1_1 && !envFilePatterns_1_1.done && (_a = envFilePatterns_1.return)) _a.call(envFilePatterns_1);
|
|
10327
|
+
}
|
|
10328
|
+
finally { if (e_1) throw e_1.error; }
|
|
10329
|
+
return [7 /*endfinally*/];
|
|
10330
|
+
case 9:
|
|
10331
|
+
if (isRootPath(rootDirname)) {
|
|
10332
|
+
return [3 /*break*/, 11];
|
|
10333
|
+
}
|
|
10334
|
+
// Note: If the directory does not exist, try the parent directory
|
|
10335
|
+
rootDirname = path.join(rootDirname, '..');
|
|
10336
|
+
_b.label = 10;
|
|
10337
|
+
case 10:
|
|
10338
|
+
i++;
|
|
10339
|
+
return [3 /*break*/, 1];
|
|
10340
|
+
case 11:
|
|
10341
|
+
llmToolsConfiguration = $llmToolsMetadataRegister
|
|
10342
|
+
.list()
|
|
10343
|
+
.map(function (metadata) { return metadata.createConfigurationFromEnv(process.env); })
|
|
10344
|
+
.filter(function (configuration) { return configuration !== null; });
|
|
10345
|
+
return [2 /*return*/, llmToolsConfiguration];
|
|
10346
|
+
}
|
|
10347
|
+
});
|
|
10348
|
+
});
|
|
10349
|
+
}
|
|
10350
|
+
/**
|
|
10351
|
+
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
10352
|
+
* TODO: Add Azure OpenAI
|
|
10353
|
+
* TODO: [🧠][🍛]
|
|
10354
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
10355
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
10356
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
10357
|
+
* TODO: This should be maybe not under `_common` but under `utils`
|
|
10358
|
+
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
10359
|
+
* TODO: [®] DRY Register logic */
|
|
10360
|
+
|
|
10340
10361
|
/**
|
|
10341
10362
|
* @@@
|
|
10342
10363
|
*
|
|
@@ -10490,6 +10511,9 @@
|
|
|
10490
10511
|
* @public exported from `@promptbook/utils`
|
|
10491
10512
|
*/
|
|
10492
10513
|
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
10514
|
+
/**
|
|
10515
|
+
* TODO: [☑]
|
|
10516
|
+
*/
|
|
10493
10517
|
|
|
10494
10518
|
/**
|
|
10495
10519
|
* Detects if the code is running in jest environment
|
|
@@ -10499,6 +10523,9 @@
|
|
|
10499
10523
|
* @public exported from `@promptbook/utils`
|
|
10500
10524
|
*/
|
|
10501
10525
|
new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
|
|
10526
|
+
/**
|
|
10527
|
+
* TODO: [☑]
|
|
10528
|
+
*/
|
|
10502
10529
|
|
|
10503
10530
|
/**
|
|
10504
10531
|
* Detects if the code is running in a web worker
|
|
@@ -10508,6 +10535,9 @@
|
|
|
10508
10535
|
* @public exported from `@promptbook/utils`
|
|
10509
10536
|
*/
|
|
10510
10537
|
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");
|
|
10538
|
+
/**
|
|
10539
|
+
* TODO: [☑]
|
|
10540
|
+
*/
|
|
10511
10541
|
|
|
10512
10542
|
/**
|
|
10513
10543
|
* Makes first letter of a string uppercase
|