@promptbook/cli 0.84.0-11 โ 0.84.0-12
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 +41 -53
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/config.d.ts +9 -1
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/wizzard/wizzard.d.ts +7 -1
- package/package.json +1 -1
- package/umd/index.umd.js +41 -53
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -38,7 +38,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
38
38
|
* @generated
|
|
39
39
|
* @see https://github.com/webgptorg/promptbook
|
|
40
40
|
*/
|
|
41
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
41
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
42
42
|
/**
|
|
43
43
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
44
44
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -314,6 +314,14 @@ var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
|
314
314
|
*/
|
|
315
315
|
var DEFAULT_BOOKS_DIRNAME = './books';
|
|
316
316
|
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
317
|
+
/**
|
|
318
|
+
* Where to store the temporary downloads
|
|
319
|
+
*
|
|
320
|
+
* Note: When the folder does not exist, it is created recursively
|
|
321
|
+
*
|
|
322
|
+
* @public exported from `@promptbook/core`
|
|
323
|
+
*/
|
|
324
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
317
325
|
/**
|
|
318
326
|
* Where to store the cache of executions for promptbook CLI
|
|
319
327
|
*
|
|
@@ -321,7 +329,7 @@ var DEFAULT_BOOKS_DIRNAME = './books';
|
|
|
321
329
|
*
|
|
322
330
|
* @public exported from `@promptbook/core`
|
|
323
331
|
*/
|
|
324
|
-
var
|
|
332
|
+
var DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
|
|
325
333
|
/**
|
|
326
334
|
* Where to store the scrape cache
|
|
327
335
|
*
|
|
@@ -516,6 +524,7 @@ function $provideFilesystemForNode(options) {
|
|
|
516
524
|
readFile: readFile,
|
|
517
525
|
writeFile: writeFile,
|
|
518
526
|
readdir: readdir,
|
|
527
|
+
mkdir: mkdir,
|
|
519
528
|
};
|
|
520
529
|
}
|
|
521
530
|
/**
|
|
@@ -2717,7 +2726,7 @@ function $provideLlmToolsForWizzardOrCli(options) {
|
|
|
2717
2726
|
_c.sent()]),
|
|
2718
2727
|
{
|
|
2719
2728
|
storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, {
|
|
2720
|
-
rootFolderPath: join(process.cwd(),
|
|
2729
|
+
rootFolderPath: join(process.cwd(), DEFAULT_EXECUTION_CACHE_DIRNAME),
|
|
2721
2730
|
}),
|
|
2722
2731
|
isCacheReloaded: isCacheReloaded,
|
|
2723
2732
|
}])];
|
|
@@ -6501,10 +6510,11 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
6501
6510
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
6502
6511
|
var _a;
|
|
6503
6512
|
return __awaiter(this, void 0, void 0, function () {
|
|
6504
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
6505
|
-
return __generator(this, function (
|
|
6506
|
-
switch (
|
|
6513
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response, mimeType, filename, hash, rootDirname_1, filepath, _f, _g, _h, _j, _k, filename_1, fileExtension, mimeType;
|
|
6514
|
+
return __generator(this, function (_l) {
|
|
6515
|
+
switch (_l.label) {
|
|
6507
6516
|
case 0:
|
|
6517
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
6508
6518
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
6509
6519
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
6510
6520
|
name = knowledgeSource.name;
|
|
@@ -6512,54 +6522,32 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6512
6522
|
if (!name) {
|
|
6513
6523
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
6514
6524
|
}
|
|
6515
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
6525
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
6516
6526
|
url = knowledgeSourceContent;
|
|
6517
6527
|
return [4 /*yield*/, fetch(url)];
|
|
6518
6528
|
case 1:
|
|
6519
|
-
|
|
6520
|
-
mimeType = ((_a =
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
/*
|
|
6527
|
-
TODO: [๐ฅฝ]
|
|
6528
|
-
> async asBlob() {
|
|
6529
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
6530
|
-
> const content = await response.blob();
|
|
6531
|
-
> return content;
|
|
6532
|
-
> },
|
|
6533
|
-
*/
|
|
6534
|
-
asJson: function () {
|
|
6535
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
6536
|
-
var content;
|
|
6537
|
-
return __generator(this, function (_a) {
|
|
6538
|
-
switch (_a.label) {
|
|
6539
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
6540
|
-
case 1:
|
|
6541
|
-
content = _a.sent();
|
|
6542
|
-
return [2 /*return*/, content];
|
|
6543
|
-
}
|
|
6544
|
-
});
|
|
6545
|
-
});
|
|
6546
|
-
},
|
|
6547
|
-
asText: function () {
|
|
6548
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
6549
|
-
var content;
|
|
6550
|
-
return __generator(this, function (_a) {
|
|
6551
|
-
switch (_a.label) {
|
|
6552
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
6553
|
-
case 1:
|
|
6554
|
-
content = _a.sent();
|
|
6555
|
-
return [2 /*return*/, content];
|
|
6556
|
-
}
|
|
6557
|
-
});
|
|
6558
|
-
});
|
|
6559
|
-
},
|
|
6560
|
-
}];
|
|
6529
|
+
response = _l.sent();
|
|
6530
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6531
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
6532
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
6533
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6534
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), ["".concat(filename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
|
|
6535
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
6561
6536
|
case 2:
|
|
6562
|
-
|
|
6537
|
+
_l.sent();
|
|
6538
|
+
_g = (_f = tools.fs).writeFile;
|
|
6539
|
+
_h = [join(rootDirname_1, filepath)];
|
|
6540
|
+
_k = (_j = Buffer).from;
|
|
6541
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
6542
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6543
|
+
case 4:
|
|
6544
|
+
_l.sent();
|
|
6545
|
+
// TODO: !!!!!!!! Check the file security
|
|
6546
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
6547
|
+
// TODO: !!!!!!!! Delete the file
|
|
6548
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6549
|
+
case 5:
|
|
6550
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
6563
6551
|
if (tools.fs === undefined) {
|
|
6564
6552
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
6565
6553
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -6572,8 +6560,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6572
6560
|
fileExtension = getFileExtension(filename_1);
|
|
6573
6561
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
6574
6562
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6575
|
-
case
|
|
6576
|
-
if (!(
|
|
6563
|
+
case 6:
|
|
6564
|
+
if (!(_l.sent())) {
|
|
6577
6565
|
throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
6578
6566
|
}
|
|
6579
6567
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -6619,7 +6607,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6619
6607
|
});
|
|
6620
6608
|
},
|
|
6621
6609
|
}];
|
|
6622
|
-
case
|
|
6610
|
+
case 7: return [2 /*return*/, {
|
|
6623
6611
|
source: name,
|
|
6624
6612
|
filename: null,
|
|
6625
6613
|
url: null,
|