@promptbook/utils 0.80.0 → 0.81.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 +13 -6
- package/esm/index.es.js +195 -55
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +15 -0
- package/esm/typings/src/_packages/core.index.d.ts +2 -6
- package/esm/typings/src/_packages/editable.index.d.ts +10 -0
- package/esm/typings/src/_packages/templates.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +12 -2
- package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
- package/esm/typings/src/config.d.ts +26 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
- package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
- package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
- package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
- package/esm/typings/src/other/templates/getBookTemplate.d.ts +19 -0
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +10 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +8 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
- package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
- package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
- package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
- package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
- package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isPathRoot.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isPathRoot.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
- package/esm/typings/src/version.d.ts +7 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +51 -0
- package/package.json +1 -1
- package/umd/index.umd.js +200 -55
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
- package/esm/typings/src/utils/formatNumber.d.ts +0 -6
- /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
- /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
- /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
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
|
+
|
|
26
30
|
## 📦 Package `@promptbook/utils`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -70,20 +74,20 @@ unwrapResult('Best greeting for the user is "Hi Pavol!"'); // 'Hi Pavol!'
|
|
|
70
74
|
|
|
71
75
|
## Templating
|
|
72
76
|
|
|
73
|
-
There is a function `
|
|
77
|
+
There is a function `templateParameters` which is used to replace the parameters in given template optimized to LLM prompt templates.
|
|
74
78
|
|
|
75
79
|
```typescript
|
|
76
|
-
import {
|
|
80
|
+
import { templateParameters } from '@promptbook/utils';
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
templateParameters('Hello, {name}!', { name: 'world' }); // 'Hello, world!'
|
|
79
83
|
```
|
|
80
84
|
|
|
81
85
|
And also multiline templates with blockquotes
|
|
82
86
|
|
|
83
87
|
```typescript
|
|
84
|
-
import {
|
|
88
|
+
import { templateParameters, spaceTrim } from '@promptbook/utils';
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
templateParameters(
|
|
87
91
|
spaceTrim(`
|
|
88
92
|
Hello, {name}!
|
|
89
93
|
|
|
@@ -348,6 +352,7 @@ Or you can install them separately:
|
|
|
348
352
|
|
|
349
353
|
- ⭐ **[ptbk](https://www.npmjs.com/package/ptbk)** - Bundle of all packages, when you want to install everything and you don't care about the size
|
|
350
354
|
- **[promptbook](https://www.npmjs.com/package/promptbook)** - Same as `ptbk`
|
|
355
|
+
- ⭐🧙♂️ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizzard to just run the books in node without any struggle
|
|
351
356
|
- **[@promptbook/core](https://www.npmjs.com/package/@promptbook/core)** - Core of the library, it contains the main logic for promptbooks
|
|
352
357
|
- **[@promptbook/node](https://www.npmjs.com/package/@promptbook/node)** - Core of the library for Node.js environment
|
|
353
358
|
- **[@promptbook/browser](https://www.npmjs.com/package/@promptbook/browser)** - Core of the library for browser environment
|
|
@@ -368,8 +373,10 @@ Or you can install them separately:
|
|
|
368
373
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
369
374
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
370
375
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
376
|
+
- **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
|
|
377
|
+
- **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
|
|
371
378
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
372
|
-
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
379
|
+
- ⭐ **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
373
380
|
|
|
374
381
|
|
|
375
382
|
|
package/esm/index.es.js
CHANGED
|
@@ -5,20 +5,86 @@ import { basename } from 'path';
|
|
|
5
5
|
/**
|
|
6
6
|
* The version of the Book language
|
|
7
7
|
*
|
|
8
|
+
* @generated
|
|
8
9
|
* @see https://github.com/webgptorg/book
|
|
9
10
|
*/
|
|
10
11
|
var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
11
12
|
/**
|
|
12
13
|
* The version of the Promptbook engine
|
|
13
14
|
*
|
|
15
|
+
* @generated
|
|
14
16
|
* @see https://github.com/webgptorg/promptbook
|
|
15
17
|
*/
|
|
16
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
18
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-11';
|
|
17
19
|
/**
|
|
18
20
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
19
21
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
20
22
|
*/
|
|
21
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Name for the Promptbook
|
|
26
|
+
*
|
|
27
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
28
|
+
*
|
|
29
|
+
* @public exported from `@promptbook/core`
|
|
30
|
+
*/
|
|
31
|
+
var NAME = "Promptbook";
|
|
32
|
+
/**
|
|
33
|
+
* Email of the responsible person
|
|
34
|
+
*
|
|
35
|
+
* @public exported from `@promptbook/core`
|
|
36
|
+
*/
|
|
37
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
38
|
+
/**
|
|
39
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
40
|
+
*
|
|
41
|
+
* @public exported from `@promptbook/core`
|
|
42
|
+
*/
|
|
43
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
44
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
45
|
+
/**
|
|
46
|
+
* The maximum number of iterations for a loops
|
|
47
|
+
*
|
|
48
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
49
|
+
*/
|
|
50
|
+
var LOOP_LIMIT = 1000;
|
|
51
|
+
/**
|
|
52
|
+
* Strings to represent various values in the context of parameter values
|
|
53
|
+
*
|
|
54
|
+
* @public exported from `@promptbook/utils`
|
|
55
|
+
*/
|
|
56
|
+
var VALUE_STRINGS = {
|
|
57
|
+
empty: '(nothing; empty string)',
|
|
58
|
+
null: '(no value; null)',
|
|
59
|
+
undefined: '(unknown value; undefined)',
|
|
60
|
+
nan: '(not a number; NaN)',
|
|
61
|
+
infinity: '(infinity; ∞)',
|
|
62
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
63
|
+
unserializable: '(unserializable value)',
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Small number limit
|
|
67
|
+
*
|
|
68
|
+
* @public exported from `@promptbook/utils`
|
|
69
|
+
*/
|
|
70
|
+
var SMALL_NUMBER = 0.001;
|
|
71
|
+
// <- TODO: [🧜♂️]
|
|
72
|
+
/**
|
|
73
|
+
* @@@
|
|
74
|
+
*
|
|
75
|
+
* @public exported from `@promptbook/core`
|
|
76
|
+
*/
|
|
77
|
+
Object.freeze({
|
|
78
|
+
delimiter: ',',
|
|
79
|
+
quoteChar: '"',
|
|
80
|
+
newline: '\n',
|
|
81
|
+
skipEmptyLines: true,
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
85
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
86
|
+
*/
|
|
87
|
+
|
|
22
88
|
/*! *****************************************************************************
|
|
23
89
|
Copyright (c) Microsoft Corporation.
|
|
24
90
|
|
|
@@ -138,50 +204,6 @@ function __spreadArray(to, from, pack) {
|
|
|
138
204
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
139
205
|
}
|
|
140
206
|
|
|
141
|
-
/**
|
|
142
|
-
* Name for the Promptbook
|
|
143
|
-
*
|
|
144
|
-
* TODO: [🗽] Unite branding and make single place for it
|
|
145
|
-
*
|
|
146
|
-
* @public exported from `@promptbook/core`
|
|
147
|
-
*/
|
|
148
|
-
var NAME = "Promptbook";
|
|
149
|
-
/**
|
|
150
|
-
* Email of the responsible person
|
|
151
|
-
*
|
|
152
|
-
* @public exported from `@promptbook/core`
|
|
153
|
-
*/
|
|
154
|
-
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
155
|
-
/**
|
|
156
|
-
* Name of the responsible person for the Promptbook on GitHub
|
|
157
|
-
*
|
|
158
|
-
* @public exported from `@promptbook/core`
|
|
159
|
-
*/
|
|
160
|
-
var ADMIN_GITHUB_NAME = 'hejny';
|
|
161
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
162
|
-
/**
|
|
163
|
-
* The maximum number of iterations for a loops
|
|
164
|
-
*
|
|
165
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
166
|
-
*/
|
|
167
|
-
var LOOP_LIMIT = 1000;
|
|
168
|
-
// <- TODO: [🧜♂️]
|
|
169
|
-
/**
|
|
170
|
-
* @@@
|
|
171
|
-
*
|
|
172
|
-
* @public exported from `@promptbook/core`
|
|
173
|
-
*/
|
|
174
|
-
Object.freeze({
|
|
175
|
-
delimiter: ',',
|
|
176
|
-
quoteChar: '"',
|
|
177
|
-
newline: '\n',
|
|
178
|
-
skipEmptyLines: true,
|
|
179
|
-
});
|
|
180
|
-
/**
|
|
181
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
182
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
183
|
-
*/
|
|
184
|
-
|
|
185
207
|
/**
|
|
186
208
|
* Make error report URL for the given error
|
|
187
209
|
*
|
|
@@ -306,21 +328,44 @@ function isValidFilePath(filename) {
|
|
|
306
328
|
if (typeof filename !== 'string') {
|
|
307
329
|
return false;
|
|
308
330
|
}
|
|
331
|
+
if (filename.split('\n').length > 1) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (filename.split(' ').length >
|
|
335
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
309
338
|
var filenameSlashes = filename.split('\\').join('/');
|
|
310
339
|
// Absolute Unix path: /hello.txt
|
|
311
340
|
if (/^(\/)/i.test(filenameSlashes)) {
|
|
341
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
312
342
|
return true;
|
|
313
343
|
}
|
|
314
344
|
// Absolute Windows path: /hello.txt
|
|
315
345
|
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
346
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
316
347
|
return true;
|
|
317
348
|
}
|
|
318
349
|
// Relative path: ./hello.txt
|
|
319
350
|
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
351
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
// Allow paths like foo/hello
|
|
355
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
356
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
// Allow paths like hello.book
|
|
360
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
361
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
320
362
|
return true;
|
|
321
363
|
}
|
|
322
364
|
return false;
|
|
323
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* TODO: [🍏] Implement for MacOs
|
|
368
|
+
*/
|
|
324
369
|
|
|
325
370
|
/**
|
|
326
371
|
* Tests if given string is valid URL.
|
|
@@ -835,7 +880,7 @@ function extractVariablesFromScript(script) {
|
|
|
835
880
|
if (!(error instanceof Error)) {
|
|
836
881
|
throw error;
|
|
837
882
|
}
|
|
838
|
-
throw new ParseError(spaceTrim$2(function (block) { return "\n Can not extract variables from the script\n
|
|
883
|
+
throw new ParseError(spaceTrim$2(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
|
|
839
884
|
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
840
885
|
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
841
886
|
}
|
|
@@ -1703,6 +1748,34 @@ function extractParameterNames(template) {
|
|
|
1703
1748
|
return parameterNames;
|
|
1704
1749
|
}
|
|
1705
1750
|
|
|
1751
|
+
/**
|
|
1752
|
+
* Format either small or big number
|
|
1753
|
+
*
|
|
1754
|
+
* @public exported from `@promptbook/utils`
|
|
1755
|
+
*/
|
|
1756
|
+
function numberToString(value) {
|
|
1757
|
+
if (value === 0) {
|
|
1758
|
+
return '0';
|
|
1759
|
+
}
|
|
1760
|
+
else if (Number.isNaN(value)) {
|
|
1761
|
+
return VALUE_STRINGS.nan;
|
|
1762
|
+
}
|
|
1763
|
+
else if (value === Infinity) {
|
|
1764
|
+
return VALUE_STRINGS.infinity;
|
|
1765
|
+
}
|
|
1766
|
+
else if (value === -Infinity) {
|
|
1767
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
1768
|
+
}
|
|
1769
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
1770
|
+
var factor = Math.pow(10, exponent);
|
|
1771
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
1772
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
1773
|
+
return valueRounded.toFixed(exponent);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return value.toString();
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1706
1779
|
/**
|
|
1707
1780
|
* Freezes the given object and all its nested objects recursively
|
|
1708
1781
|
*
|
|
@@ -1831,7 +1904,7 @@ function checkSerializableAsJson(options) {
|
|
|
1831
1904
|
if (!(error instanceof Error)) {
|
|
1832
1905
|
throw error;
|
|
1833
1906
|
}
|
|
1834
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.
|
|
1907
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
1835
1908
|
}
|
|
1836
1909
|
/*
|
|
1837
1910
|
TODO: [0] Is there some more elegant way to check circular references?
|
|
@@ -1965,16 +2038,66 @@ exportJson({
|
|
|
1965
2038
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1966
2039
|
*/
|
|
1967
2040
|
|
|
2041
|
+
/**
|
|
2042
|
+
* Function `valueToString` will convert the given value to string
|
|
2043
|
+
* This is useful and used in the `templateParameters` function
|
|
2044
|
+
*
|
|
2045
|
+
* Note: This function is not just calling `toString` method
|
|
2046
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
2047
|
+
* See `VALUE_STRINGS`
|
|
2048
|
+
*
|
|
2049
|
+
* Note: There are 2 similar functions
|
|
2050
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
2051
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
2052
|
+
*
|
|
2053
|
+
* @public exported from `@promptbook/utils`
|
|
2054
|
+
*/
|
|
2055
|
+
function valueToString(value) {
|
|
2056
|
+
try {
|
|
2057
|
+
if (value === '') {
|
|
2058
|
+
return VALUE_STRINGS.empty;
|
|
2059
|
+
}
|
|
2060
|
+
else if (value === null) {
|
|
2061
|
+
return VALUE_STRINGS.null;
|
|
2062
|
+
}
|
|
2063
|
+
else if (value === undefined) {
|
|
2064
|
+
return VALUE_STRINGS.undefined;
|
|
2065
|
+
}
|
|
2066
|
+
else if (typeof value === 'string') {
|
|
2067
|
+
return value;
|
|
2068
|
+
}
|
|
2069
|
+
else if (typeof value === 'number') {
|
|
2070
|
+
return numberToString(value);
|
|
2071
|
+
}
|
|
2072
|
+
else if (value instanceof Date) {
|
|
2073
|
+
return value.toISOString();
|
|
2074
|
+
}
|
|
2075
|
+
else {
|
|
2076
|
+
return JSON.stringify(value);
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
catch (error) {
|
|
2080
|
+
if (!(error instanceof Error)) {
|
|
2081
|
+
throw error;
|
|
2082
|
+
}
|
|
2083
|
+
console.error(error);
|
|
2084
|
+
return VALUE_STRINGS.unserializable;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
|
|
1968
2088
|
/**
|
|
1969
2089
|
* Replaces parameters in template with values from parameters object
|
|
1970
2090
|
*
|
|
2091
|
+
* Note: This function is not places strings into string,
|
|
2092
|
+
* It's more complex and can handle this operation specifically for LLM models
|
|
2093
|
+
*
|
|
1971
2094
|
* @param template the template with parameters in {curly} braces
|
|
1972
2095
|
* @param parameters the object with parameters
|
|
1973
2096
|
* @returns the template with replaced parameters
|
|
1974
2097
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
1975
2098
|
* @public exported from `@promptbook/utils`
|
|
1976
2099
|
*/
|
|
1977
|
-
function
|
|
2100
|
+
function templateParameters(template, parameters) {
|
|
1978
2101
|
var e_1, _a;
|
|
1979
2102
|
try {
|
|
1980
2103
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -2000,7 +2123,7 @@ function replaceParameters(template, parameters) {
|
|
|
2000
2123
|
var loopLimit = LOOP_LIMIT;
|
|
2001
2124
|
var _loop_1 = function () {
|
|
2002
2125
|
if (loopLimit-- < 0) {
|
|
2003
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
2126
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
2004
2127
|
}
|
|
2005
2128
|
var precol = match.groups.precol;
|
|
2006
2129
|
var parameterName = match.groups.parameterName;
|
|
@@ -2017,7 +2140,7 @@ function replaceParameters(template, parameters) {
|
|
|
2017
2140
|
if (parameterValue === undefined) {
|
|
2018
2141
|
throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
|
|
2019
2142
|
}
|
|
2020
|
-
parameterValue = parameterValue
|
|
2143
|
+
parameterValue = valueToString(parameterValue);
|
|
2021
2144
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
2022
2145
|
parameterValue = parameterValue
|
|
2023
2146
|
.split('\n')
|
|
@@ -2156,7 +2279,7 @@ function removeQuotes(text) {
|
|
|
2156
2279
|
*/
|
|
2157
2280
|
function clonePipeline(pipeline) {
|
|
2158
2281
|
// Note: Not using spread operator (...) because @@@
|
|
2159
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
2282
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations, sources = pipeline.sources;
|
|
2160
2283
|
return {
|
|
2161
2284
|
pipelineUrl: pipelineUrl,
|
|
2162
2285
|
sourceFile: sourceFile,
|
|
@@ -2170,6 +2293,7 @@ function clonePipeline(pipeline) {
|
|
|
2170
2293
|
knowledgePieces: knowledgePieces,
|
|
2171
2294
|
personas: personas,
|
|
2172
2295
|
preparations: preparations,
|
|
2296
|
+
sources: sources,
|
|
2173
2297
|
};
|
|
2174
2298
|
}
|
|
2175
2299
|
/**
|
|
@@ -2443,6 +2567,25 @@ function isValidEmail(email) {
|
|
|
2443
2567
|
return /^.+@.+\..+$/.test(email);
|
|
2444
2568
|
}
|
|
2445
2569
|
|
|
2570
|
+
/**
|
|
2571
|
+
* Determines if the given path is a root path.
|
|
2572
|
+
*
|
|
2573
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2574
|
+
* @public exported from `@promptbook/utils`
|
|
2575
|
+
*/
|
|
2576
|
+
function isPathRoot(value) {
|
|
2577
|
+
if (value === '/') {
|
|
2578
|
+
return true;
|
|
2579
|
+
}
|
|
2580
|
+
if (/^[A-Z]:\\$/i.test(value)) {
|
|
2581
|
+
return true;
|
|
2582
|
+
}
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* TODO: [🍏] Make for MacOS paths
|
|
2587
|
+
*/
|
|
2588
|
+
|
|
2446
2589
|
/**
|
|
2447
2590
|
* @@@
|
|
2448
2591
|
*
|
|
@@ -2566,9 +2709,6 @@ function isValidPipelineUrl(url) {
|
|
|
2566
2709
|
if (!url.startsWith('https://')) {
|
|
2567
2710
|
return false;
|
|
2568
2711
|
}
|
|
2569
|
-
if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
|
|
2570
|
-
return false;
|
|
2571
|
-
}
|
|
2572
2712
|
if (url.includes('#')) {
|
|
2573
2713
|
// TODO: [🐠]
|
|
2574
2714
|
return false;
|
|
@@ -2594,5 +2734,5 @@ function isValidUuid(value) {
|
|
|
2594
2734
|
return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
|
|
2595
2735
|
}
|
|
2596
2736
|
|
|
2597
|
-
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid,
|
|
2737
|
+
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, SMALL_NUMBER, VALUE_STRINGS, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isPathRoot, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, numberToString, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, searchKeywords, serializeError, spaceTrim, splitIntoSentences, templateParameters, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult, valueToString };
|
|
2598
2738
|
//# sourceMappingURL=index.es.js.map
|