@promptbook/core 0.84.0-21 → 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 (38) hide show
  1. package/README.md +5 -21
  2. package/esm/index.es.js +190 -385
  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/cli/cli-commands/about.d.ts +1 -3
  10. package/esm/typings/src/cli/cli-commands/hello.d.ts +1 -3
  11. package/esm/typings/src/cli/cli-commands/list-models.d.ts +1 -3
  12. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -3
  13. package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -3
  14. package/esm/typings/src/cli/cli-commands/run.d.ts +1 -3
  15. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +1 -1
  16. package/esm/typings/src/cli/cli-commands/test-command.d.ts +1 -3
  17. package/esm/typings/src/config.d.ts +1 -27
  18. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  19. package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
  20. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -3
  21. package/esm/typings/src/pipeline/book-notation.d.ts +2 -3
  22. package/esm/typings/src/pipeline/prompt-notation.d.ts +5 -18
  23. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  24. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -5
  25. package/esm/typings/src/wizzard/wizzard.d.ts +1 -7
  26. package/package.json +15 -8
  27. package/umd/index.umd.js +191 -391
  28. package/umd/index.umd.js.map +1 -1
  29. package/esm/typings/src/_packages/deepseek.index.d.ts +0 -8
  30. package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +0 -13
  31. package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +0 -9
  32. package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +0 -14
  33. package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +0 -14
  34. package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +0 -15
  35. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +0 -1
  36. package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +0 -1
  37. package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +0 -10
  38. package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +0 -1
package/umd/index.umd.js CHANGED
@@ -1,17 +1,17 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('moment'), require('colors')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'moment', 'colors'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.moment, global.colors));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, hexEncoder, sha256, path, cryptoJs, mimeTypes, moment, colors) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('path'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types'), require('moment'), require('colors'), require('crypto-js/sha256')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'path', 'crypto-js', 'crypto-js/enc-hex', 'mime-types', 'moment', 'colors', 'crypto-js/sha256'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.path, global.cryptoJs, global.hexEncoder, global.mimeTypes, global.moment, global.colors, global.sha256));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, waitasecond, papaparse, path, cryptoJs, hexEncoder, mimeTypes, moment, colors, sha256) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
10
10
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
11
11
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
12
- var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
13
12
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
14
13
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
14
+ var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
15
15
 
16
16
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
17
17
  /**
@@ -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-20';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-8';
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
@@ -180,94 +180,22 @@
180
180
  */
181
181
 
182
182
  /**
183
- * Checks if value is valid email
184
- *
185
- * @public exported from `@promptbook/utils`
186
- */
187
- function isValidEmail(email) {
188
- if (typeof email !== 'string') {
189
- return false;
190
- }
191
- if (email.split('\n').length > 1) {
192
- return false;
193
- }
194
- return /^.+@.+\..+$/.test(email);
195
- }
196
-
197
- /**
198
- * Tests if given string is valid URL.
183
+ * Function isValidJsonString will tell you if the string is valid JSON or not
199
184
  *
200
- * Note: This does not check if the file exists only if the path is valid
201
185
  * @public exported from `@promptbook/utils`
202
186
  */
203
- function isValidFilePath(filename) {
204
- if (typeof filename !== 'string') {
205
- return false;
206
- }
207
- if (filename.split('\n').length > 1) {
208
- return false;
209
- }
210
- if (filename.split(' ').length >
211
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
212
- return false;
213
- }
214
- var filenameSlashes = filename.split('\\').join('/');
215
- // Absolute Unix path: /hello.txt
216
- if (/^(\/)/i.test(filenameSlashes)) {
217
- // console.log(filename, 'Absolute Unix path: /hello.txt');
218
- return true;
219
- }
220
- // Absolute Windows path: /hello.txt
221
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
222
- // console.log(filename, 'Absolute Windows path: /hello.txt');
223
- return true;
224
- }
225
- // Relative path: ./hello.txt
226
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
227
- // console.log(filename, 'Relative path: ./hello.txt');
228
- return true;
229
- }
230
- // Allow paths like foo/hello
231
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
232
- // console.log(filename, 'Allow paths like foo/hello');
233
- return true;
234
- }
235
- // Allow paths like hello.book
236
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
237
- // console.log(filename, 'Allow paths like hello.book');
187
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
188
+ try {
189
+ JSON.parse(value);
238
190
  return true;
239
191
  }
240
- return false;
241
- }
242
- /**
243
- * TODO: [🍏] Implement for MacOs
244
- */
245
-
246
- /**
247
- * Tests if given string is valid URL.
248
- *
249
- * Note: Dataurl are considered perfectly valid.
250
- * Note: There are two simmilar functions:
251
- * - `isValidUrl` which tests any URL
252
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
253
- *
254
- * @public exported from `@promptbook/utils`
255
- */
256
- function isValidUrl(url) {
257
- if (typeof url !== 'string') {
258
- return false;
259
- }
260
- try {
261
- if (url.startsWith('blob:')) {
262
- url = url.replace(/^blob:/, '');
192
+ catch (error) {
193
+ if (!(error instanceof Error)) {
194
+ throw error;
263
195
  }
264
- var urlObject = new URL(url /* because fail is handled */);
265
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
196
+ if (error.message.includes('Unexpected token')) {
266
197
  return false;
267
198
  }
268
- return true;
269
- }
270
- catch (error) {
271
199
  return false;
272
200
  }
273
201
  }
@@ -291,27 +219,6 @@
291
219
  * TODO: Maybe split `ParseError` and `ApplyError`
292
220
  */
293
221
 
294
- /**
295
- * Function isValidJsonString will tell you if the string is valid JSON or not
296
- *
297
- * @public exported from `@promptbook/utils`
298
- */
299
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
300
- try {
301
- JSON.parse(value);
302
- return true;
303
- }
304
- catch (error) {
305
- if (!(error instanceof Error)) {
306
- throw error;
307
- }
308
- if (error.message.includes('Unexpected token')) {
309
- return false;
310
- }
311
- return false;
312
- }
313
- }
314
-
315
222
  /**
316
223
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
317
224
  * 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.
@@ -325,15 +232,6 @@
325
232
  if (isValidJsonString(pipelineString)) {
326
233
  throw new ParseError('Expected a book, but got a JSON string');
327
234
  }
328
- else if (isValidUrl(pipelineString)) {
329
- throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
330
- }
331
- else if (isValidFilePath(pipelineString)) {
332
- throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
333
- }
334
- else if (isValidEmail(pipelineString)) {
335
- throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
336
- }
337
235
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
338
236
  return pipelineString;
339
237
  }
@@ -674,24 +572,6 @@
674
572
  * @public exported from `@promptbook/core`
675
573
  */
676
574
  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';
689
- /**
690
- * Maximum file size limit
691
- *
692
- * @public exported from `@promptbook/core`
693
- */
694
- var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
695
575
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
696
576
  /**
697
577
  * The maximum number of iterations for a loops
@@ -772,14 +652,6 @@
772
652
  */
773
653
  var DEFAULT_BOOKS_DIRNAME = './books';
774
654
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
775
- /**
776
- * Where to store the temporary downloads
777
- *
778
- * Note: When the folder does not exist, it is created recursively
779
- *
780
- * @public exported from `@promptbook/core`
781
- */
782
- var DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
783
655
  /**
784
656
  * Where to store the cache of executions for promptbook CLI
785
657
  *
@@ -787,7 +659,7 @@
787
659
  *
788
660
  * @public exported from `@promptbook/core`
789
661
  */
790
- var DEFAULT_EXECUTION_CACHE_DIRNAME = './.promptbook/execution-cache';
662
+ var DEFAULT_EXECUTIONS_CACHE_DIRNAME = './.promptbook/executions-cache';
791
663
  /**
792
664
  * Where to store the scrape cache
793
665
  *
@@ -1313,6 +1185,35 @@
1313
1185
  return isHostnameOnPrivateNetwork(url.hostname);
1314
1186
  }
1315
1187
 
1188
+ /**
1189
+ * Tests if given string is valid URL.
1190
+ *
1191
+ * Note: Dataurl are considered perfectly valid.
1192
+ * Note: There are two simmilar functions:
1193
+ * - `isValidUrl` which tests any URL
1194
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1195
+ *
1196
+ * @public exported from `@promptbook/utils`
1197
+ */
1198
+ function isValidUrl(url) {
1199
+ if (typeof url !== 'string') {
1200
+ return false;
1201
+ }
1202
+ try {
1203
+ if (url.startsWith('blob:')) {
1204
+ url = url.replace(/^blob:/, '');
1205
+ }
1206
+ var urlObject = new URL(url /* because fail is handled */);
1207
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1208
+ return false;
1209
+ }
1210
+ return true;
1211
+ }
1212
+ catch (error) {
1213
+ return false;
1214
+ }
1215
+ }
1216
+
1316
1217
  /**
1317
1218
  * Tests if given string is valid pipeline URL URL.
1318
1219
  *
@@ -2271,28 +2172,12 @@
2271
2172
  /**
2272
2173
  * Asserts that the execution of a Promptbook is successful
2273
2174
  *
2274
- * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2275
- *
2276
2175
  * @param executionResult - The partial result of the Promptbook execution
2277
2176
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2278
2177
  * @public exported from `@promptbook/core`
2279
2178
  */
2280
2179
  function assertsExecutionSuccessful(executionResult) {
2281
- var e_1, _a;
2282
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2283
- try {
2284
- for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2285
- var warning = warnings_1_1.value;
2286
- console.warn(warning.message);
2287
- }
2288
- }
2289
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2290
- finally {
2291
- try {
2292
- if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2293
- }
2294
- finally { if (e_1) throw e_1.error; }
2295
- }
2180
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2296
2181
  if (isSuccessful === true) {
2297
2182
  return;
2298
2183
  }
@@ -3302,7 +3187,7 @@
3302
3187
  if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
3303
3188
  throw error_1;
3304
3189
  }
3305
- errors.push({ llmExecutionTools: llmExecutionTools, error: error_1 });
3190
+ errors.push(error_1);
3306
3191
  return [3 /*break*/, 13];
3307
3192
  case 13:
3308
3193
  _b = _a.next();
@@ -3329,10 +3214,7 @@
3329
3214
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3330
3215
  // 3) ...
3331
3216
  spaceTrim__default["default"](function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
3332
- .map(function (_a, i) {
3333
- var error = _a.error, llmExecutionTools = _a.llmExecutionTools;
3334
- return "".concat(i + 1, ") **").concat(llmExecutionTools.title, "** thrown **").concat(error.name || 'Error', ":** ").concat(error.message);
3335
- })
3217
+ .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
3336
3218
  .join('\n')), "\n\n "); }));
3337
3219
  }
3338
3220
  else if (this.llmExecutionTools.length === 0) {
@@ -5780,15 +5662,6 @@
5780
5662
  * TODO: [🐱‍🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
5781
5663
  */
5782
5664
 
5783
- /**
5784
- * @@@
5785
- *
5786
- * @private for `FileCacheStorage`
5787
- */
5788
- function nameToSubfolderPath(name) {
5789
- return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
5790
- }
5791
-
5792
5665
  /**
5793
5666
  * Convert file extension to mime type
5794
5667
  *
@@ -5845,55 +5718,53 @@
5845
5718
  */
5846
5719
 
5847
5720
  /**
5848
- * Convert mime type to file extension
5849
- *
5850
- * Note: If the mime type is invalid, `null` is returned
5851
- *
5852
- * @private within the repository
5853
- */
5854
- function mimeTypeToExtension(value) {
5855
- return mimeTypes.extension(value) || null;
5856
- }
5857
-
5858
- /**
5859
- * Removes emojis from a string and fix whitespaces
5860
- *
5861
- * @param text with emojis
5862
- * @returns text without emojis
5863
- * @public exported from `@promptbook/utils`
5864
- */
5865
- function removeEmojis(text) {
5866
- // Replace emojis (and also ZWJ sequence) with hyphens
5867
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
5868
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
5869
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
5870
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
5871
- return text;
5872
- }
5873
-
5874
- /**
5875
- * @@@
5721
+ * Tests if given string is valid URL.
5876
5722
  *
5877
- * @param value @@@
5878
- * @returns @@@
5879
- * @example @@@
5723
+ * Note: This does not check if the file exists only if the path is valid
5880
5724
  * @public exported from `@promptbook/utils`
5881
5725
  */
5882
- function titleToName(value) {
5883
- if (isValidUrl(value)) {
5884
- value = value.replace(/^https?:\/\//, '');
5885
- value = value.replace(/\.html$/, '');
5726
+ function isValidFilePath(filename) {
5727
+ if (typeof filename !== 'string') {
5728
+ return false;
5886
5729
  }
5887
- else if (isValidFilePath(value)) {
5888
- value = path.basename(value);
5889
- // Note: Keeping extension in the name
5730
+ if (filename.split('\n').length > 1) {
5731
+ return false;
5890
5732
  }
5891
- value = value.split('/').join('-');
5892
- value = removeEmojis(value);
5893
- value = normalizeToKebabCase(value);
5894
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
5895
- return value;
5733
+ if (filename.split(' ').length >
5734
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
5735
+ return false;
5736
+ }
5737
+ var filenameSlashes = filename.split('\\').join('/');
5738
+ // Absolute Unix path: /hello.txt
5739
+ if (/^(\/)/i.test(filenameSlashes)) {
5740
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
5741
+ return true;
5742
+ }
5743
+ // Absolute Windows path: /hello.txt
5744
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
5745
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
5746
+ return true;
5747
+ }
5748
+ // Relative path: ./hello.txt
5749
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
5750
+ // console.log(filename, 'Relative path: ./hello.txt');
5751
+ return true;
5752
+ }
5753
+ // Allow paths like foo/hello
5754
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
5755
+ // console.log(filename, 'Allow paths like foo/hello');
5756
+ return true;
5757
+ }
5758
+ // Allow paths like hello.book
5759
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
5760
+ // console.log(filename, 'Allow paths like hello.book');
5761
+ return true;
5762
+ }
5763
+ return false;
5896
5764
  }
5765
+ /**
5766
+ * TODO: [🍏] Implement for MacOs
5767
+ */
5897
5768
 
5898
5769
  /**
5899
5770
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -5930,9 +5801,9 @@
5930
5801
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5931
5802
  var _a;
5932
5803
  return __awaiter(this, void 0, void 0, function () {
5933
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
5934
- return __generator(this, function (_h) {
5935
- switch (_h.label) {
5804
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5805
+ return __generator(this, function (_f) {
5806
+ switch (_f.label) {
5936
5807
  case 0:
5937
5808
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5938
5809
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -5941,76 +5812,54 @@
5941
5812
  if (!name) {
5942
5813
  name = knowledgeSourceContentToName(knowledgeSourceContent);
5943
5814
  }
5944
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
5815
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
5945
5816
  url = knowledgeSourceContent;
5946
5817
  return [4 /*yield*/, fetch(url)];
5947
5818
  case 1:
5948
- response_1 = _h.sent();
5819
+ response_1 = _f.sent();
5949
5820
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5950
- if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
5951
- return [2 /*return*/, {
5952
- source: name,
5953
- filename: null,
5954
- url: url,
5955
- mimeType: mimeType,
5956
- /*
5957
- TODO: [🥽]
5958
- > async asBlob() {
5959
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5960
- > const content = await response.blob();
5961
- > return content;
5962
- > },
5963
- */
5964
- asJson: function () {
5965
- return __awaiter(this, void 0, void 0, function () {
5966
- var content;
5967
- return __generator(this, function (_a) {
5968
- switch (_a.label) {
5969
- case 0: return [4 /*yield*/, response_1.json()];
5970
- case 1:
5971
- content = _a.sent();
5972
- return [2 /*return*/, content];
5973
- }
5974
- });
5821
+ return [2 /*return*/, {
5822
+ source: name,
5823
+ filename: null,
5824
+ url: url,
5825
+ mimeType: mimeType,
5826
+ /*
5827
+ TODO: [🥽]
5828
+ > async asBlob() {
5829
+ > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5830
+ > const content = await response.blob();
5831
+ > return content;
5832
+ > },
5833
+ */
5834
+ asJson: function () {
5835
+ return __awaiter(this, void 0, void 0, function () {
5836
+ var content;
5837
+ return __generator(this, function (_a) {
5838
+ switch (_a.label) {
5839
+ case 0: return [4 /*yield*/, response_1.json()];
5840
+ case 1:
5841
+ content = _a.sent();
5842
+ return [2 /*return*/, content];
5843
+ }
5975
5844
  });
5976
- },
5977
- asText: function () {
5978
- return __awaiter(this, void 0, void 0, function () {
5979
- var content;
5980
- return __generator(this, function (_a) {
5981
- switch (_a.label) {
5982
- case 0: return [4 /*yield*/, response_1.text()];
5983
- case 1:
5984
- content = _a.sent();
5985
- return [2 /*return*/, content];
5986
- }
5987
- });
5845
+ });
5846
+ },
5847
+ asText: function () {
5848
+ return __awaiter(this, void 0, void 0, function () {
5849
+ var content;
5850
+ return __generator(this, function (_a) {
5851
+ switch (_a.label) {
5852
+ case 0: return [4 /*yield*/, response_1.text()];
5853
+ case 1:
5854
+ content = _a.sent();
5855
+ return [2 /*return*/, content];
5856
+ }
5988
5857
  });
5989
- },
5990
- }];
5991
- }
5992
- basename = url.split('/').pop() || titleToName(url);
5993
- hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5994
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5995
- 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));
5996
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
5858
+ });
5859
+ },
5860
+ }];
5997
5861
  case 2:
5998
- _h.sent();
5999
- _g = (_f = Buffer).from;
6000
- return [4 /*yield*/, response_1.arrayBuffer()];
6001
- case 3:
6002
- fileContent = _g.apply(_f, [_h.sent()]);
6003
- if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
6004
- 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."));
6005
- }
6006
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
6007
- case 4:
6008
- _h.sent();
6009
- // TODO: [💵] Check the file security
6010
- // TODO: [🧹][🧠] Delete the file after the scraping is done
6011
- return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6012
- case 5:
6013
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
5862
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
6014
5863
  if (tools.fs === undefined) {
6015
5864
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
6016
5865
  // <- TODO: [🧠] What is the best error type here`
@@ -6023,8 +5872,8 @@
6023
5872
  fileExtension = getFileExtension(filename_1);
6024
5873
  mimeType = extensionToMimeType(fileExtension || '');
6025
5874
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6026
- case 6:
6027
- if (!(_h.sent())) {
5875
+ case 3:
5876
+ if (!(_f.sent())) {
6028
5877
  throw new NotFoundError(spaceTrim__default["default"](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 "); }));
6029
5878
  }
6030
5879
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -6070,7 +5919,7 @@
6070
5919
  });
6071
5920
  },
6072
5921
  }];
6073
- case 7: return [2 /*return*/, {
5922
+ case 4: return [2 /*return*/, {
6074
5923
  source: name,
6075
5924
  filename: null,
6076
5925
  url: null,
@@ -7181,6 +7030,22 @@
7181
7030
  * TODO: [🌺] Use some intermediate util splitWords
7182
7031
  */
7183
7032
 
7033
+ /**
7034
+ * Removes emojis from a string and fix whitespaces
7035
+ *
7036
+ * @param text with emojis
7037
+ * @returns text without emojis
7038
+ * @public exported from `@promptbook/utils`
7039
+ */
7040
+ function removeEmojis(text) {
7041
+ // Replace emojis (and also ZWJ sequence) with hyphens
7042
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
7043
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
7044
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
7045
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
7046
+ return text;
7047
+ }
7048
+
7184
7049
  /**
7185
7050
  * Removes quotes from a string
7186
7051
  *
@@ -9040,10 +8905,7 @@
9040
8905
  description: 'Chatbot response',
9041
8906
  isInput: false,
9042
8907
  isOutput: true,
9043
- exampleValues: [
9044
- 'Hello, how can I help you?',
9045
- // <- TODO: [🧠] Make this dynamic, async, prepare-phase HLAs
9046
- ],
8908
+ exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
9047
8909
  });
9048
8910
  // TODO: Use spaceTrim in multiline strings
9049
8911
  $pipelineJson.tasks.push({
@@ -9131,15 +8993,12 @@
9131
8993
  pipelineString = removeMarkdownComments(pipelineString);
9132
8994
  pipelineString = spaceTrim__default["default"](pipelineString);
9133
8995
  var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9134
- //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
9135
- var isBacktickBlockUsed = pipelineString.includes('```');
9136
- var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
9137
- var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
9138
- // TODO: [🧉] Also (double)check
8996
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8997
+ // TODO: Also (double)check
9139
8998
  // > const usedCommands
9140
8999
  // > const isBlocksUsed
9141
9000
  // > const returnStatementCount
9142
- var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
9001
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9143
9002
  return isFlat;
9144
9003
  }
9145
9004
 
@@ -9153,26 +9012,9 @@
9153
9012
  return pipelineString;
9154
9013
  }
9155
9014
  var pipelineStringLines = pipelineString.split('\n');
9156
- var potentialReturnStatement = pipelineStringLines.pop();
9157
- var returnStatement;
9158
- if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
9159
- // Note: Last line is return statement
9160
- returnStatement = potentialReturnStatement;
9161
- }
9162
- else {
9163
- // Note: Last line is not a return statement
9164
- returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
9165
- pipelineStringLines.push(potentialReturnStatement);
9166
- }
9015
+ var returnStatement = pipelineStringLines.pop();
9167
9016
  var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
9168
- var quotedPrompt;
9169
- if (prompt.split('\n').length <= 1) {
9170
- quotedPrompt = "> ".concat(prompt);
9171
- }
9172
- else {
9173
- quotedPrompt = spaceTrim__default["default"](function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
9174
- }
9175
- 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 "); }));
9017
+ 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 "); }));
9176
9018
  // <- TODO: Maybe use book` notation
9177
9019
  return pipelineString;
9178
9020
  }
@@ -9395,6 +9237,30 @@
9395
9237
  * NOW we are working just with markdown string and its good enough
9396
9238
  */
9397
9239
 
9240
+ /**
9241
+ * @@@
9242
+ *
9243
+ * @param value @@@
9244
+ * @returns @@@
9245
+ * @example @@@
9246
+ * @public exported from `@promptbook/utils`
9247
+ */
9248
+ function titleToName(value) {
9249
+ if (isValidUrl(value)) {
9250
+ value = value.replace(/^https?:\/\//, '');
9251
+ value = value.replace(/\.html$/, '');
9252
+ }
9253
+ else if (isValidFilePath(value)) {
9254
+ value = path.basename(value);
9255
+ // Note: Keeping extension in the name
9256
+ }
9257
+ value = value.split('/').join('-');
9258
+ value = removeEmojis(value);
9259
+ value = normalizeToKebabCase(value);
9260
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
9261
+ return value;
9262
+ }
9263
+
9398
9264
  /**
9399
9265
  * Compile pipeline from string (markdown) format to JSON format synchronously
9400
9266
  *
@@ -11047,55 +10913,6 @@
11047
10913
  */
11048
10914
  var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
11049
10915
 
11050
- /**
11051
- * Registration of LLM provider metadata
11052
- *
11053
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
11054
- *
11055
- * @public exported from `@promptbook/core`
11056
- * @public exported from `@promptbook/wizzard`
11057
- * @public exported from `@promptbook/cli`
11058
- */
11059
- var _DeepseekMetadataRegistration = $llmToolsMetadataRegister.register({
11060
- title: 'Deepseek',
11061
- packageName: '@promptbook/deepseek',
11062
- className: 'DeepseekExecutionTools',
11063
- envVariables: ['DEEPSEEK_GENERATIVE_AI_API_KEY'],
11064
- getBoilerplateConfiguration: function () {
11065
- return {
11066
- title: 'Deepseek (boilerplate)',
11067
- packageName: '@promptbook/deepseek',
11068
- className: 'DeepseekExecutionTools',
11069
- options: {
11070
- apiKey: 'AI',
11071
- },
11072
- };
11073
- },
11074
- createConfigurationFromEnv: function (env) {
11075
- if ($isRunningInJest()
11076
- // <- TODO: Maybe check `env.JEST_WORKER_ID` directly here or pass `env` into `$isRunningInJest`
11077
- ) {
11078
- // Note: [🔘] Maybe same problem as Gemini
11079
- return null;
11080
- }
11081
- // Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
11082
- if (typeof env.DEEPSEEK_GENERATIVE_AI_API_KEY === 'string') {
11083
- return {
11084
- title: 'Deepseek (from env)',
11085
- packageName: '@promptbook/deepseek',
11086
- className: 'DeepseekExecutionTools',
11087
- options: {
11088
- apiKey: env.DEEPSEEK_GENERATIVE_AI_API_KEY,
11089
- },
11090
- };
11091
- }
11092
- return null;
11093
- },
11094
- });
11095
- /**
11096
- * Note: [💞] Ignore a discrepancy between file name and entity name
11097
- */
11098
-
11099
10916
  /**
11100
10917
  * Registration of LLM provider metadata
11101
10918
  *
@@ -11260,14 +11077,13 @@
11260
11077
  /**
11261
11078
  * Tag function for notating a prompt as template literal
11262
11079
  *
11263
- * Note: There are 3 similar functions:
11080
+ * Note: There are 2 similar functions:
11264
11081
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11265
- * 2) `promptTemplate` alias for `prompt`
11266
- * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
11082
+ * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
11267
11083
  *
11268
- * @param strings
11269
- * @param values
11270
- * @returns the prompt string
11084
+ * @param strings @@@
11085
+ * @param values @@@
11086
+ * @returns the pipeline string
11271
11087
  * @public exported from `@promptbook/utils`
11272
11088
  */
11273
11089
  function prompt(strings) {
@@ -11278,14 +11094,10 @@
11278
11094
  if (values.length === 0) {
11279
11095
  return spaceTrim__default["default"](strings.join(''));
11280
11096
  }
11281
- var stringsWithHiddenParameters = strings.map(function (stringsItem) {
11282
- // TODO: [0] DRY
11283
- return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
11284
- });
11285
11097
  var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
11286
11098
  var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
11287
11099
  // Combine strings and values
11288
- var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
11100
+ var pipelineString = strings.reduce(function (result, stringsItem, i) {
11289
11101
  return placeholderParameterNames[i] === undefined
11290
11102
  ? "".concat(result).concat(stringsItem)
11291
11103
  : "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
@@ -11301,12 +11113,6 @@
11301
11113
  console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
11302
11114
  throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Internal error in prompt template literal\n \n ".concat(block(JSON.stringify({ strings: strings, values: values }, null, 4)), "}\n \n "); }));
11303
11115
  }
11304
- // TODO: [0] DRY
11305
- pipelineString = pipelineString
11306
- .split("".concat(REPLACING_NONCE, "beginbracket"))
11307
- .join('{')
11308
- .split("".concat(REPLACING_NONCE, "endbracket"))
11309
- .join('}');
11310
11116
  return pipelineString;
11311
11117
  }
11312
11118
  /**
@@ -11317,10 +11123,9 @@
11317
11123
  /**
11318
11124
  * Tag function for notating a pipeline with a book\`...\ notation as template literal
11319
11125
  *
11320
- * Note: There are 3 similar functions:
11126
+ * Note: There are 2 similar functions:
11321
11127
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11322
- * 2) `promptTemplate` alias for `prompt`
11323
- * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
11128
+ * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
11324
11129
  *
11325
11130
  * @param strings @@@
11326
11131
  * @param values @@@
@@ -11480,7 +11285,7 @@
11480
11285
  className: 'MarkitdownScraper',
11481
11286
  mimeTypes: [
11482
11287
  'application/pdf',
11483
- // TODO: [💵] Make priority for scrapers and than analyze which mime-types can Markitdown scrape and allow all mime types here:
11288
+ // TODO: Make priority for scrapers and than allow all mime types here:
11484
11289
  // 'text/html',
11485
11290
  // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
11486
11291
  ],
@@ -11660,21 +11465,17 @@
11660
11465
  exports.CsvFormatDefinition = CsvFormatDefinition;
11661
11466
  exports.CsvFormatError = CsvFormatError;
11662
11467
  exports.DEFAULT_BOOKS_DIRNAME = DEFAULT_BOOKS_DIRNAME;
11663
- exports.DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = DEFAULT_BOOK_OUTPUT_PARAMETER_NAME;
11664
11468
  exports.DEFAULT_BOOK_TITLE = DEFAULT_BOOK_TITLE;
11665
11469
  exports.DEFAULT_CSV_SETTINGS = DEFAULT_CSV_SETTINGS;
11666
- exports.DEFAULT_DOWNLOAD_CACHE_DIRNAME = DEFAULT_DOWNLOAD_CACHE_DIRNAME;
11667
- exports.DEFAULT_EXECUTION_CACHE_DIRNAME = DEFAULT_EXECUTION_CACHE_DIRNAME;
11470
+ exports.DEFAULT_EXECUTIONS_CACHE_DIRNAME = DEFAULT_EXECUTIONS_CACHE_DIRNAME;
11668
11471
  exports.DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME;
11669
11472
  exports.DEFAULT_INTERMEDIATE_FILES_STRATEGY = DEFAULT_INTERMEDIATE_FILES_STRATEGY;
11670
11473
  exports.DEFAULT_IS_AUTO_INSTALLED = DEFAULT_IS_AUTO_INSTALLED;
11671
11474
  exports.DEFAULT_MAX_EXECUTION_ATTEMPTS = DEFAULT_MAX_EXECUTION_ATTEMPTS;
11672
- exports.DEFAULT_MAX_FILE_SIZE = DEFAULT_MAX_FILE_SIZE;
11673
11475
  exports.DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH;
11674
11476
  exports.DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL;
11675
11477
  exports.DEFAULT_MAX_PARALLEL_COUNT = DEFAULT_MAX_PARALLEL_COUNT;
11676
11478
  exports.DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME;
11677
- exports.DEFAULT_PROMPT_TASK_TITLE = DEFAULT_PROMPT_TASK_TITLE;
11678
11479
  exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
11679
11480
  exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
11680
11481
  exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
@@ -11724,7 +11525,6 @@
11724
11525
  exports._AnthropicClaudeMetadataRegistration = _AnthropicClaudeMetadataRegistration;
11725
11526
  exports._AzureOpenAiMetadataRegistration = _AzureOpenAiMetadataRegistration;
11726
11527
  exports._BoilerplateScraperMetadataRegistration = _BoilerplateScraperMetadataRegistration;
11727
- exports._DeepseekMetadataRegistration = _DeepseekMetadataRegistration;
11728
11528
  exports._DocumentScraperMetadataRegistration = _DocumentScraperMetadataRegistration;
11729
11529
  exports._GoogleMetadataRegistration = _GoogleMetadataRegistration;
11730
11530
  exports._LegacyDocumentScraperMetadataRegistration = _LegacyDocumentScraperMetadataRegistration;