@promptbook/remote-server 0.88.0-10 โ†’ 0.88.0-12

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.
package/README.md CHANGED
@@ -68,6 +68,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
68
68
 
69
69
 
70
70
 
71
+
72
+
73
+
71
74
  ## ๐Ÿš€ Get started
72
75
 
73
76
  Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
@@ -79,6 +82,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
79
82
 
80
83
 
81
84
 
85
+
86
+
82
87
  ## ๐Ÿ’œ The Promptbook Project
83
88
 
84
89
  Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
@@ -396,7 +401,7 @@ See [TODO.md](./TODO.md)
396
401
  <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
397
402
  <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
398
403
  </a>
399
-
404
+
400
405
  </div>
401
406
 
402
407
  ## ๐Ÿ–‹๏ธ Contributing
package/esm/index.es.js CHANGED
@@ -4,11 +4,11 @@ import http from 'http';
4
4
  import { Server } from 'socket.io';
5
5
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
6
6
  import { forTime } from 'waitasecond';
7
+ import { randomBytes } from 'crypto';
7
8
  import { spawn } from 'child_process';
8
9
  import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
9
10
  import { join, basename, dirname } from 'path';
10
11
  import { Subject } from 'rxjs';
11
- import { randomBytes } from 'crypto';
12
12
  import { format } from 'prettier';
13
13
  import parserHtml from 'prettier/parser-html';
14
14
  import hexEncoder from 'crypto-js/enc-hex';
@@ -31,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
31
31
  * @generated
32
32
  * @see https://github.com/webgptorg/promptbook
33
33
  */
34
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-10';
34
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-12';
35
35
  /**
36
36
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
37
37
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -154,7 +154,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
154
154
  *
155
155
  * @public exported from `@promptbook/core`
156
156
  */
157
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
157
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
158
158
  // <- TODO: [๐Ÿ•] Make also `BOOKS_DIRNAME_ALTERNATIVES`
159
159
  /**
160
160
  * Where to store the temporary downloads
@@ -210,6 +210,21 @@ true);
210
210
  * TODO: [๐Ÿง ][๐Ÿงœโ€โ™‚๏ธ] Maybe join remoteUrl and path into single value
211
211
  */
212
212
 
213
+ /**
214
+ * Generates random token
215
+ *
216
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
217
+ *
218
+ * @private internal helper function
219
+ * @returns secure random token
220
+ */
221
+ function $randomToken(randomness) {
222
+ return randomBytes(randomness).toString('hex');
223
+ }
224
+ /**
225
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
226
+ */
227
+
213
228
  /**
214
229
  * This error indicates errors during the execution of the pipeline
215
230
  *
@@ -217,11 +232,17 @@ true);
217
232
  */
218
233
  class PipelineExecutionError extends Error {
219
234
  constructor(message) {
235
+ // Added id parameter
220
236
  super(message);
221
237
  this.name = 'PipelineExecutionError';
238
+ // TODO: [๐Ÿ™] DRY - Maybe $randomId
239
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
222
240
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
223
241
  }
224
242
  }
243
+ /**
244
+ * TODO: !!!!!! Add id to all errors
245
+ */
225
246
 
226
247
  /**
227
248
  * This error indicates problems parsing the format value
@@ -551,19 +572,21 @@ const ALL_ERRORS = {
551
572
  */
552
573
  function serializeError(error) {
553
574
  const { name, message, stack } = error;
575
+ const { id } = error;
554
576
  if (!Object.keys(ALL_ERRORS).includes(name)) {
555
577
  console.error(spaceTrim$1((block) => `
556
-
578
+
557
579
  Cannot serialize error with name "${name}"
558
580
 
559
581
  ${block(stack || message)}
560
-
582
+
561
583
  `));
562
584
  }
563
585
  return {
564
586
  name: name,
565
587
  message,
566
588
  stack,
589
+ id, // Include id in the serialized object
567
590
  };
568
591
  }
569
592
 
@@ -1706,21 +1729,6 @@ function isPipelinePrepared(pipeline) {
1706
1729
  * - [โ™จ] Are tasks prepared
1707
1730
  */
1708
1731
 
1709
- /**
1710
- * Generates random token
1711
- *
1712
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1713
- *
1714
- * @private internal helper function
1715
- * @returns secure random token
1716
- */
1717
- function $randomToken(randomness) {
1718
- return randomBytes(randomness).toString('hex');
1719
- }
1720
- /**
1721
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1722
- */
1723
-
1724
1732
  /**
1725
1733
  * Function isValidJsonString will tell you if the string is valid JSON or not
1726
1734
  *
@@ -1778,7 +1786,7 @@ function jsonStringsToJsons(object) {
1778
1786
  * @public exported from `@promptbook/utils`
1779
1787
  */
1780
1788
  function deserializeError(error) {
1781
- const { name, stack } = error;
1789
+ const { name, stack, id } = error; // Added id
1782
1790
  let { message } = error;
1783
1791
  let ErrorClass = ALL_ERRORS[error.name];
1784
1792
  if (ErrorClass === undefined) {
@@ -1793,7 +1801,9 @@ function deserializeError(error) {
1793
1801
  ${block(stack || '')}
1794
1802
  `);
1795
1803
  }
1796
- return new ErrorClass(message);
1804
+ const deserializedError = new ErrorClass(message);
1805
+ deserializedError.id = id; // Assign id to the error object
1806
+ return deserializedError;
1797
1807
  }
1798
1808
 
1799
1809
  /**
@@ -1843,6 +1853,7 @@ function assertsTaskSuccessful(executionResult) {
1843
1853
  */
1844
1854
  function createTask(options) {
1845
1855
  const { taskType, taskProcessCallback } = options;
1856
+ // TODO: [๐Ÿ™] DRY
1846
1857
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1847
1858
  let status = 'RUNNING';
1848
1859
  const createdAt = new Date();
@@ -4691,6 +4702,9 @@ function countCharacters(text) {
4691
4702
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4692
4703
  return text.length;
4693
4704
  }
4705
+ /**
4706
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4707
+ */
4694
4708
 
4695
4709
  /**
4696
4710
  * Number of characters per standard line with 11pt Arial font size.
@@ -4722,6 +4736,9 @@ function countLines(text) {
4722
4736
  const lines = text.split('\n');
4723
4737
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4724
4738
  }
4739
+ /**
4740
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4741
+ */
4725
4742
 
4726
4743
  /**
4727
4744
  * Counts number of pages in the text
@@ -4733,6 +4750,9 @@ function countLines(text) {
4733
4750
  function countPages(text) {
4734
4751
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4735
4752
  }
4753
+ /**
4754
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4755
+ */
4736
4756
 
4737
4757
  /**
4738
4758
  * Counts number of paragraphs in the text
@@ -4742,6 +4762,9 @@ function countPages(text) {
4742
4762
  function countParagraphs(text) {
4743
4763
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4744
4764
  }
4765
+ /**
4766
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4767
+ */
4745
4768
 
4746
4769
  /**
4747
4770
  * Split text into sentences
@@ -4759,6 +4782,9 @@ function splitIntoSentences(text) {
4759
4782
  function countSentences(text) {
4760
4783
  return splitIntoSentences(text).length;
4761
4784
  }
4785
+ /**
4786
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4787
+ */
4762
4788
 
4763
4789
  /**
4764
4790
  * Counts number of words in the text
@@ -4772,6 +4798,9 @@ function countWords(text) {
4772
4798
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4773
4799
  return text.split(/[^a-zะฐ-ั0-9]+/i).filter((word) => word.length > 0).length;
4774
4800
  }
4801
+ /**
4802
+ * TODO: [๐Ÿฅด] Implement counting in formats - like JSON, CSV, XML,...
4803
+ */
4775
4804
 
4776
4805
  /**
4777
4806
  * Index of all counter functions