@promptbook/markdown-utils 0.78.0-0 → 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/README.md +0 -4
- package/esm/index.es.js +235 -193
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +14 -0
- 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/package.json +1 -1
- package/umd/index.umd.js +235 -193
- package/umd/index.umd.js.map +1 -1
|
@@ -5,6 +5,8 @@ import { createCollectionFromPromise } from '../collection/constructors/createCo
|
|
|
5
5
|
import { createCollectionFromUrl } from '../collection/constructors/createCollectionFromUrl';
|
|
6
6
|
import { createSubcollection } from '../collection/constructors/createSubcollection';
|
|
7
7
|
import { NAME } from '../config';
|
|
8
|
+
import { ADMIN_EMAIL } from '../config';
|
|
9
|
+
import { ADMIN_GITHUB_NAME } from '../config';
|
|
8
10
|
import { CLAIM } from '../config';
|
|
9
11
|
import { LOGO_LIGHT_SRC } from '../config';
|
|
10
12
|
import { LOGO_DARK_SRC } from '../config';
|
|
@@ -123,6 +125,8 @@ export { createCollectionFromPromise };
|
|
|
123
125
|
export { createCollectionFromUrl };
|
|
124
126
|
export { createSubcollection };
|
|
125
127
|
export { NAME };
|
|
128
|
+
export { ADMIN_EMAIL };
|
|
129
|
+
export { ADMIN_GITHUB_NAME };
|
|
126
130
|
export { CLAIM };
|
|
127
131
|
export { LOGO_LIGHT_SRC };
|
|
128
132
|
export { LOGO_DARK_SRC };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CsvSettings } from './formats/csv/CsvSettings';
|
|
2
2
|
import type { IntermediateFilesStrategy } from './types/IntermediateFilesStrategy';
|
|
3
|
+
import type { string_email } from './types/typeAliases';
|
|
4
|
+
import type { string_name } from './types/typeAliases';
|
|
3
5
|
import type { string_url_image } from './types/typeAliases';
|
|
4
6
|
/**
|
|
5
7
|
* Warning message for the generated sections and files files
|
|
@@ -15,6 +17,18 @@ export declare const GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has be
|
|
|
15
17
|
* @public exported from `@promptbook/core`
|
|
16
18
|
*/
|
|
17
19
|
export declare const NAME = "Promptbook";
|
|
20
|
+
/**
|
|
21
|
+
* Email of the responsible person
|
|
22
|
+
*
|
|
23
|
+
* @public exported from `@promptbook/core`
|
|
24
|
+
*/
|
|
25
|
+
export declare const ADMIN_EMAIL: string_email;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
28
|
+
*
|
|
29
|
+
* @public exported from `@promptbook/core`
|
|
30
|
+
*/
|
|
31
|
+
export declare const ADMIN_GITHUB_NAME: string_name;
|
|
18
32
|
/**
|
|
19
33
|
* Claim for the Promptbook
|
|
20
34
|
*
|
|
@@ -24,7 +24,7 @@ export declare const OPENAI_MODELS: ReadonlyArray<AvailableModel & {
|
|
|
24
24
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
25
25
|
* @see https://openai.com/api/pricing/
|
|
26
26
|
* @see /other/playground/playground.ts
|
|
27
|
-
* TODO: [🍓] Make better
|
|
27
|
+
* TODO: [🍓][💩] Make better
|
|
28
28
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
29
29
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8,5 +8,5 @@ export type PipelineString = string & {
|
|
|
8
8
|
readonly _type: 'Promptbook';
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* TODO:
|
|
11
|
+
* TODO: [💩] Better validation (validatePipelineString) or remove branded type and make it just string
|
|
12
12
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -621,204 +621,31 @@
|
|
|
621
621
|
}
|
|
622
622
|
|
|
623
623
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
627
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
628
|
-
*
|
|
629
|
-
* @returns The same object as the input, but deeply frozen
|
|
630
|
-
* @public exported from `@promptbook/utils`
|
|
631
|
-
*/
|
|
632
|
-
function $deepFreeze(objectValue) {
|
|
633
|
-
var e_1, _a;
|
|
634
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
635
|
-
try {
|
|
636
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
637
|
-
var propertyName = propertyNames_1_1.value;
|
|
638
|
-
var value = objectValue[propertyName];
|
|
639
|
-
if (value && typeof value === 'object') {
|
|
640
|
-
$deepFreeze(value);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
645
|
-
finally {
|
|
646
|
-
try {
|
|
647
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
648
|
-
}
|
|
649
|
-
finally { if (e_1) throw e_1.error; }
|
|
650
|
-
}
|
|
651
|
-
return Object.freeze(objectValue);
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
655
|
-
*/
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
624
|
+
* Warning message for the generated sections and files files
|
|
659
625
|
*
|
|
660
|
-
* @
|
|
626
|
+
* @private within the repository
|
|
661
627
|
*/
|
|
662
|
-
var
|
|
663
|
-
__extends(UnexpectedError, _super);
|
|
664
|
-
function UnexpectedError(message) {
|
|
665
|
-
var _this = _super.call(this, spaceTrim.spaceTrim(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 https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
666
|
-
_this.name = 'UnexpectedError';
|
|
667
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
668
|
-
return _this;
|
|
669
|
-
}
|
|
670
|
-
return UnexpectedError;
|
|
671
|
-
}(Error));
|
|
672
|
-
|
|
628
|
+
var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
|
|
673
629
|
/**
|
|
674
|
-
*
|
|
675
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
630
|
+
* Name for the Promptbook
|
|
676
631
|
*
|
|
677
|
-
*
|
|
678
|
-
* - `undefined` is not serializable
|
|
679
|
-
* - `NaN` is not serializable
|
|
680
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
681
|
-
* - Functions are not serializable
|
|
682
|
-
* - Circular references are not serializable
|
|
683
|
-
* - `Date` objects are not serializable
|
|
684
|
-
* - `Map` and `Set` objects are not serializable
|
|
685
|
-
* - `RegExp` objects are not serializable
|
|
686
|
-
* - `Error` objects are not serializable
|
|
687
|
-
* - `Symbol` objects are not serializable
|
|
688
|
-
* - And much more...
|
|
632
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
689
633
|
*
|
|
690
|
-
* @
|
|
691
|
-
* @public exported from `@promptbook/utils`
|
|
692
|
-
*/
|
|
693
|
-
function checkSerializableAsJson(name, value) {
|
|
694
|
-
var e_1, _a;
|
|
695
|
-
if (value === undefined) {
|
|
696
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
697
|
-
}
|
|
698
|
-
else if (value === null) {
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
else if (typeof value === 'boolean') {
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
else if (typeof value === 'string') {
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
else if (typeof value === 'symbol') {
|
|
711
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
712
|
-
}
|
|
713
|
-
else if (typeof value === 'function') {
|
|
714
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
715
|
-
}
|
|
716
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
717
|
-
for (var i = 0; i < value.length; i++) {
|
|
718
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
else if (typeof value === 'object') {
|
|
722
|
-
if (value instanceof Date) {
|
|
723
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
724
|
-
}
|
|
725
|
-
else if (value instanceof Map) {
|
|
726
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
727
|
-
}
|
|
728
|
-
else if (value instanceof Set) {
|
|
729
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
730
|
-
}
|
|
731
|
-
else if (value instanceof RegExp) {
|
|
732
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
733
|
-
}
|
|
734
|
-
else if (value instanceof Error) {
|
|
735
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
try {
|
|
739
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
740
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
741
|
-
if (subValue === undefined) {
|
|
742
|
-
// Note: undefined in object is serializable - it is just omited
|
|
743
|
-
continue;
|
|
744
|
-
}
|
|
745
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
749
|
-
finally {
|
|
750
|
-
try {
|
|
751
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
752
|
-
}
|
|
753
|
-
finally { if (e_1) throw e_1.error; }
|
|
754
|
-
}
|
|
755
|
-
try {
|
|
756
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
757
|
-
}
|
|
758
|
-
catch (error) {
|
|
759
|
-
if (!(error instanceof Error)) {
|
|
760
|
-
throw error;
|
|
761
|
-
}
|
|
762
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
763
|
-
}
|
|
764
|
-
/*
|
|
765
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
766
|
-
const seen = new Set();
|
|
767
|
-
const stack = [{ value }];
|
|
768
|
-
while (stack.length > 0) {
|
|
769
|
-
const { value } = stack.pop()!;
|
|
770
|
-
if (typeof value === 'object' && value !== null) {
|
|
771
|
-
if (seen.has(value)) {
|
|
772
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
773
|
-
}
|
|
774
|
-
seen.add(value);
|
|
775
|
-
if (Array.isArray(value)) {
|
|
776
|
-
stack.push(...value.map((value) => ({ value })));
|
|
777
|
-
} else {
|
|
778
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
*/
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
else {
|
|
787
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
792
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
793
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
634
|
+
* @public exported from `@promptbook/core`
|
|
794
635
|
*/
|
|
795
|
-
|
|
636
|
+
var NAME = "Promptbook";
|
|
796
637
|
/**
|
|
797
|
-
*
|
|
798
|
-
* @@@
|
|
638
|
+
* Email of the responsible person
|
|
799
639
|
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
* @param name - Name of the object for debugging purposes
|
|
803
|
-
* @param objectValue - Object to be deeply frozen
|
|
804
|
-
* @returns The same object as the input, but deeply frozen
|
|
805
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
806
|
-
*/
|
|
807
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
808
|
-
checkSerializableAsJson(name, objectValue);
|
|
809
|
-
return $deepFreeze(objectValue);
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
813
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
640
|
+
* @public exported from `@promptbook/core`
|
|
814
641
|
*/
|
|
815
|
-
|
|
642
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
816
643
|
/**
|
|
817
|
-
*
|
|
644
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
818
645
|
*
|
|
819
|
-
* @
|
|
646
|
+
* @public exported from `@promptbook/core`
|
|
820
647
|
*/
|
|
821
|
-
var
|
|
648
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
822
649
|
/**
|
|
823
650
|
* When the title is not provided, the default title is used
|
|
824
651
|
*
|
|
@@ -876,7 +703,8 @@
|
|
|
876
703
|
*
|
|
877
704
|
* @public exported from `@promptbook/core`
|
|
878
705
|
*/
|
|
879
|
-
var RESERVED_PARAMETER_NAMES =
|
|
706
|
+
var RESERVED_PARAMETER_NAMES =
|
|
707
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
880
708
|
'content',
|
|
881
709
|
'context',
|
|
882
710
|
'knowledge',
|
|
@@ -886,7 +714,7 @@
|
|
|
886
714
|
// <- TODO: list here all command names
|
|
887
715
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
888
716
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
889
|
-
]
|
|
717
|
+
];
|
|
890
718
|
/**
|
|
891
719
|
* @@@
|
|
892
720
|
*
|
|
@@ -954,6 +782,40 @@
|
|
|
954
782
|
return PipelineLogicError;
|
|
955
783
|
}(Error));
|
|
956
784
|
|
|
785
|
+
/**
|
|
786
|
+
* Make error report URL for the given error
|
|
787
|
+
*
|
|
788
|
+
* @private !!!!!!
|
|
789
|
+
*/
|
|
790
|
+
function getErrorReportUrl(error) {
|
|
791
|
+
var report = {
|
|
792
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
793
|
+
body: spaceTrim__default["default"](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 "); }),
|
|
794
|
+
};
|
|
795
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
796
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
797
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
798
|
+
reportUrl.searchParams.set('title', report.title);
|
|
799
|
+
reportUrl.searchParams.set('body', report.body);
|
|
800
|
+
return reportUrl;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
805
|
+
*
|
|
806
|
+
* @public exported from `@promptbook/core`
|
|
807
|
+
*/
|
|
808
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
809
|
+
__extends(UnexpectedError, _super);
|
|
810
|
+
function UnexpectedError(message) {
|
|
811
|
+
var _this = _super.call(this, spaceTrim.spaceTrim(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;
|
|
812
|
+
_this.name = 'UnexpectedError';
|
|
813
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
814
|
+
return _this;
|
|
815
|
+
}
|
|
816
|
+
return UnexpectedError;
|
|
817
|
+
}(Error));
|
|
818
|
+
|
|
957
819
|
/**
|
|
958
820
|
* Tests if given string is valid semantic version
|
|
959
821
|
*
|
|
@@ -1434,6 +1296,183 @@
|
|
|
1434
1296
|
return parameterNames;
|
|
1435
1297
|
}
|
|
1436
1298
|
|
|
1299
|
+
/**
|
|
1300
|
+
* @@@
|
|
1301
|
+
*
|
|
1302
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1303
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1304
|
+
*
|
|
1305
|
+
* @returns The same object as the input, but deeply frozen
|
|
1306
|
+
* @public exported from `@promptbook/utils`
|
|
1307
|
+
*/
|
|
1308
|
+
function $deepFreeze(objectValue) {
|
|
1309
|
+
var e_1, _a;
|
|
1310
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1311
|
+
try {
|
|
1312
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1313
|
+
var propertyName = propertyNames_1_1.value;
|
|
1314
|
+
var value = objectValue[propertyName];
|
|
1315
|
+
if (value && typeof value === 'object') {
|
|
1316
|
+
$deepFreeze(value);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1321
|
+
finally {
|
|
1322
|
+
try {
|
|
1323
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1324
|
+
}
|
|
1325
|
+
finally { if (e_1) throw e_1.error; }
|
|
1326
|
+
}
|
|
1327
|
+
return Object.freeze(objectValue);
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1331
|
+
*/
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1335
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1336
|
+
*
|
|
1337
|
+
* - Almost all primitives are serializable BUT:
|
|
1338
|
+
* - `undefined` is not serializable
|
|
1339
|
+
* - `NaN` is not serializable
|
|
1340
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1341
|
+
* - Functions are not serializable
|
|
1342
|
+
* - Circular references are not serializable
|
|
1343
|
+
* - `Date` objects are not serializable
|
|
1344
|
+
* - `Map` and `Set` objects are not serializable
|
|
1345
|
+
* - `RegExp` objects are not serializable
|
|
1346
|
+
* - `Error` objects are not serializable
|
|
1347
|
+
* - `Symbol` objects are not serializable
|
|
1348
|
+
* - And much more...
|
|
1349
|
+
*
|
|
1350
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1351
|
+
* @public exported from `@promptbook/utils`
|
|
1352
|
+
*/
|
|
1353
|
+
function checkSerializableAsJson(name, value) {
|
|
1354
|
+
var e_1, _a;
|
|
1355
|
+
if (value === undefined) {
|
|
1356
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1357
|
+
}
|
|
1358
|
+
else if (value === null) {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
else if (typeof value === 'boolean') {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
else if (typeof value === 'string') {
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
else if (typeof value === 'symbol') {
|
|
1371
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1372
|
+
}
|
|
1373
|
+
else if (typeof value === 'function') {
|
|
1374
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1375
|
+
}
|
|
1376
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1377
|
+
for (var i = 0; i < value.length; i++) {
|
|
1378
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
else if (typeof value === 'object') {
|
|
1382
|
+
if (value instanceof Date) {
|
|
1383
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1384
|
+
}
|
|
1385
|
+
else if (value instanceof Map) {
|
|
1386
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1387
|
+
}
|
|
1388
|
+
else if (value instanceof Set) {
|
|
1389
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1390
|
+
}
|
|
1391
|
+
else if (value instanceof RegExp) {
|
|
1392
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1393
|
+
}
|
|
1394
|
+
else if (value instanceof Error) {
|
|
1395
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1398
|
+
try {
|
|
1399
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1400
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1401
|
+
if (subValue === undefined) {
|
|
1402
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1409
|
+
finally {
|
|
1410
|
+
try {
|
|
1411
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1412
|
+
}
|
|
1413
|
+
finally { if (e_1) throw e_1.error; }
|
|
1414
|
+
}
|
|
1415
|
+
try {
|
|
1416
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1417
|
+
}
|
|
1418
|
+
catch (error) {
|
|
1419
|
+
if (!(error instanceof Error)) {
|
|
1420
|
+
throw error;
|
|
1421
|
+
}
|
|
1422
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1423
|
+
}
|
|
1424
|
+
/*
|
|
1425
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1426
|
+
const seen = new Set();
|
|
1427
|
+
const stack = [{ value }];
|
|
1428
|
+
while (stack.length > 0) {
|
|
1429
|
+
const { value } = stack.pop()!;
|
|
1430
|
+
if (typeof value === 'object' && value !== null) {
|
|
1431
|
+
if (seen.has(value)) {
|
|
1432
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1433
|
+
}
|
|
1434
|
+
seen.add(value);
|
|
1435
|
+
if (Array.isArray(value)) {
|
|
1436
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1437
|
+
} else {
|
|
1438
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
*/
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
else {
|
|
1447
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1452
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1453
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1454
|
+
*/
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* @@@
|
|
1458
|
+
* @@@
|
|
1459
|
+
*
|
|
1460
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1461
|
+
*
|
|
1462
|
+
* @param name - Name of the object for debugging purposes
|
|
1463
|
+
* @param objectValue - Object to be deeply frozen
|
|
1464
|
+
* @returns The same object as the input, but deeply frozen
|
|
1465
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1466
|
+
*/
|
|
1467
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1468
|
+
checkSerializableAsJson(name, objectValue);
|
|
1469
|
+
return $deepFreeze(objectValue);
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1473
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1474
|
+
*/
|
|
1475
|
+
|
|
1437
1476
|
/**
|
|
1438
1477
|
* Unprepare just strips the preparation data of the pipeline
|
|
1439
1478
|
*
|
|
@@ -3747,6 +3786,7 @@
|
|
|
3747
3786
|
*/
|
|
3748
3787
|
function extractVariablesFromScript(script) {
|
|
3749
3788
|
var variables = new Set();
|
|
3789
|
+
var originalScript = script;
|
|
3750
3790
|
script = "(()=>{".concat(script, "})()");
|
|
3751
3791
|
try {
|
|
3752
3792
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3778,7 +3818,9 @@
|
|
|
3778
3818
|
if (!(error instanceof Error)) {
|
|
3779
3819
|
throw error;
|
|
3780
3820
|
}
|
|
3781
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3821
|
+
throw new ParseError(spaceTrim.spaceTrim(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)
|
|
3822
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3823
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3782
3824
|
}
|
|
3783
3825
|
return variables;
|
|
3784
3826
|
}
|
|
@@ -5877,11 +5919,11 @@
|
|
|
5877
5919
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
5878
5920
|
if (placeForSection !== null) {
|
|
5879
5921
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
5880
|
-
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n
|
|
5922
|
+
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
5881
5923
|
}
|
|
5882
5924
|
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
5883
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
5884
|
-
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n
|
|
5925
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
5926
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
5885
5927
|
}
|
|
5886
5928
|
/**
|
|
5887
5929
|
* TODO: [🏛] This can be part of markdown builder
|