@promptbook/node 0.77.0-4 → 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
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  *
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0-3';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.0-5';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8947,7 +8947,7 @@ function $provideLlmToolsConfigurationFromEnv() {
8947
8947
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
8948
8948
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
8949
8949
  * TODO: This should be maybe not under `_common` but under `utils`
8950
- * TODO: [🧠] Maybe pass env as argument
8950
+ * TODO: [🧠][⚛] Maybe pass env as argument
8951
8951
  * TODO: [®] DRY Register logic */
8952
8952
 
8953
8953
  /**
@@ -8971,20 +8971,21 @@ var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
8971
8971
  */
8972
8972
  function $registeredLlmToolsMessage() {
8973
8973
  var e_1, _a, e_2, _b;
8974
+ var env = process.env;
8974
8975
  /**
8975
8976
  * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
8976
8977
  */
8977
8978
  var all = [];
8978
- var _loop_1 = function (packageName, className, envVariables) {
8979
+ var _loop_1 = function (title, packageName, className, envVariables) {
8979
8980
  if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
8980
8981
  return "continue";
8981
8982
  }
8982
- all.push({ packageName: packageName, className: className, envVariables: envVariables });
8983
+ all.push({ title: title, packageName: packageName, className: className, envVariables: envVariables });
8983
8984
  };
8984
8985
  try {
8985
8986
  for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
8986
- var _e = _d.value, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
8987
- _loop_1(packageName, className, envVariables);
8987
+ var _e = _d.value, title = _e.title, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
8988
+ _loop_1(title, packageName, className, envVariables);
8988
8989
  }
8989
8990
  }
8990
8991
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -9014,6 +9015,7 @@ function $registeredLlmToolsMessage() {
9014
9015
  finally { if (e_2) throw e_2.error; }
9015
9016
  }
9016
9017
  var metadata = all.map(function (metadata) {
9018
+ var _a, _b;
9017
9019
  var isMetadataAviailable = $llmToolsMetadataRegister
9018
9020
  .list()
9019
9021
  .find(function (_a) {
@@ -9026,46 +9028,77 @@ function $registeredLlmToolsMessage() {
9026
9028
  var packageName = _a.packageName, className = _a.className;
9027
9029
  return metadata.packageName === packageName && metadata.className === className;
9028
9030
  });
9029
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9031
+ var isFullyConfigured = ((_a = metadata.envVariables) === null || _a === void 0 ? void 0 : _a.every(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9032
+ var isPartiallyConfigured = ((_b = metadata.envVariables) === null || _b === void 0 ? void 0 : _b.some(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9033
+ // <- Note: [🗨]
9034
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
9030
9035
  });
9031
9036
  if (metadata.length === 0) {
9032
9037
  return "No LLM providers are available.";
9033
9038
  }
9034
- return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9039
+ return spaceTrim$1(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9040
+ .filter(function (envVariableName) {
9041
+ return metadata.some(function (_a) {
9042
+ var envVariables = _a.envVariables;
9043
+ return envVariables === null || envVariables === void 0 ? void 0 : envVariables.includes(envVariableName);
9044
+ });
9045
+ })
9046
+ .map(function (envVariableName) { return "- `".concat(envVariableName, "`"); })
9047
+ .join('\n')), "\n\n Available LLM providers are:\n ").concat(block(metadata
9035
9048
  .map(function (_a, i) {
9036
- var packageName = _a.packageName, className = _a.className, envVariables = _a.envVariables, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
9037
- var more;
9038
- if (just(false)) {
9039
- more = '';
9040
- }
9049
+ 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;
9050
+ var morePieces = [];
9051
+ if (just(false)) ;
9041
9052
  else if (!isMetadataAviailable && !isInstalled) {
9042
9053
  // TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
9043
- more = "(not installed and no metadata, looks like a unexpected behavior)";
9054
+ morePieces.push("Not installed and no metadata, looks like a unexpected behavior");
9044
9055
  }
9045
9056
  else if (isMetadataAviailable && !isInstalled) {
9046
9057
  // TODO: [�][�]
9047
- more = "(not installed)";
9058
+ morePieces.push("Not installed");
9048
9059
  }
9049
9060
  else if (!isMetadataAviailable && isInstalled) {
9050
- more = "(no metadata, looks like a unexpected behavior)";
9061
+ morePieces.push("No metadata but installed, looks like a unexpected behavior");
9051
9062
  }
9052
9063
  else if (isMetadataAviailable && isInstalled) {
9053
- more = "(installed)";
9064
+ morePieces.push("Installed");
9054
9065
  }
9055
9066
  else {
9056
- more = "(unknown state, looks like a unexpected behavior)";
9067
+ morePieces.push("unknown state, looks like a unexpected behavior");
9068
+ } /* not else */
9069
+ if (isFullyConfigured) {
9070
+ morePieces.push("Configured");
9071
+ }
9072
+ else if (isPartiallyConfigured) {
9073
+ morePieces.push("Partially confugured, missing ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.filter(function (envVariable) { return env[envVariable] === undefined; }).join(' + ')));
9057
9074
  }
9058
- var envVariablesMessage = '';
9059
- if (envVariables) {
9060
- envVariablesMessage = 'Configured by ' + envVariables.join(' + ');
9075
+ else {
9076
+ if (envVariables !== null) {
9077
+ morePieces.push("Not configured, to configure set env ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.join(' + ')));
9078
+ }
9079
+ else {
9080
+ morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
9081
+ }
9082
+ }
9083
+ var providerMessage = spaceTrim$1("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9084
+ if ($isRunningInNode) {
9085
+ if (isInstalled && isFullyConfigured) {
9086
+ providerMessage = colors.green(providerMessage);
9087
+ }
9088
+ else if (isInstalled && isPartiallyConfigured) {
9089
+ providerMessage = colors.yellow(providerMessage);
9090
+ }
9091
+ else {
9092
+ providerMessage = colors.gray(providerMessage);
9093
+ }
9061
9094
  }
9062
- return spaceTrim$1("\n ".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "`\n ").concat(more, "\n ").concat(envVariablesMessage, "\n "));
9063
- // <- TODO: !!!!!! Is this indented correctly?
9095
+ return providerMessage;
9064
9096
  })
9065
9097
  .join('\n')), "\n "); });
9066
9098
  }
9067
9099
  /**
9068
9100
  * TODO: [®] DRY Register logic
9101
+ * TODO: [🧠][⚛] Maybe pass env as argument
9069
9102
  */
9070
9103
 
9071
9104
  /**