@promptbook/cli 0.67.2 β†’ 0.67.3

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
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.67.1';
42
+ var PROMPTBOOK_VERSION = '0.67.2';
43
43
  // TODO: !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -1053,7 +1053,7 @@
1053
1053
  });
1054
1054
  }
1055
1055
 
1056
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.1",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],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.67.1",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],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.67.1",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],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.67.1",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},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- 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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1056
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.2",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],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.67.2",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],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.67.2",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],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.67.2",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT"},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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1057
1057
 
1058
1058
  /**
1059
1059
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -2981,13 +2981,24 @@
2981
2981
  var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
2982
2982
  var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.isVerbose, isVerbose = _d === void 0 ? IS_VERBOSE : _d, _e = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e;
2983
2983
  validatePipeline(pipeline);
2984
+ var pipelineIdentification = (function () {
2985
+ // Note: This is a 😐 implementation of [🚞]
2986
+ var _ = [];
2987
+ if (pipeline.sourceFile !== undefined) {
2988
+ _.push("File: ".concat(pipeline.sourceFile));
2989
+ }
2990
+ if (pipeline.pipelineUrl !== undefined) {
2991
+ _.push("Url: ".concat(pipeline.pipelineUrl));
2992
+ }
2993
+ return _.join('\n');
2994
+ })();
2984
2995
  var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
2985
2996
  var preparedPipeline;
2986
2997
  if (isPipelinePrepared(pipeline)) {
2987
2998
  preparedPipeline = pipeline;
2988
2999
  }
2989
3000
  else if (isNotPreparedWarningSupressed !== true) {
2990
- console.warn(spaceTrim.spaceTrim("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
3001
+ console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
2991
3002
  }
2992
3003
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2993
3004
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
@@ -3025,7 +3036,7 @@
3025
3036
  }
3026
3037
  function getReservedParametersForTemplate(template) {
3027
3038
  return __awaiter(this, void 0, void 0, function () {
3028
- var context, knowledge, samples, currentDate, modelName, reservedParameters, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3039
+ var context, knowledge, samples, currentDate, modelName, reservedParameters, _loop_3, RESERVED_PARAMETER_NAMES_1, RESERVED_PARAMETER_NAMES_1_1, parameterName;
3029
3040
  var e_3, _a;
3030
3041
  return __generator(this, function (_b) {
3031
3042
  switch (_b.label) {
@@ -3048,13 +3059,16 @@
3048
3059
  currentDate: currentDate,
3049
3060
  modelName: modelName,
3050
3061
  };
3062
+ _loop_3 = function (parameterName) {
3063
+ if (reservedParameters[parameterName] === undefined) {
3064
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3065
+ }
3066
+ };
3051
3067
  try {
3052
3068
  // Note: Doublecheck that ALL reserved parameters are defined:
3053
3069
  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()) {
3054
3070
  parameterName = RESERVED_PARAMETER_NAMES_1_1.value;
3055
- if (reservedParameters[parameterName] === undefined) {
3056
- throw new UnexpectedError("Reserved parameter {".concat(parameterName, "} is not defined"));
3057
- }
3071
+ _loop_3(parameterName);
3058
3072
  }
3059
3073
  }
3060
3074
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -3071,10 +3085,10 @@
3071
3085
  }
3072
3086
  function executeSingleTemplate(currentTemplate) {
3073
3087
  return __awaiter(this, void 0, void 0, function () {
3074
- var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
3075
- var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
3076
- return __generator(this, function (_u) {
3077
- switch (_u.label) {
3088
+ var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_4, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, _loop_5, attempt, state_2;
3089
+ var e_4, _f, _g;
3090
+ return __generator(this, function (_h) {
3091
+ switch (_h.label) {
3078
3092
  case 0:
3079
3093
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
3080
3094
  title = currentTemplate.title;
@@ -3091,47 +3105,48 @@
3091
3105
  // <- [3]
3092
3106
  })];
3093
3107
  case 1:
3094
- _u.sent();
3095
- _u.label = 2;
3108
+ _h.sent();
3109
+ _h.label = 2;
3096
3110
  case 2:
3097
3111
  usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3098
3112
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3099
3113
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3100
- throw new UnexpectedError(spaceTrim.spaceTrim("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
3114
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n "); }));
3101
3115
  }
3102
3116
  _b = (_a = Object).freeze;
3103
3117
  _c = [{}];
3104
3118
  return [4 /*yield*/, getReservedParametersForTemplate(currentTemplate)];
3105
3119
  case 3:
3106
- definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_u.sent())])), parametersToPass])]);
3120
+ definedParameters = _b.apply(_a, [__assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_h.sent())])), parametersToPass])]);
3107
3121
  definedParameterNames = new Set(Object.keys(definedParameters));
3108
3122
  parameters = {};
3123
+ _loop_4 = function (parameterName) {
3124
+ // Situation: Parameter is defined and used
3125
+ if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3126
+ parameters[parameterName] = definedParameters[parameterName];
3127
+ }
3128
+ // Situation: Parameter is defined but NOT used
3129
+ else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) ;
3130
+ // Situation: Parameter is NOT defined BUT used
3131
+ else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3132
+ // Houston, we have a problem
3133
+ // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3134
+ 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 "); }));
3135
+ }
3136
+ };
3109
3137
  try {
3110
3138
  // Note: [2] Check that all used parameters are defined and removing unused parameters for this template
3111
3139
  for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
3112
3140
  parameterName = _e.value;
3113
- // Situation: Parameter is defined and used
3114
- if (definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3115
- parameters[parameterName] = definedParameters[parameterName];
3116
- }
3117
- // Situation: Parameter is defined but NOT used
3118
- else if (definedParameterNames.has(parameterName) && !usedParameterNames.has(parameterName)) {
3119
- // Do not pass this parameter to prompt
3120
- }
3121
- // Situation: Parameter is NOT defined BUT used
3122
- else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
3123
- // Houston, we have a problem
3124
- // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
3125
- throw new UnexpectedError(spaceTrim.spaceTrim("\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 ")));
3126
- }
3141
+ _loop_4(parameterName);
3127
3142
  }
3128
3143
  }
3129
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
3144
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
3130
3145
  finally {
3131
3146
  try {
3132
- if (_e && !_e.done && (_p = _d.return)) _p.call(_d);
3147
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
3133
3148
  }
3134
- finally { if (e_7) throw e_7.error; }
3149
+ finally { if (e_4) throw e_4.error; }
3135
3150
  }
3136
3151
  // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
3137
3152
  Object.freeze(parameters);
@@ -3143,294 +3158,310 @@
3143
3158
  preparedContent = (currentTemplate.preparedContent || '{content}')
3144
3159
  .split('{content}')
3145
3160
  .join(currentTemplate.content);
3161
+ _loop_5 = function (attempt) {
3162
+ var isJokerAttempt, jokerParameterName, _j, _k, _l, _m, scriptTools, error_2, e_5_1, _o, _p, functionName, postprocessingError, _q, _r, scriptTools, error_3, e_6_1, e_7_1, error_4;
3163
+ var e_5, _s, e_7, _t, e_6, _u;
3164
+ return __generator(this, function (_v) {
3165
+ switch (_v.label) {
3166
+ case 0:
3167
+ isJokerAttempt = attempt < 0;
3168
+ jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3169
+ if (isJokerAttempt && !jokerParameterName) {
3170
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3171
+ }
3172
+ result = null;
3173
+ resultString = null;
3174
+ expectError = null;
3175
+ if (isJokerAttempt) {
3176
+ if (parameters[jokerParameterName] === undefined) {
3177
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3178
+ // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3179
+ }
3180
+ else {
3181
+ resultString = parameters[jokerParameterName];
3182
+ }
3183
+ }
3184
+ _v.label = 1;
3185
+ case 1:
3186
+ _v.trys.push([1, 44, 45, 46]);
3187
+ if (!!isJokerAttempt) return [3 /*break*/, 26];
3188
+ _j = currentTemplate.blockType;
3189
+ switch (_j) {
3190
+ case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
3191
+ case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
3192
+ case 'SCRIPT': return [3 /*break*/, 12];
3193
+ case 'PROMPT_DIALOG': return [3 /*break*/, 23];
3194
+ }
3195
+ return [3 /*break*/, 25];
3196
+ case 2:
3197
+ resultString = replaceParameters(preparedContent, parameters);
3198
+ return [3 /*break*/, 26];
3199
+ case 3:
3200
+ prompt = {
3201
+ title: currentTemplate.title,
3202
+ pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3203
+ ? preparedPipeline.pipelineUrl
3204
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3205
+ parameters: parameters,
3206
+ content: preparedContent,
3207
+ modelRequirements: currentTemplate.modelRequirements,
3208
+ expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3209
+ var name = _a.name;
3210
+ return name === currentTemplate.personaName;
3211
+ }) || {})), currentTemplate.expectations),
3212
+ expectFormat: currentTemplate.expectFormat,
3213
+ postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3214
+ }; // <- TODO: Not very good type guard
3215
+ _k = currentTemplate.modelRequirements.modelVariant;
3216
+ switch (_k) {
3217
+ case 'CHAT': return [3 /*break*/, 4];
3218
+ case 'COMPLETION': return [3 /*break*/, 6];
3219
+ case 'EMBEDDING': return [3 /*break*/, 8];
3220
+ }
3221
+ return [3 /*break*/, 10];
3222
+ case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
3223
+ case 5:
3224
+ chatResult = _v.sent();
3225
+ // TODO: [🍬] Destroy chatThread
3226
+ result = chatResult;
3227
+ resultString = chatResult.content;
3228
+ return [3 /*break*/, 11];
3229
+ case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
3230
+ case 7:
3231
+ completionResult = _v.sent();
3232
+ result = completionResult;
3233
+ resultString = completionResult.content;
3234
+ return [3 /*break*/, 11];
3235
+ case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
3236
+ case 9:
3237
+ embeddingResult = _v.sent();
3238
+ result = embeddingResult;
3239
+ resultString = embeddingResult.content.join(',');
3240
+ return [3 /*break*/, 11];
3241
+ 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\n "); }));
3242
+ case 11: return [3 /*break*/, 26];
3243
+ case 12:
3244
+ if (arrayableToArray(tools.script).length === 0) {
3245
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3246
+ }
3247
+ if (!currentTemplate.contentLanguage) {
3248
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for prompt template \"".concat(currentTemplate.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3249
+ }
3250
+ // TODO: DRY [1]
3251
+ scriptPipelineExecutionErrors = [];
3252
+ _v.label = 13;
3253
+ case 13:
3254
+ _v.trys.push([13, 20, 21, 22]);
3255
+ _l = (e_5 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
3256
+ _v.label = 14;
3257
+ case 14:
3258
+ if (!!_m.done) return [3 /*break*/, 19];
3259
+ scriptTools = _m.value;
3260
+ _v.label = 15;
3261
+ case 15:
3262
+ _v.trys.push([15, 17, , 18]);
3263
+ return [4 /*yield*/, scriptTools.execute($deepFreeze({
3264
+ scriptLanguage: currentTemplate.contentLanguage,
3265
+ script: preparedContent,
3266
+ parameters: parameters,
3267
+ }))];
3268
+ case 16:
3269
+ resultString = _v.sent();
3270
+ return [3 /*break*/, 19];
3271
+ case 17:
3272
+ error_2 = _v.sent();
3273
+ if (!(error_2 instanceof Error)) {
3274
+ throw error_2;
3275
+ }
3276
+ if (error_2 instanceof UnexpectedError) {
3277
+ throw error_2;
3278
+ }
3279
+ scriptPipelineExecutionErrors.push(error_2);
3280
+ return [3 /*break*/, 18];
3281
+ case 18:
3282
+ _m = _l.next();
3283
+ return [3 /*break*/, 14];
3284
+ case 19: return [3 /*break*/, 22];
3285
+ case 20:
3286
+ e_5_1 = _v.sent();
3287
+ e_5 = { error: e_5_1 };
3288
+ return [3 /*break*/, 22];
3289
+ case 21:
3290
+ try {
3291
+ if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3292
+ }
3293
+ finally { if (e_5) throw e_5.error; }
3294
+ return [7 /*endfinally*/];
3295
+ case 22:
3296
+ if (resultString !== null) {
3297
+ return [3 /*break*/, 26];
3298
+ }
3299
+ if (scriptPipelineExecutionErrors.length === 1) {
3300
+ throw scriptPipelineExecutionErrors[0];
3301
+ }
3302
+ else {
3303
+ 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
3304
+ .map(function (error) { return '- ' + error.message; })
3305
+ .join('\n\n')), "\n "); }));
3306
+ }
3307
+ case 23:
3308
+ if (tools.userInterface === undefined) {
3309
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3310
+ }
3311
+ return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3312
+ promptTitle: currentTemplate.title,
3313
+ promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3314
+ defaultValue: replaceParameters(preparedContent, parameters),
3315
+ // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
3316
+ placeholder: undefined,
3317
+ priority: priority,
3318
+ }))];
3319
+ case 24:
3320
+ // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
3321
+ resultString = _v.sent();
3322
+ return [3 /*break*/, 26];
3323
+ case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.blockType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3324
+ case 26:
3325
+ if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3326
+ _v.label = 27;
3327
+ case 27:
3328
+ _v.trys.push([27, 41, 42, 43]);
3329
+ _o = (e_7 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
3330
+ _v.label = 28;
3331
+ case 28:
3332
+ if (!!_p.done) return [3 /*break*/, 40];
3333
+ functionName = _p.value;
3334
+ // TODO: DRY [1]
3335
+ scriptPipelineExecutionErrors = [];
3336
+ postprocessingError = null;
3337
+ _v.label = 29;
3338
+ case 29:
3339
+ _v.trys.push([29, 36, 37, 38]);
3340
+ _q = (e_6 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
3341
+ _v.label = 30;
3342
+ case 30:
3343
+ if (!!_r.done) return [3 /*break*/, 35];
3344
+ scriptTools = _r.value;
3345
+ _v.label = 31;
3346
+ case 31:
3347
+ _v.trys.push([31, 33, , 34]);
3348
+ return [4 /*yield*/, scriptTools.execute({
3349
+ scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3350
+ script: "".concat(functionName, "(resultString)"),
3351
+ parameters: {
3352
+ resultString: resultString || '',
3353
+ // Note: No ...parametersForTemplate, because working with result only
3354
+ },
3355
+ })];
3356
+ case 32:
3357
+ resultString = _v.sent();
3358
+ postprocessingError = null;
3359
+ return [3 /*break*/, 35];
3360
+ case 33:
3361
+ error_3 = _v.sent();
3362
+ if (!(error_3 instanceof Error)) {
3363
+ throw error_3;
3364
+ }
3365
+ if (error_3 instanceof UnexpectedError) {
3366
+ throw error_3;
3367
+ }
3368
+ postprocessingError = error_3;
3369
+ scriptPipelineExecutionErrors.push(error_3);
3370
+ return [3 /*break*/, 34];
3371
+ case 34:
3372
+ _r = _q.next();
3373
+ return [3 /*break*/, 30];
3374
+ case 35: return [3 /*break*/, 38];
3375
+ case 36:
3376
+ e_6_1 = _v.sent();
3377
+ e_6 = { error: e_6_1 };
3378
+ return [3 /*break*/, 38];
3379
+ case 37:
3380
+ try {
3381
+ if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
3382
+ }
3383
+ finally { if (e_6) throw e_6.error; }
3384
+ return [7 /*endfinally*/];
3385
+ case 38:
3386
+ if (postprocessingError) {
3387
+ throw postprocessingError;
3388
+ }
3389
+ _v.label = 39;
3390
+ case 39:
3391
+ _p = _o.next();
3392
+ return [3 /*break*/, 28];
3393
+ case 40: return [3 /*break*/, 43];
3394
+ case 41:
3395
+ e_7_1 = _v.sent();
3396
+ e_7 = { error: e_7_1 };
3397
+ return [3 /*break*/, 43];
3398
+ case 42:
3399
+ try {
3400
+ if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3401
+ }
3402
+ finally { if (e_7) throw e_7.error; }
3403
+ return [7 /*endfinally*/];
3404
+ case 43:
3405
+ // TODO: [πŸ’] Unite object for expecting amount and format
3406
+ if (currentTemplate.expectFormat) {
3407
+ if (currentTemplate.expectFormat === 'JSON') {
3408
+ if (!isValidJsonString(resultString || '')) {
3409
+ throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(pipelineIdentification), "\n "); }));
3410
+ }
3411
+ }
3412
+ }
3413
+ // TODO: [πŸ’] Unite object for expecting amount and format
3414
+ if (currentTemplate.expectations) {
3415
+ checkExpectations(currentTemplate.expectations, resultString || '');
3416
+ }
3417
+ return [2 /*return*/, "break-attempts"];
3418
+ case 44:
3419
+ error_4 = _v.sent();
3420
+ if (!(error_4 instanceof ExpectError)) {
3421
+ throw error_4;
3422
+ }
3423
+ expectError = error_4;
3424
+ return [3 /*break*/, 46];
3425
+ case 45:
3426
+ if (!isJokerAttempt &&
3427
+ currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
3428
+ prompt
3429
+ // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3430
+ // In that case we don’t want to make a report about it because it’s not a llm execution error
3431
+ ) {
3432
+ // TODO: [🧠] Maybe put other blockTypes into report
3433
+ executionReport.promptExecutions.push({
3434
+ prompt: __assign({}, prompt),
3435
+ result: result || undefined,
3436
+ error: expectError === null ? undefined : serializeError(expectError),
3437
+ });
3438
+ }
3439
+ return [7 /*endfinally*/];
3440
+ case 46:
3441
+ if (expectError !== null && attempt === maxAttempts - 1) {
3442
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\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) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
3443
+ }
3444
+ return [2 /*return*/];
3445
+ }
3446
+ });
3447
+ };
3146
3448
  attempt = -jokerParameterNames.length;
3147
- _u.label = 4;
3449
+ _h.label = 4;
3148
3450
  case 4:
3149
- if (!(attempt < maxAttempts)) return [3 /*break*/, 52];
3150
- isJokerAttempt = attempt < 0;
3151
- jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3152
- if (isJokerAttempt && !jokerParameterName) {
3153
- throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
3154
- }
3155
- result = null;
3156
- resultString = null;
3157
- expectError = null;
3158
- if (isJokerAttempt) {
3159
- if (parameters[jokerParameterName] === undefined) {
3160
- throw new PipelineExecutionError("Joker parameter {".concat(jokerParameterName, "} not defined"));
3161
- // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3162
- }
3163
- else {
3164
- resultString = parameters[jokerParameterName];
3165
- }
3166
- }
3167
- _u.label = 5;
3451
+ if (!(attempt < maxAttempts)) return [3 /*break*/, 7];
3452
+ return [5 /*yield**/, _loop_5(attempt)];
3168
3453
  case 5:
3169
- _u.trys.push([5, 48, 49, 50]);
3170
- if (!!isJokerAttempt) return [3 /*break*/, 30];
3171
- _f = currentTemplate.blockType;
3172
- switch (_f) {
3173
- case 'SIMPLE_TEMPLATE': return [3 /*break*/, 6];
3174
- case 'PROMPT_TEMPLATE': return [3 /*break*/, 7];
3175
- case 'SCRIPT': return [3 /*break*/, 16];
3176
- case 'PROMPT_DIALOG': return [3 /*break*/, 27];
3454
+ state_2 = _h.sent();
3455
+ switch (state_2) {
3456
+ case "break-attempts": return [3 /*break*/, 7];
3177
3457
  }
3178
- return [3 /*break*/, 29];
3458
+ _h.label = 6;
3179
3459
  case 6:
3180
- resultString = replaceParameters(preparedContent, parameters);
3181
- return [3 /*break*/, 30];
3182
- case 7:
3183
- prompt = {
3184
- title: currentTemplate.title,
3185
- pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3186
- ? preparedPipeline.pipelineUrl
3187
- : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
3188
- parameters: parameters,
3189
- content: preparedContent,
3190
- modelRequirements: currentTemplate.modelRequirements,
3191
- expectations: __assign(__assign({}, (preparedPipeline.personas.find(function (_a) {
3192
- var name = _a.name;
3193
- return name === currentTemplate.personaName;
3194
- }) || {})), currentTemplate.expectations),
3195
- expectFormat: currentTemplate.expectFormat,
3196
- postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3197
- }; // <- TODO: Not very good type guard
3198
- _g = currentTemplate.modelRequirements.modelVariant;
3199
- switch (_g) {
3200
- case 'CHAT': return [3 /*break*/, 8];
3201
- case 'COMPLETION': return [3 /*break*/, 10];
3202
- case 'EMBEDDING': return [3 /*break*/, 12];
3203
- }
3204
- return [3 /*break*/, 14];
3205
- case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
3206
- case 9:
3207
- chatResult = _u.sent();
3208
- // TODO: [🍬] Destroy chatThread
3209
- result = chatResult;
3210
- resultString = chatResult.content;
3211
- return [3 /*break*/, 15];
3212
- case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
3213
- case 11:
3214
- completionResult = _u.sent();
3215
- result = completionResult;
3216
- resultString = completionResult.content;
3217
- return [3 /*break*/, 15];
3218
- case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
3219
- case 13:
3220
- embeddingResult = _u.sent();
3221
- result = embeddingResult;
3222
- resultString = embeddingResult.content.join(',');
3223
- return [3 /*break*/, 15];
3224
- case 14: throw new PipelineExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
3225
- case 15: return [3 /*break*/, 30];
3226
- case 16:
3227
- if (arrayableToArray(tools.script).length === 0) {
3228
- throw new PipelineExecutionError('No script execution tools are available');
3229
- }
3230
- if (!currentTemplate.contentLanguage) {
3231
- throw new PipelineExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
3232
- }
3233
- // TODO: DRY [1]
3234
- scriptPipelineExecutionErrors = [];
3235
- _u.label = 17;
3236
- case 17:
3237
- _u.trys.push([17, 24, 25, 26]);
3238
- _h = (e_4 = void 0, __values(arrayableToArray(tools.script))), _j = _h.next();
3239
- _u.label = 18;
3240
- case 18:
3241
- if (!!_j.done) return [3 /*break*/, 23];
3242
- scriptTools = _j.value;
3243
- _u.label = 19;
3244
- case 19:
3245
- _u.trys.push([19, 21, , 22]);
3246
- return [4 /*yield*/, scriptTools.execute($deepFreeze({
3247
- scriptLanguage: currentTemplate.contentLanguage,
3248
- script: preparedContent,
3249
- parameters: parameters,
3250
- }))];
3251
- case 20:
3252
- resultString = _u.sent();
3253
- return [3 /*break*/, 23];
3254
- case 21:
3255
- error_2 = _u.sent();
3256
- if (!(error_2 instanceof Error)) {
3257
- throw error_2;
3258
- }
3259
- if (error_2 instanceof UnexpectedError) {
3260
- throw error_2;
3261
- }
3262
- scriptPipelineExecutionErrors.push(error_2);
3263
- return [3 /*break*/, 22];
3264
- case 22:
3265
- _j = _h.next();
3266
- return [3 /*break*/, 18];
3267
- case 23: return [3 /*break*/, 26];
3268
- case 24:
3269
- e_4_1 = _u.sent();
3270
- e_4 = { error: e_4_1 };
3271
- return [3 /*break*/, 26];
3272
- case 25:
3273
- try {
3274
- if (_j && !_j.done && (_q = _h.return)) _q.call(_h);
3275
- }
3276
- finally { if (e_4) throw e_4.error; }
3277
- return [7 /*endfinally*/];
3278
- case 26:
3279
- if (resultString !== null) {
3280
- return [3 /*break*/, 30];
3281
- }
3282
- if (scriptPipelineExecutionErrors.length === 1) {
3283
- throw scriptPipelineExecutionErrors[0];
3284
- }
3285
- else {
3286
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
3287
- .map(function (error) { return '- ' + error.message; })
3288
- .join('\n\n')), "\n "); }));
3289
- }
3290
- case 27:
3291
- if (tools.userInterface === undefined) {
3292
- throw new PipelineExecutionError('User interface tools are not available');
3293
- }
3294
- return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3295
- promptTitle: currentTemplate.title,
3296
- promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3297
- defaultValue: replaceParameters(preparedContent, parameters),
3298
- // TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
3299
- placeholder: undefined,
3300
- priority: priority,
3301
- }))];
3302
- case 28:
3303
- // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
3304
- resultString = _u.sent();
3305
- return [3 /*break*/, 30];
3306
- case 29: throw new PipelineExecutionError("Unknown execution type \"".concat(currentTemplate.blockType, "\""));
3307
- case 30:
3308
- if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 47];
3309
- _u.label = 31;
3310
- case 31:
3311
- _u.trys.push([31, 45, 46, 47]);
3312
- _k = (e_6 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _l = _k.next();
3313
- _u.label = 32;
3314
- case 32:
3315
- if (!!_l.done) return [3 /*break*/, 44];
3316
- functionName = _l.value;
3317
- // TODO: DRY [1]
3318
- scriptPipelineExecutionErrors = [];
3319
- postprocessingError = null;
3320
- _u.label = 33;
3321
- case 33:
3322
- _u.trys.push([33, 40, 41, 42]);
3323
- _m = (e_5 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
3324
- _u.label = 34;
3325
- case 34:
3326
- if (!!_o.done) return [3 /*break*/, 39];
3327
- scriptTools = _o.value;
3328
- _u.label = 35;
3329
- case 35:
3330
- _u.trys.push([35, 37, , 38]);
3331
- return [4 /*yield*/, scriptTools.execute({
3332
- scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3333
- script: "".concat(functionName, "(resultString)"),
3334
- parameters: {
3335
- resultString: resultString || '',
3336
- // Note: No ...parametersForTemplate, because working with result only
3337
- },
3338
- })];
3339
- case 36:
3340
- resultString = _u.sent();
3341
- postprocessingError = null;
3342
- return [3 /*break*/, 39];
3343
- case 37:
3344
- error_3 = _u.sent();
3345
- if (!(error_3 instanceof Error)) {
3346
- throw error_3;
3347
- }
3348
- if (error_3 instanceof UnexpectedError) {
3349
- throw error_3;
3350
- }
3351
- postprocessingError = error_3;
3352
- scriptPipelineExecutionErrors.push(error_3);
3353
- return [3 /*break*/, 38];
3354
- case 38:
3355
- _o = _m.next();
3356
- return [3 /*break*/, 34];
3357
- case 39: return [3 /*break*/, 42];
3358
- case 40:
3359
- e_5_1 = _u.sent();
3360
- e_5 = { error: e_5_1 };
3361
- return [3 /*break*/, 42];
3362
- case 41:
3363
- try {
3364
- if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
3365
- }
3366
- finally { if (e_5) throw e_5.error; }
3367
- return [7 /*endfinally*/];
3368
- case 42:
3369
- if (postprocessingError) {
3370
- throw postprocessingError;
3371
- }
3372
- _u.label = 43;
3373
- case 43:
3374
- _l = _k.next();
3375
- return [3 /*break*/, 32];
3376
- case 44: return [3 /*break*/, 47];
3377
- case 45:
3378
- e_6_1 = _u.sent();
3379
- e_6 = { error: e_6_1 };
3380
- return [3 /*break*/, 47];
3381
- case 46:
3382
- try {
3383
- if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
3384
- }
3385
- finally { if (e_6) throw e_6.error; }
3386
- return [7 /*endfinally*/];
3387
- case 47:
3388
- // TODO: [πŸ’] Unite object for expecting amount and format
3389
- if (currentTemplate.expectFormat) {
3390
- if (currentTemplate.expectFormat === 'JSON') {
3391
- if (!isValidJsonString(resultString || '')) {
3392
- throw new ExpectError('Expected valid JSON string');
3393
- }
3394
- }
3395
- }
3396
- // TODO: [πŸ’] Unite object for expecting amount and format
3397
- if (currentTemplate.expectations) {
3398
- checkExpectations(currentTemplate.expectations, resultString || '');
3399
- }
3400
- return [3 /*break*/, 52];
3401
- case 48:
3402
- error_4 = _u.sent();
3403
- if (!(error_4 instanceof ExpectError)) {
3404
- throw error_4;
3405
- }
3406
- expectError = error_4;
3407
- return [3 /*break*/, 50];
3408
- case 49:
3409
- if (!isJokerAttempt &&
3410
- currentTemplate.blockType === 'PROMPT_TEMPLATE' &&
3411
- prompt
3412
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3413
- // In that case we don’t want to make a report about it because it’s not a llm execution error
3414
- ) {
3415
- // TODO: [🧠] Maybe put other blockTypes into report
3416
- executionReport.promptExecutions.push({
3417
- prompt: __assign({}, prompt),
3418
- result: result || undefined,
3419
- error: expectError === null ? undefined : serializeError(expectError),
3420
- });
3421
- }
3422
- return [7 /*endfinally*/];
3423
- case 50:
3424
- if (expectError !== null && attempt === maxAttempts - 1) {
3425
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\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) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
3426
- }
3427
- _u.label = 51;
3428
- case 51:
3429
3460
  attempt++;
3430
3461
  return [3 /*break*/, 4];
3431
- case 52:
3462
+ case 7:
3432
3463
  if (resultString === null) {
3433
- throw new UnexpectedError('Something went wrong and prompt result is null');
3464
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3434
3465
  }
3435
3466
  if (onProgress /* <- [3] */) {
3436
3467
  onProgress({
@@ -3444,7 +3475,7 @@
3444
3475
  // <- [3]
3445
3476
  });
3446
3477
  }
3447
- parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_t = {}, _t[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _t)));
3478
+ parametersToPass = Object.freeze(__assign(__assign({}, parametersToPass), (_g = {}, _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _g)));
3448
3479
  return [2 /*return*/];
3449
3480
  }
3450
3481
  });
@@ -3453,6 +3484,14 @@
3453
3484
  function filterJustOutputParameters() {
3454
3485
  var e_8, _a;
3455
3486
  var outputParameters = {};
3487
+ var _loop_6 = function (parameter) {
3488
+ if (parametersToPass[parameter.name] === undefined) {
3489
+ // [4]
3490
+ warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
3491
+ return "continue";
3492
+ }
3493
+ outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
3494
+ };
3456
3495
  try {
3457
3496
  // Note: Filter ONLY output parameters
3458
3497
  for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
@@ -3460,12 +3499,7 @@
3460
3499
  return isOutput;
3461
3500
  })), _c = _b.next(); !_c.done; _c = _b.next()) {
3462
3501
  var parameter = _c.value;
3463
- if (parametersToPass[parameter.name] === undefined) {
3464
- // [4]
3465
- warnings.push(new PipelineExecutionError("Parameter {".concat(parameter.name, "} should be an output parameter, but it was not generated during pipeline execution")));
3466
- continue;
3467
- }
3468
- outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
3502
+ _loop_6(parameter);
3469
3503
  }
3470
3504
  }
3471
3505
  catch (e_8_1) { e_8 = { error: e_8_1 }; }
@@ -3537,13 +3571,13 @@
3537
3571
  return name === parameterName;
3538
3572
  });
3539
3573
  if (parameter === undefined) {
3540
- warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3574
+ warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
3541
3575
  }
3542
3576
  else if (parameter.isInput === false) {
3543
- return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3577
+ return { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
3544
3578
  isSuccessful: false,
3545
3579
  errors: __spreadArray([
3546
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3580
+ new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
3547
3581
  ], __read(errors), false).map(serializeError),
3548
3582
  warnings: warnings.map(serializeError),
3549
3583
  executionReport: executionReport,
@@ -3592,7 +3626,7 @@
3592
3626
  case 0:
3593
3627
  if (loopLimit-- < 0) {
3594
3628
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
3595
- throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
3629
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
3596
3630
  }
3597
3631
  currentTemplate = unresovedTemplates_1.find(function (template) {
3598
3632
  return template.dependentParameterNames.every(function (name) {
@@ -3602,7 +3636,7 @@
3602
3636
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
3603
3637
  throw new UnexpectedError(
3604
3638
  // TODO: [🐎] DRY
3605
- spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3639
+ spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
3606
3640
  .map(function (_a) {
3607
3641
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
3608
3642
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
@@ -3682,6 +3716,7 @@
3682
3716
  return pipelineExecutor;
3683
3717
  }
3684
3718
  /**
3719
+ * TODO: !!! Identify not only pipeline BUT exact template ${block(pipelineIdentification)}
3685
3720
  * TODO: Use isVerbose here (not only pass to `preparePipeline`)
3686
3721
  * TODO: [🧠][🌳] Use here `countTotalUsage` and put preparation and prepared pipiline to report
3687
3722
  * TODO: [πŸͺ‚] Use maxParallelCount here (not only pass to `preparePipeline`)