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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.69.0-5",
3
+ "version": "0.69.0-7",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.69.0-5"
50
+ "@promptbook/core": "0.69.0-7"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -35,7 +35,7 @@
35
35
  /**
36
36
  * The version of the Promptbook library
37
37
  */
38
- var PROMPTBOOK_VERSION = '0.69.0-4';
38
+ var PROMPTBOOK_VERSION = '0.69.0-6';
39
39
  // TODO: !!!! List here all the versions and annotate + put into script
40
40
 
41
41
  /*! *****************************************************************************
@@ -905,7 +905,7 @@
905
905
  });
906
906
  }
907
907
 
908
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-4",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-4",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-4",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-4",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"}];
908
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.69.0-6",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
909
909
 
910
910
  /**
911
911
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -3116,7 +3116,7 @@
3116
3116
  */
3117
3117
  function executeTemplate(options) {
3118
3118
  return __awaiter(this, void 0, void 0, function () {
3119
- 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;
3119
+ var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, $ongoingResult, maxAttempts, jokerParameterNames, preparedContent, _loop_2, attempt, state_1;
3120
3120
  var e_1, _f, _g;
3121
3121
  return __generator(this, function (_h) {
3122
3122
  switch (_h.label) {
@@ -3186,21 +3186,24 @@
3186
3186
  }
3187
3187
  finally { if (e_1) throw e_1.error; }
3188
3188
  }
3189
- // Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined
3189
+ // 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
3190
3190
  Object.freeze(parameters);
3191
- result = null;
3192
- resultString = null;
3193
- expectError = null;
3191
+ $ongoingResult = {
3192
+ $result: null,
3193
+ $resultString: null,
3194
+ $expectError: null,
3195
+ $scriptPipelineExecutionErrors: [],
3196
+ };
3194
3197
  maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
3195
3198
  jokerParameterNames = currentTemplate.jokerParameterNames || [];
3196
3199
  preparedContent = (currentTemplate.preparedContent || '{content}')
3197
3200
  .split('{content}')
3198
3201
  .join(currentTemplate.content);
3199
3202
  _loop_2 = function (attempt) {
3200
- 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;
3201
- var e_2, _s, e_4, _t, e_3, _u;
3202
- return __generator(this, function (_v) {
3203
- switch (_v.label) {
3203
+ var isJokerAttempt, jokerParameterName, _j, modelRequirements, _k, _l, _m, _o, _p, _q, scriptTools, _r, error_1, e_2_1, _s, _t, _u, functionName, postprocessingError, _v, _w, scriptTools, _x, error_2, e_3_1, e_4_1, error_3;
3204
+ var e_2, _y, e_4, _z, e_3, _0;
3205
+ return __generator(this, function (_1) {
3206
+ switch (_1.label) {
3204
3207
  case 0:
3205
3208
  isJokerAttempt = attempt < 0;
3206
3209
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
@@ -3208,21 +3211,21 @@
3208
3211
  if (isJokerAttempt && !jokerParameterName) {
3209
3212
  throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3210
3213
  }
3211
- result = null;
3212
- resultString = null;
3213
- expectError = null;
3214
+ $ongoingResult.$result = null;
3215
+ $ongoingResult.$resultString = null;
3216
+ $ongoingResult.$expectError = null;
3214
3217
  if (isJokerAttempt) {
3215
3218
  if (parameters[jokerParameterName] === undefined) {
3216
3219
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3217
3220
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3218
3221
  }
3219
3222
  else {
3220
- resultString = parameters[jokerParameterName];
3223
+ $ongoingResult.$resultString = parameters[jokerParameterName];
3221
3224
  }
3222
3225
  }
3223
- _v.label = 1;
3226
+ _1.label = 1;
3224
3227
  case 1:
3225
- _v.trys.push([1, 44, 45, 46]);
3228
+ _1.trys.push([1, 44, 45, 46]);
3226
3229
  if (!!isJokerAttempt) return [3 /*break*/, 26];
3227
3230
  _j = currentTemplate.templateType;
3228
3231
  switch (_j) {
@@ -3233,11 +3236,11 @@
3233
3236
  }
3234
3237
  return [3 /*break*/, 25];
3235
3238
  case 2:
3236
- resultString = replaceParameters(preparedContent, parameters);
3239
+ $ongoingResult.$resultString = replaceParameters(preparedContent, parameters);
3237
3240
  return [3 /*break*/, 26];
3238
3241
  case 3:
3239
3242
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (currentTemplate.modelRequirements || {}));
3240
- prompt = {
3243
+ $ongoingResult.$prompt = {
3241
3244
  title: currentTemplate.title,
3242
3245
  pipelineUrl: "".concat(preparedPipeline.pipelineUrl
3243
3246
  ? preparedPipeline.pipelineUrl
@@ -3259,25 +3262,32 @@
3259
3262
  case 'EMBEDDING': return [3 /*break*/, 8];
3260
3263
  }
3261
3264
  return [3 /*break*/, 10];
3262
- case 4: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
3265
+ case 4:
3266
+ _l = $ongoingResult;
3267
+ return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingResult.$prompt))];
3263
3268
  case 5:
3264
- chatResult = _v.sent();
3269
+ _l.$chatResult = _1.sent();
3265
3270
  // TODO: [🍬] Destroy chatThread
3266
- result = chatResult;
3267
- resultString = chatResult.content;
3271
+ $ongoingResult.$result = $ongoingResult.$chatResult;
3272
+ $ongoingResult.$resultString = $ongoingResult.$chatResult.content;
3268
3273
  return [3 /*break*/, 11];
3269
- case 6: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
3274
+ case 6:
3275
+ _m = $ongoingResult;
3276
+ return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingResult.$prompt))];
3270
3277
  case 7:
3271
- completionResult = _v.sent();
3272
- result = completionResult;
3273
- resultString = completionResult.content;
3278
+ _m.$completionResult = _1.sent();
3279
+ $ongoingResult.$result = $ongoingResult.$completionResult;
3280
+ $ongoingResult.$resultString = $ongoingResult.$completionResult.content;
3274
3281
  return [3 /*break*/, 11];
3275
- case 8: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
3282
+ case 8:
3283
+ // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3284
+ _o = $ongoingResult;
3285
+ return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze($ongoingResult.$prompt))];
3276
3286
  case 9:
3277
3287
  // TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
3278
- embeddingResult = _v.sent();
3279
- result = embeddingResult;
3280
- resultString = embeddingResult.content.join(',');
3288
+ _o.$embeddingResult = _1.sent();
3289
+ $ongoingResult.$result = $ongoingResult.$embeddingResult;
3290
+ $ongoingResult.$resultString = $ongoingResult.$embeddingResult.content.join(',');
3281
3291
  return [3 /*break*/, 11];
3282
3292
  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 "); }));
3283
3293
  case 11: return [3 /*break*/, 26];
@@ -3288,60 +3298,59 @@
3288
3298
  if (!currentTemplate.contentLanguage) {
3289
3299
  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 "); }));
3290
3300
  }
3291
- // TODO: DRY [1]
3292
- scriptPipelineExecutionErrors = [];
3293
- _v.label = 13;
3301
+ _1.label = 13;
3294
3302
  case 13:
3295
- _v.trys.push([13, 20, 21, 22]);
3296
- _l = (e_2 = void 0, __values(arrayableToArray(tools.script))), _m = _l.next();
3297
- _v.label = 14;
3303
+ _1.trys.push([13, 20, 21, 22]);
3304
+ _p = (e_2 = void 0, __values(arrayableToArray(tools.script))), _q = _p.next();
3305
+ _1.label = 14;
3298
3306
  case 14:
3299
- if (!!_m.done) return [3 /*break*/, 19];
3300
- scriptTools = _m.value;
3301
- _v.label = 15;
3307
+ if (!!_q.done) return [3 /*break*/, 19];
3308
+ scriptTools = _q.value;
3309
+ _1.label = 15;
3302
3310
  case 15:
3303
- _v.trys.push([15, 17, , 18]);
3311
+ _1.trys.push([15, 17, , 18]);
3312
+ _r = $ongoingResult;
3304
3313
  return [4 /*yield*/, scriptTools.execute($deepFreeze({
3305
3314
  scriptLanguage: currentTemplate.contentLanguage,
3306
3315
  script: preparedContent,
3307
3316
  parameters: parameters,
3308
3317
  }))];
3309
3318
  case 16:
3310
- resultString = _v.sent();
3319
+ _r.$resultString = _1.sent();
3311
3320
  return [3 /*break*/, 19];
3312
3321
  case 17:
3313
- error_1 = _v.sent();
3322
+ error_1 = _1.sent();
3314
3323
  if (!(error_1 instanceof Error)) {
3315
3324
  throw error_1;
3316
3325
  }
3317
3326
  if (error_1 instanceof UnexpectedError) {
3318
3327
  throw error_1;
3319
3328
  }
3320
- scriptPipelineExecutionErrors.push(error_1);
3329
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_1);
3321
3330
  return [3 /*break*/, 18];
3322
3331
  case 18:
3323
- _m = _l.next();
3332
+ _q = _p.next();
3324
3333
  return [3 /*break*/, 14];
3325
3334
  case 19: return [3 /*break*/, 22];
3326
3335
  case 20:
3327
- e_2_1 = _v.sent();
3336
+ e_2_1 = _1.sent();
3328
3337
  e_2 = { error: e_2_1 };
3329
3338
  return [3 /*break*/, 22];
3330
3339
  case 21:
3331
3340
  try {
3332
- if (_m && !_m.done && (_s = _l.return)) _s.call(_l);
3341
+ if (_q && !_q.done && (_y = _p.return)) _y.call(_p);
3333
3342
  }
3334
3343
  finally { if (e_2) throw e_2.error; }
3335
3344
  return [7 /*endfinally*/];
3336
3345
  case 22:
3337
- if (resultString !== null) {
3346
+ if ($ongoingResult.$resultString !== null) {
3338
3347
  return [3 /*break*/, 26];
3339
3348
  }
3340
- if (scriptPipelineExecutionErrors.length === 1) {
3341
- throw scriptPipelineExecutionErrors[0];
3349
+ if ($ongoingResult.$scriptPipelineExecutionErrors.length === 1) {
3350
+ throw $ongoingResult.$scriptPipelineExecutionErrors[0];
3342
3351
  }
3343
3352
  else {
3344
- 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
3353
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingResult.$scriptPipelineExecutionErrors
3345
3354
  .map(function (error) { return '- ' + error.message; })
3346
3355
  .join('\n\n')), "\n "); }));
3347
3356
  }
@@ -3349,6 +3358,8 @@
3349
3358
  if (tools.userInterface === undefined) {
3350
3359
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3351
3360
  }
3361
+ // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3362
+ _s = $ongoingResult;
3352
3363
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3353
3364
  promptTitle: currentTemplate.title,
3354
3365
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
@@ -3359,47 +3370,46 @@
3359
3370
  }))];
3360
3371
  case 24:
3361
3372
  // TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3362
- resultString = _v.sent();
3373
+ _s.$resultString = _1.sent();
3363
3374
  return [3 /*break*/, 26];
3364
3375
  case 25: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(currentTemplate.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3365
3376
  case 26:
3366
3377
  if (!(!isJokerAttempt && currentTemplate.postprocessingFunctionNames)) return [3 /*break*/, 43];
3367
- _v.label = 27;
3378
+ _1.label = 27;
3368
3379
  case 27:
3369
- _v.trys.push([27, 41, 42, 43]);
3370
- _o = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _p = _o.next();
3371
- _v.label = 28;
3380
+ _1.trys.push([27, 41, 42, 43]);
3381
+ _t = (e_4 = void 0, __values(currentTemplate.postprocessingFunctionNames)), _u = _t.next();
3382
+ _1.label = 28;
3372
3383
  case 28:
3373
- if (!!_p.done) return [3 /*break*/, 40];
3374
- functionName = _p.value;
3375
- // TODO: DRY [1]
3376
- scriptPipelineExecutionErrors = [];
3384
+ if (!!_u.done) return [3 /*break*/, 40];
3385
+ functionName = _u.value;
3377
3386
  postprocessingError = null;
3378
- _v.label = 29;
3387
+ _1.label = 29;
3379
3388
  case 29:
3380
- _v.trys.push([29, 36, 37, 38]);
3381
- _q = (e_3 = void 0, __values(arrayableToArray(tools.script))), _r = _q.next();
3382
- _v.label = 30;
3389
+ _1.trys.push([29, 36, 37, 38]);
3390
+ _v = (e_3 = void 0, __values(arrayableToArray(tools.script))), _w = _v.next();
3391
+ _1.label = 30;
3383
3392
  case 30:
3384
- if (!!_r.done) return [3 /*break*/, 35];
3385
- scriptTools = _r.value;
3386
- _v.label = 31;
3393
+ if (!!_w.done) return [3 /*break*/, 35];
3394
+ scriptTools = _w.value;
3395
+ _1.label = 31;
3387
3396
  case 31:
3388
- _v.trys.push([31, 33, , 34]);
3397
+ _1.trys.push([31, 33, , 34]);
3398
+ _x = $ongoingResult;
3389
3399
  return [4 /*yield*/, scriptTools.execute({
3390
3400
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
3391
3401
  script: "".concat(functionName, "(resultString)"),
3392
3402
  parameters: {
3393
- resultString: resultString || '',
3403
+ resultString: $ongoingResult.$resultString || '',
3394
3404
  // Note: No ...parametersForTemplate, because working with result only
3395
3405
  },
3396
3406
  })];
3397
3407
  case 32:
3398
- resultString = _v.sent();
3408
+ _x.$resultString = _1.sent();
3399
3409
  postprocessingError = null;
3400
3410
  return [3 /*break*/, 35];
3401
3411
  case 33:
3402
- error_2 = _v.sent();
3412
+ error_2 = _1.sent();
3403
3413
  if (!(error_2 instanceof Error)) {
3404
3414
  throw error_2;
3405
3415
  }
@@ -3407,19 +3417,19 @@
3407
3417
  throw error_2;
3408
3418
  }
3409
3419
  postprocessingError = error_2;
3410
- scriptPipelineExecutionErrors.push(error_2);
3420
+ $ongoingResult.$scriptPipelineExecutionErrors.push(error_2);
3411
3421
  return [3 /*break*/, 34];
3412
3422
  case 34:
3413
- _r = _q.next();
3423
+ _w = _v.next();
3414
3424
  return [3 /*break*/, 30];
3415
3425
  case 35: return [3 /*break*/, 38];
3416
3426
  case 36:
3417
- e_3_1 = _v.sent();
3427
+ e_3_1 = _1.sent();
3418
3428
  e_3 = { error: e_3_1 };
3419
3429
  return [3 /*break*/, 38];
3420
3430
  case 37:
3421
3431
  try {
3422
- if (_r && !_r.done && (_u = _q.return)) _u.call(_q);
3432
+ if (_w && !_w.done && (_0 = _v.return)) _0.call(_v);
3423
3433
  }
3424
3434
  finally { if (e_3) throw e_3.error; }
3425
3435
  return [7 /*endfinally*/];
@@ -3427,18 +3437,18 @@
3427
3437
  if (postprocessingError) {
3428
3438
  throw postprocessingError;
3429
3439
  }
3430
- _v.label = 39;
3440
+ _1.label = 39;
3431
3441
  case 39:
3432
- _p = _o.next();
3442
+ _u = _t.next();
3433
3443
  return [3 /*break*/, 28];
3434
3444
  case 40: return [3 /*break*/, 43];
3435
3445
  case 41:
3436
- e_4_1 = _v.sent();
3446
+ e_4_1 = _1.sent();
3437
3447
  e_4 = { error: e_4_1 };
3438
3448
  return [3 /*break*/, 43];
3439
3449
  case 42:
3440
3450
  try {
3441
- if (_p && !_p.done && (_t = _o.return)) _t.call(_o);
3451
+ if (_u && !_u.done && (_z = _t.return)) _z.call(_t);
3442
3452
  }
3443
3453
  finally { if (e_4) throw e_4.error; }
3444
3454
  return [7 /*endfinally*/];
@@ -3446,10 +3456,10 @@
3446
3456
  // TODO: [πŸ’] Unite object for expecting amount and format
3447
3457
  if (currentTemplate.format) {
3448
3458
  if (currentTemplate.format === 'JSON') {
3449
- if (!isValidJsonString(resultString || '')) {
3459
+ if (!isValidJsonString($ongoingResult.$resultString || '')) {
3450
3460
  // TODO: [🏒] Do more universally via `FormatDefinition`
3451
3461
  try {
3452
- resultString = extractJsonBlock(resultString || '');
3462
+ $ongoingResult.$resultString = extractJsonBlock($ongoingResult.$resultString || '');
3453
3463
  }
3454
3464
  catch (error) {
3455
3465
  keepUnused(error);
@@ -3464,45 +3474,48 @@
3464
3474
  }
3465
3475
  // TODO: [πŸ’] Unite object for expecting amount and format
3466
3476
  if (currentTemplate.expectations) {
3467
- checkExpectations(currentTemplate.expectations, resultString || '');
3477
+ checkExpectations(currentTemplate.expectations, $ongoingResult.$resultString || '');
3468
3478
  }
3469
3479
  return [2 /*return*/, "break-attempts"];
3470
3480
  case 44:
3471
- error_3 = _v.sent();
3481
+ error_3 = _1.sent();
3472
3482
  if (!(error_3 instanceof ExpectError)) {
3473
3483
  throw error_3;
3474
3484
  }
3475
- expectError = error_3;
3485
+ $ongoingResult.$expectError = error_3;
3476
3486
  return [3 /*break*/, 46];
3477
3487
  case 45:
3478
3488
  if (!isJokerAttempt &&
3479
3489
  currentTemplate.templateType === 'PROMPT_TEMPLATE' &&
3480
- prompt
3490
+ $ongoingResult.$prompt
3481
3491
  // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
3482
3492
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3483
3493
  ) {
3484
3494
  // TODO: [🧠] Maybe put other templateTypes into report
3485
3495
  $executionReport.promptExecutions.push({
3486
- prompt: __assign({}, prompt),
3487
- result: result || undefined,
3488
- error: expectError === null ? undefined : serializeError(expectError),
3496
+ prompt: __assign({}, $ongoingResult.$prompt),
3497
+ result: $ongoingResult.$result || undefined,
3498
+ error: $ongoingResult.$expectError === null ? undefined : serializeError($ongoingResult.$expectError),
3489
3499
  });
3490
3500
  }
3491
3501
  return [7 /*endfinally*/];
3492
3502
  case 46:
3493
- if (expectError !== null && attempt === maxAttempts - 1) {
3494
- 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
3495
- .split('\n')
3496
- .map(function (line) { return "> ".concat(line); })
3497
- .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) || '')
3498
- .split('\n')
3499
- .map(function (line) { return "> ".concat(line); })
3500
- .join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
3501
- ? 'null'
3502
- : resultString
3503
+ if ($ongoingResult.$expectError !== null && attempt === maxAttempts - 1) {
3504
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
3505
+ var _a, _b, _c;
3506
+ return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
3503
3507
  .split('\n')
3504
3508
  .map(function (line) { return "> ".concat(line); })
3505
- .join('\n')), "\n ---\n "); }));
3509
+ .join('\n')), "\n\n Last error ").concat(((_b = $ongoingResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
3510
+ .split('\n')
3511
+ .map(function (line) { return "> ".concat(line); })
3512
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingResult.$resultString === null
3513
+ ? 'null'
3514
+ : $ongoingResult.$resultString
3515
+ .split('\n')
3516
+ .map(function (line) { return "> ".concat(line); })
3517
+ .join('\n')), "\n ---\n ");
3518
+ }));
3506
3519
  }
3507
3520
  return [2 /*return*/];
3508
3521
  }
@@ -3536,7 +3549,7 @@
3536
3549
 
3537
3550
  */
3538
3551
  //------------------------------------
3539
- if (resultString === null) {
3552
+ if ($ongoingResult.$resultString === null) {
3540
3553
  throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3541
3554
  }
3542
3555
  return [4 /*yield*/, onProgress({
@@ -3546,13 +3559,13 @@
3546
3559
  isDone: true,
3547
3560
  templateType: currentTemplate.templateType,
3548
3561
  parameterName: currentTemplate.resultingParameterName,
3549
- parameterValue: resultString,
3562
+ parameterValue: $ongoingResult.$resultString,
3550
3563
  // <- [🍸]
3551
3564
  })];
3552
3565
  case 7:
3553
3566
  _h.sent();
3554
3567
  return [2 /*return*/, Object.freeze((_g = {},
3555
- _g[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3568
+ _g[currentTemplate.resultingParameterName] = $ongoingResult.$resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */,
3556
3569
  _g))];
3557
3570
  }
3558
3571
  });