@promptbook/cli 0.84.0-13 → 0.84.0-15
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/LICENSE.md +1 -0
- package/README.md +3 -3
- package/esm/index.es.js +55 -17
- 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 -14
- package/umd/index.umd.js +54 -16
- package/umd/index.umd.js.map +1 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[Functional Source License, Version 1.1, ALv2 Future License](https://github.com/getsentry/fsl.software/blob/main/FSL-1.1-ALv2.template.md)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten -->
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# ✨ Promptbook
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
|
|
17
17
|
## ❄ New Features
|
|
18
18
|
|
|
19
|
+
- 🐋 **Support of [DeepSeek models](https://www.deepseek.com/)**
|
|
19
20
|
- 💙 Working [the **Book** language v1.0.0](https://github.com/webgptorg/book)
|
|
20
21
|
- 🖤 Run books from CLI - `npx ptbk run path/to/your/book`
|
|
21
|
-
- 📚 Support of `.docx`, `.doc` and `.pdf` documents
|
|
22
|
-
- ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
|
|
22
|
+
- 📚 Support of `.docx`, `.doc` and `.pdf` documents as knowledge
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
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-14';
|
|
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
|
*
|
|
@@ -6528,7 +6545,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6528
6545
|
case 1:
|
|
6529
6546
|
response_1 = _l.sent();
|
|
6530
6547
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
6531
|
-
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
6548
|
+
if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
|
|
6532
6549
|
return [2 /*return*/, {
|
|
6533
6550
|
source: name,
|
|
6534
6551
|
filename: null,
|
|
@@ -6573,7 +6590,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6573
6590
|
basename = url.split('/').pop() || titleToName(url);
|
|
6574
6591
|
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
6575
6592
|
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
6576
|
-
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".
|
|
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));
|
|
6577
6594
|
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
6578
6595
|
case 2:
|
|
6579
6596
|
_l.sent();
|
|
@@ -6584,9 +6601,9 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6584
6601
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
6585
6602
|
case 4:
|
|
6586
6603
|
_l.sent();
|
|
6587
|
-
// TODO:
|
|
6604
|
+
// TODO: [💵] Check the file security
|
|
6588
6605
|
// TODO: !!!!!!!! Check the file size (if it is not too big)
|
|
6589
|
-
// TODO: !!!!!!!! Delete the file
|
|
6606
|
+
// TODO: !!!!!!!! Delete the file after the scraping is done
|
|
6590
6607
|
return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
|
|
6591
6608
|
case 5:
|
|
6592
6609
|
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
|
|
@@ -9707,12 +9724,15 @@ function isFlatPipeline(pipelineString) {
|
|
|
9707
9724
|
pipelineString = removeMarkdownComments(pipelineString);
|
|
9708
9725
|
pipelineString = spaceTrim(pipelineString);
|
|
9709
9726
|
var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
|
|
9710
|
-
|
|
9711
|
-
|
|
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
|
|
9712
9732
|
// > const usedCommands
|
|
9713
9733
|
// > const isBlocksUsed
|
|
9714
9734
|
// > const returnStatementCount
|
|
9715
|
-
var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement
|
|
9735
|
+
var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
|
|
9716
9736
|
return isFlat;
|
|
9717
9737
|
}
|
|
9718
9738
|
|
|
@@ -9726,9 +9746,26 @@ function deflatePipeline(pipelineString) {
|
|
|
9726
9746
|
return pipelineString;
|
|
9727
9747
|
}
|
|
9728
9748
|
var pipelineStringLines = pipelineString.split('\n');
|
|
9729
|
-
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
|
+
}
|
|
9730
9760
|
var prompt = spaceTrim(pipelineStringLines.join('\n'));
|
|
9731
|
-
|
|
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 "); }));
|
|
9732
9769
|
// <- TODO: Maybe use book` notation
|
|
9733
9770
|
return pipelineString;
|
|
9734
9771
|
}
|
|
@@ -16944,7 +16981,7 @@ var markitdownScraperMetadata = $deepFreeze({
|
|
|
16944
16981
|
className: 'MarkitdownScraper',
|
|
16945
16982
|
mimeTypes: [
|
|
16946
16983
|
'application/pdf',
|
|
16947
|
-
// 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:
|
|
16948
16985
|
// 'text/html',
|
|
16949
16986
|
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16950
16987
|
],
|
|
@@ -16980,10 +17017,10 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
16980
17017
|
this.tools = tools;
|
|
16981
17018
|
this.options = options;
|
|
16982
17019
|
this.markdownScraper = new MarkdownScraper(tools, options);
|
|
17020
|
+
// Note: Module `markitdown-ts` has no types available, so it is imported using `require`
|
|
16983
17021
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16984
17022
|
var MarkItDown = require('markitdown-ts').MarkItDown;
|
|
16985
|
-
// <- TODO:
|
|
16986
|
-
// <- Note: !!!!!!!
|
|
17023
|
+
// <- TODO: 'Use Markitdown directly not through this package
|
|
16987
17024
|
this.markitdown = new MarkItDown();
|
|
16988
17025
|
}
|
|
16989
17026
|
Object.defineProperty(MarkitdownScraper.prototype, "metadata", {
|
|
@@ -17028,12 +17065,12 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
17028
17065
|
case 2:
|
|
17029
17066
|
if (!!(_f.sent())) return [3 /*break*/, 5];
|
|
17030
17067
|
src = source.filename || source.url || null;
|
|
17031
|
-
console.log('!!!', { src
|
|
17068
|
+
// console.log('!!!', { src, source, cacheFilehandler });
|
|
17032
17069
|
if (src === null) {
|
|
17033
17070
|
throw new UnexpectedError('Source has no filename or url');
|
|
17034
17071
|
}
|
|
17035
17072
|
return [4 /*yield*/, this.markitdown.convert(src, {
|
|
17036
|
-
// TODO:
|
|
17073
|
+
// TODO: Pass when sacraping Youtube
|
|
17037
17074
|
// enableYoutubeTranscript: true,
|
|
17038
17075
|
// youtubeTranscriptLanguage: 'en',
|
|
17039
17076
|
})];
|
|
@@ -17043,9 +17080,10 @@ var MarkitdownScraper = /** @class */ (function () {
|
|
|
17043
17080
|
throw new Error("Markitdown could not convert the \"".concat(source.source, "\""));
|
|
17044
17081
|
// <- TODO: !!! Make MarkitdownError
|
|
17045
17082
|
}
|
|
17046
|
-
console.log('!!!', { result
|
|
17083
|
+
// console.log('!!!', { result, cacheFilehandler });
|
|
17047
17084
|
return [4 /*yield*/, this.tools.fs.writeFile(cacheFilehandler.filename, result.text_content)];
|
|
17048
17085
|
case 4:
|
|
17086
|
+
// console.log('!!!', { result, cacheFilehandler });
|
|
17049
17087
|
_f.sent();
|
|
17050
17088
|
_f.label = 5;
|
|
17051
17089
|
case 5: return [2 /*return*/, cacheFilehandler];
|