@promptbook/node 0.84.0-13 → 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 +48 -11
- 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 +2 -2
- package/umd/index.umd.js +47 -10
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ import { unparse, parse } from 'papaparse';
|
|
|
9
9
|
import hexEncoder from 'crypto-js/enc-hex';
|
|
10
10
|
import sha256 from 'crypto-js/sha256';
|
|
11
11
|
import { SHA256 } from 'crypto-js';
|
|
12
|
-
import { lookup } from 'mime-types';
|
|
12
|
+
import { lookup, extension } from 'mime-types';
|
|
13
13
|
import { spawn } from 'child_process';
|
|
14
14
|
import * as dotenv from 'dotenv';
|
|
15
15
|
|
|
@@ -27,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-13';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -204,6 +204,12 @@ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
|
|
|
204
204
|
* @public exported from `@promptbook/core`
|
|
205
205
|
*/
|
|
206
206
|
var DEFAULT_TASK_TITLE = "Task";
|
|
207
|
+
/**
|
|
208
|
+
* When the pipeline is flat and no name of return parameter is provided, this name is used
|
|
209
|
+
*
|
|
210
|
+
* @public exported from `@promptbook/core`
|
|
211
|
+
*/
|
|
212
|
+
var DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
207
213
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
208
214
|
/**
|
|
209
215
|
* The maximum number of iterations for a loops
|
|
@@ -5469,6 +5475,17 @@ function isFileExisting(filename, fs) {
|
|
|
5469
5475
|
* TODO: [🖇] What about symlinks?
|
|
5470
5476
|
*/
|
|
5471
5477
|
|
|
5478
|
+
/**
|
|
5479
|
+
* Convert mime type to file extension
|
|
5480
|
+
*
|
|
5481
|
+
* Note: If the mime type is invalid, `null` is returned
|
|
5482
|
+
*
|
|
5483
|
+
* @private within the repository
|
|
5484
|
+
*/
|
|
5485
|
+
function mimeTypeToExtension(value) {
|
|
5486
|
+
return extension(value) || null;
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5472
5489
|
/**
|
|
5473
5490
|
* Removes emojis from a string and fix whitespaces
|
|
5474
5491
|
*
|
|
@@ -5562,7 +5579,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5562
5579
|
case 1:
|
|
5563
5580
|
response_1 = _l.sent();
|
|
5564
5581
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5565
|
-
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
5582
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
5566
5583
|
return [2 /*return*/, {
|
|
5567
5584
|
source: name,
|
|
5568
5585
|
filename: null,
|
|
@@ -5607,7 +5624,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5607
5624
|
basename = url.split('/').pop() || titleToName(url);
|
|
5608
5625
|
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
5609
5626
|
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
5610
|
-
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".
|
|
5627
|
+
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));
|
|
5611
5628
|
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
5612
5629
|
case 2:
|
|
5613
5630
|
_l.sent();
|
|
@@ -5618,9 +5635,9 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5618
5635
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
5619
5636
|
case 4:
|
|
5620
5637
|
_l.sent();
|
|
5621
|
-
// TODO:
|
|
5638
|
+
// TODO: [💵] Check the file security
|
|
5622
5639
|
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
5623
|
-
// TODO: !!!!!!!! Delete the file
|
|
5640
|
+
// TODO: !!!!!!!! Delete the file after the scraping is done
|
|
5624
5641
|
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
5625
5642
|
case 5:
|
|
5626
5643
|
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
@@ -8741,12 +8758,15 @@ function isFlatPipeline(pipelineString) {
|
|
|
8741
8758
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
8742
8759
|
pipelineString = spaceTrim(pipelineString);
|
|
8743
8760
|
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
8744
|
-
|
|
8745
|
-
|
|
8761
|
+
//const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
|
|
8762
|
+
var isBacktickBlockUsed = pipelineString.includes('```');
|
|
8763
|
+
var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
|
|
8764
|
+
var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
|
|
8765
|
+
// TODO: [🧉] Also (double)check
|
|
8746
8766
|
// > const usedCommands
|
|
8747
8767
|
// > const isBlocksUsed
|
|
8748
8768
|
// > const returnStatementCount
|
|
8749
|
-
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement
|
|
8769
|
+
var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
|
|
8750
8770
|
return isFlat;
|
|
8751
8771
|
}
|
|
8752
8772
|
|
|
@@ -8760,9 +8780,26 @@ function deflatePipeline(pipelineString) {
|
|
|
8760
8780
|
return pipelineString;
|
|
8761
8781
|
}
|
|
8762
8782
|
var pipelineStringLines = pipelineString.split('\n');
|
|
8763
|
-
var
|
|
8783
|
+
var potentialReturnStatement = pipelineStringLines.pop();
|
|
8784
|
+
var returnStatement;
|
|
8785
|
+
if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
|
|
8786
|
+
// Note: Last line is return statement
|
|
8787
|
+
returnStatement = potentialReturnStatement;
|
|
8788
|
+
}
|
|
8789
|
+
else {
|
|
8790
|
+
// Note: Last line is not a return statement
|
|
8791
|
+
returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
|
|
8792
|
+
pipelineStringLines.push(potentialReturnStatement);
|
|
8793
|
+
}
|
|
8764
8794
|
var prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
8765
|
-
|
|
8795
|
+
var quotedPrompt;
|
|
8796
|
+
if (prompt.split('\n').length <= 1) {
|
|
8797
|
+
quotedPrompt = "> ".concat(prompt);
|
|
8798
|
+
}
|
|
8799
|
+
else {
|
|
8800
|
+
quotedPrompt = spaceTrim(function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
|
|
8801
|
+
}
|
|
8802
|
+
pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ").concat(block(quotedPrompt), "\n\n ").concat(returnStatement, "\n "); }));
|
|
8766
8803
|
// <- TODO: Maybe use book` notation
|
|
8767
8804
|
return pipelineString;
|
|
8768
8805
|
}
|