@promptbook/cli 0.84.0-11 โ 0.84.0-13
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 +80 -50
- 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 +80 -50
- 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-12';
|
|
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, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
6505
|
-
return __generator(this, function (
|
|
6506
|
-
switch (
|
|
6513
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, 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,74 @@ 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
|
-
response_1 =
|
|
6529
|
+
response_1 = _l.sent();
|
|
6520
6530
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6531
|
+
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
6532
|
+
return [2 /*return*/, {
|
|
6533
|
+
source: name,
|
|
6534
|
+
filename: null,
|
|
6535
|
+
url: url,
|
|
6536
|
+
mimeType: mimeType,
|
|
6537
|
+
/*
|
|
6538
|
+
TODO: [๐ฅฝ]
|
|
6539
|
+
> async asBlob() {
|
|
6540
|
+
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
6541
|
+
> const content = await response.blob();
|
|
6542
|
+
> return content;
|
|
6543
|
+
> },
|
|
6544
|
+
*/
|
|
6545
|
+
asJson: function () {
|
|
6546
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6547
|
+
var content;
|
|
6548
|
+
return __generator(this, function (_a) {
|
|
6549
|
+
switch (_a.label) {
|
|
6550
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
6551
|
+
case 1:
|
|
6552
|
+
content = _a.sent();
|
|
6553
|
+
return [2 /*return*/, content];
|
|
6554
|
+
}
|
|
6555
|
+
});
|
|
6544
6556
|
});
|
|
6545
|
-
}
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
}
|
|
6557
|
+
},
|
|
6558
|
+
asText: function () {
|
|
6559
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6560
|
+
var content;
|
|
6561
|
+
return __generator(this, function (_a) {
|
|
6562
|
+
switch (_a.label) {
|
|
6563
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
6564
|
+
case 1:
|
|
6565
|
+
content = _a.sent();
|
|
6566
|
+
return [2 /*return*/, content];
|
|
6567
|
+
}
|
|
6568
|
+
});
|
|
6557
6569
|
});
|
|
6558
|
-
}
|
|
6559
|
-
}
|
|
6560
|
-
|
|
6570
|
+
},
|
|
6571
|
+
}];
|
|
6572
|
+
}
|
|
6573
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
6574
|
+
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
6575
|
+
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6576
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [๐] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
|
|
6577
|
+
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
6561
6578
|
case 2:
|
|
6562
|
-
|
|
6579
|
+
_l.sent();
|
|
6580
|
+
_g = (_f = tools.fs).writeFile;
|
|
6581
|
+
_h = [join(rootDirname_1, filepath)];
|
|
6582
|
+
_k = (_j = Buffer).from;
|
|
6583
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
6584
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6585
|
+
case 4:
|
|
6586
|
+
_l.sent();
|
|
6587
|
+
// TODO: !!!!!!!! Check the file security
|
|
6588
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
6589
|
+
// TODO: !!!!!!!! Delete the file
|
|
6590
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6591
|
+
case 5:
|
|
6592
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
6563
6593
|
if (tools.fs === undefined) {
|
|
6564
6594
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
6565
6595
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -6572,8 +6602,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6572
6602
|
fileExtension = getFileExtension(filename_1);
|
|
6573
6603
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
6574
6604
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6575
|
-
case
|
|
6576
|
-
if (!(
|
|
6605
|
+
case 6:
|
|
6606
|
+
if (!(_l.sent())) {
|
|
6577
6607
|
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
6608
|
}
|
|
6579
6609
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -6619,7 +6649,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6619
6649
|
});
|
|
6620
6650
|
},
|
|
6621
6651
|
}];
|
|
6622
|
-
case
|
|
6652
|
+
case 7: return [2 /*return*/, {
|
|
6623
6653
|
source: name,
|
|
6624
6654
|
filename: null,
|
|
6625
6655
|
url: null,
|