@promptbook/documents 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 +46 -51
- 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 +2 -2
- package/umd/index.umd.js +50 -55
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/documents",
|
|
3
|
-
"version": "0.84.0-
|
|
3
|
+
"version": "0.84.0-12",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"--note-0": " <- [๐]",
|
|
6
6
|
"private": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
55
55
|
"typings": "./esm/typings/src/_packages/documents.index.d.ts",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@promptbook/core": "0.84.0-
|
|
57
|
+
"@promptbook/core": "0.84.0-12"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('mime-types'), require('papaparse')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'mime-types', 'papaparse'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.mimeTypes, global.papaparse));
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml, mimeTypes, papaparse) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml, sha256, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
11
11
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
12
12
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
13
|
+
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
13
14
|
|
|
14
15
|
// โ ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
15
16
|
/**
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
* @generated
|
|
26
27
|
* @see https://github.com/webgptorg/promptbook
|
|
27
28
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
29
30
|
/**
|
|
30
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
32
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -229,6 +230,12 @@
|
|
|
229
230
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
230
231
|
*/
|
|
231
232
|
var IMMEDIATE_TIME = 10;
|
|
233
|
+
/**
|
|
234
|
+
* The maximum length of the (generated) filename
|
|
235
|
+
*
|
|
236
|
+
* @public exported from `@promptbook/core`
|
|
237
|
+
*/
|
|
238
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
232
239
|
/**
|
|
233
240
|
* Strategy for caching the intermediate results for knowledge sources
|
|
234
241
|
*
|
|
@@ -248,6 +255,15 @@
|
|
|
248
255
|
* @public exported from `@promptbook/core`
|
|
249
256
|
*/
|
|
250
257
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
258
|
+
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
259
|
+
/**
|
|
260
|
+
* Where to store the temporary downloads
|
|
261
|
+
*
|
|
262
|
+
* Note: When the folder does not exist, it is created recursively
|
|
263
|
+
*
|
|
264
|
+
* @public exported from `@promptbook/core`
|
|
265
|
+
*/
|
|
266
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
251
267
|
/**
|
|
252
268
|
* Where to store the scrape cache
|
|
253
269
|
*
|
|
@@ -3750,10 +3766,11 @@
|
|
|
3750
3766
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3751
3767
|
var _a;
|
|
3752
3768
|
return __awaiter(this, void 0, void 0, function () {
|
|
3753
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3754
|
-
return __generator(this, function (
|
|
3755
|
-
switch (
|
|
3769
|
+
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;
|
|
3770
|
+
return __generator(this, function (_l) {
|
|
3771
|
+
switch (_l.label) {
|
|
3756
3772
|
case 0:
|
|
3773
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3757
3774
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3758
3775
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
3759
3776
|
name = knowledgeSource.name;
|
|
@@ -3761,54 +3778,32 @@
|
|
|
3761
3778
|
if (!name) {
|
|
3762
3779
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3763
3780
|
}
|
|
3764
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3781
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3765
3782
|
url = knowledgeSourceContent;
|
|
3766
3783
|
return [4 /*yield*/, fetch(url)];
|
|
3767
3784
|
case 1:
|
|
3768
|
-
|
|
3769
|
-
mimeType = ((_a =
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
/*
|
|
3776
|
-
TODO: [๐ฅฝ]
|
|
3777
|
-
> async asBlob() {
|
|
3778
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
3779
|
-
> const content = await response.blob();
|
|
3780
|
-
> return content;
|
|
3781
|
-
> },
|
|
3782
|
-
*/
|
|
3783
|
-
asJson: function () {
|
|
3784
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3785
|
-
var content;
|
|
3786
|
-
return __generator(this, function (_a) {
|
|
3787
|
-
switch (_a.label) {
|
|
3788
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
3789
|
-
case 1:
|
|
3790
|
-
content = _a.sent();
|
|
3791
|
-
return [2 /*return*/, content];
|
|
3792
|
-
}
|
|
3793
|
-
});
|
|
3794
|
-
});
|
|
3795
|
-
},
|
|
3796
|
-
asText: function () {
|
|
3797
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3798
|
-
var content;
|
|
3799
|
-
return __generator(this, function (_a) {
|
|
3800
|
-
switch (_a.label) {
|
|
3801
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
3802
|
-
case 1:
|
|
3803
|
-
content = _a.sent();
|
|
3804
|
-
return [2 /*return*/, content];
|
|
3805
|
-
}
|
|
3806
|
-
});
|
|
3807
|
-
});
|
|
3808
|
-
},
|
|
3809
|
-
}];
|
|
3785
|
+
response = _l.sent();
|
|
3786
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3787
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
3788
|
+
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3789
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3790
|
+
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));
|
|
3791
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3810
3792
|
case 2:
|
|
3811
|
-
|
|
3793
|
+
_l.sent();
|
|
3794
|
+
_g = (_f = tools.fs).writeFile;
|
|
3795
|
+
_h = [path.join(rootDirname_1, filepath)];
|
|
3796
|
+
_k = (_j = Buffer).from;
|
|
3797
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
3798
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3799
|
+
case 4:
|
|
3800
|
+
_l.sent();
|
|
3801
|
+
// TODO: !!!!!!!! Check the file security
|
|
3802
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
3803
|
+
// TODO: !!!!!!!! Delete the file
|
|
3804
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3805
|
+
case 5:
|
|
3806
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3812
3807
|
if (tools.fs === undefined) {
|
|
3813
3808
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3814
3809
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -3821,8 +3816,8 @@
|
|
|
3821
3816
|
fileExtension = getFileExtension(filename_1);
|
|
3822
3817
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3823
3818
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3824
|
-
case
|
|
3825
|
-
if (!(
|
|
3819
|
+
case 6:
|
|
3820
|
+
if (!(_l.sent())) {
|
|
3826
3821
|
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 "); }));
|
|
3827
3822
|
}
|
|
3828
3823
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3868,7 +3863,7 @@
|
|
|
3868
3863
|
});
|
|
3869
3864
|
},
|
|
3870
3865
|
}];
|
|
3871
|
-
case
|
|
3866
|
+
case 7: return [2 /*return*/, {
|
|
3872
3867
|
source: name,
|
|
3873
3868
|
filename: null,
|
|
3874
3869
|
url: null,
|