@promptbook/markdown-utils 0.79.0 โ 0.80.0-0
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 +4 -0
- package/esm/index.es.js +400 -324
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +1 -1
- package/umd/index.umd.js +400 -324
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -356,7 +356,7 @@ function extractJsonBlock(markdown) {
|
|
|
356
356
|
* TODO: [๐ข] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
|
|
357
357
|
*/
|
|
358
358
|
|
|
359
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],
|
|
359
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-persona.book.md"}];
|
|
360
360
|
|
|
361
361
|
/**
|
|
362
362
|
* Prettify the html code
|
|
@@ -395,6 +395,7 @@ function prettifyMarkdown(content) {
|
|
|
395
395
|
/**
|
|
396
396
|
* Converts promptbook in JSON format to string format
|
|
397
397
|
*
|
|
398
|
+
* @deprecated TODO: [๐ฅ][๐ง ] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
398
399
|
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
399
400
|
* @returns Promptbook in string format (.book.md)
|
|
400
401
|
* @public exported from `@promptbook/core`
|
|
@@ -690,41 +691,6 @@ var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
|
690
691
|
* @public exported from `@promptbook/core`
|
|
691
692
|
*/
|
|
692
693
|
var DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
693
|
-
/**
|
|
694
|
-
* Nonce which is used for replacing things in strings
|
|
695
|
-
*
|
|
696
|
-
* @private within the repository
|
|
697
|
-
*/
|
|
698
|
-
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
699
|
-
/**
|
|
700
|
-
* The names of the parameters that are reserved for special purposes
|
|
701
|
-
*
|
|
702
|
-
* @public exported from `@promptbook/core`
|
|
703
|
-
*/
|
|
704
|
-
var RESERVED_PARAMETER_NAMES =
|
|
705
|
-
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
706
|
-
'content',
|
|
707
|
-
'context',
|
|
708
|
-
'knowledge',
|
|
709
|
-
'examples',
|
|
710
|
-
'modelName',
|
|
711
|
-
'currentDate',
|
|
712
|
-
// <- TODO: list here all command names
|
|
713
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
714
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
715
|
-
];
|
|
716
|
-
/**
|
|
717
|
-
* @@@
|
|
718
|
-
*
|
|
719
|
-
* @private within the repository
|
|
720
|
-
*/
|
|
721
|
-
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
722
|
-
/**
|
|
723
|
-
* @@@
|
|
724
|
-
*
|
|
725
|
-
* @private within the repository
|
|
726
|
-
*/
|
|
727
|
-
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
728
694
|
// <- TODO: [๐งโโ๏ธ]
|
|
729
695
|
/**
|
|
730
696
|
* @@@
|
|
@@ -759,26 +725,59 @@ var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
759
725
|
// Note: In normal situations, we check the pipeline logic:
|
|
760
726
|
true);
|
|
761
727
|
/**
|
|
762
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
763
728
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
764
729
|
* TODO: [๐ง ][๐งโโ๏ธ] Maybe join remoteUrl and path into single value
|
|
765
730
|
*/
|
|
766
731
|
|
|
767
732
|
/**
|
|
768
|
-
*
|
|
733
|
+
* Orders JSON object by keys
|
|
769
734
|
*
|
|
770
|
-
* @
|
|
735
|
+
* @returns The same type of object as the input re-ordered
|
|
736
|
+
* @public exported from `@promptbook/utils`
|
|
771
737
|
*/
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
function
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
738
|
+
function orderJson(options) {
|
|
739
|
+
var value = options.value, order = options.order;
|
|
740
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
741
|
+
return orderedValue;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Freezes the given object and all its nested objects recursively
|
|
746
|
+
*
|
|
747
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
748
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
749
|
+
*
|
|
750
|
+
* @returns The same object as the input, but deeply frozen
|
|
751
|
+
* @public exported from `@promptbook/utils`
|
|
752
|
+
*/
|
|
753
|
+
function $deepFreeze(objectValue) {
|
|
754
|
+
var e_1, _a;
|
|
755
|
+
if (Array.isArray(objectValue)) {
|
|
756
|
+
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
779
757
|
}
|
|
780
|
-
|
|
781
|
-
|
|
758
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
759
|
+
try {
|
|
760
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
761
|
+
var propertyName = propertyNames_1_1.value;
|
|
762
|
+
var value = objectValue[propertyName];
|
|
763
|
+
if (value && typeof value === 'object') {
|
|
764
|
+
$deepFreeze(value);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
769
|
+
finally {
|
|
770
|
+
try {
|
|
771
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
772
|
+
}
|
|
773
|
+
finally { if (e_1) throw e_1.error; }
|
|
774
|
+
}
|
|
775
|
+
Object.freeze(objectValue);
|
|
776
|
+
return objectValue;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
780
|
+
*/
|
|
782
781
|
|
|
783
782
|
/**
|
|
784
783
|
* Make error report URL for the given error
|
|
@@ -814,6 +813,264 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
814
813
|
return UnexpectedError;
|
|
815
814
|
}(Error));
|
|
816
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Checks if the value is [๐] serializable as JSON
|
|
818
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
819
|
+
*
|
|
820
|
+
* - Almost all primitives are serializable BUT:
|
|
821
|
+
* - `undefined` is not serializable
|
|
822
|
+
* - `NaN` is not serializable
|
|
823
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
824
|
+
* - Functions are not serializable
|
|
825
|
+
* - Circular references are not serializable
|
|
826
|
+
* - `Date` objects are not serializable
|
|
827
|
+
* - `Map` and `Set` objects are not serializable
|
|
828
|
+
* - `RegExp` objects are not serializable
|
|
829
|
+
* - `Error` objects are not serializable
|
|
830
|
+
* - `Symbol` objects are not serializable
|
|
831
|
+
* - And much more...
|
|
832
|
+
*
|
|
833
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
834
|
+
* @public exported from `@promptbook/utils`
|
|
835
|
+
*/
|
|
836
|
+
function checkSerializableAsJson(options) {
|
|
837
|
+
var e_1, _a;
|
|
838
|
+
var value = options.value, name = options.name, message = options.message;
|
|
839
|
+
if (value === undefined) {
|
|
840
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
841
|
+
}
|
|
842
|
+
else if (value === null) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
else if (typeof value === 'boolean') {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
else if (typeof value === 'string') {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
else if (typeof value === 'symbol') {
|
|
855
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
856
|
+
}
|
|
857
|
+
else if (typeof value === 'function') {
|
|
858
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
859
|
+
}
|
|
860
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
861
|
+
for (var i = 0; i < value.length; i++) {
|
|
862
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
else if (typeof value === 'object') {
|
|
866
|
+
if (value instanceof Date) {
|
|
867
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
868
|
+
}
|
|
869
|
+
else if (value instanceof Map) {
|
|
870
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
871
|
+
}
|
|
872
|
+
else if (value instanceof Set) {
|
|
873
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
874
|
+
}
|
|
875
|
+
else if (value instanceof RegExp) {
|
|
876
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
877
|
+
}
|
|
878
|
+
else if (value instanceof Error) {
|
|
879
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
try {
|
|
883
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
884
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
885
|
+
if (subValue === undefined) {
|
|
886
|
+
// Note: undefined in object is serializable - it is just omited
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
893
|
+
finally {
|
|
894
|
+
try {
|
|
895
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
896
|
+
}
|
|
897
|
+
finally { if (e_1) throw e_1.error; }
|
|
898
|
+
}
|
|
899
|
+
try {
|
|
900
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
if (!(error instanceof Error)) {
|
|
904
|
+
throw error;
|
|
905
|
+
}
|
|
906
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
907
|
+
}
|
|
908
|
+
/*
|
|
909
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
910
|
+
const seen = new Set();
|
|
911
|
+
const stack = [{ value }];
|
|
912
|
+
while (stack.length > 0) {
|
|
913
|
+
const { value } = stack.pop()!;
|
|
914
|
+
if (typeof value === 'object' && value !== null) {
|
|
915
|
+
if (seen.has(value)) {
|
|
916
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
917
|
+
}
|
|
918
|
+
seen.add(value);
|
|
919
|
+
if (Array.isArray(value)) {
|
|
920
|
+
stack.push(...value.map((value) => ({ value })));
|
|
921
|
+
} else {
|
|
922
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
*/
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
936
|
+
* TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks
|
|
937
|
+
* Note: [๐ ] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* @@@
|
|
942
|
+
*
|
|
943
|
+
* @public exported from `@promptbook/utils`
|
|
944
|
+
*/
|
|
945
|
+
function deepClone(objectValue) {
|
|
946
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
947
|
+
/*
|
|
948
|
+
!!!!!!!!
|
|
949
|
+
TODO: [๐ง ] Is there a better implementation?
|
|
950
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
951
|
+
> for (const propertyName of propertyNames) {
|
|
952
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
953
|
+
> if (value && typeof value === 'object') {
|
|
954
|
+
> deepClone(value);
|
|
955
|
+
> }
|
|
956
|
+
> }
|
|
957
|
+
> return Object.assign({}, objectValue);
|
|
958
|
+
*/
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
962
|
+
*/
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Utility to export a JSON object from a function
|
|
966
|
+
*
|
|
967
|
+
* 1) Checks if the value is serializable as JSON
|
|
968
|
+
* 2) Makes a deep clone of the object
|
|
969
|
+
* 2) Orders the object properties
|
|
970
|
+
* 2) Deeply freezes the cloned object
|
|
971
|
+
*
|
|
972
|
+
* Note: This function does not mutates the given object
|
|
973
|
+
*
|
|
974
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
975
|
+
* @public exported from `@promptbook/utils`
|
|
976
|
+
*/
|
|
977
|
+
function exportJson(options) {
|
|
978
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
979
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
980
|
+
var orderedValue =
|
|
981
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
982
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
983
|
+
// @ts-ignore
|
|
984
|
+
order === undefined
|
|
985
|
+
? deepClone(value)
|
|
986
|
+
: orderJson({
|
|
987
|
+
value: value,
|
|
988
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
989
|
+
order: order,
|
|
990
|
+
});
|
|
991
|
+
$deepFreeze(orderedValue);
|
|
992
|
+
return orderedValue;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
996
|
+
*/
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* Order of keys in the pipeline JSON
|
|
1000
|
+
*
|
|
1001
|
+
* @public exported from `@promptbook/core`
|
|
1002
|
+
*/
|
|
1003
|
+
var ORDER_OF_PIPELINE_JSON = [
|
|
1004
|
+
'title',
|
|
1005
|
+
'pipelineUrl',
|
|
1006
|
+
'bookVersion',
|
|
1007
|
+
'description',
|
|
1008
|
+
'formfactorName',
|
|
1009
|
+
'parameters',
|
|
1010
|
+
'tasks',
|
|
1011
|
+
'personas',
|
|
1012
|
+
'preparations',
|
|
1013
|
+
'knowledgeSources',
|
|
1014
|
+
'knowledgePieces',
|
|
1015
|
+
];
|
|
1016
|
+
/**
|
|
1017
|
+
* Nonce which is used for replacing things in strings
|
|
1018
|
+
*
|
|
1019
|
+
* @private within the repository
|
|
1020
|
+
*/
|
|
1021
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
1022
|
+
/**
|
|
1023
|
+
* @@@
|
|
1024
|
+
*
|
|
1025
|
+
* @private within the repository
|
|
1026
|
+
*/
|
|
1027
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
1028
|
+
/**
|
|
1029
|
+
* @@@
|
|
1030
|
+
*
|
|
1031
|
+
* @private within the repository
|
|
1032
|
+
*/
|
|
1033
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1034
|
+
/**
|
|
1035
|
+
* The names of the parameters that are reserved for special purposes
|
|
1036
|
+
*
|
|
1037
|
+
* @public exported from `@promptbook/core`
|
|
1038
|
+
*/
|
|
1039
|
+
var RESERVED_PARAMETER_NAMES = exportJson({
|
|
1040
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
1041
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
1042
|
+
value: [
|
|
1043
|
+
'content',
|
|
1044
|
+
'context',
|
|
1045
|
+
'knowledge',
|
|
1046
|
+
'examples',
|
|
1047
|
+
'modelName',
|
|
1048
|
+
'currentDate',
|
|
1049
|
+
// <- TODO: list here all command names
|
|
1050
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
1051
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1052
|
+
],
|
|
1053
|
+
});
|
|
1054
|
+
/**
|
|
1055
|
+
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
1056
|
+
*/
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
1060
|
+
*
|
|
1061
|
+
* @public exported from `@promptbook/core`
|
|
1062
|
+
*/
|
|
1063
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
1064
|
+
__extends(PipelineLogicError, _super);
|
|
1065
|
+
function PipelineLogicError(message) {
|
|
1066
|
+
var _this = _super.call(this, message) || this;
|
|
1067
|
+
_this.name = 'PipelineLogicError';
|
|
1068
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
1069
|
+
return _this;
|
|
1070
|
+
}
|
|
1071
|
+
return PipelineLogicError;
|
|
1072
|
+
}(Error));
|
|
1073
|
+
|
|
817
1074
|
/**
|
|
818
1075
|
* Tests if given string is valid semantic version
|
|
819
1076
|
*
|
|
@@ -1051,6 +1308,21 @@ function validatePipelineCore(pipeline) {
|
|
|
1051
1308
|
}
|
|
1052
1309
|
};
|
|
1053
1310
|
try {
|
|
1311
|
+
/*
|
|
1312
|
+
TODO: [๐ง ][๐
พ] Should be empty pipeline valid or not
|
|
1313
|
+
// Note: Check that pipeline has some tasks
|
|
1314
|
+
if (pipeline.tasks.length === 0) {
|
|
1315
|
+
throw new PipelineLogicError(
|
|
1316
|
+
spaceTrim(
|
|
1317
|
+
(block) => `
|
|
1318
|
+
Pipeline must have at least one task
|
|
1319
|
+
|
|
1320
|
+
${block(pipelineIdentification)}
|
|
1321
|
+
`,
|
|
1322
|
+
),
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
*/
|
|
1054
1326
|
// Note: Check each parameter individually
|
|
1055
1327
|
for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1056
1328
|
var parameter = _e.value;
|
|
@@ -1211,6 +1483,9 @@ function validatePipelineCore(pipeline) {
|
|
|
1211
1483
|
while (unresovedTasks.length > 0) {
|
|
1212
1484
|
_loop_3();
|
|
1213
1485
|
}
|
|
1486
|
+
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1487
|
+
// TODO: !!!!!! Implement this
|
|
1488
|
+
// pipeline.formfactorName
|
|
1214
1489
|
}
|
|
1215
1490
|
/**
|
|
1216
1491
|
* TODO: !! [๐งโโ๏ธ] Do not allow joker + foreach
|
|
@@ -1294,186 +1569,6 @@ function extractParameterNames(template) {
|
|
|
1294
1569
|
return parameterNames;
|
|
1295
1570
|
}
|
|
1296
1571
|
|
|
1297
|
-
/**
|
|
1298
|
-
* @@@
|
|
1299
|
-
*
|
|
1300
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1301
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1302
|
-
*
|
|
1303
|
-
* @returns The same object as the input, but deeply frozen
|
|
1304
|
-
* @public exported from `@promptbook/utils`
|
|
1305
|
-
*/
|
|
1306
|
-
function $deepFreeze(objectValue) {
|
|
1307
|
-
var e_1, _a;
|
|
1308
|
-
if (Array.isArray(objectValue)) {
|
|
1309
|
-
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
1310
|
-
}
|
|
1311
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1312
|
-
try {
|
|
1313
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1314
|
-
var propertyName = propertyNames_1_1.value;
|
|
1315
|
-
var value = objectValue[propertyName];
|
|
1316
|
-
if (value && typeof value === 'object') {
|
|
1317
|
-
$deepFreeze(value);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1322
|
-
finally {
|
|
1323
|
-
try {
|
|
1324
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1325
|
-
}
|
|
1326
|
-
finally { if (e_1) throw e_1.error; }
|
|
1327
|
-
}
|
|
1328
|
-
return Object.freeze(objectValue);
|
|
1329
|
-
}
|
|
1330
|
-
/**
|
|
1331
|
-
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
1332
|
-
*/
|
|
1333
|
-
|
|
1334
|
-
/**
|
|
1335
|
-
* Checks if the value is [๐] serializable as JSON
|
|
1336
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1337
|
-
*
|
|
1338
|
-
* - Almost all primitives are serializable BUT:
|
|
1339
|
-
* - `undefined` is not serializable
|
|
1340
|
-
* - `NaN` is not serializable
|
|
1341
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
1342
|
-
* - Functions are not serializable
|
|
1343
|
-
* - Circular references are not serializable
|
|
1344
|
-
* - `Date` objects are not serializable
|
|
1345
|
-
* - `Map` and `Set` objects are not serializable
|
|
1346
|
-
* - `RegExp` objects are not serializable
|
|
1347
|
-
* - `Error` objects are not serializable
|
|
1348
|
-
* - `Symbol` objects are not serializable
|
|
1349
|
-
* - And much more...
|
|
1350
|
-
*
|
|
1351
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1352
|
-
* @public exported from `@promptbook/utils`
|
|
1353
|
-
*/
|
|
1354
|
-
function checkSerializableAsJson(name, value) {
|
|
1355
|
-
var e_1, _a;
|
|
1356
|
-
if (value === undefined) {
|
|
1357
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1358
|
-
}
|
|
1359
|
-
else if (value === null) {
|
|
1360
|
-
return;
|
|
1361
|
-
}
|
|
1362
|
-
else if (typeof value === 'boolean') {
|
|
1363
|
-
return;
|
|
1364
|
-
}
|
|
1365
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
else if (typeof value === 'string') {
|
|
1369
|
-
return;
|
|
1370
|
-
}
|
|
1371
|
-
else if (typeof value === 'symbol') {
|
|
1372
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1373
|
-
}
|
|
1374
|
-
else if (typeof value === 'function') {
|
|
1375
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
1376
|
-
}
|
|
1377
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1378
|
-
for (var i = 0; i < value.length; i++) {
|
|
1379
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
else if (typeof value === 'object') {
|
|
1383
|
-
if (value instanceof Date) {
|
|
1384
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1385
|
-
}
|
|
1386
|
-
else if (value instanceof Map) {
|
|
1387
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1388
|
-
}
|
|
1389
|
-
else if (value instanceof Set) {
|
|
1390
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1391
|
-
}
|
|
1392
|
-
else if (value instanceof RegExp) {
|
|
1393
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1394
|
-
}
|
|
1395
|
-
else if (value instanceof Error) {
|
|
1396
|
-
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1397
|
-
}
|
|
1398
|
-
else {
|
|
1399
|
-
try {
|
|
1400
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1401
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1402
|
-
if (subValue === undefined) {
|
|
1403
|
-
// Note: undefined in object is serializable - it is just omited
|
|
1404
|
-
continue;
|
|
1405
|
-
}
|
|
1406
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1410
|
-
finally {
|
|
1411
|
-
try {
|
|
1412
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1413
|
-
}
|
|
1414
|
-
finally { if (e_1) throw e_1.error; }
|
|
1415
|
-
}
|
|
1416
|
-
try {
|
|
1417
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
1418
|
-
}
|
|
1419
|
-
catch (error) {
|
|
1420
|
-
if (!(error instanceof Error)) {
|
|
1421
|
-
throw error;
|
|
1422
|
-
}
|
|
1423
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1424
|
-
}
|
|
1425
|
-
/*
|
|
1426
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
1427
|
-
const seen = new Set();
|
|
1428
|
-
const stack = [{ value }];
|
|
1429
|
-
while (stack.length > 0) {
|
|
1430
|
-
const { value } = stack.pop()!;
|
|
1431
|
-
if (typeof value === 'object' && value !== null) {
|
|
1432
|
-
if (seen.has(value)) {
|
|
1433
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
1434
|
-
}
|
|
1435
|
-
seen.add(value);
|
|
1436
|
-
if (Array.isArray(value)) {
|
|
1437
|
-
stack.push(...value.map((value) => ({ value })));
|
|
1438
|
-
} else {
|
|
1439
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
*/
|
|
1444
|
-
return;
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
else {
|
|
1448
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
/**
|
|
1452
|
-
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name`
|
|
1453
|
-
* TODO: [๐ง ][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1454
|
-
* Note: [๐ ] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1455
|
-
*/
|
|
1456
|
-
|
|
1457
|
-
/**
|
|
1458
|
-
* @@@
|
|
1459
|
-
* @@@
|
|
1460
|
-
*
|
|
1461
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1462
|
-
*
|
|
1463
|
-
* @param name - Name of the object for debugging purposes
|
|
1464
|
-
* @param objectValue - Object to be deeply frozen
|
|
1465
|
-
* @returns The same object as the input, but deeply frozen
|
|
1466
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1467
|
-
*/
|
|
1468
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1469
|
-
checkSerializableAsJson(name, objectValue);
|
|
1470
|
-
return $deepFreeze(objectValue);
|
|
1471
|
-
}
|
|
1472
|
-
/**
|
|
1473
|
-
* TODO: [๐ง ][๐ฃ] More elegant way to tracking than passing `name`
|
|
1474
|
-
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
1475
|
-
*/
|
|
1476
|
-
|
|
1477
1572
|
/**
|
|
1478
1573
|
* Unprepare just strips the preparation data of the pipeline
|
|
1479
1574
|
*
|
|
@@ -1491,7 +1586,12 @@ function unpreparePipeline(pipeline) {
|
|
|
1491
1586
|
delete taskUnprepared.preparedContent;
|
|
1492
1587
|
return taskUnprepared;
|
|
1493
1588
|
});
|
|
1494
|
-
return
|
|
1589
|
+
return exportJson({
|
|
1590
|
+
name: 'pipelineJson',
|
|
1591
|
+
message: "Result of `unpreparePipeline`",
|
|
1592
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
1593
|
+
value: __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }),
|
|
1594
|
+
});
|
|
1495
1595
|
}
|
|
1496
1596
|
/**
|
|
1497
1597
|
* TODO: [๐งฟ] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2053,29 +2153,6 @@ $deepFreeze({
|
|
|
2053
2153
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
2054
2154
|
*/
|
|
2055
2155
|
|
|
2056
|
-
/**
|
|
2057
|
-
* @@@
|
|
2058
|
-
*
|
|
2059
|
-
* @public exported from `@promptbook/utils`
|
|
2060
|
-
*/
|
|
2061
|
-
function deepClone(objectValue) {
|
|
2062
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
2063
|
-
/*
|
|
2064
|
-
TODO: [๐ง ] Is there a better implementation?
|
|
2065
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
2066
|
-
> for (const propertyName of propertyNames) {
|
|
2067
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
2068
|
-
> if (value && typeof value === 'object') {
|
|
2069
|
-
> deepClone(value);
|
|
2070
|
-
> }
|
|
2071
|
-
> }
|
|
2072
|
-
> return Object.assign({}, objectValue);
|
|
2073
|
-
*/
|
|
2074
|
-
}
|
|
2075
|
-
/**
|
|
2076
|
-
* TODO: [๐ง ] Is there a way how to meaningfully test this utility
|
|
2077
|
-
*/
|
|
2078
|
-
|
|
2079
2156
|
/**
|
|
2080
2157
|
* Function `addUsage` will add multiple usages into one
|
|
2081
2158
|
*
|
|
@@ -3601,36 +3678,6 @@ TODO: [๐ง] This is how it can look in future
|
|
|
3601
3678
|
* [ ] One piece can have multiple sources
|
|
3602
3679
|
*/
|
|
3603
3680
|
|
|
3604
|
-
/**
|
|
3605
|
-
* @@@
|
|
3606
|
-
*
|
|
3607
|
-
* Note: It is usefull @@@
|
|
3608
|
-
*
|
|
3609
|
-
* @param pipeline
|
|
3610
|
-
* @public exported from `@promptbook/utils`
|
|
3611
|
-
*/
|
|
3612
|
-
function clonePipeline(pipeline) {
|
|
3613
|
-
// Note: Not using spread operator (...) because @@@
|
|
3614
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
3615
|
-
return {
|
|
3616
|
-
pipelineUrl: pipelineUrl,
|
|
3617
|
-
sourceFile: sourceFile,
|
|
3618
|
-
title: title,
|
|
3619
|
-
bookVersion: bookVersion,
|
|
3620
|
-
description: description,
|
|
3621
|
-
formfactorName: formfactorName,
|
|
3622
|
-
parameters: parameters,
|
|
3623
|
-
tasks: tasks,
|
|
3624
|
-
knowledgeSources: knowledgeSources,
|
|
3625
|
-
knowledgePieces: knowledgePieces,
|
|
3626
|
-
personas: personas,
|
|
3627
|
-
preparations: preparations,
|
|
3628
|
-
};
|
|
3629
|
-
}
|
|
3630
|
-
/**
|
|
3631
|
-
* TODO: [๐] Make some standard order of json properties
|
|
3632
|
-
*/
|
|
3633
|
-
|
|
3634
3681
|
/**
|
|
3635
3682
|
* @@@
|
|
3636
3683
|
*
|
|
@@ -3671,6 +3718,7 @@ function prepareTasks(pipeline, tools, options) {
|
|
|
3671
3718
|
});
|
|
3672
3719
|
}
|
|
3673
3720
|
/**
|
|
3721
|
+
* TODO: [๐] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
3674
3722
|
* TODO: [๐ง ] Add context to each task (if missing)
|
|
3675
3723
|
* TODO: [๐ง ] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3676
3724
|
* TODO: [โจ][main] !!! Prepare index the examples and maybe tasks
|
|
@@ -3759,11 +3807,19 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
3759
3807
|
case 3:
|
|
3760
3808
|
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
3761
3809
|
// ----- /Tasks preparation -----
|
|
3810
|
+
// TODO: [๐] Use here all `AsyncHighLevelAbstraction`
|
|
3762
3811
|
// Note: Count total usage
|
|
3763
3812
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3764
|
-
return [2 /*return*/,
|
|
3765
|
-
|
|
3766
|
-
|
|
3813
|
+
return [2 /*return*/, exportJson({
|
|
3814
|
+
name: 'pipelineJson',
|
|
3815
|
+
message: "Result of `preparePipeline`",
|
|
3816
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
3817
|
+
value: __assign(__assign({}, pipeline), {
|
|
3818
|
+
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
3819
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3820
|
+
// <- TODO: [๐ช] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3821
|
+
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
3822
|
+
})];
|
|
3767
3823
|
}
|
|
3768
3824
|
});
|
|
3769
3825
|
});
|
|
@@ -5323,16 +5379,21 @@ function executePipeline(options) {
|
|
|
5323
5379
|
// Note: Wait a short time to prevent race conditions
|
|
5324
5380
|
_g.sent();
|
|
5325
5381
|
_g.label = 6;
|
|
5326
|
-
case 6: return [2 /*return*/,
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5382
|
+
case 6: return [2 /*return*/, exportJson({
|
|
5383
|
+
name: "executionReport",
|
|
5384
|
+
message: "Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"),
|
|
5385
|
+
order: [],
|
|
5386
|
+
value: {
|
|
5387
|
+
isSuccessful: false,
|
|
5388
|
+
errors: __spreadArray([
|
|
5389
|
+
new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
|
|
5390
|
+
], __read(errors), false).map(serializeError),
|
|
5391
|
+
warnings: [],
|
|
5392
|
+
executionReport: executionReport,
|
|
5393
|
+
outputParameters: {},
|
|
5394
|
+
usage: ZERO_USAGE,
|
|
5395
|
+
preparedPipeline: preparedPipeline,
|
|
5396
|
+
},
|
|
5336
5397
|
})];
|
|
5337
5398
|
case 7:
|
|
5338
5399
|
_b = _a.next();
|
|
@@ -5371,16 +5432,21 @@ function executePipeline(options) {
|
|
|
5371
5432
|
// Note: Wait a short time to prevent race conditions
|
|
5372
5433
|
_h.sent();
|
|
5373
5434
|
_h.label = 3;
|
|
5374
|
-
case 3: return [2 /*return*/, { value:
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5435
|
+
case 3: return [2 /*return*/, { value: exportJson({
|
|
5436
|
+
name: 'pipelineExecutorResult',
|
|
5437
|
+
message: spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }),
|
|
5438
|
+
order: [],
|
|
5439
|
+
value: {
|
|
5440
|
+
isSuccessful: false,
|
|
5441
|
+
errors: __spreadArray([
|
|
5442
|
+
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
5443
|
+
], __read(errors), false).map(serializeError),
|
|
5444
|
+
warnings: warnings.map(serializeError),
|
|
5445
|
+
executionReport: executionReport,
|
|
5446
|
+
outputParameters: {},
|
|
5447
|
+
usage: ZERO_USAGE,
|
|
5448
|
+
preparedPipeline: preparedPipeline,
|
|
5449
|
+
},
|
|
5384
5450
|
}) }];
|
|
5385
5451
|
case 4: return [2 /*return*/];
|
|
5386
5452
|
}
|
|
@@ -5534,14 +5600,19 @@ function executePipeline(options) {
|
|
|
5534
5600
|
// Note: Wait a short time to prevent race conditions
|
|
5535
5601
|
_g.sent();
|
|
5536
5602
|
_g.label = 27;
|
|
5537
|
-
case 27: return [2 /*return*/,
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5603
|
+
case 27: return [2 /*return*/, exportJson({
|
|
5604
|
+
name: 'pipelineExecutorResult',
|
|
5605
|
+
message: "Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult",
|
|
5606
|
+
order: [],
|
|
5607
|
+
value: {
|
|
5608
|
+
isSuccessful: false,
|
|
5609
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
5610
|
+
warnings: warnings.map(serializeError),
|
|
5611
|
+
usage: usage_1,
|
|
5612
|
+
executionReport: executionReport,
|
|
5613
|
+
outputParameters: outputParameters_1,
|
|
5614
|
+
preparedPipeline: preparedPipeline,
|
|
5615
|
+
},
|
|
5545
5616
|
})];
|
|
5546
5617
|
case 28:
|
|
5547
5618
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
@@ -5562,14 +5633,19 @@ function executePipeline(options) {
|
|
|
5562
5633
|
// Note: Wait a short time to prevent race conditions
|
|
5563
5634
|
_g.sent();
|
|
5564
5635
|
_g.label = 30;
|
|
5565
|
-
case 30: return [2 /*return*/,
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5636
|
+
case 30: return [2 /*return*/, exportJson({
|
|
5637
|
+
name: 'pipelineExecutorResult',
|
|
5638
|
+
message: "Successful PipelineExecutorResult",
|
|
5639
|
+
order: [],
|
|
5640
|
+
value: {
|
|
5641
|
+
isSuccessful: true,
|
|
5642
|
+
errors: errors.map(serializeError),
|
|
5643
|
+
warnings: warnings.map(serializeError),
|
|
5644
|
+
usage: usage,
|
|
5645
|
+
executionReport: executionReport,
|
|
5646
|
+
outputParameters: outputParameters,
|
|
5647
|
+
preparedPipeline: preparedPipeline,
|
|
5648
|
+
},
|
|
5573
5649
|
})];
|
|
5574
5650
|
}
|
|
5575
5651
|
});
|
|
@@ -5693,7 +5769,7 @@ var markdownScraperMetadata = $deepFreeze({
|
|
|
5693
5769
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5694
5770
|
isAvilableInBrowser: true,
|
|
5695
5771
|
requiredExecutables: [],
|
|
5696
|
-
}); /* <-
|
|
5772
|
+
}); /* <- Note: [๐ค] */
|
|
5697
5773
|
/**
|
|
5698
5774
|
* Registration of known scraper metadata
|
|
5699
5775
|
*
|
|
@@ -5884,7 +5960,7 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
5884
5960
|
*/
|
|
5885
5961
|
var createMarkdownScraper = Object.assign(function (tools, options) {
|
|
5886
5962
|
return new MarkdownScraper(tools, options);
|
|
5887
|
-
}, markdownScraperMetadata); /* <-
|
|
5963
|
+
}, markdownScraperMetadata); /* <- Note: [๐ค] */
|
|
5888
5964
|
/**
|
|
5889
5965
|
* TODO: [๐ถ] Naming "constructor" vs "creator" vs "factory"
|
|
5890
5966
|
*/
|