@promptbook/cli 0.84.0-12 → 0.84.0-14
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 +95 -16
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +12 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +94 -15
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -11,7 +11,7 @@ import { format } from 'prettier';
|
|
|
11
11
|
import parserHtml from 'prettier/parser-html';
|
|
12
12
|
import { unparse, parse } from 'papaparse';
|
|
13
13
|
import { SHA256 } from 'crypto-js';
|
|
14
|
-
import { lookup } from 'mime-types';
|
|
14
|
+
import { lookup, extension } from 'mime-types';
|
|
15
15
|
import { spawn } from 'child_process';
|
|
16
16
|
import glob from 'glob-promise';
|
|
17
17
|
import prompts from 'prompts';
|
|
@@ -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-13';
|
|
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
|
|
@@ -229,6 +229,12 @@ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
|
229
229
|
* @public exported from `@promptbook/core`
|
|
230
230
|
*/
|
|
231
231
|
var DEFAULT_TASK_TITLE = "Task";
|
|
232
|
+
/**
|
|
233
|
+
* When the pipeline is flat and no name of return parameter is provided, this name is used
|
|
234
|
+
*
|
|
235
|
+
* @public exported from `@promptbook/core`
|
|
236
|
+
*/
|
|
237
|
+
var DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
232
238
|
/**
|
|
233
239
|
* Warning message for the generated sections and files files
|
|
234
240
|
*
|
|
@@ -6475,6 +6481,17 @@ function getFileExtension(value) {
|
|
|
6475
6481
|
return match ? match[1].toLowerCase() : null;
|
|
6476
6482
|
}
|
|
6477
6483
|
|
|
6484
|
+
/**
|
|
6485
|
+
* Convert mime type to file extension
|
|
6486
|
+
*
|
|
6487
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
6488
|
+
*
|
|
6489
|
+
* @private within the repository
|
|
6490
|
+
*/
|
|
6491
|
+
function mimeTypeToExtension(value) {
|
|
6492
|
+
return extension(value) || null;
|
|
6493
|
+
}
|
|
6494
|
+
|
|
6478
6495
|
/**
|
|
6479
6496
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
6480
6497
|
*
|
|
@@ -6510,7 +6527,7 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
6510
6527
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
6511
6528
|
var _a;
|
|
6512
6529
|
return __awaiter(this, void 0, void 0, function () {
|
|
6513
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
6530
|
+
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
6531
|
return __generator(this, function (_l) {
|
|
6515
6532
|
switch (_l.label) {
|
|
6516
6533
|
case 0:
|
|
@@ -6526,25 +6543,67 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6526
6543
|
url = knowledgeSourceContent;
|
|
6527
6544
|
return [4 /*yield*/, fetch(url)];
|
|
6528
6545
|
case 1:
|
|
6529
|
-
|
|
6530
|
-
mimeType = ((_a =
|
|
6531
|
-
|
|
6546
|
+
response_1 = _l.sent();
|
|
6547
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6548
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
6549
|
+
return [2 /*return*/, {
|
|
6550
|
+
source: name,
|
|
6551
|
+
filename: null,
|
|
6552
|
+
url: url,
|
|
6553
|
+
mimeType: mimeType,
|
|
6554
|
+
/*
|
|
6555
|
+
TODO: [🥽]
|
|
6556
|
+
> async asBlob() {
|
|
6557
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
6558
|
+
> const content = await response.blob();
|
|
6559
|
+
> return content;
|
|
6560
|
+
> },
|
|
6561
|
+
*/
|
|
6562
|
+
asJson: function () {
|
|
6563
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6564
|
+
var content;
|
|
6565
|
+
return __generator(this, function (_a) {
|
|
6566
|
+
switch (_a.label) {
|
|
6567
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
6568
|
+
case 1:
|
|
6569
|
+
content = _a.sent();
|
|
6570
|
+
return [2 /*return*/, content];
|
|
6571
|
+
}
|
|
6572
|
+
});
|
|
6573
|
+
});
|
|
6574
|
+
},
|
|
6575
|
+
asText: function () {
|
|
6576
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6577
|
+
var content;
|
|
6578
|
+
return __generator(this, function (_a) {
|
|
6579
|
+
switch (_a.label) {
|
|
6580
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
6581
|
+
case 1:
|
|
6582
|
+
content = _a.sent();
|
|
6583
|
+
return [2 /*return*/, content];
|
|
6584
|
+
}
|
|
6585
|
+
});
|
|
6586
|
+
});
|
|
6587
|
+
},
|
|
6588
|
+
}];
|
|
6589
|
+
}
|
|
6590
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
6532
6591
|
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
6533
6592
|
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(
|
|
6593
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
|
|
6535
6594
|
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
6536
6595
|
case 2:
|
|
6537
6596
|
_l.sent();
|
|
6538
6597
|
_g = (_f = tools.fs).writeFile;
|
|
6539
6598
|
_h = [join(rootDirname_1, filepath)];
|
|
6540
6599
|
_k = (_j = Buffer).from;
|
|
6541
|
-
return [4 /*yield*/,
|
|
6600
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
6542
6601
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6543
6602
|
case 4:
|
|
6544
6603
|
_l.sent();
|
|
6545
|
-
// TODO:
|
|
6604
|
+
// TODO: [💵] Check the file security
|
|
6546
6605
|
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
6547
|
-
// TODO: !!!!!!!! Delete the file
|
|
6606
|
+
// TODO: !!!!!!!! Delete the file after the scraping is done
|
|
6548
6607
|
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6549
6608
|
case 5:
|
|
6550
6609
|
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
@@ -9665,12 +9724,15 @@ function isFlatPipeline(pipelineString) {
|
|
|
9665
9724
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
9666
9725
|
pipelineString = spaceTrim(pipelineString);
|
|
9667
9726
|
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
9668
|
-
|
|
9669
|
-
|
|
9727
|
+
//const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
|
|
9728
|
+
var isBacktickBlockUsed = pipelineString.includes('```');
|
|
9729
|
+
var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
|
|
9730
|
+
var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
|
|
9731
|
+
// TODO: [🧉] Also (double)check
|
|
9670
9732
|
// > const usedCommands
|
|
9671
9733
|
// > const isBlocksUsed
|
|
9672
9734
|
// > const returnStatementCount
|
|
9673
|
-
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement
|
|
9735
|
+
var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
|
|
9674
9736
|
return isFlat;
|
|
9675
9737
|
}
|
|
9676
9738
|
|
|
@@ -9684,9 +9746,26 @@ function deflatePipeline(pipelineString) {
|
|
|
9684
9746
|
return pipelineString;
|
|
9685
9747
|
}
|
|
9686
9748
|
var pipelineStringLines = pipelineString.split('\n');
|
|
9687
|
-
var
|
|
9749
|
+
var potentialReturnStatement = pipelineStringLines.pop();
|
|
9750
|
+
var returnStatement;
|
|
9751
|
+
if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
|
|
9752
|
+
// Note: Last line is return statement
|
|
9753
|
+
returnStatement = potentialReturnStatement;
|
|
9754
|
+
}
|
|
9755
|
+
else {
|
|
9756
|
+
// Note: Last line is not a return statement
|
|
9757
|
+
returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
|
|
9758
|
+
pipelineStringLines.push(potentialReturnStatement);
|
|
9759
|
+
}
|
|
9688
9760
|
var prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
9689
|
-
|
|
9761
|
+
var quotedPrompt;
|
|
9762
|
+
if (prompt.split('\n').length <= 1) {
|
|
9763
|
+
quotedPrompt = "> ".concat(prompt);
|
|
9764
|
+
}
|
|
9765
|
+
else {
|
|
9766
|
+
quotedPrompt = spaceTrim(function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
|
|
9767
|
+
}
|
|
9768
|
+
pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ").concat(block(quotedPrompt), "\n\n ").concat(returnStatement, "\n "); }));
|
|
9690
9769
|
// <- TODO: Maybe use book` notation
|
|
9691
9770
|
return pipelineString;
|
|
9692
9771
|
}
|
|
@@ -16902,7 +16981,7 @@ var markitdownScraperMetadata = $deepFreeze({
|
|
|
16902
16981
|
className: 'MarkitdownScraper',
|
|
16903
16982
|
mimeTypes: [
|
|
16904
16983
|
'application/pdf',
|
|
16905
|
-
// TODO: Make priority for scrapers and than allow all mime types here:
|
|
16984
|
+
// TODO: [💵] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
|
|
16906
16985
|
// 'text/html',
|
|
16907
16986
|
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16908
16987
|
],
|