@promptbook/core 0.77.0-5 → 0.77.0-6

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/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-5';
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,21 @@ 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 = process.env;
9618
9629
  /**
9619
9630
  * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
9620
9631
  */
9621
9632
  var all = [];
9622
- var _loop_1 = function (packageName, className, envVariables) {
9633
+ var _loop_1 = function (title, packageName, className, envVariables) {
9623
9634
  if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9624
9635
  return "continue";
9625
9636
  }
9626
- all.push({ packageName: packageName, className: className, envVariables: envVariables });
9637
+ all.push({ title: title, packageName: packageName, className: className, envVariables: envVariables });
9627
9638
  };
9628
9639
  try {
9629
9640
  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);
9641
+ var _e = _d.value, title = _e.title, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
9642
+ _loop_1(title, packageName, className, envVariables);
9632
9643
  }
9633
9644
  }
9634
9645
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -9658,6 +9669,7 @@ function $registeredLlmToolsMessage() {
9658
9669
  finally { if (e_2) throw e_2.error; }
9659
9670
  }
9660
9671
  var metadata = all.map(function (metadata) {
9672
+ var _a, _b;
9661
9673
  var isMetadataAviailable = $llmToolsMetadataRegister
9662
9674
  .list()
9663
9675
  .find(function (_a) {
@@ -9670,46 +9682,77 @@ function $registeredLlmToolsMessage() {
9670
9682
  var packageName = _a.packageName, className = _a.className;
9671
9683
  return metadata.packageName === packageName && metadata.className === className;
9672
9684
  });
9673
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9685
+ var isFullyConfigured = ((_a = metadata.envVariables) === null || _a === void 0 ? void 0 : _a.every(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9686
+ var isPartiallyConfigured = ((_b = metadata.envVariables) === null || _b === void 0 ? void 0 : _b.some(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9687
+ // <- Note: [🗨]
9688
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
9674
9689
  });
9675
9690
  if (metadata.length === 0) {
9676
9691
  return "No LLM providers are available.";
9677
9692
  }
9678
- return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9693
+ return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9694
+ .filter(function (envVariableName) {
9695
+ return metadata.some(function (_a) {
9696
+ var envVariables = _a.envVariables;
9697
+ return envVariables === null || envVariables === void 0 ? void 0 : envVariables.includes(envVariableName);
9698
+ });
9699
+ })
9700
+ .map(function (envVariableName) { return "- `".concat(envVariableName, "`"); })
9701
+ .join('\n')), "\n\n Available LLM providers are:\n ").concat(block(metadata
9679
9702
  .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
- }
9703
+ 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;
9704
+ var morePieces = [];
9705
+ if (just(false)) ;
9685
9706
  else if (!isMetadataAviailable && !isInstalled) {
9686
9707
  // 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)";
9708
+ morePieces.push("Not installed and no metadata, looks like a unexpected behavior");
9688
9709
  }
9689
9710
  else if (isMetadataAviailable && !isInstalled) {
9690
9711
  // TODO: [�][�]
9691
- more = "(not installed)";
9712
+ morePieces.push("Not installed");
9692
9713
  }
9693
9714
  else if (!isMetadataAviailable && isInstalled) {
9694
- more = "(no metadata, looks like a unexpected behavior)";
9715
+ morePieces.push("No metadata but installed, looks like a unexpected behavior");
9695
9716
  }
9696
9717
  else if (isMetadataAviailable && isInstalled) {
9697
- more = "(installed)";
9718
+ morePieces.push("Installed");
9719
+ }
9720
+ else {
9721
+ morePieces.push("unknown state, looks like a unexpected behavior");
9722
+ } /* not else */
9723
+ if (isFullyConfigured) {
9724
+ morePieces.push("Configured");
9725
+ }
9726
+ else if (isPartiallyConfigured) {
9727
+ morePieces.push("Partially confugured, missing ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.filter(function (envVariable) { return env[envVariable] === undefined; }).join(' + ')));
9698
9728
  }
9699
9729
  else {
9700
- more = "(unknown state, looks like a unexpected behavior)";
9730
+ if (envVariables !== null) {
9731
+ morePieces.push("Not configured, to configure set env ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.join(' + ')));
9732
+ }
9733
+ else {
9734
+ morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
9735
+ }
9701
9736
  }
9702
- var envVariablesMessage = '';
9703
- if (envVariables) {
9704
- envVariablesMessage = 'Configured by ' + envVariables.join(' + ');
9737
+ var providerMessage = spaceTrim("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9738
+ if ($isRunningInNode) {
9739
+ if (isInstalled && isFullyConfigured) {
9740
+ providerMessage = colors.green(providerMessage);
9741
+ }
9742
+ else if (isInstalled && isPartiallyConfigured) {
9743
+ providerMessage = colors.yellow(providerMessage);
9744
+ }
9745
+ else {
9746
+ providerMessage = colors.gray(providerMessage);
9747
+ }
9705
9748
  }
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?
9749
+ return providerMessage;
9708
9750
  })
9709
9751
  .join('\n')), "\n "); });
9710
9752
  }
9711
9753
  /**
9712
9754
  * TODO: [®] DRY Register logic
9755
+ * TODO: [🧠][⚛] Maybe pass env as argument
9713
9756
  */
9714
9757
 
9715
9758
  /**
@@ -10060,7 +10103,23 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
10060
10103
  else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
10061
10104
  typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
10062
10105
  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 ")));
10106
+ return null;
10107
+ /*
10108
+ Note: [🗨] Partial configuration is handled more gracefully elsewhere
10109
+ > throw new Error(
10110
+ > spaceTrim(`
10111
+ > You must provide all of the following environment variables:
10112
+ >
10113
+ > - AZUREOPENAI_RESOURCE_NAME (${
10114
+ > typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined'
10115
+ > })
10116
+ > - AZUREOPENAI_DEPLOYMENT_NAME (${
10117
+ > typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined'
10118
+ > })
10119
+ > - AZUREOPENAI_API_KEY (${typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined'})
10120
+ > `),
10121
+ > );
10122
+ */
10064
10123
  }
10065
10124
  return null;
10066
10125
  },
@@ -10179,9 +10238,8 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
10179
10238
  title: 'Open AI Assistant',
10180
10239
  packageName: '@promptbook/openai',
10181
10240
  className: 'OpenAiAssistantExecutionTools',
10182
- envVariables: [
10183
- /* TODO: 'OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID' */
10184
- ],
10241
+ envVariables: null,
10242
+ // <- TODO: ['OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID']
10185
10243
  getBoilerplateConfiguration: function () {
10186
10244
  return {
10187
10245
  title: 'Open AI Assistant (boilerplate)',