@promptbook/cli 0.77.1 → 0.78.2
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/esm/index.es.js +509 -466
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +337 -294
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import commander from 'commander';
|
|
3
|
-
import spaceTrim
|
|
3
|
+
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
4
4
|
import { forTime } from 'waitasecond';
|
|
5
5
|
import { basename, join, dirname } from 'path';
|
|
6
6
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
|
|
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
37
37
|
*
|
|
38
38
|
* @see https://github.com/webgptorg/promptbook
|
|
39
39
|
*/
|
|
40
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
40
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
41
41
|
/**
|
|
42
42
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
43
43
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -183,204 +183,31 @@ function just(value) {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
189
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
190
|
-
*
|
|
191
|
-
* @returns The same object as the input, but deeply frozen
|
|
192
|
-
* @public exported from `@promptbook/utils`
|
|
193
|
-
*/
|
|
194
|
-
function $deepFreeze(objectValue) {
|
|
195
|
-
var e_1, _a;
|
|
196
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
197
|
-
try {
|
|
198
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
199
|
-
var propertyName = propertyNames_1_1.value;
|
|
200
|
-
var value = objectValue[propertyName];
|
|
201
|
-
if (value && typeof value === 'object') {
|
|
202
|
-
$deepFreeze(value);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
207
|
-
finally {
|
|
208
|
-
try {
|
|
209
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
210
|
-
}
|
|
211
|
-
finally { if (e_1) throw e_1.error; }
|
|
212
|
-
}
|
|
213
|
-
return Object.freeze(objectValue);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
217
|
-
*/
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
186
|
+
* Warning message for the generated sections and files files
|
|
221
187
|
*
|
|
222
|
-
* @
|
|
188
|
+
* @private within the repository
|
|
223
189
|
*/
|
|
224
|
-
var
|
|
225
|
-
__extends(UnexpectedError, _super);
|
|
226
|
-
function UnexpectedError(message) {
|
|
227
|
-
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 https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
228
|
-
_this.name = 'UnexpectedError';
|
|
229
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
230
|
-
return _this;
|
|
231
|
-
}
|
|
232
|
-
return UnexpectedError;
|
|
233
|
-
}(Error));
|
|
234
|
-
|
|
190
|
+
var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
|
|
235
191
|
/**
|
|
236
|
-
*
|
|
237
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
192
|
+
* Name for the Promptbook
|
|
238
193
|
*
|
|
239
|
-
*
|
|
240
|
-
* - `undefined` is not serializable
|
|
241
|
-
* - `NaN` is not serializable
|
|
242
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
243
|
-
* - Functions are not serializable
|
|
244
|
-
* - Circular references are not serializable
|
|
245
|
-
* - `Date` objects are not serializable
|
|
246
|
-
* - `Map` and `Set` objects are not serializable
|
|
247
|
-
* - `RegExp` objects are not serializable
|
|
248
|
-
* - `Error` objects are not serializable
|
|
249
|
-
* - `Symbol` objects are not serializable
|
|
250
|
-
* - And much more...
|
|
194
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
251
195
|
*
|
|
252
|
-
* @
|
|
253
|
-
* @public exported from `@promptbook/utils`
|
|
254
|
-
*/
|
|
255
|
-
function checkSerializableAsJson(name, value) {
|
|
256
|
-
var e_1, _a;
|
|
257
|
-
if (value === undefined) {
|
|
258
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
259
|
-
}
|
|
260
|
-
else if (value === null) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
else if (typeof value === 'boolean') {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
else if (typeof value === 'string') {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
else if (typeof value === 'symbol') {
|
|
273
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
274
|
-
}
|
|
275
|
-
else if (typeof value === 'function') {
|
|
276
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
277
|
-
}
|
|
278
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
279
|
-
for (var i = 0; i < value.length; i++) {
|
|
280
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else if (typeof value === 'object') {
|
|
284
|
-
if (value instanceof Date) {
|
|
285
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
286
|
-
}
|
|
287
|
-
else if (value instanceof Map) {
|
|
288
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
289
|
-
}
|
|
290
|
-
else if (value instanceof Set) {
|
|
291
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
292
|
-
}
|
|
293
|
-
else if (value instanceof RegExp) {
|
|
294
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
295
|
-
}
|
|
296
|
-
else if (value instanceof Error) {
|
|
297
|
-
throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
try {
|
|
301
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
302
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
303
|
-
if (subValue === undefined) {
|
|
304
|
-
// Note: undefined in object is serializable - it is just omited
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
311
|
-
finally {
|
|
312
|
-
try {
|
|
313
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
314
|
-
}
|
|
315
|
-
finally { if (e_1) throw e_1.error; }
|
|
316
|
-
}
|
|
317
|
-
try {
|
|
318
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
319
|
-
}
|
|
320
|
-
catch (error) {
|
|
321
|
-
if (!(error instanceof Error)) {
|
|
322
|
-
throw error;
|
|
323
|
-
}
|
|
324
|
-
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
325
|
-
}
|
|
326
|
-
/*
|
|
327
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
328
|
-
const seen = new Set();
|
|
329
|
-
const stack = [{ value }];
|
|
330
|
-
while (stack.length > 0) {
|
|
331
|
-
const { value } = stack.pop()!;
|
|
332
|
-
if (typeof value === 'object' && value !== null) {
|
|
333
|
-
if (seen.has(value)) {
|
|
334
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
335
|
-
}
|
|
336
|
-
seen.add(value);
|
|
337
|
-
if (Array.isArray(value)) {
|
|
338
|
-
stack.push(...value.map((value) => ({ value })));
|
|
339
|
-
} else {
|
|
340
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
*/
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
354
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
355
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
196
|
+
* @public exported from `@promptbook/core`
|
|
356
197
|
*/
|
|
357
|
-
|
|
198
|
+
var NAME = "Promptbook";
|
|
358
199
|
/**
|
|
359
|
-
*
|
|
360
|
-
* @@@
|
|
200
|
+
* Email of the responsible person
|
|
361
201
|
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* @param name - Name of the object for debugging purposes
|
|
365
|
-
* @param objectValue - Object to be deeply frozen
|
|
366
|
-
* @returns The same object as the input, but deeply frozen
|
|
367
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
202
|
+
* @public exported from `@promptbook/core`
|
|
368
203
|
*/
|
|
369
|
-
|
|
370
|
-
checkSerializableAsJson(name, objectValue);
|
|
371
|
-
return $deepFreeze(objectValue);
|
|
372
|
-
}
|
|
204
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
373
205
|
/**
|
|
374
|
-
*
|
|
375
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
376
|
-
*/
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Warning message for the generated sections and files files
|
|
206
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
380
207
|
*
|
|
381
|
-
* @
|
|
208
|
+
* @public exported from `@promptbook/core`
|
|
382
209
|
*/
|
|
383
|
-
var
|
|
210
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
384
211
|
/**
|
|
385
212
|
* Claim for the Promptbook
|
|
386
213
|
*
|
|
@@ -492,7 +319,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
|
492
319
|
*
|
|
493
320
|
* @public exported from `@promptbook/core`
|
|
494
321
|
*/
|
|
495
|
-
var RESERVED_PARAMETER_NAMES =
|
|
322
|
+
var RESERVED_PARAMETER_NAMES =
|
|
323
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
496
324
|
'content',
|
|
497
325
|
'context',
|
|
498
326
|
'knowledge',
|
|
@@ -502,7 +330,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
|
|
|
502
330
|
// <- TODO: list here all command names
|
|
503
331
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
504
332
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
505
|
-
]
|
|
333
|
+
];
|
|
506
334
|
/**
|
|
507
335
|
* @@@
|
|
508
336
|
*
|
|
@@ -608,7 +436,7 @@ var $isRunningInNode = new Function("\n try {\n return this === global
|
|
|
608
436
|
function initializeAboutCommand(program) {
|
|
609
437
|
var _this = this;
|
|
610
438
|
var makeCommand = program.command('about');
|
|
611
|
-
makeCommand.description(spaceTrim
|
|
439
|
+
makeCommand.description(spaceTrim("\n Tells about Promptbook CLI and its abilities\n "));
|
|
612
440
|
makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
613
441
|
return __generator(this, function (_a) {
|
|
614
442
|
console.info(colors.bold(colors.cyan("Promptbook: ".concat(CLAIM))));
|
|
@@ -634,7 +462,7 @@ function initializeAboutCommand(program) {
|
|
|
634
462
|
function initializeHelloCommand(program) {
|
|
635
463
|
var _this = this;
|
|
636
464
|
var helloCommand = program.command('hello');
|
|
637
|
-
helloCommand.description(spaceTrim
|
|
465
|
+
helloCommand.description(spaceTrim("\n Just command for testing\n "));
|
|
638
466
|
helloCommand.argument('[name]', 'Your name', 'Paul');
|
|
639
467
|
helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
|
|
640
468
|
helloCommand.action(function (name, _a) {
|
|
@@ -682,18 +510,175 @@ function $provideFilesystemForNode(options) {
|
|
|
682
510
|
if (!$isRunningInNode()) {
|
|
683
511
|
throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
|
|
684
512
|
}
|
|
685
|
-
(options || {}).isVerbose;
|
|
686
|
-
return {
|
|
687
|
-
stat: stat,
|
|
688
|
-
access: access,
|
|
689
|
-
constants: constants,
|
|
690
|
-
readFile: readFile,
|
|
691
|
-
writeFile: writeFile,
|
|
692
|
-
readdir: readdir,
|
|
693
|
-
};
|
|
513
|
+
(options || {}).isVerbose;
|
|
514
|
+
return {
|
|
515
|
+
stat: stat,
|
|
516
|
+
access: access,
|
|
517
|
+
constants: constants,
|
|
518
|
+
readFile: readFile,
|
|
519
|
+
writeFile: writeFile,
|
|
520
|
+
readdir: readdir,
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Make error report URL for the given error
|
|
529
|
+
*
|
|
530
|
+
* @private !!!!!!
|
|
531
|
+
*/
|
|
532
|
+
function getErrorReportUrl(error) {
|
|
533
|
+
var report = {
|
|
534
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
535
|
+
body: spaceTrim(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 "); }),
|
|
536
|
+
};
|
|
537
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
538
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
539
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
540
|
+
reportUrl.searchParams.set('title', report.title);
|
|
541
|
+
reportUrl.searchParams.set('body', report.body);
|
|
542
|
+
return reportUrl;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
547
|
+
*
|
|
548
|
+
* @public exported from `@promptbook/core`
|
|
549
|
+
*/
|
|
550
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
551
|
+
__extends(UnexpectedError, _super);
|
|
552
|
+
function UnexpectedError(message) {
|
|
553
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
554
|
+
_this.name = 'UnexpectedError';
|
|
555
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
556
|
+
return _this;
|
|
557
|
+
}
|
|
558
|
+
return UnexpectedError;
|
|
559
|
+
}(Error));
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
563
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
564
|
+
*
|
|
565
|
+
* - Almost all primitives are serializable BUT:
|
|
566
|
+
* - `undefined` is not serializable
|
|
567
|
+
* - `NaN` is not serializable
|
|
568
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
569
|
+
* - Functions are not serializable
|
|
570
|
+
* - Circular references are not serializable
|
|
571
|
+
* - `Date` objects are not serializable
|
|
572
|
+
* - `Map` and `Set` objects are not serializable
|
|
573
|
+
* - `RegExp` objects are not serializable
|
|
574
|
+
* - `Error` objects are not serializable
|
|
575
|
+
* - `Symbol` objects are not serializable
|
|
576
|
+
* - And much more...
|
|
577
|
+
*
|
|
578
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
579
|
+
* @public exported from `@promptbook/utils`
|
|
580
|
+
*/
|
|
581
|
+
function checkSerializableAsJson(name, value) {
|
|
582
|
+
var e_1, _a;
|
|
583
|
+
if (value === undefined) {
|
|
584
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
585
|
+
}
|
|
586
|
+
else if (value === null) {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
else if (typeof value === 'boolean') {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
else if (typeof value === 'string') {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
else if (typeof value === 'symbol') {
|
|
599
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
600
|
+
}
|
|
601
|
+
else if (typeof value === 'function') {
|
|
602
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
603
|
+
}
|
|
604
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
605
|
+
for (var i = 0; i < value.length; i++) {
|
|
606
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else if (typeof value === 'object') {
|
|
610
|
+
if (value instanceof Date) {
|
|
611
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
612
|
+
}
|
|
613
|
+
else if (value instanceof Map) {
|
|
614
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
615
|
+
}
|
|
616
|
+
else if (value instanceof Set) {
|
|
617
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
618
|
+
}
|
|
619
|
+
else if (value instanceof RegExp) {
|
|
620
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
621
|
+
}
|
|
622
|
+
else if (value instanceof Error) {
|
|
623
|
+
throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
try {
|
|
627
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
628
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
629
|
+
if (subValue === undefined) {
|
|
630
|
+
// Note: undefined in object is serializable - it is just omited
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
637
|
+
finally {
|
|
638
|
+
try {
|
|
639
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
640
|
+
}
|
|
641
|
+
finally { if (e_1) throw e_1.error; }
|
|
642
|
+
}
|
|
643
|
+
try {
|
|
644
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
if (!(error instanceof Error)) {
|
|
648
|
+
throw error;
|
|
649
|
+
}
|
|
650
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
651
|
+
}
|
|
652
|
+
/*
|
|
653
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
654
|
+
const seen = new Set();
|
|
655
|
+
const stack = [{ value }];
|
|
656
|
+
while (stack.length > 0) {
|
|
657
|
+
const { value } = stack.pop()!;
|
|
658
|
+
if (typeof value === 'object' && value !== null) {
|
|
659
|
+
if (seen.has(value)) {
|
|
660
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
661
|
+
}
|
|
662
|
+
seen.add(value);
|
|
663
|
+
if (Array.isArray(value)) {
|
|
664
|
+
stack.push(...value.map((value) => ({ value })));
|
|
665
|
+
} else {
|
|
666
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
*/
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
676
|
+
}
|
|
694
677
|
}
|
|
695
678
|
/**
|
|
696
|
-
*
|
|
679
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
680
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
681
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
697
682
|
*/
|
|
698
683
|
|
|
699
684
|
/**
|
|
@@ -739,7 +724,7 @@ function isSerializableAsJson(value) {
|
|
|
739
724
|
*/
|
|
740
725
|
function stringifyPipelineJson(pipeline) {
|
|
741
726
|
if (!isSerializableAsJson(pipeline)) {
|
|
742
|
-
throw new UnexpectedError(spaceTrim
|
|
727
|
+
throw new UnexpectedError(spaceTrim("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
|
|
743
728
|
}
|
|
744
729
|
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
745
730
|
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
@@ -756,6 +741,84 @@ function stringifyPipelineJson(pipeline) {
|
|
|
756
741
|
* TODO: [🍙] Make some standard order of json properties
|
|
757
742
|
*/
|
|
758
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Checks if the file exists
|
|
746
|
+
*
|
|
747
|
+
* @private within the repository
|
|
748
|
+
*/
|
|
749
|
+
function isFileExisting(filename, fs) {
|
|
750
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
751
|
+
var isReadAccessAllowed, isFile;
|
|
752
|
+
return __generator(this, function (_a) {
|
|
753
|
+
switch (_a.label) {
|
|
754
|
+
case 0: return [4 /*yield*/, fs
|
|
755
|
+
.access(filename, fs.constants.R_OK)
|
|
756
|
+
.then(function () { return true; })
|
|
757
|
+
.catch(function () { return false; })];
|
|
758
|
+
case 1:
|
|
759
|
+
isReadAccessAllowed = _a.sent();
|
|
760
|
+
if (!isReadAccessAllowed) {
|
|
761
|
+
return [2 /*return*/, false];
|
|
762
|
+
}
|
|
763
|
+
return [4 /*yield*/, fs
|
|
764
|
+
.stat(filename)
|
|
765
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
766
|
+
.catch(function () { return false; })];
|
|
767
|
+
case 2:
|
|
768
|
+
isFile = _a.sent();
|
|
769
|
+
return [2 /*return*/, isFile];
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
776
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
777
|
+
* TODO: [🖇] What about symlinks?
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Removes emojis from a string and fix whitespaces
|
|
782
|
+
*
|
|
783
|
+
* @param text with emojis
|
|
784
|
+
* @returns text without emojis
|
|
785
|
+
* @public exported from `@promptbook/utils`
|
|
786
|
+
*/
|
|
787
|
+
function removeEmojis(text) {
|
|
788
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
789
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
790
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
791
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
792
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
793
|
+
return text;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Tests if given string is valid URL.
|
|
798
|
+
*
|
|
799
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
800
|
+
* @public exported from `@promptbook/utils`
|
|
801
|
+
*/
|
|
802
|
+
function isValidFilePath(filename) {
|
|
803
|
+
if (typeof filename !== 'string') {
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
807
|
+
// Absolute Unix path: /hello.txt
|
|
808
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
// Absolute Windows path: /hello.txt
|
|
812
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
// Relative path: ./hello.txt
|
|
816
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
817
|
+
return true;
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
|
|
759
822
|
/**
|
|
760
823
|
* Tests if given string is valid URL.
|
|
761
824
|
*
|
|
@@ -1108,48 +1171,6 @@ function normalizeToKebabCase(text) {
|
|
|
1108
1171
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1109
1172
|
*/
|
|
1110
1173
|
|
|
1111
|
-
/**
|
|
1112
|
-
* Removes emojis from a string and fix whitespaces
|
|
1113
|
-
*
|
|
1114
|
-
* @param text with emojis
|
|
1115
|
-
* @returns text without emojis
|
|
1116
|
-
* @public exported from `@promptbook/utils`
|
|
1117
|
-
*/
|
|
1118
|
-
function removeEmojis(text) {
|
|
1119
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1120
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
1121
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1122
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
1123
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
1124
|
-
return text;
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
/**
|
|
1128
|
-
* Tests if given string is valid URL.
|
|
1129
|
-
*
|
|
1130
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
1131
|
-
* @public exported from `@promptbook/utils`
|
|
1132
|
-
*/
|
|
1133
|
-
function isValidFilePath(filename) {
|
|
1134
|
-
if (typeof filename !== 'string') {
|
|
1135
|
-
return false;
|
|
1136
|
-
}
|
|
1137
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
1138
|
-
// Absolute Unix path: /hello.txt
|
|
1139
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1140
|
-
return true;
|
|
1141
|
-
}
|
|
1142
|
-
// Absolute Windows path: /hello.txt
|
|
1143
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1144
|
-
return true;
|
|
1145
|
-
}
|
|
1146
|
-
// Relative path: ./hello.txt
|
|
1147
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1148
|
-
return true;
|
|
1149
|
-
}
|
|
1150
|
-
return false;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
1174
|
/**
|
|
1154
1175
|
* @@@
|
|
1155
1176
|
*
|
|
@@ -1174,42 +1195,6 @@ function titleToName(value) {
|
|
|
1174
1195
|
return value;
|
|
1175
1196
|
}
|
|
1176
1197
|
|
|
1177
|
-
/**
|
|
1178
|
-
* Checks if the file exists
|
|
1179
|
-
*
|
|
1180
|
-
* @private within the repository
|
|
1181
|
-
*/
|
|
1182
|
-
function isFileExisting(filename, fs) {
|
|
1183
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1184
|
-
var isReadAccessAllowed, isFile;
|
|
1185
|
-
return __generator(this, function (_a) {
|
|
1186
|
-
switch (_a.label) {
|
|
1187
|
-
case 0: return [4 /*yield*/, fs
|
|
1188
|
-
.access(filename, fs.constants.R_OK)
|
|
1189
|
-
.then(function () { return true; })
|
|
1190
|
-
.catch(function () { return false; })];
|
|
1191
|
-
case 1:
|
|
1192
|
-
isReadAccessAllowed = _a.sent();
|
|
1193
|
-
if (!isReadAccessAllowed) {
|
|
1194
|
-
return [2 /*return*/, false];
|
|
1195
|
-
}
|
|
1196
|
-
return [4 /*yield*/, fs
|
|
1197
|
-
.stat(filename)
|
|
1198
|
-
.then(function (fileStat) { return fileStat.isFile(); })
|
|
1199
|
-
.catch(function () { return false; })];
|
|
1200
|
-
case 2:
|
|
1201
|
-
isFile = _a.sent();
|
|
1202
|
-
return [2 /*return*/, isFile];
|
|
1203
|
-
}
|
|
1204
|
-
});
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
1209
|
-
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
1210
|
-
* TODO: [🖇] What about symlinks?
|
|
1211
|
-
*/
|
|
1212
|
-
|
|
1213
1198
|
/**
|
|
1214
1199
|
* @@@
|
|
1215
1200
|
*
|
|
@@ -1538,6 +1523,40 @@ function deepClone(objectValue) {
|
|
|
1538
1523
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1539
1524
|
*/
|
|
1540
1525
|
|
|
1526
|
+
/**
|
|
1527
|
+
* @@@
|
|
1528
|
+
*
|
|
1529
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1530
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1531
|
+
*
|
|
1532
|
+
* @returns The same object as the input, but deeply frozen
|
|
1533
|
+
* @public exported from `@promptbook/utils`
|
|
1534
|
+
*/
|
|
1535
|
+
function $deepFreeze(objectValue) {
|
|
1536
|
+
var e_1, _a;
|
|
1537
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1538
|
+
try {
|
|
1539
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1540
|
+
var propertyName = propertyNames_1_1.value;
|
|
1541
|
+
var value = objectValue[propertyName];
|
|
1542
|
+
if (value && typeof value === 'object') {
|
|
1543
|
+
$deepFreeze(value);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1548
|
+
finally {
|
|
1549
|
+
try {
|
|
1550
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1551
|
+
}
|
|
1552
|
+
finally { if (e_1) throw e_1.error; }
|
|
1553
|
+
}
|
|
1554
|
+
return Object.freeze(objectValue);
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1558
|
+
*/
|
|
1559
|
+
|
|
1541
1560
|
/**
|
|
1542
1561
|
* Represents the usage with no resources consumed
|
|
1543
1562
|
*
|
|
@@ -1761,7 +1780,7 @@ function countTotalUsage(llmTools) {
|
|
|
1761
1780
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
1762
1781
|
__extends(NotYetImplementedError, _super);
|
|
1763
1782
|
function NotYetImplementedError(message) {
|
|
1764
|
-
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;
|
|
1783
|
+
var _this = _super.call(this, spaceTrim$1(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;
|
|
1765
1784
|
_this.name = 'NotYetImplementedError';
|
|
1766
1785
|
Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
|
|
1767
1786
|
return _this;
|
|
@@ -2050,7 +2069,7 @@ function $registeredLlmToolsMessage() {
|
|
|
2050
2069
|
if (metadata.length === 0) {
|
|
2051
2070
|
return "No LLM providers are available.";
|
|
2052
2071
|
}
|
|
2053
|
-
return spaceTrim
|
|
2072
|
+
return spaceTrim(function (block) { return "\n Relevant environment variables:\n ".concat(block(Object.keys(env)
|
|
2054
2073
|
.filter(function (envVariableName) {
|
|
2055
2074
|
return metadata.some(function (_a) {
|
|
2056
2075
|
var envVariables = _a.envVariables;
|
|
@@ -2094,7 +2113,7 @@ function $registeredLlmToolsMessage() {
|
|
|
2094
2113
|
morePieces.push("Not configured"); // <- Note: Can not be configured via environment variables
|
|
2095
2114
|
}
|
|
2096
2115
|
}
|
|
2097
|
-
var providerMessage = spaceTrim
|
|
2116
|
+
var providerMessage = spaceTrim("\n ".concat(i + 1, ") **").concat(title, "** `").concat(className, "` from `").concat(packageName, "`\n ").concat(morePieces.join('; '), "\n "));
|
|
2098
2117
|
if ($isRunningInNode) {
|
|
2099
2118
|
if (isInstalled && isFullyConfigured) {
|
|
2100
2119
|
providerMessage = colors.green(providerMessage);
|
|
@@ -2334,7 +2353,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2334
2353
|
// 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
2335
2354
|
// 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
|
|
2336
2355
|
// 3) ...
|
|
2337
|
-
spaceTrim
|
|
2356
|
+
spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
|
|
2338
2357
|
.map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
|
|
2339
2358
|
.join('\n')), "\n\n "); }));
|
|
2340
2359
|
}
|
|
@@ -2342,7 +2361,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2342
2361
|
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2343
2362
|
}
|
|
2344
2363
|
else {
|
|
2345
|
-
throw new PipelineExecutionError(spaceTrim
|
|
2364
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
|
|
2346
2365
|
}
|
|
2347
2366
|
}
|
|
2348
2367
|
});
|
|
@@ -2377,7 +2396,7 @@ function joinLlmExecutionTools() {
|
|
|
2377
2396
|
llmExecutionTools[_i] = arguments[_i];
|
|
2378
2397
|
}
|
|
2379
2398
|
if (llmExecutionTools.length === 0) {
|
|
2380
|
-
var warningMessage = spaceTrim
|
|
2399
|
+
var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
|
|
2381
2400
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2382
2401
|
console.warn(warningMessage);
|
|
2383
2402
|
/*
|
|
@@ -2426,7 +2445,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
|
|
|
2426
2445
|
return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
|
|
2427
2446
|
});
|
|
2428
2447
|
if (registeredItem === undefined) {
|
|
2429
|
-
throw new Error(spaceTrim
|
|
2448
|
+
throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
|
|
2430
2449
|
}
|
|
2431
2450
|
return registeredItem(__assign({ isVerbose: isVerbose, userId: userId }, llmConfiguration.options));
|
|
2432
2451
|
});
|
|
@@ -2465,7 +2484,7 @@ function $provideLlmToolsFromEnv(options) {
|
|
|
2465
2484
|
var configuration = $provideLlmToolsConfigurationFromEnv();
|
|
2466
2485
|
if (configuration.length === 0) {
|
|
2467
2486
|
// TODO: [🥃]
|
|
2468
|
-
throw new Error(spaceTrim
|
|
2487
|
+
throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
|
|
2469
2488
|
}
|
|
2470
2489
|
return createLlmToolsFromConfiguration(configuration, options);
|
|
2471
2490
|
}
|
|
@@ -2514,7 +2533,7 @@ function $provideLlmToolsForCli(options) {
|
|
|
2514
2533
|
function initializeListModelsCommand(program) {
|
|
2515
2534
|
var _this = this;
|
|
2516
2535
|
var listModelsCommand = program.command('list-models');
|
|
2517
|
-
listModelsCommand.description(spaceTrim
|
|
2536
|
+
listModelsCommand.description(spaceTrim("\n List all available and configured LLM models\n "));
|
|
2518
2537
|
listModelsCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2519
2538
|
return __generator(this, function (_a) {
|
|
2520
2539
|
$provideLlmToolsForCli({});
|
|
@@ -2768,7 +2787,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
2768
2787
|
pipelineString += '\n\n';
|
|
2769
2788
|
pipelineString += '```' + contentLanguage;
|
|
2770
2789
|
pipelineString += '\n';
|
|
2771
|
-
pipelineString += spaceTrim
|
|
2790
|
+
pipelineString += spaceTrim(content);
|
|
2772
2791
|
// <- TODO: [main] !!! Escape
|
|
2773
2792
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
2774
2793
|
pipelineString += '\n';
|
|
@@ -2813,7 +2832,7 @@ function taskParameterJsonToString(taskParameterJson) {
|
|
|
2813
2832
|
var MissingToolsError = /** @class */ (function (_super) {
|
|
2814
2833
|
__extends(MissingToolsError, _super);
|
|
2815
2834
|
function MissingToolsError(message) {
|
|
2816
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
2835
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
|
|
2817
2836
|
_this.name = 'MissingToolsError';
|
|
2818
2837
|
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
2819
2838
|
return _this;
|
|
@@ -3086,7 +3105,7 @@ function validatePipeline(pipeline) {
|
|
|
3086
3105
|
if (!(error instanceof PipelineLogicError)) {
|
|
3087
3106
|
throw error;
|
|
3088
3107
|
}
|
|
3089
|
-
console.error(spaceTrim(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
|
|
3108
|
+
console.error(spaceTrim$1(function (block) { return "\n Pipeline is not valid but logic errors are temporarily disabled via `IS_PIPELINE_LOGIC_VALIDATED`\n\n ".concat(block(error.message), "\n "); }));
|
|
3090
3109
|
}
|
|
3091
3110
|
}
|
|
3092
3111
|
return pipeline;
|
|
@@ -3110,35 +3129,35 @@ function validatePipelineCore(pipeline) {
|
|
|
3110
3129
|
})();
|
|
3111
3130
|
if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
|
|
3112
3131
|
// <- Note: [🚲]
|
|
3113
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3132
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3114
3133
|
}
|
|
3115
3134
|
if (pipeline.bookVersion !== undefined && !isValidPromptbookVersion(pipeline.bookVersion)) {
|
|
3116
3135
|
// <- Note: [🚲]
|
|
3117
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3136
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.bookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3118
3137
|
}
|
|
3119
3138
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
3120
3139
|
if (!Array.isArray(pipeline.parameters)) {
|
|
3121
3140
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
3122
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3141
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3123
3142
|
}
|
|
3124
3143
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
3125
3144
|
if (!Array.isArray(pipeline.tasks)) {
|
|
3126
3145
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
3127
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3146
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Pipeline is valid JSON but with wrong structure\n\n `PipelineJson.tasks` expected to be an array, but got ".concat(typeof pipeline.tasks, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3128
3147
|
}
|
|
3129
3148
|
var _loop_1 = function (parameter) {
|
|
3130
3149
|
if (parameter.isInput && parameter.isOutput) {
|
|
3131
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Parameter `{".concat(parameter.name, "}` can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3150
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Parameter `{".concat(parameter.name, "}` can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3132
3151
|
}
|
|
3133
3152
|
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
3134
3153
|
if (!parameter.isInput &&
|
|
3135
3154
|
!parameter.isOutput &&
|
|
3136
3155
|
!pipeline.tasks.some(function (task) { return task.dependentParameterNames.includes(parameter.name); })) {
|
|
3137
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3156
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3138
3157
|
}
|
|
3139
3158
|
// Note: Testing that parameter is either input or result of some task
|
|
3140
3159
|
if (!parameter.isInput && !pipeline.tasks.some(function (task) { return task.resultingParameterName === parameter.name; })) {
|
|
3141
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3160
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is declared but not defined\n\n You can do one of these:\n 1) Remove declaration of `{").concat(parameter.name, "}`\n 2) Add task that results in `-> {").concat(parameter.name, "}`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3142
3161
|
}
|
|
3143
3162
|
};
|
|
3144
3163
|
try {
|
|
@@ -3166,20 +3185,20 @@ function validatePipelineCore(pipeline) {
|
|
|
3166
3185
|
var _loop_2 = function (task) {
|
|
3167
3186
|
var e_4, _h, e_5, _j;
|
|
3168
3187
|
if (definedParameters.has(task.resultingParameterName)) {
|
|
3169
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3188
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(task.resultingParameterName, "}` is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3170
3189
|
}
|
|
3171
3190
|
if (RESERVED_PARAMETER_NAMES.includes(task.resultingParameterName)) {
|
|
3172
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3191
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(task.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3173
3192
|
}
|
|
3174
3193
|
definedParameters.add(task.resultingParameterName);
|
|
3175
3194
|
if (task.jokerParameterNames && task.jokerParameterNames.length > 0) {
|
|
3176
3195
|
if (!task.format &&
|
|
3177
3196
|
!task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
3178
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3197
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(task.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3179
3198
|
}
|
|
3180
3199
|
var _loop_4 = function (joker) {
|
|
3181
3200
|
if (!task.dependentParameterNames.includes(joker)) {
|
|
3182
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3201
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(joker, "}` is used for {").concat(task.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3183
3202
|
}
|
|
3184
3203
|
};
|
|
3185
3204
|
try {
|
|
@@ -3199,13 +3218,13 @@ function validatePipelineCore(pipeline) {
|
|
|
3199
3218
|
if (task.expectations) {
|
|
3200
3219
|
var _loop_5 = function (unit, min, max) {
|
|
3201
3220
|
if (min !== undefined && max !== undefined && min > max) {
|
|
3202
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3221
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3203
3222
|
}
|
|
3204
3223
|
if (min !== undefined && min < 0) {
|
|
3205
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3224
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3206
3225
|
}
|
|
3207
3226
|
if (max !== undefined && max <= 0) {
|
|
3208
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3227
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3209
3228
|
}
|
|
3210
3229
|
};
|
|
3211
3230
|
try {
|
|
@@ -3266,7 +3285,7 @@ function validatePipelineCore(pipeline) {
|
|
|
3266
3285
|
var _loop_3 = function () {
|
|
3267
3286
|
if (loopLimit-- < 0) {
|
|
3268
3287
|
// Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
|
|
3269
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3288
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3270
3289
|
}
|
|
3271
3290
|
var currentlyResovedTasks = unresovedTasks.filter(function (task) {
|
|
3272
3291
|
return task.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
@@ -3274,7 +3293,7 @@ function validatePipelineCore(pipeline) {
|
|
|
3274
3293
|
if (currentlyResovedTasks.length === 0) {
|
|
3275
3294
|
throw new PipelineLogicError(
|
|
3276
3295
|
// TODO: [🐎] DRY
|
|
3277
|
-
spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks
|
|
3296
|
+
spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks
|
|
3278
3297
|
.map(function (_a) {
|
|
3279
3298
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
3280
3299
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -3385,6 +3404,26 @@ function extractParameterNames(template) {
|
|
|
3385
3404
|
return parameterNames;
|
|
3386
3405
|
}
|
|
3387
3406
|
|
|
3407
|
+
/**
|
|
3408
|
+
* @@@
|
|
3409
|
+
* @@@
|
|
3410
|
+
*
|
|
3411
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
3412
|
+
*
|
|
3413
|
+
* @param name - Name of the object for debugging purposes
|
|
3414
|
+
* @param objectValue - Object to be deeply frozen
|
|
3415
|
+
* @returns The same object as the input, but deeply frozen
|
|
3416
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
3417
|
+
*/
|
|
3418
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
3419
|
+
checkSerializableAsJson(name, objectValue);
|
|
3420
|
+
return $deepFreeze(objectValue);
|
|
3421
|
+
}
|
|
3422
|
+
/**
|
|
3423
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
3424
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
3425
|
+
*/
|
|
3426
|
+
|
|
3388
3427
|
/**
|
|
3389
3428
|
* Unprepare just strips the preparation data of the pipeline
|
|
3390
3429
|
*
|
|
@@ -3438,7 +3477,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
3438
3477
|
var pipeline = pipelines_1_1.value;
|
|
3439
3478
|
// TODO: [👠] DRY
|
|
3440
3479
|
if (pipeline.pipelineUrl === undefined) {
|
|
3441
|
-
throw new PipelineUrlError(spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
3480
|
+
throw new PipelineUrlError(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
3442
3481
|
}
|
|
3443
3482
|
// Note: [🐨]
|
|
3444
3483
|
validatePipeline(pipeline);
|
|
@@ -3450,7 +3489,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
3450
3489
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
3451
3490
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
3452
3491
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
3453
|
-
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
3492
|
+
throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
3454
3493
|
}
|
|
3455
3494
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
3456
3495
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -3480,9 +3519,9 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
3480
3519
|
var pipeline = this.collection.get(url);
|
|
3481
3520
|
if (!pipeline) {
|
|
3482
3521
|
if (this.listPipelines().length === 0) {
|
|
3483
|
-
throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
3522
|
+
throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
|
|
3484
3523
|
}
|
|
3485
|
-
throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
3524
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
|
|
3486
3525
|
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
3487
3526
|
.join('\n')), "\n\n "); }));
|
|
3488
3527
|
}
|
|
@@ -3706,10 +3745,10 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
3706
3745
|
throw deserializeError(errors[0]);
|
|
3707
3746
|
}
|
|
3708
3747
|
else {
|
|
3709
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
3748
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
|
|
3710
3749
|
.map(function (_a, index) {
|
|
3711
3750
|
var name = _a.name, stack = _a.stack, message = _a.message;
|
|
3712
|
-
return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
3751
|
+
return spaceTrim$1(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
|
|
3713
3752
|
})
|
|
3714
3753
|
.join('\n')), "\n "); }));
|
|
3715
3754
|
}
|
|
@@ -3759,7 +3798,7 @@ function isPipelinePrepared(pipeline) {
|
|
|
3759
3798
|
function serializeError(error) {
|
|
3760
3799
|
var name = error.name, message = error.message, stack = error.stack;
|
|
3761
3800
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
3762
|
-
console.error(spaceTrim
|
|
3801
|
+
console.error(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
3763
3802
|
}
|
|
3764
3803
|
return {
|
|
3765
3804
|
name: name,
|
|
@@ -3774,10 +3813,11 @@ function serializeError(error) {
|
|
|
3774
3813
|
* @param script from which to extract the variables
|
|
3775
3814
|
* @returns the list of variable names
|
|
3776
3815
|
* @throws {ParseError} if the script is invalid
|
|
3777
|
-
* @public exported from `@promptbook/utils`
|
|
3816
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3778
3817
|
*/
|
|
3779
|
-
function
|
|
3818
|
+
function extractVariablesFromScript(script) {
|
|
3780
3819
|
var variables = new Set();
|
|
3820
|
+
var originalScript = script;
|
|
3781
3821
|
script = "(()=>{".concat(script, "})()");
|
|
3782
3822
|
try {
|
|
3783
3823
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3809,7 +3849,9 @@ function extractVariables(script) {
|
|
|
3809
3849
|
if (!(error instanceof Error)) {
|
|
3810
3850
|
throw error;
|
|
3811
3851
|
}
|
|
3812
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3852
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
|
|
3853
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3854
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3813
3855
|
}
|
|
3814
3856
|
return variables;
|
|
3815
3857
|
}
|
|
@@ -3823,7 +3865,7 @@ function extractVariables(script) {
|
|
|
3823
3865
|
* @param task the task with used parameters
|
|
3824
3866
|
* @returns the set of parameter names
|
|
3825
3867
|
* @throws {ParseError} if the script is invalid
|
|
3826
|
-
* @public exported from `@promptbook/
|
|
3868
|
+
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
3827
3869
|
*/
|
|
3828
3870
|
function extractParameterNamesFromTask(task) {
|
|
3829
3871
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -3844,7 +3886,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3844
3886
|
}
|
|
3845
3887
|
if (taskType === 'SCRIPT_TASK') {
|
|
3846
3888
|
try {
|
|
3847
|
-
for (var _g = __values(
|
|
3889
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3848
3890
|
var parameterName = _h.value;
|
|
3849
3891
|
parameterNames.add(parameterName);
|
|
3850
3892
|
}
|
|
@@ -4013,7 +4055,7 @@ var CsvFormatDefinition = {
|
|
|
4013
4055
|
case 0:
|
|
4014
4056
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
4015
4057
|
if (csv.errors.length !== 0) {
|
|
4016
|
-
throw new CsvFormatError(spaceTrim
|
|
4058
|
+
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
|
|
4017
4059
|
}
|
|
4018
4060
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
4019
4061
|
var _a, _b;
|
|
@@ -4051,7 +4093,7 @@ var CsvFormatDefinition = {
|
|
|
4051
4093
|
case 0:
|
|
4052
4094
|
csv = parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
4053
4095
|
if (csv.errors.length !== 0) {
|
|
4054
|
-
throw new CsvFormatError(spaceTrim
|
|
4096
|
+
throw new CsvFormatError(spaceTrim(function (block) { return "\n CSV parsing error\n\n Error(s) from CSV parsing:\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n\n The CSV setings:\n ").concat(block(JSON.stringify(__assign(__assign({}, settings), MANDATORY_CSV_SETTINGS), null, 2)), "\n\n The CSV data:\n ").concat(block(value), "\n "); }));
|
|
4055
4097
|
}
|
|
4056
4098
|
return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
|
|
4057
4099
|
var _this = this;
|
|
@@ -4292,7 +4334,7 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
4292
4334
|
}
|
|
4293
4335
|
// Phase 2️⃣: Non-matching mapping
|
|
4294
4336
|
if (expectedParameterNames.size !== availableParametersNames.size) {
|
|
4295
|
-
throw new PipelineExecutionError(spaceTrim
|
|
4337
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
|
|
4296
4338
|
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
4297
4339
|
.join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
|
|
4298
4340
|
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
@@ -4705,14 +4747,14 @@ function executeAttempts(options) {
|
|
|
4705
4747
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
4706
4748
|
// TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
4707
4749
|
if (isJokerAttempt && !jokerParameterName) {
|
|
4708
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4750
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4709
4751
|
}
|
|
4710
4752
|
$ongoingTaskResult.$result = null;
|
|
4711
4753
|
$ongoingTaskResult.$resultString = null;
|
|
4712
4754
|
$ongoingTaskResult.$expectError = null;
|
|
4713
4755
|
if (isJokerAttempt) {
|
|
4714
4756
|
if (parameters[jokerParameterName] === undefined) {
|
|
4715
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4757
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4716
4758
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
4717
4759
|
}
|
|
4718
4760
|
else {
|
|
@@ -4781,15 +4823,15 @@ function executeAttempts(options) {
|
|
|
4781
4823
|
$ongoingTaskResult.$result = $ongoingTaskResult.$completionResult;
|
|
4782
4824
|
$ongoingTaskResult.$resultString = $ongoingTaskResult.$completionResult.content;
|
|
4783
4825
|
return [3 /*break*/, 10];
|
|
4784
|
-
case 8: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
|
|
4785
|
-
case 9: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4826
|
+
case 8: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
|
|
4827
|
+
case 9: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown model variant \"".concat(task.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
4786
4828
|
case 10: return [3 /*break*/, 25];
|
|
4787
4829
|
case 11:
|
|
4788
4830
|
if (arrayableToArray(tools.script).length === 0) {
|
|
4789
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4831
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4790
4832
|
}
|
|
4791
4833
|
if (!task.contentLanguage) {
|
|
4792
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4834
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script language is not defined for SCRIPT TASK \"".concat(task.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4793
4835
|
}
|
|
4794
4836
|
_t.label = 12;
|
|
4795
4837
|
case 12:
|
|
@@ -4843,13 +4885,13 @@ function executeAttempts(options) {
|
|
|
4843
4885
|
throw $ongoingTaskResult.$scriptPipelineExecutionErrors[0];
|
|
4844
4886
|
}
|
|
4845
4887
|
else {
|
|
4846
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
|
|
4888
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat($ongoingTaskResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTaskResult.$scriptPipelineExecutionErrors
|
|
4847
4889
|
.map(function (error) { return '- ' + error.message; })
|
|
4848
4890
|
.join('\n\n')), "\n "); }));
|
|
4849
4891
|
}
|
|
4850
4892
|
case 22:
|
|
4851
4893
|
if (tools.userInterface === undefined) {
|
|
4852
|
-
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4894
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
4853
4895
|
}
|
|
4854
4896
|
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4855
4897
|
_j = $ongoingTaskResult;
|
|
@@ -4865,7 +4907,7 @@ function executeAttempts(options) {
|
|
|
4865
4907
|
// TODO: [🌹] When making next attempt for `DIALOG TASK`, preserve the previous user input
|
|
4866
4908
|
_j.$resultString = _t.sent();
|
|
4867
4909
|
return [3 /*break*/, 25];
|
|
4868
|
-
case 24: throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4910
|
+
case 24: throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Unknown execution type \"".concat(task.taskType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4869
4911
|
case 25:
|
|
4870
4912
|
if (!(!isJokerAttempt && task.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
4871
4913
|
_t.label = 26;
|
|
@@ -4955,13 +4997,13 @@ function executeAttempts(options) {
|
|
|
4955
4997
|
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
4956
4998
|
}
|
|
4957
4999
|
catch (error) {
|
|
4958
|
-
throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
5000
|
+
throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
4959
5001
|
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
4960
5002
|
}
|
|
4961
5003
|
}
|
|
4962
5004
|
}
|
|
4963
5005
|
else {
|
|
4964
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5006
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown format \"".concat(task.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
4965
5007
|
}
|
|
4966
5008
|
}
|
|
4967
5009
|
// TODO: [💝] Unite object for expecting amount and format
|
|
@@ -4995,7 +5037,7 @@ function executeAttempts(options) {
|
|
|
4995
5037
|
return [7 /*endfinally*/];
|
|
4996
5038
|
case 45:
|
|
4997
5039
|
if ($ongoingTaskResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
4998
|
-
throw new PipelineExecutionError(spaceTrim(function (block) {
|
|
5040
|
+
throw new PipelineExecutionError(spaceTrim$1(function (block) {
|
|
4999
5041
|
var _a, _b, _c;
|
|
5000
5042
|
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTaskResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
5001
5043
|
.split('\n')
|
|
@@ -5031,7 +5073,7 @@ function executeAttempts(options) {
|
|
|
5031
5073
|
return [3 /*break*/, 1];
|
|
5032
5074
|
case 4:
|
|
5033
5075
|
if ($ongoingTaskResult.$resultString === null) {
|
|
5034
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5076
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5035
5077
|
}
|
|
5036
5078
|
return [2 /*return*/, $ongoingTaskResult.$resultString];
|
|
5037
5079
|
}
|
|
@@ -5059,7 +5101,7 @@ function executeFormatSubvalues(options) {
|
|
|
5059
5101
|
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
5060
5102
|
}
|
|
5061
5103
|
if (jokerParameterNames.length !== 0) {
|
|
5062
|
-
throw new UnexpectedError(spaceTrim
|
|
5104
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5063
5105
|
}
|
|
5064
5106
|
parameterValue = parameters[task.foreach.parameterName] || '';
|
|
5065
5107
|
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
@@ -5068,7 +5110,7 @@ function executeFormatSubvalues(options) {
|
|
|
5068
5110
|
if (formatDefinition === undefined) {
|
|
5069
5111
|
throw new UnexpectedError(
|
|
5070
5112
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
5071
|
-
spaceTrim
|
|
5113
|
+
spaceTrim(function (block) { return "\n Unsupported format \"".concat(task.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
5072
5114
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
5073
5115
|
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5074
5116
|
}
|
|
@@ -5078,7 +5120,7 @@ function executeFormatSubvalues(options) {
|
|
|
5078
5120
|
if (subvalueDefinition === undefined) {
|
|
5079
5121
|
throw new UnexpectedError(
|
|
5080
5122
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
5081
|
-
spaceTrim
|
|
5123
|
+
spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(task.foreach.subformatName, "\" for format \"").concat(task.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
5082
5124
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
5083
5125
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
5084
5126
|
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
@@ -5104,12 +5146,12 @@ function executeFormatSubvalues(options) {
|
|
|
5104
5146
|
if (!(error instanceof PipelineExecutionError)) {
|
|
5105
5147
|
throw error;
|
|
5106
5148
|
}
|
|
5107
|
-
throw new PipelineExecutionError(spaceTrim
|
|
5149
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
|
|
5108
5150
|
}
|
|
5109
5151
|
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
5110
5152
|
// Note: [👨👨👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
5111
5153
|
Object.freeze(allSubparameters);
|
|
5112
|
-
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim
|
|
5154
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
5113
5155
|
case 1:
|
|
5114
5156
|
subresultString = _a.sent();
|
|
5115
5157
|
return [2 /*return*/, subresultString];
|
|
@@ -5202,7 +5244,7 @@ function getReservedParametersForTask(options) {
|
|
|
5202
5244
|
};
|
|
5203
5245
|
_loop_1 = function (parameterName) {
|
|
5204
5246
|
if (reservedParameters[parameterName] === undefined) {
|
|
5205
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5247
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Reserved parameter {".concat(parameterName, "} is not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
5206
5248
|
}
|
|
5207
5249
|
};
|
|
5208
5250
|
try {
|
|
@@ -5257,7 +5299,7 @@ function executeTask(options) {
|
|
|
5257
5299
|
dependentParameterNames = new Set(currentTask.dependentParameterNames);
|
|
5258
5300
|
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
5259
5301
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
5260
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
5302
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
5261
5303
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
5262
5304
|
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
5263
5305
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
@@ -5285,7 +5327,7 @@ function executeTask(options) {
|
|
|
5285
5327
|
else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
|
|
5286
5328
|
// Houston, we have a problem
|
|
5287
5329
|
// Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
|
|
5288
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
5330
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is NOT defined\n BUT used in task \"").concat(currentTask.title || currentTask.name, "\"\n\n This should be catched in `validatePipeline`\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
5289
5331
|
}
|
|
5290
5332
|
};
|
|
5291
5333
|
try {
|
|
@@ -5371,7 +5413,7 @@ function filterJustOutputParameters(options) {
|
|
|
5371
5413
|
var _loop_1 = function (parameter) {
|
|
5372
5414
|
if (parametersToPass[parameter.name] === undefined) {
|
|
5373
5415
|
// [4]
|
|
5374
|
-
$warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
5416
|
+
$warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` should be an output parameter, but it was not generated during pipeline execution\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
5375
5417
|
return "continue";
|
|
5376
5418
|
}
|
|
5377
5419
|
outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
|
|
@@ -5491,7 +5533,7 @@ function executePipeline(options) {
|
|
|
5491
5533
|
return name === parameterName;
|
|
5492
5534
|
});
|
|
5493
5535
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
5494
|
-
warnings.push(new PipelineExecutionError(spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
5536
|
+
warnings.push(new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
5495
5537
|
return [3 /*break*/, 4];
|
|
5496
5538
|
case 1:
|
|
5497
5539
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -5503,10 +5545,10 @@ function executePipeline(options) {
|
|
|
5503
5545
|
// Note: Wait a short time to prevent race conditions
|
|
5504
5546
|
_h.sent();
|
|
5505
5547
|
_h.label = 3;
|
|
5506
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
5548
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim$1(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
5507
5549
|
isSuccessful: false,
|
|
5508
5550
|
errors: __spreadArray([
|
|
5509
|
-
new PipelineExecutionError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
5551
|
+
new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
5510
5552
|
], __read(errors), false).map(serializeError),
|
|
5511
5553
|
warnings: warnings.map(serializeError),
|
|
5512
5554
|
executionReport: executionReport,
|
|
@@ -5570,7 +5612,7 @@ function executePipeline(options) {
|
|
|
5570
5612
|
case 0:
|
|
5571
5613
|
if (loopLimit-- < 0) {
|
|
5572
5614
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
5573
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5615
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
5574
5616
|
}
|
|
5575
5617
|
currentTask = unresovedTasks_1.find(function (task) {
|
|
5576
5618
|
return task.dependentParameterNames.every(function (name) {
|
|
@@ -5580,7 +5622,7 @@ function executePipeline(options) {
|
|
|
5580
5622
|
if (!(!currentTask && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
5581
5623
|
throw new UnexpectedError(
|
|
5582
5624
|
// TODO: [🐎] DRY
|
|
5583
|
-
spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
|
|
5625
|
+
spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n **Can not resolve:**\n ").concat(block(unresovedTasks_1
|
|
5584
5626
|
.map(function (_a) {
|
|
5585
5627
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
5586
5628
|
return "- Parameter `{".concat(resultingParameterName, "}` which depends on ").concat(dependentParameterNames
|
|
@@ -5608,7 +5650,7 @@ function executePipeline(options) {
|
|
|
5608
5650
|
unresovedTasks_1 = unresovedTasks_1.filter(function (task) { return task !== currentTask; });
|
|
5609
5651
|
work_1 = executeTask(__assign(__assign({}, options), { currentTask: currentTask, preparedPipeline: preparedPipeline, parametersToPass: parametersToPass, tools: tools, onProgress: function (progress) {
|
|
5610
5652
|
if (isReturned) {
|
|
5611
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
5653
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
5612
5654
|
.split('\n')
|
|
5613
5655
|
.map(function (line) { return "> ".concat(line); })
|
|
5614
5656
|
.join('\n')), "\n "); }));
|
|
@@ -5616,7 +5658,7 @@ function executePipeline(options) {
|
|
|
5616
5658
|
if (onProgress) {
|
|
5617
5659
|
onProgress(progress);
|
|
5618
5660
|
}
|
|
5619
|
-
}, $executionReport: executionReport, pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5661
|
+
}, $executionReport: executionReport, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Task name: ").concat(currentTask.name, "\n Task title: ").concat(currentTask.title, "\n "); }) }))
|
|
5620
5662
|
.then(function (newParametersToPass) {
|
|
5621
5663
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
5622
5664
|
resovedParameterNames_1 = __spreadArray(__spreadArray([], __read(resovedParameterNames_1), false), [currentTask.resultingParameterName], false);
|
|
@@ -5738,7 +5780,7 @@ function createPipelineExecutor(options) {
|
|
|
5738
5780
|
preparedPipeline = pipeline;
|
|
5739
5781
|
}
|
|
5740
5782
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
5741
|
-
console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
5783
|
+
console.warn(spaceTrim$1(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
5742
5784
|
}
|
|
5743
5785
|
var runCount = 0;
|
|
5744
5786
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -5753,7 +5795,7 @@ function createPipelineExecutor(options) {
|
|
|
5753
5795
|
inputParameters: inputParameters,
|
|
5754
5796
|
tools: tools,
|
|
5755
5797
|
onProgress: onProgress,
|
|
5756
|
-
pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
5798
|
+
pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
5757
5799
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
5758
5800
|
maxParallelCount: maxParallelCount,
|
|
5759
5801
|
csvSettings: csvSettings,
|
|
@@ -5948,9 +5990,9 @@ function $registeredScrapersMessage(availableScrapers) {
|
|
|
5948
5990
|
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
|
|
5949
5991
|
});
|
|
5950
5992
|
if (metadata.length === 0) {
|
|
5951
|
-
return spaceTrim
|
|
5993
|
+
return spaceTrim("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
|
|
5952
5994
|
}
|
|
5953
|
-
return spaceTrim
|
|
5995
|
+
return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
|
|
5954
5996
|
.map(function (_a, i) {
|
|
5955
5997
|
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
|
|
5956
5998
|
var more = [];
|
|
@@ -6104,7 +6146,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
6104
6146
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
6105
6147
|
case 3:
|
|
6106
6148
|
if (!(_e.sent())) {
|
|
6107
|
-
throw new NotFoundError(spaceTrim
|
|
6149
|
+
throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
6108
6150
|
}
|
|
6109
6151
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
6110
6152
|
return [2 /*return*/, {
|
|
@@ -6217,7 +6259,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
6217
6259
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
6218
6260
|
return [2 /*return*/, "break"];
|
|
6219
6261
|
}
|
|
6220
|
-
console.warn(spaceTrim
|
|
6262
|
+
console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n \n The source:\n > ").concat(block(knowledgeSource.sourceContent
|
|
6221
6263
|
.split('\n')
|
|
6222
6264
|
.map(function (line) { return "> ".concat(line); })
|
|
6223
6265
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6255,7 +6297,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
6255
6297
|
return [7 /*endfinally*/];
|
|
6256
6298
|
case 9:
|
|
6257
6299
|
if (partialPieces === null) {
|
|
6258
|
-
throw new KnowledgeScrapeError(spaceTrim
|
|
6300
|
+
throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
|
|
6259
6301
|
.split('\n')
|
|
6260
6302
|
.map(function (line) { return "> ".concat(line); })
|
|
6261
6303
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6354,7 +6396,7 @@ function prepareTasks(pipeline, tools, options) {
|
|
|
6354
6396
|
dependentParameterNames = task.dependentParameterNames;
|
|
6355
6397
|
preparedContent = undefined;
|
|
6356
6398
|
if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
|
|
6357
|
-
preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
6399
|
+
preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
|
|
6358
6400
|
// <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
|
|
6359
6401
|
dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
|
|
6360
6402
|
'knowledge',
|
|
@@ -6553,7 +6595,7 @@ var knowledgeCommandParser = {
|
|
|
6553
6595
|
*/
|
|
6554
6596
|
parse: function (input) {
|
|
6555
6597
|
var args = input.args;
|
|
6556
|
-
var sourceContent = spaceTrim
|
|
6598
|
+
var sourceContent = spaceTrim(args[0] || '');
|
|
6557
6599
|
if (sourceContent === '') {
|
|
6558
6600
|
throw new ParseError("Source is not defined");
|
|
6559
6601
|
}
|
|
@@ -6697,7 +6739,7 @@ var sectionCommandParser = {
|
|
|
6697
6739
|
return normalized.includes(sectionType.split('_TASK').join(''));
|
|
6698
6740
|
});
|
|
6699
6741
|
if (taskTypes.length !== 1) {
|
|
6700
|
-
throw new ParseError(spaceTrim
|
|
6742
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unknown section type \"".concat(normalized, "\"\n\n Supported section types are:\n ").concat(block(SectionTypes.join(', ')), "\n "); }));
|
|
6701
6743
|
}
|
|
6702
6744
|
var taskType = taskTypes[0];
|
|
6703
6745
|
return {
|
|
@@ -6712,10 +6754,10 @@ var sectionCommandParser = {
|
|
|
6712
6754
|
*/
|
|
6713
6755
|
$applyToTaskJson: function (command, $taskJson, $pipelineJson) {
|
|
6714
6756
|
if ($taskJson.isSectionTypeSet === true) {
|
|
6715
|
-
throw new ParseError(spaceTrim
|
|
6757
|
+
throw new ParseError(spaceTrim("\n Section type is already defined in the section.\n It can be defined only once.\n "));
|
|
6716
6758
|
}
|
|
6717
6759
|
$taskJson.isSectionTypeSet = true;
|
|
6718
|
-
// TODO: [🍧] Rearrange better - but at bottom and unwrap from function
|
|
6760
|
+
// TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
|
|
6719
6761
|
var expectResultingParameterName = function () {
|
|
6720
6762
|
if ($taskJson.resultingParameterName) {
|
|
6721
6763
|
return;
|
|
@@ -7054,7 +7096,7 @@ var expectCommandParser = {
|
|
|
7054
7096
|
/**
|
|
7055
7097
|
* Description of the FORMAT command
|
|
7056
7098
|
*/
|
|
7057
|
-
description: spaceTrim
|
|
7099
|
+
description: spaceTrim("\n Expect command describes the desired output of the task *(after post-processing)*\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
7058
7100
|
/**
|
|
7059
7101
|
* Link to documentation
|
|
7060
7102
|
*/
|
|
@@ -7138,7 +7180,7 @@ var expectCommandParser = {
|
|
|
7138
7180
|
if (!(error instanceof Error)) {
|
|
7139
7181
|
throw error;
|
|
7140
7182
|
}
|
|
7141
|
-
throw new ParseError(spaceTrim
|
|
7183
|
+
throw new ParseError(spaceTrim(function (block) {
|
|
7142
7184
|
return "\n Invalid FORMAT command\n ".concat(block(error.message), ":\n ");
|
|
7143
7185
|
}));
|
|
7144
7186
|
}
|
|
@@ -7344,7 +7386,7 @@ function validateParameterName(parameterName) {
|
|
|
7344
7386
|
if (!(error instanceof ParseError)) {
|
|
7345
7387
|
throw error;
|
|
7346
7388
|
}
|
|
7347
|
-
throw new ParseError(spaceTrim
|
|
7389
|
+
throw new ParseError(spaceTrim(function (block) { return "\n ".concat(block(error.message), "\n\n Tried to validate parameter name:\n ").concat(block(rawParameterName), "\n "); }));
|
|
7348
7390
|
}
|
|
7349
7391
|
return parameterName;
|
|
7350
7392
|
}
|
|
@@ -7402,7 +7444,7 @@ var foreachCommandParser = {
|
|
|
7402
7444
|
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
|
|
7403
7445
|
});
|
|
7404
7446
|
if (formatDefinition === undefined) {
|
|
7405
|
-
throw new ParseError(spaceTrim
|
|
7447
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unsupported format \"".concat(formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
7406
7448
|
.map(function (formatName) { return "- ".concat(formatName); })
|
|
7407
7449
|
.join('\n')), "\n "); }));
|
|
7408
7450
|
// <- TODO: [🏢] List all supported format names
|
|
@@ -7411,7 +7453,7 @@ var foreachCommandParser = {
|
|
|
7411
7453
|
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
|
|
7412
7454
|
});
|
|
7413
7455
|
if (subvalueDefinition === undefined) {
|
|
7414
|
-
throw new ParseError(spaceTrim
|
|
7456
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
7415
7457
|
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
7416
7458
|
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
7417
7459
|
.join('\n')), "\n "); }));
|
|
@@ -7454,7 +7496,7 @@ var foreachCommandParser = {
|
|
|
7454
7496
|
outputSubparameterName = 'newLine';
|
|
7455
7497
|
}
|
|
7456
7498
|
else {
|
|
7457
|
-
throw new ParseError(spaceTrim
|
|
7499
|
+
throw new ParseError(spaceTrim("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
|
|
7458
7500
|
}
|
|
7459
7501
|
}
|
|
7460
7502
|
return {
|
|
@@ -7524,7 +7566,7 @@ var formatCommandParser = {
|
|
|
7524
7566
|
/**
|
|
7525
7567
|
* Description of the FORMAT command
|
|
7526
7568
|
*/
|
|
7527
|
-
description: spaceTrim
|
|
7569
|
+
description: spaceTrim("\n Format command describes the desired output of the task (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
|
|
7528
7570
|
/**
|
|
7529
7571
|
* Link to documentation
|
|
7530
7572
|
*/
|
|
@@ -7801,7 +7843,7 @@ var formfactorCommandParser = {
|
|
|
7801
7843
|
return __spreadArray([definition.name], __read(__assign({ aliasNames: [] }, definition).aliasNames), false).includes(formfactorNameCandidate);
|
|
7802
7844
|
});
|
|
7803
7845
|
if (formfactor === undefined) {
|
|
7804
|
-
throw new ParseError(spaceTrim
|
|
7846
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unknown formfactor name \"".concat(formfactorNameCandidate, "\"\n\n Available formfactors:\n ").concat(block(FORMFACTOR_DEFINITIONS.map(function (_a) {
|
|
7805
7847
|
var name = _a.name;
|
|
7806
7848
|
return "- ".concat(name);
|
|
7807
7849
|
}).join('\n')), "\n "); }));
|
|
@@ -7952,7 +7994,7 @@ var modelCommandParser = {
|
|
|
7952
7994
|
*/
|
|
7953
7995
|
parse: function (input) {
|
|
7954
7996
|
var args = input.args, normalized = input.normalized;
|
|
7955
|
-
var availableVariantsMessage = spaceTrim
|
|
7997
|
+
var availableVariantsMessage = spaceTrim(function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
|
|
7956
7998
|
return "- ".concat(variantName).concat(variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)');
|
|
7957
7999
|
}).join('\n')), "\n "); });
|
|
7958
8000
|
// TODO: Make this more elegant and dynamically
|
|
@@ -7973,10 +8015,10 @@ var modelCommandParser = {
|
|
|
7973
8015
|
// <- Note: [🤖]
|
|
7974
8016
|
}
|
|
7975
8017
|
else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
|
|
7976
|
-
spaceTrim
|
|
8018
|
+
spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
|
|
7977
8019
|
}
|
|
7978
8020
|
else {
|
|
7979
|
-
throw new ParseError(spaceTrim
|
|
8021
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
|
|
7980
8022
|
}
|
|
7981
8023
|
}
|
|
7982
8024
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -7987,7 +8029,7 @@ var modelCommandParser = {
|
|
|
7987
8029
|
};
|
|
7988
8030
|
}
|
|
7989
8031
|
else {
|
|
7990
|
-
throw new ParseError(spaceTrim
|
|
8032
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
7991
8033
|
}
|
|
7992
8034
|
},
|
|
7993
8035
|
/**
|
|
@@ -8001,10 +8043,10 @@ var modelCommandParser = {
|
|
|
8001
8043
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
8002
8044
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
8003
8045
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
8004
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
8046
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
8005
8047
|
}
|
|
8006
8048
|
else {
|
|
8007
|
-
throw new ParseError(spaceTrim
|
|
8049
|
+
throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
8008
8050
|
}
|
|
8009
8051
|
}
|
|
8010
8052
|
$pipelineJson.defaultModelRequirements[command.key] = command.value;
|
|
@@ -8029,11 +8071,11 @@ var modelCommandParser = {
|
|
|
8029
8071
|
}[command.key], " ").concat(command.value, "` in the task \"").concat($taskJson.title || $taskJson.name, "\""));
|
|
8030
8072
|
}
|
|
8031
8073
|
else {
|
|
8032
|
-
throw new ParseError(spaceTrim
|
|
8074
|
+
throw new ParseError(spaceTrim("\n Redefinition of MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\"\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($taskJson.modelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
8033
8075
|
}
|
|
8034
8076
|
}
|
|
8035
8077
|
if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
|
|
8036
|
-
console.log(spaceTrim
|
|
8078
|
+
console.log(spaceTrim("\n Setting MODEL `".concat(command.key, "` in the task \"").concat($taskJson.title || $taskJson.name, "\" to the same value as in the pipeline head\n\n In pipeline head:\n - MODEL ").concat(command.key, " ").concat(($pipelineJson.defaultModelRequirements || {})[command.key], "\n\n But same value is used in the task:\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
8037
8079
|
}
|
|
8038
8080
|
$taskJson.modelRequirements[command.key] = command.value;
|
|
8039
8081
|
},
|
|
@@ -8108,7 +8150,7 @@ var parameterCommandParser = {
|
|
|
8108
8150
|
// <- TODO: When [🥶] fixed, change to:
|
|
8109
8151
|
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
8110
8152
|
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
8111
|
-
throw new ParseError(spaceTrim
|
|
8153
|
+
throw new ParseError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterNameRaw, "}` can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
|
|
8112
8154
|
}
|
|
8113
8155
|
var isInput = normalized.startsWith('INPUT');
|
|
8114
8156
|
var isOutput = normalized.startsWith('OUTPUT');
|
|
@@ -8285,8 +8327,8 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
8285
8327
|
persona.description = personaDescription;
|
|
8286
8328
|
return;
|
|
8287
8329
|
}
|
|
8288
|
-
console.warn(spaceTrim
|
|
8289
|
-
persona.description += spaceTrim
|
|
8330
|
+
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
8331
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
8290
8332
|
}
|
|
8291
8333
|
|
|
8292
8334
|
/**
|
|
@@ -8636,7 +8678,7 @@ var COMMANDS = [
|
|
|
8636
8678
|
personaCommandParser,
|
|
8637
8679
|
foreachCommandParser,
|
|
8638
8680
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
8639
|
-
// <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8681
|
+
// <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8640
8682
|
];
|
|
8641
8683
|
/**
|
|
8642
8684
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8653,7 +8695,7 @@ var COMMANDS = [
|
|
|
8653
8695
|
function getParserForCommand(command) {
|
|
8654
8696
|
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
8655
8697
|
if (commandParser === undefined) {
|
|
8656
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " parser is not found\n\n ").concat(block(JSON.stringify(command, null, 4)
|
|
8698
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " parser is not found\n\n ").concat(block(JSON.stringify(command, null, 4)
|
|
8657
8699
|
.split('\n')
|
|
8658
8700
|
.map(function (line) { return "> ".concat(line); })
|
|
8659
8701
|
.join('\n')), "\n "); }));
|
|
@@ -8725,7 +8767,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
8725
8767
|
.map(removeMarkdownFormatting)
|
|
8726
8768
|
.map(function (item) { return item.trim(); });
|
|
8727
8769
|
if (items.length === 0 || items[0] === '') {
|
|
8728
|
-
throw new ParseError(spaceTrim(function (block) {
|
|
8770
|
+
throw new ParseError(spaceTrim$1(function (block) {
|
|
8729
8771
|
return "\n Malformed command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8730
8772
|
}));
|
|
8731
8773
|
}
|
|
@@ -8756,7 +8798,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
8756
8798
|
return command;
|
|
8757
8799
|
}
|
|
8758
8800
|
}
|
|
8759
|
-
throw new ParseError(spaceTrim(function (block) {
|
|
8801
|
+
throw new ParseError(spaceTrim$1(function (block) {
|
|
8760
8802
|
return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8761
8803
|
}));
|
|
8762
8804
|
}
|
|
@@ -8798,7 +8840,7 @@ function parseCommandVariant(input) {
|
|
|
8798
8840
|
if (!(error instanceof ParseError)) {
|
|
8799
8841
|
throw error;
|
|
8800
8842
|
}
|
|
8801
|
-
throw new ParseError(spaceTrim(function (block) {
|
|
8843
|
+
throw new ParseError(spaceTrim$1(function (block) {
|
|
8802
8844
|
return "\n Invalid ".concat(commandName, " command:\n\n Your command:\n - ").concat(raw, "\n\n The detailed error:\n ").concat(block(error.message), "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8803
8845
|
}));
|
|
8804
8846
|
}
|
|
@@ -8889,7 +8931,7 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
8889
8931
|
function extractOneBlockFromMarkdown(markdown) {
|
|
8890
8932
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
8891
8933
|
if (codeBlocks.length !== 1) {
|
|
8892
|
-
throw new ParseError(spaceTrim
|
|
8934
|
+
throw new ParseError(spaceTrim(function (block) { return "\n There should be exactly 1 code block in task section, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
8893
8935
|
}
|
|
8894
8936
|
return codeBlocks[0];
|
|
8895
8937
|
}
|
|
@@ -8910,7 +8952,7 @@ function parseMarkdownSection(value) {
|
|
|
8910
8952
|
}
|
|
8911
8953
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
8912
8954
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
8913
|
-
var content = spaceTrim
|
|
8955
|
+
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
8914
8956
|
if (level < 1 || level > 6) {
|
|
8915
8957
|
throw new ParseError('Markdown section must have heading level between 1 and 6');
|
|
8916
8958
|
}
|
|
@@ -8932,13 +8974,14 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
8932
8974
|
var e_1, _a;
|
|
8933
8975
|
var lines = markdown.split('\n');
|
|
8934
8976
|
var sections = [];
|
|
8977
|
+
// TODO: [🧽] DRY
|
|
8935
8978
|
var currentType = 'MARKDOWN';
|
|
8936
8979
|
var buffer = [];
|
|
8937
8980
|
var finishSection = function () {
|
|
8938
8981
|
if (buffer.length === 0) {
|
|
8939
8982
|
return;
|
|
8940
8983
|
}
|
|
8941
|
-
var section = spaceTrim
|
|
8984
|
+
var section = spaceTrim(buffer.join('\n'));
|
|
8942
8985
|
if (section === '') {
|
|
8943
8986
|
return;
|
|
8944
8987
|
}
|
|
@@ -9034,7 +9077,7 @@ function flattenMarkdown(markdown) {
|
|
|
9034
9077
|
}
|
|
9035
9078
|
finally { if (e_1) throw e_1.error; }
|
|
9036
9079
|
}
|
|
9037
|
-
return spaceTrim
|
|
9080
|
+
return spaceTrim(flattenedMarkdown);
|
|
9038
9081
|
}
|
|
9039
9082
|
/**
|
|
9040
9083
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -9052,7 +9095,7 @@ function flattenMarkdown(markdown) {
|
|
|
9052
9095
|
* @public exported from `@promptbook/markdown-utils`
|
|
9053
9096
|
*/
|
|
9054
9097
|
function removeContentComments(content) {
|
|
9055
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
9098
|
+
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
9056
9099
|
}
|
|
9057
9100
|
|
|
9058
9101
|
/**
|
|
@@ -9103,7 +9146,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9103
9146
|
if (pipelineString.startsWith('#!')) {
|
|
9104
9147
|
var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
|
|
9105
9148
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
9106
|
-
throw new ParseError(spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
9149
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
9107
9150
|
}
|
|
9108
9151
|
pipelineString = restLines.join('\n');
|
|
9109
9152
|
}
|
|
@@ -9113,27 +9156,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9113
9156
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
9114
9157
|
var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
|
|
9115
9158
|
if (pipelineHead === undefined) {
|
|
9116
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9159
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9117
9160
|
}
|
|
9118
9161
|
if (pipelineHead.level !== 1) {
|
|
9119
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9162
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not h1\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9120
9163
|
}
|
|
9121
9164
|
if (!pipelineSections.every(function (section) { return section.level === 2; })) {
|
|
9122
|
-
throw new UnexpectedError(spaceTrim(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9165
|
+
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Not every pipeline section is h2\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
9123
9166
|
}
|
|
9124
9167
|
// =============================================================
|
|
9125
9168
|
///Note: 2️⃣ Function for defining parameters
|
|
9126
9169
|
var defineParam = function (parameterCommand) {
|
|
9127
9170
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
9128
9171
|
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
9129
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
|
|
9172
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(parameterName, "} is reserved and cannot be used as resulting parameter name\n\n ").concat(block(getPipelineIdentification()), "\n "); }) /* <- TODO: [🚞] */);
|
|
9130
9173
|
}
|
|
9131
9174
|
var existingParameter = $pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
9132
9175
|
if (existingParameter &&
|
|
9133
9176
|
existingParameter.description &&
|
|
9134
9177
|
existingParameter.description !== parameterDescription &&
|
|
9135
9178
|
parameterDescription) {
|
|
9136
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Parameter `{".concat(parameterName, "}` is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
9179
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Parameter `{".concat(parameterName, "}` is defined multiple times with different description:\n\n ").concat(block(getPipelineIdentification()), "\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
9137
9180
|
}
|
|
9138
9181
|
if (existingParameter) {
|
|
9139
9182
|
if (parameterDescription) {
|
|
@@ -9161,7 +9204,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9161
9204
|
description = description.split(/^>.*$/gm).join('');
|
|
9162
9205
|
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
9163
9206
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
9164
|
-
description = spaceTrim(description);
|
|
9207
|
+
description = spaceTrim$1(description);
|
|
9165
9208
|
if (description === '') {
|
|
9166
9209
|
description = undefined;
|
|
9167
9210
|
}
|
|
@@ -9172,7 +9215,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9172
9215
|
var command = parseCommand(listItem, 'PIPELINE_HEAD');
|
|
9173
9216
|
var commandParser = getParserForCommand(command);
|
|
9174
9217
|
if (commandParser.isUsedInPipelineHead !== true /* <- Note: [🦦][4] */) {
|
|
9175
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9218
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the head of the pipeline ONLY at the pipeline task\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9176
9219
|
}
|
|
9177
9220
|
try {
|
|
9178
9221
|
commandParser.$applyToPipelineJson(command, $pipelineJson);
|
|
@@ -9182,7 +9225,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9182
9225
|
if (!(error instanceof ParseError)) {
|
|
9183
9226
|
throw error;
|
|
9184
9227
|
}
|
|
9185
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9228
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command ".concat(command.type, " failed to apply to the pipeline\n\n The error:\n ").concat(block(error.message), "\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9186
9229
|
}
|
|
9187
9230
|
if (command.type === 'PARAMETER') {
|
|
9188
9231
|
defineParam(command);
|
|
@@ -9244,7 +9287,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9244
9287
|
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
9245
9288
|
//Note: Remove lists and return statement - TODO: [🎾]
|
|
9246
9289
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
9247
|
-
description_1 = spaceTrim(description_1);
|
|
9290
|
+
description_1 = spaceTrim$1(description_1);
|
|
9248
9291
|
if (description_1 === '') {
|
|
9249
9292
|
description_1 = undefined;
|
|
9250
9293
|
}
|
|
@@ -9280,7 +9323,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9280
9323
|
var _loop_4 = function (listItem, command) {
|
|
9281
9324
|
var commandParser = getParserForCommand(command);
|
|
9282
9325
|
if (commandParser.isUsedInPipelineTask !== true /* <- Note: [🦦][4] */) {
|
|
9283
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9326
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` is not allowed in the task of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9284
9327
|
}
|
|
9285
9328
|
try {
|
|
9286
9329
|
commandParser.$applyToTaskJson(
|
|
@@ -9291,7 +9334,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9291
9334
|
if (!(error instanceof ParseError)) {
|
|
9292
9335
|
throw error;
|
|
9293
9336
|
}
|
|
9294
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9337
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Command `".concat(command.type, "` failed to apply to the task\n\n The error:\n ").concat(block(error.message), "\n\n Current state of the task:\n ").concat(block(JSON.stringify($taskJson, null, 4)), "\n *<- Maybe wrong order of commands?*\n\n Raw command:\n - ").concat(listItem, "\n\n Usage of ").concat(command.type, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
9295
9338
|
}
|
|
9296
9339
|
if (command.type === 'PARAMETER') {
|
|
9297
9340
|
defineParam(command);
|
|
@@ -9315,10 +9358,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
9315
9358
|
// TODO: [🍧] Should be done in SECTION command
|
|
9316
9359
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
9317
9360
|
if (!language) {
|
|
9318
|
-
throw new ParseError(spaceTrim(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
9361
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n You must specify the language of the script in the `SCRIPT` task\n\n ".concat(block(getPipelineIdentification()), "\n "); }));
|
|
9319
9362
|
}
|
|
9320
9363
|
if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
9321
|
-
throw new ParseError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
9364
|
+
throw new ParseError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
9322
9365
|
}
|
|
9323
9366
|
$taskJson.contentLanguage = language;
|
|
9324
9367
|
}
|
|
@@ -9979,13 +10022,13 @@ function parseKeywordsFromString(input) {
|
|
|
9979
10022
|
* @public exported from `@promptbook/utils`
|
|
9980
10023
|
*/
|
|
9981
10024
|
function trimCodeBlock(value) {
|
|
9982
|
-
value = spaceTrim(value);
|
|
10025
|
+
value = spaceTrim$1(value);
|
|
9983
10026
|
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
9984
10027
|
return value;
|
|
9985
10028
|
}
|
|
9986
10029
|
value = value.replace(/^```[a-z]*/i, '');
|
|
9987
10030
|
value = value.replace(/```$/i, '');
|
|
9988
|
-
value = spaceTrim(value);
|
|
10031
|
+
value = spaceTrim$1(value);
|
|
9989
10032
|
return value;
|
|
9990
10033
|
}
|
|
9991
10034
|
|
|
@@ -9998,9 +10041,9 @@ function trimCodeBlock(value) {
|
|
|
9998
10041
|
* @public exported from `@promptbook/utils`
|
|
9999
10042
|
*/
|
|
10000
10043
|
function trimEndOfCodeBlock(value) {
|
|
10001
|
-
value = spaceTrim(value);
|
|
10044
|
+
value = spaceTrim$1(value);
|
|
10002
10045
|
value = value.replace(/```$/g, '');
|
|
10003
|
-
value = spaceTrim(value);
|
|
10046
|
+
value = spaceTrim$1(value);
|
|
10004
10047
|
return value;
|
|
10005
10048
|
}
|
|
10006
10049
|
|
|
@@ -10022,7 +10065,7 @@ function unwrapResult(text, options) {
|
|
|
10022
10065
|
var trimmedText = text;
|
|
10023
10066
|
// Remove leading and trailing spaces and newlines
|
|
10024
10067
|
if (isTrimmed) {
|
|
10025
|
-
trimmedText = spaceTrim(trimmedText);
|
|
10068
|
+
trimmedText = spaceTrim$1(trimmedText);
|
|
10026
10069
|
}
|
|
10027
10070
|
var processedText = trimmedText;
|
|
10028
10071
|
if (isIntroduceSentenceRemoved) {
|
|
@@ -10031,7 +10074,7 @@ function unwrapResult(text, options) {
|
|
|
10031
10074
|
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
10032
10075
|
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
10033
10076
|
}
|
|
10034
|
-
processedText = spaceTrim(processedText);
|
|
10077
|
+
processedText = spaceTrim$1(processedText);
|
|
10035
10078
|
}
|
|
10036
10079
|
if (processedText.length < 3) {
|
|
10037
10080
|
return trimmedText;
|
|
@@ -10091,10 +10134,10 @@ function preserve(func) {
|
|
|
10091
10134
|
return __generator(this, function (_a) {
|
|
10092
10135
|
switch (_a.label) {
|
|
10093
10136
|
case 0:
|
|
10094
|
-
// TODO: Change to `await forEver` or something better
|
|
10137
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
10095
10138
|
return [4 /*yield*/, forTime(100000000)];
|
|
10096
10139
|
case 1:
|
|
10097
|
-
// TODO: Change to `await forEver` or something better
|
|
10140
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
10098
10141
|
_a.sent();
|
|
10099
10142
|
_a.label = 2;
|
|
10100
10143
|
case 2:
|
|
@@ -10158,7 +10201,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
10158
10201
|
*/
|
|
10159
10202
|
JavascriptEvalExecutionTools.prototype.execute = function (options) {
|
|
10160
10203
|
return __awaiter(this, void 0, void 0, function () {
|
|
10161
|
-
var scriptLanguage, parameters, script, spaceTrim, removeQuotes$1, unwrapResult$1, trimEndOfCodeBlock$1, trimCodeBlock$1, trim, reverse, removeEmojis$1, prettifyMarkdown$1, capitalize$1, decapitalize$1, nameToUriPart$1, nameToUriParts$1, removeDiacritics$1, normalizeWhitespaces$1, normalizeToKebabCase$1, normalizeTo_camelCase$1, normalizeTo_snake_case$1, normalizeTo_PascalCase$1, parseKeywords, normalizeTo_SCREAMING_CASE$1, buildinFunctions, buildinFunctionsStatement, customFunctions, customFunctionsStatement, statementToEvaluate, result, error_1, undefinedName_1;
|
|
10204
|
+
var scriptLanguage, parameters, script, spaceTrim$1, removeQuotes$1, unwrapResult$1, trimEndOfCodeBlock$1, trimCodeBlock$1, trim, reverse, removeEmojis$1, prettifyMarkdown$1, capitalize$1, decapitalize$1, nameToUriPart$1, nameToUriParts$1, removeDiacritics$1, normalizeWhitespaces$1, normalizeToKebabCase$1, normalizeTo_camelCase$1, normalizeTo_snake_case$1, normalizeTo_PascalCase$1, parseKeywords, normalizeTo_SCREAMING_CASE$1, buildinFunctions, buildinFunctionsStatement, customFunctions, customFunctionsStatement, statementToEvaluate, result, error_1, undefinedName_1;
|
|
10162
10205
|
return __generator(this, function (_a) {
|
|
10163
10206
|
switch (_a.label) {
|
|
10164
10207
|
case 0:
|
|
@@ -10167,8 +10210,8 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
10167
10210
|
if (scriptLanguage !== 'javascript') {
|
|
10168
10211
|
throw new PipelineExecutionError("Script language ".concat(scriptLanguage, " not supported to be executed by JavascriptEvalExecutionTools"));
|
|
10169
10212
|
}
|
|
10170
|
-
spaceTrim = function (_) { return spaceTrim
|
|
10171
|
-
preserve(spaceTrim);
|
|
10213
|
+
spaceTrim$1 = function (_) { return spaceTrim(_); };
|
|
10214
|
+
preserve(spaceTrim$1);
|
|
10172
10215
|
removeQuotes$1 = removeQuotes;
|
|
10173
10216
|
preserve(removeQuotes$1);
|
|
10174
10217
|
unwrapResult$1 = unwrapResult;
|
|
@@ -10218,7 +10261,7 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
10218
10261
|
}
|
|
10219
10262
|
buildinFunctions = {
|
|
10220
10263
|
// TODO: [🍯] DRY all these functions across the file
|
|
10221
|
-
spaceTrim: spaceTrim,
|
|
10264
|
+
spaceTrim: spaceTrim$1,
|
|
10222
10265
|
removeQuotes: removeQuotes$1,
|
|
10223
10266
|
unwrapResult: unwrapResult$1,
|
|
10224
10267
|
trimEndOfCodeBlock: trimEndOfCodeBlock$1,
|
|
@@ -10254,14 +10297,14 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
10254
10297
|
return "const ".concat(functionName, " = customFunctions.").concat(functionName, ";");
|
|
10255
10298
|
})
|
|
10256
10299
|
.join('\n');
|
|
10257
|
-
statementToEvaluate = spaceTrim
|
|
10300
|
+
statementToEvaluate = spaceTrim(function (block) { return "\n\n // Build-in functions:\n ".concat(block(buildinFunctionsStatement), "\n\n // Custom functions:\n ").concat(block(customFunctionsStatement || '// -- No custom functions --'), "\n\n // The script:\n ").concat(block(Object.entries(parameters)
|
|
10258
10301
|
.map(function (_a) {
|
|
10259
10302
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
10260
10303
|
return "const ".concat(key, " = ").concat(JSON.stringify(value), ";");
|
|
10261
10304
|
})
|
|
10262
10305
|
.join('\n')), "\n (()=>{ ").concat(script, " })()\n "); });
|
|
10263
10306
|
if (this.options.isVerbose) {
|
|
10264
|
-
console.info(spaceTrim
|
|
10307
|
+
console.info(spaceTrim(function (block) { return "\n \uD83D\uDE80 Evaluating ".concat(scriptLanguage, " script:\n\n ").concat(block(statementToEvaluate)); }));
|
|
10265
10308
|
}
|
|
10266
10309
|
_a.label = 1;
|
|
10267
10310
|
case 1:
|
|
@@ -10286,12 +10329,12 @@ var JavascriptEvalExecutionTools = /** @class */ (function () {
|
|
|
10286
10329
|
To: [PipelineExecutionError: Parameter `{thing}` is not defined],
|
|
10287
10330
|
*/
|
|
10288
10331
|
if (!statementToEvaluate.includes(undefinedName_1 + '(')) {
|
|
10289
|
-
throw new PipelineExecutionError(spaceTrim
|
|
10332
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n\n Parameter `{".concat(undefinedName_1, "}` is not defined\n\n This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:\n\n ").concat(block(Object.keys(parameters)
|
|
10290
10333
|
.map(function (key) { return " - ".concat(key, "\n"); })
|
|
10291
10334
|
.join('')), "\n\n The script is:\n ```javascript\n ").concat(block(script), "\n ```\n\n Original error message:\n ").concat(block(error_1.message), "\n\n\n "); }));
|
|
10292
10335
|
}
|
|
10293
10336
|
else {
|
|
10294
|
-
throw new PipelineExecutionError(spaceTrim
|
|
10337
|
+
throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Function ".concat(undefinedName_1, "() is not defined\n\n - Make sure that the function is one of built-in functions\n - Or you have to defined the function during construction of JavascriptEvalExecutionTools\n\n Original error message:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
10295
10338
|
}
|
|
10296
10339
|
}
|
|
10297
10340
|
throw error_1;
|
|
@@ -10694,7 +10737,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10694
10737
|
}
|
|
10695
10738
|
else {
|
|
10696
10739
|
existing = collection.get(pipeline.pipelineUrl);
|
|
10697
|
-
throw new PipelineUrlError(spaceTrim
|
|
10740
|
+
throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
10698
10741
|
}
|
|
10699
10742
|
}
|
|
10700
10743
|
}
|
|
@@ -10704,7 +10747,7 @@ function createCollectionFromDirectory(path, tools, options) {
|
|
|
10704
10747
|
if (!(error_1 instanceof Error)) {
|
|
10705
10748
|
throw error_1;
|
|
10706
10749
|
}
|
|
10707
|
-
wrappedErrorMessage = spaceTrim
|
|
10750
|
+
wrappedErrorMessage = spaceTrim(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
10708
10751
|
if (isCrashedOnError) {
|
|
10709
10752
|
throw new CollectionError(wrappedErrorMessage);
|
|
10710
10753
|
}
|
|
@@ -10814,7 +10857,7 @@ function usageToHuman(usage) {
|
|
|
10814
10857
|
// Note: For negligible usage, we report at least something
|
|
10815
10858
|
reportItems.push('Negligible');
|
|
10816
10859
|
}
|
|
10817
|
-
return spaceTrim
|
|
10860
|
+
return spaceTrim(function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
|
|
10818
10861
|
}
|
|
10819
10862
|
/**
|
|
10820
10863
|
* TODO: [🍓][🧞♂️] Use "$1" not "1 USD"
|
|
@@ -10833,18 +10876,18 @@ function usageToHuman(usage) {
|
|
|
10833
10876
|
function initializeMakeCommand(program) {
|
|
10834
10877
|
var _this = this;
|
|
10835
10878
|
var makeCommand = program.command('make');
|
|
10836
|
-
makeCommand.description(spaceTrim
|
|
10879
|
+
makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
|
|
10837
10880
|
// TODO: [🧅] DRY command arguments
|
|
10838
10881
|
makeCommand.argument('[path]',
|
|
10839
10882
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
10840
10883
|
'Path to promptbook collection directory', DEFAULT_BOOKS_DIRNAME);
|
|
10841
10884
|
makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
|
|
10842
|
-
makeCommand.option('-f, --format <format>', spaceTrim
|
|
10885
|
+
makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳🌈] */);
|
|
10843
10886
|
makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
|
|
10844
10887
|
makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
|
|
10845
10888
|
makeCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
|
|
10846
10889
|
makeCommand.option('-v, --verbose', "Is output verbose", false);
|
|
10847
|
-
makeCommand.option('-o, --out-file <path>', spaceTrim
|
|
10890
|
+
makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
|
|
10848
10891
|
makeCommand.action(function (path, _a) {
|
|
10849
10892
|
var projectName = _a.projectName, format = _a.format, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, outFile = _a.outFile;
|
|
10850
10893
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -10963,7 +11006,7 @@ function initializeMakeCommand(program) {
|
|
|
10963
11006
|
if (lastChar !== ']') {
|
|
10964
11007
|
throw new UnexpectedError("Last character of serialized collection should be \"]\" not \"".concat(lastChar, "\""));
|
|
10965
11008
|
}
|
|
10966
|
-
return spaceTrim
|
|
11009
|
+
return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
|
|
10967
11010
|
})();
|
|
10968
11011
|
saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
|
|
10969
11012
|
var filename;
|
|
@@ -10997,14 +11040,14 @@ function initializeMakeCommand(program) {
|
|
|
10997
11040
|
case 21:
|
|
10998
11041
|
if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 23];
|
|
10999
11042
|
formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
|
|
11000
|
-
return [4 /*yield*/, saveFile('js', spaceTrim
|
|
11043
|
+
return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
|
|
11001
11044
|
case 22:
|
|
11002
11045
|
(_g.sent()) + '\n';
|
|
11003
11046
|
_g.label = 23;
|
|
11004
11047
|
case 23:
|
|
11005
11048
|
if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 25];
|
|
11006
11049
|
formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
|
|
11007
|
-
return [4 /*yield*/, saveFile('ts', spaceTrim
|
|
11050
|
+
return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
|
|
11008
11051
|
case 24:
|
|
11009
11052
|
_g.sent();
|
|
11010
11053
|
_g.label = 25;
|
|
@@ -11040,7 +11083,7 @@ function addAutoGeneratedSection(content, options) {
|
|
|
11040
11083
|
var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
|
|
11041
11084
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
11042
11085
|
var sectionMatch = content.match(sectionRegex);
|
|
11043
|
-
var contentToInsert = spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
|
|
11086
|
+
var contentToInsert = spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
|
|
11044
11087
|
if (sectionMatch) {
|
|
11045
11088
|
return content.replace(sectionRegex, contentToInsert);
|
|
11046
11089
|
}
|
|
@@ -11048,11 +11091,11 @@ function addAutoGeneratedSection(content, options) {
|
|
|
11048
11091
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
11049
11092
|
if (placeForSection !== null) {
|
|
11050
11093
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
11051
|
-
return content.replace(heading_1, spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n
|
|
11094
|
+
return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
11052
11095
|
}
|
|
11053
11096
|
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
11054
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
11055
|
-
return spaceTrim(function (block) { return "\n ".concat(block(content), "\n
|
|
11097
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
11098
|
+
return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
11056
11099
|
}
|
|
11057
11100
|
/**
|
|
11058
11101
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -11082,7 +11125,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
11082
11125
|
}
|
|
11083
11126
|
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
11084
11127
|
};
|
|
11085
|
-
var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
11128
|
+
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
11086
11129
|
.flatMap(function (_a) {
|
|
11087
11130
|
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
11088
11131
|
return __spreadArray([
|
|
@@ -11143,7 +11186,7 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
11143
11186
|
return { href: "#".concat(task.name), title: task.title };
|
|
11144
11187
|
},
|
|
11145
11188
|
});
|
|
11146
|
-
promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
11189
|
+
promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
11147
11190
|
pipelineString = addAutoGeneratedSection(pipelineString, {
|
|
11148
11191
|
sectionName: 'Graph',
|
|
11149
11192
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -11171,7 +11214,7 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
11171
11214
|
function initializePrettifyCommand(program) {
|
|
11172
11215
|
var _this = this;
|
|
11173
11216
|
var prettifyCommand = program.command('prettify');
|
|
11174
|
-
prettifyCommand.description(spaceTrim
|
|
11217
|
+
prettifyCommand.description(spaceTrim("\n Iterates over `.book.md` files and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
|
|
11175
11218
|
prettifyCommand.argument('<filesGlob>',
|
|
11176
11219
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
11177
11220
|
'Pipelines to prettify as glob pattern');
|
|
@@ -11419,7 +11462,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11419
11462
|
var e_1, _a;
|
|
11420
11463
|
var _b, _c, _d, _e, _f, _g;
|
|
11421
11464
|
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
11422
|
-
var executionReportString = spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
11465
|
+
var executionReportString = spaceTrim$1(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
11423
11466
|
var headerList = [];
|
|
11424
11467
|
if (executionReportJson.pipelineUrl) {
|
|
11425
11468
|
headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
|
|
@@ -11477,7 +11520,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11477
11520
|
'\n\n' +
|
|
11478
11521
|
executionReportJson.promptExecutions
|
|
11479
11522
|
.map(function (promptExecution) {
|
|
11480
|
-
// TODO: Make some better system to convert
|
|
11523
|
+
// TODO: [💩] Make some better system to convert headings to links
|
|
11481
11524
|
var hash = normalizeToKebabCase(promptExecution.prompt.title);
|
|
11482
11525
|
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
11483
11526
|
hash = '-' + hash;
|
|
@@ -11539,7 +11582,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11539
11582
|
if (just(true)) {
|
|
11540
11583
|
executionReportString +=
|
|
11541
11584
|
'\n\n\n\n' +
|
|
11542
|
-
spaceTrim(function (block) {
|
|
11585
|
+
spaceTrim$1(function (block) {
|
|
11543
11586
|
var _a;
|
|
11544
11587
|
return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
|
|
11545
11588
|
});
|
|
@@ -11550,7 +11593,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11550
11593
|
executionReportString += '*No result*';
|
|
11551
11594
|
}
|
|
11552
11595
|
else if (typeof promptExecution.result.content === 'string') {
|
|
11553
|
-
executionReportString += spaceTrim(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
11596
|
+
executionReportString += spaceTrim$1(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
11554
11597
|
}
|
|
11555
11598
|
else {
|
|
11556
11599
|
executionReportString += embeddingVectorToString(promptExecution.result.content);
|
|
@@ -11559,7 +11602,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11559
11602
|
if (promptExecution.error && promptExecution.error.message) {
|
|
11560
11603
|
executionReportString +=
|
|
11561
11604
|
'\n\n\n\n' +
|
|
11562
|
-
spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
11605
|
+
spaceTrim$1(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
11563
11606
|
}
|
|
11564
11607
|
};
|
|
11565
11608
|
try {
|
|
@@ -11592,7 +11635,7 @@ function executionReportJsonToString(executionReportJson, options) {
|
|
|
11592
11635
|
function initializeRunCommand(program) {
|
|
11593
11636
|
var _this = this;
|
|
11594
11637
|
var runCommand = program.command('run', { isDefault: true });
|
|
11595
|
-
runCommand.description(spaceTrim
|
|
11638
|
+
runCommand.description(spaceTrim("\n Runs a pipeline\n "));
|
|
11596
11639
|
// TODO: [🧅] DRY command arguments
|
|
11597
11640
|
runCommand.argument('<path>',
|
|
11598
11641
|
// <- Note: [🧟♂️] This is NOT promptbook collection directory BUT direct path to .book.md file
|
|
@@ -11677,7 +11720,7 @@ function initializeRunCommand(program) {
|
|
|
11677
11720
|
if (!error.message.includes('No LLM tools')) {
|
|
11678
11721
|
throw error;
|
|
11679
11722
|
}
|
|
11680
|
-
console.error(colors.red(spaceTrim
|
|
11723
|
+
console.error(colors.red(spaceTrim(function (block) { return "\n You need to configure LLM tools first\n\n 1) Create .env file at the root of your project\n 2) Configure API keys for LLM tools\n \n For example:\n ".concat(block($llmToolsMetadataRegister
|
|
11681
11724
|
.list()
|
|
11682
11725
|
.map(function (_a) {
|
|
11683
11726
|
var title = _a.title, envVariables = _a.envVariables;
|
|
@@ -11721,7 +11764,7 @@ function initializeRunCommand(program) {
|
|
|
11721
11764
|
if (!(error_1 instanceof ParseError)) {
|
|
11722
11765
|
throw error_1;
|
|
11723
11766
|
}
|
|
11724
|
-
console.error(colors.red(spaceTrim
|
|
11767
|
+
console.error(colors.red(spaceTrim(function (block) { return "\n ".concat(block(error_1.message), "\n\n in ").concat(filePath, "\n "); })));
|
|
11725
11768
|
return [2 /*return*/, process.exit(1)];
|
|
11726
11769
|
case 15:
|
|
11727
11770
|
if (isVerbose) {
|
|
@@ -11772,7 +11815,7 @@ function initializeRunCommand(program) {
|
|
|
11772
11815
|
};
|
|
11773
11816
|
});
|
|
11774
11817
|
if (isInteractive === false && questions.length !== 0) {
|
|
11775
|
-
console.error(colors.red(spaceTrim
|
|
11818
|
+
console.error(colors.red(spaceTrim(function (block) { return "\n When using --no-interactive you need to pass all the input parameters through --json\n\n You are missing:\n ".concat(block(pipeline.parameters
|
|
11776
11819
|
.filter(function (_a) {
|
|
11777
11820
|
var isInput = _a.isInput;
|
|
11778
11821
|
return isInput;
|
|
@@ -11918,7 +11961,7 @@ function initializeRunCommand(program) {
|
|
|
11918
11961
|
function initializeTestCommand(program) {
|
|
11919
11962
|
var _this = this;
|
|
11920
11963
|
var testCommand = program.command('test');
|
|
11921
|
-
testCommand.description(spaceTrim
|
|
11964
|
+
testCommand.description(spaceTrim("\n Iterates over `.book.md` and `.book.json` and checks if they are parsable and logically valid\n "));
|
|
11922
11965
|
testCommand.argument('<filesGlob>',
|
|
11923
11966
|
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
11924
11967
|
'Pipelines to test as glob pattern');
|
|
@@ -12044,7 +12087,7 @@ function promptbookCli() {
|
|
|
12044
12087
|
var isVerbose, program;
|
|
12045
12088
|
return __generator(this, function (_a) {
|
|
12046
12089
|
if (!$isRunningInNode()) {
|
|
12047
|
-
throw new EnvironmentMismatchError(spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
|
|
12090
|
+
throw new EnvironmentMismatchError(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
|
|
12048
12091
|
}
|
|
12049
12092
|
isVerbose = process.argv.some(function (arg) { return arg === '--verbose' || arg === '-v'; });
|
|
12050
12093
|
// <- TODO: Can be this be done with commander before the commander commands are initialized?
|
|
@@ -12245,7 +12288,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
|
|
|
12245
12288
|
socket.on('connect', function () {
|
|
12246
12289
|
resolve(socket);
|
|
12247
12290
|
});
|
|
12248
|
-
// TODO: [
|
|
12291
|
+
// TODO: [💩] Better timeout handling
|
|
12249
12292
|
setTimeout(function () {
|
|
12250
12293
|
reject(new Error("Timeout while connecting to ".concat(_this.options.remoteUrl)));
|
|
12251
12294
|
}, CONNECTION_TIMEOUT_MS);
|
|
@@ -12743,7 +12786,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
12743
12786
|
return modelName.startsWith(defaultModelName);
|
|
12744
12787
|
});
|
|
12745
12788
|
if (model === undefined) {
|
|
12746
|
-
throw new UnexpectedError(spaceTrim
|
|
12789
|
+
throw new UnexpectedError(spaceTrim(function (block) {
|
|
12747
12790
|
return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(ANTHROPIC_CLAUDE_MODELS.map(function (_a) {
|
|
12748
12791
|
var modelName = _a.modelName;
|
|
12749
12792
|
return "- \"".concat(modelName, "\"");
|
|
@@ -13223,7 +13266,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
|
13223
13266
|
modelVariant: 'CHAT',
|
|
13224
13267
|
modelTitle: 'o1-preview-2024-09-12',
|
|
13225
13268
|
modelName: 'o1-preview-2024-09-12',
|
|
13226
|
-
// <- TODO: [
|
|
13269
|
+
// <- TODO: [💩] Some better system to organize theese date suffixes and versions
|
|
13227
13270
|
pricing: {
|
|
13228
13271
|
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
13229
13272
|
output: computeUsage("$60.00 / 1M tokens"),
|
|
@@ -13273,7 +13316,7 @@ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
|
13273
13316
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
13274
13317
|
* @see https://openai.com/api/pricing/
|
|
13275
13318
|
* @see /other/playground/playground.ts
|
|
13276
|
-
* TODO: [🍓] Make better
|
|
13319
|
+
* TODO: [🍓][💩] Make better
|
|
13277
13320
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
13278
13321
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
13279
13322
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -13757,7 +13800,7 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
13757
13800
|
return modelVariant === 'CHAT';
|
|
13758
13801
|
})) === null || _a === void 0 ? void 0 : _a.modelName);
|
|
13759
13802
|
if (!modelName) {
|
|
13760
|
-
throw new PipelineExecutionError(spaceTrim
|
|
13803
|
+
throw new PipelineExecutionError(spaceTrim("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
|
|
13761
13804
|
}
|
|
13762
13805
|
return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
|
|
13763
13806
|
case 1:
|
|
@@ -14369,7 +14412,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
14369
14412
|
return modelName === defaultModelName;
|
|
14370
14413
|
});
|
|
14371
14414
|
if (model === undefined) {
|
|
14372
|
-
throw new UnexpectedError(spaceTrim
|
|
14415
|
+
throw new UnexpectedError(spaceTrim(function (block) {
|
|
14373
14416
|
return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(OPENAI_MODELS.map(function (_a) {
|
|
14374
14417
|
var modelName = _a.modelName;
|
|
14375
14418
|
return "- \"".concat(modelName, "\"");
|
|
@@ -14767,11 +14810,11 @@ function $execCommand(options) {
|
|
|
14767
14810
|
if (isVerbose) {
|
|
14768
14811
|
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
14769
14812
|
}
|
|
14770
|
-
resolve(spaceTrim(output_1.join('\n')));
|
|
14813
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
14771
14814
|
}
|
|
14772
14815
|
}
|
|
14773
14816
|
else {
|
|
14774
|
-
resolve(spaceTrim(output_1.join('\n')));
|
|
14817
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
14775
14818
|
}
|
|
14776
14819
|
};
|
|
14777
14820
|
commandProcess.on('close', finishWithCode);
|
|
@@ -14788,7 +14831,7 @@ function $execCommand(options) {
|
|
|
14788
14831
|
if (isVerbose) {
|
|
14789
14832
|
console.warn(error);
|
|
14790
14833
|
}
|
|
14791
|
-
resolve(spaceTrim(output_1.join('\n')));
|
|
14834
|
+
resolve(spaceTrim$1(output_1.join('\n')));
|
|
14792
14835
|
}
|
|
14793
14836
|
});
|
|
14794
14837
|
}
|
|
@@ -14990,8 +15033,8 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
14990
15033
|
switch (_c.label) {
|
|
14991
15034
|
case 0:
|
|
14992
15035
|
name = "piece-".concat(i);
|
|
14993
|
-
title = spaceTrim
|
|
14994
|
-
knowledgePieceContent = spaceTrim
|
|
15036
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
15037
|
+
knowledgePieceContent = spaceTrim(knowledgeTextPiece);
|
|
14995
15038
|
keywords = [];
|
|
14996
15039
|
index = [];
|
|
14997
15040
|
_c.label = 1;
|
|
@@ -15001,7 +15044,7 @@ var MarkdownScraper = /** @class */ (function () {
|
|
|
15001
15044
|
case 2:
|
|
15002
15045
|
titleResult = _c.sent();
|
|
15003
15046
|
_a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
|
|
15004
|
-
title = spaceTrim
|
|
15047
|
+
title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
|
|
15005
15048
|
name = titleToName(title);
|
|
15006
15049
|
return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
|
|
15007
15050
|
case 3:
|
|
@@ -15167,7 +15210,7 @@ var DocumentScraper = /** @class */ (function () {
|
|
|
15167
15210
|
case 4:
|
|
15168
15211
|
// Note: [0]
|
|
15169
15212
|
if (!(_g.sent())) {
|
|
15170
|
-
throw new UnexpectedError(spaceTrim
|
|
15213
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n File that was supposed to be created by Pandoc does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
15171
15214
|
}
|
|
15172
15215
|
_g.label = 5;
|
|
15173
15216
|
case 5: return [2 /*return*/, cacheFilehandler];
|
|
@@ -15340,7 +15383,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
|
|
|
15340
15383
|
case 4:
|
|
15341
15384
|
files_1 = _g.sent();
|
|
15342
15385
|
if (files_1.length !== 1) {
|
|
15343
|
-
throw new UnexpectedError(spaceTrim
|
|
15386
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n Expected exactly 1 file in the LibreOffice output directory, got ".concat(files_1.length, "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n "); }));
|
|
15344
15387
|
}
|
|
15345
15388
|
file = files_1[0];
|
|
15346
15389
|
return [4 /*yield*/, rename(join(documentSourceOutdirPathForLibreOffice_1, file), cacheFilehandler.filename)];
|
|
@@ -15352,7 +15395,7 @@ var LegacyDocumentScraper = /** @class */ (function () {
|
|
|
15352
15395
|
return [4 /*yield*/, isFileExisting(cacheFilehandler.filename, this.tools.fs)];
|
|
15353
15396
|
case 7:
|
|
15354
15397
|
if (!(_g.sent())) {
|
|
15355
|
-
throw new UnexpectedError(spaceTrim
|
|
15398
|
+
throw new UnexpectedError(spaceTrim(function (block) { return "\n File that was supposed to be created by LibreOffice does not exist for unknown reason\n\n Expected file:\n ".concat(block(cacheFilehandler.filename), "\n\n The temporary folder:\n ").concat(block(documentSourceOutdirPathForLibreOffice_1), "\n\n Command:\n > ").concat(block(command_1), "\n\n "); }));
|
|
15356
15399
|
}
|
|
15357
15400
|
_g.label = 8;
|
|
15358
15401
|
case 8: return [2 /*return*/, cacheFilehandler];
|