@promptbook/remote-client 0.89.0-9 → 0.92.0-3

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 (41) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +160 -53
  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 +10 -4
  6. package/esm/typings/src/_packages/types.index.d.ts +18 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  9. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  10. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  11. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  12. package/esm/typings/src/config.d.ts +10 -19
  13. package/esm/typings/src/errors/0-index.d.ts +7 -4
  14. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  15. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  16. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  17. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  18. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  19. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  20. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  21. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  22. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  23. package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
  24. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  28. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  29. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  30. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  34. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  35. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  36. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  37. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  38. package/package.json +7 -3
  39. package/umd/index.umd.js +160 -53
  40. package/umd/index.umd.js.map +1 -1
  41. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/README.md CHANGED
@@ -244,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
244
244
 
245
245
 
246
246
 
247
+ ## 🔒 Security
248
+
249
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
250
+
247
251
  ## 📦 Packages _(for developers)_
248
252
 
249
253
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -300,7 +304,7 @@ The following glossary is used to clarify certain concepts:
300
304
  ### General LLM / AI terms
301
305
 
302
306
  - **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.
307
+ - [**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
308
  - **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
309
  - **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
310
  - **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 +312,6 @@ The following glossary is used to clarify certain concepts:
308
312
  - **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
313
  - **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
314
 
311
-
312
-
313
-
314
-
315
315
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
316
316
 
317
317
 
@@ -425,6 +425,8 @@ See [TODO.md](./TODO.md)
425
425
 
426
426
  ## 🖋️ Contributing
427
427
 
428
- We are open to pull requests, feedback, and suggestions.
428
+ 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).
429
+
430
+ ## 📞 Support
429
431
 
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/).
432
+ 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-9';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-3';
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
  /**
@@ -320,6 +320,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
320
320
  * @public exported from `@promptbook/core`
321
321
  */
322
322
  const ADMIN_GITHUB_NAME = 'hejny';
323
+ // <- TODO: [🐊] Pick the best claim
323
324
  /**
324
325
  * When the title is not provided, the default title is used
325
326
  *
@@ -443,6 +444,26 @@ class UnexpectedError extends Error {
443
444
  }
444
445
  }
445
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
+
446
467
  /**
447
468
  * Index of all custom errors
448
469
  *
@@ -463,7 +484,10 @@ const PROMPTBOOK_ERRORS = {
463
484
  PipelineExecutionError,
464
485
  PipelineLogicError,
465
486
  PipelineUrlError,
487
+ AuthenticationError,
488
+ PromptbookFetchError,
466
489
  UnexpectedError,
490
+ WrappedError,
467
491
  // TODO: [🪑]> VersionMismatchError,
468
492
  };
469
493
  /**
@@ -480,8 +504,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
480
504
  TypeError,
481
505
  URIError,
482
506
  AggregateError,
483
- AuthenticationError,
484
- PromptbookFetchError,
485
507
  /*
486
508
  Note: Not widely supported
487
509
  > InternalError,
@@ -530,6 +552,35 @@ function deserializeError(error) {
530
552
  return deserializedError;
531
553
  }
532
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
+
533
584
  /**
534
585
  * Creates a connection to the remote proxy server.
535
586
  *
@@ -539,17 +590,31 @@ function deserializeError(error) {
539
590
  */
540
591
  async function createRemoteClient(options) {
541
592
  const { remoteServerUrl } = options;
542
- let path = new URL(remoteServerUrl).pathname;
543
- if (path.endsWith('/')) {
544
- 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
+ `));
545
611
  }
546
- path = `${path}/socket.io`;
547
612
  return new Promise((resolve, reject) => {
548
613
  const socket = io(remoteServerUrl, {
549
614
  retries: CONNECTION_RETRIES_LIMIT,
550
615
  timeout: CONNECTION_TIMEOUT_MS,
551
- path,
552
- transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
616
+ path: '/socket.io',
617
+ transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
553
618
  });
554
619
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
555
620
  socket.on('connect', () => {
@@ -683,35 +748,6 @@ function isValidFilePath(filename) {
683
748
  * TODO: [🍏] Implement for MacOs
684
749
  */
685
750
 
686
- /**
687
- * Tests if given string is valid URL.
688
- *
689
- * Note: Dataurl are considered perfectly valid.
690
- * Note: There are two simmilar functions:
691
- * - `isValidUrl` which tests any URL
692
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
693
- *
694
- * @public exported from `@promptbook/utils`
695
- */
696
- function isValidUrl(url) {
697
- if (typeof url !== 'string') {
698
- return false;
699
- }
700
- try {
701
- if (url.startsWith('blob:')) {
702
- url = url.replace(/^blob:/, '');
703
- }
704
- const urlObject = new URL(url /* because fail is handled */);
705
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
706
- return false;
707
- }
708
- return true;
709
- }
710
- catch (error) {
711
- return false;
712
- }
713
- }
714
-
715
751
  const defaultDiacriticsRemovalMap = [
716
752
  {
717
753
  base: 'A',
@@ -1539,6 +1575,34 @@ const bookVersionCommandParser = {
1539
1575
  },
1540
1576
  };
1541
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
+
1542
1606
  /**
1543
1607
  * Units of text measurement
1544
1608
  *
@@ -1619,6 +1683,8 @@ function parseNumber(value) {
1619
1683
  */
1620
1684
 
1621
1685
  /**
1686
+ import { WrappedError } from '../../errors/WrappedError';
1687
+ import { assertsError } from '../../errors/assertsError';
1622
1688
  * Parses the expect command
1623
1689
  *
1624
1690
  * @see `documentationUrl` for more details
@@ -1710,9 +1776,7 @@ const expectCommandParser = {
1710
1776
  };
1711
1777
  }
1712
1778
  catch (error) {
1713
- if (!(error instanceof Error)) {
1714
- throw error;
1715
- }
1779
+ assertsError(error);
1716
1780
  throw new ParseError(spaceTrim$1((block) => `
1717
1781
  Invalid FORMAT command
1718
1782
  ${block(error.message)}:
@@ -1770,6 +1834,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
1770
1834
  // encoding: 'utf-8',
1771
1835
  });
1772
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
+
1773
1859
  /**
1774
1860
  * Definition for CSV spreadsheet
1775
1861
  *
@@ -1780,7 +1866,7 @@ const CsvFormatDefinition = {
1780
1866
  formatName: 'CSV',
1781
1867
  aliases: ['SPREADSHEET', 'TABLE'],
1782
1868
  isValid(value, settings, schema) {
1783
- return true;
1869
+ return isValidCsvString(value);
1784
1870
  },
1785
1871
  canBeValid(partialValue, settings, schema) {
1786
1872
  return true;
@@ -1861,6 +1947,9 @@ const CsvFormatDefinition = {
1861
1947
  /**
1862
1948
  * Function isValidJsonString will tell you if the string is valid JSON or not
1863
1949
  *
1950
+ * @param value The string to check
1951
+ * @returns True if the string is a valid JSON string, false otherwise
1952
+ *
1864
1953
  * @public exported from `@promptbook/utils`
1865
1954
  */
1866
1955
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -1869,9 +1958,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1869
1958
  return true;
1870
1959
  }
1871
1960
  catch (error) {
1872
- if (!(error instanceof Error)) {
1873
- throw error;
1874
- }
1961
+ assertsError(error);
1875
1962
  if (error.message.includes('Unexpected token')) {
1876
1963
  return false;
1877
1964
  }
@@ -1955,6 +2042,30 @@ const TextFormatDefinition = {
1955
2042
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
1956
2043
  */
1957
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
+
1958
2069
  /**
1959
2070
  * Definition for XML format
1960
2071
  *
@@ -1964,7 +2075,7 @@ const XmlFormatDefinition = {
1964
2075
  formatName: 'XML',
1965
2076
  mimeType: 'application/xml',
1966
2077
  isValid(value, settings, schema) {
1967
- return true;
2078
+ return isValidXmlString(value);
1968
2079
  },
1969
2080
  canBeValid(partialValue, settings, schema) {
1970
2081
  return true;
@@ -2189,9 +2300,7 @@ function checkSerializableAsJson(options) {
2189
2300
  JSON.stringify(value); // <- TODO: [0]
2190
2301
  }
2191
2302
  catch (error) {
2192
- if (!(error instanceof Error)) {
2193
- throw error;
2194
- }
2303
+ assertsError(error);
2195
2304
  throw new UnexpectedError(spaceTrim$1((block) => `
2196
2305
  \`${name}\` is not serializable
2197
2306
 
@@ -4846,9 +4955,7 @@ function extractVariablesFromJavascript(script) {
4846
4955
  }
4847
4956
  }
4848
4957
  catch (error) {
4849
- if (!(error instanceof Error)) {
4850
- throw error;
4851
- }
4958
+ assertsError(error);
4852
4959
  throw new ParseError(spaceTrim((block) => `
4853
4960
  Can not extract variables from the script
4854
4961
  ${block(error.stack || error.message)}