@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.
@@ -145,6 +145,7 @@ import type { string_reserved_parameter_name } from '../types/typeAliases';
145
145
  import type { ReservedParameters } from '../types/typeAliases';
146
146
  import type { string_title } from '../types/typeAliases';
147
147
  import type { string_persona_description } from '../types/typeAliases';
148
+ import type { string_model_description } from '../types/typeAliases';
148
149
  import type { string_knowledge_source_content } from '../types/typeAliases';
149
150
  import type { string_knowledge_source_link } from '../types/typeAliases';
150
151
  import type { string_html } from '../types/typeAliases';
@@ -402,6 +403,7 @@ export type { string_reserved_parameter_name };
402
403
  export type { ReservedParameters };
403
404
  export type { string_title };
404
405
  export type { string_persona_description };
406
+ export type { string_model_description };
405
407
  export type { string_knowledge_source_content };
406
408
  export type { string_knowledge_source_link };
407
409
  export type { string_html };
@@ -1,4 +1,5 @@
1
1
  import type { ModelVariant } from '../types/ModelVariant';
2
+ import type { string_model_description } from '../types/typeAliases';
2
3
  import type { string_model_name } from '../types/typeAliases';
3
4
  import type { string_title } from '../types/typeAliases';
4
5
  /**
@@ -6,19 +7,32 @@ import type { string_title } from '../types/typeAliases';
6
7
  */
7
8
  export type AvailableModel = {
8
9
  /**
9
- * The model title
10
+ * The model title, when not provided, the `modelName` should be used
11
+ *
12
+ * @example "GPT o1"
10
13
  */
11
14
  readonly modelTitle?: string_title;
12
15
  /**
13
16
  * The model name aviailable
17
+ *
18
+ * @example "o1"
14
19
  */
15
20
  readonly modelName: string_model_name;
16
21
  /**
17
22
  * Variant of the model
23
+ *
24
+ * @example "CHAT"
18
25
  */
19
26
  readonly modelVariant: ModelVariant;
27
+ /**
28
+ * Unstructured description of the model
29
+ *
30
+ * This will be used to pick the best available model for each task
31
+ *
32
+ * @example "Model with 1 billion parameters and advanced reasoning capabilities"
33
+ */
34
+ readonly modelDescription?: string_model_description;
20
35
  };
21
36
  /**
22
- * TODO: !!!!!! Maybe remove `modelTitle`
23
37
  * TODO: !!!!!! Put pricing information here
24
38
  */
@@ -26,7 +26,7 @@ export type LlmExecutionTools = {
26
26
  *
27
27
  * @example "Use all models from OpenAI"
28
28
  */
29
- readonly description: string_markdown;
29
+ readonly description?: string_markdown;
30
30
  /**
31
31
  * Check comfiguration
32
32
  *
@@ -21,5 +21,5 @@ export declare function $provideLlmToolsConfigurationFromEnv(): LlmToolsConfigur
21
21
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
22
22
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
23
23
  * TODO: This should be maybe not under `_common` but under `utils`
24
- * TODO: [🧠] Maybe pass env as argument
24
+ * TODO: [🧠][⚛] Maybe pass env as argument
25
25
  * TODO: [®] DRY Register logic */
@@ -9,4 +9,5 @@ import type { string_markdown } from '../../../types/typeAliases';
9
9
  export declare function $registeredLlmToolsMessage(): string_markdown;
10
10
  /**
11
11
  * TODO: [®] DRY Register logic
12
+ * TODO: [🧠][⚛] Maybe pass env as argument
12
13
  */
@@ -1,7 +1,7 @@
1
- import type { string_SCREAMING_CASE } from '../../../utils/normalization/normalizeTo_SCREAMING_CASE';
2
1
  import type { string_name } from '../../../types/typeAliases';
3
2
  import type { string_title } from '../../../types/typeAliases';
4
3
  import type { Registered } from '../../../utils/$Register';
4
+ import type { string_SCREAMING_CASE } from '../../../utils/normalization/normalizeTo_SCREAMING_CASE';
5
5
  import type { LlmToolsConfiguration } from './LlmToolsConfiguration';
6
6
  /**
7
7
  * @@@
@@ -14,9 +14,12 @@ export type LlmToolsMetadata = Registered & {
14
14
  */
15
15
  readonly title: string_title;
16
16
  /**
17
- * @@@
17
+ * List of environment variables that can be used to configure the provider
18
+ *
19
+ * If `[]`, empty array, it means that the provider is available automatically without any configuration
20
+ * If `null`, it means that the provider can not be configured via environment variables
18
21
  */
19
- readonly envVariables: ReadonlyArray<string_name & string_SCREAMING_CASE>;
22
+ readonly envVariables: ReadonlyArray<string_name & string_SCREAMING_CASE> | null;
20
23
  /**
21
24
  * @@@
22
25
  */
@@ -1,12 +1,9 @@
1
1
  import type { createGoogleGenerativeAI } from '@ai-sdk/google';
2
- import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
2
+ import type { VercelExecutionToolsOptions } from '../vercel/VercelExecutionToolsOptions';
3
3
  /**
4
4
  * Options for `GoogleExecutionTools`
5
5
  *
6
- * !!!!!! This extends Google's `ClientOptions` with are directly passed to the Google generative AI client.
6
+ * This combines options for Promptbook, Google and Vercel together
7
7
  * @public exported from `@promptbook/google`
8
8
  */
9
- export type GoogleExecutionToolsOptions = CommonToolsOptions & Parameters<typeof createGoogleGenerativeAI>[0];
10
- /**
11
- * TODO: [🧠][🤺] Pass `userId`
12
- */
9
+ export type GoogleExecutionToolsOptions = Omit<VercelExecutionToolsOptions, 'title' | 'description' | 'vercelProvider' | 'availableModels'> & Parameters<typeof createGoogleGenerativeAI>[0];
@@ -1,12 +1,13 @@
1
1
  import type { AvailableModel } from '../../execution/AvailableModel';
2
2
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
3
+ import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
4
  import type { VercelProvider } from './VercelProvider';
4
5
  /**
5
6
  * Options for `createExecutionToolsFromVercelProvider`
6
7
  *
7
8
  * @public exported from `@promptbook/google`
8
9
  */
9
- export type VercelExecutionToolsOptions = CommonToolsOptions & {
10
+ export type VercelExecutionToolsOptions = CommonToolsOptions & Pick<LlmExecutionTools, 'title' | 'description'> & {
10
11
  /**
11
12
  * Vercel provider for the execution tools
12
13
  */
@@ -1,7 +1,7 @@
1
1
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
2
2
  import type { VercelExecutionToolsOptions } from './VercelExecutionToolsOptions';
3
3
  /**
4
- * !!!!!!
4
+ * Adapter which creates Promptbook execution tools from Vercel provider
5
5
  *
6
6
  * @public exported from `@promptbook/vercel`
7
7
  */
@@ -128,11 +128,17 @@ export type ReservedParameters = Record<string_reserved_parameter_name, string_p
128
128
  */
129
129
  export type string_title = string;
130
130
  /**
131
- * Description of persona
131
+ * Unstructured description of the persona
132
132
  *
133
133
  * For example `"Skilled copywriter"`
134
134
  */
135
135
  export type string_persona_description = string;
136
+ /**
137
+ * Unstructured description of the model
138
+ *
139
+ * For example `"Model with logical reasoning and creative mindset"`
140
+ */
141
+ export type string_model_description = string;
136
142
  /**
137
143
  * Source of one knowledge
138
144
  *
@@ -0,0 +1,11 @@
1
+ import type { really_any } from '../organization/really_any';
2
+ /**
3
+ * Function `asSerializable` will convert values which are not serializable to serializable values
4
+ * It walks deeply through the object and converts all values
5
+ *
6
+ * For example:
7
+ * - `Date` objects will be converted to string
8
+ *
9
+ * @private Internal helper function
10
+ */
11
+ export declare function asSerializable(value: really_any): really_any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.77.0-5",
3
+ "version": "0.77.0-6",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
@@ -54,6 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/core.index.d.ts",
56
56
  "dependencies": {
57
+ "colors": "1.4.0",
57
58
  "crypto-js": "4.2.0",
58
59
  "moment": "2.30.1",
59
60
  "papaparse": "5.4.1",
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('path'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('moment'), require('crypto-js/sha256')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'path', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'moment', 'crypto-js/sha256'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.path, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.moment, global.sha256));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, path, cryptoJs, hexEncoder, mimeTypes, moment, sha256) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('path'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('moment'), require('colors'), require('crypto-js/sha256')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'path', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'moment', 'colors', 'crypto-js/sha256'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.path, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.moment, global.colors, global.sha256));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, path, cryptoJs, hexEncoder, mimeTypes, moment, colors, sha256) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -10,6 +10,7 @@
10
10
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
11
11
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
12
12
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
13
+ var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
13
14
  var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
14
15
 
15
16
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
@@ -24,7 +25,7 @@
24
25
  *
25
26
  * @see https://github.com/webgptorg/promptbook
26
27
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0-4';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.0-5';
28
29
  /**
29
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -9608,6 +9609,15 @@
9608
9609
  * TODO: [®] DRY Register logic
9609
9610
  */
9610
9611
 
9612
+ /**
9613
+ * Detects if the code is running in a Node.js environment
9614
+ *
9615
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
9616
+ *
9617
+ * @public exported from `@promptbook/utils`
9618
+ */
9619
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
9620
+
9611
9621
  /**
9612
9622
  * Creates a message with all registered LLM tools
9613
9623
  *
@@ -9617,20 +9627,21 @@
9617
9627
  */
9618
9628
  function $registeredLlmToolsMessage() {
9619
9629
  var e_1, _a, e_2, _b;
9630
+ var env = process.env;
9620
9631
  /**
9621
9632
  * Mixes registered LLM tools from $llmToolsMetadataRegister and $llmToolsRegister
9622
9633
  */
9623
9634
  var all = [];
9624
- var _loop_1 = function (packageName, className, envVariables) {
9635
+ var _loop_1 = function (title, packageName, className, envVariables) {
9625
9636
  if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
9626
9637
  return "continue";
9627
9638
  }
9628
- all.push({ packageName: packageName, className: className, envVariables: envVariables });
9639
+ all.push({ title: title, packageName: packageName, className: className, envVariables: envVariables });
9629
9640
  };
9630
9641
  try {
9631
9642
  for (var _c = __values($llmToolsMetadataRegister.list()), _d = _c.next(); !_d.done; _d = _c.next()) {
9632
- var _e = _d.value, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
9633
- _loop_1(packageName, className, envVariables);
9643
+ var _e = _d.value, title = _e.title, packageName = _e.packageName, className = _e.className, envVariables = _e.envVariables;
9644
+ _loop_1(title, packageName, className, envVariables);
9634
9645
  }
9635
9646
  }
9636
9647
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -9660,6 +9671,7 @@
9660
9671
  finally { if (e_2) throw e_2.error; }
9661
9672
  }
9662
9673
  var metadata = all.map(function (metadata) {
9674
+ var _a, _b;
9663
9675
  var isMetadataAviailable = $llmToolsMetadataRegister
9664
9676
  .list()
9665
9677
  .find(function (_a) {
@@ -9672,46 +9684,77 @@
9672
9684
  var packageName = _a.packageName, className = _a.className;
9673
9685
  return metadata.packageName === packageName && metadata.className === className;
9674
9686
  });
9675
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
9687
+ var isFullyConfigured = ((_a = metadata.envVariables) === null || _a === void 0 ? void 0 : _a.every(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9688
+ var isPartiallyConfigured = ((_b = metadata.envVariables) === null || _b === void 0 ? void 0 : _b.some(function (envVariableName) { return env[envVariableName] !== undefined; })) || false;
9689
+ // <- Note: [🗨]
9690
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isFullyConfigured: isFullyConfigured, isPartiallyConfigured: isPartiallyConfigured });
9676
9691
  });
9677
9692
  if (metadata.length === 0) {
9678
9693
  return "No LLM providers are available.";
9679
9694
  }
9680
- return spaceTrim__default["default"](function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
9695
+ return spaceTrim__default["default"](function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
9696
+ .filter(function (envVariableName) {
9697
+ return metadata.some(function (_a) {
9698
+ var envVariables = _a.envVariables;
9699
+ return envVariables === null || envVariables === void 0 ? void 0 : envVariables.includes(envVariableName);
9700
+ });
9701
+ })
9702
+ .map(function (envVariableName) { return "- `".concat(envVariableName, "`"); })
9703
+ .join('\n')), "\n\n Available LLM providers are:\n ").concat(block(metadata
9681
9704
  .map(function (_a, i) {
9682
- var packageName = _a.packageName, className = _a.className, envVariables = _a.envVariables, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
9683
- var more;
9684
- if (just(false)) {
9685
- more = '';
9686
- }
9705
+ 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;
9706
+ var morePieces = [];
9707
+ if (just(false)) ;
9687
9708
  else if (!isMetadataAviailable && !isInstalled) {
9688
9709
  // TODO: [�][�] Maybe do allow to do auto-install if package not registered and not found
9689
- more = "(not installed and no metadata, looks like a unexpected behavior)";
9710
+ morePieces.push("Not installed and no metadata, looks like a unexpected behavior");
9690
9711
  }
9691
9712
  else if (isMetadataAviailable && !isInstalled) {
9692
9713
  // TODO: [�][�]
9693
- more = "(not installed)";
9714
+ morePieces.push("Not installed");
9694
9715
  }
9695
9716
  else if (!isMetadataAviailable && isInstalled) {
9696
- more = "(no metadata, looks like a unexpected behavior)";
9717
+ morePieces.push("No metadata but installed, looks like a unexpected behavior");
9697
9718
  }
9698
9719
  else if (isMetadataAviailable && isInstalled) {
9699
- more = "(installed)";
9720
+ morePieces.push("Installed");
9721
+ }
9722
+ else {
9723
+ morePieces.push("unknown state, looks like a unexpected behavior");
9724
+ } /* not else */
9725
+ if (isFullyConfigured) {
9726
+ morePieces.push("Configured");
9727
+ }
9728
+ else if (isPartiallyConfigured) {
9729
+ morePieces.push("Partially confugured, missing ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.filter(function (envVariable) { return env[envVariable] === undefined; }).join(' + ')));
9700
9730
  }
9701
9731
  else {
9702
- more = "(unknown state, looks like a unexpected behavior)";
9732
+ if (envVariables !== null) {
9733
+ morePieces.push("Not configured, to configure set env ".concat(envVariables === null || envVariables === void 0 ? void 0 : envVariables.join(' + ')));
9734
+ }
9735
+ else {
9736
+ morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
9737
+ }
9703
9738
  }
9704
- var envVariablesMessage = '';
9705
- if (envVariables) {
9706
- envVariablesMessage = 'Configured by ' + envVariables.join(' + ');
9739
+ var providerMessage = spaceTrim__default["default"]("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
9740
+ if ($isRunningInNode) {
9741
+ if (isInstalled && isFullyConfigured) {
9742
+ providerMessage = colors__default["default"].green(providerMessage);
9743
+ }
9744
+ else if (isInstalled && isPartiallyConfigured) {
9745
+ providerMessage = colors__default["default"].yellow(providerMessage);
9746
+ }
9747
+ else {
9748
+ providerMessage = colors__default["default"].gray(providerMessage);
9749
+ }
9707
9750
  }
9708
- return spaceTrim__default["default"]("\n ".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "`\n ").concat(more, "\n ").concat(envVariablesMessage, "\n "));
9709
- // <- TODO: !!!!!! Is this indented correctly?
9751
+ return providerMessage;
9710
9752
  })
9711
9753
  .join('\n')), "\n "); });
9712
9754
  }
9713
9755
  /**
9714
9756
  * TODO: [®] DRY Register logic
9757
+ * TODO: [🧠][⚛] Maybe pass env as argument
9715
9758
  */
9716
9759
 
9717
9760
  /**
@@ -10062,7 +10105,23 @@
10062
10105
  else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
10063
10106
  typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
10064
10107
  typeof env.AZUREOPENAI_API_KEY === 'string') {
10065
- throw new Error(spaceTrim__default["default"]("\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 ")));
10108
+ return null;
10109
+ /*
10110
+ Note: [🗨] Partial configuration is handled more gracefully elsewhere
10111
+ > throw new Error(
10112
+ > spaceTrim(`
10113
+ > You must provide all of the following environment variables:
10114
+ >
10115
+ > - AZUREOPENAI_RESOURCE_NAME (${
10116
+ > typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined'
10117
+ > })
10118
+ > - AZUREOPENAI_DEPLOYMENT_NAME (${
10119
+ > typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined'
10120
+ > })
10121
+ > - AZUREOPENAI_API_KEY (${typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined'})
10122
+ > `),
10123
+ > );
10124
+ */
10066
10125
  }
10067
10126
  return null;
10068
10127
  },
@@ -10181,9 +10240,8 @@
10181
10240
  title: 'Open AI Assistant',
10182
10241
  packageName: '@promptbook/openai',
10183
10242
  className: 'OpenAiAssistantExecutionTools',
10184
- envVariables: [
10185
- /* TODO: 'OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID' */
10186
- ],
10243
+ envVariables: null,
10244
+ // <- TODO: ['OPENAI_API_KEY', 'OPENAI_ASSISTANT_ID']
10187
10245
  getBoilerplateConfiguration: function () {
10188
10246
  return {
10189
10247
  title: 'Open AI Assistant (boilerplate)',