@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
|
@@ -19,7 +19,8 @@ import { DEFAULT_MAX_EXECUTION_ATTEMPTS } from '../config';
|
|
|
19
19
|
import { DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH } from '../config';
|
|
20
20
|
import { DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL } from '../config';
|
|
21
21
|
import { DEFAULT_BOOKS_DIRNAME } from '../config';
|
|
22
|
-
import {
|
|
22
|
+
import { DEFAULT_DOWNLOAD_CACHE_DIRNAME } from '../config';
|
|
23
|
+
import { DEFAULT_EXECUTION_CACHE_DIRNAME } from '../config';
|
|
23
24
|
import { DEFAULT_SCRAPE_CACHE_DIRNAME } from '../config';
|
|
24
25
|
import { DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME } from '../config';
|
|
25
26
|
import { DEFAULT_REMOTE_URL } from '../config';
|
|
@@ -145,7 +146,8 @@ export { DEFAULT_MAX_EXECUTION_ATTEMPTS };
|
|
|
145
146
|
export { DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH };
|
|
146
147
|
export { DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL };
|
|
147
148
|
export { DEFAULT_BOOKS_DIRNAME };
|
|
148
|
-
export {
|
|
149
|
+
export { DEFAULT_DOWNLOAD_CACHE_DIRNAME };
|
|
150
|
+
export { DEFAULT_EXECUTION_CACHE_DIRNAME };
|
|
149
151
|
export { DEFAULT_SCRAPE_CACHE_DIRNAME };
|
|
150
152
|
export { DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME };
|
|
151
153
|
export { DEFAULT_REMOTE_URL };
|
|
@@ -166,6 +166,14 @@ export declare const DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
|
|
|
166
166
|
* @public exported from `@promptbook/core`
|
|
167
167
|
*/
|
|
168
168
|
export declare const DEFAULT_BOOKS_DIRNAME = "./books";
|
|
169
|
+
/**
|
|
170
|
+
* Where to store the temporary downloads
|
|
171
|
+
*
|
|
172
|
+
* Note: When the folder does not exist, it is created recursively
|
|
173
|
+
*
|
|
174
|
+
* @public exported from `@promptbook/core`
|
|
175
|
+
*/
|
|
176
|
+
export declare const DEFAULT_DOWNLOAD_CACHE_DIRNAME = "./.promptbook/download-cache";
|
|
169
177
|
/**
|
|
170
178
|
* Where to store the cache of executions for promptbook CLI
|
|
171
179
|
*
|
|
@@ -173,7 +181,7 @@ export declare const DEFAULT_BOOKS_DIRNAME = "./books";
|
|
|
173
181
|
*
|
|
174
182
|
* @public exported from `@promptbook/core`
|
|
175
183
|
*/
|
|
176
|
-
export declare const
|
|
184
|
+
export declare const DEFAULT_EXECUTION_CACHE_DIRNAME = "./.promptbook/execution-cache";
|
|
177
185
|
/**
|
|
178
186
|
* Where to store the scrape cache
|
|
179
187
|
*
|
|
@@ -3,7 +3,7 @@ import type fs from 'fs/promises';
|
|
|
3
3
|
/**
|
|
4
4
|
* Container for all the tools needed to manipulate with filesystem
|
|
5
5
|
*/
|
|
6
|
-
export type FilesystemTools = Pick<typeof fs, 'access' | 'constants' | 'readFile' | 'writeFile' | 'stat' | 'readdir'>;
|
|
6
|
+
export type FilesystemTools = Pick<typeof fs, 'access' | 'constants' | 'readFile' | 'writeFile' | 'stat' | 'readdir' | 'mkdir'>;
|
|
7
7
|
/**
|
|
8
8
|
* TODO: Implement destroyable pattern to free resources
|
|
9
9
|
*/
|
|
@@ -6,6 +6,7 @@ import type { PipelineString } from '../pipeline/PipelineString';
|
|
|
6
6
|
import type { TaskProgress } from '../types/TaskProgress';
|
|
7
7
|
import type { InputParameters } from '../types/typeAliases';
|
|
8
8
|
import type { string_filename } from '../types/typeAliases';
|
|
9
|
+
import type { string_parameter_value } from '../types/typeAliases';
|
|
9
10
|
import type { string_pipeline_url } from '../types/typeAliases';
|
|
10
11
|
/**
|
|
11
12
|
* Wizzard for simple usage of the Promptbook
|
|
@@ -27,7 +28,12 @@ declare class Wizzard {
|
|
|
27
28
|
*
|
|
28
29
|
* Note: This works simmilar to the `ptbk run` command
|
|
29
30
|
*/
|
|
30
|
-
execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<
|
|
31
|
+
execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<{
|
|
32
|
+
/**
|
|
33
|
+
* Simple result of the execution
|
|
34
|
+
*/
|
|
35
|
+
result: string_parameter_value;
|
|
36
|
+
} & PipelineExecutorResult>;
|
|
31
37
|
private executionTools;
|
|
32
38
|
/**
|
|
33
39
|
* Provides the tools automatically for the Node.js environment
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @generated
|
|
52
52
|
* @see https://github.com/webgptorg/promptbook
|
|
53
53
|
*/
|
|
54
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
54
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
55
55
|
/**
|
|
56
56
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
57
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -327,6 +327,14 @@
|
|
|
327
327
|
*/
|
|
328
328
|
var DEFAULT_BOOKS_DIRNAME = './books';
|
|
329
329
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
330
|
+
/**
|
|
331
|
+
* Where to store the temporary downloads
|
|
332
|
+
*
|
|
333
|
+
* Note: When the folder does not exist, it is created recursively
|
|
334
|
+
*
|
|
335
|
+
* @public exported from `@promptbook/core`
|
|
336
|
+
*/
|
|
337
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
330
338
|
/**
|
|
331
339
|
* Where to store the cache of executions for promptbook CLI
|
|
332
340
|
*
|
|
@@ -334,7 +342,7 @@
|
|
|
334
342
|
*
|
|
335
343
|
* @public exported from `@promptbook/core`
|
|
336
344
|
*/
|
|
337
|
-
var
|
|
345
|
+
var DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
|
|
338
346
|
/**
|
|
339
347
|
* Where to store the scrape cache
|
|
340
348
|
*
|
|
@@ -529,6 +537,7 @@
|
|
|
529
537
|
readFile: promises.readFile,
|
|
530
538
|
writeFile: promises.writeFile,
|
|
531
539
|
readdir: promises.readdir,
|
|
540
|
+
mkdir: promises.mkdir,
|
|
532
541
|
};
|
|
533
542
|
}
|
|
534
543
|
/**
|
|
@@ -2730,7 +2739,7 @@
|
|
|
2730
2739
|
_c.sent()]),
|
|
2731
2740
|
{
|
|
2732
2741
|
storage: new FileCacheStorage({ fs: $provideFilesystemForNode() }, {
|
|
2733
|
-
rootFolderPath: path.join(process.cwd(),
|
|
2742
|
+
rootFolderPath: path.join(process.cwd(), DEFAULT_EXECUTION_CACHE_DIRNAME),
|
|
2734
2743
|
}),
|
|
2735
2744
|
isCacheReloaded: isCacheReloaded,
|
|
2736
2745
|
}])];
|
|
@@ -6514,10 +6523,11 @@
|
|
|
6514
6523
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
6515
6524
|
var _a;
|
|
6516
6525
|
return __awaiter(this, void 0, void 0, function () {
|
|
6517
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
6518
|
-
return __generator(this, function (
|
|
6519
|
-
switch (
|
|
6526
|
+
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;
|
|
6527
|
+
return __generator(this, function (_l) {
|
|
6528
|
+
switch (_l.label) {
|
|
6520
6529
|
case 0:
|
|
6530
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
6521
6531
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
6522
6532
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
6523
6533
|
name = knowledgeSource.name;
|
|
@@ -6525,54 +6535,32 @@
|
|
|
6525
6535
|
if (!name) {
|
|
6526
6536
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
6527
6537
|
}
|
|
6528
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
6538
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
6529
6539
|
url = knowledgeSourceContent;
|
|
6530
6540
|
return [4 /*yield*/, fetch(url)];
|
|
6531
6541
|
case 1:
|
|
6532
|
-
|
|
6533
|
-
mimeType = ((_a =
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
/*
|
|
6540
|
-
TODO: [🥽]
|
|
6541
|
-
> async asBlob() {
|
|
6542
|
-
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
6543
|
-
> const content = await response.blob();
|
|
6544
|
-
> return content;
|
|
6545
|
-
> },
|
|
6546
|
-
*/
|
|
6547
|
-
asJson: 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.json()];
|
|
6553
|
-
case 1:
|
|
6554
|
-
content = _a.sent();
|
|
6555
|
-
return [2 /*return*/, content];
|
|
6556
|
-
}
|
|
6557
|
-
});
|
|
6558
|
-
});
|
|
6559
|
-
},
|
|
6560
|
-
asText: function () {
|
|
6561
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
6562
|
-
var content;
|
|
6563
|
-
return __generator(this, function (_a) {
|
|
6564
|
-
switch (_a.label) {
|
|
6565
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
6566
|
-
case 1:
|
|
6567
|
-
content = _a.sent();
|
|
6568
|
-
return [2 /*return*/, content];
|
|
6569
|
-
}
|
|
6570
|
-
});
|
|
6571
|
-
});
|
|
6572
|
-
},
|
|
6573
|
-
}];
|
|
6542
|
+
response = _l.sent();
|
|
6543
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6544
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
6545
|
+
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
6546
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6547
|
+
filepath = path.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));
|
|
6548
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
6574
6549
|
case 2:
|
|
6575
|
-
|
|
6550
|
+
_l.sent();
|
|
6551
|
+
_g = (_f = tools.fs).writeFile;
|
|
6552
|
+
_h = [path.join(rootDirname_1, filepath)];
|
|
6553
|
+
_k = (_j = Buffer).from;
|
|
6554
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
6555
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6556
|
+
case 4:
|
|
6557
|
+
_l.sent();
|
|
6558
|
+
// TODO: !!!!!!!! Check the file security
|
|
6559
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
6560
|
+
// TODO: !!!!!!!! Delete the file
|
|
6561
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6562
|
+
case 5:
|
|
6563
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
6576
6564
|
if (tools.fs === undefined) {
|
|
6577
6565
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
6578
6566
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -6585,8 +6573,8 @@
|
|
|
6585
6573
|
fileExtension = getFileExtension(filename_1);
|
|
6586
6574
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
6587
6575
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6588
|
-
case
|
|
6589
|
-
if (!(
|
|
6576
|
+
case 6:
|
|
6577
|
+
if (!(_l.sent())) {
|
|
6590
6578
|
throw new NotFoundError(spaceTrim__default["default"](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 "); }));
|
|
6591
6579
|
}
|
|
6592
6580
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -6632,7 +6620,7 @@
|
|
|
6632
6620
|
});
|
|
6633
6621
|
},
|
|
6634
6622
|
}];
|
|
6635
|
-
case
|
|
6623
|
+
case 7: return [2 /*return*/, {
|
|
6636
6624
|
source: name,
|
|
6637
6625
|
filename: null,
|
|
6638
6626
|
url: null,
|