@promptbook/remote-client 0.89.0-8 → 0.89.0

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 (50) hide show
  1. package/README.md +9 -11
  2. package/esm/index.es.js +173 -52
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/servers.d.ts +40 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -4
  6. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
  7. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  8. package/esm/typings/src/_packages/types.index.d.ts +24 -14
  9. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  10. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  12. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  13. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  14. package/esm/typings/src/config.d.ts +10 -19
  15. package/esm/typings/src/errors/0-index.d.ts +8 -2
  16. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  17. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  18. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  19. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  20. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  21. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  22. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  23. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  24. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  25. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  26. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  28. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  29. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +15 -4
  30. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  31. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  32. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +9 -3
  34. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  35. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  36. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  37. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  38. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  39. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  40. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
  41. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +57 -38
  42. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  43. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  44. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  45. package/package.json +7 -3
  46. package/umd/index.umd.js +173 -52
  47. package/umd/index.umd.js.map +1 -1
  48. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
  49. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  50. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/README.md CHANGED
@@ -23,10 +23,6 @@
23
23
 
24
24
 
25
25
 
26
- <blockquote style="color: #ff8811">
27
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
- </blockquote>
29
-
30
26
  ## 📦 Package `@promptbook/remote-client`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -244,6 +240,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
244
240
 
245
241
 
246
242
 
243
+ ## 🔒 Security
244
+
245
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
246
+
247
247
  ## 📦 Packages _(for developers)_
248
248
 
249
249
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -300,7 +300,7 @@ The following glossary is used to clarify certain concepts:
300
300
  ### General LLM / AI terms
301
301
 
302
302
  - **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
303
- - **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
303
+ - [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
304
304
  - **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
305
305
  - **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
306
306
  - **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
@@ -308,10 +308,6 @@ The following glossary is used to clarify certain concepts:
308
308
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
309
309
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
310
310
 
311
-
312
-
313
-
314
-
315
311
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
316
312
 
317
313
 
@@ -425,6 +421,8 @@ See [TODO.md](./TODO.md)
425
421
 
426
422
  ## 🖋️ Contributing
427
423
 
428
- We are open to pull requests, feedback, and suggestions.
424
+ You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
425
+
426
+ ## 📞 Support
429
427
 
430
- You can also star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
428
+ If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  * @generated
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-8';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -238,7 +238,7 @@ class PipelineExecutionError extends Error {
238
238
  }
239
239
  }
240
240
  /**
241
- * TODO: !!!!!! Add id to all errors
241
+ * TODO: [🧠][🌂] Add id to all errors
242
242
  */
243
243
 
244
244
  /**
@@ -267,6 +267,19 @@ class PipelineUrlError extends Error {
267
267
  }
268
268
  }
269
269
 
270
+ /**
271
+ * Error thrown when a fetch request fails
272
+ *
273
+ * @public exported from `@promptbook/core`
274
+ */
275
+ class PromptbookFetchError extends Error {
276
+ constructor(message) {
277
+ super(message);
278
+ this.name = 'PromptbookFetchError';
279
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
280
+ }
281
+ }
282
+
270
283
  /**
271
284
  * Returns the same value that is passed as argument.
272
285
  * No side effects.
@@ -307,6 +320,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
307
320
  * @public exported from `@promptbook/core`
308
321
  */
309
322
  const ADMIN_GITHUB_NAME = 'hejny';
323
+ // <- TODO: [🐊] Pick the best claim
310
324
  /**
311
325
  * When the title is not provided, the default title is used
312
326
  *
@@ -430,6 +444,26 @@ class UnexpectedError extends Error {
430
444
  }
431
445
  }
432
446
 
447
+ /**
448
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
449
+ *
450
+ * @public exported from `@promptbook/core`
451
+ */
452
+ class WrappedError extends Error {
453
+ constructor(whatWasThrown) {
454
+ const tag = `[🤮]`;
455
+ console.error(tag, whatWasThrown);
456
+ super(spaceTrim(`
457
+ Non-Error object was thrown
458
+
459
+ Note: Look for ${tag} in the console for more details
460
+ Please report issue on ${ADMIN_EMAIL}
461
+ `));
462
+ this.name = 'WrappedError';
463
+ Object.setPrototypeOf(this, WrappedError.prototype);
464
+ }
465
+ }
466
+
433
467
  /**
434
468
  * Index of all custom errors
435
469
  *
@@ -450,7 +484,10 @@ const PROMPTBOOK_ERRORS = {
450
484
  PipelineExecutionError,
451
485
  PipelineLogicError,
452
486
  PipelineUrlError,
487
+ AuthenticationError,
488
+ PromptbookFetchError,
453
489
  UnexpectedError,
490
+ WrappedError,
454
491
  // TODO: [🪑]> VersionMismatchError,
455
492
  };
456
493
  /**
@@ -467,7 +504,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
467
504
  TypeError,
468
505
  URIError,
469
506
  AggregateError,
470
- AuthenticationError,
471
507
  /*
472
508
  Note: Not widely supported
473
509
  > InternalError,
@@ -516,6 +552,35 @@ function deserializeError(error) {
516
552
  return deserializedError;
517
553
  }
518
554
 
555
+ /**
556
+ * Tests if given string is valid URL.
557
+ *
558
+ * Note: Dataurl are considered perfectly valid.
559
+ * Note: There are two simmilar functions:
560
+ * - `isValidUrl` which tests any URL
561
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
562
+ *
563
+ * @public exported from `@promptbook/utils`
564
+ */
565
+ function isValidUrl(url) {
566
+ if (typeof url !== 'string') {
567
+ return false;
568
+ }
569
+ try {
570
+ if (url.startsWith('blob:')) {
571
+ url = url.replace(/^blob:/, '');
572
+ }
573
+ const urlObject = new URL(url /* because fail is handled */);
574
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
575
+ return false;
576
+ }
577
+ return true;
578
+ }
579
+ catch (error) {
580
+ return false;
581
+ }
582
+ }
583
+
519
584
  /**
520
585
  * Creates a connection to the remote proxy server.
521
586
  *
@@ -525,17 +590,31 @@ function deserializeError(error) {
525
590
  */
526
591
  async function createRemoteClient(options) {
527
592
  const { remoteServerUrl } = options;
528
- let path = new URL(remoteServerUrl).pathname;
529
- if (path.endsWith('/')) {
530
- path = path.slice(0, -1);
593
+ if (!isValidUrl(remoteServerUrl)) {
594
+ throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
595
+ }
596
+ const remoteServerUrlParsed = new URL(remoteServerUrl);
597
+ if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
598
+ remoteServerUrlParsed.pathname = '/';
599
+ throw new Error(spaceTrim$1((block) => `
600
+ Remote server requires root url \`/\`
601
+
602
+ You have provided \`remoteServerUrl\`:
603
+ ${block(remoteServerUrl)}
604
+
605
+ But something like this is expected:
606
+ ${block(remoteServerUrlParsed.href)}
607
+
608
+ Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
609
+
610
+ `));
531
611
  }
532
- path = `${path}/socket.io`;
533
612
  return new Promise((resolve, reject) => {
534
613
  const socket = io(remoteServerUrl, {
535
614
  retries: CONNECTION_RETRIES_LIMIT,
536
615
  timeout: CONNECTION_TIMEOUT_MS,
537
- path,
538
- transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
616
+ path: '/socket.io',
617
+ transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
539
618
  });
540
619
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
541
620
  socket.on('connect', () => {
@@ -669,35 +748,6 @@ function isValidFilePath(filename) {
669
748
  * TODO: [🍏] Implement for MacOs
670
749
  */
671
750
 
672
- /**
673
- * Tests if given string is valid URL.
674
- *
675
- * Note: Dataurl are considered perfectly valid.
676
- * Note: There are two simmilar functions:
677
- * - `isValidUrl` which tests any URL
678
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
679
- *
680
- * @public exported from `@promptbook/utils`
681
- */
682
- function isValidUrl(url) {
683
- if (typeof url !== 'string') {
684
- return false;
685
- }
686
- try {
687
- if (url.startsWith('blob:')) {
688
- url = url.replace(/^blob:/, '');
689
- }
690
- const urlObject = new URL(url /* because fail is handled */);
691
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
692
- return false;
693
- }
694
- return true;
695
- }
696
- catch (error) {
697
- return false;
698
- }
699
- }
700
-
701
751
  const defaultDiacriticsRemovalMap = [
702
752
  {
703
753
  base: 'A',
@@ -1525,6 +1575,34 @@ const bookVersionCommandParser = {
1525
1575
  },
1526
1576
  };
1527
1577
 
1578
+ /**
1579
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
1580
+ *
1581
+ * @param whatWasThrown Any object that was thrown
1582
+ * @returns Nothing if the error is an instance of `Error`
1583
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
1584
+ *
1585
+ * @private within the repository
1586
+ */
1587
+ function assertsError(whatWasThrown) {
1588
+ // Case 1: Handle error which was rethrown as `WrappedError`
1589
+ if (whatWasThrown instanceof WrappedError) {
1590
+ const wrappedError = whatWasThrown;
1591
+ throw wrappedError;
1592
+ }
1593
+ // Case 2: Handle unexpected errors
1594
+ if (whatWasThrown instanceof UnexpectedError) {
1595
+ const unexpectedError = whatWasThrown;
1596
+ throw unexpectedError;
1597
+ }
1598
+ // Case 3: Handle standard errors - keep them up to consumer
1599
+ if (whatWasThrown instanceof Error) {
1600
+ return;
1601
+ }
1602
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
1603
+ throw new WrappedError(whatWasThrown);
1604
+ }
1605
+
1528
1606
  /**
1529
1607
  * Units of text measurement
1530
1608
  *
@@ -1605,6 +1683,8 @@ function parseNumber(value) {
1605
1683
  */
1606
1684
 
1607
1685
  /**
1686
+ import { WrappedError } from '../../errors/WrappedError';
1687
+ import { assertsError } from '../../errors/assertsError';
1608
1688
  * Parses the expect command
1609
1689
  *
1610
1690
  * @see `documentationUrl` for more details
@@ -1696,9 +1776,7 @@ const expectCommandParser = {
1696
1776
  };
1697
1777
  }
1698
1778
  catch (error) {
1699
- if (!(error instanceof Error)) {
1700
- throw error;
1701
- }
1779
+ assertsError(error);
1702
1780
  throw new ParseError(spaceTrim$1((block) => `
1703
1781
  Invalid FORMAT command
1704
1782
  ${block(error.message)}:
@@ -1756,6 +1834,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
1756
1834
  // encoding: 'utf-8',
1757
1835
  });
1758
1836
 
1837
+ /**
1838
+ * Function to check if a string is valid CSV
1839
+ *
1840
+ * @param value The string to check
1841
+ * @returns True if the string is a valid CSV string, false otherwise
1842
+ *
1843
+ * @public exported from `@promptbook/utils`
1844
+ */
1845
+ function isValidCsvString(value) {
1846
+ try {
1847
+ // A simple check for CSV format: at least one comma and no invalid characters
1848
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
1849
+ return true;
1850
+ }
1851
+ return false;
1852
+ }
1853
+ catch (error) {
1854
+ assertsError(error);
1855
+ return false;
1856
+ }
1857
+ }
1858
+
1759
1859
  /**
1760
1860
  * Definition for CSV spreadsheet
1761
1861
  *
@@ -1766,7 +1866,7 @@ const CsvFormatDefinition = {
1766
1866
  formatName: 'CSV',
1767
1867
  aliases: ['SPREADSHEET', 'TABLE'],
1768
1868
  isValid(value, settings, schema) {
1769
- return true;
1869
+ return isValidCsvString(value);
1770
1870
  },
1771
1871
  canBeValid(partialValue, settings, schema) {
1772
1872
  return true;
@@ -1847,6 +1947,9 @@ const CsvFormatDefinition = {
1847
1947
  /**
1848
1948
  * Function isValidJsonString will tell you if the string is valid JSON or not
1849
1949
  *
1950
+ * @param value The string to check
1951
+ * @returns True if the string is a valid JSON string, false otherwise
1952
+ *
1850
1953
  * @public exported from `@promptbook/utils`
1851
1954
  */
1852
1955
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -1855,9 +1958,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1855
1958
  return true;
1856
1959
  }
1857
1960
  catch (error) {
1858
- if (!(error instanceof Error)) {
1859
- throw error;
1860
- }
1961
+ assertsError(error);
1861
1962
  if (error.message.includes('Unexpected token')) {
1862
1963
  return false;
1863
1964
  }
@@ -1941,6 +2042,30 @@ const TextFormatDefinition = {
1941
2042
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
1942
2043
  */
1943
2044
 
2045
+ /**
2046
+ * Function to check if a string is valid XML
2047
+ *
2048
+ * @param value
2049
+ * @returns True if the string is a valid XML string, false otherwise
2050
+ *
2051
+ * @public exported from `@promptbook/utils`
2052
+ */
2053
+ function isValidXmlString(value) {
2054
+ try {
2055
+ const parser = new DOMParser();
2056
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
2057
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
2058
+ if (parserError.length > 0) {
2059
+ return false;
2060
+ }
2061
+ return true;
2062
+ }
2063
+ catch (error) {
2064
+ assertsError(error);
2065
+ return false;
2066
+ }
2067
+ }
2068
+
1944
2069
  /**
1945
2070
  * Definition for XML format
1946
2071
  *
@@ -1950,7 +2075,7 @@ const XmlFormatDefinition = {
1950
2075
  formatName: 'XML',
1951
2076
  mimeType: 'application/xml',
1952
2077
  isValid(value, settings, schema) {
1953
- return true;
2078
+ return isValidXmlString(value);
1954
2079
  },
1955
2080
  canBeValid(partialValue, settings, schema) {
1956
2081
  return true;
@@ -2175,9 +2300,7 @@ function checkSerializableAsJson(options) {
2175
2300
  JSON.stringify(value); // <- TODO: [0]
2176
2301
  }
2177
2302
  catch (error) {
2178
- if (!(error instanceof Error)) {
2179
- throw error;
2180
- }
2303
+ assertsError(error);
2181
2304
  throw new UnexpectedError(spaceTrim$1((block) => `
2182
2305
  \`${name}\` is not serializable
2183
2306
 
@@ -4832,9 +4955,7 @@ function extractVariablesFromJavascript(script) {
4832
4955
  }
4833
4956
  }
4834
4957
  catch (error) {
4835
- if (!(error instanceof Error)) {
4836
- throw error;
4837
- }
4958
+ assertsError(error);
4838
4959
  throw new ParseError(spaceTrim((block) => `
4839
4960
  Can not extract variables from the script
4840
4961
  ${block(error.stack || error.message)}