@promptbook/remote-server 0.84.0-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 (29) hide show
  1. package/README.md +1 -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/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 +2 -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/pipeline/book-notation.d.ts +4 -0
  14. package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -0
  15. package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
  16. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
  17. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
  18. package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
  19. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
  20. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
  21. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
  22. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
  23. package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
  24. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
  25. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
  26. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  27. package/package.json +3 -3
  28. package/umd/index.umd.js +500 -345
  29. 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-9';
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
  *
@@ -802,6 +529,40 @@
802
529
  return PipelineUrlError;
803
530
  }(Error));
804
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);
561
+ return _this;
562
+ }
563
+ return UnexpectedError;
564
+ }(Error));
565
+
805
566
  /**
806
567
  * Index of all custom errors
807
568
  *
@@ -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
  *
@@ -2216,7 +2303,7 @@
2216
2303
  *
2217
2304
  * @private within the repository
2218
2305
  */
2219
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
2306
+ var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
2220
2307
  /**
2221
2308
  * @@@
2222
2309
  *
@@ -5673,6 +5760,18 @@
5673
5760
  * TODO: [®] DRY Register logic
5674
5761
  */
5675
5762
 
5763
+ /**
5764
+ * @@@
5765
+ *
5766
+ * Note: `$` is used to indicate that this interacts with the global scope
5767
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
5768
+ * @public exported from `@promptbook/core`
5769
+ */
5770
+ var $scrapersRegister = new $Register('scraper_constructors');
5771
+ /**
5772
+ * TODO: [®] DRY Register logic
5773
+ */
5774
+
5676
5775
  /**
5677
5776
  * Creates a message with all registered scrapers
5678
5777
  *
@@ -6472,6 +6571,62 @@
6472
6571
  * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
6473
6572
  */
6474
6573
 
6574
+ /**
6575
+ * @@@
6576
+ *
6577
+ * 1) @@@
6578
+ * 2) @@@
6579
+ *
6580
+ * @public exported from `@promptbook/node`
6581
+ */
6582
+ function $provideScrapersForNode(tools, options) {
6583
+ return __awaiter(this, void 0, void 0, function () {
6584
+ var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
6585
+ var e_1, _f;
6586
+ return __generator(this, function (_g) {
6587
+ switch (_g.label) {
6588
+ case 0:
6589
+ if (!$isRunningInNode()) {
6590
+ throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
6591
+ }
6592
+ _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
6593
+ scrapers = [];
6594
+ _g.label = 1;
6595
+ case 1:
6596
+ _g.trys.push([1, 6, 7, 8]);
6597
+ _d = __values($scrapersRegister.list()), _e = _d.next();
6598
+ _g.label = 2;
6599
+ case 2:
6600
+ if (!!_e.done) return [3 /*break*/, 5];
6601
+ scraperFactory = _e.value;
6602
+ return [4 /*yield*/, scraperFactory(tools, options || {})];
6603
+ case 3:
6604
+ scraper = _g.sent();
6605
+ scrapers.push(scraper);
6606
+ _g.label = 4;
6607
+ case 4:
6608
+ _e = _d.next();
6609
+ return [3 /*break*/, 2];
6610
+ case 5: return [3 /*break*/, 8];
6611
+ case 6:
6612
+ e_1_1 = _g.sent();
6613
+ e_1 = { error: e_1_1 };
6614
+ return [3 /*break*/, 8];
6615
+ case 7:
6616
+ try {
6617
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
6618
+ }
6619
+ finally { if (e_1) throw e_1.error; }
6620
+ return [7 /*endfinally*/];
6621
+ case 8: return [2 /*return*/, scrapers];
6622
+ }
6623
+ });
6624
+ });
6625
+ }
6626
+ /**
6627
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6628
+ */
6629
+
6475
6630
  /**
6476
6631
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
6477
6632
  *