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