@promptbook/remote-server 0.83.0 → 0.84.0-10

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 (37) hide show
  1. package/README.md +5 -0
  2. package/esm/index.es.js +498 -344
  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/editable.index.d.ts +8 -2
  7. package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
  8. package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  10. package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
  11. package/esm/typings/src/constants.d.ts +1 -1
  12. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
  13. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
  14. package/esm/typings/src/pipeline/book-notation.d.ts +4 -0
  15. package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -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/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
  29. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
  30. package/esm/typings/src/utils/editable/{utils → edit-pipeline-string}/removePipelineCommand.d.ts +1 -1
  31. package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
  32. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
  33. package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +3 -0
  34. package/package.json +3 -3
  35. package/umd/index.umd.js +500 -345
  36. package/umd/index.umd.js.map +1 -1
  37. /package/esm/typings/src/utils/editable/{utils/removePipelineCommand.test.d.ts → edit-pipeline-string/addPipelineCommand.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -2,13 +2,12 @@ import colors from 'colors';
2
2
  import http from 'http';
3
3
  import { Server } from 'socket.io';
4
4
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
5
+ import { spawn } from 'child_process';
6
+ import { forTime } from 'waitasecond';
5
7
  import { stat, access, constants, readFile, writeFile, readdir } from 'fs/promises';
6
- import { exec as exec$2 } from 'child_process';
7
- import { promisify } from 'util';
8
8
  import { join } from 'path';
9
9
  import { format } from 'prettier';
10
10
  import parserHtml from 'prettier/parser-html';
11
- import { forTime } from 'waitasecond';
12
11
  import { unparse, parse } from 'papaparse';
13
12
  import { SHA256 } from 'crypto-js';
14
13
  import hexEncoder from 'crypto-js/enc-hex';
@@ -28,7 +27,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
28
27
  * @generated
29
28
  * @see https://github.com/webgptorg/promptbook
30
29
  */
31
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-9';
32
31
  /**
33
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -186,7 +185,7 @@ var NAME = "Promptbook";
186
185
  *
187
186
  * @public exported from `@promptbook/core`
188
187
  */
189
- var ADMIN_EMAIL = 'me@pavolhejny.com';
188
+ var ADMIN_EMAIL = 'pavol@ptbk.io';
190
189
  /**
191
190
  * Name of the responsible person for the Promptbook on GitHub
192
191
  *
@@ -297,311 +296,6 @@ true);
297
296
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
298
297
  */
299
298
 
300
- /**
301
- * This error type indicates that you try to use a feature that is not available in the current environment
302
- *
303
- * @public exported from `@promptbook/core`
304
- */
305
- var EnvironmentMismatchError = /** @class */ (function (_super) {
306
- __extends(EnvironmentMismatchError, _super);
307
- function EnvironmentMismatchError(message) {
308
- var _this = _super.call(this, message) || this;
309
- _this.name = 'EnvironmentMismatchError';
310
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
311
- return _this;
312
- }
313
- return EnvironmentMismatchError;
314
- }(Error));
315
-
316
- /**
317
- * Detects if the code is running in a Node.js environment
318
- *
319
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
320
- *
321
- * @public exported from `@promptbook/utils`
322
- */
323
- var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
324
-
325
- /**
326
- * @@@
327
- *
328
- * @public exported from `@promptbook/node`
329
- */
330
- function $provideFilesystemForNode(options) {
331
- if (!$isRunningInNode()) {
332
- throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
333
- }
334
- (options || {}).isVerbose;
335
- return {
336
- stat: stat,
337
- access: access,
338
- constants: constants,
339
- readFile: readFile,
340
- writeFile: writeFile,
341
- readdir: readdir,
342
- };
343
- }
344
- /**
345
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
346
- */
347
-
348
- /**
349
- * This error type indicates that some part of the code is not implemented yet
350
- *
351
- * @public exported from `@promptbook/core`
352
- */
353
- var NotYetImplementedError = /** @class */ (function (_super) {
354
- __extends(NotYetImplementedError, _super);
355
- function NotYetImplementedError(message) {
356
- var _this = _super.call(this, 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;
357
- _this.name = 'NotYetImplementedError';
358
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
359
- return _this;
360
- }
361
- return NotYetImplementedError;
362
- }(Error));
363
-
364
- /**
365
- * Make error report URL for the given error
366
- *
367
- * @private private within the repository
368
- */
369
- function getErrorReportUrl(error) {
370
- var report = {
371
- title: "\uD83D\uDC1C Error report from ".concat(NAME),
372
- body: spaceTrim$1(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 "); }),
373
- };
374
- var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
375
- reportUrl.searchParams.set('labels', 'bug');
376
- reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
377
- reportUrl.searchParams.set('title', report.title);
378
- reportUrl.searchParams.set('body', report.body);
379
- return reportUrl;
380
- }
381
-
382
- /**
383
- * This error type indicates that the error should not happen and its last check before crashing with some other error
384
- *
385
- * @public exported from `@promptbook/core`
386
- */
387
- var UnexpectedError = /** @class */ (function (_super) {
388
- __extends(UnexpectedError, _super);
389
- function UnexpectedError(message) {
390
- var _this = _super.call(this, 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;
391
- _this.name = 'UnexpectedError';
392
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
393
- return _this;
394
- }
395
- return UnexpectedError;
396
- }(Error));
397
-
398
- /**
399
- * @@@
400
- *
401
- * Note: `$` is used to indicate that this function is not a pure function - it access global scope
402
- *
403
- * @private internal function of `$Register`
404
- */
405
- function $getGlobalScope() {
406
- return Function('return this')();
407
- }
408
-
409
- /**
410
- * @@@
411
- *
412
- * @param text @@@
413
- * @returns @@@
414
- * @example 'HELLO_WORLD'
415
- * @example 'I_LOVE_PROMPTBOOK'
416
- * @public exported from `@promptbook/utils`
417
- */
418
- function normalizeTo_SCREAMING_CASE(text) {
419
- var e_1, _a;
420
- var charType;
421
- var lastCharType = 'OTHER';
422
- var normalizedName = '';
423
- try {
424
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
425
- var char = text_1_1.value;
426
- var normalizedChar = void 0;
427
- if (/^[a-z]$/.test(char)) {
428
- charType = 'LOWERCASE';
429
- normalizedChar = char.toUpperCase();
430
- }
431
- else if (/^[A-Z]$/.test(char)) {
432
- charType = 'UPPERCASE';
433
- normalizedChar = char;
434
- }
435
- else if (/^[0-9]$/.test(char)) {
436
- charType = 'NUMBER';
437
- normalizedChar = char;
438
- }
439
- else {
440
- charType = 'OTHER';
441
- normalizedChar = '_';
442
- }
443
- if (charType !== lastCharType &&
444
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
445
- !(lastCharType === 'NUMBER') &&
446
- !(charType === 'NUMBER')) {
447
- normalizedName += '_';
448
- }
449
- normalizedName += normalizedChar;
450
- lastCharType = charType;
451
- }
452
- }
453
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
454
- finally {
455
- try {
456
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
457
- }
458
- finally { if (e_1) throw e_1.error; }
459
- }
460
- normalizedName = normalizedName.replace(/_+/g, '_');
461
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
462
- normalizedName = normalizedName.replace(/^_/, '');
463
- normalizedName = normalizedName.replace(/_$/, '');
464
- return normalizedName;
465
- }
466
- /**
467
- * TODO: Tests
468
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
469
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
470
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
471
- * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
472
- * TODO: [🌺] Use some intermediate util splitWords
473
- */
474
-
475
- /**
476
- * @@@
477
- *
478
- * @param text @@@
479
- * @returns @@@
480
- * @example 'hello_world'
481
- * @example 'i_love_promptbook'
482
- * @public exported from `@promptbook/utils`
483
- */
484
- function normalizeTo_snake_case(text) {
485
- return normalizeTo_SCREAMING_CASE(text).toLowerCase();
486
- }
487
-
488
- /**
489
- * Register is @@@
490
- *
491
- * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
492
- *
493
- * @private internal utility, exported are only signleton instances of this class
494
- */
495
- var $Register = /** @class */ (function () {
496
- function $Register(registerName) {
497
- this.registerName = registerName;
498
- var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
499
- var globalScope = $getGlobalScope();
500
- if (globalScope[storageName] === undefined) {
501
- globalScope[storageName] = [];
502
- }
503
- else if (!Array.isArray(globalScope[storageName])) {
504
- throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
505
- }
506
- this.storage = globalScope[storageName];
507
- }
508
- $Register.prototype.list = function () {
509
- // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
510
- return this.storage;
511
- };
512
- $Register.prototype.register = function (registered) {
513
- var packageName = registered.packageName, className = registered.className;
514
- var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
515
- var existingRegistration = this.storage[existingRegistrationIndex];
516
- if (!existingRegistration) {
517
- this.storage.push(registered);
518
- }
519
- else {
520
- this.storage[existingRegistrationIndex] = registered;
521
- }
522
- return {
523
- registerName: this.registerName,
524
- packageName: packageName,
525
- className: className,
526
- get isDestroyed() {
527
- return false;
528
- },
529
- destroy: function () {
530
- throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
531
- },
532
- };
533
- };
534
- return $Register;
535
- }());
536
-
537
- /**
538
- * @@@
539
- *
540
- * Note: `$` is used to indicate that this interacts with the global scope
541
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
542
- * @public exported from `@promptbook/core`
543
- */
544
- var $scrapersRegister = new $Register('scraper_constructors');
545
- /**
546
- * TODO: [®] DRY Register logic
547
- */
548
-
549
- /**
550
- * @@@
551
- *
552
- * 1) @@@
553
- * 2) @@@
554
- *
555
- * @public exported from `@promptbook/node`
556
- */
557
- function $provideScrapersForNode(tools, options) {
558
- return __awaiter(this, void 0, void 0, function () {
559
- var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
560
- var e_1, _f;
561
- return __generator(this, function (_g) {
562
- switch (_g.label) {
563
- case 0:
564
- if (!$isRunningInNode()) {
565
- throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
566
- }
567
- _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
568
- scrapers = [];
569
- _g.label = 1;
570
- case 1:
571
- _g.trys.push([1, 6, 7, 8]);
572
- _d = __values($scrapersRegister.list()), _e = _d.next();
573
- _g.label = 2;
574
- case 2:
575
- if (!!_e.done) return [3 /*break*/, 5];
576
- scraperFactory = _e.value;
577
- return [4 /*yield*/, scraperFactory(tools, options || {})];
578
- case 3:
579
- scraper = _g.sent();
580
- scrapers.push(scraper);
581
- _g.label = 4;
582
- case 4:
583
- _e = _d.next();
584
- return [3 /*break*/, 2];
585
- case 5: return [3 /*break*/, 8];
586
- case 6:
587
- e_1_1 = _g.sent();
588
- e_1 = { error: e_1_1 };
589
- return [3 /*break*/, 8];
590
- case 7:
591
- try {
592
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
593
- }
594
- finally { if (e_1) throw e_1.error; }
595
- return [7 /*endfinally*/];
596
- case 8: return [2 /*return*/, scrapers];
597
- }
598
- });
599
- });
600
- }
601
- /**
602
- * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
603
- */
604
-
605
299
  /**
606
300
  * This error indicates errors during the execution of the pipeline
607
301
  *
@@ -670,6 +364,22 @@ var CollectionError = /** @class */ (function (_super) {
670
364
  return CollectionError;
671
365
  }(Error));
672
366
 
367
+ /**
368
+ * This error type indicates that you try to use a feature that is not available in the current environment
369
+ *
370
+ * @public exported from `@promptbook/core`
371
+ */
372
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
373
+ __extends(EnvironmentMismatchError, _super);
374
+ function EnvironmentMismatchError(message) {
375
+ var _this = _super.call(this, message) || this;
376
+ _this.name = 'EnvironmentMismatchError';
377
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
378
+ return _this;
379
+ }
380
+ return EnvironmentMismatchError;
381
+ }(Error));
382
+
673
383
  /**
674
384
  * This error occurs when some expectation is not met in the execution of the pipeline
675
385
  *
@@ -753,6 +463,22 @@ var NotFoundError = /** @class */ (function (_super) {
753
463
  return NotFoundError;
754
464
  }(Error));
755
465
 
466
+ /**
467
+ * This error type indicates that some part of the code is not implemented yet
468
+ *
469
+ * @public exported from `@promptbook/core`
470
+ */
471
+ var NotYetImplementedError = /** @class */ (function (_super) {
472
+ __extends(NotYetImplementedError, _super);
473
+ function NotYetImplementedError(message) {
474
+ var _this = _super.call(this, 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;
475
+ _this.name = 'NotYetImplementedError';
476
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
477
+ return _this;
478
+ }
479
+ return NotYetImplementedError;
480
+ }(Error));
481
+
756
482
  /**
757
483
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
758
484
  *
@@ -804,6 +530,40 @@ var PipelineUrlError = /** @class */ (function (_super) {
804
530
  return PipelineUrlError;
805
531
  }(Error));
806
532
 
533
+ /**
534
+ * Make error report URL for the given error
535
+ *
536
+ * @private private within the repository
537
+ */
538
+ function getErrorReportUrl(error) {
539
+ var report = {
540
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
541
+ body: spaceTrim$1(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 "); }),
542
+ };
543
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
544
+ reportUrl.searchParams.set('labels', 'bug');
545
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
546
+ reportUrl.searchParams.set('title', report.title);
547
+ reportUrl.searchParams.set('body', report.body);
548
+ return reportUrl;
549
+ }
550
+
551
+ /**
552
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
553
+ *
554
+ * @public exported from `@promptbook/core`
555
+ */
556
+ var UnexpectedError = /** @class */ (function (_super) {
557
+ __extends(UnexpectedError, _super);
558
+ function UnexpectedError(message) {
559
+ var _this = _super.call(this, 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;
560
+ _this.name = 'UnexpectedError';
561
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
562
+ return _this;
563
+ }
564
+ return UnexpectedError;
565
+ }(Error));
566
+
807
567
  /**
808
568
  * Index of all custom errors
809
569
  *
@@ -877,30 +637,196 @@ function serializeError(error) {
877
637
  };
878
638
  }
879
639
 
880
- // Note: We want to use the `exec` as async function
881
- var exec$1 = promisify(exec$2);
640
+ /**
641
+ * Detects if the code is running in a Node.js environment
642
+ *
643
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
644
+ *
645
+ * @public exported from `@promptbook/utils`
646
+ */
647
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
648
+
649
+ /**
650
+ * Normalize options for `execCommand` and `execCommands`
651
+ *
652
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
653
+ *
654
+ * @private internal utility of `execCommand` and `execCommands`
655
+ */
656
+ function $execCommandNormalizeOptions(options) {
657
+ var _a;
658
+ var _b, _c, _d, _e;
659
+ var command;
660
+ var cwd;
661
+ var crashOnError;
662
+ var args = [];
663
+ var timeout;
664
+ var isVerbose;
665
+ if (typeof options === 'string') {
666
+ // TODO: [1] DRY default values
667
+ command = options;
668
+ cwd = process.cwd();
669
+ crashOnError = true;
670
+ timeout = Infinity; // <- TODO: [⏳]
671
+ isVerbose = DEFAULT_IS_VERBOSE;
672
+ }
673
+ else {
674
+ /*
675
+ TODO:
676
+ if ((options as any).commands !== undefined) {
677
+ commands = (options as any).commands;
678
+ } else {
679
+ commands = [(options as any).command];
680
+ }
681
+ */
682
+ // TODO: [1] DRY default values
683
+ command = options.command;
684
+ cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
685
+ crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
686
+ timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
687
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
688
+ }
689
+ // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
690
+ var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
691
+ .map(function (_a) {
692
+ var _b = __read(_a, 1), match = _b[0];
693
+ return match;
694
+ })
695
+ .filter(function (arg) { return arg !== ''; });
696
+ if (_.length > 1) {
697
+ _a = __read(_), command = _a[0], args = _a.slice(1);
698
+ }
699
+ if (options.args) {
700
+ args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
701
+ }
702
+ var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
703
+ if (['ts-node'].includes(humanReadableCommand)) {
704
+ humanReadableCommand += " ".concat(args[1]);
705
+ }
706
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
707
+ command = "".concat(command, ".cmd");
708
+ }
709
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
710
+ }
711
+ // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
712
+
713
+ /**
714
+ * Run one command in a shell
715
+ *
716
+ *
717
+ * Note: There are 2 similar functions in the codebase:
718
+ * - `$execCommand` which runs a single command
719
+ * - `$execCommands` which runs multiple commands
720
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
721
+ *
722
+ * @public exported from `@promptbook/node`
723
+ */
724
+ function $execCommand(options) {
725
+ if (!$isRunningInNode()) {
726
+ throw new EnvironmentMismatchError('Function `$execCommand` can run only in Node environment.js');
727
+ }
728
+ return new Promise(function (resolve, reject) {
729
+ // eslint-disable-next-line prefer-const
730
+ 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;
731
+ if (timeout !== Infinity) {
732
+ // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
733
+ forTime(timeout).then(function () {
734
+ if (crashOnError) {
735
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms")));
736
+ }
737
+ else {
738
+ console.warn("Command \"".concat(humanReadableCommand, "\" exceeded time limit of ").concat(timeout, "ms but continues running"));
739
+ resolve('Command exceeded time limit');
740
+ }
741
+ });
742
+ }
743
+ if (isVerbose) {
744
+ console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
745
+ }
746
+ try {
747
+ var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
748
+ if (isVerbose) {
749
+ commandProcess.on('message', function (message) {
750
+ console.info({ message: message });
751
+ });
752
+ }
753
+ var output_1 = [];
754
+ commandProcess.stdout.on('data', function (stdout) {
755
+ output_1.push(stdout.toString());
756
+ if (isVerbose) {
757
+ console.info(stdout.toString());
758
+ }
759
+ });
760
+ commandProcess.stderr.on('data', function (stderr) {
761
+ output_1.push(stderr.toString());
762
+ if (isVerbose && stderr.toString().trim()) {
763
+ console.warn(stderr.toString());
764
+ }
765
+ });
766
+ var finishWithCode = function (code) {
767
+ if (code !== 0) {
768
+ if (crashOnError) {
769
+ reject(new Error(output_1.join('\n').trim() ||
770
+ "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
771
+ }
772
+ else {
773
+ if (isVerbose) {
774
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
775
+ }
776
+ resolve(spaceTrim(output_1.join('\n')));
777
+ }
778
+ }
779
+ else {
780
+ resolve(spaceTrim(output_1.join('\n')));
781
+ }
782
+ };
783
+ commandProcess.on('close', finishWithCode);
784
+ commandProcess.on('exit', finishWithCode);
785
+ commandProcess.on('disconnect', function () {
786
+ // Note: Unexpected disconnection should always result in rejection
787
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" disconnected")));
788
+ });
789
+ commandProcess.on('error', function (error) {
790
+ if (crashOnError) {
791
+ reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
792
+ }
793
+ else {
794
+ if (isVerbose) {
795
+ console.warn(error);
796
+ }
797
+ resolve(spaceTrim(output_1.join('\n')));
798
+ }
799
+ });
800
+ }
801
+ catch (error) {
802
+ // Note: Unexpected error in sync code should always result in rejection
803
+ reject(error);
804
+ }
805
+ });
806
+ }
807
+ /**
808
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
809
+ */
810
+
882
811
  /**
883
812
  * @@@
884
813
  *
885
814
  * @private within the repository
886
815
  */
887
816
  function locateAppOnLinux(_a) {
888
- var appName = _a.appName, linuxWhich = _a.linuxWhich;
817
+ var linuxWhich = _a.linuxWhich;
889
818
  return __awaiter(this, void 0, void 0, function () {
890
- var _b, stderr, stdout, error_1;
891
- return __generator(this, function (_c) {
892
- switch (_c.label) {
819
+ var result, error_1;
820
+ return __generator(this, function (_b) {
821
+ switch (_b.label) {
893
822
  case 0:
894
- _c.trys.push([0, 2, , 3]);
895
- return [4 /*yield*/, exec$1("which ".concat(linuxWhich))];
823
+ _b.trys.push([0, 2, , 3]);
824
+ return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
896
825
  case 1:
897
- _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
898
- if (!stderr && stdout) {
899
- return [2 /*return*/, stdout.trim()];
900
- }
901
- throw new Error("Can not locate app ".concat(appName, " on Linux.\n ").concat(stderr));
826
+ result = _b.sent();
827
+ return [2 /*return*/, result.trim()];
902
828
  case 2:
903
- error_1 = _c.sent();
829
+ error_1 = _b.sent();
904
830
  if (!(error_1 instanceof Error)) {
905
831
  throw error_1;
906
832
  }
@@ -915,6 +841,29 @@ function locateAppOnLinux(_a) {
915
841
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
916
842
  */
917
843
 
844
+ /**
845
+ * @@@
846
+ *
847
+ * @public exported from `@promptbook/node`
848
+ */
849
+ function $provideFilesystemForNode(options) {
850
+ if (!$isRunningInNode()) {
851
+ throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
852
+ }
853
+ (options || {}).isVerbose;
854
+ return {
855
+ stat: stat,
856
+ access: access,
857
+ constants: constants,
858
+ readFile: readFile,
859
+ writeFile: writeFile,
860
+ readdir: readdir,
861
+ };
862
+ }
863
+ /**
864
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
865
+ */
866
+
918
867
  /**
919
868
  * Checks if the file is executable
920
869
  *
@@ -947,43 +896,41 @@ function isExecutable(path, fs) {
947
896
  // @see https://stackoverflow.com/questions/37000981/how-to-import-node-module-in-typescript-without-type-definitions
948
897
  // eslint-disable-next-line @typescript-eslint/no-var-requires
949
898
  var userhome = require('userhome');
950
- // Note: We want to use the `exec` as async function
951
- var exec = promisify(exec$2);
952
899
  /**
953
900
  * @@@
954
901
  *
955
902
  * @private within the repository
956
903
  */
957
904
  function locateAppOnMacOs(_a) {
958
- var appName = _a.appName, macOsName = _a.macOsName;
905
+ var macOsName = _a.macOsName;
959
906
  return __awaiter(this, void 0, void 0, function () {
960
- var toExec, regPath, altPath, _b, stderr, stdout, error_1;
961
- return __generator(this, function (_c) {
962
- switch (_c.label) {
907
+ var toExec, regPath, altPath, result, error_1;
908
+ return __generator(this, function (_b) {
909
+ switch (_b.label) {
963
910
  case 0:
964
- _c.trys.push([0, 6, , 7]);
911
+ _b.trys.push([0, 6, , 7]);
965
912
  toExec = "/Contents/MacOS/".concat(macOsName);
966
913
  regPath = "/Applications/".concat(macOsName, ".app") + toExec;
967
914
  altPath = userhome(regPath.slice(1));
968
915
  return [4 /*yield*/, isExecutable(regPath, $provideFilesystemForNode())];
969
916
  case 1:
970
- if (!_c.sent()) return [3 /*break*/, 2];
917
+ if (!_b.sent()) return [3 /*break*/, 2];
971
918
  return [2 /*return*/, regPath];
972
919
  case 2: return [4 /*yield*/, isExecutable(altPath, $provideFilesystemForNode())];
973
920
  case 3:
974
- if (_c.sent()) {
921
+ if (_b.sent()) {
975
922
  return [2 /*return*/, altPath];
976
923
  }
977
- _c.label = 4;
978
- case 4: return [4 /*yield*/, exec("mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"))];
924
+ _b.label = 4;
925
+ case 4: return [4 /*yield*/, $execCommand({
926
+ crashOnError: true,
927
+ command: "mdfind 'kMDItemDisplayName == \"".concat(macOsName, "\" && kMDItemKind == Application'"),
928
+ })];
979
929
  case 5:
980
- _b = _c.sent(), stderr = _b.stderr, stdout = _b.stdout;
981
- if (!stderr && stdout) {
982
- return [2 /*return*/, stdout.trim() + toExec];
983
- }
984
- throw new Error("Can not locate app ".concat(appName, " on macOS.\n ").concat(stderr));
930
+ result = _b.sent();
931
+ return [2 /*return*/, result.trim() + toExec];
985
932
  case 6:
986
- error_1 = _c.sent();
933
+ error_1 = _b.sent();
987
934
  if (!(error_1 instanceof Error)) {
988
935
  throw error_1;
989
936
  }
@@ -1084,7 +1031,7 @@ function locateApp(options) {
1084
1031
  }
1085
1032
  else if (process.platform === 'darwin') {
1086
1033
  if (macOsName) {
1087
- return locateAppOnMacOs({ appName: appName, macOsName: macOsName });
1034
+ return locateAppOnMacOs({ macOsName: macOsName });
1088
1035
  }
1089
1036
  else {
1090
1037
  throw new Error("".concat(appName, " is not available on macOS."));
@@ -1092,7 +1039,7 @@ function locateApp(options) {
1092
1039
  }
1093
1040
  else {
1094
1041
  if (linuxWhich) {
1095
- return locateAppOnLinux({ appName: appName, linuxWhich: linuxWhich });
1042
+ return locateAppOnLinux({ linuxWhich: linuxWhich });
1096
1043
  }
1097
1044
  else {
1098
1045
  throw new Error("".concat(appName, " is not available on Linux."));
@@ -1464,6 +1411,145 @@ function joinLlmExecutionTools() {
1464
1411
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1465
1412
  */
1466
1413
 
1414
+ /**
1415
+ * @@@
1416
+ *
1417
+ * Note: `$` is used to indicate that this function is not a pure function - it access global scope
1418
+ *
1419
+ * @private internal function of `$Register`
1420
+ */
1421
+ function $getGlobalScope() {
1422
+ return Function('return this')();
1423
+ }
1424
+
1425
+ /**
1426
+ * @@@
1427
+ *
1428
+ * @param text @@@
1429
+ * @returns @@@
1430
+ * @example 'HELLO_WORLD'
1431
+ * @example 'I_LOVE_PROMPTBOOK'
1432
+ * @public exported from `@promptbook/utils`
1433
+ */
1434
+ function normalizeTo_SCREAMING_CASE(text) {
1435
+ var e_1, _a;
1436
+ var charType;
1437
+ var lastCharType = 'OTHER';
1438
+ var normalizedName = '';
1439
+ try {
1440
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
1441
+ var char = text_1_1.value;
1442
+ var normalizedChar = void 0;
1443
+ if (/^[a-z]$/.test(char)) {
1444
+ charType = 'LOWERCASE';
1445
+ normalizedChar = char.toUpperCase();
1446
+ }
1447
+ else if (/^[A-Z]$/.test(char)) {
1448
+ charType = 'UPPERCASE';
1449
+ normalizedChar = char;
1450
+ }
1451
+ else if (/^[0-9]$/.test(char)) {
1452
+ charType = 'NUMBER';
1453
+ normalizedChar = char;
1454
+ }
1455
+ else {
1456
+ charType = 'OTHER';
1457
+ normalizedChar = '_';
1458
+ }
1459
+ if (charType !== lastCharType &&
1460
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1461
+ !(lastCharType === 'NUMBER') &&
1462
+ !(charType === 'NUMBER')) {
1463
+ normalizedName += '_';
1464
+ }
1465
+ normalizedName += normalizedChar;
1466
+ lastCharType = charType;
1467
+ }
1468
+ }
1469
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1470
+ finally {
1471
+ try {
1472
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1473
+ }
1474
+ finally { if (e_1) throw e_1.error; }
1475
+ }
1476
+ normalizedName = normalizedName.replace(/_+/g, '_');
1477
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1478
+ normalizedName = normalizedName.replace(/^_/, '');
1479
+ normalizedName = normalizedName.replace(/_$/, '');
1480
+ return normalizedName;
1481
+ }
1482
+ /**
1483
+ * TODO: Tests
1484
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1485
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1486
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1487
+ * > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1488
+ * TODO: [🌺] Use some intermediate util splitWords
1489
+ */
1490
+
1491
+ /**
1492
+ * @@@
1493
+ *
1494
+ * @param text @@@
1495
+ * @returns @@@
1496
+ * @example 'hello_world'
1497
+ * @example 'i_love_promptbook'
1498
+ * @public exported from `@promptbook/utils`
1499
+ */
1500
+ function normalizeTo_snake_case(text) {
1501
+ return normalizeTo_SCREAMING_CASE(text).toLowerCase();
1502
+ }
1503
+
1504
+ /**
1505
+ * Register is @@@
1506
+ *
1507
+ * Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
1508
+ *
1509
+ * @private internal utility, exported are only signleton instances of this class
1510
+ */
1511
+ var $Register = /** @class */ (function () {
1512
+ function $Register(registerName) {
1513
+ this.registerName = registerName;
1514
+ var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
1515
+ var globalScope = $getGlobalScope();
1516
+ if (globalScope[storageName] === undefined) {
1517
+ globalScope[storageName] = [];
1518
+ }
1519
+ else if (!Array.isArray(globalScope[storageName])) {
1520
+ throw new UnexpectedError("Expected (global) ".concat(storageName, " to be an array, but got ").concat(typeof globalScope[storageName]));
1521
+ }
1522
+ this.storage = globalScope[storageName];
1523
+ }
1524
+ $Register.prototype.list = function () {
1525
+ // <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
1526
+ return this.storage;
1527
+ };
1528
+ $Register.prototype.register = function (registered) {
1529
+ var packageName = registered.packageName, className = registered.className;
1530
+ var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
1531
+ var existingRegistration = this.storage[existingRegistrationIndex];
1532
+ if (!existingRegistration) {
1533
+ this.storage.push(registered);
1534
+ }
1535
+ else {
1536
+ this.storage[existingRegistrationIndex] = registered;
1537
+ }
1538
+ return {
1539
+ registerName: this.registerName,
1540
+ packageName: packageName,
1541
+ className: className,
1542
+ get isDestroyed() {
1543
+ return false;
1544
+ },
1545
+ destroy: function () {
1546
+ throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
1547
+ },
1548
+ };
1549
+ };
1550
+ return $Register;
1551
+ }());
1552
+
1467
1553
  /**
1468
1554
  * @@@
1469
1555
  *
@@ -2218,7 +2304,7 @@ var ORDER_OF_PIPELINE_JSON = [
2218
2304
  *
2219
2305
  * @private within the repository
2220
2306
  */
2221
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
2307
+ var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
2222
2308
  /**
2223
2309
  * @@@
2224
2310
  *
@@ -5675,6 +5761,18 @@ var $scrapersMetadataRegister = new $Register('scrapers_metadata');
5675
5761
  * TODO: [®] DRY Register logic
5676
5762
  */
5677
5763
 
5764
+ /**
5765
+ * @@@
5766
+ *
5767
+ * Note: `$` is used to indicate that this interacts with the global scope
5768
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
5769
+ * @public exported from `@promptbook/core`
5770
+ */
5771
+ var $scrapersRegister = new $Register('scraper_constructors');
5772
+ /**
5773
+ * TODO: [®] DRY Register logic
5774
+ */
5775
+
5678
5776
  /**
5679
5777
  * Creates a message with all registered scrapers
5680
5778
  *
@@ -6474,6 +6572,62 @@ function preparePipeline(pipeline, tools, options) {
6474
6572
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
6475
6573
  */
6476
6574
 
6575
+ /**
6576
+ * @@@
6577
+ *
6578
+ * 1) @@@
6579
+ * 2) @@@
6580
+ *
6581
+ * @public exported from `@promptbook/node`
6582
+ */
6583
+ function $provideScrapersForNode(tools, options) {
6584
+ return __awaiter(this, void 0, void 0, function () {
6585
+ var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
6586
+ var e_1, _f;
6587
+ return __generator(this, function (_g) {
6588
+ switch (_g.label) {
6589
+ case 0:
6590
+ if (!$isRunningInNode()) {
6591
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
6592
+ }
6593
+ _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
6594
+ scrapers = [];
6595
+ _g.label = 1;
6596
+ case 1:
6597
+ _g.trys.push([1, 6, 7, 8]);
6598
+ _d = __values($scrapersRegister.list()), _e = _d.next();
6599
+ _g.label = 2;
6600
+ case 2:
6601
+ if (!!_e.done) return [3 /*break*/, 5];
6602
+ scraperFactory = _e.value;
6603
+ return [4 /*yield*/, scraperFactory(tools, options || {})];
6604
+ case 3:
6605
+ scraper = _g.sent();
6606
+ scrapers.push(scraper);
6607
+ _g.label = 4;
6608
+ case 4:
6609
+ _e = _d.next();
6610
+ return [3 /*break*/, 2];
6611
+ case 5: return [3 /*break*/, 8];
6612
+ case 6:
6613
+ e_1_1 = _g.sent();
6614
+ e_1 = { error: e_1_1 };
6615
+ return [3 /*break*/, 8];
6616
+ case 7:
6617
+ try {
6618
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
6619
+ }
6620
+ finally { if (e_1) throw e_1.error; }
6621
+ return [7 /*endfinally*/];
6622
+ case 8: return [2 /*return*/, scrapers];
6623
+ }
6624
+ });
6625
+ });
6626
+ }
6627
+ /**
6628
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6629
+ */
6630
+
6477
6631
  /**
6478
6632
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
6479
6633
  *