@promptbook/pdf 0.78.4 → 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 +424 -345
- 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 +5 -2
- 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/formfactors/generator/GeneratorFormfactorDefinition.d.ts +6 -1
- package/esm/typings/src/formfactors/index.d.ts +12 -2
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +6 -1
- 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 +2 -2
- package/umd/index.umd.js +424 -345
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
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.79.0';
|
|
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
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
function TODO_USE() {
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
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"]}],
|
|
179
|
+
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"}];
|
|
180
180
|
|
|
181
181
|
/**
|
|
182
182
|
* Prettify the html code
|
|
@@ -224,6 +224,7 @@
|
|
|
224
224
|
/**
|
|
225
225
|
* Converts promptbook in JSON format to string format
|
|
226
226
|
*
|
|
227
|
+
* @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
|
|
227
228
|
* @param pipelineJson Promptbook in JSON format (.book.json)
|
|
228
229
|
* @returns Promptbook in string format (.book.md)
|
|
229
230
|
* @public exported from `@promptbook/core`
|
|
@@ -507,78 +508,368 @@
|
|
|
507
508
|
* @public exported from `@promptbook/core`
|
|
508
509
|
*/
|
|
509
510
|
var DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
511
|
+
// <- TODO: [🧜♂️]
|
|
510
512
|
/**
|
|
511
|
-
*
|
|
513
|
+
* @@@
|
|
512
514
|
*
|
|
513
|
-
* @
|
|
515
|
+
* @public exported from `@promptbook/core`
|
|
514
516
|
*/
|
|
515
|
-
var
|
|
517
|
+
var DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
518
|
+
delimiter: ',',
|
|
519
|
+
quoteChar: '"',
|
|
520
|
+
newline: '\n',
|
|
521
|
+
skipEmptyLines: true,
|
|
522
|
+
});
|
|
516
523
|
/**
|
|
517
|
-
*
|
|
524
|
+
* @@@
|
|
518
525
|
*
|
|
519
526
|
* @public exported from `@promptbook/core`
|
|
520
527
|
*/
|
|
521
|
-
var
|
|
522
|
-
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
523
|
-
'content',
|
|
524
|
-
'context',
|
|
525
|
-
'knowledge',
|
|
526
|
-
'examples',
|
|
527
|
-
'modelName',
|
|
528
|
-
'currentDate',
|
|
529
|
-
// <- TODO: list here all command names
|
|
530
|
-
// <- TODO: Add more like 'date', 'modelName',...
|
|
531
|
-
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
532
|
-
];
|
|
528
|
+
var DEFAULT_IS_VERBOSE = false;
|
|
533
529
|
/**
|
|
534
530
|
* @@@
|
|
535
531
|
*
|
|
536
|
-
* @
|
|
532
|
+
* @public exported from `@promptbook/core`
|
|
537
533
|
*/
|
|
538
|
-
var
|
|
534
|
+
var DEFAULT_IS_AUTO_INSTALLED = false;
|
|
539
535
|
/**
|
|
540
536
|
* @@@
|
|
541
537
|
*
|
|
542
538
|
* @private within the repository
|
|
543
539
|
*/
|
|
544
|
-
var
|
|
545
|
-
|
|
540
|
+
var IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
541
|
+
/**/
|
|
542
|
+
// Note: In normal situations, we check the pipeline logic:
|
|
543
|
+
true);
|
|
546
544
|
/**
|
|
547
|
-
*
|
|
545
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
546
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Orders JSON object by keys
|
|
551
|
+
*
|
|
552
|
+
* @returns The same type of object as the input re-ordered
|
|
553
|
+
* @public exported from `@promptbook/utils`
|
|
554
|
+
*/
|
|
555
|
+
function orderJson(options) {
|
|
556
|
+
var value = options.value, order = options.order;
|
|
557
|
+
var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
|
|
558
|
+
return orderedValue;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Freezes the given object and all its nested objects recursively
|
|
563
|
+
*
|
|
564
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
565
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
566
|
+
*
|
|
567
|
+
* @returns The same object as the input, but deeply frozen
|
|
568
|
+
* @public exported from `@promptbook/utils`
|
|
569
|
+
*/
|
|
570
|
+
function $deepFreeze(objectValue) {
|
|
571
|
+
var e_1, _a;
|
|
572
|
+
if (Array.isArray(objectValue)) {
|
|
573
|
+
return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
|
|
574
|
+
}
|
|
575
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
576
|
+
try {
|
|
577
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
578
|
+
var propertyName = propertyNames_1_1.value;
|
|
579
|
+
var value = objectValue[propertyName];
|
|
580
|
+
if (value && typeof value === 'object') {
|
|
581
|
+
$deepFreeze(value);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
586
|
+
finally {
|
|
587
|
+
try {
|
|
588
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
589
|
+
}
|
|
590
|
+
finally { if (e_1) throw e_1.error; }
|
|
591
|
+
}
|
|
592
|
+
Object.freeze(objectValue);
|
|
593
|
+
return objectValue;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
597
|
+
*/
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Make error report URL for the given error
|
|
601
|
+
*
|
|
602
|
+
* @private !!!!!!
|
|
603
|
+
*/
|
|
604
|
+
function getErrorReportUrl(error) {
|
|
605
|
+
var report = {
|
|
606
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
607
|
+
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 "); }),
|
|
608
|
+
};
|
|
609
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
610
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
611
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
612
|
+
reportUrl.searchParams.set('title', report.title);
|
|
613
|
+
reportUrl.searchParams.set('body', report.body);
|
|
614
|
+
return reportUrl;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
548
619
|
*
|
|
549
620
|
* @public exported from `@promptbook/core`
|
|
550
621
|
*/
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
622
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
623
|
+
__extends(UnexpectedError, _super);
|
|
624
|
+
function UnexpectedError(message) {
|
|
625
|
+
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;
|
|
626
|
+
_this.name = 'UnexpectedError';
|
|
627
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
628
|
+
return _this;
|
|
629
|
+
}
|
|
630
|
+
return UnexpectedError;
|
|
631
|
+
}(Error));
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
635
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
636
|
+
*
|
|
637
|
+
* - Almost all primitives are serializable BUT:
|
|
638
|
+
* - `undefined` is not serializable
|
|
639
|
+
* - `NaN` is not serializable
|
|
640
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
641
|
+
* - Functions are not serializable
|
|
642
|
+
* - Circular references are not serializable
|
|
643
|
+
* - `Date` objects are not serializable
|
|
644
|
+
* - `Map` and `Set` objects are not serializable
|
|
645
|
+
* - `RegExp` objects are not serializable
|
|
646
|
+
* - `Error` objects are not serializable
|
|
647
|
+
* - `Symbol` objects are not serializable
|
|
648
|
+
* - And much more...
|
|
649
|
+
*
|
|
650
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
651
|
+
* @public exported from `@promptbook/utils`
|
|
652
|
+
*/
|
|
653
|
+
function checkSerializableAsJson(options) {
|
|
654
|
+
var e_1, _a;
|
|
655
|
+
var value = options.value, name = options.name, message = options.message;
|
|
656
|
+
if (value === undefined) {
|
|
657
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
658
|
+
}
|
|
659
|
+
else if (value === null) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
else if (typeof value === 'boolean') {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
else if (typeof value === 'string') {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
else if (typeof value === 'symbol') {
|
|
672
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
673
|
+
}
|
|
674
|
+
else if (typeof value === 'function') {
|
|
675
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
676
|
+
}
|
|
677
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
678
|
+
for (var i = 0; i < value.length; i++) {
|
|
679
|
+
checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
else if (typeof value === 'object') {
|
|
683
|
+
if (value instanceof Date) {
|
|
684
|
+
throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
|
|
685
|
+
}
|
|
686
|
+
else if (value instanceof Map) {
|
|
687
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
688
|
+
}
|
|
689
|
+
else if (value instanceof Set) {
|
|
690
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
691
|
+
}
|
|
692
|
+
else if (value instanceof RegExp) {
|
|
693
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
694
|
+
}
|
|
695
|
+
else if (value instanceof Error) {
|
|
696
|
+
throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
try {
|
|
700
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
701
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
702
|
+
if (subValue === undefined) {
|
|
703
|
+
// Note: undefined in object is serializable - it is just omited
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
710
|
+
finally {
|
|
711
|
+
try {
|
|
712
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
713
|
+
}
|
|
714
|
+
finally { if (e_1) throw e_1.error; }
|
|
715
|
+
}
|
|
716
|
+
try {
|
|
717
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
718
|
+
}
|
|
719
|
+
catch (error) {
|
|
720
|
+
if (!(error instanceof Error)) {
|
|
721
|
+
throw error;
|
|
722
|
+
}
|
|
723
|
+
throw new UnexpectedError(spaceTrim__default["default"](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 "); }));
|
|
724
|
+
}
|
|
725
|
+
/*
|
|
726
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
727
|
+
const seen = new Set();
|
|
728
|
+
const stack = [{ value }];
|
|
729
|
+
while (stack.length > 0) {
|
|
730
|
+
const { value } = stack.pop()!;
|
|
731
|
+
if (typeof value === 'object' && value !== null) {
|
|
732
|
+
if (seen.has(value)) {
|
|
733
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
734
|
+
}
|
|
735
|
+
seen.add(value);
|
|
736
|
+
if (Array.isArray(value)) {
|
|
737
|
+
stack.push(...value.map((value) => ({ value })));
|
|
738
|
+
} else {
|
|
739
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
*/
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
753
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
754
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
755
|
+
*/
|
|
756
|
+
|
|
557
757
|
/**
|
|
558
758
|
* @@@
|
|
559
759
|
*
|
|
760
|
+
* @public exported from `@promptbook/utils`
|
|
761
|
+
*/
|
|
762
|
+
function deepClone(objectValue) {
|
|
763
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
764
|
+
/*
|
|
765
|
+
!!!!!!!!
|
|
766
|
+
TODO: [🧠] Is there a better implementation?
|
|
767
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
768
|
+
> for (const propertyName of propertyNames) {
|
|
769
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
770
|
+
> if (value && typeof value === 'object') {
|
|
771
|
+
> deepClone(value);
|
|
772
|
+
> }
|
|
773
|
+
> }
|
|
774
|
+
> return Object.assign({}, objectValue);
|
|
775
|
+
*/
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
779
|
+
*/
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Utility to export a JSON object from a function
|
|
783
|
+
*
|
|
784
|
+
* 1) Checks if the value is serializable as JSON
|
|
785
|
+
* 2) Makes a deep clone of the object
|
|
786
|
+
* 2) Orders the object properties
|
|
787
|
+
* 2) Deeply freezes the cloned object
|
|
788
|
+
*
|
|
789
|
+
* Note: This function does not mutates the given object
|
|
790
|
+
*
|
|
791
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
792
|
+
* @public exported from `@promptbook/utils`
|
|
793
|
+
*/
|
|
794
|
+
function exportJson(options) {
|
|
795
|
+
var name = options.name, value = options.value, order = options.order, message = options.message;
|
|
796
|
+
checkSerializableAsJson({ name: name, value: value, message: message });
|
|
797
|
+
var orderedValue =
|
|
798
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
799
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
800
|
+
// @ts-ignore
|
|
801
|
+
order === undefined
|
|
802
|
+
? deepClone(value)
|
|
803
|
+
: orderJson({
|
|
804
|
+
value: value,
|
|
805
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
806
|
+
order: order,
|
|
807
|
+
});
|
|
808
|
+
$deepFreeze(orderedValue);
|
|
809
|
+
return orderedValue;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Order of keys in the pipeline JSON
|
|
817
|
+
*
|
|
560
818
|
* @public exported from `@promptbook/core`
|
|
561
819
|
*/
|
|
562
|
-
var
|
|
820
|
+
var ORDER_OF_PIPELINE_JSON = [
|
|
821
|
+
'title',
|
|
822
|
+
'pipelineUrl',
|
|
823
|
+
'bookVersion',
|
|
824
|
+
'description',
|
|
825
|
+
'formfactorName',
|
|
826
|
+
'parameters',
|
|
827
|
+
'tasks',
|
|
828
|
+
'personas',
|
|
829
|
+
'preparations',
|
|
830
|
+
'knowledgeSources',
|
|
831
|
+
'knowledgePieces',
|
|
832
|
+
];
|
|
833
|
+
/**
|
|
834
|
+
* Nonce which is used for replacing things in strings
|
|
835
|
+
*
|
|
836
|
+
* @private within the repository
|
|
837
|
+
*/
|
|
838
|
+
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
563
839
|
/**
|
|
564
840
|
* @@@
|
|
565
841
|
*
|
|
566
|
-
* @
|
|
842
|
+
* @private within the repository
|
|
567
843
|
*/
|
|
568
|
-
var
|
|
844
|
+
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
569
845
|
/**
|
|
570
846
|
* @@@
|
|
571
847
|
*
|
|
572
848
|
* @private within the repository
|
|
573
849
|
*/
|
|
574
|
-
var
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
850
|
+
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
851
|
+
/**
|
|
852
|
+
* The names of the parameters that are reserved for special purposes
|
|
853
|
+
*
|
|
854
|
+
* @public exported from `@promptbook/core`
|
|
855
|
+
*/
|
|
856
|
+
var RESERVED_PARAMETER_NAMES = exportJson({
|
|
857
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
858
|
+
message: "The names of the parameters that are reserved for special purposes",
|
|
859
|
+
value: [
|
|
860
|
+
'content',
|
|
861
|
+
'context',
|
|
862
|
+
'knowledge',
|
|
863
|
+
'examples',
|
|
864
|
+
'modelName',
|
|
865
|
+
'currentDate',
|
|
866
|
+
// <- TODO: list here all command names
|
|
867
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
868
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
869
|
+
],
|
|
870
|
+
});
|
|
578
871
|
/**
|
|
579
|
-
* TODO: Extract `constants.ts` from `config.ts`
|
|
580
872
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
581
|
-
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
582
873
|
*/
|
|
583
874
|
|
|
584
875
|
/**
|
|
@@ -616,40 +907,6 @@
|
|
|
616
907
|
return PipelineLogicError;
|
|
617
908
|
}(Error));
|
|
618
909
|
|
|
619
|
-
/**
|
|
620
|
-
* Make error report URL for the given error
|
|
621
|
-
*
|
|
622
|
-
* @private !!!!!!
|
|
623
|
-
*/
|
|
624
|
-
function getErrorReportUrl(error) {
|
|
625
|
-
var report = {
|
|
626
|
-
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
627
|
-
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 "); }),
|
|
628
|
-
};
|
|
629
|
-
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
630
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
631
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
632
|
-
reportUrl.searchParams.set('title', report.title);
|
|
633
|
-
reportUrl.searchParams.set('body', report.body);
|
|
634
|
-
return reportUrl;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
639
|
-
*
|
|
640
|
-
* @public exported from `@promptbook/core`
|
|
641
|
-
*/
|
|
642
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
643
|
-
__extends(UnexpectedError, _super);
|
|
644
|
-
function UnexpectedError(message) {
|
|
645
|
-
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;
|
|
646
|
-
_this.name = 'UnexpectedError';
|
|
647
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
648
|
-
return _this;
|
|
649
|
-
}
|
|
650
|
-
return UnexpectedError;
|
|
651
|
-
}(Error));
|
|
652
|
-
|
|
653
910
|
/**
|
|
654
911
|
* Tests if given string is valid semantic version
|
|
655
912
|
*
|
|
@@ -887,6 +1144,21 @@
|
|
|
887
1144
|
}
|
|
888
1145
|
};
|
|
889
1146
|
try {
|
|
1147
|
+
/*
|
|
1148
|
+
TODO: [🧠][🅾] Should be empty pipeline valid or not
|
|
1149
|
+
// Note: Check that pipeline has some tasks
|
|
1150
|
+
if (pipeline.tasks.length === 0) {
|
|
1151
|
+
throw new PipelineLogicError(
|
|
1152
|
+
spaceTrim(
|
|
1153
|
+
(block) => `
|
|
1154
|
+
Pipeline must have at least one task
|
|
1155
|
+
|
|
1156
|
+
${block(pipelineIdentification)}
|
|
1157
|
+
`,
|
|
1158
|
+
),
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
*/
|
|
890
1162
|
// Note: Check each parameter individually
|
|
891
1163
|
for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
892
1164
|
var parameter = _e.value;
|
|
@@ -1047,6 +1319,9 @@
|
|
|
1047
1319
|
while (unresovedTasks.length > 0) {
|
|
1048
1320
|
_loop_3();
|
|
1049
1321
|
}
|
|
1322
|
+
// Note: Check that formfactor is corresponding to the pipeline interface
|
|
1323
|
+
// TODO: !!!!!! Implement this
|
|
1324
|
+
// pipeline.formfactorName
|
|
1050
1325
|
}
|
|
1051
1326
|
/**
|
|
1052
1327
|
* TODO: !! [🧞♀️] Do not allow joker + foreach
|
|
@@ -1130,183 +1405,6 @@
|
|
|
1130
1405
|
return parameterNames;
|
|
1131
1406
|
}
|
|
1132
1407
|
|
|
1133
|
-
/**
|
|
1134
|
-
* @@@
|
|
1135
|
-
*
|
|
1136
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1137
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1138
|
-
*
|
|
1139
|
-
* @returns The same object as the input, but deeply frozen
|
|
1140
|
-
* @public exported from `@promptbook/utils`
|
|
1141
|
-
*/
|
|
1142
|
-
function $deepFreeze(objectValue) {
|
|
1143
|
-
var e_1, _a;
|
|
1144
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1145
|
-
try {
|
|
1146
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1147
|
-
var propertyName = propertyNames_1_1.value;
|
|
1148
|
-
var value = objectValue[propertyName];
|
|
1149
|
-
if (value && typeof value === 'object') {
|
|
1150
|
-
$deepFreeze(value);
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1155
|
-
finally {
|
|
1156
|
-
try {
|
|
1157
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1158
|
-
}
|
|
1159
|
-
finally { if (e_1) throw e_1.error; }
|
|
1160
|
-
}
|
|
1161
|
-
return Object.freeze(objectValue);
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1165
|
-
*/
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
* Checks if the value is [🚉] serializable as JSON
|
|
1169
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1170
|
-
*
|
|
1171
|
-
* - Almost all primitives are serializable BUT:
|
|
1172
|
-
* - `undefined` is not serializable
|
|
1173
|
-
* - `NaN` is not serializable
|
|
1174
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
1175
|
-
* - Functions are not serializable
|
|
1176
|
-
* - Circular references are not serializable
|
|
1177
|
-
* - `Date` objects are not serializable
|
|
1178
|
-
* - `Map` and `Set` objects are not serializable
|
|
1179
|
-
* - `RegExp` objects are not serializable
|
|
1180
|
-
* - `Error` objects are not serializable
|
|
1181
|
-
* - `Symbol` objects are not serializable
|
|
1182
|
-
* - And much more...
|
|
1183
|
-
*
|
|
1184
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1185
|
-
* @public exported from `@promptbook/utils`
|
|
1186
|
-
*/
|
|
1187
|
-
function checkSerializableAsJson(name, value) {
|
|
1188
|
-
var e_1, _a;
|
|
1189
|
-
if (value === undefined) {
|
|
1190
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1191
|
-
}
|
|
1192
|
-
else if (value === null) {
|
|
1193
|
-
return;
|
|
1194
|
-
}
|
|
1195
|
-
else if (typeof value === 'boolean') {
|
|
1196
|
-
return;
|
|
1197
|
-
}
|
|
1198
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
else if (typeof value === 'string') {
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
else if (typeof value === 'symbol') {
|
|
1205
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1206
|
-
}
|
|
1207
|
-
else if (typeof value === 'function') {
|
|
1208
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
1209
|
-
}
|
|
1210
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1211
|
-
for (var i = 0; i < value.length; i++) {
|
|
1212
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
else if (typeof value === 'object') {
|
|
1216
|
-
if (value instanceof Date) {
|
|
1217
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1218
|
-
}
|
|
1219
|
-
else if (value instanceof Map) {
|
|
1220
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1221
|
-
}
|
|
1222
|
-
else if (value instanceof Set) {
|
|
1223
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1224
|
-
}
|
|
1225
|
-
else if (value instanceof RegExp) {
|
|
1226
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1227
|
-
}
|
|
1228
|
-
else if (value instanceof Error) {
|
|
1229
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
try {
|
|
1233
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1234
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1235
|
-
if (subValue === undefined) {
|
|
1236
|
-
// Note: undefined in object is serializable - it is just omited
|
|
1237
|
-
continue;
|
|
1238
|
-
}
|
|
1239
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1243
|
-
finally {
|
|
1244
|
-
try {
|
|
1245
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1246
|
-
}
|
|
1247
|
-
finally { if (e_1) throw e_1.error; }
|
|
1248
|
-
}
|
|
1249
|
-
try {
|
|
1250
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
1251
|
-
}
|
|
1252
|
-
catch (error) {
|
|
1253
|
-
if (!(error instanceof Error)) {
|
|
1254
|
-
throw error;
|
|
1255
|
-
}
|
|
1256
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1257
|
-
}
|
|
1258
|
-
/*
|
|
1259
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
1260
|
-
const seen = new Set();
|
|
1261
|
-
const stack = [{ value }];
|
|
1262
|
-
while (stack.length > 0) {
|
|
1263
|
-
const { value } = stack.pop()!;
|
|
1264
|
-
if (typeof value === 'object' && value !== null) {
|
|
1265
|
-
if (seen.has(value)) {
|
|
1266
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
1267
|
-
}
|
|
1268
|
-
seen.add(value);
|
|
1269
|
-
if (Array.isArray(value)) {
|
|
1270
|
-
stack.push(...value.map((value) => ({ value })));
|
|
1271
|
-
} else {
|
|
1272
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
*/
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
else {
|
|
1281
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1286
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1287
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1288
|
-
*/
|
|
1289
|
-
|
|
1290
|
-
/**
|
|
1291
|
-
* @@@
|
|
1292
|
-
* @@@
|
|
1293
|
-
*
|
|
1294
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1295
|
-
*
|
|
1296
|
-
* @param name - Name of the object for debugging purposes
|
|
1297
|
-
* @param objectValue - Object to be deeply frozen
|
|
1298
|
-
* @returns The same object as the input, but deeply frozen
|
|
1299
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1300
|
-
*/
|
|
1301
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1302
|
-
checkSerializableAsJson(name, objectValue);
|
|
1303
|
-
return $deepFreeze(objectValue);
|
|
1304
|
-
}
|
|
1305
|
-
/**
|
|
1306
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1307
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1308
|
-
*/
|
|
1309
|
-
|
|
1310
1408
|
/**
|
|
1311
1409
|
* Unprepare just strips the preparation data of the pipeline
|
|
1312
1410
|
*
|
|
@@ -1324,7 +1422,12 @@
|
|
|
1324
1422
|
delete taskUnprepared.preparedContent;
|
|
1325
1423
|
return taskUnprepared;
|
|
1326
1424
|
});
|
|
1327
|
-
return
|
|
1425
|
+
return exportJson({
|
|
1426
|
+
name: 'pipelineJson',
|
|
1427
|
+
message: "Result of `unpreparePipeline`",
|
|
1428
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
1429
|
+
value: __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }),
|
|
1430
|
+
});
|
|
1328
1431
|
}
|
|
1329
1432
|
/**
|
|
1330
1433
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1870,29 +1973,6 @@
|
|
|
1870
1973
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1871
1974
|
*/
|
|
1872
1975
|
|
|
1873
|
-
/**
|
|
1874
|
-
* @@@
|
|
1875
|
-
*
|
|
1876
|
-
* @public exported from `@promptbook/utils`
|
|
1877
|
-
*/
|
|
1878
|
-
function deepClone(objectValue) {
|
|
1879
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
1880
|
-
/*
|
|
1881
|
-
TODO: [🧠] Is there a better implementation?
|
|
1882
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1883
|
-
> for (const propertyName of propertyNames) {
|
|
1884
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
1885
|
-
> if (value && typeof value === 'object') {
|
|
1886
|
-
> deepClone(value);
|
|
1887
|
-
> }
|
|
1888
|
-
> }
|
|
1889
|
-
> return Object.assign({}, objectValue);
|
|
1890
|
-
*/
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1894
|
-
*/
|
|
1895
|
-
|
|
1896
1976
|
/**
|
|
1897
1977
|
* Function `addUsage` will add multiple usages into one
|
|
1898
1978
|
*
|
|
@@ -3418,36 +3498,6 @@
|
|
|
3418
3498
|
* [ ] One piece can have multiple sources
|
|
3419
3499
|
*/
|
|
3420
3500
|
|
|
3421
|
-
/**
|
|
3422
|
-
* @@@
|
|
3423
|
-
*
|
|
3424
|
-
* Note: It is usefull @@@
|
|
3425
|
-
*
|
|
3426
|
-
* @param pipeline
|
|
3427
|
-
* @public exported from `@promptbook/utils`
|
|
3428
|
-
*/
|
|
3429
|
-
function clonePipeline(pipeline) {
|
|
3430
|
-
// Note: Not using spread operator (...) because @@@
|
|
3431
|
-
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;
|
|
3432
|
-
return {
|
|
3433
|
-
pipelineUrl: pipelineUrl,
|
|
3434
|
-
sourceFile: sourceFile,
|
|
3435
|
-
title: title,
|
|
3436
|
-
bookVersion: bookVersion,
|
|
3437
|
-
description: description,
|
|
3438
|
-
formfactorName: formfactorName,
|
|
3439
|
-
parameters: parameters,
|
|
3440
|
-
tasks: tasks,
|
|
3441
|
-
knowledgeSources: knowledgeSources,
|
|
3442
|
-
knowledgePieces: knowledgePieces,
|
|
3443
|
-
personas: personas,
|
|
3444
|
-
preparations: preparations,
|
|
3445
|
-
};
|
|
3446
|
-
}
|
|
3447
|
-
/**
|
|
3448
|
-
* TODO: [🍙] Make some standard order of json properties
|
|
3449
|
-
*/
|
|
3450
|
-
|
|
3451
3501
|
/**
|
|
3452
3502
|
* @@@
|
|
3453
3503
|
*
|
|
@@ -3488,6 +3538,7 @@
|
|
|
3488
3538
|
});
|
|
3489
3539
|
}
|
|
3490
3540
|
/**
|
|
3541
|
+
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
3491
3542
|
* TODO: [🧠] Add context to each task (if missing)
|
|
3492
3543
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
3493
3544
|
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
@@ -3576,11 +3627,19 @@
|
|
|
3576
3627
|
case 3:
|
|
3577
3628
|
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
3578
3629
|
// ----- /Tasks preparation -----
|
|
3630
|
+
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
3579
3631
|
// Note: Count total usage
|
|
3580
3632
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3581
|
-
return [2 /*return*/,
|
|
3582
|
-
|
|
3583
|
-
|
|
3633
|
+
return [2 /*return*/, exportJson({
|
|
3634
|
+
name: 'pipelineJson',
|
|
3635
|
+
message: "Result of `preparePipeline`",
|
|
3636
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
3637
|
+
value: __assign(__assign({}, pipeline), {
|
|
3638
|
+
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
3639
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
3640
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
3641
|
+
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
3642
|
+
})];
|
|
3584
3643
|
}
|
|
3585
3644
|
});
|
|
3586
3645
|
});
|
|
@@ -5277,16 +5336,21 @@
|
|
|
5277
5336
|
// Note: Wait a short time to prevent race conditions
|
|
5278
5337
|
_g.sent();
|
|
5279
5338
|
_g.label = 6;
|
|
5280
|
-
case 6: return [2 /*return*/,
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5339
|
+
case 6: return [2 /*return*/, exportJson({
|
|
5340
|
+
name: "executionReport",
|
|
5341
|
+
message: "Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"),
|
|
5342
|
+
order: [],
|
|
5343
|
+
value: {
|
|
5344
|
+
isSuccessful: false,
|
|
5345
|
+
errors: __spreadArray([
|
|
5346
|
+
new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
|
|
5347
|
+
], __read(errors), false).map(serializeError),
|
|
5348
|
+
warnings: [],
|
|
5349
|
+
executionReport: executionReport,
|
|
5350
|
+
outputParameters: {},
|
|
5351
|
+
usage: ZERO_USAGE,
|
|
5352
|
+
preparedPipeline: preparedPipeline,
|
|
5353
|
+
},
|
|
5290
5354
|
})];
|
|
5291
5355
|
case 7:
|
|
5292
5356
|
_b = _a.next();
|
|
@@ -5325,16 +5389,21 @@
|
|
|
5325
5389
|
// Note: Wait a short time to prevent race conditions
|
|
5326
5390
|
_h.sent();
|
|
5327
5391
|
_h.label = 3;
|
|
5328
|
-
case 3: return [2 /*return*/, { value:
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5392
|
+
case 3: return [2 /*return*/, { value: exportJson({
|
|
5393
|
+
name: 'pipelineExecutorResult',
|
|
5394
|
+
message: spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }),
|
|
5395
|
+
order: [],
|
|
5396
|
+
value: {
|
|
5397
|
+
isSuccessful: false,
|
|
5398
|
+
errors: __spreadArray([
|
|
5399
|
+
new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
5400
|
+
], __read(errors), false).map(serializeError),
|
|
5401
|
+
warnings: warnings.map(serializeError),
|
|
5402
|
+
executionReport: executionReport,
|
|
5403
|
+
outputParameters: {},
|
|
5404
|
+
usage: ZERO_USAGE,
|
|
5405
|
+
preparedPipeline: preparedPipeline,
|
|
5406
|
+
},
|
|
5338
5407
|
}) }];
|
|
5339
5408
|
case 4: return [2 /*return*/];
|
|
5340
5409
|
}
|
|
@@ -5488,14 +5557,19 @@
|
|
|
5488
5557
|
// Note: Wait a short time to prevent race conditions
|
|
5489
5558
|
_g.sent();
|
|
5490
5559
|
_g.label = 27;
|
|
5491
|
-
case 27: return [2 /*return*/,
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5560
|
+
case 27: return [2 /*return*/, exportJson({
|
|
5561
|
+
name: 'pipelineExecutorResult',
|
|
5562
|
+
message: "Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult",
|
|
5563
|
+
order: [],
|
|
5564
|
+
value: {
|
|
5565
|
+
isSuccessful: false,
|
|
5566
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
5567
|
+
warnings: warnings.map(serializeError),
|
|
5568
|
+
usage: usage_1,
|
|
5569
|
+
executionReport: executionReport,
|
|
5570
|
+
outputParameters: outputParameters_1,
|
|
5571
|
+
preparedPipeline: preparedPipeline,
|
|
5572
|
+
},
|
|
5499
5573
|
})];
|
|
5500
5574
|
case 28:
|
|
5501
5575
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
@@ -5516,14 +5590,19 @@
|
|
|
5516
5590
|
// Note: Wait a short time to prevent race conditions
|
|
5517
5591
|
_g.sent();
|
|
5518
5592
|
_g.label = 30;
|
|
5519
|
-
case 30: return [2 /*return*/,
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5593
|
+
case 30: return [2 /*return*/, exportJson({
|
|
5594
|
+
name: 'pipelineExecutorResult',
|
|
5595
|
+
message: "Successful PipelineExecutorResult",
|
|
5596
|
+
order: [],
|
|
5597
|
+
value: {
|
|
5598
|
+
isSuccessful: true,
|
|
5599
|
+
errors: errors.map(serializeError),
|
|
5600
|
+
warnings: warnings.map(serializeError),
|
|
5601
|
+
usage: usage,
|
|
5602
|
+
executionReport: executionReport,
|
|
5603
|
+
outputParameters: outputParameters,
|
|
5604
|
+
preparedPipeline: preparedPipeline,
|
|
5605
|
+
},
|
|
5527
5606
|
})];
|
|
5528
5607
|
}
|
|
5529
5608
|
});
|
|
@@ -5647,7 +5726,7 @@
|
|
|
5647
5726
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5648
5727
|
isAvilableInBrowser: true,
|
|
5649
5728
|
requiredExecutables: [],
|
|
5650
|
-
}); /* <-
|
|
5729
|
+
}); /* <- Note: [🤛] */
|
|
5651
5730
|
/**
|
|
5652
5731
|
* Registration of known scraper metadata
|
|
5653
5732
|
*
|
|
@@ -5844,7 +5923,7 @@
|
|
|
5844
5923
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
5845
5924
|
isAvilableInBrowser: true,
|
|
5846
5925
|
requiredExecutables: [],
|
|
5847
|
-
}); /* <-
|
|
5926
|
+
}); /* <- Note: [🤛] */
|
|
5848
5927
|
/**
|
|
5849
5928
|
* Registration of known scraper metadata
|
|
5850
5929
|
*
|
|
@@ -5924,7 +6003,7 @@
|
|
|
5924
6003
|
*/
|
|
5925
6004
|
var createPdfScraper = Object.assign(function (tools, options) {
|
|
5926
6005
|
return new PdfScraper(tools, options);
|
|
5927
|
-
}, pdfScraperMetadata); /* <-
|
|
6006
|
+
}, pdfScraperMetadata); /* <- Note: [🤛] */
|
|
5928
6007
|
/**
|
|
5929
6008
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
5930
6009
|
*/
|