@promptbook/core 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.
@@ -12,6 +12,8 @@ import { LOGO_LIGHT_SRC } from '../config';
12
12
  import { LOGO_DARK_SRC } from '../config';
13
13
  import { DEFAULT_BOOK_TITLE } from '../config';
14
14
  import { DEFAULT_TASK_TITLE } from '../config';
15
+ import { DEFAULT_PROMPT_TASK_TITLE } from '../config';
16
+ import { DEFAULT_BOOK_OUTPUT_PARAMETER_NAME } from '../config';
15
17
  import { MAX_FILENAME_LENGTH } from '../config';
16
18
  import { DEFAULT_INTERMEDIATE_FILES_STRATEGY } from '../config';
17
19
  import { DEFAULT_MAX_PARALLEL_COUNT } from '../config';
@@ -139,6 +141,8 @@ export { LOGO_LIGHT_SRC };
139
141
  export { LOGO_DARK_SRC };
140
142
  export { DEFAULT_BOOK_TITLE };
141
143
  export { DEFAULT_TASK_TITLE };
144
+ export { DEFAULT_PROMPT_TASK_TITLE };
145
+ export { DEFAULT_BOOK_OUTPUT_PARAMETER_NAME };
142
146
  export { MAX_FILENAME_LENGTH };
143
147
  export { DEFAULT_INTERMEDIATE_FILES_STRATEGY };
144
148
  export { DEFAULT_MAX_PARALLEL_COUNT };
@@ -65,6 +65,18 @@ export declare const DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
65
65
  * @public exported from `@promptbook/core`
66
66
  */
67
67
  export declare const DEFAULT_TASK_TITLE = "Task";
68
+ /**
69
+ * When the title of the prompt task is not provided, the default title is used
70
+ *
71
+ * @public exported from `@promptbook/core`
72
+ */
73
+ export declare const DEFAULT_PROMPT_TASK_TITLE = "Prompt";
74
+ /**
75
+ * When the pipeline is flat and no name of return parameter is provided, this name is used
76
+ *
77
+ * @public exported from `@promptbook/core`
78
+ */
79
+ export declare const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = "result";
68
80
  /**
69
81
  * Warning message for the generated sections and files files
70
82
  *
@@ -0,0 +1,10 @@
1
+ import type { string_file_extension } from '../../types/typeAliases';
2
+ import type { string_mime_type } from '../../types/typeAliases';
3
+ /**
4
+ * Convert mime type to file extension
5
+ *
6
+ * Note: If the mime type is invalid, `null` is returned
7
+ *
8
+ * @private within the repository
9
+ */
10
+ export declare function mimeTypeToExtension(value: string_mime_type): string_file_extension | null;
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.84.0-13",
3
+ "version": "0.84.0-15",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
- "--note-0": " <- [🐊]",
6
5
  "private": false,
7
6
  "sideEffects": false,
8
7
  "repository": {
@@ -12,7 +11,6 @@
12
11
  "contributors": [
13
12
  "Pavol HejnΓ½ <pavol@ptbk.io> (https://www.pavolhejny.com/)"
14
13
  ],
15
- "--todo-0": "TODO: [❇️] Make better list of keywords",
16
14
  "keywords": [
17
15
  "ai",
18
16
  "llm",
@@ -35,21 +33,11 @@
35
33
  "anthropic",
36
34
  "LLMOps"
37
35
  ],
38
- "license": "CC-BY-4.0",
36
+ "license": "SEE LICENSE IN LICENSE.md",
39
37
  "bugs": {
40
38
  "url": "https://github.com/webgptorg/promptbook/issues"
41
39
  },
42
40
  "homepage": "https://www.npmjs.com/package/@promptbook/core",
43
- "funding": [
44
- {
45
- "type": "individual",
46
- "url": "https://buymeacoffee.com/hejny"
47
- },
48
- {
49
- "type": "github",
50
- "url": "https://github.com/webgptorg/promptbook/blob/main/README.md#%EF%B8%8F-contributing"
51
- }
52
- ],
53
41
  "main": "./umd/index.umd.js",
54
42
  "module": "./esm/index.es.js",
55
43
  "typings": "./esm/typings/src/_packages/core.index.d.ts",
package/umd/index.umd.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-12';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-14';
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
@@ -674,6 +674,18 @@
674
674
  * @public exported from `@promptbook/core`
675
675
  */
676
676
  var DEFAULT_TASK_TITLE = "Task";
677
+ /**
678
+ * When the title of the prompt task is not provided, the default title is used
679
+ *
680
+ * @public exported from `@promptbook/core`
681
+ */
682
+ var DEFAULT_PROMPT_TASK_TITLE = "Prompt";
683
+ /**
684
+ * When the pipeline is flat and no name of return parameter is provided, this name is used
685
+ *
686
+ * @public exported from `@promptbook/core`
687
+ */
688
+ var DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
677
689
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
678
690
  /**
679
691
  * The maximum number of iterations for a loops
@@ -5823,6 +5835,17 @@
5823
5835
  * TODO: [πŸ–‡] What about symlinks?
5824
5836
  */
5825
5837
 
5838
+ /**
5839
+ * Convert mime type to file extension
5840
+ *
5841
+ * Note: If the mime type is invalid, `null` is returned
5842
+ *
5843
+ * @private within the repository
5844
+ */
5845
+ function mimeTypeToExtension(value) {
5846
+ return mimeTypes.extension(value) || null;
5847
+ }
5848
+
5826
5849
  /**
5827
5850
  * Removes emojis from a string and fix whitespaces
5828
5851
  *
@@ -5916,7 +5939,7 @@
5916
5939
  case 1:
5917
5940
  response_1 = _l.sent();
5918
5941
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5919
- if (tools.fs === undefined || !url.endsWith('.pdf')) {
5942
+ if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [πŸ’΅] */)) {
5920
5943
  return [2 /*return*/, {
5921
5944
  source: name,
5922
5945
  filename: null,
@@ -5961,7 +5984,7 @@
5961
5984
  basename = url.split('/').pop() || titleToName(url);
5962
5985
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5963
5986
  rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5964
- filepath = path.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));
5987
+ filepath = path.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));
5965
5988
  return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
5966
5989
  case 2:
5967
5990
  _l.sent();
@@ -5972,9 +5995,9 @@
5972
5995
  case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
5973
5996
  case 4:
5974
5997
  _l.sent();
5975
- // TODO: !!!!!!!! Check the file security
5998
+ // TODO: [πŸ’΅] Check the file security
5976
5999
  // TODO: !!!!!!!! Check the file size (if it is not too big)
5977
- // TODO: !!!!!!!! Delete the file
6000
+ // TODO: !!!!!!!! Delete the file after the scraping is done
5978
6001
  return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
5979
6002
  case 5:
5980
6003
  if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
@@ -9095,12 +9118,15 @@
9095
9118
  pipelineString = removeMarkdownComments(pipelineString);
9096
9119
  pipelineString = spaceTrim__default["default"](pipelineString);
9097
9120
  var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9098
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9099
- // TODO: Also (double)check
9121
+ //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
9122
+ var isBacktickBlockUsed = pipelineString.includes('```');
9123
+ var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
9124
+ var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
9125
+ // TODO: [πŸ§‰] Also (double)check
9100
9126
  // > const usedCommands
9101
9127
  // > const isBlocksUsed
9102
9128
  // > const returnStatementCount
9103
- var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9129
+ var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
9104
9130
  return isFlat;
9105
9131
  }
9106
9132
 
@@ -9114,9 +9140,26 @@
9114
9140
  return pipelineString;
9115
9141
  }
9116
9142
  var pipelineStringLines = pipelineString.split('\n');
9117
- var returnStatement = pipelineStringLines.pop();
9143
+ var potentialReturnStatement = pipelineStringLines.pop();
9144
+ var returnStatement;
9145
+ if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
9146
+ // Note: Last line is return statement
9147
+ returnStatement = potentialReturnStatement;
9148
+ }
9149
+ else {
9150
+ // Note: Last line is not a return statement
9151
+ returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
9152
+ pipelineStringLines.push(potentialReturnStatement);
9153
+ }
9118
9154
  var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
9119
- pipelineString = validatePipelineString(spaceTrim__default["default"](function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
9155
+ var quotedPrompt;
9156
+ if (prompt.split('\n').length <= 1) {
9157
+ quotedPrompt = "> ".concat(prompt);
9158
+ }
9159
+ else {
9160
+ quotedPrompt = spaceTrim__default["default"](function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
9161
+ }
9162
+ pipelineString = validatePipelineString(spaceTrim__default["default"](function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ").concat(block(quotedPrompt), "\n\n ").concat(returnStatement, "\n "); }));
9120
9163
  // <- TODO: Maybe use book` notation
9121
9164
  return pipelineString;
9122
9165
  }
@@ -11375,7 +11418,7 @@
11375
11418
  className: 'MarkitdownScraper',
11376
11419
  mimeTypes: [
11377
11420
  'application/pdf',
11378
- // TODO: Make priority for scrapers and than allow all mime types here:
11421
+ // TODO: [πŸ’΅] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
11379
11422
  // 'text/html',
11380
11423
  // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
11381
11424
  ],
@@ -11555,6 +11598,7 @@
11555
11598
  exports.CsvFormatDefinition = CsvFormatDefinition;
11556
11599
  exports.CsvFormatError = CsvFormatError;
11557
11600
  exports.DEFAULT_BOOKS_DIRNAME = DEFAULT_BOOKS_DIRNAME;
11601
+ exports.DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = DEFAULT_BOOK_OUTPUT_PARAMETER_NAME;
11558
11602
  exports.DEFAULT_BOOK_TITLE = DEFAULT_BOOK_TITLE;
11559
11603
  exports.DEFAULT_CSV_SETTINGS = DEFAULT_CSV_SETTINGS;
11560
11604
  exports.DEFAULT_DOWNLOAD_CACHE_DIRNAME = DEFAULT_DOWNLOAD_CACHE_DIRNAME;
@@ -11567,6 +11611,7 @@
11567
11611
  exports.DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL;
11568
11612
  exports.DEFAULT_MAX_PARALLEL_COUNT = DEFAULT_MAX_PARALLEL_COUNT;
11569
11613
  exports.DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME;
11614
+ exports.DEFAULT_PROMPT_TASK_TITLE = DEFAULT_PROMPT_TASK_TITLE;
11570
11615
  exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
11571
11616
  exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
11572
11617
  exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;