@promptbook/core 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
@@ -10,7 +10,7 @@ import moment from 'moment';
10
10
  /**
11
11
  * The version of the Promptbook library
12
12
  */
13
- var PROMPTBOOK_VERSION = '0.69.0-6';
13
+ var PROMPTBOOK_VERSION = '0.69.0-7';
14
14
  // TODO: !!!! List here all the versions and annotate + put into script
15
15
 
16
16
  /*! *****************************************************************************
@@ -652,13 +652,13 @@ var IMMEDIATE_TIME = 10;
652
652
  *
653
653
  * @public exported from `@promptbook/core`
654
654
  */
655
- var MAX_PARALLEL_COUNT = 5;
655
+ var MAX_PARALLEL_COUNT = 5; // <- TODO: [πŸ€Ήβ€β™‚οΈ]
656
656
  /**
657
657
  * The maximum number of attempts to execute LLM task before giving up
658
658
  *
659
659
  * @public exported from `@promptbook/core`
660
660
  */
661
- var MAX_EXECUTION_ATTEMPTS = 3;
661
+ var MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [πŸ€Ήβ€β™‚οΈ]
662
662
  /**
663
663
  * The maximum length of the (generated) filename
664
664
  *
@@ -1817,7 +1817,7 @@ function forEachAsync(array, options, callbackfunction) {
1817
1817
  });
1818
1818
  }
1819
1819
 
1820
- 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"}];
1820
+ 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"}];
1821
1821
 
1822
1822
  var defaultDiacriticsRemovalMap = [
1823
1823
  {
@@ -2377,6 +2377,23 @@ function isPipelinePrepared(pipeline) {
2377
2377
  * - [♨] Are templates prepared
2378
2378
  */
2379
2379
 
2380
+ /**
2381
+ * Serializes an error into a [πŸš‰] JSON-serializable object
2382
+ *
2383
+ * @public exported from `@promptbook/utils`
2384
+ */
2385
+ function serializeError(error) {
2386
+ var name = error.name, message = error.message, stack = error.stack;
2387
+ if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2388
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2389
+ }
2390
+ return {
2391
+ name: name,
2392
+ message: message,
2393
+ stack: stack,
2394
+ };
2395
+ }
2396
+
2380
2397
  /**
2381
2398
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2382
2399
  *
@@ -2670,23 +2687,6 @@ function joinLlmExecutionTools() {
2670
2687
  * TODO: [πŸ‘·β€β™‚οΈ] @@@ Manual about construction of llmTools
2671
2688
  */
2672
2689
 
2673
- /**
2674
- * Serializes an error into a [πŸš‰] JSON-serializable object
2675
- *
2676
- * @public exported from `@promptbook/utils`
2677
- */
2678
- function serializeError(error) {
2679
- var name = error.name, message = error.message, stack = error.stack;
2680
- if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2681
- throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2682
- }
2683
- return {
2684
- name: name,
2685
- message: message,
2686
- stack: stack,
2687
- };
2688
- }
2689
-
2690
2690
  /**
2691
2691
  * Takes an item or an array of items and returns an array of items
2692
2692
  *
@@ -2824,6 +2824,81 @@ function extractParameterNamesFromTemplate(template) {
2824
2824
  * TODO: [πŸ”£] If script require contentLanguage
2825
2825
  */
2826
2826
 
2827
+ /**
2828
+ * Create difference set of two sets.
2829
+ *
2830
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2831
+ * @public exported from `@promptbook/utils`
2832
+ */
2833
+ function difference(a, b, isEqual) {
2834
+ var e_1, _a;
2835
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2836
+ var diff = new Set();
2837
+ var _loop_1 = function (itemA) {
2838
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2839
+ diff.add(itemA);
2840
+ }
2841
+ };
2842
+ try {
2843
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2844
+ var itemA = _c.value;
2845
+ _loop_1(itemA);
2846
+ }
2847
+ }
2848
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2849
+ finally {
2850
+ try {
2851
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2852
+ }
2853
+ finally { if (e_1) throw e_1.error; }
2854
+ }
2855
+ return diff;
2856
+ }
2857
+ /**
2858
+ * TODO: [🧠][πŸ’―] Maybe also implement symmetricDifference
2859
+ */
2860
+
2861
+ /**
2862
+ * Creates a new set with all elements that are present in either set
2863
+ *
2864
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2865
+ * @public exported from `@promptbook/utils`
2866
+ */
2867
+ function union() {
2868
+ var e_1, _a, e_2, _b;
2869
+ var sets = [];
2870
+ for (var _i = 0; _i < arguments.length; _i++) {
2871
+ sets[_i] = arguments[_i];
2872
+ }
2873
+ var union = new Set();
2874
+ try {
2875
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2876
+ var set = sets_1_1.value;
2877
+ try {
2878
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2879
+ var item = _d.value;
2880
+ union.add(item);
2881
+ }
2882
+ }
2883
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2884
+ finally {
2885
+ try {
2886
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2887
+ }
2888
+ finally { if (e_2) throw e_2.error; }
2889
+ }
2890
+ }
2891
+ }
2892
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2893
+ finally {
2894
+ try {
2895
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2896
+ }
2897
+ finally { if (e_1) throw e_1.error; }
2898
+ }
2899
+ return union;
2900
+ }
2901
+
2827
2902
  /**
2828
2903
  * Function isValidJsonString will tell you if the string is valid JSON or not
2829
2904
  *
@@ -3061,81 +3136,6 @@ function replaceParameters(template, parameters) {
3061
3136
  return replacedTemplate;
3062
3137
  }
3063
3138
 
3064
- /**
3065
- * Create difference set of two sets.
3066
- *
3067
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
3068
- * @public exported from `@promptbook/utils`
3069
- */
3070
- function difference(a, b, isEqual) {
3071
- var e_1, _a;
3072
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
3073
- var diff = new Set();
3074
- var _loop_1 = function (itemA) {
3075
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
3076
- diff.add(itemA);
3077
- }
3078
- };
3079
- try {
3080
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
3081
- var itemA = _c.value;
3082
- _loop_1(itemA);
3083
- }
3084
- }
3085
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3086
- finally {
3087
- try {
3088
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3089
- }
3090
- finally { if (e_1) throw e_1.error; }
3091
- }
3092
- return diff;
3093
- }
3094
- /**
3095
- * TODO: [🧠][πŸ’―] Maybe also implement symmetricDifference
3096
- */
3097
-
3098
- /**
3099
- * Creates a new set with all elements that are present in either set
3100
- *
3101
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
3102
- * @public exported from `@promptbook/utils`
3103
- */
3104
- function union() {
3105
- var e_1, _a, e_2, _b;
3106
- var sets = [];
3107
- for (var _i = 0; _i < arguments.length; _i++) {
3108
- sets[_i] = arguments[_i];
3109
- }
3110
- var union = new Set();
3111
- try {
3112
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
3113
- var set = sets_1_1.value;
3114
- try {
3115
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
3116
- var item = _d.value;
3117
- union.add(item);
3118
- }
3119
- }
3120
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3121
- finally {
3122
- try {
3123
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
3124
- }
3125
- finally { if (e_2) throw e_2.error; }
3126
- }
3127
- }
3128
- }
3129
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3130
- finally {
3131
- try {
3132
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
3133
- }
3134
- finally { if (e_1) throw e_1.error; }
3135
- }
3136
- return union;
3137
- }
3138
-
3139
3139
  /**
3140
3140
  * Counts number of characters in the text
3141
3141
  *
@@ -3285,249 +3285,49 @@ function isPassingExpectations(expectations, value) {
3285
3285
  * TODO: [πŸ’] Unite object for expecting amount and format
3286
3286
  */
3287
3287
 
3288
- /**
3289
- * Just marks a place of place where should be something implemented
3290
- * No side effects.
3291
- *
3292
- * Note: It can be usefull suppressing eslint errors of unused variables
3293
- *
3294
- * @param value any values
3295
- * @returns void
3296
- * @private within the repository
3297
- */
3298
- function TODO_USE() {
3299
- var value = [];
3300
- for (var _i = 0; _i < arguments.length; _i++) {
3301
- value[_i] = arguments[_i];
3302
- }
3303
- }
3304
-
3305
- /**
3306
- * @@@
3307
- *
3308
- * @private internal utility of `createPipelineExecutor`
3309
- */
3310
- function getContextForTemplate(template) {
3311
- return __awaiter(this, void 0, void 0, function () {
3312
- return __generator(this, function (_a) {
3313
- TODO_USE(template);
3314
- return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
3315
- });
3316
- });
3317
- }
3318
-
3319
- /**
3320
- * @@@
3321
- *
3322
- * @private internal utility of `createPipelineExecutor`
3323
- */
3324
- function getKnowledgeForTemplate(options) {
3325
- return __awaiter(this, void 0, void 0, function () {
3326
- var preparedPipeline, template;
3327
- return __generator(this, function (_a) {
3328
- preparedPipeline = options.preparedPipeline, template = options.template;
3329
- // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
3330
- TODO_USE(template);
3331
- return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
3332
- var content = _a.content;
3333
- return "- ".concat(content);
3334
- }).join('\n')];
3335
- });
3336
- });
3337
- }
3338
-
3339
3288
  /**
3340
3289
  * @@@
3341
3290
  *
3342
3291
  * @private internal utility of `createPipelineExecutor`
3343
3292
  */
3344
- function getSamplesForTemplate(template) {
3293
+ function executeAttempts(options) {
3345
3294
  return __awaiter(this, void 0, void 0, function () {
3295
+ var $ongoingTemplateResult, jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, _loop_1, attempt, state_1;
3346
3296
  return __generator(this, function (_a) {
3347
- // TODO: [♨] Implement Better - use real index and keyword search
3348
- TODO_USE(template);
3349
- return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
3350
- });
3351
- });
3352
- }
3353
-
3354
- /**
3355
- * @@@
3356
- *
3357
- * @private internal utility of `createPipelineExecutor`
3358
- */
3359
- function getReservedParametersForTemplate(options) {
3360
- return __awaiter(this, void 0, void 0, function () {
3361
- var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3362
- var e_1, _a;
3363
- return __generator(this, function (_b) {
3364
- switch (_b.label) {
3297
+ switch (_a.label) {
3365
3298
  case 0:
3366
- preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
3367
- return [4 /*yield*/, getContextForTemplate(template)];
3368
- case 1:
3369
- context = _b.sent();
3370
- return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
3371
- case 2:
3372
- knowledge = _b.sent();
3373
- return [4 /*yield*/, getSamplesForTemplate(template)];
3374
- case 3:
3375
- samples = _b.sent();
3376
- currentDate = new Date().toISOString();
3377
- modelName = RESERVED_PARAMETER_MISSING_VALUE;
3378
- reservedParameters = {
3379
- content: RESERVED_PARAMETER_RESTRICTED,
3380
- context: context,
3381
- knowledge: knowledge,
3382
- samples: samples,
3383
- currentDate: currentDate,
3384
- modelName: modelName,
3385
- };
3386
- _loop_1 = function (parameterName) {
3387
- if (reservedParameters[parameterName] === undefined) {
3388
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3389
- }
3390
- };
3391
- try {
3392
- // Note: Doublecheck that ALL reserved parameters are defined:
3393
- 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()) {
3394
- parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
3395
- _loop_1(parameterName);
3396
- }
3397
- }
3398
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3399
- finally {
3400
- try {
3401
- if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
3402
- }
3403
- finally { if (e_1) throw e_1.error; }
3404
- }
3405
- return [2 /*return*/, reservedParameters];
3406
- }
3407
- });
3408
- });
3409
- }
3410
-
3411
- /**
3412
- * @@@
3413
- *
3414
- * @private internal utility of `createPipelineExecutor`
3415
- */
3416
- function executeTemplate(options) {
3417
- return __awaiter(this, void 0, void 0, function () {
3418
- 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;
3419
- var e_1, _f, _g;
3420
- return __generator(this, function (_h) {
3421
- switch (_h.label) {
3422
- case 0:
3423
- 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;
3299
+ $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;
3424
3300
  maxExecutionAttempts = settings.maxExecutionAttempts;
3425
- name = "pipeline-executor-frame-".concat(currentTemplate.name);
3426
- title = currentTemplate.title;
3427
- priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3428
- return [4 /*yield*/, onProgress({
3429
- name: name,
3430
- title: title,
3431
- isStarted: false,
3432
- isDone: false,
3433
- templateType: currentTemplate.templateType,
3434
- parameterName: currentTemplate.resultingParameterName,
3435
- parameterValue: null,
3436
- // <- [🍸]
3437
- })];
3438
- case 1:
3439
- _h.sent();
3440
- usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3441
- dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3442
- if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3443
- throw new UnexpectedError(spaceTrim$1(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)
3444
- .map(function (name) { return "{".concat(name, "}"); })
3445
- .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3446
- .map(function (name) { return "{".concat(name, "}"); })
3447
- .join(', '), "\n\n "); }));
3448
- }
3449
- _b = (_a = Object).freeze;
3450
- _c = [{}];
3451
- return [4 /*yield*/, getReservedParametersForTemplate({
3452
- preparedPipeline: preparedPipeline,
3453
- template: currentTemplate,
3454
- pipelineIdentification: pipelineIdentification,
3455
- })];
3456
- case 2:
3457
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
3458
- definedParameterNames = new Set(Object.keys(definedParameters));
3459
- parameters = {};
3460
- _loop_1 = function (parameterName) {
3461
- // Situation: Parameter is defined and used
3462
- if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3463
- parameters[parameterName] = definedParameters[parameterName];
3464
- }
3465
- // Situation: Parameter is defined but NOT used
3466
- else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
3467
- // Situation: Parameter is NOT defined BUT used
3468
- else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3469
- // Houston, we have a problem
3470
- // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3471
- throw new UnexpectedError(spaceTrim$1(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 "); }));
3472
- }
3473
- };
3474
- try {
3475
- // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
3476
- for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
3477
- parameterName = _e.value;
3478
- _loop_1(parameterName);
3479
- }
3480
- }
3481
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3482
- finally {
3483
- try {
3484
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
3485
- }
3486
- finally { if (e_1) throw e_1.error; }
3487
- }
3488
- // 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
3489
- Object.freeze(parameters);
3490
- $ongoingResult = {
3491
- $result: null,
3492
- $resultString: null,
3493
- $expectError: null,
3494
- $scriptPipelineExecutionErrors: [],
3495
- };
3496
- maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3497
- jokerParameterNames = currentTemplate.jokerParameterNames || [];
3498
- preparedContent = (currentTemplate.preparedContent || '{content}')
3499
- .split('{content}')
3500
- .join(currentTemplate.content);
3501
- _loop_2 = function (attempt) {
3502
- 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;
3503
- var e_2, _y, e_4, _z, e_3, _0;
3504
- return __generator(this, function (_1) {
3505
- switch (_1.label) {
3301
+ _loop_1 = function (attempt) {
3302
+ 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;
3303
+ var e_1, _r, e_3, _s, e_2, _t;
3304
+ return __generator(this, function (_u) {
3305
+ switch (_u.label) {
3506
3306
  case 0:
3507
3307
  isJokerAttempt = attempt < 0;
3508
3308
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3509
3309
  // TODO: [🧠] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
3510
3310
  if (isJokerAttempt && !jokerParameterName) {
3511
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3311
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3512
3312
  }
3513
- $ongoingResult.$result = null;
3514
- $ongoingResult.$resultString = null;
3515
- $ongoingResult.$expectError = null;
3313
+ $ongoingTemplateResult.$result = null;
3314
+ $ongoingTemplateResult.$resultString = null;
3315
+ $ongoingTemplateResult.$expectError = null;
3516
3316
  if (isJokerAttempt) {
3517
3317
  if (parameters[jokerParameterName] === undefined) {
3518
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3318
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3519
3319
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3520
3320
  }
3521
3321
  else {
3522
- $ongoingResult.$resultString = parameters[jokerParameterName];
3322
+ $ongoingTemplateResult.$resultString = parameters[jokerParameterName];
3523
3323
  }
3524
3324
  }
3525
- _1.label = 1;
3325
+ _u.label = 1;
3526
3326
  case 1:
3527
- _1.trys.push([1, 44, 45, 46]);
3327
+ _u.trys.push([1, 44, 45, 46]);
3528
3328
  if (!!isJokerAttempt) return [3 /*break*/, 26];
3529
- _j = currentTemplate.templateType;
3530
- switch (_j) {
3329
+ _b = template.templateType;
3330
+ switch (_b) {
3531
3331
  case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3532
3332
  case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3533
3333
  case 'SCRIPT_TEMPLATE': return [3 /*break*/, 12];
@@ -3535,133 +3335,136 @@ function executeTemplate(options) {
3535
3335
  }
3536
3336
  return [3 /*break*/, 25];
3537
3337
  case 2:
3538
- $ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
3338
+ $ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
3539
3339
  return [3 /*break*/, 26];
3540
3340
  case 3:
3541
- modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3542
- $ongoingResult.$prompt = {
3543
- title: currentTemplate.title,
3341
+ modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
3342
+ $ongoingTemplateResult.$prompt = {
3343
+ title: template.title,
3544
3344
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3545
3345
  ? preparedPipeline.pipelineUrl
3546
- : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3346
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name),
3547
3347
  parameters: parameters,
3548
3348
  content: preparedContent,
3549
3349
  modelRequirements: modelRequirements,
3550
3350
  expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3551
3351
  var name = _a.name;
3552
- return name === currentTemplate.personaName;
3553
- }) || {})), currentTemplate.expectations),
3554
- format: currentTemplate.format,
3555
- postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3352
+ return name === template.personaName;
3353
+ }) ||
3354
+ {})), template.expectations),
3355
+ format: template.format,
3356
+ postprocessingFunctionNames: template.postprocessingFunctionNames,
3556
3357
  }; // <- TODO: Not very good type guard
3557
- _k = modelRequirements.modelVariant;
3558
- switch (_k) {
3358
+ _c = modelRequirements.modelVariant;
3359
+ switch (_c) {
3559
3360
  case 'CHAT': return [3 /*break*/, 4];
3560
3361
  case 'COMPLETION': return [3 /*break*/, 6];
3561
3362
  case 'EMBEDDING': return [3 /*break*/, 8];
3562
3363
  }
3563
3364
  return [3 /*break*/, 10];
3564
3365
  case 4:
3565
- _l = $ongoingResult;
3566
- return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
3366
+ _d = $ongoingTemplateResult;
3367
+ return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
3567
3368
  case 5:
3568
- _l.$chatResult = _1.sent();
3369
+ _d.$chatResult = _u.sent();
3569
3370
  // TODO: [🍬] Destroy chatThread
3570
- $ongoingResult.$result = $ongoingResult.$chatResult;
3571
- $ongoingResult.$resultString = $ongoingResult.$chatResult.content;
3371
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
3372
+ $ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
3572
3373
  return [3 /*break*/, 11];
3573
3374
  case 6:
3574
- _m = $ongoingResult;
3575
- return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
3375
+ _e = $ongoingTemplateResult;
3376
+ return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
3576
3377
  case 7:
3577
- _m.$completionResult = _1.sent();
3578
- $ongoingResult.$result = $ongoingResult.$completionResult;
3579
- $ongoingResult.$resultString = $ongoingResult.$completionResult.content;
3378
+ _e.$completionResult = _u.sent();
3379
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
3380
+ $ongoingTemplateResult.$resultString =
3381
+ $ongoingTemplateResult.$completionResult.content;
3580
3382
  return [3 /*break*/, 11];
3581
3383
  case 8:
3582
3384
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3583
- _o = $ongoingResult;
3584
- return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
3385
+ _f = $ongoingTemplateResult;
3386
+ return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingTemplateResult.$prompt))];
3585
3387
  case 9:
3586
3388
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3587
- _o.$embeddingResult = _1.sent();
3588
- $ongoingResult.$result = $ongoingResult.$embeddingResult;
3589
- $ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
3389
+ _f.$embeddingResult = _u.sent();
3390
+ $ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
3391
+ $ongoingTemplateResult.$resultString =
3392
+ $ongoingTemplateResult.$embeddingResult.content.join(',');
3590
3393
  return [3 /*break*/, 11];
3591
- case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3394
+ case 10: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3592
3395
  case 11: return [3 /*break*/, 26];
3593
3396
  case 12:
3594
3397
  if (arrayableToArray(tools.script).length === 0) {
3595
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3398
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3596
3399
  }
3597
- if (!currentTemplate.contentLanguage) {
3598
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3400
+ if (!template.contentLanguage) {
3401
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3599
3402
  }
3600
- _1.label = 13;
3403
+ _u.label = 13;
3601
3404
  case 13:
3602
- _1.trys.push([13, 20, 21, 22]);
3603
- _p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
3604
- _1.label = 14;
3405
+ _u.trys.push([13, 20, 21, 22]);
3406
+ _g = (e_1 = void 0, __values(arrayableToArray(tools.script))), _h = _g.next();
3407
+ _u.label = 14;
3605
3408
  case 14:
3606
- if (!!_q.done) return [3 /*break*/, 19];
3607
- scriptTools = _q.value;
3608
- _1.label = 15;
3409
+ if (!!_h.done) return [3 /*break*/, 19];
3410
+ scriptTools = _h.value;
3411
+ _u.label = 15;
3609
3412
  case 15:
3610
- _1.trys.push([15, 17, , 18]);
3611
- _r = $ongoingResult;
3413
+ _u.trys.push([15, 17, , 18]);
3414
+ _j = $ongoingTemplateResult;
3612
3415
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3613
- scriptLanguage: currentTemplate.contentLanguage,
3416
+ scriptLanguage: template.contentLanguage,
3614
3417
  script: preparedContent,
3615
3418
  parameters: parameters,
3616
3419
  }))];
3617
3420
  case 16:
3618
- _r.$resultString = _1.sent();
3421
+ _j.$resultString = _u.sent();
3619
3422
  return [3 /*break*/, 19];
3620
3423
  case 17:
3621
- error_1 = _1.sent();
3424
+ error_1 = _u.sent();
3622
3425
  if (!(error_1 instanceof Error)) {
3623
3426
  throw error_1;
3624
3427
  }
3625
3428
  if (error_1 instanceof UnexpectedError) {
3626
3429
  throw error_1;
3627
3430
  }
3628
- $ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
3431
+ $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
3629
3432
  return [3 /*break*/, 18];
3630
3433
  case 18:
3631
- _q = _p.next();
3434
+ _h = _g.next();
3632
3435
  return [3 /*break*/, 14];
3633
3436
  case 19: return [3 /*break*/, 22];
3634
3437
  case 20:
3635
- e_2_1 = _1.sent();
3636
- e_2 = { error: e_2_1 };
3438
+ e_1_1 = _u.sent();
3439
+ e_1 = { error: e_1_1 };
3637
3440
  return [3 /*break*/, 22];
3638
3441
  case 21:
3639
3442
  try {
3640
- if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
3443
+ if (_h && !_h.done && (_r = _g.return)) _r.call(_g);
3641
3444
  }
3642
- finally { if (e_2) throw e_2.error; }
3445
+ finally { if (e_1) throw e_1.error; }
3643
3446
  return [7 /*endfinally*/];
3644
3447
  case 22:
3645
- if ($ongoingResult.$resultString !== null) {
3448
+ if ($ongoingTemplateResult.$resultString !== null) {
3646
3449
  return [3 /*break*/, 26];
3647
3450
  }
3648
- if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
3649
- throw $ongoingResult.$scriptPipelineExecutionErrors[0];
3451
+ if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
3452
+ throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
3650
3453
  }
3651
3454
  else {
3652
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingResult.$scriptPipelineExecutionErrors
3455
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
3653
3456
  .map(function (error) { return '- ' + error.message; })
3654
- .join('\n\n')), "\n "); }));
3457
+ .join('\n\n')), "\n "); }));
3655
3458
  }
3656
3459
  case 23:
3657
3460
  if (tools.userInterface === undefined) {
3658
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3461
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3659
3462
  }
3660
3463
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3661
- _s = $ongoingResult;
3464
+ _k = $ongoingTemplateResult;
3662
3465
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3663
- promptTitle: currentTemplate.title,
3664
- promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3466
+ promptTitle: template.title,
3467
+ promptMessage: replaceParameters(template.description || '', parameters),
3665
3468
  defaultValue: replaceParameters(preparedContent, parameters),
3666
3469
  // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
3667
3470
  placeholder: undefined,
@@ -3669,46 +3472,46 @@ function executeTemplate(options) {
3669
3472
  }))];
3670
3473
  case 24:
3671
3474
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3672
- _s.$resultString = _1.sent();
3475
+ _k.$resultString = _u.sent();
3673
3476
  return [3 /*break*/, 26];
3674
- case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3477
+ case 25: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3675
3478
  case 26:
3676
- if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3677
- _1.label = 27;
3479
+ if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 43];
3480
+ _u.label = 27;
3678
3481
  case 27:
3679
- _1.trys.push([27, 41, 42, 43]);
3680
- _t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
3681
- _1.label = 28;
3482
+ _u.trys.push([27, 41, 42, 43]);
3483
+ _l = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _m = _l.next();
3484
+ _u.label = 28;
3682
3485
  case 28:
3683
- if (!!_u.done) return [3 /*break*/, 40];
3684
- functionName = _u.value;
3486
+ if (!!_m.done) return [3 /*break*/, 40];
3487
+ functionName = _m.value;
3685
3488
  postprocessingError = null;
3686
- _1.label = 29;
3489
+ _u.label = 29;
3687
3490
  case 29:
3688
- _1.trys.push([29, 36, 37, 38]);
3689
- _v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
3690
- _1.label = 30;
3491
+ _u.trys.push([29, 36, 37, 38]);
3492
+ _o = (e_2 = void 0, __values(arrayableToArray(tools.script))), _p = _o.next();
3493
+ _u.label = 30;
3691
3494
  case 30:
3692
- if (!!_w.done) return [3 /*break*/, 35];
3693
- scriptTools = _w.value;
3694
- _1.label = 31;
3495
+ if (!!_p.done) return [3 /*break*/, 35];
3496
+ scriptTools = _p.value;
3497
+ _u.label = 31;
3695
3498
  case 31:
3696
- _1.trys.push([31, 33, , 34]);
3697
- _x = $ongoingResult;
3499
+ _u.trys.push([31, 33, , 34]);
3500
+ _q = $ongoingTemplateResult;
3698
3501
  return [4 /*yield*/, scriptTools.execute({
3699
3502
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3700
3503
  script: "".concat(functionName, "(resultString)"),
3701
3504
  parameters: {
3702
- resultString: $ongoingResult.$resultString || '',
3505
+ resultString: $ongoingTemplateResult.$resultString || '',
3703
3506
  // Note: No ...parametersForTemplate, because working with result only
3704
3507
  },
3705
3508
  })];
3706
3509
  case 32:
3707
- _x.$resultString = _1.sent();
3510
+ _q.$resultString = _u.sent();
3708
3511
  postprocessingError = null;
3709
3512
  return [3 /*break*/, 35];
3710
3513
  case 33:
3711
- error_2 = _1.sent();
3514
+ error_2 = _u.sent();
3712
3515
  if (!(error_2 instanceof Error)) {
3713
3516
  throw error_2;
3714
3517
  }
@@ -3716,104 +3519,106 @@ function executeTemplate(options) {
3716
3519
  throw error_2;
3717
3520
  }
3718
3521
  postprocessingError = error_2;
3719
- $ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
3522
+ $ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
3720
3523
  return [3 /*break*/, 34];
3721
3524
  case 34:
3722
- _w = _v.next();
3525
+ _p = _o.next();
3723
3526
  return [3 /*break*/, 30];
3724
3527
  case 35: return [3 /*break*/, 38];
3725
3528
  case 36:
3726
- e_3_1 = _1.sent();
3727
- e_3 = { error: e_3_1 };
3529
+ e_2_1 = _u.sent();
3530
+ e_2 = { error: e_2_1 };
3728
3531
  return [3 /*break*/, 38];
3729
3532
  case 37:
3730
3533
  try {
3731
- if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
3534
+ if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3732
3535
  }
3733
- finally { if (e_3) throw e_3.error; }
3536
+ finally { if (e_2) throw e_2.error; }
3734
3537
  return [7 /*endfinally*/];
3735
3538
  case 38:
3736
3539
  if (postprocessingError) {
3737
3540
  throw postprocessingError;
3738
3541
  }
3739
- _1.label = 39;
3542
+ _u.label = 39;
3740
3543
  case 39:
3741
- _u = _t.next();
3544
+ _m = _l.next();
3742
3545
  return [3 /*break*/, 28];
3743
3546
  case 40: return [3 /*break*/, 43];
3744
3547
  case 41:
3745
- e_4_1 = _1.sent();
3746
- e_4 = { error: e_4_1 };
3548
+ e_3_1 = _u.sent();
3549
+ e_3 = { error: e_3_1 };
3747
3550
  return [3 /*break*/, 43];
3748
3551
  case 42:
3749
3552
  try {
3750
- if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
3553
+ if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3751
3554
  }
3752
- finally { if (e_4) throw e_4.error; }
3555
+ finally { if (e_3) throw e_3.error; }
3753
3556
  return [7 /*endfinally*/];
3754
3557
  case 43:
3755
3558
  // TODO: [πŸ’] Unite object for expecting amount and format
3756
- if (currentTemplate.format) {
3757
- if (currentTemplate.format === 'JSON') {
3758
- if (!isValidJsonString($ongoingResult.$resultString || '')) {
3559
+ if (template.format) {
3560
+ if (template.format === 'JSON') {
3561
+ if (!isValidJsonString($ongoingTemplateResult.$resultString || '')) {
3759
3562
  // TODO: [🏒] Do more universally via `FormatDefinition`
3760
3563
  try {
3761
- $ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
3564
+ $ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
3762
3565
  }
3763
3566
  catch (error) {
3764
3567
  keepUnused(error);
3765
- throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3766
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3568
+ throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3569
+ /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3767
3570
  }
3768
3571
  }
3769
3572
  }
3770
3573
  else {
3771
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(currentTemplate.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3574
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3772
3575
  }
3773
3576
  }
3774
3577
  // TODO: [πŸ’] Unite object for expecting amount and format
3775
- if (currentTemplate.expectations) {
3776
- checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
3578
+ if (template.expectations) {
3579
+ checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
3777
3580
  }
3778
3581
  return [2 /*return*/, "break-attempts"];
3779
3582
  case 44:
3780
- error_3 = _1.sent();
3583
+ error_3 = _u.sent();
3781
3584
  if (!(error_3 instanceof ExpectError)) {
3782
3585
  throw error_3;
3783
3586
  }
3784
- $ongoingResult.$expectError = error_3;
3587
+ $ongoingTemplateResult.$expectError = error_3;
3785
3588
  return [3 /*break*/, 46];
3786
3589
  case 45:
3787
3590
  if (!isJokerAttempt &&
3788
- currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
3789
- $ongoingResult.$prompt
3591
+ template.templateType === 'PROMPT_TEMPLATE' &&
3592
+ $ongoingTemplateResult.$prompt
3790
3593
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3791
3594
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3792
3595
  ) {
3793
3596
  // TODO: [🧠] Maybe put other templateTypes into report
3794
3597
  $executionReport.promptExecutions.push({
3795
- prompt: __assign({}, $ongoingResult.$prompt),
3796
- result: $ongoingResult.$result || undefined,
3797
- error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
3598
+ prompt: __assign({}, $ongoingTemplateResult.$prompt),
3599
+ result: $ongoingTemplateResult.$result || undefined,
3600
+ error: $ongoingTemplateResult.$expectError === null
3601
+ ? undefined
3602
+ : serializeError($ongoingTemplateResult.$expectError),
3798
3603
  });
3799
3604
  }
3800
3605
  return [7 /*endfinally*/];
3801
3606
  case 46:
3802
- if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
3607
+ if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
3803
3608
  throw new PipelineExecutionError(spaceTrim$1(function (block) {
3804
3609
  var _a, _b, _c;
3805
- 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) || '')
3610
+ 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) || '')
3806
3611
  .split('\n')
3807
3612
  .map(function (line) { return "> ".concat(line); })
3808
- .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) || '')
3613
+ .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) || '')
3809
3614
  .split('\n')
3810
3615
  .map(function (line) { return "> ".concat(line); })
3811
- .join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
3616
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
3812
3617
  ? 'null'
3813
- : $ongoingResult.$resultString
3618
+ : $ongoingTemplateResult.$resultString
3814
3619
  .split('\n')
3815
3620
  .map(function (line) { return "> ".concat(line); })
3816
- .join('\n')), "\n ---\n ");
3621
+ .join('\n')), "\n ---\n ");
3817
3622
  }));
3818
3623
  }
3819
3624
  return [2 /*return*/];
@@ -3821,34 +3626,279 @@ function executeTemplate(options) {
3821
3626
  });
3822
3627
  };
3823
3628
  attempt = -jokerParameterNames.length;
3824
- _h.label = 3;
3825
- case 3:
3826
- if (!(attempt < maxAttempts)) return [3 /*break*/, 6];
3827
- return [5 /*yield**/, _loop_2(attempt)];
3828
- case 4:
3829
- state_1 = _h.sent();
3629
+ _a.label = 1;
3630
+ case 1:
3631
+ if (!(attempt < maxAttempts)) return [3 /*break*/, 4];
3632
+ return [5 /*yield**/, _loop_1(attempt)];
3633
+ case 2:
3634
+ state_1 = _a.sent();
3830
3635
  switch (state_1) {
3831
- case "break-attempts": return [3 /*break*/, 6];
3636
+ case "break-attempts": return [3 /*break*/, 4];
3832
3637
  }
3833
- _h.label = 5;
3834
- case 5:
3638
+ _a.label = 3;
3639
+ case 3:
3835
3640
  attempt++;
3836
- return [3 /*break*/, 3];
3837
- case 6:
3838
- //------------------------------------
3839
- /*
3840
-
3841
-
3842
-
3843
-
3844
-
3845
-
3846
-
3847
-
3848
-
3849
- */
3850
- //------------------------------------
3851
- if ($ongoingResult.$resultString === null) {
3641
+ return [3 /*break*/, 1];
3642
+ case 4: return [2 /*return*/];
3643
+ }
3644
+ });
3645
+ });
3646
+ }
3647
+ /**
3648
+ * TODO: Break into smaller functions
3649
+ */
3650
+
3651
+ /**
3652
+ * @@@
3653
+ *
3654
+ * @private internal utility of `createPipelineExecutor`
3655
+ */
3656
+ function executeFormatCells(options) {
3657
+ return __awaiter(this, void 0, void 0, function () {
3658
+ var template;
3659
+ return __generator(this, function (_a) {
3660
+ template = options.template;
3661
+ if (template.foreach === undefined) {
3662
+ return [2 /*return*/, /* not await */ executeAttempts(options)];
3663
+ }
3664
+ throw new NotYetImplementedError('FOREACH execution not implemented yet');
3665
+ });
3666
+ });
3667
+ }
3668
+
3669
+ /**
3670
+ * Just marks a place of place where should be something implemented
3671
+ * No side effects.
3672
+ *
3673
+ * Note: It can be usefull suppressing eslint errors of unused variables
3674
+ *
3675
+ * @param value any values
3676
+ * @returns void
3677
+ * @private within the repository
3678
+ */
3679
+ function TODO_USE() {
3680
+ var value = [];
3681
+ for (var _i = 0; _i < arguments.length; _i++) {
3682
+ value[_i] = arguments[_i];
3683
+ }
3684
+ }
3685
+
3686
+ /**
3687
+ * @@@
3688
+ *
3689
+ * @private internal utility of `createPipelineExecutor`
3690
+ */
3691
+ function getContextForTemplate(template) {
3692
+ return __awaiter(this, void 0, void 0, function () {
3693
+ return __generator(this, function (_a) {
3694
+ TODO_USE(template);
3695
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
3696
+ });
3697
+ });
3698
+ }
3699
+
3700
+ /**
3701
+ * @@@
3702
+ *
3703
+ * @private internal utility of `createPipelineExecutor`
3704
+ */
3705
+ function getKnowledgeForTemplate(options) {
3706
+ return __awaiter(this, void 0, void 0, function () {
3707
+ var preparedPipeline, template;
3708
+ return __generator(this, function (_a) {
3709
+ preparedPipeline = options.preparedPipeline, template = options.template;
3710
+ // TODO: [♨] Implement Better - use real index and keyword search from `template` and {samples}
3711
+ TODO_USE(template);
3712
+ return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
3713
+ var content = _a.content;
3714
+ return "- ".concat(content);
3715
+ }).join('\n')];
3716
+ });
3717
+ });
3718
+ }
3719
+
3720
+ /**
3721
+ * @@@
3722
+ *
3723
+ * @private internal utility of `createPipelineExecutor`
3724
+ */
3725
+ function getSamplesForTemplate(template) {
3726
+ return __awaiter(this, void 0, void 0, function () {
3727
+ return __generator(this, function (_a) {
3728
+ // TODO: [♨] Implement Better - use real index and keyword search
3729
+ TODO_USE(template);
3730
+ return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
3731
+ });
3732
+ });
3733
+ }
3734
+
3735
+ /**
3736
+ * @@@
3737
+ *
3738
+ * @private internal utility of `createPipelineExecutor`
3739
+ */
3740
+ function getReservedParametersForTemplate(options) {
3741
+ return __awaiter(this, void 0, void 0, function () {
3742
+ var preparedPipeline, template, pipelineIdentification, context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_1, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3743
+ var e_1, _a;
3744
+ return __generator(this, function (_b) {
3745
+ switch (_b.label) {
3746
+ case 0:
3747
+ preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
3748
+ return [4 /*yield*/, getContextForTemplate(template)];
3749
+ case 1:
3750
+ context = _b.sent();
3751
+ return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
3752
+ case 2:
3753
+ knowledge = _b.sent();
3754
+ return [4 /*yield*/, getSamplesForTemplate(template)];
3755
+ case 3:
3756
+ samples = _b.sent();
3757
+ currentDate = new Date().toISOString();
3758
+ modelName = RESERVED_PARAMETER_MISSING_VALUE;
3759
+ reservedParameters = {
3760
+ content: RESERVED_PARAMETER_RESTRICTED,
3761
+ context: context,
3762
+ knowledge: knowledge,
3763
+ samples: samples,
3764
+ currentDate: currentDate,
3765
+ modelName: modelName,
3766
+ };
3767
+ _loop_1 = function (parameterName) {
3768
+ if (reservedParameters[parameterName] === undefined) {
3769
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3770
+ }
3771
+ };
3772
+ try {
3773
+ // Note: Doublecheck that ALL reserved parameters are defined:
3774
+ 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()) {
3775
+ parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
3776
+ _loop_1(parameterName);
3777
+ }
3778
+ }
3779
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3780
+ finally {
3781
+ try {
3782
+ if (RESERVED_PARAMETER_NAMES_1_1 && !RESERVED_PARAMETER_NAMES_1_1.done && (_a = RESERVED_PARAMETER_NAMES_1.return)) _a.call(RESERVED_PARAMETER_NAMES_1);
3783
+ }
3784
+ finally { if (e_1) throw e_1.error; }
3785
+ }
3786
+ return [2 /*return*/, reservedParameters];
3787
+ }
3788
+ });
3789
+ });
3790
+ }
3791
+
3792
+ /**
3793
+ * @@@
3794
+ *
3795
+ * @private internal utility of `createPipelineExecutor`
3796
+ */
3797
+ function executeTemplate(options) {
3798
+ return __awaiter(this, void 0, void 0, function () {
3799
+ 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;
3800
+ var e_1, _f, _g;
3801
+ return __generator(this, function (_h) {
3802
+ switch (_h.label) {
3803
+ case 0:
3804
+ 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;
3805
+ maxExecutionAttempts = settings.maxExecutionAttempts;
3806
+ name = "pipeline-executor-frame-".concat(currentTemplate.name);
3807
+ title = currentTemplate.title;
3808
+ priority = preparedPipeline.templates.length - preparedPipeline.templates.indexOf(currentTemplate);
3809
+ return [4 /*yield*/, onProgress({
3810
+ name: name,
3811
+ title: title,
3812
+ isStarted: false,
3813
+ isDone: false,
3814
+ templateType: currentTemplate.templateType,
3815
+ parameterName: currentTemplate.resultingParameterName,
3816
+ parameterValue: null,
3817
+ // <- [🍸]
3818
+ })];
3819
+ case 1:
3820
+ _h.sent();
3821
+ usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
3822
+ dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3823
+ if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3824
+ throw new UnexpectedError(spaceTrim$1(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)
3825
+ .map(function (name) { return "{".concat(name, "}"); })
3826
+ .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3827
+ .map(function (name) { return "{".concat(name, "}"); })
3828
+ .join(', '), "\n\n "); }));
3829
+ }
3830
+ _b = (_a = Object).freeze;
3831
+ _c = [{}];
3832
+ return [4 /*yield*/, getReservedParametersForTemplate({
3833
+ preparedPipeline: preparedPipeline,
3834
+ template: currentTemplate,
3835
+ pipelineIdentification: pipelineIdentification,
3836
+ })];
3837
+ case 2:
3838
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
3839
+ definedParameterNames = new Set(Object.keys(definedParameters));
3840
+ parameters = {};
3841
+ _loop_1 = function (parameterName) {
3842
+ // Situation: Parameter is defined and used
3843
+ if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3844
+ parameters[parameterName] = definedParameters[parameterName];
3845
+ }
3846
+ // Situation: Parameter is defined but NOT used
3847
+ else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
3848
+ // Situation: Parameter is NOT defined BUT used
3849
+ else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3850
+ // Houston, we have a problem
3851
+ // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3852
+ throw new UnexpectedError(spaceTrim$1(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 "); }));
3853
+ }
3854
+ };
3855
+ try {
3856
+ // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
3857
+ for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
3858
+ parameterName = _e.value;
3859
+ _loop_1(parameterName);
3860
+ }
3861
+ }
3862
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3863
+ finally {
3864
+ try {
3865
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
3866
+ }
3867
+ finally { if (e_1) throw e_1.error; }
3868
+ }
3869
+ // 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
3870
+ Object.freeze(parameters);
3871
+ $ongoingTemplateResult = {
3872
+ $result: null,
3873
+ $resultString: null,
3874
+ $expectError: null,
3875
+ $scriptPipelineExecutionErrors: [],
3876
+ };
3877
+ maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3878
+ jokerParameterNames = currentTemplate.jokerParameterNames || [];
3879
+ preparedContent = (currentTemplate.preparedContent || '{content}')
3880
+ .split('{content}')
3881
+ .join(currentTemplate.content);
3882
+ // <- TODO: [🍡] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
3883
+ return [4 /*yield*/, executeFormatCells({
3884
+ $ongoingTemplateResult: $ongoingTemplateResult,
3885
+ jokerParameterNames: jokerParameterNames,
3886
+ priority: priority,
3887
+ maxAttempts: maxAttempts,
3888
+ preparedContent: preparedContent,
3889
+ parameters: parameters,
3890
+ template: currentTemplate,
3891
+ preparedPipeline: preparedPipeline,
3892
+ tools: tools,
3893
+ llmTools: llmTools,
3894
+ settings: settings,
3895
+ $executionReport: $executionReport,
3896
+ pipelineIdentification: pipelineIdentification,
3897
+ })];
3898
+ case 3:
3899
+ // <- TODO: [🍡] Use here `replaceParameters` to replace {websiteContent} with option to ignore missing parameters
3900
+ _h.sent();
3901
+ if ($ongoingTemplateResult.$resultString === null) {
3852
3902
  throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3853
3903
  }
3854
3904
  return [4 /*yield*/, onProgress({
@@ -3858,13 +3908,13 @@ function executeTemplate(options) {
3858
3908
  isDone: true,
3859
3909
  templateType: currentTemplate.templateType,
3860
3910
  parameterName: currentTemplate.resultingParameterName,
3861
- parameterValue: $ongoingResult.$resultString,
3911
+ parameterValue: $ongoingTemplateResult.$resultString,
3862
3912
  // <- [🍸]
3863
3913
  })];
3864
- case 7:
3914
+ case 4:
3865
3915
  _h.sent();
3866
3916
  return [2 /*return*/, Object.freeze((_g = {},
3867
- _g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3917
+ _g[currentTemplate.resultingParameterName] = $ongoingTemplateResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3868
3918
  _g))];
3869
3919
  }
3870
3920
  });
@@ -4140,6 +4190,8 @@ function executePipeline(options) {
4140
4190
  .then(function () {
4141
4191
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
4142
4192
  });
4193
+ // <- Note: Errors are catched here [3]
4194
+ // 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
4143
4195
  resolving_1.push(work_1);
4144
4196
  _j.label = 4;
4145
4197
  case 4: return [2 /*return*/];