@promptbook/remote-server 0.84.0-0 → 0.84.0-11

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 (30) hide show
  1. package/README.md +1 -0
  2. package/esm/index.es.js +624 -430
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +8 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
  7. package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  9. package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
  10. package/esm/typings/src/constants.d.ts +1 -1
  11. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
  12. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
  13. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
  14. package/esm/typings/src/pipeline/book-notation.d.ts +5 -0
  15. package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
  16. package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
  17. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
  18. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
  19. package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
  20. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
  21. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
  22. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
  23. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
  24. package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
  25. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
  26. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
  27. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  28. package/package.json +3 -3
  29. package/umd/index.umd.js +626 -431
  30. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('http'), require('socket.io'), require('spacetrim'), require('fs/promises'), require('child_process'), require('util'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond'), require('papaparse'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'http', 'socket.io', 'spacetrim', 'fs/promises', 'child_process', 'util', 'path', 'prettier', 'prettier/parser-html', 'waitasecond', 'papaparse', 'crypto-js', 'crypto-js/enc-hex', 'mime-types'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.http, global.socket_io, global.spaceTrim, global.promises, global.child_process, global.util, global.path, global.prettier, global.parserHtml, global.waitasecond, global.papaparse, global.cryptoJs, global.hexEncoder, global.mimeTypes));
5
- })(this, (function (exports, colors, http, socket_io, spaceTrim, promises, child_process, util, path, prettier, parserHtml, waitasecond, papaparse, cryptoJs, hexEncoder, mimeTypes) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('http'), require('socket.io'), require('spacetrim'), require('child_process'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js'), require('crypto-js/enc-hex'), require('mime-types')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'http', 'socket.io', 'spacetrim', 'child_process', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js', 'crypto-js/enc-hex', 'mime-types'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.http, global.socket_io, global.spaceTrim, global.child_process, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.cryptoJs, global.hexEncoder, global.mimeTypes));
5
+ })(this, (function (exports, colors, http, socket_io, spaceTrim, child_process, waitasecond, promises, path, prettier, parserHtml, papaparse, cryptoJs, hexEncoder, mimeTypes) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -184,7 +184,7 @@
184
184
  *
185
185
  * @public exported from `@promptbook/core`
186
186
  */
187
- var ADMIN_EMAIL = 'me@pavolhejny.com';
187
+ var ADMIN_EMAIL = 'pavol@ptbk.io';
188
188
  /**
189
189
  * Name of the responsible person for the Promptbook on GitHub
190
190
  *
@@ -295,311 +295,6 @@
295
295
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
296
296
  */
297
297
 
298
- /**
299
- * This error type indicates that you try to use a feature that is not available in the current environment
300
- *
301
- * @public exported from `@promptbook/core`
302
- */
303
- var EnvironmentMismatchError = /** @class */ (function (_super) {
304
- __extends(EnvironmentMismatchError, _super);
305
- function EnvironmentMismatchError(message) {
306
- var _this = _super.call(this, message) || this;
307
- _this.name = 'EnvironmentMismatchError';
308
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
309
- return _this;
310
- }
311
- return EnvironmentMismatchError;
312
- }(Error));
313
-
314
- /**
315
- * Detects if the code is running in a Node.js environment
316
- *
317
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
318
- *
319
- * @public exported from `@promptbook/utils`
320
- */
321
- var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
322
-
323
- /**
324
- * @@@
325
- *
326
- * @public exported from `@promptbook/node`
327
- */
328
- function $provideFilesystemForNode(options) {
329
- if (!$isRunningInNode()) {
330
- throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
331
- }
332
- (options || {}).isVerbose;
333
- return {
334
- stat: promises.stat,
335
- access: promises.access,
336
- constants: promises.constants,
337
- readFile: promises.readFile,
338
- writeFile: promises.writeFile,
339
- readdir: promises.readdir,
340
- };
341
- }
342
- /**
343
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
344
- */
345
-
346
- /**
347
- * This error type indicates that some part of the code is not implemented yet
348
- *
349
- * @public exported from `@promptbook/core`
350
- */
351
- var NotYetImplementedError = /** @class */ (function (_super) {
352
- __extends(NotYetImplementedError, _super);
353
- function NotYetImplementedError(message) {
354
- var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
355
- _this.name = 'NotYetImplementedError';
356
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
357
- return _this;
358
- }
359
- return NotYetImplementedError;
360
- }(Error));
361
-
362
- /**
363
- * Make error report URL for the given error
364
- *
365
- * @private private within the repository
366
- */
367
- function getErrorReportUrl(error) {
368
- var report = {
369
- title: "\uD83D\uDC1C Error report from ".concat(NAME),
370
- body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
371
- };
372
- var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
373
- reportUrl.searchParams.set('labels', 'bug');
374
- reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
375
- reportUrl.searchParams.set('title', report.title);
376
- reportUrl.searchParams.set('body', report.body);
377
- return reportUrl;
378
- }
379
-
380
- /**
381
- * This error type indicates that the error should not happen and its last check before crashing with some other error
382
- *
383
- * @public exported from `@promptbook/core`
384
- */
385
- var UnexpectedError = /** @class */ (function (_super) {
386
- __extends(UnexpectedError, _super);
387
- function UnexpectedError(message) {
388
- var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
389
- _this.name = 'UnexpectedError';
390
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
391
- return _this;
392
- }
393
- return UnexpectedError;
394
- }(Error));
395
-
396
- /**
397
- * @@@
398
- *
399
- * Note: `$` is used to indicate that this function is not a pure function - it access global scope
400
- *
401
- * @private internal function of `$Register`
402
- */
403
- function $getGlobalScope() {
404
- return Function('return this')();
405
- }
406
-
407
- /**
408
- * @@@
409
- *
410
- * @param text @@@
411
- * @returns @@@
412
- * @example 'HELLO_WORLD'
413
- * @example 'I_LOVE_PROMPTBOOK'
414
- * @public exported from `@promptbook/utils`
415
- */
416
- function normalizeTo_SCREAMING_CASE(text) {
417
- var e_1, _a;
418
- var charType;
419
- var lastCharType = 'OTHER';
420
- var normalizedName = '';
421
- try {
422
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
423
- var char = text_1_1.value;
424
- var normalizedChar = void 0;
425
- if (/^[a-z]$/.test(char)) {
426
- charType = 'LOWERCASE';
427
- normalizedChar = char.toUpperCase();
428
- }
429
- else if (/^[A-Z]$/.test(char)) {
430
- charType = 'UPPERCASE';
431
- normalizedChar = char;
432
- }
433
- else if (/^[0-9]$/.test(char)) {
434
- charType = 'NUMBER';
435
- normalizedChar = char;
436
- }
437
- else {
438
- charType = 'OTHER';
439
- normalizedChar = '_';
440
- }
441
- if (charType !== lastCharType &&
442
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
443
- !(lastCharType === 'NUMBER') &&
444
- !(charType === 'NUMBER')) {
445
- normalizedName += '_';
446
- }
447
- normalizedName += normalizedChar;
448
- lastCharType = charType;
449
- }
450
- }
451
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
452
- finally {
453
- try {
454
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
455
- }
456
- finally { if (e_1) throw e_1.error; }
457
- }
458
- normalizedName = normalizedName.replace(/_+/g, '_');
459
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
460
- normalizedName = normalizedName.replace(/^_/, '');
461
- normalizedName = normalizedName.replace(/_$/, '');
462
- return normalizedName;
463
- }
464
- /**
465
- * TODO: Tests
466
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
467
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
468
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
469
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
470
- * TODO: [🌺] Use some intermediate util splitWords
471
- */
472
-
473
- /**
474
- * @@@
475
- *
476
- * @param text @@@
477
- * @returns @@@
478
- * @example 'hello_world'
479
- * @example 'i_love_promptbook'
480
- * @public exported from `@promptbook/utils`
481
- */
482
- function normalizeTo_snake_case(text) {
483
- return normalizeTo_SCREAMING_CASE(text).toLowerCase();
484
- }
485
-
486
- /**
487
- * Register is @@@
488
- *
489
- * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
490
- *
491
- * @private internal utility, exported are only signleton instances of this class
492
- */
493
- var $Register = /** @class */ (function () {
494
- function $Register(registerName) {
495
- this.registerName = registerName;
496
- var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
497
- var globalScope = $getGlobalScope();
498
- if (globalScope[storageName] === undefined) {
499
- globalScope[storageName] = [];
500
- }
501
- else if (!Array.isArray(globalScope[storageName])) {
502
- throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
503
- }
504
- this.storage = globalScope[storageName];
505
- }
506
- $Register.prototype.list = function () {
507
- // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
508
- return this.storage;
509
- };
510
- $Register.prototype.register = function (registered) {
511
- var packageName = registered.packageName, className = registered.className;
512
- var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
513
- var existingRegistration = this.storage[existingRegistrationIndex];
514
- if (!existingRegistration) {
515
- this.storage.push(registered);
516
- }
517
- else {
518
- this.storage[existingRegistrationIndex] = registered;
519
- }
520
- return {
521
- registerName: this.registerName,
522
- packageName: packageName,
523
- className: className,
524
- get isDestroyed() {
525
- return false;
526
- },
527
- destroy: function () {
528
- throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
529
- },
530
- };
531
- };
532
- return $Register;
533
- }());
534
-
535
- /**
536
- * @@@
537
- *
538
- * Note: `$` is used to indicate that this interacts with the global scope
539
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
540
- * @public exported from `@promptbook/core`
541
- */
542
- var $scrapersRegister = new $Register('scraper_constructors');
543
- /**
544
- * TODO: [®] DRY Register logic
545
- */
546
-
547
- /**
548
- * @@@
549
- *
550
- * 1) @@@
551
- * 2) @@@
552
- *
553
- * @public exported from `@promptbook/node`
554
- */
555
- function $provideScrapersForNode(tools, options) {
556
- return __awaiter(this, void 0, void 0, function () {
557
- var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
558
- var e_1, _f;
559
- return __generator(this, function (_g) {
560
- switch (_g.label) {
561
- case 0:
562
- if (!$isRunningInNode()) {
563
- throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
564
- }
565
- _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
566
- scrapers = [];
567
- _g.label = 1;
568
- case 1:
569
- _g.trys.push([1, 6, 7, 8]);
570
- _d = __values($scrapersRegister.list()), _e = _d.next();
571
- _g.label = 2;
572
- case 2:
573
- if (!!_e.done) return [3 /*break*/, 5];
574
- scraperFactory = _e.value;
575
- return [4 /*yield*/, scraperFactory(tools, options || {})];
576
- case 3:
577
- scraper = _g.sent();
578
- scrapers.push(scraper);
579
- _g.label = 4;
580
- case 4:
581
- _e = _d.next();
582
- return [3 /*break*/, 2];
583
- case 5: return [3 /*break*/, 8];
584
- case 6:
585
- e_1_1 = _g.sent();
586
- e_1 = { error: e_1_1 };
587
- return [3 /*break*/, 8];
588
- case 7:
589
- try {
590
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
591
- }
592
- finally { if (e_1) throw e_1.error; }
593
- return [7 /*endfinally*/];
594
- case 8: return [2 /*return*/, scrapers];
595
- }
596
- });
597
- });
598
- }
599
- /**
600
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
601
- */
602
-
603
298
  /**
604
299
  * This error indicates errors during the execution of the pipeline
605
300
  *
@@ -668,6 +363,22 @@
668
363
  return CollectionError;
669
364
  }(Error));
670
365
 
366
+ /**
367
+ * This error type indicates that you try to use a feature that is not available in the current environment
368
+ *
369
+ * @public exported from `@promptbook/core`
370
+ */
371
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
372
+ __extends(EnvironmentMismatchError, _super);
373
+ function EnvironmentMismatchError(message) {
374
+ var _this = _super.call(this, message) || this;
375
+ _this.name = 'EnvironmentMismatchError';
376
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
377
+ return _this;
378
+ }
379
+ return EnvironmentMismatchError;
380
+ }(Error));
381
+
671
382
  /**
672
383
  * This error occurs when some expectation is not met in the execution of the pipeline
673
384
  *
@@ -751,6 +462,22 @@
751
462
  return NotFoundError;
752
463
  }(Error));
753
464
 
465
+ /**
466
+ * This error type indicates that some part of the code is not implemented yet
467
+ *
468
+ * @public exported from `@promptbook/core`
469
+ */
470
+ var NotYetImplementedError = /** @class */ (function (_super) {
471
+ __extends(NotYetImplementedError, _super);
472
+ function NotYetImplementedError(message) {
473
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
474
+ _this.name = 'NotYetImplementedError';
475
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
476
+ return _this;
477
+ }
478
+ return NotYetImplementedError;
479
+ }(Error));
480
+
754
481
  /**
755
482
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
756
483
  *
@@ -791,15 +518,49 @@
791
518
  *
792
519
  * @public exported from `@promptbook/core`
793
520
  */
794
- var PipelineUrlError = /** @class */ (function (_super) {
795
- __extends(PipelineUrlError, _super);
796
- function PipelineUrlError(message) {
797
- var _this = _super.call(this, message) || this;
798
- _this.name = 'PipelineUrlError';
799
- Object.setPrototypeOf(_this, PipelineUrlError.prototype);
521
+ var PipelineUrlError = /** @class */ (function (_super) {
522
+ __extends(PipelineUrlError, _super);
523
+ function PipelineUrlError(message) {
524
+ var _this = _super.call(this, message) || this;
525
+ _this.name = 'PipelineUrlError';
526
+ Object.setPrototypeOf(_this, PipelineUrlError.prototype);
527
+ return _this;
528
+ }
529
+ return PipelineUrlError;
530
+ }(Error));
531
+
532
+ /**
533
+ * Make error report URL for the given error
534
+ *
535
+ * @private private within the repository
536
+ */
537
+ function getErrorReportUrl(error) {
538
+ var report = {
539
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
540
+ body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
541
+ };
542
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
543
+ reportUrl.searchParams.set('labels', 'bug');
544
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
545
+ reportUrl.searchParams.set('title', report.title);
546
+ reportUrl.searchParams.set('body', report.body);
547
+ return reportUrl;
548
+ }
549
+
550
+ /**
551
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
552
+ *
553
+ * @public exported from `@promptbook/core`
554
+ */
555
+ var UnexpectedError = /** @class */ (function (_super) {
556
+ __extends(UnexpectedError, _super);
557
+ function UnexpectedError(message) {
558
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
559
+ _this.name = 'UnexpectedError';
560
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
800
561
  return _this;
801
562
  }
802
- return PipelineUrlError;
563
+ return UnexpectedError;
803
564
  }(Error));
804
565
 
805
566
  /**
@@ -875,30 +636,196 @@
875
636
  };
876
637
  }
877
638
 
878
- // Note: We want to use the `exec` as async function
879
- var exec$1 = util.promisify(child_process.exec);
639
+ /**
640
+ * Detects if the code is running in a Node.js environment
641
+ *
642
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
643
+ *
644
+ * @public exported from `@promptbook/utils`
645
+ */
646
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
647
+
648
+ /**
649
+ * Normalize options for `execCommand` and `execCommands`
650
+ *
651
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
652
+ *
653
+ * @private internal utility of `execCommand` and `execCommands`
654
+ */
655
+ function $execCommandNormalizeOptions(options) {
656
+ var _a;
657
+ var _b, _c, _d, _e;
658
+ var command;
659
+ var cwd;
660
+ var crashOnError;
661
+ var args = [];
662
+ var timeout;
663
+ var isVerbose;
664
+ if (typeof options === 'string') {
665
+ // TODO: [1] DRY default values
666
+ command = options;
667
+ cwd = process.cwd();
668
+ crashOnError = true;
669
+ timeout = Infinity; // <- TODO: [⏳]
670
+ isVerbose = DEFAULT_IS_VERBOSE;
671
+ }
672
+ else {
673
+ /*
674
+ TODO:
675
+ if ((options as any).commands !== undefined) {
676
+ commands = (options as any).commands;
677
+ } else {
678
+ commands = [(options as any).command];
679
+ }
680
+ */
681
+ // TODO: [1] DRY default values
682
+ command = options.command;
683
+ cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
684
+ crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
685
+ timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
686
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
687
+ }
688
+ // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
689
+ var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
690
+ .map(function (_a) {
691
+ var _b = __read(_a, 1), match = _b[0];
692
+ return match;
693
+ })
694
+ .filter(function (arg) { return arg !== ''; });
695
+ if (_.length > 1) {
696
+ _a = __read(_), command = _a[0], args = _a.slice(1);
697
+ }
698
+ if (options.args) {
699
+ args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
700
+ }
701
+ var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
702
+ if (['ts-node'].includes(humanReadableCommand)) {
703
+ humanReadableCommand += " ".concat(args[1]);
704
+ }
705
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
706
+ command = "".concat(command, ".cmd");
707
+ }
708
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
709
+ }
710
+ // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
711
+
712
+ /**
713
+ * Run one command in a shell
714
+ *
715
+ *
716
+ * Note: There are 2 similar functions in the codebase:
717
+ * - `$execCommand` which runs a single command
718
+ * - `$execCommands` which runs multiple commands
719
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
720
+ *
721
+ * @public exported from `@promptbook/node`
722
+ */
723
+ function $execCommand(options) {
724
+ if (!$isRunningInNode()) {
725
+ throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
726
+ }
727
+ return new Promise(function (resolve, reject) {
728
+ // eslint-disable-next-line prefer-const
729
+ var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
730
+ if (timeout !== Infinity) {
731
+ // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
732
+ waitasecond.forTime(timeout).then(function () {
733
+ if (crashOnError) {
734
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
735
+ }
736
+ else {
737
+ console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
738
+ resolve('Command exceeded time limit');
739
+ }
740
+ });
741
+ }
742
+ if (isVerbose) {
743
+ console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
744
+ }
745
+ try {
746
+ var commandProcess = child_process.spawn(command, args, { cwd: cwd, shell: true });
747
+ if (isVerbose) {
748
+ commandProcess.on('message', function (message) {
749
+ console.info({ message: message });
750
+ });
751
+ }
752
+ var output_1 = [];
753
+ commandProcess.stdout.on('data', function (stdout) {
754
+ output_1.push(stdout.toString());
755
+ if (isVerbose) {
756
+ console.info(stdout.toString());
757
+ }
758
+ });
759
+ commandProcess.stderr.on('data', function (stderr) {
760
+ output_1.push(stderr.toString());
761
+ if (isVerbose && stderr.toString().trim()) {
762
+ console.warn(stderr.toString());
763
+ }
764
+ });
765
+ var finishWithCode = function (code) {
766
+ if (code !== 0) {
767
+ if (crashOnError) {
768
+ reject(new Error(output_1.join('\n').trim() ||
769
+ "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
770
+ }
771
+ else {
772
+ if (isVerbose) {
773
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
774
+ }
775
+ resolve(spaceTrim.spaceTrim(output_1.join('\n')));
776
+ }
777
+ }
778
+ else {
779
+ resolve(spaceTrim.spaceTrim(output_1.join('\n')));
780
+ }
781
+ };
782
+ commandProcess.on('close', finishWithCode);
783
+ commandProcess.on('exit', finishWithCode);
784
+ commandProcess.on('disconnect', function () {
785
+ // Note: Unexpected disconnection should always result in rejection
786
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
787
+ });
788
+ commandProcess.on('error', function (error) {
789
+ if (crashOnError) {
790
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
791
+ }
792
+ else {
793
+ if (isVerbose) {
794
+ console.warn(error);
795
+ }
796
+ resolve(spaceTrim.spaceTrim(output_1.join('\n')));
797
+ }
798
+ });
799
+ }
800
+ catch (error) {
801
+ // Note: Unexpected error in sync code should always result in rejection
802
+ reject(error);
803
+ }
804
+ });
805
+ }
806
+ /**
807
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
808
+ */
809
+
880
810
  /**
881
811
  * @@@
882
812
  *
883
813
  * @private within the repository
884
814
  */
885
815
  function locateAppOnLinux(_a) {
886
- var appName = _a.appName, linuxWhich = _a.linuxWhich;
816
+ var linuxWhich = _a.linuxWhich;
887
817
  return __awaiter(this, void 0, void 0, function () {
888
- var _b, stderr, stdout, error_1;
889
- return __generator(this, function (_c) {
890
- switch (_c.label) {
818
+ var result, error_1;
819
+ return __generator(this, function (_b) {
820
+ switch (_b.label) {
891
821
  case 0:
892
- _c.trys.push([0, 2, , 3]);
893
- return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
822
+ _b.trys.push([0, 2, , 3]);
823
+ return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
894
824
  case 1:
895
- _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
896
- if (!stderr && stdout) {
897
- return [2 /*return*/, stdout.trim()];
898
- }
899
- throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
825
+ result = _b.sent();
826
+ return [2 /*return*/, result.trim()];
900
827
  case 2:
901
- error_1 = _c.sent();
828
+ error_1 = _b.sent();
902
829
  if (!(error_1 instanceof Error)) {
903
830
  throw error_1;
904
831
  }
@@ -913,6 +840,29 @@
913
840
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
914
841
  */
915
842
 
843
+ /**
844
+ * @@@
845
+ *
846
+ * @public exported from `@promptbook/node`
847
+ */
848
+ function $provideFilesystemForNode(options) {
849
+ if (!$isRunningInNode()) {
850
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
851
+ }
852
+ (options || {}).isVerbose;
853
+ return {
854
+ stat: promises.stat,
855
+ access: promises.access,
856
+ constants: promises.constants,
857
+ readFile: promises.readFile,
858
+ writeFile: promises.writeFile,
859
+ readdir: promises.readdir,
860
+ };
861
+ }
862
+ /**
863
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
864
+ */
865
+
916
866
  /**
917
867
  * Checks if the file is executable
918
868
  *
@@ -945,43 +895,41 @@
945
895
  // @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
946
896
  // eslint-disable-next-line @typescript-eslint/no-var-requires
947
897
  var userhome = require('userhome');
948
- // Note: We want to use the `exec` as async function
949
- var exec = util.promisify(child_process.exec);
950
898
  /**
951
899
  * @@@
952
900
  *
953
901
  * @private within the repository
954
902
  */
955
903
  function locateAppOnMacOs(_a) {
956
- var appName = _a.appName, macOsName = _a.macOsName;
904
+ var macOsName = _a.macOsName;
957
905
  return __awaiter(this, void 0, void 0, function () {
958
- var toExec, regPath, altPath, _b, stderr, stdout, error_1;
959
- return __generator(this, function (_c) {
960
- switch (_c.label) {
906
+ var toExec, regPath, altPath, result, error_1;
907
+ return __generator(this, function (_b) {
908
+ switch (_b.label) {
961
909
  case 0:
962
- _c.trys.push([0, 6, , 7]);
910
+ _b.trys.push([0, 6, , 7]);
963
911
  toExec = "/Contents/MacOS/".concat(macOsName);
964
912
  regPath = "/Applications/".concat(macOsName, ".app") + toExec;
965
913
  altPath = userhome(regPath.slice(1));
966
914
  return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
967
915
  case 1:
968
- if (!_c.sent()) return [3 /*break*/, 2];
916
+ if (!_b.sent()) return [3 /*break*/, 2];
969
917
  return [2 /*return*/, regPath];
970
918
  case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
971
919
  case 3:
972
- if (_c.sent()) {
920
+ if (_b.sent()) {
973
921
  return [2 /*return*/, altPath];
974
922
  }
975
- _c.label = 4;
976
- case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
923
+ _b.label = 4;
924
+ case 4: return [4 /*yield*/, $execCommand({
925
+ crashOnError: true,
926
+ command: "mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"),
927
+ })];
977
928
  case 5:
978
- _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
979
- if (!stderr && stdout) {
980
- return [2 /*return*/, stdout.trim() + toExec];
981
- }
982
- throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
929
+ result = _b.sent();
930
+ return [2 /*return*/, result.trim() + toExec];
983
931
  case 6:
984
- error_1 = _c.sent();
932
+ error_1 = _b.sent();
985
933
  if (!(error_1 instanceof Error)) {
986
934
  throw error_1;
987
935
  }
@@ -1082,7 +1030,7 @@
1082
1030
  }
1083
1031
  else if (process.platform === 'darwin') {
1084
1032
  if (macOsName) {
1085
- return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
1033
+ return locateAppOnMacOs({ macOsName: macOsName });
1086
1034
  }
1087
1035
  else {
1088
1036
  throw new Error("".concat(appName, " is not available on macOS."));
@@ -1090,7 +1038,7 @@
1090
1038
  }
1091
1039
  else {
1092
1040
  if (linuxWhich) {
1093
- return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
1041
+ return locateAppOnLinux({ linuxWhich: linuxWhich });
1094
1042
  }
1095
1043
  else {
1096
1044
  throw new Error("".concat(appName, " is not available on Linux."));
@@ -1462,6 +1410,145 @@
1462
1410
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1463
1411
  */
1464
1412
 
1413
+ /**
1414
+ * @@@
1415
+ *
1416
+ * Note: `$` is used to indicate that this function is not a pure function - it access global scope
1417
+ *
1418
+ * @private internal function of `$Register`
1419
+ */
1420
+ function $getGlobalScope() {
1421
+ return Function('return this')();
1422
+ }
1423
+
1424
+ /**
1425
+ * @@@
1426
+ *
1427
+ * @param text @@@
1428
+ * @returns @@@
1429
+ * @example 'HELLO_WORLD'
1430
+ * @example 'I_LOVE_PROMPTBOOK'
1431
+ * @public exported from `@promptbook/utils`
1432
+ */
1433
+ function normalizeTo_SCREAMING_CASE(text) {
1434
+ var e_1, _a;
1435
+ var charType;
1436
+ var lastCharType = 'OTHER';
1437
+ var normalizedName = '';
1438
+ try {
1439
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
1440
+ var char = text_1_1.value;
1441
+ var normalizedChar = void 0;
1442
+ if (/^[a-z]$/.test(char)) {
1443
+ charType = 'LOWERCASE';
1444
+ normalizedChar = char.toUpperCase();
1445
+ }
1446
+ else if (/^[A-Z]$/.test(char)) {
1447
+ charType = 'UPPERCASE';
1448
+ normalizedChar = char;
1449
+ }
1450
+ else if (/^[0-9]$/.test(char)) {
1451
+ charType = 'NUMBER';
1452
+ normalizedChar = char;
1453
+ }
1454
+ else {
1455
+ charType = 'OTHER';
1456
+ normalizedChar = '_';
1457
+ }
1458
+ if (charType !== lastCharType &&
1459
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1460
+ !(lastCharType === 'NUMBER') &&
1461
+ !(charType === 'NUMBER')) {
1462
+ normalizedName += '_';
1463
+ }
1464
+ normalizedName += normalizedChar;
1465
+ lastCharType = charType;
1466
+ }
1467
+ }
1468
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1469
+ finally {
1470
+ try {
1471
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1472
+ }
1473
+ finally { if (e_1) throw e_1.error; }
1474
+ }
1475
+ normalizedName = normalizedName.replace(/_+/g, '_');
1476
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1477
+ normalizedName = normalizedName.replace(/^_/, '');
1478
+ normalizedName = normalizedName.replace(/_$/, '');
1479
+ return normalizedName;
1480
+ }
1481
+ /**
1482
+ * TODO: Tests
1483
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1484
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1485
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1486
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1487
+ * TODO: [🌺] Use some intermediate util splitWords
1488
+ */
1489
+
1490
+ /**
1491
+ * @@@
1492
+ *
1493
+ * @param text @@@
1494
+ * @returns @@@
1495
+ * @example 'hello_world'
1496
+ * @example 'i_love_promptbook'
1497
+ * @public exported from `@promptbook/utils`
1498
+ */
1499
+ function normalizeTo_snake_case(text) {
1500
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
1501
+ }
1502
+
1503
+ /**
1504
+ * Register is @@@
1505
+ *
1506
+ * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
1507
+ *
1508
+ * @private internal utility, exported are only signleton instances of this class
1509
+ */
1510
+ var $Register = /** @class */ (function () {
1511
+ function $Register(registerName) {
1512
+ this.registerName = registerName;
1513
+ var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
1514
+ var globalScope = $getGlobalScope();
1515
+ if (globalScope[storageName] === undefined) {
1516
+ globalScope[storageName] = [];
1517
+ }
1518
+ else if (!Array.isArray(globalScope[storageName])) {
1519
+ throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
1520
+ }
1521
+ this.storage = globalScope[storageName];
1522
+ }
1523
+ $Register.prototype.list = function () {
1524
+ // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
1525
+ return this.storage;
1526
+ };
1527
+ $Register.prototype.register = function (registered) {
1528
+ var packageName = registered.packageName, className = registered.className;
1529
+ var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
1530
+ var existingRegistration = this.storage[existingRegistrationIndex];
1531
+ if (!existingRegistration) {
1532
+ this.storage.push(registered);
1533
+ }
1534
+ else {
1535
+ this.storage[existingRegistrationIndex] = registered;
1536
+ }
1537
+ return {
1538
+ registerName: this.registerName,
1539
+ packageName: packageName,
1540
+ className: className,
1541
+ get isDestroyed() {
1542
+ return false;
1543
+ },
1544
+ destroy: function () {
1545
+ throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
1546
+ },
1547
+ };
1548
+ };
1549
+ return $Register;
1550
+ }());
1551
+
1465
1552
  /**
1466
1553
  * @@@
1467
1554
  *
@@ -1669,6 +1756,99 @@
1669
1756
 
1670
1757
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
1671
1758
 
1759
+ /**
1760
+ * Checks if value is valid email
1761
+ *
1762
+ * @public exported from `@promptbook/utils`
1763
+ */
1764
+ function isValidEmail(email) {
1765
+ if (typeof email !== 'string') {
1766
+ return false;
1767
+ }
1768
+ if (email.split('\n').length > 1) {
1769
+ return false;
1770
+ }
1771
+ return /^.+@.+\..+$/.test(email);
1772
+ }
1773
+
1774
+ /**
1775
+ * Tests if given string is valid URL.
1776
+ *
1777
+ * Note: This does not check if the file exists only if the path is valid
1778
+ * @public exported from `@promptbook/utils`
1779
+ */
1780
+ function isValidFilePath(filename) {
1781
+ if (typeof filename !== 'string') {
1782
+ return false;
1783
+ }
1784
+ if (filename.split('\n').length > 1) {
1785
+ return false;
1786
+ }
1787
+ if (filename.split(' ').length >
1788
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
1789
+ return false;
1790
+ }
1791
+ var filenameSlashes = filename.split('\\').join('/');
1792
+ // Absolute Unix path: /hello.txt
1793
+ if (/^(\/)/i.test(filenameSlashes)) {
1794
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
1795
+ return true;
1796
+ }
1797
+ // Absolute Windows path: /hello.txt
1798
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1799
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
1800
+ return true;
1801
+ }
1802
+ // Relative path: ./hello.txt
1803
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1804
+ // console.log(filename, 'Relative path: ./hello.txt');
1805
+ return true;
1806
+ }
1807
+ // Allow paths like foo/hello
1808
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
1809
+ // console.log(filename, 'Allow paths like foo/hello');
1810
+ return true;
1811
+ }
1812
+ // Allow paths like hello.book
1813
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
1814
+ // console.log(filename, 'Allow paths like hello.book');
1815
+ return true;
1816
+ }
1817
+ return false;
1818
+ }
1819
+ /**
1820
+ * TODO: [🍏] Implement for MacOs
1821
+ */
1822
+
1823
+ /**
1824
+ * Tests if given string is valid URL.
1825
+ *
1826
+ * Note: Dataurl are considered perfectly valid.
1827
+ * Note: There are two simmilar functions:
1828
+ * - `isValidUrl` which tests any URL
1829
+ * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
1830
+ *
1831
+ * @public exported from `@promptbook/utils`
1832
+ */
1833
+ function isValidUrl(url) {
1834
+ if (typeof url !== 'string') {
1835
+ return false;
1836
+ }
1837
+ try {
1838
+ if (url.startsWith('blob:')) {
1839
+ url = url.replace(/^blob:/, '');
1840
+ }
1841
+ var urlObject = new URL(url /* because fail is handled */);
1842
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
1843
+ return false;
1844
+ }
1845
+ return true;
1846
+ }
1847
+ catch (error) {
1848
+ return false;
1849
+ }
1850
+ }
1851
+
1672
1852
  /**
1673
1853
  * Function isValidJsonString will tell you if the string is valid JSON or not
1674
1854
  *
@@ -1703,6 +1883,15 @@
1703
1883
  if (isValidJsonString(pipelineString)) {
1704
1884
  throw new ParseError('Expected a book, but got a JSON string');
1705
1885
  }
1886
+ else if (isValidUrl(pipelineString)) {
1887
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1888
+ }
1889
+ else if (isValidFilePath(pipelineString)) {
1890
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1891
+ }
1892
+ else if (isValidEmail(pipelineString)) {
1893
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1894
+ }
1706
1895
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1707
1896
  return pipelineString;
1708
1897
  }
@@ -2216,7 +2405,7 @@
2216
2405
  *
2217
2406
  * @private within the repository
2218
2407
  */
2219
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
2408
+ var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
2220
2409
  /**
2221
2410
  * @@@
2222
2411
  *
@@ -2346,35 +2535,6 @@
2346
2535
  return isHostnameOnPrivateNetwork(url.hostname);
2347
2536
  }
2348
2537
 
2349
- /**
2350
- * Tests if given string is valid URL.
2351
- *
2352
- * Note: Dataurl are considered perfectly valid.
2353
- * Note: There are two simmilar functions:
2354
- * - `isValidUrl` which tests any URL
2355
- * - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
2356
- *
2357
- * @public exported from `@promptbook/utils`
2358
- */
2359
- function isValidUrl(url) {
2360
- if (typeof url !== 'string') {
2361
- return false;
2362
- }
2363
- try {
2364
- if (url.startsWith('blob:')) {
2365
- url = url.replace(/^blob:/, '');
2366
- }
2367
- var urlObject = new URL(url /* because fail is handled */);
2368
- if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
2369
- return false;
2370
- }
2371
- return true;
2372
- }
2373
- catch (error) {
2374
- return false;
2375
- }
2376
- }
2377
-
2378
2538
  /**
2379
2539
  * Tests if given string is valid pipeline URL URL.
2380
2540
  *
@@ -2874,12 +3034,28 @@
2874
3034
  /**
2875
3035
  * Asserts that the execution of a Promptbook is successful
2876
3036
  *
3037
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
3038
+ *
2877
3039
  * @param executionResult - The partial result of the Promptbook execution
2878
3040
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2879
3041
  * @public exported from `@promptbook/core`
2880
3042
  */
2881
3043
  function assertsExecutionSuccessful(executionResult) {
2882
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
3044
+ var e_1, _a;
3045
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
3046
+ try {
3047
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
3048
+ var warning = warnings_1_1.value;
3049
+ console.warn(warning.message);
3050
+ }
3051
+ }
3052
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3053
+ finally {
3054
+ try {
3055
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
3056
+ }
3057
+ finally { if (e_1) throw e_1.error; }
3058
+ }
2883
3059
  if (isSuccessful === true) {
2884
3060
  return;
2885
3061
  }
@@ -5673,6 +5849,18 @@
5673
5849
  * TODO: [®] DRY Register logic
5674
5850
  */
5675
5851
 
5852
+ /**
5853
+ * @@@
5854
+ *
5855
+ * Note: `$` is used to indicate that this interacts with the global scope
5856
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
5857
+ * @public exported from `@promptbook/core`
5858
+ */
5859
+ var $scrapersRegister = new $Register('scraper_constructors');
5860
+ /**
5861
+ * TODO: [®] DRY Register logic
5862
+ */
5863
+
5676
5864
  /**
5677
5865
  * Creates a message with all registered scrapers
5678
5866
  *
@@ -5931,55 +6119,6 @@
5931
6119
  * TODO: [🖇] What about symlinks?
5932
6120
  */
5933
6121
 
5934
- /**
5935
- * Tests if given string is valid URL.
5936
- *
5937
- * Note: This does not check if the file exists only if the path is valid
5938
- * @public exported from `@promptbook/utils`
5939
- */
5940
- function isValidFilePath(filename) {
5941
- if (typeof filename !== 'string') {
5942
- return false;
5943
- }
5944
- if (filename.split('\n').length > 1) {
5945
- return false;
5946
- }
5947
- if (filename.split(' ').length >
5948
- 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
5949
- return false;
5950
- }
5951
- var filenameSlashes = filename.split('\\').join('/');
5952
- // Absolute Unix path: /hello.txt
5953
- if (/^(\/)/i.test(filenameSlashes)) {
5954
- // console.log(filename, 'Absolute Unix path: /hello.txt');
5955
- return true;
5956
- }
5957
- // Absolute Windows path: /hello.txt
5958
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
5959
- // console.log(filename, 'Absolute Windows path: /hello.txt');
5960
- return true;
5961
- }
5962
- // Relative path: ./hello.txt
5963
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
5964
- // console.log(filename, 'Relative path: ./hello.txt');
5965
- return true;
5966
- }
5967
- // Allow paths like foo/hello
5968
- if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
5969
- // console.log(filename, 'Allow paths like foo/hello');
5970
- return true;
5971
- }
5972
- // Allow paths like hello.book
5973
- if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
5974
- // console.log(filename, 'Allow paths like hello.book');
5975
- return true;
5976
- }
5977
- return false;
5978
- }
5979
- /**
5980
- * TODO: [🍏] Implement for MacOs
5981
- */
5982
-
5983
6122
  /**
5984
6123
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5985
6124
  *
@@ -6472,6 +6611,62 @@
6472
6611
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
6473
6612
  */
6474
6613
 
6614
+ /**
6615
+ * @@@
6616
+ *
6617
+ * 1) @@@
6618
+ * 2) @@@
6619
+ *
6620
+ * @public exported from `@promptbook/node`
6621
+ */
6622
+ function $provideScrapersForNode(tools, options) {
6623
+ return __awaiter(this, void 0, void 0, function () {
6624
+ var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
6625
+ var e_1, _f;
6626
+ return __generator(this, function (_g) {
6627
+ switch (_g.label) {
6628
+ case 0:
6629
+ if (!$isRunningInNode()) {
6630
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
6631
+ }
6632
+ _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
6633
+ scrapers = [];
6634
+ _g.label = 1;
6635
+ case 1:
6636
+ _g.trys.push([1, 6, 7, 8]);
6637
+ _d = __values($scrapersRegister.list()), _e = _d.next();
6638
+ _g.label = 2;
6639
+ case 2:
6640
+ if (!!_e.done) return [3 /*break*/, 5];
6641
+ scraperFactory = _e.value;
6642
+ return [4 /*yield*/, scraperFactory(tools, options || {})];
6643
+ case 3:
6644
+ scraper = _g.sent();
6645
+ scrapers.push(scraper);
6646
+ _g.label = 4;
6647
+ case 4:
6648
+ _e = _d.next();
6649
+ return [3 /*break*/, 2];
6650
+ case 5: return [3 /*break*/, 8];
6651
+ case 6:
6652
+ e_1_1 = _g.sent();
6653
+ e_1 = { error: e_1_1 };
6654
+ return [3 /*break*/, 8];
6655
+ case 7:
6656
+ try {
6657
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
6658
+ }
6659
+ finally { if (e_1) throw e_1.error; }
6660
+ return [7 /*endfinally*/];
6661
+ case 8: return [2 /*return*/, scrapers];
6662
+ }
6663
+ });
6664
+ });
6665
+ }
6666
+ /**
6667
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6668
+ */
6669
+
6475
6670
  /**
6476
6671
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
6477
6672
  *