@promptbook/markdown-utils 0.88.0-11 → 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 +7 -19
- package/esm/index.es.js +51 -22
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
- package/package.json +1 -1
- package/umd/index.umd.js +54 -25
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -58,8 +58,6 @@ 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
|
-
|
|
63
61
|
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!
|
|
64
62
|
|
|
65
63
|
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.
|
|
@@ -70,6 +68,9 @@ This shift is going to happen, whether we are ready for it or not. Our mission i
|
|
|
70
68
|
|
|
71
69
|
|
|
72
70
|
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
73
74
|
## 🚀 Get started
|
|
74
75
|
|
|
75
76
|
Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
|
|
@@ -81,6 +82,8 @@ Take a look at the simple starter kit with books integrated into the **Hello Wor
|
|
|
81
82
|
|
|
82
83
|
|
|
83
84
|
|
|
85
|
+
|
|
86
|
+
|
|
84
87
|
## 💜 The Promptbook Project
|
|
85
88
|
|
|
86
89
|
Promptbook project is ecosystem of multiple projects and tools, following is a list of most important pieces of the project:
|
|
@@ -122,29 +125,22 @@ Hello world examples:
|
|
|
122
125
|
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
123
126
|
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
128
|
We also have a community of developers and users of **Promptbook**:
|
|
128
129
|
|
|
129
130
|
- [Discord community](https://discord.gg/x3QWNaa89N)
|
|
130
131
|
- [Landing page `ptbk.io`](https://ptbk.io)
|
|
131
132
|
- [Github discussions](https://github.com/webgptorg/promptbook/discussions)
|
|
132
133
|
- [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
|
|
133
|
-
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
134
|
+
- [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
|
|
134
135
|
|
|
135
136
|
And **Promptbook.studio** branded socials:
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
139
138
|
- [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
|
|
140
139
|
|
|
141
140
|
And **Promptujeme** sub-brand:
|
|
142
141
|
|
|
143
142
|
_/Subbrand for Czech clients/_
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
144
|
- [Promptujeme.cz](https://www.promptujeme.cz/)
|
|
149
145
|
- [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
|
|
150
146
|
|
|
@@ -162,8 +158,6 @@ _/Sub-brand for images and graphics generated via Promptbook prompting/_
|
|
|
162
158
|
|
|
163
159
|
## 💙 The Book language
|
|
164
160
|
|
|
165
|
-
|
|
166
|
-
|
|
167
161
|
Following is the documentation and blueprint of the [Book language](https://github.com/webgptorg/book).
|
|
168
162
|
|
|
169
163
|
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.
|
|
@@ -213,8 +207,6 @@ Personas can have access to different knowledge, tools and actions. They can als
|
|
|
213
207
|
|
|
214
208
|
- [PERSONA](https://github.com/webgptorg/promptbook/blob/main/documents/commands/PERSONA.md)
|
|
215
209
|
|
|
216
|
-
|
|
217
|
-
|
|
218
210
|
### **How:** Knowledge, Instruments and Actions
|
|
219
211
|
|
|
220
212
|
The resources used by the personas are used to do the work.
|
|
@@ -303,12 +295,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
303
295
|
- **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.
|
|
304
296
|
- **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.
|
|
305
297
|
|
|
306
|
-
|
|
307
|
-
|
|
308
298
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
309
299
|
|
|
310
|
-
|
|
311
|
-
|
|
312
300
|
### 💯 Core concepts
|
|
313
301
|
|
|
314
302
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
|
@@ -413,7 +401,7 @@ See [TODO.md](./TODO.md)
|
|
|
413
401
|
<a href="https://technologickainkubace.org/en/about-technology-incubation/about-the-project/">
|
|
414
402
|
<img src="./other/partners/CI-Technology-Incubation.png" alt="Technology Incubation" height="70">
|
|
415
403
|
</a>
|
|
416
|
-
|
|
404
|
+
|
|
417
405
|
</div>
|
|
418
406
|
|
|
419
407
|
## 🖋️ Contributing
|
package/esm/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
2
2
|
import { format } from 'prettier';
|
|
3
3
|
import parserHtml from 'prettier/parser-html';
|
|
4
|
-
import { Subject } from 'rxjs';
|
|
5
4
|
import { randomBytes } from 'crypto';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
7
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
8
8
|
import sha256 from 'crypto-js/sha256';
|
|
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-12';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -659,7 +659,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
659
659
|
*
|
|
660
660
|
* @public exported from `@promptbook/core`
|
|
661
661
|
*/
|
|
662
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
662
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
663
663
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
664
664
|
/**
|
|
665
665
|
* Where to store the temporary downloads
|
|
@@ -1676,6 +1676,21 @@ class MissingToolsError extends Error {
|
|
|
1676
1676
|
}
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
1679
|
+
/**
|
|
1680
|
+
* Generates random token
|
|
1681
|
+
*
|
|
1682
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
1683
|
+
*
|
|
1684
|
+
* @private internal helper function
|
|
1685
|
+
* @returns secure random token
|
|
1686
|
+
*/
|
|
1687
|
+
function $randomToken(randomness) {
|
|
1688
|
+
return randomBytes(randomness).toString('hex');
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1692
|
+
*/
|
|
1693
|
+
|
|
1679
1694
|
/**
|
|
1680
1695
|
* This error indicates errors during the execution of the pipeline
|
|
1681
1696
|
*
|
|
@@ -1683,11 +1698,17 @@ class MissingToolsError extends Error {
|
|
|
1683
1698
|
*/
|
|
1684
1699
|
class PipelineExecutionError extends Error {
|
|
1685
1700
|
constructor(message) {
|
|
1701
|
+
// Added id parameter
|
|
1686
1702
|
super(message);
|
|
1687
1703
|
this.name = 'PipelineExecutionError';
|
|
1704
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
1705
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1688
1706
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1689
1707
|
}
|
|
1690
1708
|
}
|
|
1709
|
+
/**
|
|
1710
|
+
* TODO: !!!!!! Add id to all errors
|
|
1711
|
+
*/
|
|
1691
1712
|
|
|
1692
1713
|
/**
|
|
1693
1714
|
* Determine if the pipeline is fully prepared
|
|
@@ -1726,21 +1747,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
1726
1747
|
* - [♨] Are tasks prepared
|
|
1727
1748
|
*/
|
|
1728
1749
|
|
|
1729
|
-
/**
|
|
1730
|
-
* Generates random token
|
|
1731
|
-
*
|
|
1732
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
1733
|
-
*
|
|
1734
|
-
* @private internal helper function
|
|
1735
|
-
* @returns secure random token
|
|
1736
|
-
*/
|
|
1737
|
-
function $randomToken(randomness) {
|
|
1738
|
-
return randomBytes(randomness).toString('hex');
|
|
1739
|
-
}
|
|
1740
|
-
/**
|
|
1741
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1742
|
-
*/
|
|
1743
|
-
|
|
1744
1750
|
/**
|
|
1745
1751
|
* Recursively converts JSON strings to JSON objects
|
|
1746
1752
|
|
|
@@ -1957,7 +1963,7 @@ const ALL_ERRORS = {
|
|
|
1957
1963
|
* @public exported from `@promptbook/utils`
|
|
1958
1964
|
*/
|
|
1959
1965
|
function deserializeError(error) {
|
|
1960
|
-
const { name, stack } = error;
|
|
1966
|
+
const { name, stack, id } = error; // Added id
|
|
1961
1967
|
let { message } = error;
|
|
1962
1968
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
1963
1969
|
if (ErrorClass === undefined) {
|
|
@@ -1972,7 +1978,9 @@ function deserializeError(error) {
|
|
|
1972
1978
|
${block(stack || '')}
|
|
1973
1979
|
`);
|
|
1974
1980
|
}
|
|
1975
|
-
|
|
1981
|
+
const deserializedError = new ErrorClass(message);
|
|
1982
|
+
deserializedError.id = id; // Assign id to the error object
|
|
1983
|
+
return deserializedError;
|
|
1976
1984
|
}
|
|
1977
1985
|
|
|
1978
1986
|
/**
|
|
@@ -2022,6 +2030,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2022
2030
|
*/
|
|
2023
2031
|
function createTask(options) {
|
|
2024
2032
|
const { taskType, taskProcessCallback } = options;
|
|
2033
|
+
// TODO: [🐙] DRY
|
|
2025
2034
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2026
2035
|
let status = 'RUNNING';
|
|
2027
2036
|
const createdAt = new Date();
|
|
@@ -2118,19 +2127,21 @@ function createTask(options) {
|
|
|
2118
2127
|
*/
|
|
2119
2128
|
function serializeError(error) {
|
|
2120
2129
|
const { name, message, stack } = error;
|
|
2130
|
+
const { id } = error;
|
|
2121
2131
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2122
2132
|
console.error(spaceTrim((block) => `
|
|
2123
|
-
|
|
2133
|
+
|
|
2124
2134
|
Cannot serialize error with name "${name}"
|
|
2125
2135
|
|
|
2126
2136
|
${block(stack || message)}
|
|
2127
|
-
|
|
2137
|
+
|
|
2128
2138
|
`));
|
|
2129
2139
|
}
|
|
2130
2140
|
return {
|
|
2131
2141
|
name: name,
|
|
2132
2142
|
message,
|
|
2133
2143
|
stack,
|
|
2144
|
+
id, // Include id in the serialized object
|
|
2134
2145
|
};
|
|
2135
2146
|
}
|
|
2136
2147
|
|
|
@@ -4326,6 +4337,9 @@ function countCharacters(text) {
|
|
|
4326
4337
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4327
4338
|
return text.length;
|
|
4328
4339
|
}
|
|
4340
|
+
/**
|
|
4341
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4342
|
+
*/
|
|
4329
4343
|
|
|
4330
4344
|
/**
|
|
4331
4345
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4357,6 +4371,9 @@ function countLines(text) {
|
|
|
4357
4371
|
const lines = text.split('\n');
|
|
4358
4372
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4359
4373
|
}
|
|
4374
|
+
/**
|
|
4375
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4376
|
+
*/
|
|
4360
4377
|
|
|
4361
4378
|
/**
|
|
4362
4379
|
* Counts number of pages in the text
|
|
@@ -4368,6 +4385,9 @@ function countLines(text) {
|
|
|
4368
4385
|
function countPages(text) {
|
|
4369
4386
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4370
4387
|
}
|
|
4388
|
+
/**
|
|
4389
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4390
|
+
*/
|
|
4371
4391
|
|
|
4372
4392
|
/**
|
|
4373
4393
|
* Counts number of paragraphs in the text
|
|
@@ -4377,6 +4397,9 @@ function countPages(text) {
|
|
|
4377
4397
|
function countParagraphs(text) {
|
|
4378
4398
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4379
4399
|
}
|
|
4400
|
+
/**
|
|
4401
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4402
|
+
*/
|
|
4380
4403
|
|
|
4381
4404
|
/**
|
|
4382
4405
|
* Split text into sentences
|
|
@@ -4394,6 +4417,9 @@ function splitIntoSentences(text) {
|
|
|
4394
4417
|
function countSentences(text) {
|
|
4395
4418
|
return splitIntoSentences(text).length;
|
|
4396
4419
|
}
|
|
4420
|
+
/**
|
|
4421
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4422
|
+
*/
|
|
4397
4423
|
|
|
4398
4424
|
/**
|
|
4399
4425
|
* Counts number of words in the text
|
|
@@ -4407,6 +4433,9 @@ function countWords(text) {
|
|
|
4407
4433
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4408
4434
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4409
4435
|
}
|
|
4436
|
+
/**
|
|
4437
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4438
|
+
*/
|
|
4410
4439
|
|
|
4411
4440
|
/**
|
|
4412
4441
|
* Index of all counter functions
|