@promptbook/cli 0.86.5 โ 0.86.8
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/README.md +13 -8
- package/esm/index.es.js +48 -34
- package/esm/index.es.js.map +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +48 -34
- package/umd/index.umd.js.map +1 -1
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
* @generated
|
|
55
55
|
* @see https://github.com/webgptorg/promptbook
|
|
56
56
|
*/
|
|
57
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
57
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.86.8';
|
|
58
58
|
/**
|
|
59
59
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
60
60
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -1516,9 +1516,11 @@
|
|
|
1516
1516
|
FileCacheStorage.prototype.getFilenameForKey = function (key) {
|
|
1517
1517
|
// TODO: [๐ฌ] DRY
|
|
1518
1518
|
var name = titleToName(key);
|
|
1519
|
+
var nameStart = name.split('-', 2)[0] || 'unnamed';
|
|
1519
1520
|
var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
|
|
1520
1521
|
// <- TODO: [๐ฅฌ] Encapsulate sha256 to some private utility function
|
|
1521
|
-
return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath
|
|
1522
|
+
return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.rootFolderPath,
|
|
1523
|
+
nameStart], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
|
|
1522
1524
|
};
|
|
1523
1525
|
/**
|
|
1524
1526
|
* @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
@@ -1704,13 +1706,14 @@
|
|
|
1704
1706
|
return /* not await */ llmTools.listModels();
|
|
1705
1707
|
} });
|
|
1706
1708
|
var callCommonModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
1707
|
-
var key, cacheItem, _a, promptResult, _b;
|
|
1709
|
+
var parameters, content, modelRequirements, key, cacheItem, _a, promptResult, _b;
|
|
1708
1710
|
return __generator(this, function (_c) {
|
|
1709
1711
|
switch (_c.label) {
|
|
1710
1712
|
case 0:
|
|
1713
|
+
parameters = prompt.parameters, content = prompt.content, modelRequirements = prompt.modelRequirements;
|
|
1711
1714
|
key = titleToName(prompt.title.substring(0, MAX_FILENAME_LENGTH - 10) +
|
|
1712
1715
|
'-' +
|
|
1713
|
-
sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(
|
|
1716
|
+
sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify({ parameters: parameters, content: content, modelRequirements: modelRequirements }))).toString( /* hex */));
|
|
1714
1717
|
if (!!isCacheReloaded) return [3 /*break*/, 2];
|
|
1715
1718
|
return [4 /*yield*/, storage.getItem(key)];
|
|
1716
1719
|
case 1:
|
|
@@ -7597,7 +7600,9 @@
|
|
|
7597
7600
|
return __generator(this, function (_a) {
|
|
7598
7601
|
dependentParameterNames = task.dependentParameterNames;
|
|
7599
7602
|
preparedContent = undefined;
|
|
7600
|
-
if (
|
|
7603
|
+
if (task.taskType === 'PROMPT_TASK' &&
|
|
7604
|
+
knowledgePiecesCount > 0 &&
|
|
7605
|
+
!dependentParameterNames.includes('knowledge')) {
|
|
7601
7606
|
preparedContent = spaceTrim.spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
7602
7607
|
// <- TODO: [๐ง ][๐งป] Cutomize shape/language/formatting of the addition to the prompt
|
|
7603
7608
|
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
@@ -13027,31 +13032,31 @@
|
|
|
13027
13032
|
*/
|
|
13028
13033
|
function $getCompiledBook(tools, pipelineSource, options) {
|
|
13029
13034
|
return __awaiter(this, void 0, void 0, function () {
|
|
13030
|
-
var fs, fetch, filePathRaw, filePath, filePathCandidates, filePathCandidates_1, filePathCandidates_1_1, filePathCandidate, pipelineString, _a, pipelineJson, e_1_1, rootDirname, _loop_1, i, state_1, response_1, pipelineString, pipelineJson, pipelineJson;
|
|
13035
|
+
var fs, fetch, filePathRaw, filePath, filePathCandidates, filePathCandidates_1, filePathCandidates_1_1, filePathCandidate, pipelineString, _a, pipelineJson, compiledFilePath, bookcBundle, data, e_1_1, rootDirname, _loop_1, i, state_1, response_1, pipelineString, pipelineJson, pipelineJson;
|
|
13031
13036
|
var e_1, _b;
|
|
13032
13037
|
var _this = this;
|
|
13033
13038
|
return __generator(this, function (_c) {
|
|
13034
13039
|
switch (_c.label) {
|
|
13035
13040
|
case 0:
|
|
13036
13041
|
fs = tools.fs, fetch = tools.fetch;
|
|
13037
|
-
if (!isValidFilePath(pipelineSource)) return [3 /*break*/,
|
|
13042
|
+
if (!isValidFilePath(pipelineSource)) return [3 /*break*/, 12];
|
|
13038
13043
|
filePathRaw = pipelineSource;
|
|
13039
13044
|
filePath = null;
|
|
13040
13045
|
filePathCandidates = [filePathRaw, "".concat(filePathRaw, ".md"), "".concat(filePathRaw, ".book"), "".concat(filePathRaw, ".book")];
|
|
13041
13046
|
filePathCandidates = __spreadArray(__spreadArray([], __read(filePathCandidates), false), __read(filePathCandidates.map(function (path) { return path.split('\\').join('/'); })), false);
|
|
13042
13047
|
_c.label = 1;
|
|
13043
13048
|
case 1:
|
|
13044
|
-
_c.trys.push([1,
|
|
13049
|
+
_c.trys.push([1, 10, 11, 12]);
|
|
13045
13050
|
filePathCandidates_1 = __values(filePathCandidates), filePathCandidates_1_1 = filePathCandidates_1.next();
|
|
13046
13051
|
_c.label = 2;
|
|
13047
13052
|
case 2:
|
|
13048
|
-
if (!!filePathCandidates_1_1.done) return [3 /*break*/,
|
|
13053
|
+
if (!!filePathCandidates_1_1.done) return [3 /*break*/, 9];
|
|
13049
13054
|
filePathCandidate = filePathCandidates_1_1.value;
|
|
13050
13055
|
return [4 /*yield*/, isFileExisting(filePathCandidate, fs)
|
|
13051
13056
|
// <- TODO: Also test that among the candidates the file is book not just any file
|
|
13052
13057
|
];
|
|
13053
13058
|
case 3:
|
|
13054
|
-
if (!_c.sent()) return [3 /*break*/,
|
|
13059
|
+
if (!_c.sent()) return [3 /*break*/, 8];
|
|
13055
13060
|
filePath = filePathCandidate;
|
|
13056
13061
|
_a = validatePipelineString;
|
|
13057
13062
|
return [4 /*yield*/, fs.readFile(filePath, 'utf-8')];
|
|
@@ -13060,23 +13065,32 @@
|
|
|
13060
13065
|
return [4 /*yield*/, compilePipeline(pipelineString, tools, __assign({ rootDirname: process.cwd() }, options))];
|
|
13061
13066
|
case 5:
|
|
13062
13067
|
pipelineJson = _c.sent();
|
|
13063
|
-
|
|
13068
|
+
compiledFilePath = filePath.replace('.book.md', '.book').replace('.book', '.bookc');
|
|
13069
|
+
bookcBundle = new JSZip__default["default"]();
|
|
13070
|
+
bookcBundle.file('index.book.json', JSON.stringify([pipelineJson]));
|
|
13071
|
+
return [4 /*yield*/, bookcBundle.generateAsync({ type: 'nodebuffer', streamFiles: true })];
|
|
13064
13072
|
case 6:
|
|
13073
|
+
data = _c.sent();
|
|
13074
|
+
return [4 /*yield*/, fs.writeFile(compiledFilePath, data)];
|
|
13075
|
+
case 7:
|
|
13076
|
+
_c.sent();
|
|
13077
|
+
return [2 /*return*/, pipelineJson];
|
|
13078
|
+
case 8:
|
|
13065
13079
|
filePathCandidates_1_1 = filePathCandidates_1.next();
|
|
13066
13080
|
return [3 /*break*/, 2];
|
|
13067
|
-
case
|
|
13068
|
-
case
|
|
13081
|
+
case 9: return [3 /*break*/, 12];
|
|
13082
|
+
case 10:
|
|
13069
13083
|
e_1_1 = _c.sent();
|
|
13070
13084
|
e_1 = { error: e_1_1 };
|
|
13071
|
-
return [3 /*break*/,
|
|
13072
|
-
case
|
|
13085
|
+
return [3 /*break*/, 12];
|
|
13086
|
+
case 11:
|
|
13073
13087
|
try {
|
|
13074
13088
|
if (filePathCandidates_1_1 && !filePathCandidates_1_1.done && (_b = filePathCandidates_1.return)) _b.call(filePathCandidates_1);
|
|
13075
13089
|
}
|
|
13076
13090
|
finally { if (e_1) throw e_1.error; }
|
|
13077
13091
|
return [7 /*endfinally*/];
|
|
13078
|
-
case
|
|
13079
|
-
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/,
|
|
13092
|
+
case 12:
|
|
13093
|
+
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/, 16];
|
|
13080
13094
|
rootDirname = process.cwd();
|
|
13081
13095
|
_loop_1 = function (i) {
|
|
13082
13096
|
var booksDirname, collection_1, pipeline;
|
|
@@ -13127,47 +13141,47 @@
|
|
|
13127
13141
|
});
|
|
13128
13142
|
};
|
|
13129
13143
|
i = 0;
|
|
13130
|
-
_c.label =
|
|
13131
|
-
case
|
|
13132
|
-
if (!(i < LOOP_LIMIT)) return [3 /*break*/,
|
|
13144
|
+
_c.label = 13;
|
|
13145
|
+
case 13:
|
|
13146
|
+
if (!(i < LOOP_LIMIT)) return [3 /*break*/, 16];
|
|
13133
13147
|
return [5 /*yield**/, _loop_1(i)];
|
|
13134
|
-
case
|
|
13148
|
+
case 14:
|
|
13135
13149
|
state_1 = _c.sent();
|
|
13136
13150
|
if (typeof state_1 === "object")
|
|
13137
13151
|
return [2 /*return*/, state_1.value];
|
|
13138
13152
|
switch (state_1) {
|
|
13139
|
-
case "break-up_to_root": return [3 /*break*/,
|
|
13153
|
+
case "break-up_to_root": return [3 /*break*/, 16];
|
|
13140
13154
|
}
|
|
13141
|
-
_c.label =
|
|
13142
|
-
case
|
|
13155
|
+
_c.label = 15;
|
|
13156
|
+
case 15:
|
|
13143
13157
|
i++;
|
|
13144
|
-
return [3 /*break*/,
|
|
13145
|
-
case
|
|
13146
|
-
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/,
|
|
13158
|
+
return [3 /*break*/, 13];
|
|
13159
|
+
case 16:
|
|
13160
|
+
if (!isValidPipelineUrl(pipelineSource)) return [3 /*break*/, 20];
|
|
13147
13161
|
return [4 /*yield*/, fetch(pipelineSource)];
|
|
13148
|
-
case
|
|
13162
|
+
case 17:
|
|
13149
13163
|
response_1 = _c.sent();
|
|
13150
13164
|
if (response_1.status >= 300) {
|
|
13151
13165
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found on URL:\n ".concat(block(pipelineSource), "\n\n Request failed with status ").concat(block(response_1.status.toString()), " ").concat(block(response_1.statusText), "\n "); }));
|
|
13152
13166
|
}
|
|
13153
13167
|
return [4 /*yield*/, response_1.text()];
|
|
13154
|
-
case
|
|
13168
|
+
case 18:
|
|
13155
13169
|
pipelineString = _c.sent();
|
|
13156
13170
|
// console.log({ pipelineString });
|
|
13157
13171
|
if (!isValidPipelineString(pipelineString)) {
|
|
13158
13172
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found on URL:\n ".concat(block(pipelineSource), "\n\n Requested URL does not seem to contain a valid book\n "); }));
|
|
13159
13173
|
}
|
|
13160
13174
|
return [4 /*yield*/, compilePipeline(pipelineString, tools, __assign({ rootDirname: null }, options))];
|
|
13161
|
-
case
|
|
13175
|
+
case 19:
|
|
13162
13176
|
pipelineJson = _c.sent();
|
|
13163
13177
|
return [2 /*return*/, pipelineJson];
|
|
13164
|
-
case
|
|
13165
|
-
if (!isValidPipelineString(pipelineSource)) return [3 /*break*/,
|
|
13178
|
+
case 20:
|
|
13179
|
+
if (!isValidPipelineString(pipelineSource)) return [3 /*break*/, 22];
|
|
13166
13180
|
return [4 /*yield*/, compilePipeline(pipelineSource, tools, __assign({ rootDirname: null }, options))];
|
|
13167
|
-
case
|
|
13181
|
+
case 21:
|
|
13168
13182
|
pipelineJson = _c.sent();
|
|
13169
13183
|
return [2 /*return*/, pipelineJson];
|
|
13170
|
-
case
|
|
13184
|
+
case 22: /* not else */ throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Book not found:\n ".concat(block(pipelineSource), "\n\n Pipelines can be loaded from:\n 1) As a file ./books/write-cv.book\n 2) As a URL https://promptbook.studio/hejny/write-cv.book found in ./books folder recursively\n 2) As a URL https://promptbook.studio/hejny/write-cv.book fetched from the internet\n 3) As a string\n\n\n "); }));
|
|
13171
13185
|
}
|
|
13172
13186
|
});
|
|
13173
13187
|
});
|