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