@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.
- package/README.md +1 -0
- package/esm/index.es.js +624 -430
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +8 -0
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
- package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
- package/esm/typings/src/constants.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +5 -0
- package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
- package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/package.json +3 -3
- package/umd/index.umd.js +626 -431
- package/umd/index.umd.js.map +1 -1
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.
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
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 = '
|
|
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
|
*
|
|
@@ -793,15 +519,49 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
793
519
|
*
|
|
794
520
|
* @public exported from `@promptbook/core`
|
|
795
521
|
*/
|
|
796
|
-
var PipelineUrlError = /** @class */ (function (_super) {
|
|
797
|
-
__extends(PipelineUrlError, _super);
|
|
798
|
-
function PipelineUrlError(message) {
|
|
799
|
-
var _this = _super.call(this, message) || this;
|
|
800
|
-
_this.name = 'PipelineUrlError';
|
|
801
|
-
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
522
|
+
var PipelineUrlError = /** @class */ (function (_super) {
|
|
523
|
+
__extends(PipelineUrlError, _super);
|
|
524
|
+
function PipelineUrlError(message) {
|
|
525
|
+
var _this = _super.call(this, message) || this;
|
|
526
|
+
_this.name = 'PipelineUrlError';
|
|
527
|
+
Object.setPrototypeOf(_this, PipelineUrlError.prototype);
|
|
528
|
+
return _this;
|
|
529
|
+
}
|
|
530
|
+
return PipelineUrlError;
|
|
531
|
+
}(Error));
|
|
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);
|
|
802
562
|
return _this;
|
|
803
563
|
}
|
|
804
|
-
return
|
|
564
|
+
return UnexpectedError;
|
|
805
565
|
}(Error));
|
|
806
566
|
|
|
807
567
|
/**
|
|
@@ -877,30 +637,196 @@ function serializeError(error) {
|
|
|
877
637
|
};
|
|
878
638
|
}
|
|
879
639
|
|
|
880
|
-
|
|
881
|
-
|
|
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
|
|
817
|
+
var linuxWhich = _a.linuxWhich;
|
|
889
818
|
return __awaiter(this, void 0, void 0, function () {
|
|
890
|
-
var
|
|
891
|
-
return __generator(this, function (
|
|
892
|
-
switch (
|
|
819
|
+
var result, error_1;
|
|
820
|
+
return __generator(this, function (_b) {
|
|
821
|
+
switch (_b.label) {
|
|
893
822
|
case 0:
|
|
894
|
-
|
|
895
|
-
return [4 /*yield*/,
|
|
823
|
+
_b.trys.push([0, 2, , 3]);
|
|
824
|
+
return [4 /*yield*/, $execCommand({ crashOnError: true, command: "which ".concat(linuxWhich) })];
|
|
896
825
|
case 1:
|
|
897
|
-
|
|
898
|
-
|
|
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 =
|
|
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
|
|
905
|
+
var macOsName = _a.macOsName;
|
|
959
906
|
return __awaiter(this, void 0, void 0, function () {
|
|
960
|
-
var toExec, regPath, altPath,
|
|
961
|
-
return __generator(this, function (
|
|
962
|
-
switch (
|
|
907
|
+
var toExec, regPath, altPath, result, error_1;
|
|
908
|
+
return __generator(this, function (_b) {
|
|
909
|
+
switch (_b.label) {
|
|
963
910
|
case 0:
|
|
964
|
-
|
|
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 (!
|
|
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 (
|
|
921
|
+
if (_b.sent()) {
|
|
975
922
|
return [2 /*return*/, altPath];
|
|
976
923
|
}
|
|
977
|
-
|
|
978
|
-
case 4: return [4 /*yield*/,
|
|
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
|
-
|
|
981
|
-
|
|
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 =
|
|
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({
|
|
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({
|
|
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
|
*
|
|
@@ -1671,6 +1757,99 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
1671
1757
|
|
|
1672
1758
|
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"}];
|
|
1673
1759
|
|
|
1760
|
+
/**
|
|
1761
|
+
* Checks if value is valid email
|
|
1762
|
+
*
|
|
1763
|
+
* @public exported from `@promptbook/utils`
|
|
1764
|
+
*/
|
|
1765
|
+
function isValidEmail(email) {
|
|
1766
|
+
if (typeof email !== 'string') {
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1769
|
+
if (email.split('\n').length > 1) {
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1772
|
+
return /^.+@.+\..+$/.test(email);
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* Tests if given string is valid URL.
|
|
1777
|
+
*
|
|
1778
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
1779
|
+
* @public exported from `@promptbook/utils`
|
|
1780
|
+
*/
|
|
1781
|
+
function isValidFilePath(filename) {
|
|
1782
|
+
if (typeof filename !== 'string') {
|
|
1783
|
+
return false;
|
|
1784
|
+
}
|
|
1785
|
+
if (filename.split('\n').length > 1) {
|
|
1786
|
+
return false;
|
|
1787
|
+
}
|
|
1788
|
+
if (filename.split(' ').length >
|
|
1789
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
1790
|
+
return false;
|
|
1791
|
+
}
|
|
1792
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
1793
|
+
// Absolute Unix path: /hello.txt
|
|
1794
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1795
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
1796
|
+
return true;
|
|
1797
|
+
}
|
|
1798
|
+
// Absolute Windows path: /hello.txt
|
|
1799
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1800
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
1801
|
+
return true;
|
|
1802
|
+
}
|
|
1803
|
+
// Relative path: ./hello.txt
|
|
1804
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1805
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
1806
|
+
return true;
|
|
1807
|
+
}
|
|
1808
|
+
// Allow paths like foo/hello
|
|
1809
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
1810
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
1811
|
+
return true;
|
|
1812
|
+
}
|
|
1813
|
+
// Allow paths like hello.book
|
|
1814
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
1815
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
1816
|
+
return true;
|
|
1817
|
+
}
|
|
1818
|
+
return false;
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* TODO: [🍏] Implement for MacOs
|
|
1822
|
+
*/
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* Tests if given string is valid URL.
|
|
1826
|
+
*
|
|
1827
|
+
* Note: Dataurl are considered perfectly valid.
|
|
1828
|
+
* Note: There are two simmilar functions:
|
|
1829
|
+
* - `isValidUrl` which tests any URL
|
|
1830
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1831
|
+
*
|
|
1832
|
+
* @public exported from `@promptbook/utils`
|
|
1833
|
+
*/
|
|
1834
|
+
function isValidUrl(url) {
|
|
1835
|
+
if (typeof url !== 'string') {
|
|
1836
|
+
return false;
|
|
1837
|
+
}
|
|
1838
|
+
try {
|
|
1839
|
+
if (url.startsWith('blob:')) {
|
|
1840
|
+
url = url.replace(/^blob:/, '');
|
|
1841
|
+
}
|
|
1842
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
1843
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
return true;
|
|
1847
|
+
}
|
|
1848
|
+
catch (error) {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1674
1853
|
/**
|
|
1675
1854
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1676
1855
|
*
|
|
@@ -1705,6 +1884,15 @@ function validatePipelineString(pipelineString) {
|
|
|
1705
1884
|
if (isValidJsonString(pipelineString)) {
|
|
1706
1885
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
1707
1886
|
}
|
|
1887
|
+
else if (isValidUrl(pipelineString)) {
|
|
1888
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
1889
|
+
}
|
|
1890
|
+
else if (isValidFilePath(pipelineString)) {
|
|
1891
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
1892
|
+
}
|
|
1893
|
+
else if (isValidEmail(pipelineString)) {
|
|
1894
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
1895
|
+
}
|
|
1708
1896
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
1709
1897
|
return pipelineString;
|
|
1710
1898
|
}
|
|
@@ -2218,7 +2406,7 @@ var ORDER_OF_PIPELINE_JSON = [
|
|
|
2218
2406
|
*
|
|
2219
2407
|
* @private within the repository
|
|
2220
2408
|
*/
|
|
2221
|
-
var REPLACING_NONCE = '
|
|
2409
|
+
var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
2222
2410
|
/**
|
|
2223
2411
|
* @@@
|
|
2224
2412
|
*
|
|
@@ -2348,35 +2536,6 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
2348
2536
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
2349
2537
|
}
|
|
2350
2538
|
|
|
2351
|
-
/**
|
|
2352
|
-
* Tests if given string is valid URL.
|
|
2353
|
-
*
|
|
2354
|
-
* Note: Dataurl are considered perfectly valid.
|
|
2355
|
-
* Note: There are two simmilar functions:
|
|
2356
|
-
* - `isValidUrl` which tests any URL
|
|
2357
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
2358
|
-
*
|
|
2359
|
-
* @public exported from `@promptbook/utils`
|
|
2360
|
-
*/
|
|
2361
|
-
function isValidUrl(url) {
|
|
2362
|
-
if (typeof url !== 'string') {
|
|
2363
|
-
return false;
|
|
2364
|
-
}
|
|
2365
|
-
try {
|
|
2366
|
-
if (url.startsWith('blob:')) {
|
|
2367
|
-
url = url.replace(/^blob:/, '');
|
|
2368
|
-
}
|
|
2369
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
2370
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
2371
|
-
return false;
|
|
2372
|
-
}
|
|
2373
|
-
return true;
|
|
2374
|
-
}
|
|
2375
|
-
catch (error) {
|
|
2376
|
-
return false;
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
2539
|
/**
|
|
2381
2540
|
* Tests if given string is valid pipeline URL URL.
|
|
2382
2541
|
*
|
|
@@ -2876,12 +3035,28 @@ function deserializeError(error) {
|
|
|
2876
3035
|
/**
|
|
2877
3036
|
* Asserts that the execution of a Promptbook is successful
|
|
2878
3037
|
*
|
|
3038
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
3039
|
+
*
|
|
2879
3040
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2880
3041
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2881
3042
|
* @public exported from `@promptbook/core`
|
|
2882
3043
|
*/
|
|
2883
3044
|
function assertsExecutionSuccessful(executionResult) {
|
|
2884
|
-
var
|
|
3045
|
+
var e_1, _a;
|
|
3046
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
3047
|
+
try {
|
|
3048
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
3049
|
+
var warning = warnings_1_1.value;
|
|
3050
|
+
console.warn(warning.message);
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3054
|
+
finally {
|
|
3055
|
+
try {
|
|
3056
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
3057
|
+
}
|
|
3058
|
+
finally { if (e_1) throw e_1.error; }
|
|
3059
|
+
}
|
|
2885
3060
|
if (isSuccessful === true) {
|
|
2886
3061
|
return;
|
|
2887
3062
|
}
|
|
@@ -5675,6 +5850,18 @@ var $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
|
5675
5850
|
* TODO: [®] DRY Register logic
|
|
5676
5851
|
*/
|
|
5677
5852
|
|
|
5853
|
+
/**
|
|
5854
|
+
* @@@
|
|
5855
|
+
*
|
|
5856
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
5857
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
5858
|
+
* @public exported from `@promptbook/core`
|
|
5859
|
+
*/
|
|
5860
|
+
var $scrapersRegister = new $Register('scraper_constructors');
|
|
5861
|
+
/**
|
|
5862
|
+
* TODO: [®] DRY Register logic
|
|
5863
|
+
*/
|
|
5864
|
+
|
|
5678
5865
|
/**
|
|
5679
5866
|
* Creates a message with all registered scrapers
|
|
5680
5867
|
*
|
|
@@ -5933,55 +6120,6 @@ function isFileExisting(filename, fs) {
|
|
|
5933
6120
|
* TODO: [🖇] What about symlinks?
|
|
5934
6121
|
*/
|
|
5935
6122
|
|
|
5936
|
-
/**
|
|
5937
|
-
* Tests if given string is valid URL.
|
|
5938
|
-
*
|
|
5939
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
5940
|
-
* @public exported from `@promptbook/utils`
|
|
5941
|
-
*/
|
|
5942
|
-
function isValidFilePath(filename) {
|
|
5943
|
-
if (typeof filename !== 'string') {
|
|
5944
|
-
return false;
|
|
5945
|
-
}
|
|
5946
|
-
if (filename.split('\n').length > 1) {
|
|
5947
|
-
return false;
|
|
5948
|
-
}
|
|
5949
|
-
if (filename.split(' ').length >
|
|
5950
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
5951
|
-
return false;
|
|
5952
|
-
}
|
|
5953
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
5954
|
-
// Absolute Unix path: /hello.txt
|
|
5955
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5956
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
5957
|
-
return true;
|
|
5958
|
-
}
|
|
5959
|
-
// Absolute Windows path: /hello.txt
|
|
5960
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5961
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
5962
|
-
return true;
|
|
5963
|
-
}
|
|
5964
|
-
// Relative path: ./hello.txt
|
|
5965
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5966
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
5967
|
-
return true;
|
|
5968
|
-
}
|
|
5969
|
-
// Allow paths like foo/hello
|
|
5970
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
5971
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
5972
|
-
return true;
|
|
5973
|
-
}
|
|
5974
|
-
// Allow paths like hello.book
|
|
5975
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
5976
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
5977
|
-
return true;
|
|
5978
|
-
}
|
|
5979
|
-
return false;
|
|
5980
|
-
}
|
|
5981
|
-
/**
|
|
5982
|
-
* TODO: [🍏] Implement for MacOs
|
|
5983
|
-
*/
|
|
5984
|
-
|
|
5985
6123
|
/**
|
|
5986
6124
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5987
6125
|
*
|
|
@@ -6474,6 +6612,62 @@ function preparePipeline(pipeline, tools, options) {
|
|
|
6474
6612
|
* @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
|
|
6475
6613
|
*/
|
|
6476
6614
|
|
|
6615
|
+
/**
|
|
6616
|
+
* @@@
|
|
6617
|
+
*
|
|
6618
|
+
* 1) @@@
|
|
6619
|
+
* 2) @@@
|
|
6620
|
+
*
|
|
6621
|
+
* @public exported from `@promptbook/node`
|
|
6622
|
+
*/
|
|
6623
|
+
function $provideScrapersForNode(tools, options) {
|
|
6624
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6625
|
+
var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
|
|
6626
|
+
var e_1, _f;
|
|
6627
|
+
return __generator(this, function (_g) {
|
|
6628
|
+
switch (_g.label) {
|
|
6629
|
+
case 0:
|
|
6630
|
+
if (!$isRunningInNode()) {
|
|
6631
|
+
throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
|
|
6632
|
+
}
|
|
6633
|
+
_a = options || {}, _a.isAutoInstalled, _a.isVerbose;
|
|
6634
|
+
scrapers = [];
|
|
6635
|
+
_g.label = 1;
|
|
6636
|
+
case 1:
|
|
6637
|
+
_g.trys.push([1, 6, 7, 8]);
|
|
6638
|
+
_d = __values($scrapersRegister.list()), _e = _d.next();
|
|
6639
|
+
_g.label = 2;
|
|
6640
|
+
case 2:
|
|
6641
|
+
if (!!_e.done) return [3 /*break*/, 5];
|
|
6642
|
+
scraperFactory = _e.value;
|
|
6643
|
+
return [4 /*yield*/, scraperFactory(tools, options || {})];
|
|
6644
|
+
case 3:
|
|
6645
|
+
scraper = _g.sent();
|
|
6646
|
+
scrapers.push(scraper);
|
|
6647
|
+
_g.label = 4;
|
|
6648
|
+
case 4:
|
|
6649
|
+
_e = _d.next();
|
|
6650
|
+
return [3 /*break*/, 2];
|
|
6651
|
+
case 5: return [3 /*break*/, 8];
|
|
6652
|
+
case 6:
|
|
6653
|
+
e_1_1 = _g.sent();
|
|
6654
|
+
e_1 = { error: e_1_1 };
|
|
6655
|
+
return [3 /*break*/, 8];
|
|
6656
|
+
case 7:
|
|
6657
|
+
try {
|
|
6658
|
+
if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
|
|
6659
|
+
}
|
|
6660
|
+
finally { if (e_1) throw e_1.error; }
|
|
6661
|
+
return [7 /*endfinally*/];
|
|
6662
|
+
case 8: return [2 /*return*/, scrapers];
|
|
6663
|
+
}
|
|
6664
|
+
});
|
|
6665
|
+
});
|
|
6666
|
+
}
|
|
6667
|
+
/**
|
|
6668
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
6669
|
+
*/
|
|
6670
|
+
|
|
6477
6671
|
/**
|
|
6478
6672
|
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
6479
6673
|
*
|