@promptbook/utils 0.77.1 → 0.78.2
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/esm/index.es.js +365 -500
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +353 -490
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import spaceTrim$
|
|
1
|
+
import spaceTrim$1, { spaceTrim as spaceTrim$2 } from 'spacetrim';
|
|
2
2
|
import { basename } from 'path';
|
|
3
3
|
|
|
4
4
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -13,7 +13,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
13
13
|
*
|
|
14
14
|
* @see https://github.com/webgptorg/promptbook
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
16
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
17
17
|
/**
|
|
18
18
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
19
19
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -138,6 +138,87 @@ function __spreadArray(to, from, pack) {
|
|
|
138
138
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
139
139
|
}
|
|
140
140
|
|
|
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
|
+
/**
|
|
169
|
+
* Nonce which is used for replacing things in strings
|
|
170
|
+
*
|
|
171
|
+
* @private within the repository
|
|
172
|
+
*/
|
|
173
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
174
|
+
/**
|
|
175
|
+
* @@@
|
|
176
|
+
*
|
|
177
|
+
* @private within the repository
|
|
178
|
+
*/
|
|
179
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
180
|
+
/**
|
|
181
|
+
* @@@
|
|
182
|
+
*
|
|
183
|
+
* @private within the repository
|
|
184
|
+
*/
|
|
185
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
186
|
+
// <- TODO: [🧜♂️]
|
|
187
|
+
/**
|
|
188
|
+
* @@@
|
|
189
|
+
*
|
|
190
|
+
* @public exported from `@promptbook/core`
|
|
191
|
+
*/
|
|
192
|
+
Object.freeze({
|
|
193
|
+
delimiter: ',',
|
|
194
|
+
quoteChar: '"',
|
|
195
|
+
newline: '\n',
|
|
196
|
+
skipEmptyLines: true,
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* TODO: Extract `constants.ts` from `config.ts`
|
|
200
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
201
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Make error report URL for the given error
|
|
206
|
+
*
|
|
207
|
+
* @private !!!!!!
|
|
208
|
+
*/
|
|
209
|
+
function getErrorReportUrl(error) {
|
|
210
|
+
var report = {
|
|
211
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
212
|
+
body: spaceTrim$1(function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
213
|
+
};
|
|
214
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
215
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
216
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
217
|
+
reportUrl.searchParams.set('title', report.title);
|
|
218
|
+
reportUrl.searchParams.set('body', report.body);
|
|
219
|
+
return reportUrl;
|
|
220
|
+
}
|
|
221
|
+
|
|
141
222
|
/**
|
|
142
223
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
143
224
|
*
|
|
@@ -146,7 +227,7 @@ function __spreadArray(to, from, pack) {
|
|
|
146
227
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
147
228
|
__extends(UnexpectedError, _super);
|
|
148
229
|
function UnexpectedError(message) {
|
|
149
|
-
var _this = _super.call(this, spaceTrim$
|
|
230
|
+
var _this = _super.call(this, spaceTrim$2(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
150
231
|
_this.name = 'UnexpectedError';
|
|
151
232
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
152
233
|
return _this;
|
|
@@ -218,6 +299,48 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
218
299
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
219
300
|
*/
|
|
220
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Removes emojis from a string and fix whitespaces
|
|
304
|
+
*
|
|
305
|
+
* @param text with emojis
|
|
306
|
+
* @returns text without emojis
|
|
307
|
+
* @public exported from `@promptbook/utils`
|
|
308
|
+
*/
|
|
309
|
+
function removeEmojis(text) {
|
|
310
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
311
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
312
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
313
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
314
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
315
|
+
return text;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Tests if given string is valid URL.
|
|
320
|
+
*
|
|
321
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
322
|
+
* @public exported from `@promptbook/utils`
|
|
323
|
+
*/
|
|
324
|
+
function isValidFilePath(filename) {
|
|
325
|
+
if (typeof filename !== 'string') {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
329
|
+
// Absolute Unix path: /hello.txt
|
|
330
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
// Absolute Windows path: /hello.txt
|
|
334
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
// Relative path: ./hello.txt
|
|
338
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
|
|
221
344
|
/**
|
|
222
345
|
* Tests if given string is valid URL.
|
|
223
346
|
*
|
|
@@ -570,48 +693,6 @@ function normalizeToKebabCase(text) {
|
|
|
570
693
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
571
694
|
*/
|
|
572
695
|
|
|
573
|
-
/**
|
|
574
|
-
* Removes emojis from a string and fix whitespaces
|
|
575
|
-
*
|
|
576
|
-
* @param text with emojis
|
|
577
|
-
* @returns text without emojis
|
|
578
|
-
* @public exported from `@promptbook/utils`
|
|
579
|
-
*/
|
|
580
|
-
function removeEmojis(text) {
|
|
581
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
582
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
583
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
584
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
585
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
586
|
-
return text;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Tests if given string is valid URL.
|
|
591
|
-
*
|
|
592
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
593
|
-
* @public exported from `@promptbook/utils`
|
|
594
|
-
*/
|
|
595
|
-
function isValidFilePath(filename) {
|
|
596
|
-
if (typeof filename !== 'string') {
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
600
|
-
// Absolute Unix path: /hello.txt
|
|
601
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
602
|
-
return true;
|
|
603
|
-
}
|
|
604
|
-
// Absolute Windows path: /hello.txt
|
|
605
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
606
|
-
return true;
|
|
607
|
-
}
|
|
608
|
-
// Relative path: ./hello.txt
|
|
609
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
696
|
/**
|
|
616
697
|
* @@@
|
|
617
698
|
*
|
|
@@ -660,7 +741,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
660
741
|
}
|
|
661
742
|
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
662
743
|
};
|
|
663
|
-
var promptbookMermaid = spaceTrim$
|
|
744
|
+
var promptbookMermaid = spaceTrim$2(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
664
745
|
.flatMap(function (_a) {
|
|
665
746
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
666
747
|
return __spreadArray([
|
|
@@ -700,34 +781,6 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
700
781
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
701
782
|
*/
|
|
702
783
|
|
|
703
|
-
/**
|
|
704
|
-
* Parses the task and returns the list of all parameter names
|
|
705
|
-
*
|
|
706
|
-
* @param template the string template with parameters in {curly} braces
|
|
707
|
-
* @returns the list of parameter names
|
|
708
|
-
* @public exported from `@promptbook/utils`
|
|
709
|
-
*/
|
|
710
|
-
function extractParameterNames(template) {
|
|
711
|
-
var e_1, _a;
|
|
712
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
713
|
-
var parameterNames = new Set();
|
|
714
|
-
try {
|
|
715
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
716
|
-
var match = matches_1_1.value;
|
|
717
|
-
var parameterName = match[0].slice(1, -1);
|
|
718
|
-
parameterNames.add(parameterName);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
722
|
-
finally {
|
|
723
|
-
try {
|
|
724
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
725
|
-
}
|
|
726
|
-
finally { if (e_1) throw e_1.error; }
|
|
727
|
-
}
|
|
728
|
-
return parameterNames;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
784
|
/**
|
|
732
785
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
733
786
|
*
|
|
@@ -753,10 +806,11 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
753
806
|
* @param script from which to extract the variables
|
|
754
807
|
* @returns the list of variable names
|
|
755
808
|
* @throws {ParseError} if the script is invalid
|
|
756
|
-
* @public exported from `@promptbook/utils`
|
|
809
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
757
810
|
*/
|
|
758
|
-
function
|
|
811
|
+
function extractVariablesFromScript(script) {
|
|
759
812
|
var variables = new Set();
|
|
813
|
+
var originalScript = script;
|
|
760
814
|
script = "(()=>{".concat(script, "})()");
|
|
761
815
|
try {
|
|
762
816
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -788,7 +842,9 @@ function extractVariables(script) {
|
|
|
788
842
|
if (!(error instanceof Error)) {
|
|
789
843
|
throw error;
|
|
790
844
|
}
|
|
791
|
-
throw new ParseError(spaceTrim$
|
|
845
|
+
throw new ParseError(spaceTrim$2(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
|
|
846
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
847
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
792
848
|
}
|
|
793
849
|
return variables;
|
|
794
850
|
}
|
|
@@ -797,211 +853,55 @@ function extractVariables(script) {
|
|
|
797
853
|
*/
|
|
798
854
|
|
|
799
855
|
/**
|
|
800
|
-
*
|
|
856
|
+
* This error indicates problems parsing the format value
|
|
801
857
|
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
* @public exported from `@promptbook/
|
|
858
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
859
|
+
* This is not thrown directly but in extended classes
|
|
860
|
+
*
|
|
861
|
+
* @public exported from `@promptbook/core`
|
|
806
862
|
*/
|
|
807
|
-
function
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
818
|
-
finally {
|
|
819
|
-
try {
|
|
820
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
821
|
-
}
|
|
822
|
-
finally { if (e_1) throw e_1.error; }
|
|
823
|
-
}
|
|
824
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
825
|
-
try {
|
|
826
|
-
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
827
|
-
var parameterName = _h.value;
|
|
828
|
-
parameterNames.add(parameterName);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
832
|
-
finally {
|
|
833
|
-
try {
|
|
834
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
835
|
-
}
|
|
836
|
-
finally { if (e_2) throw e_2.error; }
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
try {
|
|
840
|
-
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
841
|
-
var jokerName = _k.value;
|
|
842
|
-
parameterNames.add(jokerName);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
846
|
-
finally {
|
|
847
|
-
try {
|
|
848
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
849
|
-
}
|
|
850
|
-
finally { if (e_3) throw e_3.error; }
|
|
851
|
-
}
|
|
852
|
-
parameterNames.delete('content');
|
|
853
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
854
|
-
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
855
|
-
if (foreach !== undefined) {
|
|
856
|
-
try {
|
|
857
|
-
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
858
|
-
var subparameterName = _m.value;
|
|
859
|
-
if (parameterNames.has(subparameterName)) {
|
|
860
|
-
parameterNames.delete(subparameterName);
|
|
861
|
-
parameterNames.add(foreach.parameterName);
|
|
862
|
-
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
867
|
-
finally {
|
|
868
|
-
try {
|
|
869
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
870
|
-
}
|
|
871
|
-
finally { if (e_4) throw e_4.error; }
|
|
872
|
-
}
|
|
863
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
864
|
+
__extends(AbstractFormatError, _super);
|
|
865
|
+
// Note: To allow instanceof do not put here error `name`
|
|
866
|
+
// public readonly name = 'AbstractFormatError';
|
|
867
|
+
function AbstractFormatError(message) {
|
|
868
|
+
var _this = _super.call(this, message) || this;
|
|
869
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
870
|
+
return _this;
|
|
873
871
|
}
|
|
874
|
-
return
|
|
875
|
-
}
|
|
872
|
+
return AbstractFormatError;
|
|
873
|
+
}(Error));
|
|
874
|
+
|
|
876
875
|
/**
|
|
877
|
-
*
|
|
876
|
+
* This error indicates problem with parsing of CSV
|
|
877
|
+
*
|
|
878
|
+
* @public exported from `@promptbook/core`
|
|
878
879
|
*/
|
|
880
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
881
|
+
__extends(CsvFormatError, _super);
|
|
882
|
+
function CsvFormatError(message) {
|
|
883
|
+
var _this = _super.call(this, message) || this;
|
|
884
|
+
_this.name = 'CsvFormatError';
|
|
885
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
886
|
+
return _this;
|
|
887
|
+
}
|
|
888
|
+
return CsvFormatError;
|
|
889
|
+
}(AbstractFormatError));
|
|
879
890
|
|
|
880
891
|
/**
|
|
881
|
-
* This error indicates that the
|
|
892
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
882
893
|
*
|
|
883
894
|
* @public exported from `@promptbook/core`
|
|
884
895
|
*/
|
|
885
|
-
var
|
|
886
|
-
__extends(
|
|
887
|
-
function
|
|
896
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
897
|
+
__extends(CollectionError, _super);
|
|
898
|
+
function CollectionError(message) {
|
|
888
899
|
var _this = _super.call(this, message) || this;
|
|
889
|
-
_this.name = '
|
|
890
|
-
Object.setPrototypeOf(_this,
|
|
900
|
+
_this.name = 'CollectionError';
|
|
901
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
891
902
|
return _this;
|
|
892
903
|
}
|
|
893
|
-
return
|
|
894
|
-
}(Error));
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Function `renameParameter` will find all usable parameters for given task
|
|
898
|
-
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
899
|
-
*
|
|
900
|
-
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
901
|
-
* @public exported from `@promptbook/utils`
|
|
902
|
-
*/
|
|
903
|
-
function renameParameter(options) {
|
|
904
|
-
var e_1, _a, e_2, _b;
|
|
905
|
-
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
906
|
-
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
907
|
-
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
908
|
-
}
|
|
909
|
-
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
910
|
-
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
911
|
-
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
912
|
-
try {
|
|
913
|
-
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
914
|
-
var parameter = _d.value;
|
|
915
|
-
if (parameter.name !== oldParameterName) {
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
parameter.name = newParameterName;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
922
|
-
finally {
|
|
923
|
-
try {
|
|
924
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
925
|
-
}
|
|
926
|
-
finally { if (e_1) throw e_1.error; }
|
|
927
|
-
}
|
|
928
|
-
try {
|
|
929
|
-
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
930
|
-
var task = _f.value;
|
|
931
|
-
if (task.resultingParameterName === oldParameterName) {
|
|
932
|
-
task.resultingParameterName = newParameterName;
|
|
933
|
-
}
|
|
934
|
-
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
935
|
-
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
936
|
-
});
|
|
937
|
-
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
938
|
-
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
939
|
-
task.description =
|
|
940
|
-
task.description === undefined
|
|
941
|
-
? undefined
|
|
942
|
-
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
946
|
-
finally {
|
|
947
|
-
try {
|
|
948
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
949
|
-
}
|
|
950
|
-
finally { if (e_2) throw e_2.error; }
|
|
951
|
-
}
|
|
952
|
-
return renamedPipeline;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* This error indicates problems parsing the format value
|
|
957
|
-
*
|
|
958
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
959
|
-
* This is not thrown directly but in extended classes
|
|
960
|
-
*
|
|
961
|
-
* @public exported from `@promptbook/core`
|
|
962
|
-
*/
|
|
963
|
-
var AbstractFormatError = /** @class */ (function (_super) {
|
|
964
|
-
__extends(AbstractFormatError, _super);
|
|
965
|
-
// Note: To allow instanceof do not put here error `name`
|
|
966
|
-
// public readonly name = 'AbstractFormatError';
|
|
967
|
-
function AbstractFormatError(message) {
|
|
968
|
-
var _this = _super.call(this, message) || this;
|
|
969
|
-
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
970
|
-
return _this;
|
|
971
|
-
}
|
|
972
|
-
return AbstractFormatError;
|
|
973
|
-
}(Error));
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
* This error indicates problem with parsing of CSV
|
|
977
|
-
*
|
|
978
|
-
* @public exported from `@promptbook/core`
|
|
979
|
-
*/
|
|
980
|
-
var CsvFormatError = /** @class */ (function (_super) {
|
|
981
|
-
__extends(CsvFormatError, _super);
|
|
982
|
-
function CsvFormatError(message) {
|
|
983
|
-
var _this = _super.call(this, message) || this;
|
|
984
|
-
_this.name = 'CsvFormatError';
|
|
985
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
986
|
-
return _this;
|
|
987
|
-
}
|
|
988
|
-
return CsvFormatError;
|
|
989
|
-
}(AbstractFormatError));
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
993
|
-
*
|
|
994
|
-
* @public exported from `@promptbook/core`
|
|
995
|
-
*/
|
|
996
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
997
|
-
__extends(CollectionError, _super);
|
|
998
|
-
function CollectionError(message) {
|
|
999
|
-
var _this = _super.call(this, message) || this;
|
|
1000
|
-
_this.name = 'CollectionError';
|
|
1001
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1002
|
-
return _this;
|
|
1003
|
-
}
|
|
1004
|
-
return CollectionError;
|
|
904
|
+
return CollectionError;
|
|
1005
905
|
}(Error));
|
|
1006
906
|
|
|
1007
907
|
/**
|
|
@@ -1079,7 +979,7 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
1079
979
|
var MissingToolsError = /** @class */ (function (_super) {
|
|
1080
980
|
__extends(MissingToolsError, _super);
|
|
1081
981
|
function MissingToolsError(message) {
|
|
1082
|
-
var _this = _super.call(this, spaceTrim$
|
|
982
|
+
var _this = _super.call(this, spaceTrim$2(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
1083
983
|
_this.name = 'MissingToolsError';
|
|
1084
984
|
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
1085
985
|
return _this;
|
|
@@ -1111,7 +1011,7 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1111
1011
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1112
1012
|
__extends(NotYetImplementedError, _super);
|
|
1113
1013
|
function NotYetImplementedError(message) {
|
|
1114
|
-
var _this = _super.call(this, spaceTrim$
|
|
1014
|
+
var _this = _super.call(this, spaceTrim$2(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
1115
1015
|
_this.name = 'NotYetImplementedError';
|
|
1116
1016
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1117
1017
|
return _this;
|
|
@@ -1135,6 +1035,22 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1135
1035
|
return PipelineExecutionError;
|
|
1136
1036
|
}(Error));
|
|
1137
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
1040
|
+
*
|
|
1041
|
+
* @public exported from `@promptbook/core`
|
|
1042
|
+
*/
|
|
1043
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
1044
|
+
__extends(PipelineLogicError, _super);
|
|
1045
|
+
function PipelineLogicError(message) {
|
|
1046
|
+
var _this = _super.call(this, message) || this;
|
|
1047
|
+
_this.name = 'PipelineLogicError';
|
|
1048
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
1049
|
+
return _this;
|
|
1050
|
+
}
|
|
1051
|
+
return PipelineLogicError;
|
|
1052
|
+
}(Error));
|
|
1053
|
+
|
|
1138
1054
|
/**
|
|
1139
1055
|
* This error indicates errors in referencing promptbooks between each other
|
|
1140
1056
|
*
|
|
@@ -1228,7 +1144,7 @@ function deserializeError(error) {
|
|
|
1228
1144
|
function serializeError(error) {
|
|
1229
1145
|
var name = error.name, message = error.message, stack = error.stack;
|
|
1230
1146
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
1231
|
-
console.error(spaceTrim$
|
|
1147
|
+
console.error(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
1232
1148
|
}
|
|
1233
1149
|
return {
|
|
1234
1150
|
name: name,
|
|
@@ -1752,243 +1668,35 @@ function searchKeywords(haystack, needle) {
|
|
|
1752
1668
|
* @public exported from `@promptbook/utils`
|
|
1753
1669
|
* @see https://github.com/hejny/spacetrim#usage
|
|
1754
1670
|
*/
|
|
1755
|
-
var spaceTrim = spaceTrim$
|
|
1671
|
+
var spaceTrim = spaceTrim$2;
|
|
1756
1672
|
|
|
1757
1673
|
/**
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1760
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1761
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1674
|
+
* Parses the task and returns the list of all parameter names
|
|
1762
1675
|
*
|
|
1763
|
-
* @
|
|
1676
|
+
* @param template the string template with parameters in {curly} braces
|
|
1677
|
+
* @returns the list of parameter names
|
|
1764
1678
|
* @public exported from `@promptbook/utils`
|
|
1765
1679
|
*/
|
|
1766
|
-
function
|
|
1680
|
+
function extractParameterNames(template) {
|
|
1767
1681
|
var e_1, _a;
|
|
1768
|
-
var
|
|
1682
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1683
|
+
var parameterNames = new Set();
|
|
1769
1684
|
try {
|
|
1770
|
-
for (var
|
|
1771
|
-
var
|
|
1772
|
-
var
|
|
1773
|
-
|
|
1774
|
-
$deepFreeze(value);
|
|
1775
|
-
}
|
|
1685
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1686
|
+
var match = matches_1_1.value;
|
|
1687
|
+
var parameterName = match[0].slice(1, -1);
|
|
1688
|
+
parameterNames.add(parameterName);
|
|
1776
1689
|
}
|
|
1777
1690
|
}
|
|
1778
1691
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1779
1692
|
finally {
|
|
1780
1693
|
try {
|
|
1781
|
-
if (
|
|
1694
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1782
1695
|
}
|
|
1783
1696
|
finally { if (e_1) throw e_1.error; }
|
|
1784
1697
|
}
|
|
1785
|
-
return
|
|
1786
|
-
}
|
|
1787
|
-
/**
|
|
1788
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1789
|
-
*/
|
|
1790
|
-
|
|
1791
|
-
/**
|
|
1792
|
-
* Checks if the value is [🚉] serializable as JSON
|
|
1793
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1794
|
-
*
|
|
1795
|
-
* - Almost all primitives are serializable BUT:
|
|
1796
|
-
* - `undefined` is not serializable
|
|
1797
|
-
* - `NaN` is not serializable
|
|
1798
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
1799
|
-
* - Functions are not serializable
|
|
1800
|
-
* - Circular references are not serializable
|
|
1801
|
-
* - `Date` objects are not serializable
|
|
1802
|
-
* - `Map` and `Set` objects are not serializable
|
|
1803
|
-
* - `RegExp` objects are not serializable
|
|
1804
|
-
* - `Error` objects are not serializable
|
|
1805
|
-
* - `Symbol` objects are not serializable
|
|
1806
|
-
* - And much more...
|
|
1807
|
-
*
|
|
1808
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1809
|
-
* @public exported from `@promptbook/utils`
|
|
1810
|
-
*/
|
|
1811
|
-
function checkSerializableAsJson(name, value) {
|
|
1812
|
-
var e_1, _a;
|
|
1813
|
-
if (value === undefined) {
|
|
1814
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1815
|
-
}
|
|
1816
|
-
else if (value === null) {
|
|
1817
|
-
return;
|
|
1818
|
-
}
|
|
1819
|
-
else if (typeof value === 'boolean') {
|
|
1820
|
-
return;
|
|
1821
|
-
}
|
|
1822
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1823
|
-
return;
|
|
1824
|
-
}
|
|
1825
|
-
else if (typeof value === 'string') {
|
|
1826
|
-
return;
|
|
1827
|
-
}
|
|
1828
|
-
else if (typeof value === 'symbol') {
|
|
1829
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1830
|
-
}
|
|
1831
|
-
else if (typeof value === 'function') {
|
|
1832
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
1833
|
-
}
|
|
1834
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1835
|
-
for (var i = 0; i < value.length; i++) {
|
|
1836
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
else if (typeof value === 'object') {
|
|
1840
|
-
if (value instanceof Date) {
|
|
1841
|
-
throw new UnexpectedError(spaceTrim$2("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1842
|
-
}
|
|
1843
|
-
else if (value instanceof Map) {
|
|
1844
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1845
|
-
}
|
|
1846
|
-
else if (value instanceof Set) {
|
|
1847
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1848
|
-
}
|
|
1849
|
-
else if (value instanceof RegExp) {
|
|
1850
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1851
|
-
}
|
|
1852
|
-
else if (value instanceof Error) {
|
|
1853
|
-
throw new UnexpectedError(spaceTrim$2("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1854
|
-
}
|
|
1855
|
-
else {
|
|
1856
|
-
try {
|
|
1857
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1858
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1859
|
-
if (subValue === undefined) {
|
|
1860
|
-
// Note: undefined in object is serializable - it is just omited
|
|
1861
|
-
continue;
|
|
1862
|
-
}
|
|
1863
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1867
|
-
finally {
|
|
1868
|
-
try {
|
|
1869
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1870
|
-
}
|
|
1871
|
-
finally { if (e_1) throw e_1.error; }
|
|
1872
|
-
}
|
|
1873
|
-
try {
|
|
1874
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
1875
|
-
}
|
|
1876
|
-
catch (error) {
|
|
1877
|
-
if (!(error instanceof Error)) {
|
|
1878
|
-
throw error;
|
|
1879
|
-
}
|
|
1880
|
-
throw new UnexpectedError(spaceTrim$2(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1881
|
-
}
|
|
1882
|
-
/*
|
|
1883
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
1884
|
-
const seen = new Set();
|
|
1885
|
-
const stack = [{ value }];
|
|
1886
|
-
while (stack.length > 0) {
|
|
1887
|
-
const { value } = stack.pop()!;
|
|
1888
|
-
if (typeof value === 'object' && value !== null) {
|
|
1889
|
-
if (seen.has(value)) {
|
|
1890
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
1891
|
-
}
|
|
1892
|
-
seen.add(value);
|
|
1893
|
-
if (Array.isArray(value)) {
|
|
1894
|
-
stack.push(...value.map((value) => ({ value })));
|
|
1895
|
-
} else {
|
|
1896
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
*/
|
|
1901
|
-
return;
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
else {
|
|
1905
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
/**
|
|
1909
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1910
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1911
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1912
|
-
*/
|
|
1913
|
-
|
|
1914
|
-
/**
|
|
1915
|
-
* @@@
|
|
1916
|
-
* @@@
|
|
1917
|
-
*
|
|
1918
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1919
|
-
*
|
|
1920
|
-
* @param name - Name of the object for debugging purposes
|
|
1921
|
-
* @param objectValue - Object to be deeply frozen
|
|
1922
|
-
* @returns The same object as the input, but deeply frozen
|
|
1923
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1924
|
-
*/
|
|
1925
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1926
|
-
checkSerializableAsJson(name, objectValue);
|
|
1927
|
-
return $deepFreeze(objectValue);
|
|
1698
|
+
return parameterNames;
|
|
1928
1699
|
}
|
|
1929
|
-
/**
|
|
1930
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1931
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1932
|
-
*/
|
|
1933
|
-
|
|
1934
|
-
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
1935
|
-
/**
|
|
1936
|
-
* The maximum number of iterations for a loops
|
|
1937
|
-
*
|
|
1938
|
-
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
1939
|
-
*/
|
|
1940
|
-
var LOOP_LIMIT = 1000;
|
|
1941
|
-
/**
|
|
1942
|
-
* Nonce which is used for replacing things in strings
|
|
1943
|
-
*
|
|
1944
|
-
* @private within the repository
|
|
1945
|
-
*/
|
|
1946
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
1947
|
-
/**
|
|
1948
|
-
* The names of the parameters that are reserved for special purposes
|
|
1949
|
-
*
|
|
1950
|
-
* @public exported from `@promptbook/core`
|
|
1951
|
-
*/
|
|
1952
|
-
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
1953
|
-
'content',
|
|
1954
|
-
'context',
|
|
1955
|
-
'knowledge',
|
|
1956
|
-
'examples',
|
|
1957
|
-
'modelName',
|
|
1958
|
-
'currentDate',
|
|
1959
|
-
// <- TODO: list here all command names
|
|
1960
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
1961
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1962
|
-
]);
|
|
1963
|
-
/**
|
|
1964
|
-
* @@@
|
|
1965
|
-
*
|
|
1966
|
-
* @private within the repository
|
|
1967
|
-
*/
|
|
1968
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
1969
|
-
/**
|
|
1970
|
-
* @@@
|
|
1971
|
-
*
|
|
1972
|
-
* @private within the repository
|
|
1973
|
-
*/
|
|
1974
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1975
|
-
// <- TODO: [🧜♂️]
|
|
1976
|
-
/**
|
|
1977
|
-
* @@@
|
|
1978
|
-
*
|
|
1979
|
-
* @public exported from `@promptbook/core`
|
|
1980
|
-
*/
|
|
1981
|
-
Object.freeze({
|
|
1982
|
-
delimiter: ',',
|
|
1983
|
-
quoteChar: '"',
|
|
1984
|
-
newline: '\n',
|
|
1985
|
-
skipEmptyLines: true,
|
|
1986
|
-
});
|
|
1987
|
-
/**
|
|
1988
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
1989
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1990
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
1991
|
-
*/
|
|
1992
1700
|
|
|
1993
1701
|
/**
|
|
1994
1702
|
* Replaces parameters in template with values from parameters object
|
|
@@ -2171,6 +1879,163 @@ function removeQuotes(text) {
|
|
|
2171
1879
|
return text;
|
|
2172
1880
|
}
|
|
2173
1881
|
|
|
1882
|
+
/**
|
|
1883
|
+
* @@@
|
|
1884
|
+
*
|
|
1885
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1886
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1887
|
+
*
|
|
1888
|
+
* @returns The same object as the input, but deeply frozen
|
|
1889
|
+
* @public exported from `@promptbook/utils`
|
|
1890
|
+
*/
|
|
1891
|
+
function $deepFreeze(objectValue) {
|
|
1892
|
+
var e_1, _a;
|
|
1893
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1894
|
+
try {
|
|
1895
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1896
|
+
var propertyName = propertyNames_1_1.value;
|
|
1897
|
+
var value = objectValue[propertyName];
|
|
1898
|
+
if (value && typeof value === 'object') {
|
|
1899
|
+
$deepFreeze(value);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1904
|
+
finally {
|
|
1905
|
+
try {
|
|
1906
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1907
|
+
}
|
|
1908
|
+
finally { if (e_1) throw e_1.error; }
|
|
1909
|
+
}
|
|
1910
|
+
return Object.freeze(objectValue);
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1914
|
+
*/
|
|
1915
|
+
|
|
1916
|
+
/**
|
|
1917
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1918
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1919
|
+
*
|
|
1920
|
+
* - Almost all primitives are serializable BUT:
|
|
1921
|
+
* - `undefined` is not serializable
|
|
1922
|
+
* - `NaN` is not serializable
|
|
1923
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1924
|
+
* - Functions are not serializable
|
|
1925
|
+
* - Circular references are not serializable
|
|
1926
|
+
* - `Date` objects are not serializable
|
|
1927
|
+
* - `Map` and `Set` objects are not serializable
|
|
1928
|
+
* - `RegExp` objects are not serializable
|
|
1929
|
+
* - `Error` objects are not serializable
|
|
1930
|
+
* - `Symbol` objects are not serializable
|
|
1931
|
+
* - And much more...
|
|
1932
|
+
*
|
|
1933
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1934
|
+
* @public exported from `@promptbook/utils`
|
|
1935
|
+
*/
|
|
1936
|
+
function checkSerializableAsJson(name, value) {
|
|
1937
|
+
var e_1, _a;
|
|
1938
|
+
if (value === undefined) {
|
|
1939
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1940
|
+
}
|
|
1941
|
+
else if (value === null) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
else if (typeof value === 'boolean') {
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
else if (typeof value === 'string') {
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
else if (typeof value === 'symbol') {
|
|
1954
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1955
|
+
}
|
|
1956
|
+
else if (typeof value === 'function') {
|
|
1957
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1958
|
+
}
|
|
1959
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1960
|
+
for (var i = 0; i < value.length; i++) {
|
|
1961
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
else if (typeof value === 'object') {
|
|
1965
|
+
if (value instanceof Date) {
|
|
1966
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1967
|
+
}
|
|
1968
|
+
else if (value instanceof Map) {
|
|
1969
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1970
|
+
}
|
|
1971
|
+
else if (value instanceof Set) {
|
|
1972
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1973
|
+
}
|
|
1974
|
+
else if (value instanceof RegExp) {
|
|
1975
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1976
|
+
}
|
|
1977
|
+
else if (value instanceof Error) {
|
|
1978
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1979
|
+
}
|
|
1980
|
+
else {
|
|
1981
|
+
try {
|
|
1982
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1983
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1984
|
+
if (subValue === undefined) {
|
|
1985
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1986
|
+
continue;
|
|
1987
|
+
}
|
|
1988
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1992
|
+
finally {
|
|
1993
|
+
try {
|
|
1994
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1995
|
+
}
|
|
1996
|
+
finally { if (e_1) throw e_1.error; }
|
|
1997
|
+
}
|
|
1998
|
+
try {
|
|
1999
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
2000
|
+
}
|
|
2001
|
+
catch (error) {
|
|
2002
|
+
if (!(error instanceof Error)) {
|
|
2003
|
+
throw error;
|
|
2004
|
+
}
|
|
2005
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
2006
|
+
}
|
|
2007
|
+
/*
|
|
2008
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
2009
|
+
const seen = new Set();
|
|
2010
|
+
const stack = [{ value }];
|
|
2011
|
+
while (stack.length > 0) {
|
|
2012
|
+
const { value } = stack.pop()!;
|
|
2013
|
+
if (typeof value === 'object' && value !== null) {
|
|
2014
|
+
if (seen.has(value)) {
|
|
2015
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
2016
|
+
}
|
|
2017
|
+
seen.add(value);
|
|
2018
|
+
if (Array.isArray(value)) {
|
|
2019
|
+
stack.push(...value.map((value) => ({ value })));
|
|
2020
|
+
} else {
|
|
2021
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
*/
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
else {
|
|
2030
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
2035
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
2036
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
2037
|
+
*/
|
|
2038
|
+
|
|
2174
2039
|
/**
|
|
2175
2040
|
* @@@
|
|
2176
2041
|
*
|
|
@@ -2381,13 +2246,13 @@ function union() {
|
|
|
2381
2246
|
* @public exported from `@promptbook/utils`
|
|
2382
2247
|
*/
|
|
2383
2248
|
function trimCodeBlock(value) {
|
|
2384
|
-
value = spaceTrim$
|
|
2249
|
+
value = spaceTrim$2(value);
|
|
2385
2250
|
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
2386
2251
|
return value;
|
|
2387
2252
|
}
|
|
2388
2253
|
value = value.replace(/^```[a-z]*/i, '');
|
|
2389
2254
|
value = value.replace(/```$/i, '');
|
|
2390
|
-
value = spaceTrim$
|
|
2255
|
+
value = spaceTrim$2(value);
|
|
2391
2256
|
return value;
|
|
2392
2257
|
}
|
|
2393
2258
|
|
|
@@ -2400,9 +2265,9 @@ function trimCodeBlock(value) {
|
|
|
2400
2265
|
* @public exported from `@promptbook/utils`
|
|
2401
2266
|
*/
|
|
2402
2267
|
function trimEndOfCodeBlock(value) {
|
|
2403
|
-
value = spaceTrim$
|
|
2268
|
+
value = spaceTrim$2(value);
|
|
2404
2269
|
value = value.replace(/```$/g, '');
|
|
2405
|
-
value = spaceTrim$
|
|
2270
|
+
value = spaceTrim$2(value);
|
|
2406
2271
|
return value;
|
|
2407
2272
|
}
|
|
2408
2273
|
|
|
@@ -2424,7 +2289,7 @@ function unwrapResult(text, options) {
|
|
|
2424
2289
|
var trimmedText = text;
|
|
2425
2290
|
// Remove leading and trailing spaces and newlines
|
|
2426
2291
|
if (isTrimmed) {
|
|
2427
|
-
trimmedText = spaceTrim$
|
|
2292
|
+
trimmedText = spaceTrim$2(trimmedText);
|
|
2428
2293
|
}
|
|
2429
2294
|
var processedText = trimmedText;
|
|
2430
2295
|
if (isIntroduceSentenceRemoved) {
|
|
@@ -2433,7 +2298,7 @@ function unwrapResult(text, options) {
|
|
|
2433
2298
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
2434
2299
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
2435
2300
|
}
|
|
2436
|
-
processedText = spaceTrim$
|
|
2301
|
+
processedText = spaceTrim$2(processedText);
|
|
2437
2302
|
}
|
|
2438
2303
|
if (processedText.length < 3) {
|
|
2439
2304
|
return trimmedText;
|
|
@@ -2641,5 +2506,5 @@ function isValidUuid(value) {
|
|
|
2641
2506
|
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);
|
|
2642
2507
|
}
|
|
2643
2508
|
|
|
2644
|
-
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, extractParameterNames,
|
|
2509
|
+
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, 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, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, replaceParameters, searchKeywords, serializeError, spaceTrim, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
|
|
2645
2510
|
//# sourceMappingURL=index.es.js.map
|