@promptbook/remote-server 0.88.0-9 → 0.89.0-1

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/README.md +35 -14
  2. package/esm/index.es.js +62 -26
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +10 -0
  6. package/esm/typings/src/config.d.ts +1 -1
  7. package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
  8. package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
  9. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +7 -0
  10. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
  11. package/esm/typings/src/playground/BrjappConnector.d.ts +64 -0
  12. package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
  13. package/esm/typings/src/playground/playground.d.ts +5 -0
  14. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
  15. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
  16. package/esm/typings/src/types/typeAliases.d.ts +2 -2
  17. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
  18. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
  19. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
  20. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
  21. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
  22. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
  23. package/package.json +2 -2
  24. package/umd/index.umd.js +65 -29
  25. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -58,6 +58,8 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
58
58
 
59
59
  During the computer revolution, we have seen [multiple generations of computer languages](https://github.com/webgptorg/promptbook/discussions/180), from the physical rewiring of the vacuum tubes through low-level machine code to the high-level languages like Python or JavaScript. And now, we're on the edge of the **next revolution**!
60
60
 
61
+
62
+
61
63
  It's a revolution of writing software in **plain human language** that is understandable and executable by both humans and machines – and it's going to change everything!
62
64
 
63
65
  The incredible growth in power of microprocessors and the Moore's Law have been the driving force behind the ever-more powerful languages, and it's been an amazing journey! Similarly, the large language models (like GPT or Claude) are the next big thing in language technology, and they're set to transform the way we interact with computers.
@@ -68,6 +70,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
68
70
 
69
71
 
70
72
 
73
+
74
+
75
+
71
76
  ## 🚀 Get started
72
77
 
73
78
  Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
@@ -79,6 +84,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
79
84
 
80
85
 
81
86
 
87
+
88
+
82
89
  ## 💜 The Promptbook Project
83
90
 
84
91
  Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
@@ -114,22 +121,35 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
114
121
  </tbody>
115
122
  </table>
116
123
 
124
+ Hello world examples:
125
+
126
+ - [Hello world](https://github.com/webgptorg/hello-world)
127
+ - [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
128
+ - [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
129
+
130
+
131
+
117
132
  We also have a community of developers and users of **Promptbook**:
118
133
 
119
134
  - [Discord community](https://discord.gg/x3QWNaa89N)
120
135
  - [Landing page `ptbk.io`](https://ptbk.io)
121
136
  - [Github discussions](https://github.com/webgptorg/promptbook/discussions)
122
137
  - [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
123
- - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
138
+ - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
124
139
 
125
140
  And **Promptbook.studio** branded socials:
126
141
 
142
+
143
+
127
144
  - [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
128
145
 
129
146
  And **Promptujeme** sub-brand:
130
147
 
131
148
  _/Subbrand for Czech clients/_
132
149
 
150
+
151
+
152
+
133
153
  - [Promptujeme.cz](https://www.promptujeme.cz/)
134
154
  - [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
135
155
 
@@ -147,6 +167,8 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
147
167
 
148
168
  ## 💙 The Book language
149
169
 
170
+
171
+
150
172
  Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
151
173
 
152
174
  Book is a language that can be used to write AI applications, agents, workflows, automations, knowledgebases, translators, sheet processors, email automations and more. It allows you to harness the power of AI models in human-like terms, without the need to know the specifics and technicalities of the models.
@@ -196,6 +218,8 @@ Personas can have access to different knowledge, tools and actions. They can als
196
218
 
197
219
  - [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
198
220
 
221
+
222
+
199
223
  ### **How:** Knowledge, Instruments and Actions
200
224
 
201
225
  The resources used by the personas are used to do the work.
@@ -271,11 +295,9 @@ Or you can install them separately:
271
295
 
272
296
  ## 📚 Dictionary
273
297
 
274
- ### 📚 Dictionary
275
-
276
298
  The following glossary is used to clarify certain concepts:
277
299
 
278
- #### General LLM / AI terms
300
+ ### General LLM / AI terms
279
301
 
280
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.
281
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.
@@ -286,9 +308,13 @@ The following glossary is used to clarify certain concepts:
286
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.
287
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.
288
310
 
289
- _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
290
311
 
291
- #### 💯 Core concepts
312
+
313
+ _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
314
+
315
+
316
+
317
+ ### 💯 Core concepts
292
318
 
293
319
  - [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
294
320
  - [📯 Pipeline](https://github.com/webgptorg/promptbook/discussions/64)
@@ -301,7 +327,7 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
301
327
  - [🔣 Words not tokens](https://github.com/webgptorg/promptbook/discussions/29)
302
328
  - [☯ Separation of concerns](https://github.com/webgptorg/promptbook/discussions/32)
303
329
 
304
- ##### Advanced concepts
330
+ #### Advanced concepts
305
331
 
306
332
  - [📚 Knowledge (Retrieval-augmented generation)](https://github.com/webgptorg/promptbook/discussions/41)
307
333
  - [🌏 Remote server](https://github.com/webgptorg/promptbook/discussions/89)
@@ -316,11 +342,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
316
342
  - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
317
343
  - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
318
344
 
319
- ### Terms specific to Promptbook TypeScript implementation
320
-
321
- - Anonymous mode
322
- - Application mode
323
-
324
345
 
325
346
 
326
347
  ## 🚂 Promptbook Engine
@@ -391,11 +412,11 @@ See [TODO.md](./TODO.md)
391
412
  <div style="display: flex; align-items: center; gap: 20px;">
392
413
 
393
414
  <a href="https://promptbook.studio/">
394
- <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="100">
415
+ <img src="./design/promptbook-studio-logo.png" alt="Partner 3" height="70">
395
416
  </a>
396
417
 
397
418
  <a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
398
- <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="100">
419
+ <img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
399
420
  </a>
400
421
 
401
422
  </div>
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-9';
34
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
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();
@@ -1875,7 +1886,7 @@ function createTask(options) {
1875
1886
  assertsTaskSuccessful(executionResult);
1876
1887
  status = 'FINISHED';
1877
1888
  currentValue = jsonStringsToJsons(executionResult);
1878
- // <- TODO: Convert JSON values in string to JSON objects
1889
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1879
1890
  partialResultSubject.next(executionResult);
1880
1891
  }
1881
1892
  catch (error) {
@@ -2519,8 +2530,9 @@ function addUsage(...usageItems) {
2519
2530
  * @returns LLM tools with same functionality with added total cost counting
2520
2531
  * @public exported from `@promptbook/core`
2521
2532
  */
2522
- function countTotalUsage(llmTools) {
2533
+ function countUsage(llmTools) {
2523
2534
  let totalUsage = ZERO_USAGE;
2535
+ const spending = new Subject();
2524
2536
  const proxyTools = {
2525
2537
  get title() {
2526
2538
  // TODO: [🧠] Maybe put here some suffix
@@ -2530,12 +2542,15 @@ function countTotalUsage(llmTools) {
2530
2542
  // TODO: [🧠] Maybe put here some suffix
2531
2543
  return llmTools.description;
2532
2544
  },
2533
- async checkConfiguration() {
2545
+ checkConfiguration() {
2534
2546
  return /* not await */ llmTools.checkConfiguration();
2535
2547
  },
2536
2548
  listModels() {
2537
2549
  return /* not await */ llmTools.listModels();
2538
2550
  },
2551
+ spending() {
2552
+ return spending.asObservable();
2553
+ },
2539
2554
  getTotalUsage() {
2540
2555
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2541
2556
  return totalUsage;
@@ -2546,6 +2561,7 @@ function countTotalUsage(llmTools) {
2546
2561
  // console.info('[🚕] callChatModel through countTotalUsage');
2547
2562
  const promptResult = await llmTools.callChatModel(prompt);
2548
2563
  totalUsage = addUsage(totalUsage, promptResult.usage);
2564
+ spending.next(promptResult.usage);
2549
2565
  return promptResult;
2550
2566
  };
2551
2567
  }
@@ -2554,6 +2570,7 @@ function countTotalUsage(llmTools) {
2554
2570
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2555
2571
  const promptResult = await llmTools.callCompletionModel(prompt);
2556
2572
  totalUsage = addUsage(totalUsage, promptResult.usage);
2573
+ spending.next(promptResult.usage);
2557
2574
  return promptResult;
2558
2575
  };
2559
2576
  }
@@ -2562,6 +2579,7 @@ function countTotalUsage(llmTools) {
2562
2579
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2563
2580
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2564
2581
  totalUsage = addUsage(totalUsage, promptResult.usage);
2582
+ spending.next(promptResult.usage);
2565
2583
  return promptResult;
2566
2584
  };
2567
2585
  }
@@ -3844,7 +3862,7 @@ async function preparePipeline(pipeline, tools, options) {
3844
3862
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3845
3863
  const _llms = arrayableToArray(tools.llm);
3846
3864
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3847
- const llmToolsWithUsage = countTotalUsage(llmTools);
3865
+ const llmToolsWithUsage = countUsage(llmTools);
3848
3866
  // <- TODO: [🌯]
3849
3867
  /*
3850
3868
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -4691,6 +4709,9 @@ function countCharacters(text) {
4691
4709
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4692
4710
  return text.length;
4693
4711
  }
4712
+ /**
4713
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4714
+ */
4694
4715
 
4695
4716
  /**
4696
4717
  * Number of characters per standard line with 11pt Arial font size.
@@ -4722,6 +4743,9 @@ function countLines(text) {
4722
4743
  const lines = text.split('\n');
4723
4744
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4724
4745
  }
4746
+ /**
4747
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4748
+ */
4725
4749
 
4726
4750
  /**
4727
4751
  * Counts number of pages in the text
@@ -4733,6 +4757,9 @@ function countLines(text) {
4733
4757
  function countPages(text) {
4734
4758
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4735
4759
  }
4760
+ /**
4761
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4762
+ */
4736
4763
 
4737
4764
  /**
4738
4765
  * Counts number of paragraphs in the text
@@ -4742,6 +4769,9 @@ function countPages(text) {
4742
4769
  function countParagraphs(text) {
4743
4770
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4744
4771
  }
4772
+ /**
4773
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4774
+ */
4745
4775
 
4746
4776
  /**
4747
4777
  * Split text into sentences
@@ -4759,6 +4789,9 @@ function splitIntoSentences(text) {
4759
4789
  function countSentences(text) {
4760
4790
  return splitIntoSentences(text).length;
4761
4791
  }
4792
+ /**
4793
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4794
+ */
4762
4795
 
4763
4796
  /**
4764
4797
  * Counts number of words in the text
@@ -4772,6 +4805,9 @@ function countWords(text) {
4772
4805
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4773
4806
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4774
4807
  }
4808
+ /**
4809
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4810
+ */
4775
4811
 
4776
4812
  /**
4777
4813
  * Index of all counter functions