@promptbook/node 0.89.0-8 → 0.89.0-9

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.
Files changed (25) hide show
  1. package/esm/index.es.js +63 -27
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
  5. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -18
  7. package/esm/typings/src/errors/0-index.d.ts +3 -0
  8. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  9. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilepath.d.ts +12 -0
  10. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  11. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  12. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +5 -3
  13. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  14. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  15. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  16. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  17. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  18. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
  19. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +43 -30
  20. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  21. package/package.json +2 -2
  22. package/umd/index.umd.js +63 -27
  23. package/umd/index.umd.js.map +1 -1
  24. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  25. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-8';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1798,6 +1798,19 @@ class NotYetImplementedError extends Error {
1798
1798
  }
1799
1799
  }
1800
1800
 
1801
+ /**
1802
+ * Error thrown when a fetch request fails
1803
+ *
1804
+ * @public exported from `@promptbook/core`
1805
+ */
1806
+ class PromptbookFetchError extends Error {
1807
+ constructor(message) {
1808
+ super(message);
1809
+ this.name = 'PromptbookFetchError';
1810
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1811
+ }
1812
+ }
1813
+
1801
1814
  /**
1802
1815
  * Index of all custom errors
1803
1816
  *
@@ -1836,6 +1849,7 @@ const COMMON_JAVASCRIPT_ERRORS = {
1836
1849
  URIError,
1837
1850
  AggregateError,
1838
1851
  AuthenticationError,
1852
+ PromptbookFetchError,
1839
1853
  /*
1840
1854
  Note: Not widely supported
1841
1855
  > InternalError,
@@ -5047,17 +5061,24 @@ function titleToName(value) {
5047
5061
  /**
5048
5062
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5049
5063
  *
5050
- * @private as default `fetch` function used in Promptbook scrapers
5064
+ * @public exported from `@promptbook/core`
5051
5065
  */
5052
- const scraperFetch = async (url, init) => {
5066
+ const promptbookFetch = async (urlOrRequest, init) => {
5053
5067
  try {
5054
- return await fetch(url, init);
5068
+ return await fetch(urlOrRequest, init);
5055
5069
  }
5056
5070
  catch (error) {
5057
5071
  if (!(error instanceof Error)) {
5058
5072
  throw error;
5059
5073
  }
5060
- throw new KnowledgeScrapeError(spaceTrim((block) => `
5074
+ let url;
5075
+ if (typeof urlOrRequest === 'string') {
5076
+ url = urlOrRequest;
5077
+ }
5078
+ else if (urlOrRequest instanceof Request) {
5079
+ url = urlOrRequest.url;
5080
+ }
5081
+ throw new PromptbookFetchError(spaceTrim((block) => `
5061
5082
  Can not fetch "${url}"
5062
5083
 
5063
5084
  Fetch error:
@@ -5078,7 +5099,7 @@ const scraperFetch = async (url, init) => {
5078
5099
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5079
5100
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
5080
5101
  var _a;
5081
- const { fetch = scraperFetch } = tools;
5102
+ const { fetch = promptbookFetch } = tools;
5082
5103
  const { knowledgeSourceContent } = knowledgeSource;
5083
5104
  let { name } = knowledgeSource;
5084
5105
  const { rootDirname = null,
@@ -9558,21 +9579,15 @@ function $registeredLlmToolsMessage() {
9558
9579
  */
9559
9580
 
9560
9581
  /**
9561
- * @@@
9582
+ * Provides the path to the `.env` file
9562
9583
  *
9563
- * @@@ .env
9584
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9564
9585
  *
9565
- * It looks for environment variables:
9566
- * - `process.env.OPENAI_API_KEY`
9567
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9568
- * - ...
9569
- *
9570
- * @returns @@@
9571
- * @public exported from `@promptbook/node`
9586
+ * @private within the repository - for CLI utils
9572
9587
  */
9573
- async function $provideLlmToolsConfigurationFromEnv() {
9588
+ async function $provideEnvFilepath() {
9574
9589
  if (!$isRunningInNode()) {
9575
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9590
+ throw new EnvironmentMismatchError('Function `$provideEnvFilepath` works only in Node.js environment');
9576
9591
  }
9577
9592
  const envFilePatterns = [
9578
9593
  '.env',
@@ -9592,8 +9607,7 @@ async function $provideLlmToolsConfigurationFromEnv() {
9592
9607
  const envFilename = join(rootDirname, pattern);
9593
9608
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
9594
9609
  $setUsedEnvFilename(envFilename);
9595
- dotenv.config({ path: envFilename });
9596
- break up_to_root;
9610
+ return envFilename;
9597
9611
  }
9598
9612
  }
9599
9613
  if (isRootPath(rootDirname)) {
@@ -9602,6 +9616,34 @@ async function $provideLlmToolsConfigurationFromEnv() {
9602
9616
  // Note: If the directory does not exist, try the parent directory
9603
9617
  rootDirname = join(rootDirname, '..');
9604
9618
  }
9619
+ return null;
9620
+ }
9621
+ /**
9622
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9623
+ */
9624
+
9625
+ /**
9626
+ * @@@
9627
+ *
9628
+ * @@@ .env
9629
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9630
+ *
9631
+ * It looks for environment variables:
9632
+ * - `process.env.OPENAI_API_KEY`
9633
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9634
+ * - ...
9635
+ *
9636
+ * @returns @@@
9637
+ * @public exported from `@promptbook/node`
9638
+ */
9639
+ async function $provideLlmToolsConfigurationFromEnv() {
9640
+ if (!$isRunningInNode()) {
9641
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9642
+ }
9643
+ const envFilepath = await $provideEnvFilepath();
9644
+ if (envFilepath !== null) {
9645
+ dotenv.config({ path: envFilepath });
9646
+ }
9605
9647
  const llmToolsConfiguration = $llmToolsMetadataRegister
9606
9648
  .list()
9607
9649
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -9609,15 +9651,8 @@ async function $provideLlmToolsConfigurationFromEnv() {
9609
9651
  return llmToolsConfiguration;
9610
9652
  }
9611
9653
  /**
9612
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
9613
- * TODO: Add Azure OpenAI
9614
- * TODO: [🧠][🍛]
9615
- * TODO: [🧠] Is there some meaningfull way how to test this util
9616
9654
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9617
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9618
- * TODO: This should be maybe not under `_common` but under `utils`
9619
- * TODO: [🧠][⚛] Maybe pass env as argument
9620
- * TODO: [®] DRY Register logic */
9655
+ */
9621
9656
 
9622
9657
  /**
9623
9658
  * @@@
@@ -9676,6 +9711,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
9676
9711
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9677
9712
  *
9678
9713
  * @@@ .env
9714
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9679
9715
  *
9680
9716
  * It looks for environment variables:
9681
9717
  * - `process.env.OPENAI_API_KEY`