@promptbook/core 0.36.4 → 0.38.0
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 +116 -61
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/wizzard.index.d.ts +3 -0
- package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/execution/ExecutionTools.d.ts +2 -2
- package/esm/typings/execution/NaturalExecutionTools.d.ts +2 -2
- package/esm/typings/execution/PromptResult.d.ts +3 -4
- package/esm/typings/execution/PromptbookExecutor.d.ts +2 -2
- package/esm/typings/execution/ScriptExecutionTools.d.ts +5 -5
- package/esm/typings/execution/UserInterfaceTools.d.ts +4 -4
- package/esm/typings/execution/createPromptbookExecutor.d.ts +3 -2
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -2
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/{IAutomaticTranslator.d.ts → AutomaticTranslator.d.ts} +2 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +3 -3
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +2 -2
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +5 -5
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
- package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +4 -4
- package/esm/typings/types/Command.d.ts +20 -19
- package/esm/typings/types/ModelRequirements.d.ts +3 -3
- package/esm/typings/types/Prompt.d.ts +2 -2
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +6 -4
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -2
- package/esm/typings/types/TaskProgress.d.ts +2 -2
- package/esm/typings/types/typeAliases.d.ts +0 -26
- package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +2 -2
- package/esm/typings/wizzard/Wizzard.d.ts +3 -0
- package/esm/typings/wizzard/sample.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +116 -61
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/wizzard.index.d.ts +3 -0
- package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +2 -2
- package/umd/typings/execution/ExecutionTools.d.ts +2 -2
- package/umd/typings/execution/NaturalExecutionTools.d.ts +2 -2
- package/umd/typings/execution/PromptResult.d.ts +3 -4
- package/umd/typings/execution/PromptbookExecutor.d.ts +2 -2
- package/umd/typings/execution/ScriptExecutionTools.d.ts +5 -5
- package/umd/typings/execution/UserInterfaceTools.d.ts +4 -4
- package/umd/typings/execution/createPromptbookExecutor.d.ts +3 -2
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +2 -2
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -2
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/{IAutomaticTranslator.d.ts → AutomaticTranslator.d.ts} +2 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +3 -3
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +2 -2
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +5 -5
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -0
- package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +4 -4
- package/umd/typings/types/Command.d.ts +20 -19
- package/umd/typings/types/ModelRequirements.d.ts +3 -3
- package/umd/typings/types/Prompt.d.ts +2 -2
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +6 -4
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -2
- package/umd/typings/types/TaskProgress.d.ts +2 -2
- package/umd/typings/types/typeAliases.d.ts +0 -26
- package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +2 -2
- package/umd/typings/wizzard/Wizzard.d.ts +3 -0
- package/umd/typings/wizzard/sample.d.ts +1 -0
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/ITranslatorOptions.d.ts +0 -4
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/ITranslatorOptions.d.ts +0 -4
package/umd/index.umd.js
CHANGED
|
@@ -430,7 +430,7 @@
|
|
|
430
430
|
/**
|
|
431
431
|
* The version of the Promptbook library
|
|
432
432
|
*/
|
|
433
|
-
var PROMPTBOOK_VERSION = '0.
|
|
433
|
+
var PROMPTBOOK_VERSION = '0.37.0';
|
|
434
434
|
|
|
435
435
|
/**
|
|
436
436
|
* Execution type describes the way how the block is executed
|
|
@@ -643,12 +643,14 @@
|
|
|
643
643
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
644
644
|
throw new Error(spaceTrim__default["default"]("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
645
645
|
}
|
|
646
|
-
var
|
|
646
|
+
var isInput = type.startsWith('INPUT');
|
|
647
|
+
var isOutput = type.startsWith('OUTPUT');
|
|
647
648
|
return {
|
|
648
649
|
type: 'PARAMETER',
|
|
649
650
|
parameterName: parameterName,
|
|
650
651
|
parameterDescription: parameterDescription.trim() || null,
|
|
651
|
-
|
|
652
|
+
isInput: isInput,
|
|
653
|
+
isOutput: isOutput,
|
|
652
654
|
};
|
|
653
655
|
}
|
|
654
656
|
else if (type.startsWith('JOKER')) {
|
|
@@ -780,7 +782,7 @@
|
|
|
780
782
|
// =============================================================
|
|
781
783
|
///Note: 2️⃣ Function for adding parameters
|
|
782
784
|
var addParam = function (parameterCommand) {
|
|
783
|
-
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription,
|
|
785
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
784
786
|
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
785
787
|
if (existingParameter &&
|
|
786
788
|
existingParameter.description &&
|
|
@@ -797,7 +799,8 @@
|
|
|
797
799
|
promptbookJson.parameters.push({
|
|
798
800
|
name: parameterName,
|
|
799
801
|
description: parameterDescription || undefined,
|
|
800
|
-
isInput:
|
|
802
|
+
isInput: isInput,
|
|
803
|
+
isOutput: isOutput,
|
|
801
804
|
});
|
|
802
805
|
}
|
|
803
806
|
};
|
|
@@ -1044,7 +1047,7 @@
|
|
|
1044
1047
|
* @throws {Error} if invalid
|
|
1045
1048
|
*/
|
|
1046
1049
|
function validatePromptbookJson(promptbook) {
|
|
1047
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
1050
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
1048
1051
|
var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
|
|
1049
1052
|
var isInput = _a.isInput;
|
|
1050
1053
|
return isInput;
|
|
@@ -1052,10 +1055,40 @@
|
|
|
1052
1055
|
var name = _a.name;
|
|
1053
1056
|
return name;
|
|
1054
1057
|
}));
|
|
1058
|
+
var _loop_1 = function (parameter) {
|
|
1059
|
+
if (parameter.isInput && parameter.isOutput) {
|
|
1060
|
+
throw new Error("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
1061
|
+
}
|
|
1062
|
+
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
1063
|
+
if (!parameter.isInput &&
|
|
1064
|
+
!parameter.isOutput &&
|
|
1065
|
+
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
1066
|
+
throw new Error(spaceTrim__default["default"]("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
|
|
1067
|
+
}
|
|
1068
|
+
// Note: Testing that parameter is either input or result of some template
|
|
1069
|
+
if (!parameter.isInput &&
|
|
1070
|
+
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
1071
|
+
throw new Error(spaceTrim__default["default"]("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
try {
|
|
1075
|
+
// Note: Check each parameter individually
|
|
1076
|
+
for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1077
|
+
var parameter = _f.value;
|
|
1078
|
+
_loop_1(parameter);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1082
|
+
finally {
|
|
1083
|
+
try {
|
|
1084
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
1085
|
+
}
|
|
1086
|
+
finally { if (e_1) throw e_1.error; }
|
|
1087
|
+
}
|
|
1055
1088
|
try {
|
|
1056
1089
|
// Note: Check each template individually
|
|
1057
|
-
for (var
|
|
1058
|
-
var template =
|
|
1090
|
+
for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1091
|
+
var template = _h.value;
|
|
1059
1092
|
if (definedParameters.has(template.resultingParameterName)) {
|
|
1060
1093
|
throw new Error("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
1061
1094
|
}
|
|
@@ -1070,25 +1103,25 @@
|
|
|
1070
1103
|
throw new Error("Joker parameters are used but no expectations are defined");
|
|
1071
1104
|
}
|
|
1072
1105
|
try {
|
|
1073
|
-
for (var
|
|
1074
|
-
var joker =
|
|
1106
|
+
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1107
|
+
var joker = _k.value;
|
|
1075
1108
|
if (!template.dependentParameterNames.includes(joker)) {
|
|
1076
1109
|
throw new Error("Parameter {".concat(joker, "} is used as joker but not in dependentParameterNames"));
|
|
1077
1110
|
}
|
|
1078
1111
|
}
|
|
1079
1112
|
}
|
|
1080
|
-
catch (
|
|
1113
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1081
1114
|
finally {
|
|
1082
1115
|
try {
|
|
1083
|
-
if (
|
|
1116
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
1084
1117
|
}
|
|
1085
|
-
finally { if (
|
|
1118
|
+
finally { if (e_3) throw e_3.error; }
|
|
1086
1119
|
}
|
|
1087
1120
|
}
|
|
1088
1121
|
if (template.expectAmount) {
|
|
1089
1122
|
try {
|
|
1090
|
-
for (var
|
|
1091
|
-
var
|
|
1123
|
+
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectAmount))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1124
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1092
1125
|
if (min !== undefined && max !== undefined && min > max) {
|
|
1093
1126
|
throw new Error("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
1094
1127
|
}
|
|
@@ -1100,23 +1133,23 @@
|
|
|
1100
1133
|
}
|
|
1101
1134
|
}
|
|
1102
1135
|
}
|
|
1103
|
-
catch (
|
|
1136
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1104
1137
|
finally {
|
|
1105
1138
|
try {
|
|
1106
|
-
if (
|
|
1139
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
1107
1140
|
}
|
|
1108
|
-
finally { if (
|
|
1141
|
+
finally { if (e_4) throw e_4.error; }
|
|
1109
1142
|
}
|
|
1110
1143
|
}
|
|
1111
1144
|
definedParameters.add(template.resultingParameterName);
|
|
1112
1145
|
}
|
|
1113
1146
|
}
|
|
1114
|
-
catch (
|
|
1147
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1115
1148
|
finally {
|
|
1116
1149
|
try {
|
|
1117
|
-
if (
|
|
1150
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
1118
1151
|
}
|
|
1119
|
-
finally { if (
|
|
1152
|
+
finally { if (e_2) throw e_2.error; }
|
|
1120
1153
|
}
|
|
1121
1154
|
// Note: Detect circular dependencies
|
|
1122
1155
|
var resovedParameters = promptbook.parameters
|
|
@@ -1129,7 +1162,7 @@
|
|
|
1129
1162
|
return name;
|
|
1130
1163
|
});
|
|
1131
1164
|
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1132
|
-
var
|
|
1165
|
+
var _loop_2 = function () {
|
|
1133
1166
|
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
1134
1167
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
1135
1168
|
});
|
|
@@ -1150,7 +1183,7 @@
|
|
|
1150
1183
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
1151
1184
|
};
|
|
1152
1185
|
while (unresovedTemplates.length > 0) {
|
|
1153
|
-
|
|
1186
|
+
_loop_2();
|
|
1154
1187
|
}
|
|
1155
1188
|
}
|
|
1156
1189
|
/**
|
|
@@ -1331,15 +1364,15 @@
|
|
|
1331
1364
|
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1332
1365
|
function executeSingleTemplate(currentTemplate) {
|
|
1333
1366
|
return __awaiter(this, void 0, void 0, function () {
|
|
1334
|
-
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2,
|
|
1335
|
-
var
|
|
1367
|
+
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, _j, _k, _l, unit, _m, max, min, amount, error_4;
|
|
1368
|
+
var e_2, _o, e_4, _p, e_3, _q, e_5, _r, _s;
|
|
1336
1369
|
return __generator(this, function (_t) {
|
|
1337
1370
|
switch (_t.label) {
|
|
1338
1371
|
case 0:
|
|
1339
1372
|
name = "promptbook-executor-frame-".concat(currentTemplate.name);
|
|
1340
1373
|
title = currentTemplate.title;
|
|
1341
1374
|
priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
|
|
1342
|
-
if (!onProgress) return [3 /*break*/, 2];
|
|
1375
|
+
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1343
1376
|
return [4 /*yield*/, onProgress({
|
|
1344
1377
|
name: name,
|
|
1345
1378
|
title: title,
|
|
@@ -1348,6 +1381,7 @@
|
|
|
1348
1381
|
executionType: currentTemplate.executionType,
|
|
1349
1382
|
parameterName: currentTemplate.resultingParameterName,
|
|
1350
1383
|
parameterValue: null,
|
|
1384
|
+
// <- [3]
|
|
1351
1385
|
})];
|
|
1352
1386
|
case 1:
|
|
1353
1387
|
_t.sent();
|
|
@@ -1435,7 +1469,7 @@
|
|
|
1435
1469
|
_t.label = 14;
|
|
1436
1470
|
case 14:
|
|
1437
1471
|
_t.trys.push([14, 21, 22, 23]);
|
|
1438
|
-
_c = (
|
|
1472
|
+
_c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
|
|
1439
1473
|
_t.label = 15;
|
|
1440
1474
|
case 15:
|
|
1441
1475
|
if (!!_d.done) return [3 /*break*/, 20];
|
|
@@ -1463,14 +1497,14 @@
|
|
|
1463
1497
|
return [3 /*break*/, 15];
|
|
1464
1498
|
case 20: return [3 /*break*/, 23];
|
|
1465
1499
|
case 21:
|
|
1466
|
-
|
|
1467
|
-
|
|
1500
|
+
e_2_1 = _t.sent();
|
|
1501
|
+
e_2 = { error: e_2_1 };
|
|
1468
1502
|
return [3 /*break*/, 23];
|
|
1469
1503
|
case 22:
|
|
1470
1504
|
try {
|
|
1471
1505
|
if (_d && !_d.done && (_o = _c.return)) _o.call(_c);
|
|
1472
1506
|
}
|
|
1473
|
-
finally { if (
|
|
1507
|
+
finally { if (e_2) throw e_2.error; }
|
|
1474
1508
|
return [7 /*endfinally*/];
|
|
1475
1509
|
case 23:
|
|
1476
1510
|
if (resultString) {
|
|
@@ -1504,7 +1538,7 @@
|
|
|
1504
1538
|
_t.label = 28;
|
|
1505
1539
|
case 28:
|
|
1506
1540
|
_t.trys.push([28, 42, 43, 44]);
|
|
1507
|
-
_e = (
|
|
1541
|
+
_e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
|
|
1508
1542
|
_t.label = 29;
|
|
1509
1543
|
case 29:
|
|
1510
1544
|
if (!!_f.done) return [3 /*break*/, 41];
|
|
@@ -1515,7 +1549,7 @@
|
|
|
1515
1549
|
_t.label = 30;
|
|
1516
1550
|
case 30:
|
|
1517
1551
|
_t.trys.push([30, 37, 38, 39]);
|
|
1518
|
-
_g = (
|
|
1552
|
+
_g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
|
|
1519
1553
|
_t.label = 31;
|
|
1520
1554
|
case 31:
|
|
1521
1555
|
if (!!_h.done) return [3 /*break*/, 36];
|
|
@@ -1545,14 +1579,14 @@
|
|
|
1545
1579
|
return [3 /*break*/, 31];
|
|
1546
1580
|
case 36: return [3 /*break*/, 39];
|
|
1547
1581
|
case 37:
|
|
1548
|
-
|
|
1549
|
-
|
|
1582
|
+
e_3_1 = _t.sent();
|
|
1583
|
+
e_3 = { error: e_3_1 };
|
|
1550
1584
|
return [3 /*break*/, 39];
|
|
1551
1585
|
case 38:
|
|
1552
1586
|
try {
|
|
1553
1587
|
if (_h && !_h.done && (_q = _g.return)) _q.call(_g);
|
|
1554
1588
|
}
|
|
1555
|
-
finally { if (
|
|
1589
|
+
finally { if (e_3) throw e_3.error; }
|
|
1556
1590
|
return [7 /*endfinally*/];
|
|
1557
1591
|
case 39:
|
|
1558
1592
|
if (postprocessingError) {
|
|
@@ -1564,14 +1598,14 @@
|
|
|
1564
1598
|
return [3 /*break*/, 29];
|
|
1565
1599
|
case 41: return [3 /*break*/, 44];
|
|
1566
1600
|
case 42:
|
|
1567
|
-
|
|
1568
|
-
|
|
1601
|
+
e_4_1 = _t.sent();
|
|
1602
|
+
e_4 = { error: e_4_1 };
|
|
1569
1603
|
return [3 /*break*/, 44];
|
|
1570
1604
|
case 43:
|
|
1571
1605
|
try {
|
|
1572
1606
|
if (_f && !_f.done && (_p = _e.return)) _p.call(_e);
|
|
1573
1607
|
}
|
|
1574
|
-
finally { if (
|
|
1608
|
+
finally { if (e_4) throw e_4.error; }
|
|
1575
1609
|
return [7 /*endfinally*/];
|
|
1576
1610
|
case 44:
|
|
1577
1611
|
if (currentTemplate.expectFormat) {
|
|
@@ -1583,7 +1617,7 @@
|
|
|
1583
1617
|
}
|
|
1584
1618
|
if (currentTemplate.expectAmount) {
|
|
1585
1619
|
try {
|
|
1586
|
-
for (_j = (
|
|
1620
|
+
for (_j = (e_5 = void 0, __values(Object.entries(currentTemplate.expectAmount))), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1587
1621
|
_l = __read(_k.value, 2), unit = _l[0], _m = _l[1], max = _m.max, min = _m.min;
|
|
1588
1622
|
amount = CountUtils[unit.toUpperCase()](resultString || '');
|
|
1589
1623
|
if (min && amount < min) {
|
|
@@ -1594,12 +1628,12 @@
|
|
|
1594
1628
|
}
|
|
1595
1629
|
}
|
|
1596
1630
|
}
|
|
1597
|
-
catch (
|
|
1631
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1598
1632
|
finally {
|
|
1599
1633
|
try {
|
|
1600
1634
|
if (_k && !_k.done && (_r = _j.return)) _r.call(_j);
|
|
1601
1635
|
}
|
|
1602
|
-
finally { if (
|
|
1636
|
+
finally { if (e_5) throw e_5.error; }
|
|
1603
1637
|
}
|
|
1604
1638
|
}
|
|
1605
1639
|
return [3 /*break*/, 49];
|
|
@@ -1643,7 +1677,7 @@
|
|
|
1643
1677
|
// <- TODO: [🥨] Make some NeverShouldHappenError
|
|
1644
1678
|
throw new Error('Something went wrong and prompt result is null');
|
|
1645
1679
|
}
|
|
1646
|
-
if (onProgress) {
|
|
1680
|
+
if (onProgress /* <- [3] */) {
|
|
1647
1681
|
onProgress({
|
|
1648
1682
|
name: name,
|
|
1649
1683
|
title: title,
|
|
@@ -1652,6 +1686,7 @@
|
|
|
1652
1686
|
executionType: currentTemplate.executionType,
|
|
1653
1687
|
parameterName: currentTemplate.resultingParameterName,
|
|
1654
1688
|
parameterValue: resultString,
|
|
1689
|
+
// <- [3]
|
|
1655
1690
|
});
|
|
1656
1691
|
}
|
|
1657
1692
|
parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _s));
|
|
@@ -1660,9 +1695,10 @@
|
|
|
1660
1695
|
});
|
|
1661
1696
|
});
|
|
1662
1697
|
}
|
|
1663
|
-
var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, _loop_1, error_1;
|
|
1664
|
-
|
|
1665
|
-
|
|
1698
|
+
var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, _loop_1, error_1, _a, _b, parameter;
|
|
1699
|
+
var e_1, _c;
|
|
1700
|
+
return __generator(this, function (_d) {
|
|
1701
|
+
switch (_d.label) {
|
|
1666
1702
|
case 0:
|
|
1667
1703
|
parametersToPass = inputParameters;
|
|
1668
1704
|
executionReport = {
|
|
@@ -1673,9 +1709,9 @@
|
|
|
1673
1709
|
description: promptbook.description,
|
|
1674
1710
|
promptExecutions: [],
|
|
1675
1711
|
};
|
|
1676
|
-
|
|
1712
|
+
_d.label = 1;
|
|
1677
1713
|
case 1:
|
|
1678
|
-
|
|
1714
|
+
_d.trys.push([1, 6, , 7]);
|
|
1679
1715
|
resovedParameters_1 = promptbook.parameters
|
|
1680
1716
|
.filter(function (_a) {
|
|
1681
1717
|
var isInput = _a.isInput;
|
|
@@ -1689,8 +1725,8 @@
|
|
|
1689
1725
|
resolving_1 = [];
|
|
1690
1726
|
_loop_1 = function () {
|
|
1691
1727
|
var currentTemplate, work_1;
|
|
1692
|
-
return __generator(this, function (
|
|
1693
|
-
switch (
|
|
1728
|
+
return __generator(this, function (_e) {
|
|
1729
|
+
switch (_e.label) {
|
|
1694
1730
|
case 0:
|
|
1695
1731
|
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1696
1732
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
@@ -1701,7 +1737,7 @@
|
|
|
1701
1737
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1702
1738
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1703
1739
|
case 2:
|
|
1704
|
-
/* [5] */
|
|
1740
|
+
/* [5] */ _e.sent();
|
|
1705
1741
|
return [3 /*break*/, 4];
|
|
1706
1742
|
case 3:
|
|
1707
1743
|
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
@@ -1713,24 +1749,24 @@
|
|
|
1713
1749
|
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1714
1750
|
});
|
|
1715
1751
|
resolving_1.push(work_1);
|
|
1716
|
-
|
|
1752
|
+
_e.label = 4;
|
|
1717
1753
|
case 4: return [2 /*return*/];
|
|
1718
1754
|
}
|
|
1719
1755
|
});
|
|
1720
1756
|
};
|
|
1721
|
-
|
|
1757
|
+
_d.label = 2;
|
|
1722
1758
|
case 2:
|
|
1723
1759
|
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1724
1760
|
return [5 /*yield**/, _loop_1()];
|
|
1725
1761
|
case 3:
|
|
1726
|
-
|
|
1762
|
+
_d.sent();
|
|
1727
1763
|
return [3 /*break*/, 2];
|
|
1728
1764
|
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1729
1765
|
case 5:
|
|
1730
|
-
|
|
1766
|
+
_d.sent();
|
|
1731
1767
|
return [3 /*break*/, 7];
|
|
1732
1768
|
case 6:
|
|
1733
|
-
error_1 =
|
|
1769
|
+
error_1 = _d.sent();
|
|
1734
1770
|
if (!(error_1 instanceof Error)) {
|
|
1735
1771
|
throw error_1;
|
|
1736
1772
|
}
|
|
@@ -1740,12 +1776,30 @@
|
|
|
1740
1776
|
executionReport: executionReport,
|
|
1741
1777
|
outputParameters: parametersToPass,
|
|
1742
1778
|
}];
|
|
1743
|
-
case 7:
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1779
|
+
case 7:
|
|
1780
|
+
try {
|
|
1781
|
+
// Note: Filter ONLY output parameters
|
|
1782
|
+
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1783
|
+
parameter = _b.value;
|
|
1784
|
+
if (parameter.isOutput) {
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
delete parametersToPass[parameter.name];
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1791
|
+
finally {
|
|
1792
|
+
try {
|
|
1793
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1794
|
+
}
|
|
1795
|
+
finally { if (e_1) throw e_1.error; }
|
|
1796
|
+
}
|
|
1797
|
+
return [2 /*return*/, {
|
|
1798
|
+
isSuccessful: true,
|
|
1799
|
+
errors: [],
|
|
1800
|
+
executionReport: executionReport,
|
|
1801
|
+
outputParameters: parametersToPass,
|
|
1802
|
+
}];
|
|
1749
1803
|
}
|
|
1750
1804
|
});
|
|
1751
1805
|
}); };
|
|
@@ -1755,6 +1809,7 @@
|
|
|
1755
1809
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1756
1810
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1757
1811
|
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1812
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1758
1813
|
*/
|
|
1759
1814
|
|
|
1760
1815
|
/**
|