@promptbook/utils 0.66.0 → 0.67.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +428 -137
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -4
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/_packages/utils.index.d.ts +14 -8
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
- package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
- package/esm/typings/src/errors/index.d.ts +27 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
- package/esm/typings/src/execution/PromptResult.d.ts +4 -4
- package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +431 -137
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -4,7 +4,7 @@ import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
|
4
4
|
/**
|
|
5
5
|
* The version of the Promptbook library
|
|
6
6
|
*/
|
|
7
|
-
var PROMPTBOOK_VERSION = '0.
|
|
7
|
+
var PROMPTBOOK_VERSION = '0.67.0-0';
|
|
8
8
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
9
9
|
|
|
10
10
|
/*! *****************************************************************************
|
|
@@ -696,7 +696,7 @@ function extractVariables(script) {
|
|
|
696
696
|
var undefinedName = error.message.split(' ')[0];
|
|
697
697
|
/*
|
|
698
698
|
Note: Parsing the error
|
|
699
|
-
[
|
|
699
|
+
[PipelineUrlError: thing is not defined]
|
|
700
700
|
*/
|
|
701
701
|
if (!undefinedName) {
|
|
702
702
|
throw error;
|
|
@@ -714,7 +714,7 @@ function extractVariables(script) {
|
|
|
714
714
|
if (!(error instanceof Error)) {
|
|
715
715
|
throw error;
|
|
716
716
|
}
|
|
717
|
-
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.
|
|
717
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
|
|
718
718
|
}
|
|
719
719
|
return variables;
|
|
720
720
|
}
|
|
@@ -856,6 +856,167 @@ function renameParameter(options) {
|
|
|
856
856
|
return renamedPipeline;
|
|
857
857
|
}
|
|
858
858
|
|
|
859
|
+
/**
|
|
860
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
861
|
+
*
|
|
862
|
+
* @public exported from `@promptbook/core`
|
|
863
|
+
*/
|
|
864
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
865
|
+
__extends(CollectionError, _super);
|
|
866
|
+
function CollectionError(message) {
|
|
867
|
+
var _this = _super.call(this, message) || this;
|
|
868
|
+
_this.name = 'CollectionError';
|
|
869
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
870
|
+
return _this;
|
|
871
|
+
}
|
|
872
|
+
return CollectionError;
|
|
873
|
+
}(Error));
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
877
|
+
*
|
|
878
|
+
* @public exported from `@promptbook/core`
|
|
879
|
+
*/
|
|
880
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
881
|
+
__extends(EnvironmentMismatchError, _super);
|
|
882
|
+
function EnvironmentMismatchError(message) {
|
|
883
|
+
var _this = _super.call(this, message) || this;
|
|
884
|
+
_this.name = 'EnvironmentMismatchError';
|
|
885
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
886
|
+
return _this;
|
|
887
|
+
}
|
|
888
|
+
return EnvironmentMismatchError;
|
|
889
|
+
}(Error));
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* This error type indicates that some limit was reached
|
|
893
|
+
*
|
|
894
|
+
* @public exported from `@promptbook/core`
|
|
895
|
+
*/
|
|
896
|
+
var LimitReachedError = /** @class */ (function (_super) {
|
|
897
|
+
__extends(LimitReachedError, _super);
|
|
898
|
+
function LimitReachedError(message) {
|
|
899
|
+
var _this = _super.call(this, message) || this;
|
|
900
|
+
_this.name = 'LimitReachedError';
|
|
901
|
+
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
902
|
+
return _this;
|
|
903
|
+
}
|
|
904
|
+
return LimitReachedError;
|
|
905
|
+
}(Error));
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* This error indicates that promptbook not found in the collection
|
|
909
|
+
*
|
|
910
|
+
* @public exported from `@promptbook/core`
|
|
911
|
+
*/
|
|
912
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
913
|
+
__extends(NotFoundError, _super);
|
|
914
|
+
function NotFoundError(message) {
|
|
915
|
+
var _this = _super.call(this, message) || this;
|
|
916
|
+
_this.name = 'NotFoundError';
|
|
917
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
918
|
+
return _this;
|
|
919
|
+
}
|
|
920
|
+
return NotFoundError;
|
|
921
|
+
}(Error));
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* This error type indicates that some part of the code is not implemented yet
|
|
925
|
+
*
|
|
926
|
+
* @public exported from `@promptbook/core`
|
|
927
|
+
*/
|
|
928
|
+
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
929
|
+
__extends(NotYetImplementedError, _super);
|
|
930
|
+
function NotYetImplementedError(message) {
|
|
931
|
+
var _this = _super.call(this, spaceTrim(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;
|
|
932
|
+
_this.name = 'NotYetImplementedError';
|
|
933
|
+
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
934
|
+
return _this;
|
|
935
|
+
}
|
|
936
|
+
return NotYetImplementedError;
|
|
937
|
+
}(Error));
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* This error indicates errors during the execution of the pipeline
|
|
941
|
+
*
|
|
942
|
+
* @public exported from `@promptbook/core`
|
|
943
|
+
*/
|
|
944
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
945
|
+
__extends(PipelineExecutionError, _super);
|
|
946
|
+
function PipelineExecutionError(message) {
|
|
947
|
+
var _this = _super.call(this, message) || this;
|
|
948
|
+
_this.name = 'PipelineExecutionError';
|
|
949
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
950
|
+
return _this;
|
|
951
|
+
}
|
|
952
|
+
return PipelineExecutionError;
|
|
953
|
+
}(Error));
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
957
|
+
*
|
|
958
|
+
* @public exported from `@promptbook/core`
|
|
959
|
+
*/
|
|
960
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
961
|
+
__extends(PipelineUrlError, _super);
|
|
962
|
+
function PipelineUrlError(message) {
|
|
963
|
+
var _this = _super.call(this, message) || this;
|
|
964
|
+
_this.name = 'PipelineUrlError';
|
|
965
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
966
|
+
return _this;
|
|
967
|
+
}
|
|
968
|
+
return PipelineUrlError;
|
|
969
|
+
}(Error));
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Index of all custom errors
|
|
973
|
+
*
|
|
974
|
+
* @public exported from `@promptbook/core`
|
|
975
|
+
*/
|
|
976
|
+
var ERRORS = {
|
|
977
|
+
CollectionError: CollectionError,
|
|
978
|
+
EnvironmentMismatchError: EnvironmentMismatchError,
|
|
979
|
+
LimitReachedError: LimitReachedError,
|
|
980
|
+
NotFoundError: NotFoundError,
|
|
981
|
+
NotYetImplementedError: NotYetImplementedError,
|
|
982
|
+
ParsingError: ParsingError,
|
|
983
|
+
PipelineExecutionError: PipelineExecutionError,
|
|
984
|
+
PipelineLogicError: PipelineLogicError,
|
|
985
|
+
PipelineUrlError: PipelineUrlError,
|
|
986
|
+
UnexpectedError: UnexpectedError,
|
|
987
|
+
// TODO: [🪑]> VersionMismatchError,
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Deserializes the error object
|
|
992
|
+
*
|
|
993
|
+
* @public exported from `@promptbook/utils`
|
|
994
|
+
*/
|
|
995
|
+
function deserializeError(error) {
|
|
996
|
+
if (error.name === 'Error') {
|
|
997
|
+
return new Error(error.message);
|
|
998
|
+
}
|
|
999
|
+
var CustomError = ERRORS[error.name];
|
|
1000
|
+
return new CustomError(error.message);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Serializes an error into a [🚉] JSON-serializable object
|
|
1005
|
+
*
|
|
1006
|
+
* @public exported from `@promptbook/utils`
|
|
1007
|
+
*/
|
|
1008
|
+
function serializeError(error) {
|
|
1009
|
+
var name = error.name, message = error.message, stack = error.stack;
|
|
1010
|
+
if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
|
|
1011
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
1012
|
+
}
|
|
1013
|
+
return {
|
|
1014
|
+
name: name,
|
|
1015
|
+
message: message,
|
|
1016
|
+
stack: stack,
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
|
|
859
1020
|
/**
|
|
860
1021
|
* Async version of Array.forEach
|
|
861
1022
|
*
|
|
@@ -1093,106 +1254,6 @@ function $currentDate() {
|
|
|
1093
1254
|
return new Date().toISOString();
|
|
1094
1255
|
}
|
|
1095
1256
|
|
|
1096
|
-
/**
|
|
1097
|
-
* @@@
|
|
1098
|
-
*
|
|
1099
|
-
* Note: It is usefull @@@
|
|
1100
|
-
*
|
|
1101
|
-
* @param pipeline
|
|
1102
|
-
* @public exported from `@promptbook/utils`
|
|
1103
|
-
*/
|
|
1104
|
-
function clonePipeline(pipeline) {
|
|
1105
|
-
// Note: Not using spread operator (...) because @@@
|
|
1106
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
1107
|
-
return {
|
|
1108
|
-
pipelineUrl: pipelineUrl,
|
|
1109
|
-
sourceFile: sourceFile,
|
|
1110
|
-
title: title,
|
|
1111
|
-
promptbookVersion: promptbookVersion,
|
|
1112
|
-
description: description,
|
|
1113
|
-
parameters: parameters,
|
|
1114
|
-
promptTemplates: promptTemplates,
|
|
1115
|
-
knowledgeSources: knowledgeSources,
|
|
1116
|
-
knowledgePieces: knowledgePieces,
|
|
1117
|
-
personas: personas,
|
|
1118
|
-
preparations: preparations,
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* TODO: [🍙] Make some standart order of json properties
|
|
1123
|
-
*/
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* @@@
|
|
1127
|
-
*
|
|
1128
|
-
* @public exported from `@promptbook/utils`
|
|
1129
|
-
*/
|
|
1130
|
-
function deepClone(objectValue) {
|
|
1131
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
1132
|
-
/*
|
|
1133
|
-
TODO: [🧠] Is there a better implementation?
|
|
1134
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1135
|
-
> for (const propertyName of propertyNames) {
|
|
1136
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
1137
|
-
> if (value && typeof value === 'object') {
|
|
1138
|
-
> deepClone(value);
|
|
1139
|
-
> }
|
|
1140
|
-
> }
|
|
1141
|
-
> return Object.assign({}, objectValue);
|
|
1142
|
-
*/
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1146
|
-
*/
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* @@@
|
|
1150
|
-
*
|
|
1151
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1152
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1153
|
-
*
|
|
1154
|
-
* @returns The same object as the input, but deeply frozen
|
|
1155
|
-
* @public exported from `@promptbook/utils`
|
|
1156
|
-
*/
|
|
1157
|
-
function $deepFreeze(objectValue) {
|
|
1158
|
-
var e_1, _a;
|
|
1159
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1160
|
-
try {
|
|
1161
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1162
|
-
var propertyName = propertyNames_1_1.value;
|
|
1163
|
-
var value = objectValue[propertyName];
|
|
1164
|
-
if (value && typeof value === 'object') {
|
|
1165
|
-
$deepFreeze(value);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1170
|
-
finally {
|
|
1171
|
-
try {
|
|
1172
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1173
|
-
}
|
|
1174
|
-
finally { if (e_1) throw e_1.error; }
|
|
1175
|
-
}
|
|
1176
|
-
return Object.freeze(objectValue);
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1180
|
-
*/
|
|
1181
|
-
|
|
1182
|
-
/**
|
|
1183
|
-
* @@@
|
|
1184
|
-
*
|
|
1185
|
-
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
1186
|
-
*
|
|
1187
|
-
* @public exported from `@promptbook/utils`
|
|
1188
|
-
*/
|
|
1189
|
-
function $getGlobalScope() {
|
|
1190
|
-
return Function('return this')();
|
|
1191
|
-
}
|
|
1192
|
-
/***
|
|
1193
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
1194
|
-
*/
|
|
1195
|
-
|
|
1196
1257
|
/**
|
|
1197
1258
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
1198
1259
|
*
|
|
@@ -1656,6 +1717,183 @@ function removeQuotes(text) {
|
|
|
1656
1717
|
return text;
|
|
1657
1718
|
}
|
|
1658
1719
|
|
|
1720
|
+
/**
|
|
1721
|
+
* @@@
|
|
1722
|
+
*
|
|
1723
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1724
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1725
|
+
*
|
|
1726
|
+
* @returns The same object as the input, but deeply frozen
|
|
1727
|
+
* @public exported from `@promptbook/utils`
|
|
1728
|
+
*/
|
|
1729
|
+
function $deepFreeze(objectValue) {
|
|
1730
|
+
var e_1, _a;
|
|
1731
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1732
|
+
try {
|
|
1733
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1734
|
+
var propertyName = propertyNames_1_1.value;
|
|
1735
|
+
var value = objectValue[propertyName];
|
|
1736
|
+
if (value && typeof value === 'object') {
|
|
1737
|
+
$deepFreeze(value);
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1742
|
+
finally {
|
|
1743
|
+
try {
|
|
1744
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1745
|
+
}
|
|
1746
|
+
finally { if (e_1) throw e_1.error; }
|
|
1747
|
+
}
|
|
1748
|
+
return Object.freeze(objectValue);
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1752
|
+
*/
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1756
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1757
|
+
*
|
|
1758
|
+
* - Almost all primitives are serializable BUT:
|
|
1759
|
+
* - `undefined` is not serializable
|
|
1760
|
+
* - `NaN` is not serializable
|
|
1761
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1762
|
+
* - Functions are not serializable
|
|
1763
|
+
* - Circular references are not serializable
|
|
1764
|
+
* - `Date` objects are not serializable
|
|
1765
|
+
* - `Map` and `Set` objects are not serializable
|
|
1766
|
+
* - `RegExp` objects are not serializable
|
|
1767
|
+
* - `Error` objects are not serializable
|
|
1768
|
+
* - `Symbol` objects are not serializable
|
|
1769
|
+
* - And much more...
|
|
1770
|
+
*
|
|
1771
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1772
|
+
* @public exported from `@promptbook/utils`
|
|
1773
|
+
*/
|
|
1774
|
+
function checkSerializableAsJson(name, value) {
|
|
1775
|
+
var e_1, _a;
|
|
1776
|
+
if (value === undefined) {
|
|
1777
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1778
|
+
}
|
|
1779
|
+
else if (value === null) {
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
else if (typeof value === 'boolean') {
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
else if (typeof value === 'string') {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
else if (typeof value === 'symbol') {
|
|
1792
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1793
|
+
}
|
|
1794
|
+
else if (typeof value === 'function') {
|
|
1795
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1796
|
+
}
|
|
1797
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1798
|
+
for (var i = 0; i < value.length; i++) {
|
|
1799
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
else if (typeof value === 'object') {
|
|
1803
|
+
if (value instanceof Date) {
|
|
1804
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1805
|
+
}
|
|
1806
|
+
else if (value instanceof Map) {
|
|
1807
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1808
|
+
}
|
|
1809
|
+
else if (value instanceof Set) {
|
|
1810
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1811
|
+
}
|
|
1812
|
+
else if (value instanceof RegExp) {
|
|
1813
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1814
|
+
}
|
|
1815
|
+
else if (value instanceof Error) {
|
|
1816
|
+
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1817
|
+
}
|
|
1818
|
+
else {
|
|
1819
|
+
try {
|
|
1820
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1821
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1822
|
+
if (subValue === undefined) {
|
|
1823
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1824
|
+
continue;
|
|
1825
|
+
}
|
|
1826
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1830
|
+
finally {
|
|
1831
|
+
try {
|
|
1832
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1833
|
+
}
|
|
1834
|
+
finally { if (e_1) throw e_1.error; }
|
|
1835
|
+
}
|
|
1836
|
+
try {
|
|
1837
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1838
|
+
}
|
|
1839
|
+
catch (error) {
|
|
1840
|
+
if (!(error instanceof Error)) {
|
|
1841
|
+
throw error;
|
|
1842
|
+
}
|
|
1843
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1844
|
+
}
|
|
1845
|
+
/*
|
|
1846
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1847
|
+
const seen = new Set();
|
|
1848
|
+
const stack = [{ value }];
|
|
1849
|
+
while (stack.length > 0) {
|
|
1850
|
+
const { value } = stack.pop()!;
|
|
1851
|
+
if (typeof value === 'object' && value !== null) {
|
|
1852
|
+
if (seen.has(value)) {
|
|
1853
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1854
|
+
}
|
|
1855
|
+
seen.add(value);
|
|
1856
|
+
if (Array.isArray(value)) {
|
|
1857
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1858
|
+
} else {
|
|
1859
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
*/
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
else {
|
|
1868
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1873
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
1874
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1875
|
+
*/
|
|
1876
|
+
|
|
1877
|
+
/**
|
|
1878
|
+
* @@@
|
|
1879
|
+
* @@@
|
|
1880
|
+
*
|
|
1881
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1882
|
+
*
|
|
1883
|
+
* @param name - Name of the object for debugging purposes
|
|
1884
|
+
* @param objectValue - Object to be deeply frozen
|
|
1885
|
+
* @returns The same object as the input, but deeply frozen
|
|
1886
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1887
|
+
*/
|
|
1888
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1889
|
+
checkSerializableAsJson(name, objectValue);
|
|
1890
|
+
return $deepFreeze(objectValue);
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1894
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1895
|
+
*/
|
|
1896
|
+
|
|
1659
1897
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
1660
1898
|
/**
|
|
1661
1899
|
* The maximum number of iterations for a loops
|
|
@@ -1674,7 +1912,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
1674
1912
|
*
|
|
1675
1913
|
* @public exported from `@promptbook/core`
|
|
1676
1914
|
*/
|
|
1677
|
-
$
|
|
1915
|
+
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
1678
1916
|
'content',
|
|
1679
1917
|
'context',
|
|
1680
1918
|
'knowledge',
|
|
@@ -1700,38 +1938,6 @@ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
|
1700
1938
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
1701
1939
|
*/
|
|
1702
1940
|
|
|
1703
|
-
/**
|
|
1704
|
-
* This error type indicates that some limit was reached
|
|
1705
|
-
*
|
|
1706
|
-
* @public exported from `@promptbook/core`
|
|
1707
|
-
*/
|
|
1708
|
-
var LimitReachedError = /** @class */ (function (_super) {
|
|
1709
|
-
__extends(LimitReachedError, _super);
|
|
1710
|
-
function LimitReachedError(message) {
|
|
1711
|
-
var _this = _super.call(this, message) || this;
|
|
1712
|
-
_this.name = 'LimitReachedError';
|
|
1713
|
-
Object.setPrototypeOf(_this, LimitReachedError.prototype);
|
|
1714
|
-
return _this;
|
|
1715
|
-
}
|
|
1716
|
-
return LimitReachedError;
|
|
1717
|
-
}(Error));
|
|
1718
|
-
|
|
1719
|
-
/**
|
|
1720
|
-
* This error indicates errors during the execution of the pipeline
|
|
1721
|
-
*
|
|
1722
|
-
* @public exported from `@promptbook/core`
|
|
1723
|
-
*/
|
|
1724
|
-
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1725
|
-
__extends(PipelineExecutionError, _super);
|
|
1726
|
-
function PipelineExecutionError(message) {
|
|
1727
|
-
var _this = _super.call(this, message) || this;
|
|
1728
|
-
_this.name = 'PipelineExecutionError';
|
|
1729
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
1730
|
-
return _this;
|
|
1731
|
-
}
|
|
1732
|
-
return PipelineExecutionError;
|
|
1733
|
-
}(Error));
|
|
1734
|
-
|
|
1735
1941
|
/**
|
|
1736
1942
|
* Replaces parameters in template with values from parameters object
|
|
1737
1943
|
*
|
|
@@ -1811,6 +2017,91 @@ function replaceParameters(template, parameters) {
|
|
|
1811
2017
|
return replacedTemplate;
|
|
1812
2018
|
}
|
|
1813
2019
|
|
|
2020
|
+
/**
|
|
2021
|
+
* @@@
|
|
2022
|
+
*
|
|
2023
|
+
* Note: It is usefull @@@
|
|
2024
|
+
*
|
|
2025
|
+
* @param pipeline
|
|
2026
|
+
* @public exported from `@promptbook/utils`
|
|
2027
|
+
*/
|
|
2028
|
+
function clonePipeline(pipeline) {
|
|
2029
|
+
// Note: Not using spread operator (...) because @@@
|
|
2030
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
2031
|
+
return {
|
|
2032
|
+
pipelineUrl: pipelineUrl,
|
|
2033
|
+
sourceFile: sourceFile,
|
|
2034
|
+
title: title,
|
|
2035
|
+
promptbookVersion: promptbookVersion,
|
|
2036
|
+
description: description,
|
|
2037
|
+
parameters: parameters,
|
|
2038
|
+
promptTemplates: promptTemplates,
|
|
2039
|
+
knowledgeSources: knowledgeSources,
|
|
2040
|
+
knowledgePieces: knowledgePieces,
|
|
2041
|
+
personas: personas,
|
|
2042
|
+
preparations: preparations,
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
2047
|
+
*/
|
|
2048
|
+
|
|
2049
|
+
/**
|
|
2050
|
+
* @@@
|
|
2051
|
+
*
|
|
2052
|
+
* @public exported from `@promptbook/utils`
|
|
2053
|
+
*/
|
|
2054
|
+
function deepClone(objectValue) {
|
|
2055
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
2056
|
+
/*
|
|
2057
|
+
TODO: [🧠] Is there a better implementation?
|
|
2058
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2059
|
+
> for (const propertyName of propertyNames) {
|
|
2060
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
2061
|
+
> if (value && typeof value === 'object') {
|
|
2062
|
+
> deepClone(value);
|
|
2063
|
+
> }
|
|
2064
|
+
> }
|
|
2065
|
+
> return Object.assign({}, objectValue);
|
|
2066
|
+
*/
|
|
2067
|
+
}
|
|
2068
|
+
/**
|
|
2069
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
2070
|
+
*/
|
|
2071
|
+
|
|
2072
|
+
/**
|
|
2073
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
2074
|
+
*
|
|
2075
|
+
* - Almost all primitives are serializable BUT:
|
|
2076
|
+
* - `undefined` is not serializable
|
|
2077
|
+
* - `NaN` is not serializable
|
|
2078
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
2079
|
+
* - Functions are not serializable
|
|
2080
|
+
* - Circular references are not serializable
|
|
2081
|
+
* - `Date` objects are not serializable
|
|
2082
|
+
* - `Map` and `Set` objects are not serializable
|
|
2083
|
+
* - `RegExp` objects are not serializable
|
|
2084
|
+
* - `Error` objects are not serializable
|
|
2085
|
+
* - `Symbol` objects are not serializable
|
|
2086
|
+
* - And much more...
|
|
2087
|
+
*
|
|
2088
|
+
*
|
|
2089
|
+
* @public exported from `@promptbook/utils`
|
|
2090
|
+
*/
|
|
2091
|
+
function isSerializableAsJson(value) {
|
|
2092
|
+
try {
|
|
2093
|
+
checkSerializableAsJson('', value);
|
|
2094
|
+
return true;
|
|
2095
|
+
}
|
|
2096
|
+
catch (error) {
|
|
2097
|
+
return false;
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
2102
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
2103
|
+
*/
|
|
2104
|
+
|
|
1814
2105
|
/**
|
|
1815
2106
|
* Create difference set of two sets.
|
|
1816
2107
|
*
|
|
@@ -2250,5 +2541,5 @@ function isValidUuid(value) {
|
|
|
2250
2541
|
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);
|
|
2251
2542
|
}
|
|
2252
2543
|
|
|
2253
|
-
export { $currentDate, $deepFreeze, $
|
|
2544
|
+
export { $currentDate, $deepFreeze, $isRunningInBrowser, $isRunningInNode, $isRunningInWebWorker, $randomSeed, CountUtils, DIACRITIC_VARIANTS_LETTERS, PROMPTBOOK_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, extractBlock, extractParameterNames, extractParameterNamesFromPromptTemplate, extractVariables, 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, renameParameter, renderPromptbookMermaid, replaceParameters, searchKeywords, serializeError, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
|
|
2254
2545
|
//# sourceMappingURL=index.es.js.map
|