@promptbook/cli 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 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-12';
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
  *
@@ -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), ".pdf")], false));
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: !!!!!!!! Check the file security
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
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9711
- // TODO: Also (double)check
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 returnStatement = pipelineStringLines.pop();
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
- pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
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
  ],