@promptbook/pdf 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/pdf",
|
|
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/pdf.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
|
"crypto-js": "4.2.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('mime-types'), require('papaparse')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'waitasecond', 'mime-types', 'papaparse'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.waitasecond, global.mimeTypes, global.papaparse));
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, waitasecond, mimeTypes, papaparse) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, waitasecond, 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
|
|
|
9
9
|
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
10
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
11
11
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
12
|
+
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
12
13
|
|
|
13
14
|
// โ ๏ธ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
14
15
|
/**
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
* @generated
|
|
25
26
|
* @see https://github.com/webgptorg/promptbook
|
|
26
27
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-11';
|
|
28
29
|
/**
|
|
29
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
31
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -228,6 +229,12 @@
|
|
|
228
229
|
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
229
230
|
*/
|
|
230
231
|
var IMMEDIATE_TIME = 10;
|
|
232
|
+
/**
|
|
233
|
+
* The maximum length of the (generated) filename
|
|
234
|
+
*
|
|
235
|
+
* @public exported from `@promptbook/core`
|
|
236
|
+
*/
|
|
237
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
231
238
|
/**
|
|
232
239
|
* Strategy for caching the intermediate results for knowledge sources
|
|
233
240
|
*
|
|
@@ -247,6 +254,15 @@
|
|
|
247
254
|
* @public exported from `@promptbook/core`
|
|
248
255
|
*/
|
|
249
256
|
var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [๐คนโโ๏ธ]
|
|
257
|
+
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
258
|
+
/**
|
|
259
|
+
* Where to store the temporary downloads
|
|
260
|
+
*
|
|
261
|
+
* Note: When the folder does not exist, it is created recursively
|
|
262
|
+
*
|
|
263
|
+
* @public exported from `@promptbook/core`
|
|
264
|
+
*/
|
|
265
|
+
var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
250
266
|
/**
|
|
251
267
|
* Where to store the scrape cache
|
|
252
268
|
*
|
|
@@ -3600,10 +3616,11 @@
|
|
|
3600
3616
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3601
3617
|
var _a;
|
|
3602
3618
|
return __awaiter(this, void 0, void 0, function () {
|
|
3603
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3604
|
-
return __generator(this, function (
|
|
3605
|
-
switch (
|
|
3619
|
+
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;
|
|
3620
|
+
return __generator(this, function (_l) {
|
|
3621
|
+
switch (_l.label) {
|
|
3606
3622
|
case 0:
|
|
3623
|
+
console.log('!!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3607
3624
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3608
3625
|
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
3609
3626
|
name = knowledgeSource.name;
|
|
@@ -3611,54 +3628,32 @@
|
|
|
3611
3628
|
if (!name) {
|
|
3612
3629
|
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
3613
3630
|
}
|
|
3614
|
-
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/,
|
|
3631
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
|
|
3615
3632
|
url = knowledgeSourceContent;
|
|
3616
3633
|
return [4 /*yield*/, fetch(url)];
|
|
3617
3634
|
case 1:
|
|
3618
|
-
|
|
3619
|
-
mimeType = ((_a =
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
/*
|
|
3626
|
-
TODO: [๐ฅฝ]
|
|
3627
|
-
> async asBlob() {
|
|
3628
|
-
> // TODO: [๐จ๐ปโ๐คโ๐จ๐ป] This can be called multiple times BUT when called second time, response in already consumed
|
|
3629
|
-
> const content = await response.blob();
|
|
3630
|
-
> return content;
|
|
3631
|
-
> },
|
|
3632
|
-
*/
|
|
3633
|
-
asJson: function () {
|
|
3634
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3635
|
-
var content;
|
|
3636
|
-
return __generator(this, function (_a) {
|
|
3637
|
-
switch (_a.label) {
|
|
3638
|
-
case 0: return [4 /*yield*/, response_1.json()];
|
|
3639
|
-
case 1:
|
|
3640
|
-
content = _a.sent();
|
|
3641
|
-
return [2 /*return*/, content];
|
|
3642
|
-
}
|
|
3643
|
-
});
|
|
3644
|
-
});
|
|
3645
|
-
},
|
|
3646
|
-
asText: function () {
|
|
3647
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3648
|
-
var content;
|
|
3649
|
-
return __generator(this, function (_a) {
|
|
3650
|
-
switch (_a.label) {
|
|
3651
|
-
case 0: return [4 /*yield*/, response_1.text()];
|
|
3652
|
-
case 1:
|
|
3653
|
-
content = _a.sent();
|
|
3654
|
-
return [2 /*return*/, content];
|
|
3655
|
-
}
|
|
3656
|
-
});
|
|
3657
|
-
});
|
|
3658
|
-
},
|
|
3659
|
-
}];
|
|
3635
|
+
response = _l.sent();
|
|
3636
|
+
mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3637
|
+
filename = url.split('/').pop() || titleToName(url);
|
|
3638
|
+
hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
|
|
3639
|
+
rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3640
|
+
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));
|
|
3641
|
+
return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
|
|
3660
3642
|
case 2:
|
|
3661
|
-
|
|
3643
|
+
_l.sent();
|
|
3644
|
+
_g = (_f = tools.fs).writeFile;
|
|
3645
|
+
_h = [path.join(rootDirname_1, filepath)];
|
|
3646
|
+
_k = (_j = Buffer).from;
|
|
3647
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
3648
|
+
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3649
|
+
case 4:
|
|
3650
|
+
_l.sent();
|
|
3651
|
+
// TODO: !!!!!!!! Check the file security
|
|
3652
|
+
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
3653
|
+
// TODO: !!!!!!!! Delete the file
|
|
3654
|
+
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
3655
|
+
case 5:
|
|
3656
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
3662
3657
|
if (tools.fs === undefined) {
|
|
3663
3658
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
3664
3659
|
// <- TODO: [๐ง ] What is the best error type here`
|
|
@@ -3671,8 +3666,8 @@
|
|
|
3671
3666
|
fileExtension = getFileExtension(filename_1);
|
|
3672
3667
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3673
3668
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3674
|
-
case
|
|
3675
|
-
if (!(
|
|
3669
|
+
case 6:
|
|
3670
|
+
if (!(_l.sent())) {
|
|
3676
3671
|
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 "); }));
|
|
3677
3672
|
}
|
|
3678
3673
|
// TODO: [๐ง ][๐ฟ] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -3718,7 +3713,7 @@
|
|
|
3718
3713
|
});
|
|
3719
3714
|
},
|
|
3720
3715
|
}];
|
|
3721
|
-
case
|
|
3716
|
+
case 7: return [2 /*return*/, {
|
|
3722
3717
|
source: name,
|
|
3723
3718
|
filename: null,
|
|
3724
3719
|
url: null,
|