@promptbook/node 0.67.7 → 0.67.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.es.js CHANGED
@@ -4,6 +4,7 @@ import { join as join$1, dirname } from 'path';
4
4
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
5
5
  import { format } from 'prettier';
6
6
  import parserHtml from 'prettier/parser-html';
7
+ import { forTime } from 'waitasecond';
7
8
  import hexEncoder from 'crypto-js/enc-hex';
8
9
  import sha256 from 'crypto-js/sha256';
9
10
  import { join } from 'path/posix';
@@ -13,7 +14,7 @@ import * as dotenv from 'dotenv';
13
14
  /**
14
15
  * The version of the Promptbook library
15
16
  */
16
- var PROMPTBOOK_VERSION = '0.67.6';
17
+ var PROMPTBOOK_VERSION = '0.67.8';
17
18
  // TODO: !!!! List here all the versions and annotate + put into script
18
19
 
19
20
  /*! *****************************************************************************
@@ -355,6 +356,12 @@ function $asDeeplyFrozenSerializableJson(name, objectValue) {
355
356
  * @private within the repository - too low-level in comparison with other `MAX_...`
356
357
  */
357
358
  var LOOP_LIMIT = 1000;
359
+ /**
360
+ * Short time interval to prevent race conditions in milliseconds
361
+ *
362
+ * @private within the repository - too low-level in comparison with other `MAX_...`
363
+ */
364
+ var IMMEDIATE_TIME = 10;
358
365
  /**
359
366
  * The maximum number of (LLM) tasks running in parallel
360
367
  *
@@ -867,7 +874,7 @@ function forEachAsync(array, options, callbackfunction) {
867
874
  });
868
875
  }
869
876
 
870
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.6",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.6",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.6",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.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}],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"}];
877
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.8",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.8",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.8",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.8",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"}];
871
878
 
872
879
  /**
873
880
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -3052,7 +3059,7 @@ function createPipelineExecutor(options) {
3052
3059
  }
3053
3060
  function executeSingleTemplate(currentTemplate) {
3054
3061
  return __awaiter(this, void 0, void 0, function () {
3055
- 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;
3062
+ var name, title, priority, progress_1, 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, progress_2;
3056
3063
  var e_4, _f, _g;
3057
3064
  return __generator(this, function (_h) {
3058
3065
  switch (_h.label) {
@@ -3060,17 +3067,24 @@ function createPipelineExecutor(options) {
3060
3067
  name = "pipeline-executor-frame-".concat(currentTemplate.name);
3061
3068
  title = currentTemplate.title;
3062
3069
  priority = preparedPipeline.promptTemplates.length - preparedPipeline.promptTemplates.indexOf(currentTemplate);
3063
- if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
3064
- return [4 /*yield*/, onProgress({
3065
- name: name,
3066
- title: title,
3067
- isStarted: false,
3068
- isDone: false,
3069
- blockType: currentTemplate.blockType,
3070
- parameterName: currentTemplate.resultingParameterName,
3071
- parameterValue: null,
3072
- // <- [3]
3073
- })];
3070
+ if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
3071
+ progress_1 = {
3072
+ name: name,
3073
+ title: title,
3074
+ isStarted: false,
3075
+ isDone: false,
3076
+ blockType: currentTemplate.blockType,
3077
+ parameterName: currentTemplate.resultingParameterName,
3078
+ parameterValue: null,
3079
+ // <- [3]
3080
+ };
3081
+ if (isReturned) {
3082
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished \uD83C\uDF4F\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress_1, null, 4)
3083
+ .split('\n')
3084
+ .map(function (line) { return "> ".concat(line); })
3085
+ .join('\n')), "\n "); }));
3086
+ }
3087
+ return [4 /*yield*/, onProgress(progress_1)];
3074
3088
  case 1:
3075
3089
  _h.sent();
3076
3090
  _h.label = 2;
@@ -3456,18 +3470,28 @@ function createPipelineExecutor(options) {
3456
3470
  if (resultString === null) {
3457
3471
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
3458
3472
  }
3459
- if (onProgress /* <- [3] */) {
3460
- onProgress({
3461
- name: name,
3462
- title: title,
3463
- isStarted: true,
3464
- isDone: true,
3465
- blockType: currentTemplate.blockType,
3466
- parameterName: currentTemplate.resultingParameterName,
3467
- parameterValue: resultString,
3468
- // <- [3]
3469
- });
3473
+ if (!(onProgress !== undefined) /* <- [3] */) return [3 /*break*/, 9]; /* <- [3] */
3474
+ progress_2 = {
3475
+ name: name,
3476
+ title: title,
3477
+ isStarted: true,
3478
+ isDone: true,
3479
+ blockType: currentTemplate.blockType,
3480
+ parameterName: currentTemplate.resultingParameterName,
3481
+ parameterValue: resultString,
3482
+ // <- [3]
3483
+ };
3484
+ if (isReturned) {
3485
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished \uD83C\uDF4E\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress_2, null, 4)
3486
+ .split('\n')
3487
+ .map(function (line) { return "> ".concat(line); })
3488
+ .join('\n')), "\n\n "); }));
3470
3489
  }
3490
+ return [4 /*yield*/, onProgress(progress_2)];
3491
+ case 8:
3492
+ _h.sent();
3493
+ _h.label = 9;
3494
+ case 9:
3471
3495
  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)));
3472
3496
  return [2 /*return*/];
3473
3497
  }
@@ -3504,7 +3528,7 @@ function createPipelineExecutor(options) {
3504
3528
  }
3505
3529
  return outputParameters;
3506
3530
  }
3507
- var errors, warnings, executionReport, _a, _b, parameter, _loop_1, _c, _d, parameterName, state_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
3531
+ var errors, warnings, executionReport, isReturned, _a, _b, parameter, e_1_1, _loop_1, _c, _d, parameterName, state_1, e_2_1, parametersToPass, resovedParameterNames_1, unresovedTemplates_1, resolving_1, loopLimit, _loop_2, error_1, usage_1, outputParameters_1, usage, outputParameters;
3508
3532
  var e_1, _e, e_2, _f;
3509
3533
  return __generator(this, function (_g) {
3510
3534
  switch (_g.label) {
@@ -3529,77 +3553,123 @@ function createPipelineExecutor(options) {
3529
3553
  description: preparedPipeline.description,
3530
3554
  promptExecutions: [],
3531
3555
  };
3556
+ isReturned = false;
3557
+ _g.label = 3;
3558
+ case 3:
3559
+ _g.trys.push([3, 9, 10, 11]);
3560
+ _a = __values(preparedPipeline.parameters.filter(function (_a) {
3561
+ var isInput = _a.isInput;
3562
+ return isInput;
3563
+ })), _b = _a.next();
3564
+ _g.label = 4;
3565
+ case 4:
3566
+ if (!!_b.done) return [3 /*break*/, 8];
3567
+ parameter = _b.value;
3568
+ if (!(inputParameters[parameter.name] === undefined)) return [3 /*break*/, 7];
3569
+ isReturned = true;
3570
+ if (!(onProgress !== undefined)) return [3 /*break*/, 6];
3571
+ // Note: Wait a short time to prevent race conditions
3572
+ return [4 /*yield*/, forTime(IMMEDIATE_TIME)];
3573
+ case 5:
3574
+ // Note: Wait a short time to prevent race conditions
3575
+ _g.sent();
3576
+ _g.label = 6;
3577
+ case 6: return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3578
+ isSuccessful: false,
3579
+ errors: __spreadArray([
3580
+ new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3581
+ ], __read(errors), false).map(serializeError),
3582
+ warnings: [],
3583
+ executionReport: executionReport,
3584
+ outputParameters: {},
3585
+ usage: ZERO_USAGE,
3586
+ preparedPipeline: preparedPipeline,
3587
+ })];
3588
+ case 7:
3589
+ _b = _a.next();
3590
+ return [3 /*break*/, 4];
3591
+ case 8: return [3 /*break*/, 11];
3592
+ case 9:
3593
+ e_1_1 = _g.sent();
3594
+ e_1 = { error: e_1_1 };
3595
+ return [3 /*break*/, 11];
3596
+ case 10:
3532
3597
  try {
3533
- // Note: Check that all input input parameters are defined
3534
- for (_a = __values(preparedPipeline.parameters.filter(function (_a) {
3535
- var isInput = _a.isInput;
3536
- return isInput;
3537
- })), _b = _a.next(); !_b.done; _b = _a.next()) {
3538
- parameter = _b.value;
3539
- if (inputParameters[parameter.name] === undefined) {
3540
- return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3541
- isSuccessful: false,
3542
- errors: __spreadArray([
3543
- new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3544
- ], __read(errors), false).map(serializeError),
3545
- warnings: [],
3546
- executionReport: executionReport,
3547
- outputParameters: {},
3548
- usage: ZERO_USAGE,
3549
- preparedPipeline: preparedPipeline,
3550
- })];
3551
- }
3552
- }
3553
- }
3554
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3555
- finally {
3556
- try {
3557
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
3558
- }
3559
- finally { if (e_1) throw e_1.error; }
3598
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
3560
3599
  }
3600
+ finally { if (e_1) throw e_1.error; }
3601
+ return [7 /*endfinally*/];
3602
+ case 11:
3561
3603
  _loop_1 = function (parameterName) {
3562
- var parameter = preparedPipeline.parameters.find(function (_a) {
3563
- var name = _a.name;
3564
- return name === parameterName;
3604
+ var parameter;
3605
+ return __generator(this, function (_h) {
3606
+ switch (_h.label) {
3607
+ case 0:
3608
+ parameter = preparedPipeline.parameters.find(function (_a) {
3609
+ var name = _a.name;
3610
+ return name === parameterName;
3611
+ });
3612
+ if (!(parameter === undefined)) return [3 /*break*/, 1];
3613
+ warnings.push(new PipelineExecutionError(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 "); })));
3614
+ return [3 /*break*/, 4];
3615
+ case 1:
3616
+ if (!(parameter.isInput === false)) return [3 /*break*/, 4];
3617
+ isReturned = true;
3618
+ if (!(onProgress !== undefined)) return [3 /*break*/, 3];
3619
+ // Note: Wait a short time to prevent race conditions
3620
+ return [4 /*yield*/, forTime(IMMEDIATE_TIME)];
3621
+ case 2:
3622
+ // Note: Wait a short time to prevent race conditions
3623
+ _h.sent();
3624
+ _h.label = 3;
3625
+ case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
3626
+ isSuccessful: false,
3627
+ errors: __spreadArray([
3628
+ new PipelineExecutionError(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 "); }))
3629
+ ], __read(errors), false).map(serializeError),
3630
+ warnings: warnings.map(serializeError),
3631
+ executionReport: executionReport,
3632
+ outputParameters: {},
3633
+ usage: ZERO_USAGE,
3634
+ preparedPipeline: preparedPipeline,
3635
+ }) }];
3636
+ case 4: return [2 /*return*/];
3637
+ }
3565
3638
  });
3566
- if (parameter === undefined) {
3567
- warnings.push(new PipelineExecutionError(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 "); })));
3568
- }
3569
- else if (parameter.isInput === false) {
3570
- return { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
3571
- isSuccessful: false,
3572
- errors: __spreadArray([
3573
- new PipelineExecutionError(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 "); }))
3574
- ], __read(errors), false).map(serializeError),
3575
- warnings: warnings.map(serializeError),
3576
- executionReport: executionReport,
3577
- outputParameters: {},
3578
- usage: ZERO_USAGE,
3579
- preparedPipeline: preparedPipeline,
3580
- }) };
3581
- }
3582
3639
  };
3640
+ _g.label = 12;
3641
+ case 12:
3642
+ _g.trys.push([12, 17, 18, 19]);
3643
+ _c = __values(Object.keys(inputParameters)), _d = _c.next();
3644
+ _g.label = 13;
3645
+ case 13:
3646
+ if (!!_d.done) return [3 /*break*/, 16];
3647
+ parameterName = _d.value;
3648
+ return [5 /*yield**/, _loop_1(parameterName)];
3649
+ case 14:
3650
+ state_1 = _g.sent();
3651
+ if (typeof state_1 === "object")
3652
+ return [2 /*return*/, state_1.value];
3653
+ _g.label = 15;
3654
+ case 15:
3655
+ _d = _c.next();
3656
+ return [3 /*break*/, 13];
3657
+ case 16: return [3 /*break*/, 19];
3658
+ case 17:
3659
+ e_2_1 = _g.sent();
3660
+ e_2 = { error: e_2_1 };
3661
+ return [3 /*break*/, 19];
3662
+ case 18:
3583
3663
  try {
3584
- // Note: Check that no extra input parameters are passed
3585
- for (_c = __values(Object.keys(inputParameters)), _d = _c.next(); !_d.done; _d = _c.next()) {
3586
- parameterName = _d.value;
3587
- state_1 = _loop_1(parameterName);
3588
- if (typeof state_1 === "object")
3589
- return [2 /*return*/, state_1.value];
3590
- }
3591
- }
3592
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3593
- finally {
3594
- try {
3595
- if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
3596
- }
3597
- finally { if (e_2) throw e_2.error; }
3664
+ if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
3598
3665
  }
3666
+ finally { if (e_2) throw e_2.error; }
3667
+ return [7 /*endfinally*/];
3668
+ case 19:
3599
3669
  parametersToPass = inputParameters;
3600
- _g.label = 3;
3601
- case 3:
3602
- _g.trys.push([3, 8, , 9]);
3670
+ _g.label = 20;
3671
+ case 20:
3672
+ _g.trys.push([20, 25, , 28]);
3603
3673
  resovedParameterNames_1 = preparedPipeline.parameters
3604
3674
  .filter(function (_a) {
3605
3675
  var isInput = _a.isInput;
@@ -3614,8 +3684,8 @@ function createPipelineExecutor(options) {
3614
3684
  loopLimit = LOOP_LIMIT;
3615
3685
  _loop_2 = function () {
3616
3686
  var currentTemplate, work_1;
3617
- return __generator(this, function (_h) {
3618
- switch (_h.label) {
3687
+ return __generator(this, function (_j) {
3688
+ switch (_j.label) {
3619
3689
  case 0:
3620
3690
  if (loopLimit-- < 0) {
3621
3691
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
@@ -3641,7 +3711,7 @@ function createPipelineExecutor(options) {
3641
3711
  if (!!currentTemplate) return [3 /*break*/, 3];
3642
3712
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
3643
3713
  case 2:
3644
- /* [5] */ _h.sent();
3714
+ /* [5] */ _j.sent();
3645
3715
  return [3 /*break*/, 4];
3646
3716
  case 3:
3647
3717
  unresovedTemplates_1 = unresovedTemplates_1.filter(function (template) { return template !== currentTemplate; });
@@ -3653,23 +3723,23 @@ function createPipelineExecutor(options) {
3653
3723
  resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
3654
3724
  });
3655
3725
  resolving_1.push(work_1);
3656
- _h.label = 4;
3726
+ _j.label = 4;
3657
3727
  case 4: return [2 /*return*/];
3658
3728
  }
3659
3729
  });
3660
3730
  };
3661
- _g.label = 4;
3662
- case 4:
3663
- if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 6];
3731
+ _g.label = 21;
3732
+ case 21:
3733
+ if (!(unresovedTemplates_1.length > 0)) return [3 /*break*/, 23];
3664
3734
  return [5 /*yield**/, _loop_2()];
3665
- case 5:
3735
+ case 22:
3666
3736
  _g.sent();
3667
- return [3 /*break*/, 4];
3668
- case 6: return [4 /*yield*/, Promise.all(resolving_1)];
3669
- case 7:
3737
+ return [3 /*break*/, 21];
3738
+ case 23: return [4 /*yield*/, Promise.all(resolving_1)];
3739
+ case 24:
3670
3740
  _g.sent();
3671
- return [3 /*break*/, 9];
3672
- case 8:
3741
+ return [3 /*break*/, 28];
3742
+ case 25:
3673
3743
  error_1 = _g.sent();
3674
3744
  if (!(error_1 instanceof Error)) {
3675
3745
  throw error_1;
@@ -3679,30 +3749,46 @@ function createPipelineExecutor(options) {
3679
3749
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3680
3750
  })), false));
3681
3751
  outputParameters_1 = filterJustOutputParameters();
3682
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
3683
- isSuccessful: false,
3684
- errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
3685
- warnings: warnings.map(serializeError),
3686
- usage: usage_1,
3687
- executionReport: executionReport,
3688
- outputParameters: outputParameters_1,
3689
- preparedPipeline: preparedPipeline,
3690
- })];
3691
- case 9:
3752
+ isReturned = true;
3753
+ if (!(onProgress !== undefined)) return [3 /*break*/, 27];
3754
+ // Note: Wait a short time to prevent race conditions
3755
+ return [4 /*yield*/, forTime(IMMEDIATE_TIME)];
3756
+ case 26:
3757
+ // Note: Wait a short time to prevent race conditions
3758
+ _g.sent();
3759
+ _g.label = 27;
3760
+ case 27: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
3761
+ isSuccessful: false,
3762
+ errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
3763
+ warnings: warnings.map(serializeError),
3764
+ usage: usage_1,
3765
+ executionReport: executionReport,
3766
+ outputParameters: outputParameters_1,
3767
+ preparedPipeline: preparedPipeline,
3768
+ })];
3769
+ case 28:
3692
3770
  usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
3693
3771
  var result = _a.result;
3694
3772
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3695
3773
  })), false));
3696
3774
  outputParameters = filterJustOutputParameters();
3697
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
3698
- isSuccessful: true,
3699
- errors: errors.map(serializeError),
3700
- warnings: warnings.map(serializeError),
3701
- usage: usage,
3702
- executionReport: executionReport,
3703
- outputParameters: outputParameters,
3704
- preparedPipeline: preparedPipeline,
3705
- })];
3775
+ isReturned = true;
3776
+ if (!(onProgress !== undefined)) return [3 /*break*/, 30];
3777
+ // Note: Wait a short time to prevent race conditions
3778
+ return [4 /*yield*/, forTime(IMMEDIATE_TIME)];
3779
+ case 29:
3780
+ // Note: Wait a short time to prevent race conditions
3781
+ _g.sent();
3782
+ _g.label = 30;
3783
+ case 30: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
3784
+ isSuccessful: true,
3785
+ errors: errors.map(serializeError),
3786
+ warnings: warnings.map(serializeError),
3787
+ usage: usage,
3788
+ executionReport: executionReport,
3789
+ outputParameters: outputParameters,
3790
+ preparedPipeline: preparedPipeline,
3791
+ })];
3706
3792
  }
3707
3793
  });
3708
3794
  }); };