@promptbook/core 0.77.0-5 → 0.77.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
@@ -23,10 +23,6 @@
23
23
 
24
24
 
25
25
 
26
- <blockquote style="color: #ff8811">
27
- <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>.
28
- </blockquote>
29
-
30
26
  ## 📦 Package `@promptbook/core`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -8,6 +8,7 @@ import { SHA256 } from 'crypto-js';
8
8
  import hexEncoder from 'crypto-js/enc-hex';
9
9
  import { lookup } from 'mime-types';
10
10
  import moment from 'moment';
11
+ import colors from 'colors';
11
12
  import sha256 from 'crypto-js/sha256';
12
13
 
13
14
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -22,7 +23,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
22
23
  *
23
24
  * @see https://github.com/webgptorg/promptbook
24
25
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0-4';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.0-6';
26
27
  /**
27
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -9606,6 +9607,15 @@ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
9606
9607
  * TODO: [®] DRY Register logic
9607
9608
  */
9608
9609
 
9610
+ /**
9611
+ * Detects if the code is running in a Node.js environment
9612
+ *
9613
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
9614
+ *
9615
+ * @public exported from `@promptbook/utils`
9616
+ */
9617
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
9618
+
9609
9619
  /**
9610
9620
  * Creates a message with all registered LLM tools
9611
9621
  *
@@ -9615,20 +9625,28 @@ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
9615
9625
  */
9616
9626
  function $registeredLlmToolsMessage() {
9617
9627
  var e_1, _a, e_2, _b;
9628
+ var env;
9629
+ if ($isRunningInNode()) {
9630
+ env = process.env;
9631
+ // <- TODO: [⚛] Some DRY way how to get to `process.env` and pass it into functions - ACRY search for `env`
9632
+ }
9633
+ else {
9634
+ env = {};
9635
+ }
9618
9636
  /**
9619
9637
  * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
9620
9638
  */
9621
9639
  var all = [];
9622
- var _loop_1 = function (packageName, className, envVariables) {
9640
+ var _loop_1 = function (title, packageName, className, envVariables) {
9623
9641
  if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9624
9642
  return "continue";
9625
9643
  }
9626
- all.push({ packageName: packageName, className: className, envVariables: envVariables });
9644
+ all.push({ title: title, packageName: packageName, className: className, envVariables: envVariables });
9627
9645
  };
9628
9646
  try {
9629
9647
  for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
9630
- var _e = _d.value, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
9631
- _loop_1(packageName, className, envVariables);
9648
+ var _e = _d.value, title = _e.title, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
9649
+ _loop_1(title, packageName, className, envVariables);
9632
9650
  }
9633
9651
  }
9634
9652
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -9658,6 +9676,7 @@ function $registeredLlmToolsMessage() {
9658
9676
  finally { if (e_2) throw e_2.error; }
9659
9677
  }
9660
9678
  var metadata = all.map(function (metadata) {
9679
+ var _a, _b;
9661
9680
  var isMetadataAviailable = $llmToolsMetadataRegister
9662
9681
  .list()
9663
9682
  .find(function (_a) {
@@ -9670,46 +9689,77 @@ function $registeredLlmToolsMessage() {
9670
9689
  var packageName = _a.packageName, className = _a.className;
9671
9690
  return metadata.packageName === packageName && metadata.className === className;
9672
9691
  });
9673
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9692
+ var isFullyConfigured = ((_a = metadata.envVariables) === null || _a === void 0 ? void 0 : _a.every(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9693
+ var isPartiallyConfigured = ((_b = metadata.envVariables) === null || _b === void 0 ? void 0 : _b.some(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9694
+ // <- Note: [🗨]
9695
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
9674
9696
  });
9675
9697
  if (metadata.length === 0) {
9676
9698
  return "No LLM providers are available.";
9677
9699
  }
9678
- return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9700
+ return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9701
+ .filter(function (envVariableName) {
9702
+ return metadata.some(function (_a) {
9703
+ var envVariables = _a.envVariables;
9704
+ return envVariables === null || envVariables === void 0 ? void 0 : envVariables.includes(envVariableName);
9705
+ });
9706
+ })
9707
+ .map(function (envVariableName) { return "- `".concat(envVariableName, "`"); })
9708
+ .join('\n')), "\n\n Available LLM providers are:\n ").concat(block(metadata
9679
9709
  .map(function (_a, i) {
9680
- var packageName = _a.packageName, className = _a.className, envVariables = _a.envVariables, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
9681
- var more;
9682
- if (just(false)) {
9683
- more = '';
9684
- }
9710
+ var title = _a.title, packageName = _a.packageName, className = _a.className, envVariables = _a.envVariables, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, isFullyConfigured = _a.isFullyConfigured, isPartiallyConfigured = _a.isPartiallyConfigured;
9711
+ var morePieces = [];
9712
+ if (just(false)) ;
9685
9713
  else if (!isMetadataAviailable && !isInstalled) {
9686
9714
  // TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
9687
- more = "(not installed and no metadata, looks like a unexpected behavior)";
9715
+ morePieces.push("Not installed and no metadata, looks like a unexpected behavior");
9688
9716
  }
9689
9717
  else if (isMetadataAviailable && !isInstalled) {
9690
9718
  // TODO: [�][�]
9691
- more = "(not installed)";
9719
+ morePieces.push("Not installed");
9692
9720
  }
9693
9721
  else if (!isMetadataAviailable && isInstalled) {
9694
- more = "(no metadata, looks like a unexpected behavior)";
9722
+ morePieces.push("No metadata but installed, looks like a unexpected behavior");
9695
9723
  }
9696
9724
  else if (isMetadataAviailable && isInstalled) {
9697
- more = "(installed)";
9725
+ morePieces.push("Installed");
9698
9726
  }
9699
9727
  else {
9700
- more = "(unknown state, looks like a unexpected behavior)";
9728
+ morePieces.push("unknown state, looks like a unexpected behavior");
9729
+ } /* not else */
9730
+ if (isFullyConfigured) {
9731
+ morePieces.push("Configured");
9701
9732
  }
9702
- var envVariablesMessage = '';
9703
- if (envVariables) {
9704
- envVariablesMessage = 'Configured by ' + envVariables.join(' + ');
9733
+ else if (isPartiallyConfigured) {
9734
+ morePieces.push("Partially confugured, missing ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.filter(function (envVariable) { return env[envVariable] === undefined; }).join(' + ')));
9705
9735
  }
9706
- return spaceTrim("\n ".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "`\n ").concat(more, "\n ").concat(envVariablesMessage, "\n "));
9707
- // <- TODO: !!!!!! Is this indented correctly?
9736
+ else {
9737
+ if (envVariables !== null) {
9738
+ morePieces.push("Not configured, to configure set env ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.join(' + ')));
9739
+ }
9740
+ else {
9741
+ morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
9742
+ }
9743
+ }
9744
+ var providerMessage = spaceTrim("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9745
+ if ($isRunningInNode) {
9746
+ if (isInstalled && isFullyConfigured) {
9747
+ providerMessage = colors.green(providerMessage);
9748
+ }
9749
+ else if (isInstalled && isPartiallyConfigured) {
9750
+ providerMessage = colors.yellow(providerMessage);
9751
+ }
9752
+ else {
9753
+ providerMessage = colors.gray(providerMessage);
9754
+ }
9755
+ }
9756
+ return providerMessage;
9708
9757
  })
9709
9758
  .join('\n')), "\n "); });
9710
9759
  }
9711
9760
  /**
9712
9761
  * TODO: [®] DRY Register logic
9762
+ * TODO: [🧠][⚛] Maybe pass env as argument
9713
9763
  */
9714
9764
 
9715
9765
  /**
@@ -10060,7 +10110,23 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
10060
10110
  else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
10061
10111
  typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
10062
10112
  typeof env.AZUREOPENAI_API_KEY === 'string') {
10063
- throw new Error(spaceTrim("\n You must provide all of the following environment variables:\n\n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ")\n ")));
10113
+ return null;
10114
+ /*
10115
+ Note: [🗨] Partial configuration is handled more gracefully elsewhere
10116
+ > throw new Error(
10117
+ > spaceTrim(`
10118
+ > You must provide all of the following environment variables:
10119
+ >
10120
+ > - AZUREOPENAI_RESOURCE_NAME (${
10121
+ > typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined'
10122
+ > })
10123
+ > - AZUREOPENAI_DEPLOYMENT_NAME (${
10124
+ > typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined'
10125
+ > })
10126
+ > - AZUREOPENAI_API_KEY (${typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined'})
10127
+ > `),
10128
+ > );
10129
+ */
10064
10130
  }
10065
10131
  return null;
10066
10132
  },
@@ -10097,10 +10163,7 @@ var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
10097
10163
  packageName: '@promptbook/google',
10098
10164
  className: 'GoogleExecutionTools',
10099
10165
  options: {
10100
- apiKey: 'sk-ant-api03-',
10101
- isProxied: true,
10102
- remoteUrl: DEFAULT_REMOTE_URL,
10103
- path: DEFAULT_REMOTE_URL_PATH,
10166
+ apiKey: 'AI',
10104
10167
  },
10105
10168
  };
10106
10169
  },
@@ -10179,9 +10242,8 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
10179
10242
  title: 'Open AI Assistant',
10180
10243
  packageName: '@promptbook/openai',
10181
10244
  className: 'OpenAiAssistantExecutionTools',
10182
- envVariables: [
10183
- /* TODO: 'OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID' */
10184
- ],
10245
+ envVariables: null,
10246
+ // <- TODO: ['OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID']
10185
10247
  getBoilerplateConfiguration: function () {
10186
10248
  return {
10187
10249
  title: 'Open AI Assistant (boilerplate)',