@promptbook/core 0.84.0-20 → 0.84.0-9

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.
Files changed (29) hide show
  1. package/README.md +5 -11
  2. package/esm/index.es.js +187 -376
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +0 -4
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -12
  6. package/esm/typings/src/_packages/types.index.d.ts +0 -2
  7. package/esm/typings/src/_packages/utils.index.d.ts +0 -2
  8. package/esm/typings/src/_packages/wizzard.index.d.ts +0 -4
  9. package/esm/typings/src/config.d.ts +1 -27
  10. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  11. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  12. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
  13. package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
  14. package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
  15. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  16. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
  17. package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
  18. package/package.json +15 -8
  19. package/umd/index.umd.js +188 -382
  20. package/umd/index.umd.js.map +1 -1
  21. package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
  22. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
  23. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
  24. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
  25. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
  26. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
  27. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
  28. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
  29. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -1
package/esm/index.es.js CHANGED
@@ -3,13 +3,13 @@ import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
4
  import { forTime } from 'waitasecond';
5
5
  import { unparse, parse } from 'papaparse';
6
- import hexEncoder from 'crypto-js/enc-hex';
7
- import sha256 from 'crypto-js/sha256';
8
- import { basename, join, dirname } from 'path';
6
+ import { join, basename } from 'path';
9
7
  import { SHA256 } from 'crypto-js';
10
- import { lookup, extension } from 'mime-types';
8
+ import hexEncoder from 'crypto-js/enc-hex';
9
+ import { lookup } from 'mime-types';
11
10
  import moment from 'moment';
12
11
  import colors from 'colors';
12
+ import sha256 from 'crypto-js/sha256';
13
13
 
14
14
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
15
15
  /**
@@ -25,7 +25,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-19';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -178,94 +178,22 @@ function collectionToJson(collection) {
178
178
  */
179
179
 
180
180
  /**
181
- * Checks if value is valid email
182
- *
183
- * @public exported from `@promptbook/utils`
184
- */
185
- function isValidEmail(email) {
186
- if (typeof email !== 'string') {
187
- return false;
188
- }
189
- if (email.split('\n').length > 1) {
190
- return false;
191
- }
192
- return /^.+@.+\..+$/.test(email);
193
- }
194
-
195
- /**
196
- * Tests if given string is valid URL.
181
+ * Function isValidJsonString will tell you if the string is valid JSON or not
197
182
  *
198
- * Note: This does not check if the file exists only if the path is valid
199
183
  * @public exported from `@promptbook/utils`
200
184
  */
201
- function isValidFilePath(filename) {
202
- if (typeof filename !== 'string') {
203
- return false;
204
- }
205
- if (filename.split('\n').length > 1) {
206
- return false;
207
- }
208
- if (filename.split(' ').length >
209
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
210
- return false;
211
- }
212
- var filenameSlashes = filename.split('\\').join('/');
213
- // Absolute Unix path: /hello.txt
214
- if (/^(\/)/i.test(filenameSlashes)) {
215
- // console.log(filename, 'Absolute Unix path: /hello.txt');
216
- return true;
217
- }
218
- // Absolute Windows path: /hello.txt
219
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
220
- // console.log(filename, 'Absolute Windows path: /hello.txt');
221
- return true;
222
- }
223
- // Relative path: ./hello.txt
224
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
225
- // console.log(filename, 'Relative path: ./hello.txt');
226
- return true;
227
- }
228
- // Allow paths like foo/hello
229
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
230
- // console.log(filename, 'Allow paths like foo/hello');
231
- return true;
232
- }
233
- // Allow paths like hello.book
234
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
235
- // console.log(filename, 'Allow paths like hello.book');
185
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
186
+ try {
187
+ JSON.parse(value);
236
188
  return true;
237
189
  }
238
- return false;
239
- }
240
- /**
241
- * TODO: [🍏] Implement for MacOs
242
- */
243
-
244
- /**
245
- * Tests if given string is valid URL.
246
- *
247
- * Note: Dataurl are considered perfectly valid.
248
- * Note: There are two simmilar functions:
249
- * - `isValidUrl` which tests any URL
250
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
251
- *
252
- * @public exported from `@promptbook/utils`
253
- */
254
- function isValidUrl(url) {
255
- if (typeof url !== 'string') {
256
- return false;
257
- }
258
- try {
259
- if (url.startsWith('blob:')) {
260
- url = url.replace(/^blob:/, '');
190
+ catch (error) {
191
+ if (!(error instanceof Error)) {
192
+ throw error;
261
193
  }
262
- var urlObject = new URL(url /* because fail is handled */);
263
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
194
+ if (error.message.includes('Unexpected token')) {
264
195
  return false;
265
196
  }
266
- return true;
267
- }
268
- catch (error) {
269
197
  return false;
270
198
  }
271
199
  }
@@ -289,27 +217,6 @@ var ParseError = /** @class */ (function (_super) {
289
217
  * TODO: Maybe split `ParseError` and `ApplyError`
290
218
  */
291
219
 
292
- /**
293
- * Function isValidJsonString will tell you if the string is valid JSON or not
294
- *
295
- * @public exported from `@promptbook/utils`
296
- */
297
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
298
- try {
299
- JSON.parse(value);
300
- return true;
301
- }
302
- catch (error) {
303
- if (!(error instanceof Error)) {
304
- throw error;
305
- }
306
- if (error.message.includes('Unexpected token')) {
307
- return false;
308
- }
309
- return false;
310
- }
311
- }
312
-
313
220
  /**
314
221
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
315
222
  * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
@@ -323,15 +230,6 @@ function validatePipelineString(pipelineString) {
323
230
  if (isValidJsonString(pipelineString)) {
324
231
  throw new ParseError('Expected a book, but got a JSON string');
325
232
  }
326
- else if (isValidUrl(pipelineString)) {
327
- throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
328
- }
329
- else if (isValidFilePath(pipelineString)) {
330
- throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
331
- }
332
- else if (isValidEmail(pipelineString)) {
333
- throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
334
- }
335
233
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
336
234
  return pipelineString;
337
235
  }
@@ -672,24 +570,6 @@ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
672
570
  * @public exported from `@promptbook/core`
673
571
  */
674
572
  var DEFAULT_TASK_TITLE = "Task";
675
- /**
676
- * When the title of the prompt task is not provided, the default title is used
677
- *
678
- * @public exported from `@promptbook/core`
679
- */
680
- var DEFAULT_PROMPT_TASK_TITLE = "Prompt";
681
- /**
682
- * When the pipeline is flat and no name of return parameter is provided, this name is used
683
- *
684
- * @public exported from `@promptbook/core`
685
- */
686
- var DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
687
- /**
688
- * Maximum file size limit
689
- *
690
- * @public exported from `@promptbook/core`
691
- */
692
- var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
693
573
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
694
574
  /**
695
575
  * The maximum number of iterations for a loops
@@ -770,14 +650,6 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
770
650
  */
771
651
  var DEFAULT_BOOKS_DIRNAME = './books';
772
652
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
773
- /**
774
- * Where to store the temporary downloads
775
- *
776
- * Note: When the folder does not exist, it is created recursively
777
- *
778
- * @public exported from `@promptbook/core`
779
- */
780
- var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
781
653
  /**
782
654
  * Where to store the cache of executions for promptbook CLI
783
655
  *
@@ -785,7 +657,7 @@ var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
785
657
  *
786
658
  * @public exported from `@promptbook/core`
787
659
  */
788
- var DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
660
+ var DEFAULT_EXECUTIONS_CACHE_DIRNAME = './.promptbook/executions-cache';
789
661
  /**
790
662
  * Where to store the scrape cache
791
663
  *
@@ -1311,6 +1183,35 @@ function isUrlOnPrivateNetwork(url) {
1311
1183
  return isHostnameOnPrivateNetwork(url.hostname);
1312
1184
  }
1313
1185
 
1186
+ /**
1187
+ * Tests if given string is valid URL.
1188
+ *
1189
+ * Note: Dataurl are considered perfectly valid.
1190
+ * Note: There are two simmilar functions:
1191
+ * - `isValidUrl` which tests any URL
1192
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1193
+ *
1194
+ * @public exported from `@promptbook/utils`
1195
+ */
1196
+ function isValidUrl(url) {
1197
+ if (typeof url !== 'string') {
1198
+ return false;
1199
+ }
1200
+ try {
1201
+ if (url.startsWith('blob:')) {
1202
+ url = url.replace(/^blob:/, '');
1203
+ }
1204
+ var urlObject = new URL(url /* because fail is handled */);
1205
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1206
+ return false;
1207
+ }
1208
+ return true;
1209
+ }
1210
+ catch (error) {
1211
+ return false;
1212
+ }
1213
+ }
1214
+
1314
1215
  /**
1315
1216
  * Tests if given string is valid pipeline URL URL.
1316
1217
  *
@@ -2269,28 +2170,12 @@ function deserializeError(error) {
2269
2170
  /**
2270
2171
  * Asserts that the execution of a Promptbook is successful
2271
2172
  *
2272
- * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2273
- *
2274
2173
  * @param executionResult - The partial result of the Promptbook execution
2275
2174
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2276
2175
  * @public exported from `@promptbook/core`
2277
2176
  */
2278
2177
  function assertsExecutionSuccessful(executionResult) {
2279
- var e_1, _a;
2280
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2281
- try {
2282
- for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2283
- var warning = warnings_1_1.value;
2284
- console.warn(warning.message);
2285
- }
2286
- }
2287
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2288
- finally {
2289
- try {
2290
- if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2291
- }
2292
- finally { if (e_1) throw e_1.error; }
2293
- }
2178
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2294
2179
  if (isSuccessful === true) {
2295
2180
  return;
2296
2181
  }
@@ -5775,15 +5660,6 @@ function knowledgeSourceContentToName(knowledgeSourceContent) {
5775
5660
  * TODO: [🐱‍🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
5776
5661
  */
5777
5662
 
5778
- /**
5779
- * @@@
5780
- *
5781
- * @private for `FileCacheStorage`
5782
- */
5783
- function nameToSubfolderPath(name) {
5784
- return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
5785
- }
5786
-
5787
5663
  /**
5788
5664
  * Convert file extension to mime type
5789
5665
  *
@@ -5840,55 +5716,53 @@ function isFileExisting(filename, fs) {
5840
5716
  */
5841
5717
 
5842
5718
  /**
5843
- * Convert mime type to file extension
5844
- *
5845
- * Note: If the mime type is invalid, `null` is returned
5846
- *
5847
- * @private within the repository
5848
- */
5849
- function mimeTypeToExtension(value) {
5850
- return extension(value) || null;
5851
- }
5852
-
5853
- /**
5854
- * Removes emojis from a string and fix whitespaces
5855
- *
5856
- * @param text with emojis
5857
- * @returns text without emojis
5858
- * @public exported from `@promptbook/utils`
5859
- */
5860
- function removeEmojis(text) {
5861
- // Replace emojis (and also ZWJ sequence) with hyphens
5862
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
5863
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
5864
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
5865
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
5866
- return text;
5867
- }
5868
-
5869
- /**
5870
- * @@@
5719
+ * Tests if given string is valid URL.
5871
5720
  *
5872
- * @param value @@@
5873
- * @returns @@@
5874
- * @example @@@
5721
+ * Note: This does not check if the file exists only if the path is valid
5875
5722
  * @public exported from `@promptbook/utils`
5876
5723
  */
5877
- function titleToName(value) {
5878
- if (isValidUrl(value)) {
5879
- value = value.replace(/^https?:\/\//, '');
5880
- value = value.replace(/\.html$/, '');
5724
+ function isValidFilePath(filename) {
5725
+ if (typeof filename !== 'string') {
5726
+ return false;
5881
5727
  }
5882
- else if (isValidFilePath(value)) {
5883
- value = basename(value);
5884
- // Note: Keeping extension in the name
5728
+ if (filename.split('\n').length > 1) {
5729
+ return false;
5885
5730
  }
5886
- value = value.split('/').join('-');
5887
- value = removeEmojis(value);
5888
- value = normalizeToKebabCase(value);
5889
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
5890
- return value;
5731
+ if (filename.split(' ').length >
5732
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
5733
+ return false;
5734
+ }
5735
+ var filenameSlashes = filename.split('\\').join('/');
5736
+ // Absolute Unix path: /hello.txt
5737
+ if (/^(\/)/i.test(filenameSlashes)) {
5738
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
5739
+ return true;
5740
+ }
5741
+ // Absolute Windows path: /hello.txt
5742
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
5743
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
5744
+ return true;
5745
+ }
5746
+ // Relative path: ./hello.txt
5747
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
5748
+ // console.log(filename, 'Relative path: ./hello.txt');
5749
+ return true;
5750
+ }
5751
+ // Allow paths like foo/hello
5752
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
5753
+ // console.log(filename, 'Allow paths like foo/hello');
5754
+ return true;
5755
+ }
5756
+ // Allow paths like hello.book
5757
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
5758
+ // console.log(filename, 'Allow paths like hello.book');
5759
+ return true;
5760
+ }
5761
+ return false;
5891
5762
  }
5763
+ /**
5764
+ * TODO: [🍏] Implement for MacOs
5765
+ */
5892
5766
 
5893
5767
  /**
5894
5768
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -5925,9 +5799,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
5925
5799
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5926
5800
  var _a;
5927
5801
  return __awaiter(this, void 0, void 0, function () {
5928
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
5929
- return __generator(this, function (_h) {
5930
- switch (_h.label) {
5802
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5803
+ return __generator(this, function (_f) {
5804
+ switch (_f.label) {
5931
5805
  case 0:
5932
5806
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5933
5807
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -5936,76 +5810,54 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5936
5810
  if (!name) {
5937
5811
  name = knowledgeSourceContentToName(knowledgeSourceContent);
5938
5812
  }
5939
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
5813
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
5940
5814
  url = knowledgeSourceContent;
5941
5815
  return [4 /*yield*/, fetch(url)];
5942
5816
  case 1:
5943
- response_1 = _h.sent();
5817
+ response_1 = _f.sent();
5944
5818
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5945
- if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
5946
- return [2 /*return*/, {
5947
- source: name,
5948
- filename: null,
5949
- url: url,
5950
- mimeType: mimeType,
5951
- /*
5952
- TODO: [🥽]
5953
- > async asBlob() {
5954
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5955
- > const content = await response.blob();
5956
- > return content;
5957
- > },
5958
- */
5959
- asJson: function () {
5960
- return __awaiter(this, void 0, void 0, function () {
5961
- var content;
5962
- return __generator(this, function (_a) {
5963
- switch (_a.label) {
5964
- case 0: return [4 /*yield*/, response_1.json()];
5965
- case 1:
5966
- content = _a.sent();
5967
- return [2 /*return*/, content];
5968
- }
5969
- });
5819
+ return [2 /*return*/, {
5820
+ source: name,
5821
+ filename: null,
5822
+ url: url,
5823
+ mimeType: mimeType,
5824
+ /*
5825
+ TODO: [🥽]
5826
+ > async asBlob() {
5827
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5828
+ > const content = await response.blob();
5829
+ > return content;
5830
+ > },
5831
+ */
5832
+ asJson: function () {
5833
+ return __awaiter(this, void 0, void 0, function () {
5834
+ var content;
5835
+ return __generator(this, function (_a) {
5836
+ switch (_a.label) {
5837
+ case 0: return [4 /*yield*/, response_1.json()];
5838
+ case 1:
5839
+ content = _a.sent();
5840
+ return [2 /*return*/, content];
5841
+ }
5970
5842
  });
5971
- },
5972
- asText: function () {
5973
- return __awaiter(this, void 0, void 0, function () {
5974
- var content;
5975
- return __generator(this, function (_a) {
5976
- switch (_a.label) {
5977
- case 0: return [4 /*yield*/, response_1.text()];
5978
- case 1:
5979
- content = _a.sent();
5980
- return [2 /*return*/, content];
5981
- }
5982
- });
5843
+ });
5844
+ },
5845
+ asText: function () {
5846
+ return __awaiter(this, void 0, void 0, function () {
5847
+ var content;
5848
+ return __generator(this, function (_a) {
5849
+ switch (_a.label) {
5850
+ case 0: return [4 /*yield*/, response_1.text()];
5851
+ case 1:
5852
+ content = _a.sent();
5853
+ return [2 /*return*/, content];
5854
+ }
5983
5855
  });
5984
- },
5985
- }];
5986
- }
5987
- basename = url.split('/').pop() || titleToName(url);
5988
- hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
5989
- rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5990
- 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));
5991
- return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
5856
+ });
5857
+ },
5858
+ }];
5992
5859
  case 2:
5993
- _h.sent();
5994
- _g = (_f = Buffer).from;
5995
- return [4 /*yield*/, response_1.arrayBuffer()];
5996
- case 3:
5997
- fileContent = _g.apply(_f, [_h.sent()]);
5998
- if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
5999
- throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
6000
- }
6001
- return [4 /*yield*/, tools.fs.writeFile(join(rootDirname_1, filepath), fileContent)];
6002
- case 4:
6003
- _h.sent();
6004
- // TODO: [💵] Check the file security
6005
- // TODO: [🧹][🧠] Delete the file after the scraping is done
6006
- return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6007
- case 5:
6008
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
5860
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
6009
5861
  if (tools.fs === undefined) {
6010
5862
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
6011
5863
  // <- TODO: [🧠] What is the best error type here`
@@ -6018,8 +5870,8 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6018
5870
  fileExtension = getFileExtension(filename_1);
6019
5871
  mimeType = extensionToMimeType(fileExtension || '');
6020
5872
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6021
- case 6:
6022
- if (!(_h.sent())) {
5873
+ case 3:
5874
+ if (!(_f.sent())) {
6023
5875
  throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
6024
5876
  }
6025
5877
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -6065,7 +5917,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6065
5917
  });
6066
5918
  },
6067
5919
  }];
6068
- case 7: return [2 /*return*/, {
5920
+ case 4: return [2 /*return*/, {
6069
5921
  source: name,
6070
5922
  filename: null,
6071
5923
  url: null,
@@ -7176,6 +7028,22 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
7176
7028
  * TODO: [🌺] Use some intermediate util splitWords
7177
7029
  */
7178
7030
 
7031
+ /**
7032
+ * Removes emojis from a string and fix whitespaces
7033
+ *
7034
+ * @param text with emojis
7035
+ * @returns text without emojis
7036
+ * @public exported from `@promptbook/utils`
7037
+ */
7038
+ function removeEmojis(text) {
7039
+ // Replace emojis (and also ZWJ sequence) with hyphens
7040
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
7041
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
7042
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
7043
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
7044
+ return text;
7045
+ }
7046
+
7179
7047
  /**
7180
7048
  * Removes quotes from a string
7181
7049
  *
@@ -9123,15 +8991,12 @@ function isFlatPipeline(pipelineString) {
9123
8991
  pipelineString = removeMarkdownComments(pipelineString);
9124
8992
  pipelineString = spaceTrim(pipelineString);
9125
8993
  var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9126
- //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
9127
- var isBacktickBlockUsed = pipelineString.includes('```');
9128
- var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
9129
- var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
9130
- // TODO: [🧉] Also (double)check
8994
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8995
+ // TODO: Also (double)check
9131
8996
  // > const usedCommands
9132
8997
  // > const isBlocksUsed
9133
8998
  // > const returnStatementCount
9134
- var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
8999
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9135
9000
  return isFlat;
9136
9001
  }
9137
9002
 
@@ -9145,26 +9010,9 @@ function deflatePipeline(pipelineString) {
9145
9010
  return pipelineString;
9146
9011
  }
9147
9012
  var pipelineStringLines = pipelineString.split('\n');
9148
- var potentialReturnStatement = pipelineStringLines.pop();
9149
- var returnStatement;
9150
- if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
9151
- // Note: Last line is return statement
9152
- returnStatement = potentialReturnStatement;
9153
- }
9154
- else {
9155
- // Note: Last line is not a return statement
9156
- returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
9157
- pipelineStringLines.push(potentialReturnStatement);
9158
- }
9013
+ var returnStatement = pipelineStringLines.pop();
9159
9014
  var prompt = spaceTrim(pipelineStringLines.join('\n'));
9160
- var quotedPrompt;
9161
- if (prompt.split('\n').length <= 1) {
9162
- quotedPrompt = "> ".concat(prompt);
9163
- }
9164
- else {
9165
- quotedPrompt = spaceTrim(function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
9166
- }
9167
- pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ").concat(block(quotedPrompt), "\n\n ").concat(returnStatement, "\n "); }));
9015
+ 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 "); }));
9168
9016
  // <- TODO: Maybe use book` notation
9169
9017
  return pipelineString;
9170
9018
  }
@@ -9387,6 +9235,30 @@ function flattenMarkdown(markdown) {
9387
9235
  * NOW we are working just with markdown string and its good enough
9388
9236
  */
9389
9237
 
9238
+ /**
9239
+ * @@@
9240
+ *
9241
+ * @param value @@@
9242
+ * @returns @@@
9243
+ * @example @@@
9244
+ * @public exported from `@promptbook/utils`
9245
+ */
9246
+ function titleToName(value) {
9247
+ if (isValidUrl(value)) {
9248
+ value = value.replace(/^https?:\/\//, '');
9249
+ value = value.replace(/\.html$/, '');
9250
+ }
9251
+ else if (isValidFilePath(value)) {
9252
+ value = basename(value);
9253
+ // Note: Keeping extension in the name
9254
+ }
9255
+ value = value.split('/').join('-');
9256
+ value = removeEmojis(value);
9257
+ value = normalizeToKebabCase(value);
9258
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
9259
+ return value;
9260
+ }
9261
+
9390
9262
  /**
9391
9263
  * Compile pipeline from string (markdown) format to JSON format synchronously
9392
9264
  *
@@ -11039,55 +10911,6 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
11039
10911
  */
11040
10912
  var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
11041
10913
 
11042
- /**
11043
- * Registration of LLM provider metadata
11044
- *
11045
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
11046
- *
11047
- * @public exported from `@promptbook/core`
11048
- * @public exported from `@promptbook/wizzard`
11049
- * @public exported from `@promptbook/cli`
11050
- */
11051
- var _DeepseekMetadataRegistration = $llmToolsMetadataRegister.register({
11052
- title: 'Deepseek',
11053
- packageName: '@promptbook/deepseek',
11054
- className: 'DeepseekExecutionTools',
11055
- envVariables: ['DEEPSEEK_GENERATIVE_AI_API_KEY'],
11056
- getBoilerplateConfiguration: function () {
11057
- return {
11058
- title: 'Deepseek (boilerplate)',
11059
- packageName: '@promptbook/deepseek',
11060
- className: 'DeepseekExecutionTools',
11061
- options: {
11062
- apiKey: 'AI',
11063
- },
11064
- };
11065
- },
11066
- createConfigurationFromEnv: function (env) {
11067
- if ($isRunningInJest()
11068
- // <- TODO: Maybe check `env.JEST_WORKER_ID` directly here or pass `env` into `$isRunningInJest`
11069
- ) {
11070
- // Note: [🔘] Maybe same problem as Gemini
11071
- return null;
11072
- }
11073
- // Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
11074
- if (typeof env.DEEPSEEK_GENERATIVE_AI_API_KEY === 'string') {
11075
- return {
11076
- title: 'Deepseek (from env)',
11077
- packageName: '@promptbook/deepseek',
11078
- className: 'DeepseekExecutionTools',
11079
- options: {
11080
- apiKey: env.DEEPSEEK_GENERATIVE_AI_API_KEY,
11081
- },
11082
- };
11083
- }
11084
- return null;
11085
- },
11086
- });
11087
- /**
11088
- * Note: [💞] Ignore a discrepancy between file name and entity name
11089
- */
11090
-
11091
10914
  /**
11092
10915
  * Registration of LLM provider metadata
11093
10916
  *
@@ -11252,14 +11075,13 @@ function isValidPipelineString(pipelineString) {
11252
11075
  /**
11253
11076
  * Tag function for notating a prompt as template literal
11254
11077
  *
11255
- * Note: There are 3 similar functions:
11078
+ * Note: There are 2 similar functions:
11256
11079
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11257
- * 2) `promptTemplate` alias for `prompt`
11258
- * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
11080
+ * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
11259
11081
  *
11260
- * @param strings
11261
- * @param values
11262
- * @returns the prompt string
11082
+ * @param strings @@@
11083
+ * @param values @@@
11084
+ * @returns the pipeline string
11263
11085
  * @public exported from `@promptbook/utils`
11264
11086
  */
11265
11087
  function prompt(strings) {
@@ -11270,14 +11092,10 @@ function prompt(strings) {
11270
11092
  if (values.length === 0) {
11271
11093
  return spaceTrim(strings.join(''));
11272
11094
  }
11273
- var stringsWithHiddenParameters = strings.map(function (stringsItem) {
11274
- // TODO: [0] DRY
11275
- return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
11276
- });
11277
11095
  var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
11278
11096
  var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
11279
11097
  // Combine strings and values
11280
- var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
11098
+ var pipelineString = strings.reduce(function (result, stringsItem, i) {
11281
11099
  return placeholderParameterNames[i] === undefined
11282
11100
  ? "".concat(result).concat(stringsItem)
11283
11101
  : "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
@@ -11293,12 +11111,6 @@ function prompt(strings) {
11293
11111
  console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
11294
11112
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Internal error in prompt template literal\n \n ".concat(block(JSON.stringify({ strings: strings, values: values }, null, 4)), "}\n \n "); }));
11295
11113
  }
11296
- // TODO: [0] DRY
11297
- pipelineString = pipelineString
11298
- .split("".concat(REPLACING_NONCE, "beginbracket"))
11299
- .join('{')
11300
- .split("".concat(REPLACING_NONCE, "endbracket"))
11301
- .join('}');
11302
11114
  return pipelineString;
11303
11115
  }
11304
11116
  /**
@@ -11309,10 +11121,9 @@ function prompt(strings) {
11309
11121
  /**
11310
11122
  * Tag function for notating a pipeline with a book\`...\ notation as template literal
11311
11123
  *
11312
- * Note: There are 3 similar functions:
11124
+ * Note: There are 2 similar functions:
11313
11125
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11314
- * 2) `promptTemplate` alias for `prompt`
11315
- * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
11126
+ * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
11316
11127
  *
11317
11128
  * @param strings @@@
11318
11129
  * @param values @@@
@@ -11472,7 +11283,7 @@ var markitdownScraperMetadata = $deepFreeze({
11472
11283
  className: 'MarkitdownScraper',
11473
11284
  mimeTypes: [
11474
11285
  'application/pdf',
11475
- // TODO: [💵] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
11286
+ // TODO: Make priority for scrapers and than allow all mime types here:
11476
11287
  // 'text/html',
11477
11288
  // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
11478
11289
  ],
@@ -11634,5 +11445,5 @@ var PrefixStorage = /** @class */ (function () {
11634
11445
  return PrefixStorage;
11635
11446
  }());
11636
11447
 
11637
- export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_DOWNLOAD_CACHE_DIRNAME, DEFAULT_EXECUTION_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_PROMPT_TASK_TITLE, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DeepseekMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, book, cacheLlmTools, collectionToJson, compilePipeline, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, parsePipeline, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline, validatePipelineString };
11448
+ export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TASK_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _BoilerplateScraperMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _MarkitdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, book, cacheLlmTools, collectionToJson, compilePipeline, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, parsePipeline, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline, validatePipelineString };
11638
11449
  //# sourceMappingURL=index.es.js.map