@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/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-19';
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
  }
@@ -5777,15 +5662,6 @@
5777
5662
  * TODO: [🐱‍🐉][🧠] Make some smart crop NOT source-i-m-pavol-a-develop-... BUT source-i-m-pavol-a-developer-...
5778
5663
  */
5779
5664
 
5780
- /**
5781
- * @@@
5782
- *
5783
- * @private for `FileCacheStorage`
5784
- */
5785
- function nameToSubfolderPath(name) {
5786
- return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
5787
- }
5788
-
5789
5665
  /**
5790
5666
  * Convert file extension to mime type
5791
5667
  *
@@ -5842,55 +5718,53 @@
5842
5718
  */
5843
5719
 
5844
5720
  /**
5845
- * Convert mime type to file extension
5846
- *
5847
- * Note: If the mime type is invalid, `null` is returned
5848
- *
5849
- * @private within the repository
5850
- */
5851
- function mimeTypeToExtension(value) {
5852
- return mimeTypes.extension(value) || null;
5853
- }
5854
-
5855
- /**
5856
- * Removes emojis from a string and fix whitespaces
5857
- *
5858
- * @param text with emojis
5859
- * @returns text without emojis
5860
- * @public exported from `@promptbook/utils`
5861
- */
5862
- function removeEmojis(text) {
5863
- // Replace emojis (and also ZWJ sequence) with hyphens
5864
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
5865
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
5866
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
5867
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
5868
- return text;
5869
- }
5870
-
5871
- /**
5872
- * @@@
5721
+ * Tests if given string is valid URL.
5873
5722
  *
5874
- * @param value @@@
5875
- * @returns @@@
5876
- * @example @@@
5723
+ * Note: This does not check if the file exists only if the path is valid
5877
5724
  * @public exported from `@promptbook/utils`
5878
5725
  */
5879
- function titleToName(value) {
5880
- if (isValidUrl(value)) {
5881
- value = value.replace(/^https?:\/\//, '');
5882
- value = value.replace(/\.html$/, '');
5726
+ function isValidFilePath(filename) {
5727
+ if (typeof filename !== 'string') {
5728
+ return false;
5883
5729
  }
5884
- else if (isValidFilePath(value)) {
5885
- value = path.basename(value);
5886
- // Note: Keeping extension in the name
5730
+ if (filename.split('\n').length > 1) {
5731
+ return false;
5887
5732
  }
5888
- value = value.split('/').join('-');
5889
- value = removeEmojis(value);
5890
- value = normalizeToKebabCase(value);
5891
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
5892
- 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;
5893
5764
  }
5765
+ /**
5766
+ * TODO: [🍏] Implement for MacOs
5767
+ */
5894
5768
 
5895
5769
  /**
5896
5770
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -5927,9 +5801,9 @@
5927
5801
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5928
5802
  var _a;
5929
5803
  return __awaiter(this, void 0, void 0, function () {
5930
- var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, fileContent, _f, _g, filename_1, fileExtension, mimeType;
5931
- return __generator(this, function (_h) {
5932
- 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) {
5933
5807
  case 0:
5934
5808
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5935
5809
  knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
@@ -5938,76 +5812,54 @@
5938
5812
  if (!name) {
5939
5813
  name = knowledgeSourceContentToName(knowledgeSourceContent);
5940
5814
  }
5941
- if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 5];
5815
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
5942
5816
  url = knowledgeSourceContent;
5943
5817
  return [4 /*yield*/, fetch(url)];
5944
5818
  case 1:
5945
- response_1 = _h.sent();
5819
+ response_1 = _f.sent();
5946
5820
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5947
- if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [💵] */)) {
5948
- return [2 /*return*/, {
5949
- source: name,
5950
- filename: null,
5951
- url: url,
5952
- mimeType: mimeType,
5953
- /*
5954
- TODO: [🥽]
5955
- > async asBlob() {
5956
- > // TODO: [👨🏻‍🤝‍👨🏻] This can be called multiple times BUT when called second time, response in already consumed
5957
- > const content = await response.blob();
5958
- > return content;
5959
- > },
5960
- */
5961
- asJson: function () {
5962
- return __awaiter(this, void 0, void 0, function () {
5963
- var content;
5964
- return __generator(this, function (_a) {
5965
- switch (_a.label) {
5966
- case 0: return [4 /*yield*/, response_1.json()];
5967
- case 1:
5968
- content = _a.sent();
5969
- return [2 /*return*/, content];
5970
- }
5971
- });
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
+ }
5972
5844
  });
5973
- },
5974
- asText: function () {
5975
- return __awaiter(this, void 0, void 0, function () {
5976
- var content;
5977
- return __generator(this, function (_a) {
5978
- switch (_a.label) {
5979
- case 0: return [4 /*yield*/, response_1.text()];
5980
- case 1:
5981
- content = _a.sent();
5982
- return [2 /*return*/, content];
5983
- }
5984
- });
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
+ }
5985
5857
  });
5986
- },
5987
- }];
5988
- }
5989
- basename = url.split('/').pop() || titleToName(url);
5990
- hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
5991
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
5992
- 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));
5993
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
5858
+ });
5859
+ },
5860
+ }];
5994
5861
  case 2:
5995
- _h.sent();
5996
- _g = (_f = Buffer).from;
5997
- return [4 /*yield*/, response_1.arrayBuffer()];
5998
- case 3:
5999
- fileContent = _g.apply(_f, [_h.sent()]);
6000
- if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
6001
- 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."));
6002
- }
6003
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
6004
- case 4:
6005
- _h.sent();
6006
- // TODO: [💵] Check the file security
6007
- // TODO: [🧹][🧠] Delete the file after the scraping is done
6008
- return [2 /*return*/, makeKnowledgeSourceHandler({ name: name, knowledgeSourceContent: filepath }, tools, __assign(__assign({}, options), { rootDirname: rootDirname_1 }))];
6009
- case 5:
6010
- if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 7];
5862
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
6011
5863
  if (tools.fs === undefined) {
6012
5864
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
6013
5865
  // <- TODO: [🧠] What is the best error type here`
@@ -6020,8 +5872,8 @@
6020
5872
  fileExtension = getFileExtension(filename_1);
6021
5873
  mimeType = extensionToMimeType(fileExtension || '');
6022
5874
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
6023
- case 6:
6024
- if (!(_h.sent())) {
5875
+ case 3:
5876
+ if (!(_f.sent())) {
6025
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 "); }));
6026
5878
  }
6027
5879
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -6067,7 +5919,7 @@
6067
5919
  });
6068
5920
  },
6069
5921
  }];
6070
- case 7: return [2 /*return*/, {
5922
+ case 4: return [2 /*return*/, {
6071
5923
  source: name,
6072
5924
  filename: null,
6073
5925
  url: null,
@@ -7178,6 +7030,22 @@
7178
7030
  * TODO: [🌺] Use some intermediate util splitWords
7179
7031
  */
7180
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
+
7181
7049
  /**
7182
7050
  * Removes quotes from a string
7183
7051
  *
@@ -9125,15 +8993,12 @@
9125
8993
  pipelineString = removeMarkdownComments(pipelineString);
9126
8994
  pipelineString = spaceTrim__default["default"](pipelineString);
9127
8995
  var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9128
- //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
9129
- var isBacktickBlockUsed = pipelineString.includes('```');
9130
- var isQuoteBlocksUsed = /^>\s+/m.test(pipelineString);
9131
- var isBlocksUsed = isBacktickBlockUsed || isQuoteBlocksUsed;
9132
- // TODO: [🧉] Also (double)check
8996
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8997
+ // TODO: Also (double)check
9133
8998
  // > const usedCommands
9134
8999
  // > const isBlocksUsed
9135
9000
  // > const returnStatementCount
9136
- var isFlat = !isMarkdownBeginningWithHeadline && !isBlocksUsed; /* && isLastLineReturnStatement */
9001
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9137
9002
  return isFlat;
9138
9003
  }
9139
9004
 
@@ -9147,26 +9012,9 @@
9147
9012
  return pipelineString;
9148
9013
  }
9149
9014
  var pipelineStringLines = pipelineString.split('\n');
9150
- var potentialReturnStatement = pipelineStringLines.pop();
9151
- var returnStatement;
9152
- if (/(-|=)>\s*\{.*\}/.test(potentialReturnStatement)) {
9153
- // Note: Last line is return statement
9154
- returnStatement = potentialReturnStatement;
9155
- }
9156
- else {
9157
- // Note: Last line is not a return statement
9158
- returnStatement = "-> {".concat(DEFAULT_BOOK_OUTPUT_PARAMETER_NAME, "}");
9159
- pipelineStringLines.push(potentialReturnStatement);
9160
- }
9015
+ var returnStatement = pipelineStringLines.pop();
9161
9016
  var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
9162
- var quotedPrompt;
9163
- if (prompt.split('\n').length <= 1) {
9164
- quotedPrompt = "> ".concat(prompt);
9165
- }
9166
- else {
9167
- quotedPrompt = spaceTrim__default["default"](function (block) { return "\n ```\n ".concat(block(prompt.split('`').join('\\`')), "\n ```\n "); });
9168
- }
9169
- 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 "); }));
9170
9018
  // <- TODO: Maybe use book` notation
9171
9019
  return pipelineString;
9172
9020
  }
@@ -9389,6 +9237,30 @@
9389
9237
  * NOW we are working just with markdown string and its good enough
9390
9238
  */
9391
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
+
9392
9264
  /**
9393
9265
  * Compile pipeline from string (markdown) format to JSON format synchronously
9394
9266
  *
@@ -11041,55 +10913,6 @@
11041
10913
  */
11042
10914
  var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
11043
10915
 
11044
- /**
11045
- * Registration of LLM provider metadata
11046
- *
11047
- * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
11048
- *
11049
- * @public exported from `@promptbook/core`
11050
- * @public exported from `@promptbook/wizzard`
11051
- * @public exported from `@promptbook/cli`
11052
- */
11053
- var _DeepseekMetadataRegistration = $llmToolsMetadataRegister.register({
11054
- title: 'Deepseek',
11055
- packageName: '@promptbook/deepseek',
11056
- className: 'DeepseekExecutionTools',
11057
- envVariables: ['DEEPSEEK_GENERATIVE_AI_API_KEY'],
11058
- getBoilerplateConfiguration: function () {
11059
- return {
11060
- title: 'Deepseek (boilerplate)',
11061
- packageName: '@promptbook/deepseek',
11062
- className: 'DeepseekExecutionTools',
11063
- options: {
11064
- apiKey: 'AI',
11065
- },
11066
- };
11067
- },
11068
- createConfigurationFromEnv: function (env) {
11069
- if ($isRunningInJest()
11070
- // <- TODO: Maybe check `env.JEST_WORKER_ID` directly here or pass `env` into `$isRunningInJest`
11071
- ) {
11072
- // Note: [🔘] Maybe same problem as Gemini
11073
- return null;
11074
- }
11075
- // Note: Note using `process.env` BUT `env` to pass in the environment variables dynamically
11076
- if (typeof env.DEEPSEEK_GENERATIVE_AI_API_KEY === 'string') {
11077
- return {
11078
- title: 'Deepseek (from env)',
11079
- packageName: '@promptbook/deepseek',
11080
- className: 'DeepseekExecutionTools',
11081
- options: {
11082
- apiKey: env.DEEPSEEK_GENERATIVE_AI_API_KEY,
11083
- },
11084
- };
11085
- }
11086
- return null;
11087
- },
11088
- });
11089
- /**
11090
- * Note: [💞] Ignore a discrepancy between file name and entity name
11091
- */
11092
-
11093
10916
  /**
11094
10917
  * Registration of LLM provider metadata
11095
10918
  *
@@ -11254,14 +11077,13 @@
11254
11077
  /**
11255
11078
  * Tag function for notating a prompt as template literal
11256
11079
  *
11257
- * Note: There are 3 similar functions:
11080
+ * Note: There are 2 similar functions:
11258
11081
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11259
- * 2) `promptTemplate` alias for `prompt`
11260
- * 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`
11261
11083
  *
11262
- * @param strings
11263
- * @param values
11264
- * @returns the prompt string
11084
+ * @param strings @@@
11085
+ * @param values @@@
11086
+ * @returns the pipeline string
11265
11087
  * @public exported from `@promptbook/utils`
11266
11088
  */
11267
11089
  function prompt(strings) {
@@ -11272,14 +11094,10 @@
11272
11094
  if (values.length === 0) {
11273
11095
  return spaceTrim__default["default"](strings.join(''));
11274
11096
  }
11275
- var stringsWithHiddenParameters = strings.map(function (stringsItem) {
11276
- // TODO: [0] DRY
11277
- return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
11278
- });
11279
11097
  var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
11280
11098
  var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
11281
11099
  // Combine strings and values
11282
- var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
11100
+ var pipelineString = strings.reduce(function (result, stringsItem, i) {
11283
11101
  return placeholderParameterNames[i] === undefined
11284
11102
  ? "".concat(result).concat(stringsItem)
11285
11103
  : "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
@@ -11295,12 +11113,6 @@
11295
11113
  console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
11296
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 "); }));
11297
11115
  }
11298
- // TODO: [0] DRY
11299
- pipelineString = pipelineString
11300
- .split("".concat(REPLACING_NONCE, "beginbracket"))
11301
- .join('{')
11302
- .split("".concat(REPLACING_NONCE, "endbracket"))
11303
- .join('}');
11304
11116
  return pipelineString;
11305
11117
  }
11306
11118
  /**
@@ -11311,10 +11123,9 @@
11311
11123
  /**
11312
11124
  * Tag function for notating a pipeline with a book\`...\ notation as template literal
11313
11125
  *
11314
- * Note: There are 3 similar functions:
11126
+ * Note: There are 2 similar functions:
11315
11127
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
11316
- * 2) `promptTemplate` alias for `prompt`
11317
- * 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`
11318
11129
  *
11319
11130
  * @param strings @@@
11320
11131
  * @param values @@@
@@ -11474,7 +11285,7 @@
11474
11285
  className: 'MarkitdownScraper',
11475
11286
  mimeTypes: [
11476
11287
  'application/pdf',
11477
- // 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:
11478
11289
  // 'text/html',
11479
11290
  // 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
11480
11291
  ],
@@ -11654,21 +11465,17 @@
11654
11465
  exports.CsvFormatDefinition = CsvFormatDefinition;
11655
11466
  exports.CsvFormatError = CsvFormatError;
11656
11467
  exports.DEFAULT_BOOKS_DIRNAME = DEFAULT_BOOKS_DIRNAME;
11657
- exports.DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = DEFAULT_BOOK_OUTPUT_PARAMETER_NAME;
11658
11468
  exports.DEFAULT_BOOK_TITLE = DEFAULT_BOOK_TITLE;
11659
11469
  exports.DEFAULT_CSV_SETTINGS = DEFAULT_CSV_SETTINGS;
11660
- exports.DEFAULT_DOWNLOAD_CACHE_DIRNAME = DEFAULT_DOWNLOAD_CACHE_DIRNAME;
11661
- exports.DEFAULT_EXECUTION_CACHE_DIRNAME = DEFAULT_EXECUTION_CACHE_DIRNAME;
11470
+ exports.DEFAULT_EXECUTIONS_CACHE_DIRNAME = DEFAULT_EXECUTIONS_CACHE_DIRNAME;
11662
11471
  exports.DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME;
11663
11472
  exports.DEFAULT_INTERMEDIATE_FILES_STRATEGY = DEFAULT_INTERMEDIATE_FILES_STRATEGY;
11664
11473
  exports.DEFAULT_IS_AUTO_INSTALLED = DEFAULT_IS_AUTO_INSTALLED;
11665
11474
  exports.DEFAULT_MAX_EXECUTION_ATTEMPTS = DEFAULT_MAX_EXECUTION_ATTEMPTS;
11666
- exports.DEFAULT_MAX_FILE_SIZE = DEFAULT_MAX_FILE_SIZE;
11667
11475
  exports.DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH;
11668
11476
  exports.DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL;
11669
11477
  exports.DEFAULT_MAX_PARALLEL_COUNT = DEFAULT_MAX_PARALLEL_COUNT;
11670
11478
  exports.DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME;
11671
- exports.DEFAULT_PROMPT_TASK_TITLE = DEFAULT_PROMPT_TASK_TITLE;
11672
11479
  exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
11673
11480
  exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
11674
11481
  exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
@@ -11718,7 +11525,6 @@
11718
11525
  exports._AnthropicClaudeMetadataRegistration = _AnthropicClaudeMetadataRegistration;
11719
11526
  exports._AzureOpenAiMetadataRegistration = _AzureOpenAiMetadataRegistration;
11720
11527
  exports._BoilerplateScraperMetadataRegistration = _BoilerplateScraperMetadataRegistration;
11721
- exports._DeepseekMetadataRegistration = _DeepseekMetadataRegistration;
11722
11528
  exports._DocumentScraperMetadataRegistration = _DocumentScraperMetadataRegistration;
11723
11529
  exports._GoogleMetadataRegistration = _GoogleMetadataRegistration;
11724
11530
  exports._LegacyDocumentScraperMetadataRegistration = _LegacyDocumentScraperMetadataRegistration;