@promptbook/node 0.69.0-7 β†’ 0.69.0-8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -14,7 +14,7 @@ import * as dotenv from 'dotenv';
14
14
  /**
15
15
  * The version of the Promptbook library
16
16
  */
17
- var PROMPTBOOK_VERSION = '0.69.0-6';
17
+ var PROMPTBOOK_VERSION = '0.69.0-7';
18
18
  // TODO: !!!! List here all the versions and annotate + put into script
19
19
 
20
20
  /*! *****************************************************************************
@@ -367,13 +367,13 @@ var IMMEDIATE_TIME = 10;
367
367
  *
368
368
  * @public exported from `@promptbook/core`
369
369
  */
370
- var MAX_PARALLEL_COUNT = 5;
370
+ var MAX_PARALLEL_COUNT = 5; // <- TODO: [πŸ€Ήβ€β™‚οΈ]
371
371
  /**
372
372
  * The maximum number of attempts to execute LLM task before giving up
373
373
  *
374
374
  * @public exported from `@promptbook/core`
375
375
  */
376
- var MAX_EXECUTION_ATTEMPTS = 3;
376
+ var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [πŸ€Ήβ€β™‚οΈ]
377
377
  /**
378
378
  * The maximum length of the (generated) filename
379
379
  *
@@ -884,7 +884,7 @@ function forEachAsync(array, options, callbackfunction) {
884
884
  });
885
885
  }
886
886
 
887
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.69.0-6",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
887
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-7",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.69.0-7",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.69.0-7",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.69.0-7",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
888
888
 
889
889
  /**
890
890
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -2079,6 +2079,23 @@ function isPipelinePrepared(pipeline) {
2079
2079
  * - [♨] Are templates prepared
2080
2080
  */
2081
2081
 
2082
+ /**
2083
+ * Serializes an error into a [πŸš‰] JSON-serializable object
2084
+ *
2085
+ * @public exported from `@promptbook/utils`
2086
+ */
2087
+ function serializeError(error) {
2088
+ var name = error.name, message = error.message, stack = error.stack;
2089
+ if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2090
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2091
+ }
2092
+ return {
2093
+ name: name,
2094
+ message: message,
2095
+ stack: stack,
2096
+ };
2097
+ }
2098
+
2082
2099
  /**
2083
2100
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2084
2101
  *
@@ -2372,23 +2389,6 @@ function joinLlmExecutionTools() {
2372
2389
  * TODO: [πŸ‘·β€β™‚οΈ] @@@ Manual about construction of llmTools
2373
2390
  */
2374
2391
 
2375
- /**
2376
- * Serializes an error into a [πŸš‰] JSON-serializable object
2377
- *
2378
- * @public exported from `@promptbook/utils`
2379
- */
2380
- function serializeError(error) {
2381
- var name = error.name, message = error.message, stack = error.stack;
2382
- if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2383
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2384
- }
2385
- return {
2386
- name: name,
2387
- message: message,
2388
- stack: stack,
2389
- };
2390
- }
2391
-
2392
2392
  /**
2393
2393
  * Takes an item or an array of items and returns an array of items
2394
2394
  *
@@ -2526,6 +2526,81 @@ function extractParameterNamesFromTemplate(template) {
2526
2526
  * TODO: [πŸ”£] If script require contentLanguage
2527
2527
  */
2528
2528
 
2529
+ /**
2530
+ * Create difference set of two sets.
2531
+ *
2532
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2533
+ * @public exported from `@promptbook/utils`
2534
+ */
2535
+ function difference(a, b, isEqual) {
2536
+ var e_1, _a;
2537
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2538
+ var diff = new Set();
2539
+ var _loop_1 = function (itemA) {
2540
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2541
+ diff.add(itemA);
2542
+ }
2543
+ };
2544
+ try {
2545
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2546
+ var itemA = _c.value;
2547
+ _loop_1(itemA);
2548
+ }
2549
+ }
2550
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2551
+ finally {
2552
+ try {
2553
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2554
+ }
2555
+ finally { if (e_1) throw e_1.error; }
2556
+ }
2557
+ return diff;
2558
+ }
2559
+ /**
2560
+ * TODO: [🧠][πŸ’―] Maybe also implement symmetricDifference
2561
+ */
2562
+
2563
+ /**
2564
+ * Creates a new set with all elements that are present in either set
2565
+ *
2566
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2567
+ * @public exported from `@promptbook/utils`
2568
+ */
2569
+ function union() {
2570
+ var e_1, _a, e_2, _b;
2571
+ var sets = [];
2572
+ for (var _i = 0; _i < arguments.length; _i++) {
2573
+ sets[_i] = arguments[_i];
2574
+ }
2575
+ var union = new Set();
2576
+ try {
2577
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2578
+ var set = sets_1_1.value;
2579
+ try {
2580
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2581
+ var item = _d.value;
2582
+ union.add(item);
2583
+ }
2584
+ }
2585
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2586
+ finally {
2587
+ try {
2588
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2589
+ }
2590
+ finally { if (e_2) throw e_2.error; }
2591
+ }
2592
+ }
2593
+ }
2594
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2595
+ finally {
2596
+ try {
2597
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2598
+ }
2599
+ finally { if (e_1) throw e_1.error; }
2600
+ }
2601
+ return union;
2602
+ }
2603
+
2529
2604
  /**
2530
2605
  * Function isValidJsonString will tell you if the string is valid JSON or not
2531
2606
  *
@@ -2763,81 +2838,6 @@ function replaceParameters(template, parameters) {
2763
2838
  return replacedTemplate;
2764
2839
  }
2765
2840
 
2766
- /**
2767
- * Create difference set of two sets.
2768
- *
2769
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2770
- * @public exported from `@promptbook/utils`
2771
- */
2772
- function difference(a, b, isEqual) {
2773
- var e_1, _a;
2774
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2775
- var diff = new Set();
2776
- var _loop_1 = function (itemA) {
2777
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2778
- diff.add(itemA);
2779
- }
2780
- };
2781
- try {
2782
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2783
- var itemA = _c.value;
2784
- _loop_1(itemA);
2785
- }
2786
- }
2787
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2788
- finally {
2789
- try {
2790
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2791
- }
2792
- finally { if (e_1) throw e_1.error; }
2793
- }
2794
- return diff;
2795
- }
2796
- /**
2797
- * TODO: [🧠][πŸ’―] Maybe also implement symmetricDifference
2798
- */
2799
-
2800
- /**
2801
- * Creates a new set with all elements that are present in either set
2802
- *
2803
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2804
- * @public exported from `@promptbook/utils`
2805
- */
2806
- function union() {
2807
- var e_1, _a, e_2, _b;
2808
- var sets = [];
2809
- for (var _i = 0; _i < arguments.length; _i++) {
2810
- sets[_i] = arguments[_i];
2811
- }
2812
- var union = new Set();
2813
- try {
2814
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2815
- var set = sets_1_1.value;
2816
- try {
2817
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2818
- var item = _d.value;
2819
- union.add(item);
2820
- }
2821
- }
2822
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2823
- finally {
2824
- try {
2825
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2826
- }
2827
- finally { if (e_2) throw e_2.error; }
2828
- }
2829
- }
2830
- }
2831
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2832
- finally {
2833
- try {
2834
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2835
- }
2836
- finally { if (e_1) throw e_1.error; }
2837
- }
2838
- return union;
2839
- }
2840
-
2841
2841
  /**
2842
2842
  * Counts number of characters in the text
2843
2843
  *
@@ -2965,249 +2965,49 @@ function checkExpectations(expectations, value) {
2965
2965
  * TODO: [πŸ’] Unite object for expecting amount and format
2966
2966
  */
2967
2967
 
2968
- /**
2969
- * Just marks a place of place where should be something implemented
2970
- * No side effects.
2971
- *
2972
- * Note: It can be usefull suppressing eslint errors of unused variables
2973
- *
2974
- * @param value any values
2975
- * @returns void
2976
- * @private within the repository
2977
- */
2978
- function TODO_USE() {
2979
- var value = [];
2980
- for (var _i = 0; _i < arguments.length; _i++) {
2981
- value[_i] = arguments[_i];
2982
- }
2983
- }
2984
-
2985
- /**
2986
- * @@@
2987
- *
2988
- * @private internal utility of `createPipelineExecutor`
2989
- */
2990
- function getContextForTemplate(template) {
2991
- return __awaiter(this, void 0, void 0, function () {
2992
- return __generator(this, function (_a) {
2993
- TODO_USE(template);
2994
- return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
2995
- });
2996
- });
2997
- }
2998
-
2999
- /**
3000
- * @@@
3001
- *
3002
- * @private internal utility of `createPipelineExecutor`
3003
- */
3004
- function getKnowledgeForTemplate(options) {
3005
- return __awaiter(this, void 0, void 0, function () {
3006
- var preparedPipeline, template;
3007
- return __generator(this, function (_a) {
3008
- preparedPipeline = options.preparedPipeline, template = options.template;
3009
- // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
3010
- TODO_USE(template);
3011
- return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
3012
- var content = _a.content;
3013
- return "- ".concat(content);
3014
- }).join('\n')];
3015
- });
3016
- });
3017
- }
3018
-
3019
2968
  /**
3020
2969
  * @@@
3021
2970
  *
3022
2971
  * @private internal utility of `createPipelineExecutor`
3023
2972
  */
3024
- function getSamplesForTemplate(template) {
2973
+ function executeAttempts(options) {
3025
2974
  return __awaiter(this, void 0, void 0, function () {
2975
+ var $ongoingTemplateResult, jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, _loop_1, attempt, state_1;
3026
2976
  return __generator(this, function (_a) {
3027
- // TODO: [♨] Implement Better - use real index and keyword search
3028
- TODO_USE(template);
3029
- return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
3030
- });
3031
- });
3032
- }
3033
-
3034
- /**
3035
- * @@@
3036
- *
3037
- * @private internal utility of `createPipelineExecutor`
3038
- */
3039
- function getReservedParametersForTemplate(options) {
3040
- return __awaiter(this, void 0, void 0, function () {
3041
- var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3042
- var e_1, _a;
3043
- return __generator(this, function (_b) {
3044
- switch (_b.label) {
2977
+ switch (_a.label) {
3045
2978
  case 0:
3046
- preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
3047
- return [4 /*yield*/, getContextForTemplate(template)];
3048
- case 1:
3049
- context = _b.sent();
3050
- return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
3051
- case 2:
3052
- knowledge = _b.sent();
3053
- return [4 /*yield*/, getSamplesForTemplate(template)];
3054
- case 3:
3055
- samples = _b.sent();
3056
- currentDate = new Date().toISOString();
3057
- modelName = RESERVED_PARAMETER_MISSING_VALUE;
3058
- reservedParameters = {
3059
- content: RESERVED_PARAMETER_RESTRICTED,
3060
- context: context,
3061
- knowledge: knowledge,
3062
- samples: samples,
3063
- currentDate: currentDate,
3064
- modelName: modelName,
3065
- };
3066
- _loop_1 = function (parameterName) {
3067
- if (reservedParameters[parameterName] === undefined) {
3068
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3069
- }
3070
- };
3071
- try {
3072
- // Note: Doublecheck that ALL reserved parameters are defined:
3073
- for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
3074
- parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
3075
- _loop_1(parameterName);
3076
- }
3077
- }
3078
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3079
- finally {
3080
- try {
3081
- if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
3082
- }
3083
- finally { if (e_1) throw e_1.error; }
3084
- }
3085
- return [2 /*return*/, reservedParameters];
3086
- }
3087
- });
3088
- });
3089
- }
3090
-
3091
- /**
3092
- * @@@
3093
- *
3094
- * @private internal utility of `createPipelineExecutor`
3095
- */
3096
- function executeTemplate(options) {
3097
- return __awaiter(this, void 0, void 0, function () {
3098
- var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, $ongoingResult, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
3099
- var e_1, _f, _g;
3100
- return __generator(this, function (_h) {
3101
- switch (_h.label) {
3102
- case 0:
3103
- currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
2979
+ $ongoingTemplateResult = options.$ongoingTemplateResult, jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, llmTools = options.llmTools, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
3104
2980
  maxExecutionAttempts = settings.maxExecutionAttempts;
3105
- name = "pipeline-executor-frame-".concat(currentTemplate.name);
3106
- title = currentTemplate.title;
3107
- priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3108
- return [4 /*yield*/, onProgress({
3109
- name: name,
3110
- title: title,
3111
- isStarted: false,
3112
- isDone: false,
3113
- templateType: currentTemplate.templateType,
3114
- parameterName: currentTemplate.resultingParameterName,
3115
- parameterValue: null,
3116
- // <- [🍸]
3117
- })];
3118
- case 1:
3119
- _h.sent();
3120
- usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3121
- dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3122
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3123
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
3124
- .map(function (name) { return "{".concat(name, "}"); })
3125
- .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3126
- .map(function (name) { return "{".concat(name, "}"); })
3127
- .join(', '), "\n\n "); }));
3128
- }
3129
- _b = (_a = Object).freeze;
3130
- _c = [{}];
3131
- return [4 /*yield*/, getReservedParametersForTemplate({
3132
- preparedPipeline: preparedPipeline,
3133
- template: currentTemplate,
3134
- pipelineIdentification: pipelineIdentification,
3135
- })];
3136
- case 2:
3137
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
3138
- definedParameterNames = new Set(Object.keys(definedParameters));
3139
- parameters = {};
3140
- _loop_1 = function (parameterName) {
3141
- // Situation: Parameter is defined and used
3142
- if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3143
- parameters[parameterName] = definedParameters[parameterName];
3144
- }
3145
- // Situation: Parameter is defined but NOT used
3146
- else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
3147
- // Situation: Parameter is NOT defined BUT used
3148
- else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3149
- // Houston, we have a problem
3150
- // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3151
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3152
- }
3153
- };
3154
- try {
3155
- // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
3156
- for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
3157
- parameterName = _e.value;
3158
- _loop_1(parameterName);
3159
- }
3160
- }
3161
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3162
- finally {
3163
- try {
3164
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
3165
- }
3166
- finally { if (e_1) throw e_1.error; }
3167
- }
3168
- // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
3169
- Object.freeze(parameters);
3170
- $ongoingResult = {
3171
- $result: null,
3172
- $resultString: null,
3173
- $expectError: null,
3174
- $scriptPipelineExecutionErrors: [],
3175
- };
3176
- maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3177
- jokerParameterNames = currentTemplate.jokerParameterNames || [];
3178
- preparedContent = (currentTemplate.preparedContent || '{content}')
3179
- .split('{content}')
3180
- .join(currentTemplate.content);
3181
- _loop_2 = function (attempt) {
3182
- var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, _o, _p, _q, scriptTools, _r, error_1, e_2_1, _s, _t, _u, functionName, postprocessingError, _v, _w, scriptTools, _x, error_2, e_3_1, e_4_1, error_3;
3183
- var e_2, _y, e_4, _z, e_3, _0;
3184
- return __generator(this, function (_1) {
3185
- switch (_1.label) {
2981
+ _loop_1 = function (attempt) {
2982
+ var isJokerAttempt, jokerParameterName, _b, modelRequirements, _c, _d, _e, _f, _g, _h, scriptTools, _j, error_1, e_1_1, _k, _l, _m, functionName, postprocessingError, _o, _p, scriptTools, _q, error_2, e_2_1, e_3_1, error_3;
2983
+ var e_1, _r, e_3, _s, e_2, _t;
2984
+ return __generator(this, function (_u) {
2985
+ switch (_u.label) {
3186
2986
  case 0:
3187
2987
  isJokerAttempt = attempt < 0;
3188
2988
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3189
2989
  // TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
3190
2990
  if (isJokerAttempt && !jokerParameterName) {
3191
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
2991
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3192
2992
  }
3193
- $ongoingResult.$result = null;
3194
- $ongoingResult.$resultString = null;
3195
- $ongoingResult.$expectError = null;
2993
+ $ongoingTemplateResult.$result = null;
2994
+ $ongoingTemplateResult.$resultString = null;
2995
+ $ongoingTemplateResult.$expectError = null;
3196
2996
  if (isJokerAttempt) {
3197
2997
  if (parameters[jokerParameterName] === undefined) {
3198
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
2998
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3199
2999
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3200
3000
  }
3201
3001
  else {
3202
- $ongoingResult.$resultString = parameters[jokerParameterName];
3002
+ $ongoingTemplateResult.$resultString = parameters[jokerParameterName];
3203
3003
  }
3204
3004
  }
3205
- _1.label = 1;
3005
+ _u.label = 1;
3206
3006
  case 1:
3207
- _1.trys.push([1, 44, 45, 46]);
3007
+ _u.trys.push([1, 44, 45, 46]);
3208
3008
  if (!!isJokerAttempt) return [3 /*break*/, 26];
3209
- _j = currentTemplate.templateType;
3210
- switch (_j) {
3009
+ _b = template.templateType;
3010
+ switch (_b) {
3211
3011
  case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3212
3012
  case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3213
3013
  case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
@@ -3215,133 +3015,136 @@ function executeTemplate(options) {
3215
3015
  }
3216
3016
  return [3 /*break*/, 25];
3217
3017
  case 2:
3218
- $ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
3018
+ $ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
3219
3019
  return [3 /*break*/, 26];
3220
3020
  case 3:
3221
- modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3222
- $ongoingResult.$prompt = {
3223
- title: currentTemplate.title,
3021
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
3022
+ $ongoingTemplateResult.$prompt = {
3023
+ title: template.title,
3224
3024
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3225
3025
  ? preparedPipeline.pipelineUrl
3226
- : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3026
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name),
3227
3027
  parameters: parameters,
3228
3028
  content: preparedContent,
3229
3029
  modelRequirements: modelRequirements,
3230
3030
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3231
3031
  var name = _a.name;
3232
- return name === currentTemplate.personaName;
3233
- }) || {})), currentTemplate.expectations),
3234
- format: currentTemplate.format,
3235
- postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3032
+ return name === template.personaName;
3033
+ }) ||
3034
+ {})), template.expectations),
3035
+ format: template.format,
3036
+ postprocessingFunctionNames: template.postprocessingFunctionNames,
3236
3037
  }; // <- TODO: Not very good type guard
3237
- _k = modelRequirements.modelVariant;
3238
- switch (_k) {
3038
+ _c = modelRequirements.modelVariant;
3039
+ switch (_c) {
3239
3040
  case 'CHAT': return [3 /*break*/, 4];
3240
3041
  case 'COMPLETION': return [3 /*break*/, 6];
3241
3042
  case 'EMBEDDING': return [3 /*break*/, 8];
3242
3043
  }
3243
3044
  return [3 /*break*/, 10];
3244
3045
  case 4:
3245
- _l = $ongoingResult;
3246
- return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
3046
+ _d = $ongoingTemplateResult;
3047
+ return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
3247
3048
  case 5:
3248
- _l.$chatResult = _1.sent();
3049
+ _d.$chatResult = _u.sent();
3249
3050
  // TODO: [🍬] Destroy chatThread
3250
- $ongoingResult.$result = $ongoingResult.$chatResult;
3251
- $ongoingResult.$resultString = $ongoingResult.$chatResult.content;
3051
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
3052
+ $ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
3252
3053
  return [3 /*break*/, 11];
3253
3054
  case 6:
3254
- _m = $ongoingResult;
3255
- return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
3055
+ _e = $ongoingTemplateResult;
3056
+ return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
3256
3057
  case 7:
3257
- _m.$completionResult = _1.sent();
3258
- $ongoingResult.$result = $ongoingResult.$completionResult;
3259
- $ongoingResult.$resultString = $ongoingResult.$completionResult.content;
3058
+ _e.$completionResult = _u.sent();
3059
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
3060
+ $ongoingTemplateResult.$resultString =
3061
+ $ongoingTemplateResult.$completionResult.content;
3260
3062
  return [3 /*break*/, 11];
3261
3063
  case 8:
3262
3064
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3263
- _o = $ongoingResult;
3264
- return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
3065
+ _f = $ongoingTemplateResult;
3066
+ return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
3265
3067
  case 9:
3266
3068
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3267
- _o.$embeddingResult = _1.sent();
3268
- $ongoingResult.$result = $ongoingResult.$embeddingResult;
3269
- $ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
3069
+ _f.$embeddingResult = _u.sent();
3070
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
3071
+ $ongoingTemplateResult.$resultString =
3072
+ $ongoingTemplateResult.$embeddingResult.content.join(',');
3270
3073
  return [3 /*break*/, 11];
3271
- case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3074
+ case 10: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3272
3075
  case 11: return [3 /*break*/, 26];
3273
3076
  case 12:
3274
3077
  if (arrayableToArray(tools.script).length === 0) {
3275
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3078
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3276
3079
  }
3277
- if (!currentTemplate.contentLanguage) {
3278
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3080
+ if (!template.contentLanguage) {
3081
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3279
3082
  }
3280
- _1.label = 13;
3083
+ _u.label = 13;
3281
3084
  case 13:
3282
- _1.trys.push([13, 20, 21, 22]);
3283
- _p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
3284
- _1.label = 14;
3085
+ _u.trys.push([13, 20, 21, 22]);
3086
+ _g = (e_1 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
3087
+ _u.label = 14;
3285
3088
  case 14:
3286
- if (!!_q.done) return [3 /*break*/, 19];
3287
- scriptTools = _q.value;
3288
- _1.label = 15;
3089
+ if (!!_h.done) return [3 /*break*/, 19];
3090
+ scriptTools = _h.value;
3091
+ _u.label = 15;
3289
3092
  case 15:
3290
- _1.trys.push([15, 17, , 18]);
3291
- _r = $ongoingResult;
3093
+ _u.trys.push([15, 17, , 18]);
3094
+ _j = $ongoingTemplateResult;
3292
3095
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3293
- scriptLanguage: currentTemplate.contentLanguage,
3096
+ scriptLanguage: template.contentLanguage,
3294
3097
  script: preparedContent,
3295
3098
  parameters: parameters,
3296
3099
  }))];
3297
3100
  case 16:
3298
- _r.$resultString = _1.sent();
3101
+ _j.$resultString = _u.sent();
3299
3102
  return [3 /*break*/, 19];
3300
3103
  case 17:
3301
- error_1 = _1.sent();
3104
+ error_1 = _u.sent();
3302
3105
  if (!(error_1 instanceof Error)) {
3303
3106
  throw error_1;
3304
3107
  }
3305
3108
  if (error_1 instanceof UnexpectedError) {
3306
3109
  throw error_1;
3307
3110
  }
3308
- $ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
3111
+ $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
3309
3112
  return [3 /*break*/, 18];
3310
3113
  case 18:
3311
- _q = _p.next();
3114
+ _h = _g.next();
3312
3115
  return [3 /*break*/, 14];
3313
3116
  case 19: return [3 /*break*/, 22];
3314
3117
  case 20:
3315
- e_2_1 = _1.sent();
3316
- e_2 = { error: e_2_1 };
3118
+ e_1_1 = _u.sent();
3119
+ e_1 = { error: e_1_1 };
3317
3120
  return [3 /*break*/, 22];
3318
3121
  case 21:
3319
3122
  try {
3320
- if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
3123
+ if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
3321
3124
  }
3322
- finally { if (e_2) throw e_2.error; }
3125
+ finally { if (e_1) throw e_1.error; }
3323
3126
  return [7 /*endfinally*/];
3324
3127
  case 22:
3325
- if ($ongoingResult.$resultString !== null) {
3128
+ if ($ongoingTemplateResult.$resultString !== null) {
3326
3129
  return [3 /*break*/, 26];
3327
3130
  }
3328
- if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
3329
- throw $ongoingResult.$scriptPipelineExecutionErrors[0];
3131
+ if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
3132
+ throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
3330
3133
  }
3331
3134
  else {
3332
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingResult.$scriptPipelineExecutionErrors
3135
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
3333
3136
  .map(function (error) { return '- ' + error.message; })
3334
- .join('\n\n')), "\n "); }));
3137
+ .join('\n\n')), "\n "); }));
3335
3138
  }
3336
3139
  case 23:
3337
3140
  if (tools.userInterface === undefined) {
3338
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3141
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3339
3142
  }
3340
3143
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3341
- _s = $ongoingResult;
3144
+ _k = $ongoingTemplateResult;
3342
3145
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3343
- promptTitle: currentTemplate.title,
3344
- promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3146
+ promptTitle: template.title,
3147
+ promptMessage: replaceParameters(template.description || '', parameters),
3345
3148
  defaultValue: replaceParameters(preparedContent, parameters),
3346
3149
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
3347
3150
  placeholder: undefined,
@@ -3349,46 +3152,46 @@ function executeTemplate(options) {
3349
3152
  }))];
3350
3153
  case 24:
3351
3154
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3352
- _s.$resultString = _1.sent();
3155
+ _k.$resultString = _u.sent();
3353
3156
  return [3 /*break*/, 26];
3354
- case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3157
+ case 25: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3355
3158
  case 26:
3356
- if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3357
- _1.label = 27;
3159
+ if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
3160
+ _u.label = 27;
3358
3161
  case 27:
3359
- _1.trys.push([27, 41, 42, 43]);
3360
- _t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
3361
- _1.label = 28;
3162
+ _u.trys.push([27, 41, 42, 43]);
3163
+ _l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
3164
+ _u.label = 28;
3362
3165
  case 28:
3363
- if (!!_u.done) return [3 /*break*/, 40];
3364
- functionName = _u.value;
3166
+ if (!!_m.done) return [3 /*break*/, 40];
3167
+ functionName = _m.value;
3365
3168
  postprocessingError = null;
3366
- _1.label = 29;
3169
+ _u.label = 29;
3367
3170
  case 29:
3368
- _1.trys.push([29, 36, 37, 38]);
3369
- _v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
3370
- _1.label = 30;
3171
+ _u.trys.push([29, 36, 37, 38]);
3172
+ _o = (e_2 = void 0, __values(arrayableToArray(tools.script))), _p = _o.next();
3173
+ _u.label = 30;
3371
3174
  case 30:
3372
- if (!!_w.done) return [3 /*break*/, 35];
3373
- scriptTools = _w.value;
3374
- _1.label = 31;
3175
+ if (!!_p.done) return [3 /*break*/, 35];
3176
+ scriptTools = _p.value;
3177
+ _u.label = 31;
3375
3178
  case 31:
3376
- _1.trys.push([31, 33, , 34]);
3377
- _x = $ongoingResult;
3179
+ _u.trys.push([31, 33, , 34]);
3180
+ _q = $ongoingTemplateResult;
3378
3181
  return [4 /*yield*/, scriptTools.execute({
3379
3182
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3380
3183
  script: "".concat(functionName, "(resultString)"),
3381
3184
  parameters: {
3382
- resultString: $ongoingResult.$resultString || '',
3185
+ resultString: $ongoingTemplateResult.$resultString || '',
3383
3186
  // Note: No ...parametersForTemplate, because working with result only
3384
3187
  },
3385
3188
  })];
3386
3189
  case 32:
3387
- _x.$resultString = _1.sent();
3190
+ _q.$resultString = _u.sent();
3388
3191
  postprocessingError = null;
3389
3192
  return [3 /*break*/, 35];
3390
3193
  case 33:
3391
- error_2 = _1.sent();
3194
+ error_2 = _u.sent();
3392
3195
  if (!(error_2 instanceof Error)) {
3393
3196
  throw error_2;
3394
3197
  }
@@ -3396,104 +3199,106 @@ function executeTemplate(options) {
3396
3199
  throw error_2;
3397
3200
  }
3398
3201
  postprocessingError = error_2;
3399
- $ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
3202
+ $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
3400
3203
  return [3 /*break*/, 34];
3401
3204
  case 34:
3402
- _w = _v.next();
3205
+ _p = _o.next();
3403
3206
  return [3 /*break*/, 30];
3404
3207
  case 35: return [3 /*break*/, 38];
3405
3208
  case 36:
3406
- e_3_1 = _1.sent();
3407
- e_3 = { error: e_3_1 };
3209
+ e_2_1 = _u.sent();
3210
+ e_2 = { error: e_2_1 };
3408
3211
  return [3 /*break*/, 38];
3409
3212
  case 37:
3410
3213
  try {
3411
- if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
3214
+ if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3412
3215
  }
3413
- finally { if (e_3) throw e_3.error; }
3216
+ finally { if (e_2) throw e_2.error; }
3414
3217
  return [7 /*endfinally*/];
3415
3218
  case 38:
3416
3219
  if (postprocessingError) {
3417
3220
  throw postprocessingError;
3418
3221
  }
3419
- _1.label = 39;
3222
+ _u.label = 39;
3420
3223
  case 39:
3421
- _u = _t.next();
3224
+ _m = _l.next();
3422
3225
  return [3 /*break*/, 28];
3423
3226
  case 40: return [3 /*break*/, 43];
3424
3227
  case 41:
3425
- e_4_1 = _1.sent();
3426
- e_4 = { error: e_4_1 };
3228
+ e_3_1 = _u.sent();
3229
+ e_3 = { error: e_3_1 };
3427
3230
  return [3 /*break*/, 43];
3428
3231
  case 42:
3429
3232
  try {
3430
- if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
3233
+ if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3431
3234
  }
3432
- finally { if (e_4) throw e_4.error; }
3235
+ finally { if (e_3) throw e_3.error; }
3433
3236
  return [7 /*endfinally*/];
3434
3237
  case 43:
3435
3238
  // TODO: [πŸ’] Unite object for expecting amount and format
3436
- if (currentTemplate.format) {
3437
- if (currentTemplate.format === 'JSON') {
3438
- if (!isValidJsonString($ongoingResult.$resultString || '')) {
3239
+ if (template.format) {
3240
+ if (template.format === 'JSON') {
3241
+ if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
3439
3242
  // TODO: [🏒] Do more universally via `FormatDefinition`
3440
3243
  try {
3441
- $ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
3244
+ $ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
3442
3245
  }
3443
3246
  catch (error) {
3444
3247
  keepUnused(error);
3445
- throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3446
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3248
+ throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3249
+ /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3447
3250
  }
3448
3251
  }
3449
3252
  }
3450
3253
  else {
3451
- throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3254
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3452
3255
  }
3453
3256
  }
3454
3257
  // TODO: [πŸ’] Unite object for expecting amount and format
3455
- if (currentTemplate.expectations) {
3456
- checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
3258
+ if (template.expectations) {
3259
+ checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
3457
3260
  }
3458
3261
  return [2 /*return*/, "break-attempts"];
3459
3262
  case 44:
3460
- error_3 = _1.sent();
3263
+ error_3 = _u.sent();
3461
3264
  if (!(error_3 instanceof ExpectError)) {
3462
3265
  throw error_3;
3463
3266
  }
3464
- $ongoingResult.$expectError = error_3;
3267
+ $ongoingTemplateResult.$expectError = error_3;
3465
3268
  return [3 /*break*/, 46];
3466
3269
  case 45:
3467
3270
  if (!isJokerAttempt &&
3468
- currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
3469
- $ongoingResult.$prompt
3271
+ template.templateType === 'PROMPT_TEMPLATE' &&
3272
+ $ongoingTemplateResult.$prompt
3470
3273
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3471
3274
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3472
3275
  ) {
3473
3276
  // TODO: [🧠] Maybe put other templateTypes into report
3474
3277
  $executionReport.promptExecutions.push({
3475
- prompt: __assign({}, $ongoingResult.$prompt),
3476
- result: $ongoingResult.$result || undefined,
3477
- error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
3278
+ prompt: __assign({}, $ongoingTemplateResult.$prompt),
3279
+ result: $ongoingTemplateResult.$result || undefined,
3280
+ error: $ongoingTemplateResult.$expectError === null
3281
+ ? undefined
3282
+ : serializeError($ongoingTemplateResult.$expectError),
3478
3283
  });
3479
3284
  }
3480
3285
  return [7 /*endfinally*/];
3481
3286
  case 46:
3482
- if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
3287
+ if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
3483
3288
  throw new PipelineExecutionError(spaceTrim(function (block) {
3484
3289
  var _a, _b, _c;
3485
- return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
3290
+ return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
3486
3291
  .split('\n')
3487
3292
  .map(function (line) { return "> ".concat(line); })
3488
- .join('\n')), "\n\n Last error ").concat(((_b = $ongoingResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
3293
+ .join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
3489
3294
  .split('\n')
3490
3295
  .map(function (line) { return "> ".concat(line); })
3491
- .join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
3296
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
3492
3297
  ? 'null'
3493
- : $ongoingResult.$resultString
3298
+ : $ongoingTemplateResult.$resultString
3494
3299
  .split('\n')
3495
3300
  .map(function (line) { return "> ".concat(line); })
3496
- .join('\n')), "\n ---\n ");
3301
+ .join('\n')), "\n ---\n ");
3497
3302
  }));
3498
3303
  }
3499
3304
  return [2 /*return*/];
@@ -3501,34 +3306,279 @@ function executeTemplate(options) {
3501
3306
  });
3502
3307
  };
3503
3308
  attempt = -jokerParameterNames.length;
3504
- _h.label = 3;
3505
- case 3:
3506
- if (!(attempt < maxAttempts)) return [3 /*break*/, 6];
3507
- return [5 /*yield**/, _loop_2(attempt)];
3508
- case 4:
3509
- state_1 = _h.sent();
3309
+ _a.label = 1;
3310
+ case 1:
3311
+ if (!(attempt < maxAttempts)) return [3 /*break*/, 4];
3312
+ return [5 /*yield**/, _loop_1(attempt)];
3313
+ case 2:
3314
+ state_1 = _a.sent();
3510
3315
  switch (state_1) {
3511
- case "break-attempts": return [3 /*break*/, 6];
3316
+ case "break-attempts": return [3 /*break*/, 4];
3512
3317
  }
3513
- _h.label = 5;
3514
- case 5:
3318
+ _a.label = 3;
3319
+ case 3:
3515
3320
  attempt++;
3516
- return [3 /*break*/, 3];
3517
- case 6:
3518
- //------------------------------------
3519
- /*
3520
-
3521
-
3522
-
3523
-
3524
-
3525
-
3526
-
3527
-
3528
-
3529
- */
3530
- //------------------------------------
3531
- if ($ongoingResult.$resultString === null) {
3321
+ return [3 /*break*/, 1];
3322
+ case 4: return [2 /*return*/];
3323
+ }
3324
+ });
3325
+ });
3326
+ }
3327
+ /**
3328
+ * TODO: Break into smaller functions
3329
+ */
3330
+
3331
+ /**
3332
+ * @@@
3333
+ *
3334
+ * @private internal utility of `createPipelineExecutor`
3335
+ */
3336
+ function executeFormatCells(options) {
3337
+ return __awaiter(this, void 0, void 0, function () {
3338
+ var template;
3339
+ return __generator(this, function (_a) {
3340
+ template = options.template;
3341
+ if (template.foreach === undefined) {
3342
+ return [2 /*return*/, /* not await */ executeAttempts(options)];
3343
+ }
3344
+ throw new NotYetImplementedError('FOREACH execution not implemented yet');
3345
+ });
3346
+ });
3347
+ }
3348
+
3349
+ /**
3350
+ * Just marks a place of place where should be something implemented
3351
+ * No side effects.
3352
+ *
3353
+ * Note: It can be usefull suppressing eslint errors of unused variables
3354
+ *
3355
+ * @param value any values
3356
+ * @returns void
3357
+ * @private within the repository
3358
+ */
3359
+ function TODO_USE() {
3360
+ var value = [];
3361
+ for (var _i = 0; _i < arguments.length; _i++) {
3362
+ value[_i] = arguments[_i];
3363
+ }
3364
+ }
3365
+
3366
+ /**
3367
+ * @@@
3368
+ *
3369
+ * @private internal utility of `createPipelineExecutor`
3370
+ */
3371
+ function getContextForTemplate(template) {
3372
+ return __awaiter(this, void 0, void 0, function () {
3373
+ return __generator(this, function (_a) {
3374
+ TODO_USE(template);
3375
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
3376
+ });
3377
+ });
3378
+ }
3379
+
3380
+ /**
3381
+ * @@@
3382
+ *
3383
+ * @private internal utility of `createPipelineExecutor`
3384
+ */
3385
+ function getKnowledgeForTemplate(options) {
3386
+ return __awaiter(this, void 0, void 0, function () {
3387
+ var preparedPipeline, template;
3388
+ return __generator(this, function (_a) {
3389
+ preparedPipeline = options.preparedPipeline, template = options.template;
3390
+ // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
3391
+ TODO_USE(template);
3392
+ return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
3393
+ var content = _a.content;
3394
+ return "- ".concat(content);
3395
+ }).join('\n')];
3396
+ });
3397
+ });
3398
+ }
3399
+
3400
+ /**
3401
+ * @@@
3402
+ *
3403
+ * @private internal utility of `createPipelineExecutor`
3404
+ */
3405
+ function getSamplesForTemplate(template) {
3406
+ return __awaiter(this, void 0, void 0, function () {
3407
+ return __generator(this, function (_a) {
3408
+ // TODO: [♨] Implement Better - use real index and keyword search
3409
+ TODO_USE(template);
3410
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
3411
+ });
3412
+ });
3413
+ }
3414
+
3415
+ /**
3416
+ * @@@
3417
+ *
3418
+ * @private internal utility of `createPipelineExecutor`
3419
+ */
3420
+ function getReservedParametersForTemplate(options) {
3421
+ return __awaiter(this, void 0, void 0, function () {
3422
+ var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3423
+ var e_1, _a;
3424
+ return __generator(this, function (_b) {
3425
+ switch (_b.label) {
3426
+ case 0:
3427
+ preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
3428
+ return [4 /*yield*/, getContextForTemplate(template)];
3429
+ case 1:
3430
+ context = _b.sent();
3431
+ return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
3432
+ case 2:
3433
+ knowledge = _b.sent();
3434
+ return [4 /*yield*/, getSamplesForTemplate(template)];
3435
+ case 3:
3436
+ samples = _b.sent();
3437
+ currentDate = new Date().toISOString();
3438
+ modelName = RESERVED_PARAMETER_MISSING_VALUE;
3439
+ reservedParameters = {
3440
+ content: RESERVED_PARAMETER_RESTRICTED,
3441
+ context: context,
3442
+ knowledge: knowledge,
3443
+ samples: samples,
3444
+ currentDate: currentDate,
3445
+ modelName: modelName,
3446
+ };
3447
+ _loop_1 = function (parameterName) {
3448
+ if (reservedParameters[parameterName] === undefined) {
3449
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3450
+ }
3451
+ };
3452
+ try {
3453
+ // Note: Doublecheck that ALL reserved parameters are defined:
3454
+ for (RESERVED_PARAMETER_NAMES_1 = __values(RESERVED_PARAMETER_NAMES), RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next(); !RESERVED_PARAMETER_NAMES_1_1.done; RESERVED_PARAMETER_NAMES_1_1 = RESERVED_PARAMETER_NAMES_1.next()) {
3455
+ parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
3456
+ _loop_1(parameterName);
3457
+ }
3458
+ }
3459
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3460
+ finally {
3461
+ try {
3462
+ if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
3463
+ }
3464
+ finally { if (e_1) throw e_1.error; }
3465
+ }
3466
+ return [2 /*return*/, reservedParameters];
3467
+ }
3468
+ });
3469
+ });
3470
+ }
3471
+
3472
+ /**
3473
+ * @@@
3474
+ *
3475
+ * @private internal utility of `createPipelineExecutor`
3476
+ */
3477
+ function executeTemplate(options) {
3478
+ return __awaiter(this, void 0, void 0, function () {
3479
+ var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, $ongoingTemplateResult, maxAttempts, jokerParameterNames, preparedContent;
3480
+ var e_1, _f, _g;
3481
+ return __generator(this, function (_h) {
3482
+ switch (_h.label) {
3483
+ case 0:
3484
+ currentTemplate = options.currentTemplate, preparedPipeline = options.preparedPipeline, parametersToPass = options.parametersToPass, tools = options.tools, llmTools = options.llmTools, onProgress = options.onProgress, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
3485
+ maxExecutionAttempts = settings.maxExecutionAttempts;
3486
+ name = "pipeline-executor-frame-".concat(currentTemplate.name);
3487
+ title = currentTemplate.title;
3488
+ priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3489
+ return [4 /*yield*/, onProgress({
3490
+ name: name,
3491
+ title: title,
3492
+ isStarted: false,
3493
+ isDone: false,
3494
+ templateType: currentTemplate.templateType,
3495
+ parameterName: currentTemplate.resultingParameterName,
3496
+ parameterValue: null,
3497
+ // <- [🍸]
3498
+ })];
3499
+ case 1:
3500
+ _h.sent();
3501
+ usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3502
+ dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3503
+ if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3504
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
3505
+ .map(function (name) { return "{".concat(name, "}"); })
3506
+ .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3507
+ .map(function (name) { return "{".concat(name, "}"); })
3508
+ .join(', '), "\n\n "); }));
3509
+ }
3510
+ _b = (_a = Object).freeze;
3511
+ _c = [{}];
3512
+ return [4 /*yield*/, getReservedParametersForTemplate({
3513
+ preparedPipeline: preparedPipeline,
3514
+ template: currentTemplate,
3515
+ pipelineIdentification: pipelineIdentification,
3516
+ })];
3517
+ case 2:
3518
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
3519
+ definedParameterNames = new Set(Object.keys(definedParameters));
3520
+ parameters = {};
3521
+ _loop_1 = function (parameterName) {
3522
+ // Situation: Parameter is defined and used
3523
+ if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3524
+ parameters[parameterName] = definedParameters[parameterName];
3525
+ }
3526
+ // Situation: Parameter is defined but NOT used
3527
+ else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
3528
+ // Situation: Parameter is NOT defined BUT used
3529
+ else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3530
+ // Houston, we have a problem
3531
+ // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3532
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3533
+ }
3534
+ };
3535
+ try {
3536
+ // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
3537
+ for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
3538
+ parameterName = _e.value;
3539
+ _loop_1(parameterName);
3540
+ }
3541
+ }
3542
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3543
+ finally {
3544
+ try {
3545
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
3546
+ }
3547
+ finally { if (e_1) throw e_1.error; }
3548
+ }
3549
+ // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
3550
+ Object.freeze(parameters);
3551
+ $ongoingTemplateResult = {
3552
+ $result: null,
3553
+ $resultString: null,
3554
+ $expectError: null,
3555
+ $scriptPipelineExecutionErrors: [],
3556
+ };
3557
+ maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3558
+ jokerParameterNames = currentTemplate.jokerParameterNames || [];
3559
+ preparedContent = (currentTemplate.preparedContent || '{content}')
3560
+ .split('{content}')
3561
+ .join(currentTemplate.content);
3562
+ // <- TODO: [🍡] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
3563
+ return [4 /*yield*/, executeFormatCells({
3564
+ $ongoingTemplateResult: $ongoingTemplateResult,
3565
+ jokerParameterNames: jokerParameterNames,
3566
+ priority: priority,
3567
+ maxAttempts: maxAttempts,
3568
+ preparedContent: preparedContent,
3569
+ parameters: parameters,
3570
+ template: currentTemplate,
3571
+ preparedPipeline: preparedPipeline,
3572
+ tools: tools,
3573
+ llmTools: llmTools,
3574
+ settings: settings,
3575
+ $executionReport: $executionReport,
3576
+ pipelineIdentification: pipelineIdentification,
3577
+ })];
3578
+ case 3:
3579
+ // <- TODO: [🍡] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
3580
+ _h.sent();
3581
+ if ($ongoingTemplateResult.$resultString === null) {
3532
3582
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3533
3583
  }
3534
3584
  return [4 /*yield*/, onProgress({
@@ -3538,13 +3588,13 @@ function executeTemplate(options) {
3538
3588
  isDone: true,
3539
3589
  templateType: currentTemplate.templateType,
3540
3590
  parameterName: currentTemplate.resultingParameterName,
3541
- parameterValue: $ongoingResult.$resultString,
3591
+ parameterValue: $ongoingTemplateResult.$resultString,
3542
3592
  // <- [🍸]
3543
3593
  })];
3544
- case 7:
3594
+ case 4:
3545
3595
  _h.sent();
3546
3596
  return [2 /*return*/, Object.freeze((_g = {},
3547
- _g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3597
+ _g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3548
3598
  _g))];
3549
3599
  }
3550
3600
  });
@@ -3820,6 +3870,8 @@ function executePipeline(options) {
3820
3870
  .then(function () {
3821
3871
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
3822
3872
  });
3873
+ // <- Note: Errors are catched here [3]
3874
+ // TODO: BUT if in multiple templates are errors, only the first one is catched so maybe we should catch errors here and save them to errors array here
3823
3875
  resolving_1.push(work_1);
3824
3876
  _j.label = 4;
3825
3877
  case 4: return [2 /*return*/];