@promptbook/node 0.89.0-7 → 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 -16
  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 +63 -21
  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/umd/index.umd.js CHANGED
@@ -46,7 +46,7 @@
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-7';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1814,6 +1814,19 @@
1814
1814
  }
1815
1815
  }
1816
1816
 
1817
+ /**
1818
+ * Error thrown when a fetch request fails
1819
+ *
1820
+ * @public exported from `@promptbook/core`
1821
+ */
1822
+ class PromptbookFetchError extends Error {
1823
+ constructor(message) {
1824
+ super(message);
1825
+ this.name = 'PromptbookFetchError';
1826
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1827
+ }
1828
+ }
1829
+
1817
1830
  /**
1818
1831
  * Index of all custom errors
1819
1832
  *
@@ -1852,6 +1865,7 @@
1852
1865
  URIError,
1853
1866
  AggregateError,
1854
1867
  AuthenticationError,
1868
+ PromptbookFetchError,
1855
1869
  /*
1856
1870
  Note: Not widely supported
1857
1871
  > InternalError,
@@ -5063,17 +5077,24 @@
5063
5077
  /**
5064
5078
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5065
5079
  *
5066
- * @private as default `fetch` function used in Promptbook scrapers
5080
+ * @public exported from `@promptbook/core`
5067
5081
  */
5068
- const scraperFetch = async (url, init) => {
5082
+ const promptbookFetch = async (urlOrRequest, init) => {
5069
5083
  try {
5070
- return await fetch(url, init);
5084
+ return await fetch(urlOrRequest, init);
5071
5085
  }
5072
5086
  catch (error) {
5073
5087
  if (!(error instanceof Error)) {
5074
5088
  throw error;
5075
5089
  }
5076
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5090
+ let url;
5091
+ if (typeof urlOrRequest === 'string') {
5092
+ url = urlOrRequest;
5093
+ }
5094
+ else if (urlOrRequest instanceof Request) {
5095
+ url = urlOrRequest.url;
5096
+ }
5097
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
5077
5098
  Can not fetch "${url}"
5078
5099
 
5079
5100
  Fetch error:
@@ -5094,7 +5115,7 @@
5094
5115
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5095
5116
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
5096
5117
  var _a;
5097
- const { fetch = scraperFetch } = tools;
5118
+ const { fetch = promptbookFetch } = tools;
5098
5119
  const { knowledgeSourceContent } = knowledgeSource;
5099
5120
  let { name } = knowledgeSource;
5100
5121
  const { rootDirname = null,
@@ -9574,21 +9595,15 @@
9574
9595
  */
9575
9596
 
9576
9597
  /**
9577
- * @@@
9598
+ * Provides the path to the `.env` file
9578
9599
  *
9579
- * @@@ .env
9600
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9580
9601
  *
9581
- * It looks for environment variables:
9582
- * - `process.env.OPENAI_API_KEY`
9583
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9584
- * - ...
9585
- *
9586
- * @returns @@@
9587
- * @public exported from `@promptbook/node`
9602
+ * @private within the repository - for CLI utils
9588
9603
  */
9589
- async function $provideLlmToolsConfigurationFromEnv() {
9604
+ async function $provideEnvFilepath() {
9590
9605
  if (!$isRunningInNode()) {
9591
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9606
+ throw new EnvironmentMismatchError('Function `$provideEnvFilepath` works only in Node.js environment');
9592
9607
  }
9593
9608
  const envFilePatterns = [
9594
9609
  '.env',
@@ -9608,8 +9623,7 @@
9608
9623
  const envFilename = path.join(rootDirname, pattern);
9609
9624
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
9610
9625
  $setUsedEnvFilename(envFilename);
9611
- dotenv__namespace.config({ path: envFilename });
9612
- break up_to_root;
9626
+ return envFilename;
9613
9627
  }
9614
9628
  }
9615
9629
  if (isRootPath(rootDirname)) {
@@ -9618,6 +9632,34 @@
9618
9632
  // Note: If the directory does not exist, try the parent directory
9619
9633
  rootDirname = path.join(rootDirname, '..');
9620
9634
  }
9635
+ return null;
9636
+ }
9637
+ /**
9638
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9639
+ */
9640
+
9641
+ /**
9642
+ * @@@
9643
+ *
9644
+ * @@@ .env
9645
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9646
+ *
9647
+ * It looks for environment variables:
9648
+ * - `process.env.OPENAI_API_KEY`
9649
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9650
+ * - ...
9651
+ *
9652
+ * @returns @@@
9653
+ * @public exported from `@promptbook/node`
9654
+ */
9655
+ async function $provideLlmToolsConfigurationFromEnv() {
9656
+ if (!$isRunningInNode()) {
9657
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9658
+ }
9659
+ const envFilepath = await $provideEnvFilepath();
9660
+ if (envFilepath !== null) {
9661
+ dotenv__namespace.config({ path: envFilepath });
9662
+ }
9621
9663
  const llmToolsConfiguration = $llmToolsMetadataRegister
9622
9664
  .list()
9623
9665
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -9625,15 +9667,8 @@
9625
9667
  return llmToolsConfiguration;
9626
9668
  }
9627
9669
  /**
9628
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
9629
- * TODO: Add Azure OpenAI
9630
- * TODO: [🧠][🍛]
9631
- * TODO: [🧠] Is there some meaningfull way how to test this util
9632
9670
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9633
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9634
- * TODO: This should be maybe not under `_common` but under `utils`
9635
- * TODO: [🧠][⚛] Maybe pass env as argument
9636
- * TODO: [®] DRY Register logic */
9671
+ */
9637
9672
 
9638
9673
  /**
9639
9674
  * @@@
@@ -9692,6 +9727,7 @@
9692
9727
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9693
9728
  *
9694
9729
  * @@@ .env
9730
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9695
9731
  *
9696
9732
  * It looks for environment variables:
9697
9733
  * - `process.env.OPENAI_API_KEY`