@promptbook/core 0.69.0-19 โ†’ 0.69.0-20

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.
@@ -15,7 +15,7 @@ export type PipelineExecutorResult = {
15
15
  *
16
16
  * Note: If the execution was not successful, there are only some of the result parameters
17
17
  */
18
- readonly outputParameters: Parameters;
18
+ readonly outputParameters: Readonly<Parameters>;
19
19
  /**
20
20
  * Whether the execution was successful, details are aviable in `executionReport`
21
21
  */
@@ -23,19 +23,19 @@ export type PipelineExecutorResult = {
23
23
  /**
24
24
  * Added usage of whole execution, detailed usage is aviable in `executionReport`
25
25
  */
26
- readonly usage: PromptResultUsage;
26
+ readonly usage: ReadonlyDeep<PromptResultUsage>;
27
27
  /**
28
28
  * Errors that occured during the execution, details are aviable in `executionReport`
29
29
  */
30
- readonly errors: Array<ErrorJson>;
30
+ readonly errors: ReadonlyDeep<Array<ErrorJson>>;
31
31
  /**
32
32
  * Warnings that occured during the execution, details are aviable in `executionReport`
33
33
  */
34
- readonly warnings: Array<ErrorJson>;
34
+ readonly warnings: ReadonlyDeep<Array<ErrorJson>>;
35
35
  /**
36
36
  * The report of the execution with all details
37
37
  */
38
- readonly executionReport: ExecutionReportJson;
38
+ readonly executionReport: ReadonlyDeep<ExecutionReportJson>;
39
39
  /**
40
40
  * The prepared pipeline that was used for the execution
41
41
  *
@@ -45,7 +45,6 @@ export type PipelineExecutorResult = {
45
45
  readonly preparedPipeline: ReadonlyDeep<PipelineJson>;
46
46
  };
47
47
  /**
48
- * TODO: !!!!!! Maybe add ReadonlyDeep< to all
49
48
  * TODO: [๐Ÿง ] Should this file be in /execution or /types folder?
50
49
  * TODO: [๐Ÿง ] Maybe constrain `ErrorJson` -> `ErrorJson & { name: 'PipelineExecutionError' | 'Error' }`
51
50
  */
@@ -10,12 +10,36 @@ import type { PromptResult } from '../PromptResult';
10
10
  * @private internal utility of `createPipelineExecutor`
11
11
  */
12
12
  export type $OngoingTemplateResult = {
13
+ /**
14
+ * @@@
15
+ */
13
16
  $prompt?: Prompt;
17
+ /**
18
+ * @@@
19
+ */
14
20
  $chatResult?: ChatPromptResult;
21
+ /**
22
+ * @@@
23
+ */
15
24
  $completionResult?: CompletionPromptResult;
25
+ /**
26
+ * @@@
27
+ */
16
28
  $embeddingResult?: EmbeddingPromptResult;
29
+ /**
30
+ * @@@
31
+ */
17
32
  $result: PromptResult | null;
33
+ /**
34
+ * @@@
35
+ */
18
36
  $resultString: string | null;
37
+ /**
38
+ * @@@
39
+ */
19
40
  $expectError: ExpectError | null;
41
+ /**
42
+ * @@@
43
+ */
20
44
  $scriptPipelineExecutionErrors: Array<Error>;
21
45
  };
@@ -33,7 +33,7 @@ export type ExecuteAttemptsOptions = {
33
33
  /**
34
34
  * @@@
35
35
  */
36
- readonly parameters: ReadonlyDeep<Parameters>;
36
+ readonly parameters: Readonly<Parameters>;
37
37
  /**
38
38
  * @@@
39
39
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.69.0-19",
3
+ "version": "0.69.0-20",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -16,7 +16,7 @@
16
16
  /**
17
17
  * The version of the Promptbook library
18
18
  */
19
- var PROMPTBOOK_VERSION = '0.69.0-18';
19
+ var PROMPTBOOK_VERSION = '0.69.0-19';
20
20
  // TODO:[main] !!!! List here all the versions and annotate + put into script
21
21
 
22
22
  /*! *****************************************************************************
@@ -3706,16 +3706,16 @@
3706
3706
  case 0:
3707
3707
  isJokerAttempt = attempt < 0;
3708
3708
  jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
3709
- // TODO: [๐Ÿง ] !!!!!! JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
3709
+ // TODO: [๐Ÿง ][๐Ÿญ] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
3710
3710
  if (isJokerAttempt && !jokerParameterName) {
3711
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3711
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
3712
3712
  }
3713
3713
  $ongoingTemplateResult.$result = null;
3714
3714
  $ongoingTemplateResult.$resultString = null;
3715
3715
  $ongoingTemplateResult.$expectError = null;
3716
3716
  if (isJokerAttempt) {
3717
3717
  if (parameters[jokerParameterName] === undefined) {
3718
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3718
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
3719
3719
  // <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
3720
3720
  }
3721
3721
  else {
@@ -3781,14 +3781,14 @@
3781
3781
  $ongoingTemplateResult.$completionResult.content;
3782
3782
  return [3 /*break*/, 10];
3783
3783
  case 8: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
3784
- case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3784
+ case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
3785
3785
  case 10: return [3 /*break*/, 25];
3786
3786
  case 11:
3787
3787
  if (arrayableToArray(tools.script).length === 0) {
3788
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3788
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3789
3789
  }
3790
3790
  if (!template.contentLanguage) {
3791
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3791
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3792
3792
  }
3793
3793
  _t.label = 12;
3794
3794
  case 12:
@@ -3842,13 +3842,13 @@
3842
3842
  throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
3843
3843
  }
3844
3844
  else {
3845
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
3845
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
3846
3846
  .map(function (error) { return '- ' + error.message; })
3847
- .join('\n\n')), "\n "); }));
3847
+ .join('\n\n')), "\n "); }));
3848
3848
  }
3849
3849
  case 22:
3850
3850
  if (tools.userInterface === undefined) {
3851
- throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3851
+ throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
3852
3852
  }
3853
3853
  // TODO: [๐ŸŒน] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3854
3854
  _j = $ongoingTemplateResult;
@@ -3864,7 +3864,7 @@
3864
3864
  // TODO: [๐ŸŒน] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
3865
3865
  _j.$resultString = _t.sent();
3866
3866
  return [3 /*break*/, 25];
3867
- case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3867
+ case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3868
3868
  case 25:
3869
3869
  if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 42];
3870
3870
  _t.label = 26;
@@ -3955,13 +3955,13 @@
3955
3955
  }
3956
3956
  catch (error) {
3957
3957
  keepUnused(error);
3958
- throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3959
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3958
+ throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3959
+ /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3960
3960
  }
3961
3961
  }
3962
3962
  }
3963
3963
  else {
3964
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3964
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3965
3965
  }
3966
3966
  }
3967
3967
  // TODO: [๐Ÿ’] Unite object for expecting amount and format
@@ -3997,18 +3997,18 @@
3997
3997
  if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
3998
3998
  throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
3999
3999
  var _a, _b, _c;
4000
- return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
4000
+ return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
4001
4001
  .split('\n')
4002
4002
  .map(function (line) { return "> ".concat(line); })
4003
- .join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
4003
+ .join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
4004
4004
  .split('\n')
4005
4005
  .map(function (line) { return "> ".concat(line); })
4006
- .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
4006
+ .join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
4007
4007
  ? 'null'
4008
4008
  : $ongoingTemplateResult.$resultString
4009
4009
  .split('\n')
4010
4010
  .map(function (line) { return "> ".concat(line); })
4011
- .join('\n')), "\n ---\n ");
4011
+ .join('\n')), "\n ---\n ");
4012
4012
  }));
4013
4013
  }
4014
4014
  return [2 /*return*/];
@@ -4031,7 +4031,7 @@
4031
4031
  return [3 /*break*/, 1];
4032
4032
  case 4:
4033
4033
  if ($ongoingTemplateResult.$resultString === null) {
4034
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
4034
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
4035
4035
  }
4036
4036
  return [2 /*return*/, $ongoingTemplateResult.$resultString];
4037
4037
  }
@@ -4495,7 +4495,7 @@
4495
4495
  return name === parameterName;
4496
4496
  });
4497
4497
  if (!(parameter === undefined)) return [3 /*break*/, 1];
4498
- 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 "); })));
4498
+ 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 "); })));
4499
4499
  return [3 /*break*/, 4];
4500
4500
  case 1:
4501
4501
  if (!(parameter.isInput === false)) return [3 /*break*/, 4];
@@ -4507,10 +4507,10 @@
4507
4507
  // Note: Wait a short time to prevent race conditions
4508
4508
  _h.sent();
4509
4509
  _h.label = 3;
4510
- case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
4510
+ case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
4511
4511
  isSuccessful: false,
4512
4512
  errors: __spreadArray([
4513
- 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 "); }))
4513
+ 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 "); }))
4514
4514
  ], __read(errors), false).map(serializeError),
4515
4515
  warnings: warnings.map(serializeError),
4516
4516
  executionReport: executionReport,
@@ -4574,7 +4574,7 @@
4574
4574
  case 0:
4575
4575
  if (loopLimit-- < 0) {
4576
4576
  // Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
4577
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
4577
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
4578
4578
  }
4579
4579
  currentTemplate = unresovedTemplates_1.find(function (template) {
4580
4580
  return template.dependentParameterNames.every(function (name) {
@@ -4584,14 +4584,14 @@
4584
4584
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
4585
4585
  throw new UnexpectedError(
4586
4586
  // TODO: [๐ŸŽ] DRY
4587
- 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
4587
+ 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
4588
4588
  .map(function (_a) {
4589
4589
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
4590
4590
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
4591
4591
  .map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
4592
4592
  .join(' and '));
4593
4593
  })
4594
- .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
4594
+ .join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
4595
4595
  case 1:
4596
4596
  if (!!currentTemplate) return [3 /*break*/, 3];
4597
4597
  /* [๐Ÿคนโ€โ™‚๏ธ] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -4608,10 +4608,10 @@
4608
4608
  llmTools: llmTools,
4609
4609
  onProgress: function (progress) {
4610
4610
  if (isReturned) {
4611
- throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
4611
+ throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
4612
4612
  .split('\n')
4613
4613
  .map(function (line) { return "> ".concat(line); })
4614
- .join('\n')), "\n "); }));
4614
+ .join('\n')), "\n "); }));
4615
4615
  }
4616
4616
  if (onProgress) {
4617
4617
  onProgress(progress);